summaryrefslogtreecommitdiffstats
path: root/Modules/hashlib.h
Commit message (Expand)AuthorAgeFilesLines
* Closes #18627: merge from 3.3Ned Deily2013-08-021-1/+1
|\
| * Issue #18627: Fix typo noticed by Vajrasky Kok.Ned Deily2013-08-021-1/+1
* | Issue #16113: integrade SHA-3 (Keccak) patch from http://hg.python.org/sandbo...Christian Heimes2012-10-061-0/+33
|/
* Fixes Issue #3745: Fix hashlib to always reject unicode and nonGregory P. Smith2009-02-121-0/+28
8&id=265dce6cbbe700183228632f16bc1d4a2683c935&id2=52e5004b59d89e5f1bf2ceaba0d2c9e63368454b'>.hgignore4
-rw-r--r--.hgtags7
-rw-r--r--Doc/Makefile2
-rw-r--r--Doc/c-api/arg.rst37
-rw-r--r--Doc/c-api/exceptions.rst17
-rw-r--r--Doc/c-api/init.rst33
-rw-r--r--Doc/c-api/intro.rst11
-rw-r--r--Doc/c-api/long.rst18
-rw-r--r--Doc/c-api/memory.rst113
-rw-r--r--Doc/c-api/structures.rst5
-rw-r--r--Doc/c-api/sys.rst25
-rw-r--r--Doc/c-api/unicode.rst53
-rw-r--r--Doc/data/refcounts.dat3
-rw-r--r--Doc/extending/embedding.rst6
-rw-r--r--Doc/faq/programming.rst3
-rw-r--r--Doc/glossary.rst26
-rw-r--r--Doc/howto/argparse.rst3
-rw-r--r--Doc/howto/clinic.rst4
-rw-r--r--Doc/howto/index.rst1
-rw-r--r--Doc/howto/instrumentation.rst411
-rw-r--r--Doc/includes/email-alternative-new-api.py56
-rw-r--r--[-rwxr-xr-x]Doc/includes/email-alternative.py76
-rw-r--r--Doc/includes/email-dir.py55
-rw-r--r--Doc/includes/email-headers.py22
-rw-r--r--Doc/includes/email-mime.py29
-rw-r--r--Doc/includes/email-read-alternative.py (renamed from Doc/includes/email-read-alternative-new-api.py)0
-rw-r--r--Doc/includes/email-simple.py8
-rw-r--r--Doc/includes/email-unpack.py8
-rw-r--r--Doc/includes/run-func.c4
-rw-r--r--Doc/includes/test.py2
-rw-r--r--Doc/includes/tzinfo-examples.py130
-rw-r--r--Doc/installing/index.rst61
-rw-r--r--Doc/library/asynchat.rst16
-rw-r--r--Doc/library/asyncio-eventloop.rst5
-rw-r--r--Doc/library/binascii.rst11
-rw-r--r--Doc/library/bz2.rst6
-rw-r--r--Doc/library/cmath.rst36
-rw-r--r--Doc/library/code.rst19
-rw-r--r--Doc/library/codecs.rst10
-rw-r--r--Doc/library/collections.abc.rst34
-rw-r--r--Doc/library/collections.rst31
-rw-r--r--Doc/library/compileall.rst18
-rw-r--r--Doc/library/concurrent.futures.rst6
-rw-r--r--Doc/library/constants.rst22
-rw-r--r--Doc/library/contextlib.rst20
-rw-r--r--Doc/library/crypt.rst2
-rw-r--r--Doc/library/crypto.rst2
-rw-r--r--Doc/library/csv.rst49
-rw-r--r--Doc/library/ctypes.rst17
-rw-r--r--Doc/library/datetime.rst305
-rw-r--r--Doc/library/dbm.rst4
-rw-r--r--Doc/library/decimal.rst23
-rw-r--r--Doc/library/dis.rst86
-rw-r--r--Doc/library/email.charset.rst5
-rw-r--r--Doc/library/email.compat32-message.rst754
-rw-r--r--Doc/library/email.contentmanager.rst304
-rw-r--r--Doc/library/email.encoders.rst6
-rw-r--r--Doc/library/email.errors.rst38
-rw-r--r--Doc/library/email.examples.rst (renamed from Doc/library/email-examples.rst)33
-rw-r--r--Doc/library/email.generator.rst376
-rw-r--r--Doc/library/email.header.rst8
-rw-r--r--Doc/library/email.headerregistry.rst49
-rw-r--r--Doc/library/email.message.rst719
-rw-r--r--Doc/library/email.mime.rst58
-rw-r--r--Doc/library/email.parser.rst358
-rw-r--r--Doc/library/email.policy.rst280
-rw-r--r--Doc/library/email.rst464
-rw-r--r--Doc/library/email.util.rst68
-rw-r--r--Doc/library/enum.rst394
-rw-r--r--Doc/library/exceptions.rst38
-rw-r--r--Doc/library/faulthandler.rst3
-rw-r--r--Doc/library/fileinput.rst19
-rw-r--r--Doc/library/ftplib.rst7
-rw-r--r--Doc/library/functions.rst68
-rw-r--r--Doc/library/glob.rst2
-rw-r--r--Doc/library/grp.rst3
-rw-r--r--Doc/library/gzip.rst5
-rw-r--r--Doc/library/hashlib-blake2-tree.pngbin0 -> 11148 bytes-rw-r--r--Doc/library/hashlib-blake2.rst444
-rw-r--r--Doc/library/hashlib.rst79
-rw-r--r--Doc/library/http.client.rst115
-rw-r--r--Doc/library/http.server.rst14
-rw-r--r--Doc/library/imaplib.rst19
-rw-r--r--Doc/library/imghdr.rst3
-rw-r--r--Doc/library/imp.rst15
-rw-r--r--Doc/library/importlib.rst195
-rw-r--r--Doc/library/inspect.rst57
-rw-r--r--Doc/library/itertools.rst8
-rw-r--r--Doc/library/json.rst29
-rw-r--r--Doc/library/logging.handlers.rst89
-rw-r--r--Doc/library/lzma.rst18
-rw-r--r--Doc/library/math.rst9
-rw-r--r--Doc/library/mmap.rst9
-rw-r--r--Doc/library/multiprocessing.rst97
-rw-r--r--Doc/library/os.path.rst87
-rw-r--r--Doc/library/os.rst372
-rw-r--r--Doc/library/pathlib.rst25
-rw-r--r--Doc/library/pdb.rst8
-rw-r--r--Doc/library/pickle.rst19
-rw-r--r--Doc/library/pkgutil.rst9
-rw-r--r--Doc/library/poplib.rst7
-rw-r--r--Doc/library/queue.rst11
-rw-r--r--Doc/library/random.rst72
-rw-r--r--Doc/library/re.rst57
-rw-r--r--Doc/library/readline.rst14
-rw-r--r--Doc/library/secrets.rst198
-rw-r--r--Doc/library/select.rst69
-rw-r--r--Doc/library/shlex.rst111
-rw-r--r--Doc/library/shutil.rst2
-rw-r--r--Doc/library/site.rst3
-rw-r--r--Doc/library/smtpd.rst50
-rw-r--r--Doc/library/smtplib.rst8
-rw-r--r--Doc/library/socket.rst76
-rw-r--r--Doc/library/socketserver.rst68
-rw-r--r--Doc/library/spwd.rst3
-rw-r--r--Doc/library/sqlite3.rst20
-rw-r--r--Doc/library/ssl.rst275
-rw-r--r--Doc/library/statistics.rst33
-rw-r--r--Doc/library/stdtypes.rst27
-rw-r--r--Doc/library/string.rst23
-rw-r--r--Doc/library/struct.rst23
-rw-r--r--Doc/library/subprocess.rst107
-rw-r--r--Doc/library/sys.rst97
-rw-r--r--Doc/library/sysconfig.rst2
-rw-r--r--Doc/library/telnetlib.rst11
-rw-r--r--Doc/library/test.rst42
-rw-r--r--Doc/library/time.rst12
-rw-r--r--Doc/library/timeit.rst21
-rw-r--r--Doc/library/tkinter.tix.rst4
-rw-r--r--Doc/library/traceback.rst14
-rw-r--r--Doc/library/tracemalloc.rst45
-rw-r--r--Doc/library/types.rst6
-rw-r--r--Doc/library/typing.rst28
-rw-r--r--Doc/library/undoc.rst2
-rw-r--r--Doc/library/unicodedata.rst8
-rw-r--r--Doc/library/unittest.mock.rst40
-rw-r--r--Doc/library/unittest.rst6
-rw-r--r--Doc/library/urllib.parse.rst18
-rw-r--r--Doc/library/urllib.request.rst65
-rw-r--r--Doc/library/urllib.robotparser.rst30
-rw-r--r--Doc/library/venv.rst134
-rw-r--r--Doc/library/warnings.rst16
-rw-r--r--Doc/library/winreg.rst14
-rw-r--r--Doc/library/winsound.rst8
-rw-r--r--Doc/library/wsgiref.rst32
-rw-r--r--Doc/library/xmlrpc.client.rst17
-rw-r--r--Doc/library/xmlrpc.server.rst59
-rw-r--r--Doc/library/zipfile.rst130
-rw-r--r--Doc/library/zlib.rst31
-rw-r--r--Doc/make.bat2
-rw-r--r--Doc/reference/compound_stmts.rst24
-rw-r--r--Doc/reference/datamodel.rst122
-rw-r--r--Doc/reference/import.rst37
-rw-r--r--Doc/reference/lexical_analysis.rst158
-rw-r--r--Doc/reference/simple_stmts.rst52
-rw-r--r--Doc/tools/extensions/pyspecific.py2
-rwxr-xr-xDoc/tools/rstlint.py2
-rw-r--r--Doc/tools/susp-ignored.csv61
-rw-r--r--Doc/tutorial/controlflow.rst3
-rw-r--r--Doc/tutorial/inputoutput.rst3
-rw-r--r--Doc/tutorial/interpreter.rst12
-rw-r--r--Doc/tutorial/introduction.rst3
-rw-r--r--Doc/tutorial/stdlib.rst2
-rw-r--r--Doc/tutorial/stdlib2.rst2
-rw-r--r--Doc/tutorial/venv.rst111
-rw-r--r--Doc/using/cmdline.rst90
-rw-r--r--Doc/using/index.rst1
-rw-r--r--Doc/using/mac.rst6
-rw-r--r--Doc/using/scripts.rst12
-rw-r--r--Doc/using/venv-create.inc95
-rw-r--r--Doc/using/windows.rst135
-rw-r--r--Doc/whatsnew/2.1.rst2
-rw-r--r--Doc/whatsnew/3.2.rst4
-rw-r--r--Doc/whatsnew/3.3.rst2
-rw-r--r--Doc/whatsnew/3.4.rst10
-rw-r--r--Doc/whatsnew/3.5.rst6
-rw-r--r--Doc/whatsnew/3.6.rst1476
-rw-r--r--Doc/whatsnew/index.rst1
-rw-r--r--Grammar/Grammar24
-rw-r--r--Include/Python-ast.h56
-rw-r--r--Include/Python.h1
-rw-r--r--Include/abstract.h94
-rw-r--r--Include/asdl.h1
-rw-r--r--Include/bytes_methods.h27
-rw-r--r--Include/bytesobject.h90
-rw-r--r--Include/ceval.h23
-rw-r--r--Include/code.h27
-rw-r--r--Include/datetime.h17
-rw-r--r--Include/descrobject.h2
-rw-r--r--Include/dictobject.h25
-rw-r--r--Include/fileobject.h1
-rw-r--r--Include/fileutils.h20
-rw-r--r--Include/floatobject.h10
-rw-r--r--Include/funcobject.h14
-rw-r--r--Include/genobject.h31
-rw-r--r--Include/graminit.h137
-rw-r--r--Include/grammar.h1
-rw-r--r--Include/import.h2
-rw-r--r--Include/intrcheck.h3
-rw-r--r--Include/longintrepr.h12
-rw-r--r--Include/longobject.h26
-rw-r--r--Include/methodobject.h16
-rw-r--r--Include/modsupport.h30
-rw-r--r--Include/namespaceobject.h2
-rw-r--r--Include/object.h20
-rw-r--r--Include/objimpl.h7
-rw-r--r--Include/opcode.h10
-rw-r--r--Include/osmodule.h15
-rw-r--r--Include/patchlevel.h10
-rw-r--r--Include/pgenheaders.h1
-rw-r--r--Include/py_curses.h4
-rw-r--r--Include/pyatomic.h4
-rw-r--r--Include/pydebug.h4
-rw-r--r--Include/pydtrace.d19
-rw-r--r--Include/pydtrace.h53
-rw-r--r--Include/pyerrors.h15
-rw-r--r--Include/pygetopt.h2
-rw-r--r--Include/pyhash.h16
-rw-r--r--Include/pylifecycle.h7
-rw-r--r--Include/pymacro.h15
-rw-r--r--Include/pymath.h8
-rw-r--r--Include/pymem.h43
-rw-r--r--Include/pyport.h189
-rw-r--r--Include/pystate.h49
-rw-r--r--Include/pystrhex.h2
-rw-r--r--Include/pystrtod.h4
-rw-r--r--Include/pythonrun.h8
-rw-r--r--Include/pythread.h11
-rw-r--r--Include/pytime.h21
-rw-r--r--Include/setobject.h11
-rw-r--r--Include/structmember.h2
-rw-r--r--Include/symtable.h2
-rw-r--r--Include/sysmodule.h4
-rw-r--r--Include/traceback.h52
-rw-r--r--Include/unicodeobject.h63
-rw-r--r--Include/warnings.h7
-rw-r--r--Lib/_collections_abc.py111
-rw-r--r--Lib/_compat_pickle.py7
-rw-r--r--Lib/_osx_support.py10
-rw-r--r--Lib/_pydecimal.py62
-rw-r--r--Lib/_pyio.py9
-rw-r--r--Lib/_strptime.py83
-rw-r--r--Lib/aifc.py9
-rw-r--r--Lib/argparse.py10
-rw-r--r--Lib/ast.py52
-rw-r--r--Lib/asynchat.py29
-rw-r--r--Lib/asyncio/base_events.py6
-rw-r--r--Lib/asyncio/base_subprocess.py3
-rw-r--r--Lib/asyncio/futures.py95
-rw-r--r--Lib/asyncio/proactor_events.py3
-rw-r--r--Lib/asyncio/selector_events.py3
-rw-r--r--Lib/asyncio/sslproto.py3
-rw-r--r--Lib/asyncio/test_utils.py8
-rw-r--r--Lib/asyncio/unix_events.py6
-rw-r--r--Lib/asyncio/windows_events.py9
-rw-r--r--Lib/asyncio/windows_utils.py3
-rw-r--r--Lib/asyncore.py5
-rwxr-xr-xLib/base64.py5
-rw-r--r--Lib/bz2.py16
-rw-r--r--Lib/calendar.py85
-rwxr-xr-xLib/cgi.py2
-rw-r--r--Lib/code.py16
-rw-r--r--Lib/collections/__init__.py22
-rw-r--r--Lib/collections/__main__.py38
-rw-r--r--Lib/compileall.py20
-rw-r--r--Lib/concurrent/futures/thread.py11
-rw-r--r--Lib/contextlib.py42
-rw-r--r--Lib/copy.py115
-rw-r--r--Lib/crypt.py3
-rw-r--r--Lib/csv.py24
-rw-r--r--Lib/ctypes/__init__.py17
-rw-r--r--Lib/ctypes/test/test_bitfields.py5
-rw-r--r--Lib/ctypes/test/test_find.py43
-rw-r--r--Lib/ctypes/test/test_funcptr.py4
-rw-r--r--Lib/ctypes/test/test_loading.py17
-rw-r--r--Lib/ctypes/test/test_objects.py2
-rw-r--r--Lib/ctypes/test/test_parameters.py8
-rw-r--r--Lib/ctypes/test/test_pep3118.py2
-rw-r--r--Lib/ctypes/test/test_returnfuncptrs.py1
-rw-r--r--Lib/ctypes/test/test_sizes.py1
-rw-r--r--Lib/ctypes/test/test_structures.py7
-rw-r--r--Lib/ctypes/test/test_values.py6
-rw-r--r--Lib/ctypes/util.py40
-rw-r--r--Lib/datetime.py316
-rw-r--r--Lib/dbm/dumb.py18
-rw-r--r--Lib/difflib.py2
-rw-r--r--Lib/dis.py61
-rw-r--r--Lib/distutils/archive_util.py2
-rw-r--r--Lib/distutils/cmd.py5
-rw-r--r--Lib/distutils/command/bdist_dumb.py2
-rw-r--r--Lib/distutils/command/bdist_msi.py6
-rw-r--r--Lib/distutils/command/bdist_wininst.py2
-rw-r--r--Lib/distutils/command/build.py4
-rw-r--r--Lib/distutils/command/build_ext.py6
-rw-r--r--Lib/distutils/command/build_scripts.py2
-rw-r--r--Lib/distutils/command/config.py4
-rw-r--r--Lib/distutils/command/install.py12
-rw-r--r--Lib/distutils/command/install_egg_info.py4
-rw-r--r--Lib/distutils/command/register.py8
-rw-r--r--Lib/distutils/command/sdist.py15
-rw-r--r--Lib/distutils/core.py5
-rw-r--r--Lib/distutils/cygwinccompiler.py2
-rw-r--r--Lib/distutils/dist.py3
-rw-r--r--Lib/distutils/extension.py1
-rw-r--r--Lib/distutils/filelist.py15
-rw-r--r--Lib/distutils/msvc9compiler.py2
-rw-r--r--Lib/distutils/sysconfig.py48
-rw-r--r--Lib/distutils/tests/test_bdist_rpm.py4
-rw-r--r--Lib/distutils/tests/test_build.py5
-rw-r--r--Lib/distutils/tests/test_build_ext.py1
-rw-r--r--Lib/distutils/tests/test_build_py.py3
-rw-r--r--Lib/distutils/tests/test_clean.py2
-rw-r--r--Lib/distutils/tests/test_config.py2
-rw-r--r--Lib/distutils/tests/test_core.py30
-rw-r--r--Lib/distutils/tests/test_cygwinccompiler.py3
-rw-r--r--Lib/distutils/tests/test_dep_util.py1
-rw-r--r--Lib/distutils/tests/test_file_util.py1
-rw-r--r--Lib/distutils/tests/test_filelist.py14
-rw-r--r--Lib/distutils/tests/test_install_data.py2
-rw-r--r--Lib/distutils/tests/test_install_headers.py2
-rw-r--r--Lib/distutils/tests/test_install_lib.py3
-rw-r--r--Lib/distutils/tests/test_spawn.py14
-rw-r--r--Lib/distutils/tests/test_unixccompiler.py1
-rw-r--r--Lib/distutils/text_file.py2
-rw-r--r--Lib/distutils/util.py15
-rw-r--r--Lib/distutils/versionpredicate.py2
-rw-r--r--Lib/doctest.py25
-rw-r--r--Lib/email/_header_value_parser.py16
-rw-r--r--Lib/email/_policybase.py4
-rw-r--r--Lib/email/contentmanager.py6
-rw-r--r--Lib/email/feedparser.py19
-rw-r--r--Lib/email/generator.py6
-rw-r--r--Lib/email/header.py4
-rw-r--r--Lib/email/message.py25
-rw-r--r--Lib/email/mime/application.py5
-rw-r--r--Lib/email/mime/audio.py5
-rw-r--r--Lib/email/mime/base.py8
-rw-r--r--Lib/email/mime/image.py5
-rw-r--r--Lib/email/mime/message.py4
-rw-r--r--Lib/email/mime/multipart.py3
-rw-r--r--Lib/email/mime/text.py4
-rw-r--r--Lib/email/policy.py2
-rw-r--r--Lib/encodings/__init__.py17
-rw-r--r--Lib/encodings/aliases.py1
-rw-r--r--Lib/encodings/oem.py41
-rw-r--r--Lib/enum.py324
-rw-r--r--Lib/fileinput.py14
-rw-r--r--Lib/fnmatch.py2
-rw-r--r--Lib/fractions.py34
-rw-r--r--Lib/ftplib.py11
-rw-r--r--Lib/functools.py92
-rw-r--r--Lib/genericpath.py6
-rw-r--r--Lib/glob.py70
-rw-r--r--Lib/gzip.py8
-rw-r--r--Lib/hashlib.py54
-rw-r--r--Lib/hmac.py2
-rw-r--r--Lib/html/parser.py4
-rw-r--r--Lib/http/client.py241
-rw-r--r--Lib/http/cookiejar.py6
-rw-r--r--Lib/http/cookies.py5
-rw-r--r--Lib/http/server.py66
-rw-r--r--Lib/idlelib/NEWS.txt96
-rw-r--r--Lib/idlelib/README.txt287
-rw-r--r--Lib/idlelib/__init__.py2
-rw-r--r--Lib/idlelib/__main__.py4
-rw-r--r--Lib/idlelib/autocomplete.py (renamed from Lib/idlelib/AutoComplete.py)67
-rw-r--r--Lib/idlelib/autocomplete_w.py (renamed from Lib/idlelib/AutoCompleteWindow.py)41
-rw-r--r--Lib/idlelib/autoexpand.py (renamed from Lib/idlelib/AutoExpand.py)7
-rw-r--r--Lib/idlelib/browser.py (renamed from Lib/idlelib/ClassBrowser.py)18
-rw-r--r--Lib/idlelib/calltip_w.py (renamed from Lib/idlelib/CallTipWindow.py)8
-rw-r--r--Lib/idlelib/calltips.py (renamed from Lib/idlelib/CallTips.py)12
-rw-r--r--Lib/idlelib/codecontext.py (renamed from Lib/idlelib/CodeContext.py)12
-rw-r--r--Lib/idlelib/colorizer.py (renamed from Lib/idlelib/ColorDelegator.py)29
-rw-r--r--Lib/idlelib/config-keys.def51
-rw-r--r--Lib/idlelib/config-main.def4
-rw-r--r--Lib/idlelib/config.py (renamed from Lib/idlelib/configHandler.py)160
-rw-r--r--Lib/idlelib/configHelpSourceEdit.py170
-rw-r--r--Lib/idlelib/configSectionNameDialog.py98
-rw-r--r--Lib/idlelib/config_key.py (renamed from Lib/idlelib/keybindingDialog.py)21
-rw-r--r--Lib/idlelib/configdialog.py (renamed from Lib/idlelib/configDialog.py)131
-rw-r--r--Lib/idlelib/debugger.py (renamed from Lib/idlelib/Debugger.py)21
-rw-r--r--Lib/idlelib/debugger_r.py (renamed from Lib/idlelib/RemoteDebugger.py)8
-rw-r--r--Lib/idlelib/debugobj.py (renamed from Lib/idlelib/ObjectBrowser.py)26
-rw-r--r--Lib/idlelib/debugobj_r.py (renamed from Lib/idlelib/RemoteObjectBrowser.py)0
-rw-r--r--Lib/idlelib/delegator.py (renamed from Lib/idlelib/Delegator.py)0
-rw-r--r--Lib/idlelib/dynoption.py (renamed from Lib/idlelib/dynOptionMenuWidget.py)9
-rw-r--r--Lib/idlelib/editor.py (renamed from Lib/idlelib/EditorWindow.py)276
-rw-r--r--Lib/idlelib/filelist.py (renamed from Lib/idlelib/FileList.py)5
-rw-r--r--Lib/idlelib/grep.py (renamed from Lib/idlelib/GrepDialog.py)48
-rw-r--r--Lib/idlelib/help.py26
-rw-r--r--Lib/idlelib/help.txt372
-rw-r--r--Lib/idlelib/help_about.py (renamed from Lib/idlelib/aboutDialog.py)13
-rw-r--r--Lib/idlelib/history.py (renamed from Lib/idlelib/IdleHistory.py)8
-rw-r--r--Lib/idlelib/hyperparser.py (renamed from Lib/idlelib/HyperParser.py)7
-rw-r--r--Lib/idlelib/idle.py3
-rw-r--r--Lib/idlelib/idle.pyw12
-rw-r--r--Lib/idlelib/idle_test/__init__.py2
-rw-r--r--Lib/idlelib/idle_test/htest.py145
-rw-r--r--Lib/idlelib/idle_test/mock_idle.py4
-rw-r--r--Lib/idlelib/idle_test/test_autocomplete.py13
-rw-r--r--Lib/idlelib/idle_test/test_autoexpand.py6
-rw-r--r--Lib/idlelib/idle_test/test_calltips.py2
-rw-r--r--Lib/idlelib/idle_test/test_colorizer.py56
-rw-r--r--Lib/idlelib/idle_test/test_config.py160
-rw-r--r--Lib/idlelib/idle_test/test_config_help.py106
-rw-r--r--Lib/idlelib/idle_test/test_config_key.py33
-rw-r--r--Lib/idlelib/idle_test/test_config_name.py75
-rw-r--r--Lib/idlelib/idle_test/test_configdialog.py8
-rw-r--r--Lib/idlelib/idle_test/test_debugger.py29
-rw-r--r--Lib/idlelib/idle_test/test_delegator.py2
-rw-r--r--Lib/idlelib/idle_test/test_editmenu.py30
-rw-r--r--Lib/idlelib/idle_test/test_editor.py2
-rw-r--r--Lib/idlelib/idle_test/test_grep.py6
-rw-r--r--Lib/idlelib/idle_test/test_help.py34
-rw-r--r--Lib/idlelib/idle_test/test_help_about.py24
-rw-r--r--Lib/idlelib/idle_test/test_history.py (renamed from Lib/idlelib/idle_test/test_idlehistory.py)4
-rw-r--r--Lib/idlelib/idle_test/test_hyperparser.py6
-rw-r--r--Lib/idlelib/idle_test/test_iomenu.py (renamed from Lib/idlelib/idle_test/test_io.py)5
-rw-r--r--Lib/idlelib/idle_test/test_macosx.py103
-rw-r--r--Lib/idlelib/idle_test/test_paragraph.py (renamed from Lib/idlelib/idle_test/test_formatparagraph.py)8
-rw-r--r--Lib/idlelib/idle_test/test_parenmatch.py17
-rw-r--r--Lib/idlelib/idle_test/test_pathbrowser.py8
-rw-r--r--Lib/idlelib/idle_test/test_percolator.py4
-rw-r--r--Lib/idlelib/idle_test/test_query.py353
-rw-r--r--Lib/idlelib/idle_test/test_redirector.py (renamed from Lib/idlelib/idle_test/test_widgetredir.py)5
-rw-r--r--Lib/idlelib/idle_test/test_replace.py (renamed from Lib/idlelib/idle_test/test_replacedialog.py)16
-rw-r--r--Lib/idlelib/idle_test/test_rstrip.py4
-rw-r--r--Lib/idlelib/idle_test/test_scrolledlist.py29
-rw-r--r--Lib/idlelib/idle_test/test_search.py (renamed from Lib/idlelib/idle_test/test_searchdialog.py)8
-rw-r--r--Lib/idlelib/idle_test/test_searchbase.py (renamed from Lib/idlelib/idle_test/test_searchdialogbase.py)27
-rw-r--r--Lib/idlelib/idle_test/test_searchengine.py16
-rw-r--r--Lib/idlelib/idle_test/test_text.py21
-rw-r--r--Lib/idlelib/idle_test/test_textview.py20
-rw-r--r--Lib/idlelib/idle_test/test_tree.py36
-rw-r--r--Lib/idlelib/idle_test/test_undo.py (renamed from Lib/idlelib/idle_test/test_undodelegator.py)8
-rw-r--r--Lib/idlelib/idle_test/test_warning.py6
-rw-r--r--Lib/idlelib/idlever.py12
-rw-r--r--Lib/idlelib/iomenu.py (renamed from Lib/idlelib/IOBinding.py)95
-rw-r--r--Lib/idlelib/macosx.py (renamed from Lib/idlelib/macosxSupport.py)99
-rw-r--r--Lib/idlelib/mainmenu.py (renamed from Lib/idlelib/Bindings.py)4
-rw-r--r--Lib/idlelib/multicall.py (renamed from Lib/idlelib/MultiCall.py)17
-rw-r--r--Lib/idlelib/outwin.py (renamed from Lib/idlelib/OutputWindow.py)11
-rw-r--r--Lib/idlelib/paragraph.py (renamed from Lib/idlelib/FormatParagraph.py)10
-rw-r--r--Lib/idlelib/parenmatch.py (renamed from Lib/idlelib/ParenMatch.py)14
-rw-r--r--Lib/idlelib/pathbrowser.py (renamed from Lib/idlelib/PathBrowser.py)11
-rw-r--r--Lib/idlelib/percolator.py (renamed from Lib/idlelib/Percolator.py)13
-rw-r--r--Lib/idlelib/pyparse.py (renamed from Lib/idlelib/PyParse.py)2
-rwxr-xr-xLib/idlelib/pyshell.py (renamed from Lib/idlelib/PyShell.py)220
-rw-r--r--Lib/idlelib/query.py308
-rw-r--r--Lib/idlelib/redirector.py (renamed from Lib/idlelib/WidgetRedirector.py)21
-rw-r--r--Lib/idlelib/replace.py (renamed from Lib/idlelib/ReplaceDialog.py)26
-rw-r--r--Lib/idlelib/rpc.py26
-rw-r--r--Lib/idlelib/rstrip.py (renamed from Lib/idlelib/RstripExtension.py)0
-rw-r--r--Lib/idlelib/run.py159
-rw-r--r--Lib/idlelib/runscript.py (renamed from Lib/idlelib/ScriptBinding.py)17
-rw-r--r--Lib/idlelib/scrolledlist.py (renamed from Lib/idlelib/ScrolledList.py)21
-rw-r--r--Lib/idlelib/search.py (renamed from Lib/idlelib/SearchDialog.py)29
-rw-r--r--Lib/idlelib/searchbase.py (renamed from Lib/idlelib/SearchDialogBase.py)40
-rw-r--r--Lib/idlelib/searchengine.py (renamed from Lib/idlelib/SearchEngine.py)5
-rw-r--r--Lib/idlelib/stackviewer.py (renamed from Lib/idlelib/StackViewer.py)30
-rw-r--r--Lib/idlelib/statusbar.py (renamed from Lib/idlelib/MultiStatusBar.py)35
-rw-r--r--Lib/idlelib/tabbedpages.py26
-rw-r--r--Lib/idlelib/textview.py (renamed from Lib/idlelib/textView.py)34
-rw-r--r--Lib/idlelib/tooltip.py (renamed from Lib/idlelib/ToolTip.py)19
-rw-r--r--Lib/idlelib/tree.py (renamed from Lib/idlelib/TreeWidget.py)23
-rw-r--r--Lib/idlelib/undo.py (renamed from Lib/idlelib/UndoDelegator.py)26
-rw-r--r--Lib/idlelib/windows.py (renamed from Lib/idlelib/WindowList.py)2
-rw-r--r--Lib/idlelib/zoomheight.py (renamed from Lib/idlelib/ZoomHeight.py)6
-rw-r--r--Lib/imaplib.py19
-rw-r--r--Lib/imghdr.py4
-rw-r--r--Lib/imp.py2
-rw-r--r--Lib/importlib/_bootstrap.py70
-rw-r--r--Lib/importlib/_bootstrap_external.py99
-rw-r--r--Lib/importlib/util.py28
-rw-r--r--Lib/inspect.py45
-rw-r--r--Lib/io.py7
-rw-r--r--Lib/ipaddress.py4
-rw-r--r--Lib/json/__init__.py58
-rw-r--r--Lib/json/decoder.py2
-rw-r--r--Lib/json/encoder.py5
-rw-r--r--Lib/lib2to3/Grammar.txt7
-rw-r--r--Lib/lib2to3/fixer_util.py2
-rw-r--r--Lib/lib2to3/fixes/fix_dict.py3
-rw-r--r--Lib/lib2to3/fixes/fix_exec.py1
-rw-r--r--Lib/lib2to3/fixes/fix_filter.py1
-rw-r--r--Lib/lib2to3/fixes/fix_has_key.py1
-rw-r--r--Lib/lib2to3/fixes/fix_metaclass.py2
-rw-r--r--Lib/lib2to3/fixes/fix_nonzero.py2
-rw-r--r--Lib/lib2to3/fixes/fix_print.py2
-rw-r--r--Lib/lib2to3/fixes/fix_types.py3
-rw-r--r--Lib/lib2to3/fixes/fix_urllib.py1
-rw-r--r--Lib/lib2to3/refactor.py3
-rw-r--r--Lib/lib2to3/tests/data/py3_test_grammar.py2
-rw-r--r--Lib/lib2to3/tests/support.py2
-rw-r--r--Lib/lib2to3/tests/test_all_fixers.py1
-rw-r--r--Lib/lib2to3/tests/test_fixers.py7
-rw-r--r--Lib/lib2to3/tests/test_parser.py50
-rw-r--r--Lib/lib2to3/tests/test_pytree.py5
-rw-r--r--Lib/lib2to3/tests/test_refactor.py6
-rw-r--r--Lib/lib2to3/tests/test_util.py3
-rw-r--r--Lib/locale.py8
-rw-r--r--Lib/logging/__init__.py35
-rw-r--r--Lib/logging/handlers.py34
-rw-r--r--Lib/lzma.py18
-rw-r--r--Lib/mailbox.py7
-rw-r--r--Lib/mimetypes.py6
-rw-r--r--Lib/modulefinder.py7
-rw-r--r--Lib/msilib/__init__.py12
-rw-r--r--Lib/multiprocessing/connection.py8
-rw-r--r--Lib/multiprocessing/context.py13
-rw-r--r--Lib/multiprocessing/forkserver.py2
-rw-r--r--Lib/multiprocessing/heap.py5
-rw-r--r--Lib/multiprocessing/managers.py100
-rw-r--r--Lib/multiprocessing/pool.py20
-rw-r--r--Lib/multiprocessing/popen_forkserver.py7
-rw-r--r--Lib/multiprocessing/popen_spawn_posix.py7
-rw-r--r--Lib/multiprocessing/popen_spawn_win32.py9
-rw-r--r--Lib/multiprocessing/queues.py10
-rw-r--r--Lib/multiprocessing/reduction.py34
-rw-r--r--Lib/multiprocessing/resource_sharer.py2
-rw-r--r--Lib/multiprocessing/sharedctypes.py6
-rw-r--r--Lib/multiprocessing/spawn.py9
-rw-r--r--Lib/ntpath.py20
-rw-r--r--Lib/opcode.py32
-rw-r--r--Lib/optparse.py3
-rw-r--r--Lib/os.py251
-rw-r--r--Lib/pathlib.py116
-rwxr-xr-xLib/pdb.py22
-rw-r--r--Lib/pickle.py105
-rw-r--r--Lib/pickletools.py3
-rw-r--r--Lib/pkgutil.py31
-rw-r--r--Lib/plat-aix4/IN.py165
-rwxr-xr-xLib/plat-aix4/regen8
-rw-r--r--Lib/plat-darwin/IN.py662
-rwxr-xr-xLib/plat-darwin/regen3
-rw-r--r--Lib/plat-freebsd4/IN.py355
-rwxr-xr-xLib/plat-freebsd4/regen3
-rw-r--r--Lib/plat-freebsd5/IN.py355
-rwxr-xr-xLib/plat-freebsd5/regen3
-rw-r--r--Lib/plat-freebsd6/IN.py551
-rwxr-xr-xLib/plat-freebsd6/regen3
-rw-r--r--Lib/plat-freebsd7/IN.py571
-rwxr-xr-xLib/plat-freebsd7/regen3
-rw-r--r--Lib/plat-freebsd8/IN.py571
-rwxr-xr-xLib/plat-freebsd8/regen3
-rwxr-xr-xLib/plat-generic/regen3
-rw-r--r--Lib/plat-linux/CDROM.py207
-rw-r--r--Lib/plat-linux/DLFCN.py83
-rw-r--r--Lib/plat-linux/IN.py615
-rw-r--r--Lib/plat-linux/TYPES.py170
-rwxr-xr-xLib/plat-linux/regen8
-rw-r--r--Lib/plat-netbsd1/IN.py56
-rwxr-xr-xLib/plat-netbsd1/regen3
-rwxr-xr-xLib/plat-next3/regen6
-rw-r--r--Lib/plat-sunos5/CDIO.py73
-rw-r--r--Lib/plat-sunos5/DLFCN.py27
-rw-r--r--Lib/plat-sunos5/IN.py1421
-rw-r--r--Lib/plat-sunos5/STROPTS.py1813
-rw-r--r--Lib/plat-sunos5/TYPES.py313
-rwxr-xr-xLib/plat-sunos5/regen9
-rw-r--r--Lib/plat-unixware7/IN.py836
-rw-r--r--Lib/plat-unixware7/STROPTS.py328
-rwxr-xr-xLib/plat-unixware7/regen9
-rwxr-xr-xLib/platform.py37
-rw-r--r--Lib/plistlib.py2
-rw-r--r--Lib/poplib.py4
-rw-r--r--Lib/posixpath.py19
-rw-r--r--Lib/pyclbr.py3
-rw-r--r--[-rwxr-xr-x]Lib/pydoc.py36
-rw-r--r--Lib/pydoc_data/topics.py13026
-rw-r--r--Lib/random.py52
-rw-r--r--Lib/re.py51
-rw-r--r--Lib/rlcompleter.py38
-rw-r--r--Lib/sched.py11
-rw-r--r--Lib/secrets.py71
-rw-r--r--Lib/shlex.py72
-rw-r--r--Lib/shutil.py3
-rw-r--r--Lib/site-packages/README.txt2
-rw-r--r--Lib/site.py80
-rwxr-xr-xLib/smtpd.py42
-rwxr-xr-xLib/smtplib.py8
-rw-r--r--Lib/sndhdr.py12
-rw-r--r--Lib/socket.py12
-rw-r--r--Lib/socketserver.py210
-rw-r--r--Lib/sqlite3/test/dbapi.py43
-rw-r--r--Lib/sqlite3/test/transactions.py36
-rw-r--r--Lib/sre_compile.py140
-rw-r--r--Lib/sre_parse.py177
-rw-r--r--Lib/ssl.py179
-rw-r--r--Lib/statistics.py151
-rw-r--r--Lib/string.py11
-rw-r--r--Lib/subprocess.py136
-rwxr-xr-xLib/symbol.py137
-rw-r--r--Lib/symtable.py5
-rw-r--r--Lib/sysconfig.py28
-rwxr-xr-xLib/tarfile.py108
-rw-r--r--Lib/telnetlib.py15
-rw-r--r--Lib/tempfile.py1
-rw-r--r--Lib/test/__main__.py5
-rw-r--r--Lib/test/_test_multiprocessing.py96
-rw-r--r--Lib/test/ann_module.py53
-rw-r--r--Lib/test/ann_module2.py36
-rw-r--r--Lib/test/ann_module3.py18
-rw-r--r--Lib/test/audiotests.py3
-rw-r--r--Lib/test/autotest.py5
-rw-r--r--Lib/test/badsyntax_async1.py2
-rw-r--r--Lib/test/badsyntax_async2.py2
-rw-r--r--Lib/test/badsyntax_async3.py2
-rw-r--r--Lib/test/badsyntax_async4.py2
-rw-r--r--Lib/test/badsyntax_async5.py2
-rw-r--r--Lib/test/badsyntax_async6.py2
-rw-r--r--Lib/test/badsyntax_async7.py2
-rw-r--r--Lib/test/badsyntax_async8.py2
-rw-r--r--Lib/test/capath/0e4015b9.016
-rw-r--r--Lib/test/capath/b1930218.021
-rw-r--r--Lib/test/capath/ce7b8643.016
-rw-r--r--Lib/test/capath/ceff1710.021
-rw-r--r--Lib/test/cmath_testcases.txt141
-rw-r--r--Lib/test/datetimetester.py893
-rw-r--r--Lib/test/dtracedata/assert_usable.d5
-rw-r--r--Lib/test/dtracedata/assert_usable.stp5
-rw-r--r--Lib/test/dtracedata/call_stack.d31
-rw-r--r--Lib/test/dtracedata/call_stack.d.expected18
-rw-r--r--Lib/test/dtracedata/call_stack.py30
-rw-r--r--Lib/test/dtracedata/call_stack.stp41
-rw-r--r--Lib/test/dtracedata/call_stack.stp.expected14
-rw-r--r--Lib/test/dtracedata/gc.d18
-rw-r--r--Lib/test/dtracedata/gc.d.expected8
-rw-r--r--Lib/test/dtracedata/gc.py13
-rw-r--r--Lib/test/dtracedata/gc.stp26
-rw-r--r--Lib/test/dtracedata/gc.stp.expected8
-rw-r--r--Lib/test/dtracedata/instance.py24
-rw-r--r--Lib/test/dtracedata/line.d7
-rw-r--r--Lib/test/dtracedata/line.d.expected20
-rw-r--r--Lib/test/dtracedata/line.py17
-rw-r--r--Lib/test/eintrdata/eintr_tester.py13
-rw-r--r--Lib/test/exception_hierarchy.txt1
-rw-r--r--Lib/test/libregrtest/__init__.py5
-rw-r--r--Lib/test/libregrtest/cmdline.py347
-rw-r--r--Lib/test/libregrtest/main.py532
-rw-r--r--Lib/test/libregrtest/refleak.py202
-rw-r--r--Lib/test/libregrtest/runtest.py244
-rw-r--r--Lib/test/libregrtest/runtest_mp.py245
-rw-r--r--Lib/test/libregrtest/save_env.py285
-rw-r--r--Lib/test/libregrtest/setup.py121
-rw-r--r--Lib/test/list_tests.py14
-rw-r--r--Lib/test/lock_tests.py12
-rw-r--r--Lib/test/make_ssl_certs.py1
-rw-r--r--Lib/test/pickletester.py23
-rw-r--r--Lib/test/pydoc_mod.py2
-rwxr-xr-xLib/test/re_tests.py12
-rw-r--r--[-rwxr-xr-x]Lib/test/regrtest.py1597
-rw-r--r--Lib/test/seq_tests.py1
-rw-r--r--Lib/test/signalinterproctester.py84
-rw-r--r--Lib/test/sortperf.py2
-rw-r--r--Lib/test/support/__init__.py87
-rw-r--r--Lib/test/test___all__.py2
-rw-r--r--Lib/test/test__locale.py1
-rw-r--r--Lib/test/test__osx_support.py1
-rw-r--r--Lib/test/test_aifc.py1
-rw-r--r--Lib/test/test_argparse.py15
-rw-r--r--Lib/test/test_array.py23
-rw-r--r--Lib/test/test_ast.py177
-rw-r--r--Lib/test/test_asyncgen.py825
-rw-r--r--Lib/test/test_asynchat.py32
-rw-r--r--Lib/test/test_asyncio/test_futures.py13
-rw-r--r--Lib/test/test_asyncore.py3
-rw-r--r--Lib/test/test_augassign.py8
-rw-r--r--Lib/test/test_baseexception.py (renamed from Lib/test/test_pep352.py)1
-rw-r--r--Lib/test/test_bigmem.py1
-rw-r--r--Lib/test/test_binascii.py26
-rw-r--r--Lib/test/test_binhex.py1
-rw-r--r--Lib/test/test_binop.py50
-rw-r--r--Lib/test/test_bool.py18
-rw-r--r--Lib/test/test_buffer.py1
-rw-r--r--Lib/test/test_bufio.py2
-rw-r--r--Lib/test/test_builtin.py24
-rw-r--r--Lib/test/test_bytes.py230
-rw-r--r--Lib/test/test_bz2.py12
-rw-r--r--Lib/test/test_calendar.py17
-rw-r--r--Lib/test/test_capi.py120
-rw-r--r--Lib/test/test_cgi.py8
-rw-r--r--Lib/test/test_charmapcodec.py2
-rw-r--r--Lib/test/test_cmath.py37
-rw-r--r--Lib/test/test_cmd_line.py3
-rw-r--r--Lib/test/test_cmd_line_script.py7
-rw-r--r--Lib/test/test_code_module.py30
-rw-r--r--Lib/test/test_codeccallbacks.py5
-rw-r--r--Lib/test/test_codecencodings_cn.py1
-rw-r--r--Lib/test/test_codecencodings_hk.py1
-rw-r--r--Lib/test/test_codecencodings_iso2022.py1
-rw-r--r--Lib/test/test_codecencodings_jp.py1
-rw-r--r--Lib/test/test_codecencodings_kr.py1
-rw-r--r--Lib/test/test_codecencodings_tw.py1
-rw-r--r--Lib/test/test_codecmaps_cn.py1
-rw-r--r--Lib/test/test_codecmaps_hk.py1
-rw-r--r--Lib/test/test_codecmaps_jp.py1
-rw-r--r--Lib/test/test_codecmaps_kr.py1
-rw-r--r--Lib/test/test_codecmaps_tw.py1
-rw-r--r--Lib/test/test_codecs.py255
-rw-r--r--Lib/test/test_codeop.py1
-rw-r--r--Lib/test/test_collections.py215
-rw-r--r--Lib/test/test_compile.py17
-rw-r--r--Lib/test/test_compileall.py57
-rw-r--r--Lib/test/test_complex.py14
-rw-r--r--Lib/test/test_concurrent_futures.py24
-rw-r--r--Lib/test/test_configparser.py6
-rw-r--r--Lib/test/test_contains.py25
-rw-r--r--Lib/test/test_contextlib.py35
-rw-r--r--Lib/test/test_copy.py2
-rw-r--r--Lib/test/test_coroutines.py471
-rw-r--r--Lib/test/test_cprofile.py2
-rw-r--r--Lib/test/test_csv.py101
-rw-r--r--Lib/test/test_datetime.py10
-rw-r--r--Lib/test/test_dbm.py1
-rw-r--r--Lib/test/test_dbm_dumb.py27
-rw-r--r--Lib/test/test_dbm_gnu.py2
-rw-r--r--Lib/test/test_dbm_ndbm.py2
-rw-r--r--Lib/test/test_decimal.py43
-rw-r--r--Lib/test/test_deque.py79
-rw-r--r--Lib/test/test_descr.py15
-rw-r--r--Lib/test/test_descrtut.py1
-rw-r--r--Lib/test/test_devpoll.py3
-rw-r--r--Lib/test/test_dict.py91
-rw-r--r--Lib/test/test_dict_version.py186
-rw-r--r--Lib/test/test_dictcomps.py2
-rw-r--r--Lib/test/test_dictviews.py22
-rw-r--r--Lib/test/test_difflib.py12
-rw-r--r--Lib/test/test_difflib_expect.html12
-rw-r--r--Lib/test/test_dis.py589
-rw-r--r--Lib/test/test_doctest.py9
-rw-r--r--Lib/test/test_dtrace.py178
-rw-r--r--Lib/test/test_dynamic.py1
-rw-r--r--Lib/test/test_eintr.py12
-rw-r--r--Lib/test/test_email/__init__.py1
-rw-r--r--Lib/test/test_email/test__header_value_parser.py4
-rw-r--r--Lib/test/test_email/test_asian_codecs.py1
-rw-r--r--Lib/test/test_email/test_email.py44
-rw-r--r--Lib/test/test_email/test_generator.py2
-rw-r--r--Lib/test/test_email/test_headerregistry.py1
-rw-r--r--Lib/test/test_email/test_message.py20
-rw-r--r--Lib/test/test_email/test_parser.py91
-rw-r--r--Lib/test/test_email/test_policy.py42
-rw-r--r--Lib/test/test_enum.py771
-rw-r--r--Lib/test/test_enumerate.py9
-rw-r--r--Lib/test/test_epoll.py1
-rw-r--r--Lib/test/test_exception_hierarchy.py (renamed from Lib/test/test_pep3151.py)1
-rw-r--r--Lib/test/test_exceptions.py1
-rw-r--r--Lib/test/test_extcall.py5
-rw-r--r--Lib/test/test_faulthandler.py98
-rw-r--r--Lib/test/test_file.py4
-rw-r--r--Lib/test/test_fileinput.py36
-rw-r--r--Lib/test/test_float.py46
-rw-r--r--Lib/test/test_fnmatch.py16
-rw-r--r--Lib/test/test_format.py4
-rw-r--r--Lib/test/test_fractions.py15
-rw-r--r--Lib/test/test_fstring.py748
-rw-r--r--Lib/test/test_ftplib.py21
-rw-r--r--Lib/test/test_functools.py192
-rw-r--r--Lib/test/test_future.py2
-rw-r--r--Lib/test/test_gc.py2
-rw-r--r--Lib/test/test_gdb.py44
-rw-r--r--Lib/test/test_generator_stop.py (renamed from Lib/test/test_pep479.py)0
-rw-r--r--Lib/test/test_generators.py6
-rw-r--r--Lib/test/test_genericpath.py339
-rw-r--r--Lib/test/test_getargs2.py64
-rw-r--r--Lib/test/test_gettext.py7
-rw-r--r--Lib/test/test_grammar.py319
-rw-r--r--Lib/test/test_grp.py10
-rw-r--r--Lib/test/test_gzip.py26
-rw-r--r--Lib/test/test_hashlib.py428
-rw-r--r--Lib/test/test_heapq.py1
-rw-r--r--Lib/test/test_hmac.py1
-rw-r--r--Lib/test/test_htmlparser.py3
-rw-r--r--Lib/test/test_http_cookiejar.py6
-rw-r--r--Lib/test/test_httplib.py198
-rw-r--r--Lib/test/test_httpservers.py50
-rw-r--r--Lib/test/test_idle.py23
-rw-r--r--Lib/test/test_imaplib.py61
-rw-r--r--Lib/test/test_imghdr.py7
-rw-r--r--Lib/test/test_imp.py3
-rw-r--r--Lib/test/test_import/__init__.py12
-rw-r--r--Lib/test/test_importlib/extension/test_case_sensitivity.py3
-rw-r--r--Lib/test/test_importlib/extension/test_finder.py1
-rw-r--r--Lib/test/test_importlib/extension/test_path_hook.py2
-rw-r--r--Lib/test/test_importlib/frozen/test_loader.py2
-rw-r--r--Lib/test/test_importlib/import_/test___package__.py55
-rw-r--r--Lib/test/test_importlib/import_/test_api.py4
-rw-r--r--Lib/test/test_importlib/import_/test_fromlist.py10
-rw-r--r--Lib/test/test_importlib/import_/test_packages.py1
-rw-r--r--Lib/test/test_importlib/import_/test_path.py68
-rw-r--r--Lib/test/test_importlib/import_/test_relative_imports.py24
-rw-r--r--Lib/test/test_importlib/regrtest.py17
-rw-r--r--Lib/test/test_importlib/source/test_case_sensitivity.py1
-rw-r--r--Lib/test/test_importlib/source/test_file_loader.py9
-rw-r--r--Lib/test/test_importlib/source/test_path_hook.py11
-rw-r--r--Lib/test/test_importlib/source/test_source_encoding.py1
-rw-r--r--Lib/test/test_importlib/test_abc.py22
-rw-r--r--Lib/test/test_importlib/test_api.py31
-rw-r--r--Lib/test/test_importlib/test_lazy.py2
-rw-r--r--Lib/test/test_importlib/test_locks.py1
-rw-r--r--Lib/test/test_importlib/test_namespace_pkgs.py38
-rw-r--r--Lib/test/test_importlib/test_spec.py6
-rw-r--r--Lib/test/test_importlib/test_util.py27
-rw-r--r--Lib/test/test_importlib/test_windows.py2
-rw-r--r--Lib/test/test_inspect.py49
-rw-r--r--Lib/test/test_int.py26
-rw-r--r--Lib/test/test_io.py37
-rw-r--r--Lib/test/test_ipaddress.py11
-rw-r--r--Lib/test/test_iter.py12
-rw-r--r--Lib/test/test_iterlen.py1
-rw-r--r--Lib/test/test_itertools.py65
-rw-r--r--Lib/test/test_json/__init__.py1
-rw-r--r--Lib/test/test_json/test_decode.py4
-rw-r--r--Lib/test/test_json/test_fail.py1
-rw-r--r--Lib/test/test_json/test_unicode.py16
-rw-r--r--Lib/test/test_kqueue.py1
-rw-r--r--Lib/test/test_linecache.py75
-rw-r--r--Lib/test/test_list.py2
-rw-r--r--Lib/test/test_logging.py72
-rw-r--r--Lib/test/test_long.py76
-rw-r--r--Lib/test/test_lzma.py26
-rw-r--r--Lib/test/test_macpath.py2
-rw-r--r--Lib/test/test_mailbox.py13
-rw-r--r--Lib/test/test_mailcap.py3
-rw-r--r--Lib/test/test_marshal.py7
-rw-r--r--Lib/test/test_math.py310
-rw-r--r--Lib/test/test_mimetypes.py6
-rw-r--r--Lib/test/test_mmap.py7
-rw-r--r--Lib/test/test_msilib.py1
-rw-r--r--Lib/test/test_multibytecodec.py2
-rw-r--r--Lib/test/test_multiprocessing_fork.py6
-rw-r--r--Lib/test/test_multiprocessing_forkserver.py5
-rw-r--r--Lib/test/test_multiprocessing_main_handling.py6
-rw-r--r--Lib/test/test_multiprocessing_spawn.py5
-rw-r--r--Lib/test/test_nis.py1
-rw-r--r--Lib/test/test_nntplib.py6
-rw-r--r--Lib/test/test_normalization.py1
-rw-r--r--Lib/test/test_ntpath.py83
-rw-r--r--Lib/test/test_opcodes.py27
-rw-r--r--Lib/test/test_operator.py50
-rw-r--r--Lib/test/test_optparse.py7
-rw-r--r--Lib/test/test_ordered_dict.py59
-rw-r--r--Lib/test/test_os.py692
-rw-r--r--Lib/test/test_parser.py50
-rw-r--r--Lib/test/test_pathlib.py19
-rw-r--r--Lib/test/test_pdb.py70
-rw-r--r--Lib/test/test_peepholer.py20
-rw-r--r--Lib/test/test_pep247.py66
-rw-r--r--Lib/test/test_pickle.py16
-rw-r--r--Lib/test/test_pickletools.py34
-rw-r--r--Lib/test/test_pipes.py7
-rw-r--r--Lib/test/test_pkgutil.py6
-rw-r--r--Lib/test/test_platform.py5
-rw-r--r--Lib/test/test_plistlib.py9
-rw-r--r--Lib/test/test_poplib.py11
-rw-r--r--Lib/test/test_posix.py34
-rw-r--r--Lib/test/test_posixpath.py80
-rw-r--r--Lib/test/test_pow.py2
-rw-r--r--Lib/test/test_pty.py1
-rw-r--r--Lib/test/test_pulldom.py1
-rw-r--r--Lib/test/test_pyclbr.py4
-rw-r--r--Lib/test/test_pydoc.py25
-rw-r--r--Lib/test/test_quopri.py2
-rw-r--r--Lib/test/test_random.py78
-rw-r--r--Lib/test/test_range.py52
-rw-r--r--Lib/test/test_re.py369
-rw-r--r--Lib/test/test_readline.py15
-rw-r--r--Lib/test/test_regrtest.py629
-rw-r--r--Lib/test/test_richcmp.py25
-rw-r--r--Lib/test/test_rlcompleter.py55
-rw-r--r--Lib/test/test_robotparser.py396
-rw-r--r--Lib/test/test_runpy.py11
-rw-r--r--Lib/test/test_sched.py1
-rw-r--r--Lib/test/test_secrets.py123
-rw-r--r--Lib/test/test_set.py25
-rw-r--r--Lib/test/test_shlex.py110
-rw-r--r--Lib/test/test_shutil.py8
-rw-r--r--Lib/test/test_signal.py171
-rw-r--r--Lib/test/test_site.py37
-rw-r--r--Lib/test/test_smtpd.py52
-rw-r--r--Lib/test/test_socket.py232
-rw-r--r--Lib/test/test_socketserver.py183
-rw-r--r--Lib/test/test_sort.py1
-rw-r--r--Lib/test/test_spwd.py15
-rw-r--r--Lib/test/test_ssl.py997
-rw-r--r--Lib/test/test_statistics.py200
-rw-r--r--Lib/test/test_strftime.py6
-rw-r--r--Lib/test/test_string_literals.py (renamed from Lib/test/test_strlit.py)4
-rw-r--r--Lib/test/test_strptime.py76
-rw-r--r--Lib/test/test_struct.py128
-rw-r--r--Lib/test/test_subclassinit.py268
-rw-r--r--Lib/test/test_subprocess.py215
-rw-r--r--Lib/test/test_sunau.py1
-rw-r--r--Lib/test/test_super.py81
-rw-r--r--Lib/test/test_support.py31
-rw-r--r--Lib/test/test_symbol.py54
-rw-r--r--Lib/test/test_symtable.py17
-rw-r--r--Lib/test/test_syntax.py30
-rw-r--r--Lib/test/test_sys.py47
-rw-r--r--Lib/test/test_sys_settrace.py4
-rw-r--r--Lib/test/test_sysconfig.py5
-rw-r--r--Lib/test/test_tarfile.py18
-rw-r--r--Lib/test/test_telnetlib.py6
-rw-r--r--Lib/test/test_threading.py9
-rw-r--r--Lib/test/test_time.py598
-rw-r--r--Lib/test/test_timeit.py22
-rw-r--r--Lib/test/test_tokenize.py76
-rw-r--r--Lib/test/test_tools/__init__.py1
-rw-r--r--Lib/test/test_tools/test_gprof2html.py3
-rw-r--r--Lib/test/test_tools/test_md5sum.py3
-rw-r--r--Lib/test/test_tools/test_pdeps.py4
-rw-r--r--Lib/test/test_tools/test_unparse.py19
-rw-r--r--Lib/test/test_trace.py66
-rw-r--r--Lib/test/test_traceback.py147
-rw-r--r--Lib/test/test_tracemalloc.py219
-rw-r--r--Lib/test/test_ttk_guionly.py1
-rw-r--r--Lib/test/test_ttk_textonly.py1
-rw-r--r--Lib/test/test_types.py19
-rw-r--r--Lib/test/test_unicode.py36
-rw-r--r--Lib/test/test_unicode_file_functions.py (renamed from Lib/test/test_pep277.py)0
-rw-r--r--Lib/test/test_unicode_identifiers.py (renamed from Lib/test/test_pep3131.py)0
-rw-r--r--Lib/test/test_unicodedata.py8
-rw-r--r--Lib/test/test_unpack.py21
-rw-r--r--Lib/test/test_unpack_ex.py1
-rw-r--r--Lib/test/test_urllib.py13
-rw-r--r--Lib/test/test_urllib2.py121
-rw-r--r--Lib/test/test_urllib2_localnet.py34
-rw-r--r--Lib/test/test_urllibnet.py1
-rw-r--r--Lib/test/test_urlparse.py36
-rw-r--r--Lib/test/test_userdict.py6
-rw-r--r--Lib/test/test_userlist.py2
-rw-r--r--Lib/test/test_userstring.py3
-rw-r--r--Lib/test/test_utf8source.py (renamed from Lib/test/test_pep3120.py)0
-rw-r--r--Lib/test/test_uu.py1
-rw-r--r--Lib/test/test_venv.py33
-rw-r--r--Lib/test/test_warnings/__init__.py45
-rw-r--r--Lib/test/test_wave.py8
-rw-r--r--Lib/test/test_weakref.py9
-rw-r--r--Lib/test/test_weakset.py9
-rw-r--r--Lib/test/test_winconsoleio.py147
-rw-r--r--Lib/test/test_winreg.py1
-rw-r--r--Lib/test/test_winsound.py26
-rw-r--r--Lib/test/test_with.py9
-rw-r--r--Lib/test/test_wsgiref.py2
-rw-r--r--Lib/test/test_xml_etree.py16
-rw-r--r--Lib/test/test_xml_etree_c.py4
-rw-r--r--Lib/test/test_xmlrpc.py53
-rw-r--r--Lib/test/test_xmlrpc_net.py3
-rw-r--r--Lib/test/test_yield_from.py (renamed from Lib/test/test_pep380.py)0
-rw-r--r--Lib/test/test_zipfile.py286
-rw-r--r--Lib/test/test_zipimport.py27
-rw-r--r--Lib/test/test_zipimport_support.py1
-rw-r--r--Lib/test/test_zlib.py35
-rw-r--r--Lib/threading.py8
-rw-r--r--[-rwxr-xr-x]Lib/timeit.py73
-rw-r--r--Lib/tkinter/__init__.py218
-rw-r--r--Lib/tkinter/commondialog.py5
-rw-r--r--Lib/tkinter/dialog.py5
-rw-r--r--Lib/tkinter/test/runtktests.py2
-rw-r--r--Lib/tkinter/test/test_tkinter/test_misc.py8
-rw-r--r--Lib/tkinter/test/test_tkinter/test_variables.py52
-rw-r--r--Lib/tkinter/test/test_tkinter/test_widgets.py7
-rw-r--r--Lib/tkinter/test/test_ttk/test_functions.py1
-rw-r--r--Lib/tkinter/test/test_ttk/test_widgets.py49
-rw-r--r--Lib/tkinter/tix.py36
-rw-r--r--Lib/tkinter/ttk.py66
-rw-r--r--Lib/tokenize.py135
-rwxr-xr-xLib/trace.py382
-rw-r--r--Lib/traceback.py28
-rw-r--r--Lib/tracemalloc.py73
-rw-r--r--Lib/turtledemo/__main__.py7
-rwxr-xr-xLib/turtledemo/bytedesign.py1
-rwxr-xr-xLib/turtledemo/planet_and_moon.py1
-rw-r--r--Lib/types.py5
-rw-r--r--Lib/unittest/mock.py48
-rw-r--r--Lib/unittest/runner.py2
-rw-r--r--Lib/unittest/test/test_assertions.py18
-rw-r--r--Lib/unittest/test/test_loader.py8
-rw-r--r--Lib/unittest/test/testmock/support.py2
-rw-r--r--Lib/unittest/test/testmock/testmagicmethods.py1
-rw-r--r--Lib/unittest/test/testmock/testmock.py39
-rw-r--r--Lib/unittest/test/testmock/testpatch.py10
-rw-r--r--Lib/urllib/parse.py70
-rw-r--r--Lib/urllib/request.py90
-rw-r--r--Lib/urllib/robotparser.py43
-rw-r--r--Lib/uuid.py1
-rw-r--r--Lib/venv/__init__.py58
-rw-r--r--Lib/warnings.py118
-rw-r--r--Lib/wave.py2
-rw-r--r--Lib/wsgiref/simple_server.py30
-rw-r--r--Lib/xml/dom/xmlbuilder.py6
-rw-r--r--Lib/xml/etree/ElementPath.py22
-rw-r--r--Lib/xml/etree/ElementTree.py98
-rw-r--r--Lib/xmlrpc/client.py34
-rw-r--r--Lib/xmlrpc/server.py25
-rw-r--r--Lib/zipfile.py444
-rwxr-xr-xMac/BuildScript/build-installer.py121
-rw-r--r--Mac/BuildScript/resources/ReadMe.rtf108
-rw-r--r--Mac/BuildScript/resources/Welcome.rtf13
-rwxr-xr-xMac/BuildScript/resources/install_certificates.command48
-rw-r--r--Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py2
-rw-r--r--Makefile.pre.in143
-rw-r--r--Misc/ACKS32
-rw-r--r--Misc/NEWS2298
-rw-r--r--Misc/README.valgrind3
-rw-r--r--Misc/SpecialBuilds.txt34
-rw-r--r--Misc/coverity_model.c5
-rw-r--r--Modules/Setup.config.in3
-rw-r--r--Modules/Setup.dist4
-rw-r--r--Modules/_asynciomodule.c1040
-rw-r--r--Modules/_bisectmodule.c6
-rwxr-xr-xModules/_blake2/blake2b2s.py49
-rw-r--r--Modules/_blake2/blake2b_impl.c460
-rw-r--r--Modules/_blake2/blake2module.c105
-rw-r--r--Modules/_blake2/blake2ns.h32
-rw-r--r--Modules/_blake2/blake2s_impl.c460
-rw-r--r--Modules/_blake2/clinic/blake2b_impl.c.h125
-rw-r--r--Modules/_blake2/clinic/blake2s_impl.c.h125
-rw-r--r--Modules/_blake2/impl/blake2-config.h74
-rw-r--r--Modules/_blake2/impl/blake2-impl.h139
-rw-r--r--Modules/_blake2/impl/blake2.h161
-rw-r--r--Modules/_blake2/impl/blake2b-load-sse2.h70
-rw-r--r--Modules/_blake2/impl/blake2b-load-sse41.h404
-rw-r--r--Modules/_blake2/impl/blake2b-ref.c420
-rw-r--r--Modules/_blake2/impl/blake2b-round.h159
-rw-r--r--Modules/_blake2/impl/blake2b.c453
-rw-r--r--Modules/_blake2/impl/blake2s-load-sse2.h61
-rw-r--r--Modules/_blake2/impl/blake2s-load-sse41.h231
-rw-r--r--Modules/_blake2/impl/blake2s-load-xop.h191
-rw-r--r--Modules/_blake2/impl/blake2s-ref.c411
-rw-r--r--Modules/_blake2/impl/blake2s-round.h90
-rw-r--r--Modules/_blake2/impl/blake2s.c435
-rw-r--r--Modules/_bz2module.c3
-rw-r--r--Modules/_codecsmodule.c303
-rw-r--r--Modules/_collectionsmodule.c649
-rw-r--r--Modules/_csv.c24
-rw-r--r--Modules/_ctypes/_ctypes.c36
-rw-r--r--Modules/_ctypes/_ctypes_test.c43
-rw-r--r--Modules/_ctypes/callbacks.c2
-rw-r--r--Modules/_ctypes/callproc.c28
-rw-r--r--Modules/_ctypes/cfield.c76
-rw-r--r--Modules/_ctypes/ctypes.h10
-rw-r--r--Modules/_ctypes/libffi/src/dlmalloc.c2
-rw-r--r--Modules/_ctypes/libffi_arm_wince/debug.c59
-rw-r--r--Modules/_ctypes/libffi_arm_wince/ffi.c310
-rw-r--r--Modules/_ctypes/libffi_arm_wince/ffi.h317
-rw-r--r--Modules/_ctypes/libffi_arm_wince/ffi_common.h111
-rw-r--r--Modules/_ctypes/libffi_arm_wince/fficonfig.h152
-rw-r--r--Modules/_ctypes/libffi_arm_wince/ffitarget.h49
-rw-r--r--Modules/_ctypes/libffi_arm_wince/prep_cif.c175
-rw-r--r--Modules/_ctypes/libffi_arm_wince/sysv.asm228
-rw-r--r--Modules/_curses_panel.c4
-rw-r--r--Modules/_cursesmodule.c2
-rw-r--r--Modules/_datetimemodule.c1065
-rw-r--r--Modules/_dbmmodule.c8
-rw-r--r--Modules/_decimal/_decimal.c113
-rw-r--r--Modules/_decimal/docstrings.h9
-rw-r--r--Modules/_decimal/libmpdec/basearith.c1
-rw-r--r--Modules/_decimal/libmpdec/io.c1
-rw-r--r--Modules/_decimal/libmpdec/memory.c7
-rw-r--r--Modules/_decimal/libmpdec/mpalloc.h (renamed from Modules/_decimal/libmpdec/memory.h)4
-rw-r--r--Modules/_decimal/libmpdec/mpdecimal.c2
-rw-r--r--Modules/_decimal/libmpdec/mpdecimal.h12
-rw-r--r--Modules/_decimal/libmpdec/vccompat.h5
-rw-r--r--Modules/_decimal/tests/deccheck.py6
-rw-r--r--Modules/_elementtree.c585
-rw-r--r--Modules/_functoolsmodule.c60
-rw-r--r--Modules/_gdbmmodule.c2
-rw-r--r--Modules/_hashopenssl.c129
-rw-r--r--Modules/_heapqmodule.c10
-rw-r--r--Modules/_io/_iomodule.c83
-rw-r--r--Modules/_io/_iomodule.h29
-rw-r--r--Modules/_io/bufferedio.c2
-rw-r--r--Modules/_io/bytesio.c6
-rw-r--r--Modules/_io/clinic/_iomodule.c.h14
-rw-r--r--Modules/_io/clinic/bufferedio.c.h80
-rw-r--r--Modules/_io/clinic/bytesio.c.h31
-rw-r--r--Modules/_io/clinic/fileio.c.h31
-rw-r--r--Modules/_io/clinic/iobase.c.h11
-rw-r--r--Modules/_io/clinic/stringio.c.h22
-rw-r--r--Modules/_io/clinic/textio.c.h45
-rw-r--r--Modules/_io/clinic/winconsoleio.c.h331
-rw-r--r--Modules/_io/fileio.c46
-rw-r--r--Modules/_io/iobase.c2
-rw-r--r--Modules/_io/stringio.c2
-rw-r--r--Modules/_io/textio.c30
-rw-r--r--Modules/_io/winconsoleio.c1154
-rw-r--r--Modules/_json.c4
-rw-r--r--Modules/_localemodule.c56
-rw-r--r--Modules/_lsprof.c41
-rw-r--r--Modules/_lzmamodule.c30
-rw-r--r--Modules/_multiprocessing/multiprocessing.c2
-rw-r--r--Modules/_multiprocessing/multiprocessing.h2
-rw-r--r--Modules/_operator.c18
-rw-r--r--Modules/_pickle.c410
-rw-r--r--Modules/_posixsubprocess.c5
-rw-r--r--Modules/_randommodule.c101
-rw-r--r--Modules/_scproxy.c16
-rw-r--r--Modules/_sha3/README.txt11
-rwxr-xr-xModules/_sha3/cleanup.py50
-rw-r--r--Modules/_sha3/clinic/sha3module.c.h154
-rw-r--r--Modules/_sha3/kcp/KeccakHash.c82
-rw-r--r--Modules/_sha3/kcp/KeccakHash.h114
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-64.macros2208
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-SnP-opt32.h37
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-SnP-opt64.h49
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-SnP.h7
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-inplace32BI.c1162
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-opt64-config.h3
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-opt64.c474
-rw-r--r--Modules/_sha3/kcp/KeccakP-1600-unrolling.macros185
-rw-r--r--Modules/_sha3/kcp/KeccakSponge.c92
-rw-r--r--Modules/_sha3/kcp/KeccakSponge.h172
-rw-r--r--Modules/_sha3/kcp/KeccakSponge.inc332
-rw-r--r--Modules/_sha3/kcp/PlSnP-Fallback.inc257
-rw-r--r--Modules/_sha3/kcp/SnP-Relaned.h134
-rw-r--r--Modules/_sha3/kcp/align.h35
-rw-r--r--Modules/_sha3/sha3module.c757
-rw-r--r--Modules/_sqlite/cache.c3
-rw-r--r--Modules/_sqlite/connection.c91
-rw-r--r--Modules/_sqlite/connection.h4
-rw-r--r--Modules/_sqlite/cursor.c150
-rw-r--r--Modules/_sqlite/cursor.h6
-rw-r--r--Modules/_sqlite/module.c15
-rw-r--r--Modules/_sqlite/statement.c18
-rw-r--r--Modules/_sqlite/statement.h1
-rw-r--r--Modules/_sqlite/util.c21
-rw-r--r--Modules/_sre.c50
-rw-r--r--Modules/_ssl.c601
-rw-r--r--Modules/_struct.c198
-rw-r--r--Modules/_testbuffer.c2
-rw-r--r--Modules/_testcapimodule.c287
-rw-r--r--Modules/_testmultiphase.c2
-rw-r--r--Modules/_tkinter.c77
-rw-r--r--Modules/_tracemalloc.c586
-rw-r--r--Modules/_winapi.c16
-rw-r--r--Modules/addrinfo.h12
-rw-r--r--Modules/arraymodule.c136
-rw-r--r--Modules/audioop.c76
-rw-r--r--Modules/binascii.c287
-rw-r--r--Modules/cjkcodecs/clinic/multibytecodec.c.h65
-rw-r--r--Modules/clinic/_bz2module.c.h35
-rw-r--r--Modules/clinic/_codecsmodule.c.h334
-rw-r--r--Modules/clinic/_cryptmodule.c.h5
-rw-r--r--Modules/clinic/_cursesmodule.c.h14
-rw-r--r--Modules/clinic/_datetimemodule.c.h14
-rw-r--r--Modules/clinic/_dbmmodule.c.h11
-rw-r--r--Modules/clinic/_elementtree.c.h120
-rw-r--r--Modules/clinic/_gdbmmodule.c.h14
-rw-r--r--Modules/clinic/_hashopenssl.c.h60
-rw-r--r--Modules/clinic/_lzmamodule.c.h43
-rw-r--r--Modules/clinic/_opcode.c.h8
-rw-r--r--Modules/clinic/_pickle.c.h75
-rw-r--r--Modules/clinic/_sre.c.h206
-rw-r--r--Modules/clinic/_ssl.c.h198
-rw-r--r--Modules/clinic/_tkinter.c.h53
-rw-r--r--Modules/clinic/_weakref.c.h5
-rw-r--r--Modules/clinic/_winapi.c.h143
-rw-r--r--Modules/clinic/arraymodule.c.h29
-rw-r--r--Modules/clinic/audioop.c.h167
-rw-r--r--Modules/clinic/binascii.c.h118
-rw-r--r--Modules/clinic/cmathmodule.c.h83
-rw-r--r--Modules/clinic/fcntlmodule.c.h14
-rw-r--r--Modules/clinic/grpmodule.c.h26
-rw-r--r--Modules/clinic/md5module.c.h14
-rw-r--r--Modules/clinic/posixmodule.c.h1216
-rw-r--r--Modules/clinic/pwdmodule.c.h5
-rw-r--r--Modules/clinic/pyexpat.c.h32
-rw-r--r--Modules/clinic/sha1module.c.h14
-rw-r--r--Modules/clinic/sha256module.c.h26
-rw-r--r--Modules/clinic/sha512module.c.h74
-rw-r--r--Modules/clinic/signalmodule.c.h32
-rw-r--r--Modules/clinic/spwdmodule.c.h5
-rw-r--r--Modules/clinic/unicodedata.c.h44
-rw-r--r--Modules/clinic/zlibmodule.c.h115
-rw-r--r--Modules/cmathmodule.c55
-rw-r--r--Modules/faulthandler.c316
-rw-r--r--Modules/gcmodule.c20
-rw-r--r--Modules/getaddrinfo.c4
-rw-r--r--Modules/getpath.c4
-rw-r--r--Modules/grpmodule.c21
-rw-r--r--Modules/hashlib.h19
-rw-r--r--Modules/hashtable.c196
-rw-r--r--Modules/hashtable.h181
-rw-r--r--Modules/itertoolsmodule.c387
-rw-r--r--Modules/main.c53
-rw-r--r--Modules/mathmodule.c5
-rw-r--r--Modules/md5module.c2
-rw-r--r--Modules/mmapmodule.c19
-rw-r--r--Modules/nismodule.c6
-rw-r--r--Modules/ossaudiodev.c6
-rw-r--r--Modules/overlapped.c10
-rw-r--r--Modules/parsermodule.c2555
-rw-r--r--Modules/posixmodule.c1810
-rw-r--r--Modules/pwdmodule.c8
-rw-r--r--Modules/pyexpat.c38
-rw-r--r--Modules/readline.c27
-rw-r--r--Modules/resource.c10
-rw-r--r--Modules/selectmodule.c42
-rw-r--r--Modules/sha1module.c2
-rw-r--r--Modules/sha512module.c172
-rw-r--r--Modules/signalmodule.c226
-rw-r--r--Modules/socketmodule.c717
-rw-r--r--Modules/spwdmodule.c5
-rw-r--r--Modules/sre_lib.h61
-rw-r--r--Modules/symtablemodule.c1
-rw-r--r--Modules/timemodule.c178
-rw-r--r--Modules/unicodedata.c7
-rw-r--r--Modules/unicodedata_db.h3239
-rw-r--r--Modules/unicodename_db.h45498
-rw-r--r--Modules/winreparse.h17
-rw-r--r--Modules/xxlimited.c2
-rw-r--r--Modules/xxmodule.c2
-rw-r--r--Modules/zipimport.c6
-rw-r--r--Modules/zlibmodule.c30
-rw-r--r--Objects/abstract.c653
-rw-r--r--Objects/bytearrayobject.c1032
-rw-r--r--Objects/bytes_methods.c431
-rw-r--r--Objects/bytesobject.c2295
-rw-r--r--Objects/classobject.c29
-rw-r--r--Objects/clinic/bytearrayobject.c.h134
-rw-r--r--Objects/clinic/bytesobject.c.h137
-rw-r--r--Objects/clinic/dictobject.c.h5
-rw-r--r--Objects/clinic/unicodeobject.c.h5
-rw-r--r--Objects/codeobject.c116
-rw-r--r--Objects/complexobject.c63
-rw-r--r--Objects/descrobject.c38
-rw-r--r--Objects/dict-common.h60
-rw-r--r--Objects/dictobject.c1694
-rw-r--r--Objects/enumobject.c12
-rw-r--r--Objects/exceptions.c40
-rw-r--r--Objects/fileobject.c11
-rw-r--r--Objects/floatobject.c348
-rw-r--r--Objects/frameobject.c14
-rw-r--r--Objects/funcobject.c35
-rw-r--r--Objects/genobject.c1024
-rw-r--r--Objects/iterobject.c40
-rw-r--r--Objects/listobject.c66
-rw-r--r--Objects/listsort.txt2
-rw-r--r--Objects/lnotab_notes.txt47
-rw-r--r--Objects/longobject.c542
-rw-r--r--Objects/memoryobject.c100
-rw-r--r--Objects/methodobject.c152
-rw-r--r--Objects/moduleobject.c5
-rw-r--r--Objects/namespaceobject.c8
-rw-r--r--Objects/object.c81
-rw-r--r--Objects/obmalloc.c432
-rw-r--r--Objects/odictobject.c73
-rw-r--r--Objects/rangeobject.c34
-rw-r--r--Objects/setobject.c623
-rw-r--r--Objects/stringlib/codecs.h208
-rw-r--r--Objects/stringlib/ctype.h5
-rw-r--r--Objects/stringlib/fastsearch.h150
-rw-r--r--Objects/stringlib/find.h82
-rw-r--r--Objects/stringlib/find_max_char.h5
-rw-r--r--Objects/stringlib/join.h8
-rw-r--r--Objects/stringlib/localeutil.h4
-rw-r--r--Objects/stringlib/transmogrify.h615
-rw-r--r--Objects/stringlib/unicode_format.h2
-rw-r--r--Objects/structseq.c30
-rw-r--r--Objects/tupleobject.c19
-rw-r--r--Objects/typeobject.c523
-rw-r--r--Objects/unicodeobject.c2420
-rw-r--r--Objects/unicodetype_db.h1573
-rw-r--r--Objects/weakrefobject.c4
-rw-r--r--PC/_msi.c12
-rw-r--r--PC/_testconsole.c131
-rw-r--r--PC/bdist_wininst/install.c18
-rw-r--r--PC/clinic/_testconsole.c.h82
-rw-r--r--PC/clinic/msvcrtmodule.c.h67
-rw-r--r--PC/clinic/winreg.c.h135
-rw-r--r--PC/clinic/winsound.c.h51
-rw-r--r--PC/config.c4
-rw-r--r--PC/getpathp.c265
-rw-r--r--PC/icons/launcher.icnsbin0 -> 264476 bytes-rw-r--r--PC/icons/launcher.icobin0 -> 87263 bytes-rw-r--r--PC/icons/launcher.svg1
-rw-r--r--PC/icons/py.icnsbin0 -> 195977 bytes-rw-r--r--PC/icons/py.icobin0 -> 75809 bytes-rw-r--r--PC/icons/py.svg1
-rw-r--r--PC/icons/pyc.icnsbin0 -> 212125 bytes-rw-r--r--PC/icons/pyc.icobin0 -> 78396 bytes-rw-r--r--PC/icons/pyc.svg1
-rw-r--r--PC/icons/pyd.icnsbin0 -> 223199 bytes-rw-r--r--PC/icons/pyd.icobin0 -> 83351 bytes-rw-r--r--PC/icons/pyd.svg1
-rw-r--r--PC/icons/python.icnsbin0 -> 201868 bytes-rw-r--r--PC/icons/python.icobin0 -> 77671 bytes-rw-r--r--PC/icons/python.svg1
-rw-r--r--PC/icons/pythonw.icnsbin0 -> 193222 bytes-rw-r--r--PC/icons/pythonw.icobin0 -> 76102 bytes-rw-r--r--PC/icons/pythonw.svg1
-rw-r--r--PC/icons/setup.icnsbin0 -> 220699 bytes-rw-r--r--PC/icons/setup.icobin0 -> 78328 bytes-rw-r--r--PC/icons/setup.svg1
-rw-r--r--PC/launcher.c33
-rw-r--r--PC/launcher.icobin19790 -> 0 bytes-rw-r--r--PC/msvcrtmodule.c34
-rw-r--r--PC/py.icobin19790 -> 0 bytes-rw-r--r--PC/pyc.icobin19790 -> 0 bytes-rw-r--r--PC/pycon.icobin19790 -> 0 bytes-rw-r--r--PC/pyconfig.h92
-rw-r--r--PC/pylauncher.rc10
-rw-r--r--PC/python.manifest7
-rw-r--r--PC/python3.def1419
-rw-r--r--PC/python_exe.rc2
-rw-r--r--PC/pythonw_exe.rc49
-rw-r--r--PC/testpy.py4
-rw-r--r--PC/winreg.c40
-rw-r--r--PC/winsound.c74
-rw-r--r--PCbuild/_asyncio.vcxproj77
-rw-r--r--PCbuild/_asyncio.vcxproj.filters16
-rw-r--r--PCbuild/_lzma.vcxproj12
-rw-r--r--PCbuild/_testconsole.vcxproj83
-rw-r--r--PCbuild/_testconsole.vcxproj.filters22
-rw-r--r--PCbuild/build_pgo.bat6
-rw-r--r--PCbuild/get_externals.bat8
-rw-r--r--PCbuild/liblzma.vcxproj216
-rw-r--r--PCbuild/openssl.props2
-rw-r--r--PCbuild/pcbuild.proj4
-rw-r--r--PCbuild/pcbuild.sln20
-rw-r--r--PCbuild/prepare_ssl.bat4
-rw-r--r--PCbuild/pyproject.props13
-rw-r--r--PCbuild/python.props5
-rw-r--r--PCbuild/pythoncore.vcxproj13
-rw-r--r--PCbuild/pythoncore.vcxproj.filters28
-rw-r--r--PCbuild/pythonw.vcxproj2
-rw-r--r--PCbuild/readme.txt6
-rw-r--r--PCbuild/rt.bat2
-rw-r--r--PCbuild/sqlite3.vcxproj4
-rw-r--r--PCbuild/tcltk.props6
-rw-r--r--PCbuild/xxlimited.vcxproj2
-rw-r--r--Parser/Python.asdl13
-rw-r--r--Parser/asdl.py3
-rw-r--r--[-rwxr-xr-x]Parser/asdl_c.py16
-rw-r--r--Parser/grammar.c27
-rw-r--r--Parser/myreadline.c138
-rw-r--r--Parser/node.c2
-rw-r--r--Parser/parser.c9
-rw-r--r--Parser/parsetok.c6
-rw-r--r--Parser/pgen.c24
-rw-r--r--Parser/pgenmain.c14
-rw-r--r--Parser/tokenizer.c246
-rw-r--r--Programs/_freeze_importlib.c2
-rw-r--r--Programs/_testembed.c2
-rw-r--r--Programs/python.c9
-rw-r--r--Python/Python-ast.c394
-rw-r--r--Python/_warnings.c221
-rw-r--r--Python/asdl.c8
-rw-r--r--Python/ast.c1400
-rw-r--r--Python/bltinmodule.c129
-rw-r--r--Python/ceval.c1923
-rw-r--r--Python/ceval_gil.h4
-rw-r--r--Python/clinic/bltinmodule.c.h53
-rw-r--r--Python/clinic/import.c.h29
-rw-r--r--Python/compile.c1321
-rw-r--r--Python/condvar.h6
-rw-r--r--Python/dtoa.c125
-rw-r--r--Python/dynload_win.c8
-rw-r--r--Python/errors.c144
-rw-r--r--Python/fileutils.c177
-rw-r--r--Python/formatter_unicode.c107
-rw-r--r--Python/frozen.c20
-rw-r--r--Python/frozenmain.c4
-rw-r--r--Python/future.c5
-rw-r--r--Python/getargs.c867
-rw-r--r--Python/graminit.c1924
-rw-r--r--Python/import.c423
-rw-r--r--Python/importdl.c4
-rw-r--r--Python/importlib.h3724
-rw-r--r--Python/importlib_external.h4868
-rwxr-xr-xPython/makeopcodetargets.py48
-rw-r--r--Python/marshal.c122
-rw-r--r--Python/modsupport.c25
-rw-r--r--Python/mystrtoul.c6
-rw-r--r--Python/opcode_targets.h18
-rw-r--r--Python/peephole.c661
-rw-r--r--Python/pyhash.c53
-rw-r--r--Python/pylifecycle.c170
-rw-r--r--Python/pystate.c50
-rw-r--r--Python/pystrtod.c75
-rw-r--r--Python/pythonrun.c36
-rw-r--r--Python/pytime.c348
-rw-r--r--Python/random.c340
-rw-r--r--Python/structmember.c20
-rw-r--r--Python/symtable.c155
-rw-r--r--Python/sysmodule.c293
-rw-r--r--Python/thread_nt.h24
-rw-r--r--Python/traceback.c225
-rw-r--r--Python/wordcode_helpers.h41
-rw-r--r--README53
-rw-r--r--Tools/buildbot/build-amd64.bat5
-rw-r--r--Tools/buildbot/clean-amd64.bat5
-rw-r--r--Tools/buildbot/clean.bat1
-rw-r--r--Tools/buildbot/external-amd64.bat3
-rw-r--r--Tools/buildbot/external.bat3
-rw-r--r--Tools/buildbot/test-amd64.bat6
-rw-r--r--Tools/buildbot/test.bat4
-rwxr-xr-xTools/clinic/clinic.py128
-rwxr-xr-xTools/demo/ss1.py2
-rwxr-xr-xTools/freeze/freeze.py6
-rw-r--r--Tools/freeze/winmakemakefile.py6
-rwxr-xr-xTools/gdb/libpython.py2
-rw-r--r--Tools/hg/hgtouch.py1
-rwxr-xr-xTools/i18n/pygettext.py51
-rw-r--r--Tools/msi/buildrelease.bat33
-rw-r--r--Tools/msi/bundle/Default.thm7
-rw-r--r--Tools/msi/bundle/Default.wxl3
-rw-r--r--Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp155
-rw-r--r--Tools/msi/bundle/bundle.icobin19790 -> 0 bytes-rw-r--r--Tools/msi/bundle/bundle.wxs2
-rw-r--r--Tools/msi/common.wxs12
-rw-r--r--Tools/msi/common_en-US.wxl_template1
-rw-r--r--Tools/msi/exe/exe.wixproj1
-rw-r--r--Tools/msi/exe/exe.wxs2
-rw-r--r--Tools/msi/exe/exe_d.wixproj1
-rw-r--r--Tools/msi/exe/exe_en-US.wxl_template1
-rw-r--r--Tools/msi/exe/exe_files.wxs10
-rw-r--r--Tools/msi/exe/exe_pdb.wixproj1
-rw-r--r--Tools/msi/exe/exe_reg.wxs25
-rw-r--r--Tools/msi/launcher/launcher.wixproj2
-rw-r--r--Tools/msi/launcher/launcher.wxs16
-rw-r--r--Tools/msi/launcher/launcher_en-US.wxl1
-rw-r--r--Tools/msi/launcher/launcher_reg.wxs8
-rw-r--r--Tools/msi/lib/lib.wixproj1
-rw-r--r--Tools/msi/lib/lib.wxs1
-rw-r--r--Tools/msi/lib/lib_files.wxs13
-rw-r--r--Tools/msi/make_zip.py54
-rw-r--r--Tools/msi/msi.props11
-rw-r--r--Tools/msi/msi.targets33
-rw-r--r--Tools/msi/test/test_files.wxs12
-rw-r--r--Tools/msi/tools/tools.wixproj1
-rw-r--r--Tools/msi/tools/tools.wxs1
-rw-r--r--Tools/msi/tools/tools_files.wxs7
-rw-r--r--Tools/nuget/make_pkg.proj1
-rw-r--r--Tools/parser/unparse.py86
-rw-r--r--Tools/pybench/CommandLine.py4
-rw-r--r--Tools/pybench/With.py1
-rw-r--r--Tools/pynche/ColorDB.py6
-rwxr-xr-xTools/scripts/combinerefs.py4
-rwxr-xr-xTools/scripts/diff.py2
-rwxr-xr-xTools/scripts/fixdiv.py4
-rw-r--r--Tools/scripts/generate_opcode_h.py2
-rwxr-xr-xTools/scripts/h2py.py8
-rwxr-xr-xTools/scripts/highlight.py16
-rwxr-xr-xTools/scripts/idle32
-rwxr-xr-xTools/scripts/mailerdaemon.py2
-rwxr-xr-xTools/scripts/nm2def.py4
-rwxr-xr-xTools/scripts/parseentities.py4
-rwxr-xr-xTools/scripts/pathfix.py2
-rwxr-xr-xTools/scripts/ptags.py2
-rwxr-xr-xTools/scripts/pyvenv6
-rwxr-xr-xTools/scripts/svneol.py2
-rwxr-xr-xTools/scripts/texi2html.py10
-rw-r--r--Tools/ssl/test_multiple_versions.py6
-rw-r--r--Tools/tz/zdump.py81
-rw-r--r--Tools/unicode/gencodec.py10
-rw-r--r--Tools/unicode/makeunicodedata.py11
-rw-r--r--aclocal.m44
-rwxr-xr-xconfigure1244
-rw-r--r--configure.ac436
-rw-r--r--pyconfig.h.in105
-rw-r--r--setup.py61
1466 files changed, 123883 insertions, 75551 deletions
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..4ce80d8
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,9 @@
+## CPython Mirror
+
+https://github.com/python/cpython is a cpython mirror repository. Pull requests
+are not accepted on this repo and will be automatically closed.
+
+### Submit patches at https://bugs.python.org
+
+For additional information about contributing to CPython, see the
+[developer's guide](https://docs.python.org/devguide/#contributing).
diff --git a/.gitignore b/.gitignore
index d267d15..ed4ebfb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,8 +21,6 @@ Doc/venv/
Lib/distutils/command/*.pdb
Lib/lib2to3/*.pickle
Lib/test/data/*
-Lib/_sysconfigdata.py
-Lib/plat-mac/errors.rsrc.df.rsrc
Makefile
Makefile.pre
Misc/python.pc
@@ -73,6 +71,7 @@ db_home
ipch/
libpython*.a
libpython*.so*
+libpython*.dylib
platform
pybuilddir.txt
pyconfig.h
diff --git a/.hgignore b/.hgignore
index cf9453a..92896b7 100644
--- a/.hgignore
+++ b/.hgignore
@@ -2,6 +2,7 @@
.purify
.svn/
^.idea/
+^.vscode/
.DS_Store
Makefile$
Makefile.pre$
@@ -25,7 +26,6 @@ python-config$
python-config.py$
reflog.txt$
tags$
-Lib/plat-mac/errors.rsrc.df.rsrc
Misc/python.pc
Misc/python-config.sh$
Modules/Setup$
@@ -43,6 +43,7 @@ Parser/pgen$
syntax: glob
libpython*.a
libpython*.so*
+libpython*.dylib
*.swp
*.o
*.pyc
@@ -54,6 +55,7 @@ libpython*.so*
*.profclang?
*.profraw
*.dyn
+Include/pydtrace_probes.h
Lib/distutils/command/*.pdb
Lib/lib2to3/*.pickle
Lib/test/data/*
diff --git a/.hgtags b/.hgtags
index ed4fc92..390e10d 100644
--- a/.hgtags
+++ b/.hgtags
@@ -148,6 +148,7 @@ b4cbecbc0781e89a309d03b60a1f75f8499250e6 v3.4.3
737efcadf5a678b184e0fa431aae11276bf06648 v3.4.4
3631bb4a2490292ebf81d3e947ae36da145da564 v3.4.5rc1
619b61e505d0e2ccc8516b366e4ddd1971b46a6f v3.4.5
+3631bb4a2490292ebf81d3e947ae36da145da564 v3.4.5rc1
5d4b6a57d5fd7564bf73f3db0e46fe5eeb00bcd8 v3.5.0a1
0337bd7ebcb6559d69679bc7025059ad1ce4f432 v3.5.0a2
82656e28b5e5c4ae48d8dd8b5f0d7968908a82b6 v3.5.0a3
@@ -165,3 +166,9 @@ cc15d736d860303b9da90d43cd32db39bab048df v3.5.0rc2
37a07cee5969e6d3672583187a73cf636ff28e1b v3.5.1
68feec6488b26327a85a634605dd28eca4daa5f1 v3.5.2rc1
4def2a2901a5618ea45bcc8f2a1411ef33af18ad v3.5.2
+5896da372fb044e38595fb74495de1e1e7c8fb3c v3.6.0a1
+37889342355223e2fc1438de3dc7ffcd625c60f7 v3.6.0a2
+f3edf13dc339b8942ae6b309771ab197dd8ce6fa v3.6.0a3
+017cf260936b444788c9b671d195b7bfd83dbd25 v3.6.0a4
+5b0ca4ed5e2f0669d76ece7ef975c544580f12b4 v3.6.0b1
+b9fadc7d1c3f9c3c77f32f35afbe1a1cc38070e6 v3.6.0b2
diff --git a/Doc/Makefile b/Doc/Makefile
index 10c3288..91f937f 100644
--- a/Doc/Makefile
+++ b/Doc/Makefile
@@ -153,7 +153,7 @@ dist:
cp -pPR build/epub/Python.epub dist/python-$(DISTVERSION)-docs.epub
check:
- $(PYTHON) tools/rstlint.py -i tools
+ $(PYTHON) tools/rstlint.py -i tools -i venv
serve:
../Tools/scripts/serve.py build/html
diff --git a/Doc/c-api/arg.rst b/Doc/c-api/arg.rst
index d5e4703..569903f 100644
--- a/Doc/c-api/arg.rst
+++ b/Doc/c-api/arg.rst
@@ -223,8 +223,7 @@ which disallows mutable objects such as :class:`bytearray`.
:c:func:`PyArg_ParseTuple` will use this location as the buffer and interpret the
initial value of *\*buffer_length* as the buffer size. It will then copy the
encoded data into the buffer and NUL-terminate it. If the buffer is not large
- enough, a :exc:`TypeError` will be set.
- Note: starting from Python 3.6 a :exc:`ValueError` will be set.
+ enough, a :exc:`ValueError` will be set.
In both cases, *\*buffer_length* is set to the length of the encoded data
without the trailing NUL byte.
@@ -266,15 +265,12 @@ Numbers
Convert a Python integer to a C :c:type:`unsigned long` without
overflow checking.
-``L`` (:class:`int`) [PY_LONG_LONG]
- Convert a Python integer to a C :c:type:`long long`. This format is only
- available on platforms that support :c:type:`long long` (or :c:type:`_int64` on
- Windows).
+``L`` (:class:`int`) [long long]
+ Convert a Python integer to a C :c:type:`long long`.
-``K`` (:class:`int`) [unsigned PY_LONG_LONG]
+``K`` (:class:`int`) [unsigned long long]
Convert a Python integer to a C :c:type:`unsigned long long`
- without overflow checking. This format is only available on platforms that
- support :c:type:`unsigned long long` (or :c:type:`unsigned _int64` on Windows).
+ without overflow checking.
``n`` (:class:`int`) [Py_ssize_t]
Convert a Python integer to a C :c:type:`Py_ssize_t`.
@@ -424,8 +420,15 @@ API Functions
.. c:function:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...)
Parse the parameters of a function that takes both positional and keyword
- parameters into local variables. Returns true on success; on failure, it
- returns false and raises the appropriate exception.
+ parameters into local variables. The *keywords* argument is a
+ *NULL*-terminated array of keyword parameter names. Empty names denote
+ :ref:`positional-only parameters <positional-only_parameter>`.
+ Returns true on success; on failure, it returns false and raises the
+ appropriate exception.
+
+ .. versionchanged:: 3.6
+ Added support for :ref:`positional-only parameters
+ <positional-only_parameter>`.
.. c:function:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], va_list vargs)
@@ -588,15 +591,11 @@ Building values
``k`` (:class:`int`) [unsigned long]
Convert a C :c:type:`unsigned long` to a Python integer object.
- ``L`` (:class:`int`) [PY_LONG_LONG]
- Convert a C :c:type:`long long` to a Python integer object. Only available
- on platforms that support :c:type:`long long` (or :c:type:`_int64` on
- Windows).
+ ``L`` (:class:`int`) [long long]
+ Convert a C :c:type:`long long` to a Python integer object.
- ``K`` (:class:`int`) [unsigned PY_LONG_LONG]
- Convert a C :c:type:`unsigned long long` to a Python integer object. Only
- available on platforms that support :c:type:`unsigned long long` (or
- :c:type:`unsigned _int64` on Windows).
+ ``K`` (:class:`int`) [unsigned long long]
+ Convert a C :c:type:`unsigned long long` to a Python integer object.
``n`` (:class:`int`) [Py_ssize_t]
Convert a C :c:type:`Py_ssize_t` to a Python integer.
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst
index 19cbb3b..25fb29c 100644
--- a/Doc/c-api/exceptions.rst
+++ b/Doc/c-api/exceptions.rst
@@ -306,6 +306,13 @@ an error value).
:mod:`warnings` module and the :option:`-W` option in the command line
documentation. There is no C API for warning control.
+.. c:function:: PyObject* PyErr_SetImportErrorSubclass(PyObject *msg, PyObject *name, PyObject *path)
+
+ Much like :c:func:`PyErr_SetImportError` but this function allows for
+ specifying a subclass of :exc:`ImportError` to raise.
+
+ .. versionadded:: 3.4
+
.. c:function:: int PyErr_WarnExplicitObject(PyObject *category, PyObject *message, PyObject *filename, int lineno, PyObject *module, PyObject *registry)
@@ -334,6 +341,14 @@ an error value).
.. versionadded:: 3.2
+.. c:function:: int PyErr_ResourceWarning(PyObject *source, Py_ssize_t stack_level, const char *format, ...)
+
+ Function similar to :c:func:`PyErr_WarnFormat`, but *category* is
+ :exc:`ResourceWarning` and pass *source* to :func:`warnings.WarningMessage`.
+
+ .. versionadded:: 3.6
+
+
Querying the error indicator
============================
@@ -774,6 +789,8 @@ the variables:
+-----------------------------------------+---------------------------------+----------+
| :c:data:`PyExc_ImportError` | :exc:`ImportError` | |
+-----------------------------------------+---------------------------------+----------+
+| :c:data:`PyExc_ModuleNotFoundError` | :exc:`ModuleNotFoundError` | |
++-----------------------------------------+---------------------------------+----------+
| :c:data:`PyExc_IndexError` | :exc:`IndexError` | |
+-----------------------------------------+---------------------------------+----------+
| :c:data:`PyExc_InterruptedError` | :exc:`InterruptedError` | |
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index e78ddae..c272a1c 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -25,7 +25,7 @@ Initializing and finalizing the interpreter
triple: module; search; path
single: PySys_SetArgv()
single: PySys_SetArgvEx()
- single: Py_Finalize()
+ single: Py_FinalizeEx()
Initialize the Python interpreter. In an application embedding Python, this
should be called before using any other Python/C API functions; with the
@@ -34,7 +34,7 @@ Initializing and finalizing the interpreter
modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. It also initializes
the module search path (``sys.path``). It does not set ``sys.argv``; use
:c:func:`PySys_SetArgvEx` for that. This is a no-op when called for a second time
- (without calling :c:func:`Py_Finalize` first). There is no return value; it is a
+ (without calling :c:func:`Py_FinalizeEx` first). There is no return value; it is a
fatal error if the initialization fails.
.. note::
@@ -52,19 +52,20 @@ Initializing and finalizing the interpreter
.. c:function:: int Py_IsInitialized()
Return true (nonzero) when the Python interpreter has been initialized, false
- (zero) if not. After :c:func:`Py_Finalize` is called, this returns false until
+ (zero) if not. After :c:func:`Py_FinalizeEx` is called, this returns false until
:c:func:`Py_Initialize` is called again.
-.. c:function:: void Py_Finalize()
+.. c:function:: int Py_FinalizeEx()
Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of
Python/C API functions, and destroy all sub-interpreters (see
:c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since
the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
allocated by the Python interpreter. This is a no-op when called for a second
- time (without calling :c:func:`Py_Initialize` again first). There is no return
- value; errors during finalization are ignored.
+ time (without calling :c:func:`Py_Initialize` again first). Normally the
+ return value is 0. If there were errors during finalization
+ (flushing buffered data), -1 is returned.
This function is provided for a number of reasons. An embedding application
might want to restart Python without having to restart the application itself.
@@ -83,7 +84,15 @@ Initializing and finalizing the interpreter
freed. Some memory allocated by extension modules may not be freed. Some
extensions may not work properly if their initialization routine is called more
than once; this can happen if an application calls :c:func:`Py_Initialize` and
- :c:func:`Py_Finalize` more than once.
+ :c:func:`Py_FinalizeEx` more than once.
+
+ .. versionadded:: 3.6
+
+
+.. c:function:: void Py_Finalize()
+
+ This is a backwards-compatible version of :c:func:`Py_FinalizeEx` that
+ disregards the return value.
Process-wide parameters
@@ -111,7 +120,7 @@ Process-wide parameters
Note that :data:`sys.stderr` always uses the "backslashreplace" error
handler, regardless of this (or any other) setting.
- If :c:func:`Py_Finalize` is called, this function will need to be called
+ If :c:func:`Py_FinalizeEx` is called, this function will need to be called
again in order to affect subsequent calls to :c:func:`Py_Initialize`.
Returns 0 if successful, a nonzero value on error (e.g. calling after the
@@ -922,7 +931,7 @@ using the following functions:
entry.)
.. index::
- single: Py_Finalize()
+ single: Py_FinalizeEx()
single: Py_Initialize()
Extension modules are shared between (sub-)interpreters as follows: the first
@@ -932,7 +941,7 @@ using the following functions:
and filled with the contents of this copy; the extension's ``init`` function is
not called. Note that this is different from what happens when an extension is
imported after the interpreter has been completely re-initialized by calling
- :c:func:`Py_Finalize` and :c:func:`Py_Initialize`; in that case, the extension's
+ :c:func:`Py_FinalizeEx` and :c:func:`Py_Initialize`; in that case, the extension's
``initmodule`` function *is* called again.
.. index:: single: close() (in module os)
@@ -940,14 +949,14 @@ using the following functions:
.. c:function:: void Py_EndInterpreter(PyThreadState *tstate)
- .. index:: single: Py_Finalize()
+ .. index:: single: Py_FinalizeEx()
Destroy the (sub-)interpreter represented by the given thread state. The given
thread state must be the current thread state. See the discussion of thread
states below. When the call returns, the current thread state is *NULL*. All
thread states associated with this interpreter are destroyed. (The global
interpreter lock must be held before calling this function and is still held
- when it returns.) :c:func:`Py_Finalize` will destroy all sub-interpreters that
+ when it returns.) :c:func:`Py_FinalizeEx` will destroy all sub-interpreters that
haven't been explicitly destroyed at that point.
diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst
index bc3a752..74681d2 100644
--- a/Doc/c-api/intro.rst
+++ b/Doc/c-api/intro.rst
@@ -64,9 +64,10 @@ The header files are typically installed with Python. On Unix, these are
located in the directories :file:`{prefix}/include/pythonversion/` and
:file:`{exec_prefix}/include/pythonversion/`, where :envvar:`prefix` and
:envvar:`exec_prefix` are defined by the corresponding parameters to Python's
-:program:`configure` script and *version* is ``sys.version[:3]``. On Windows,
-the headers are installed in :file:`{prefix}/include`, where :envvar:`prefix` is
-the installation directory specified to the installer.
+:program:`configure` script and *version* is
+``'%d.%d' % sys.version_info[:2]``. On Windows, the headers are installed
+in :file:`{prefix}/include`, where :envvar:`prefix` is the installation
+directory specified to the installer.
To include the headers, place both directories (if different) on your compiler's
search path for includes. Do *not* place the parent directories on the search
@@ -578,9 +579,9 @@ Sometimes, it is desirable to "uninitialize" Python. For instance, the
application may want to start over (make another call to
:c:func:`Py_Initialize`) or the application is simply done with its use of
Python and wants to free memory allocated by Python. This can be accomplished
-by calling :c:func:`Py_Finalize`. The function :c:func:`Py_IsInitialized` returns
+by calling :c:func:`Py_FinalizeEx`. The function :c:func:`Py_IsInitialized` returns
true if Python is currently in the initialized state. More information about
-these functions is given in a later chapter. Notice that :c:func:`Py_Finalize`
+these functions is given in a later chapter. Notice that :c:func:`Py_FinalizeEx`
does *not* free all memory allocated by the Python interpreter, e.g. memory
allocated by extension modules currently cannot be released.
diff --git a/Doc/c-api/long.rst b/Doc/c-api/long.rst
index b348015..bae9703 100644
--- a/Doc/c-api/long.rst
+++ b/Doc/c-api/long.rst
@@ -62,13 +62,13 @@ All integers are implemented as "long" integer objects of arbitrary size.
*NULL* on failure.
-.. c:function:: PyObject* PyLong_FromLongLong(PY_LONG_LONG v)
+.. c:function:: PyObject* PyLong_FromLongLong(long long v)
Return a new :c:type:`PyLongObject` object from a C :c:type:`long long`, or *NULL*
on failure.
-.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v)
+.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned long long v)
Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long long`,
or *NULL* on failure.
@@ -148,7 +148,7 @@ All integers are implemented as "long" integer objects of arbitrary size.
occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
-.. c:function:: PY_LONG_LONG PyLong_AsLongLong(PyObject *obj)
+.. c:function:: long long PyLong_AsLongLong(PyObject *obj)
.. index::
single: OverflowError (built-in exception)
@@ -161,7 +161,7 @@ All integers are implemented as "long" integer objects of arbitrary size.
:c:type:`long`.
-.. c:function:: PY_LONG_LONG PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow)
+.. c:function:: long long PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow)
Return a C :c:type:`long long` representation of *obj*. If *obj* is not an
instance of :c:type:`PyLongObject`, first call its :meth:`__int__` method
@@ -210,16 +210,16 @@ All integers are implemented as "long" integer objects of arbitrary size.
:c:type:`size_t`.
-.. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong)
+.. c:function:: unsigned long long PyLong_AsUnsignedLongLong(PyObject *pylong)
.. index::
single: OverflowError (built-in exception)
- Return a C :c:type:`unsigned PY_LONG_LONG` representation of *pylong*.
- *pylong* must be an instance of :c:type:`PyLongObject`.
+ Return a C :c:type:`unsigned long long` representation of *pylong*. *pylong*
+ must be an instance of :c:type:`PyLongObject`.
Raise :exc:`OverflowError` if the value of *pylong* is out of range for an
- :c:type:`unsigned PY_LONG_LONG`.
+ :c:type:`unsigned long long`.
.. versionchanged:: 3.1
A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`.
@@ -235,7 +235,7 @@ All integers are implemented as "long" integer objects of arbitrary size.
return the reduction of that value modulo :const:`ULONG_MAX + 1`.
-.. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *obj)
+.. c:function:: unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj)
Return a C :c:type:`unsigned long long` representation of *obj*. If *obj*
is not an instance of :c:type:`PyLongObject`, first call its :meth:`__int__`
diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst
index 290ef09..3ff5452 100644
--- a/Doc/c-api/memory.rst
+++ b/Doc/c-api/memory.rst
@@ -85,9 +85,12 @@ for the I/O buffer escapes completely the Python memory manager.
.. seealso::
+ The :envvar:`PYTHONMALLOC` environment variable can be used to configure
+ the memory allocators used by Python.
+
The :envvar:`PYTHONMALLOCSTATS` environment variable can be used to print
- memory allocation statistics every time a new object arena is created, and
- on shutdown.
+ statistics of the :ref:`pymalloc memory allocator <pymalloc>` every time a
+ new pymalloc object arena is created, and on shutdown.
Raw Memory Interface
@@ -162,15 +165,17 @@ The following function sets, modeled after the ANSI C standard, but specifying
behavior when requesting zero bytes, are available for allocating and releasing
memory from the Python heap.
-The default memory block allocator uses the following functions:
-:c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc` and :c:func:`free`; call
-``malloc(1)`` (or ``calloc(1, 1)``) when requesting zero bytes.
+By default, these functions use :ref:`pymalloc memory allocator <pymalloc>`.
.. warning::
The :term:`GIL <global interpreter lock>` must be held when using these
functions.
+.. versionchanged:: 3.6
+
+ The default allocator is now pymalloc instead of system :c:func:`malloc`.
+
.. c:function:: void* PyMem_Malloc(size_t n)
Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the
@@ -292,15 +297,32 @@ Customize Memory Allocators
Enum used to identify an allocator domain. Domains:
- * :c:data:`PYMEM_DOMAIN_RAW`: functions :c:func:`PyMem_RawMalloc`,
- :c:func:`PyMem_RawRealloc`, :c:func:`PyMem_RawCalloc` and
- :c:func:`PyMem_RawFree`
- * :c:data:`PYMEM_DOMAIN_MEM`: functions :c:func:`PyMem_Malloc`,
- :c:func:`PyMem_Realloc`, :c:func:`PyMem_Calloc` and :c:func:`PyMem_Free`
- * :c:data:`PYMEM_DOMAIN_OBJ`: functions :c:func:`PyObject_Malloc`,
- :c:func:`PyObject_Realloc`, :c:func:`PyObject_Calloc` and
- :c:func:`PyObject_Free`
+ .. c:var:: PYMEM_DOMAIN_RAW
+
+ Functions:
+
+ * :c:func:`PyMem_RawMalloc`
+ * :c:func:`PyMem_RawRealloc`
+ * :c:func:`PyMem_RawCalloc`
+ * :c:func:`PyMem_RawFree`
+
+ .. c:var:: PYMEM_DOMAIN_MEM
+
+ Functions:
+
+ * :c:func:`PyMem_Malloc`,
+ * :c:func:`PyMem_Realloc`
+ * :c:func:`PyMem_Calloc`
+ * :c:func:`PyMem_Free`
+ .. c:var:: PYMEM_DOMAIN_OBJ
+
+ Functions:
+
+ * :c:func:`PyObject_Malloc`
+ * :c:func:`PyObject_Realloc`
+ * :c:func:`PyObject_Calloc`
+ * :c:func:`PyObject_Free`
.. c:function:: void PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
@@ -325,43 +347,62 @@ Customize Memory Allocators
.. c:function:: void PyMem_SetupDebugHooks(void)
- Setup hooks to detect bugs in the following Python memory allocator
- functions:
-
- - :c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawRealloc`,
- :c:func:`PyMem_RawCalloc`, :c:func:`PyMem_RawFree`
- - :c:func:`PyMem_Malloc`, :c:func:`PyMem_Realloc`, :c:func:`PyMem_Calloc`,
- :c:func:`PyMem_Free`
- - :c:func:`PyObject_Malloc`, :c:func:`PyObject_Realloc`,
- :c:func:`PyObject_Calloc`, :c:func:`PyObject_Free`
+ Setup hooks to detect bugs in the Python memory allocator functions.
Newly allocated memory is filled with the byte ``0xCB``, freed memory is
- filled with the byte ``0xDB``. Additional checks:
+ filled with the byte ``0xDB``.
- - detect API violations, ex: :c:func:`PyObject_Free` called on a buffer
+ Runtime checks:
+
+ - Detect API violations, ex: :c:func:`PyObject_Free` called on a buffer
allocated by :c:func:`PyMem_Malloc`
- - detect write before the start of the buffer (buffer underflow)
- - detect write after the end of the buffer (buffer overflow)
+ - Detect write before the start of the buffer (buffer underflow)
+ - Detect write after the end of the buffer (buffer overflow)
+ - Check that the :term:`GIL <global interpreter lock>` is held when
+ allocator functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex:
+ :c:func:`PyObject_Malloc`) and :c:data:`PYMEM_DOMAIN_MEM` (ex:
+ :c:func:`PyMem_Malloc`) domains are called
+
+ On error, the debug hooks use the :mod:`tracemalloc` module to get the
+ traceback where a memory block was allocated. The traceback is only
+ displayed if :mod:`tracemalloc` is tracing Python memory allocations and the
+ memory block was traced.
- The function does nothing if Python is not compiled is debug mode.
+ These hooks are installed by default if Python is compiled in debug
+ mode. The :envvar:`PYTHONMALLOC` environment variable can be used to install
+ debug hooks on a Python compiled in release mode.
+ .. versionchanged:: 3.6
+ This function now also works on Python compiled in release mode.
+ On error, the debug hooks now use :mod:`tracemalloc` to get the traceback
+ where a memory block was allocated. The debug hooks now also check
+ if the GIL is held when functions of :c:data:`PYMEM_DOMAIN_OBJ` and
+ :c:data:`PYMEM_DOMAIN_MEM` domains are called.
-Customize PyObject Arena Allocator
-==================================
-Python has a *pymalloc* allocator for allocations smaller than 512 bytes. This
-allocator is optimized for small objects with a short lifetime. It uses memory
-mappings called "arenas" with a fixed size of 256 KB. It falls back to
-:c:func:`PyMem_RawMalloc` and :c:func:`PyMem_RawRealloc` for allocations larger
-than 512 bytes. *pymalloc* is the default allocator used by
-:c:func:`PyObject_Malloc`.
+.. _pymalloc:
-The default arena allocator uses the following functions:
+The pymalloc allocator
+======================
+
+Python has a *pymalloc* allocator optimized for small objects (smaller or equal
+to 512 bytes) with a short lifetime. It uses memory mappings called "arenas"
+with a fixed size of 256 KB. It falls back to :c:func:`PyMem_RawMalloc` and
+:c:func:`PyMem_RawRealloc` for allocations larger than 512 bytes.
+
+*pymalloc* is the default allocator of the :c:data:`PYMEM_DOMAIN_MEM` (ex:
+:c:func:`PyObject_Malloc`) and :c:data:`PYMEM_DOMAIN_OBJ` (ex:
+:c:func:`PyObject_Malloc`) domains.
+
+The arena allocator uses the following functions:
* :c:func:`VirtualAlloc` and :c:func:`VirtualFree` on Windows,
* :c:func:`mmap` and :c:func:`munmap` if available,
* :c:func:`malloc` and :c:func:`free` otherwise.
+Customize pymalloc Arena Allocator
+----------------------------------
+
.. versionadded:: 3.4
.. c:type:: PyObjectArenaAllocator
diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst
index cc84314..e9e8add 100644
--- a/Doc/c-api/structures.rst
+++ b/Doc/c-api/structures.rst
@@ -150,8 +150,9 @@ specific C type of the *self* object.
The :attr:`ml_flags` field is a bitfield which can include the following flags.
The individual flags indicate either a calling convention or a binding
convention. Of the calling convention flags, only :const:`METH_VARARGS` and
-:const:`METH_KEYWORDS` can be combined. Any of the calling convention flags
-can be combined with a binding flag.
+:const:`METH_KEYWORDS` can be combined (but note that :const:`METH_KEYWORDS`
+alone is equivalent to ``METH_VARARGS | METH_KEYWORDS``). Any of the calling
+convention flags can be combined with a binding flag.
.. data:: METH_VARARGS
diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst
index 3d83b27..035cdc1 100644
--- a/Doc/c-api/sys.rst
+++ b/Doc/c-api/sys.rst
@@ -5,6 +5,17 @@
Operating System Utilities
==========================
+.. c:function:: PyObject* PyOS_FSPath(PyObject *path)
+
+ Return the file system representation for *path*. If the object is a
+ :class:`str` or :class:`bytes` object, then its reference count is
+ incremented. If the object implements the :class:`os.PathLike` interface,
+ then :meth:`~os.PathLike.__fspath__` is returned as long as it is a
+ :class:`str` or :class:`bytes` object. Otherwise :exc:`TypeError` is raised
+ and ``NULL`` is returned.
+
+ .. versionadded:: 3.6
+
.. c:function:: int Py_FdIsInteractive(FILE *fp, const char *filename)
@@ -212,20 +223,24 @@ Process Control
.. c:function:: void Py_Exit(int status)
.. index::
- single: Py_Finalize()
+ single: Py_FinalizeEx()
single: exit()
- Exit the current process. This calls :c:func:`Py_Finalize` and then calls the
- standard C library function ``exit(status)``.
+ Exit the current process. This calls :c:func:`Py_FinalizeEx` and then calls the
+ standard C library function ``exit(status)``. If :c:func:`Py_FinalizeEx`
+ indicates an error, the exit status is set to 120.
+
+ .. versionchanged:: 3.6
+ Errors from finalization no longer ignored.
.. c:function:: int Py_AtExit(void (*func) ())
.. index::
- single: Py_Finalize()
+ single: Py_FinalizeEx()
single: cleanup functions
- Register a cleanup function to be called by :c:func:`Py_Finalize`. The cleanup
+ Register a cleanup function to be called by :c:func:`Py_FinalizeEx`. The cleanup
function will be called with no arguments and should return no value. At most
32 cleanup functions can be registered. When the registration is successful,
:c:func:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst
index 26831c4..f02318b 100644
--- a/Doc/c-api/unicode.rst
+++ b/Doc/c-api/unicode.rst
@@ -440,7 +440,6 @@ APIs:
.. % because not all compilers support the %z width modifier -- we fake it
.. % when necessary via interpolating PY_FORMAT_SIZE_T.
.. % Similar comments apply to the %ll width modifier and
- .. % PY_FORMAT_LONG_LONG.
.. tabularcolumns:: |l|l|L|
@@ -525,11 +524,6 @@ APIs:
copied as-is to the result string, and any extra arguments discarded.
.. note::
-
- The `"%lld"` and `"%llu"` format specifiers are only available
- when :const:`HAVE_LONG_LONG` is defined.
-
- .. note::
The width formatter unit is number of characters rather than bytes.
The precision formatter unit is number of bytes for ``"%s"`` and
``"%V"`` (if the ``PyObject*`` argument is NULL), and a number of
@@ -811,38 +805,47 @@ File System Encoding
""""""""""""""""""""
To encode and decode file names and other environment strings,
-:c:data:`Py_FileSystemEncoding` should be used as the encoding, and
-``"surrogateescape"`` should be used as the error handler (:pep:`383`). To
-encode file names during argument parsing, the ``"O&"`` converter should be
-used, passing :c:func:`PyUnicode_FSConverter` as the conversion function:
+:c:data:`Py_FileSystemDefaultEncoding` should be used as the encoding, and
+:c:data:`Py_FileSystemDefaultEncodeErrors` should be used as the error handler
+(:pep:`383` and :pep:`529`). To encode file names to :class:`bytes` during
+argument parsing, the ``"O&"`` converter should be used, passing
+:c:func:`PyUnicode_FSConverter` as the conversion function:
.. c:function:: int PyUnicode_FSConverter(PyObject* obj, void* result)
- ParseTuple converter: encode :class:`str` objects to :class:`bytes` using
+ ParseTuple converter: encode :class:`str` objects -- obtained directly or
+ through the :class:`os.PathLike` interface -- to :class:`bytes` using
:c:func:`PyUnicode_EncodeFSDefault`; :class:`bytes` objects are output as-is.
*result* must be a :c:type:`PyBytesObject*` which must be released when it is
no longer used.
.. versionadded:: 3.1
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
-To decode file names during argument parsing, the ``"O&"`` converter should be
-used, passing :c:func:`PyUnicode_FSDecoder` as the conversion function:
+To decode file names to :class:`str` during argument parsing, the ``"O&"``
+converter should be used, passing :c:func:`PyUnicode_FSDecoder` as the
+conversion function:
.. c:function:: int PyUnicode_FSDecoder(PyObject* obj, void* result)
- ParseTuple converter: decode :class:`bytes` objects to :class:`str` using
- :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str` objects are output
- as-is. *result* must be a :c:type:`PyUnicodeObject*` which must be released
- when it is no longer used.
+ ParseTuple converter: decode :class:`bytes` objects -- obtained either
+ directly or indirectly through the :class:`os.PathLike` interface -- to
+ :class:`str` using :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str`
+ objects are output as-is. *result* must be a :c:type:`PyUnicodeObject*` which
+ must be released when it is no longer used.
.. versionadded:: 3.2
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. c:function:: PyObject* PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
Decode a string using :c:data:`Py_FileSystemDefaultEncoding` and the
- ``"surrogateescape"`` error handler, or ``"strict"`` on Windows.
+ :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
locale encoding.
@@ -856,28 +859,28 @@ used, passing :c:func:`PyUnicode_FSDecoder` as the conversion function:
The :c:func:`Py_DecodeLocale` function.
- .. versionchanged:: 3.2
- Use ``"strict"`` error handler on Windows.
+ .. versionchanged:: 3.6
+ Use :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
.. c:function:: PyObject* PyUnicode_DecodeFSDefault(const char *s)
Decode a null-terminated string using :c:data:`Py_FileSystemDefaultEncoding`
- and the ``"surrogateescape"`` error handler, or ``"strict"`` on Windows.
+ and the :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
locale encoding.
Use :c:func:`PyUnicode_DecodeFSDefaultAndSize` if you know the string length.
- .. versionchanged:: 3.2
- Use ``"strict"`` error handler on Windows.
+ .. versionchanged:: 3.6
+ Use :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
.. c:function:: PyObject* PyUnicode_EncodeFSDefault(PyObject *unicode)
Encode a Unicode object to :c:data:`Py_FileSystemDefaultEncoding` with the
- ``"surrogateescape"`` error handler, or ``"strict"`` on Windows, and return
+ :c:data:`Py_FileSystemDefaultEncodeErrors` error handler, and return
:class:`bytes`. Note that the resulting :class:`bytes` object may contain
null bytes.
@@ -894,6 +897,8 @@ used, passing :c:func:`PyUnicode_FSDecoder` as the conversion function:
.. versionadded:: 3.2
+ .. versionchanged:: 3.6
+ Use :c:data:`Py_FileSystemDefaultEncodeErrors` error handler.
wchar_t Support
"""""""""""""""
diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat
index e388195..8b469f4 100644
--- a/Doc/data/refcounts.dat
+++ b/Doc/data/refcounts.dat
@@ -921,6 +921,9 @@ PyNumber_Xor:PyObject*:o2:0:
PyObject_AsFileDescriptor:int:::
PyObject_AsFileDescriptor:PyObject*:o:0:
+PyOS_FSPath:PyObject*::+1:
+PyOS_FSPath:PyObject*:path:0:
+
PyObject_Call:PyObject*::+1:
PyObject_Call:PyObject*:callable_object:0:
PyObject_Call:PyObject*:args:0:
diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst
index 64033dc..ab2f616 100644
--- a/Doc/extending/embedding.rst
+++ b/Doc/extending/embedding.rst
@@ -67,7 +67,9 @@ perform some operation on a file. ::
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
- Py_Finalize();
+ if (Py_FinalizeEx() < 0) {
+ exit(120);
+ }
PyMem_RawFree(program);
return 0;
}
@@ -76,7 +78,7 @@ The :c:func:`Py_SetProgramName` function should be called before
:c:func:`Py_Initialize` to inform the interpreter about paths to Python run-time
libraries. Next, the Python interpreter is initialized with
:c:func:`Py_Initialize`, followed by the execution of a hard-coded Python script
-that prints the date and time. Afterwards, the :c:func:`Py_Finalize` call shuts
+that prints the date and time. Afterwards, the :c:func:`Py_FinalizeEx` call shuts
the interpreter down, followed by the end of the program. In a real program,
you may want to get the Python script from another source, perhaps a text-editor
routine, a file, or a database. Getting the Python code from a file can better
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 694753e..9c5e20d 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -838,7 +838,8 @@ How do I convert a number to a string?
To convert, e.g., the number 144 to the string '144', use the built-in type
constructor :func:`str`. If you want a hexadecimal or octal representation, use
the built-in functions :func:`hex` or :func:`oct`. For fancy formatting, see
-the :ref:`formatstrings` section, e.g. ``"{:04d}".format(144)`` yields
+the :ref:`f-strings` and :ref:`formatstrings` sections,
+e.g. ``"{:04d}".format(144)`` yields
``'0144'`` and ``"{:.3f}".format(1.0/3.0)`` yields ``'0.333'``.
diff --git a/Doc/glossary.rst b/Doc/glossary.rst
index 45b794f..f80b6df 100644
--- a/Doc/glossary.rst
+++ b/Doc/glossary.rst
@@ -718,6 +718,8 @@ Glossary
def func(foo, bar=None): ...
+ .. _positional-only_parameter:
+
* :dfn:`positional-only`: specifies an argument that can be supplied only
by position. Python has no syntax for defining positional-only
parameters. However, some built-in functions have positional-only
@@ -776,6 +778,16 @@ Glossary
One of the default :term:`meta path finders <meta path finder>` which
searches an :term:`import path` for modules.
+ path-like object
+ An object representing a file system path. A path-like object is either
+ a :class:`str` or :class:`bytes` object representing a path, or an object
+ implementing the :class:`os.PathLike` protocol. An object that supports
+ the :class:`os.PathLike` protocol can be converted to a :class:`str` or
+ :class:`bytes` file system path by calling the :func:`os.fspath` function;
+ :func:`os.fsdecode` and :func:`os.fsencode` can be used to guarantee a
+ :class:`str` or :class:`bytes` result instead, respectively. Introduced
+ by :pep:`519`.
+
portion
A set of files in a single directory (possibly stored in a zip file)
that contribute to a namespace package, as defined in :pep:`420`.
@@ -952,13 +964,25 @@ Glossary
``'\r'``. See :pep:`278` and :pep:`3116`, as well as
:func:`bytes.splitlines` for an additional use.
+ variable annotation
+ A type metadata value associated with a module global variable or
+ a class attribute. Its syntax is explained in section :ref:`annassign`.
+ Annotations are stored in the :attr:`__annotations__` special
+ attribute of a class or module object and can be accessed using
+ :func:`typing.get_type_hints`.
+
+ Python itself does not assign any particular meaning to variable
+ annotations. They are intended to be interpreted by third-party libraries
+ or type checking tools. See :pep:`526`, :pep:`484` which describe
+ some of their potential uses.
+
virtual environment
A cooperatively isolated runtime environment that allows Python users
and applications to install and upgrade Python distribution packages
without interfering with the behaviour of other Python applications
running on the same system.
- See also :ref:`scripts-pyvenv`.
+ See also :mod:`venv`.
virtual machine
A computer defined entirely in software. Python's virtual machine
diff --git a/Doc/howto/argparse.rst b/Doc/howto/argparse.rst
index 3b79b92..7e161a5 100644
--- a/Doc/howto/argparse.rst
+++ b/Doc/howto/argparse.rst
@@ -547,7 +547,8 @@ And this is what it gives:
Traceback (most recent call last):
File "prog.py", line 11, in <module>
if args.verbosity >= 2:
- TypeError: unorderable types: NoneType() >= int()
+ TypeError: '>=' not supported between instances of 'NoneType' and 'int'
+
* First output went well, and fixes the bug we had before.
That is, we want any value >= 2 to be as verbose as possible.
diff --git a/Doc/howto/clinic.rst b/Doc/howto/clinic.rst
index caa4975..f435884 100644
--- a/Doc/howto/clinic.rst
+++ b/Doc/howto/clinic.rst
@@ -827,9 +827,9 @@ on the right is the text you'd replace it with.
``'i'`` ``int``
``'I'`` ``unsigned_int(bitwise=True)``
``'k'`` ``unsigned_long(bitwise=True)``
-``'K'`` ``unsigned_PY_LONG_LONG(bitwise=True)``
+``'K'`` ``unsigned_long_long(bitwise=True)``
``'l'`` ``long``
-``'L'`` ``PY_LONG_LONG``
+``'L'`` ``long long``
``'n'`` ``Py_ssize_t``
``'O'`` ``object``
``'O!'`` ``object(subclass_of='&PySomething_Type')``
diff --git a/Doc/howto/index.rst b/Doc/howto/index.rst
index de65950..593341c 100644
--- a/Doc/howto/index.rst
+++ b/Doc/howto/index.rst
@@ -28,4 +28,5 @@ Currently, the HOWTOs are:
argparse.rst
ipaddress.rst
clinic.rst
+ instrumentation.rst
diff --git a/Doc/howto/instrumentation.rst b/Doc/howto/instrumentation.rst
new file mode 100644
index 0000000..621a608
--- /dev/null
+++ b/Doc/howto/instrumentation.rst
@@ -0,0 +1,411 @@
+.. _instrumentation:
+
+===============================================
+Instrumenting CPython with DTrace and SystemTap
+===============================================
+
+:author: David Malcolm
+:author: Łukasz Langa
+
+DTrace and SystemTap are monitoring tools, each providing a way to inspect
+what the processes on a computer system are doing. They both use
+domain-specific languages allowing a user to write scripts which:
+
+ - filter which processes are to be observed
+ - gather data from the processes of interest
+ - generate reports on the data
+
+As of Python 3.6, CPython can be built with embedded "markers", also
+known as "probes", that can be observed by a DTrace or SystemTap script,
+making it easier to monitor what the CPython processes on a system are
+doing.
+
+.. I'm using ".. code-block:: c" for SystemTap scripts, as "c" is syntactically
+ the closest match that Sphinx supports
+
+.. impl-detail::
+
+ DTrace markers are implementation details of the CPython interpreter.
+ No guarantees are made about probe compatibility between versions of
+ CPython. DTrace scripts can stop working or work incorrectly without
+ warning when changing CPython versions.
+
+
+Enabling the static markers
+---------------------------
+
+macOS comes with built-in support for DTrace. On Linux, in order to
+build CPython with the embedded markers for SystemTap, the SystemTap
+development tools must be installed.
+
+On a Linux machine, this can be done via::
+
+ yum install systemtap-sdt-devel
+
+or::
+
+ sudo apt-get install systemtap-sdt-dev
+
+
+CPython must then be configured `--with-dtrace`::
+
+ checking for --with-dtrace... yes
+
+On macOS, you can list available DTrace probes by running a Python
+process in the background and listing all probes made available by the
+Python provider::
+
+ $ python3.6 -q &
+ $ sudo dtrace -l -P python$! # or: dtrace -l -m python3.6
+
+ ID PROVIDER MODULE FUNCTION NAME
+ 29564 python18035 python3.6 _PyEval_EvalFrameDefault function-entry
+ 29565 python18035 python3.6 dtrace_function_entry function-entry
+ 29566 python18035 python3.6 _PyEval_EvalFrameDefault function-return
+ 29567 python18035 python3.6 dtrace_function_return function-return
+ 29568 python18035 python3.6 collect gc-done
+ 29569 python18035 python3.6 collect gc-start
+ 29570 python18035 python3.6 _PyEval_EvalFrameDefault line
+ 29571 python18035 python3.6 maybe_dtrace_line line
+
+On Linux, you can verify if the SystemTap static markers are present in
+the built binary by seeing if it contains a ".note.stapsdt" section.
+
+.. code-block:: bash
+
+ $ readelf -S ./python | grep .note.stapsdt
+ [30] .note.stapsdt NOTE 0000000000000000 00308d78
+
+If you've built Python as a shared library (with --enable-shared), you
+need to look instead within the shared library. For example:
+
+.. code-block:: bash
+
+ $ readelf -S libpython3.3dm.so.1.0 | grep .note.stapsdt
+ [29] .note.stapsdt NOTE 0000000000000000 00365b68
+
+Sufficiently modern readelf can print the metadata:
+
+.. code-block:: bash
+
+ $ readelf -n ./python
+
+ Displaying notes found at file offset 0x00000254 with length 0x00000020:
+ Owner Data size Description
+ GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
+ OS: Linux, ABI: 2.6.32
+
+ Displaying notes found at file offset 0x00000274 with length 0x00000024:
+ Owner Data size Description
+ GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)
+ Build ID: df924a2b08a7e89f6e11251d4602022977af2670
+
+ Displaying notes found at file offset 0x002d6c30 with length 0x00000144:
+ Owner Data size Description
+ stapsdt 0x00000031 NT_STAPSDT (SystemTap probe descriptors)
+ Provider: python
+ Name: gc__start
+ Location: 0x00000000004371c3, Base: 0x0000000000630ce2, Semaphore: 0x00000000008d6bf6
+ Arguments: -4@%ebx
+ stapsdt 0x00000030 NT_STAPSDT (SystemTap probe descriptors)
+ Provider: python
+ Name: gc__done
+ Location: 0x00000000004374e1, Base: 0x0000000000630ce2, Semaphore: 0x00000000008d6bf8
+ Arguments: -8@%rax
+ stapsdt 0x00000045 NT_STAPSDT (SystemTap probe descriptors)
+ Provider: python
+ Name: function__entry
+ Location: 0x000000000053db6c, Base: 0x0000000000630ce2, Semaphore: 0x00000000008d6be8
+ Arguments: 8@%rbp 8@%r12 -4@%eax
+ stapsdt 0x00000046 NT_STAPSDT (SystemTap probe descriptors)
+ Provider: python
+ Name: function__return
+ Location: 0x000000000053dba8, Base: 0x0000000000630ce2, Semaphore: 0x00000000008d6bea
+ Arguments: 8@%rbp 8@%r12 -4@%eax
+
+The above metadata contains information for SystemTap describing how it
+can patch strategically-placed machine code instructions to enable the
+tracing hooks used by a SystemTap script.
+
+
+Static DTrace probes
+--------------------
+
+The following example DTrace script can be used to show the call/return
+hierarchy of a Python script, only tracing within the invocation of
+a function called "start". In other words, import-time function
+invocations are not going to be listed:
+
+.. code-block:: c
+
+ self int indent;
+
+ python$target:::function-entry
+ /copyinstr(arg1) == "start"/
+ {
+ self->trace = 1;
+ }
+
+ python$target:::function-entry
+ /self->trace/
+ {
+ printf("%d\t%*s:", timestamp, 15, probename);
+ printf("%*s", self->indent, "");
+ printf("%s:%s:%d\n", basename(copyinstr(arg0)), copyinstr(arg1), arg2);
+ self->indent++;
+ }
+
+ python$target:::function-return
+ /self->trace/
+ {
+ self->indent--;
+ printf("%d\t%*s:", timestamp, 15, probename);
+ printf("%*s", self->indent, "");
+ printf("%s:%s:%d\n", basename(copyinstr(arg0)), copyinstr(arg1), arg2);
+ }
+
+ python$target:::function-return
+ /copyinstr(arg1) == "start"/
+ {
+ self->trace = 0;
+ }
+
+It can be invoked like this:
+
+.. code-block:: bash
+
+ $ sudo dtrace -q -s call_stack.d -c "python3.6 script.py"
+
+The output looks like this::
+
+ 156641360502280 function-entry:call_stack.py:start:23
+ 156641360518804 function-entry: call_stack.py:function_1:1
+ 156641360532797 function-entry: call_stack.py:function_3:9
+ 156641360546807 function-return: call_stack.py:function_3:10
+ 156641360563367 function-return: call_stack.py:function_1:2
+ 156641360578365 function-entry: call_stack.py:function_2:5
+ 156641360591757 function-entry: call_stack.py:function_1:1
+ 156641360605556 function-entry: call_stack.py:function_3:9
+ 156641360617482 function-return: call_stack.py:function_3:10
+ 156641360629814 function-return: call_stack.py:function_1:2
+ 156641360642285 function-return: call_stack.py:function_2:6
+ 156641360656770 function-entry: call_stack.py:function_3:9
+ 156641360669707 function-return: call_stack.py:function_3:10
+ 156641360687853 function-entry: call_stack.py:function_4:13
+ 156641360700719 function-return: call_stack.py:function_4:14
+ 156641360719640 function-entry: call_stack.py:function_5:18
+ 156641360732567 function-return: call_stack.py:function_5:21
+ 156641360747370 function-return:call_stack.py:start:28
+
+
+Static SystemTap markers
+------------------------
+
+The low-level way to use the SystemTap integration is to use the static
+markers directly. This requires you to explicitly state the binary file
+containing them.
+
+For example, this SystemTap script can be used to show the call/return
+hierarchy of a Python script:
+
+.. code-block:: c
+
+ probe process("python").mark("function__entry") {
+ filename = user_string($arg1);
+ funcname = user_string($arg2);
+ lineno = $arg3;
+
+ printf("%s => %s in %s:%d\\n",
+ thread_indent(1), funcname, filename, lineno);
+ }
+
+ probe process("python").mark("function__return") {
+ filename = user_string($arg1);
+ funcname = user_string($arg2);
+ lineno = $arg3;
+
+ printf("%s <= %s in %s:%d\\n",
+ thread_indent(-1), funcname, filename, lineno);
+ }
+
+It can be invoked like this:
+
+.. code-block:: bash
+
+ $ stap \
+ show-call-hierarchy.stp \
+ -c "./python test.py"
+
+The output looks like this::
+
+ 11408 python(8274): => __contains__ in Lib/_abcoll.py:362
+ 11414 python(8274): => __getitem__ in Lib/os.py:425
+ 11418 python(8274): => encode in Lib/os.py:490
+ 11424 python(8274): <= encode in Lib/os.py:493
+ 11428 python(8274): <= __getitem__ in Lib/os.py:426
+ 11433 python(8274): <= __contains__ in Lib/_abcoll.py:366
+
+where the columns are:
+
+ - time in microseconds since start of script
+
+ - name of executable
+
+ - PID of process
+
+and the remainder indicates the call/return hierarchy as the script executes.
+
+For a `--enable-shared` build of CPython, the markers are contained within the
+libpython shared library, and the probe's dotted path needs to reflect this. For
+example, this line from the above example::
+
+ probe process("python").mark("function__entry") {
+
+should instead read::
+
+ probe process("python").library("libpython3.6dm.so.1.0").mark("function__entry") {
+
+(assuming a debug build of CPython 3.6)
+
+
+Available static markers
+------------------------
+
+.. I'm reusing the "c:function" type for markers
+
+.. c:function:: function__entry(str filename, str funcname, int lineno)
+
+ This marker indicates that execution of a Python function has begun.
+ It is only triggered for pure-Python (bytecode) functions.
+
+ The filename, function name, and line number are provided back to the
+ tracing script as positional arguments, which must be accessed using
+ ``$arg1``, ``$arg2``, ``$arg3``:
+
+ * ``$arg1`` : ``(const char *)`` filename, accessible using ``user_string($arg1)``
+
+ * ``$arg2`` : ``(const char *)`` function name, accessible using
+ ``user_string($arg2)``
+
+ * ``$arg3`` : ``int`` line number
+
+.. c:function:: function__return(str filename, str funcname, int lineno)
+
+ This marker is the converse of :c:func:`function__entry`, and indicates that
+ execution of a Python function has ended (either via ``return``, or via an
+ exception). It is only triggered for pure-Python (bytecode) functions.
+
+ The arguments are the same as for :c:func:`function__entry`
+
+.. c:function:: line(str filename, str funcname, int lineno)
+
+ This marker indicates a Python line is about to be executed. It is
+ the equivalent of line-by-line tracing with a Python profiler. It is
+ not triggered within C functions.
+
+ The arguments are the same as for :c:func:`function__entry`.
+
+.. c:function:: gc__start(int generation)
+
+ Fires when the Python interpreter starts a garbage collection cycle.
+ ``arg0`` is the generation to scan, like :func:`gc.collect()`.
+
+.. c:function:: gc__done(long collected)
+
+ Fires when the Python interpreter finishes a garbage collection
+ cycle. ``arg0`` is the number of collected objects.
+
+
+SystemTap Tapsets
+-----------------
+
+The higher-level way to use the SystemTap integration is to use a "tapset":
+SystemTap's equivalent of a library, which hides some of the lower-level
+details of the static markers.
+
+Here is a tapset file, based on a non-shared build of CPython:
+
+.. code-block:: c
+
+ /*
+ Provide a higher-level wrapping around the function__entry and
+ function__return markers:
+ \*/
+ probe python.function.entry = process("python").mark("function__entry")
+ {
+ filename = user_string($arg1);
+ funcname = user_string($arg2);
+ lineno = $arg3;
+ frameptr = $arg4
+ }
+ probe python.function.return = process("python").mark("function__return")
+ {
+ filename = user_string($arg1);
+ funcname = user_string($arg2);
+ lineno = $arg3;
+ frameptr = $arg4
+ }
+
+If this file is installed in SystemTap's tapset directory (e.g.
+``/usr/share/systemtap/tapset``), then these additional probepoints become
+available:
+
+.. c:function:: python.function.entry(str filename, str funcname, int lineno, frameptr)
+
+ This probe point indicates that execution of a Python function has begun.
+ It is only triggered for pure-python (bytecode) functions.
+
+.. c:function:: python.function.return(str filename, str funcname, int lineno, frameptr)
+
+ This probe point is the converse of :c:func:`python.function.return`, and
+ indicates that execution of a Python function has ended (either via
+ ``return``, or via an exception). It is only triggered for pure-python
+ (bytecode) functions.
+
+
+Examples
+--------
+This SystemTap script uses the tapset above to more cleanly implement the
+example given above of tracing the Python function-call hierarchy, without
+needing to directly name the static markers:
+
+.. code-block:: c
+
+ probe python.function.entry
+ {
+ printf("%s => %s in %s:%d\n",
+ thread_indent(1), funcname, filename, lineno);
+ }
+
+ probe python.function.return
+ {
+ printf("%s <= %s in %s:%d\n",
+ thread_indent(-1), funcname, filename, lineno);
+ }
+
+
+The following script uses the tapset above to provide a top-like view of all
+running CPython code, showing the top 20 most frequently-entered bytecode
+frames, each second, across the whole system:
+
+.. code-block:: c
+
+ global fn_calls;
+
+ probe python.function.entry
+ {
+ fn_calls[pid(), filename, funcname, lineno] += 1;
+ }
+
+ probe timer.ms(1000) {
+ printf("\033[2J\033[1;1H") /* clear screen \*/
+ printf("%6s %80s %6s %30s %6s\n",
+ "PID", "FILENAME", "LINE", "FUNCTION", "CALLS")
+ foreach ([pid, filename, funcname, lineno] in fn_calls- limit 20) {
+ printf("%6d %80s %6d %30s %6d\n",
+ pid, filename, lineno, funcname,
+ fn_calls[pid, filename, funcname, lineno]);
+ }
+ delete fn_calls;
+ }
+
diff --git a/Doc/includes/email-alternative-new-api.py b/Doc/includes/email-alternative-new-api.py
deleted file mode 100644
index 321f727..0000000
--- a/Doc/includes/email-alternative-new-api.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/env python3
-
-import smtplib
-
-from email.message import EmailMessage
-from email.headerregistry import Address
-from email.utils import make_msgid
-
-# Create the base text message.
-msg = EmailMessage()
-msg['Subject'] = "Ayons asperges pour le déjeuner"
-msg['From'] = Address("Pepé Le Pew", "pepe", "example.com")
-msg['To'] = (Address("Penelope Pussycat", "penelope", "example.com"),
- Address("Fabrette Pussycat", "fabrette", "example.com"))
-msg.set_content("""\
-Salut!
-
-Cela ressemble à un excellent recipie[1] déjeuner.
-
-[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718
-
---Pepé
-""")
-
-# Add the html version. This converts the message into a multipart/alternative
-# container, with the original text message as the first part and the new html
-# message as the second part.
-asparagus_cid = make_msgid()
-msg.add_alternative("""\
-<html>
- <head></head>
- <body>
- <p>Salut!<\p>
- <p>Cela ressemble à un excellent
- <a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718>
- recipie
- </a> déjeuner.
- </p>
- <img src="cid:{asparagus_cid}" \>
- </body>
-</html>
-""".format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
-# note that we needed to peel the <> off the msgid for use in the html.
-
-# Now add the related image to the html part.
-with open("roasted-asparagus.jpg", 'rb') as img:
- msg.get_payload()[1].add_related(img.read(), 'image', 'jpeg',
- cid=asparagus_cid)
-
-# Make a local copy of what we are going to send.
-with open('outgoing.msg', 'wb') as f:
- f.write(bytes(msg))
-
-# Send the message via local SMTP server.
-with smtplib.SMTP('localhost') as s:
- s.send_message(msg)
diff --git a/Doc/includes/email-alternative.py b/Doc/includes/email-alternative.py
index 85070f3..2e142b1 100755..100644
--- a/Doc/includes/email-alternative.py
+++ b/Doc/includes/email-alternative.py
@@ -2,47 +2,55 @@
import smtplib
-from email.mime.multipart import MIMEMultipart
-from email.mime.text import MIMEText
-
-# me == my email address
-# you == recipient's email address
-me = "my@email.com"
-you = "your@email.com"
-
-# Create message container - the correct MIME type is multipart/alternative.
-msg = MIMEMultipart('alternative')
-msg['Subject'] = "Link"
-msg['From'] = me
-msg['To'] = you
-
-# Create the body of the message (a plain-text and an HTML version).
-text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttps://www.python.org"
-html = """\
+from email.message import EmailMessage
+from email.headerregistry import Address
+from email.utils import make_msgid
+
+# Create the base text message.
+msg = EmailMessage()
+msg['Subject'] = "Ayons asperges pour le déjeuner"
+msg['From'] = Address("Pepé Le Pew", "pepe", "example.com")
+msg['To'] = (Address("Penelope Pussycat", "penelope", "example.com"),
+ Address("Fabrette Pussycat", "fabrette", "example.com"))
+msg.set_content("""\
+Salut!
+
+Cela ressemble à un excellent recipie[1] déjeuner.
+
+[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718
+
+--Pepé
+""")
+
+# Add the html version. This converts the message into a multipart/alternative
+# container, with the original text message as the first part and the new html
+# message as the second part.
+asparagus_cid = make_msgid()
+msg.add_alternative("""\
<html>
<head></head>
<body>
- <p>Hi!<br>
- How are you?<br>
- Here is the <a href="https://www.python.org">link</a> you wanted.
+ <p>Salut!</p>
+ <p>Cela ressemble à un excellent
+ <a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718>
+ recipie
+ </a> déjeuner.
</p>
+ <img src="cid:{asparagus_cid}" />
</body>
</html>
-"""
+""".format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
+# note that we needed to peel the <> off the msgid for use in the html.
-# Record the MIME types of both parts - text/plain and text/html.
-part1 = MIMEText(text, 'plain')
-part2 = MIMEText(html, 'html')
+# Now add the related image to the html part.
+with open("roasted-asparagus.jpg", 'rb') as img:
+ msg.get_payload()[1].add_related(img.read(), 'image', 'jpeg',
+ cid=asparagus_cid)
-# Attach parts into message container.
-# According to RFC 2046, the last part of a multipart message, in this case
-# the HTML message, is best and preferred.
-msg.attach(part1)
-msg.attach(part2)
+# Make a local copy of what we are going to send.
+with open('outgoing.msg', 'wb') as f:
+ f.write(bytes(msg))
# Send the message via local SMTP server.
-s = smtplib.SMTP('localhost')
-# sendmail function takes 3 arguments: sender's address, recipient's address
-# and message to send - here it is sent as one string.
-s.sendmail(me, you, msg.as_string())
-s.quit()
+with smtplib.SMTP('localhost') as s:
+ s.send_message(msg)
diff --git a/Doc/includes/email-dir.py b/Doc/includes/email-dir.py
index 3c7c770..0dcfbfb 100644
--- a/Doc/includes/email-dir.py
+++ b/Doc/includes/email-dir.py
@@ -3,22 +3,14 @@
"""Send the contents of a directory as a MIME message."""
import os
-import sys
import smtplib
# For guessing MIME type based on file name extension
import mimetypes
from argparse import ArgumentParser
-from email import encoders
-from email.message import Message
-from email.mime.audio import MIMEAudio
-from email.mime.base import MIMEBase
-from email.mime.image import MIMEImage
-from email.mime.multipart import MIMEMultipart
-from email.mime.text import MIMEText
-
-COMMASPACE = ', '
+from email.message import EmailMessage
+from email.policy import SMTP
def main():
@@ -47,12 +39,12 @@ must be running an SMTP server.
directory = args.directory
if not directory:
directory = '.'
- # Create the enclosing (outer) message
- outer = MIMEMultipart()
- outer['Subject'] = 'Contents of directory %s' % os.path.abspath(directory)
- outer['To'] = COMMASPACE.join(args.recipients)
- outer['From'] = args.sender
- outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
+ # Create the message
+ msg = EmailMessage()
+ msg['Subject'] = 'Contents of directory %s' % os.path.abspath(directory)
+ msg['To'] = ', '.join(args.recipients)
+ msg['From'] = args.sender
+ msg.preamble = 'You will not see this in a MIME-aware mail reader.\n'
for filename in os.listdir(directory):
path = os.path.join(directory, filename)
@@ -67,33 +59,18 @@ must be running an SMTP server.
# use a generic bag-of-bits type.
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
- if maintype == 'text':
- with open(path) as fp:
- # Note: we should handle calculating the charset
- msg = MIMEText(fp.read(), _subtype=subtype)
- elif maintype == 'image':
- with open(path, 'rb') as fp:
- msg = MIMEImage(fp.read(), _subtype=subtype)
- elif maintype == 'audio':
- with open(path, 'rb') as fp:
- msg = MIMEAudio(fp.read(), _subtype=subtype)
- else:
- with open(path, 'rb') as fp:
- msg = MIMEBase(maintype, subtype)
- msg.set_payload(fp.read())
- # Encode the payload using Base64
- encoders.encode_base64(msg)
- # Set the filename parameter
- msg.add_header('Content-Disposition', 'attachment', filename=filename)
- outer.attach(msg)
+ with open(path, 'rb') as fp:
+ msg.add_attachment(fp.read(),
+ maintype=maintype,
+ subtype=subtype,
+ filename=filename)
# Now send or store the message
- composed = outer.as_string()
if args.output:
- with open(args.output, 'w') as fp:
- fp.write(composed)
+ with open(args.output, 'wb') as fp:
+ fp.write(msg.as_bytes(policy=SMTP))
else:
with smtplib.SMTP('localhost') as s:
- s.sendmail(args.sender, args.recipients, composed)
+ s.send_message(msg)
if __name__ == '__main__':
diff --git a/Doc/includes/email-headers.py b/Doc/includes/email-headers.py
index 89c8f3a..2c42145 100644
--- a/Doc/includes/email-headers.py
+++ b/Doc/includes/email-headers.py
@@ -1,18 +1,24 @@
# Import the email modules we'll need
-from email.parser import Parser
+from email.parser import BytesParser, Parser
+from email.policy import default
# If the e-mail headers are in a file, uncomment these two lines:
-# with open(messagefile) as fp:
-# headers = Parser().parse(fp)
+# with open(messagefile, 'rb') as fp:
+# headers = BytesParser(policy=default).parse(fp)
-# Or for parsing headers in a string, use:
-headers = Parser().parsestr('From: <user@example.com>\n'
+# Or for parsing headers in a string (this is an uncommon operation), use:
+headers = Parser(policy=default).parsestr(
+ 'From: Foo Bar <user@example.com>\n'
'To: <someone_else@example.com>\n'
'Subject: Test message\n'
'\n'
'Body would go here\n')
# Now the header items can be accessed as a dictionary:
-print('To: %s' % headers['to'])
-print('From: %s' % headers['from'])
-print('Subject: %s' % headers['subject'])
+print('To: {}'.format(headers['to']))
+print('From: {}'.format(headers['from']))
+print('Subject: {}'.format(headers['subject']))
+
+# You can also access the parts of the addresses:
+print('Recipient username: {}'.format(headers['to'].addresses[0].username))
+print('Sender name: {}'.format(headers['from'].addresses[0].display_name))
diff --git a/Doc/includes/email-mime.py b/Doc/includes/email-mime.py
index 61d0830..c610242 100644
--- a/Doc/includes/email-mime.py
+++ b/Doc/includes/email-mime.py
@@ -1,30 +1,29 @@
# Import smtplib for the actual sending function
import smtplib
-# Here are the email package modules we'll need
-from email.mime.image import MIMEImage
-from email.mime.multipart import MIMEMultipart
+# And imghdr to find the types of our images
+import imghdr
-COMMASPACE = ', '
+# Here are the email package modules we'll need
+from email.message import EmailMessage
-# Create the container (outer) email message.
-msg = MIMEMultipart()
+# Create the container email message.
+msg = EmailMessage()
msg['Subject'] = 'Our family reunion'
# me == the sender's email address
# family = the list of all recipients' email addresses
msg['From'] = me
-msg['To'] = COMMASPACE.join(family)
+msg['To'] = ', '.join(family)
msg.preamble = 'Our family reunion'
-# Assume we know that the image files are all in PNG format
+# Open the files in binary mode. Use imghdr to figure out the
+# MIME subtype for each specific image.
for file in pngfiles:
- # Open the files in binary mode. Let the MIMEImage class automatically
- # guess the specific image type.
with open(file, 'rb') as fp:
- img = MIMEImage(fp.read())
- msg.attach(img)
+ img_data = fp.read()
+ msg.add_attachment(img_data, maintype='image',
+ subtype=imghdr.what(None, img_data))
# Send the email via our own SMTP server.
-s = smtplib.SMTP('localhost')
-s.send_message(msg)
-s.quit()
+with smtplib.SMTP('localhost') as s:
+ s.send_message(msg)
diff --git a/Doc/includes/email-read-alternative-new-api.py b/Doc/includes/email-read-alternative.py
index 3f5ab24..3f5ab24 100644
--- a/Doc/includes/email-read-alternative-new-api.py
+++ b/Doc/includes/email-read-alternative.py
diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py
index b9b8b41..f69ef40 100644
--- a/Doc/includes/email-simple.py
+++ b/Doc/includes/email-simple.py
@@ -2,13 +2,13 @@
import smtplib
# Import the email modules we'll need
-from email.mime.text import MIMEText
+from email.message import EmailMessage
-# Open a plain text file for reading. For this example, assume that
-# the text file contains only ASCII characters.
+# Open the plain text file whose name is in textfile for reading.
with open(textfile) as fp:
# Create a text/plain message
- msg = MIMEText(fp.read())
+ msg = EmailMessage()
+ msg.set_content(fp.read())
# me == the sender's email address
# you == the recipient's email address
diff --git a/Doc/includes/email-unpack.py b/Doc/includes/email-unpack.py
index 574a0b6..e0a7f01 100644
--- a/Doc/includes/email-unpack.py
+++ b/Doc/includes/email-unpack.py
@@ -3,11 +3,11 @@
"""Unpack a MIME message into a directory of files."""
import os
-import sys
import email
-import errno
import mimetypes
+from email.policy import default
+
from argparse import ArgumentParser
@@ -22,8 +22,8 @@ Unpack a MIME message into a directory of files.
parser.add_argument('msgfile')
args = parser.parse_args()
- with open(args.msgfile) as fp:
- msg = email.message_from_file(fp)
+ with open(args.msgfile, 'rb') as fp:
+ msg = email.message_from_binary_file(fp, policy=default)
try:
os.mkdir(args.directory)
diff --git a/Doc/includes/run-func.c b/Doc/includes/run-func.c
index 986d670..ead7bdd 100644
--- a/Doc/includes/run-func.c
+++ b/Doc/includes/run-func.c
@@ -63,6 +63,8 @@ main(int argc, char *argv[])
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
return 1;
}
- Py_Finalize();
+ if (Py_FinalizeEx() < 0) {
+ return 120;
+ }
return 0;
}
diff --git a/Doc/includes/test.py b/Doc/includes/test.py
index 7ebf46a..9e9d4a6 100644
--- a/Doc/includes/test.py
+++ b/Doc/includes/test.py
@@ -204,7 +204,7 @@ Test cyclic gc(?)
import os
import sys
from distutils.util import get_platform
-PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
+PLAT_SPEC = "%s-%d.%d" % (get_platform(), *sys.version_info[:2])
src = os.path.join("build", "lib.%s" % PLAT_SPEC)
sys.path.append(src)
diff --git a/Doc/includes/tzinfo-examples.py b/Doc/includes/tzinfo-examples.py
index 3a8cf47..ae5a509 100644
--- a/Doc/includes/tzinfo-examples.py
+++ b/Doc/includes/tzinfo-examples.py
@@ -1,46 +1,13 @@
-from datetime import tzinfo, timedelta, datetime
+from datetime import tzinfo, timedelta, datetime, timezone
ZERO = timedelta(0)
HOUR = timedelta(hours=1)
-
-# A UTC class.
-
-class UTC(tzinfo):
- """UTC"""
-
- def utcoffset(self, dt):
- return ZERO
-
- def tzname(self, dt):
- return "UTC"
-
- def dst(self, dt):
- return ZERO
-
-utc = UTC()
-
-# A class building tzinfo objects for fixed-offset time zones.
-# Note that FixedOffset(0, "UTC") is a different way to build a
-# UTC tzinfo object.
-
-class FixedOffset(tzinfo):
- """Fixed offset in minutes east from UTC."""
-
- def __init__(self, offset, name):
- self.__offset = timedelta(minutes=offset)
- self.__name = name
-
- def utcoffset(self, dt):
- return self.__offset
-
- def tzname(self, dt):
- return self.__name
-
- def dst(self, dt):
- return ZERO
+SECOND = timedelta(seconds=1)
# A class capturing the platform's idea of local time.
-
+# (May result in wrong values on historical times in
+# timezones where UTC offset and/or the DST rules had
+# changed in the past.)
import time as _time
STDOFFSET = timedelta(seconds = -_time.timezone)
@@ -53,6 +20,16 @@ DSTDIFF = DSTOFFSET - STDOFFSET
class LocalTimezone(tzinfo):
+ def fromutc(self, dt):
+ assert dt.tzinfo is self
+ stamp = (dt - datetime(1970, 1, 1, tzinfo=self)) // SECOND
+ args = _time.localtime(stamp)[:6]
+ dst_diff = DSTDIFF // SECOND
+ # Detect fold
+ fold = (args == _time.localtime(stamp - dst_diff))
+ return datetime(*args, microsecond=dt.microsecond,
+ tzinfo=self, fold=fold)
+
def utcoffset(self, dt):
if self._isdst(dt):
return DSTOFFSET
@@ -99,20 +76,37 @@ def first_sunday_on_or_after(dt):
# In the US, since 2007, DST starts at 2am (standard time) on the second
# Sunday in March, which is the first Sunday on or after Mar 8.
DSTSTART_2007 = datetime(1, 3, 8, 2)
-# and ends at 2am (DST time; 1am standard time) on the first Sunday of Nov.
-DSTEND_2007 = datetime(1, 11, 1, 1)
+# and ends at 2am (DST time) on the first Sunday of Nov.
+DSTEND_2007 = datetime(1, 11, 1, 2)
# From 1987 to 2006, DST used to start at 2am (standard time) on the first
-# Sunday in April and to end at 2am (DST time; 1am standard time) on the last
+# Sunday in April and to end at 2am (DST time) on the last
# Sunday of October, which is the first Sunday on or after Oct 25.
DSTSTART_1987_2006 = datetime(1, 4, 1, 2)
-DSTEND_1987_2006 = datetime(1, 10, 25, 1)
+DSTEND_1987_2006 = datetime(1, 10, 25, 2)
# From 1967 to 1986, DST used to start at 2am (standard time) on the last
-# Sunday in April (the one on or after April 24) and to end at 2am (DST time;
-# 1am standard time) on the last Sunday of October, which is the first Sunday
+# Sunday in April (the one on or after April 24) and to end at 2am (DST time)
+# on the last Sunday of October, which is the first Sunday
# on or after Oct 25.
DSTSTART_1967_1986 = datetime(1, 4, 24, 2)
DSTEND_1967_1986 = DSTEND_1987_2006
+def us_dst_range(year):
+ # Find start and end times for US DST. For years before 1967, return
+ # start = end for no DST.
+ if 2006 < year:
+ dststart, dstend = DSTSTART_2007, DSTEND_2007
+ elif 1986 < year < 2007:
+ dststart, dstend = DSTSTART_1987_2006, DSTEND_1987_2006
+ elif 1966 < year < 1987:
+ dststart, dstend = DSTSTART_1967_1986, DSTEND_1967_1986
+ else:
+ return (datetime(year, 1, 1), ) * 2
+
+ start = first_sunday_on_or_after(dststart.replace(year=year))
+ end = first_sunday_on_or_after(dstend.replace(year=year))
+ return start, end
+
+
class USTimeZone(tzinfo):
def __init__(self, hours, reprname, stdname, dstname):
@@ -141,27 +135,39 @@ class USTimeZone(tzinfo):
# implementation) passes a datetime with dt.tzinfo is self.
return ZERO
assert dt.tzinfo is self
-
- # Find start and end times for US DST. For years before 1967, return
- # ZERO for no DST.
- if 2006 < dt.year:
- dststart, dstend = DSTSTART_2007, DSTEND_2007
- elif 1986 < dt.year < 2007:
- dststart, dstend = DSTSTART_1987_2006, DSTEND_1987_2006
- elif 1966 < dt.year < 1987:
- dststart, dstend = DSTSTART_1967_1986, DSTEND_1967_1986
- else:
- return ZERO
-
- start = first_sunday_on_or_after(dststart.replace(year=dt.year))
- end = first_sunday_on_or_after(dstend.replace(year=dt.year))
-
+ start, end = us_dst_range(dt.year)
# Can't compare naive to aware objects, so strip the timezone from
# dt first.
- if start <= dt.replace(tzinfo=None) < end:
+ dt = dt.replace(tzinfo=None)
+ if start + HOUR <= dt < end - HOUR:
+ # DST is in effect.
return HOUR
- else:
- return ZERO
+ if end - HOUR <= dt < end:
+ # Fold (an ambiguous hour): use dt.fold to disambiguate.
+ return ZERO if dt.fold else HOUR
+ if start <= dt < start + HOUR:
+ # Gap (a non-existent hour): reverse the fold rule.
+ return HOUR if dt.fold else ZERO
+ # DST is off.
+ return ZERO
+
+ def fromutc(self, dt):
+ assert dt.tzinfo is self
+ start, end = us_dst_range(dt.year)
+ start = start.replace(tzinfo=self)
+ end = end.replace(tzinfo=self)
+ std_time = dt + self.stdoffset
+ dst_time = std_time + HOUR
+ if end <= dst_time < end + HOUR:
+ # Repeated hour
+ return std_time.replace(fold=1)
+ if std_time < start or dst_time >= end:
+ # Standard time
+ return std_time
+ if start <= std_time < end - HOUR:
+ # Daylight saving time
+ return dst_time
+
Eastern = USTimeZone(-5, "Eastern", "EST", "EDT")
Central = USTimeZone(-6, "Central", "CST", "CDT")
diff --git a/Doc/installing/index.rst b/Doc/installing/index.rst
index 1ef3149..b22465d 100644
--- a/Doc/installing/index.rst
+++ b/Doc/installing/index.rst
@@ -2,9 +2,9 @@
.. _installing-index:
-*****************************
- Installing Python Modules
-*****************************
+*************************
+Installing Python Modules
+*************************
:Email: distutils-sig@python.org
@@ -34,24 +34,24 @@ Key terms
* ``pip`` is the preferred installer program. Starting with Python 3.4, it
is included by default with the Python binary installers.
-* a virtual environment is a semi-isolated Python environment that allows
+* A *virtual environment* is a semi-isolated Python environment that allows
packages to be installed for use by a particular application, rather than
- being installed system wide
-* ``pyvenv`` is the standard tool for creating virtual environments, and has
+ being installed system wide.
+* ``venv`` is the standard tool for creating virtual environments, and has
been part of Python since Python 3.3. Starting with Python 3.4, it
- defaults to installing ``pip`` into all created virtual environments
+ defaults to installing ``pip`` into all created virtual environments.
* ``virtualenv`` is a third party alternative (and predecessor) to
- ``pyvenv``. It allows virtual environments to be used on versions of
- Python prior to 3.4, which either don't provide ``pyvenv`` at all, or
+ ``venv``. It allows virtual environments to be used on versions of
+ Python prior to 3.4, which either don't provide ``venv`` at all, or
aren't able to automatically install ``pip`` into created environments.
-* the `Python Packaging Index <https://pypi.python.org/pypi>`__ is a public
+* The `Python Packaging Index <https://pypi.python.org/pypi>`__ is a public
repository of open source licensed packages made available for use by
- other Python users
+ other Python users.
* the `Python Packaging Authority
<https://www.pypa.io/en/latest/>`__ are the group of
developers and documentation authors responsible for the maintenance and
evolution of the standard packaging tools and the associated metadata and
- file format standards. They maintain a variety of tools, documentation
+ file format standards. They maintain a variety of tools, documentation,
and issue trackers on both `GitHub <https://github.com/pypa>`__ and
`BitBucket <https://bitbucket.org/pypa/>`__.
* ``distutils`` is the original build and distribution system first added to
@@ -62,6 +62,19 @@ Key terms
of the mailing list used to coordinate Python packaging standards
development).
+.. deprecated:: 3.6
+ ``pyvenv`` was the recommended tool for creating virtual environments for
+ Python 3.3 and 3.4, and is `deprecated in Python 3.6
+ <https://docs.python.org/dev/whatsnew/3.6.html#deprecated-features>`_.
+
+.. versionchanged:: 3.5
+ The use of ``venv`` is now recommended for creating virtual environments.
+
+.. seealso::
+
+ `Python Packaging User Guide: Creating and using virtual environments
+ <https://packaging.python.org/installing/#creating-virtual-environments>`__
+
Basic usage
===========
@@ -100,13 +113,14 @@ explicitly::
More information and resources regarding ``pip`` and its capabilities can be
found in the `Python Packaging User Guide <https://packaging.python.org>`__.
-``pyvenv`` has its own documentation at :ref:`scripts-pyvenv`. Installing
-into an active virtual environment uses the commands shown above.
+Creation of virtual environments is done through the :mod:`venv` module.
+Installing packages into an active virtual environment uses the commands shown
+above.
.. seealso::
`Python Packaging User Guide: Installing Python Distribution Packages
- <https://packaging.python.org/en/latest/installing/>`__
+ <https://packaging.python.org/installing/>`__
How do I ...?
@@ -124,7 +138,7 @@ User Guide.
.. seealso::
`Python Packaging User Guide: Requirements for Installing Packages
- <https://packaging.python.org/en/latest/installing/#requirements-for-installing-packages>`__
+ <https://packaging.python.org/installing/#requirements-for-installing-packages>`__
.. installing-per-user-installation:
@@ -142,20 +156,19 @@ package just for the current user, rather than for all users of the system.
A number of scientific Python packages have complex binary dependencies, and
aren't currently easy to install using ``pip`` directly. At this point in
time, it will often be easier for users to install these packages by
-`other means
-<https://packaging.python.org/en/latest/science/>`__
+`other means <https://packaging.python.org/science/>`__
rather than attempting to install them with ``pip``.
.. seealso::
`Python Packaging User Guide: Installing Scientific Packages
- <https://packaging.python.org/en/latest/science/>`__
+ <https://packaging.python.org/science/>`__
... work with multiple versions of Python installed in parallel?
----------------------------------------------------------------
-On Linux, Mac OS X and other POSIX systems, use the versioned Python commands
+On Linux, Mac OS X, and other POSIX systems, use the versioned Python commands
in combination with the ``-m`` switch to run the appropriate copy of
``pip``::
@@ -164,7 +177,7 @@ in combination with the ``-m`` switch to run the appropriate copy of
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
-(appropriately versioned ``pip`` commands may also be available)
+Appropriately versioned ``pip`` commands may also be available.
On Windows, use the ``py`` Python launcher in combination with the ``-m``
switch::
@@ -212,11 +225,11 @@ as users are more regularly able to install pre-built extensions rather
than needing to build them themselves.
Some of the solutions for installing `scientific software
-<https://packaging.python.org/en/latest/science/>`__
-that is not yet available as pre-built ``wheel`` files may also help with
+<https://packaging.python.org/science/>`__
+that are not yet available as pre-built ``wheel`` files may also help with
obtaining other binary extensions without needing to build them locally.
.. seealso::
`Python Packaging User Guide: Binary Extensions
- <https://packaging.python.org/en/latest/extensions/>`__
+ <https://packaging.python.org/extensions/>`__
diff --git a/Doc/library/asynchat.rst b/Doc/library/asynchat.rst
index ae72d26..e02360c 100644
--- a/Doc/library/asynchat.rst
+++ b/Doc/library/asynchat.rst
@@ -58,13 +58,13 @@ connection requests.
The asynchronous output buffer size (default ``4096``).
Unlike :class:`asyncore.dispatcher`, :class:`async_chat` allows you to
- define a first-in-first-out queue (fifo) of *producers*. A producer need
+ define a :abbr:`FIFO (first-in, first-out)` queue of *producers*. A producer need
have only one method, :meth:`more`, which should return data to be
transmitted on the channel.
The producer indicates exhaustion (*i.e.* that it contains no more data) by
having its :meth:`more` method return the empty bytes object. At this point
- the :class:`async_chat` object removes the producer from the fifo and starts
- using the next producer, if any. When the producer fifo is empty the
+ the :class:`async_chat` object removes the producer from the queue and starts
+ using the next producer, if any. When the producer queue is empty the
:meth:`handle_write` method does nothing. You use the channel object's
:meth:`set_terminator` method to describe how to recognize the end of, or
an important breakpoint in, an incoming transmission from the remote
@@ -78,8 +78,8 @@ connection requests.
.. method:: async_chat.close_when_done()
- Pushes a ``None`` on to the producer fifo. When this producer is popped off
- the fifo it causes the channel to be closed.
+ Pushes a ``None`` on to the producer queue. When this producer is popped off
+ the queue it causes the channel to be closed.
.. method:: async_chat.collect_incoming_data(data)
@@ -92,7 +92,7 @@ connection requests.
.. method:: async_chat.discard_buffers()
In emergencies this method will discard any data held in the input and/or
- output buffers and the producer fifo.
+ output buffers and the producer queue.
.. method:: async_chat.found_terminator()
@@ -110,7 +110,7 @@ connection requests.
.. method:: async_chat.push(data)
- Pushes data on to the channel's fifo to ensure its transmission.
+ Pushes data on to the channel's queue to ensure its transmission.
This is all you need to do to have the channel write the data out to the
network, although it is possible to use your own producers in more complex
schemes to implement encryption and chunking, for example.
@@ -118,7 +118,7 @@ connection requests.
.. method:: async_chat.push_with_producer(producer)
- Takes a producer object and adds it to the producer fifo associated with
+ Takes a producer object and adds it to the producer queue associated with
the channel. When all currently-pushed producers have been exhausted the
channel will consume this producer's data by calling its :meth:`more`
method and send the data to the remote endpoint.
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
index ba52d9b..ed1d773 100644
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -110,8 +110,9 @@ keywords to your callback, use :func:`functools.partial`. For example,
called after :meth:`call_soon` returns, when control returns to the event
loop.
- This operates as a FIFO queue, callbacks are called in the order in
- which they are registered. Each callback will be called exactly once.
+ This operates as a :abbr:`FIFO (first-in, first-out)` queue, callbacks
+ are called in the order in which they are registered. Each callback
+ will be called exactly once.
Any positional arguments after the callback will be passed to the
callback when it is called.
diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst
index 878d8db..4f5f0f2 100644
--- a/Doc/library/binascii.rst
+++ b/Doc/library/binascii.rst
@@ -53,13 +53,14 @@ The :mod:`binascii` module defines the following functions:
than one line may be passed at a time.
-.. function:: b2a_base64(data)
+.. function:: b2a_base64(data, \*, newline=True)
Convert binary data to a line of ASCII characters in base64 coding. The return
- value is the converted line, including a newline char. The newline is
- added because the original use case for this function was to feed it a
- series of 57 byte input lines to get output lines that conform to the
- MIME-base64 standard. Otherwise the output conforms to :rfc:`3548`.
+ value is the converted line, including a newline char if *newline* is
+ true. The output of this function conforms to :rfc:`3548`.
+
+ .. versionchanged:: 3.6
+ Added the *newline* parameter.
.. function:: a2b_qp(data, header=False)
diff --git a/Doc/library/bz2.rst b/Doc/library/bz2.rst
index 6c49d9f..d5f6225 100644
--- a/Doc/library/bz2.rst
+++ b/Doc/library/bz2.rst
@@ -61,6 +61,9 @@ All of the classes in this module may safely be accessed from multiple threads.
.. versionchanged:: 3.4
The ``'x'`` (exclusive creation) mode was added.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. class:: BZ2File(filename, mode='r', buffering=None, compresslevel=9)
@@ -128,6 +131,9 @@ All of the classes in this module may safely be accessed from multiple threads.
The :meth:`~io.BufferedIOBase.read` method now accepts an argument of
``None``.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
Incremental (de)compression
---------------------------
diff --git a/Doc/library/cmath.rst b/Doc/library/cmath.rst
index 62ddb6b..d935c41 100644
--- a/Doc/library/cmath.rst
+++ b/Doc/library/cmath.rst
@@ -253,6 +253,40 @@ Constants
The mathematical constant *e*, as a float.
+.. data:: tau
+
+ The mathematical constant *τ*, as a float.
+
+ .. versionadded:: 3.6
+
+.. data:: inf
+
+ Floating-point positive infinity. Equivalent to ``float('inf')``.
+
+ .. versionadded:: 3.6
+
+.. data:: infj
+
+ Complex number with zero real part and positive infinity imaginary
+ part. Equivalent to ``complex(0.0, float('inf'))``.
+
+ .. versionadded:: 3.6
+
+.. data:: nan
+
+ A floating-point "not a number" (NaN) value. Equivalent to
+ ``float('nan')``.
+
+ .. versionadded:: 3.6
+
+.. data:: nanj
+
+ Complex number with zero real part and NaN imaginary part. Equivalent to
+ ``complex(0.0, float('nan'))``.
+
+ .. versionadded:: 3.6
+
+
.. index:: module: math
Note that the selection of functions is similar, but not identical, to that in
@@ -276,5 +310,3 @@ cuts for numerical purposes, a good reference should be the following:
Kahan, W: Branch cuts for complex elementary functions; or, Much ado about
nothing's sign bit. In Iserles, A., and Powell, M. (eds.), The state of the art
in numerical analysis. Clarendon Press (1987) pp165-211.
-
-
diff --git a/Doc/library/code.rst b/Doc/library/code.rst
index 443af69..e2c47ba 100644
--- a/Doc/library/code.rst
+++ b/Doc/library/code.rst
@@ -30,15 +30,19 @@ build applications which provide an interactive interpreter prompt.
``sys.ps1`` and ``sys.ps2``, and input buffering.
-.. function:: interact(banner=None, readfunc=None, local=None)
+.. function:: interact(banner=None, readfunc=None, local=None, exitmsg=None)
Convenience function to run a read-eval-print loop. This creates a new
instance of :class:`InteractiveConsole` and sets *readfunc* to be used as
the :meth:`InteractiveConsole.raw_input` method, if provided. If *local* is
provided, it is passed to the :class:`InteractiveConsole` constructor for
use as the default namespace for the interpreter loop. The :meth:`interact`
- method of the instance is then run with *banner* passed as the banner to
- use, if provided. The console object is discarded after use.
+ method of the instance is then run with *banner* and *exitmsg* passed as the
+ banner and exit message to use, if provided. The console object is discarded
+ after use.
+
+ .. versionchanged:: 3.6
+ Added *exitmsg* parameter.
.. function:: compile_command(source, filename="<input>", symbol="single")
@@ -136,7 +140,7 @@ The :class:`InteractiveConsole` class is a subclass of
interpreter objects as well as the following additions.
-.. method:: InteractiveConsole.interact(banner=None)
+.. method:: InteractiveConsole.interact(banner=None, exitmsg=None)
Closely emulate the interactive Python console. The optional *banner* argument
specify the banner to print before the first interaction; by default it prints a
@@ -144,9 +148,16 @@ interpreter objects as well as the following additions.
by the class name of the console object in parentheses (so as not to confuse
this with the real interpreter -- since it's so close!).
+ The optional *exitmsg* argument specifies an exit message printed when exiting.
+ Pass the empty string to suppress the exit message. If *exitmsg* is not given or
+ ``None``, a default message is printed.
+
.. versionchanged:: 3.4
To suppress printing any banner, pass an empty string.
+ .. versionchanged:: 3.6
+ Print an exit message when exiting.
+
.. method:: InteractiveConsole.push(line)
diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst
index 03f0228..aa1d123 100644
--- a/Doc/library/codecs.rst
+++ b/Doc/library/codecs.rst
@@ -1263,10 +1263,16 @@ encodings.
| | | Only ``errors='strict'`` |
| | | is supported. |
+--------------------+---------+---------------------------+
-| mbcs | dbcs | Windows only: Encode |
-| | | operand according to the |
+| mbcs | ansi, | Windows only: Encode |
+| | dbcs | operand according to the |
| | | ANSI codepage (CP_ACP) |
+--------------------+---------+---------------------------+
+| oem | | Windows only: Encode |
+| | | operand according to the |
+| | | OEM codepage (CP_OEMCP) |
+| | | |
+| | | .. versionadded:: 3.6 |
++--------------------+---------+---------------------------+
| palmos | | Encoding of PalmOS 3.5 |
+--------------------+---------+---------------------------+
| punycode | | Implements :rfc:`3492`. |
diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst
index aeb6a73..e4b75a0 100644
--- a/Doc/library/collections.abc.rst
+++ b/Doc/library/collections.abc.rst
@@ -41,13 +41,16 @@ ABC Inherits from Abstract Methods Mixin
:class:`Hashable` ``__hash__``
:class:`Iterable` ``__iter__``
:class:`Iterator` :class:`Iterable` ``__next__`` ``__iter__``
+:class:`Reversible` :class:`Iterable` ``__reversed__``
:class:`Generator` :class:`Iterator` ``send``, ``throw`` ``close``, ``__iter__``, ``__next__``
:class:`Sized` ``__len__``
:class:`Callable` ``__call__``
+:class:`Collection` :class:`Sized`, ``__contains__``,
+ :class:`Iterable`, ``__iter__``,
+ :class:`Container` ``__len__``
-:class:`Sequence` :class:`Sized`, ``__getitem__``, ``__contains__``, ``__iter__``, ``__reversed__``,
- :class:`Iterable`, ``__len__`` ``index``, and ``count``
- :class:`Container`
+:class:`Sequence` :class:`Reversible`, ``__getitem__``, ``__contains__``, ``__iter__``, ``__reversed__``,
+ :class:`Collection` ``__len__`` ``index``, and ``count``
:class:`MutableSequence` :class:`Sequence` ``__getitem__``, Inherited :class:`Sequence` methods and
``__setitem__``, ``append``, ``reverse``, ``extend``, ``pop``,
@@ -58,9 +61,9 @@ ABC Inherits from Abstract Methods Mixin
:class:`ByteString` :class:`Sequence` ``__getitem__``, Inherited :class:`Sequence` methods
``__len__``
-:class:`Set` :class:`Sized`, ``__contains__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
- :class:`Iterable`, ``__iter__``, ``__gt__``, ``__ge__``, ``__and__``, ``__or__``,
- :class:`Container` ``__len__`` ``__sub__``, ``__xor__``, and ``isdisjoint``
+:class:`Set` :class:`Collection` ``__contains__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
+ ``__iter__``, ``__gt__``, ``__ge__``, ``__and__``, ``__or__``,
+ ``__len__`` ``__sub__``, ``__xor__``, and ``isdisjoint``
:class:`MutableSet` :class:`Set` ``__contains__``, Inherited :class:`Set` methods and
``__iter__``, ``clear``, ``pop``, ``remove``, ``__ior__``,
@@ -68,9 +71,9 @@ ABC Inherits from Abstract Methods Mixin
``add``,
``discard``
-:class:`Mapping` :class:`Sized`, ``__getitem__``, ``__contains__``, ``keys``, ``items``, ``values``,
- :class:`Iterable`, ``__iter__``, ``get``, ``__eq__``, and ``__ne__``
- :class:`Container` ``__len__``
+:class:`Mapping` :class:`Collection` ``__getitem__``, ``__contains__``, ``keys``, ``items``, ``values``,
+ ``__iter__``, ``get``, ``__eq__``, and ``__ne__``
+ ``__len__``
:class:`MutableMapping` :class:`Mapping` ``__getitem__``, Inherited :class:`Mapping` methods and
``__setitem__``, ``pop``, ``popitem``, ``clear``, ``update``,
@@ -105,12 +108,25 @@ ABC Inherits from Abstract Methods Mixin
ABC for classes that provide the :meth:`__iter__` method.
See also the definition of :term:`iterable`.
+.. class:: Collection
+
+ ABC for sized iterable container classes.
+
+ .. versionadded:: 3.6
+
.. class:: Iterator
ABC for classes that provide the :meth:`~iterator.__iter__` and
:meth:`~iterator.__next__` methods. See also the definition of
:term:`iterator`.
+.. class:: Reversible
+
+ ABC for iterable classes that also provide the :meth:`__reversed__`
+ method.
+
+ .. versionadded:: 3.6
+
.. class:: Generator
ABC for generator classes that implement the protocol defined in
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index d0aa62e..9f3f5dc 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -763,7 +763,7 @@ Named tuples assign meaning to each position in a tuple and allow for more reada
self-documenting code. They can be used wherever regular tuples are used, and
they add the ability to access fields by name instead of position index.
-.. function:: namedtuple(typename, field_names, verbose=False, rename=False)
+.. function:: namedtuple(typename, field_names, *, verbose=False, rename=False, module=None)
Returns a new tuple subclass named *typename*. The new subclass is used to
create tuple-like objects that have fields accessible by attribute lookup as
@@ -790,12 +790,21 @@ they add the ability to access fields by name instead of position index.
built. This option is outdated; instead, it is simpler to print the
:attr:`_source` attribute.
+ If *module* is defined, the ``__module__`` attribute of the named tuple is
+ set to that value.
+
Named tuple instances do not have per-instance dictionaries, so they are
lightweight and require no more memory than regular tuples.
.. versionchanged:: 3.1
- Added support for *rename*.
+ Added support for *rename*.
+
+ .. versionchanged:: 3.6
+ The *verbose* and *rename* parameters became
+ :ref:`keyword-only arguments <keyword-only_parameter>`.
+ .. versionchanged:: 3.6
+ Added the *module* parameter.
.. doctest::
:options: +NORMALIZE_WHITESPACE
@@ -846,7 +855,9 @@ field names, the method and attribute names start with an underscore.
.. method:: somenamedtuple._asdict()
Return a new :class:`OrderedDict` which maps field names to their corresponding
- values::
+ values:
+
+ .. doctest::
>>> p = Point(x=11, y=22)
>>> p._asdict()
@@ -908,7 +919,9 @@ Since a named tuple is a regular Python class, it is easy to add or change
functionality with a subclass. Here is how to add a calculated field and
a fixed-width print format:
- >>> class Point(namedtuple('Point', 'x y')):
+.. doctest::
+
+ >>> class Point(namedtuple('Point', ['x', 'y'])):
... __slots__ = ()
... @property
... def hypot(self):
@@ -959,6 +972,11 @@ customize a prototype instance:
constructor that is convenient for use cases where named tuples are being
subclassed.
+ * See :meth:`types.SimpleNamespace` for a mutable namespace based on an
+ underlying dictionary instead of a tuple.
+
+ * See :meth:`typing.NamedTuple` for a way to add type hints for named tuples.
+
:class:`OrderedDict` objects
----------------------------
@@ -980,8 +998,9 @@ the items are returned in the order their keys were first added.
.. method:: popitem(last=True)
The :meth:`popitem` method for ordered dictionaries returns and removes a
- (key, value) pair. The pairs are returned in LIFO order if *last* is true
- or FIFO order if false.
+ (key, value) pair. The pairs are returned in
+ :abbr:`LIFO (last-in, first-out)` order if *last* is true
+ or :abbr:`FIFO (first-in, first-out)` order if false.
.. method:: move_to_end(key, last=True)
diff --git a/Doc/library/compileall.rst b/Doc/library/compileall.rst
index 511c581..c1af02b 100644
--- a/Doc/library/compileall.rst
+++ b/Doc/library/compileall.rst
@@ -102,7 +102,8 @@ Public functions
.. function:: compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1, workers=1)
Recursively descend the directory tree named by *dir*, compiling all :file:`.py`
- files along the way.
+ files along the way. Return a true value if all the files compiled successfully,
+ and a false value otherwise.
The *maxlevels* parameter is used to limit the depth of the recursion; it
defaults to ``10``.
@@ -152,9 +153,13 @@ Public functions
The *legacy* parameter only writes out ``.pyc`` files, not ``.pyo`` files
no matter what the value of *optimize* is.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1)
- Compile the file with path *fullname*.
+ Compile the file with path *fullname*. Return a true value if the file
+ compiled successfully, and a false value otherwise.
If *ddir* is given, it is prepended to the path to the file being compiled
for use in compilation time tracebacks, and is also compiled in to the
@@ -190,8 +195,10 @@ Public functions
.. function:: compile_path(skip_curdir=True, maxlevels=0, force=False, quiet=0, legacy=False, optimize=-1)
- Byte-compile all the :file:`.py` files found along ``sys.path``. If
- *skip_curdir* is true (the default), the current directory is not included
+ Byte-compile all the :file:`.py` files found along ``sys.path``. Return a
+ true value if all the files compiled successfully, and a false value otherwise.
+
+ If *skip_curdir* is true (the default), the current directory is not included
in the search. All other parameters are passed to the :func:`compile_dir`
function. Note that unlike the other compile functions, ``maxlevels``
defaults to ``0``.
@@ -217,6 +224,9 @@ subdirectory and all its subdirectories::
import re
compileall.compile_dir('Lib/', rx=re.compile(r'[/\\][.]svn'), force=True)
+ # pathlib.Path objects can also be used.
+ import pathlib
+ compileall.compile_dir(pathlib.Path('Lib/'), force=True)
.. seealso::
diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst
index ae03f4b..d85576b 100644
--- a/Doc/library/concurrent.futures.rst
+++ b/Doc/library/concurrent.futures.rst
@@ -124,7 +124,7 @@ And::
executor.submit(wait_on_future)
-.. class:: ThreadPoolExecutor(max_workers=None)
+.. class:: ThreadPoolExecutor(max_workers=None, thread_name_prefix='')
An :class:`Executor` subclass that uses a pool of at most *max_workers*
threads to execute calls asynchronously.
@@ -137,6 +137,10 @@ And::
should be higher than the number of workers
for :class:`ProcessPoolExecutor`.
+ .. versionadded:: 3.6
+ The *thread_name_prefix* argument was added to allow users to
+ control the threading.Thread names for worker threads created by
+ the pool for easier debugging.
.. _threadpoolexecutor-example:
diff --git a/Doc/library/constants.rst b/Doc/library/constants.rst
index d5a0f09..f0742ce 100644
--- a/Doc/library/constants.rst
+++ b/Doc/library/constants.rst
@@ -33,16 +33,22 @@ A small number of constants live in the built-in namespace. They are:
(e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.
Its truth value is true.
-.. note::
+ .. note::
+
+ When a binary (or in-place) method returns ``NotImplemented`` the
+ interpreter will try the reflected operation on the other type (or some
+ other fallback, depending on the operator). If all attempts return
+ ``NotImplemented``, the interpreter will raise an appropriate exception.
+ Incorrectly returning ``NotImplemented`` will result in a misleading
+ error message or the ``NotImplemented`` value being returned to Python code.
+
+ See :ref:`implementing-the-arithmetic-operations` for examples.
- When ``NotImplemented`` is returned, the interpreter will then try the
- reflected operation on the other type, or some other fallback, depending
- on the operator. If all attempted operations return ``NotImplemented``, the
- interpreter will raise an appropriate exception.
+ .. note::
- See
- :ref:`implementing-the-arithmetic-operations`
- for more details.
+ ``NotImplentedError`` and ``NotImplemented`` are not interchangeable,
+ even though they have similar names and purposes.
+ See :exc:`NotImplementedError` for details on when to use it.
.. data:: Ellipsis
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index cf85fcd..dd34c96 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -18,6 +18,18 @@ Utilities
Functions and classes provided:
+.. class:: AbstractContextManager
+
+ An :term:`abstract base class` for classes that implement
+ :meth:`object.__enter__` and :meth:`object.__exit__`. A default
+ implementation for :meth:`object.__enter__` is provided which returns
+ ``self`` while :meth:`object.__exit__` is an abstract method which by default
+ returns ``None``. See also the definition of :ref:`typecontextmanager`.
+
+ .. versionadded:: 3.6
+
+
+
.. decorator:: contextmanager
This function is a :term:`decorator` that can be used to define a factory
@@ -447,9 +459,9 @@ Here's an example of doing this for a context manager that accepts resource
acquisition and release functions, along with an optional validation function,
and maps them to the context management protocol::
- from contextlib import contextmanager, ExitStack
+ from contextlib import contextmanager, AbstractContextManager, ExitStack
- class ResourceManager:
+ class ResourceManager(AbstractContextManager):
def __init__(self, acquire_resource, release_resource, check_resource_ok=None):
self.acquire_resource = acquire_resource
@@ -578,10 +590,10 @@ single definition::
self.name = name
def __enter__(self):
- logging.info('Entering: {}'.format(self.name))
+ logging.info('Entering: %s', self.name)
def __exit__(self, exc_type, exc, exc_tb):
- logging.info('Exiting: {}'.format(self.name))
+ logging.info('Exiting: %s', self.name)
Instances of this class can be used as both a context manager::
diff --git a/Doc/library/crypt.rst b/Doc/library/crypt.rst
index a21c1e7..dbd4274 100644
--- a/Doc/library/crypt.rst
+++ b/Doc/library/crypt.rst
@@ -68,7 +68,7 @@ Module Attributes
A list of available password hashing algorithms, as
``crypt.METHOD_*`` objects. This list is sorted from strongest to
- weakest, and is guaranteed to have at least ``crypt.METHOD_CRYPT``.
+ weakest.
Module Functions
diff --git a/Doc/library/crypto.rst b/Doc/library/crypto.rst
index 1eddfdc..8eb4b81 100644
--- a/Doc/library/crypto.rst
+++ b/Doc/library/crypto.rst
@@ -15,4 +15,6 @@ Here's an overview:
.. toctree::
hashlib.rst
+ hashlib-blake2.rst
hmac.rst
+ secrets.rst
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
index 7fb4fc8..f916572 100644
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -149,18 +149,25 @@ The :mod:`csv` module defines the following classes:
.. class:: DictReader(csvfile, fieldnames=None, restkey=None, restval=None, \
dialect='excel', *args, **kwds)
- Create an object which operates like a regular reader but maps the
- information read into a dict whose keys are given by the optional
- *fieldnames* parameter. The *fieldnames* parameter is a :mod:`sequence
- <collections.abc>` whose elements are associated with the fields of the
- input data in order. These elements become the keys of the resulting
- dictionary. If the *fieldnames* parameter is omitted, the values in the
- first row of the *csvfile* will be used as the fieldnames. If the row read
- has more fields than the fieldnames sequence, the remaining data is added as
- a sequence keyed by the value of *restkey*. If the row read has fewer
- fields than the fieldnames sequence, the remaining keys take the value of
- the optional *restval* parameter. Any other optional or keyword arguments
- are passed to the underlying :class:`reader` instance.
+ Create an object that operates like a regular reader but maps the
+ information in each row to an :mod:`OrderedDict <collections.OrderedDict>`
+ whose keys are given by the optional *fieldnames* parameter.
+
+ The *fieldnames* parameter is a :term:`sequence`. If *fieldnames* is
+ omitted, the values in the first row of the *csvfile* will be used as the
+ fieldnames. Regardless of how the fieldnames are determined, the ordered
+ dictionary preserves their original ordering.
+
+ If a row has more fields than fieldnames, the remaining data is put in a
+ list and stored with the fieldname specified by *restkey* (which defaults
+ to ``None``). If a non-blank row has fewer fields than fieldnames, the
+ missing values are filled-in with ``None``.
+
+ All other optional or keyword arguments are passed to the underlying
+ :class:`reader` instance.
+
+ .. versionchanged:: 3.6
+ Returned rows are now of type :class:`OrderedDict`.
A short usage example::
@@ -170,9 +177,11 @@ The :mod:`csv` module defines the following classes:
... for row in reader:
... print(row['first_name'], row['last_name'])
...
- Baked Beans
- Lovely Spam
- Wonderful Spam
+ Eric Idle
+ John Cleese
+
+ >>> print(row)
+ OrderedDict([('first_name', 'John'), ('last_name', 'Cleese')])
.. class:: DictWriter(csvfile, fieldnames, restval='', extrasaction='raise', \
@@ -186,10 +195,12 @@ The :mod:`csv` module defines the following classes:
written if the dictionary is missing a key in *fieldnames*. If the
dictionary passed to the :meth:`writerow` method contains a key not found in
*fieldnames*, the optional *extrasaction* parameter indicates what action to
- take. If it is set to ``'raise'`` a :exc:`ValueError` is raised. If it is
- set to ``'ignore'``, extra values in the dictionary are ignored. Any other
- optional or keyword arguments are passed to the underlying :class:`writer`
- instance.
+ take.
+ If it is set to ``'raise'``, the default value, a :exc:`ValueError`
+ is raised.
+ If it is set to ``'ignore'``, extra values in the dictionary are ignored.
+ Any other optional or keyword arguments are passed to the underlying
+ :class:`writer` instance.
Note that unlike the :class:`DictReader` class, the *fieldnames* parameter
of the :class:`DictWriter` is not optional. Since Python's :class:`dict`
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
index 94822ba..3381a9d 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -1239,9 +1239,10 @@ When programming in a compiled language, shared libraries are accessed when
compiling/linking a program, and when the program is run.
The purpose of the :func:`find_library` function is to locate a library in a way
-similar to what the compiler does (on platforms with several versions of a
-shared library the most recent should be loaded), while the ctypes library
-loaders act like when a program is run, and call the runtime loader directly.
+similar to what the compiler or runtime loader does (on platforms with several
+versions of a shared library the most recent should be loaded), while the ctypes
+library loaders act like when a program is run, and call the runtime loader
+directly.
The :mod:`ctypes.util` module provides a function which can help to determine
the library to load.
@@ -1259,8 +1260,14 @@ the library to load.
The exact functionality is system dependent.
On Linux, :func:`find_library` tries to run external programs
-(``/sbin/ldconfig``, ``gcc``, and ``objdump``) to find the library file. It
-returns the filename of the library file. Here are some examples::
+(``/sbin/ldconfig``, ``gcc``, ``objdump`` and ``ld``) to find the library file.
+It returns the filename of the library file.
+
+.. versionchanged:: 3.6
+ On Linux, the value of the environment variable ``LD_LIBRARY_PATH`` is used
+ when searching for libraries, if a library cannot be found by any other means.
+
+Here are some examples::
>>> from ctypes.util import find_library
>>> find_library("m")
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 9254ae8..ecaad06 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -522,7 +522,7 @@ objects are considered to be true.
Instance methods:
-.. method:: date.replace(year, month, day)
+.. method:: date.replace(year=self.year, month=self.month, day=self.day)
Return a date with the same value, except for those parameters given new
values by whichever keyword arguments are specified. For example, if ``d ==
@@ -610,7 +610,8 @@ Instance methods:
.. method:: date.__format__(format)
Same as :meth:`.date.strftime`. This makes it possible to specify a format
- string for a :class:`.date` object when using :meth:`str.format`. For a
+ string for a :class:`.date` object in :ref:`formatted string
+ literals <f-strings>` and when using :meth:`str.format`. For a
complete list of formatting directives, see
:ref:`strftime-strptime-behavior`.
@@ -682,22 +683,26 @@ both directions; like a time object, :class:`.datetime` assumes there are exactl
Constructor:
-.. class:: datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
+.. class:: datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
The year, month and day arguments are required. *tzinfo* may be ``None``, or an
instance of a :class:`tzinfo` subclass. The remaining arguments may be integers,
in the following ranges:
- * ``MINYEAR <= year <= MAXYEAR``
- * ``1 <= month <= 12``
- * ``1 <= day <= number of days in the given month and year``
- * ``0 <= hour < 24``
- * ``0 <= minute < 60``
- * ``0 <= second < 60``
- * ``0 <= microsecond < 1000000``
+ * ``MINYEAR <= year <= MAXYEAR``,
+ * ``1 <= month <= 12``,
+ * ``1 <= day <= number of days in the given month and year``,
+ * ``0 <= hour < 24``,
+ * ``0 <= minute < 60``,
+ * ``0 <= second < 60``,
+ * ``0 <= microsecond < 1000000``,
+ * ``fold in [0, 1]``.
If an argument outside those ranges is given, :exc:`ValueError` is raised.
+ .. versionadded:: 3.6
+ Added the ``fold`` argument.
+
Other constructors, all class methods:
.. classmethod:: datetime.today()
@@ -757,6 +762,8 @@ Other constructors, all class methods:
instead of :exc:`ValueError` on :c:func:`localtime` or :c:func:`gmtime`
failure.
+ .. versionchanged:: 3.6
+ :meth:`fromtimestamp` may return instances with :attr:`.fold` set to 1.
.. classmethod:: datetime.utcfromtimestamp(timestamp)
@@ -793,16 +800,23 @@ Other constructors, all class methods:
microsecond of the result are all 0, and :attr:`.tzinfo` is ``None``.
-.. classmethod:: datetime.combine(date, time)
+.. classmethod:: datetime.combine(date, time, tzinfo=self.tzinfo)
Return a new :class:`.datetime` object whose date components are equal to the
- given :class:`date` object's, and whose time components and :attr:`.tzinfo`
- attributes are equal to the given :class:`.time` object's. For any
- :class:`.datetime` object *d*,
- ``d == datetime.combine(d.date(), d.timetz())``. If date is a
+ given :class:`date` object's, and whose time components
+ are equal to the given :class:`.time` object's. If the *tzinfo*
+ argument is provided, its value is used to set the :attr:`.tzinfo` attribute
+ of the result, otherwise the :attr:`~.time.tzinfo` attribute of the *time* argument
+ is used.
+
+ For any :class:`.datetime` object *d*,
+ ``d == datetime.combine(d.date(), d.time(), d.tzinfo)``. If date is a
:class:`.datetime` object, its time components and :attr:`.tzinfo` attributes
are ignored.
+ .. versionchanged:: 3.6
+ Added the *tzinfo* argument.
+
.. classmethod:: datetime.strptime(date_string, format)
@@ -878,6 +892,16 @@ Instance attributes (read-only):
or ``None`` if none was passed.
+.. attribute:: datetime.fold
+
+ In ``[0, 1]``. Used to disambiguate wall times during a repeated interval. (A
+ repeated interval occurs when clocks are rolled back at the end of daylight saving
+ time or when the UTC offset for the current zone is decreased for political reasons.)
+ The value 0 (1) represents the earlier (later) of the two moments with the same wall
+ time representation.
+
+ .. versionadded:: 3.6
+
Supported operations:
+---------------------------------------+--------------------------------+
@@ -966,23 +990,34 @@ Instance methods:
.. method:: datetime.time()
- Return :class:`.time` object with same hour, minute, second and microsecond.
+ Return :class:`.time` object with same hour, minute, second, microsecond and fold.
:attr:`.tzinfo` is ``None``. See also method :meth:`timetz`.
+ .. versionchanged:: 3.6
+ The fold value is copied to the returned :class:`.time` object.
+
.. method:: datetime.timetz()
- Return :class:`.time` object with same hour, minute, second, microsecond, and
+ Return :class:`.time` object with same hour, minute, second, microsecond, fold, and
tzinfo attributes. See also method :meth:`time`.
+ .. versionchanged:: 3.6
+ The fold value is copied to the returned :class:`.time` object.
-.. method:: datetime.replace([year[, month[, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]]]]])
+
+.. method:: datetime.replace(year=self.year, month=self.month, day=self.day, \
+ hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, \
+ tzinfo=self.tzinfo, * fold=0)
Return a datetime with the same attributes, except for those attributes given
new values by whichever keyword arguments are specified. Note that
``tzinfo=None`` can be specified to create a naive datetime from an aware
datetime with no conversion of date and time data.
+ .. versionadded:: 3.6
+ Added the ``fold`` argument.
+
.. method:: datetime.astimezone(tz=None)
@@ -991,23 +1026,20 @@ Instance methods:
*self*, but in *tz*'s local time.
If provided, *tz* must be an instance of a :class:`tzinfo` subclass, and its
- :meth:`utcoffset` and :meth:`dst` methods must not return ``None``. *self* must
- be aware (``self.tzinfo`` must not be ``None``, and ``self.utcoffset()`` must
- not return ``None``).
+ :meth:`utcoffset` and :meth:`dst` methods must not return ``None``. If *self*
+ is naive (``self.tzinfo is None``), it is presumed to represent time in the
+ system timezone.
If called without arguments (or with ``tz=None``) the system local
- timezone is assumed. The ``.tzinfo`` attribute of the converted
+ timezone is assumed for the target timezone. The ``.tzinfo`` attribute of the converted
datetime instance will be set to an instance of :class:`timezone`
with the zone name and offset obtained from the OS.
If ``self.tzinfo`` is *tz*, ``self.astimezone(tz)`` is equal to *self*: no
adjustment of date or time data is performed. Else the result is local
- time in time zone *tz*, representing the same UTC time as *self*: after
- ``astz = dt.astimezone(tz)``, ``astz - astz.utcoffset()`` will usually have
- the same date and time data as ``dt - dt.utcoffset()``. The discussion
- of class :class:`tzinfo` explains the cases at Daylight Saving Time transition
- boundaries where this cannot be achieved (an issue only if *tz* models both
- standard and daylight time).
+ time in the timezone *tz*, representing the same UTC time as *self*: after
+ ``astz = dt.astimezone(tz)``, ``astz - astz.utcoffset()`` will have
+ the same date and time data as ``dt - dt.utcoffset()``.
If you merely want to attach a time zone object *tz* to a datetime *dt* without
adjustment of date and time data, use ``dt.replace(tzinfo=tz)``. If you
@@ -1029,6 +1061,10 @@ Instance methods:
.. versionchanged:: 3.3
*tz* now can be omitted.
+ .. versionchanged:: 3.6
+ The :meth:`astimezone` method can now be called on naive instances that
+ are presumed to represent system local time.
+
.. method:: datetime.utcoffset()
@@ -1105,6 +1141,10 @@ Instance methods:
.. versionadded:: 3.3
+ .. versionchanged:: 3.6
+ The :meth:`timestamp` method uses the :attr:`.fold` attribute to
+ disambiguate the times during a repeated interval.
+
.. note::
There is no method to obtain the POSIX timestamp directly from a
@@ -1138,7 +1178,7 @@ Instance methods:
``self.date().isocalendar()``.
-.. method:: datetime.isoformat(sep='T')
+.. method:: datetime.isoformat(sep='T', timespec='auto')
Return a string representing the date and time in ISO 8601 format,
YYYY-MM-DDTHH:MM:SS.mmmmmm or, if :attr:`microsecond` is 0,
@@ -1159,6 +1199,37 @@ Instance methods:
>>> datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
'2002-12-25 00:00:00-06:39'
+ The optional argument *timespec* specifies the number of additional
+ components of the time to include (the default is ``'auto'``).
+ It can be one of the following:
+
+ - ``'auto'``: Same as ``'seconds'`` if :attr:`microsecond` is 0,
+ same as ``'microseconds'`` otherwise.
+ - ``'hours'``: Include the :attr:`hour` in the two-digit HH format.
+ - ``'minutes'``: Include :attr:`hour` and :attr:`minute` in HH:MM format.
+ - ``'seconds'``: Include :attr:`hour`, :attr:`minute`, and :attr:`second`
+ in HH:MM:SS format.
+ - ``'milliseconds'``: Include full time, but truncate fractional second
+ part to milliseconds. HH:MM:SS.sss format.
+ - ``'microseconds'``: Include full time in HH:MM:SS.mmmmmm format.
+
+ .. note::
+
+ Excluded time components are truncated, not rounded.
+
+ :exc:`ValueError` will be raised on an invalid *timespec* argument.
+
+
+ >>> from datetime import datetime
+ >>> datetime.now().isoformat(timespec='minutes')
+ '2002-12-25T00:00'
+ >>> dt = datetime(2015, 1, 1, 12, 30, 59, 0)
+ >>> dt.isoformat(timespec='microseconds')
+ '2015-01-01T12:30:59.000000'
+
+ .. versionadded:: 3.6
+ Added the *timespec* argument.
+
.. method:: datetime.__str__()
@@ -1185,7 +1256,8 @@ Instance methods:
.. method:: datetime.__format__(format)
Same as :meth:`.datetime.strftime`. This makes it possible to specify a format
- string for a :class:`.datetime` object when using :meth:`str.format`. For a
+ string for a :class:`.datetime` object in :ref:`formatted string
+ literals <f-strings>` and when using :meth:`str.format`. For a
complete list of formatting directives, see
:ref:`strftime-strptime-behavior`.
@@ -1302,16 +1374,17 @@ Using datetime with tzinfo:
A time object represents a (local) time of day, independent of any particular
day, and subject to adjustment via a :class:`tzinfo` object.
-.. class:: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None)
+.. class:: time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
All arguments are optional. *tzinfo* may be ``None``, or an instance of a
:class:`tzinfo` subclass. The remaining arguments may be integers, in the
following ranges:
- * ``0 <= hour < 24``
- * ``0 <= minute < 60``
- * ``0 <= second < 60``
- * ``0 <= microsecond < 1000000``.
+ * ``0 <= hour < 24``,
+ * ``0 <= minute < 60``,
+ * ``0 <= second < 60``,
+ * ``0 <= microsecond < 1000000``,
+ * ``fold in [0, 1]``.
If an argument outside those ranges is given, :exc:`ValueError` is raised. All
default to ``0`` except *tzinfo*, which defaults to :const:`None`.
@@ -1364,6 +1437,17 @@ Instance attributes (read-only):
``None`` if none was passed.
+.. attribute:: time.fold
+
+ In ``[0, 1]``. Used to disambiguate wall times during a repeated interval. (A
+ repeated interval occurs when clocks are rolled back at the end of daylight saving
+ time or when the UTC offset for the current zone is decreased for political reasons.)
+ The value 0 (1) represents the earlier (later) of the two moments with the same wall
+ time representation.
+
+ .. versionadded:: 3.6
+
+
Supported operations:
* comparison of :class:`.time` to :class:`.time`, where *a* is considered less
@@ -1399,21 +1483,58 @@ In boolean contexts, a :class:`.time` object is always considered to be true.
Instance methods:
-.. method:: time.replace([hour[, minute[, second[, microsecond[, tzinfo]]]]])
+.. method:: time.replace(hour=self.hour, minute=self.minute, second=self.second, \
+ microsecond=self.microsecond, tzinfo=self.tzinfo, * fold=0)
Return a :class:`.time` with the same value, except for those attributes given
new values by whichever keyword arguments are specified. Note that
``tzinfo=None`` can be specified to create a naive :class:`.time` from an
aware :class:`.time`, without conversion of the time data.
+ .. versionadded:: 3.6
+ Added the ``fold`` argument.
+
-.. method:: time.isoformat()
+.. method:: time.isoformat(timespec='auto')
Return a string representing the time in ISO 8601 format, HH:MM:SS.mmmmmm or, if
- self.microsecond is 0, HH:MM:SS If :meth:`utcoffset` does not return ``None``, a
+ :attr:`microsecond` is 0, HH:MM:SS If :meth:`utcoffset` does not return ``None``, a
6-character string is appended, giving the UTC offset in (signed) hours and
minutes: HH:MM:SS.mmmmmm+HH:MM or, if self.microsecond is 0, HH:MM:SS+HH:MM
+ The optional argument *timespec* specifies the number of additional
+ components of the time to include (the default is ``'auto'``).
+ It can be one of the following:
+
+ - ``'auto'``: Same as ``'seconds'`` if :attr:`microsecond` is 0,
+ same as ``'microseconds'`` otherwise.
+ - ``'hours'``: Include the :attr:`hour` in the two-digit HH format.
+ - ``'minutes'``: Include :attr:`hour` and :attr:`minute` in HH:MM format.
+ - ``'seconds'``: Include :attr:`hour`, :attr:`minute`, and :attr:`second`
+ in HH:MM:SS format.
+ - ``'milliseconds'``: Include full time, but truncate fractional second
+ part to milliseconds. HH:MM:SS.sss format.
+ - ``'microseconds'``: Include full time in HH:MM:SS.mmmmmm format.
+
+ .. note::
+
+ Excluded time components are truncated, not rounded.
+
+ :exc:`ValueError` will be raised on an invalid *timespec* argument.
+
+
+ >>> from datetime import time
+ >>> time(hour=12, minute=34, second=56, microsecond=123456).isoformat(timespec='minutes')
+ '12:34'
+ >>> dt = time(hour=12, minute=34, second=56, microsecond=0)
+ >>> dt.isoformat(timespec='microseconds')
+ '12:34:56.000000'
+ >>> dt.isoformat(timespec='auto')
+ '12:34:56'
+
+ .. versionadded:: 3.6
+ Added the *timespec* argument.
+
.. method:: time.__str__()
@@ -1430,7 +1551,8 @@ Instance methods:
.. method:: time.__format__(format)
Same as :meth:`.time.strftime`. This makes it possible to specify a format string
- for a :class:`.time` object when using :meth:`str.format`. For a
+ for a :class:`.time` object in :ref:`formatted string
+ literals <f-strings>` and when using :meth:`str.format`. For a
complete list of formatting directives, see
:ref:`strftime-strptime-behavior`.
@@ -1680,9 +1802,19 @@ minute after 1:59 (EST) on the second Sunday in March, and ends the minute after
When DST starts (the "start" line), the local wall clock leaps from 1:59 to
3:00. A wall time of the form 2:MM doesn't really make sense on that day, so
``astimezone(Eastern)`` won't deliver a result with ``hour == 2`` on the day DST
-begins. In order for :meth:`astimezone` to make this guarantee, the
-:meth:`tzinfo.dst` method must consider times in the "missing hour" (2:MM for
-Eastern) to be in daylight time.
+begins. For example, at the Spring forward transition of 2016, we get
+
+ >>> u0 = datetime(2016, 3, 13, 5, tzinfo=timezone.utc)
+ >>> for i in range(4):
+ ... u = u0 + i*HOUR
+ ... t = u.astimezone(Eastern)
+ ... print(u.time(), 'UTC =', t.time(), t.tzname())
+ ...
+ 05:00:00 UTC = 00:00:00 EST
+ 06:00:00 UTC = 01:00:00 EST
+ 07:00:00 UTC = 03:00:00 EDT
+ 08:00:00 UTC = 04:00:00 EDT
+
When DST ends (the "end" line), there's a potentially worse problem: there's an
hour that can't be spelled unambiguously in local wall time: the last hour of
@@ -1691,28 +1823,41 @@ daylight time ends. The local wall clock leaps from 1:59 (daylight time) back
to 1:00 (standard time) again. Local times of the form 1:MM are ambiguous.
:meth:`astimezone` mimics the local clock's behavior by mapping two adjacent UTC
hours into the same local hour then. In the Eastern example, UTC times of the
-form 5:MM and 6:MM both map to 1:MM when converted to Eastern. In order for
-:meth:`astimezone` to make this guarantee, the :meth:`tzinfo.dst` method must
-consider times in the "repeated hour" to be in standard time. This is easily
-arranged, as in the example, by expressing DST switch times in the time zone's
-standard local time.
+form 5:MM and 6:MM both map to 1:MM when converted to Eastern, but earlier times
+have the :attr:`~datetime.fold` attribute set to 0 and the later times have it set to 1.
+For example, at the Fall back transition of 2016, we get
+
+ >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)
+ >>> for i in range(4):
+ ... u = u0 + i*HOUR
+ ... t = u.astimezone(Eastern)
+ ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold)
+ ...
+ 04:00:00 UTC = 00:00:00 EDT 0
+ 05:00:00 UTC = 01:00:00 EDT 0
+ 06:00:00 UTC = 01:00:00 EST 1
+ 07:00:00 UTC = 02:00:00 EST 0
+
+Note that the :class:`datetime` instances that differ only by the value of the
+:attr:`~datetime.fold` attribute are considered equal in comparisons.
-Applications that can't bear such ambiguities should avoid using hybrid
+Applications that can't bear wall-time ambiguities should explicitly check the
+value of the :attr:`~datetime.fold` attribute or avoid using hybrid
:class:`tzinfo` subclasses; there are no ambiguities when using :class:`timezone`,
or any other fixed-offset :class:`tzinfo` subclass (such as a class representing
only EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
.. seealso::
- `pytz <https://pypi.python.org/pypi/pytz/>`_
+ `datetuil.tz <https://dateutil.readthedocs.io/en/stable/tz.html>`_
The standard library has :class:`timezone` class for handling arbitrary
fixed offsets from UTC and :attr:`timezone.utc` as UTC timezone instance.
- *pytz* library brings the *IANA timezone database* (also known as the
+ *datetuil.tz* library brings the *IANA timezone database* (also known as the
Olson database) to Python and its usage is recommended.
`IANA timezone database <https://www.iana.org/time-zones>`_
- The Time Zone Database (often called tz or zoneinfo) contains code and
+ The Time Zone Database (often called tz, tzdata or zoneinfo) contains code and
data that represent the history of local time for many representative
locations around the globe. It is updated periodically to reflect changes
made by political bodies to time zone boundaries, UTC offsets, and
@@ -1732,7 +1877,7 @@ in different days of the year or where historical changes have been
made to civil time.
-.. class:: timezone(offset[, name])
+.. class:: timezone(offset, name=None)
The *offset* argument must be specified as a :class:`timedelta`
object representing the difference between the local time and UTC. It must
@@ -1741,10 +1886,7 @@ made to civil time.
otherwise :exc:`ValueError` is raised.
The *name* argument is optional. If specified it must be a string that
- is used as the value returned by the ``tzname(dt)`` method. Otherwise,
- ``tzname(dt)`` returns a string 'UTCsHH:MM', where s is the sign of
- *offset*, HH and MM are two digits of ``offset.hours`` and
- ``offset.minutes`` respectively.
+ will be used as the value returned by the :meth:`datetime.tzname` method.
.. versionadded:: 3.2
@@ -1757,11 +1899,19 @@ made to civil time.
.. method:: timezone.tzname(dt)
- Return the fixed value specified when the :class:`timezone` instance is
- constructed or a string 'UTCsHH:MM', where s is the sign of
- *offset*, HH and MM are two digits of ``offset.hours`` and
+ Return the fixed value specified when the :class:`timezone` instance
+ is constructed. If *name* is not provided in the constructor, the
+ name returned by ``tzname(dt)`` is generated from the value of the
+ ``offset`` as follows. If *offset* is ``timedelta(0)``, the name
+ is "UTC", otherwise it is a string 'UTC±HH:MM', where ± is the sign
+ of ``offset``, HH and MM are two digits of ``offset.hours`` and
``offset.minutes`` respectively.
+ .. versionchanged:: 3.6
+ Name generated from ``offset=timedelta(0)`` is now plain 'UTC', not
+ 'UTC+00:00'.
+
+
.. method:: timezone.dst(dt)
Always returns ``None``.
@@ -1911,6 +2061,34 @@ format codes.
| ``%%`` | A literal ``'%'`` character. | % | |
+-----------+--------------------------------+------------------------+-------+
+Several additional directives not required by the C89 standard are included for
+convenience. These parameters all correspond to ISO 8601 date values. These
+may not be available on all platforms when used with the :meth:`strftime`
+method. The ISO 8601 year and ISO 8601 week directives are not interchangeable
+with the year and week number directives above. Calling :meth:`strptime` with
+incomplete or ambiguous ISO 8601 directives will raise a :exc:`ValueError`.
+
++-----------+--------------------------------+------------------------+-------+
+| Directive | Meaning | Example | Notes |
++===========+================================+========================+=======+
+| ``%G`` | ISO 8601 year with century | 0001, 0002, ..., 2013, | \(8) |
+| | representing the year that | 2014, ..., 9998, 9999 | |
+| | contains the greater part of | | |
+| | the ISO week (``%V``). | | |
++-----------+--------------------------------+------------------------+-------+
+| ``%u`` | ISO 8601 weekday as a decimal | 1, 2, ..., 7 | |
+| | number where 1 is Monday. | | |
++-----------+--------------------------------+------------------------+-------+
+| ``%V`` | ISO 8601 week as a decimal | 01, 02, ..., 53 | \(8) |
+| | number with Monday as | | |
+| | the first day of the week. | | |
+| | Week 01 is the week containing | | |
+| | Jan 4. | | |
++-----------+--------------------------------+------------------------+-------+
+
+.. versionadded:: 3.6
+ ``%G``, ``%u`` and ``%V`` were added.
+
Notes:
(1)
@@ -1975,7 +2153,14 @@ Notes:
(7)
When used with the :meth:`strptime` method, ``%U`` and ``%W`` are only used
- in calculations when the day of the week and the year are specified.
+ in calculations when the day of the week and the calendar year (``%Y``)
+ are specified.
+
+(8)
+ Similar to ``%U`` and ``%W``, ``%V`` is only used in calculations when the
+ day of the week and the ISO year (``%G``) are specified in a
+ :meth:`strptime` format string. Also note that ``%G`` and ``%Y`` are not
+ interchangeable.
.. rubric:: Footnotes
diff --git a/Doc/library/dbm.rst b/Doc/library/dbm.rst
index 2a1db91..32e80b2 100644
--- a/Doc/library/dbm.rst
+++ b/Doc/library/dbm.rst
@@ -351,6 +351,10 @@ The module defines the following:
:func:`.open` always creates a new database when the flag has the value
``'n'``.
+ .. deprecated-removed:: 3.6 3.8
+ Creating database in ``'r'`` and ``'w'`` modes. Modifying database in
+ ``'r'`` mode.
+
In addition to the methods provided by the
:class:`collections.abc.MutableMapping` class, :class:`dumbdbm` objects
provide the following methods:
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
index b5ce0b1..e984edc 100644
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -345,7 +345,7 @@ Decimal objects
*value* can be an integer, string, tuple, :class:`float`, or another :class:`Decimal`
object. If no *value* is given, returns ``Decimal('0')``. If *value* is a
string, it should conform to the decimal numeric string syntax after leading
- and trailing whitespace characters are removed::
+ and trailing whitespace characters, as well as underscores throughout, are removed::
sign ::= '+' | '-'
digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
@@ -394,6 +394,10 @@ Decimal objects
:class:`float` arguments raise an exception if the :exc:`FloatOperation`
trap is set. By default the trap is off.
+ .. versionchanged:: 3.6
+ Underscores are allowed for grouping, as with integral and floating-point
+ literals in code.
+
Decimal floating point objects share many properties with the other built-in
numeric types such as :class:`float` and :class:`int`. All of the usual math
operations and special methods apply. Likewise, decimal objects can be
@@ -447,6 +451,19 @@ Decimal objects
``Decimal('321e+5').adjusted()`` returns seven. Used for determining the
position of the most significant digit with respect to the decimal point.
+ .. method:: as_integer_ratio()
+
+ Return a pair ``(n, d)`` of integers that represent the given
+ :class:`Decimal` instance as a fraction, in lowest terms and
+ with a positive denominator::
+
+ >>> Decimal('-3.14').as_integer_ratio()
+ (-157, 50)
+
+ The conversion is exact. Raise OverflowError on infinities and ValueError
+ on NaNs.
+
+ .. versionadded:: 3.6
.. method:: as_tuple()
@@ -1062,8 +1079,8 @@ In addition to the three supplied contexts, new contexts can be created with the
Decimal('4.44')
This method implements the to-number operation of the IBM specification.
- If the argument is a string, no leading or trailing whitespace is
- permitted.
+ If the argument is a string, no leading or trailing whitespace or
+ underscores are permitted.
.. method:: create_decimal_from_float(f)
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index f86725b..a15690b 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -31,9 +31,9 @@ the following command can be used to display the disassembly of
>>> dis.dis(myfunc)
2 0 LOAD_GLOBAL 0 (len)
- 3 LOAD_FAST 0 (alist)
- 6 CALL_FUNCTION 1
- 9 RETURN_VALUE
+ 2 LOAD_FAST 0 (alist)
+ 4 CALL_FUNCTION 1
+ 6 RETURN_VALUE
(The "2" is a line number).
@@ -607,6 +607,14 @@ iterations of the loop.
.. versionadded:: 3.3
+.. opcode:: SETUP_ANNOTATIONS
+
+ Checks whether ``__annotations__`` is defined in ``locals()``, if not it is
+ set up to an empty ``dict``. This opcode is only emitted if a class
+ or module body contains :term:`variable annotations <variable annotation>`
+ statically.
+
+ .. versionadded:: 3.6
.. opcode:: IMPORT_STAR
@@ -682,8 +690,7 @@ iterations of the loop.
.. XXX explain the WHY stuff!
-All of the following opcodes expect arguments. An argument is two bytes, with
-the more significant byte last.
+All of the following opcodes use their arguments.
.. opcode:: STORE_NAME (namei)
@@ -769,6 +776,23 @@ the more significant byte last.
to hold *count* entries.
+.. opcode:: BUILD_CONST_KEY_MAP (count)
+
+ The version of :opcode:`BUILD_MAP` specialized for constant keys. *count*
+ values are consumed from the stack. The top element on the stack contains
+ a tuple of keys.
+
+ .. versionadded:: 3.6
+
+
+.. opcode:: BUILD_STRING (count)
+
+ Concatenates *count* strings from the stack and pushes the resulting string
+ onto the stack.
+
+ .. versionadded:: 3.6
+
+
.. opcode:: LOAD_ATTR (namei)
Replaces TOS with ``getattr(TOS, co_names[namei])``.
@@ -874,6 +898,13 @@ the more significant byte last.
Deletes local ``co_varnames[var_num]``.
+.. opcode:: STORE_ANNOTATION (namei)
+
+ Stores TOS as ``locals()['__annotations__'][co_names[namei]] = TOS``.
+
+ .. versionadded:: 3.6
+
+
.. opcode:: LOAD_CLOSURE (i)
Pushes a reference to the cell contained in slot *i* of the cell and free
@@ -929,27 +960,16 @@ the more significant byte last.
.. opcode:: MAKE_FUNCTION (argc)
Pushes a new function object on the stack. From bottom to top, the consumed
- stack must consist of
-
- * ``argc & 0xFF`` default argument objects in positional order
- * ``(argc >> 8) & 0xFF`` pairs of name and default argument, with the name
- just below the object on the stack, for keyword-only parameters
- * ``(argc >> 16) & 0x7FFF`` parameter annotation objects
- * a tuple listing the parameter names for the annotations (only if there are
- ony annotation objects)
+ stack must consist of values if the argument carries a specified flag value
+
+ * ``0x01`` a tuple of default argument objects in positional order
+ * ``0x02`` a dictionary of keyword-only parameters' default values
+ * ``0x04`` an annotation dictionary
+ * ``0x08`` a tuple containing cells for free variables, making a closure
* the code associated with the function (at TOS1)
* the :term:`qualified name` of the function (at TOS)
-.. opcode:: MAKE_CLOSURE (argc)
-
- Creates a new function object, sets its *__closure__* slot, and pushes it on
- the stack. TOS is the :term:`qualified name` of the function, TOS1 is the
- code associated with the function, and TOS2 is the tuple containing cells for
- the closure's free variables. *argc* is interpreted as in ``MAKE_FUNCTION``;
- the annotations and defaults are also in the same order below TOS2.
-
-
.. opcode:: BUILD_SLICE (argc)
.. index:: builtin: slice
@@ -989,6 +1009,28 @@ the more significant byte last.
arguments.
+.. opcode:: FORMAT_VALUE (flags)
+
+ Used for implementing formatted literal strings (f-strings). Pops
+ an optional *fmt_spec* from the stack, then a required *value*.
+ *flags* is interpreted as follows:
+
+ * ``(flags & 0x03) == 0x00``: *value* is formatted as-is.
+ * ``(flags & 0x03) == 0x01``: call :func:`str` on *value* before
+ formatting it.
+ * ``(flags & 0x03) == 0x02``: call :func:`repr` on *value* before
+ formatting it.
+ * ``(flags & 0x03) == 0x03``: call :func:`ascii` on *value* before
+ formatting it.
+ * ``(flags & 0x04) == 0x04``: pop *fmt_spec* from the stack and use
+ it, else use an empty *fmt_spec*.
+
+ Formatting is performed using :c:func:`PyObject_Format`. The
+ result is pushed on the stack.
+
+ .. versionadded:: 3.6
+
+
.. opcode:: HAVE_ARGUMENT
This is not really an opcode. It identifies the dividing line between
diff --git a/Doc/library/email.charset.rst b/Doc/library/email.charset.rst
index 161d86a..053463f 100644
--- a/Doc/library/email.charset.rst
+++ b/Doc/library/email.charset.rst
@@ -8,6 +8,11 @@
--------------
+This module is part of the legacy (``Compat32``) email API. In the new
+API only the aliases table is used.
+
+The remaining text in this section is the original documentation of the module.
+
This module provides a class :class:`Charset` for representing character sets
and character set conversions in email messages, as well as a character set
registry and several convenience methods for manipulating this registry.
diff --git a/Doc/library/email.compat32-message.rst b/Doc/library/email.compat32-message.rst
new file mode 100644
index 0000000..2c65079
--- /dev/null
+++ b/Doc/library/email.compat32-message.rst
@@ -0,0 +1,754 @@
+.. _compat32_message:
+
+:mod:`email.message.Message`: Representing an email message using the :data:`~email.policy.compat32` API
+--------------------------------------------------------------------------------------------------------
+
+.. module:: email.message
+ :synopsis: The base class representing email messages in a fashion
+ backward compatible with python3.2
+
+
+The :class:`Message` class is very similar to the
+:class:`~email.message.EmailMessage` class, without the methods added by that
+class, and with the default behavior of certain other methods being slightly
+different. We also document here some methods that, while supported by the
+:class:`~email.message.EmailMessage` class, are not recommended unless you are
+dealing with legacy code.
+
+The philosophy and structure of the two classes is otherwise the same.
+
+This document describes the behavior under the default (for :class:`Message`)
+policy :attr:`~email.policy.Compat32`. If you are going to use another policy,
+you should be using the :class:`~email.message.EmailMessage` class instead.
+
+An email message consists of *headers* and a *payload*. Headers must be
+:rfc:`5233` style names and values, where the field name and value are
+separated by a colon. The colon is not part of either the field name or the
+field value. The payload may be a simple text message, or a binary object, or
+a structured sequence of sub-messages each with their own set of headers and
+their own payload. The latter type of payload is indicated by the message
+having a MIME type such as :mimetype:`multipart/\*` or
+:mimetype:`message/rfc822`.
+
+The conceptual model provided by a :class:`Message` object is that of an
+ordered dictionary of headers with additional methods for accessing both
+specialized information from the headers, for accessing the payload, for
+generating a serialized version of the mssage, and for recursively walking over
+the object tree. Note that duplicate headers are supported but special methods
+must be used to access them.
+
+The :class:`Message` psuedo-dictionary is indexed by the header names, which
+must be ASCII values. The values of the dictionary are strings that are
+supposed to contain only ASCII characters; there is some special handling for
+non-ASCII input, but it doesn't always produce the correct results. Headers
+are stored and returned in case-preserving form, but field names are matched
+case-insensitively. There may also be a single envelope header, also known as
+the *Unix-From* header or the ``From_`` header. The *payload* is either a
+string or bytes, in the case of simple message objects, or a list of
+:class:`Message` objects, for MIME container documents (e.g.
+:mimetype:`multipart/\*` and :mimetype:`message/rfc822`).
+
+Here are the methods of the :class:`Message` class:
+
+
+.. class:: Message(policy=compat32)
+
+ If *policy* is specified (it must be an instance of a :mod:`~email.policy`
+ class) use the rules it specifies to update and serialize the representation
+ of the message. If *policy* is not set, use the :class:`compat32
+ <email.policy.Compat32>` policy, which maintains backward compatibility with
+ the Python 3.2 version of the email package. For more information see the
+ :mod:`~email.policy` documentation.
+
+ .. versionchanged:: 3.3 The *policy* keyword argument was added.
+
+
+ .. method:: as_string(unixfrom=False, maxheaderlen=0, policy=None)
+
+ Return the entire message flattened as a string. When optional *unixfrom*
+ is true, the envelope header is included in the returned string.
+ *unixfrom* defaults to ``False``. For backward compabitility reasons,
+ *maxheaderlen* defaults to ``0``, so if you want a different value you
+ must override it explicitly (the value specified for *max_line_length* in
+ the policy will be ignored by this method). The *policy* argument may be
+ used to override the default policy obtained from the message instance.
+ This can be used to control some of the formatting produced by the
+ method, since the specified *policy* will be passed to the ``Generator``.
+
+ Flattening the message may trigger changes to the :class:`Message` if
+ defaults need to be filled in to complete the transformation to a string
+ (for example, MIME boundaries may be generated or modified).
+
+ Note that this method is provided as a convenience and may not always
+ format the message the way you want. For example, by default it does
+ not do the mangling of lines that begin with ``From`` that is
+ required by the unix mbox format. For more flexibility, instantiate a
+ :class:`~email.generator.Generator` instance and use its
+ :meth:`~email.generator.Generator.flatten` method directly. For example::
+
+ from io import StringIO
+ from email.generator import Generator
+ fp = StringIO()
+ g = Generator(fp, mangle_from_=True, maxheaderlen=60)
+ g.flatten(msg)
+ text = fp.getvalue()
+
+ If the message object contains binary data that is not encoded according
+ to RFC standards, the non-compliant data will be replaced by unicode
+ "unknown character" code points. (See also :meth:`.as_bytes` and
+ :class:`~email.generator.BytesGenerator`.)
+
+ .. versionchanged:: 3.4 the *policy* keyword argument was added.
+
+
+ .. method:: __str__()
+
+ Equivalent to :meth:`.as_string()`. Allows ``str(msg)`` to produce a
+ string containing the formatted message.
+
+
+ .. method:: as_bytes(unixfrom=False, policy=None)
+
+ Return the entire message flattened as a bytes object. When optional
+ *unixfrom* is true, the envelope header is included in the returned
+ string. *unixfrom* defaults to ``False``. The *policy* argument may be
+ used to override the default policy obtained from the message instance.
+ This can be used to control some of the formatting produced by the
+ method, since the specified *policy* will be passed to the
+ ``BytesGenerator``.
+
+ Flattening the message may trigger changes to the :class:`Message` if
+ defaults need to be filled in to complete the transformation to a string
+ (for example, MIME boundaries may be generated or modified).
+
+ Note that this method is provided as a convenience and may not always
+ format the message the way you want. For example, by default it does
+ not do the mangling of lines that begin with ``From`` that is
+ required by the unix mbox format. For more flexibility, instantiate a
+ :class:`~email.generator.BytesGenerator` instance and use its
+ :meth:`~email.generator.BytesGenerator.flatten` method directly.
+ For example::
+
+ from io import BytesIO
+ from email.generator import BytesGenerator
+ fp = BytesIO()
+ g = BytesGenerator(fp, mangle_from_=True, maxheaderlen=60)
+ g.flatten(msg)
+ text = fp.getvalue()
+
+ .. versionadded:: 3.4
+
+
+ .. method:: __bytes__()
+
+ Equivalent to :meth:`.as_bytes()`. Allows ``bytes(msg)`` to produce a
+ bytes object containing the formatted message.
+
+ .. versionadded:: 3.4
+
+
+ .. method:: is_multipart()
+
+ Return ``True`` if the message's payload is a list of sub-\
+ :class:`Message` objects, otherwise return ``False``. When
+ :meth:`is_multipart` returns ``False``, the payload should be a string
+ object (which might be a CTE encoded binary payload. (Note that
+ :meth:`is_multipart` returning ``True`` does not necessarily mean that
+ "msg.get_content_maintype() == 'multipart'" will return the ``True``.
+ For example, ``is_multipart`` will return ``True`` when the
+ :class:`Message` is of type ``message/rfc822``.)
+
+
+ .. method:: set_unixfrom(unixfrom)
+
+ Set the message's envelope header to *unixfrom*, which should be a string.
+
+
+ .. method:: get_unixfrom()
+
+ Return the message's envelope header. Defaults to ``None`` if the
+ envelope header was never set.
+
+
+ .. method:: attach(payload)
+
+ Add the given *payload* to the current payload, which must be ``None`` or
+ a list of :class:`Message` objects before the call. After the call, the
+ payload will always be a list of :class:`Message` objects. If you want to
+ set the payload to a scalar object (e.g. a string), use
+ :meth:`set_payload` instead.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class its functionality is
+ replaced by :meth:`~email.message.EmailMessage.set_content` and the
+ realted ``make`` and ``add`` methods.
+
+
+ .. method:: get_payload(i=None, decode=False)
+
+ Return the current payload, which will be a list of
+ :class:`Message` objects when :meth:`is_multipart` is ``True``, or a
+ string when :meth:`is_multipart` is ``False``. If the payload is a list
+ and you mutate the list object, you modify the message's payload in place.
+
+ With optional argument *i*, :meth:`get_payload` will return the *i*-th
+ element of the payload, counting from zero, if :meth:`is_multipart` is
+ ``True``. An :exc:`IndexError` will be raised if *i* is less than 0 or
+ greater than or equal to the number of items in the payload. If the
+ payload is a string (i.e. :meth:`is_multipart` is ``False``) and *i* is
+ given, a :exc:`TypeError` is raised.
+
+ Optional *decode* is a flag indicating whether the payload should be
+ decoded or not, according to the :mailheader:`Content-Transfer-Encoding`
+ header. When ``True`` and the message is not a multipart, the payload will
+ be decoded if this header's value is ``quoted-printable`` or ``base64``.
+ If some other encoding is used, or :mailheader:`Content-Transfer-Encoding`
+ header is missing, the payload is
+ returned as-is (undecoded). In all cases the returned value is binary
+ data. If the message is a multipart and the *decode* flag is ``True``,
+ then ``None`` is returned. If the payload is base64 and it was not
+ perfectly formed (missing padding, characters outside the base64
+ alphabet), then an appropriate defect will be added to the message's
+ defect property (:class:`~email.errors.InvalidBase64PaddingDefect` or
+ :class:`~email.errors.InvalidBase64CharactersDefect`, respectively).
+
+ When *decode* is ``False`` (the default) the body is returned as a string
+ without decoding the :mailheader:`Content-Transfer-Encoding`. However,
+ for a :mailheader:`Content-Transfer-Encoding` of 8bit, an attempt is made
+ to decode the original bytes using the ``charset`` specified by the
+ :mailheader:`Content-Type` header, using the ``replace`` error handler.
+ If no ``charset`` is specified, or if the ``charset`` given is not
+ recognized by the email package, the body is decoded using the default
+ ASCII charset.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class its functionality is
+ replaced by :meth:`~email.message.EmailMessage.get_content` and
+ :meth:`~email.message.EmailMessage.iter_parts`.
+
+
+ .. method:: set_payload(payload, charset=None)
+
+ Set the entire message object's payload to *payload*. It is the client's
+ responsibility to ensure the payload invariants. Optional *charset* sets
+ the message's default character set; see :meth:`set_charset` for details.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class its functionality is
+ replaced by :meth:`~email.message.EmailMessage.set_content`.
+
+
+ .. method:: set_charset(charset)
+
+ Set the character set of the payload to *charset*, which can either be a
+ :class:`~email.charset.Charset` instance (see :mod:`email.charset`), a
+ string naming a character set, or ``None``. If it is a string, it will
+ be converted to a :class:`~email.charset.Charset` instance. If *charset*
+ is ``None``, the ``charset`` parameter will be removed from the
+ :mailheader:`Content-Type` header (the message will not be otherwise
+ modified). Anything else will generate a :exc:`TypeError`.
+
+ If there is no existing :mailheader:`MIME-Version` header one will be
+ added. If there is no existing :mailheader:`Content-Type` header, one
+ will be added with a value of :mimetype:`text/plain`. Whether the
+ :mailheader:`Content-Type` header already exists or not, its ``charset``
+ parameter will be set to *charset.output_charset*. If
+ *charset.input_charset* and *charset.output_charset* differ, the payload
+ will be re-encoded to the *output_charset*. If there is no existing
+ :mailheader:`Content-Transfer-Encoding` header, then the payload will be
+ transfer-encoded, if needed, using the specified
+ :class:`~email.charset.Charset`, and a header with the appropriate value
+ will be added. If a :mailheader:`Content-Transfer-Encoding` header
+ already exists, the payload is assumed to already be correctly encoded
+ using that :mailheader:`Content-Transfer-Encoding` and is not modified.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class its functionality is
+ replaced by the *charset* parameter of the
+ :meth:`email.emailmessage.EmailMessage.set_content` method.
+
+
+ .. method:: get_charset()
+
+ Return the :class:`~email.charset.Charset` instance associated with the
+ message's payload.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class it always returns
+ ``None``.
+
+
+ The following methods implement a mapping-like interface for accessing the
+ message's :rfc:`2822` headers. Note that there are some semantic differences
+ between these methods and a normal mapping (i.e. dictionary) interface. For
+ example, in a dictionary there are no duplicate keys, but here there may be
+ duplicate message headers. Also, in dictionaries there is no guaranteed
+ order to the keys returned by :meth:`keys`, but in a :class:`Message` object,
+ headers are always returned in the order they appeared in the original
+ message, or were added to the message later. Any header deleted and then
+ re-added are always appended to the end of the header list.
+
+ These semantic differences are intentional and are biased toward maximal
+ convenience.
+
+ Note that in all cases, any envelope header present in the message is not
+ included in the mapping interface.
+
+ In a model generated from bytes, any header values that (in contravention of
+ the RFCs) contain non-ASCII bytes will, when retrieved through this
+ interface, be represented as :class:`~email.header.Header` objects with
+ a charset of `unknown-8bit`.
+
+
+ .. method:: __len__()
+
+ Return the total number of headers, including duplicates.
+
+
+ .. method:: __contains__(name)
+
+ Return true if the message object has a field named *name*. Matching is
+ done case-insensitively and *name* should not include the trailing colon.
+ Used for the ``in`` operator, e.g.::
+
+ if 'message-id' in myMessage:
+ print('Message-ID:', myMessage['message-id'])
+
+
+ .. method:: __getitem__(name)
+
+ Return the value of the named header field. *name* should not include the
+ colon field separator. If the header is missing, ``None`` is returned; a
+ :exc:`KeyError` is never raised.
+
+ Note that if the named field appears more than once in the message's
+ headers, exactly which of those field values will be returned is
+ undefined. Use the :meth:`get_all` method to get the values of all the
+ extant named headers.
+
+
+ .. method:: __setitem__(name, val)
+
+ Add a header to the message with field name *name* and value *val*. The
+ field is appended to the end of the message's existing fields.
+
+ Note that this does *not* overwrite or delete any existing header with the same
+ name. If you want to ensure that the new header is the only one present in the
+ message with field name *name*, delete the field first, e.g.::
+
+ del msg['subject']
+ msg['subject'] = 'Python roolz!'
+
+
+ .. method:: __delitem__(name)
+
+ Delete all occurrences of the field with name *name* from the message's
+ headers. No exception is raised if the named field isn't present in the
+ headers.
+
+
+ .. method:: keys()
+
+ Return a list of all the message's header field names.
+
+
+ .. method:: values()
+
+ Return a list of all the message's field values.
+
+
+ .. method:: items()
+
+ Return a list of 2-tuples containing all the message's field headers and
+ values.
+
+
+ .. method:: get(name, failobj=None)
+
+ Return the value of the named header field. This is identical to
+ :meth:`__getitem__` except that optional *failobj* is returned if the
+ named header is missing (defaults to ``None``).
+
+ Here are some additional useful methods:
+
+
+ .. method:: get_all(name, failobj=None)
+
+ Return a list of all the values for the field named *name*. If there are
+ no such named headers in the message, *failobj* is returned (defaults to
+ ``None``).
+
+
+ .. method:: add_header(_name, _value, **_params)
+
+ Extended header setting. This method is similar to :meth:`__setitem__`
+ except that additional header parameters can be provided as keyword
+ arguments. *_name* is the header field to add and *_value* is the
+ *primary* value for the header.
+
+ For each item in the keyword argument dictionary *_params*, the key is
+ taken as the parameter name, with underscores converted to dashes (since
+ dashes are illegal in Python identifiers). Normally, the parameter will
+ be added as ``key="value"`` unless the value is ``None``, in which case
+ only the key will be added. If the value contains non-ASCII characters,
+ it can be specified as a three tuple in the format
+ ``(CHARSET, LANGUAGE, VALUE)``, where ``CHARSET`` is a string naming the
+ charset to be used to encode the value, ``LANGUAGE`` can usually be set
+ to ``None`` or the empty string (see :rfc:`2231` for other possibilities),
+ and ``VALUE`` is the string value containing non-ASCII code points. If
+ a three tuple is not passed and the value contains non-ASCII characters,
+ it is automatically encoded in :rfc:`2231` format using a ``CHARSET``
+ of ``utf-8`` and a ``LANGUAGE`` of ``None``.
+
+ Here's an example::
+
+ msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
+
+ This will add a header that looks like ::
+
+ Content-Disposition: attachment; filename="bud.gif"
+
+ An example with non-ASCII characters::
+
+ msg.add_header('Content-Disposition', 'attachment',
+ filename=('iso-8859-1', '', 'Fußballer.ppt'))
+
+ Which produces ::
+
+ Content-Disposition: attachment; filename*="iso-8859-1''Fu%DFballer.ppt"
+
+
+ .. method:: replace_header(_name, _value)
+
+ Replace a header. Replace the first header found in the message that
+ matches *_name*, retaining header order and field name case. If no
+ matching header was found, a :exc:`KeyError` is raised.
+
+
+ .. method:: get_content_type()
+
+ Return the message's content type. The returned string is coerced to
+ lower case of the form :mimetype:`maintype/subtype`. If there was no
+ :mailheader:`Content-Type` header in the message the default type as given
+ by :meth:`get_default_type` will be returned. Since according to
+ :rfc:`2045`, messages always have a default type, :meth:`get_content_type`
+ will always return a value.
+
+ :rfc:`2045` defines a message's default type to be :mimetype:`text/plain`
+ unless it appears inside a :mimetype:`multipart/digest` container, in
+ which case it would be :mimetype:`message/rfc822`. If the
+ :mailheader:`Content-Type` header has an invalid type specification,
+ :rfc:`2045` mandates that the default type be :mimetype:`text/plain`.
+
+
+ .. method:: get_content_maintype()
+
+ Return the message's main content type. This is the :mimetype:`maintype`
+ part of the string returned by :meth:`get_content_type`.
+
+
+ .. method:: get_content_subtype()
+
+ Return the message's sub-content type. This is the :mimetype:`subtype`
+ part of the string returned by :meth:`get_content_type`.
+
+
+ .. method:: get_default_type()
+
+ Return the default content type. Most messages have a default content
+ type of :mimetype:`text/plain`, except for messages that are subparts of
+ :mimetype:`multipart/digest` containers. Such subparts have a default
+ content type of :mimetype:`message/rfc822`.
+
+
+ .. method:: set_default_type(ctype)
+
+ Set the default content type. *ctype* should either be
+ :mimetype:`text/plain` or :mimetype:`message/rfc822`, although this is not
+ enforced. The default content type is not stored in the
+ :mailheader:`Content-Type` header.
+
+
+ .. method:: get_params(failobj=None, header='content-type', unquote=True)
+
+ Return the message's :mailheader:`Content-Type` parameters, as a list.
+ The elements of the returned list are 2-tuples of key/value pairs, as
+ split on the ``'='`` sign. The left hand side of the ``'='`` is the key,
+ while the right hand side is the value. If there is no ``'='`` sign in
+ the parameter the value is the empty string, otherwise the value is as
+ described in :meth:`get_param` and is unquoted if optional *unquote* is
+ ``True`` (the default).
+
+ Optional *failobj* is the object to return if there is no
+ :mailheader:`Content-Type` header. Optional *header* is the header to
+ search instead of :mailheader:`Content-Type`.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class its functionality is
+ replaced by the *params* property of the individual header objects
+ returned by the header access methods.
+
+
+ .. method:: get_param(param, failobj=None, header='content-type', unquote=True)
+
+ Return the value of the :mailheader:`Content-Type` header's parameter
+ *param* as a string. If the message has no :mailheader:`Content-Type`
+ header or if there is no such parameter, then *failobj* is returned
+ (defaults to ``None``).
+
+ Optional *header* if given, specifies the message header to use instead of
+ :mailheader:`Content-Type`.
+
+ Parameter keys are always compared case insensitively. The return value
+ can either be a string, or a 3-tuple if the parameter was :rfc:`2231`
+ encoded. When it's a 3-tuple, the elements of the value are of the form
+ ``(CHARSET, LANGUAGE, VALUE)``. Note that both ``CHARSET`` and
+ ``LANGUAGE`` can be ``None``, in which case you should consider ``VALUE``
+ to be encoded in the ``us-ascii`` charset. You can usually ignore
+ ``LANGUAGE``.
+
+ If your application doesn't care whether the parameter was encoded as in
+ :rfc:`2231`, you can collapse the parameter value by calling
+ :func:`email.utils.collapse_rfc2231_value`, passing in the return value
+ from :meth:`get_param`. This will return a suitably decoded Unicode
+ string when the value is a tuple, or the original string unquoted if it
+ isn't. For example::
+
+ rawparam = msg.get_param('foo')
+ param = email.utils.collapse_rfc2231_value(rawparam)
+
+ In any case, the parameter value (either the returned string, or the
+ ``VALUE`` item in the 3-tuple) is always unquoted, unless *unquote* is set
+ to ``False``.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class its functionality is
+ replaced by the *params* property of the individual header objects
+ returned by the header access methods.
+
+
+ .. method:: set_param(param, value, header='Content-Type', requote=True, \
+ charset=None, language='', replace=False)
+
+ Set a parameter in the :mailheader:`Content-Type` header. If the
+ parameter already exists in the header, its value will be replaced with
+ *value*. If the :mailheader:`Content-Type` header as not yet been defined
+ for this message, it will be set to :mimetype:`text/plain` and the new
+ parameter value will be appended as per :rfc:`2045`.
+
+ Optional *header* specifies an alternative header to
+ :mailheader:`Content-Type`, and all parameters will be quoted as necessary
+ unless optional *requote* is ``False`` (the default is ``True``).
+
+ If optional *charset* is specified, the parameter will be encoded
+ according to :rfc:`2231`. Optional *language* specifies the RFC 2231
+ language, defaulting to the empty string. Both *charset* and *language*
+ should be strings.
+
+ If *replace* is ``False`` (the default) the header is moved to the
+ end of the list of headers. If *replace* is ``True``, the header
+ will be updated in place.
+
+ .. versionchanged:: 3.4 ``replace`` keyword was added.
+
+
+ .. method:: del_param(param, header='content-type', requote=True)
+
+ Remove the given parameter completely from the :mailheader:`Content-Type`
+ header. The header will be re-written in place without the parameter or
+ its value. All values will be quoted as necessary unless *requote* is
+ ``False`` (the default is ``True``). Optional *header* specifies an
+ alternative to :mailheader:`Content-Type`.
+
+
+ .. method:: set_type(type, header='Content-Type', requote=True)
+
+ Set the main type and subtype for the :mailheader:`Content-Type`
+ header. *type* must be a string in the form :mimetype:`maintype/subtype`,
+ otherwise a :exc:`ValueError` is raised.
+
+ This method replaces the :mailheader:`Content-Type` header, keeping all
+ the parameters in place. If *requote* is ``False``, this leaves the
+ existing header's quoting as is, otherwise the parameters will be quoted
+ (the default).
+
+ An alternative header can be specified in the *header* argument. When the
+ :mailheader:`Content-Type` header is set a :mailheader:`MIME-Version`
+ header is also added.
+
+ This is a legacy method. On the
+ :class:`~email.emailmessage.EmailMessage` class its functionality is
+ replaced by the ``make_`` and ``add_`` methods.
+
+
+ .. method:: get_filename(failobj=None)
+
+ Return the value of the ``filename`` parameter of the
+ :mailheader:`Content-Disposition` header of the message. If the header
+ does not have a ``filename`` parameter, this method falls back to looking
+ for the ``name`` parameter on the :mailheader:`Content-Type` header. If
+ neither is found, or the header is missing, then *failobj* is returned.
+ The returned string will always be unquoted as per
+ :func:`email.utils.unquote`.
+
+
+ .. method:: get_boundary(failobj=None)
+
+ Return the value of the ``boundary`` parameter of the
+ :mailheader:`Content-Type` header of the message, or *failobj* if either
+ the header is missing, or has no ``boundary`` parameter. The returned
+ string will always be unquoted as per :func:`email.utils.unquote`.
+
+
+ .. method:: set_boundary(boundary)
+
+ Set the ``boundary`` parameter of the :mailheader:`Content-Type` header to
+ *boundary*. :meth:`set_boundary` will always quote *boundary* if
+ necessary. A :exc:`~email.errors.HeaderParseError` is raised if the
+ message object has no :mailheader:`Content-Type` header.
+
+ Note that using this method is subtly different than deleting the old
+ :mailheader:`Content-Type` header and adding a new one with the new
+ boundary via :meth:`add_header`, because :meth:`set_boundary` preserves
+ the order of the :mailheader:`Content-Type` header in the list of
+ headers. However, it does *not* preserve any continuation lines which may
+ have been present in the original :mailheader:`Content-Type` header.
+
+
+ .. method:: get_content_charset(failobj=None)
+
+ Return the ``charset`` parameter of the :mailheader:`Content-Type` header,
+ coerced to lower case. If there is no :mailheader:`Content-Type` header, or if
+ that header has no ``charset`` parameter, *failobj* is returned.
+
+ Note that this method differs from :meth:`get_charset` which returns the
+ :class:`~email.charset.Charset` instance for the default encoding of the message body.
+
+
+ .. method:: get_charsets(failobj=None)
+
+ Return a list containing the character set names in the message. If the
+ message is a :mimetype:`multipart`, then the list will contain one element
+ for each subpart in the payload, otherwise, it will be a list of length 1.
+
+ Each item in the list will be a string which is the value of the
+ ``charset`` parameter in the :mailheader:`Content-Type` header for the
+ represented subpart. However, if the subpart has no
+ :mailheader:`Content-Type` header, no ``charset`` parameter, or is not of
+ the :mimetype:`text` main MIME type, then that item in the returned list
+ will be *failobj*.
+
+
+ .. method:: get_content_disposition()
+
+ Return the lowercased value (without parameters) of the message's
+ :mailheader:`Content-Disposition` header if it has one, or ``None``. The
+ possible values for this method are *inline*, *attachment* or ``None``
+ if the message follows :rfc:`2183`.
+
+ .. versionadded:: 3.5
+
+ .. method:: walk()
+
+ The :meth:`walk` method is an all-purpose generator which can be used to
+ iterate over all the parts and subparts of a message object tree, in
+ depth-first traversal order. You will typically use :meth:`walk` as the
+ iterator in a ``for`` loop; each iteration returns the next subpart.
+
+ Here's an example that prints the MIME type of every part of a multipart
+ message structure:
+
+ .. testsetup::
+
+ >>> from email import message_from_binary_file
+ >>> with open('Lib/test/test_email/data/msg_16.txt', 'rb') as f:
+ ... msg = message_from_binary_file(f)
+ >>> from email.iterators import _structure
+
+ .. doctest::
+
+ >>> for part in msg.walk():
+ ... print(part.get_content_type())
+ multipart/report
+ text/plain
+ message/delivery-status
+ text/plain
+ text/plain
+ message/rfc822
+ text/plain
+
+ ``walk`` iterates over the subparts of any part where
+ :meth:`is_multipart` returns ``True``, even though
+ ``msg.get_content_maintype() == 'multipart'`` may return ``False``. We
+ can see this in our example by making use of the ``_structure`` debug
+ helper function:
+
+ .. doctest::
+
+ >>> for part in msg.walk():
+ ... print(part.get_content_maintype() == 'multipart'),
+ ... part.is_multipart())
+ True True
+ False False
+ False True
+ False False
+ False False
+ False True
+ False False
+ >>> _structure(msg)
+ multipart/report
+ text/plain
+ message/delivery-status
+ text/plain
+ text/plain
+ message/rfc822
+ text/plain
+
+ Here the ``message`` parts are not ``multiparts``, but they do contain
+ subparts. ``is_multipart()`` returns ``True`` and ``walk`` descends
+ into the subparts.
+
+
+ :class:`Message` objects can also optionally contain two instance attributes,
+ which can be used when generating the plain text of a MIME message.
+
+
+ .. attribute:: preamble
+
+ The format of a MIME document allows for some text between the blank line
+ following the headers, and the first multipart boundary string. Normally,
+ this text is never visible in a MIME-aware mail reader because it falls
+ outside the standard MIME armor. However, when viewing the raw text of
+ the message, or when viewing the message in a non-MIME aware reader, this
+ text can become visible.
+
+ The *preamble* attribute contains this leading extra-armor text for MIME
+ documents. When the :class:`~email.parser.Parser` discovers some text
+ after the headers but before the first boundary string, it assigns this
+ text to the message's *preamble* attribute. When the
+ :class:`~email.generator.Generator` is writing out the plain text
+ representation of a MIME message, and it finds the
+ message has a *preamble* attribute, it will write this text in the area
+ between the headers and the first boundary. See :mod:`email.parser` and
+ :mod:`email.generator` for details.
+
+ Note that if the message object has no preamble, the *preamble* attribute
+ will be ``None``.
+
+
+ .. attribute:: epilogue
+
+ The *epilogue* attribute acts the same way as the *preamble* attribute,
+ except that it contains text that appears between the last boundary and
+ the end of the message.
+
+ You do not need to set the epilogue to the empty string in order for the
+ :class:`~email.generator.Generator` to print a newline at the end of the
+ file.
+
+
+ .. attribute:: defects
+
+ The *defects* attribute contains a list of all the problems found when
+ parsing this message. See :mod:`email.errors` for a detailed description
+ of the possible parsing defects.
diff --git a/Doc/library/email.contentmanager.rst b/Doc/library/email.contentmanager.rst
index a9c078b..57743d5 100644
--- a/Doc/library/email.contentmanager.rst
+++ b/Doc/library/email.contentmanager.rst
@@ -7,251 +7,12 @@
.. moduleauthor:: R. David Murray <rdmurray@bitdance.com>
.. sectionauthor:: R. David Murray <rdmurray@bitdance.com>
-.. versionadded:: 3.4
- as a :term:`provisional module <provisional package>`.
-
**Source code:** :source:`Lib/email/contentmanager.py`
-.. note::
-
- The contentmanager module has been included in the standard library on a
- :term:`provisional basis <provisional package>`. Backwards incompatible
- changes (up to and including removal of the module) may occur if deemed
- necessary by the core developers.
-
---------------
-
-The :mod:`~email.message` module provides a class that can represent an
-arbitrary email message. That basic message model has a useful and flexible
-API, but it provides only a lower-level API for interacting with the generic
-parts of a message (the headers, generic header parameters, and the payload,
-which may be a list of sub-parts). This module provides classes and tools
-that provide an enhanced and extensible API for dealing with various specific
-types of content, including the ability to retrieve the content of the message
-as a specialized object type rather than as a simple bytes object. The module
-automatically takes care of the RFC-specified MIME details (required headers
-and parameters, etc.) for the certain common content types content properties,
-and support for additional types can be added by an application using the
-extension mechanisms.
-
-This module defines the eponymous "Content Manager" classes. The base
-:class:`.ContentManager` class defines an API for registering content
-management functions which extract data from ``Message`` objects or insert data
-and headers into ``Message`` objects, thus providing a way of converting
-between ``Message`` objects containing data and other representations of that
-data (Python data types, specialized Python objects, external files, etc). The
-module also defines one concrete content manager: :data:`raw_data_manager`
-converts between MIME content types and ``str`` or ``bytes`` data. It also
-provides a convenient API for managing the MIME parameters when inserting
-content into ``Message``\ s. It also handles inserting and extracting
-``Message`` objects when dealing with the ``message/rfc822`` content type.
-
-Another part of the enhanced interface is subclasses of
-:class:`~email.message.Message` that provide new convenience API functions,
-including convenience methods for calling the Content Managers derived from
-this module.
-
-.. note::
-
- Although :class:`.EmailMessage` and :class:`.MIMEPart` are currently
- documented in this module because of the provisional nature of the code, the
- implementation lives in the :mod:`email.message` module.
-
-.. currentmodule:: email.message
-
-.. class:: EmailMessage(policy=default)
-
- If *policy* is specified (it must be an instance of a :mod:`~email.policy`
- class) use the rules it specifies to udpate and serialize the representation
- of the message. If *policy* is not set, use the
- :class:`~email.policy.default` policy, which follows the rules of the email
- RFCs except for line endings (instead of the RFC mandated ``\r\n``, it uses
- the Python standard ``\n`` line endings). For more information see the
- :mod:`~email.policy` documentation.
-
- This class is a subclass of :class:`~email.message.Message`. It adds
- the following methods:
-
-
- .. method:: is_attachment
-
- Return ``True`` if there is a :mailheader:`Content-Disposition` header
- and its (case insensitive) value is ``attachment``, ``False`` otherwise.
-
- .. versionchanged:: 3.4.2
- is_attachment is now a method instead of a property, for consistency
- with :meth:`~email.message.Message.is_multipart`.
-
-
- .. method:: get_body(preferencelist=('related', 'html', 'plain'))
-
- Return the MIME part that is the best candidate to be the "body" of the
- message.
-
- *preferencelist* must be a sequence of strings from the set ``related``,
- ``html``, and ``plain``, and indicates the order of preference for the
- content type of the part returned.
-
- Start looking for candidate matches with the object on which the
- ``get_body`` method is called.
-
- If ``related`` is not included in *preferencelist*, consider the root
- part (or subpart of the root part) of any related encountered as a
- candidate if the (sub-)part matches a preference.
-
- When encountering a ``multipart/related``, check the ``start`` parameter
- and if a part with a matching :mailheader:`Content-ID` is found, consider
- only it when looking for candidate matches. Otherwise consider only the
- first (default root) part of the ``multipart/related``.
-
- If a part has a :mailheader:`Content-Disposition` header, only consider
- the part a candidate match if the value of the header is ``inline``.
-
- If none of the candidates matches any of the preferences in
- *preferneclist*, return ``None``.
-
- Notes: (1) For most applications the only *preferencelist* combinations
- that really make sense are ``('plain',)``, ``('html', 'plain')``, and the
- default, ``('related', 'html', 'plain')``. (2) Because matching starts
- with the object on which ``get_body`` is called, calling ``get_body`` on
- a ``multipart/related`` will return the object itself unless
- *preferencelist* has a non-default value. (3) Messages (or message parts)
- that do not specify a :mailheader:`Content-Type` or whose
- :mailheader:`Content-Type` header is invalid will be treated as if they
- are of type ``text/plain``, which may occasionally cause ``get_body`` to
- return unexpected results.
-
-
- .. method:: iter_attachments()
-
- Return an iterator over all of the parts of the message that are not
- candidate "body" parts. That is, skip the first occurrence of each of
- ``text/plain``, ``text/html``, ``multipart/related``, or
- ``multipart/alternative`` (unless they are explicitly marked as
- attachments via :mailheader:`Content-Disposition: attachment`), and
- return all remaining parts. When applied directly to a
- ``multipart/related``, return an iterator over the all the related parts
- except the root part (ie: the part pointed to by the ``start`` parameter,
- or the first part if there is no ``start`` parameter or the ``start``
- parameter doesn't match the :mailheader:`Content-ID` of any of the
- parts). When applied directly to a ``multipart/alternative`` or a
- non-``multipart``, return an empty iterator.
-
-
- .. method:: iter_parts()
-
- Return an iterator over all of the immediate sub-parts of the message,
- which will be empty for a non-``multipart``. (See also
- :meth:`~email.message.walk`.)
-
-
- .. method:: get_content(*args, content_manager=None, **kw)
-
- Call the ``get_content`` method of the *content_manager*, passing self
- as the message object, and passing along any other arguments or keywords
- as additional arguments. If *content_manager* is not specified, use
- the ``content_manager`` specified by the current :mod:`~email.policy`.
+------------
+.. versionadded:: 3.6 [1]_
- .. method:: set_content(*args, content_manager=None, **kw)
-
- Call the ``set_content`` method of the *content_manager*, passing self
- as the message object, and passing along any other arguments or keywords
- as additional arguments. If *content_manager* is not specified, use
- the ``content_manager`` specified by the current :mod:`~email.policy`.
-
-
- .. method:: make_related(boundary=None)
-
- Convert a non-``multipart`` message into a ``multipart/related`` message,
- moving any existing :mailheader:`Content-` headers and payload into a
- (new) first part of the ``multipart``. If *boundary* is specified, use
- it as the boundary string in the multipart, otherwise leave the boundary
- to be automatically created when it is needed (for example, when the
- message is serialized).
-
-
- .. method:: make_alternative(boundary=None)
-
- Convert a non-``multipart`` or a ``multipart/related`` into a
- ``multipart/alternative``, moving any existing :mailheader:`Content-`
- headers and payload into a (new) first part of the ``multipart``. If
- *boundary* is specified, use it as the boundary string in the multipart,
- otherwise leave the boundary to be automatically created when it is
- needed (for example, when the message is serialized).
-
-
- .. method:: make_mixed(boundary=None)
-
- Convert a non-``multipart``, a ``multipart/related``, or a
- ``multipart-alternative`` into a ``multipart/mixed``, moving any existing
- :mailheader:`Content-` headers and payload into a (new) first part of the
- ``multipart``. If *boundary* is specified, use it as the boundary string
- in the multipart, otherwise leave the boundary to be automatically
- created when it is needed (for example, when the message is serialized).
-
-
- .. method:: add_related(*args, content_manager=None, **kw)
-
- If the message is a ``multipart/related``, create a new message
- object, pass all of the arguments to its :meth:`set_content` method,
- and :meth:`~email.message.Message.attach` it to the ``multipart``. If
- the message is a non-``multipart``, call :meth:`make_related` and then
- proceed as above. If the message is any other type of ``multipart``,
- raise a :exc:`TypeError`. If *content_manager* is not specified, use
- the ``content_manager`` specified by the current :mod:`~email.policy`.
- If the added part has no :mailheader:`Content-Disposition` header,
- add one with the value ``inline``.
-
-
- .. method:: add_alternative(*args, content_manager=None, **kw)
-
- If the message is a ``multipart/alternative``, create a new message
- object, pass all of the arguments to its :meth:`set_content` method, and
- :meth:`~email.message.Message.attach` it to the ``multipart``. If the
- message is a non-``multipart`` or ``multipart/related``, call
- :meth:`make_alternative` and then proceed as above. If the message is
- any other type of ``multipart``, raise a :exc:`TypeError`. If
- *content_manager* is not specified, use the ``content_manager`` specified
- by the current :mod:`~email.policy`.
-
-
- .. method:: add_attachment(*args, content_manager=None, **kw)
-
- If the message is a ``multipart/mixed``, create a new message object,
- pass all of the arguments to its :meth:`set_content` method, and
- :meth:`~email.message.Message.attach` it to the ``multipart``. If the
- message is a non-``multipart``, ``multipart/related``, or
- ``multipart/alternative``, call :meth:`make_mixed` and then proceed as
- above. If *content_manager* is not specified, use the ``content_manager``
- specified by the current :mod:`~email.policy`. If the added part
- has no :mailheader:`Content-Disposition` header, add one with the value
- ``attachment``. This method can be used both for explicit attachments
- (:mailheader:`Content-Disposition: attachment` and ``inline`` attachments
- (:mailheader:`Content-Disposition: inline`), by passing appropriate
- options to the ``content_manager``.
-
-
- .. method:: clear()
-
- Remove the payload and all of the headers.
-
-
- .. method:: clear_content()
-
- Remove the payload and all of the :exc:`Content-` headers, leaving
- all other headers intact and in their original order.
-
-
-.. class:: MIMEPart(policy=default)
-
- This class represents a subpart of a MIME message. It is identical to
- :class:`EmailMessage`, except that no :mailheader:`MIME-Version` headers are
- added when :meth:`~EmailMessage.set_content` is called, since sub-parts do
- not need their own :mailheader:`MIME-Version` headers.
-
-
-.. currentmodule:: email.contentmanager
.. class:: ContentManager()
@@ -362,7 +123,7 @@ Currently the email package provides only one concrete content manager,
set_content(msg, <'bytes'>, maintype, subtype, cte="base64", \
disposition=None, filename=None, cid=None, \
params=None, headers=None)
- set_content(msg, <'Message'>, cte=None, \
+ set_content(msg, <'EmailMessage'>, cte=None, \
disposition=None, filename=None, cid=None, \
params=None, headers=None)
set_content(msg, <'list'>, subtype='mixed', \
@@ -378,14 +139,14 @@ Currently the email package provides only one concrete content manager,
subtype to *subtype* if it is specified, or ``plain`` if it is not.
* For ``bytes``, use the specified *maintype* and *subtype*, or
raise a :exc:`TypeError` if they are not specified.
- * For :class:`~email.message.Message` objects, set the maintype to
- ``message``, and set the subtype to *subtype* if it is specified
- or ``rfc822`` if it is not. If *subtype* is ``partial``, raise an
- error (``bytes`` objects must be used to construct
- ``message/partial`` parts).
+ * For :class:`~email.message.EmailMessage` objects, set the maintype
+ to ``message``, and set the subtype to *subtype* if it is
+ specified or ``rfc822`` if it is not. If *subtype* is
+ ``partial``, raise an error (``bytes`` objects must be used to
+ construct ``message/partial`` parts).
* For *<'list'>*, which should be a list of
- :class:`~email.message.Message` objects, set the ``maintype`` to
- ``multipart``, and the ``subtype`` to *subtype* if it is
+ :class:`~email.message.EmailMessage` objects, set the ``maintype``
+ to ``multipart``, and the ``subtype`` to *subtype* if it is
specified, and ``mixed`` if it is not. If the message parts in
the *<'list'>* have :mailheader:`MIME-Version` headers, remove
them.
@@ -397,32 +158,35 @@ Currently the email package provides only one concrete content manager,
If *cte* is set, encode the payload using the specified content transfer
encoding, and set the :mailheader:`Content-Transfer-Endcoding` header to
- that value. For ``str`` objects, if it is not set use heuristics to
- determine the most compact encoding. Possible values for *cte* are
- ``quoted-printable``, ``base64``, ``7bit``, ``8bit``, and ``binary``.
- If the input cannot be encoded in the specified encoding (eg: ``7bit``),
- raise a :exc:`ValueError`. For :class:`~email.message.Message`, per
- :rfc:`2046`, raise an error if a *cte* of ``quoted-printable`` or
- ``base64`` is requested for *subtype* ``rfc822``, and for any *cte*
- other than ``7bit`` for *subtype* ``external-body``. For
- ``message/rfc822``, use ``8bit`` if *cte* is not specified. For all
- other values of *subtype*, use ``7bit``.
+ that value. Possible values for *cte* are ``quoted-printable``,
+ ``base64``, ``7bit``, ``8bit``, and ``binary``. If the input cannot be
+ encoded in the specified encoding (for example, specifying a *cte* of
+ ``7bit`` for an input that contains non-ASCII values), raise a
+ :exc:`ValueError`.
+
+ * For ``str`` objects, if *cte* is not set use heuristics to
+ determine the most compact encoding.
+ * For :class:`~email.message.EmailMessage`, per :rfc:`2046`, raise
+ an error if a *cte* of ``quoted-printable`` or ``base64`` is
+ requested for *subtype* ``rfc822``, and for any *cte* other than
+ ``7bit`` for *subtype* ``external-body``. For
+ ``message/rfc822``, use ``8bit`` if *cte* is not specified. For
+ all other values of *subtype*, use ``7bit``.
.. note:: A *cte* of ``binary`` does not actually work correctly yet.
- The ``Message`` object as modified by ``set_content`` is correct, but
- :class:`~email.generator.BytesGenerator` does not serialize it
- correctly.
+ The ``EmailMessage`` object as modified by ``set_content`` is
+ correct, but :class:`~email.generator.BytesGenerator` does not
+ serialize it correctly.
If *disposition* is set, use it as the value of the
:mailheader:`Content-Disposition` header. If not specified, and
*filename* is specified, add the header with the value ``attachment``.
- If it is not specified and *filename* is also not specified, do not add
- the header. The only valid values for *disposition* are ``attachment``
- and ``inline``.
+ If *disposition* is not specified and *filename* is also not specified,
+ do not add the header. The only valid values for *disposition* are
+ ``attachment`` and ``inline``.
If *filename* is specified, use it as the value of the ``filename``
- parameter of the :mailheader:`Content-Disposition` header. There is no
- default.
+ parameter of the :mailheader:`Content-Disposition` header.
If *cid* is specified, add a :mailheader:`Content-ID` header with
*cid* as its value.
@@ -435,3 +199,9 @@ Currently the email package provides only one concrete content manager,
``headername: headervalue`` or a list of ``header`` objects
(distinguished from strings by having a ``name`` attribute), add the
headers to *msg*.
+
+
+.. rubric:: Footnotes
+
+.. [1] Oringally added in 3.4 as a :term:`provisional module <provisional
+ package>`
diff --git a/Doc/library/email.encoders.rst b/Doc/library/email.encoders.rst
index 9d7f9bf..e24ac7b 100644
--- a/Doc/library/email.encoders.rst
+++ b/Doc/library/email.encoders.rst
@@ -8,6 +8,12 @@
--------------
+This module is part of the legacy (``Compat32``) email API. In the
+new API the functionality is provided by the *cte* parameter of
+the :meth:`~email.message.EmailMessage.set_content` method.
+
+The remaining text in this section is the original documentation of the module.
+
When creating :class:`~email.message.Message` objects from scratch, you often
need to encode the payloads for transport through compliant mail servers. This
is especially true for :mimetype:`image/\*` and :mimetype:`text/\*` type messages
diff --git a/Doc/library/email.errors.rst b/Doc/library/email.errors.rst
index 8470783..2d0d192 100644
--- a/Doc/library/email.errors.rst
+++ b/Doc/library/email.errors.rst
@@ -20,33 +20,27 @@ The following exception classes are defined in the :mod:`email.errors` module:
.. exception:: MessageParseError()
- This is the base class for exceptions raised by the :class:`~email.parser.Parser`
- class. It is derived from :exc:`MessageError`.
+ This is the base class for exceptions raised by the
+ :class:`~email.parser.Parser` class. It is derived from
+ :exc:`MessageError`. This class is also used internally by the parser used
+ by :mod:`~email.headerregistry`.
.. exception:: HeaderParseError()
- Raised under some error conditions when parsing the :rfc:`2822` headers of a
- message, this class is derived from :exc:`MessageParseError`. It can be raised
- from the :meth:`Parser.parse <email.parser.Parser.parse>` or
- :meth:`Parser.parsestr <email.parser.Parser.parsestr>` methods.
-
- Situations where it can be raised include finding an envelope header after the
- first :rfc:`2822` header of the message, finding a continuation line before the
- first :rfc:`2822` header is found, or finding a line in the headers which is
- neither a header or a continuation line.
+ Raised under some error conditions when parsing the :rfc:`5322` headers of a
+ message, this class is derived from :exc:`MessageParseError`. The
+ :meth:`~email.message.EmailMessage.set_boundary` method will raise this
+ error if the content type is unknown when the method is called.
+ :class:`~email.header.Header` may raise this error for certain base64
+ decoding errors, and when an attempt is made to create a header that appears
+ to contain an embedded header (that is, there is what is supposed to be a
+ continuation line that has no leading whitespace and looks like a header).
.. exception:: BoundaryError()
- Raised under some error conditions when parsing the :rfc:`2822` headers of a
- message, this class is derived from :exc:`MessageParseError`. It can be raised
- from the :meth:`Parser.parse <email.parser.Parser.parse>` or
- :meth:`Parser.parsestr <email.parser.Parser.parsestr>` methods.
-
- Situations where it can be raised include not being able to find the starting or
- terminating boundary in a :mimetype:`multipart/\*` message when strict parsing
- is used.
+ Deprecated and no longer used.
.. exception:: MultipartConversionError()
@@ -64,14 +58,14 @@ The following exception classes are defined in the :mod:`email.errors` module:
:class:`~email.mime.nonmultipart.MIMENonMultipart` (e.g.
:class:`~email.mime.image.MIMEImage`).
-Here's the list of the defects that the :class:`~email.parser.FeedParser`
+
+Here is the list of the defects that the :class:`~email.parser.FeedParser`
can find while parsing messages. Note that the defects are added to the message
where the problem was found, so for example, if a message nested inside a
:mimetype:`multipart/alternative` had a malformed header, that nested message
object would have a defect, but the containing messages would not.
-All defect classes are subclassed from :class:`email.errors.MessageDefect`, but
-this class is *not* an exception!
+All defect classes are subclassed from :class:`email.errors.MessageDefect`.
* :class:`NoBoundaryInMultipartDefect` -- A message claimed to be a multipart,
but had no :mimetype:`boundary` parameter.
diff --git a/Doc/library/email-examples.rst b/Doc/library/email.examples.rst
index ad93b5c..84e9aee 100644
--- a/Doc/library/email-examples.rst
+++ b/Doc/library/email.examples.rst
@@ -6,13 +6,14 @@
Here are a few examples of how to use the :mod:`email` package to read, write,
and send simple email messages, as well as more complex MIME messages.
-First, let's see how to create and send a simple text message:
+First, let's see how to create and send a simple text message (both the
+text content and the addresses may contain unicode characters):
.. literalinclude:: ../includes/email-simple.py
-And parsing RFC822 headers can easily be done by the parse(filename) or
-parsestr(message_as_string) methods of the Parser() class:
+Parsing RFC822 headers can easily be done by the using the classes
+from the :mod:`~email.parser` module:
.. literalinclude:: ../includes/email-headers.py
@@ -34,30 +35,19 @@ above, into a directory of files:
.. literalinclude:: ../includes/email-unpack.py
+
Here's an example of how to create an HTML message with an alternative plain
-text version: [2]_
+text version. To make things a bit more interesting, we include a related
+image in the html part, and we save a copy of what we are going to send to
+disk, as well as sending it.
.. literalinclude:: ../includes/email-alternative.py
-.. _email-contentmanager-api-examples:
-
-Examples using the Provisional API
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Here is a reworking of the last example using the provisional API. To make
-things a bit more interesting, we include a related image in the html part, and
-we save a copy of what we are going to send to disk, as well as sending it.
-
-This example also shows how easy it is to include non-ASCII, and simplifies the
-sending of the message using the :meth:`.send_message` method of the
-:mod:`smtplib` module.
-
-.. literalinclude:: ../includes/email-alternative-new-api.py
-
-If we were instead sent the message from the last example, here is one
-way we could process it:
+If we were sent the message from the last example, here is one way we could
+process it:
-.. literalinclude:: ../includes/email-read-alternative-new-api.py
+.. literalinclude:: ../includes/email-read-alternative.py
Up to the prompt, the output from the above is:
@@ -75,4 +65,3 @@ Up to the prompt, the output from the above is:
.. rubric:: Footnotes
.. [1] Thanks to Matthew Dixon Cowles for the original inspiration and examples.
-.. [2] Contributed by Martin Matejek.
diff --git a/Doc/library/email.generator.rst b/Doc/library/email.generator.rst
index d596ed8..ab0fbc2 100644
--- a/Doc/library/email.generator.rst
+++ b/Doc/library/email.generator.rst
@@ -8,210 +8,244 @@
--------------
-One of the most common tasks is to generate the flat text of the email message
-represented by a message object structure. You will need to do this if you want
-to send your message via the :mod:`smtplib` module or the :mod:`nntplib` module,
-or print the message on the console. Taking a message object structure and
-producing a flat text document is the job of the :class:`Generator` class.
-
-Again, as with the :mod:`email.parser` module, you aren't limited to the
-functionality of the bundled generator; you could write one from scratch
-yourself. However the bundled generator knows how to generate most email in a
-standards-compliant way, should handle MIME and non-MIME email messages just
-fine, and is designed so that the transformation from flat text, to a message
-structure via the :class:`~email.parser.Parser` class, and back to flat text,
-is idempotent (the input is identical to the output) [#]_. On the other hand,
-using the Generator on a :class:`~email.message.Message` constructed by program
-may result in changes to the :class:`~email.message.Message` object as defaults
-are filled in.
-
-:class:`bytes` output can be generated using the :class:`BytesGenerator` class.
-If the message object structure contains non-ASCII bytes, this generator's
-:meth:`~BytesGenerator.flatten` method will emit the original bytes. Parsing a
-binary message and then flattening it with :class:`BytesGenerator` should be
-idempotent for standards compliant messages.
-
-Here are the public methods of the :class:`Generator` class, imported from the
-:mod:`email.generator` module:
-
-
-.. class:: Generator(outfp, mangle_from_=True, maxheaderlen=78, *, policy=None)
-
- The constructor for the :class:`Generator` class takes a :term:`file-like object`
- called *outfp* for an argument. *outfp* must support the :meth:`write` method
- and be usable as the output file for the :func:`print` function.
-
- Optional *mangle_from_* is a flag that, when ``True``, puts a ``>`` character in
- front of any line in the body that starts exactly as ``From``, i.e. ``From``
- followed by a space at the beginning of the line. This is the only guaranteed
- portable way to avoid having such lines be mistaken for a Unix mailbox format
- envelope header separator (see `WHY THE CONTENT-LENGTH FORMAT IS BAD
- <https://www.jwz.org/doc/content-length.html>`_ for details). *mangle_from_*
- defaults to ``True``, but you might want to set this to ``False`` if you are not
- writing Unix mailbox format files.
-
- Optional *maxheaderlen* specifies the longest length for a non-continued header.
- When a header line is longer than *maxheaderlen* (in characters, with tabs
- expanded to 8 spaces), the header will be split as defined in the
- :class:`~email.header.Header` class. Set to zero to disable header wrapping.
- The default is 78, as recommended (but not required) by :rfc:`2822`.
-
- The *policy* keyword specifies a :mod:`~email.policy` object that controls a
- number of aspects of the generator's operation. If no *policy* is specified,
- then the *policy* attached to the message object passed to :attr:`flatten`
- is used.
+One of the most common tasks is to generate the flat (serialized) version of
+the email message represented by a message object structure. You will need to
+do this if you want to send your message via :meth:`smtplib.SMTP.sendmail` or
+the :mod:`nntplib` module, or print the message on the console. Taking a
+message object structure and producing a serialized representation is the job
+of the generator classes.
+
+As with the :mod:`email.parser` module, you aren't limited to the functionality
+of the bundled generator; you could write one from scratch yourself. However
+the bundled generator knows how to generate most email in a standards-compliant
+way, should handle MIME and non-MIME email messages just fine, and is designed
+so that the bytes-oriented parsing and generation operations are inverses,
+assuming the same non-transforming :mod:`~email.policy` is used for both. That
+is, parsing the serialized byte stream via the
+:class:`~email.parser.BytesParser` class and then regenerating the serialized
+byte stream using :class:`BytesGenerator` should produce output identical to
+the input [#]_. (On the other hand, using the generator on an
+:class:`~email.message.EmailMessage` constructed by program may result in
+changes to the :class:`~email.message.EmailMessage` object as defaults are
+filled in.)
+
+The :class:`Generator` class can be used to flatten a message into a text (as
+opposed to binary) serialized representation, but since Unicode cannot
+represent binary data directly, the message is of necessity transformed into
+something that contains only ASCII characters, using the standard email RFC
+Content Transfer Encoding techniques for encoding email messages for transport
+over channels that are not "8 bit clean".
+
+
+.. class:: BytesGenerator(outfp, mangle_from_=None, maxheaderlen=None, *, \
+ policy=None)
- .. versionchanged:: 3.3 Added the *policy* keyword.
+ Return a :class:`BytesGenerator` object that will write any message provided
+ to the :meth:`flatten` method, or any surrogateescape encoded text provided
+ to the :meth:`write` method, to the :term:`file-like object` *outfp*.
+ *outfp* must support a ``write`` method that accepts binary data.
+
+ If optional *mangle_from_* is ``True``, put a ``>`` character in front of
+ any line in the body that starts with the exact string ``"From "``, that is
+ ``From`` followed by a space at the beginning of a line. *mangle_from_*
+ defaults to the value of the :attr:`~email.policy.Policy.mangle_from_`
+ setting of the *policy* (which is ``True`` for the
+ :data:`~email.policy.compat32` policy and ``False`` for all others).
+ *mangle_from_* is intended for use when messages are stored in unix mbox
+ format (see :mod:`mailbox` and `WHY THE CONTENT-LENGTH FORMAT IS BAD
+ <http://www.jwz.org/doc/content-length.html>`_).
+
+ If *maxheaderlen* is not ``None``, refold any header lines that are longer
+ than *maxheaderlen*, or if ``0``, do not rewrap any headers. If
+ *manheaderlen* is ``None`` (the default), wrap headers and other message
+ lines according to the *policy* settings.
+
+ If *policy* is specified, use that policy to control message generation. If
+ *policy* is ``None`` (the default), use the policy associated with the
+ :class:`~email.message.Message` or :class:`~email.message.EmailMessage`
+ object passed to ``flatten`` to control the message generation. See
+ :mod:`email.policy` for details on what *policy* controls.
- The other public :class:`Generator` methods are:
+ .. versionadded:: 3.2
+ .. versionchanged:: 3.3 Added the *policy* keyword.
- .. method:: flatten(msg, unixfrom=False, linesep=None)
+ .. versionchanged:: 3.6 The default behavior of the *mangle_from_*
+ and *maxheaderlen* parameters is to follow the policy.
- Print the textual representation of the message object structure rooted at
- *msg* to the output file specified when the :class:`Generator` instance
- was created. Subparts are visited depth-first and the resulting text will
- be properly MIME encoded.
- Optional *unixfrom* is a flag that forces the printing of the envelope
- header delimiter before the first :rfc:`2822` header of the root message
- object. If the root object has no envelope header, a standard one is
- crafted. By default, this is set to ``False`` to inhibit the printing of
- the envelope delimiter.
+ .. method:: flatten(msg, unixfrom=False, linesep=None)
+ Print the textual representation of the message object structure rooted
+ at *msg* to the output file specified when the :class:`BytesGenerator`
+ instance was created.
+
+ If the :mod:`~email.policy` option :attr:`~email.policy.Policy.cte_type`
+ is ``8bit`` (the default), copy any headers in the original parsed
+ message that have not been modified to the output with any bytes with the
+ high bit set reproduced as in the original, and preserve the non-ASCII
+ :mailheader:`Content-Transfer-Encoding` of any body parts that have them.
+ If ``cte_type`` is ``7bit``, convert the bytes with the high bit set as
+ needed using an ASCII-compatible :mailheader:`Content-Transfer-Encoding`.
+ That is, transform parts with non-ASCII
+ :mailheader:`Cotnent-Transfer-Encoding`
+ (:mailheader:`Content-Transfer-Encoding: 8bit`) to an ASCII compatibile
+ :mailheader:`Content-Transfer-Encoding`, and encode RFC-invalid non-ASCII
+ bytes in headers using the MIME ``unknown-8bit`` character set, thus
+ rendering them RFC-compliant.
+
+ .. XXX: There should be an option that just does the RFC
+ compliance transformation on headers but leaves CTE 8bit parts alone.
+
+ If *unixfrom* is ``True``, print the envelope header delimiter used by
+ the Unix mailbox format (see :mod:`mailbox`) before the first of the
+ :rfc:`5322` headers of the root message object. If the root object has
+ no envelope header, craft a standard one. The default is ``False``.
Note that for subparts, no envelope header is ever printed.
- Optional *linesep* specifies the line separator character used to
- terminate lines in the output. If specified it overrides the value
- specified by the *msg*\'s or ``Generator``\'s ``policy``.
+ If *linesep* is not ``None``, use it as the separator character between
+ all the lines of the flattened message. If *linesep* is ``None`` (the
+ default), use the value specified in the *policy*.
- Because strings cannot represent non-ASCII bytes, if the policy that
- applies when ``flatten`` is run has :attr:`~email.policy.Policy.cte_type`
- set to ``8bit``, ``Generator`` will operate as if it were set to
- ``7bit``. This means that messages parsed with a Bytes parser that have
- a :mailheader:`Content-Transfer-Encoding` of ``8bit`` will be converted
- to a use a ``7bit`` Content-Transfer-Encoding. Non-ASCII bytes in the
- headers will be :rfc:`2047` encoded with a charset of ``unknown-8bit``.
+ .. XXX: flatten should take a *policy* keyword.
- .. versionchanged:: 3.2
- Added support for re-encoding ``8bit`` message bodies, and the
- *linesep* argument.
.. method:: clone(fp)
- Return an independent clone of this :class:`Generator` instance with the
- exact same options.
-
- .. method:: write(s)
-
- Write the string *s* to the underlying file object, i.e. *outfp* passed to
- :class:`Generator`'s constructor. This provides just enough file-like API
- for :class:`Generator` instances to be used in the :func:`print` function.
+ Return an independent clone of this :class:`BytesGenerator` instance with
+ the exact same option settings, and *fp* as the new *outfp*.
-As a convenience, see the :class:`~email.message.Message` methods
-:meth:`~email.message.Message.as_string` and ``str(aMessage)``, a.k.a.
-:meth:`~email.message.Message.__str__`, which simplify the generation of a
-formatted string representation of a message object. For more detail, see
-:mod:`email.message`.
-.. class:: BytesGenerator(outfp, mangle_from_=True, maxheaderlen=78, *, \
- policy=None)
+ .. method:: write(s)
- The constructor for the :class:`BytesGenerator` class takes a binary
- :term:`file-like object` called *outfp* for an argument. *outfp* must
- support a :meth:`write` method that accepts binary data.
+ Encode *s* using the ``ASCII`` codec and the ``surrogateescape`` error
+ handler, and pass it to the *write* method of the *outfp* passed to the
+ :class:`BytesGenerator`'s constructor.
- Optional *mangle_from_* is a flag that, when ``True``, puts a ``>``
- character in front of any line in the body that starts exactly as ``From``,
- i.e. ``From`` followed by a space at the beginning of the line. This is the
- only guaranteed portable way to avoid having such lines be mistaken for a
- Unix mailbox format envelope header separator (see `WHY THE CONTENT-LENGTH
- FORMAT IS BAD <https://www.jwz.org/doc/content-length.html>`_ for details).
- *mangle_from_* defaults to ``True``, but you might want to set this to
- ``False`` if you are not writing Unix mailbox format files.
- Optional *maxheaderlen* specifies the longest length for a non-continued
- header. When a header line is longer than *maxheaderlen* (in characters,
- with tabs expanded to 8 spaces), the header will be split as defined in the
- :class:`~email.header.Header` class. Set to zero to disable header
- wrapping. The default is 78, as recommended (but not required) by
- :rfc:`2822`.
+As a convenience, :class:`~email.message.EmailMessage` provides the methods
+:meth:`~email.message.EmailMessage.as_bytes` and ``bytes(aMessage)`` (a.k.a.
+:meth:`~email.message.EmailMessage.__bytes__`), which simplify the generation of
+a serialized binary representation of a message object. For more detail, see
+:mod:`email.message`.
- The *policy* keyword specifies a :mod:`~email.policy` object that controls a
- number of aspects of the generator's operation. If no *policy* is specified,
- then the *policy* attached to the message object passed to :attr:`flatten`
- is used.
+Because strings cannot represent binary data, the :class:`Generator` class must
+convert any binary data in any message it flattens to an ASCII compatible
+format, by converting them to an ASCII compatible
+:mailheader:`Content-Transfer_Encoding`. Using the terminology of the email
+RFCs, you can think of this as :class:`Generator` serializing to an I/O stream
+that is not "8 bit clean". In other words, most applications will want
+to be using :class:`BytesGenerator`, and not :class:`Generator`.
+
+.. class:: Generator(outfp, mangle_from_=None, maxheaderlen=None, *, \
+ policy=None)
+
+ Return a :class:`Generator` object that will write any message provided
+ to the :meth:`flatten` method, or any text provided to the :meth:`write`
+ method, to the :term:`file-like object` *outfp*. *outfp* must support a
+ ``write`` method that accepts string data.
+
+ If optional *mangle_from_* is ``True``, put a ``>`` character in front of
+ any line in the body that starts with the exact string ``"From "``, that is
+ ``From`` followed by a space at the beginning of a line. *mangle_from_*
+ defaults to the value of the :attr:`~email.policy.Policy.mangle_from_`
+ setting of the *policy* (which is ``True`` for the
+ :data:`~email.policy.compat32` policy and ``False`` for all others).
+ *mangle_from_* is intended for use when messages are stored in unix mbox
+ format (see :mod:`mailbox` and `WHY THE CONTENT-LENGTH FORMAT IS BAD
+ <http://www.jwz.org/doc/content-length.html>`_).
+
+ If *maxheaderlen* is not ``None``, refold any header lines that are longer
+ than *maxheaderlen*, or if ``0``, do not rewrap any headers. If
+ *manheaderlen* is ``None`` (the default), wrap headers and other message
+ lines according to the *policy* settings.
+
+ If *policy* is specified, use that policy to control message generation. If
+ *policy* is ``None`` (the default), use the policy associated with the
+ :class:`~email.message.Message` or :class:`~email.message.EmailMessage`
+ object passed to ``flatten`` to control the message generation. See
+ :mod:`email.policy` for details on what *policy* controls.
.. versionchanged:: 3.3 Added the *policy* keyword.
- The other public :class:`BytesGenerator` methods are:
+ .. versionchanged:: 3.6 The default behavior of the *mangle_from_*
+ and *maxheaderlen* parameters is to follow the policy.
.. method:: flatten(msg, unixfrom=False, linesep=None)
Print the textual representation of the message object structure rooted
- at *msg* to the output file specified when the :class:`BytesGenerator`
- instance was created. Subparts are visited depth-first and the resulting
- text will be properly MIME encoded. If the :mod:`~email.policy` option
- :attr:`~email.policy.Policy.cte_type` is ``8bit`` (the default),
- then any bytes with the high bit set in the original parsed message that
- have not been modified will be copied faithfully to the output. If
- ``cte_type`` is ``7bit``, the bytes will be converted as needed
- using an ASCII-compatible Content-Transfer-Encoding. In particular,
- RFC-invalid non-ASCII bytes in headers will be encoded using the MIME
- ``unknown-8bit`` character set, thus rendering them RFC-compliant.
-
- .. XXX: There should be a complementary option that just does the RFC
- compliance transformation but leaves CTE 8bit parts alone.
-
- Messages parsed with a Bytes parser that have a
- :mailheader:`Content-Transfer-Encoding` of 8bit will be reconstructed
- as 8bit if they have not been modified.
-
- Optional *unixfrom* is a flag that forces the printing of the envelope
- header delimiter before the first :rfc:`2822` header of the root message
- object. If the root object has no envelope header, a standard one is
- crafted. By default, this is set to ``False`` to inhibit the printing of
- the envelope delimiter.
-
+ at *msg* to the output file specified when the :class:`Generator`
+ instance was created.
+
+ If the :mod:`~email.policy` option :attr:`~email.policy.Policy.cte_type`
+ is ``8bit``, generate the message as if the option were set to ``7bit``.
+ (This is required because strings cannot represent non-ASCII bytes.)
+ Convert any bytes with the high bit set as needed using an
+ ASCII-compatible :mailheader:`Content-Transfer-Encoding`. That is,
+ transform parts with non-ASCII :mailheader:`Cotnent-Transfer-Encoding`
+ (:mailheader:`Content-Transfer-Encoding: 8bit`) to an ASCII compatibile
+ :mailheader:`Content-Transfer-Encoding`, and encode RFC-invalid non-ASCII
+ bytes in headers using the MIME ``unknown-8bit`` character set, thus
+ rendering them RFC-compliant.
+
+ If *unixfrom* is ``True``, print the envelope header delimiter used by
+ the Unix mailbox format (see :mod:`mailbox`) before the first of the
+ :rfc:`5322` headers of the root message object. If the root object has
+ no envelope header, craft a standard one. The default is ``False``.
Note that for subparts, no envelope header is ever printed.
- Optional *linesep* specifies the line separator character used to
- terminate lines in the output. If specified it overrides the value
- specified by the ``Generator``\ or *msg*\ 's ``policy``.
+ If *linesep* is not ``None``, use it as the separator character between
+ all the lines of the flattened message. If *linesep* is ``None`` (the
+ default), use the value specified in the *policy*.
+
+ .. XXX: flatten should take a *policy* keyword.
+
+ .. versionchanged:: 3.2
+ Added support for re-encoding ``8bit`` message bodies, and the
+ *linesep* argument.
+
.. method:: clone(fp)
- Return an independent clone of this :class:`BytesGenerator` instance with
- the exact same options.
+ Return an independent clone of this :class:`Generator` instance with the
+ exact same options, and *fp* as the new *outfp*.
+
.. method:: write(s)
- Write the string *s* to the underlying file object. *s* is encoded using
- the ``ASCII`` codec and written to the *write* method of the *outfp*
- *outfp* passed to the :class:`BytesGenerator`'s constructor. This
- provides just enough file-like API for :class:`BytesGenerator` instances
- to be used in the :func:`print` function.
+ Write *s* to the *write* method of the *outfp* passed to the
+ :class:`Generator`'s constructor. This provides just enough file-like
+ API for :class:`Generator` instances to be used in the :func:`print`
+ function.
- .. versionadded:: 3.2
-The :mod:`email.generator` module also provides a derived class, called
-:class:`DecodedGenerator` which is like the :class:`Generator` base class,
-except that non-\ :mimetype:`text` parts are substituted with a format string
-representing the part.
+As a convenience, :class:`~email.message.EmailMessage` provides the methods
+:meth:`~email.message.EmailMessage.as_string` and ``str(aMessage)`` (a.k.a.
+:meth:`~email.message.EmailMessage.__str__`), which simplify the generation of
+a formatted string representation of a message object. For more detail, see
+:mod:`email.message`.
+
+The :mod:`email.generator` module also provides a derived class,
+:class:`DecodedGenerator`, which is like the :class:`Generator` base class,
+except that non-\ :mimetype:`text` parts are not serialized, but are instead
+represented in the output stream by a string derived from a template filled
+in with information about the part.
-.. class:: DecodedGenerator(outfp, mangle_from_=True, maxheaderlen=78, fmt=None)
+.. class:: DecodedGenerator(outfp, mangle_from_=None, maxheaderlen=None, \
+ fmt=None, *, policy=None)
- This class, derived from :class:`Generator` walks through all the subparts of a
- message. If the subpart is of main type :mimetype:`text`, then it prints the
- decoded payload of the subpart. Optional *_mangle_from_* and *maxheaderlen* are
- as with the :class:`Generator` base class.
+ Act like :class:`Generator`, except that for any subpart of the message
+ passed to :meth:`Generator.flatten`, if the subpart is of main type
+ :mimetype:`text`, print the decoded payload of the subpart, and if the main
+ type is not :mimetype:`text`, instead of printing it fill in the string
+ *fmt* using information from the part and print the resulting
+ filled-in string.
- If the subpart is not of main type :mimetype:`text`, optional *fmt* is a format
- string that is used instead of the message payload. *fmt* is expanded with the
- following keywords, ``%(keyword)s`` format:
+ To fill in *fmt*, execute ``fmt % part_info``, where ``part_info``
+ is a dictionary composed of the following keys and values:
* ``type`` -- Full MIME type of the non-\ :mimetype:`text` part
@@ -225,15 +259,21 @@ representing the part.
* ``encoding`` -- Content transfer encoding of the non-\ :mimetype:`text` part
- The default value for *fmt* is ``None``, meaning ::
+ If *fmt* is ``None``, use the following default *fmt*:
+
+ "[Non-text (%(type)s) part of message omitted, filename %(filename)s]"
- [Non-text (%(type)s) part of message omitted, filename %(filename)s]
+ Optional *_mangle_from_* and *maxheaderlen* are as with the
+ :class:`Generator` base class.
.. rubric:: Footnotes
-.. [#] This statement assumes that you use the appropriate setting for the
- ``unixfrom`` argument, and that you set maxheaderlen=0 (which will
- preserve whatever the input line lengths were). It is also not strictly
- true, since in many cases runs of whitespace in headers are collapsed
- into single blanks. The latter is a bug that will eventually be fixed.
+.. [#] This statement assumes that you use the appropriate setting for
+ ``unixfrom``, and that there are no :mod:`policy` settings calling for
+ automatic adjustments (for example,
+ :attr:`~email.policy.Policy.refold_source` must be ``none``, which is
+ *not* the default). It is also not 100% true, since if the message
+ does not conform to the RFC standards occasionally information about the
+ exact original text is lost during parsing error recovery. It is a goal
+ to fix these latter edge cases when possible.
diff --git a/Doc/library/email.header.rst b/Doc/library/email.header.rst
index e94837c..07152c2 100644
--- a/Doc/library/email.header.rst
+++ b/Doc/library/email.header.rst
@@ -8,6 +8,14 @@
--------------
+This module is part of the legacy (``Compat32``) email API. In the current API
+encoding and decoding of headers is handled transparently by the
+dictionary-like API of the :class:`~email.message.EmailMessage` class. In
+addition to uses in legacy code, this module can be useful in applications that
+need to completely control the character sets used when encoding headers.
+
+The remaining text in this section is the original documentation of the module.
+
:rfc:`2822` is the base standard that describes the format of email messages.
It derives from the older :rfc:`822` standard which came into widespread use at
a time when most email was composed of ASCII characters only. :rfc:`2822` is a
diff --git a/Doc/library/email.headerregistry.rst b/Doc/library/email.headerregistry.rst
index 0707bd8..2c830cf 100644
--- a/Doc/library/email.headerregistry.rst
+++ b/Doc/library/email.headerregistry.rst
@@ -7,20 +7,12 @@
.. moduleauthor:: R. David Murray <rdmurray@bitdance.com>
.. sectionauthor:: R. David Murray <rdmurray@bitdance.com>
-.. versionadded:: 3.3
- as a :term:`provisional module <provisional package>`.
-
**Source code:** :source:`Lib/email/headerregistry.py`
-.. note::
-
- The headerregistry module has been included in the standard library on a
- :term:`provisional basis <provisional package>`. Backwards incompatible
- changes (up to and including removal of the module) may occur if deemed
- necessary by the core developers.
-
--------------
+.. versionadded:: 3.6 [1]_
+
Headers are represented by customized subclasses of :class:`str`. The
particular class used to represent a given header is determined by the
:attr:`~email.policy.EmailPolicy.header_factory` of the :mod:`~email.policy` in
@@ -86,10 +78,11 @@ headers.
.. method:: fold(*, policy)
Return a string containing :attr:`~email.policy.Policy.linesep`
- characters as required to correctly fold the header according
- to *policy*. A :attr:`~email.policy.Policy.cte_type` of
- ``8bit`` will be treated as if it were ``7bit``, since strings
- may not contain binary data.
+ characters as required to correctly fold the header according to
+ *policy*. A :attr:`~email.policy.Policy.cte_type` of ``8bit`` will be
+ treated as if it were ``7bit``, since headers may not contain arbitrary
+ binary data. If :attr:`~email.policy.EmailPolicy.utf8` is ``False``,
+ non-ASCII data will be :rfc:`2047` encoded.
``BaseHeader`` by itself cannot be used to create a header object. It
@@ -106,7 +99,7 @@ headers.
values for at least the keys ``decoded`` and ``defects``. ``decoded``
should be the string value for the header (that is, the header value fully
decoded to unicode). The parse method should assume that *string* may
- contain transport encoded parts, but should correctly handle all valid
+ contain content-transfer-encoded parts, but should correctly handle all valid
unicode characters as well so that it can parse un-encoded header values.
``BaseHeader``'s ``__new__`` then creates the header instance, and calls its
@@ -135,11 +128,10 @@ headers.
mechanism for encoding non-ASCII text as ASCII characters within a header
value. When a *value* containing encoded words is passed to the
constructor, the ``UnstructuredHeader`` parser converts such encoded words
- back in to the original unicode, following the :rfc:`2047` rules for
- unstructured text. The parser uses heuristics to attempt to decode certain
- non-compliant encoded words. Defects are registered in such cases, as well
- as defects for issues such as invalid characters within the encoded words or
- the non-encoded text.
+ into unicode, following the :rfc:`2047` rules for unstructured text. The
+ parser uses heuristics to attempt to decode certain non-compliant encoded
+ words. Defects are registered in such cases, as well as defects for issues
+ such as invalid characters within the encoded words or the non-encoded text.
This header type provides no additional attributes.
@@ -213,15 +205,16 @@ headers.
the list of addresses is "flattened" into a one dimensional list).
The ``decoded`` value of the header will have all encoded words decoded to
- unicode. :class:`~encodings.idna` encoded domain names are also decoded to unicode. The
- ``decoded`` value is set by :attr:`~str.join`\ ing the :class:`str` value of
- the elements of the ``groups`` attribute with ``', '``.
+ unicode. :class:`~encodings.idna` encoded domain names are also decoded to
+ unicode. The ``decoded`` value is set by :attr:`~str.join`\ ing the
+ :class:`str` value of the elements of the ``groups`` attribute with ``',
+ '``.
A list of :class:`.Address` and :class:`.Group` objects in any combination
may be used to set the value of an address header. ``Group`` objects whose
``display_name`` is ``None`` will be interpreted as single addresses, which
allows an address list to be copied with groups intact by using the list
- obtained ``groups`` attribute of the source header.
+ obtained from the ``groups`` attribute of the source header.
.. class:: SingleAddressHeader
@@ -267,7 +260,7 @@ variant, :attr:`~.BaseHeader.max_count` is set to 1.
.. class:: ParameterizedMIMEHeader
- MOME headers all start with the prefix 'Content-'. Each specific header has
+ MIME headers all start with the prefix 'Content-'. Each specific header has
a certain value, described under the class for that header. Some can
also take a list of supplemental parameters, which have a common format.
This class serves as a base for all the MIME headers that take parameters.
@@ -454,3 +447,9 @@ construct structured values to assign to specific headers.
``display_name`` is none and there is a single ``Address`` in the
``addresses`` list, the ``str`` value will be the same as the ``str`` of
that single ``Address``.
+
+
+.. rubric:: Footnotes
+
+.. [1] Oringally added in 3.3 as a :term:`provisional module <provisional
+ package>`
diff --git a/Doc/library/email.message.rst b/Doc/library/email.message.rst
index 2907975..95136d2 100644
--- a/Doc/library/email.message.rst
+++ b/Doc/library/email.message.rst
@@ -3,91 +3,102 @@
.. module:: email.message
:synopsis: The base class representing email messages.
+.. moduleauthor:: R. David Murray <rdmurray@bitdance.com>
+.. sectionauthor:: R. David Murray <rdmurray@bitdance.com>,
+ Barry A. Warsaw <barry@python.org>
**Source code:** :source:`Lib/email/message.py`
--------------
-The central class in the :mod:`email` package is the :class:`Message` class,
-imported from the :mod:`email.message` module. It is the base class for the
-:mod:`email` object model. :class:`Message` provides the core functionality for
-setting and querying header fields, and for accessing message bodies.
-
-Conceptually, a :class:`Message` object consists of *headers* and *payloads*.
-Headers are :rfc:`2822` style field names and values where the field name and
-value are separated by a colon. The colon is not part of either the field name
-or the field value.
-
-Headers are stored and returned in case-preserving form but are matched
-case-insensitively. There may also be a single envelope header, also known as
-the *Unix-From* header or the ``From_`` header. The payload is either a string
-in the case of simple message objects or a list of :class:`Message` objects for
-MIME container documents (e.g. :mimetype:`multipart/\*` and
-:mimetype:`message/rfc822`).
-
-:class:`Message` objects provide a mapping style interface for accessing the
-message headers, and an explicit interface for accessing both the headers and
-the payload. It provides convenience methods for generating a flat text
-representation of the message object tree, for accessing commonly used header
-parameters, and for recursively walking over the object tree.
-
-Here are the methods of the :class:`Message` class:
-
-
-.. class:: Message(policy=compat32)
-
- If *policy* is specified (it must be an instance of a :mod:`~email.policy`
- class) use the rules it specifies to update and serialize the representation
- of the message. If *policy* is not set, use the :class:`compat32
- <email.policy.Compat32>` policy, which maintains backward compatibility with
- the Python 3.2 version of the email package. For more information see the
+.. versionadded:: 3.6 [1]_
+
+The central class in the :mod:`email` package is the :class:`EmailMessage`
+class, imported from the :mod:`email.message` module. It is the base class for
+the :mod:`email` object model. :class:`EmailMessage` provides the core
+functionality for setting and querying header fields, for accessing message
+bodies, and for creating or modifying structured messages.
+
+An email message consists of *headers* and a *payload* (which is also referred
+to as the *content*). Headers are :rfc:`5322` or :rfc:`6532` style field names
+and values, where the field name and value are separated by a colon. The colon
+is not part of either the field name or the field value. The payload may be a
+simple text message, or a binary object, or a structured sequence of
+sub-messages each with their own set of headers and their own payload. The
+latter type of payload is indicated by the message having a MIME type such as
+:mimetype:`multipart/\*` or :mimetype:`message/rfc822`.
+
+The conceptual model provided by an :class:`EmailMessage` object is that of an
+ordered dictionary of headers coupled with a *payload* that represents the
+:rfc:`5322` body of the message, which might be a list of sub-``EmailMessage``
+objects. In addition to the normal dictionary methods for accessing the header
+names and values, there are methods for accessing specialized information from
+the headers (for example the MIME content type), for operating on the payload,
+for generating a serialized version of the message, and for recursively walking
+over the object tree.
+
+The :class:`EmailMessage` dictionary-like interface is indexed by the header
+names, which must be ASCII values. The values of the dictionary are strings
+with some extra methods. Headers are stored and returned in case-preserving
+form, but field names are matched case-insensitively. Unlike a real dict,
+there is an ordering to the keys, and there can be duplicate keys. Additional
+methods are provided for working with headers that have duplicate keys.
+
+The *payload* is either a string or bytes object, in the case of simple message
+objects, or a list of :class:`EmailMessage` objects, for MIME container
+documents such as :mimetype:`multipart/\*` and :mimetype:`message/rfc822`
+message objects.
+
+
+.. class:: EmailMessage(policy=default)
+
+ If *policy* is specified use the rules it specifies to udpate and serialize
+ the representation of the message. If *policy* is not set, use the
+ :class:`~email.policy.default` policy, which follows the rules of the email
+ RFCs except for line endings (instead of the RFC mandated ``\r\n``, it uses
+ the Python standard ``\n`` line endings). For more information see the
:mod:`~email.policy` documentation.
- .. versionchanged:: 3.3 The *policy* keyword argument was added.
-
-
- .. method:: as_string(unixfrom=False, maxheaderlen=0, policy=None)
-
- Return the entire message flattened as a string. When optional *unixfrom*
- is true, the envelope header is included in the returned string.
- *unixfrom* defaults to ``False``. For backward compabitility reasons,
- *maxheaderlen* defaults to ``0``, so if you want a different value you
- must override it explicitly (the value specified for *max_line_length* in
- the policy will be ignored by this method). The *policy* argument may be
- used to override the default policy obtained from the message instance.
- This can be used to control some of the formatting produced by the
- method, since the specified *policy* will be passed to the ``Generator``.
-
- Flattening the message may trigger changes to the :class:`Message` if
- defaults need to be filled in to complete the transformation to a string
- (for example, MIME boundaries may be generated or modified).
-
- Note that this method is provided as a convenience and may not always
- format the message the way you want. For example, by default it does
- not do the mangling of lines that begin with ``From`` that is
- required by the unix mbox format. For more flexibility, instantiate a
- :class:`~email.generator.Generator` instance and use its
- :meth:`~email.generator.Generator.flatten` method directly. For example::
-
- from io import StringIO
- from email.generator import Generator
- fp = StringIO()
- g = Generator(fp, mangle_from_=True, maxheaderlen=60)
- g.flatten(msg)
- text = fp.getvalue()
+ .. method:: as_string(unixfrom=False, maxheaderlen=None, policy=None)
- If the message object contains binary data that is not encoded according
- to RFC standards, the non-compliant data will be replaced by unicode
- "unknown character" code points. (See also :meth:`.as_bytes` and
- :class:`~email.generator.BytesGenerator`.)
-
- .. versionchanged:: 3.4 the *policy* keyword argument was added.
+ Return the entire message flattened as a string. When optional
+ *unixfrom* is true, the envelope header is included in the returned
+ string. *unixfrom* defaults to ``False``. For backward compabitility
+ with the base :class:`~email.message.Message` class *maxheaderlen* is
+ accepted, but defaults to ``None``, which means that by default the line
+ length is controlled by the
+ :attr:`~email.policy.EmailPolicy.max_line_length` of the policy. The
+ *policy* argument may be used to override the default policy obtained
+ from the message instance. This can be used to control some of the
+ formatting produced by the method, since the specified *policy* will be
+ passed to the :class:`~email.generator.Generator`.
+
+ Flattening the message may trigger changes to the :class:`EmailMessage`
+ if defaults need to be filled in to complete the transformation to a
+ string (for example, MIME boundaries may be generated or modified).
+
+ Note that this method is provided as a convenience and may not be the
+ most useful way to serialize messages in your application, especially if
+ you are dealing with multiple messages. See
+ :class:`email.generator.Generator` for a more flexible API for
+ serializing messages. Note also that this method is restricted to
+ producing messages serialized as "7 bit clean" when
+ :attr:`~email.policy.EmailPolicy.utf8` is ``False``, which is the default.
+
+ .. versionchanged:: 3.6 the default behavior when *maxheaderlen*
+ is not specified was changed from defaulting to 0 to defaulting
+ to the value of *max_line_length* from the policy.
.. method:: __str__()
- Equivalent to :meth:`.as_string()`. Allows ``str(msg)`` to produce a
- string containing the formatted message.
+ Equivalent to `as_string(policy=self.policy.clone(utf8=True)`. Allows
+ ``str(msg)`` to produce a string containing the serialized message in a
+ readable format.
+
+ .. versionchanged:: 3.4 the method was changed to use ``utf8=True``,
+ thus producing an :rfc:`6531`-like message representation, instead of
+ being a direct alias for :meth:`as_string`.
.. method:: as_bytes(unixfrom=False, policy=None)
@@ -98,52 +109,42 @@ Here are the methods of the :class:`Message` class:
used to override the default policy obtained from the message instance.
This can be used to control some of the formatting produced by the
method, since the specified *policy* will be passed to the
- ``BytesGenerator``.
-
- Flattening the message may trigger changes to the :class:`Message` if
- defaults need to be filled in to complete the transformation to a string
- (for example, MIME boundaries may be generated or modified).
+ :class:`~email.generator.BytesGenerator`.
- Note that this method is provided as a convenience and may not always
- format the message the way you want. For example, by default it does
- not do the mangling of lines that begin with ``From`` that is
- required by the unix mbox format. For more flexibility, instantiate a
- :class:`~email.generator.BytesGenerator` instance and use its
- :meth:`~email.generator.BytesGenerator.flatten` method directly.
- For example::
+ Flattening the message may trigger changes to the :class:`EmailMessage`
+ if defaults need to be filled in to complete the transformation to a
+ string (for example, MIME boundaries may be generated or modified).
- from io import BytesIO
- from email.generator import BytesGenerator
- fp = BytesIO()
- g = BytesGenerator(fp, mangle_from_=True, maxheaderlen=60)
- g.flatten(msg)
- text = fp.getvalue()
-
- .. versionadded:: 3.4
+ Note that this method is provided as a convenience and may not be the
+ most useful way to serialize messages in your application, especially if
+ you are dealing with multiple messages. See
+ :class:`email.generator.BytesGenerator` for a more flexible API for
+ serializing messages.
.. method:: __bytes__()
Equivalent to :meth:`.as_bytes()`. Allows ``bytes(msg)`` to produce a
- bytes object containing the formatted message.
-
- .. versionadded:: 3.4
+ bytes object containing the serialized message.
.. method:: is_multipart()
Return ``True`` if the message's payload is a list of sub-\
- :class:`Message` objects, otherwise return ``False``. When
+ :class:`EmailMessage` objects, otherwise return ``False``. When
:meth:`is_multipart` returns ``False``, the payload should be a string
- object. (Note that :meth:`is_multipart` returning ``True`` does not
- necessarily mean that "msg.get_content_maintype() == 'multipart'" will
- return the ``True``. For example, ``is_multipart`` will return ``True``
- when the :class:`Message` is of type ``message/rfc822``.)
+ object (which might be a CTE encoded binary payload). Note that
+ :meth:`is_multipart` returning ``True`` does not necessarily mean that
+ "msg.get_content_maintype() == 'multipart'" will return the ``True``.
+ For example, ``is_multipart`` will return ``True`` when the
+ :class:`EmailMessage` is of type ``message/rfc822``.
.. method:: set_unixfrom(unixfrom)
- Set the message's envelope header to *unixfrom*, which should be a string.
+ Set the message's envelope header to *unixfrom*, which should be a
+ string. (See :class:`~mailbox.mboxMessage` for a brief description of
+ this header.)
.. method:: get_unixfrom()
@@ -152,109 +153,23 @@ Here are the methods of the :class:`Message` class:
envelope header was never set.
- .. method:: attach(payload)
-
- Add the given *payload* to the current payload, which must be ``None`` or
- a list of :class:`Message` objects before the call. After the call, the
- payload will always be a list of :class:`Message` objects. If you want to
- set the payload to a scalar object (e.g. a string), use
- :meth:`set_payload` instead.
-
-
- .. method:: get_payload(i=None, decode=False)
-
- Return the current payload, which will be a list of
- :class:`Message` objects when :meth:`is_multipart` is ``True``, or a
- string when :meth:`is_multipart` is ``False``. If the payload is a list
- and you mutate the list object, you modify the message's payload in place.
-
- With optional argument *i*, :meth:`get_payload` will return the *i*-th
- element of the payload, counting from zero, if :meth:`is_multipart` is
- ``True``. An :exc:`IndexError` will be raised if *i* is less than 0 or
- greater than or equal to the number of items in the payload. If the
- payload is a string (i.e. :meth:`is_multipart` is ``False``) and *i* is
- given, a :exc:`TypeError` is raised.
-
- Optional *decode* is a flag indicating whether the payload should be
- decoded or not, according to the :mailheader:`Content-Transfer-Encoding`
- header. When ``True`` and the message is not a multipart, the payload will
- be decoded if this header's value is ``quoted-printable`` or ``base64``.
- If some other encoding is used, or :mailheader:`Content-Transfer-Encoding`
- header is missing, the payload is
- returned as-is (undecoded). In all cases the returned value is binary
- data. If the message is a multipart and the *decode* flag is ``True``,
- then ``None`` is returned. If the payload is base64 and it was not
- perfectly formed (missing padding, characters outside the base64
- alphabet), then an appropriate defect will be added to the message's
- defect property (:class:`~email.errors.InvalidBase64PaddingDefect` or
- :class:`~email.errors.InvalidBase64CharactersDefect`, respectively).
-
- When *decode* is ``False`` (the default) the body is returned as a string
- without decoding the :mailheader:`Content-Transfer-Encoding`. However,
- for a :mailheader:`Content-Transfer-Encoding` of 8bit, an attempt is made
- to decode the original bytes using the ``charset`` specified by the
- :mailheader:`Content-Type` header, using the ``replace`` error handler.
- If no ``charset`` is specified, or if the ``charset`` given is not
- recognized by the email package, the body is decoded using the default
- ASCII charset.
-
-
- .. method:: set_payload(payload, charset=None)
-
- Set the entire message object's payload to *payload*. It is the client's
- responsibility to ensure the payload invariants. Optional *charset* sets
- the message's default character set; see :meth:`set_charset` for details.
-
- .. method:: set_charset(charset)
-
- Set the character set of the payload to *charset*, which can either be a
- :class:`~email.charset.Charset` instance (see :mod:`email.charset`), a
- string naming a character set, or ``None``. If it is a string, it will
- be converted to a :class:`~email.charset.Charset` instance. If *charset*
- is ``None``, the ``charset`` parameter will be removed from the
- :mailheader:`Content-Type` header (the message will not be otherwise
- modified). Anything else will generate a :exc:`TypeError`.
-
- If there is no existing :mailheader:`MIME-Version` header one will be
- added. If there is no existing :mailheader:`Content-Type` header, one
- will be added with a value of :mimetype:`text/plain`. Whether the
- :mailheader:`Content-Type` header already exists or not, its ``charset``
- parameter will be set to *charset.output_charset*. If
- *charset.input_charset* and *charset.output_charset* differ, the payload
- will be re-encoded to the *output_charset*. If there is no existing
- :mailheader:`Content-Transfer-Encoding` header, then the payload will be
- transfer-encoded, if needed, using the specified
- :class:`~email.charset.Charset`, and a header with the appropriate value
- will be added. If a :mailheader:`Content-Transfer-Encoding` header
- already exists, the payload is assumed to already be correctly encoded
- using that :mailheader:`Content-Transfer-Encoding` and is not modified.
-
- .. method:: get_charset()
-
- Return the :class:`~email.charset.Charset` instance associated with the
- message's payload.
-
- The following methods implement a mapping-like interface for accessing the
- message's :rfc:`2822` headers. Note that there are some semantic differences
+ The following methods implement the mapping-like interface for accessing the
+ message's headers. Note that there are some semantic differences
between these methods and a normal mapping (i.e. dictionary) interface. For
example, in a dictionary there are no duplicate keys, but here there may be
duplicate message headers. Also, in dictionaries there is no guaranteed
- order to the keys returned by :meth:`keys`, but in a :class:`Message` object,
- headers are always returned in the order they appeared in the original
- message, or were added to the message later. Any header deleted and then
- re-added are always appended to the end of the header list.
+ order to the keys returned by :meth:`keys`, but in an :class:`EmailMessage`
+ object, headers are always returned in the order they appeared in the
+ original message, or in which they were added to the message later. Any
+ header deleted and then re-added is always appended to the end of the
+ header list.
- These semantic differences are intentional and are biased toward maximal
- convenience.
+ These semantic differences are intentional and are biased toward
+ convenience in the most common use cases.
Note that in all cases, any envelope header present in the message is not
included in the mapping interface.
- In a model generated from bytes, any header values that (in contravention of
- the RFCs) contain non-ASCII bytes will, when retrieved through this
- interface, be represented as :class:`~email.header.Header` objects with
- a charset of `unknown-8bit`.
-
.. method:: __len__()
@@ -264,8 +179,8 @@ Here are the methods of the :class:`Message` class:
.. method:: __contains__(name)
Return true if the message object has a field named *name*. Matching is
- done case-insensitively and *name* should not include the trailing colon.
- Used for the ``in`` operator, e.g.::
+ done without regard to case and *name* does not include the trailing
+ colon. Used for the ``in`` operator. For example::
if 'message-id' in myMessage:
print('Message-ID:', myMessage['message-id'])
@@ -273,20 +188,23 @@ Here are the methods of the :class:`Message` class:
.. method:: __getitem__(name)
- Return the value of the named header field. *name* should not include the
+ Return the value of the named header field. *name* does not include the
colon field separator. If the header is missing, ``None`` is returned; a
:exc:`KeyError` is never raised.
Note that if the named field appears more than once in the message's
headers, exactly which of those field values will be returned is
undefined. Use the :meth:`get_all` method to get the values of all the
- extant named headers.
+ extant headers named *name*.
+
+ Using the standard (non-``compat32``) policies, the returned value is an
+ instance of a subclass of :class:`email.headerregistry.BaseHeader`.
.. method:: __setitem__(name, val)
Add a header to the message with field name *name* and value *val*. The
- field is appended to the end of the message's existing fields.
+ field is appended to the end of the message's existing headers.
Note that this does *not* overwrite or delete any existing header with the same
name. If you want to ensure that the new header is the only one present in the
@@ -295,6 +213,13 @@ Here are the methods of the :class:`Message` class:
del msg['subject']
msg['subject'] = 'Python roolz!'
+ If the :mod:`policy` defines certain haders to be unique (as the standard
+ policies do), this method may raise a :exc:`ValueError` when an attempt
+ is made to assign a value to such a header when one already exists. This
+ behavior is intentional for consistency's sake, but do not depend on it
+ as we may choose to make such assignments do an automatic deletion of the
+ existing header in the future.
+
.. method:: __delitem__(name)
@@ -323,9 +248,10 @@ Here are the methods of the :class:`Message` class:
Return the value of the named header field. This is identical to
:meth:`__getitem__` except that optional *failobj* is returned if the
- named header is missing (defaults to ``None``).
+ named header is missing (*failobj* defaults to ``None``).
- Here are some additional useful methods:
+
+ Here are some additional useful header related methods:
.. method:: get_all(name, failobj=None)
@@ -346,17 +272,19 @@ Here are the methods of the :class:`Message` class:
taken as the parameter name, with underscores converted to dashes (since
dashes are illegal in Python identifiers). Normally, the parameter will
be added as ``key="value"`` unless the value is ``None``, in which case
- only the key will be added. If the value contains non-ASCII characters,
- it can be specified as a three tuple in the format
- ``(CHARSET, LANGUAGE, VALUE)``, where ``CHARSET`` is a string naming the
- charset to be used to encode the value, ``LANGUAGE`` can usually be set
- to ``None`` or the empty string (see :rfc:`2231` for other possibilities),
- and ``VALUE`` is the string value containing non-ASCII code points. If
- a three tuple is not passed and the value contains non-ASCII characters,
- it is automatically encoded in :rfc:`2231` format using a ``CHARSET``
- of ``utf-8`` and a ``LANGUAGE`` of ``None``.
-
- Here's an example::
+ only the key will be added.
+
+ If the value contains non-ASCII characters, the charset and language may
+ be explicitly controlled by specifing the value as a three tuple in the
+ format ``(CHARSET, LANGUAGE, VALUE)``, where ``CHARSET`` is a string
+ naming the charset to be used to encode the value, ``LANGUAGE`` can
+ usually be set to ``None`` or the empty string (see :rfc:`2231` for other
+ possibilities), and ``VALUE`` is the string value containing non-ASCII
+ code points. If a three tuple is not passed and the value contains
+ non-ASCII characters, it is automatically encoded in :rfc:`2231` format
+ using a ``CHARSET`` of ``utf-8`` and a ``LANGUAGE`` of ``None``.
+
+ Here is an example::
msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
@@ -364,37 +292,35 @@ Here are the methods of the :class:`Message` class:
Content-Disposition: attachment; filename="bud.gif"
- An example with non-ASCII characters::
+ An example of the extended interface with non-ASCII characters::
msg.add_header('Content-Disposition', 'attachment',
filename=('iso-8859-1', '', 'Fußballer.ppt'))
- Which produces ::
-
- Content-Disposition: attachment; filename*="iso-8859-1''Fu%DFballer.ppt"
-
.. method:: replace_header(_name, _value)
Replace a header. Replace the first header found in the message that
- matches *_name*, retaining header order and field name case. If no
- matching header was found, a :exc:`KeyError` is raised.
+ matches *_name*, retaining header order and field name case of the
+ original header. If no matching header is found, raise a
+ :exc:`KeyError`.
.. method:: get_content_type()
- Return the message's content type. The returned string is coerced to
- lower case of the form :mimetype:`maintype/subtype`. If there was no
- :mailheader:`Content-Type` header in the message the default type as given
- by :meth:`get_default_type` will be returned. Since according to
- :rfc:`2045`, messages always have a default type, :meth:`get_content_type`
- will always return a value.
+ Return the message's content type, coerced to lower case of the form
+ :mimetype:`maintype/subtype`. If there is no :mailheader:`Content-Type`
+ header in the message return the value returned by
+ :meth:`get_default_type`. If the :mailheader:`Content-Type` header is
+ invalid, return ``text/plain``.
- :rfc:`2045` defines a message's default type to be :mimetype:`text/plain`
- unless it appears inside a :mimetype:`multipart/digest` container, in
- which case it would be :mimetype:`message/rfc822`. If the
- :mailheader:`Content-Type` header has an invalid type specification,
- :rfc:`2045` mandates that the default type be :mimetype:`text/plain`.
+ (According to :rfc:`2045`, messages always have a default type,
+ :meth:`get_content_type` will always return a value. :rfc:`2045` defines
+ a message's default type to be :mimetype:`text/plain` unless it appears
+ inside a :mimetype:`multipart/digest` container, in which case it would
+ be :mimetype:`message/rfc822`. If the :mailheader:`Content-Type` header
+ has an invalid type specification, :rfc:`2045` mandates that the default
+ type be :mimetype:`text/plain`.)
.. method:: get_content_maintype()
@@ -420,81 +346,41 @@ Here are the methods of the :class:`Message` class:
.. method:: set_default_type(ctype)
Set the default content type. *ctype* should either be
- :mimetype:`text/plain` or :mimetype:`message/rfc822`, although this is not
- enforced. The default content type is not stored in the
- :mailheader:`Content-Type` header.
-
-
- .. method:: get_params(failobj=None, header='content-type', unquote=True)
-
- Return the message's :mailheader:`Content-Type` parameters, as a list.
- The elements of the returned list are 2-tuples of key/value pairs, as
- split on the ``'='`` sign. The left hand side of the ``'='`` is the key,
- while the right hand side is the value. If there is no ``'='`` sign in
- the parameter the value is the empty string, otherwise the value is as
- described in :meth:`get_param` and is unquoted if optional *unquote* is
- ``True`` (the default).
-
- Optional *failobj* is the object to return if there is no
- :mailheader:`Content-Type` header. Optional *header* is the header to
- search instead of :mailheader:`Content-Type`.
-
-
- .. method:: get_param(param, failobj=None, header='content-type', unquote=True)
-
- Return the value of the :mailheader:`Content-Type` header's parameter
- *param* as a string. If the message has no :mailheader:`Content-Type`
- header or if there is no such parameter, then *failobj* is returned
- (defaults to ``None``).
-
- Optional *header* if given, specifies the message header to use instead of
- :mailheader:`Content-Type`.
-
- Parameter keys are always compared case insensitively. The return value
- can either be a string, or a 3-tuple if the parameter was :rfc:`2231`
- encoded. When it's a 3-tuple, the elements of the value are of the form
- ``(CHARSET, LANGUAGE, VALUE)``. Note that both ``CHARSET`` and
- ``LANGUAGE`` can be ``None``, in which case you should consider ``VALUE``
- to be encoded in the ``us-ascii`` charset. You can usually ignore
- ``LANGUAGE``.
-
- If your application doesn't care whether the parameter was encoded as in
- :rfc:`2231`, you can collapse the parameter value by calling
- :func:`email.utils.collapse_rfc2231_value`, passing in the return value
- from :meth:`get_param`. This will return a suitably decoded Unicode
- string when the value is a tuple, or the original string unquoted if it
- isn't. For example::
-
- rawparam = msg.get_param('foo')
- param = email.utils.collapse_rfc2231_value(rawparam)
-
- In any case, the parameter value (either the returned string, or the
- ``VALUE`` item in the 3-tuple) is always unquoted, unless *unquote* is set
- to ``False``.
+ :mimetype:`text/plain` or :mimetype:`message/rfc822`, although this is
+ not enforced. The default content type is not stored in the
+ :mailheader:`Content-Type` header, so it only affects the return value of
+ the ``get_content_type`` methods when no :mailheader:`Content-Type`
+ header is present in the message.
.. method:: set_param(param, value, header='Content-Type', requote=True, \
charset=None, language='', replace=False)
Set a parameter in the :mailheader:`Content-Type` header. If the
- parameter already exists in the header, its value will be replaced with
- *value*. If the :mailheader:`Content-Type` header as not yet been defined
- for this message, it will be set to :mimetype:`text/plain` and the new
- parameter value will be appended as per :rfc:`2045`.
-
- Optional *header* specifies an alternative header to
- :mailheader:`Content-Type`, and all parameters will be quoted as necessary
- unless optional *requote* is ``False`` (the default is ``True``).
-
- If optional *charset* is specified, the parameter will be encoded
- according to :rfc:`2231`. Optional *language* specifies the RFC 2231
- language, defaulting to the empty string. Both *charset* and *language*
- should be strings.
+ parameter already exists in the header, replace its value with *value*.
+ When *header* is ``Content-Type`` (the default) and the header does not
+ yet exist in the message, add it, set its value to
+ :mimetype:`text/plain`, and append the new parameter value. Optional
+ *header* specifies an alternative header to :mailheader:`Content-Type`.
+
+ If the value contains non-ASCII characters, the charset and language may
+ be explicity specified using the optional *charset* and *language*
+ parameters. Optional *language* specifies the :rfc:`2231` language,
+ defaulting to the empty string. Both *charset* and *language* should be
+ strings. The default is to use the ``utf8`` *charset* and ``None`` for
+ the *language*.
If *replace* is ``False`` (the default) the header is moved to the
end of the list of headers. If *replace* is ``True``, the header
will be updated in place.
+ Use of the *requote* parameter with :class:`EmailMessage` objects is
+ deprecated.
+
+ Note that existing parameter values of headers may be accessed through
+ the :attr:`~email.headerregistry.BaseHeader.params` attribute of the
+ header value (for example, ``msg['Content-Type'].params['charset']``.
+
.. versionchanged:: 3.4 ``replace`` keyword was added.
@@ -502,25 +388,11 @@ Here are the methods of the :class:`Message` class:
Remove the given parameter completely from the :mailheader:`Content-Type`
header. The header will be re-written in place without the parameter or
- its value. All values will be quoted as necessary unless *requote* is
- ``False`` (the default is ``True``). Optional *header* specifies an
- alternative to :mailheader:`Content-Type`.
-
-
- .. method:: set_type(type, header='Content-Type', requote=True)
-
- Set the main type and subtype for the :mailheader:`Content-Type`
- header. *type* must be a string in the form :mimetype:`maintype/subtype`,
- otherwise a :exc:`ValueError` is raised.
-
- This method replaces the :mailheader:`Content-Type` header, keeping all
- the parameters in place. If *requote* is ``False``, this leaves the
- existing header's quoting as is, otherwise the parameters will be quoted
- (the default).
+ its value. Optional *header* specifies an alternative to
+ :mailheader:`Content-Type`.
- An alternative header can be specified in the *header* argument. When the
- :mailheader:`Content-Type` header is set a :mailheader:`MIME-Version`
- header is also added.
+ Use of the *requote* parameter with :class:`EmailMessage` objects is
+ deprecated.
.. method:: get_filename(failobj=None)
@@ -549,12 +421,11 @@ Here are the methods of the :class:`Message` class:
necessary. A :exc:`~email.errors.HeaderParseError` is raised if the
message object has no :mailheader:`Content-Type` header.
- Note that using this method is subtly different than deleting the old
+ Note that using this method is subtly different from deleting the old
:mailheader:`Content-Type` header and adding a new one with the new
boundary via :meth:`add_header`, because :meth:`set_boundary` preserves
the order of the :mailheader:`Content-Type` header in the list of
- headers. However, it does *not* preserve any continuation lines which may
- have been present in the original :mailheader:`Content-Type` header.
+ headers.
.. method:: get_content_charset(failobj=None)
@@ -563,9 +434,6 @@ Here are the methods of the :class:`Message` class:
coerced to lower case. If there is no :mailheader:`Content-Type` header, or if
that header has no ``charset`` parameter, *failobj* is returned.
- Note that this method differs from :meth:`get_charset` which returns the
- :class:`~email.charset.Charset` instance for the default encoding of the message body.
-
.. method:: get_charsets(failobj=None)
@@ -575,10 +443,19 @@ Here are the methods of the :class:`Message` class:
Each item in the list will be a string which is the value of the
``charset`` parameter in the :mailheader:`Content-Type` header for the
- represented subpart. However, if the subpart has no
- :mailheader:`Content-Type` header, no ``charset`` parameter, or is not of
- the :mimetype:`text` main MIME type, then that item in the returned list
- will be *failobj*.
+ represented subpart. If the subpart has no :mailheader:`Content-Type`
+ header, no ``charset`` parameter, or is not of the :mimetype:`text` main
+ MIME type, then that item in the returned list will be *failobj*.
+
+
+ .. method:: is_attachment
+
+ Return ``True`` if there is a :mailheader:`Content-Disposition` header
+ and its (case insensitive) value is ``attachment``, ``False`` otherwise.
+
+ .. versionchanged:: 3.4.2
+ is_attachment is now a method instead of a property, for consistency
+ with :meth:`~email.message.Message.is_multipart`.
.. method:: get_content_disposition()
@@ -590,6 +467,11 @@ Here are the methods of the :class:`Message` class:
.. versionadded:: 3.5
+
+ The following methods relate to interrogating and manipulating the content
+ (payload) of the message.
+
+
.. method:: walk()
The :meth:`walk` method is an all-purpose generator which can be used to
@@ -651,8 +533,169 @@ Here are the methods of the :class:`Message` class:
into the subparts.
- :class:`Message` objects can also optionally contain two instance attributes,
- which can be used when generating the plain text of a MIME message.
+ .. method:: get_body(preferencelist=('related', 'html', 'plain'))
+
+ Return the MIME part that is the best candidate to be the "body" of the
+ message.
+
+ *preferencelist* must be a sequence of strings from the set ``related``,
+ ``html``, and ``plain``, and indicates the order of preference for the
+ content type of the part returned.
+
+ Start looking for candidate matches with the object on which the
+ ``get_body`` method is called.
+
+ If ``related`` is not included in *preferencelist*, consider the root
+ part (or subpart of the root part) of any related encountered as a
+ candidate if the (sub-)part matches a preference.
+
+ When encountering a ``multipart/related``, check the ``start`` parameter
+ and if a part with a matching :mailheader:`Content-ID` is found, consider
+ only it when looking for candidate matches. Otherwise consider only the
+ first (default root) part of the ``multipart/related``.
+
+ If a part has a :mailheader:`Content-Disposition` header, only consider
+ the part a candidate match if the value of the header is ``inline``.
+
+ If none of the candidates matches any of the preferences in
+ *preferneclist*, return ``None``.
+
+ Notes: (1) For most applications the only *preferencelist* combinations
+ that really make sense are ``('plain',)``, ``('html', 'plain')``, and the
+ default ``('related', 'html', 'plain')``. (2) Because matching starts
+ with the object on which ``get_body`` is called, calling ``get_body`` on
+ a ``multipart/related`` will return the object itself unless
+ *preferencelist* has a non-default value. (3) Messages (or message parts)
+ that do not specify a :mailheader:`Content-Type` or whose
+ :mailheader:`Content-Type` header is invalid will be treated as if they
+ are of type ``text/plain``, which may occasionally cause ``get_body`` to
+ return unexpected results.
+
+
+ .. method:: iter_attachments()
+
+ Return an iterator over all of the immediate sub-parts of the message
+ that are not candidate "body" parts. That is, skip the first occurrence
+ of each of ``text/plain``, ``text/html``, ``multipart/related``, or
+ ``multipart/alternative`` (unless they are explicitly marked as
+ attachments via :mailheader:`Content-Disposition: attachment`), and
+ return all remaining parts. When applied directly to a
+ ``multipart/related``, return an iterator over the all the related parts
+ except the root part (ie: the part pointed to by the ``start`` parameter,
+ or the first part if there is no ``start`` parameter or the ``start``
+ parameter doesn't match the :mailheader:`Content-ID` of any of the
+ parts). When applied directly to a ``multipart/alternative`` or a
+ non-``multipart``, return an empty iterator.
+
+
+ .. method:: iter_parts()
+
+ Return an iterator over all of the immediate sub-parts of the message,
+ which will be empty for a non-``multipart``. (See also
+ :meth:`~email.message.EmailMessage.walk`.)
+
+
+ .. method:: get_content(*args, content_manager=None, **kw)
+
+ Call the :meth:`~email.contentmanager.ContentManager.get_content` method
+ of the *content_manager*, passing self as the message object, and passing
+ along any other arguments or keywords as additional arguments. If
+ *content_manager* is not specified, use the ``content_manager`` specified
+ by the current :mod:`~email.policy`.
+
+
+ .. method:: set_content(*args, content_manager=None, **kw)
+
+ Call the :meth:`~email.contentmanager.ContentManager.set_content` method
+ of the *content_manager*, passing self as the message object, and passing
+ along any other arguments or keywords as additional arguments. If
+ *content_manager* is not specified, use the ``content_manager`` specified
+ by the current :mod:`~email.policy`.
+
+
+ .. method:: make_related(boundary=None)
+
+ Convert a non-``multipart`` message into a ``multipart/related`` message,
+ moving any existing :mailheader:`Content-` headers and payload into a
+ (new) first part of the ``multipart``. If *boundary* is specified, use
+ it as the boundary string in the multipart, otherwise leave the boundary
+ to be automatically created when it is needed (for example, when the
+ message is serialized).
+
+
+ .. method:: make_alternative(boundary=None)
+
+ Convert a non-``multipart`` or a ``multipart/related`` into a
+ ``multipart/alternative``, moving any existing :mailheader:`Content-`
+ headers and payload into a (new) first part of the ``multipart``. If
+ *boundary* is specified, use it as the boundary string in the multipart,
+ otherwise leave the boundary to be automatically created when it is
+ needed (for example, when the message is serialized).
+
+
+ .. method:: make_mixed(boundary=None)
+
+ Convert a non-``multipart``, a ``multipart/related``, or a
+ ``multipart-alternative`` into a ``multipart/mixed``, moving any existing
+ :mailheader:`Content-` headers and payload into a (new) first part of the
+ ``multipart``. If *boundary* is specified, use it as the boundary string
+ in the multipart, otherwise leave the boundary to be automatically
+ created when it is needed (for example, when the message is serialized).
+
+
+ .. method:: add_related(*args, content_manager=None, **kw)
+
+ If the message is a ``multipart/related``, create a new message
+ object, pass all of the arguments to its :meth:`set_content` method,
+ and :meth:`~email.message.Message.attach` it to the ``multipart``. If
+ the message is a non-``multipart``, call :meth:`make_related` and then
+ proceed as above. If the message is any other type of ``multipart``,
+ raise a :exc:`TypeError`. If *content_manager* is not specified, use
+ the ``content_manager`` specified by the current :mod:`~email.policy`.
+ If the added part has no :mailheader:`Content-Disposition` header,
+ add one with the value ``inline``.
+
+
+ .. method:: add_alternative(*args, content_manager=None, **kw)
+
+ If the message is a ``multipart/alternative``, create a new message
+ object, pass all of the arguments to its :meth:`set_content` method, and
+ :meth:`~email.message.Message.attach` it to the ``multipart``. If the
+ message is a non-``multipart`` or ``multipart/related``, call
+ :meth:`make_alternative` and then proceed as above. If the message is
+ any other type of ``multipart``, raise a :exc:`TypeError`. If
+ *content_manager* is not specified, use the ``content_manager`` specified
+ by the current :mod:`~email.policy`.
+
+
+ .. method:: add_attachment(*args, content_manager=None, **kw)
+
+ If the message is a ``multipart/mixed``, create a new message object,
+ pass all of the arguments to its :meth:`set_content` method, and
+ :meth:`~email.message.Message.attach` it to the ``multipart``. If the
+ message is a non-``multipart``, ``multipart/related``, or
+ ``multipart/alternative``, call :meth:`make_mixed` and then proceed as
+ above. If *content_manager* is not specified, use the ``content_manager``
+ specified by the current :mod:`~email.policy`. If the added part
+ has no :mailheader:`Content-Disposition` header, add one with the value
+ ``attachment``. This method can be used both for explicit attachments
+ (:mailheader:`Content-Disposition: attachment` and ``inline`` attachments
+ (:mailheader:`Content-Disposition: inline`), by passing appropriate
+ options to the ``content_manager``.
+
+
+ .. method:: clear()
+
+ Remove the payload and all of the headers.
+
+
+ .. method:: clear_content()
+
+ Remove the payload and all of the :exc:`Content-` headers, leaving
+ all other headers intact and in their original order.
+
+
+ :class:`EmailMessage` objects have the following instance attributes:
.. attribute:: preamble
@@ -682,11 +725,8 @@ Here are the methods of the :class:`Message` class:
The *epilogue* attribute acts the same way as the *preamble* attribute,
except that it contains text that appears between the last boundary and
- the end of the message.
-
- You do not need to set the epilogue to the empty string in order for the
- :class:`~email.generator.Generator` to print a newline at the end of the
- file.
+ the end of the message. As with the :attr:`~EmailMessage.preamble`,
+ if there is no epilog text this attribute will be ``None``.
.. attribute:: defects
@@ -694,3 +734,18 @@ Here are the methods of the :class:`Message` class:
The *defects* attribute contains a list of all the problems found when
parsing this message. See :mod:`email.errors` for a detailed description
of the possible parsing defects.
+
+
+.. class:: MIMEPart(policy=default)
+
+ This class represents a subpart of a MIME message. It is identical to
+ :class:`EmailMessage`, except that no :mailheader:`MIME-Version` headers are
+ added when :meth:`~EmailMessage.set_content` is called, since sub-parts do
+ not need their own :mailheader:`MIME-Version` headers.
+
+
+.. rubric:: Footnotes
+
+.. [1] Oringally added in 3.4 as a :term:`provisional module <provisional
+ package>`. Docs for legacy message class moved to
+ :ref:`compat32_message`.
diff --git a/Doc/library/email.mime.rst b/Doc/library/email.mime.rst
index 8297dea..d9dae9f 100644
--- a/Doc/library/email.mime.rst
+++ b/Doc/library/email.mime.rst
@@ -8,6 +8,11 @@
--------------
+This module is part of the legacy (``Compat32``) email API. Its functionality
+is partially replaced by the :mod:`~email.contentmanager` in the new API, but
+in certain applications these classes may still be useful, even in non-legacy
+code.
+
Ordinarily, you get a message object structure by passing a file or some text to
a parser, which parses the text and returns the root message object. However
you can also build a complete message structure from scratch, or even individual
@@ -25,7 +30,7 @@ Here are the classes:
.. currentmodule:: email.mime.base
-.. class:: MIMEBase(_maintype, _subtype, **_params)
+.. class:: MIMEBase(_maintype, _subtype, *, policy=compat32, **_params)
Module: :mod:`email.mime.base`
@@ -41,10 +46,17 @@ Here are the classes:
key/value dictionary and is passed directly to :meth:`Message.add_header
<email.message.Message.add_header>`.
+ If *policy* is specified, (defaults to the
+ :class:`compat32 <email.policy.Compat32>` policy) it will be passed to
+ :class:`~email.message.Message`.
+
The :class:`MIMEBase` class always adds a :mailheader:`Content-Type` header
(based on *_maintype*, *_subtype*, and *_params*), and a
:mailheader:`MIME-Version` header (always set to ``1.0``).
+ .. versionchanged:: 3.6
+ Added *policy* keyword-only parameter.
+
.. currentmodule:: email.mime.nonmultipart
@@ -62,7 +74,8 @@ Here are the classes:
.. currentmodule:: email.mime.multipart
-.. class:: MIMEMultipart(_subtype='mixed', boundary=None, _subparts=None, **_params)
+.. class:: MIMEMultipart(_subtype='mixed', boundary=None, _subparts=None, \
+ *, policy=compat32, **_params)
Module: :mod:`email.mime.multipart`
@@ -82,14 +95,20 @@ Here are the classes:
to the message by using the :meth:`Message.attach
<email.message.Message.attach>` method.
+ Optional *policy* argument defaults to :class:`compat32 <email.policy.Compat32>`.
+
Additional parameters for the :mailheader:`Content-Type` header are taken from
the keyword arguments, or passed into the *_params* argument, which is a keyword
dictionary.
+ .. versionchanged:: 3.6
+ Added *policy* keyword-only parameter.
.. currentmodule:: email.mime.application
-.. class:: MIMEApplication(_data, _subtype='octet-stream', _encoder=email.encoders.encode_base64, **_params)
+.. class:: MIMEApplication(_data, _subtype='octet-stream', \
+ _encoder=email.encoders.encode_base64, \
+ *, policy=compat32, **_params)
Module: :mod:`email.mime.application`
@@ -109,12 +128,18 @@ Here are the classes:
object as necessary. The default encoding is base64. See the
:mod:`email.encoders` module for a list of the built-in encoders.
+ Optional *policy* argument defaults to :class:`compat32 <email.policy.Compat32>`.
+
*_params* are passed straight through to the base class constructor.
+ .. versionchanged:: 3.6
+ Added *policy* keyword-only parameter.
.. currentmodule:: email.mime.audio
-.. class:: MIMEAudio(_audiodata, _subtype=None, _encoder=email.encoders.encode_base64, **_params)
+.. class:: MIMEAudio(_audiodata, _subtype=None, \
+ _encoder=email.encoders.encode_base64, \
+ *, policy=compat32, **_params)
Module: :mod:`email.mime.audio`
@@ -137,12 +162,18 @@ Here are the classes:
object as necessary. The default encoding is base64. See the
:mod:`email.encoders` module for a list of the built-in encoders.
+ Optional *policy* argument defaults to :class:`compat32 <email.policy.Compat32>`.
+
*_params* are passed straight through to the base class constructor.
+ .. versionchanged:: 3.6
+ Added *policy* keyword-only parameter.
.. currentmodule:: email.mime.image
-.. class:: MIMEImage(_imagedata, _subtype=None, _encoder=email.encoders.encode_base64, **_params)
+.. class:: MIMEImage(_imagedata, _subtype=None, \
+ _encoder=email.encoders.encode_base64, \
+ *, policy=compat32, **_params)
Module: :mod:`email.mime.image`
@@ -165,13 +196,17 @@ Here are the classes:
object as necessary. The default encoding is base64. See the
:mod:`email.encoders` module for a list of the built-in encoders.
+ Optional *policy* argument defaults to :class:`compat32 <email.policy.Compat32>`.
+
*_params* are passed straight through to the :class:`~email.mime.base.MIMEBase`
constructor.
+ .. versionchanged:: 3.6
+ Added *policy* keyword-only parameter.
.. currentmodule:: email.mime.message
-.. class:: MIMEMessage(_msg, _subtype='rfc822')
+.. class:: MIMEMessage(_msg, _subtype='rfc822', *, policy=compat32)
Module: :mod:`email.mime.message`
@@ -184,10 +219,14 @@ Here are the classes:
Optional *_subtype* sets the subtype of the message; it defaults to
:mimetype:`rfc822`.
+ Optional *policy* argument defaults to :class:`compat32 <email.policy.Compat32>`.
+
+ .. versionchanged:: 3.6
+ Added *policy* keyword-only parameter.
.. currentmodule:: email.mime.text
-.. class:: MIMEText(_text, _subtype='plain', _charset=None)
+.. class:: MIMEText(_text, _subtype='plain', _charset=None, *, policy=compat32)
Module: :mod:`email.mime.text`
@@ -211,5 +250,10 @@ Here are the classes:
will automatically encode the new payload (and add a new
:mailheader:`Content-Transfer-Encoding` header).
+ Optional *policy* argument defaults to :class:`compat32 <email.policy.Compat32>`.
+
.. versionchanged:: 3.5
*_charset* also accepts :class:`~email.charset.Charset` instances.
+
+ .. versionchanged:: 3.6
+ Added *policy* keyword-only parameter.
diff --git a/Doc/library/email.parser.rst b/Doc/library/email.parser.rst
index b8eb7c5..c323ebc 100644
--- a/Doc/library/email.parser.rst
+++ b/Doc/library/email.parser.rst
@@ -8,210 +8,223 @@
--------------
-Message object structures can be created in one of two ways: they can be created
-from whole cloth by instantiating :class:`~email.message.Message` objects and
-stringing them together via :meth:`~email.message.Message.attach` and
-:meth:`~email.message.Message.set_payload` calls, or they
-can be created by parsing a flat text representation of the email message.
+Message object structures can be created in one of two ways: they can be
+created from whole cloth by creating an :class:`~email.message.EmailMessage`
+object, adding headers using the dictionary interface, and adding payload(s)
+using :meth:`~email.message.EmailMessage.set_content` and related methods, or
+they can be created by parsing a serialized representation of the email
+message.
The :mod:`email` package provides a standard parser that understands most email
-document structures, including MIME documents. You can pass the parser a string
-or a file object, and the parser will return to you the root
-:class:`~email.message.Message` instance of the object structure. For simple,
-non-MIME messages the payload of this root object will likely be a string
-containing the text of the message. For MIME messages, the root object will
-return ``True`` from its :meth:`~email.message.Message.is_multipart` method, and
-the subparts can be accessed via the :meth:`~email.message.Message.get_payload`
-and :meth:`~email.message.Message.walk` methods.
-
-There are actually two parser interfaces available for use, the classic
-:class:`Parser` API and the incremental :class:`FeedParser` API. The classic
-:class:`Parser` API is fine if you have the entire text of the message in memory
-as a string, or if the entire message lives in a file on the file system.
-:class:`FeedParser` is more appropriate for when you're reading the message from
-a stream which might block waiting for more input (e.g. reading an email message
-from a socket). The :class:`FeedParser` can consume and parse the message
-incrementally, and only returns the root object when you close the parser [#]_.
+document structures, including MIME documents. You can pass the parser a
+bytes, string or file object, and the parser will return to you the root
+:class:`~email.message.EmailMessage` instance of the object structure. For
+simple, non-MIME messages the payload of this root object will likely be a
+string containing the text of the message. For MIME messages, the root object
+will return ``True`` from its :meth:`~email.message.EmailMessage.is_multipart`
+method, and the subparts can be accessed via the payload manipulation methods,
+such as :meth:`~email.message.EmailMessage.get_body`,
+:meth:`~email.message.EmailMessage.iter_parts`, and
+:meth:`~email.message.EmailMessage.walk`.
+
+There are actually two parser interfaces available for use, the :class:`Parser`
+API and the incremental :class:`FeedParser` API. The :class:`Parser` API is
+most useful if you have the entire text of the message in memory, or if the
+entire message lives in a file on the file system. :class:`FeedParser` is more
+appropriate when you are reading the message from a stream which might block
+waiting for more input (such as reading an email message from a socket). The
+:class:`FeedParser` can consume and parse the message incrementally, and only
+returns the root object when you close the parser.
Note that the parser can be extended in limited ways, and of course you can
-implement your own parser completely from scratch. There is no magical
-connection between the :mod:`email` package's bundled parser and the
-:class:`~email.message.Message` class, so your custom parser can create message
-object trees any way it finds necessary.
+implement your own parser completely from scratch. All of the logic that
+connects the :mod:`email` package's bundled parser and the
+:class:`~email.message.EmailMessage` class is embodied in the :mod:`policy`
+class, so a custom parser can create message object trees any way it finds
+necessary by implementing custom versions of the appropriate :mod:`policy`
+methods.
FeedParser API
^^^^^^^^^^^^^^
-The :class:`FeedParser`, imported from the :mod:`email.feedparser` module,
-provides an API that is conducive to incremental parsing of email messages, such
-as would be necessary when reading the text of an email message from a source
-that can block (e.g. a socket). The :class:`FeedParser` can of course be used
-to parse an email message fully contained in a string or a file, but the classic
-:class:`Parser` API may be more convenient for such use cases. The semantics
-and results of the two parser APIs are identical.
-
-The :class:`FeedParser`'s API is simple; you create an instance, feed it a bunch
-of text until there's no more to feed it, then close the parser to retrieve the
-root message object. The :class:`FeedParser` is extremely accurate when parsing
-standards-compliant messages, and it does a very good job of parsing
-non-compliant messages, providing information about how a message was deemed
-broken. It will populate a message object's *defects* attribute with a list of
-any problems it found in a message. See the :mod:`email.errors` module for the
+The :class:`BytesFeedParser`, imported from the :mod:`email.feedparser` module,
+provides an API that is conducive to incremental parsing of email messages,
+such as would be necessary when reading the text of an email message from a
+source that can block (such as a socket). The :class:`BytesFeedParser` can of
+course be used to parse an email message fully contained in a :term:`bytes-like
+object`, string, or file, but the :class:`BytesParser` API may be more
+convenient for such use cases. The semantics and results of the two parser
+APIs are identical.
+
+The :class:`BytesFeedParser`'s API is simple; you create an instance, feed it a
+bunch of bytes until there's no more to feed it, then close the parser to
+retrieve the root message object. The :class:`BytesFeedParser` is extremely
+accurate when parsing standards-compliant messages, and it does a very good job
+of parsing non-compliant messages, providing information about how a message
+was deemed broken. It will populate a message object's
+:attr:`~email.message.EmailMessage.defects` attribute with a list of any
+problems it found in a message. See the :mod:`email.errors` module for the
list of defects that it can find.
-Here is the API for the :class:`FeedParser`:
+Here is the API for the :class:`BytesFeedParser`:
-.. class:: FeedParser(_factory=email.message.Message, *, policy=policy.compat32)
+.. class:: BytesFeedParser(_factory=None, *, policy=policy.compat32)
- Create a :class:`FeedParser` instance. Optional *_factory* is a no-argument
- callable that will be called whenever a new message object is needed. It
- defaults to the :class:`email.message.Message` class.
+ Create a :class:`BytesFeedParser` instance. Optional *_factory* is a
+ no-argument callable; if not specified use the
+ :attr:`~email.policy.Policy.message_factory` from the *policy*. Call
+ *_factory* whenever a new message object is needed.
- If *policy* is specified (it must be an instance of a :mod:`~email.policy`
- class) use the rules it specifies to update the representation of the
- message. If *policy* is not set, use the :class:`compat32
- <email.policy.Compat32>` policy, which maintains backward compatibility with
- the Python 3.2 version of the email package. For more information see the
+ If *policy* is specified use the rules it specifies to update the
+ representation of the message. If *policy* is not set, use the
+ :class:`compat32 <email.policy.Compat32>` policy, which maintains backward
+ compatibility with the Python 3.2 version of the email package and provides
+ :class:`~email.message.Message` as the default factory. All other policies
+ provide :class:`~email.message.EmailMessage` as the default *_factory*. For
+ more information on what else *policy* controls, see the
:mod:`~email.policy` documentation.
+ Note: **The policy keyword should always be specified**; The default will
+ change to :data:`email.policy.default` in a future version of Python.
+
+ .. versionadded:: 3.2
+
.. versionchanged:: 3.3 Added the *policy* keyword.
+ .. versionchanged:: 3.6 *_factory* defaults to the policy ``message_factory``.
+
.. method:: feed(data)
- Feed the :class:`FeedParser` some more data. *data* should be a string
- containing one or more lines. The lines can be partial and the
- :class:`FeedParser` will stitch such partial lines together properly. The
- lines in the string can have any of the common three line endings,
- carriage return, newline, or carriage return and newline (they can even be
- mixed).
+ Feed the parser some more data. *data* should be a :term:`bytes-like
+ object` containing one or more lines. The lines can be partial and the
+ parser will stitch such partial lines together properly. The lines can
+ have any of the three common line endings: carriage return, newline, or
+ carriage return and newline (they can even be mixed).
+
.. method:: close()
- Closing a :class:`FeedParser` completes the parsing of all previously fed
- data, and returns the root message object. It is undefined what happens
- if you feed more data to a closed :class:`FeedParser`.
+ Complete the parsing of all previously fed data and return the root
+ message object. It is undefined what happens if :meth:`~feed` is called
+ after this method has been called.
-.. class:: BytesFeedParser(_factory=email.message.Message)
+.. class:: FeedParser(_factory=None, *, policy=policy.compat32)
- Works exactly like :class:`FeedParser` except that the input to the
- :meth:`~FeedParser.feed` method must be bytes and not string.
+ Works like :class:`BytesFeedParser` except that the input to the
+ :meth:`~BytesFeedParser.feed` method must be a string. This is of limited
+ utility, since the only way for such a message to be valid is for it to
+ contain only ASCII text or, if :attr:`~email.policy.Policy.utf8` is
+ ``True``, no binary attachments.
- .. versionadded:: 3.2
+ .. versionchanged:: 3.3 Added the *policy* keyword.
-Parser class API
-^^^^^^^^^^^^^^^^
+Parser API
+^^^^^^^^^^
-The :class:`Parser` class, imported from the :mod:`email.parser` module,
+The :class:`BytesParser` class, imported from the :mod:`email.parser` module,
provides an API that can be used to parse a message when the complete contents
-of the message are available in a string or file. The :mod:`email.parser`
-module also provides header-only parsers, called :class:`HeaderParser` and
-:class:`BytesHeaderParser`, which can be used if you're only interested in the
-headers of the message. :class:`HeaderParser` and :class:`BytesHeaderParser`
+of the message are available in a :term:`bytes-like object` or file. The
+:mod:`email.parser` module also provides :class:`Parser` for parsing strings,
+and header-only parsers, :class:`BytesHeaderParser` and
+:class:`HeaderParser`, which can be used if you're only interested in the
+headers of the message. :class:`BytesHeaderParser` and :class:`HeaderParser`
can be much faster in these situations, since they do not attempt to parse the
-message body, instead setting the payload to the raw body as a string. They
-have the same API as the :class:`Parser` and :class:`BytesParser` classes.
+message body, instead setting the payload to the raw body.
-.. versionadded:: 3.3
- The BytesHeaderParser class.
+.. class:: BytesParser(_class=None, *, policy=policy.compat32)
-.. class:: Parser(_class=email.message.Message, *, policy=policy.compat32)
+ Create a :class:`BytesParser` instance. The *_class* and *policy*
+ arguments have the same meaning and sematnics as the *_factory*
+ and *policy* arguments of :class:`BytesFeedParser`.
- The constructor for the :class:`Parser` class takes an optional argument
- *_class*. This must be a callable factory (such as a function or a class), and
- it is used whenever a sub-message object needs to be created. It defaults to
- :class:`~email.message.Message` (see :mod:`email.message`). The factory will
- be called without arguments.
-
- If *policy* is specified (it must be an instance of a :mod:`~email.policy`
- class) use the rules it specifies to update the representation of the
- message. If *policy* is not set, use the :class:`compat32
- <email.policy.Compat32>` policy, which maintains backward compatibility with
- the Python 3.2 version of the email package. For more information see the
- :mod:`~email.policy` documentation.
+ Note: **The policy keyword should always be specified**; The default will
+ change to :data:`email.policy.default` in a future version of Python.
.. versionchanged:: 3.3
Removed the *strict* argument that was deprecated in 2.4. Added the
*policy* keyword.
-
- The other public :class:`Parser` methods are:
+ .. versionchanged:: 3.6 *_class* defaults to the policy ``message_factory``.
.. method:: parse(fp, headersonly=False)
- Read all the data from the file-like object *fp*, parse the resulting
- text, and return the root message object. *fp* must support both the
- :meth:`~io.TextIOBase.readline` and the :meth:`~io.TextIOBase.read`
- methods on file-like objects.
+ Read all the data from the binary file-like object *fp*, parse the
+ resulting bytes, and return the message object. *fp* must support
+ both the :meth:`~io.IOBase.readline` and the :meth:`~io.IOBase.read`
+ methods.
- The text contained in *fp* must be formatted as a block of :rfc:`2822`
+ The bytes contained in *fp* must be formatted as a block of :rfc:`5322`
+ (or, if :attr:`~email.policy.Policy.utf8` is ``True``, :rfc:`6532`)
style headers and header continuation lines, optionally preceded by an
envelope header. The header block is terminated either by the end of the
data or by a blank line. Following the header block is the body of the
- message (which may contain MIME-encoded subparts).
+ message (which may contain MIME-encoded subparts, including subparts
+ with a :mailheader:`Content-Transfer-Encoding` of ``8bit``.
Optional *headersonly* is a flag specifying whether to stop parsing after
reading the headers or not. The default is ``False``, meaning it parses
the entire contents of the file.
- .. method:: parsestr(text, headersonly=False)
- Similar to the :meth:`parse` method, except it takes a string object
- instead of a file-like object. Calling this method on a string is exactly
- equivalent to wrapping *text* in a :class:`~io.StringIO` instance first and
- calling :meth:`parse`.
+ .. method:: parsebytes(bytes, headersonly=False)
+
+ Similar to the :meth:`parse` method, except it takes a :term:`bytes-like
+ object` instead of a file-like object. Calling this method on a
+ :term:`bytes-like object` is equivalent to wrapping *bytes* in a
+ :class:`~io.BytesIO` instance first and calling :meth:`parse`.
Optional *headersonly* is as with the :meth:`parse` method.
+ .. versionadded:: 3.2
-.. class:: BytesParser(_class=email.message.Message, *, policy=policy.compat32)
- This class is exactly parallel to :class:`Parser`, but handles bytes input.
- The *_class* and *strict* arguments are interpreted in the same way as for
- the :class:`Parser` constructor.
+.. class:: BytesHeaderParser(_class=None, *, policy=policy.compat32)
- If *policy* is specified (it must be an instance of a :mod:`~email.policy`
- class) use the rules it specifies to update the representation of the
- message. If *policy* is not set, use the :class:`compat32
- <email.policy.Compat32>` policy, which maintains backward compatibility with
- the Python 3.2 version of the email package. For more information see the
- :mod:`~email.policy` documentation.
+ Exactly like :class:`BytesParser`, except that *headersonly*
+ defaults to ``True``.
+
+ .. versionadded:: 3.3
+
+
+.. class:: Parser(_class=None, *, policy=policy.compat32)
+
+ This class is parallel to :class:`BytesParser`, but handles string input.
.. versionchanged:: 3.3
Removed the *strict* argument. Added the *policy* keyword.
+ .. versionchanged:: 3.6 *_class* defaults to the policy ``message_factory``.
+
.. method:: parse(fp, headersonly=False)
- Read all the data from the binary file-like object *fp*, parse the
- resulting bytes, and return the message object. *fp* must support
- both the :meth:`~io.IOBase.readline` and the :meth:`~io.IOBase.read`
- methods on file-like objects.
+ Read all the data from the text-mode file-like object *fp*, parse the
+ resulting text, and return the root message object. *fp* must support
+ both the :meth:`~io.TextIOBase.readline` and the
+ :meth:`~io.TextIOBase.read` methods on file-like objects.
- The bytes contained in *fp* must be formatted as a block of :rfc:`2822`
- style headers and header continuation lines, optionally preceded by an
- envelope header. The header block is terminated either by the end of the
- data or by a blank line. Following the header block is the body of the
- message (which may contain MIME-encoded subparts, including subparts
- with a :mailheader:`Content-Transfer-Encoding` of ``8bit``.
+ Other than the text mode requirement, this method operates like
+ :meth:`BytesParser.parse`.
- Optional *headersonly* is a flag specifying whether to stop parsing after
- reading the headers or not. The default is ``False``, meaning it parses
- the entire contents of the file.
- .. method:: parsebytes(text, headersonly=False)
+ .. method:: parsestr(text, headersonly=False)
- Similar to the :meth:`parse` method, except it takes a :term:`bytes-like
- object` instead of a file-like object. Calling this method is equivalent
- to wrapping *text* in a :class:`~io.BytesIO` instance first and calling
- :meth:`parse`.
+ Similar to the :meth:`parse` method, except it takes a string object
+ instead of a file-like object. Calling this method on a string is
+ equivalent to wrapping *text* in a :class:`~io.StringIO` instance first
+ and calling :meth:`parse`.
Optional *headersonly* is as with the :meth:`parse` method.
- .. versionadded:: 3.2
+
+.. class:: HeaderParser(_class=None, *, policy=policy.compat32)
+
+ Exactly like :class:`Parser`, except that *headersonly*
+ defaults to ``True``.
Since creating a message object structure from a string or a file object is such
@@ -220,55 +233,58 @@ in the top-level :mod:`email` package namespace.
.. currentmodule:: email
-.. function:: message_from_string(s, _class=email.message.Message, *, \
- policy=policy.compat32)
- Return a message object structure from a string. This is exactly equivalent to
- ``Parser().parsestr(s)``. *_class* and *policy* are interpreted as
- with the :class:`~email.parser.Parser` class constructor.
+.. function:: message_from_bytes(s, _class=None, *, policy=policy.compat32)
+
+ Return a message object structure from a :term:`bytes-like object`. This is
+ equivalent to ``BytesParser().parsebytes(s)``. Optional *_class* and
+ *strict* are interpreted as with the :class:`~email.parser.BytesParser` class
+ constructor.
+ .. versionadded:: 3.2
.. versionchanged:: 3.3
Removed the *strict* argument. Added the *policy* keyword.
-.. function:: message_from_bytes(s, _class=email.message.Message, *, \
- policy=policy.compat32)
- Return a message object structure from a :term:`bytes-like object`. This is exactly
- equivalent to ``BytesParser().parsebytes(s)``. Optional *_class* and
- *strict* are interpreted as with the :class:`~email.parser.Parser` class
+.. function:: message_from_binary_file(fp, _class=None, *,
+ policy=policy.compat32)
+
+ Return a message object structure tree from an open binary :term:`file
+ object`. This is equivalent to ``BytesParser().parse(fp)``. *_class* and
+ *policy* are interpreted as with the :class:`~email.parser.BytesParser` class
constructor.
.. versionadded:: 3.2
.. versionchanged:: 3.3
Removed the *strict* argument. Added the *policy* keyword.
-.. function:: message_from_file(fp, _class=email.message.Message, *, \
- policy=policy.compat32)
- Return a message object structure tree from an open :term:`file object`.
- This is exactly equivalent to ``Parser().parse(fp)``. *_class*
- and *policy* are interpreted as with the :class:`~email.parser.Parser` class
- constructor.
+.. function:: message_from_string(s, _class=None, *, policy=policy.compat32)
+
+ Return a message object structure from a string. This is equivalent to
+ ``Parser().parsestr(s)``. *_class* and *policy* are interpreted as
+ with the :class:`~email.parser.Parser` class constructor.
.. versionchanged:: 3.3
Removed the *strict* argument. Added the *policy* keyword.
-.. function:: message_from_binary_file(fp, _class=email.message.Message, *, \
- policy=policy.compat32)
- Return a message object structure tree from an open binary :term:`file
- object`. This is exactly equivalent to ``BytesParser().parse(fp)``.
- *_class* and *policy* are interpreted as with the
- :class:`~email.parser.Parser` class constructor.
+.. function:: message_from_file(fp, _class=None, *, policy=policy.compat32)
+
+ Return a message object structure tree from an open :term:`file object`.
+ This is equivalent to ``Parser().parse(fp)``. *_class* and *policy* are
+ interpreted as with the :class:`~email.parser.Parser` class constructor.
- .. versionadded:: 3.2
.. versionchanged:: 3.3
Removed the *strict* argument. Added the *policy* keyword.
+ .. versionchanged:: 3.6 *_class* defaults to the policy ``message_factory``.
-Here's an example of how you might use this at an interactive Python prompt::
+
+Here's an example of how you might use :func:`message_from_bytes` at an
+interactive Python prompt::
>>> import email
- >>> msg = email.message_from_string(myString) # doctest: +SKIP
+ >>> msg = email.message_from_bytes(myBytes) # doctest: +SKIP
Additional notes
@@ -278,35 +294,27 @@ Here are some notes on the parsing semantics:
* Most non-\ :mimetype:`multipart` type messages are parsed as a single message
object with a string payload. These objects will return ``False`` for
- :meth:`~email.message.Message.is_multipart`. Their
- :meth:`~email.message.Message.get_payload` method will return a string object.
+ :meth:`~email.message.EmailMessage.is_multipart`, and
+ :meth:`~email.message.EmailMessage.iter_parts` will yield an empty list.
* All :mimetype:`multipart` type messages will be parsed as a container message
object with a list of sub-message objects for their payload. The outer
container message will return ``True`` for
- :meth:`~email.message.Message.is_multipart` and their
- :meth:`~email.message.Message.get_payload` method will return the list of
- :class:`~email.message.Message` subparts.
+ :meth:`~email.message.EmailMessage.is_multipart`, and
+ :meth:`~email.message.EmailMessage.iter_parts` will yield a list of subparts.
-* Most messages with a content type of :mimetype:`message/\*` (e.g.
- :mimetype:`message/delivery-status` and :mimetype:`message/rfc822`) will also be
- parsed as container object containing a list payload of length 1. Their
- :meth:`~email.message.Message.is_multipart` method will return ``True``.
- The single element in the list payload will be a sub-message object.
+* Most messages with a content type of :mimetype:`message/\*` (such as
+ :mimetype:`message/delivery-status` and :mimetype:`message/rfc822`) will also
+ be parsed as container object containing a list payload of length 1. Their
+ :meth:`~email.message.EmailMessage.is_multipart` method will return ``True``.
+ The single element yielded by :meth:`~email.message.EmailMessage.iter_parts`
+ will be a sub-message object.
-* Some non-standards compliant messages may not be internally consistent about
+* Some non-standards-compliant messages may not be internally consistent about
their :mimetype:`multipart`\ -edness. Such messages may have a
:mailheader:`Content-Type` header of type :mimetype:`multipart`, but their
- :meth:`~email.message.Message.is_multipart` method may return ``False``.
+ :meth:`~email.message.EmailMessage.is_multipart` method may return ``False``.
If such messages were parsed with the :class:`~email.parser.FeedParser`,
they will have an instance of the
:class:`~email.errors.MultipartInvariantViolationDefect` class in their
*defects* attribute list. See :mod:`email.errors` for details.
-
-.. rubric:: Footnotes
-
-.. [#] As of email package version 3.0, introduced in Python 2.4, the classic
- :class:`~email.parser.Parser` was re-implemented in terms of the
- :class:`~email.parser.FeedParser`, so the semantics and results are
- identical between the two parsers.
-
diff --git a/Doc/library/email.policy.rst b/Doc/library/email.policy.rst
index 2a6047d..8a41877 100644
--- a/Doc/library/email.policy.rst
+++ b/Doc/library/email.policy.rst
@@ -18,9 +18,12 @@ described by the various email and MIME RFCs. However, the general format of
email messages (a block of header fields each consisting of a name followed by
a colon followed by a value, the whole block followed by a blank line and an
arbitrary 'body'), is a format that has found utility outside of the realm of
-email. Some of these uses conform fairly closely to the main RFCs, some do
-not. And even when working with email, there are times when it is desirable to
-break strict compliance with the RFCs.
+email. Some of these uses conform fairly closely to the main email RFCs, some
+do not. Even when working with email, there are times when it is desirable to
+break strict compliance with the RFCs, such as generating emails that
+interoperate with email servers that do not themselves follow the standards, or
+that implement extensions you want to use in ways that violate the
+standards.
Policy objects give the email package the flexibility to handle all these
disparate use cases.
@@ -31,27 +34,40 @@ control the behavior of various components of the email package during use.
email package to alter the default behavior. The settable values and their
defaults are described below.
-There is a default policy used by all classes in the email package. This
-policy is named :class:`Compat32`, with a corresponding pre-defined instance
-named :const:`compat32`. It provides for complete backward compatibility (in
-some cases, including bug compatibility) with the pre-Python3.3 version of the
-email package.
+There is a default policy used by all classes in the email package. For all of
+the :mod:`~email.parser` classes and the related convenience functions, and for
+the :class:`~email.message.Message` class, this is the :class:`Compat32`
+policy, via its corresponding pre-defined instance :const:`compat32`. This
+policy provides for complete backward compatibility (in some cases, including
+bug compatibility) with the pre-Python3.3 version of the email package.
+
+This default value for the *policy* keyword to
+:class:`~email.message.EmailMessage` is the :class:`EmailPolicy` policy, via
+its pre-defined instance :data:`~default`.
+
+When a :class:`~email.message.Message` or :class:`~email.message.EmailMessage`
+object is created, it acquires a policy. If the message is created by a
+:mod:`~email.parser`, a policy passed to the parser will be the policy used by
+the message it creates. If the message is created by the program, then the
+policy can be specified when it is created. When a message is passed to a
+:mod:`~email.generator`, the generator uses the policy from the message by
+default, but you can also pass a specific policy to the generator that will
+override the one stored on the message object.
+
+The default value for the *policy* keyword for the :mod:`email.parser` classes
+and the parser convenience functions **will be changing** in a future version of
+Python. Therefore you should **always specify explicitly which policy you want
+to use** when calling any of the classes and functions described in the
+:mod:`~email.parser` module.
The first part of this documentation covers the features of :class:`Policy`, an
-:term:`abstract base class` that defines the features that are common to all
+:term:`abstract base class` that defines the features that are common to all
policy objects, including :const:`compat32`. This includes certain hook
methods that are called internally by the email package, which a custom policy
-could override to obtain different behavior.
-
-When a :class:`~email.message.Message` object is created, it acquires a policy.
-By default this will be :const:`compat32`, but a different policy can be
-specified. If the ``Message`` is created by a :mod:`~email.parser`, a policy
-passed to the parser will be the policy used by the ``Message`` it creates. If
-the ``Message`` is created by the program, then the policy can be specified
-when it is created. When a ``Message`` is passed to a :mod:`~email.generator`,
-the generator uses the policy from the ``Message`` by default, but you can also
-pass a specific policy to the generator that will override the one stored on
-the ``Message`` object.
+could override to obtain different behavior. The second part describes the
+concrete classes :class:`EmailPolicy` and :class:`Compat32`, which implement
+the hooks that provide the standard behavior and the backward compatible
+behavior and features, respectively.
:class:`Policy` instances are immutable, but they can be cloned, accepting the
same keyword arguments as the class constructor and returning a new
@@ -147,6 +163,7 @@ added matters. To illustrate::
This class defines the following properties, and thus values for the
following may be passed in the constructor of any policy class:
+
.. attribute:: max_line_length
The maximum length of any line in the serialized output, not counting the
@@ -154,12 +171,14 @@ added matters. To illustrate::
``0`` or :const:`None` indicates that no line wrapping should be
done at all.
+
.. attribute:: linesep
The string to be used to terminate lines in serialized output. The
default is ``\n`` because that's the internal end-of-line discipline used
by Python, though ``\r\n`` is required by the RFCs.
+
.. attribute:: cte_type
Controls the type of Content Transfer Encodings that may be or are
@@ -174,8 +193,8 @@ added matters. To illustrate::
``8bit`` data is not constrained to be 7 bit clean. Data in headers is
still required to be ASCII-only and so will be encoded (see
- 'binary_fold' below for an exception), but body parts may use
- the ``8bit`` CTE.
+ :meth:`fold_binary` and :attr:`~EmailPolicy.utf8` below for
+ exceptions), but body parts may use the ``8bit`` CTE.
======== ===============================================================
A ``cte_type`` value of ``8bit`` only works with ``BytesGenerator``, not
@@ -183,6 +202,7 @@ added matters. To illustrate::
``Generator`` is operating under a policy that specifies
``cte_type=8bit``, it will act as if ``cte_type`` is ``7bit``.
+
.. attribute:: raise_on_defect
If :const:`True`, any defects encountered will be raised as errors. If
@@ -190,7 +210,6 @@ added matters. To illustrate::
:meth:`register_defect` method.
-
.. attribute:: mangle_from\_
If :const:`True`, lines starting with *"From "* in the body are
@@ -201,19 +220,31 @@ added matters. To illustrate::
.. versionadded:: 3.5
The *mangle_from_* parameter.
+
+ .. attribute:: message_factory
+
+ A factory function for constructing a new empty message object. Used
+ by the parser when building messages. Defaults to ``None``, in
+ which case :class:`~email.message.Message` is used.
+
+ .. versionadded:: 3.6
+
The following :class:`Policy` method is intended to be called by code using
the email library to create policy instances with custom settings:
+
.. method:: clone(**kw)
Return a new :class:`Policy` instance whose attributes have the same
values as the current instance, except where those attributes are
given new values by the keyword arguments.
+
The remaining :class:`Policy` methods are called by the email package code,
and are not intended to be called by an application using the email package.
A custom policy must implement all of these methods.
+
.. method:: handle_defect(obj, defect)
Handle a *defect* found on *obj*. When the email package calls this
@@ -224,6 +255,7 @@ added matters. To illustrate::
it is ``True``, *defect* is raised as an exception. If it is ``False``
(the default), *obj* and *defect* are passed to :meth:`register_defect`.
+
.. method:: register_defect(obj, defect)
Register a *defect* on *obj*. In the email package, *defect* will always
@@ -236,14 +268,16 @@ added matters. To illustrate::
custom ``Message`` objects) should also provide such an attribute,
otherwise defects in parsed messages will raise unexpected errors.
+
.. method:: header_max_count(name)
Return the maximum allowed number of headers named *name*.
- Called when a header is added to a :class:`~email.message.Message`
- object. If the returned value is not ``0`` or ``None``, and there are
- already a number of headers with the name *name* equal to the value
- returned, a :exc:`ValueError` is raised.
+ Called when a header is added to an :class:`~email.message.EmailMessage`
+ or :class:`~email.message.Message` object. If the returned value is not
+ ``0`` or ``None``, and there are already a number of headers with the
+ name *name* greather than or equal to the value returned, a
+ :exc:`ValueError` is raised.
Because the default behavior of ``Message.__setitem__`` is to append the
value to the list of headers, it is easy to create duplicate headers
@@ -255,6 +289,7 @@ added matters. To illustrate::
The default implementation returns ``None`` for all header names.
+
.. method:: header_source_parse(sourcelines)
The email package calls this method with a list of strings, each string
@@ -274,6 +309,7 @@ added matters. To illustrate::
There is no default implementation
+
.. method:: header_store_parse(name, value)
The email package calls this method with the name and value provided by
@@ -289,6 +325,7 @@ added matters. To illustrate::
There is no default implementation
+
.. method:: header_fetch_parse(name, value)
The email package calls this method with the *name* and *value* currently
@@ -304,6 +341,7 @@ added matters. To illustrate::
There is no default implementation
+
.. method:: fold(name, value)
The email package calls this method with the *name* and *value* currently
@@ -316,6 +354,7 @@ added matters. To illustrate::
*value* may contain surrogateescaped binary data. There should be no
surrogateescaped binary data in the string returned by the method.
+
.. method:: fold_binary(name, value)
The same as :meth:`fold`, except that the returned value should be a
@@ -325,73 +364,6 @@ added matters. To illustrate::
converted back into binary data in the returned bytes object.
-.. class:: Compat32(**kw)
-
- This concrete :class:`Policy` is the backward compatibility policy. It
- replicates the behavior of the email package in Python 3.2. The
- :mod:`~email.policy` module also defines an instance of this class,
- :const:`compat32`, that is used as the default policy. Thus the default
- behavior of the email package is to maintain compatibility with Python 3.2.
-
- The following attributes have values that are different from the
- :class:`Policy` default:
-
- .. attribute:: mangle_from_
-
- The default is ``True``.
-
- The class provides the following concrete implementations of the
- abstract methods of :class:`Policy`:
-
- .. method:: header_source_parse(sourcelines)
-
- The name is parsed as everything up to the '``:``' and returned
- unmodified. The value is determined by stripping leading whitespace off
- the remainder of the first line, joining all subsequent lines together,
- and stripping any trailing carriage return or linefeed characters.
-
- .. method:: header_store_parse(name, value)
-
- The name and value are returned unmodified.
-
- .. method:: header_fetch_parse(name, value)
-
- If the value contains binary data, it is converted into a
- :class:`~email.header.Header` object using the ``unknown-8bit`` charset.
- Otherwise it is returned unmodified.
-
- .. method:: fold(name, value)
-
- Headers are folded using the :class:`~email.header.Header` folding
- algorithm, which preserves existing line breaks in the value, and wraps
- each resulting line to the ``max_line_length``. Non-ASCII binary data are
- CTE encoded using the ``unknown-8bit`` charset.
-
- .. method:: fold_binary(name, value)
-
- Headers are folded using the :class:`~email.header.Header` folding
- algorithm, which preserves existing line breaks in the value, and wraps
- each resulting line to the ``max_line_length``. If ``cte_type`` is
- ``7bit``, non-ascii binary data is CTE encoded using the ``unknown-8bit``
- charset. Otherwise the original source header is used, with its existing
- line breaks and any (RFC invalid) binary data it may contain.
-
-
-An instance of :class:`Compat32` is provided as a module constant:
-
-.. data:: compat32
-
- An instance of :class:`Compat32`, providing backward compatibility with the
- behavior of the email package in Python 3.2.
-
-
-.. note::
-
- The documentation below describes new policies that are included in the
- standard library on a :term:`provisional basis <provisional package>`.
- Backwards incompatible changes (up to and including removal of the feature)
- may occur if deemed necessary by the core developers.
-
.. class:: EmailPolicy(**kw)
@@ -404,9 +376,15 @@ An instance of :class:`Compat32` is provided as a module constant:
on the type of the field. The parsing and folding algorithm fully implement
:rfc:`2047` and :rfc:`5322`.
+ The default value for the :attr:`~email.policy.Policy.message_factory`
+ attribute is :class:`~email.message.EmailMessage`.
+
In addition to the settable attributes listed above that apply to all
policies, this policy adds the following additional attributes:
+ .. versionadded:: 3.6 [1]_
+
+
.. attribute:: utf8
If ``False``, follow :rfc:`5322`, supporting non-ASCII characters in
@@ -415,13 +393,14 @@ An instance of :class:`Compat32` is provided as a module constant:
formatted in this way may be passed to SMTP servers that support
the ``SMTPUTF8`` extension (:rfc:`6531`).
+
.. attribute:: refold_source
If the value for a header in the ``Message`` object originated from a
:mod:`~email.parser` (as opposed to being set by a program), this
attribute indicates whether or not a generator should refold that value
- when transforming the message back into stream form. The possible values
- are:
+ when transforming the message back into serialized form. The possible
+ values are:
======== ===============================================================
``none`` all source values use original folding
@@ -434,23 +413,24 @@ An instance of :class:`Compat32` is provided as a module constant:
The default is ``long``.
+
.. attribute:: header_factory
A callable that takes two arguments, ``name`` and ``value``, where
``name`` is a header field name and ``value`` is an unfolded header field
value, and returns a string subclass that represents that header. A
default ``header_factory`` (see :mod:`~email.headerregistry`) is provided
- that understands some of the :RFC:`5322` header field types. (Currently
- address fields and date fields have special treatment, while all other
- fields are treated as unstructured. This list will be completed before
- the extension is marked stable.)
+ that supports custom parsing for the various address and date :RFC:`5322`
+ header field types, and the major MIME header field stypes. Support for
+ additional custom parsing will be added in the future.
+
.. attribute:: content_manager
An object with at least two methods: get_content and set_content. When
- the :meth:`~email.message.Message.get_content` or
- :meth:`~email.message.Message.set_content` method of a
- :class:`~email.message.Message` object is called, it calls the
+ the :meth:`~email.message.EmailMessage.get_content` or
+ :meth:`~email.message.EmailMessage.set_content` method of an
+ :class:`~email.message.EmailMessage` object is called, it calls the
corresponding method of this object, passing it the message object as its
first argument, and any arguments or keywords that were passed to it as
additional arguments. By default ``content_manager`` is set to
@@ -462,16 +442,22 @@ An instance of :class:`Compat32` is provided as a module constant:
The class provides the following concrete implementations of the abstract
methods of :class:`Policy`:
+
.. method:: header_max_count(name)
Returns the value of the
:attr:`~email.headerregistry.BaseHeader.max_count` attribute of the
specialized class used to represent the header with the given name.
+
.. method:: header_source_parse(sourcelines)
- The implementation of this method is the same as that for the
- :class:`Compat32` policy.
+
+ The name is parsed as everything up to the '``:``' and returned
+ unmodified. The value is determined by stripping leading whitespace off
+ the remainder of the first line, joining all subsequent lines together,
+ and stripping any trailing carriage return or linefeed characters.
+
.. method:: header_store_parse(name, value)
@@ -482,6 +468,7 @@ An instance of :class:`Compat32` is provided as a module constant:
the value. In this case a ``ValueError`` is raised if the input value
contains CR or LF characters.
+
.. method:: header_fetch_parse(name, value)
If the value has a ``name`` attribute, it is returned to unmodified.
@@ -490,6 +477,7 @@ An instance of :class:`Compat32` is provided as a module constant:
header object is returned. Any surrogateescaped bytes get turned into
the unicode unknown-character glyph.
+
.. method:: fold(name, value)
Header folding is controlled by the :attr:`refold_source` policy setting.
@@ -508,6 +496,7 @@ An instance of :class:`Compat32` is provided as a module constant:
regardless of the ``refold_source`` setting, which causes the binary data
to be CTE encoded using the ``unknown-8bit`` charset.
+
.. method:: fold_binary(name, value)
The same as :meth:`fold` if :attr:`~Policy.cte_type` is ``7bit``, except
@@ -519,23 +508,27 @@ An instance of :class:`Compat32` is provided as a module constant:
``refold_header`` setting, since there is no way to know whether the
binary data consists of single byte characters or multibyte characters.
+
The following instances of :class:`EmailPolicy` provide defaults suitable for
specific application domains. Note that in the future the behavior of these
instances (in particular the ``HTTP`` instance) may be adjusted to conform even
more closely to the RFCs relevant to their domains.
+
.. data:: default
An instance of ``EmailPolicy`` with all defaults unchanged. This policy
uses the standard Python ``\n`` line endings rather than the RFC-correct
``\r\n``.
+
.. data:: SMTP
Suitable for serializing messages in conformance with the email RFCs.
Like ``default``, but with ``linesep`` set to ``\r\n``, which is RFC
compliant.
+
.. data:: SMTPUTF8
The same as ``SMTP`` except that :attr:`~EmailPolicy.utf8` is ``True``.
@@ -544,11 +537,13 @@ more closely to the RFCs relevant to their domains.
sender or recipient addresses have non-ASCII characters (the
:meth:`smtplib.SMTP.send_message` method handles this automatically).
+
.. data:: HTTP
Suitable for serializing headers with for use in HTTP traffic. Like
``SMTP`` except that ``max_line_length`` is set to ``None`` (unlimited).
+
.. data:: strict
Convenience instance. The same as ``default`` except that
@@ -557,6 +552,7 @@ more closely to the RFCs relevant to their domains.
somepolicy + policy.strict
+
With all of these :class:`EmailPolicies <.EmailPolicy>`, the effective API of
the email package is changed from the Python 3.2 API in the following ways:
@@ -573,7 +569,7 @@ the email package is changed from the Python 3.2 API in the following ways:
and allowed.
From the application view, this means that any header obtained through the
-:class:`~email.message.Message` is a header object with extra
+:class:`~email.message.EmailMessage` is a header object with extra
attributes, whose string value is the fully decoded unicode value of the
header. Likewise, a header may be assigned a new value, or a new header
created, using a unicode string, and the policy will take care of converting
@@ -581,3 +577,75 @@ the unicode string into the correct RFC encoded form.
The header objects and their attributes are described in
:mod:`~email.headerregistry`.
+
+
+
+.. class:: Compat32(**kw)
+
+ This concrete :class:`Policy` is the backward compatibility policy. It
+ replicates the behavior of the email package in Python 3.2. The
+ :mod:`~email.policy` module also defines an instance of this class,
+ :const:`compat32`, that is used as the default policy. Thus the default
+ behavior of the email package is to maintain compatibility with Python 3.2.
+
+ The following attributes have values that are different from the
+ :class:`Policy` default:
+
+
+ .. attribute:: mangle_from_
+
+ The default is ``True``.
+
+
+ The class provides the following concrete implementations of the
+ abstract methods of :class:`Policy`:
+
+
+ .. method:: header_source_parse(sourcelines)
+
+ The name is parsed as everything up to the '``:``' and returned
+ unmodified. The value is determined by stripping leading whitespace off
+ the remainder of the first line, joining all subsequent lines together,
+ and stripping any trailing carriage return or linefeed characters.
+
+
+ .. method:: header_store_parse(name, value)
+
+ The name and value are returned unmodified.
+
+
+ .. method:: header_fetch_parse(name, value)
+
+ If the value contains binary data, it is converted into a
+ :class:`~email.header.Header` object using the ``unknown-8bit`` charset.
+ Otherwise it is returned unmodified.
+
+
+ .. method:: fold(name, value)
+
+ Headers are folded using the :class:`~email.header.Header` folding
+ algorithm, which preserves existing line breaks in the value, and wraps
+ each resulting line to the ``max_line_length``. Non-ASCII binary data are
+ CTE encoded using the ``unknown-8bit`` charset.
+
+
+ .. method:: fold_binary(name, value)
+
+ Headers are folded using the :class:`~email.header.Header` folding
+ algorithm, which preserves existing line breaks in the value, and wraps
+ each resulting line to the ``max_line_length``. If ``cte_type`` is
+ ``7bit``, non-ascii binary data is CTE encoded using the ``unknown-8bit``
+ charset. Otherwise the original source header is used, with its existing
+ line breaks and any (RFC invalid) binary data it may contain.
+
+
+.. data:: compat32
+
+ An instance of :class:`Compat32`, providing backward compatibility with the
+ behavior of the email package in Python 3.2.
+
+
+.. rubric:: Footnotes
+
+.. [1] Oringally added in 3.3 as a :term:`provisional feature <provisional
+ package>`.
diff --git a/Doc/library/email.rst b/Doc/library/email.rst
index e8bb02b..c4187dd 100644
--- a/Doc/library/email.rst
+++ b/Doc/library/email.rst
@@ -3,50 +3,104 @@
.. module:: email
:synopsis: Package supporting the parsing, manipulating, and generating
- email messages, including MIME documents.
-
-.. moduleauthor:: Barry A. Warsaw <barry@python.org>
-.. sectionauthor:: Barry A. Warsaw <barry@python.org>
-.. Copyright (C) 2001-2010 Python Software Foundation
+ email messages.
+.. moduleauthor:: Barry A. Warsaw <barry@python.org>,
+ R. David Murray <rdmurray@bitdance.com>
+.. sectionauthor:: R. David Murray <rdmurray@bitdance.com>
**Source code:** :source:`Lib/email/__init__.py`
--------------
-The :mod:`email` package is a library for managing email messages, including
-MIME and other :rfc:`2822`\ -based message documents. It is specifically *not*
-designed to do any sending of email messages to SMTP (:rfc:`2821`), NNTP, or
-other servers; those are functions of modules such as :mod:`smtplib` and
-:mod:`nntplib`. The :mod:`email` package attempts to be as RFC-compliant as
-possible, supporting in addition to :rfc:`2822`, such MIME-related RFCs as
-:rfc:`2045`, :rfc:`2046`, :rfc:`2047`, and :rfc:`2231`.
-
-The primary distinguishing feature of the :mod:`email` package is that it splits
-the parsing and generating of email messages from the internal *object model*
-representation of email. Applications using the :mod:`email` package deal
-primarily with objects; you can add sub-objects to messages, remove sub-objects
-from messages, completely re-arrange the contents, etc. There is a separate
-parser and a separate generator which handles the transformation from flat text
-to the object model, and then back to flat text again. There are also handy
-subclasses for some common MIME object types, and a few miscellaneous utilities
-that help with such common tasks as extracting and parsing message field values,
-creating RFC-compliant dates, etc.
+The :mod:`email` package is a library for managing email messages. It is
+specifically *not* designed to do any sending of email messages to SMTP
+(:rfc:`2821`), NNTP, or other servers; those are functions of modules such as
+:mod:`smtplib` and :mod:`nntplib`. The :mod:`email` package attempts to be as
+RFC-compliant as possible, supporting :rfc:`5233` and :rfc:`6532`, as well as
+such MIME-related RFCs as :rfc:`2045`, :rfc:`2046`, :rfc:`2047`, :rfc:`2183`,
+and :rfc:`2231`.
+
+The overall structure of the email package can be divided into three major
+components, plus a fourth component that controls the behavior of the other
+components.
+
+The central component of the package is an "object model" that represents email
+messages. An application interacts with the package primarily through the
+object model interface defined in the :mod:`~email.message` sub-module. The
+application can use this API to ask questions about an existing email, to
+construct a new email, or to add or remove email subcomponents that themselves
+use the same object model interface. That is, following the nature of email
+messages and their MIME subcomponents, the email object model is a tree
+structure of objects that all provide the :class:`~email.message.EmailMessage`
+API.
+
+The other two major components of the package are the :mod:`~email.parser` and
+the :mod:`~email.generator`. The parser takes the serialized version of an
+email message (a stream of bytes) and converts it into a tree of
+:class:`~email.message.EmailMessage` objects. The generator takes an
+:class:`~email.message.EmailMessage` and turns it back into a serialized byte
+stream. (The parser and generator also handle streams of text characters, but
+this usage is discouraged as it is too easy to end up with messages that are
+not valid in one way or another.)
+
+The control component is the :mod:`~email.policy` module. Every
+:class:`~email.message.EmailMessage`, every :mod:`~email.generator`, and every
+:mod:`~email.parser` has an associated :mod:`~email.policy` object that
+controls its behavior. Usually an application only needs to specify the policy
+when an :class:`~email.message.EmailMessage` is created, either by directly
+instantiating an :class:`~email.message.EmailMessage` to create a new email,
+or by parsing an input stream using a :mod:`~email.parser`. But the policy can
+be changed when the message is serialized using a :mod:`~email.generator`.
+This allows, for example, a generic email message to be parsed from disk, but
+to serialize it using standard SMTP settings when sending it to an email
+server.
+
+The email package does its best to hide the details of the various governing
+RFCs from the application. Conceptually the application should be able to
+treat the email message as a structured tree of unicode text and binary
+attachments, without having to worry about how these are represented when
+serialized. In practice, however, it is often necessary to be aware of at
+least some of the rules governing MIME messages and their structure,
+specifically the names and nature of the MIME "content types" and how they
+identify multipart documents. For the most part this knowledge should only be
+required for more complex applications, and even then it should only be the
+high level structure in question, and not the details of how those structures
+are represented. Since MIME content types are used widely in modern internet
+software (not just email), this will be a familiar concept to many programmers.
The following sections describe the functionality of the :mod:`email` package.
-The ordering follows a progression that should be common in applications: an
-email message is read as flat text from a file or other source, the text is
-parsed to produce the object structure of the email message, this structure is
-manipulated, and finally, the object tree is rendered back into flat text.
-
-It is perfectly feasible to create the object structure out of whole cloth ---
-i.e. completely from scratch. From there, a similar progression can be taken as
-above.
-
-Also included are detailed specifications of all the classes and modules that
-the :mod:`email` package provides, the exception classes you might encounter
-while using the :mod:`email` package, some auxiliary utilities, and a few
-examples. For users of the older :mod:`mimelib` package, or previous versions
-of the :mod:`email` package, a section on differences and porting is provided.
+We start with the :mod:`~email.message` object model, which is the primary
+interface an application will use, and follow that with the
+:mod:`~email.parser` and :mod:`~email.generator` components. Then we cover the
+:mod:`~email.policy` controls, which completes the treatment of the main
+components of the library.
+
+The next three sections cover the exceptions the package may raise and the
+defects (non-compliance with the RFCs) that the :mod:`~email.parser` may
+detect. Then we cover the :mod:`~email.headerregistry` and the
+:mod:`~email.contentmanager` sub-components, which provide tools for doing more
+detailed manipulation of headers and payloads, respectively. Both of these
+components contain features relevant to consuming and producing non-trivial
+messages, but also document their extensibility APIs, which will be of interest
+to advanced applications.
+
+Following those is a set of examples of using the fundamental parts of the APIs
+covered in the preceding sections.
+
+The forgoing represent the modern (unicode friendly) API of the email package.
+The remaining sections, starting with the :class:`~email.message.Message`
+class, cover the legacy :data:`~email.policy.compat32` API that deals much more
+directly with the details of how email messages are represented. The
+:data:`~email.policy.compat32` API does *not* hide the details of the RFCs from
+the application, but for applications that need to operate at that level, they
+can be useful tools. This documentation is also relevant for applications that
+are still using the :mod:`~email.policy.compat32` API for backward
+compatibility reasons.
+
+.. versionchanged:: 3.6
+ Docs reorganized and rewritten to promote the new
+ :class:`~email.message.EmailMessage`/:class:`~email.policy.EmailPolicy`
+ API.
Contents of the :mod:`email` package documentation:
@@ -56,335 +110,43 @@ Contents of the :mod:`email` package documentation:
email.parser.rst
email.generator.rst
email.policy.rst
+
+ email.errors.rst
email.headerregistry.rst
email.contentmanager.rst
+
+ email.examples.rst
+
+Legacy API:
+
+.. toctree::
+
+ email.compat32-message.rst
email.mime.rst
email.header.rst
email.charset.rst
email.encoders.rst
- email.errors.rst
email.util.rst
email.iterators.rst
- email-examples.rst
.. seealso::
Module :mod:`smtplib`
- SMTP protocol client
-
- Module :mod:`nntplib`
- NNTP protocol client
-
-
-.. _email-pkg-history:
-
-Package History
----------------
-
-This table describes the release history of the email package, corresponding to
-the version of Python that the package was released with. For purposes of this
-document, when you see a note about change or added versions, these refer to the
-Python version the change was made in, *not* the email package version. This
-table also describes the Python compatibility of each version of the package.
-
-+---------------+------------------------------+-----------------------+
-| email version | distributed with | compatible with |
-+===============+==============================+=======================+
-| :const:`1.x` | Python 2.2.0 to Python 2.2.1 | *no longer supported* |
-+---------------+------------------------------+-----------------------+
-| :const:`2.5` | Python 2.2.2+ and Python 2.3 | Python 2.1 to 2.5 |
-+---------------+------------------------------+-----------------------+
-| :const:`3.0` | Python 2.4 and Python 2.5 | Python 2.3 to 2.6 |
-+---------------+------------------------------+-----------------------+
-| :const:`4.0` | Python 2.5 to Python 2.7 | Python 2.3 to 2.7 |
-+---------------+------------------------------+-----------------------+
-| :const:`5.0` | Python 3.0 and Python 3.1 | Python 3.0 to 3.2 |
-+---------------+------------------------------+-----------------------+
-| :const:`5.1` | Python 3.2 | Python 3.2 |
-+---------------+------------------------------+-----------------------+
-
-After Version 5.1 (Python 3.2), the email package no longer has a version that
-is separate from the Python version. (See the :ref:`whatsnew-index` documents
-for the respective Python versions for details on changes.)
-
-Here are the major differences between :mod:`email` version 5.1 and
-version 5.0:
-
-* It is once again possible to parse messages containing non-ASCII bytes,
- and to reproduce such messages if the data containing the non-ASCII
- bytes is not modified.
-
-* New functions :func:`message_from_bytes` and :func:`message_from_binary_file`,
- and new classes :class:`~email.parser.BytesFeedParser` and
- :class:`~email.parser.BytesParser` allow binary message data to be parsed
- into model objects.
-
-* Given bytes input to the model, :meth:`~email.message.Message.get_payload`
- will by default decode a message body that has a
- :mailheader:`Content-Transfer-Encoding` of ``8bit`` using the charset
- specified in the MIME headers and return the resulting string.
-
-* Given bytes input to the model, :class:`~email.generator.Generator` will
- convert message bodies that have a :mailheader:`Content-Transfer-Encoding` of
- 8bit to instead have a 7bit Content-Transfer-Encoding.
-
-* New class :class:`~email.generator.BytesGenerator` produces bytes
- as output, preserving any unchanged non-ASCII data that was
- present in the input used to build the model, including message bodies
- with a :mailheader:`Content-Transfer-Encoding` of 8bit.
-
-Here are the major differences between :mod:`email` version 5.0 and version 4:
-
-* All operations are on unicode strings. Text inputs must be strings,
- text outputs are strings. Outputs are limited to the ASCII character
- set and so can be encoded to ASCII for transmission. Inputs are also
- limited to ASCII; this is an acknowledged limitation of email 5.0 and
- means it can only be used to parse email that is 7bit clean.
-
-Here are the major differences between :mod:`email` version 4 and version 3:
-
-* All modules have been renamed according to :pep:`8` standards. For example,
- the version 3 module :mod:`email.Message` was renamed to :mod:`email.message` in
- version 4.
-
-* A new subpackage :mod:`email.mime` was added and all the version 3
- :mod:`email.MIME\*` modules were renamed and situated into the :mod:`email.mime`
- subpackage. For example, the version 3 module :mod:`email.MIMEText` was renamed
- to :mod:`email.mime.text`.
-
- *Note that the version 3 names will continue to work until Python 2.6*.
-
-* The :mod:`email.mime.application` module was added, which contains the
- :class:`~email.mime.application.MIMEApplication` class.
-
-* Methods that were deprecated in version 3 have been removed. These include
- :meth:`Generator.__call__`, :meth:`Message.get_type`,
- :meth:`Message.get_main_type`, :meth:`Message.get_subtype`.
-
-* Fixes have been added for :rfc:`2231` support which can change some of the
- return types for :func:`Message.get_param <email.message.Message.get_param>`
- and friends. Under some
- circumstances, values which used to return a 3-tuple now return simple strings
- (specifically, if all extended parameter segments were unencoded, there is no
- language and charset designation expected, so the return type is now a simple
- string). Also, %-decoding used to be done for both encoded and unencoded
- segments; this decoding is now done only for encoded segments.
-
-Here are the major differences between :mod:`email` version 3 and version 2:
-
-* The :class:`~email.parser.FeedParser` class was introduced, and the
- :class:`~email.parser.Parser` class was implemented in terms of the
- :class:`~email.parser.FeedParser`. All parsing therefore is
- non-strict, and parsing will make a best effort never to raise an exception.
- Problems found while parsing messages are stored in the message's *defect*
- attribute.
-
-* All aspects of the API which raised :exc:`DeprecationWarning`\ s in version 2
- have been removed. These include the *_encoder* argument to the
- :class:`~email.mime.text.MIMEText` constructor, the
- :meth:`Message.add_payload` method, the :func:`Utils.dump_address_pair`
- function, and the functions :func:`Utils.decode` and :func:`Utils.encode`.
-
-* New :exc:`DeprecationWarning`\ s have been added to:
- :meth:`Generator.__call__`, :meth:`Message.get_type`,
- :meth:`Message.get_main_type`, :meth:`Message.get_subtype`, and the *strict*
- argument to the :class:`~email.parser.Parser` class. These are expected to
- be removed in future versions.
-
-* Support for Pythons earlier than 2.3 has been removed.
-
-Here are the differences between :mod:`email` version 2 and version 1:
-
-* The :mod:`email.Header` and :mod:`email.Charset` modules have been added.
-
-* The pickle format for :class:`~email.message.Message` instances has changed.
- Since this was never (and still isn't) formally defined, this isn't
- considered a backward incompatibility. However if your application pickles
- and unpickles :class:`~email.message.Message` instances, be aware that in
- :mod:`email` version 2, :class:`~email.message.Message` instances now have
- private variables *_charset* and *_default_type*.
-
-* Several methods in the :class:`~email.message.Message` class have been
- deprecated, or their signatures changed. Also, many new methods have been
- added. See the documentation for the :class:`~email.message.Message` class
- for details. The changes should be completely backward compatible.
+ SMTP (Simple Mail Transport Protcol) client
-* The object structure has changed in the face of :mimetype:`message/rfc822`
- content types. In :mod:`email` version 1, such a type would be represented
- by a scalar payload, i.e. the container message's
- :meth:`~email.message.Message.is_multipart` returned false,
- :meth:`~email.message.Message.get_payload` was not a list object, but a
- single :class:`~email.message.Message` instance.
+ Module :mod:`poplib`
+ POP (Post Office Protocol) client
- This structure was inconsistent with the rest of the package, so the object
- representation for :mimetype:`message/rfc822` content types was changed. In
- :mod:`email` version 2, the container *does* return ``True`` from
- :meth:`~email.message.Message.is_multipart`, and
- :meth:`~email.message.Message.get_payload` returns a list containing a single
- :class:`~email.message.Message` item.
+ Module :mod:`imaplib`
+ IMAP (Internet Message Access Protocol) client
- Note that this is one place that backward compatibility could not be
- completely maintained. However, if you're already testing the return type of
- :meth:`~email.message.Message.get_payload`, you should be fine. You just need
- to make sure your code doesn't do a :meth:`~email.message.Message.set_payload`
- with a :class:`~email.message.Message` instance on a container with a content
- type of :mimetype:`message/rfc822`.
-
-* The :class:`~email.parser.Parser` constructor's *strict* argument was added,
- and its :meth:`~email.parser.Parser.parse` and
- :meth:`~email.parser.Parser.parsestr` methods grew a *headersonly* argument.
- The *strict* flag was also added to functions :func:`email.message_from_file`
- and :func:`email.message_from_string`.
-
-* :meth:`Generator.__call__` is deprecated; use :meth:`Generator.flatten
- <email.generator.Generator.flatten>` instead. The
- :class:`~email.generator.Generator` class has also grown the
- :meth:`~email.generator.Generator.clone` method.
-
-* The :class:`~email.generator.DecodedGenerator` class in the
- :mod:`email.generator` module was added.
-
-* The intermediate base classes
- :class:`~email.mime.nonmultipart.MIMENonMultipart` and
- :class:`~email.mime.multipart.MIMEMultipart` have been added, and interposed
- in the class hierarchy for most of the other MIME-related derived classes.
-
-* The *_encoder* argument to the :class:`~email.mime.text.MIMEText` constructor
- has been deprecated. Encoding now happens implicitly based on the
- *_charset* argument.
-
-* The following functions in the :mod:`email.Utils` module have been deprecated:
- :func:`dump_address_pairs`, :func:`decode`, and :func:`encode`. The following
- functions have been added to the module: :func:`make_msgid`,
- :func:`decode_rfc2231`, :func:`encode_rfc2231`, and :func:`decode_params`.
-
-* The non-public function :func:`email.Iterators._structure` was added.
-
-
-Differences from :mod:`mimelib`
--------------------------------
-
-The :mod:`email` package was originally prototyped as a separate library called
-`mimelib <http://mimelib.sourceforge.net/>`_. Changes have been made so that method names
-are more consistent, and some methods or modules have either been added or
-removed. The semantics of some of the methods have also changed. For the most
-part, any functionality available in :mod:`mimelib` is still available in the
-:mod:`email` package, albeit often in a different way. Backward compatibility
-between the :mod:`mimelib` package and the :mod:`email` package was not a
-priority.
-
-Here is a brief description of the differences between the :mod:`mimelib` and
-the :mod:`email` packages, along with hints on how to port your applications.
-
-Of course, the most visible difference between the two packages is that the
-package name has been changed to :mod:`email`. In addition, the top-level
-package has the following differences:
-
-* :func:`messageFromString` has been renamed to :func:`message_from_string`.
-
-* :func:`messageFromFile` has been renamed to :func:`message_from_file`.
-
-The :class:`~email.message.Message` class has the following differences:
-
-* The method :meth:`asString` was renamed to
- :meth:`~email.message.Message.as_string`.
-
-* The method :meth:`ismultipart` was renamed to
- :meth:`~email.message.Message.is_multipart`.
-
-* The :meth:`~email.message.Message.get_payload` method has grown a *decode*
- optional argument.
-
-* The method :meth:`getall` was renamed to
- :meth:`~email.message.Message.get_all`.
-
-* The method :meth:`addheader` was renamed to
- :meth:`~email.message.Message.add_header`.
-
-* The method :meth:`gettype` was renamed to :meth:`get_type`.
-
-* The method :meth:`getmaintype` was renamed to :meth:`get_main_type`.
-
-* The method :meth:`getsubtype` was renamed to :meth:`get_subtype`.
-
-* The method :meth:`getparams` was renamed to
- :meth:`~email.message.Message.get_params`. Also, whereas :meth:`getparams`
- returned a list of strings, :meth:`~email.message.Message.get_params` returns
- a list of 2-tuples, effectively the key/value pairs of the parameters, split
- on the ``'='`` sign.
-
-* The method :meth:`getparam` was renamed to
- :meth:`~email.message.Message.get_param`.
-
-* The method :meth:`getcharsets` was renamed to
- :meth:`~email.message.Message.get_charsets`.
-
-* The method :meth:`getfilename` was renamed to
- :meth:`~email.message.Message.get_filename`.
-
-* The method :meth:`getboundary` was renamed to
- :meth:`~email.message.Message.get_boundary`.
-
-* The method :meth:`setboundary` was renamed to
- :meth:`~email.message.Message.set_boundary`.
-
-* The method :meth:`getdecodedpayload` was removed. To get similar
- functionality, pass the value 1 to the *decode* flag of the
- :meth:`~email.message.Message.get_payload` method.
-
-* The method :meth:`getpayloadastext` was removed. Similar functionality is
- supported by the :class:`~email.generator.DecodedGenerator` class in the
- :mod:`email.generator` module.
-
-* The method :meth:`getbodyastext` was removed. You can get similar
- functionality by creating an iterator with
- :func:`~email.iterators.typed_subpart_iterator` in the :mod:`email.iterators`
- module.
-
-The :class:`~email.parser.Parser` class has no differences in its public
-interface. It does have some additional smarts to recognize
-:mimetype:`message/delivery-status` type messages, which it represents as a
-:class:`~email.message.Message` instance containing separate
-:class:`~email.message.Message` subparts for each header block in the delivery
-status notification [#]_.
-
-The :class:`~email.generator.Generator` class has no differences in its public
-interface. There is a new class in the :mod:`email.generator` module though,
-called :class:`~email.generator.DecodedGenerator` which provides most of the
-functionality previously available in the :meth:`Message.getpayloadastext`
-method.
-
-The following modules and classes have been changed:
-
-* The :class:`~email.mime.base.MIMEBase` class constructor arguments *_major*
- and *_minor* have changed to *_maintype* and *_subtype* respectively.
-
-* The ``Image`` class/module has been renamed to ``MIMEImage``. The *_minor*
- argument has been renamed to *_subtype*.
-
-* The ``Text`` class/module has been renamed to ``MIMEText``. The *_minor*
- argument has been renamed to *_subtype*.
-
-* The ``MessageRFC822`` class/module has been renamed to ``MIMEMessage``. Note
- that an earlier version of :mod:`mimelib` called this class/module ``RFC822``,
- but that clashed with the Python standard library module :mod:`rfc822` on some
- case-insensitive file systems.
-
- Also, the :class:`~email.mime.message.MIMEMessage` class now represents any
- kind of MIME message
- with main type :mimetype:`message`. It takes an optional argument *_subtype*
- which is used to set the MIME subtype. *_subtype* defaults to
- :mimetype:`rfc822`.
-
-:mod:`mimelib` provided some utility functions in its :mod:`address` and
-:mod:`date` modules. All of these functions have been moved to the
-:mod:`email.utils` module.
-
-The ``MsgReader`` class/module has been removed. Its functionality is most
-closely supported in the :func:`~email.iterators.body_line_iterator` function
-in the :mod:`email.iterators` module.
+ Module :mod:`nntplib`
+ NNTP (Net News Transport Protocol) client
-.. rubric:: Footnotes
+ Module :mod:`mailbox`
+ Tools for creating, reading, and managing collections of messages on disk
+ using a variety standard formats.
-.. [#] Delivery Status Notifications (DSN) are defined in :rfc:`1894`.
+ Module :mod:`smtpd`
+ SMTP server framework (primarily useful for testing)
diff --git a/Doc/library/email.util.rst b/Doc/library/email.util.rst
index 5cff746..63fae2a 100644
--- a/Doc/library/email.util.rst
+++ b/Doc/library/email.util.rst
@@ -8,7 +8,43 @@
--------------
-There are several useful utilities provided in the :mod:`email.utils` module:
+There are a couple of useful utilities provided in the :mod:`email.utils`
+module:
+
+.. function:: localtime(dt=None)
+
+ Return local time as an aware datetime object. If called without
+ arguments, return current time. Otherwise *dt* argument should be a
+ :class:`~datetime.datetime` instance, and it is converted to the local time
+ zone according to the system time zone database. If *dt* is naive (that
+ is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. In this
+ case, a positive or zero value for *isdst* causes ``localtime`` to presume
+ initially that summer time (for example, Daylight Saving Time) is or is not
+ (respectively) in effect for the specified time. A negative value for
+ *isdst* causes the ``localtime`` to attempt to divine whether summer time
+ is in effect for the specified time.
+
+ .. versionadded:: 3.3
+
+
+.. function:: make_msgid(idstring=None, domain=None)
+
+ Returns a string suitable for an :rfc:`2822`\ -compliant
+ :mailheader:`Message-ID` header. Optional *idstring* if given, is a string
+ used to strengthen the uniqueness of the message id. Optional *domain* if
+ given provides the portion of the msgid after the '@'. The default is the
+ local hostname. It is not normally necessary to override this default, but
+ may be useful certain cases, such as a constructing distributed system that
+ uses a consistent domain name across multiple hosts.
+
+ .. versionchanged:: 3.2
+ Added the *domain* keyword.
+
+
+The remaining functions are part of the legacy (``Compat32``) email API. There
+is no need to directly use these with the new API, since the parsing and
+formatting they provide is done automatically by the header parsing machinery
+of the new API.
.. function:: quote(str)
@@ -141,36 +177,6 @@ There are several useful utilities provided in the :mod:`email.utils` module:
.. versionadded:: 3.3
-.. function:: localtime(dt=None)
-
- Return local time as an aware datetime object. If called without
- arguments, return current time. Otherwise *dt* argument should be a
- :class:`~datetime.datetime` instance, and it is converted to the local time
- zone according to the system time zone database. If *dt* is naive (that
- is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. In this
- case, a positive or zero value for *isdst* causes ``localtime`` to presume
- initially that summer time (for example, Daylight Saving Time) is or is not
- (respectively) in effect for the specified time. A negative value for
- *isdst* causes the ``localtime`` to attempt to divine whether summer time
- is in effect for the specified time.
-
- .. versionadded:: 3.3
-
-
-.. function:: make_msgid(idstring=None, domain=None)
-
- Returns a string suitable for an :rfc:`2822`\ -compliant
- :mailheader:`Message-ID` header. Optional *idstring* if given, is a string
- used to strengthen the uniqueness of the message id. Optional *domain* if
- given provides the portion of the msgid after the '@'. The default is the
- local hostname. It is not normally necessary to override this default, but
- may be useful certain cases, such as a constructing distributed system that
- uses a consistent domain name across multiple hosts.
-
- .. versionchanged:: 3.2
- Added the *domain* keyword.
-
-
.. function:: decode_rfc2231(s)
Decode the string *s* according to :rfc:`2231`.
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index a3d5afc..87aa8b1 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -23,9 +23,10 @@ by identity, and the enumeration itself can be iterated over.
Module Contents
---------------
-This module defines two enumeration classes that can be used to define unique
-sets of names and values: :class:`Enum` and :class:`IntEnum`. It also defines
-one decorator, :func:`unique`.
+This module defines four enumeration classes that can be used to define unique
+sets of names and values: :class:`Enum`, :class:`IntEnum`, and
+:class:`IntFlags`. It also defines one decorator, :func:`unique`, and one
+helper, :class:`auto`.
.. class:: Enum
@@ -37,10 +38,27 @@ one decorator, :func:`unique`.
Base class for creating enumerated constants that are also
subclasses of :class:`int`.
+.. class:: IntFlag
+
+ Base class for creating enumerated constants that can be combined using
+ the bitwise operators without losing their :class:`IntFlag` membership.
+ :class:`IntFlag` members are also subclasses of :class:`int`.
+
+.. class:: Flag
+
+ Base class for creating enumerated constants that can be combined using
+ the bitwise operations without losing their :class:`Flag` membership.
+
.. function:: unique
Enum class decorator that ensures only one name is bound to any one value.
+.. class:: auto
+
+ Instances are replaced with an appropriate value for Enum members.
+
+.. versionadded:: 3.6 ``Flag``, ``IntFlag``, ``auto``
+
Creating an Enum
----------------
@@ -57,6 +75,13 @@ follows::
... blue = 3
...
+.. note:: Enum member values
+
+ Member values can be anything: :class:`int`, :class:`str`, etc.. If
+ the exact value is unimportant you may use :class:`auto` instances and an
+ appropriate value will be chosen for you. Care must be taken if you mix
+ :class:`auto` with other values.
+
.. note:: Nomenclature
- The class :class:`Color` is an *enumeration* (or *enum*)
@@ -212,6 +237,42 @@ found :exc:`ValueError` is raised with the details::
ValueError: duplicate values found in <enum 'Mistake'>: four -> three
+Using automatic values
+----------------------
+
+If the exact value is unimportant you can use :class:`auto`::
+
+ >>> from enum import Enum, auto
+ >>> class Color(Enum):
+ ... red = auto()
+ ... blue = auto()
+ ... green = auto()
+ ...
+ >>> list(Color)
+ [<Color.red: 1>, <Color.blue: 2>, <Color.green: 3>]
+
+The values are chosen by :func:`_generate_next_value_`, which can be
+overridden::
+
+ >>> class AutoName(Enum):
+ ... def _generate_next_value_(name, start, count, last_values):
+ ... return name
+ ...
+ >>> class Ordinal(AutoName):
+ ... north = auto()
+ ... south = auto()
+ ... east = auto()
+ ... west = auto()
+ ...
+ >>> list(Ordinal)
+ [<Ordinal.north: 'north'>, <Ordinal.south: 'south'>, <Ordinal.east: 'east'>, <Ordinal.west: 'west'>]
+
+.. note::
+
+ The goal of the default :meth:`_generate_next_value_` methods is to provide
+ the next :class:`int` in sequence with the last :class:`int` provided, but
+ the way it does this is an implementation detail and may change.
+
Iteration
---------
@@ -257,7 +318,7 @@ members are not integers (but see `IntEnum`_ below)::
>>> Color.red < Color.blue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
- TypeError: unorderable types: Color() < Color()
+ TypeError: '<' not supported between instances of 'Color' and 'Color'
Equality comparisons are defined though::
@@ -478,7 +539,7 @@ Derived Enumerations
IntEnum
^^^^^^^
-A variation of :class:`Enum` is provided which is also a subclass of
+The first variation of :class:`Enum` that is provided is also a subclass of
:class:`int`. Members of an :class:`IntEnum` can be compared to integers;
by extension, integer enumerations of different types can also be compared
to each other::
@@ -521,13 +582,124 @@ However, they still can't be compared to standard :class:`Enum` enumerations::
>>> [i for i in range(Shape.square)]
[0, 1]
-For the vast majority of code, :class:`Enum` is strongly recommended,
-since :class:`IntEnum` breaks some semantic promises of an enumeration (by
-being comparable to integers, and thus by transitivity to other
-unrelated enumerations). It should be used only in special cases where
-there's no other choice; for example, when integer constants are
-replaced with enumerations and backwards compatibility is required with code
-that still expects integers.
+
+IntFlag
+^^^^^^^
+
+The next variation of :class:`Enum` provided, :class:`IntFlag`, is also based
+on :class:`int`. The difference being :class:`IntFlag` members can be combined
+using the bitwise operators (&, \|, ^, ~) and the result is still an
+:class:`IntFlag` member. However, as the name implies, :class:`IntFlag`
+members also subclass :class:`int` and can be used wherever an :class:`int` is
+used. Any operation on an :class:`IntFlag` member besides the bit-wise
+operations will lose the :class:`IntFlag` membership.
+
+.. versionadded:: 3.6
+
+Sample :class:`IntFlag` class::
+
+ >>> from enum import IntFlag
+ >>> class Perm(IntFlag):
+ ... R = 4
+ ... W = 2
+ ... X = 1
+ ...
+ >>> Perm.R | Perm.W
+ <Perm.R|W: 6>
+ >>> Perm.R + Perm.W
+ 6
+ >>> RW = Perm.R | Perm.W
+ >>> Perm.R in RW
+ True
+
+It is also possible to name the combinations::
+
+ >>> class Perm(IntFlag):
+ ... R = 4
+ ... W = 2
+ ... X = 1
+ ... RWX = 7
+ >>> Perm.RWX
+ <Perm.RWX: 7>
+ >>> ~Perm.RWX
+ <Perm.-8: -8>
+
+Another important difference between :class:`IntFlag` and :class:`Enum` is that
+if no flags are set (the value is 0), its boolean evaluation is :data:`False`::
+
+ >>> Perm.R & Perm.X
+ <Perm.0: 0>
+ >>> bool(Perm.R & Perm.X)
+ False
+
+Because :class:`IntFlag` members are also subclasses of :class:`int` they can
+be combined with them::
+
+ >>> Perm.X | 8
+ <Perm.8|X: 9>
+
+
+Flag
+^^^^
+
+The last variation is :class:`Flag`. Like :class:`IntFlag`, :class:`Flag`
+members can be combined using the bitwise operators (&, \|, ^, ~). Unlike
+:class:`IntFlag`, they cannot be combined with, nor compared against, any
+other :class:`Flag` enumeration, nor :class:`int`. While it is possible to
+specify the values directly it is recommended to use :class:`auto` as the
+value and let :class:`Flag` select an appropriate value.
+
+.. versionadded:: 3.6
+
+Like :class:`IntFlag`, if a combination of :class:`Flag` members results in no
+flags being set, the boolean evaluation is :data:`False`::
+
+ >>> from enum import Flag
+ >>> class Color(Flag):
+ ... red = auto()
+ ... blue = auto()
+ ... green = auto()
+ ...
+ >>> Color.red & Color.green
+ <Color.0: 0>
+ >>> bool(Color.red & Color.green)
+ False
+
+Individual flags should have values that are powers of two (1, 2, 4, 8, ...),
+while combinations of flags won't::
+
+ >>> class Color(Flag):
+ ... red = auto()
+ ... blue = auto()
+ ... green = auto()
+ ... white = red | blue | green
+ ...
+ >>> Color.white
+ <Color.white: 7>
+
+Giving a name to the "no flags set" condition does not change its boolean
+value::
+
+ >>> class Color(Flag):
+ ... black = 0
+ ... red = auto()
+ ... blue = auto()
+ ... green = auto()
+ ...
+ >>> Color.black
+ <Color.black: 0>
+ >>> bool(Color.black)
+ False
+
+.. note::
+
+ For the majority of new code, :class:`Enum` and :class:`Flag` are strongly
+ recommended, since :class:`IntEnum` and :class:`IntFlag` break some
+ semantic promises of an enumeration (by being comparable to integers, and
+ thus by transitivity to other unrelated enumerations). :class:`IntEnum`
+ and :class:`IntFlag` should be used only in cases where :class:`Enum` and
+ :class:`Flag` will not do; for example, when integer constants are replaced
+ with enumerations, or for interoperability with other systems.
Others
@@ -558,7 +730,8 @@ Some rules:
4. %-style formatting: `%s` and `%r` call the :class:`Enum` class's
:meth:`__str__` and :meth:`__repr__` respectively; other codes (such as
`%i` or `%h` for IntEnum) treat the enum member as its mixed-in type.
-5. :meth:`str.format` (or :func:`format`) will use the mixed-in
+5. :ref:`Formatted string literals <f-strings>`, :meth:`str.format`,
+ and :func:`format` will use the mixed-in
type's :meth:`__format__`. If the :class:`Enum` class's :func:`str` or
:func:`repr` is desired, use the `!s` or `!r` format codes.
@@ -566,18 +739,87 @@ Some rules:
Interesting examples
--------------------
-While :class:`Enum` and :class:`IntEnum` are expected to cover the majority of
-use-cases, they cannot cover them all. Here are recipes for some different
-types of enumerations that can be used directly, or as examples for creating
-one's own.
+While :class:`Enum`, :class:`IntEnum`, :class:`IntFlag`, and :class:`Flag` are
+expected to cover the majority of use-cases, they cannot cover them all. Here
+are recipes for some different types of enumerations that can be used directly,
+or as examples for creating one's own.
+
+
+Omitting values
+^^^^^^^^^^^^^^^
+In many use-cases one doesn't care what the actual value of an enumeration
+is. There are several ways to define this type of simple enumeration:
-AutoNumber
-^^^^^^^^^^
+- use instances of :class:`auto` for the value
+- use instances of :class:`object` as the value
+- use a descriptive string as the value
+- use a tuple as the value and a custom :meth:`__new__` to replace the
+ tuple with an :class:`int` value
-Avoids having to specify the value for each enumeration member::
+Using any of these methods signifies to the user that these values are not
+important, and also enables one to add, remove, or reorder members without
+having to renumber the remaining members.
- >>> class AutoNumber(Enum):
+Whichever method you choose, you should provide a :meth:`repr` that also hides
+the (unimportant) value::
+
+ >>> class NoValue(Enum):
+ ... def __repr__(self):
+ ... return '<%s.%s>' % (self.__class__.__name__, self.name)
+ ...
+
+
+Using :class:`auto`
+"""""""""""""""""""
+
+Using :class:`object` would look like::
+
+ >>> class Color(NoValue):
+ ... red = auto()
+ ... blue = auto()
+ ... green = auto()
+ ...
+ >>> Color.green
+ <Color.green>
+
+
+Using :class:`object`
+"""""""""""""""""""""
+
+Using :class:`object` would look like::
+
+ >>> class Color(NoValue):
+ ... red = object()
+ ... green = object()
+ ... blue = object()
+ ...
+ >>> Color.green
+ <Color.green>
+
+
+Using a descriptive string
+""""""""""""""""""""""""""
+
+Using a string as the value would look like::
+
+ >>> class Color(NoValue):
+ ... red = 'stop'
+ ... green = 'go'
+ ... blue = 'too fast!'
+ ...
+ >>> Color.green
+ <Color.green>
+ >>> Color.green.value
+ 'go'
+
+
+Using a custom :meth:`__new__`
+""""""""""""""""""""""""""""""
+
+Using an auto-numbering :meth:`__new__` would look like::
+
+ >>> class AutoNumber(NoValue):
... def __new__(cls):
... value = len(cls.__members__) + 1
... obj = object.__new__(cls)
@@ -589,8 +831,11 @@ Avoids having to specify the value for each enumeration member::
... green = ()
... blue = ()
...
- >>> Color.green.value == 2
- True
+ >>> Color.green
+ <Color.green>
+ >>> Color.green.value
+ 2
+
.. note::
@@ -730,10 +975,60 @@ member instances.
Finer Points
^^^^^^^^^^^^
-:class:`Enum` members are instances of an :class:`Enum` class, and even
-though they are accessible as `EnumClass.member`, they should not be accessed
-directly from the member as that lookup may fail or, worse, return something
-besides the :class:`Enum` member you looking for::
+Supported ``__dunder__`` names
+""""""""""""""""""""""""""""""
+
+:attr:`__members__` is an :class:`OrderedDict` of ``member_name``:``member``
+items. It is only available on the class.
+
+:meth:`__new__`, if specified, must create and return the enum members; it is
+also a very good idea to set the member's :attr:`_value_` appropriately. Once
+all the members are created it is no longer used.
+
+
+Supported ``_sunder_`` names
+""""""""""""""""""""""""""""
+
+- ``_name_`` -- name of the member
+- ``_value_`` -- value of the member; can be set / modified in ``__new__``
+
+- ``_missing_`` -- a lookup function used when a value is not found; may be
+ overridden
+- ``_order_`` -- used in Python 2/3 code to ensure member order is consistent
+ (class attribute, removed during class creation)
+- ``_generate_next_value_`` -- used by the `Functional API`_ and by
+ :class:`auto` to get an appropriate value for an enum member; may be
+ overridden
+
+.. versionadded:: 3.6 ``_missing_``, ``_order_``, ``_generate_next_value_``
+
+To help keep Python 2 / Python 3 code in sync an :attr:`_order_` attribute can
+be provided. It will be checked against the actual order of the enumeration
+and raise an error if the two do not match::
+
+ >>> class Color(Enum):
+ ... _order_ = 'red green blue'
+ ... red = 1
+ ... blue = 3
+ ... green = 2
+ ...
+ Traceback (most recent call last):
+ ...
+ TypeError: member order does not match _order_
+
+.. note::
+
+ In Python 2 code the :attr:`_order_` attribute is necessary as definition
+ order is lost before it can be recorded.
+
+``Enum`` member type
+""""""""""""""""""""
+
+:class:`Enum` members are instances of their :class:`Enum` class, and are
+normally accessed as ``EnumClass.member``. Under certain circumstances they
+can also be accessed as ``EnumClass.member.member``, but you should never do
+this as that lookup may fail or, worse, return something besides the
+:class:`Enum` member you are looking for::
>>> class FieldTypes(Enum):
... name = 0
@@ -747,7 +1042,24 @@ besides the :class:`Enum` member you looking for::
.. versionchanged:: 3.5
-The :attr:`__members__` attribute is only available on the class.
+
+Boolean value of ``Enum`` classes and members
+"""""""""""""""""""""""""""""""""""""""""""""
+
+:class:`Enum` members that are mixed with non-:class:`Enum` types (such as
+:class:`int`, :class:`str`, etc.) are evaluated according to the mixed-in
+type's rules; otherwise, all members evaluate as :data:`True`. To make your
+own Enum's boolean evaluation depend on the member's value add the following to
+your class::
+
+ def __bool__(self):
+ return bool(self.value)
+
+:class:`Enum` classes always evaluate as :data:`True`.
+
+
+``Enum`` classes with methods
+"""""""""""""""""""""""""""""
If you give your :class:`Enum` subclass extra methods, like the `Planet`_
class above, those methods will show up in a :func:`dir` of the member,
@@ -758,11 +1070,23 @@ but not of the class::
>>> dir(Planet.EARTH)
['__class__', '__doc__', '__module__', 'name', 'surface_gravity', 'value']
-The :meth:`__new__` method will only be used for the creation of the
-:class:`Enum` members -- after that it is replaced. Any custom :meth:`__new__`
-method must create the object and set the :attr:`_value_` attribute
-appropriately.
-If you wish to change how :class:`Enum` members are looked up you should either
-write a helper function or a :func:`classmethod` for the :class:`Enum`
-subclass.
+Combining members of ``Flag``
+"""""""""""""""""""""""""""""
+
+If a combination of Flag members is not named, the :func:`repr` will include
+all named flags and all named combinations of flags that are in the value::
+
+ >>> class Color(Flag):
+ ... red = auto()
+ ... green = auto()
+ ... blue = auto()
+ ... magenta = red | blue
+ ... yellow = red | green
+ ... cyan = green | blue
+ ...
+ >>> Color(3) # named combination
+ <Color.yellow: 3>
+ >>> Color(7) # not named combination
+ <Color.cyan|magenta|blue|yellow|green|red: 7>
+
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
index 5a71933..a428f51 100644
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -170,8 +170,9 @@ The following exceptions are the exceptions that are usually raised.
.. exception:: ImportError
- Raised when an :keyword:`import` statement fails to find the module definition
- or when a ``from ... import`` fails to find a name that is to be imported.
+ Raised when the :keyword:`import` statement has troubles trying to
+ load a module. Also raised when the "from list" in ``from ... import``
+ has a name that cannot be found.
The :attr:`name` and :attr:`path` attributes can be set using keyword-only
arguments to the constructor. When set they represent the name of the module
@@ -181,6 +182,14 @@ The following exceptions are the exceptions that are usually raised.
.. versionchanged:: 3.3
Added the :attr:`name` and :attr:`path` attributes.
+.. exception:: ModuleNotFoundError
+
+ A subclass of :exc:`ImportError` which is raised by :keyword:`import`
+ when a module could not be located. It is also raised when ``None``
+ is found in :data:`sys.modules`.
+
+ .. versionadded:: 3.6
+
.. exception:: IndexError
@@ -228,9 +237,21 @@ The following exceptions are the exceptions that are usually raised.
.. exception:: NotImplementedError
This exception is derived from :exc:`RuntimeError`. In user defined base
- classes, abstract methods should raise this exception when they require derived
- classes to override the method.
+ classes, abstract methods should raise this exception when they require
+ derived classes to override the method, or while the class is being
+ developed to indicate that the real implementation still needs to be added.
+
+ .. note::
+ It should not be used to indicate that an operater or method is not
+ meant to be supported at all -- in that case either leave the operator /
+ method undefined or, if a subclass, set it to :data:`None`.
+
+ .. note::
+
+ ``NotImplementedError`` and ``NotImplemented`` are not interchangeable,
+ even though they have similar names and purposes. See
+ :data:`NotImplemented` for details on when to use it.
.. exception:: OSError([arg])
OSError(errno, strerror[, filename[, winerror[, filename2]]])
@@ -436,6 +457,15 @@ The following exceptions are the exceptions that are usually raised.
Raised when an operation or function is applied to an object of inappropriate
type. The associated value is a string giving details about the type mismatch.
+ This exception may be raised by user code to indicate that an attempted
+ operation on an object is not supported, and is not meant to be. If an object
+ is meant to support a given operation but has not yet provided an
+ implementation, :exc:`NotImplementedError` is the proper exception to raise.
+
+ Passing arguments of the wrong type (e.g. passing a :class:`list` when an
+ :class:`int` is expected) should result in a :exc:`TypeError`, but passing
+ arguments with the wrong value (e.g. a number outside expected boundaries)
+ should result in a :exc:`ValueError`.
.. exception:: UnboundLocalError
diff --git a/Doc/library/faulthandler.rst b/Doc/library/faulthandler.rst
index deedea1..d0c4cd0 100644
--- a/Doc/library/faulthandler.rst
+++ b/Doc/library/faulthandler.rst
@@ -70,6 +70,9 @@ Fault handler state
.. versionchanged:: 3.5
Added support for passing file descriptor to this function.
+ .. versionchanged:: 3.6
+ On Windows, a handler for Windows exception is also installed.
+
.. function:: disable()
Disable the fault handler: uninstall the signal handlers installed by
diff --git a/Doc/library/fileinput.rst b/Doc/library/fileinput.rst
index aa4c529..5881fef 100644
--- a/Doc/library/fileinput.rst
+++ b/Doc/library/fileinput.rst
@@ -72,9 +72,8 @@ The following function is the primary interface of this module:
.. versionchanged:: 3.2
Can be used as a context manager.
- .. versionchanged:: 3.5.2
- The *bufsize* parameter is no longer used.
-
+ .. deprecated-removed:: 3.6 3.8
+ The *bufsize* parameter.
The following functions use the global state created by :func:`fileinput.input`;
if there is no active state, :exc:`RuntimeError` is raised.
@@ -167,8 +166,8 @@ available for subclassing as well:
.. deprecated:: 3.4
The ``'rU'`` and ``'U'`` modes.
- .. versionchanged:: 3.5.2
- The *bufsize* parameter is no longer used.
+ .. deprecated-removed:: 3.6 3.8
+ The *bufsize* parameter.
**Optional in-place filtering:** if the keyword argument ``inplace=True`` is
@@ -195,10 +194,14 @@ The two following opening hooks are provided by this module:
Usage example: ``fi = fileinput.FileInput(openhook=fileinput.hook_compressed)``
-.. function:: hook_encoded(encoding)
+.. function:: hook_encoded(encoding, errors=None)
Returns a hook which opens each file with :func:`open`, using the given
- *encoding* to read the file.
+ *encoding* and *errors* to read the file.
Usage example: ``fi =
- fileinput.FileInput(openhook=fileinput.hook_encoded("iso-8859-1"))``
+ fileinput.FileInput(openhook=fileinput.hook_encoded("utf-8",
+ "surrogateescape"))``
+
+ .. versionchanged:: 3.6
+ Added the optional *errors* parameter.
diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst
index 1e35f37..b8c1dcf 100644
--- a/Doc/library/ftplib.rst
+++ b/Doc/library/ftplib.rst
@@ -97,6 +97,13 @@ The module defines the following items:
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
:data:`ssl.HAS_SNI`).
+ .. deprecated:: 3.6
+
+ *keyfile* and *certfile* are deprecated in favor of *context*.
+ Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let
+ :func:`ssl.create_default_context` select the system's trusted CA
+ certificates for you.
+
Here's a sample session using the :class:`FTP_TLS` class::
>>> ftps = FTP_TLS('ftp.pureftpd.org')
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 5af9fe4..c4fcd98 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -271,6 +271,9 @@ are always available. They are listed here in alphabetical order.
The complex type is described in :ref:`typesnumeric`.
+ .. versionchanged:: 3.6
+ Grouping digits with underscores as in code literals is allowed.
+
.. function:: delattr(object, name)
@@ -531,11 +534,14 @@ are always available. They are listed here in alphabetical order.
The float type is described in :ref:`typesnumeric`.
- .. index::
- single: __format__
- single: string; format() (built-in function)
+ .. versionchanged:: 3.6
+ Grouping digits with underscores as in code literals is allowed.
+.. index::
+ single: __format__
+ single: string; format() (built-in function)
+
.. function:: format(value[, format_spec])
Convert a *value* to a "formatted" representation, as controlled by
@@ -702,6 +708,10 @@ are always available. They are listed here in alphabetical order.
:meth:`base.__int__ <object.__int__>` instead of :meth:`base.__index__
<object.__index__>`.
+ .. versionchanged:: 3.6
+ Grouping digits with underscores as in code literals is allowed.
+
+
.. function:: isinstance(object, classinfo)
Return true if the *object* argument is an instance of the *classinfo*
@@ -878,11 +888,11 @@ are always available. They are listed here in alphabetical order.
Open *file* and return a corresponding :term:`file object`. If the file
cannot be opened, an :exc:`OSError` is raised.
- *file* is either a string or bytes object giving the pathname (absolute or
- relative to the current working directory) of the file to be opened or
- 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 a :term:`path-like object` giving the pathname (absolute or
+ relative to 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.
@@ -1055,27 +1065,38 @@ are always available. They are listed here in alphabetical order.
(where :func:`open` is declared), :mod:`os`, :mod:`os.path`, :mod:`tempfile`,
and :mod:`shutil`.
- .. versionchanged:: 3.3
- The *opener* parameter was added.
- The ``'x'`` mode was added.
- :exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
- :exc:`FileExistsError` is now raised if the file opened in exclusive
- creation mode (``'x'``) already exists.
+ .. versionchanged::
+ 3.3
- .. versionchanged:: 3.4
- The file is now non-inheritable.
+ * The *opener* parameter was added.
+ * The ``'x'`` mode was added.
+ * :exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
+ * :exc:`FileExistsError` is now raised if the file opened in exclusive
+ * creation mode (``'x'``) already exists.
+
+ .. versionchanged::
+ 3.4
+
+ * The file is now non-inheritable.
.. deprecated-removed:: 3.4 4.0
The ``'U'`` mode.
- .. versionchanged:: 3.5
- If the system call is interrupted and the signal handler does not raise an
- exception, the function now retries the system call instead of raising an
- :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
+ .. versionchanged::
+ 3.5
- .. versionchanged:: 3.5
- The ``'namereplace'`` error handler was added.
+ * If the system call is interrupted and the signal handler does not raise an
+ exception, the function now retries the system call instead of raising an
+ :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
+ * The ``'namereplace'`` error handler was added.
+
+ .. versionchanged::
+ 3.6
+
+ * Support added to accept objects implementing :class:`os.PathLike`.
+ * On Windows, opening a console buffer may return a subclass of
+ :class:`io.RawIOBase` other than :class:`io.FileIO`.
.. function:: ord(c)
@@ -1460,6 +1481,9 @@ are always available. They are listed here in alphabetical order.
See also :ref:`bltin-type-objects`.
+ .. versionchanged:: 3.6
+ Subclasses of :class:`type` which don't override ``type.__new__`` may no
+ longer use the one-argument form to get the type of an object.
.. function:: vars([object])
diff --git a/Doc/library/glob.rst b/Doc/library/glob.rst
index 328eef3..a8a5a50 100644
--- a/Doc/library/glob.rst
+++ b/Doc/library/glob.rst
@@ -14,7 +14,7 @@ The :mod:`glob` module finds all the pathnames matching a specified pattern
according to the rules used by the Unix shell, although results are returned in
arbitrary order. No tilde expansion is done, but ``*``, ``?``, and character
ranges expressed with ``[]`` will be correctly matched. This is done by using
-the :func:`os.listdir` and :func:`fnmatch.fnmatch` functions in concert, and
+the :func:`os.scandir` and :func:`fnmatch.fnmatch` functions in concert, and
not by actually invoking a subshell. Note that unlike :func:`fnmatch.fnmatch`,
:mod:`glob` treats filenames beginning with a dot (``.``) as special cases.
(For tilde and shell variable expansion, use :func:`os.path.expanduser` and
diff --git a/Doc/library/grp.rst b/Doc/library/grp.rst
index a30e622..74de3f9 100644
--- a/Doc/library/grp.rst
+++ b/Doc/library/grp.rst
@@ -43,6 +43,9 @@ It defines the following items:
Return the group database entry for the given numeric group ID. :exc:`KeyError`
is raised if the entry asked for cannot be found.
+ .. deprecated:: 3.6
+ Since Python 3.6 the support of non-integer arguments like floats or
+ strings in :func:`getgrgid` is deprecated.
.. function:: getgrnam(name)
diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst
index 792d57a..9c6b722 100644
--- a/Doc/library/gzip.rst
+++ b/Doc/library/gzip.rst
@@ -56,6 +56,8 @@ The module defines the following items:
.. versionchanged:: 3.4
Added support for the ``'x'``, ``'xb'`` and ``'xt'`` modes.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
.. class:: GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None)
@@ -151,6 +153,9 @@ The module defines the following items:
The :meth:`~io.BufferedIOBase.read` method now accepts an argument of
``None``.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: compress(data, compresslevel=9)
diff --git a/Doc/library/hashlib-blake2-tree.png b/Doc/library/hashlib-blake2-tree.png
new file mode 100644
index 0000000..010dcba
--- /dev/null
+++ b/Doc/library/hashlib-blake2-tree.png
Binary files differ
diff --git a/Doc/library/hashlib-blake2.rst b/Doc/library/hashlib-blake2.rst
new file mode 100644
index 0000000..eb5e441
--- /dev/null
+++ b/Doc/library/hashlib-blake2.rst
@@ -0,0 +1,444 @@
+.. _hashlib-blake2:
+
+:mod:`hashlib` --- BLAKE2 hash functions
+========================================
+
+.. module:: hashlib
+ :synopsis: BLAKE2 hash function for Python
+.. sectionauthor:: Dmitry Chestnykh
+
+.. index::
+ single: blake2b, blake2s
+
+BLAKE2_ is a cryptographic hash function defined in RFC-7693_ that comes in two
+flavors:
+
+* **BLAKE2b**, optimized for 64-bit platforms and produces digests of any size
+ between 1 and 64 bytes,
+
+* **BLAKE2s**, optimized for 8- to 32-bit platforms and produces digests of any
+ size between 1 and 32 bytes.
+
+BLAKE2 supports **keyed mode** (a faster and simpler replacement for HMAC_),
+**salted hashing**, **personalization**, and **tree hashing**.
+
+Hash objects from this module follow the API of standard library's
+:mod:`hashlib` objects.
+
+
+Module
+======
+
+Creating hash objects
+---------------------
+
+New hash objects are created by calling constructor functions:
+
+
+.. function:: blake2b(data=b'', digest_size=64, key=b'', salt=b'', \
+ person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, \
+ node_depth=0, inner_size=0, last_node=False)
+
+.. function:: blake2s(data=b'', digest_size=32, key=b'', salt=b'', \
+ person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, \
+ node_depth=0, inner_size=0, last_node=False)
+
+
+These functions return the corresponding hash objects for calculating
+BLAKE2b or BLAKE2s. They optionally take these general parameters:
+
+* *data*: initial chunk of data to hash, which must be interpretable as buffer
+ of bytes.
+
+* *digest_size*: size of output digest in bytes.
+
+* *key*: key for keyed hashing (up to 64 bytes for BLAKE2b, up to 32 bytes for
+ BLAKE2s).
+
+* *salt*: salt for randomized hashing (up to 16 bytes for BLAKE2b, up to 8
+ bytes for BLAKE2s).
+
+* *person*: personalization string (up to 16 bytes for BLAKE2b, up to 8 bytes
+ for BLAKE2s).
+
+The following table shows limits for general parameters (in bytes):
+
+======= =========== ======== ========= ===========
+Hash digest_size len(key) len(salt) len(person)
+======= =========== ======== ========= ===========
+BLAKE2b 64 64 16 16
+BLAKE2s 32 32 8 8
+======= =========== ======== ========= ===========
+
+.. note::
+
+ BLAKE2 specification defines constant lengths for salt and personalization
+ parameters, however, for convenience, this implementation accepts byte
+ strings of any size up to the specified length. If the length of the
+ parameter is less than specified, it is padded with zeros, thus, for
+ example, ``b'salt'`` and ``b'salt\x00'`` is the same value. (This is not
+ the case for *key*.)
+
+These sizes are available as module `constants`_ described below.
+
+Constructor functions also accept the following tree hashing parameters:
+
+* *fanout*: fanout (0 to 255, 0 if unlimited, 1 in sequential mode).
+
+* *depth*: maximal depth of tree (1 to 255, 255 if unlimited, 1 in
+ sequential mode).
+
+* *leaf_size*: maximal byte length of leaf (0 to 2**32-1, 0 if unlimited or in
+ sequential mode).
+
+* *node_offset*: node offset (0 to 2**64-1 for BLAKE2b, 0 to 2**48-1 for
+ BLAKE2s, 0 for the first, leftmost, leaf, or in sequential mode).
+
+* *node_depth*: node depth (0 to 255, 0 for leaves, or in sequential mode).
+
+* *inner_size*: inner digest size (0 to 64 for BLAKE2b, 0 to 32 for
+ BLAKE2s, 0 in sequential mode).
+
+* *last_node*: boolean indicating whether the processed node is the last
+ one (`False` for sequential mode).
+
+.. figure:: hashlib-blake2-tree.png
+ :alt: Explanation of tree mode parameters.
+
+See section 2.10 in `BLAKE2 specification
+<https://blake2.net/blake2_20130129.pdf>`_ for comprehensive review of tree
+hashing.
+
+
+Constants
+---------
+
+.. data:: blake2b.SALT_SIZE
+.. data:: blake2s.SALT_SIZE
+
+Salt length (maximum length accepted by constructors).
+
+
+.. data:: blake2b.PERSON_SIZE
+.. data:: blake2s.PERSON_SIZE
+
+Personalization string length (maximum length accepted by constructors).
+
+
+.. data:: blake2b.MAX_KEY_SIZE
+.. data:: blake2s.MAX_KEY_SIZE
+
+Maximum key size.
+
+
+.. data:: blake2b.MAX_DIGEST_SIZE
+.. data:: blake2s.MAX_DIGEST_SIZE
+
+Maximum digest size that the hash function can output.
+
+
+Examples
+========
+
+Simple hashing
+--------------
+
+To calculate hash of some data, you should first construct a hash object by
+calling the appropriate constructor function (:func:`blake2b` or
+:func:`blake2s`), then update it with the data by calling :meth:`update` on the
+object, and, finally, get the digest out of the object by calling
+:meth:`digest` (or :meth:`hexdigest` for hex-encoded string).
+
+ >>> from hashlib import blake2b
+ >>> h = blake2b()
+ >>> h.update(b'Hello world')
+ >>> h.hexdigest()
+ '6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
+
+
+As a shortcut, you can pass the first chunk of data to update directly to the
+constructor as the first argument (or as *data* keyword argument):
+
+ >>> from hashlib import blake2b
+ >>> blake2b(b'Hello world').hexdigest()
+ '6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
+
+You can call :meth:`hash.update` as many times as you need to iteratively
+update the hash:
+
+ >>> from hashlib import blake2b
+ >>> items = [b'Hello', b' ', b'world']
+ >>> h = blake2b()
+ >>> for item in items:
+ ... h.update(item)
+ >>> h.hexdigest()
+ '6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
+
+
+Using different digest sizes
+----------------------------
+
+BLAKE2 has configurable size of digests up to 64 bytes for BLAKE2b and up to 32
+bytes for BLAKE2s. For example, to replace SHA-1 with BLAKE2b without changing
+the size of output, we can tell BLAKE2b to produce 20-byte digests:
+
+ >>> from hashlib import blake2b
+ >>> h = blake2b(digest_size=20)
+ >>> h.update(b'Replacing SHA1 with the more secure function')
+ >>> h.hexdigest()
+ 'd24f26cf8de66472d58d4e1b1774b4c9158b1f4c'
+ >>> h.digest_size
+ 20
+ >>> len(h.digest())
+ 20
+
+Hash objects with different digest sizes have completely different outputs
+(shorter hashes are *not* prefixes of longer hashes); BLAKE2b and BLAKE2s
+produce different outputs even if the output length is the same:
+
+ >>> from hashlib import blake2b, blake2s
+ >>> blake2b(digest_size=10).hexdigest()
+ '6fa1d8fcfd719046d762'
+ >>> blake2b(digest_size=11).hexdigest()
+ 'eb6ec15daf9546254f0809'
+ >>> blake2s(digest_size=10).hexdigest()
+ '1bf21a98c78a1c376ae9'
+ >>> blake2s(digest_size=11).hexdigest()
+ '567004bf96e4a25773ebf4'
+
+
+Keyed hashing
+-------------
+
+Keyed hashing can be used for authentication as a faster and simpler
+replacement for `Hash-based message authentication code
+<http://en.wikipedia.org/wiki/Hash-based_message_authentication_code>`_ (HMAC).
+BLAKE2 can be securely used in prefix-MAC mode thanks to the
+indifferentiability property inherited from BLAKE.
+
+This example shows how to get a (hex-encoded) 128-bit authentication code for
+message ``b'message data'`` with key ``b'pseudorandom key'``::
+
+ >>> from hashlib import blake2b
+ >>> h = blake2b(key=b'pseudorandom key', digest_size=16)
+ >>> h.update(b'message data')
+ >>> h.hexdigest()
+ '3d363ff7401e02026f4a4687d4863ced'
+
+
+As a practical example, a web application can symmetrically sign cookies sent
+to users and later verify them to make sure they weren't tampered with::
+
+ >>> from hashlib import blake2b
+ >>> from hmac import compare_digest
+ >>>
+ >>> SECRET_KEY = b'pseudorandomly generated server secret key'
+ >>> AUTH_SIZE = 16
+ >>>
+ >>> def sign(cookie):
+ ... h = blake2b(data=cookie, digest_size=AUTH_SIZE, key=SECRET_KEY)
+ ... return h.hexdigest()
+ >>>
+ >>> cookie = b'user:vatrogasac'
+ >>> sig = sign(cookie)
+ >>> print("{0},{1}".format(cookie.decode('utf-8'), sig))
+ user:vatrogasac,349cf904533767ed2d755279a8df84d0
+ >>> compare_digest(cookie, sig)
+ True
+ >>> compare_digest(b'user:policajac', sig)
+ False
+ >>> compare_digesty(cookie, '0102030405060708090a0b0c0d0e0f00')
+ False
+
+Even though there's a native keyed hashing mode, BLAKE2 can, of course, be used
+in HMAC construction with :mod:`hmac` module::
+
+ >>> import hmac, hashlib
+ >>> m = hmac.new(b'secret key', digestmod=hashlib.blake2s)
+ >>> m.update(b'message')
+ >>> m.hexdigest()
+ 'e3c8102868d28b5ff85fc35dda07329970d1a01e273c37481326fe0c861c8142'
+
+
+Randomized hashing
+------------------
+
+By setting *salt* parameter users can introduce randomization to the hash
+function. Randomized hashing is useful for protecting against collision attacks
+on the hash function used in digital signatures.
+
+ Randomized hashing is designed for situations where one party, the message
+ preparer, generates all or part of a message to be signed by a second
+ party, the message signer. If the message preparer is able to find
+ cryptographic hash function collisions (i.e., two messages producing the
+ same hash value), then she might prepare meaningful versions of the message
+ that would produce the same hash value and digital signature, but with
+ different results (e.g., transferring $1,000,000 to an account, rather than
+ $10). Cryptographic hash functions have been designed with collision
+ resistance as a major goal, but the current concentration on attacking
+ cryptographic hash functions may result in a given cryptographic hash
+ function providing less collision resistance than expected. Randomized
+ hashing offers the signer additional protection by reducing the likelihood
+ that a preparer can generate two or more messages that ultimately yield the
+ same hash value during the digital signature generation process – even if
+ it is practical to find collisions for the hash function. However, the use
+ of randomized hashing may reduce the amount of security provided by a
+ digital signature when all portions of the message are prepared
+ by the signer.
+
+ (`NIST SP-800-106 "Randomized Hashing for Digital Signatures"
+ <http://csrc.nist.gov/publications/nistpubs/800-106/NIST-SP-800-106.pdf>`_)
+
+In BLAKE2 the salt is processed as a one-time input to the hash function during
+initialization, rather than as an input to each compression function.
+
+.. warning::
+
+ *Salted hashing* (or just hashing) with BLAKE2 or any other general-purpose
+ cryptographic hash function, such as SHA-256, is not suitable for hashing
+ passwords. See `BLAKE2 FAQ <https://blake2.net/#qa>`_ for more
+ information.
+..
+
+ >>> import os
+ >>> from hashlib import blake2b
+ >>> msg = b'some message'
+ >>> # Calculate the first hash with a random salt.
+ >>> salt1 = os.urandom(blake2b.SALT_SIZE)
+ >>> h1 = blake2b(salt=salt1)
+ >>> h1.update(msg)
+ >>> # Calculate the second hash with a different random salt.
+ >>> salt2 = os.urandom(blake2b.SALT_SIZE)
+ >>> h2 = blake2b(salt=salt2)
+ >>> h2.update(msg)
+ >>> # The digests are different.
+ >>> h1.digest() != h2.digest()
+ True
+
+
+Personalization
+---------------
+
+Sometimes it is useful to force hash function to produce different digests for
+the same input for different purposes. Quoting the authors of the Skein hash
+function:
+
+ We recommend that all application designers seriously consider doing this;
+ we have seen many protocols where a hash that is computed in one part of
+ the protocol can be used in an entirely different part because two hash
+ computations were done on similar or related data, and the attacker can
+ force the application to make the hash inputs the same. Personalizing each
+ hash function used in the protocol summarily stops this type of attack.
+
+ (`The Skein Hash Function Family
+ <http://www.skein-hash.info/sites/default/files/skein1.3.pdf>`_,
+ p. 21)
+
+BLAKE2 can be personalized by passing bytes to the *person* argument::
+
+ >>> from hashlib import blake2b
+ >>> FILES_HASH_PERSON = b'MyApp Files Hash'
+ >>> BLOCK_HASH_PERSON = b'MyApp Block Hash'
+ >>> h = blake2b(digest_size=32, person=FILES_HASH_PERSON)
+ >>> h.update(b'the same content')
+ >>> h.hexdigest()
+ '20d9cd024d4fb086aae819a1432dd2466de12947831b75c5a30cf2676095d3b4'
+ >>> h = blake2b(digest_size=32, person=BLOCK_HASH_PERSON)
+ >>> h.update(b'the same content')
+ >>> h.hexdigest()
+ 'cf68fb5761b9c44e7878bfb2c4c9aea52264a80b75005e65619778de59f383a3'
+
+Personalization together with the keyed mode can also be used to derive different
+keys from a single one.
+
+ >>> from hashlib import blake2s
+ >>> from base64 import b64decode, b64encode
+ >>> orig_key = b64decode(b'Rm5EPJai72qcK3RGBpW3vPNfZy5OZothY+kHY6h21KM=')
+ >>> enc_key = blake2s(key=orig_key, person=b'kEncrypt').digest()
+ >>> mac_key = blake2s(key=orig_key, person=b'kMAC').digest()
+ >>> print(b64encode(enc_key).decode('utf-8'))
+ rbPb15S/Z9t+agffno5wuhB77VbRi6F9Iv2qIxU7WHw=
+ >>> print(b64encode(mac_key).decode('utf-8'))
+ G9GtHFE1YluXY1zWPlYk1e/nWfu0WSEb0KRcjhDeP/o=
+
+Tree mode
+---------
+
+Here's an example of hashing a minimal tree with two leaf nodes::
+
+ 10
+ / \
+ 00 01
+
+This example uses 64-byte internal digests, and returns the 32-byte final
+digest::
+
+ >>> from hashlib import blake2b
+ >>>
+ >>> FANOUT = 2
+ >>> DEPTH = 2
+ >>> LEAF_SIZE = 4096
+ >>> INNER_SIZE = 64
+ >>>
+ >>> buf = bytearray(6000)
+ >>>
+ >>> # Left leaf
+ ... h00 = blake2b(buf[0:LEAF_SIZE], fanout=FANOUT, depth=DEPTH,
+ ... leaf_size=LEAF_SIZE, inner_size=INNER_SIZE,
+ ... node_offset=0, node_depth=0, last_node=False)
+ >>> # Right leaf
+ ... h01 = blake2b(buf[LEAF_SIZE:], fanout=FANOUT, depth=DEPTH,
+ ... leaf_size=LEAF_SIZE, inner_size=INNER_SIZE,
+ ... node_offset=1, node_depth=0, last_node=True)
+ >>> # Root node
+ ... h10 = blake2b(digest_size=32, fanout=FANOUT, depth=DEPTH,
+ ... leaf_size=LEAF_SIZE, inner_size=INNER_SIZE,
+ ... node_offset=0, node_depth=1, last_node=True)
+ >>> h10.update(h00.digest())
+ >>> h10.update(h01.digest())
+ >>> h10.hexdigest()
+ '3ad2a9b37c6070e374c7a8c508fe20ca86b6ed54e286e93a0318e95e881db5aa'
+
+Credits
+=======
+
+BLAKE2_ was designed by *Jean-Philippe Aumasson*, *Samuel Neves*, *Zooko
+Wilcox-O'Hearn*, and *Christian Winnerlein* based on SHA-3_ finalist BLAKE_
+created by *Jean-Philippe Aumasson*, *Luca Henzen*, *Willi Meier*, and
+*Raphael C.-W. Phan*.
+
+It uses core algorithm from ChaCha_ cipher designed by *Daniel J. Bernstein*.
+
+The stdlib implementation is based on pyblake2_ module. It was written by
+*Dmitry Chestnykh* based on C implementation written by *Samuel Neves*. The
+documentation was copied from pyblake2_ and written by *Dmitry Chestnykh*.
+
+The C code was partly rewritten for Python by *Christian Heimes*.
+
+The following public domain dedication applies for both C hash function
+implementation, extension code, and this documentation:
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along
+ with this software. If not, see
+ http://creativecommons.org/publicdomain/zero/1.0/.
+
+The following people have helped with development or contributed their changes
+to the project and the public domain according to the Creative Commons Public
+Domain Dedication 1.0 Universal:
+
+* *Alexandr Sokolovskiy*
+
+.. seealso:: Official BLAKE2 website: https://blake2.net
+
+.. _RFC-7693: https://tools.ietf.org/html/rfc7693
+.. _BLAKE2: https://blake2.net
+.. _HMAC: https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
+.. _BLAKE: https://131002.net/blake/
+.. _SHA-3: https://en.wikipedia.org/wiki/NIST_hash_function_competition
+.. _ChaCha: https://cr.yp.to/chacha.html
+.. _pyblake2: https://pythonhosted.org/pyblake2/
+
diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst
index a2e96ca..2cb3c78 100644
--- a/Doc/library/hashlib.rst
+++ b/Doc/library/hashlib.rst
@@ -44,8 +44,8 @@ Hash algorithms
---------------
There is one constructor method named for each type of :dfn:`hash`. All return
-a hash object with the same simple interface. For example: use :func:`sha1` to
-create a SHA1 hash object. You can now feed this object with :term:`bytes-like
+a hash object with the same simple interface. For example: use :func:`sha256` to
+create a SHA-256 hash object. You can now feed this object with :term:`bytes-like
objects <bytes-like object>` (normally :class:`bytes`) using the :meth:`update` method.
At any point you can ask it for the :dfn:`digest` of the
concatenation of the data fed to it so far using the :meth:`digest` or
@@ -64,21 +64,33 @@ concatenation of the data fed to it so far using the :meth:`digest` or
.. index:: single: OpenSSL; (use in module hashlib)
Constructors for hash algorithms that are always present in this module are
-:func:`md5`, :func:`sha1`, :func:`sha224`, :func:`sha256`, :func:`sha384`,
-and :func:`sha512`. Additional algorithms may also be available depending upon
-the OpenSSL library that Python uses on your platform.
+:func:`sha1`, :func:`sha224`, :func:`sha256`, :func:`sha384`,
+:func:`sha512`, :func:`blake2b`, and :func:`blake2s`.
+:func:`md5` is normally available as well, though it
+may be missing if you are using a rare "FIPS compliant" build of Python.
+Additional algorithms may also be available depending upon the OpenSSL
+library that Python uses on your platform. On most platforms the
+:func:`sha3_224`, :func:`sha3_256`, :func:`sha3_384`, :func:`sha3_512`,
+:func:`shake_128`, :func:`shake_256` are also available.
+
+.. versionadded:: 3.6
+ SHA3 (Keccak) and SHAKE constructors :func:`sha3_224`, :func:`sha3_256`,
+ :func:`sha3_384`, :func:`sha3_512`, :func:`shake_128`, :func:`shake_256`.
+
+.. versionadded:: 3.6
+ :func:`blake2b` and :func:`blake2s` were added.
For example, to obtain the digest of the byte string ``b'Nobody inspects the
spammish repetition'``::
>>> import hashlib
- >>> m = hashlib.md5()
+ >>> m = hashlib.sha256()
>>> m.update(b"Nobody inspects")
>>> m.update(b" the spammish repetition")
>>> m.digest()
- b'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
+ b'\x03\x1e\xdd}Ae\x15\x93\xc5\xfe\\\x00o\xa5u+7\xfd\xdf\xf7\xbcN\x84:\xa6\xaf\x0c\x95\x0fK\x94\x06'
>>> m.digest_size
- 16
+ 32
>>> m.block_size
64
@@ -107,7 +119,9 @@ Hashlib provides the following constant attributes:
.. data:: algorithms_guaranteed
A set containing the names of the hash algorithms guaranteed to be supported
- by this module on all platforms.
+ by this module on all platforms. Note that 'md5' is in this list despite
+ some upstream vendors offering an odd "FIPS compliant" Python build that
+ excludes it.
.. versionadded:: 3.2
@@ -181,6 +195,28 @@ A hash object has the following methods:
compute the digests of data sharing a common initial substring.
+SHAKE variable length digests
+-----------------------------
+
+The :func:`shake_128` and :func:`shake_256` algorithms provide variable
+length digests with length_in_bits//2 up to 128 or 256 bits of security.
+As such, their digest methods require a length. Maximum length is not limited
+by the SHAKE algorithm.
+
+.. method:: shake.digest(length)
+
+ Return the digest of the data passed to the :meth:`update` method so far.
+ This is a bytes object of size ``length`` which may contain bytes in
+ the whole range from 0 to 255.
+
+
+.. method:: shake.hexdigest(length)
+
+ Like :meth:`digest` except the digest is returned as a string object of
+ double length, containing only hexadecimal digits. This may be used to
+ exchange the value safely in email or other non-binary environments.
+
+
Key derivation
--------------
@@ -221,6 +257,29 @@ include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
Python implementation uses an inline version of :mod:`hmac`. It is about
three times slower and doesn't release the GIL.
+.. function:: scrypt(password, *, salt, n, r, p, maxmem=0, dklen=64)
+
+ The function provides scrypt password-based key derivation function as
+ defined in :rfc:`7914`.
+
+ *password* and *salt* must be bytes-like objects. Applications and
+ libraries should limit *password* to a sensible length (e.g. 1024). *salt*
+ should be about 16 or more bytes from a proper source, e.g. :func:`os.urandom`.
+
+ *n* is the CPU/Memory cost factor, *r* the block size, *p* parallelization
+ factor and *maxmem* limits memory (OpenSSL 1.1.0 defaults to 32 MB).
+ *dklen* is the length of the derived key.
+
+ Availability: OpenSSL 1.1+
+
+ .. versionadded:: 3.6
+
+
+BLAKE2
+------
+
+BLAKE2 takes additional arguments, see :ref:`hashlib-blake2`.
+
.. seealso::
@@ -230,6 +289,8 @@ include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
Module :mod:`base64`
Another way to encode binary hashes for non-binary environments.
+ See :ref:`hashlib-blake2`.
+
http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
The FIPS 180-2 publication on Secure Hash Algorithms.
diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst
index d863fe9..17f289d 100644
--- a/Doc/library/http.client.rst
+++ b/Doc/library/http.client.rst
@@ -69,13 +69,6 @@ The module provides the following classes:
must be a :class:`ssl.SSLContext` instance describing the various SSL
options.
- *key_file* and *cert_file* are deprecated, please use
- :meth:`ssl.SSLContext.load_cert_chain` instead, or let
- :func:`ssl.create_default_context` select the system's trusted CA
- certificates for you. The *check_hostname* parameter is also deprecated; the
- :attr:`ssl.SSLContext.check_hostname` attribute of *context* should be used
- instead.
-
Please read :ref:`ssl-security` for more information on best practices.
.. versionchanged:: 3.2
@@ -95,6 +88,17 @@ The module provides the following classes:
:func:`ssl._create_unverified_context` can be passed to the *context*
parameter.
+ .. deprecated:: 3.6
+
+ *key_file* and *cert_file* are deprecated in favor of *context*.
+ Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let
+ :func:`ssl.create_default_context` select the system's trusted CA
+ certificates for you.
+
+ The *check_hostname* parameter is also deprecated; the
+ :attr:`ssl.SSLContext.check_hostname` attribute of *context* should
+ be used instead.
+
.. class:: HTTPResponse(sock, debuglevel=0, method=None, url=None)
@@ -217,39 +221,61 @@ HTTPConnection Objects
:class:`HTTPConnection` instances have the following methods:
-.. method:: HTTPConnection.request(method, url, body=None, headers={})
+.. method:: HTTPConnection.request(method, url, body=None, headers={}, *, \
+ encode_chunked=False)
This will send a request to the server using the HTTP request
method *method* and the selector *url*.
If *body* is specified, the specified data is sent after the headers are
- finished. It may be a string, a :term:`bytes-like object`, an open
- :term:`file object`, or an iterable of :term:`bytes-like object`\s. If
- *body* is a string, it is encoded as ISO-8859-1, the default for HTTP. If
- it is a bytes-like object the bytes are sent as is. If it is a :term:`file
- object`, the contents of the file is sent; this file object should support
- at least the ``read()`` method. If the file object has a ``mode``
- attribute, the data returned by the ``read()`` method will be encoded as
- ISO-8859-1 unless the ``mode`` attribute contains the substring ``b``,
- otherwise the data returned by ``read()`` is sent as is. If *body* is an
- iterable, the elements of the iterable are sent as is until the iterable is
- exhausted.
-
- The *headers* argument should be a mapping of extra HTTP
- headers to send with the request.
-
- If *headers* does not contain a Content-Length item, one is added
- automatically if possible. If *body* is ``None``, the Content-Length header
- is set to ``0`` for methods that expect a body (``PUT``, ``POST``, and
- ``PATCH``). If *body* is a string or bytes object, the Content-Length
- header is set to its length. If *body* is a :term:`file object` and it
- works to call :func:`~os.fstat` on the result of its ``fileno()`` method,
- then the Content-Length header is set to the ``st_size`` reported by the
- ``fstat`` call. Otherwise no Content-Length header is added.
+ finished. It may be a :class:`str`, a :term:`bytes-like object`, an
+ open :term:`file object`, or an iterable of :class:`bytes`. If *body*
+ is a string, it is encoded as ISO-8859-1, the default for HTTP. If it
+ is a bytes-like object, the bytes are sent as is. If it is a :term:`file
+ object`, the contents of the file is sent; this file object should
+ support at least the ``read()`` method. If the file object is an
+ instance of :class:`io.TextIOBase`, the data returned by the ``read()``
+ method will be encoded as ISO-8859-1, otherwise the data returned by
+ ``read()`` is sent as is. If *body* is an iterable, the elements of the
+ iterable are sent as is until the iterable is exhausted.
+
+ The *headers* argument should be a mapping of extra HTTP headers to send
+ with the request.
+
+ If *headers* contains neither Content-Length nor Transfer-Encoding,
+ but there is a request body, one of those
+ header fields will be added automatically. If
+ *body* is ``None``, the Content-Length header is set to ``0`` for
+ methods that expect a body (``PUT``, ``POST``, and ``PATCH``). If
+ *body* is a string or a bytes-like object that is not also a
+ :term:`file <file object>`, the Content-Length header is
+ set to its length. Any other type of *body* (files
+ and iterables in general) will be chunk-encoded, and the
+ Transfer-Encoding header will automatically be set instead of
+ Content-Length.
+
+ The *encode_chunked* argument is only relevant if Transfer-Encoding is
+ specified in *headers*. If *encode_chunked* is ``False``, the
+ HTTPConnection object assumes that all encoding is handled by the
+ calling code. If it is ``True``, the body will be chunk-encoded.
+
+ .. note::
+ Chunked transfer encoding has been added to the HTTP protocol
+ version 1.1. Unless the HTTP server is known to handle HTTP 1.1,
+ the caller must either specify the Content-Length, or must pass a
+ :class:`str` or bytes-like object that is not also a file as the
+ body representation.
.. versionadded:: 3.2
*body* can now be an iterable.
+ .. versionchanged:: 3.6
+ If neither Content-Length nor Transfer-Encoding are set in
+ *headers*, file and iterable *body* objects are now chunk-encoded.
+ The *encode_chunked* argument was added.
+ No attempt is made to determine the Content-Length for file
+ objects.
+
.. method:: HTTPConnection.getresponse()
Should be called after a request is sent to get the response from the server.
@@ -335,13 +361,32 @@ also send your request step by step, by using the four functions below.
an argument.
-.. method:: HTTPConnection.endheaders(message_body=None)
+.. method:: HTTPConnection.endheaders(message_body=None, *, encode_chunked=False)
Send a blank line to the server, signalling the end of the headers. The
optional *message_body* argument can be used to pass a message body
- associated with the request. The message body will be sent in the same
- packet as the message headers if it is string, otherwise it is sent in a
- separate packet.
+ associated with the request.
+
+ If *encode_chunked* is ``True``, the result of each iteration of
+ *message_body* will be chunk-encoded as specified in :rfc:`7230`,
+ Section 3.3.1. How the data is encoded is dependent on the type of
+ *message_body*. If *message_body* implements the :ref:`buffer interface
+ <bufferobjects>` the encoding will result in a single chunk.
+ If *message_body* is a :class:`collections.Iterable`, each iteration
+ of *message_body* will result in a chunk. If *message_body* is a
+ :term:`file object`, each call to ``.read()`` will result in a chunk.
+ The method automatically signals the end of the chunk-encoded data
+ immediately after *message_body*.
+
+ .. note:: Due to the chunked encoding specification, empty chunks
+ yielded by an iterator body will be ignored by the chunk-encoder.
+ This is to avoid premature termination of the read of the request by
+ the target server due to malformed encoding.
+
+ .. versionadded:: 3.6
+ Chunked encoding support. The *encode_chunked* parameter was
+ added.
+
.. method:: HTTPConnection.send(data)
diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst
index ae7fb97..fb5c1df 100644
--- a/Doc/library/http.server.rst
+++ b/Doc/library/http.server.rst
@@ -98,8 +98,8 @@ of which this module provides three different variants:
.. attribute:: rfile
- Contains an input stream, positioned at the start of the optional input
- data.
+ An :class:`io.BufferedIOBase` input stream, ready to read from
+ the start of the optional input data.
.. attribute:: wfile
@@ -107,6 +107,9 @@ of which this module provides three different variants:
client. Proper adherence to the HTTP protocol must be used when writing to
this stream.
+ .. versionchanged:: 3.6
+ This is an :class:`io.BufferedIOBase` stream.
+
:class:`BaseHTTPRequestHandler` has the following attributes:
.. attribute:: server_version
@@ -369,10 +372,9 @@ the current directory::
Handler = http.server.SimpleHTTPRequestHandler
- httpd = socketserver.TCPServer(("", PORT), Handler)
-
- print("serving at port", PORT)
- httpd.serve_forever()
+ with socketserver.TCPServer(("", PORT), Handler) as httpd:
+ print("serving at port", PORT)
+ httpd.serve_forever()
.. _http-server-cli:
diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst
index 771ca43..1632eb7 100644
--- a/Doc/library/imaplib.rst
+++ b/Doc/library/imaplib.rst
@@ -103,6 +103,14 @@ There's also a subclass for secure connections:
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
:data:`ssl.HAS_SNI`).
+ .. deprecated:: 3.6
+
+ *keyfile* and *certfile* are deprecated in favor of *ssl_context*.
+ Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let
+ :func:`ssl.create_default_context` select the system's trusted CA
+ certificates for you.
+
+
The second subclass allows for connections created by a child process:
@@ -500,6 +508,17 @@ An :class:`IMAP4` instance has the following methods:
M.store(num, '+FLAGS', '\\Deleted')
M.expunge()
+ .. note::
+
+ Creating flags containing ']' (for example: "[test]") violates
+ :rfc:`3501` (the IMAP protocol). However, imaplib has historically
+ allowed creation of such tags, and popular IMAP servers, such as Gmail,
+ accept and produce such flags. There are non-Python programs which also
+ create such tags. Although it is an RFC violation and IMAP clients and
+ servers are supposed to be strict, imaplib nonetheless continues to allow
+ such tags to be created for backward compatibility reasons, and as of
+ python 3.6, handles them if they are sent from the server, since this
+ improves real-world compatibility.
.. method:: IMAP4.subscribe(mailbox)
diff --git a/Doc/library/imghdr.rst b/Doc/library/imghdr.rst
index f11f6dc..800e919 100644
--- a/Doc/library/imghdr.rst
+++ b/Doc/library/imghdr.rst
@@ -20,6 +20,9 @@ The :mod:`imghdr` module defines the following function:
string describing the image type. If optional *h* is provided, the *filename*
is ignored and *h* is assumed to contain the byte stream to test.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
The following image types are recognized, as listed below with the return value
from :func:`what`:
diff --git a/Doc/library/imp.rst b/Doc/library/imp.rst
index 9828ba6..ccf5f92 100644
--- a/Doc/library/imp.rst
+++ b/Doc/library/imp.rst
@@ -85,7 +85,9 @@ This module provides an interface to the mechanisms used to implement the
.. deprecated:: 3.3
Use :func:`importlib.util.find_spec` instead unless Python 3.3
compatibility is required, in which case use
- :func:`importlib.find_loader`.
+ :func:`importlib.find_loader`. For example usage of the former case,
+ see the :ref:`importlib-examples` section of the :mod:`importlib`
+ documentation.
.. function:: load_module(name, file, pathname, description)
@@ -112,9 +114,12 @@ This module provides an interface to the mechanisms used to implement the
If previously used in conjunction with :func:`imp.find_module` then
consider using :func:`importlib.import_module`, otherwise use the loader
returned by the replacement you chose for :func:`imp.find_module`. If you
- called :func:`imp.load_module` and related functions directly then use the
- classes in :mod:`importlib.machinery`, e.g.
- ``importlib.machinery.SourceFileLoader(name, path).load_module()``.
+ called :func:`imp.load_module` and related functions directly with file
+ path arguments then use a combination of
+ :func:`importlib.util.spec_from_file_location` and
+ :func:`importlib.util.module_from_spec`. See the :ref:`importlib-examples`
+ section of the :mod:`importlib` documentation for details of the various
+ approaches.
.. function:: new_module(name)
@@ -123,7 +128,7 @@ This module provides an interface to the mechanisms used to implement the
in ``sys.modules``.
.. deprecated:: 3.4
- Use :class:`types.ModuleType` instead.
+ Use :func:`importlib.util.module_from_spec` instead.
.. function:: reload(module)
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index cb52f74..f63a18d 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -267,7 +267,7 @@ ABC hierarchy::
module and *path* will be the value of :attr:`__path__` from the
parent package. If a spec cannot be found, ``None`` is returned.
When passed in, ``target`` is a module object that the finder may
- use to make a more educated about what spec to return.
+ use to make a more educated guess about what spec to return.
.. versionadded:: 3.4
@@ -317,7 +317,7 @@ ABC hierarchy::
within the :term:`path entry` to which it is assigned. If a spec
cannot be found, ``None`` is returned. When passed in, ``target``
is a module object that the finder may use to make a more educated
- about what spec to return.
+ guess about what spec to return.
.. versionadded:: 3.4
@@ -379,10 +379,14 @@ ABC hierarchy::
An abstract method that executes the module in its own namespace
when a module is imported or reloaded. The module should already
- be initialized when exec_module() is called.
+ be initialized when ``exec_module()`` is called. When this method exists,
+ :meth:`~importlib.abc.Loader.create_module` must be defined.
.. versionadded:: 3.4
+ .. versionchanged:: 3.6
+ :meth:`~importlib.abc.Loader.create_module` must also be defined.
+
.. method:: load_module(fullname)
A legacy method for loading a module. If the module cannot be
@@ -936,6 +940,10 @@ find and load modules.
Concrete implementation of :meth:`importlib.abc.Loader.load_module` where
specifying the name of the module to load is optional.
+ .. deprecated:: 3.6
+
+ Use :meth:`importlib.abc.Loader.exec_module` instead.
+
.. class:: SourcelessFileLoader(fullname, path)
@@ -975,6 +983,10 @@ find and load modules.
Concrete implementation of :meth:`importlib.abc.Loader.load_module` where
specifying the name of the module to load is optional.
+ .. deprecated:: 3.6
+
+ Use :meth:`importlib.abc.Loader.exec_module` instead.
+
.. class:: ExtensionFileLoader(fullname, path)
@@ -1137,6 +1149,9 @@ an :term:`importer`.
The *optimization* parameter was added and the *debug_override* parameter
was deprecated.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: source_from_cache(path)
@@ -1150,6 +1165,9 @@ an :term:`importer`.
.. versionadded:: 3.4
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: decode_source(source_bytes)
Decode the given bytes representing source code and return it as a string
@@ -1192,12 +1210,13 @@ an :term:`importer`.
.. function:: module_from_spec(spec)
- Create a new module based on **spec** and ``spec.loader.create_module()``.
+ Create a new module based on **spec** and
+ :meth:`spec.loader.create_module <importlib.abc.Loader.create_module>`.
- If ``spec.loader.create_module()`` does not return ``None``, then any
- pre-existing attributes will not be reset. Also, no :exc:`AttributeError`
- will be raised if triggered while accessing **spec** or setting an attribute
- on the module.
+ If :meth:`spec.loader.create_module <importlib.abc.Loader.create_module>`
+ does not return ``None``, then any pre-existing attributes will not be reset.
+ Also, no :exc:`AttributeError` will be raised if triggered while accessing
+ **spec** or setting an attribute on the module.
This function is preferred over using :class:`types.ModuleType` to create a
new module as **spec** is used to set as many import-controlled attributes on
@@ -1259,7 +1278,8 @@ an :term:`importer`.
.. decorator:: set_package
- A :term:`decorator` for :meth:`importlib.abc.Loader.load_module` to set the :attr:`__package__` attribute on the returned module. If :attr:`__package__`
+ A :term:`decorator` for :meth:`importlib.abc.Loader.load_module` to set the
+ :attr:`__package__` attribute on the returned module. If :attr:`__package__`
is set and has a value other than ``None`` it will not be changed.
.. deprecated:: 3.4
@@ -1284,6 +1304,9 @@ an :term:`importer`.
.. versionadded:: 3.4
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. class:: LazyLoader(loader)
A class which postpones the execution of the loader of a module until the
@@ -1292,13 +1315,12 @@ an :term:`importer`.
This class **only** works with loaders that define
:meth:`~importlib.abc.Loader.exec_module` as control over what module type
is used for the module is required. For those same reasons, the loader's
- :meth:`~importlib.abc.Loader.create_module` method will be ignored (i.e., the
- loader's method should only return ``None``; this excludes
- :class:`BuiltinImporter` and :class:`ExtensionFileLoader`). Finally,
- modules which substitute the object placed into :attr:`sys.modules` will
- not work as there is no way to properly replace the module references
- throughout the interpreter safely; :exc:`ValueError` is raised if such a
- substitution is detected.
+ :meth:`~importlib.abc.Loader.create_module` method must return ``None`` or a
+ type for which its ``__class__`` attribute can be mutated along with not
+ using :term:`slots <__slots__>`. Finally, modules which substitute the object
+ placed into :attr:`sys.modules` will not work as there is no way to properly
+ replace the module references throughout the interpreter safely;
+ :exc:`ValueError` is raised if such a substitution is detected.
.. note::
For projects where startup time is critical, this class allows for
@@ -1309,6 +1331,11 @@ an :term:`importer`.
.. versionadded:: 3.5
+ .. versionchanged:: 3.6
+ Began calling :meth:`~importlib.abc.Loader.create_module`, removing the
+ compatibility warning for :class:`importlib.machinery.BuiltinImporter` and
+ :class:`importlib.machinery.ExtensionFileLoader`.
+
.. classmethod:: factory(loader)
A static method which returns a callable that creates a lazy loader. This
@@ -1320,3 +1347,139 @@ an :term:`importer`.
loader = importlib.machinery.SourceFileLoader
lazy_loader = importlib.util.LazyLoader.factory(loader)
finder = importlib.machinery.FileFinder(path, (lazy_loader, suffixes))
+
+.. _importlib-examples:
+
+Examples
+--------
+
+Importing programmatically
+''''''''''''''''''''''''''
+
+To programmatically import a module, use :func:`importlib.import_module`.
+::
+
+ import importlib
+
+ itertools = importlib.import_module('itertools')
+
+
+Checking if a module can be imported
+''''''''''''''''''''''''''''''''''''
+
+If you need to find out if a module can be imported without actually doing the
+import, then you should use :func:`importlib.util.find_spec`.
+::
+
+ import importlib.util
+ import sys
+
+ # For illustrative purposes.
+ name = 'itertools'
+
+ spec = importlib.util.find_spec(name)
+ if spec is None:
+ print("can't find the itertools module")
+ else:
+ # If you chose to perform the actual import ...
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ # Adding the module to sys.modules is optional.
+ sys.modules[name] = module
+
+
+Importing a source file directly
+''''''''''''''''''''''''''''''''
+
+To import a Python source file directly, use the following recipe
+(Python 3.4 and newer only)::
+
+ import importlib.util
+ import sys
+
+ # For illustrative purposes.
+ import tokenize
+ file_path = tokenize.__file__
+ module_name = tokenize.__name__
+
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ # Optional; only necessary if you want to be able to import the module
+ # by name later.
+ sys.modules[module_name] = module
+
+
+Setting up an importer
+''''''''''''''''''''''
+
+For deep customizations of import, you typically want to implement an
+:term:`importer`. This means managing both the :term:`finder` and :term:`loader`
+side of things. For finders there are two flavours to choose from depending on
+your needs: a :term:`meta path finder` or a :term:`path entry finder`. The
+former is what you would put on :attr:`sys.meta_path` while the latter is what
+you create using a :term:`path entry hook` on :attr:`sys.path_hooks` which works
+with :attr:`sys.path` entries to potentially create a finder. This example will
+show you how to register your own importers so that import will use them (for
+creating an importer for yourself, read the documentation for the appropriate
+classes defined within this package)::
+
+ import importlib.machinery
+ import sys
+
+ # For illustrative purposes only.
+ SpamMetaPathFinder = importlib.machinery.PathFinder
+ SpamPathEntryFinder = importlib.machinery.FileFinder
+ loader_details = (importlib.machinery.SourceFileLoader,
+ importlib.machinery.SOURCE_SUFFIXES)
+
+ # Setting up a meta path finder.
+ # Make sure to put the finder in the proper location in the list in terms of
+ # priority.
+ sys.meta_path.append(SpamMetaPathFinder)
+
+ # Setting up a path entry finder.
+ # Make sure to put the path hook in the proper location in the list in terms
+ # of priority.
+ sys.path_hooks.append(SpamPathEntryFinder.path_hook(loader_details))
+
+
+Approximating :func:`importlib.import_module`
+'''''''''''''''''''''''''''''''''''''''''''''
+
+Import itself is implemented in Python code, making it possible to
+expose most of the import machinery through importlib. The following
+helps illustrate the various APIs that importlib exposes by providing an
+approximate implementation of
+:func:`importlib.import_module` (Python 3.4 and newer for the importlib usage,
+Python 3.6 and newer for other parts of the code).
+::
+
+ import importlib.util
+ import sys
+
+ def import_module(name, package=None):
+ """An approximate implementation of import."""
+ absolute_name = importlib.util.resolve_name(name, package)
+ try:
+ return sys.modules[absolute_name]
+ except KeyError:
+ pass
+
+ path = None
+ if '.' in absolute_name:
+ parent_name, _, child_name = absolute_name.rpartition('.')
+ parent_module = import_module(parent_name)
+ path = parent_module.spec.submodule_search_locations
+ for finder in sys.meta_path:
+ spec = finder.find_spec(absolute_name, path)
+ if spec is not None:
+ break
+ else:
+ raise ImportError(f'No module named {absolute_name!r}')
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ sys.modules[absolute_name] = module
+ if path is not None:
+ setattr(parent_module, child_name, module)
+ return module
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 62a3988..fc815a6 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -235,24 +235,6 @@ attributes:
listed in the metaclass' custom :meth:`__dir__`.
-.. function:: getmoduleinfo(path)
-
- Returns a :term:`named tuple` ``ModuleInfo(name, suffix, mode, module_type)``
- of values that describe how Python will interpret the file identified by
- *path* if it is a module, or ``None`` if it would not be identified as a
- module. In that tuple, *name* is the name of the module without the name of
- any enclosing package, *suffix* is the trailing part of the file name (which
- may not be a dot-delimited extension), *mode* is the :func:`open` mode that
- would be used (``'r'`` or ``'rb'``), and *module_type* is an integer giving
- the type of the module. *module_type* will have a value which can be
- compared to the constants defined in the :mod:`imp` module; see the
- documentation for that module for more information on module types.
-
- .. deprecated:: 3.3
- You may check the file path's suffix against the supported suffixes
- listed in :mod:`importlib.machinery` to infer the same information.
-
-
.. function:: getmodulename(path)
Return the name of the module named by the file *path*, without including the
@@ -266,8 +248,7 @@ attributes:
still return ``None``.
.. versionchanged:: 3.3
- This function is now based directly on :mod:`importlib` rather than the
- deprecated :func:`getmoduleinfo`.
+ The function is based directly on :mod:`importlib`.
.. function:: ismodule(object)
@@ -646,6 +627,16 @@ function.
The name of the parameter as a string. The name must be a valid
Python identifier.
+ .. impl-detail::
+
+ CPython generates implicit parameter names of the form ``.0`` on the
+ code objects used to implement comprehensions and generator
+ expressions.
+
+ .. versionchanged:: 3.6
+ These parameter names are exposed by this module as names like
+ ``implicit0``.
+
.. attribute:: Parameter.default
The default value for the parameter. If the parameter has no default
@@ -854,8 +845,6 @@ Classes and functions
from kwonlyargs to defaults. *annotations* is a dictionary mapping argument
names to annotations.
- The first four items in the tuple correspond to :func:`getargspec`.
-
.. versionchanged:: 3.4
This function is now based on :func:`signature`, but still ignores
``__wrapped__`` attributes and includes the already bound first
@@ -884,7 +873,7 @@ Classes and functions
.. function:: formatargspec(args[, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations[, formatarg, formatvarargs, formatvarkw, formatvalue, formatreturns, formatannotations]])
Format a pretty argument spec from the values returned by
- :func:`getargspec` or :func:`getfullargspec`.
+ :func:`getfullargspec`.
The first seven arguments are (``args``, ``varargs``, ``varkw``,
``defaults``, ``kwonlyargs``, ``kwonlydefaults``, ``annotations``).
@@ -1264,20 +1253,29 @@ the following flags:
.. data:: CO_COROUTINE
- The flag is set when the code object is a coroutine function, i.e.
- a coroutine object is returned when the code object is executed. See
- :pep:`492` for more details.
+ The flag is set when the code object is a coroutine function.
+ When the code object is executed it returns a coroutine object.
+ See :pep:`492` for more details.
.. versionadded:: 3.5
.. data:: CO_ITERABLE_COROUTINE
- Used to turn generators into generator-based coroutines. Generator
- objects with this flag can be used in ``await`` expression, and can
- ``yield from`` coroutine objects. See :pep:`492` for more details.
+ The flag is used to transform generators into generator-based
+ coroutines. Generator objects with this flag can be used in
+ ``await`` expression, and can ``yield from`` coroutine objects.
+ See :pep:`492` for more details.
.. versionadded:: 3.5
+.. data:: CO_ASYNC_GENERATOR
+
+ The flag is set when the code object is an asynchronous generator
+ function. When the code object is executed it returns an
+ asynchronous generator object. See :pep:`525` for more details.
+
+ .. versionadded:: 3.6
+
.. note::
The flags are specific to CPython, and may not be defined in other
Python implementations. Furthermore, the flags are an implementation
@@ -1286,7 +1284,6 @@ the following flags:
for any introspection needs.
-
.. _inspect-module-cli:
Command Line Interface
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index dfc1ddc..b0d0a8c 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -591,7 +591,13 @@ loops that truncate the stream.
.. function:: tee(iterable, n=2)
- Return *n* independent iterators from a single iterable. Roughly equivalent to::
+ Return *n* independent iterators from a single iterable.
+
+ The following Python code helps explain what *tee* does (although the actual
+ implementation is more complex and uses only a single underlying
+ :abbr:`FIFO (first-in, first-out)` queue).
+
+ Roughly equivalent to::
def tee(iterable, n=2):
it = iter(iterable)
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
index c1a52a7..033e3fc 100644
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -126,7 +126,7 @@ See :ref:`json-commandline` for detailed documentation.
Basic Usage
-----------
-.. function:: dump(obj, fp, skipkeys=False, ensure_ascii=True, \
+.. function:: dump(obj, fp, *, skipkeys=False, ensure_ascii=True, \
check_circular=True, allow_nan=True, cls=None, \
indent=None, separators=None, default=None, \
sort_keys=False, **kw)
@@ -187,8 +187,11 @@ Basic Usage
:meth:`default` method to serialize additional types), specify it with the
*cls* kwarg; otherwise :class:`JSONEncoder` is used.
+ .. versionchanged:: 3.6
+ All optional parameters are now :ref:`keyword-only <keyword-only_parameter>`.
-.. function:: dumps(obj, skipkeys=False, ensure_ascii=True, \
+
+.. function:: dumps(obj, *, skipkeys=False, ensure_ascii=True, \
check_circular=True, allow_nan=True, cls=None, \
indent=None, separators=None, default=None, \
sort_keys=False, **kw)
@@ -212,7 +215,7 @@ Basic Usage
the original one. That is, ``loads(dumps(x)) != x`` if x has non-string
keys.
-.. function:: load(fp, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
+.. function:: load(fp, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Deserialize *fp* (a ``.read()``-supporting :term:`file-like object`
containing a JSON document) to a Python object using this :ref:`conversion
@@ -260,10 +263,14 @@ Basic Usage
If the data being deserialized is not a valid JSON document, a
:exc:`JSONDecodeError` will be raised.
-.. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
+ .. versionchanged:: 3.6
+ All optional parameters are now :ref:`keyword-only <keyword-only_parameter>`.
+
+.. function:: loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
- Deserialize *s* (a :class:`str` instance containing a JSON document) to a
- Python object using this :ref:`conversion table <json-to-py-table>`.
+ Deserialize *s* (a :class:`str`, :class:`bytes` or :class:`bytearray`
+ instance containing a JSON document) to a Python object using this
+ :ref:`conversion table <json-to-py-table>`.
The other arguments have the same meaning as in :func:`load`, except
*encoding* which is ignored and deprecated.
@@ -274,7 +281,7 @@ Basic Usage
Encoders and Decoders
---------------------
-.. class:: JSONDecoder(object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)
+.. class:: JSONDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)
Simple JSON decoder.
@@ -344,6 +351,9 @@ Encoders and Decoders
If the data being deserialized is not a valid JSON document, a
:exc:`JSONDecodeError` will be raised.
+ .. versionchanged:: 3.6
+ All parameters are now :ref:`keyword-only <keyword-only_parameter>`.
+
.. method:: decode(s)
Return the Python representation of *s* (a :class:`str` instance
@@ -362,7 +372,7 @@ Encoders and Decoders
extraneous data at the end.
-.. class:: JSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
+.. class:: JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Extensible JSON encoder for Python data structures.
@@ -443,6 +453,9 @@ Encoders and Decoders
the object or raise a :exc:`TypeError`. If not specified, :exc:`TypeError`
is raised.
+ .. versionchanged:: 3.6
+ All parameters are now :ref:`keyword-only <keyword-only_parameter>`.
+
.. method:: default(o)
diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst
index 0c02d3d..6be3279 100644
--- a/Doc/library/logging.handlers.rst
+++ b/Doc/library/logging.handlers.rst
@@ -84,6 +84,9 @@ sends logging output to a disk file. It inherits the output functionality from
with that encoding. If *delay* is true, then file opening is deferred until the
first call to :meth:`emit`. By default, the file grows indefinitely.
+ .. versionchanged:: 3.6
+ As well as string values, :class:`~pathlib.Path` objects are also accepted
+ for the *filename* argument.
.. method:: close()
@@ -160,12 +163,23 @@ for this value.
with that encoding. If *delay* is true, then file opening is deferred until the
first call to :meth:`emit`. By default, the file grows indefinitely.
+ .. versionchanged:: 3.6
+ As well as string values, :class:`~pathlib.Path` objects are also accepted
+ for the *filename* argument.
+
+ .. method:: reopenIfNeeded()
+
+ Checks to see if the file has changed. If it has, the existing stream is
+ flushed and closed and the file opened again, typically as a precursor to
+ outputting the record to the file.
+
+ .. versionadded:: 3.6
+
.. method:: emit(record)
- Outputs the record to the file, but first checks to see if the file has
- changed. If it has, the existing stream is flushed and closed and the
- file opened again, before outputting the record to the file.
+ Outputs the record to the file, but first calls :meth:`reopenIfNeeded` to
+ reopen the file if it has changed.
.. _base-rotating-handler:
@@ -279,6 +293,9 @@ module, supports rotation of disk log files.
:file:`app.log.2`, etc. exist, then they are renamed to :file:`app.log.2`,
:file:`app.log.3` etc. respectively.
+ .. versionchanged:: 3.6
+ As well as string values, :class:`~pathlib.Path` objects are also accepted
+ for the *filename* argument.
.. method:: doRollover()
@@ -310,21 +327,24 @@ timed intervals.
You can use the *when* to specify the type of *interval*. The list of possible
values is below. Note that they are not case sensitive.
- +----------------+-----------------------+
- | Value | Type of interval |
- +================+=======================+
- | ``'S'`` | Seconds |
- +----------------+-----------------------+
- | ``'M'`` | Minutes |
- +----------------+-----------------------+
- | ``'H'`` | Hours |
- +----------------+-----------------------+
- | ``'D'`` | Days |
- +----------------+-----------------------+
- | ``'W0'-'W6'`` | Weekday (0=Monday) |
- +----------------+-----------------------+
- | ``'midnight'`` | Roll over at midnight |
- +----------------+-----------------------+
+ +----------------+----------------------------+-------------------------+
+ | Value | Type of interval | If/how *atTime* is used |
+ +================+============================+=========================+
+ | ``'S'`` | Seconds | Ignored |
+ +----------------+----------------------------+-------------------------+
+ | ``'M'`` | Minutes | Ignored |
+ +----------------+----------------------------+-------------------------+
+ | ``'H'`` | Hours | Ignored |
+ +----------------+----------------------------+-------------------------+
+ | ``'D'`` | Days | Ignored |
+ +----------------+----------------------------+-------------------------+
+ | ``'W0'-'W6'`` | Weekday (0=Monday) | Used to compute initial |
+ | | | rollover time |
+ +----------------+----------------------------+-------------------------+
+ | ``'midnight'`` | Roll over at midnight, if | Used to compute initial |
+ | | *atTime* not specified, | rollover time |
+ | | else at time *atTime* | |
+ +----------------+----------------------------+-------------------------+
When using weekday-based rotation, specify 'W0' for Monday, 'W1' for
Tuesday, and so on up to 'W6' for Sunday. In this case, the value passed for
@@ -352,16 +372,35 @@ timed intervals.
If *atTime* is not ``None``, it must be a ``datetime.time`` instance which
specifies the time of day when rollover occurs, for the cases where rollover
- is set to happen "at midnight" or "on a particular weekday".
+ is set to happen "at midnight" or "on a particular weekday". Note that in
+ these cases, the *atTime* value is effectively used to compute the *initial*
+ rollover, and subsequent rollovers would be calculated via the normal
+ interval calculation.
+
+ .. note:: Calculation of the initial rollover time is done when the handler
+ is initialised. Calculation of subsequent rollover times is done only
+ when rollover occurs, and rollover occurs only when emitting output. If
+ this is not kept in mind, it might lead to some confusion. For example,
+ if an interval of "every minute" is set, that does not mean you will
+ always see log files with times (in the filename) separated by a minute;
+ if, during application execution, logging output is generated more
+ frequently than once a minute, *then* you can expect to see log files
+ with times separated by a minute. If, on the other hand, logging messages
+ are only output once every five minutes (say), then there will be gaps in
+ the file times corresponding to the minutes where no output (and hence no
+ rollover) occurred.
.. versionchanged:: 3.4
*atTime* parameter was added.
+ .. versionchanged:: 3.6
+ As well as string values, :class:`~pathlib.Path` objects are also accepted
+ for the *filename* argument.
+
.. method:: doRollover()
Does a rollover, as described above.
-
.. method:: emit(record)
Outputs the record to the file, catering for rollover as described above.
@@ -798,12 +837,18 @@ should, then :meth:`flush` is expected to do the flushing.
overridden to implement custom flushing strategies.
-.. class:: MemoryHandler(capacity, flushLevel=ERROR, target=None)
+.. class:: MemoryHandler(capacity, flushLevel=ERROR, target=None, flushOnClose=True)
Returns a new instance of the :class:`MemoryHandler` class. The instance is
initialized with a buffer size of *capacity*. If *flushLevel* is not specified,
:const:`ERROR` is used. If no *target* is specified, the target will need to be
- set using :meth:`setTarget` before this handler does anything useful.
+ set using :meth:`setTarget` before this handler does anything useful. If
+ *flushOnClose* is specified as ``False``, then the buffer is *not* flushed when
+ the handler is closed. If not specified or specified as ``True``, the previous
+ behaviour of flushing the buffer will occur when the handler is closed.
+
+ .. versionchanged:: 3.6
+ The *flushOnClose* parameter was added.
.. method:: close()
diff --git a/Doc/library/lzma.rst b/Doc/library/lzma.rst
index 61b3ba3..5edb23d 100644
--- a/Doc/library/lzma.rst
+++ b/Doc/library/lzma.rst
@@ -39,8 +39,9 @@ Reading and writing compressed files
object`.
The *filename* argument can be either an actual file name (given as a
- :class:`str` or :class:`bytes` object), in which case the named file is
- opened, or it can be an existing file object to read from or write to.
+ :class:`str`, :class:`bytes` or :term:`path-like object` object), in
+ which case the named file is opened, or it can be an existing file object
+ to read from or write to.
The *mode* argument can be any of ``"r"``, ``"rb"``, ``"w"``, ``"wb"``,
``"x"``, ``"xb"``, ``"a"`` or ``"ab"`` for binary mode, or ``"rt"``,
@@ -64,6 +65,9 @@ Reading and writing compressed files
.. versionchanged:: 3.4
Added support for the ``"x"``, ``"xb"`` and ``"xt"`` modes.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. class:: LZMAFile(filename=None, mode="r", \*, format=None, check=-1, preset=None, filters=None)
@@ -71,9 +75,10 @@ Reading and writing compressed files
An :class:`LZMAFile` can wrap an already-open :term:`file object`, or operate
directly on a named file. The *filename* argument specifies either the file
- object to wrap, or the name of the file to open (as a :class:`str` or
- :class:`bytes` object). When wrapping an existing file object, the wrapped
- file will not be closed when the :class:`LZMAFile` is closed.
+ object to wrap, or the name of the file to open (as a :class:`str`,
+ :class:`bytes` or :term:`path-like object` object). When wrapping an
+ existing file object, the wrapped file will not be closed when the
+ :class:`LZMAFile` is closed.
The *mode* argument can be either ``"r"`` for reading (default), ``"w"`` for
overwriting, ``"x"`` for exclusive creation, or ``"a"`` for appending. These
@@ -118,6 +123,9 @@ Reading and writing compressed files
The :meth:`~io.BufferedIOBase.read` method now accepts an argument of
``None``.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
Compressing and decompressing data in memory
--------------------------------------------
diff --git a/Doc/library/math.rst b/Doc/library/math.rst
index 3fdea18..da2b8cc 100644
--- a/Doc/library/math.rst
+++ b/Doc/library/math.rst
@@ -426,6 +426,15 @@ Constants
The mathematical constant e = 2.718281..., to available precision.
+.. data:: tau
+
+ The mathematical constant τ = 6.283185..., to available precision.
+ Tau is a circle constant equal to 2π, the ratio of a circle's circumference to
+ its radius. To learn more about Tau, check out Vi Hart's video `Pi is (still)
+ Wrong <https://www.youtube.com/watch?v=jG7vhMMXagQ>`_, and start celebrating
+ `Tau day <http://tauday.com/>`_ by eating twice as much pie!
+
+ .. versionadded:: 3.6
.. data:: inf
diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst
index f4a6f53..6e6e290 100644
--- a/Doc/library/mmap.rst
+++ b/Doc/library/mmap.rst
@@ -264,13 +264,18 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
.. method:: write(bytes)
Write the bytes in *bytes* into memory at the current position of the
- file pointer; the file position is updated to point after the bytes that
- were written. If the mmap was created with :const:`ACCESS_READ`, then
+ file pointer and return the number of bytes written (never less than
+ ``len(bytes)``, since if the write fails, a :exc:`ValueError` will be
+ raised). The file position is updated to point after the bytes that
+ were written. If the mmap was created with :const:`ACCESS_READ`, then
writing to it will raise a :exc:`TypeError` exception.
.. versionchanged:: 3.5
Writable :term:`bytes-like object` is now accepted.
+ .. versionchanged:: 3.6
+ The number of bytes written is now returned.
+
.. method:: write_byte(byte)
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst
index d45bc20..96d1424 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -650,8 +650,9 @@ primitives like locks.
For passing messages one can use :func:`Pipe` (for a connection between two
processes) or a queue (which allows multiple producers and consumers).
-The :class:`Queue`, :class:`SimpleQueue` and :class:`JoinableQueue` types are multi-producer,
-multi-consumer FIFO queues modelled on the :class:`queue.Queue` class in the
+The :class:`Queue`, :class:`SimpleQueue` and :class:`JoinableQueue` types
+are multi-producer, multi-consumer :abbr:`FIFO (first-in, first-out)`
+queues modelled on the :class:`queue.Queue` class in the
standard library. They differ in that :class:`Queue` lacks the
:meth:`~queue.Queue.task_done` and :meth:`~queue.Queue.join` methods introduced
into Python 2.5's :class:`queue.Queue` class.
@@ -889,8 +890,13 @@ Miscellaneous
.. function:: cpu_count()
- Return the number of CPUs in the system. May raise
- :exc:`NotImplementedError`.
+ Return the number of CPUs in the system.
+
+ This number is not equivalent to the number of CPUs the current process can
+ use. The number of usable CPUs can be obtained with
+ ``len(os.sched_getaffinity(0))``
+
+ May raise :exc:`NotImplementedError`.
.. seealso::
:func:`os.cpu_count`
@@ -1679,7 +1685,9 @@ their parent process exits. The manager classes are defined in the
of processes. Objects of this type are returned by
:func:`multiprocessing.Manager`.
- It also supports creation of shared lists and dictionaries.
+ Its methods create and return :ref:`multiprocessing-proxy_objects` for a
+ number of commonly used data types to be synchronized across processes.
+ This notably includes shared lists and dictionaries.
.. method:: Barrier(parties[, action[, timeout]])
@@ -1742,31 +1750,17 @@ their parent process exits. The manager classes are defined in the
dict(mapping)
dict(sequence)
- Create a shared ``dict`` object and return a proxy for it.
+ Create a shared :class:`dict` object and return a proxy for it.
.. method:: list()
list(sequence)
- Create a shared ``list`` object and return a proxy for it.
-
- .. note::
-
- Modifications to mutable values or items in dict and list proxies will not
- be propagated through the manager, because the proxy has no way of knowing
- when its values or items are modified. To modify such an item, you can
- re-assign the modified object to the container proxy::
-
- # create a list proxy and append a mutable object (a dictionary)
- lproxy = manager.list()
- lproxy.append({})
- # now mutate the dictionary
- d = lproxy[0]
- d['a'] = 1
- d['b'] = 2
- # at this point, the changes to d are not yet synced, but by
- # reassigning the dictionary, the proxy is notified of the change
- lproxy[0] = d
+ Create a shared :class:`list` object and return a proxy for it.
+ .. versionchanged:: 3.6
+ Shared objects are capable of being nested. For example, a shared
+ container object such as a shared list can contain other shared objects
+ which will all be managed and synchronized by the :class:`SyncManager`.
.. class:: Namespace
@@ -1878,6 +1872,8 @@ client to access it remotely::
>>> s = m.get_server()
>>> s.serve_forever()
+.. _multiprocessing-proxy_objects:
+
Proxy Objects
~~~~~~~~~~~~~
@@ -1887,8 +1883,7 @@ proxy. Multiple proxy objects may have the same referent.
A proxy object has methods which invoke corresponding methods of its referent
(although not every method of the referent will necessarily be available through
-the proxy). A proxy can usually be used in most of the same ways that its
-referent can:
+the proxy). In this way, a proxy can be used just like its referent can:
.. doctest::
@@ -1909,9 +1904,9 @@ the referent, whereas applying :func:`repr` will return the representation of
the proxy.
An important feature of proxy objects is that they are picklable so they can be
-passed between processes. Note, however, that if a proxy is sent to the
-corresponding manager's process then unpickling it will produce the referent
-itself. This means, for example, that one shared object can contain a second:
+passed between processes. As such, a referent can contain
+:ref:`multiprocessing-proxy_objects`. This permits nesting of these managed
+lists, dicts, and other :ref:`multiprocessing-proxy_objects`:
.. doctest::
@@ -1919,10 +1914,46 @@ itself. This means, for example, that one shared object can contain a second:
>>> b = manager.list()
>>> a.append(b) # referent of a now contains referent of b
>>> print(a, b)
- [[]] []
+ [<ListProxy object, typeid 'list' at ...>] []
>>> b.append('hello')
- >>> print(a, b)
- [['hello']] ['hello']
+ >>> print(a[0], b)
+ ['hello'] ['hello']
+
+Similarly, dict and list proxies may be nested inside one another::
+
+ >>> l_outer = manager.list([ manager.dict() for i in range(2) ])
+ >>> d_first_inner = l_outer[0]
+ >>> d_first_inner['a'] = 1
+ >>> d_first_inner['b'] = 2
+ >>> l_outer[1]['c'] = 3
+ >>> l_outer[1]['z'] = 26
+ >>> print(l_outer[0])
+ {'a': 1, 'b': 2}
+ >>> print(l_outer[1])
+ {'c': 3, 'z': 26}
+
+If standard (non-proxy) :class:`list` or :class:`dict` objects are contained
+in a referent, modifications to those mutable values will not be propagated
+through the manager because the proxy has no way of knowing when the values
+contained within are modified. However, storing a value in a container proxy
+(which triggers a ``__setitem__`` on the proxy object) does propagate through
+the manager and so to effectively modify such an item, one could re-assign the
+modified value to the container proxy::
+
+ # create a list proxy and append a mutable object (a dictionary)
+ lproxy = manager.list()
+ lproxy.append({})
+ # now mutate the dictionary
+ d = lproxy[0]
+ d['a'] = 1
+ d['b'] = 2
+ # at this point, the changes to d are not yet synced, but by
+ # updating the dictionary, the proxy is notified of the change
+ lproxy[0] = d
+
+This approach is perhaps less convenient than employing nested
+:ref:`multiprocessing-proxy_objects` for most use cases but also
+demonstrates a level of control over the synchronization.
.. note::
diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst
index bf0dfac..406054e 100644
--- a/Doc/library/os.path.rst
+++ b/Doc/library/os.path.rst
@@ -61,6 +61,9 @@ the :mod:`glob` module.)
platforms, this is equivalent to calling the function :func:`normpath` as
follows: ``normpath(join(os.getcwd(), path))``.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: basename(path)
@@ -71,6 +74,9 @@ the :mod:`glob` module.)
``'/foo/bar/'`` returns ``'bar'``, the :func:`basename` function returns an
empty string (``''``).
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: commonpath(paths)
@@ -83,6 +89,9 @@ the :mod:`glob` module.)
.. versionadded:: 3.5
+ .. versionchanged:: 3.6
+ Accepts a sequence of :term:`path-like objects <path-like object>`.
+
.. function:: commonprefix(list)
@@ -104,12 +113,18 @@ the :mod:`glob` module.)
>>> os.path.commonpath(['/usr/lib', '/usr/local/lib'])
'/usr'
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: dirname(path)
Return the directory name of pathname *path*. This is the first element of
the pair returned by passing *path* to the function :func:`split`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: exists(path)
@@ -123,6 +138,9 @@ the :mod:`glob` module.)
*path* can now be an integer: ``True`` is returned if it is an
open file descriptor, ``False`` otherwise.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: lexists(path)
@@ -130,6 +148,9 @@ the :mod:`glob` module.)
broken symbolic links. Equivalent to :func:`exists` on platforms lacking
:func:`os.lstat`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: expanduser(path)
@@ -151,6 +172,9 @@ the :mod:`glob` module.)
If the expansion fails or if the path does not begin with a tilde, the path is
returned unchanged.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: expandvars(path)
@@ -162,6 +186,9 @@ the :mod:`glob` module.)
On Windows, ``%name%`` expansions are supported in addition to ``$name`` and
``${name}``.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: getatime(path)
@@ -182,6 +209,9 @@ the :mod:`glob` module.)
If :func:`os.stat_float_times` returns ``True``, the result is a floating point
number.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: getctime(path)
@@ -191,12 +221,18 @@ the :mod:`glob` module.)
the :mod:`time` module). Raise :exc:`OSError` if the file does not exist or
is inaccessible.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: getsize(path)
Return the size, in bytes, of *path*. Raise :exc:`OSError` if the file does
not exist or is inaccessible.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: isabs(path)
@@ -204,24 +240,36 @@ the :mod:`glob` module.)
begins with a slash, on Windows that it begins with a (back)slash after chopping
off a potential drive letter.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: isfile(path)
Return ``True`` if *path* is an existing regular file. This follows symbolic
links, so both :func:`islink` and :func:`isfile` can be true for the same path.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: isdir(path)
Return ``True`` if *path* is an existing directory. This follows symbolic
links, so both :func:`islink` and :func:`isdir` can be true for the same path.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: islink(path)
Return ``True`` if *path* refers to a directory entry that is a symbolic link.
Always ``False`` if symbolic links are not supported by the Python runtime.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: ismount(path)
@@ -237,6 +285,9 @@ the :mod:`glob` module.)
.. versionadded:: 3.4
Support for detecting non-root mount points on Windows.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: join(path, *paths)
@@ -255,13 +306,20 @@ the :mod:`glob` module.)
``os.path.join("c:", "foo")`` represents a path relative to the current
directory on drive :file:`C:` (:file:`c:foo`), not :file:`c:\\foo`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *path* and *paths*.
+
.. function:: normcase(path)
Normalize the case of a pathname. On Unix and Mac OS X, this returns the
path unchanged; on case-insensitive filesystems, it converts the path to
lowercase. On Windows, it also converts forward slashes to backward slashes.
- Raise a TypeError if the type of *path* is not ``str`` or ``bytes``.
+ Raise a TypeError if the type of *path* is not ``str`` or ``bytes`` (directly
+ or indirectly through the :class:`os.PathLike` interface).
+
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
.. function:: normpath(path)
@@ -272,12 +330,18 @@ the :mod:`glob` module.)
that contains symbolic links. On Windows, it converts forward slashes to
backward slashes. To normalize case, use :func:`normcase`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: realpath(path)
Return the canonical path of the specified filename, eliminating any symbolic
links encountered in the path (if they are supported by the operating system).
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: relpath(path, start=os.curdir)
@@ -290,6 +354,9 @@ the :mod:`glob` module.)
Availability: Unix, Windows.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: samefile(path1, path2)
@@ -305,6 +372,9 @@ the :mod:`glob` module.)
.. versionchanged:: 3.4
Windows now uses the same implementation as all other platforms.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: sameopenfile(fp1, fp2)
@@ -315,6 +385,9 @@ the :mod:`glob` module.)
.. versionchanged:: 3.2
Added Windows support.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: samestat(stat1, stat2)
@@ -328,6 +401,9 @@ the :mod:`glob` module.)
.. versionchanged:: 3.4
Added Windows support.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: split(path)
@@ -341,6 +417,9 @@ the :mod:`glob` module.)
(but the strings may differ). Also see the functions :func:`dirname` and
:func:`basename`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: splitdrive(path)
@@ -359,6 +438,9 @@ the :mod:`glob` module.)
and share, up to but not including the fourth separator.
e.g. ``splitdrive("//host/computer/dir")`` returns ``("//host/computer", "/dir")``
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: splitext(path)
@@ -367,6 +449,9 @@ the :mod:`glob` module.)
period. Leading periods on the basename are ignored; ``splitext('.cshrc')``
returns ``('.cshrc', '')``.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: splitunc(path)
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 5a67f93..3260cdc 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -57,7 +57,7 @@ Notes on the availability of these functions:
The name of the operating system dependent module imported. The following
names have currently been registered: ``'posix'``, ``'nt'``,
- ``'ce'``, ``'java'``.
+ ``'java'``.
.. seealso::
:attr:`sys.platform` has a finer granularity. :func:`os.uname` gives
@@ -171,23 +171,60 @@ process and user.
.. function:: fsencode(filename)
- Encode *filename* to the filesystem encoding with ``'surrogateescape'``
- error handler, or ``'strict'`` on Windows; return :class:`bytes` unchanged.
+ Encode :term:`path-like <path-like object>` *filename* to the filesystem
+ encoding with ``'surrogateescape'`` error handler, or ``'strict'`` on
+ Windows; return :class:`bytes` unchanged.
:func:`fsdecode` is the reverse function.
.. versionadded:: 3.2
+ .. versionchanged:: 3.6
+ Support added to accept objects implementing the :class:`os.PathLike`
+ interface.
+
.. function:: fsdecode(filename)
- Decode *filename* from the filesystem encoding with ``'surrogateescape'``
- error handler, or ``'strict'`` on Windows; return :class:`str` unchanged.
+ Decode the :term:`path-like <path-like object>` *filename* from the
+ filesystem encoding with ``'surrogateescape'`` error handler, or ``'strict'``
+ on Windows; return :class:`str` unchanged.
:func:`fsencode` is the reverse function.
.. versionadded:: 3.2
+ .. versionchanged:: 3.6
+ Support added to accept objects implementing the :class:`os.PathLike`
+ interface.
+
+
+.. function:: fspath(path)
+
+ Return the file system representation of the path.
+
+ If :class:`str` or :class:`bytes` is passed in, it is returned unchanged.
+ Otherwise :meth:`~os.PathLike.__fspath__` is called and its value is
+ returned as long as it is a :class:`str` or :class:`bytes` object.
+ In all other cases, :exc:`TypeError` is raised.
+
+ .. versionadded:: 3.6
+
+
+.. class:: PathLike
+
+ An :term:`abstract base class` for objects representing a file system path,
+ e.g. :class:`pathlib.PurePath`.
+
+ .. versionadded:: 3.6
+
+ .. abstractmethod:: __fspath__()
+
+ Return the file system path representation of the object.
+
+ The method should only return a :class:`str` or :class:`bytes` object,
+ with the preference being for :class:`str`.
+
.. function:: getenv(key, default=None)
@@ -896,6 +933,9 @@ as internal buffering of data.
exception, the function now retries the system call instead of raising an
:exc:`InterruptedError` exception (see :pep:`475` for the rationale).
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
The following constants are options for the *flags* parameter to the
:func:`~os.open` function. They can be combined using the bitwise OR operator
``|``. Some of them are not available on all platforms. For descriptions of
@@ -1392,6 +1432,9 @@ features:
.. versionchanged:: 3.3
Added the *dir_fd*, *effective_ids*, and *follow_symlinks* parameters.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. data:: F_OK
R_OK
@@ -1416,6 +1459,9 @@ features:
Added support for specifying *path* as a file descriptor
on some platforms.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: chflags(path, flags, *, follow_symlinks=True)
@@ -1442,6 +1488,9 @@ features:
.. versionadded:: 3.3
The *follow_symlinks* argument.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: chmod(path, mode, *, dir_fd=None, follow_symlinks=True)
@@ -1483,6 +1532,9 @@ features:
Added support for specifying *path* as an open file descriptor,
and the *dir_fd* and *follow_symlinks* arguments.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: chown(path, uid, gid, *, dir_fd=None, follow_symlinks=True)
@@ -1502,6 +1554,9 @@ features:
Added support for specifying an open file descriptor for *path*,
and the *dir_fd* and *follow_symlinks* arguments.
+ .. versionchanged:: 3.6
+ Supports a :term:`path-like object`.
+
.. function:: chroot(path)
@@ -1509,6 +1564,9 @@ features:
Availability: Unix.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: fchdir(fd)
@@ -1537,6 +1595,9 @@ features:
Availability: Unix.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: lchmod(path, mode)
@@ -1547,6 +1608,8 @@ features:
Availability: Unix.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
.. function:: lchown(path, uid, gid)
@@ -1556,6 +1619,9 @@ features:
Availability: Unix.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: link(src, dst, *, src_dir_fd=None, dst_dir_fd=None, follow_symlinks=True)
@@ -1573,6 +1639,9 @@ features:
.. versionadded:: 3.3
Added the *src_dir_fd*, *dst_dir_fd*, and *follow_symlinks* arguments.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *src* and *dst*.
+
.. function:: listdir(path='.')
@@ -1580,8 +1649,9 @@ features:
*path*. The list is in arbitrary order, and does not include the special
entries ``'.'`` and ``'..'`` even if they are present in the directory.
- *path* may be either of type ``str`` or of type ``bytes``. If *path*
- is of type ``bytes``, the filenames returned will also be of type ``bytes``;
+ *path* may be a :term:`path-like object`. If *path* is of type ``bytes``
+ (directly or indirectly through the :class:`PathLike` interface),
+ the filenames returned will also be of type ``bytes``;
in all other circumstances, they will be of type ``str``.
This function can also support :ref:`specifying a file descriptor
@@ -1602,6 +1672,9 @@ features:
.. versionadded:: 3.3
Added support for specifying an open file descriptor for *path*.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: lstat(path, \*, dir_fd=None)
@@ -1628,6 +1701,9 @@ features:
.. versionchanged:: 3.3
Added the *dir_fd* parameter.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *src* and *dst*.
+
.. function:: mkdir(path, mode=0o777, *, dir_fd=None)
@@ -1652,6 +1728,9 @@ features:
.. versionadded:: 3.3
The *dir_fd* argument.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: makedirs(name, mode=0o777, exist_ok=False)
@@ -1685,6 +1764,9 @@ features:
mode of the existing directory. Since this behavior was impossible to
implement safely, it was removed in Python 3.4.1. See :issue:`21082`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: mkfifo(path, mode=0o666, *, dir_fd=None)
@@ -1705,6 +1787,9 @@ features:
.. versionadded:: 3.3
The *dir_fd* argument.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: mknod(path, mode=0o600, device=0, *, dir_fd=None)
@@ -1724,6 +1809,9 @@ features:
.. versionadded:: 3.3
The *dir_fd* argument.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: major(device)
@@ -1762,6 +1850,9 @@ features:
Availability: Unix.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. data:: pathconf_names
@@ -1779,9 +1870,10 @@ features:
may be converted to an absolute pathname using
``os.path.join(os.path.dirname(path), result)``.
- If the *path* is a string object, the result will also be a string object,
+ If the *path* is a string object (directly or indirectly through a
+ :class:`PathLike` interface), the result will also be a string object,
and the call may raise a UnicodeDecodeError. If the *path* is a bytes
- object, the result will be a bytes object.
+ object (direct or indirectly), the result will be a bytes object.
This function can also support :ref:`paths relative to directory descriptors
<dir_fd>`.
@@ -1794,6 +1886,9 @@ features:
.. versionadded:: 3.3
The *dir_fd* argument.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: remove(path, *, dir_fd=None)
@@ -1812,6 +1907,9 @@ features:
.. versionadded:: 3.3
The *dir_fd* argument.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: removedirs(name)
@@ -1826,6 +1924,9 @@ features:
they are empty. Raises :exc:`OSError` if the leaf directory could not be
successfully removed.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
@@ -1845,6 +1946,9 @@ features:
.. versionadded:: 3.3
The *src_dir_fd* and *dst_dir_fd* arguments.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *src* and *dst*.
+
.. function:: renames(old, new)
@@ -1858,6 +1962,9 @@ features:
This function can fail with the new directory structure made if you lack
permissions needed to remove the leaf directory or file.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *old* and *new*.
+
.. function:: replace(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
@@ -1872,6 +1979,9 @@ features:
.. versionadded:: 3.3
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *src* and *dst*.
+
.. function:: rmdir(path, *, dir_fd=None)
@@ -1885,38 +1995,58 @@ features:
.. versionadded:: 3.3
The *dir_fd* parameter.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: scandir(path='.')
- Return an iterator of :class:`DirEntry` objects corresponding to the entries
- in the directory given by *path*. The entries are yielded in arbitrary
- order, and the special entries ``'.'`` and ``'..'`` are not included.
+ Return an iterator of :class:`os.DirEntry` objects corresponding to the
+ entries in the directory given by *path*. The entries are yielded in
+ arbitrary order, and the special entries ``'.'`` and ``'..'`` are not
+ included.
Using :func:`scandir` instead of :func:`listdir` can significantly
increase the performance of code that also needs file type or file
- attribute information, because :class:`DirEntry` objects expose this
+ attribute information, because :class:`os.DirEntry` objects expose this
information if the operating system provides it when scanning a directory.
- All :class:`DirEntry` methods may perform a system call, but
- :func:`~DirEntry.is_dir` and :func:`~DirEntry.is_file` usually only
- require a system call for symbolic links; :func:`DirEntry.stat`
+ All :class:`os.DirEntry` methods may perform a system call, but
+ :func:`~os.DirEntry.is_dir` and :func:`~os.DirEntry.is_file` usually only
+ require a system call for symbolic links; :func:`os.DirEntry.stat`
always requires a system call on Unix but only requires one for
symbolic links on Windows.
- On Unix, *path* can be of type :class:`str` or :class:`bytes` (use
+ On Unix, *path* can be of type :class:`str` or :class:`bytes` (either
+ directly or indirectly through the :class:`PathLike` interface; use
:func:`~os.fsencode` and :func:`~os.fsdecode` to encode and decode
:class:`bytes` paths). On Windows, *path* must be of type :class:`str`.
- On both systems, the type of the :attr:`~DirEntry.name` and
- :attr:`~DirEntry.path` attributes of each :class:`DirEntry` will be of
+ On both systems, the type of the :attr:`~os.DirEntry.name` and
+ :attr:`~os.DirEntry.path` attributes of each :class:`os.DirEntry` will be of
the same type as *path*.
+ The :func:`scandir` iterator supports the :term:`context manager` protocol
+ and has the following method:
+
+ .. method:: scandir.close()
+
+ Close the iterator and free acquired resources.
+
+ This is called automatically when the iterator is exhausted or garbage
+ collected, or when an error happens during iterating. However it
+ is advisable to call it explicitly or use the :keyword:`with`
+ statement.
+
+ .. versionadded:: 3.6
+
The following example shows a simple use of :func:`scandir` to display all
the files (excluding directories) in the given *path* that don't start with
``'.'``. The ``entry.is_file()`` call will generally not make an additional
system call::
- for entry in os.scandir(path):
- if not entry.name.startswith('.') and entry.is_file():
- print(entry.name)
+ with os.scandir(path) as it:
+ for entry in it:
+ if not entry.name.startswith('.') and entry.is_file():
+ print(entry.name)
.. note::
@@ -1932,6 +2062,14 @@ features:
.. versionadded:: 3.5
+ .. versionadded:: 3.6
+ Added support for the :term:`context manager` protocol and the
+ :func:`~scandir.close()` method. If a :func:`scandir` iterator is neither
+ exhausted nor explicitly closed a :exc:`ResourceWarning` will be emitted
+ in its destructor.
+
+ The function accepts a :term:`path-like object`.
+
.. class:: DirEntry
@@ -1940,19 +2078,22 @@ features:
:func:`scandir` will provide as much of this information as possible without
making additional system calls. When a ``stat()`` or ``lstat()`` system call
- is made, the ``DirEntry`` object will cache the result.
+ is made, the ``os.DirEntry`` object will cache the result.
- ``DirEntry`` instances are not intended to be stored in long-lived data
+ ``os.DirEntry`` instances are not intended to be stored in long-lived data
structures; if you know the file metadata has changed or if a long time has
elapsed since calling :func:`scandir`, call ``os.stat(entry.path)`` to fetch
up-to-date information.
- Because the ``DirEntry`` methods can make operating system calls, they may
+ Because the ``os.DirEntry`` methods can make operating system calls, they may
also raise :exc:`OSError`. If you need very fine-grained
control over errors, you can catch :exc:`OSError` when calling one of the
- ``DirEntry`` methods and handle as appropriate.
+ ``os.DirEntry`` methods and handle as appropriate.
- Attributes and methods on a ``DirEntry`` instance are as follows:
+ To be directly usable as a :term:`path-like object`, ``os.DirEntry``
+ implements the :class:`PathLike` interface.
+
+ Attributes and methods on a ``os.DirEntry`` instance are as follows:
.. attribute:: name
@@ -1978,8 +2119,9 @@ features:
Return the inode number of the entry.
- The result is cached on the ``DirEntry`` object. Use ``os.stat(entry.path,
- follow_symlinks=False).st_ino`` to fetch up-to-date information.
+ The result is cached on the ``os.DirEntry`` object. Use
+ ``os.stat(entry.path, follow_symlinks=False).st_ino`` to fetch up-to-date
+ information.
On the first, uncached call, a system call is required on Windows but
not on Unix.
@@ -1994,7 +2136,7 @@ features:
is a directory (without following symlinks); return ``False`` if the
entry is any other kind of file or if it doesn't exist anymore.
- The result is cached on the ``DirEntry`` object, with a separate cache
+ The result is cached on the ``os.DirEntry`` object, with a separate cache
for *follow_symlinks* ``True`` and ``False``. Call :func:`os.stat` along
with :func:`stat.S_ISDIR` to fetch up-to-date information.
@@ -2018,8 +2160,8 @@ features:
is a file (without following symlinks); return ``False`` if the entry is
a directory or other non-file entry, or if it doesn't exist anymore.
- The result is cached on the ``DirEntry`` object. Caching, system calls
- made, and exceptions raised are as per :func:`~DirEntry.is_dir`.
+ The result is cached on the ``os.DirEntry`` object. Caching, system calls
+ made, and exceptions raised are as per :func:`~os.DirEntry.is_dir`.
.. method:: is_symlink()
@@ -2027,7 +2169,7 @@ features:
return ``False`` if the entry points to a directory or any kind of file,
or if it doesn't exist anymore.
- The result is cached on the ``DirEntry`` object. Call
+ The result is cached on the ``os.DirEntry`` object. Call
:func:`os.path.islink` to fetch up-to-date information.
On the first, uncached call, no system call is required in most cases.
@@ -2052,23 +2194,28 @@ features:
:class:`stat_result` are always set to zero. Call :func:`os.stat` to
get these attributes.
- The result is cached on the ``DirEntry`` object, with a separate cache
+ The result is cached on the ``os.DirEntry`` object, with a separate cache
for *follow_symlinks* ``True`` and ``False``. Call :func:`os.stat` to
fetch up-to-date information.
Note that there is a nice correspondence between several attributes
- and methods of ``DirEntry`` and of :class:`pathlib.Path`. In
- particular, the ``name`` attribute has the same meaning, as do the
- ``is_dir()``, ``is_file()``, ``is_symlink()`` and ``stat()`` methods.
+ and methods of ``os.DirEntry`` and of :class:`pathlib.Path`. In
+ particular, the ``name`` attribute has the same
+ meaning, as do the ``is_dir()``, ``is_file()``, ``is_symlink()``
+ and ``stat()`` methods.
.. versionadded:: 3.5
+ .. versionchanged:: 3.6
+ Added support for the :class:`~os.PathLike` interface.
+
.. function:: stat(path, \*, dir_fd=None, follow_symlinks=True)
Get the status of a file or a file descriptor. Perform the equivalent of a
:c:func:`stat` system call on the given path. *path* may be specified as
- either a string or as an open file descriptor. Return a :class:`stat_result`
+ either a string -- directly or indirectly through the :class:`PathLike`
+ interface -- or as an open file descriptor. Return a :class:`stat_result`
object.
This function normally follows symlinks; to stat a symlink add the argument
@@ -2098,6 +2245,9 @@ features:
Added the *dir_fd* and *follow_symlinks* arguments, specifying a file
descriptor instead of a path.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. class:: stat_result
@@ -2319,19 +2469,22 @@ features:
This function can support :ref:`specifying a file descriptor <path_fd>`.
+ Availability: Unix.
+
.. versionchanged:: 3.2
The :const:`ST_RDONLY` and :const:`ST_NOSUID` constants were added.
+ .. versionadded:: 3.3
+ Added support for specifying an open file descriptor for *path*.
+
.. versionchanged:: 3.4
The :const:`ST_NODEV`, :const:`ST_NOEXEC`, :const:`ST_SYNCHRONOUS`,
:const:`ST_MANDLOCK`, :const:`ST_WRITE`, :const:`ST_APPEND`,
:const:`ST_IMMUTABLE`, :const:`ST_NOATIME`, :const:`ST_NODIRATIME`,
and :const:`ST_RELATIME` constants were added.
- Availability: Unix.
-
- .. versionadded:: 3.3
- Added support for specifying an open file descriptor for *path*.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
.. data:: supports_dir_fd
@@ -2452,6 +2605,9 @@ features:
Added the *dir_fd* argument, and now allow *target_is_directory*
on non-Windows platforms.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *src* and *dst*.
+
.. function:: sync()
@@ -2476,6 +2632,10 @@ features:
.. versionchanged:: 3.5
Added support for Windows
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
+
.. function:: unlink(path, *, dir_fd=None)
Remove (delete) the file *path*. This function is semantically
@@ -2486,6 +2646,9 @@ features:
.. versionadded:: 3.3
The *dir_fd* parameter.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: utime(path, times=None, *[, ns], dir_fd=None, follow_symlinks=True)
@@ -2523,6 +2686,9 @@ features:
Added support for specifying an open file descriptor for *path*,
and the *dir_fd*, *follow_symlinks*, and *ns* parameters.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: walk(top, topdown=True, onerror=None, followlinks=False)
@@ -2613,6 +2779,9 @@ features:
This function now calls :func:`os.scandir` instead of :func:`os.listdir`,
making it faster by reducing the number of calls to :func:`os.stat`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: fwalk(top='.', topdown=True, onerror=None, *, follow_symlinks=False, dir_fd=None)
@@ -2669,6 +2838,9 @@ features:
.. versionadded:: 3.3
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
Linux extended attributes
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2680,12 +2852,16 @@ These functions are all available on Linux only.
.. function:: getxattr(path, attribute, *, follow_symlinks=True)
Return the value of the extended filesystem attribute *attribute* for
- *path*. *attribute* can be bytes or str. If it is str, it is encoded
- with the filesystem encoding.
+ *path*. *attribute* can be bytes or str (directly or indirectly through the
+ :class:`PathLike` interface). If it is str, it is encoded with the filesystem
+ encoding.
This function can support :ref:`specifying a file descriptor <path_fd>` and
:ref:`not following symlinks <follow_symlinks>`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` fpr *path* and *attribute*.
+
.. function:: listxattr(path=None, *, follow_symlinks=True)
@@ -2697,21 +2873,29 @@ These functions are all available on Linux only.
This function can support :ref:`specifying a file descriptor <path_fd>` and
:ref:`not following symlinks <follow_symlinks>`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: removexattr(path, attribute, *, follow_symlinks=True)
Removes the extended filesystem attribute *attribute* from *path*.
- *attribute* should be bytes or str. If it is a string, it is encoded
+ *attribute* should be bytes or str (directly or indirectly through the
+ :class:`PathLike` interface). If it is a string, it is encoded
with the filesystem encoding.
This function can support :ref:`specifying a file descriptor <path_fd>` and
:ref:`not following symlinks <follow_symlinks>`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *path* and *attribute*.
+
.. function:: setxattr(path, attribute, value, flags=0, *, follow_symlinks=True)
Set the extended filesystem attribute *attribute* on *path* to *value*.
- *attribute* must be a bytes or str with no embedded NULs. If it is a str,
+ *attribute* must be a bytes or str with no embedded NULs (directly or
+ indirectly through the :class:`PathLike` interface). If it is a str,
it is encoded with the filesystem encoding. *flags* may be
:data:`XATTR_REPLACE` or :data:`XATTR_CREATE`. If :data:`XATTR_REPLACE` is
given and the attribute does not exist, ``EEXISTS`` will be raised.
@@ -2726,6 +2910,9 @@ These functions are all available on Linux only.
A bug in Linux kernel versions less than 2.6.39 caused the flags argument
to be ignored on some filesystems.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object` for *path* and *attribute*.
+
.. data:: XATTR_SIZE_MAX
@@ -2827,6 +3014,9 @@ to be ignored.
Added support for specifying an open file descriptor for *path*
for :func:`execve`.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. function:: _exit(n)
Exit the process with status *n*, without calling cleanup handlers, flushing
@@ -3137,6 +3327,9 @@ written in Python, such as a mail server's external command delivery program.
:func:`spawnve` are not thread-safe on Windows; we advise you to use the
:mod:`subprocess` module instead.
+ .. versionchanged:: 3.6
+ Accepts a :term:`path-like object`.
+
.. data:: P_NOWAIT
P_NOWAITO
@@ -3623,6 +3816,11 @@ Miscellaneous System Information
Return the number of CPUs in the system. Returns ``None`` if undetermined.
+ This number is not equivalent to the number of CPUs the current process can
+ use. The number of usable CPUs can be obtained with
+ ``len(os.sched_getaffinity(0))``
+
+
.. versionadded:: 3.4
@@ -3738,35 +3936,89 @@ Higher-level operations on pathnames are defined in the :mod:`os.path` module.
.. versionadded:: 3.3
-.. _os-miscfunc:
-Miscellaneous Functions
------------------------
+Random numbers
+--------------
+
+
+.. function:: getrandom(size, flags=0)
+
+ Get up to *size* random bytes. The function can return less bytes than
+ requested.
+
+ These bytes can be used to seed user-space random number generators or for
+ cryptographic purposes.
+
+ ``getrandom()`` relies on entropy gathered from device drivers and other
+ sources of environmental noise. Unnecessarily reading large quantities of
+ data will have a negative impact on other users of the ``/dev/random`` and
+ ``/dev/urandom`` devices.
+
+ The flags argument is a bit mask that can contain zero or more of the
+ following values ORed together: :py:data:`os.GRND_RANDOM` and
+ :py:data:`GRND_NONBLOCK`.
+
+ See also the `Linux getrandom() manual page
+ <http://man7.org/linux/man-pages/man2/getrandom.2.html>`_.
+
+ Availability: Linux 3.17 and newer.
+ .. versionadded:: 3.6
-.. function:: urandom(n)
+.. function:: urandom(size)
- Return a string of *n* random bytes suitable for cryptographic use.
+ Return a string of *size* random bytes suitable for cryptographic use.
This function returns random bytes from an OS-specific randomness source. The
returned data should be unpredictable enough for cryptographic applications,
though its exact quality depends on the OS implementation.
- On Linux, ``getrandom()`` syscall is used if available and the urandom
- entropy pool is initialized (``getrandom()`` does not block).
- On a Unix-like system this will query ``/dev/urandom``. On Windows, it
- will use ``CryptGenRandom()``. If a randomness source is not found,
- :exc:`NotImplementedError` will be raised.
+ On Linux, if the ``getrandom()`` syscall is available, it is used in
+ blocking mode: block until the system urandom entropy pool is initialized
+ (128 bits of entropy are collected by the kernel). See the :pep:`524` for
+ the rationale. On Linux, the :func:`getrandom` function can be used to get
+ random bytes in non-blocking mode (using the :data:`GRND_NONBLOCK` flag) or
+ to poll until the system urandom entropy pool is initialized.
- For an easy-to-use interface to the random number generator
- provided by your platform, please see :class:`random.SystemRandom`.
+ On a Unix-like system, random bytes are read from the ``/dev/urandom``
+ device. If the ``/dev/urandom`` device is not available or not readable, the
+ :exc:`NotImplementedError` exception is raised.
+
+ On Windows, it will use ``CryptGenRandom()``.
+
+ .. seealso::
+ The :mod:`secrets` module provides higher level functions. For an
+ easy-to-use interface to the random number generator provided by your
+ platform, please see :class:`random.SystemRandom`.
+
+ .. versionchanged:: 3.6.0
+ On Linux, ``getrandom()`` is now used in blocking mode to increase the
+ security.
.. versionchanged:: 3.5.2
- On Linux, if ``getrandom()`` blocks (the urandom entropy pool is not
- initialized yet), fall back on reading ``/dev/urandom``.
+ On Linux, if the ``getrandom()`` syscall blocks (the urandom entropy pool
+ is not initialized yet), fall back on reading ``/dev/urandom``.
.. versionchanged:: 3.5
On Linux 3.17 and newer, the ``getrandom()`` syscall is now used
when available. On OpenBSD 5.6 and newer, the C ``getentropy()``
function is now used. These functions avoid the usage of an internal file
descriptor.
+
+.. data:: GRND_NONBLOCK
+
+ By default, when reading from ``/dev/random``, :func:`getrandom` blocks if
+ no random bytes are available, and when reading from ``/dev/urandom``, it blocks
+ if the entropy pool has not yet been initialized.
+
+ If the :py:data:`GRND_NONBLOCK` flag is set, then :func:`getrandom` does not
+ block in these cases, but instead immediately raises :exc:`BlockingIOError`.
+
+ .. versionadded:: 3.6
+
+.. data:: GRND_RANDOM
+
+ If this bit is set, then random bytes are drawn from the
+ ``/dev/random`` pool instead of the ``/dev/urandom`` pool.
+
+ .. versionadded:: 3.6
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 7b90a1f..5a81917 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -35,12 +35,6 @@ Pure paths are useful in some special cases; for example:
accessing the OS. In this case, instantiating one of the pure classes may be
useful since those simply don't have any OS-accessing operations.
-.. note::
- This module has been included in the standard library on a
- :term:`provisional basis <provisional package>`. Backwards incompatible
- changes (up to and including removal of the package) may occur if deemed
- necessary by the core developers.
-
.. seealso::
:pep:`428`: The pathlib module -- object-oriented filesystem paths.
@@ -111,7 +105,8 @@ we also call *flavours*:
PurePosixPath('setup.py')
Each element of *pathsegments* can be either a string representing a
- path segment, or another path object::
+ path segment, an object implementing the :class:`os.PathLike` interface
+ which returns a string, or another path object::
>>> PurePath('foo', 'some/path', 'bar')
PurePosixPath('foo/some/path/bar')
@@ -152,6 +147,12 @@ we also call *flavours*:
to ``PurePosixPath('bar')``, which is wrong if ``foo`` is a symbolic link
to another directory)
+ Pure path objects implement the :class:`os.PathLike` interface, allowing them
+ to be used anywhere the interface is accepted.
+
+ .. versionchanged:: 3.6
+ Added support for the :class:`os.PathLike` interface.
+
.. class:: PurePosixPath(*pathsegments)
A subclass of :class:`PurePath`, this path flavour represents non-Windows
@@ -199,7 +200,7 @@ Paths of a different flavour compare unequal and cannot be ordered::
>>> PureWindowsPath('foo') < PurePosixPath('foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
- TypeError: unorderable types: PureWindowsPath() < PurePosixPath()
+ TypeError: '<' not supported between instances of 'PureWindowsPath' and 'PurePosixPath'
Operators
@@ -216,6 +217,14 @@ The slash operator helps create child paths, similarly to :func:`os.path.join`::
>>> '/usr' / q
PurePosixPath('/usr/bin')
+A path object can be used anywhere an object implementing :class:`os.PathLike`
+is accepted::
+
+ >>> import os
+ >>> p = PurePath('/etc')
+ >>> os.fspath(p)
+ '/etc'
+
The string representation of a path is the raw filesystem path itself
(in native form, e.g. with backslashes under Windows), which you can
pass to any function taking a file path as a string::
diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst
index d77de2e..52bef68 100644
--- a/Doc/library/pdb.rst
+++ b/Doc/library/pdb.rst
@@ -144,7 +144,7 @@ The ``run*`` functions and :func:`set_trace` are aliases for instantiating the
access further features, you have to do this yourself:
.. class:: Pdb(completekey='tab', stdin=None, stdout=None, skip=None, \
- nosigint=False)
+ nosigint=False, readrc=True)
:class:`Pdb` is the debugger class.
@@ -160,6 +160,9 @@ access further features, you have to do this yourself:
This allows you to break into the debugger again by pressing :kbd:`Ctrl-C`. If you
want Pdb not to touch the SIGINT handler, set *nosigint* to true.
+ The *readrc* argument defaults to true and controls whether Pdb will load
+ .pdbrc files from the filesystem.
+
Example call to enable tracing with *skip*::
import pdb; pdb.Pdb(skip=['django.*']).set_trace()
@@ -171,6 +174,9 @@ access further features, you have to do this yourself:
The *nosigint* argument. Previously, a SIGINT handler was never set by
Pdb.
+ .. versionchanged:: 3.6
+ The *readrc* argument.
+
.. method:: run(statement, globals=None, locals=None)
runeval(expression, globals=None, locals=None)
runcall(function, *args, **kwds)
diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst
index 0d64191..6e8430f 100644
--- a/Doc/library/pickle.rst
+++ b/Doc/library/pickle.rst
@@ -492,7 +492,7 @@ methods:
.. method:: object.__getnewargs_ex__()
- In protocols 4 and newer, classes that implements the
+ In protocols 2 and newer, classes that implements the
:meth:`__getnewargs_ex__` method can dictate the values passed to the
:meth:`__new__` method upon unpickling. The method must return a pair
``(args, kwargs)`` where *args* is a tuple of positional arguments
@@ -504,15 +504,22 @@ methods:
class requires keyword-only arguments. Otherwise, it is recommended for
compatibility to implement :meth:`__getnewargs__`.
+ .. versionchanged:: 3.6
+ :meth:`__getnewargs_ex__` is now used in protocols 2 and 3.
+
.. method:: object.__getnewargs__()
- This method serve a similar purpose as :meth:`__getnewargs_ex__` but
- for protocols 2 and newer. It must return a tuple of arguments ``args``
- which will be passed to the :meth:`__new__` method upon unpickling.
+ This method serve a similar purpose as :meth:`__getnewargs_ex__`, but
+ supports only positional arguments. It must return a tuple of arguments
+ ``args`` which will be passed to the :meth:`__new__` method upon unpickling.
+
+ :meth:`__getnewargs__` will not be called if :meth:`__getnewargs_ex__` is
+ defined.
- In protocols 4 and newer, :meth:`__getnewargs__` will not be called if
- :meth:`__getnewargs_ex__` is defined.
+ .. versionchanged:: 3.6
+ Before Python 3.6, :meth:`__getnewargs__` was called instead of
+ :meth:`__getnewargs_ex__` in protocols 2 and 3.
.. method:: object.__getstate__()
diff --git a/Doc/library/pkgutil.rst b/Doc/library/pkgutil.rst
index abeac62..90d69e4 100644
--- a/Doc/library/pkgutil.rst
+++ b/Doc/library/pkgutil.rst
@@ -11,6 +11,11 @@
This module provides utilities for the import system, in particular package
support.
+.. class:: ModuleInfo(module_finder, name, ispkg)
+
+ A namedtuple that holds a brief summary of a module's info.
+
+ .. versionadded:: 3.6
.. function:: extend_path(path, name)
@@ -139,7 +144,7 @@ support.
.. function:: iter_modules(path=None, prefix='')
- Yields ``(module_finder, name, ispkg)`` for all submodules on *path*, or, if
+ Yields :class:`ModuleInfo` for all submodules on *path*, or, if
*path* is ``None``, all top-level modules on ``sys.path``.
*path* should be either ``None`` or a list of paths to look for modules in.
@@ -160,7 +165,7 @@ support.
.. function:: walk_packages(path=None, prefix='', onerror=None)
- Yields ``(module_finder, name, ispkg)`` for all modules recursively on
+ Yields :class:`ModuleInfo` for all modules recursively on
*path*, or, if *path* is ``None``, all accessible modules.
*path* should be either ``None`` or a list of paths to look for modules in.
diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst
index ffabc32..d72b660 100644
--- a/Doc/library/poplib.rst
+++ b/Doc/library/poplib.rst
@@ -62,6 +62,13 @@ The :mod:`poplib` module provides two classes:
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
:data:`ssl.HAS_SNI`).
+ .. deprecated:: 3.6
+
+ *keyfile* and *certfile* are deprecated in favor of *context*.
+ Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let
+ :func:`ssl.create_default_context` select the system's trusted CA
+ certificates for you.
+
One exception is defined as an attribute of the :mod:`poplib` module:
diff --git a/Doc/library/queue.rst b/Doc/library/queue.rst
index 924be5a..bd0fc2d 100644
--- a/Doc/library/queue.rst
+++ b/Doc/library/queue.rst
@@ -16,8 +16,9 @@ availability of thread support in Python; see the :mod:`threading`
module.
The module implements three types of queue, which differ only in the order in
-which the entries are retrieved. In a FIFO queue, the first tasks added are
-the first retrieved. In a LIFO queue, the most recently added entry is
+which the entries are retrieved. In a :abbr:`FIFO (first-in, first-out)`
+queue, the first tasks added are the first retrieved. In a
+:abbr:`LIFO (last-in, first-out)` queue, the most recently added entry is
the first retrieved (operating like a stack). With a priority queue,
the entries are kept sorted (using the :mod:`heapq` module) and the
lowest valued entry is retrieved first.
@@ -29,14 +30,16 @@ The :mod:`queue` module defines the following classes and exceptions:
.. class:: Queue(maxsize=0)
- Constructor for a FIFO queue. *maxsize* is an integer that sets the upperbound
+ Constructor for a :abbr:`FIFO (first-in, first-out)` queue. *maxsize* is
+ an integer that sets the upperbound
limit on the number of items that can be placed in the queue. Insertion will
block once this size has been reached, until queue items are consumed. If
*maxsize* is less than or equal to zero, the queue size is infinite.
.. class:: LifoQueue(maxsize=0)
- Constructor for a LIFO queue. *maxsize* is an integer that sets the upperbound
+ Constructor for a :abbr:`LIFO (last-in, first-out)` queue. *maxsize* is
+ an integer that sets the upperbound
limit on the number of items that can be placed in the queue. Insertion will
block once this size has been reached, until queue items are consumed. If
*maxsize* is less than or equal to zero, the queue size is infinite.
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 22f18a0..a47ed9c 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -46,7 +46,8 @@ from sources provided by the operating system.
.. warning::
The pseudo-random generators of this module should not be used for
- security purposes.
+ security purposes. For security or cryptographic uses, see the
+ :mod:`secrets` module.
Bookkeeping functions:
@@ -123,6 +124,31 @@ Functions for sequences:
Return a random element from the non-empty sequence *seq*. If *seq* is empty,
raises :exc:`IndexError`.
+.. function:: choices(population, weights=None, *, cum_weights=None, k=1)
+
+ Return a *k* sized list of elements chosen from the *population* with replacement.
+ If the *population* is empty, raises :exc:`IndexError`.
+
+ If a *weights* sequence is specified, selections are made according to the
+ relative weights. Alternatively, if a *cum_weights* sequence is given, the
+ selections are made according to the cumulative weights (perhaps computed
+ using :func:`itertools.accumulate`). For example, the relative weights
+ ``[10, 5, 30, 5]`` are equivalent to the cumulative weights
+ ``[10, 15, 45, 50]``. Internally, the relative weights are converted to
+ cumulative weights before making selections, so supplying the cumulative
+ weights saves work.
+
+ If neither *weights* nor *cum_weights* are specified, selections are made
+ with equal probability. If a weights sequence is supplied, it must be
+ the same length as the *population* sequence. It is a :exc:`TypeError`
+ to specify both *weights* and *cum_weights*.
+
+ The *weights* or *cum_weights* can use any numeric type that interoperates
+ with the :class:`float` values returned by :func:`random` (that includes
+ integers, floats, and fractions but excludes decimals).
+
+ .. versionadded:: 3.6
+
.. function:: shuffle(x[, random])
@@ -313,36 +339,28 @@ Basic usage::
>>> random.choice('abcdefghij') # Single random element
'c'
- >>> items = [1, 2, 3, 4, 5, 6, 7]
- >>> random.shuffle(items)
- >>> items
- [7, 3, 2, 5, 6, 4, 1]
+ >>> deck = ['jack', 'queen', 'king', 'ace']
+ >>> shuffle(deck)
+ >>> deck
+ ['king', 'queen', 'ace', 'jack']
>>> random.sample([1, 2, 3, 4, 5], 3) # Three samples without replacement
[4, 1, 5]
-A common task is to make a :func:`random.choice` with weighted probabilities.
-
-If the weights are small integer ratios, a simple technique is to build a sample
-population with repeats::
-
- >>> weighted_choices = [('Red', 3), ('Blue', 2), ('Yellow', 1), ('Green', 4)]
- >>> population = [val for val, cnt in weighted_choices for i in range(cnt)]
- >>> population
- ['Red', 'Red', 'Red', 'Blue', 'Blue', 'Yellow', 'Green', 'Green', 'Green', 'Green']
-
- >>> random.choice(population)
- 'Green'
+ >>> # Six weighted samples with replacement
+ >>> choices(['red', 'black', 'green'], [18, 18, 2], k=6)
+ ['red', 'green', 'black', 'black', 'red', 'black']
-A more general approach is to arrange the weights in a cumulative distribution
-with :func:`itertools.accumulate`, and then locate the random value with
-:func:`bisect.bisect`::
+Example of `statistical bootstrapping
+<https://en.wikipedia.org/wiki/Bootstrapping_(statistics)>`_ using resampling
+with replacement to estimate a confidence interval for the mean of a small
+sample of size five::
- >>> choices, weights = zip(*weighted_choices)
- >>> cumdist = list(itertools.accumulate(weights))
- >>> cumdist # [3, 3+2, 3+2+1, 3+2+1+4]
- [3, 5, 6, 10]
+ # http://statistics.about.com/od/Applications/a/Example-Of-Bootstrapping.htm
+ from statistics import mean
+ from random import choices
- >>> x = random.random() * cumdist[-1]
- >>> choices[bisect.bisect(cumdist, x)]
- 'Blue'
+ data = 1, 2, 4, 4, 10
+ means = sorted(mean(choices(data, k=5)) for i in range(20))
+ print('The sample mean of {:.1f} has a 90% confidence interval '
+ 'from {:.1f} to {:.1f}'.format(mean(data), means[1], means[-2]))
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 1ca621e..c9f2263 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -230,12 +230,8 @@ The special characters are:
flags are described in :ref:`contents-of-module-re`.) This
is useful if you wish to include the flags as part of the regular
expression, instead of passing a *flag* argument to the
- :func:`re.compile` function.
-
- Note that the ``(?x)`` flag changes how the expression is parsed. It should be
- used first in the expression string, or after one or more whitespace characters.
- If there are non-whitespace characters before the flag, the results are
- undefined.
+ :func:`re.compile` function. Flags should be used first in the
+ expression string.
``(?:...)``
A non-capturing version of regular parentheses. Matches whatever regular
@@ -243,6 +239,16 @@ The special characters are:
*cannot* be retrieved after performing a match or referenced later in the
pattern.
+``(?imsx-imsx:...)``
+ (Zero or more letters from the set ``'i'``, ``'m'``, ``'s'``, ``'x'``,
+ optionally followed by ``'-'`` followed by one or more letters from the
+ same set.) The letters set or removes the corresponding flags:
+ :const:`re.I` (ignore case), :const:`re.M` (multi-line), :const:`re.S`
+ (dot matches all), and :const:`re.X` (verbose), for the part of the
+ expression. (The flags are described in :ref:`contents-of-module-re`.)
+
+ .. versionadded:: 3.6
+
``(?P<name>...)``
Similar to regular parentheses, but the substring matched by the group is
accessible via the symbolic group name *name*. Group names must be valid
@@ -327,8 +333,9 @@ The special characters are:
The special sequences consist of ``'\'`` and a character from the list below.
-If the ordinary character is not on the list, then the resulting RE will match
-the second character. For example, ``\$`` matches the character ``'$'``.
+If the ordinary character is not an ASCII digit or an ASCII letter, then the
+resulting RE will match the second character. For example, ``\$`` matches the
+character ``'$'``.
``\number``
Matches the contents of the group of the same number. Groups are numbered
@@ -448,9 +455,8 @@ three digits in length.
.. versionchanged:: 3.3
The ``'\u'`` and ``'\U'`` escape sequences have been added.
-.. deprecated-removed:: 3.5 3.6
- Unknown escapes consisting of ``'\'`` and ASCII letter now raise a
- deprecation warning and will be forbidden in Python 3.6.
+.. versionchanged:: 3.6
+ Unknown escapes consisting of ``'\'`` and an ASCII letter now are errors.
.. seealso::
@@ -538,11 +544,11 @@ form.
current locale. The use of this flag is discouraged as the locale mechanism
is very unreliable, and it only handles one "culture" at a time anyway;
you should use Unicode matching instead, which is the default in Python 3
- for Unicode (str) patterns. This flag makes sense only with bytes patterns.
+ for Unicode (str) patterns. This flag can be used only with bytes patterns.
- .. deprecated-removed:: 3.5 3.6
- Deprecated the use of :const:`re.LOCALE` with string patterns or
- :const:`re.ASCII`.
+ .. versionchanged:: 3.6
+ :const:`re.LOCALE` can be used only with bytes patterns and is
+ not compatible with :const:`re.ASCII`.
.. data:: M
@@ -748,9 +754,8 @@ form.
.. versionchanged:: 3.5
Unmatched groups are replaced with an empty string.
- .. deprecated-removed:: 3.5 3.6
- Unknown escapes consist of ``'\'`` and ASCII letter now raise a
- deprecation warning and will be forbidden in Python 3.6.
+ .. versionchanged:: 3.6
+ Unknown escapes consisting of ``'\'`` and an ASCII letter now are errors.
.. function:: subn(pattern, repl, string, count=0, flags=0)
@@ -1016,6 +1021,22 @@ Match objects support the following methods and attributes:
'c3'
+.. method:: match.__getitem__(g)
+
+ This is identical to ``m.group(g)``. This allows easier access to
+ an individual group from a match:
+
+ >>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
+ >>> m[0] # The entire match
+ 'Isaac Newton'
+ >>> m[1] # The first parenthesized subgroup.
+ 'Isaac'
+ >>> m[2] # The second parenthesized subgroup.
+ 'Newton'
+
+ .. versionadded:: 3.6
+
+
.. method:: match.groups(default=None)
Return a tuple containing all the subgroups of the match, from 1 up to however
diff --git a/Doc/library/readline.rst b/Doc/library/readline.rst
index 4d3c099..54c54b4 100644
--- a/Doc/library/readline.rst
+++ b/Doc/library/readline.rst
@@ -167,6 +167,20 @@ The following functions operate on a global history list:
This calls :c:func:`add_history` in the underlying library.
+.. function:: set_auto_history(enabled)
+
+ Enable or disable automatic calls to :c:func:`add_history` when reading
+ input via readline. The *enabled* argument should be a Boolean value
+ that when true, enables auto history, and that when false, disables
+ auto history.
+
+ .. versionadded:: 3.6
+
+ .. impl-detail::
+ Auto history is enabled by default, and changes to this do not persist
+ across multiple sessions.
+
+
Startup hooks
-------------
diff --git a/Doc/library/secrets.rst b/Doc/library/secrets.rst
new file mode 100644
index 0000000..9bf848f
--- /dev/null
+++ b/Doc/library/secrets.rst
@@ -0,0 +1,198 @@
+:mod:`secrets` --- Generate secure random numbers for managing secrets
+======================================================================
+
+.. module:: secrets
+ :synopsis: Generate secure random numbers for managing secrets.
+
+.. moduleauthor:: Steven D'Aprano <steve+python@pearwood.info>
+.. sectionauthor:: Steven D'Aprano <steve+python@pearwood.info>
+.. versionadded:: 3.6
+
+.. testsetup::
+
+ from secrets import *
+ __name__ = '<doctest>'
+
+**Source code:** :source:`Lib/secrets.py`
+
+-------------
+
+The :mod:`secrets` module is used for generating cryptographically strong
+random numbers suitable for managing data such as passwords, account
+authentication, security tokens, and related secrets.
+
+In particularly, :mod:`secrets` should be used in preference to the
+default pseudo-random number generator in the :mod:`random` module, which
+is designed for modelling and simulation, not security or cryptography.
+
+.. seealso::
+
+ :pep:`506`
+
+
+Random numbers
+--------------
+
+The :mod:`secrets` module provides access to the most secure source of
+randomness that your operating system provides.
+
+.. class:: SystemRandom
+
+ A class for generating random numbers using the highest-quality
+ sources provided by the operating system. See
+ :class:`random.SystemRandom` for additional details.
+
+.. function:: choice(sequence)
+
+ Return a randomly-chosen element from a non-empty sequence.
+
+.. function:: randbelow(n)
+
+ Return a random int in the range [0, *n*).
+
+.. function:: randbits(k)
+
+ Return an int with *k* random bits.
+
+
+Generating tokens
+-----------------
+
+The :mod:`secrets` module provides functions for generating secure
+tokens, suitable for applications such as password resets,
+hard-to-guess URLs, and similar.
+
+.. function:: token_bytes([nbytes=None])
+
+ Return a random byte string containing *nbytes* number of bytes.
+ If *nbytes* is ``None`` or not supplied, a reasonable default is
+ used.
+
+ .. doctest::
+
+ >>> token_bytes(16) #doctest:+SKIP
+ b'\xebr\x17D*t\xae\xd4\xe3S\xb6\xe2\xebP1\x8b'
+
+
+.. function:: token_hex([nbytes=None])
+
+ Return a random text string, in hexadecimal. The string has *nbytes*
+ random bytes, each byte converted to two hex digits. If *nbytes* is
+ ``None`` or not supplied, a reasonable default is used.
+
+ .. doctest::
+
+ >>> token_hex(16) #doctest:+SKIP
+ 'f9bf78b9a18ce6d46a0cd2b0b86df9da'
+
+.. function:: token_urlsafe([nbytes=None])
+
+ Return a random URL-safe text string, containing *nbytes* random
+ bytes. The text is Base64 encoded, so on average each byte results
+ in approximately 1.3 characters. If *nbytes* is ``None`` or not
+ supplied, a reasonable default is used.
+
+ .. doctest::
+
+ >>> token_urlsafe(16) #doctest:+SKIP
+ 'Drmhze6EPcv0fN_81Bj-nA'
+
+
+How many bytes should tokens use?
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+To be secure against
+`brute-force attacks <https://en.wikipedia.org/wiki/Brute-force_attack>`_,
+tokens need to have sufficient randomness. Unfortunately, what is
+considered sufficient will necessarily increase as computers get more
+powerful and able to make more guesses in a shorter period. As of 2015,
+it is believed that 32 bytes (256 bits) of randomness is sufficient for
+the typical use-case expected for the :mod:`secrets` module.
+
+For those who want to manage their own token length, you can explicitly
+specify how much randomness is used for tokens by giving an :class:`int`
+argument to the various ``token_*`` functions. That argument is taken
+as the number of bytes of randomness to use.
+
+Otherwise, if no argument is provided, or if the argument is ``None``,
+the ``token_*`` functions will use a reasonable default instead.
+
+.. note::
+
+ That default is subject to change at any time, including during
+ maintenance releases.
+
+
+Other functions
+---------------
+
+.. function:: compare_digest(a, b)
+
+ Return ``True`` if strings *a* and *b* are equal, otherwise ``False``,
+ in such a way as to reduce the risk of
+ `timing attacks <http://codahale.com/a-lesson-in-timing-attacks/>`_.
+ See :func:`hmac.compare_digest` for additional details.
+
+
+Recipes and best practices
+--------------------------
+
+This section shows recipes and best practices for using :mod:`secrets`
+to manage a basic level of security.
+
+Generate an eight-character alphanumeric password:
+
+.. testcode::
+
+ import string
+ alphabet = string.ascii_letters + string.digits
+ password = ''.join(choice(alphabet) for i in range(8))
+
+
+.. note::
+
+ Applications should not
+ `store passwords in a recoverable format <http://cwe.mitre.org/data/definitions/257.html>`_,
+ whether plain text or encrypted. They should be salted and hashed
+ using a cryptographically-strong one-way (irreversible) hash function.
+
+
+Generate a ten-character alphanumeric password with at least one
+lowercase character, at least one uppercase character, and at least
+three digits:
+
+.. testcode::
+
+ import string
+ alphabet = string.ascii_letters + string.digits
+ while True:
+ password = ''.join(choice(alphabet) for i in range(10))
+ if (any(c.islower() for c in password)
+ and any(c.isupper() for c in password)
+ and sum(c.isdigit() for c in password) >= 3):
+ break
+
+
+Generate an `XKCD-style passphrase <http://xkcd.com/936/>`_:
+
+.. testcode::
+
+ # On standard Linux systems, use a convenient dictionary file.
+ # Other platforms may need to provide their own word-list.
+ with open('/usr/share/dict/words') as f:
+ words = [word.strip() for word in f]
+ password = ' '.join(choice(words) for i in range(4))
+
+
+Generate a hard-to-guess temporary URL containing a security token
+suitable for password recovery applications:
+
+.. testcode::
+
+ url = 'https://mydomain.com/reset=' + token_urlsafe()
+
+
+
+..
+ # This modeline must appear within the last ten lines of the file.
+ kate: indent-width 3; remove-trailing-space on; replace-tabs on; encoding utf-8;
diff --git a/Doc/library/select.rst b/Doc/library/select.rst
index a81386a..f97118e 100644
--- a/Doc/library/select.rst
+++ b/Doc/library/select.rst
@@ -268,35 +268,43 @@ Edge and Level Trigger Polling (epoll) Objects
*eventmask*
- +-----------------------+-----------------------------------------------+
- | Constant | Meaning |
- +=======================+===============================================+
- | :const:`EPOLLIN` | Available for read |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLOUT` | Available for write |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLPRI` | Urgent data for read |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLERR` | Error condition happened on the assoc. fd |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLHUP` | Hang up happened on the assoc. fd |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLET` | Set Edge Trigger behavior, the default is |
- | | Level Trigger behavior |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is |
- | | pulled out, the fd is internally disabled |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLRDBAND` | Priority data band can be read. |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLWRBAND` | Priority data may be written. |
- +-----------------------+-----------------------------------------------+
- | :const:`EPOLLMSG` | Ignored. |
- +-----------------------+-----------------------------------------------+
+ +-------------------------+-----------------------------------------------+
+ | Constant | Meaning |
+ +=========================+===============================================+
+ | :const:`EPOLLIN` | Available for read |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLOUT` | Available for write |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLPRI` | Urgent data for read |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLERR` | Error condition happened on the assoc. fd |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLHUP` | Hang up happened on the assoc. fd |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLET` | Set Edge Trigger behavior, the default is |
+ | | Level Trigger behavior |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is |
+ | | pulled out, the fd is internally disabled |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLEXCLUSIVE` | Wake only one epoll object when the |
+ | | associated fd has an event. The default (if |
+ | | this flag is not set) is to wake all epoll |
+ | | objects polling on on a fd. |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLRDHUP` | Stream socket peer closed connection or shut |
+ | | down writing half of connection. |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLRDBAND` | Priority data band can be read. |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLWRBAND` | Priority data may be written. |
+ +-------------------------+-----------------------------------------------+
+ | :const:`EPOLLMSG` | Ignored. |
+ +-------------------------+-----------------------------------------------+
.. method:: epoll.close()
@@ -385,6 +393,9 @@ linearly scanned again. :c:func:`select` is O(highest file descriptor), while
+-------------------+------------------------------------------+
| :const:`POLLHUP` | Hung up |
+-------------------+------------------------------------------+
+ | :const:`POLLRDHUP`| Stream socket peer closed connection, or |
+ | | shut down writing half of connection |
+ +-------------------+------------------------------------------+
| :const:`POLLNVAL` | Invalid request: descriptor not open |
+-------------------+------------------------------------------+
diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst
index e81f982..1a89bf6 100644
--- a/Doc/library/shlex.rst
+++ b/Doc/library/shlex.rst
@@ -73,11 +73,11 @@ The :mod:`shlex` module defines the following functions:
The :mod:`shlex` module defines the following class:
-.. class:: shlex(instream=None, infile=None, posix=False)
+.. class:: shlex(instream=None, infile=None, posix=False, punctuation_chars=False)
A :class:`~shlex.shlex` instance or subclass instance is a lexical analyzer
object. The initialization argument, if present, specifies where to read
- characters from. It must be a file-/stream-like object with
+ characters from. It must be a file-/stream-like object with
:meth:`~io.TextIOBase.read` and :meth:`~io.TextIOBase.readline` methods, or
a string. If no argument is given, input will be taken from ``sys.stdin``.
The second optional argument is a filename string, which sets the initial
@@ -87,8 +87,19 @@ The :mod:`shlex` module defines the following class:
when *posix* is not true (default), the :class:`~shlex.shlex` instance will
operate in compatibility mode. When operating in POSIX mode,
:class:`~shlex.shlex` will try to be as close as possible to the POSIX shell
- parsing rules.
-
+ parsing rules. The *punctuation_chars* argument provides a way to make the
+ behaviour even closer to how real shells parse. This can take a number of
+ values: the default value, ``False``, preserves the behaviour seen under
+ Python 3.5 and earlier. If set to ``True``, then parsing of the characters
+ ``();<>|&`` is changed: any run of these characters (considered punctuation
+ characters) is returned as a single token. If set to a non-empty string of
+ characters, those characters will be used as the punctuation characters. Any
+ characters in the :attr:`wordchars` attribute that appear in
+ *punctuation_chars* will be removed from :attr:`wordchars`. See
+ :ref:`improved-shell-compatibility` for more information.
+
+ .. versionchanged:: 3.6
+ The *punctuation_chars* parameter was added.
.. seealso::
@@ -191,7 +202,13 @@ variables which either control lexical analysis or can be used for debugging:
.. attribute:: shlex.wordchars
The string of characters that will accumulate into multi-character tokens. By
- default, includes all ASCII alphanumerics and underscore.
+ default, includes all ASCII alphanumerics and underscore. In POSIX mode, the
+ accented characters in the Latin-1 set are also included. If
+ :attr:`punctuation_chars` is not empty, the characters ``~-./*?=``, which can
+ appear in filename specifications and command line parameters, will also be
+ included in this attribute, and any characters which appear in
+ ``punctuation_chars`` will be removed from ``wordchars`` if they are present
+ there.
.. attribute:: shlex.whitespace
@@ -222,9 +239,13 @@ variables which either control lexical analysis or can be used for debugging:
.. attribute:: shlex.whitespace_split
- If ``True``, tokens will only be split in whitespaces. This is useful, for
+ If ``True``, tokens will only be split in whitespaces. This is useful, for
example, for parsing command lines with :class:`~shlex.shlex`, getting
- tokens in a similar way to shell arguments.
+ tokens in a similar way to shell arguments. If this attribute is ``True``,
+ :attr:`punctuation_chars` will have no effect, and splitting will happen
+ only on whitespaces. When using :attr:`punctuation_chars`, which is
+ intended to provide parsing closer to that implemented by shells, it is
+ advisable to leave ``whitespace_split`` as ``False`` (the default value).
.. attribute:: shlex.infile
@@ -245,10 +266,9 @@ variables which either control lexical analysis or can be used for debugging:
This attribute is ``None`` by default. If you assign a string to it, that
string will be recognized as a lexical-level inclusion request similar to the
``source`` keyword in various shells. That is, the immediately following token
- will be opened as a filename and input will
- be taken from that stream until EOF, at which
- point the :meth:`~io.IOBase.close` method of that stream will be called and
- the input source will again become the original input stream. Source
+ will be opened as a filename and input will be taken from that stream until
+ EOF, at which point the :meth:`~io.IOBase.close` method of that stream will be
+ called and the input source will again become the original input stream. Source
requests may be stacked any number of levels deep.
@@ -275,6 +295,16 @@ variables which either control lexical analysis or can be used for debugging:
(``''``), in non-POSIX mode, and to ``None`` in POSIX mode.
+.. attribute:: shlex.punctuation_chars
+
+ Characters that will be considered punctuation. Runs of punctuation
+ characters will be returned as a single token. However, note that no
+ semantic validity checking will be performed: for example, '>>>' could be
+ returned as a token, even though it may not be recognised as such by shells.
+
+ .. versionadded:: 3.6
+
+
.. _shlex-parsing-rules:
Parsing Rules
@@ -327,3 +357,62 @@ following parsing rules.
* EOF is signaled with a :const:`None` value;
* Quoted empty strings (``''``) are allowed.
+
+.. _improved-shell-compatibility:
+
+Improved Compatibility with Shells
+----------------------------------
+
+.. versionadded:: 3.6
+
+The :class:`shlex` class provides compatibility with the parsing performed by
+common Unix shells like ``bash``, ``dash``, and ``sh``. To take advantage of
+this compatibility, specify the ``punctuation_chars`` argument in the
+constructor. This defaults to ``False``, which preserves pre-3.6 behaviour.
+However, if it is set to ``True``, then parsing of the characters ``();<>|&``
+is changed: any run of these characters is returned as a single token. While
+this is short of a full parser for shells (which would be out of scope for the
+standard library, given the multiplicity of shells out there), it does allow
+you to perform processing of command lines more easily than you could
+otherwise. To illustrate, you can see the difference in the following snippet::
+
+ import shlex
+
+ for punct in (False, True):
+ if punct:
+ message = 'Old'
+ else:
+ message = 'New'
+ text = "a && b; c && d || e; f >'abc'; (def \"ghi\")"
+ s = shlex.shlex(text, punctuation_chars=punct)
+ print('%s: %s' % (message, list(s)))
+
+which prints out::
+
+ Old: ['a', '&', '&', 'b', ';', 'c', '&', '&', 'd', '|', '|', 'e', ';', 'f', '>', "'abc'", ';', '(', 'def', '"ghi"', ')']
+ New: ['a', '&&', 'b', ';', 'c', '&&', 'd', '||', 'e', ';', 'f', '>', "'abc'", ';', '(', 'def', '"ghi"', ')']
+
+Of course, tokens will be returned which are not valid for shells, and you'll
+need to implement your own error checks on the returned tokens.
+
+Instead of passing ``True`` as the value for the punctuation_chars parameter,
+you can pass a string with specific characters, which will be used to determine
+which characters constitute punctuation. For example::
+
+ >>> import shlex
+ >>> s = shlex.shlex("a && b || c", punctuation_chars="|")
+ >>> list(s)
+ ['a', '&', '&', 'b', '||', 'c']
+
+.. note:: When ``punctuation_chars`` is specified, the :attr:`~shlex.wordchars`
+ attribute is augmented with the characters ``~-./*?=``. That is because these
+ characters can appear in file names (including wildcards) and command-line
+ arguments (e.g. ``--color=auto``). Hence::
+
+ >>> import shlex
+ >>> s = shlex.shlex('~/a && b-c --color=auto || d *.py?',
+ ... punctuation_chars=True)
+ >>> list(s)
+ ['~/a', '&&', 'b-c', '--color=auto', '||', 'd', '*.py?']
+
+
diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst
index a1cf241..fefd6ab 100644
--- a/Doc/library/shutil.rst
+++ b/Doc/library/shutil.rst
@@ -425,7 +425,7 @@ Another example that uses the *ignore* argument to add a logging call::
import logging
def _logpath(path, names):
- logging.info('Working in %s' % path)
+ logging.info('Working in %s', path)
return [] # nothing will be ignored
copytree(source, destination, ignore=_logpath)
diff --git a/Doc/library/site.rst b/Doc/library/site.rst
index 0a73f5a..43daf79 100644
--- a/Doc/library/site.rst
+++ b/Doc/library/site.rst
@@ -52,7 +52,8 @@ searched for site-packages; otherwise they won't.
A path configuration file is a file whose name has the form :file:`{name}.pth`
and exists in one of the four directories mentioned above; its contents are
additional items (one per line) to be added to ``sys.path``. Non-existing items
-are never added to ``sys.path``. No item is added to ``sys.path`` more than
+are never added to ``sys.path``, and no check is made that the item refers to a
+directory rather than a file. No item is added to ``sys.path`` more than
once. Blank lines and lines beginning with ``#`` are skipped. Lines starting
with ``import`` (followed by space or tab) are executed.
diff --git a/Doc/library/smtpd.rst b/Doc/library/smtpd.rst
index a096de0..e383201 100644
--- a/Doc/library/smtpd.rst
+++ b/Doc/library/smtpd.rst
@@ -29,7 +29,7 @@ SMTPServer Objects
.. class:: SMTPServer(localaddr, remoteaddr, data_size_limit=33554432,\
- map=None, enable_SMTPUTF8=False, decode_data=True)
+ map=None, enable_SMTPUTF8=False, decode_data=False)
Create a new :class:`SMTPServer` object, which binds to local address
*localaddr*. It will treat *remoteaddr* as an upstream SMTP relayer. Both
@@ -46,20 +46,19 @@ SMTPServer Objects
global socket map is used.
*enable_SMTPUTF8* determines whether the ``SMTPUTF8`` extension (as defined
- in :RFC:`6531`) should be enabled. The default is ``False``. If set to
- ``True``, *decode_data* must be ``False`` (otherwise an error is raised).
+ in :RFC:`6531`) should be enabled. The default is ``False``.
When ``True``, ``SMTPUTF8`` is accepted as a parameter to the ``MAIL``
command and when present is passed to :meth:`process_message` in the
- ``kwargs['mail_options']`` list.
+ ``kwargs['mail_options']`` list. *decode_data* and *enable_SMTPUTF8*
+ cannot be set to ``True`` at the same time.
*decode_data* specifies whether the data portion of the SMTP transaction
- should be decoded using UTF-8. The default is ``True`` for backward
- compatibility reasons, but will change to ``False`` in Python 3.6; specify
- the keyword value explicitly to avoid the :exc:`DeprecationWarning`. When
- *decode_data* is set to ``False`` the server advertises the ``8BITMIME``
+ should be decoded using UTF-8. When *decode_data* is ``False`` (the
+ default), the server advertises the ``8BITMIME``
extension (:rfc:`6152`), accepts the ``BODY=8BITMIME`` parameter to
the ``MAIL`` command, and when present passes it to :meth:`process_message`
- in the ``kwargs['mail_options']`` list.
+ in the ``kwargs['mail_options']`` list. *decode_data* and *enable_SMTPUTF8*
+ cannot be set to ``True`` at the same time.
.. method:: process_message(peer, mailfrom, rcpttos, data, **kwargs)
@@ -76,9 +75,8 @@ SMTPServer Objects
will be a bytes object.
*kwargs* is a dictionary containing additional information. It is empty
- unless at least one of ``decode_data=False`` or ``enable_SMTPUTF8=True``
- was given as an init parameter, in which case it contains the following
- keys:
+ if ``decode_data=True`` was given as an init argument, otherwise
+ it contains the following keys:
*mail_options*:
a list of all received parameters to the ``MAIL``
@@ -109,9 +107,12 @@ SMTPServer Objects
*localaddr* and *remoteaddr* may now contain IPv6 addresses.
.. versionadded:: 3.5
- the *decode_data* and *enable_SMTPUTF8* constructor arguments, and the
- *kwargs* argument to :meth:`process_message` when one or more of these is
- specified.
+ The *decode_data* and *enable_SMTPUTF8* constructor parameters, and the
+ *kwargs* parameter to :meth:`process_message` when *decode_data* is
+ ``False``.
+
+ .. versionchanged:: 3.6
+ *decode_data* is now ``False`` by default.
DebuggingServer Objects
@@ -151,7 +152,7 @@ SMTPChannel Objects
-------------------
.. class:: SMTPChannel(server, conn, addr, data_size_limit=33554432,\
- map=None, enable_SMTPUTF8=False, decode_data=True)
+ map=None, enable_SMTPUTF8=False, decode_data=False)
Create a new :class:`SMTPChannel` object which manages the communication
between the server and a single SMTP client.
@@ -163,22 +164,25 @@ SMTPChannel Objects
limit.
*enable_SMTPUTF8* determines whether the ``SMTPUTF8`` extension (as defined
- in :RFC:`6531`) should be enabled. The default is ``False``. A
- :exc:`ValueError` is raised if both *enable_SMTPUTF8* and *decode_data* are
- set to ``True`` at the same time.
+ in :RFC:`6531`) should be enabled. The default is ``False``.
+ *decode_data* and *enable_SMTPUTF8* cannot be set to ``True`` at the same
+ time.
A dictionary can be specified in *map* to avoid using a global socket map.
*decode_data* specifies whether the data portion of the SMTP transaction
- should be decoded using UTF-8. The default is ``True`` for backward
- compatibility reasons, but will change to ``False`` in Python 3.6. Specify
- the keyword value explicitly to avoid the :exc:`DeprecationWarning`.
+ should be decoded using UTF-8. The default is ``False``.
+ *decode_data* and *enable_SMTPUTF8* cannot be set to ``True`` at the same
+ time.
To use a custom SMTPChannel implementation you need to override the
:attr:`SMTPServer.channel_class` of your :class:`SMTPServer`.
.. versionchanged:: 3.5
- the *decode_data* and *enable_SMTPUTF8* arguments were added.
+ The *decode_data* and *enable_SMTPUTF8* parameters were added.
+
+ .. versionchanged:: 3.6
+ *decode_data* is now ``False`` by default.
The :class:`SMTPChannel` has the following instance variables:
diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst
index 8b98ccf..86e769e 100644
--- a/Doc/library/smtplib.rst
+++ b/Doc/library/smtplib.rst
@@ -95,6 +95,14 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
:data:`ssl.HAS_SNI`).
+ .. deprecated:: 3.6
+
+ *keyfile* and *certfile* are deprecated in favor of *context*.
+ Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let
+ :func:`ssl.create_default_context` select the system's trusted CA
+ certificates for you.
+
+
.. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None, source_address=None)
The LMTP protocol, which is very similar to ESMTP, is heavily based on the
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 79c7609..9671857 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -133,6 +133,22 @@ created. Socket addresses are represented as follows:
string format. (ex. ``b'12:23:34:45:56:67'``) This protocol is not
supported under FreeBSD.
+- :const:`AF_ALG` is a Linux-only socket based interface to Kernel
+ cryptography. An algorithm socket is configured with a tuple of two to four
+ elements ``(type, name [, feat [, mask]])``, where:
+
+ - *type* is the algorithm type as string, e.g. ``aead``, ``hash``,
+ ``skcipher`` or ``rng``.
+
+ - *name* is the algorithm name and operation mode as string, e.g.
+ ``sha256``, ``hmac(sha256)``, ``cbc(aes)`` or ``drbg_nopr_ctr_aes256``.
+
+ - *feat* and *mask* are unsigned 32bit integers.
+
+ Availability Linux 2.6.38, some algorithm types require more recent Kernels.
+
+ .. versionadded:: 3.6
+
- Certain other address families (:const:`AF_PACKET`, :const:`AF_CAN`)
support specific representations.
@@ -283,6 +299,10 @@ Constants
in the Unix header files are defined; for a few symbols, default values are
provided.
+ .. versionchanged:: 3.6
+ ``SO_DOMAIN``, ``SO_PROTOCOL``, ``SO_PEERSEC``, ``SO_PASSSEC``
+ were added.
+
.. data:: AF_CAN
PF_CAN
SOL_CAN_*
@@ -331,18 +351,33 @@ Constants
.. versionadded:: 3.3
-.. data:: SIO_*
+.. data:: SIO_RCVALL
+ SIO_KEEPALIVE_VALS
+ SIO_LOOPBACK_FAST_PATH
RCVALL_*
Constants for Windows' WSAIoctl(). The constants are used as arguments to the
:meth:`~socket.socket.ioctl` method of socket objects.
+ .. versionchanged:: 3.6
+ ``SIO_LOOPBACK_FAST_PATH`` was added.
+
.. data:: TIPC_*
TIPC related constants, matching the ones exported by the C socket API. See
the TIPC documentation for more information.
+.. data:: AF_ALG
+ SOL_ALG
+ ALG_*
+
+ Constants for Linux Kernel cryptography.
+
+ Availability: Linux >= 2.6.38.
+
+ .. versionadded:: 3.6
+
.. data:: AF_LINK
Availability: BSD, OSX.
@@ -874,6 +909,10 @@ to sockets.
it is recommended to :meth:`close` them explicitly, or to use a
:keyword:`with` statement around them.
+ .. versionchanged:: 3.6
+ :exc:`OSError` is now raised if an error occurs when the underlying
+ :c:func:`close` call is made.
+
.. note::
:meth:`close()` releases the resource associated with a connection but
@@ -994,6 +1033,12 @@ to sockets.
On other platforms, the generic :func:`fcntl.fcntl` and :func:`fcntl.ioctl`
functions may be used; they accept a socket object as their first argument.
+ Currently only the following control codes are supported:
+ ``SIO_RCVALL``, ``SIO_KEEPALIVE_VALS``, and ``SIO_LOOPBACK_FAST_PATH``.
+
+ .. versionchanged:: 3.6
+ ``SIO_LOOPBACK_FAST_PATH`` was added.
+
.. method:: socket.listen([backlog])
Enable a server to accept connections. If *backlog* is specified, it must
@@ -1277,6 +1322,15 @@ to sockets.
an exception, the method now retries the system call instead of raising
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
+.. method:: socket.sendmsg_afalg([msg], *, op[, iv[, assoclen[, flags]]])
+
+ Specialized version of :meth:`~socket.sendmsg` for :const:`AF_ALG` socket.
+ Set mode, IV, AEAD associated data length and flags for :const:`AF_ALG` socket.
+
+ Availability: Linux >= 2.6.38
+
+ .. versionadded:: 3.6
+
.. method:: socket.sendfile(file, offset=0, count=None)
Send a file until EOF is reached by using high-performance
@@ -1325,21 +1379,29 @@ to sockets.
For further information, please consult the :ref:`notes on socket timeouts <socket-timeouts>`.
-.. method:: socket.setsockopt(level, optname, value)
+.. method:: socket.setsockopt(level, optname, value: int)
+.. method:: socket.setsockopt(level, optname, value: buffer)
+.. method:: socket.setsockopt(level, optname, None, optlen: int)
.. index:: module: struct
Set the value of the given socket option (see the Unix manual page
:manpage:`setsockopt(2)`). The needed symbolic constants are defined in the
- :mod:`socket` module (:const:`SO_\*` etc.). The value can be an integer or
- a :term:`bytes-like object` representing a buffer. In the latter case it is
- up to the caller to
- ensure that the bytestring contains the proper bits (see the optional built-in
- module :mod:`struct` for a way to encode C structures as bytestrings).
+ :mod:`socket` module (:const:`SO_\*` etc.). The value can be an integer,
+ ``None`` or a :term:`bytes-like object` representing a buffer. In the later
+ case it is up to the caller to ensure that the bytestring contains the
+ proper bits (see the optional built-in module :mod:`struct` for a way to
+ encode C structures as bytestrings). When value is set to ``None``,
+ optlen argument is required. It's equivalent to call setsockopt C
+ function with optval=NULL and optlen=optlen.
+
.. versionchanged:: 3.5
Writable :term:`bytes-like object` is now accepted.
+ .. versionchanged:: 3.6
+ setsockopt(level, optname, None, optlen: int) form added.
+
.. method:: socket.shutdown(how)
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst
index 087f4e0..218a31c 100644
--- a/Doc/library/socketserver.rst
+++ b/Doc/library/socketserver.rst
@@ -52,11 +52,12 @@ handler class by subclassing the :class:`BaseRequestHandler` class and
overriding its :meth:`~BaseRequestHandler.handle` method;
this method will process incoming
requests. Second, you must instantiate one of the server classes, passing it
-the server's address and the request handler class. Then call the
+the server's address and the request handler class. It is recommended to use
+the server in a :keyword:`with` statement. Then call the
:meth:`~BaseServer.handle_request` or
:meth:`~BaseServer.serve_forever` method of the server object to
process one or many requests. Finally, call :meth:`~BaseServer.server_close`
-to close the socket.
+to close the socket (unless you used a :keyword:`with` statement).
When inheriting from :class:`ThreadingMixIn` for threaded connection behavior,
you should explicitly declare how you want your threads to behave on an abrupt
@@ -111,6 +112,8 @@ server classes.
:class:`UDPServer`. Setting the various attributes also changes the
behavior of the underlying server mechanism.
+ :class:`ForkingMixIn` and the Forking classes mentioned below are
+ only available on POSIX platforms that support :func:`~os.fork`.
.. class:: ForkingTCPServer
ForkingUDPServer
@@ -304,7 +307,11 @@ Server Objects
This function is called if the :meth:`~BaseRequestHandler.handle`
method of a :attr:`RequestHandlerClass` instance raises
an exception. The default action is to print the traceback to
- standard output and continue handling further requests.
+ standard error and continue handling further requests.
+
+ .. versionchanged:: 3.6
+ Now only called for exceptions derived from the :exc:`Exception`
+ class.
.. method:: handle_timeout()
@@ -349,6 +356,11 @@ Server Objects
default implementation always returns :const:`True`.
+ .. versionchanged:: 3.6
+ Support for the :term:`context manager` protocol was added. Exiting the
+ context manager is equivalent to calling :meth:`server_close`.
+
+
Request Handler Objects
-----------------------
@@ -397,6 +409,15 @@ Request Handler Objects
read or written, respectively, to get the request data or return data
to the client.
+ The :attr:`rfile` attributes of both classes support the
+ :class:`io.BufferedIOBase` readable interface, and
+ :attr:`DatagramRequestHandler.wfile` supports the
+ :class:`io.BufferedIOBase` writable interface.
+
+ .. versionchanged:: 3.6
+ :attr:`StreamRequestHandler.wfile` also supports the
+ :class:`io.BufferedIOBase` writable interface.
+
Examples
--------
@@ -429,11 +450,10 @@ This is the server side::
HOST, PORT = "localhost", 9999
# Create the server, binding to localhost on port 9999
- server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)
-
- # Activate the server; this will keep running until you
- # interrupt the program with Ctrl-C
- server.serve_forever()
+ with socketserver.TCPServer((HOST, PORT), MyTCPHandler) as server:
+ # Activate the server; this will keep running until you
+ # interrupt the program with Ctrl-C
+ server.serve_forever()
An alternative request handler class that makes use of streams (file-like
objects that simplify communication by providing the standard file interface)::
@@ -525,8 +545,8 @@ This is the server side::
if __name__ == "__main__":
HOST, PORT = "localhost", 9999
- server = socketserver.UDPServer((HOST, PORT), MyUDPHandler)
- server.serve_forever()
+ with socketserver.UDPServer((HOST, PORT), MyUDPHandler) as server:
+ server.serve_forever()
This is the client side::
@@ -585,22 +605,22 @@ An example for the :class:`ThreadingMixIn` class::
HOST, PORT = "localhost", 0
server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
- ip, port = server.server_address
+ with server:
+ ip, port = server.server_address
- # Start a thread with the server -- that thread will then start one
- # more thread for each request
- server_thread = threading.Thread(target=server.serve_forever)
- # Exit the server thread when the main thread terminates
- server_thread.daemon = True
- server_thread.start()
- print("Server loop running in thread:", server_thread.name)
+ # Start a thread with the server -- that thread will then start one
+ # more thread for each request
+ server_thread = threading.Thread(target=server.serve_forever)
+ # Exit the server thread when the main thread terminates
+ server_thread.daemon = True
+ server_thread.start()
+ print("Server loop running in thread:", server_thread.name)
- client(ip, port, "Hello World 1")
- client(ip, port, "Hello World 2")
- client(ip, port, "Hello World 3")
+ client(ip, port, "Hello World 1")
+ client(ip, port, "Hello World 2")
+ client(ip, port, "Hello World 3")
- server.shutdown()
- server.server_close()
+ server.shutdown()
The output of the example should look something like this:
@@ -616,3 +636,5 @@ The output of the example should look something like this:
The :class:`ForkingMixIn` class is used in the same way, except that the server
will spawn a new process for each request.
+Available only on POSIX platforms that support :func:`~os.fork`.
+
diff --git a/Doc/library/spwd.rst b/Doc/library/spwd.rst
index fd3c9ad..c6cad2a 100644
--- a/Doc/library/spwd.rst
+++ b/Doc/library/spwd.rst
@@ -55,6 +55,9 @@ The following functions are defined:
Return the shadow password database entry for the given user name.
+ .. versionchanged:: 3.6
+ Raises a :exc:`PermissionError` instead of :exc:`KeyError` if the user
+ doesn't have privileges.
.. function:: getspall()
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index 84a4783..5635577 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -629,9 +629,16 @@ Cursor Objects
.. attribute:: lastrowid
This read-only attribute provides the rowid of the last modified row. It is
- only set if you issued an ``INSERT`` statement using the :meth:`execute`
- method. For operations other than ``INSERT`` or when :meth:`executemany` is
- called, :attr:`lastrowid` is set to :const:`None`.
+ only set if you issued an ``INSERT`` or a ``REPLACE`` statement using the
+ :meth:`execute` method. For operations other than ``INSERT`` or
+ ``REPLACE`` or when :meth:`executemany` is called, :attr:`lastrowid` is
+ set to :const:`None`.
+
+ If the ``INSERT`` or ``REPLACE`` statement failed to insert the previous
+ successful rowid is returned.
+
+ .. versionchanged:: 3.6
+ Added support for the ``REPLACE`` statement.
.. attribute:: description
@@ -918,9 +925,7 @@ Controlling Transactions
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`` or the aforementioned).
+``INSERT``/``UPDATE``/``DELETE``/``REPLACE``).
So if you are within a transaction and issue a command like ``CREATE TABLE
...``, ``VACUUM``, ``PRAGMA``, the :mod:`sqlite3` module will commit implicitly
@@ -940,6 +945,9 @@ Otherwise leave it at its default, which will result in a plain "BEGIN"
statement, or set it to one of SQLite's supported isolation levels: "DEFERRED",
"IMMEDIATE" or "EXCLUSIVE".
+.. versionchanged:: 3.6
+ :mod:`sqlite3` used to implicitly commit an open transaction before DDL
+ statements. This is no longer the case.
Using :mod:`sqlite3` efficiently
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index a2f0083..eee4849 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -49,6 +49,12 @@ For more sophisticated applications, the :class:`ssl.SSLContext` class
helps manage settings and certificates, which can then be inherited
by SSL sockets created through the :meth:`SSLContext.wrap_socket` method.
+.. versionchanged:: 3.6
+
+ OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported.
+ In the future the ssl module will require at least OpenSSL 1.0.2 or
+ 1.1.0.
+
Functions, Constants, and Exceptions
------------------------------------
@@ -186,16 +192,20 @@ instead.
.. table::
- ======================== ========= ========= ========== ========= =========== ===========
- *client* / **server** **SSLv2** **SSLv3** **TLS** **TLSv1** **TLSv1.1** **TLSv1.2**
- ------------------------ --------- --------- ---------- --------- ----------- -----------
- *SSLv2* yes no yes no no no
- *SSLv3* no yes yes no no no
- *TLS* (*SSLv23*) no yes yes yes yes yes
- *TLSv1* no no yes yes no no
- *TLSv1.1* no no yes no yes no
- *TLSv1.2* no no yes no no yes
- ======================== ========= ========= ========== ========= =========== ===========
+ ======================== ============ ============ ============= ========= =========== ===========
+ *client* / **server** **SSLv2** **SSLv3** **TLS** **TLSv1** **TLSv1.1** **TLSv1.2**
+ ------------------------ ------------ ------------ ------------- --------- ----------- -----------
+ *SSLv2* yes no no [1]_ no no no
+ *SSLv3* no yes no [2]_ no no no
+ *TLS* (*SSLv23*) no [1]_ no [2]_ yes yes yes yes
+ *TLSv1* no no yes yes no no
+ *TLSv1.1* no no yes no yes no
+ *TLSv1.2* no no yes no no yes
+ ======================== ============ ============ ============= ========= =========== ===========
+
+ .. rubric:: Footnotes
+ .. [1] :class:`SSLContext` disables SSLv2 with :data:`OP_NO_SSLv2` by default.
+ .. [2] :class:`SSLContext` disables SSLv3 with :data:`OP_NO_SSLv3` by default.
.. note::
@@ -224,7 +234,6 @@ instead.
.. versionchanged:: 3.2
New optional argument *ciphers*.
-
Context creation
^^^^^^^^^^^^^^^^
@@ -279,7 +288,7 @@ purposes.
RC4 was dropped from the default cipher string.
- .. versionchanged:: 3.5.3
+ .. versionchanged:: 3.6
ChaCha20/Poly1305 was added to the default cipher string.
@@ -322,7 +331,7 @@ Random generation
.. versionadded:: 3.3
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
OpenSSL has deprecated :func:`ssl.RAND_pseudo_bytes`, use
:func:`ssl.RAND_bytes` instead.
@@ -509,6 +518,10 @@ Certificate handling
Constants
^^^^^^^^^
+ All constants are now :class:`enum.IntEnum` or :class:`enum.IntFlag` collections.
+
+ .. versionadded:: 3.6
+
.. data:: CERT_NONE
Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
@@ -542,6 +555,12 @@ Constants
be passed, either to :meth:`SSLContext.load_verify_locations` or as a
value of the ``ca_certs`` parameter to :func:`wrap_socket`.
+.. class:: VerifyMode
+
+ :class:`enum.IntEnum` collection of CERT_* constants.
+
+ .. versionadded:: 3.6
+
.. data:: VERIFY_DEFAULT
Possible value for :attr:`SSLContext.verify_flags`. In this mode, certificate
@@ -582,18 +601,40 @@ Constants
.. versionadded:: 3.4.4
+.. class:: VerifyFlags
+
+ :class:`enum.IntFlag` collection of VERIFY_* constants.
+
+ .. versionadded:: 3.6
+
.. data:: PROTOCOL_TLS
Selects the highest protocol version that both the client and server support.
Despite the name, this option can select "TLS" protocols as well as "SSL".
- .. versionadded:: 3.5.3
+ .. versionadded:: 3.6
+
+.. data:: PROTOCOL_TLS_CLIENT
+
+ Auto-negotiate the the highest protocol version like :data:`PROTOCOL_SSLv23`,
+ but only support client-side :class:`SSLSocket` connections. The protocol
+ enables :data:`CERT_REQUIRED` and :attr:`~SSLContext.check_hostname` by
+ default.
+
+ .. versionadded:: 3.6
+
+.. data:: PROTOCOL_TLS_SERVER
+
+ Auto-negotiate the the highest protocol version like :data:`PROTOCOL_SSLv23`,
+ but only support server-side :class:`SSLSocket` connections.
+
+ .. versionadded:: 3.6
.. data:: PROTOCOL_SSLv23
Alias for data:`PROTOCOL_TLS`.
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
Use data:`PROTOCOL_TLS` instead.
@@ -608,7 +649,7 @@ Constants
SSL version 2 is insecure. Its use is highly discouraged.
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
OpenSSL has removed support for SSLv2.
@@ -623,7 +664,7 @@ Constants
SSL version 3 is insecure. Its use is highly discouraged.
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
OpenSSL has deprecated all version specific protocols. Use the default
protocol data:`PROTOCOL_TLS` with flags like data:`OP_NO_SSLv3` instead.
@@ -632,7 +673,7 @@ Constants
Selects TLS version 1.0 as the channel encryption protocol.
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
OpenSSL has deprecated all version specific protocols. Use the default
protocol data:`PROTOCOL_TLS` with flags like data:`OP_NO_SSLv3` instead.
@@ -644,7 +685,7 @@ Constants
.. versionadded:: 3.4
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
OpenSSL has deprecated all version specific protocols. Use the default
protocol data:`PROTOCOL_TLS` with flags like data:`OP_NO_SSLv3` instead.
@@ -657,7 +698,7 @@ Constants
.. versionadded:: 3.4
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
OpenSSL has deprecated all version specific protocols. Use the default
protocol data:`PROTOCOL_TLS` with flags like data:`OP_NO_SSLv3` instead.
@@ -678,7 +719,7 @@ Constants
.. versionadded:: 3.2
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
SSLv2 is deprecated
@@ -691,7 +732,7 @@ Constants
.. versionadded:: 3.2
- .. deprecated:: 3.5.3
+ .. deprecated:: 3.6
SSLv3 is deprecated
@@ -751,6 +792,16 @@ Constants
.. versionadded:: 3.3
+.. class:: Options
+
+ :class:`enum.IntFlag` collection of OP_* constants.
+
+.. data:: OP_NO_TICKET
+
+ Prevent client side from requesting a session ticket.
+
+ .. versionadded:: 3.6
+
.. data:: HAS_ALPN
Whether the OpenSSL library has built-in support for the *Application-Layer
@@ -833,6 +884,12 @@ Constants
.. versionadded:: 3.4
+.. class:: AlertDescription
+
+ :class:`enum.IntEnum` collection of ALERT_DESCRIPTION_* constants.
+
+ .. versionadded:: 3.6
+
.. data:: Purpose.SERVER_AUTH
Option for :func:`create_default_context` and
@@ -851,6 +908,12 @@ Constants
.. versionadded:: 3.4
+.. class:: SSLErrorNumber
+
+ :class:`enum.IntEnum` collection of SSL_ERROR_* constants.
+
+ .. versionadded:: 3.6
+
SSL Sockets
-----------
@@ -885,7 +948,7 @@ SSL Sockets
:ref:`notes on non-blocking sockets <ssl-nonblocking>`.
Usually, :class:`SSLSocket` are not created directly, but using the
- :func:`wrap_socket` function or the :meth:`SSLContext.wrap_socket` method.
+ the :meth:`SSLContext.wrap_socket` method.
.. versionchanged:: 3.5
The :meth:`sendfile` method was added.
@@ -895,6 +958,10 @@ SSL Sockets
are received or sent. The socket timeout is now to maximum total duration
of the shutdown.
+ .. deprecated:: 3.6
+ It is deprecated to create a :class:`SSLSocket` instance directly, use
+ :meth:`SSLContext.wrap_socket` to wrap a socket.
+
SSL sockets also have the following additional methods and attributes:
@@ -915,6 +982,9 @@ SSL sockets also have the following additional methods and attributes:
The socket timeout is now to maximum total duration to read up to *len*
bytes.
+ .. deprecated:: 3.6
+ Use :meth:`~SSLSocket.recv` instead of :meth:`~SSLSocket.read`.
+
.. method:: SSLSocket.write(buf)
Write *buf* to the SSL socket and return the number of bytes written. The
@@ -930,6 +1000,9 @@ SSL sockets also have the following additional methods and attributes:
The socket timeout is no more reset each time bytes are received or sent.
The socket timeout is now to maximum total duration to write *buf*.
+ .. deprecated:: 3.6
+ Use :meth:`~SSLSocket.send` instead of :meth:`~SSLSocket.write`.
+
.. note::
The :meth:`~SSLSocket.read` and :meth:`~SSLSocket.write` methods are the
@@ -1127,6 +1200,19 @@ SSL sockets also have the following additional methods and attributes:
.. versionadded:: 3.2
+.. attribute:: SSLSocket.session
+
+ The :class:`SSLSession` for this SSL connection. The session is available
+ for client and server side sockets after the TLS handshake has been
+ performed. For client sockets the session can be set before
+ :meth:`~SSLSocket.do_handshake` has been called to reuse a session.
+
+ .. versionadded:: 3.6
+
+.. attribute:: SSLSocket.session_reused
+
+ .. versionadded:: 3.6
+
SSL Contexts
------------
@@ -1149,9 +1235,16 @@ to speed up repeated connections from the same clients.
:func:`create_default_context` lets the :mod:`ssl` module choose
security settings for a given purpose.
- .. versionchanged:: 3.5.3
+ .. versionchanged:: 3.6
- :data:`PROTOCOL_TLS` is the default value.
+ The context is created with secure default values. The options
+ :data:`OP_NO_COMPRESSION`, :data:`OP_CIPHER_SERVER_PREFERENCE`,
+ :data:`OP_SINGLE_DH_USE`, :data:`OP_SINGLE_ECDH_USE`,
+ :data:`OP_NO_SSLv2` (except for :data:`PROTOCOL_SSLv2`),
+ and :data:`OP_NO_SSLv3` (except for :data:`PROTOCOL_SSLv3`) are
+ set by default. The initial cipher suite list contains only ``HIGH``
+ ciphers, no ``NULL`` ciphers and no ``MD5`` ciphers (except for
+ :data:`PROTOCOL_SSLv2`).
:class:`SSLContext` objects have the following methods and attributes:
@@ -1259,6 +1352,62 @@ to speed up repeated connections from the same clients.
.. versionadded:: 3.4
+.. method:: SSLContext.get_ciphers()
+
+ Get a list of enabled ciphers. The list is in order of cipher priority.
+ See :meth:`SSLContext.set_ciphers`.
+
+ Example::
+
+ >>> ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ >>> ctx.set_ciphers('ECDHE+AESGCM:!ECDSA')
+ >>> ctx.get_ciphers() # OpenSSL 1.0.x
+ [{'alg_bits': 256,
+ 'description': 'ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA '
+ 'Enc=AESGCM(256) Mac=AEAD',
+ 'id': 50380848,
+ 'name': 'ECDHE-RSA-AES256-GCM-SHA384',
+ 'protocol': 'TLSv1/SSLv3',
+ 'strength_bits': 256},
+ {'alg_bits': 128,
+ 'description': 'ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA '
+ 'Enc=AESGCM(128) Mac=AEAD',
+ 'id': 50380847,
+ 'name': 'ECDHE-RSA-AES128-GCM-SHA256',
+ 'protocol': 'TLSv1/SSLv3',
+ 'strength_bits': 128}]
+
+ On OpenSSL 1.1 and newer the cipher dict contains additional fields::
+ >>> ctx.get_ciphers() # OpenSSL 1.1+
+ [{'aead': True,
+ 'alg_bits': 256,
+ 'auth': 'auth-rsa',
+ 'description': 'ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA '
+ 'Enc=AESGCM(256) Mac=AEAD',
+ 'digest': None,
+ 'id': 50380848,
+ 'kea': 'kx-ecdhe',
+ 'name': 'ECDHE-RSA-AES256-GCM-SHA384',
+ 'protocol': 'TLSv1.2',
+ 'strength_bits': 256,
+ 'symmetric': 'aes-256-gcm'},
+ {'aead': True,
+ 'alg_bits': 128,
+ 'auth': 'auth-rsa',
+ 'description': 'ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA '
+ 'Enc=AESGCM(128) Mac=AEAD',
+ 'digest': None,
+ 'id': 50380847,
+ 'kea': 'kx-ecdhe',
+ 'name': 'ECDHE-RSA-AES128-GCM-SHA256',
+ 'protocol': 'TLSv1.2',
+ 'strength_bits': 128,
+ 'symmetric': 'aes-128-gcm'}]
+
+ Availability: OpenSSL 1.0.2+
+
+ .. versionadded:: 3.6
+
.. method:: SSLContext.set_default_verify_paths()
Load a set of default "certification authority" (CA) certificates from
@@ -1397,7 +1546,7 @@ to speed up repeated connections from the same clients.
.. method:: SSLContext.wrap_socket(sock, server_side=False, \
do_handshake_on_connect=True, suppress_ragged_eofs=True, \
- server_hostname=None)
+ server_hostname=None, session=None)
Wrap an existing Python socket *sock* and return an :class:`SSLSocket`
object. *sock* must be a :data:`~socket.SOCK_STREAM` socket; other socket
@@ -1414,19 +1563,27 @@ to speed up repeated connections from the same clients.
quite similarly to HTTP virtual hosts. Specifying *server_hostname* will
raise a :exc:`ValueError` if *server_side* is true.
+ *session*, see :attr:`~SSLSocket.session`.
+
.. versionchanged:: 3.5
Always allow a server_hostname to be passed, even if OpenSSL does not
have SNI.
+ .. versionchanged:: 3.6
+ *session* argument was added.
+
.. method:: SSLContext.wrap_bio(incoming, outgoing, server_side=False, \
- server_hostname=None)
+ server_hostname=None, session=None)
Create a new :class:`SSLObject` instance by wrapping the BIO objects
*incoming* and *outgoing*. The SSL routines will read input data from the
incoming BIO and write data to the outgoing BIO.
- The *server_side* and *server_hostname* parameters have the same meaning as
- in :meth:`SSLContext.wrap_socket`.
+ The *server_side*, *server_hostname* and *session* parameters have the
+ same meaning as in :meth:`SSLContext.wrap_socket`.
+
+ .. versionchanged:: 3.6
+ *session* argument was added.
.. method:: SSLContext.session_stats()
@@ -1478,6 +1635,12 @@ to speed up repeated connections from the same clients.
to set options, not to clear them. Attempting to clear an option
(by resetting the corresponding bits) will raise a ``ValueError``.
+ .. versionchanged:: 3.6
+ :attr:`SSLContext.options` returns :class:`Options` flags:
+
+ >>> ssl.create_default_context().options
+ <Options.OP_ALL|OP_NO_SSLv3|OP_NO_SSLv2|OP_NO_COMPRESSION: 2197947391>
+
.. attribute:: SSLContext.protocol
The protocol version chosen when constructing the context. This attribute
@@ -1492,12 +1655,23 @@ to speed up repeated connections from the same clients.
.. versionadded:: 3.4
+ .. versionchanged:: 3.6
+ :attr:`SSLContext.verify_flags` returns :class:`VerifyFlags` flags:
+
+ >>> ssl.create_default_context().verify_flags
+ <VerifyFlags.VERIFY_X509_TRUSTED_FIRST: 32768>
+
.. attribute:: SSLContext.verify_mode
Whether to try to verify other peers' certificates and how to behave
if verification fails. This attribute must be one of
:data:`CERT_NONE`, :data:`CERT_OPTIONAL` or :data:`CERT_REQUIRED`.
+ .. versionchanged:: 3.6
+ :attr:`SSLContext.verify_mode` returns :class:`VerifyMode` enum:
+
+ >>> ssl.create_default_context().verify_mode
+ <VerifyMode.CERT_REQUIRED: 2>
.. index:: single: certificates
@@ -1916,6 +2090,8 @@ provided.
- :attr:`~SSLSocket.context`
- :attr:`~SSLSocket.server_side`
- :attr:`~SSLSocket.server_hostname`
+ - :attr:`~SSLSocket.session`
+ - :attr:`~SSLSocket.session_reused`
- :meth:`~SSLSocket.read`
- :meth:`~SSLSocket.write`
- :meth:`~SSLSocket.getpeercert`
@@ -1997,6 +2173,22 @@ purpose. It wraps an OpenSSL memory BIO (Basic IO) object:
become true after all data currently in the buffer has been read.
+SSL session
+-----------
+
+.. versionadded:: 3.6
+
+.. class:: SSLSession
+
+ Session object used by :attr:`~SSLSocket.session`.
+
+ .. attribute:: id
+ .. attribute:: time
+ .. attribute:: timeout
+ .. attribute:: ticket_lifetime_hint
+ .. attribute:: has_ticket
+
+
.. _ssl-security:
Security considerations
@@ -2063,18 +2255,20 @@ Protocol versions
SSL versions 2 and 3 are considered insecure and are therefore dangerous to
use. If you want maximum compatibility between clients and servers, it is
-recommended to use :const:`PROTOCOL_TLS` as the protocol version and then
-disable SSLv2 and SSLv3 explicitly using the :data:`SSLContext.options`
-attribute::
+recommended to use :const:`PROTOCOL_TLS_CLIENT` or
+:const:`PROTOCOL_TLS_SERVER` as the protocol version. SSLv2 and SSLv3 are
+disabled by default.
+
+ >>> client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
+ >>> client_context.options |= ssl.OP_NO_TLSv1
+ >>> client_context.options |= ssl.OP_NO_TLSv1_1
- context = ssl.SSLContext(ssl.PROTOCOL_TLS)
- context.options |= ssl.OP_NO_SSLv2
- context.options |= ssl.OP_NO_SSLv3
- context.options |= ssl.OP_NO_TLSv1
- context.options |= ssl.OP_NO_TLSv1_1
The SSL context created above will only allow TLSv1.2 and later (if
-supported by your system) connections.
+supported by your system) connections to a server. :const:`PROTOCOL_TLS_CLIENT`
+implies certificate validation and hostname checks by default. You have to
+load certificates into the context.
+
Cipher selection
''''''''''''''''
@@ -2085,8 +2279,9 @@ enabled when negotiating a SSL session is possible through the
ssl module disables certain weak ciphers by default, but you may want
to further restrict the cipher choice. Be sure to read OpenSSL's documentation
about the `cipher list format <https://www.openssl.org/docs/apps/ciphers.html#CIPHER-LIST-FORMAT>`_.
-If you want to check which ciphers are enabled by a given cipher list, use the
-``openssl ciphers`` command on your system.
+If you want to check which ciphers are enabled by a given cipher list, use
+:meth:`SSLContext.get_ciphers` or the ``openssl ciphers`` command on your
+system.
Multi-processing
^^^^^^^^^^^^^^^^
diff --git a/Doc/library/statistics.rst b/Doc/library/statistics.rst
index ea3d7da..c020a34 100644
--- a/Doc/library/statistics.rst
+++ b/Doc/library/statistics.rst
@@ -39,6 +39,7 @@ or sample.
======================= =============================================
:func:`mean` Arithmetic mean ("average") of data.
+:func:`harmonic_mean` Harmonic mean of data.
:func:`median` Median (middle value) of data.
:func:`median_low` Low median of data.
:func:`median_high` High median of data.
@@ -111,6 +112,38 @@ However, for reading convenience, most of the examples show sorted sequences.
``mean(data)`` is equivalent to calculating the true population mean μ.
+.. function:: harmonic_mean(data)
+
+ Return the harmonic mean of *data*, a sequence or iterator of
+ real-valued numbers.
+
+ The harmonic mean, sometimes called the subcontrary mean, is the
+ reciprocal of the arithmetic :func:`mean` of the reciprocals of the
+ data. For example, the harmonic mean of three values *a*, *b* and *c*
+ will be equivalent to ``3/(1/a + 1/b + 1/c)``.
+
+ The harmonic mean is a type of average, a measure of the central
+ location of the data. It is often appropriate when averaging quantities
+ which are rates or ratios, for example speeds. For example:
+
+ Suppose an investor purchases an equal value of shares in each of
+ three companies, with P/E (price/earning) ratios of 2.5, 3 and 10.
+ What is the average P/E ratio for the investor's portfolio?
+
+ .. doctest::
+
+ >>> harmonic_mean([2.5, 3, 10]) # For an equal investment portfolio.
+ 3.6
+
+ Using the arithmetic mean would give an average of about 5.167, which
+ is too high.
+
+ :exc:`StatisticsError` is raised if *data* is empty, or any element
+ is less than zero.
+
+ .. versionadded:: 3.6
+
+
.. function:: median(data)
Return the median (middle value) of numeric data, using the common "mean of
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index 2587ac8..19a02ff 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -1363,6 +1363,11 @@ objects that compare equal might have different :attr:`~range.start`,
The :attr:`~range.start`, :attr:`~range.stop` and :attr:`~range.step`
attributes.
+.. seealso::
+
+ * The `linspace recipe <http://code.activestate.com/recipes/579000/>`_
+ shows how to implement a lazy version of range that suitable for floating
+ point applications.
.. index::
single: string; text sequence type
@@ -1453,8 +1458,8 @@ multiple fragments.
For more information on the ``str`` class and its methods, see
:ref:`textseq` and the :ref:`string-methods` section below. To output
- formatted strings, see the :ref:`formatstrings` section. In addition,
- see the :ref:`stringservices` section.
+ formatted strings, see the :ref:`f-strings` and :ref:`formatstrings`
+ sections. In addition, see the :ref:`stringservices` section.
.. index::
@@ -2056,8 +2061,8 @@ expression support in the :mod:`re` module).
.. index::
single: formatting, string (%)
single: interpolation, string (%)
- single: string; formatting
- single: string; interpolation
+ single: string; formatting, printf
+ single: string; interpolation, printf
single: printf-style formatting
single: sprintf-style formatting
single: % formatting
@@ -2067,9 +2072,10 @@ expression support in the :mod:`re` module).
The formatting operations described here exhibit a variety of quirks that
lead to a number of common errors (such as failing to display tuples and
- dictionaries correctly). Using the newer :meth:`str.format` interface
- helps avoid these errors, and also provides a generally more powerful,
- flexible and extensible approach to formatting text.
+ dictionaries correctly). Using the newer :ref:`formatted
+ string literals <f-strings>` or the :meth:`str.format` interface
+ helps avoid these errors. These alternatives also provide more powerful,
+ flexible and extensible approaches to formatting text.
String objects have one unique built-in operation: the ``%`` operator (modulo).
This is also known as the string *formatting* or *interpolation* operator.
@@ -2630,8 +2636,8 @@ arbitrary binary data.
The prefix(es) to search for may be any :term:`bytes-like object`.
-.. method:: bytes.translate(table[, delete])
- bytearray.translate(table[, delete])
+.. method:: bytes.translate(table, delete=b'')
+ bytearray.translate(table, delete=b'')
Return a copy of the bytes or bytearray object where all bytes occurring in
the optional argument *delete* are removed, and the remaining bytes have
@@ -2647,6 +2653,9 @@ arbitrary binary data.
>>> b'read this short text'.translate(None, b'aeiou')
b'rd ths shrt txt'
+ .. versionchanged:: 3.6
+ *delete* is now supported as a keyword argument.
+
The following methods on bytes and bytearray objects have default behaviours
that assume the use of ASCII compatible binary formats, but can still be used
diff --git a/Doc/library/string.rst b/Doc/library/string.rst
index 05418a9..a0977b6 100644
--- a/Doc/library/string.rst
+++ b/Doc/library/string.rst
@@ -188,7 +188,9 @@ Format String Syntax
The :meth:`str.format` method and the :class:`Formatter` class share the same
syntax for format strings (although in the case of :class:`Formatter`,
-subclasses can define their own format string syntax).
+subclasses can define their own format string syntax). The syntax is
+related to that of :ref:`formatted string literals <f-strings>`, but
+there are differences.
Format strings contain "replacement fields" surrounded by curly braces ``{}``.
Anything that is not contained in braces is considered literal text, which is
@@ -283,7 +285,8 @@ Format Specification Mini-Language
"Format specifications" are used within replacement fields contained within a
format string to define how individual values are presented (see
-:ref:`formatstrings`). They can also be passed directly to the built-in
+:ref:`formatstrings` and :ref:`f-strings`).
+They can also be passed directly to the built-in
:func:`format` function. Each formattable type may define how the format
specification is to be interpreted.
@@ -297,18 +300,20 @@ non-empty format string typically modifies the result.
The general form of a *standard format specifier* is:
.. productionlist:: sf
- format_spec: [[`fill`]`align`][`sign`][#][0][`width`][,][.`precision`][`type`]
+ format_spec: [[`fill`]`align`][`sign`][#][0][`width`][`grouping_option`][.`precision`][`type`]
fill: <any character>
align: "<" | ">" | "=" | "^"
sign: "+" | "-" | " "
width: `integer`
+ grouping_option: "_" | ","
precision: `integer`
type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
If a valid *align* value is specified, it can be preceded by a *fill*
character that can be any character and defaults to a space if omitted.
It is not possible to use a literal curly brace ("``{``" or "``}``") as
-the *fill* character when using the :meth:`str.format`
+the *fill* character in a :ref:`formatted string literal
+<f-strings>` or when using the :meth:`str.format`
method. However, it is possible to insert a curly brace
with a nested replacement field. This limitation doesn't
affect the :func:`format` function.
@@ -374,6 +379,16 @@ instead.
.. versionchanged:: 3.1
Added the ``','`` option (see also :pep:`378`).
+The ``'_'`` option signals the use of an underscore for a thousands
+separator for floating point presentation types and for integer
+presentation type ``'d'``. For integer presentation types ``'b'``,
+``'o'``, ``'x'``, and ``'X'``, underscores will be inserted every 4
+digits. For other presentation types, specifying this option is an
+error.
+
+.. versionchanged:: 3.6
+ Added the ``'_'`` option (see also :pep:`515`).
+
*width* is a decimal integer defining the minimum field width. If not
specified, then the field width will be determined by the content.
diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst
index ae2e38f..7e861fd 100644
--- a/Doc/library/struct.rst
+++ b/Doc/library/struct.rst
@@ -216,6 +216,8 @@ platform-dependent.
+--------+--------------------------+--------------------+----------------+------------+
| ``N`` | :c:type:`size_t` | integer | | \(4) |
+--------+--------------------------+--------------------+----------------+------------+
+| ``e`` | \(7) | float | 2 | \(5) |
++--------+--------------------------+--------------------+----------------+------------+
| ``f`` | :c:type:`float` | float | 4 | \(5) |
+--------+--------------------------+--------------------+----------------+------------+
| ``d`` | :c:type:`double` | float | 8 | \(5) |
@@ -257,9 +259,10 @@ Notes:
fits your application.
(5)
- For the ``'f'`` and ``'d'`` conversion codes, the packed representation uses
- the IEEE 754 binary32 (for ``'f'``) or binary64 (for ``'d'``) format,
- regardless of the floating-point format used by the platform.
+ For the ``'f'``, ``'d'`` and ``'e'`` conversion codes, the packed
+ representation uses the IEEE 754 binary32, binary64 or binary16 format (for
+ ``'f'``, ``'d'`` or ``'e'`` respectively), regardless of the floating-point
+ format used by the platform.
(6)
The ``'P'`` format character is only available for the native byte ordering
@@ -268,6 +271,16 @@ Notes:
on the host system. The struct module does not interpret this as native
ordering, so the ``'P'`` format is not available.
+(7)
+ The IEEE 754 binary16 "half precision" type was introduced in the 2008
+ revision of the `IEEE 754 standard <ieee 754 standard_>`_. It has a sign
+ bit, a 5-bit exponent and 11-bit precision (with 10 bits explicitly stored),
+ and can represent numbers between approximately ``6.1e-05`` and ``6.5e+04``
+ at full precision. This type is not widely supported by C compilers: on a
+ typical machine, an unsigned short can be used for storage, but not for math
+ operations. See the Wikipedia page on the `half-precision floating-point
+ format <half precision format_>`_ for more information.
+
A format character may be preceded by an integral repeat count. For example,
the format string ``'4h'`` means exactly the same as ``'hhhh'``.
@@ -430,3 +443,7 @@ The :mod:`struct` module also defines the following type:
The calculated size of the struct (and hence of the bytes object produced
by the :meth:`pack` method) corresponding to :attr:`format`.
+
+.. _half precision format: https://en.wikipedia.org/wiki/Half-precision_floating-point_format
+
+.. _ieee 754 standard: https://en.wikipedia.org/wiki/IEEE_floating_point#IEEE_754-2008
diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst
index c1b28f8..ad2abe8 100644
--- a/Doc/library/subprocess.rst
+++ b/Doc/library/subprocess.rst
@@ -38,7 +38,8 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
.. function:: run(args, *, stdin=None, input=None, stdout=None, stderr=None,\
- shell=False, timeout=None, check=False)
+ shell=False, timeout=None, check=False, \
+ encoding=None, errors=None)
Run the command described by *args*. Wait for command to complete, then
return a :class:`CompletedProcess` instance.
@@ -60,15 +61,20 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
The *input* argument is passed to :meth:`Popen.communicate` and thus to the
subprocess's stdin. If used it must be a byte sequence, or a string if
- ``universal_newlines=True``. When used, the internal :class:`Popen` object
- is automatically created with ``stdin=PIPE``, and the *stdin* argument may
- not be used as well.
+ *encoding* or *errors* is specified or *universal_newlines* is true. When
+ used, the internal :class:`Popen` object is automatically created with
+ ``stdin=PIPE``, and the *stdin* argument may not be used as well.
If *check* is true, and the process exits with a non-zero exit code, a
:exc:`CalledProcessError` exception will be raised. Attributes of that
exception hold the arguments, the exit code, and stdout and stderr if they
were captured.
+ If *encoding* or *errors* are specified, or *universal_newlines* is true,
+ file objects for stdin, stdout and stderr are opened in text mode using the
+ specified *encoding* and *errors* or the :class:`io.TextIOWrapper` default.
+ Otherwise, file objects are opened in binary mode.
+
Examples::
>>> subprocess.run(["ls", "-l"]) # doesn't capture output
@@ -85,6 +91,10 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
.. versionadded:: 3.5
+ .. versionchanged:: 3.6
+
+ Added *encoding* and *errors* parameters
+
.. class:: CompletedProcess
The return value from :func:`run`, representing a process that has finished.
@@ -104,8 +114,8 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
.. attribute:: stdout
Captured stdout from the child process. A bytes sequence, or a string if
- :func:`run` was called with ``universal_newlines=True``. ``None`` if stdout
- was not captured.
+ :func:`run` was called with an encoding or errors. ``None`` if stdout was not
+ captured.
If you ran the process with ``stderr=subprocess.STDOUT``, stdout and
stderr will be combined in this attribute, and :attr:`stderr` will be
@@ -114,8 +124,8 @@ compatibility with older versions, see the :ref:`call-function-trio` section.
.. attribute:: stderr
Captured stderr from the child process. A bytes sequence, or a string if
- :func:`run` was called with ``universal_newlines=True``. ``None`` if stderr
- was not captured.
+ :func:`run` was called with an encoding or errors. ``None`` if stderr was not
+ captured.
.. method:: check_returncode()
@@ -249,19 +259,22 @@ default values. The arguments that are most commonly needed are:
.. index::
single: universal newlines; subprocess module
- If *universal_newlines* is ``False`` the file objects *stdin*, *stdout* and
- *stderr* will be opened as binary streams, and no line ending conversion is
- done.
+ If *encoding* or *errors* are specified, or *universal_newlines* is true,
+ the file objects *stdin*, *stdout* and *stderr* will be opened in text
+ mode using the *encoding* and *errors* specified in the call or the
+ defaults for :class:`io.TextIOWrapper`.
+
+ For *stdin*, line ending characters ``'\n'`` in the input will be converted
+ to the default line separator :data:`os.linesep`. For *stdout* and *stderr*,
+ all line endings in the output will be converted to ``'\n'``. For more
+ information see the documentation of the :class:`io.TextIOWrapper` class
+ when the *newline* argument to its constructor is ``None``.
- If *universal_newlines* is ``True``, these file objects
- will be opened as text streams in :term:`universal newlines` mode
- using the encoding returned by :func:`locale.getpreferredencoding(False)
- <locale.getpreferredencoding>`. For *stdin*, line ending characters
- ``'\n'`` in the input will be converted to the default line separator
- :data:`os.linesep`. For *stdout* and *stderr*, all line endings in the
- output will be converted to ``'\n'``. For more information see the
- documentation of the :class:`io.TextIOWrapper` class when the *newline*
- argument to its constructor is ``None``.
+ If text mode is not used, *stdin*, *stdout* and *stderr* will be opened as
+ binary streams. No encoding or line ending conversion is performed.
+
+ .. versionadded:: 3.6
+ Added *encoding* and *errors* parameters.
.. note::
@@ -306,7 +319,8 @@ functions.
stderr=None, preexec_fn=None, close_fds=True, shell=False, \
cwd=None, env=None, universal_newlines=False, \
startupinfo=None, creationflags=0, restore_signals=True, \
- start_new_session=False, pass_fds=())
+ start_new_session=False, pass_fds=(), *, \
+ encoding=None, errors=None)
Execute a child program in a new process. On POSIX, the class uses
:meth:`os.execvp`-like behavior to execute the child program. On Windows,
@@ -482,10 +496,14 @@ functions.
.. _side-by-side assembly: https://en.wikipedia.org/wiki/Side-by-Side_Assembly
- If *universal_newlines* is ``True``, the file objects *stdin*, *stdout*
- and *stderr* are opened as text streams in universal newlines mode, as
- described above in :ref:`frequently-used-arguments`, otherwise they are
- opened as binary streams.
+ If *encoding* or *errors* are specified, the file objects *stdin*, *stdout*
+ and *stderr* are opened in text mode with the specified encoding and
+ *errors*, as described above in :ref:`frequently-used-arguments`. If
+ *universal_newlines* is ``True``, they are opened in text mode with default
+ encoding. Otherwise, they are opened as binary streams.
+
+ .. versionadded:: 3.6
+ *encoding* and *errors* were added.
If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is
passed to the underlying ``CreateProcess`` function.
@@ -502,6 +520,10 @@ functions.
.. versionchanged:: 3.2
Added context manager support.
+ .. versionchanged:: 3.6
+ Popen destructor now emits a :exc:`ResourceWarning` warning if the child
+ process is still running.
+
Exceptions
^^^^^^^^^^
@@ -597,11 +619,12 @@ Instances of the :class:`Popen` class have the following methods:
Interact with process: Send data to stdin. Read data from stdout and stderr,
until end-of-file is reached. Wait for process to terminate. The optional
*input* argument should be data to be sent to the child process, or
- ``None``, if no data should be sent to the child. The type of *input*
- must be bytes or, if *universal_newlines* was ``True``, a string.
+ ``None``, if no data should be sent to the child. If streams were opened in
+ text mode, *input* must be a string. Otherwise, it must be bytes.
:meth:`communicate` returns a tuple ``(stdout_data, stderr_data)``.
- The data will be bytes or, if *universal_newlines* was ``True``, strings.
+ The data will be strings if streams were opened in text mode; otherwise,
+ bytes.
Note that if you want to send data to the process's stdin, you need to create
the Popen object with ``stdin=PIPE``. Similarly, to get anything other than
@@ -668,28 +691,30 @@ The following attributes are also available:
.. attribute:: Popen.stdin
If the *stdin* argument was :data:`PIPE`, this attribute is a writeable
- stream object as returned by :func:`open`. If the *universal_newlines*
- argument was ``True``, the stream is a text stream, otherwise it is a byte
- stream. If the *stdin* argument was not :data:`PIPE`, this attribute is
- ``None``.
+ stream object as returned by :func:`open`. If the *encoding* or *errors*
+ arguments were specified or the *universal_newlines* argument was ``True``,
+ the stream is a text stream, otherwise it is a byte stream. If the *stdin*
+ argument was not :data:`PIPE`, this attribute is ``None``.
.. attribute:: Popen.stdout
If the *stdout* argument was :data:`PIPE`, this attribute is a readable
stream object as returned by :func:`open`. Reading from the stream provides
- output from the child process. If the *universal_newlines* argument was
- ``True``, the stream is a text stream, otherwise it is a byte stream. If the
- *stdout* argument was not :data:`PIPE`, this attribute is ``None``.
+ output from the child process. If the *encoding* or *errors* arguments were
+ specified or the *universal_newlines* argument was ``True``, the stream is a
+ text stream, otherwise it is a byte stream. If the *stdout* argument was not
+ :data:`PIPE`, this attribute is ``None``.
.. attribute:: Popen.stderr
If the *stderr* argument was :data:`PIPE`, this attribute is a readable
stream object as returned by :func:`open`. Reading from the stream provides
- error output from the child process. If the *universal_newlines* argument was
- ``True``, the stream is a text stream, otherwise it is a byte stream. If the
- *stderr* argument was not :data:`PIPE`, this attribute is ``None``.
+ error output from the child process. If the *encoding* or *errors* arguments
+ were specified or the *universal_newlines* argument was ``True``, the stream
+ is a text stream, otherwise it is a byte stream. If the *stderr* argument was
+ not :data:`PIPE`, this attribute is ``None``.
.. warning::
@@ -882,7 +907,9 @@ calls these functions.
*timeout* was added.
-.. function:: check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False, timeout=None)
+.. function:: check_output(args, *, stdin=None, stderr=None, shell=False, \
+ encoding=None, errors=None, \
+ universal_newlines=False, timeout=None)
Run command with arguments and return its output.
@@ -1138,7 +1165,7 @@ handling consistency are valid for these functions.
Return ``(status, output)`` of executing *cmd* in a shell.
Execute the string *cmd* in a shell with :meth:`Popen.check_output` and
- return a 2-tuple ``(status, output)``. Universal newlines mode is used;
+ return a 2-tuple ``(status, output)``. The locale encoding is used;
see the notes on :ref:`frequently-used-arguments` for more details.
A trailing newline is stripped from the output.
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index 7aed75d..2d14a1d 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -256,7 +256,7 @@ always available.
(defaulting to zero), or another type of object. If it is an integer, zero
is considered "successful termination" and any nonzero value is considered
"abnormal termination" by shells and the like. Most systems require it to be
- in the range 0-127, and produce undefined results otherwise. Some systems
+ in the range 0--127, and produce undefined results otherwise. Some systems
have a convention for assigning specific meanings to specific exit codes, but
these are generally underdeveloped; Unix programs generally use 2 for command
line syntax errors and 1 for all other kind of errors. If another type of
@@ -269,6 +269,11 @@ always available.
the process when called from the main thread, and the exception is not
intercepted.
+ .. versionchanged:: 3.6
+ If an error occurs in the cleanup after the Python interpreter
+ has caught :exc:`SystemExit` (such as an error flushing buffered data
+ in the standard streams), the exit status is changed to 120.
+
.. data:: flags
@@ -423,25 +428,42 @@ always available.
.. function:: getfilesystemencoding()
- Return the name of the encoding used to convert Unicode filenames into
- system file names. The result value depends on the operating system:
+ Return the name of the encoding used to convert between Unicode
+ filenames and bytes filenames. For best compatibility, str should be
+ used for filenames in all cases, although representing filenames as bytes
+ is also supported. Functions accepting or returning filenames should support
+ either str or bytes and internally convert to the system's preferred
+ representation.
- * On Mac OS X, the encoding is ``'utf-8'``.
+ This encoding is always ASCII-compatible.
- * On Unix, the encoding is the user's preference according to the result of
- nl_langinfo(CODESET).
+ :func:`os.fsencode` and :func:`os.fsdecode` should be used to ensure that
+ the correct encoding and errors mode are used.
- * On Windows NT+, file names are Unicode natively, so no conversion is
- performed. :func:`getfilesystemencoding` still returns ``'mbcs'``, as
- this is the encoding that applications should use when they explicitly
- want to convert Unicode strings to byte strings that are equivalent when
- used as file names.
+ * On Mac OS X, the encoding is ``'utf-8'``.
- * On Windows 9x, the encoding is ``'mbcs'``.
+ * On Unix, the encoding is the locale encoding.
+
+ * On Windows, the encoding may be ``'utf-8'`` or ``'mbcs'``, depending
+ on user configuration.
.. versionchanged:: 3.2
:func:`getfilesystemencoding` result cannot be ``None`` anymore.
+ .. versionchanged:: 3.6
+ Windows is no longer guaranteed to return ``'mbcs'``. See :pep:`529`
+ and :func:`_enablelegacywindowsfsencoding` for more information.
+
+.. function:: getfilesystemencodeerrors()
+
+ Return the name of the error mode used to convert between Unicode filenames
+ and bytes filenames. The encoding name is returned from
+ :func:`getfilesystemencoding`.
+
+ :func:`os.fsencode` and :func:`os.fsdecode` should be used to ensure that
+ the correct encoding and errors mode are used.
+
+ .. versionadded:: 3.6
.. function:: getrefcount(object)
@@ -530,26 +552,15 @@ always available.
Return a named tuple describing the Windows version
currently running. The named elements are *major*, *minor*,
*build*, *platform*, *service_pack*, *service_pack_minor*,
- *service_pack_major*, *suite_mask*, and *product_type*.
- *service_pack* contains a string while all other values are
+ *service_pack_major*, *suite_mask*, *product_type* and
+ *platform_version*. *service_pack* contains a string,
+ *platform_version* a 3-tuple and all other values are
integers. The components can also be accessed by name, so
``sys.getwindowsversion()[0]`` is equivalent to
``sys.getwindowsversion().major``. For compatibility with prior
versions, only the first 5 elements are retrievable by indexing.
- *platform* may be one of the following values:
-
- +-----------------------------------------+-------------------------+
- | Constant | Platform |
- +=========================================+=========================+
- | :const:`0 (VER_PLATFORM_WIN32s)` | Win32s on Windows 3.1 |
- +-----------------------------------------+-------------------------+
- | :const:`1 (VER_PLATFORM_WIN32_WINDOWS)` | Windows 95/98/ME |
- +-----------------------------------------+-------------------------+
- | :const:`2 (VER_PLATFORM_WIN32_NT)` | Windows NT/2000/XP/x64 |
- +-----------------------------------------+-------------------------+
- | :const:`3 (VER_PLATFORM_WIN32_CE)` | Windows CE |
- +-----------------------------------------+-------------------------+
+ *platform* will be :const:`2 (VER_PLATFORM_WIN32_NT)`.
*product_type* may be one of the following values:
@@ -565,17 +576,23 @@ always available.
| | a domain controller. |
+---------------------------------------+---------------------------------+
-
This function wraps the Win32 :c:func:`GetVersionEx` function; see the
Microsoft documentation on :c:func:`OSVERSIONINFOEX` for more information
about these fields.
+ *platform_version* returns the accurate major version, minor version and
+ build number of the current operating system, rather than the version that
+ is being emulated for the process. It is intended for use in logging rather
+ than for feature detection.
+
Availability: Windows.
.. versionchanged:: 3.2
Changed to a named tuple and added *service_pack_minor*,
*service_pack_major*, *suite_mask*, and *product_type*.
+ .. versionchanged:: 3.6
+ Added *platform_version*
.. function:: get_coroutine_wrapper()
@@ -1082,18 +1099,6 @@ always available.
thus may not be available in all Python implementations.
-.. function:: settscdump(on_flag)
-
- Activate dumping of VM measurements using the Pentium timestamp counter, if
- *on_flag* is true. Deactivate these dumps if *on_flag* is off. The function is
- available only if Python was compiled with ``--with-tsc``. To understand
- the output of this dump, read :file:`Python/ceval.c` in the Python sources.
-
- .. impl-detail::
- This function is intimately bound to CPython implementation details and
- thus not likely to be implemented elsewhere.
-
-
.. function:: set_coroutine_wrapper(wrapper)
Allows intercepting creation of :term:`coroutine` objects (only ones that
@@ -1133,6 +1138,18 @@ always available.
This function has been added on a provisional basis (see :pep:`411`
for details.) Use it only for debugging purposes.
+.. function:: _enablelegacywindowsfsencoding()
+
+ Changes the default filesystem encoding and errors mode to 'mbcs' and
+ 'replace' respectively, for consistency with versions of Python prior to 3.6.
+
+ This is equivalent to defining the :envvar:`PYTHONLEGACYWINDOWSFSENCODING`
+ environment variable before launching Python.
+
+ Availability: Windows
+
+ .. versionadded:: 3.6
+ See :pep:`529` for more details.
.. data:: stdin
stdout
diff --git a/Doc/library/sysconfig.rst b/Doc/library/sysconfig.rst
index 02aaab3..08b74a9 100644
--- a/Doc/library/sysconfig.rst
+++ b/Doc/library/sysconfig.rst
@@ -164,7 +164,7 @@ Other functions
.. function:: get_python_version()
Return the ``MAJOR.MINOR`` Python version number as a string. Similar to
- ``sys.version[:3]``.
+ ``'%d.%d' % sys.version_info[:2]``.
.. function:: get_platform()
diff --git a/Doc/library/telnetlib.rst b/Doc/library/telnetlib.rst
index b950e41..f9c5153 100644
--- a/Doc/library/telnetlib.rst
+++ b/Doc/library/telnetlib.rst
@@ -43,6 +43,17 @@ Character), EL (Erase Line), GA (Go Ahead), SB (Subnegotiation Begin).
:exc:`EOFError` when the end of the connection is read, because they can return
an empty string for other reasons. See the individual descriptions below.
+ A :class:`Telnet` object is a context manager and can be used in a
+ :keyword:`with` statement. When the :keyword:`with` block ends, the
+ :meth:`close` method is called::
+
+ >>> from telnetlib import Telnet
+ >>> with Telnet('localhost', 23) as tn:
+ ... tn.interact()
+ ...
+
+ .. versionchanged:: 3.6 Context manager support added
+
.. seealso::
diff --git a/Doc/library/test.rst b/Doc/library/test.rst
index 59577f0..fab3e1f 100644
--- a/Doc/library/test.rst
+++ b/Doc/library/test.rst
@@ -582,6 +582,48 @@ The :mod:`test.support` module defines the following functions:
.. versionadded:: 3.5
+.. function:: check__all__(test_case, module, name_of_module=None, extra=(), blacklist=())
+
+ Assert that the ``__all__`` variable of *module* contains all public names.
+
+ The module's public names (its API) are detected automatically
+ based on whether they match the public name convention and were defined in
+ *module*.
+
+ The *name_of_module* argument can specify (as a string or tuple thereof) what
+ module(s) an API could be defined in in order to be detected as a public
+ API. One case for this is when *module* imports part of its public API from
+ other modules, possibly a C backend (like ``csv`` and its ``_csv``).
+
+ The *extra* argument can be a set of names that wouldn't otherwise be automatically
+ detected as "public", like objects without a proper ``__module__``
+ attribute. If provided, it will be added to the automatically detected ones.
+
+ The *blacklist* argument can be a set of names that must not be treated as part of
+ the public API even though their names indicate otherwise.
+
+ Example use::
+
+ import bar
+ import foo
+ import unittest
+ from test import support
+
+ class MiscTestCase(unittest.TestCase):
+ def test__all__(self):
+ support.check__all__(self, foo)
+
+ class OtherTestCase(unittest.TestCase):
+ def test__all__(self):
+ extra = {'BAR_CONST', 'FOO_CONST'}
+ blacklist = {'baz'} # Undocumented name.
+ # bar imports part of its API from _bar.
+ support.check__all__(self, bar, ('bar', '_bar'),
+ extra=extra, blacklist=blacklist)
+
+ .. versionadded:: 3.6
+
+
The :mod:`test.support` module defines the following classes:
.. class:: TransientResource(exc, **kwargs)
diff --git a/Doc/library/time.rst b/Doc/library/time.rst
index e6626f2..ae17f6f 100644
--- a/Doc/library/time.rst
+++ b/Doc/library/time.rst
@@ -83,6 +83,10 @@ An explanation of some terminology and conventions is in order.
and :attr:`tm_zone` attributes when platform supports corresponding
``struct tm`` members.
+ .. versionchanged:: 3.6
+ The :class:`struct_time` attributes :attr:`tm_gmtoff` and :attr:`tm_zone`
+ are now available on all platforms.
+
* Use the following functions to convert between time representations:
+-------------------------+-------------------------+-------------------------+
@@ -566,10 +570,6 @@ The module defines the following functions and data items:
:class:`struct_time`, or having elements of the wrong type, a
:exc:`TypeError` is raised.
- .. versionchanged:: 3.3
- :attr:`tm_gmtoff` and :attr:`tm_zone` attributes are available on platforms
- with C library supporting the corresponding fields in ``struct tm``.
-
.. function:: time()
Return the time in seconds since the epoch as a floating point number.
@@ -637,11 +637,11 @@ The module defines the following functions and data items:
it is possible to refer to February 29.
:samp:`M{m}.{n}.{d}`
- The *d*'th day (0 <= *d* <= 6) or week *n* of month *m* of the year (1
+ The *d*'th day (0 <= *d* <= 6) of week *n* of month *m* of the year (1
<= *n* <= 5, 1 <= *m* <= 12, where week 5 means "the last *d* day in
month *m*" which may occur in either the fourth or the fifth
week). Week 1 is the first week in which the *d*'th day occurs. Day
- zero is Sunday.
+ zero is a Sunday.
``time`` has the same format as ``offset`` except that no leading sign
('-' or '+') is allowed. The default, if time is not given, is 02:00:00.
diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst
index 57a4834..3b77276 100644
--- a/Doc/library/timeit.rst
+++ b/Doc/library/timeit.rst
@@ -100,8 +100,8 @@ The module defines three convenience functions and a public class:
can be controlled by passing a namespace to *globals*.
To measure the execution time of the first statement, use the :meth:`.timeit`
- method. The :meth:`.repeat` method is a convenience to call :meth:`.timeit`
- multiple times and return a list of results.
+ method. The :meth:`.repeat` and :meth:`.autorange` methods are convenience
+ methods to call :meth:`.timeit` multiple times.
The execution time of *setup* is excluded from the overall timed execution run.
@@ -134,6 +134,23 @@ The module defines three convenience functions and a public class:
timeit.Timer('for i in range(10): oct(i)', 'gc.enable()').timeit()
+ .. method:: Timer.autorange(callback=None)
+
+ Automatically determine how many times to call :meth:`.timeit`.
+
+ This is a convenience function that calls :meth:`.timeit` repeatedly
+ so that the total time >= 0.2 second, returning the eventual
+ (number of loops, time taken for that number of loops). It calls
+ :meth:`.timeit` with *number* set to successive powers of ten (10,
+ 100, 1000, ...) up to a maximum of one billion, until the time taken
+ is at least 0.2 second, or the maximum is reached.
+
+ If *callback* is given and is not ``None``, it will be called after
+ each trial with two arguments: ``callback(number, time_taken)``.
+
+ .. versionadded:: 3.6
+
+
.. method:: Timer.repeat(repeat=3, number=1000000)
Call :meth:`.timeit` a few times.
diff --git a/Doc/library/tkinter.tix.rst b/Doc/library/tkinter.tix.rst
index 41f20dd..11ed755 100644
--- a/Doc/library/tkinter.tix.rst
+++ b/Doc/library/tkinter.tix.rst
@@ -10,6 +10,10 @@
.. index:: single: Tix
+.. deprecated:: 3.6
+ This Tk extension is unmaintained and should not be used in new code. Use
+ :mod:`tkinter.ttk` instead.
+
--------------
The :mod:`tkinter.tix` (Tk Interface Extension) module provides an additional
diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst
index 3c1d9bb..066ee96 100644
--- a/Doc/library/traceback.rst
+++ b/Doc/library/traceback.rst
@@ -291,6 +291,20 @@ capture data for later printing in a lightweight fashion.
of tuples. Each tuple should be a 4-tuple with filename, lineno, name,
line as the elements.
+ .. method:: format()
+
+ Returns a list of strings ready for printing. Each string in the
+ resulting list corresponds to a single frame from the stack.
+ Each string ends in a newline; the strings may contain internal
+ newlines as well, for those items with source text lines.
+
+ For long sequences of the same frame and line, the first few
+ repetitions are shown, followed by a summary line stating the exact
+ number of further repetitions.
+
+ .. versionchanged:: 3.6
+ Long sequences of repeated frames are now abbreviated.
+
:class:`FrameSummary` Objects
-----------------------------
diff --git a/Doc/library/tracemalloc.rst b/Doc/library/tracemalloc.rst
index 3a0b1e0..f56f27b 100644
--- a/Doc/library/tracemalloc.rst
+++ b/Doc/library/tracemalloc.rst
@@ -359,10 +359,32 @@ Functions
See also the :func:`get_object_traceback` function.
+DomainFilter
+^^^^^^^^^^^^
+
+.. class:: DomainFilter(inclusive: bool, domain: int)
+
+ Filter traces of memory blocks by their address space (domain).
+
+ .. versionadded:: 3.6
+
+ .. attribute:: inclusive
+
+ If *inclusive* is ``True`` (include), match memory blocks allocated
+ in the address space :attr:`domain`.
+
+ If *inclusive* is ``False`` (exclude), match memory blocks not allocated
+ in the address space :attr:`domain`.
+
+ .. attribute:: domain
+
+ Address space of a memory block (``int``). Read-only property.
+
+
Filter
^^^^^^
-.. class:: Filter(inclusive: bool, filename_pattern: str, lineno: int=None, all_frames: bool=False)
+.. class:: Filter(inclusive: bool, filename_pattern: str, lineno: int=None, all_frames: bool=False, domain: int=None)
Filter on traces of memory blocks.
@@ -382,9 +404,17 @@ Filter
.. versionchanged:: 3.5
The ``'.pyo'`` file extension is no longer replaced with ``'.py'``.
+ .. versionchanged:: 3.6
+ Added the :attr:`domain` attribute.
+
+
+ .. attribute:: domain
+
+ Address space of a memory block (``int`` or ``None``).
+
.. attribute:: inclusive
- If *inclusive* is ``True`` (include), only trace memory blocks allocated
+ If *inclusive* is ``True`` (include), only match memory blocks allocated
in a file with a name matching :attr:`filename_pattern` at line number
:attr:`lineno`.
@@ -399,7 +429,7 @@ Filter
.. attribute:: filename_pattern
- Filename pattern of the filter (``str``).
+ Filename pattern of the filter (``str``). Read-only property.
.. attribute:: all_frames
@@ -462,14 +492,17 @@ Snapshot
.. method:: filter_traces(filters)
Create a new :class:`Snapshot` instance with a filtered :attr:`traces`
- sequence, *filters* is a list of :class:`Filter` instances. If *filters*
- is an empty list, return a new :class:`Snapshot` instance with a copy of
- the traces.
+ sequence, *filters* is a list of :class:`DomainFilter` and
+ :class:`Filter` instances. If *filters* is an empty list, return a new
+ :class:`Snapshot` instance with a copy of the traces.
All inclusive filters are applied at once, a trace is ignored if no
inclusive filters match it. A trace is ignored if at least one exclusive
filter matches it.
+ .. versionchanged:: 3.6
+ :class:`DomainFilter` instances are now also accepted in *filters*.
+
.. classmethod:: load(filename)
diff --git a/Doc/library/types.rst b/Doc/library/types.rst
index 118bc4c..898b95a 100644
--- a/Doc/library/types.rst
+++ b/Doc/library/types.rst
@@ -55,6 +55,12 @@ Dynamic Type Creation
.. versionadded:: 3.3
+ .. versionchanged:: 3.6
+
+ The default value for the ``namespace`` element of the returned
+ tuple has changed. Now an insertion-order-preserving mapping is
+ used when the metaclass does not have a ``__prepare__`` method,
+
.. seealso::
:ref:`metaclasses`
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 9f7fa1a..bbf5db6 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -10,8 +10,8 @@
--------------
-This module supports type hints as specified by :pep:`484`. The most
-fundamental support consists of the type :data:`Any`, :data:`Union`,
+This module supports type hints as specified by :pep:`484` and :pep:`526`.
+The most fundamental support consists of the type :data:`Any`, :data:`Union`,
:data:`Tuple`, :data:`Callable`, :class:`TypeVar`, and
:class:`Generic`. For full specification please see :pep:`484`. For
a simplified introduction to type hints see :pep:`483`.
@@ -507,7 +507,13 @@ The module defines the following classes, functions and decorators:
An alias to :class:`collections.abc.Sized`
-.. class:: AbstractSet(Sized, Iterable[T_co], Container[T_co])
+.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
+
+ A generic version of :class:`collections.abc.Collection`
+
+ .. versionadded:: 3.6
+
+.. class:: AbstractSet(Sized, Collection[T_co])
A generic version of :class:`collections.abc.Set`.
@@ -515,7 +521,7 @@ The module defines the following classes, functions and decorators:
A generic version of :class:`collections.abc.MutableSet`.
-.. class:: Mapping(Sized, Iterable[KT], Container[KT], Generic[VT_co])
+.. class:: Mapping(Sized, Collection[KT], Generic[VT_co])
A generic version of :class:`collections.abc.Mapping`.
@@ -523,7 +529,7 @@ The module defines the following classes, functions and decorators:
A generic version of :class:`collections.abc.MutableMapping`.
-.. class:: Sequence(Sized, Iterable[T_co], Container[T_co])
+.. class:: Sequence(Reversible[T_co], Collection[T_co])
A generic version of :class:`collections.abc.Sequence`.
@@ -590,6 +596,12 @@ The module defines the following classes, functions and decorators:
A generic version of :class:`collections.abc.AsyncIterator`.
+.. class:: ContextManager(Generic[T_co])
+
+ A generic version of :class:`contextlib.AbstractContextManager`.
+
+ .. versionadded:: 3.6
+
.. class:: Dict(dict, MutableMapping[KT, VT])
A generic version of :class:`dict`.
@@ -702,7 +714,7 @@ The module defines the following classes, functions and decorators:
.. function:: get_type_hints(obj)
- Return type hints for a function or method object.
+ Return type hints for a class, module, function or method object.
This is often the same as ``obj.__annotations__``, but it handles
forward references encoded as string literals, and if necessary
@@ -845,8 +857,8 @@ The module defines the following classes, functions and decorators:
and should not be set on instances of that class. Usage::
class Starship:
- stats = {} # type: ClassVar[Dict[str, int]] # class variable
- damage = 10 # type: int # instance variable
+ stats: ClassVar[Dict[str, int]] = {} # class variable
+ damage: int = 10 # instance variable
:data:`ClassVar` accepts only types and cannot be further subscribed.
diff --git a/Doc/library/undoc.rst b/Doc/library/undoc.rst
index 20830e2..2444080 100644
--- a/Doc/library/undoc.rst
+++ b/Doc/library/undoc.rst
@@ -20,7 +20,7 @@ These modules are used to implement the :mod:`os.path` module, and are not
documented beyond this mention. There's little need to document these.
:mod:`ntpath`
- --- Implementation of :mod:`os.path` on Win32, Win64, and WinCE platforms.
+ --- Implementation of :mod:`os.path` on Win32 and Win64 platforms.
:mod:`posixpath`
--- Implementation of :mod:`os.path` on POSIX.
diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst
index 6cd8132..6431809 100644
--- a/Doc/library/unicodedata.rst
+++ b/Doc/library/unicodedata.rst
@@ -17,8 +17,8 @@
This module provides access to the Unicode Character Database (UCD) which
defines character properties for all Unicode characters. The data contained in
-this database is compiled from the `UCD version 8.0.0
-<http://www.unicode.org/Public/8.0.0/ucd>`_.
+this database is compiled from the `UCD version 9.0.0
+<http://www.unicode.org/Public/9.0.0/ucd>`_.
The module uses the same names and symbols as defined by Unicode
Standard Annex #44, `"Unicode Character Database"
@@ -168,6 +168,6 @@ Examples:
.. rubric:: Footnotes
-.. [#] http://www.unicode.org/Public/8.0.0/ucd/NameAliases.txt
+.. [#] http://www.unicode.org/Public/9.0.0/ucd/NameAliases.txt
-.. [#] http://www.unicode.org/Public/8.0.0/ucd/NamedSequences.txt
+.. [#] http://www.unicode.org/Public/9.0.0/ucd/NamedSequences.txt
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst
index ef30c01..3cc22fd 100644
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -262,6 +262,34 @@ the *new_callable* argument to :func:`patch`.
used to set attributes on the mock after it is created. See the
:meth:`configure_mock` method for details.
+ .. method:: assert_called(*args, **kwargs)
+
+ Assert that the mock was called at least once.
+
+ >>> mock = Mock()
+ >>> mock.method()
+ <Mock name='mock.method()' id='...'>
+ >>> mock.method.assert_called()
+
+ .. versionadded:: 3.6
+
+ .. method:: assert_called_once(*args, **kwargs)
+
+ Assert that the mock was called exactly once.
+
+ >>> mock = Mock()
+ >>> mock.method()
+ <Mock name='mock.method()' id='...'>
+ >>> mock.method.assert_called_once()
+ >>> mock.method()
+ <Mock name='mock.method()' id='...'>
+ >>> mock.method.assert_called_once()
+ Traceback (most recent call last):
+ ...
+ AssertionError: Expected 'method' to have been called once. Called 2 times.
+
+ .. versionadded:: 3.6
+
.. method:: assert_called_with(*args, **kwargs)
@@ -339,7 +367,7 @@ the *new_callable* argument to :func:`patch`.
.. versionadded:: 3.5
- .. method:: reset_mock()
+ .. method:: reset_mock(*, return_value=False, side_effect=False)
The reset_mock method resets all the call attributes on a mock object:
@@ -351,12 +379,20 @@ the *new_callable* argument to :func:`patch`.
>>> mock.called
False
+ .. versionchanged:: 3.6
+ Added two keyword only argument to the reset_mock function.
+
This can be useful where you want to make a series of assertions that
reuse the same object. Note that :meth:`reset_mock` *doesn't* clear the
return value, :attr:`side_effect` or any child attributes you have
- set using normal assignment. Child mocks and the return value mock
+ set using normal assignment by default. In case you want to reset
+ *return_value* or :attr:`side_effect`, then pass the corresponding
+ parameter as ``True``. Child mocks and the return value mock
(if any) are reset as well.
+ .. note:: *return_value*, and :attr:`side_effect` are keyword only
+ argument.
+
.. method:: mock_add_spec(spec, spec_set=False)
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index b9b339b..1b0d7a7 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -1391,9 +1391,9 @@ Test cases
Add a function to be called after :meth:`tearDown` to cleanup resources
used during the test. Functions will be called in reverse order to the
- order they are added (LIFO). They are called with any arguments and
- keyword arguments passed into :meth:`addCleanup` when they are
- added.
+ order they are added (:abbr:`LIFO (last-in, first-out)`). They
+ are called with any arguments and keyword arguments passed into
+ :meth:`addCleanup` when they are added.
If :meth:`setUp` fails, meaning that :meth:`tearDown` is not called,
then any cleanup functions added will still be called.
diff --git a/Doc/library/urllib.parse.rst b/Doc/library/urllib.parse.rst
index 499b211..676321b 100644
--- a/Doc/library/urllib.parse.rst
+++ b/Doc/library/urllib.parse.rst
@@ -114,8 +114,9 @@ or on combining URL components into a URL string.
| | | if present | |
+------------------+-------+--------------------------+----------------------+
- See section :ref:`urlparse-result-object` for more information on the result
- object.
+ Reading the :attr:`port` attribute will raise a :exc:`ValueError` if
+ an invalid port is specified in the URL. See section
+ :ref:`urlparse-result-object` for more information on the result object.
.. versionchanged:: 3.2
Added IPv6 URL parsing capabilities.
@@ -125,6 +126,10 @@ or on combining URL components into a URL string.
false), in accordance with :rfc:`3986`. Previously, a whitelist of
schemes that support fragments existed.
+ .. versionchanged:: 3.6
+ Out-of-range port numbers now raise :exc:`ValueError`, instead of
+ returning :const:`None`.
+
.. function:: parse_qs(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace')
@@ -227,8 +232,13 @@ or on combining URL components into a URL string.
| | | if present | |
+------------------+-------+-------------------------+----------------------+
- See section :ref:`urlparse-result-object` for more information on the result
- object.
+ Reading the :attr:`port` attribute will raise a :exc:`ValueError` if
+ an invalid port is specified in the URL. See section
+ :ref:`urlparse-result-object` for more information on the result object.
+
+ .. versionchanged:: 3.6
+ Out-of-range port numbers now raise :exc:`ValueError`, instead of
+ returning :const:`None`.
.. function:: urlunsplit(parts)
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index 41b5ece..c990fb1 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -30,18 +30,9 @@ The :mod:`urllib.request` module defines the following functions:
Open the URL *url*, which can be either a string or a
:class:`Request` object.
- *data* must be a bytes object specifying additional data to be sent to the
- server, or ``None`` if no such data is needed. *data* may also be an
- iterable object and in that case Content-Length value must be specified in
- the headers. Currently HTTP requests are the only ones that use *data*; the
- HTTP request will be a POST instead of a GET when the *data* parameter is
- provided.
-
- *data* should be a buffer in the standard
- :mimetype:`application/x-www-form-urlencoded` format. The
- :func:`urllib.parse.urlencode` function takes a mapping or sequence of
- 2-tuples and returns an ASCII text string in this format. It should
- be encoded to bytes before being used as the *data* parameter.
+ *data* must be an object specifying additional data to be sent to the
+ server, or ``None`` if no such data is needed. See :class:`Request`
+ for details.
urllib.request module uses HTTP/1.1 and includes ``Connection:close`` header
in its HTTP requests.
@@ -120,6 +111,12 @@ The :mod:`urllib.request` module defines the following functions:
.. versionchanged:: 3.4.3
*context* was added.
+ .. deprecated:: 3.6
+
+ *cafile*, *capath* and *cadefault* are deprecated in favor of *context*.
+ Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let
+ :func:`ssl.create_default_context` select the system's trusted CA
+ certificates for you.
.. function:: install_opener(opener)
@@ -192,14 +189,21 @@ The following classes are provided:
*url* should be a string containing a valid URL.
- *data* must be a bytes object specifying additional data to send to the
- server, or ``None`` if no such data is needed. Currently HTTP requests are
- the only ones that use *data*; the HTTP request will be a POST instead of a
- GET when the *data* parameter is provided. *data* should be a buffer in the
- standard :mimetype:`application/x-www-form-urlencoded` format.
- The :func:`urllib.parse.urlencode` function takes a mapping or sequence of
- 2-tuples and returns an ASCII string in this format. It should be
- encoded to bytes before being used as the *data* parameter.
+ *data* must be an object specifying additional data to send to the
+ server, or ``None`` if no such data is needed. Currently HTTP
+ requests are the only ones that use *data*. The supported object
+ types include bytes, file-like objects, and iterables. If no
+ ``Content-Length`` nor ``Transfer-Encoding`` header field
+ has been provided, :class:`HTTPHandler` will set these headers according
+ to the type of *data*. ``Content-Length`` will be used to send
+ bytes objects, while ``Transfer-Encoding: chunked`` as specified in
+ :rfc:`7230`, Section 3.3.1 will be used to send files and other iterables.
+
+ For an HTTP POST request method, *data* should be a buffer in the
+ standard :mimetype:`application/x-www-form-urlencoded` format. The
+ :func:`urllib.parse.urlencode` function takes a mapping or sequence
+ of 2-tuples and returns an ASCII string in this format. It should
+ be encoded to bytes before being used as the *data* parameter.
*headers* should be a dictionary, and will be treated as if
:meth:`add_header` was called with each key and value as arguments.
@@ -211,8 +215,10 @@ The following classes are provided:
:mod:`urllib`'s default user agent string is
``"Python-urllib/2.6"`` (on Python 2.6).
- An example of using ``Content-Type`` header with *data* argument would be
- sending a dictionary like ``{"Content-Type": "application/x-www-form-urlencoded"}``.
+ An appropriate ``Content-Type`` header should be included if the *data*
+ argument is present. If this header has not been provided and *data*
+ is not None, ``Content-Type: application/x-www-form-urlencoded`` will
+ be added as a default.
The final two arguments are only of interest for correct handling
of third-party HTTP cookies:
@@ -235,15 +241,28 @@ The following classes are provided:
*method* should be a string that indicates the HTTP request method that
will be used (e.g. ``'HEAD'``). If provided, its value is stored in the
:attr:`~Request.method` attribute and is used by :meth:`get_method()`.
- Subclasses may indicate a default method by setting the
+ The default is ``'GET'`` if *data* is ``None`` or ``'POST'`` otherwise.
+ Subclasses may indicate a different default method by setting the
:attr:`~Request.method` attribute in the class itself.
+ .. note::
+ The request will not work as expected if the data object is unable
+ to deliver its content more than once (e.g. a file or an iterable
+ that can produce the content only once) and the request is retried
+ for HTTP redirects or authentication. The *data* is sent to the
+ HTTP server right away after the headers. There is no support for
+ a 100-continue expectation in the library.
+
.. versionchanged:: 3.3
:attr:`Request.method` argument is added to the Request class.
.. versionchanged:: 3.4
Default :attr:`Request.method` may be indicated at the class level.
+ .. versionchanged:: 3.6
+ Do not raise an error if the ``Content-Length`` has not been
+ provided and *data* is neither ``None`` nor a bytes object.
+ Fall back to use chunked transfer encoding instead.
.. class:: OpenerDirector()
diff --git a/Doc/library/urllib.robotparser.rst b/Doc/library/urllib.robotparser.rst
index ba701c3..7d31932 100644
--- a/Doc/library/urllib.robotparser.rst
+++ b/Doc/library/urllib.robotparser.rst
@@ -57,15 +57,41 @@ structure of :file:`robots.txt` files, see http://www.robotstxt.org/orig.html.
Sets the time the ``robots.txt`` file was last fetched to the current
time.
+ .. method:: crawl_delay(useragent)
-The following example demonstrates basic use of the RobotFileParser class.
+ Returns the value of the ``Crawl-delay`` parameter from ``robots.txt``
+ for the *useragent* in question. If there is no such parameter or it
+ doesn't apply to the *useragent* specified or the ``robots.txt`` entry
+ for this parameter has invalid syntax, return ``None``.
+
+ .. versionadded:: 3.6
+
+ .. method:: request_rate(useragent)
+
+ Returns the contents of the ``Request-rate`` parameter from
+ ``robots.txt`` in the form of a :func:`~collections.namedtuple`
+ ``(requests, seconds)``. If there is no such parameter or it doesn't
+ apply to the *useragent* specified or the ``robots.txt`` entry for this
+ parameter has invalid syntax, return ``None``.
+
+ .. versionadded:: 3.6
+
+
+The following example demonstrates basic use of the :class:`RobotFileParser`
+class::
>>> import urllib.robotparser
>>> rp = urllib.robotparser.RobotFileParser()
>>> rp.set_url("http://www.musi-cal.com/robots.txt")
>>> rp.read()
+ >>> rrate = rp.request_rate("*")
+ >>> rrate.requests
+ 3
+ >>> rrate.seconds
+ 20
+ >>> rp.crawl_delay("*")
+ 6
>>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
False
>>> rp.can_fetch("*", "http://www.musi-cal.com/")
True
-
diff --git a/Doc/library/venv.rst b/Doc/library/venv.rst
index 62892d4..a80d2d6 100644
--- a/Doc/library/venv.rst
+++ b/Doc/library/venv.rst
@@ -37,44 +37,50 @@ Creating virtual environments
.. _venv-def:
-.. note:: A virtual environment (also called a ``venv``) is a Python
- environment such that the Python interpreter, libraries and scripts
- installed into it are isolated from those installed in other virtual
- environments, and (by default) any libraries installed in a "system" Python,
- i.e. one which is installed as part of your operating system.
+.. note:: A virtual environment is a Python environment such that the Python
+ interpreter, libraries and scripts installed into it are isolated from those
+ installed in other virtual environments, and (by default) any libraries
+ installed in a "system" Python, i.e., one which is installed as part of your
+ operating system.
- A venv is a directory tree which contains Python executable files and
- other files which indicate that it is a venv.
+ A virtual environment is a directory tree which contains Python executable
+ files and other files which indicate that it is a virtual environment.
Common installation tools such as ``Setuptools`` and ``pip`` work as
- expected with venvs - i.e. when a venv is active, they install Python
- packages into the venv without needing to be told to do so explicitly.
-
- When a venv is active (i.e. the venv's Python interpreter is running), the
- attributes :attr:`sys.prefix` and :attr:`sys.exec_prefix` point to the base
- directory of the venv, whereas :attr:`sys.base_prefix` and
- :attr:`sys.base_exec_prefix` point to the non-venv Python installation
- which was used to create the venv. If a venv is not active, then
- :attr:`sys.prefix` is the same as :attr:`sys.base_prefix` and
- :attr:`sys.exec_prefix` is the same as :attr:`sys.base_exec_prefix` (they
- all point to a non-venv Python installation).
-
- When a venv is active, any options that change the installation path will be
- ignored from all distutils configuration files to prevent projects being
- inadvertently installed outside of the virtual environment.
-
- When working in a command shell, users can make a venv active by running an
- ``activate`` script in the venv's executables directory (the precise filename
- is shell-dependent), which prepends the venv's directory for executables to
- the ``PATH`` environment variable for the running shell. There should be no
- need in other circumstances to activate a venv -- scripts installed into
- venvs have a shebang line which points to the venv's Python interpreter. This
- means that the script will run with that interpreter regardless of the value
- of ``PATH``. On Windows, shebang line processing is supported if you have the
- Python Launcher for Windows installed (this was added to Python in 3.3 - see
- :pep:`397` for more details). Thus, double-clicking an installed script in
- a Windows Explorer window should run the script with the correct interpreter
- without there needing to be any reference to its venv in ``PATH``.
+ expected with virtual environments. In other words, when a virtual
+ environment is active, they install Python packages into the virtual
+ environment without needing to be told to do so explicitly.
+
+ When a virtual environment is active (i.e., the virtual environment's Python
+ interpreter is running), the attributes :attr:`sys.prefix` and
+ :attr:`sys.exec_prefix` point to the base directory of the virtual
+ environment, whereas :attr:`sys.base_prefix` and
+ :attr:`sys.base_exec_prefix` point to the non-virtual environment Python
+ installation which was used to create the virtual environment. If a virtual
+ environment is not active, then :attr:`sys.prefix` is the same as
+ :attr:`sys.base_prefix` and :attr:`sys.exec_prefix` is the same as
+ :attr:`sys.base_exec_prefix` (they all point to a non-virtual environment
+ Python installation).
+
+ When a virtual environment is active, any options that change the
+ installation path will be ignored from all distutils configuration files to
+ prevent projects being inadvertently installed outside of the virtual
+ environment.
+
+ When working in a command shell, users can make a virtual environment active
+ by running an ``activate`` script in the virtual environment's executables
+ directory (the precise filename is shell-dependent), which prepends the
+ virtual environment's directory for executables to the ``PATH`` environment
+ variable for the running shell. There should be no need in other
+ circumstances to activate a virtual environment—scripts installed into
+ virtual environments have a "shebang" line which points to the virtual
+ environment's Python interpreter. This means that the script will run with
+ that interpreter regardless of the value of ``PATH``. On Windows, "shebang"
+ line processing is supported if you have the Python Launcher for Windows
+ installed (this was added to Python in 3.3 - see :pep:`397` for more
+ details). Thus, double-clicking an installed script in a Windows Explorer
+ window should run the script with the correct interpreter without there
+ needing to be any reference to its virtual environment in ``PATH``.
.. _venv-api:
@@ -89,7 +95,8 @@ mechanisms for third-party virtual environment creators to customize environment
creation according to their needs, the :class:`EnvBuilder` class.
.. class:: EnvBuilder(system_site_packages=False, clear=False, \
- symlinks=False, upgrade=False, with_pip=False)
+ symlinks=False, upgrade=False, with_pip=False, \
+ prompt=None)
The :class:`EnvBuilder` class accepts the following keyword arguments on
instantiation:
@@ -113,9 +120,16 @@ creation according to their needs, the :class:`EnvBuilder` class.
installed in the virtual environment. This uses :mod:`ensurepip` with
the ``--default-pip`` option.
+ * ``prompt`` -- a String to be used after virtual environment is activated
+ (defaults to ``None`` which means directory name of the environment would
+ be used).
+
.. versionchanged:: 3.4
Added the ``with_pip`` parameter
+ .. versionadded:: 3.6
+ Added the ``prompt`` parameter
+
Creators of third-party virtual environment tools will be free to use the
provided ``EnvBuilder`` class as a base class.
@@ -225,7 +239,7 @@ An example of extending ``EnvBuilder``
--------------------------------------
The following script shows how to extend :class:`EnvBuilder` by implementing a
-subclass which installs setuptools and pip into a created venv::
+subclass which installs setuptools and pip into a created virtual environment::
import os
import os.path
@@ -239,12 +253,12 @@ subclass which installs setuptools and pip into a created venv::
class ExtendedEnvBuilder(venv.EnvBuilder):
"""
This builder installs setuptools and pip so that you can pip or
- easy_install other packages into the created environment.
+ easy_install other packages into the created virtual environment.
:param nodist: If True, setuptools and pip are not installed into the
- created environment.
+ created virtual environment.
:param nopip: If True, pip is not installed into the created
- environment.
+ virtual environment.
:param progress: If setuptools or pip are installed, the progress of the
installation can be monitored by passing a progress
callable. If specified, it is called with two
@@ -270,10 +284,10 @@ subclass which installs setuptools and pip into a created venv::
def post_setup(self, context):
"""
Set up any packages which need to be pre-installed into the
- environment being created.
+ virtual environment being created.
- :param context: The information for the environment creation request
- being processed.
+ :param context: The information for the virtual environment
+ creation request being processed.
"""
os.environ['VIRTUAL_ENV'] = context.env_dir
if not self.nodist:
@@ -307,7 +321,7 @@ subclass which installs setuptools and pip into a created venv::
fn = os.path.split(path)[-1]
binpath = context.bin_path
distpath = os.path.join(binpath, fn)
- # Download script into the env's binaries folder
+ # Download script into the virtual environment's binaries folder
urlretrieve(url, distpath)
progress = self.progress
if self.verbose:
@@ -319,7 +333,7 @@ subclass which installs setuptools and pip into a created venv::
else:
sys.stderr.write('Installing %s ...%s' % (name, term))
sys.stderr.flush()
- # Install in the env
+ # Install in the virtual environment
args = [context.env_exe, fn]
p = Popen(args, stdout=PIPE, stderr=PIPE, cwd=binpath)
t1 = Thread(target=self.reader, args=(p.stdout, 'stdout'))
@@ -338,10 +352,10 @@ subclass which installs setuptools and pip into a created venv::
def install_setuptools(self, context):
"""
- Install setuptools in the environment.
+ Install setuptools in the virtual environment.
- :param context: The information for the environment creation request
- being processed.
+ :param context: The information for the virtual environment
+ creation request being processed.
"""
url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'
self.install_script(context, 'setuptools', url)
@@ -354,10 +368,10 @@ subclass which installs setuptools and pip into a created venv::
def install_pip(self, context):
"""
- Install pip in the environment.
+ Install pip in the virtual environment.
- :param context: The information for the environment creation request
- being processed.
+ :param context: The information for the virtual environment
+ creation request being processed.
"""
url = 'https://raw.github.com/pypa/pip/master/contrib/get-pip.py'
self.install_script(context, 'pip', url)
@@ -380,7 +394,8 @@ subclass which installs setuptools and pip into a created venv::
'more target '
'directories.')
parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
- help='A directory to create the environment in.')
+ help='A directory in which to create the
+ 'virtual environment.')
parser.add_argument('--no-setuptools', default=False,
action='store_true', dest='nodist',
help="Don't install setuptools or pip in the "
@@ -404,14 +419,17 @@ subclass which installs setuptools and pip into a created venv::
'the platform.')
parser.add_argument('--clear', default=False, action='store_true',
dest='clear', help='Delete the contents of the '
- 'environment directory if it '
- 'already exists, before '
+ 'virtual environment '
+ 'directory if it already '
+ 'exists, before virtual '
'environment creation.')
parser.add_argument('--upgrade', default=False, action='store_true',
- dest='upgrade', help='Upgrade the environment '
- 'directory to use this version '
- 'of Python, assuming Python '
- 'has been upgraded in-place.')
+ dest='upgrade', help='Upgrade the virtual '
+ 'environment directory to '
+ 'use this version of '
+ 'Python, assuming Python '
+ 'has been upgraded '
+ 'in-place.')
parser.add_argument('--verbose', default=False, action='store_true',
dest='verbose', help='Display the output '
'from the scripts which '
diff --git a/Doc/library/warnings.rst b/Doc/library/warnings.rst
index 37f6874..5a42cc6 100644
--- a/Doc/library/warnings.rst
+++ b/Doc/library/warnings.rst
@@ -301,7 +301,7 @@ Available Functions
-------------------
-.. function:: warn(message, category=None, stacklevel=1)
+.. function:: warn(message, category=None, stacklevel=1, source=None)
Issue a warning, or maybe ignore it or raise an exception. The *category*
argument, if given, must be a warning category class (see above); it defaults to
@@ -319,8 +319,14 @@ Available Functions
source of :func:`deprecation` itself (since the latter would defeat the purpose
of the warning message).
+ *source*, if supplied, is the destroyed object which emitted a
+ :exc:`ResourceWarning`.
-.. function:: warn_explicit(message, category, filename, lineno, module=None, registry=None, module_globals=None)
+ .. versionchanged:: 3.6
+ Added *source* parameter.
+
+
+.. function:: warn_explicit(message, category, filename, lineno, module=None, registry=None, module_globals=None, source=None)
This is a low-level interface to the functionality of :func:`warn`, passing in
explicitly the message, category, filename and line number, and optionally the
@@ -336,6 +342,12 @@ Available Functions
source for modules found in zipfiles or other non-filesystem import
sources).
+ *source*, if supplied, is the destroyed object which emitted a
+ :exc:`ResourceWarning`.
+
+ .. versionchanged:: 3.6
+ Add the *source* parameter.
+
.. function:: showwarning(message, category, filename, lineno, file=None, line=None)
diff --git a/Doc/library/winreg.rst b/Doc/library/winreg.rst
index 52d591a..48bdf14 100644
--- a/Doc/library/winreg.rst
+++ b/Doc/library/winreg.rst
@@ -635,7 +635,7 @@ For more information, see `Registry Value Types
.. data:: REG_DWORD_LITTLE_ENDIAN
- A 32-bit number in little-endian format.
+ A 32-bit number in little-endian format. Equivalent to :const:`REG_DWORD`.
.. data:: REG_DWORD_BIG_ENDIAN
@@ -659,6 +659,18 @@ For more information, see `Registry Value Types
No defined value type.
+.. data:: REG_QWORD
+
+ A 64-bit number.
+
+ .. versionadded:: 3.6
+
+.. data:: REG_QWORD_LITTLE_ENDIAN
+
+ A 64-bit number in little-endian format. Equivalent to :const:`REG_QWORD`.
+
+ .. versionadded:: 3.6
+
.. data:: REG_RESOURCE_LIST
A device-driver resource list.
diff --git a/Doc/library/winsound.rst b/Doc/library/winsound.rst
index d2c4210..372f792 100644
--- a/Doc/library/winsound.rst
+++ b/Doc/library/winsound.rst
@@ -25,7 +25,8 @@ provided by Windows platforms. It includes functions and several constants.
.. function:: PlaySound(sound, flags)
Call the underlying :c:func:`PlaySound` function from the Platform API. The
- *sound* parameter may be a filename, audio data as a string, or ``None``. Its
+ *sound* parameter may be a filename, a system sound alias, audio data as a
+ :term:`bytes-like object`, or ``None``. Its
interpretation depends on the value of *flags*, which can be a bitwise ORed
combination of the constants described below. If the *sound* parameter is
``None``, any currently playing waveform sound is stopped. If the system
@@ -39,7 +40,8 @@ provided by Windows platforms. It includes functions and several constants.
sound to play; possible values are ``-1``, ``MB_ICONASTERISK``,
``MB_ICONEXCLAMATION``, ``MB_ICONHAND``, ``MB_ICONQUESTION``, and ``MB_OK``, all
described below. The value ``-1`` produces a "simple beep"; this is the final
- fallback if a sound cannot be played otherwise.
+ fallback if a sound cannot be played otherwise. If the system indicates an
+ error, :exc:`RuntimeError` is raised.
.. data:: SND_FILENAME
@@ -92,7 +94,7 @@ provided by Windows platforms. It includes functions and several constants.
.. data:: SND_MEMORY
The *sound* parameter to :func:`PlaySound` is a memory image of a WAV file, as a
- string.
+ :term:`bytes-like object`.
.. note::
diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst
index aad27a8..a1d4469 100644
--- a/Doc/library/wsgiref.rst
+++ b/Doc/library/wsgiref.rst
@@ -133,9 +133,9 @@ parameter expect a WSGI-compliant dictionary to be supplied; please see
for key, value in environ.items()]
return ret
- httpd = make_server('', 8000, simple_app)
- print("Serving on port 8000...")
- httpd.serve_forever()
+ with make_server('', 8000, simple_app) as httpd:
+ print("Serving on port 8000...")
+ httpd.serve_forever()
In addition to the environment functions above, the :mod:`wsgiref.util` module
@@ -285,14 +285,14 @@ request. (E.g., using the :func:`shift_path_info` function from
from wsgiref.simple_server import make_server, demo_app
- httpd = make_server('', 8000, demo_app)
- print("Serving HTTP on port 8000...")
+ with make_server('', 8000, demo_app) as httpd:
+ print("Serving HTTP on port 8000...")
- # Respond to requests until process is killed
- httpd.serve_forever()
+ # Respond to requests until process is killed
+ httpd.serve_forever()
- # Alternative: serve one request, then exit
- httpd.handle_request()
+ # Alternative: serve one request, then exit
+ httpd.handle_request()
.. function:: demo_app(environ, start_response)
@@ -432,9 +432,9 @@ Paste" library.
# This is the application wrapped in a validator
validator_app = validator(simple_app)
- httpd = make_server('', 8000, validator_app)
- print("Listening on port 8000....")
- httpd.serve_forever()
+ with make_server('', 8000, validator_app) as httpd:
+ print("Listening on port 8000....")
+ httpd.serve_forever()
:mod:`wsgiref.handlers` -- server/gateway base classes
@@ -774,8 +774,8 @@ This is a working "Hello World" WSGI application::
# The returned object is going to be printed
return [b"Hello World"]
- httpd = make_server('', 8000, hello_world_app)
- print("Serving on port 8000...")
+ with make_server('', 8000, hello_world_app) as httpd:
+ print("Serving on port 8000...")
- # Serve until process is killed
- httpd.serve_forever()
+ # Serve until process is killed
+ httpd.serve_forever()
diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst
index dad7a02..390828e 100644
--- a/Doc/library/xmlrpc.client.rst
+++ b/Doc/library/xmlrpc.client.rst
@@ -88,9 +88,13 @@ between conformable Python objects and XML on the wire.
+======================+=======================================================+
| ``boolean`` | :class:`bool` |
+----------------------+-------------------------------------------------------+
- | ``int`` or ``i4`` | :class:`int` in range from -2147483648 to 2147483647. |
+ | ``int``, ``i1``, | :class:`int` in range from -2147483648 to 2147483647. |
+ | ``i2``, ``i4``, | Values get the ``<int>`` tag. |
+ | ``i8`` or | |
+ | ``biginteger`` | |
+----------------------+-------------------------------------------------------+
- | ``double`` | :class:`float` |
+ | ``double`` or | :class:`float`. Values get the ``<double>`` tag. |
+ | ``float`` | |
+----------------------+-------------------------------------------------------+
| ``string`` | :class:`str` |
+----------------------+-------------------------------------------------------+
@@ -114,6 +118,8 @@ between conformable Python objects and XML on the wire.
| ``nil`` | The ``None`` constant. Passing is allowed only if |
| | *allow_none* is true. |
+----------------------+-------------------------------------------------------+
+ | ``bigdecimal`` | :class:`decimal.Decimal`. Returned type only. |
+ +----------------------+-------------------------------------------------------+
This is the full set of data types supported by XML-RPC. Method calls may also
raise a special :exc:`Fault` instance, used to signal XML-RPC server errors, or
@@ -137,6 +143,13 @@ between conformable Python objects and XML on the wire.
.. versionchanged:: 3.5
Added the *context* argument.
+ .. versionchanged:: 3.6
+ Added support of type tags with prefixes (e.g. ``ex:nil``).
+ Added support of unmarsalling additional types used by Apache XML-RPC
+ implementation for numerics: ``i1``, ``i2``, ``i8``, ``biginteger``,
+ ``float`` and ``bigdecimal``.
+ See http://ws.apache.org/xmlrpc/types.html for a description.
+
.. seealso::
diff --git a/Doc/library/xmlrpc.server.rst b/Doc/library/xmlrpc.server.rst
index 1c77e84..0511ddf 100644
--- a/Doc/library/xmlrpc.server.rst
+++ b/Doc/library/xmlrpc.server.rst
@@ -148,29 +148,29 @@ Server code::
rpc_paths = ('/RPC2',)
# Create server
- server = SimpleXMLRPCServer(("localhost", 8000),
- requestHandler=RequestHandler)
- server.register_introspection_functions()
+ with SimpleXMLRPCServer(("localhost", 8000),
+ requestHandler=RequestHandler) as server:
+ server.register_introspection_functions()
- # Register pow() function; this will use the value of
- # pow.__name__ as the name, which is just 'pow'.
- server.register_function(pow)
+ # Register pow() function; this will use the value of
+ # pow.__name__ as the name, which is just 'pow'.
+ server.register_function(pow)
- # Register a function under a different name
- def adder_function(x,y):
- return x + y
- server.register_function(adder_function, 'add')
+ # Register a function under a different name
+ def adder_function(x,y):
+ return x + y
+ server.register_function(adder_function, 'add')
- # Register an instance; all the methods of the instance are
- # published as XML-RPC methods (in this case, just 'mul').
- class MyFuncs:
- def mul(self, x, y):
- return x * y
+ # Register an instance; all the methods of the instance are
+ # published as XML-RPC methods (in this case, just 'mul').
+ class MyFuncs:
+ def mul(self, x, y):
+ return x * y
- server.register_instance(MyFuncs())
+ server.register_instance(MyFuncs())
- # Run the server's main loop
- server.serve_forever()
+ # Run the server's main loop
+ server.serve_forever()
The following client code will call the methods made available by the preceding
server::
@@ -207,18 +207,17 @@ a server allowing dotted names and registering a multicall function.
def getCurrentTime():
return datetime.datetime.now()
- server = SimpleXMLRPCServer(("localhost", 8000))
- server.register_function(pow)
- server.register_function(lambda x,y: x+y, 'add')
- server.register_instance(ExampleService(), allow_dotted_names=True)
- server.register_multicall_functions()
- print('Serving XML-RPC on localhost port 8000')
- try:
- server.serve_forever()
- except KeyboardInterrupt:
- print("\nKeyboard interrupt received, exiting.")
- server.server_close()
- sys.exit(0)
+ with SimpleXMLRPCServer(("localhost", 8000)) as server:
+ server.register_function(pow)
+ server.register_function(lambda x,y: x+y, 'add')
+ server.register_instance(ExampleService(), allow_dotted_names=True)
+ server.register_multicall_functions()
+ print('Serving XML-RPC on localhost port 8000')
+ try:
+ server.serve_forever()
+ except KeyboardInterrupt:
+ print("\nKeyboard interrupt received, exiting.")
+ sys.exit(0)
This ExampleService demo can be invoked from the command line::
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
index 1d6526c..47ba0b5 100644
--- a/Doc/library/zipfile.rst
+++ b/Doc/library/zipfile.rst
@@ -147,10 +147,10 @@ ZipFile Objects
*compression* is the ZIP compression method to use when writing the archive,
and should be :const:`ZIP_STORED`, :const:`ZIP_DEFLATED`,
:const:`ZIP_BZIP2` or :const:`ZIP_LZMA`; unrecognized
- values will cause :exc:`RuntimeError` to be raised. If :const:`ZIP_DEFLATED`,
+ values will cause :exc:`NotImplementedError` to be raised. If :const:`ZIP_DEFLATED`,
:const:`ZIP_BZIP2` or :const:`ZIP_LZMA` is specified but the corresponding module
(:mod:`zlib`, :mod:`bz2` or :mod:`lzma`) is not available, :exc:`RuntimeError`
- is also raised. The default is :const:`ZIP_STORED`. If *allowZip64* is
+ is raised. The default is :const:`ZIP_STORED`. If *allowZip64* is
``True`` (the default) zipfile will create ZIP files that use the ZIP64
extensions when the zipfile is larger than 2 GiB. If it is false :mod:`zipfile`
will raise an exception when the ZIP file would require ZIP64 extensions.
@@ -179,6 +179,10 @@ ZipFile Objects
Added support for writing to unseekable streams.
Added support for the ``'x'`` mode.
+ .. versionchanged:: 3.6
+ Previously, a plain :exc:`RuntimeError` was raised for unrecognized
+ compression values.
+
.. method:: ZipFile.close()
@@ -205,18 +209,12 @@ ZipFile Objects
Return a list of archive members by name.
-.. index::
- single: universal newlines; zipfile.ZipFile.open method
-
-.. method:: ZipFile.open(name, mode='r', pwd=None)
+.. method:: ZipFile.open(name, mode='r', pwd=None, *, force_zip64=False)
- Extract a member from the archive as a file-like object (ZipExtFile). *name*
- is the name of the file in the archive, or a :class:`ZipInfo` object. The
- *mode* parameter, if included, must be one of the following: ``'r'`` (the
- default), ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable
- :term:`universal newlines` support in the read-only object. *pwd* is the
- password used for encrypted files. Calling :meth:`.open` on a closed
- ZipFile will raise a :exc:`RuntimeError`.
+ Access a member of the archive as a binary file-like object. *name*
+ can be either the name of a file within the archive or a :class:`ZipInfo`
+ object. The *mode* parameter, if included, must be ``'r'`` (the default)
+ or ``'w'``. *pwd* is the password used to decrypt encrypted ZIP files.
:meth:`~ZipFile.open` is also a context manager and therefore supports the
:keyword:`with` statement::
@@ -225,17 +223,23 @@ ZipFile Objects
with myzip.open('eggs.txt') as myfile:
print(myfile.read())
- .. note::
+ With *mode* ``'r'`` the file-like object
+ (``ZipExtFile``) is read-only and provides the following methods:
+ :meth:`~io.BufferedIOBase.read`, :meth:`~io.IOBase.readline`,
+ :meth:`~io.IOBase.readlines`, :meth:`__iter__`,
+ :meth:`~iterator.__next__`. These objects can operate independently of
+ the ZipFile.
- The file-like object is read-only and provides the following methods:
- :meth:`~io.BufferedIOBase.read`, :meth:`~io.IOBase.readline`,
- :meth:`~io.IOBase.readlines`, :meth:`__iter__`,
- :meth:`~iterator.__next__`.
+ With ``mode='w'``, a writable file handle is returned, which supports the
+ :meth:`~io.BufferedIOBase.write` method. While a writable file handle is open,
+ attempting to read or write other files in the ZIP file will raise a
+ :exc:`ValueError`.
- .. note::
-
- Objects returned by :meth:`.open` can operate independently of the
- ZipFile.
+ When writing a file, if the file size is not known in advance but may exceed
+ 2 GiB, pass ``force_zip64=True`` to ensure that the header format is
+ capable of supporting large files. If the file size is known in advance,
+ construct a :class:`ZipInfo` object with :attr:`~ZipInfo.file_size` set, and
+ use that as the *name* parameter.
.. note::
@@ -243,10 +247,19 @@ ZipFile Objects
or a :class:`ZipInfo` object. You will appreciate this when trying to read a
ZIP file that contains members with duplicate names.
- .. deprecated-removed:: 3.4 3.6
- The ``'U'`` or ``'rU'`` mode. Use :class:`io.TextIOWrapper` for reading
+ .. versionchanged:: 3.6
+ Removed support of ``mode='U'``. Use :class:`io.TextIOWrapper` for reading
compressed text files in :term:`universal newlines` mode.
+ .. versionchanged:: 3.6
+ :meth:`open` can now be used to write files into the archive with the
+ ``mode='w'`` option.
+
+ .. versionchanged:: 3.6
+ Calling :meth:`.open` on a closed ZipFile will raise a :exc:`ValueError`.
+ Previously, a :exc:`RuntimeError` was raised.
+
+
.. method:: ZipFile.extract(member, path=None, pwd=None)
Extract a member from the archive to the current working directory; *member*
@@ -267,6 +280,10 @@ ZipFile Objects
characters (``:``, ``<``, ``>``, ``|``, ``"``, ``?``, and ``*``)
replaced by underscore (``_``).
+ .. versionchanged:: 3.6
+ Calling :meth:`extract` on a closed ZipFile will raise a
+ :exc:`ValueError`. Previously, a :exc:`RuntimeError` was raised.
+
.. method:: ZipFile.extractall(path=None, members=None, pwd=None)
@@ -283,6 +300,10 @@ ZipFile Objects
dots ``".."``. This module attempts to prevent that.
See :meth:`extract` note.
+ .. versionchanged:: 3.6
+ Calling :meth:`extractall` on a closed ZipFile will raise a
+ :exc:`ValueError`. Previously, a :exc:`RuntimeError` was raised.
+
.. method:: ZipFile.printdir()
@@ -300,18 +321,24 @@ ZipFile Objects
file in the archive, or a :class:`ZipInfo` object. The archive must be open for
read or append. *pwd* is the password used for encrypted files and, if specified,
it will override the default password set with :meth:`setpassword`. Calling
- :meth:`read` on a closed ZipFile will raise a :exc:`RuntimeError`. Calling
:meth:`read` on a ZipFile that uses a compression method other than
:const:`ZIP_STORED`, :const:`ZIP_DEFLATED`, :const:`ZIP_BZIP2` or
:const:`ZIP_LZMA` will raise a :exc:`NotImplementedError`. An error will also
be raised if the corresponding compression module is not available.
+ .. versionchanged:: 3.6
+ Calling :meth:`read` on a closed ZipFile will raise a :exc:`ValueError`.
+ Previously, a :exc:`RuntimeError` was raised.
+
.. method:: ZipFile.testzip()
Read all the files in the archive and check their CRC's and file headers.
- Return the name of the first bad file, or else return ``None``. Calling
- :meth:`testzip` on a closed ZipFile will raise a :exc:`RuntimeError`.
+ Return the name of the first bad file, or else return ``None``.
+
+ .. versionchanged:: 3.6
+ Calling :meth:`testfile` on a closed ZipFile will raise a
+ :exc:`ValueError`. Previously, a :exc:`RuntimeError` was raised.
.. method:: ZipFile.write(filename, arcname=None, compress_type=None)
@@ -321,10 +348,7 @@ ZipFile Objects
letter and with leading path separators removed). If given, *compress_type*
overrides the value given for the *compression* parameter to the constructor for
the new entry.
- The archive must be open with mode ``'w'``, ``'x'`` or ``'a'`` -- calling
- :meth:`write` on a ZipFile created with mode ``'r'`` will raise a
- :exc:`RuntimeError`. Calling :meth:`write` on a closed ZipFile will raise a
- :exc:`RuntimeError`.
+ The archive must be open with mode ``'w'``, ``'x'`` or ``'a'``.
.. note::
@@ -343,16 +367,19 @@ ZipFile Objects
If ``arcname`` (or ``filename``, if ``arcname`` is not given) contains a null
byte, the name of the file in the archive will be truncated at the null byte.
+ .. versionchanged:: 3.6
+ Calling :meth:`write` on a ZipFile created with mode ``'r'`` or
+ a closed ZipFile will raise a :exc:`ValueError`. Previously,
+ a :exc:`RuntimeError` was raised.
+
+
.. method:: ZipFile.writestr(zinfo_or_arcname, data[, compress_type])
Write the string *data* to the archive; *zinfo_or_arcname* is either the file
name it will be given in the archive, or a :class:`ZipInfo` instance. If it's
an instance, at least the filename, date, and time must be given. If it's a
name, the date and time is set to the current date and time.
- The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'`` -- calling
- :meth:`writestr` on a ZipFile created with mode ``'r'`` will raise a
- :exc:`RuntimeError`. Calling :meth:`writestr` on a closed ZipFile will
- raise a :exc:`RuntimeError`.
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``.
If given, *compress_type* overrides the value given for the *compression*
parameter to the constructor for the new entry, or in the *zinfo_or_arcname*
@@ -368,6 +395,12 @@ ZipFile Objects
.. versionchanged:: 3.2
The *compress_type* argument.
+ .. versionchanged:: 3.6
+ Calling :meth:`writestr` on a ZipFile created with mode ``'r'`` or
+ a closed ZipFile will raise a :exc:`ValueError`. Previously,
+ a :exc:`RuntimeError` was raised.
+
+
The following data attributes are also available:
@@ -465,7 +498,31 @@ Instances of the :class:`ZipInfo` class are returned by the :meth:`.getinfo` and
:meth:`.infolist` methods of :class:`ZipFile` objects. Each object stores
information about a single member of the ZIP archive.
-Instances have the following attributes:
+There is one classmethod to make a :class:`ZipInfo` instance for a filesystem
+file:
+
+.. classmethod:: ZipInfo.from_file(filename, arcname=None)
+
+ Construct a :class:`ZipInfo` instance for a file on the filesystem, in
+ preparation for adding it to a zip file.
+
+ *filename* should be the path to a file or directory on the filesystem.
+
+ If *arcname* is specified, it is used as the name within the archive.
+ If *arcname* is not specified, the name will be the same as *filename*, but
+ with any drive letter and leading path separators removed.
+
+ .. versionadded:: 3.6
+
+Instances have the following methods and attributes:
+
+.. method:: ZipInfo.is_dir()
+
+ Return ``True`` if this archive member is a directory.
+
+ This uses the entry's name: directories should always end with ``/``.
+
+ .. versionadded:: 3.6
.. attribute:: ZipInfo.filename
@@ -574,4 +631,5 @@ Instances have the following attributes:
Size of the uncompressed file.
+
.. _PKZIP Application Note: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
diff --git a/Doc/library/zlib.rst b/Doc/library/zlib.rst
index 1de7bae..3d742ab 100644
--- a/Doc/library/zlib.rst
+++ b/Doc/library/zlib.rst
@@ -47,14 +47,19 @@ The available exception and functions in this module are:
platforms, use ``adler32(data) & 0xffffffff``.
-.. function:: compress(data[, level])
+.. function:: compress(data, level=-1)
Compresses the bytes in *data*, returning a bytes object containing compressed data.
- *level* is an integer from ``0`` to ``9`` controlling the level of compression;
+ *level* is an integer from ``0`` to ``9`` or ``-1`` controlling the level of compression;
``1`` is fastest and produces the least compression, ``9`` is slowest and
- produces the most. ``0`` is no compression. The default value is ``6``.
+ produces the most. ``0`` is no compression. The default value is ``-1``
+ (Z_DEFAULT_COMPRESSION). Z_DEFAULT_COMPRESSION represents a default
+ compromise between speed and compression (currently equivalent to level 6).
Raises the :exc:`error` exception if any error occurs.
+ .. versionchanged:: 3.6
+ *level* can now be used as a keyword parameter.
+
.. function:: compressobj(level=-1, method=DEFLATED, wbits=15, memLevel=8, strategy=Z_DEFAULT_STRATEGY[, zdict])
@@ -124,7 +129,7 @@ The available exception and functions in this module are:
platforms, use ``crc32(data) & 0xffffffff``.
-.. function:: decompress(data[, wbits[, bufsize]])
+.. function:: decompress(data, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)
Decompresses the bytes in *data*, returning a bytes object containing the
uncompressed data. The *wbits* parameter depends on
@@ -159,14 +164,16 @@ The available exception and functions in this module are:
When decompressing a stream, the window size must not be smaller
than the size originally used to compress the stream; using a too-small
value may result in an :exc:`error` exception. The default *wbits* value
- is 15, which corresponds to the largest window size and requires a zlib
- header and trailer to be included.
+ corresponds to the largest window size and requires a zlib header and
+ trailer to be included.
*bufsize* is the initial size of the buffer used to hold decompressed data. If
more space is required, the buffer size will be increased as needed, so you
don't have to get this value exactly right; tuning it will only save a few calls
- to :c:func:`malloc`. The default size is 16384.
+ to :c:func:`malloc`.
+ .. versionchanged:: 3.6
+ *wbits* and *bufsize* can be used as keyword arguments.
.. function:: decompressobj(wbits=15[, zdict])
@@ -252,7 +259,7 @@ Decompression objects support the following methods and attributes:
.. versionadded:: 3.3
-.. method:: Decompress.decompress(data[, max_length])
+.. method:: Decompress.decompress(data, max_length=0)
Decompress *data*, returning a bytes object containing the uncompressed data
corresponding to at least part of the data in *string*. This data should be
@@ -264,9 +271,11 @@ Decompression objects support the following methods and attributes:
no longer than *max_length*. This may mean that not all of the compressed input
can be processed; and unconsumed data will be stored in the attribute
:attr:`unconsumed_tail`. This bytestring must be passed to a subsequent call to
- :meth:`decompress` if decompression is to continue. If *max_length* is not
- supplied then the whole input is decompressed, and :attr:`unconsumed_tail` is
- empty.
+ :meth:`decompress` if decompression is to continue. If *max_length* is zero
+ then the whole input is decompressed, and :attr:`unconsumed_tail` is empty.
+
+ .. versionchanged:: 3.6
+ *max_length* can be used as a keyword argument.
.. method:: Decompress.flush([length])
diff --git a/Doc/make.bat b/Doc/make.bat
index 5ab8085..da1f876 100644
--- a/Doc/make.bat
+++ b/Doc/make.bat
@@ -40,7 +40,7 @@ if "%1" == "clean" (
goto end
)
-%SPHINXBUILD% 2> nul
+%SPHINXBUILD% >nul 2> nul
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 88b94ea..4fc6af0 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -471,10 +471,10 @@ A function definition defines a user-defined function object (see section
decorators: `decorator`+
decorator: "@" `dotted_name` ["(" [`argument_list` [","]] ")"] NEWLINE
dotted_name: `identifier` ("." `identifier`)*
- parameter_list: (`defparameter` ",")*
- : | "*" [`parameter`] ("," `defparameter`)* ["," "**" `parameter`]
- : | "**" `parameter`
- : | `defparameter` [","] )
+ parameter_list: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
+ : | `parameter_list_starargs`
+ parameter_list_starargs: "*" [`parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
+ : | "**" `parameter` [","]
parameter: `identifier` [":" `expression`]
defparameter: `parameter` ["=" `expression`]
funcname: `identifier`
@@ -546,11 +546,12 @@ Function call semantics are described in more detail in section :ref:`calls`. A
function call always assigns values to all parameters mentioned in the parameter
list, either from position arguments, from keyword arguments, or from default
values. If the form "``*identifier``" is present, it is initialized to a tuple
-receiving any excess positional parameters, defaulting to the empty tuple. If
-the form "``**identifier``" is present, it is initialized to a new dictionary
-receiving any excess keyword arguments, defaulting to a new empty dictionary.
-Parameters after "``*``" or "``*identifier``" are keyword-only parameters and
-may only be passed used keyword arguments.
+receiving any excess positional parameters, defaulting to the empty tuple.
+If the form "``**identifier``" is present, it is initialized to a new
+ordered mapping receiving any excess keyword arguments, defaulting to a
+new empty mapping of the same type. Parameters after "``*``" or
+"``*identifier``" are keyword-only parameters and may only be passed
+used keyword arguments.
.. index:: pair: function; annotations
@@ -632,6 +633,11 @@ list for the base classes and the saved local namespace for the attribute
dictionary. The class name is bound to this class object in the original local
namespace.
+The order in which attributes are defined in the class body is preserved
+in the new class's ``__dict__``. Note that this is reliable only right
+after the class is created and only for classes that were defined using
+the definition syntax.
+
Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`.
Classes can also be decorated: just like when decorating functions, ::
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index b763f10..9619e53 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -686,33 +686,36 @@ Modules
Attribute assignment updates the module's namespace dictionary, e.g.,
``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.
- .. index:: single: __dict__ (module attribute)
-
- Special read-only attribute: :attr:`~object.__dict__` is the module's namespace as a
- dictionary object.
-
- .. impl-detail::
-
- Because of the way CPython clears module dictionaries, the module
- dictionary will be cleared when the module falls out of scope even if the
- dictionary still has live references. To avoid this, copy the dictionary
- or keep the module around while using its dictionary directly.
-
.. index::
single: __name__ (module attribute)
single: __doc__ (module attribute)
single: __file__ (module attribute)
+ single: __annotations__ (module attribute)
pair: module; namespace
Predefined (writable) attributes: :attr:`__name__` is the module's name;
:attr:`__doc__` is the module's documentation string, or ``None`` if
- unavailable; :attr:`__file__` is the pathname of the file from which the
+ unavailable; :attr:`__annotations__` (optional) is a dictionary containing
+ :term:`variable annotations <variable annotation>` collected during module
+ body execution; :attr:`__file__` is the pathname of the file from which the
module was loaded, if it was loaded from a file. The :attr:`__file__`
attribute may be missing for certain types of modules, such as C modules
that are statically linked into the interpreter; for extension modules
loaded dynamically from a shared library, it is the pathname of the shared
library file.
+ .. index:: single: __dict__ (module attribute)
+
+ Special read-only attribute: :attr:`~object.__dict__` is the module's
+ namespace as a dictionary object.
+
+ .. impl-detail::
+
+ Because of the way CPython clears module dictionaries, the module
+ dictionary will be cleared when the module falls out of scope even if the
+ dictionary still has live references. To avoid this, copy the dictionary
+ or keep the module around while using its dictionary directly.
+
Custom classes
Custom class types are typically created by class definitions (see section
:ref:`class`). A class has a namespace implemented by a dictionary object.
@@ -761,13 +764,17 @@ Custom classes
single: __dict__ (class attribute)
single: __bases__ (class attribute)
single: __doc__ (class attribute)
+ single: __annotations__ (class attribute)
Special attributes: :attr:`~definition.__name__` is the class name; :attr:`__module__` is
the module name in which the class was defined; :attr:`~object.__dict__` is the
dictionary containing the class's namespace; :attr:`~class.__bases__` is a
tuple (possibly empty or a singleton) containing the base classes, in the
order of their occurrence in the base class list; :attr:`__doc__` is the
- class's documentation string, or ``None`` if undefined.
+ class's documentation string, or ``None`` if undefined;
+ :attr:`__annotations__` (optional) is a dictionary containing
+ :term:`variable annotations <variable annotation>` collected during
+ class body execution.
Class instances
.. index::
@@ -1063,6 +1070,12 @@ to ``type(x).__getitem__(x, i)``. Except where mentioned, attempts to execute a
operation raise an exception when no appropriate method is defined (typically
:exc:`AttributeError` or :exc:`TypeError`).
+Setting a special method to ``None`` indicates that the corresponding
+operation is not available. For example, if a class sets
+:meth:`__iter__` to ``None``, the class is not iterable, so calling
+:func:`iter` on its instances will raise a :exc:`TypeError` (without
+falling back to :meth:`__getitem__`). [#]_
+
When implementing a class that emulates any built-in type, it is important that
the emulation only be implemented to the degree that it makes sense for the
object being modelled. For example, some sequences may work well with retrieval
@@ -1233,8 +1246,9 @@ Basic customization
.. method:: object.__format__(self, format_spec)
- Called by the :func:`format` built-in function (and by extension, the
- :meth:`str.format` method of class :class:`str`) to produce a "formatted"
+ Called by the :func:`format` built-in function,
+ and by extension, evaluation of :ref:`formatted string literals
+ <f-strings>` and the :meth:`str.format` method, to produce a "formatted"
string representation of an object. The ``format_spec`` argument is
a string that contains a description of the formatting options desired.
The interpretation of the ``format_spec`` argument is up to the type
@@ -1491,6 +1505,14 @@ class' :attr:`~object.__dict__`.
Called to delete the attribute on an instance *instance* of the owner class.
+.. method:: object.__set_name__(self, owner, name)
+
+ Called at the time the owning class *owner* is created. The
+ descriptor has been assigned to *name*.
+
+ .. versionadded:: 3.6
+
+
The attribute :attr:`__objclass__` is interpreted by the :mod:`inspect` module
as specifying the class where this object was defined (setting this
appropriately can assist in runtime introspection of dynamic class attributes).
@@ -1628,11 +1650,56 @@ Notes on using *__slots__*
* *__class__* assignment works only if both classes have the same *__slots__*.
-.. _metaclasses:
+.. _class-customization:
Customizing class creation
--------------------------
+Whenever a class inherits from another class, *__init_subclass__* is
+called on that class. This way, it is possible to write classes which
+change the behavior of subclasses. This is closely related to class
+decorators, but where class decorators only affect the specific class they're
+applied to, ``__init_subclass__`` solely applies to future subclasses of the
+class defining the method.
+
+.. classmethod:: object.__init_subclass__(cls)
+
+ This method is called whenever the containing class is subclassed.
+ *cls* is then the new subclass. If defined as a normal instance method,
+ this method is implicitly converted to a class method.
+
+ Keyword arguments which are given to a new class are passed to
+ the parent's class ``__init_subclass__``. For compatibility with
+ other classes using ``__init_subclass__``, one should take out the
+ needed keyword arguments and pass the others over to the base
+ class, as in::
+
+ class Philosopher:
+ def __init_subclass__(cls, default_name, **kwargs):
+ super().__init_subclass__(**kwargs)
+ cls.default_name = default_name
+
+ class AustralianPhilosopher(Philosopher, default_name="Bruce"):
+ pass
+
+ The default implementation ``object.__init_subclass__`` does
+ nothing, but raises an error if it is called with any arguments.
+
+ .. note::
+
+ The metaclass hint ``metaclass`` is consumed by the rest of the type
+ machinery, and is never passed to ``__init_subclass__`` implementations.
+ The actual metaclass (rather than the explicit hint) can be accessed as
+ ``type(cls)``.
+
+ .. versionadded:: 3.6
+
+
+.. _metaclasses:
+
+Metaclasses
+^^^^^^^^^^^
+
By default, classes are constructed using :func:`type`. The class body is
executed in a new namespace and the class name is bound locally to the
result of ``type(name, bases, namespace)``.
@@ -1690,7 +1757,7 @@ as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the
additional keyword arguments, if any, come from the class definition).
If the metaclass has no ``__prepare__`` attribute, then the class namespace
-is initialised as an empty :func:`dict` instance.
+is initialised as an empty ordered mapping.
.. seealso::
@@ -1734,9 +1801,9 @@ included in the class definition (if any) and the resulting object is bound
in the local namespace as the defined class.
When a new class is created by ``type.__new__``, the object provided as the
-namespace parameter is copied to a standard Python dictionary and the original
-object is discarded. The new copy becomes the :attr:`~object.__dict__` attribute
-of the class object.
+namespace parameter is copied to a new ordered mapping and the original
+object is discarded. The new copy is wrapped in a read-only proxy, which
+becomes the :attr:`~object.__dict__` attribute of the class object.
.. seealso::
@@ -2059,7 +2126,7 @@ left undefined.
(``+``, ``-``, ``*``, ``@``, ``/``, ``//``, ``%``, :func:`divmod`,
:func:`pow`, ``**``, ``<<``, ``>>``, ``&``, ``^``, ``|``) with reflected
(swapped) operands. These functions are only called if the left operand does
- not support the corresponding operation and the operands are of different
+ not support the corresponding operation [#]_ and the operands are of different
types. [#]_ For instance, to evaluate the expression ``x - y``, where *y* is
an instance of a class that has an :meth:`__rsub__` method, ``y.__rsub__(x)``
is called if ``x.__sub__(y)`` returns *NotImplemented*.
@@ -2475,6 +2542,17 @@ An example of an asynchronous context manager class::
controlled conditions. It generally isn't a good idea though, since it can
lead to some very strange behaviour if it is handled incorrectly.
+.. [#] The :meth:`__hash__`, :meth:`__iter__`, :meth:`__reversed__`, and
+ :meth:`__contains__` methods have special handling for this; others
+ will still raise a :exc:`TypeError`, but may do so by relying on
+ the behavior that ``None`` is not callable.
+
+.. [#] "Does not support" here means that the class has no such method, or
+ the method returns ``NotImplemented``. Do not set the method to
+ ``None`` if you want to force fallback to the right operand's reflected
+ method--that will instead have the opposite effect of explicitly
+ *blocking* such fallback.
+
.. [#] For operands of the same type, it is assumed that if the non-reflected method
(such as :meth:`__add__`) fails the operation is not supported, which is why the
reflected method is not called.
diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst
index 64302b8..5e2c1c8 100644
--- a/Doc/reference/import.rst
+++ b/Doc/reference/import.rst
@@ -36,7 +36,7 @@ implement import semantics.
When a module is first imported, Python searches for the module and if found,
it creates a module object [#fnmo]_, initializing it. If the named module
-cannot be found, an :exc:`ImportError` is raised. Python implements various
+cannot be found, an :exc:`ModuleNotFoundError` is raised. Python implements various
strategies to search for the named module when the import machinery is
invoked. These strategies can be modified and extended by using various hooks
described in the sections below.
@@ -167,7 +167,7 @@ arguments to the :keyword:`import` statement, or from the parameters to the
This name will be used in various phases of the import search, and it may be
the dotted path to a submodule, e.g. ``foo.bar.baz``. In this case, Python
first tries to import ``foo``, then ``foo.bar``, and finally ``foo.bar.baz``.
-If any of the intermediate imports fail, an :exc:`ImportError` is raised.
+If any of the intermediate imports fail, an :exc:`ModuleNotFoundError` is raised.
The module cache
@@ -186,7 +186,7 @@ object.
During import, the module name is looked up in :data:`sys.modules` and if
present, the associated value is the module satisfying the import, and the
process completes. However, if the value is ``None``, then an
-:exc:`ImportError` is raised. If the module name is missing, Python will
+:exc:`ModuleNotFoundError` is raised. If the module name is missing, Python will
continue searching for the module.
:data:`sys.modules` is writable. Deleting a key may not destroy the
@@ -194,7 +194,7 @@ associated module (as other modules may hold references to it),
but it will invalidate the cache entry for the named module, causing
Python to search anew for the named module upon its next
import. The key can also be assigned to ``None``, forcing the next import
-of the module to result in an :exc:`ImportError`.
+of the module to result in an :exc:`ModuleNotFoundError`.
Beware though, as if you keep a reference to the module object,
invalidate its cache entry in :data:`sys.modules`, and then re-import the
@@ -288,8 +288,8 @@ the named module or not.
If the meta path finder knows how to handle the named module, it returns a
spec object. If it cannot handle the named module, it returns ``None``. If
:data:`sys.meta_path` processing reaches the end of its list without returning
-a spec, then an :exc:`ImportError` is raised. Any other exceptions raised
-are simply propagated up, aborting the import process.
+a spec, then a :exc:`ModuleNotFoundError` is raised. Any other exceptions
+raised are simply propagated up, aborting the import process.
The :meth:`~importlib.abc.MetaPathFinder.find_spec()` method of meta path
finders is called with two or three arguments. The first is the fully
@@ -298,9 +298,9 @@ The second argument is the path entries to use for the module search. For
top-level modules, the second argument is ``None``, but for submodules or
subpackages, the second argument is the value of the parent package's
``__path__`` attribute. If the appropriate ``__path__`` attribute cannot
-be accessed, an :exc:`ImportError` is raised. The third argument is an
-existing module object that will be the target of loading later. The
-import system passes in a target module only during reload.
+be accessed, an :exc:`ModuleNotFoundError` is raised. The third argument
+is an existing module object that will be the target of loading later.
+The import system passes in a target module only during reload.
The meta path may be traversed multiple times for a single import request.
For example, assuming none of the modules involved has already been cached,
@@ -554,19 +554,30 @@ the module.
details.
This attribute is used instead of ``__name__`` to calculate explicit
- relative imports for main modules, as defined in :pep:`366`.
+ relative imports for main modules, as defined in :pep:`366`. It is
+ expected to have the same value as ``__spec__.parent``.
+
+ .. versionchanged:: 3.6
+ The value of ``__package__`` is expected to be the same as
+ ``__spec__.parent``.
.. attribute:: __spec__
The ``__spec__`` attribute must be set to the module spec that was
- used when importing the module. This is used primarily for
- introspection and during reloading. Setting ``__spec__``
+ used when importing the module. Setting ``__spec__``
appropriately applies equally to :ref:`modules initialized during
interpreter startup <programs>`. The one exception is ``__main__``,
where ``__spec__`` is :ref:`set to None in some cases <main_spec>`.
+ When ``__package__`` is not defined, ``__spec__.parent`` is used as
+ a fallback.
+
.. versionadded:: 3.4
+ .. versionchanged:: 3.6
+ ``__spec__.parent`` is used as a fallback when ``__package__`` is
+ not defined.
+
.. attribute:: __path__
If the module is a package (either regular or namespace), the module
@@ -876,7 +887,7 @@ import statements within that module.
To selectively prevent import of some modules from a hook early on the
meta path (rather than disabling the standard import system entirely),
-it is sufficient to raise :exc:`ImportError` directly from
+it is sufficient to raise :exc:`ModuleNoFoundError` directly from
:meth:`~importlib.abc.MetaPathFinder.find_spec` instead of returning
``None``. The latter indicates that the meta path search should continue,
while raising an exception terminates it immediately.
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst
index 37f25f1..a7c6a68 100644
--- a/Doc/reference/lexical_analysis.rst
+++ b/Doc/reference/lexical_analysis.rst
@@ -405,7 +405,8 @@ String literals are described by the following lexical definitions:
.. productionlist::
stringliteral: [`stringprefix`](`shortstring` | `longstring`)
- stringprefix: "r" | "u" | "R" | "U"
+ stringprefix: "r" | "u" | "R" | "U" | "f" | "F"
+ : | "fr" | "Fr" | "fR" | "FR" | "rf" | "rF" | "Rf" | "RF"
shortstring: "'" `shortstringitem`* "'" | '"' `shortstringitem`* '"'
longstring: "'''" `longstringitem`* "'''" | '"""' `longstringitem`* '"""'
shortstringitem: `shortstringchar` | `stringescapeseq`
@@ -464,6 +465,11 @@ is not supported.
to simplify the maintenance of dual Python 2.x and 3.x codebases.
See :pep:`414` for more information.
+A string literal with ``'f'`` or ``'F'`` in its prefix is a
+:dfn:`formatted string literal`; see :ref:`f-strings`. The ``'f'`` may be
+combined with ``'r'``, but not with ``'b'`` or ``'u'``, therefore raw
+formatted strings are possible, but formatted bytes literals are not.
+
In triple-quoted literals, unescaped newlines and quotes are allowed (and are
retained), except that three unescaped quotes in a row terminate the literal. (A
"quote" is the character used to open the literal, i.e. either ``'`` or ``"``.)
@@ -554,6 +560,10 @@ is more easily recognized as broken.) It is also important to note that the
escape sequences only recognized in string literals fall into the category of
unrecognized escapes for bytes literals.
+ .. versionchanged:: 3.6
+ Unrecognized escape sequences produce a DeprecationWarning. In
+ some future version of Python they will be a SyntaxError.
+
Even in a raw literal, quotes can be escaped with a backslash, but the
backslash remains in the result; for example, ``r"\""`` is a valid string
literal consisting of two characters: a backslash and a double quote; ``r"\"``
@@ -583,7 +593,106 @@ comments to parts of strings, for example::
Note that this feature is defined at the syntactical level, but implemented at
compile time. The '+' operator must be used to concatenate string expressions
at run time. Also note that literal concatenation can use different quoting
-styles for each component (even mixing raw strings and triple quoted strings).
+styles for each component (even mixing raw strings and triple quoted strings),
+and formatted string literals may be concatenated with plain string literals.
+
+
+.. index::
+ single: formatted string literal
+ single: interpolated string literal
+ single: string; formatted literal
+ single: string; interpolated literal
+ single: f-string
+.. _f-strings:
+
+Formatted string literals
+-------------------------
+
+.. versionadded:: 3.6
+
+A :dfn:`formatted string literal` or :dfn:`f-string` is a string literal
+that is prefixed with ``'f'`` or ``'F'``. These strings may contain
+replacement fields, which are expressions delimited by curly braces ``{}``.
+While other string literals always have a constant value, formatted strings
+are really expressions evaluated at run time.
+
+Escape sequences are decoded like in ordinary string literals (except when
+a literal is also marked as a raw string). After decoding, the grammar
+for the contents of the string is:
+
+.. productionlist::
+ f_string: (`literal_char` | "{{" | "}}" | `replacement_field`)*
+ replacement_field: "{" `f_expression` ["!" `conversion`] [":" `format_spec`] "}"
+ f_expression: (`conditional_expression` | "*" `or_expr`)
+ : ("," `conditional_expression` | "," "*" `or_expr`)* [","]
+ : | `yield_expression`
+ conversion: "s" | "r" | "a"
+ format_spec: (`literal_char` | NULL | `replacement_field`)*
+ literal_char: <any code point except "{", "}" or NULL>
+
+The parts of the string outside curly braces are treated literally,
+except that any doubled curly braces ``'{{'`` or ``'}}'`` are replaced
+with the corresponding single curly brace. A single opening curly
+bracket ``'{'`` marks a replacement field, which starts with a
+Python expression. After the expression, there may be a conversion field,
+introduced by an exclamation point ``'!'``. A format specifier may also
+be appended, introduced by a colon ``':'``. A replacement field ends
+with a closing curly bracket ``'}'``.
+
+Expressions in formatted string literals are treated like regular
+Python expressions surrounded by parentheses, with a few exceptions.
+An empty expression is not allowed, and a :keyword:`lambda` expression
+must be surrounded by explicit parentheses. Replacement expressions
+can contain line breaks (e.g. in triple-quoted strings), but they
+cannot contain comments. Each expression is evaluated in the context
+where the formatted string literal appears, in order from left to right.
+
+If a conversion is specified, the result of evaluating the expression
+is converted before formatting. Conversion ``'!s'`` calls :func:`str` on
+the result, ``'!r'`` calls :func:`repr`, and ``'!a'`` calls :func:`ascii`.
+
+The result is then formatted using the :func:`format` protocol. The
+format specifier is passed to the :meth:`__format__` method of the
+expression or conversion result. An empty string is passed when the
+format specifier is omitted. The formatted result is then included in
+the final value of the whole string.
+
+Top-level format specifiers may include nested replacement fields.
+These nested fields may include their own conversion fields and
+format specifiers, but may not include more deeply-nested replacement fields.
+
+Formatted string literals may be concatenated, but replacement fields
+cannot be split across literals.
+
+Some examples of formatted string literals::
+
+ >>> name = "Fred"
+ >>> f"He said his name is {name!r}."
+ "He said his name is 'Fred'."
+ >>> f"He said his name is {repr(name)}." # repr() is equivalent to !r
+ "He said his name is 'Fred'."
+ >>> width = 10
+ >>> precision = 4
+ >>> value = decimal.Decimal("12.34567")
+ >>> f"result: {value:{width}.{precision}}" # nested fields
+ 'result: 12.35'
+
+A consequence of sharing the same syntax as regular string literals is
+that characters in the replacement fields must not conflict with the
+quoting used in the outer formatted string literal. Also, escape
+sequences normally apply to the outer formatted string literal,
+rather than inner string literals::
+
+ f"abc {a["x"]} def" # error: outer string literal ended prematurely
+ f"abc {a[\"x\"]} def" # workaround: escape the inner quotes
+ f"abc {a['x']} def" # workaround: use different quoting
+
+ f"newline: {ord('\n')}" # error: literal line break in inner string
+ f"newline: {ord('\\n')}" # workaround: double escaping
+ fr"newline: {ord('\n')}" # workaround: raw outer string
+
+See also :pep:`498` for the proposal that added formatted string literals,
+and :meth:`str.format`, which uses a related format string mechanism.
.. _numbers:
@@ -612,20 +721,24 @@ Integer literals
Integer literals are described by the following lexical definitions:
.. productionlist::
- integer: `decimalinteger` | `octinteger` | `hexinteger` | `bininteger`
- decimalinteger: `nonzerodigit` `digit`* | "0"+
+ integer: `decinteger` | `bininteger` | `octinteger` | `hexinteger`
+ decinteger: `nonzerodigit` (["_"] `digit`)* | "0"+ (["_"] "0")*
+ bininteger: "0" ("b" | "B") (["_"] `bindigit`)+
+ octinteger: "0" ("o" | "O") (["_"] `octdigit`)+
+ hexinteger: "0" ("x" | "X") (["_"] `hexdigit`)+
nonzerodigit: "1"..."9"
digit: "0"..."9"
- octinteger: "0" ("o" | "O") `octdigit`+
- hexinteger: "0" ("x" | "X") `hexdigit`+
- bininteger: "0" ("b" | "B") `bindigit`+
+ bindigit: "0" | "1"
octdigit: "0"..."7"
hexdigit: `digit` | "a"..."f" | "A"..."F"
- bindigit: "0" | "1"
There is no limit for the length of integer literals apart from what can be
stored in available memory.
+Underscores are ignored for determining the numeric value of the literal. They
+can be used to group digits for enhanced readability. One underscore can occur
+between digits, and after base specifiers like ``0x``.
+
Note that leading zeros in a non-zero decimal number are not allowed. This is
for disambiguation with C-style octal literals, which Python used before version
3.0.
@@ -634,6 +747,10 @@ Some examples of integer literals::
7 2147483647 0o177 0b100110111
3 79228162514264337593543950336 0o377 0xdeadbeef
+ 100_000_000_000 0b_1110_0101
+
+.. versionchanged:: 3.6
+ Underscores are now allowed for grouping purposes in literals.
.. _floating:
@@ -645,23 +762,28 @@ Floating point literals are described by the following lexical definitions:
.. productionlist::
floatnumber: `pointfloat` | `exponentfloat`
- pointfloat: [`intpart`] `fraction` | `intpart` "."
- exponentfloat: (`intpart` | `pointfloat`) `exponent`
- intpart: `digit`+
- fraction: "." `digit`+
- exponent: ("e" | "E") ["+" | "-"] `digit`+
+ pointfloat: [`digitpart`] `fraction` | `digitpart` "."
+ exponentfloat: (`digitpart` | `pointfloat`) `exponent`
+ digitpart: `digit` (["_"] `digit`)*
+ fraction: "." `digitpart`
+ exponent: ("e" | "E") ["+" | "-"] `digitpart`
Note that the integer and exponent parts are always interpreted using radix 10.
For example, ``077e010`` is legal, and denotes the same number as ``77e10``. The
-allowed range of floating point literals is implementation-dependent. Some
-examples of floating point literals::
+allowed range of floating point literals is implementation-dependent. As in
+integer literals, underscores are supported for digit grouping.
- 3.14 10. .001 1e100 3.14e-10 0e0
+Some examples of floating point literals::
+
+ 3.14 10. .001 1e100 3.14e-10 0e0 3.14_15_93
Note that numeric literals do not include a sign; a phrase like ``-1`` is
actually an expression composed of the unary operator ``-`` and the literal
``1``.
+.. versionchanged:: 3.6
+ Underscores are now allowed for grouping purposes in literals.
+
.. _imaginary:
@@ -671,7 +793,7 @@ Imaginary literals
Imaginary literals are described by the following lexical definitions:
.. productionlist::
- imagnumber: (`floatnumber` | `intpart`) ("j" | "J")
+ imagnumber: (`floatnumber` | `digitpart`) ("j" | "J")
An imaginary literal yields a complex number with a real part of 0.0. Complex
numbers are represented as a pair of floating point numbers and have the same
@@ -679,7 +801,7 @@ restrictions on their range. To create a complex number with a nonzero real
part, add a floating point number to it, e.g., ``(3+4j)``. Some examples of
imaginary literals::
- 3.14j 10.j 10j .001j 1e100j 3.14e-10j
+ 3.14j 10.j 10j .001j 1e100j 3.14e-10j 3.14_15_93j
.. _operators:
diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst
index d403c4d..3dc4418 100644
--- a/Doc/reference/simple_stmts.rst
+++ b/Doc/reference/simple_stmts.rst
@@ -16,6 +16,7 @@ simple statements is:
: | `assert_stmt`
: | `assignment_stmt`
: | `augmented_assignment_stmt`
+ : | `annotated_assignment_stmt`
: | `pass_stmt`
: | `del_stmt`
: | `return_stmt`
@@ -84,7 +85,7 @@ attributes or items of mutable objects:
assignment_stmt: (`target_list` "=")+ (`starred_expression` | `yield_expression`)
target_list: `target` ("," `target`)* [","]
target: `identifier`
- : | "(" `target_list` ")"
+ : | "(" [`target_list`] ")"
: | "[" [`target_list`] "]"
: | `attributeref`
: | `subscription`
@@ -312,6 +313,50 @@ For targets which are attribute references, the same :ref:`caveat about class
and instance attributes <attr-target-note>` applies as for regular assignments.
+.. _annassign:
+
+Annotated assignment statements
+-------------------------------
+
+.. index::
+ pair: annotated; assignment
+ single: statement; assignment, annotated
+
+Annotation assignment is the combination, in a single statement,
+of a variable or attribute annotation and an optional assignment statement:
+
+.. productionlist::
+ annotated_assignment_stmt: `augtarget` ":" `expression` ["=" `expression`]
+
+The difference from normal :ref:`assignment` is that only single target and
+only single right hand side value is allowed.
+
+For simple names as assignment targets, if in class or module scope,
+the annotations are evaluated and stored in a special class or module
+attribute :attr:`__annotations__`
+that is a dictionary mapping from variable names (mangled if private) to
+evaluated annotations. This attribute is writable and is automatically
+created at the start of class or module body execution, if annotations
+are found statically.
+
+For expressions as assignment targets, the annotations are evaluated if
+in class or module scope, but not stored.
+
+If a name is annotated in a function scope, then this name is local for
+that scope. Annotations are never evaluated and stored in function scopes.
+
+If the right hand side is present, an annotated
+assignment performs the actual assignment before evaluating annotations
+(where applicable). If the right hand side is not present for an expression
+target, then the interpreter evaluates the target except for the last
+:meth:`__setitem__` or :meth:`__setattr__` call.
+
+.. seealso::
+
+ :pep:`526` - Variable and attribute annotation syntax
+ :pep:`484` - Type hints
+
+
.. _assert:
The :keyword:`assert` statement
@@ -859,11 +904,12 @@ block textually preceding that :keyword:`global` statement.
Names listed in a :keyword:`global` statement must not be defined as formal
parameters or in a :keyword:`for` loop control target, :keyword:`class`
-definition, function definition, or :keyword:`import` statement.
+definition, function definition, :keyword:`import` statement, or variable
+annotation.
.. impl-detail::
- The current implementation does not enforce the two restrictions, but
+ The current implementation does not enforce some of these restriction, but
programs should not abuse this freedom, as future implementations may enforce
them or silently change the meaning of the program.
diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py
index 6311283..273191b 100644
--- a/Doc/tools/extensions/pyspecific.py
+++ b/Doc/tools/extensions/pyspecific.py
@@ -34,7 +34,7 @@ import suspicious
ISSUE_URI = 'https://bugs.python.org/issue%s'
-SOURCE_URI = 'https://hg.python.org/cpython/file/3.5/%s'
+SOURCE_URI = 'https://hg.python.org/cpython/file/3.6/%s'
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
from docutils.parsers.rst.states import Body
diff --git a/Doc/tools/rstlint.py b/Doc/tools/rstlint.py
index de78041..2c1816e 100755
--- a/Doc/tools/rstlint.py
+++ b/Doc/tools/rstlint.py
@@ -9,8 +9,6 @@
# TODO: - wrong versions in versionadded/changed
# - wrong markup after versionchanged directive
-from __future__ import with_statement
-
import os
import re
import sys
diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv
index dba93bf..5de55a2 100644
--- a/Doc/tools/susp-ignored.csv
+++ b/Doc/tools/susp-ignored.csv
@@ -25,6 +25,30 @@ howto/curses,,:blue,"2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and 7:white.
howto/curses,,:magenta,"2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and 7:white. The"
howto/curses,,:cyan,"2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and 7:white. The"
howto/curses,,:white,"2:green, 3:yellow, 4:blue, 5:magenta, 6:cyan, and 7:white. The"
+howto/instrumentation,,::,python$target:::function-entry
+howto/instrumentation,,:function,python$target:::function-entry
+howto/instrumentation,,::,python$target:::function-return
+howto/instrumentation,,:function,python$target:::function-return
+howto/instrumentation,,:call,156641360502280 function-entry:call_stack.py:start:23
+howto/instrumentation,,:start,156641360502280 function-entry:call_stack.py:start:23
+howto/instrumentation,,:function,156641360518804 function-entry: call_stack.py:function_1:1
+howto/instrumentation,,:function,156641360532797 function-entry: call_stack.py:function_3:9
+howto/instrumentation,,:function,156641360546807 function-return: call_stack.py:function_3:10
+howto/instrumentation,,:function,156641360563367 function-return: call_stack.py:function_1:2
+howto/instrumentation,,:function,156641360578365 function-entry: call_stack.py:function_2:5
+howto/instrumentation,,:function,156641360591757 function-entry: call_stack.py:function_1:1
+howto/instrumentation,,:function,156641360605556 function-entry: call_stack.py:function_3:9
+howto/instrumentation,,:function,156641360617482 function-return: call_stack.py:function_3:10
+howto/instrumentation,,:function,156641360629814 function-return: call_stack.py:function_1:2
+howto/instrumentation,,:function,156641360642285 function-return: call_stack.py:function_2:6
+howto/instrumentation,,:function,156641360656770 function-entry: call_stack.py:function_3:9
+howto/instrumentation,,:function,156641360669707 function-return: call_stack.py:function_3:10
+howto/instrumentation,,:function,156641360687853 function-entry: call_stack.py:function_4:13
+howto/instrumentation,,:function,156641360700719 function-return: call_stack.py:function_4:14
+howto/instrumentation,,:function,156641360719640 function-entry: call_stack.py:function_5:18
+howto/instrumentation,,:function,156641360732567 function-return: call_stack.py:function_5:21
+howto/instrumentation,,:call,156641360747370 function-return:call_stack.py:start:28
+howto/instrumentation,,:start,156641360747370 function-return:call_stack.py:start:28
howto/ipaddress,,:DB8,>>> ipaddress.ip_address('2001:DB8::1')
howto/ipaddress,,::,>>> ipaddress.ip_address('2001:DB8::1')
howto/ipaddress,,:db8,IPv6Address('2001:db8::1')
@@ -106,6 +130,10 @@ library/exceptions,,:err,err.object[err.start:err.end]
library/functions,,:step,a[start:stop:step]
library/functions,,:stop,"a[start:stop, i]"
library/functions,,:stop,a[start:stop:step]
+library/hashlib-blake2,,:vatrogasac,>>> cookie = b'user:vatrogasac'
+library/hashlib-blake2,,:vatrogasac,"user:vatrogasac,349cf904533767ed2d755279a8df84d0"
+library/hashlib-blake2,,:policajac,">>> compare_digest(b'user:policajac', sig)"
+library/hashlib-blake2,,:LEAF,"h00 = blake2b(buf[0:LEAF_SIZE], fanout=FANOUT, depth=DEPTH,"
library/http.client,,:port,host:port
library/http.cookies,,`,!#$%&'*+-.^_`|~:
library/imaplib,,:MM,"""DD-Mmm-YYYY HH:MM:SS"
@@ -205,7 +233,8 @@ library/uuid,,:uuid,urn:uuid:12345678-1234-5678-1234-567812345678
library/venv,,:param,":param nodist: If True, setuptools and pip are not installed into the"
library/venv,,:param,":param progress: If setuptools or pip are installed, the progress of the"
library/venv,,:param,":param nopip: If True, pip is not installed into the created"
-library/venv,,:param,:param context: The information for the environment creation request
+library/venv,,:param,:param context: The information for the virtual environment
+library/xmlrpc.client,,:nil,ex:nil
library/xmlrpc.client,,:pass,http://user:pass@host:port/path
library/xmlrpc.client,,:pass,user:pass
library/xmlrpc.client,,:port,http://user:pass@host:port/path
@@ -239,7 +268,7 @@ using/cmdline,,:line,file:line: category: message
using/cmdline,,:message,action:message:category:module:line
using/cmdline,,:module,action:message:category:module:line
using/unix,,:Packaging,https://en.opensuse.org/Portal:Packaging
-whatsnew/2.0,418,:len,
+whatsnew/2.0,,:len,
whatsnew/2.3,,::,
whatsnew/2.3,,:config,
whatsnew/2.3,,:Critical,
@@ -272,27 +301,27 @@ whatsnew/3.2,,:feed,>>> urllib.parse.urlparse('http://[dead:beef:cafe:5417:affe:
whatsnew/3.2,,:gz,">>> with tarfile.open(name='myarchive.tar.gz', mode='w:gz') as tf:"
whatsnew/3.2,,:location,zope9-location = ${zope9:location}
whatsnew/3.2,,:prefix,zope-conf = ${custom:prefix}/etc/zope.conf
-whatsnew/changelog,,:gz,": TarFile opened with external fileobj and ""w:gz"" mode didn't"
-whatsnew/changelog,,::,": Use ""127.0.0.1"" or ""::1"" instead of ""localhost"" as much as"
-library/tarfile,149,:xz,'x:xz'
-library/xml.etree.elementtree,290,:sometag,prefix:sometag
-library/xml.etree.elementtree,301,:fictional,"<actors xmlns:fictional=""http://characters.example.com"""
-library/xml.etree.elementtree,301,:character,<fictional:character>Lancelot</fictional:character>
-library/xml.etree.elementtree,301,:character,<fictional:character>Archie Leach</fictional:character>
-library/xml.etree.elementtree,301,:character,<fictional:character>Sir Robin</fictional:character>
-library/xml.etree.elementtree,301,:character,<fictional:character>Gunther</fictional:character>
-library/xml.etree.elementtree,301,:character,<fictional:character>Commander Clement</fictional:character>
+library/tarfile,,:xz,'x:xz'
+library/xml.etree.elementtree,,:sometag,prefix:sometag
+library/xml.etree.elementtree,,:fictional,"<actors xmlns:fictional=""http://characters.example.com"""
+library/xml.etree.elementtree,,:character,<fictional:character>Lancelot</fictional:character>
+library/xml.etree.elementtree,,:character,<fictional:character>Archie Leach</fictional:character>
+library/xml.etree.elementtree,,:character,<fictional:character>Sir Robin</fictional:character>
+library/xml.etree.elementtree,,:character,<fictional:character>Gunther</fictional:character>
+library/xml.etree.elementtree,,:character,<fictional:character>Commander Clement</fictional:character>
library/xml.etree.elementtree,,:actor,"for actor in root.findall('real_person:actor', ns):"
library/xml.etree.elementtree,,:name,"name = actor.find('real_person:name', ns)"
library/xml.etree.elementtree,,:character,"for char in actor.findall('role:character', ns):"
-library/zipapp,31,:main,"$ python -m zipapp myapp -m ""myapp:main"""
-library/zipapp,82,:fn,"argument should have the form ""pkg.mod:fn"", where ""pkg.mod"" is a"
-library/zipapp,155,:callable,"""pkg.module:callable"" and the archive will be run by importing"
+library/zipapp,,:main,"$ python -m zipapp myapp -m ""myapp:main"""
+library/zipapp,,:fn,"argument should have the form ""pkg.mod:fn"", where ""pkg.mod"" is a"
+library/zipapp,,:callable,"""pkg.module:callable"" and the archive will be run by importing"
library/stdtypes,,::,>>> m[::2].tolist()
library/sys,,`,# ``wrapper`` creates a ``wrap(coro)`` coroutine:
-tutorial/venv,77,:c7b9645a6f35,"Python 3.4.3+ (3.4:c7b9645a6f35+, May 22 2015, 09:31:25)"
whatsnew/3.5,,:root,'WARNING:root:warning\n'
whatsnew/3.5,,:warning,'WARNING:root:warning\n'
whatsnew/3.5,,::,>>> addr6 = ipaddress.IPv6Address('::1')
whatsnew/3.5,,:root,ERROR:root:exception
whatsnew/3.5,,:exception,ERROR:root:exception
+whatsnew/changelog,,:version,import sys; I = version[:version.index(' ')]
+whatsnew/changelog,,:gz,": TarFile opened with external fileobj and ""w:gz"" mode didn't"
+whatsnew/changelog,,::,": Use ""127.0.0.1"" or ""::1"" instead of ""localhost"" as much as"
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index 12989b2..d434618 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -78,6 +78,9 @@ slice notation makes this especially convenient::
>>> words
['defenestrate', 'cat', 'window', 'defenestrate']
+With ``for w in words:``, the example would attempt to create an infinite list,
+inserting ``defenestrate`` over and over again.
+
.. _tut-range:
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst
index dd9c7cd..beeaac3 100644
--- a/Doc/tutorial/inputoutput.rst
+++ b/Doc/tutorial/inputoutput.rst
@@ -25,7 +25,8 @@ first way is to do all the string handling yourself; using string slicing and
concatenation operations you can create any layout you can imagine. The
string type has some methods that perform useful operations for padding
strings to a given column width; these will be discussed shortly. The second
-way is to use the :meth:`str.format` method.
+way is to use :ref:`formatted string literals <f-strings>`, or the
+:meth:`str.format` method.
The :mod:`string` module contains a :class:`~string.Template` class which offers
yet another way to substitute values into strings.
diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst
index e8d8e2b..faf57a3 100644
--- a/Doc/tutorial/interpreter.rst
+++ b/Doc/tutorial/interpreter.rst
@@ -10,13 +10,13 @@ Using the Python Interpreter
Invoking the Interpreter
========================
-The Python interpreter is usually installed as :file:`/usr/local/bin/python3.5`
+The Python interpreter is usually installed as :file:`/usr/local/bin/python3.6`
on those machines where it is available; putting :file:`/usr/local/bin` in your
Unix shell's search path makes it possible to start it by typing the command:
.. code-block:: text
- python3.5
+ python3.6
to the shell. [#]_ Since the choice of the directory where the interpreter lives
is an installation option, other places are possible; check with your local
@@ -24,11 +24,11 @@ Python guru or system administrator. (E.g., :file:`/usr/local/python` is a
popular alternative location.)
On Windows machines, the Python installation is usually placed in
-:file:`C:\\Python35`, though you can change this when you're running the
+:file:`C:\\Python36`, though you can change this when you're running the
installer. To add this directory to your path, you can type the following
command into the command prompt in a DOS box::
- set path=%path%;C:\python35
+ set path=%path%;C:\python36
Typing an end-of-file character (:kbd:`Control-D` on Unix, :kbd:`Control-Z` on
Windows) at the primary prompt causes the interpreter to exit with a zero exit
@@ -98,8 +98,8 @@ before printing the first prompt:
.. code-block:: shell-session
- $ python3.5
- Python 3.5 (default, Sep 16 2015, 09:25:04)
+ $ python3.6
+ Python 3.6 (default, Sep 16 2015, 09:25:04)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst
index 2140329..7e8ee3e 100644
--- a/Doc/tutorial/introduction.rst
+++ b/Doc/tutorial/introduction.rst
@@ -352,6 +352,9 @@ The built-in function :func:`len` returns the length of a string::
Strings support a large number of methods for
basic transformations and searching.
+ :ref:`f-strings`
+ String literals that have embedded expressions.
+
:ref:`formatstrings`
Information about string formatting with :meth:`str.format`.
diff --git a/Doc/tutorial/stdlib.rst b/Doc/tutorial/stdlib.rst
index 52ffdbe..1dd06c2 100644
--- a/Doc/tutorial/stdlib.rst
+++ b/Doc/tutorial/stdlib.rst
@@ -15,7 +15,7 @@ operating system::
>>> import os
>>> os.getcwd() # Return the current working directory
- 'C:\\Python35'
+ 'C:\\Python36'
>>> os.chdir('/server/accesslogs') # Change current working directory
>>> os.system('mkdir today') # Run the command mkdir in the system shell
0
diff --git a/Doc/tutorial/stdlib2.rst b/Doc/tutorial/stdlib2.rst
index 3714384..bf4cf87 100644
--- a/Doc/tutorial/stdlib2.rst
+++ b/Doc/tutorial/stdlib2.rst
@@ -278,7 +278,7 @@ applications include caching objects that are expensive to create::
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
d['primary'] # entry was automatically removed
- File "C:/python35/lib/weakref.py", line 46, in __getitem__
+ File "C:/python36/lib/weakref.py", line 46, in __getitem__
o = self.data[key]()
KeyError: 'primary'
diff --git a/Doc/tutorial/venv.rst b/Doc/tutorial/venv.rst
index 3b2ee2e..e2dd57d 100644
--- a/Doc/tutorial/venv.rst
+++ b/Doc/tutorial/venv.rst
@@ -20,15 +20,14 @@ the requirements of every application. If application A needs version
the requirements are in conflict and installing either version 1.0 or 2.0
will leave one application unable to run.
-The solution for this problem is to create a :term:`virtual
-environment` (often shortened to "virtualenv"), a self-contained
-directory tree that contains a Python installation for a particular
-version of Python, plus a number of additional packages.
+The solution for this problem is to create a :term:`virtual environment`, a
+self-contained directory tree that contains a Python installation for a
+particular version of Python, plus a number of additional packages.
Different applications can then use different virtual environments.
To resolve the earlier example of conflicting requirements,
application A can have its own virtual environment with version 1.0
-installed while application B has another virtualenv with version 2.0.
+installed while application B has another virtual environment with version 2.0.
If application B requires a library be upgraded to version 3.0, this will
not affect application A's environment.
@@ -36,29 +35,26 @@ not affect application A's environment.
Creating Virtual Environments
=============================
-The script used to create and manage virtual environments is called
-:program:`pyvenv`. :program:`pyvenv` will usually install the most
-recent version of Python that you have available; the script is also
-installed with a version number, so if you have multiple versions of
-Python on your system you can select a specific Python version by
-running ``pyvenv-3.4`` or whichever version you want.
+The module used to create and manage virtual environments is called
+:mod:`venv`. :mod:`venv` will usually install the most recent version of
+Python that you have available. If you have multiple versions of Python on your
+system, you can select a specific Python version by running ``python3`` or
+whichever version you want.
-To create a virtualenv, decide upon a directory
-where you want to place it and run :program:`pyvenv` with the
-directory path::
+To create a virtual environment, decide upon a directory where you want to
+place it, and run the :mod:`venv` module as a script with the directory path::
- pyvenv tutorial-env
+ python3 -m venv tutorial-env
This will create the ``tutorial-env`` directory if it doesn't exist,
and also create directories inside it containing a copy of the Python
interpreter, the standard library, and various supporting files.
-Once you've created a virtual environment, you need to
-activate it.
+Once you've created a virtual environment, you may activate it.
On Windows, run::
- tutorial-env/Scripts/activate
+ tutorial-env\Scripts\activate.bat
On Unix or MacOS, run::
@@ -69,33 +65,36 @@ On Unix or MacOS, run::
``activate.csh`` and ``activate.fish`` scripts you should use
instead.)
-Activating the virtualenv will change your shell's prompt to show what
-virtualenv you're using, and modify the environment so that running
-``python`` will get you that particular version and installation of
-Python. For example::
+Activating the virtual environment will change your shell's prompt to show what
+virtual environment you're using, and modify the environment so that running
+``python`` will get you that particular version and installation of Python.
+For example:
- -> source ~/envs/tutorial-env/bin/activate
- (tutorial-env) -> python
- Python 3.4.3+ (3.4:c7b9645a6f35+, May 22 2015, 09:31:25)
+.. code-block:: bash
+
+ $ source ~/envs/tutorial-env/bin/activate
+ (tutorial-env) $ python
+ Python 3.5.1 (default, May 6 2016, 10:59:36)
...
>>> import sys
>>> sys.path
- ['', '/usr/local/lib/python34.zip', ...,
- '~/envs/tutorial-env/lib/python3.4/site-packages']
+ ['', '/usr/local/lib/python35.zip', ...,
+ '~/envs/tutorial-env/lib/python3.5/site-packages']
>>>
Managing Packages with pip
==========================
-Once you've activated a virtual environment, you can install, upgrade,
-and remove packages using a program called :program:`pip`. By default
-``pip`` will install packages from the Python Package Index,
-<https://pypi.python.org/pypi>. You can browse the Python Package Index
-by going to it in your web browser, or you can use ``pip``'s
-limited search feature::
+You can install, upgrade, and remove packages using a program called
+:program:`pip`. By default ``pip`` will install packages from the Python
+Package Index, <https://pypi.python.org/pypi>. You can browse the Python
+Package Index by going to it in your web browser, or you can use ``pip``'s
+limited search feature:
+
+.. code-block:: bash
- (tutorial-env) -> pip search astronomy
+ (tutorial-env) $ pip search astronomy
skyfield - Elegant astronomy for Python
gary - Galactic astronomy and gravitational dynamics.
novas - The United States Naval Observatory NOVAS astronomy library
@@ -107,9 +106,11 @@ limited search feature::
"freeze", etc. (Consult the :ref:`installing-index` guide for
complete documentation for ``pip``.)
-You can install the latest version of a package by specifying a package's name::
+You can install the latest version of a package by specifying a package's name:
+
+.. code-block:: bash
- -> pip install novas
+ (tutorial-env) $ pip install novas
Collecting novas
Downloading novas-3.1.1.3.tar.gz (136kB)
Installing collected packages: novas
@@ -117,9 +118,11 @@ You can install the latest version of a package by specifying a package's name::
Successfully installed novas-3.1.1.3
You can also install a specific version of a package by giving the
-package name followed by ``==`` and the version number::
+package name followed by ``==`` and the version number:
- -> pip install requests==2.6.0
+.. code-block:: bash
+
+ (tutorial-env) $ pip install requests==2.6.0
Collecting requests==2.6.0
Using cached requests-2.6.0-py2.py3-none-any.whl
Installing collected packages: requests
@@ -128,9 +131,11 @@ package name followed by ``==`` and the version number::
If you re-run this command, ``pip`` will notice that the requested
version is already installed and do nothing. You can supply a
different version number to get that version, or you can run ``pip
-install --upgrade`` to upgrade the package to the latest version::
+install --upgrade`` to upgrade the package to the latest version:
+
+.. code-block:: bash
- -> pip install --upgrade requests
+ (tutorial-env) $ pip install --upgrade requests
Collecting requests
Installing collected packages: requests
Found existing installation: requests 2.6.0
@@ -141,9 +146,11 @@ install --upgrade`` to upgrade the package to the latest version::
``pip uninstall`` followed by one or more package names will remove the
packages from the virtual environment.
-``pip show`` will display information about a particular package::
+``pip show`` will display information about a particular package:
- (tutorial-env) -> pip show requests
+.. code-block:: bash
+
+ (tutorial-env) $ pip show requests
---
Metadata-Version: 2.0
Name: requests
@@ -157,9 +164,11 @@ packages from the virtual environment.
Requires:
``pip list`` will display all of the packages installed in the virtual
-environment::
+environment:
+
+.. code-block:: bash
- (tutorial-env) -> pip list
+ (tutorial-env) $ pip list
novas (3.1.1.3)
numpy (1.9.2)
pip (7.0.3)
@@ -168,19 +177,23 @@ environment::
``pip freeze`` will produce a similar list of the installed packages,
but the output uses the format that ``pip install`` expects.
-A common convention is to put this list in a ``requirements.txt`` file::
+A common convention is to put this list in a ``requirements.txt`` file:
- (tutorial-env) -> pip freeze > requirements.txt
- (tutorial-env) -> cat requirements.txt
+.. code-block:: bash
+
+ (tutorial-env) $ pip freeze > requirements.txt
+ (tutorial-env) $ cat requirements.txt
novas==3.1.1.3
numpy==1.9.2
requests==2.7.0
The ``requirements.txt`` can then be committed to version control and
shipped as part of an application. Users can then install all the
-necessary packages with ``install -r``::
+necessary packages with ``install -r``:
+
+.. code-block:: bash
- -> pip install -r requirements.txt
+ (tutorial-env) $ pip install -r requirements.txt
Collecting novas==3.1.1.3 (from -r requirements.txt (line 1))
...
Collecting numpy==1.9.2 (from -r requirements.txt (line 2))
diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst
index 57faf89..75cb8ea 100644
--- a/Doc/using/cmdline.rst
+++ b/Doc/using/cmdline.rst
@@ -395,6 +395,8 @@ Miscellaneous options
stored in a traceback of a trace. Use ``-X tracemalloc=NFRAME`` to start
tracing with a traceback limit of *NFRAME* frames. See the
:func:`tracemalloc.start` for more information.
+ * ``-X showalloccount`` to enable the output of the total count of allocated
+ objects for each type (only works when built with ``COUNT_ALLOCS`` defined);
It also allows passing arbitrary values and retrieving them through the
:data:`sys._xoptions` dictionary.
@@ -408,6 +410,9 @@ Miscellaneous options
.. versionadded:: 3.4
The ``-X showrefcount`` and ``-X tracemalloc`` options.
+ .. versionadded:: 3.6
+ The ``-X showalloccount`` option.
+
Options you shouldn't use
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -554,6 +559,10 @@ conflict.
.. versionchanged:: 3.4
The ``encodingname`` part is now optional.
+ .. versionchanged:: 3.6
+ On Windows, the encoding specified by this variable is ignored for interactive
+ console buffers unless :envvar:`PYTHONLEGACYWINDOWSIOENCODING` is also specified.
+ Files and pipes redirected through the standard streams are not affected.
.. envvar:: PYTHONNOUSERSITE
@@ -619,6 +628,81 @@ conflict.
.. versionadded:: 3.4
+.. envvar:: PYTHONMALLOC
+
+ Set the Python memory allocators and/or install debug hooks.
+
+ Set the family of memory allocators used by Python:
+
+ * ``malloc``: use the :c:func:`malloc` function of the C library
+ for all domains (:c:data:`PYMEM_DOMAIN_RAW`, :c:data:`PYMEM_DOMAIN_MEM`,
+ :c:data:`PYMEM_DOMAIN_OBJ`).
+ * ``pymalloc``: use the :ref:`pymalloc allocator <pymalloc>` for
+ :c:data:`PYMEM_DOMAIN_MEM` and :c:data:`PYMEM_DOMAIN_OBJ` domains and use
+ the :c:func:`malloc` function for the :c:data:`PYMEM_DOMAIN_RAW` domain.
+
+ Install debug hooks:
+
+ * ``debug``: install debug hooks on top of the default memory allocator
+ * ``malloc_debug``: same as ``malloc`` but also install debug hooks
+ * ``pymalloc_debug``: same as ``pymalloc`` but also install debug hooks
+
+ When Python is compiled in release mode, the default is ``pymalloc``. When
+ compiled in debug mode, the default is ``pymalloc_debug`` and the debug hooks
+ are used automatically.
+
+ If Python is configured without ``pymalloc`` support, ``pymalloc`` and
+ ``pymalloc_debug`` are not available, the default is ``malloc`` in release
+ mode and ``malloc_debug`` in debug mode.
+
+ See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python
+ memory allocators.
+
+ .. versionadded:: 3.6
+
+
+.. envvar:: PYTHONMALLOCSTATS
+
+ If set to a non-empty string, Python will print statistics of the
+ :ref:`pymalloc memory allocator <pymalloc>` every time a new pymalloc object
+ arena is created, and on shutdown.
+
+ This variable is ignored if the :envvar:`PYTHONMALLOC` environment variable
+ is used to force the :c:func:`malloc` allocator of the C library, or if
+ Python is configured without ``pymalloc`` support.
+
+ .. versionchanged:: 3.6
+ This variable can now also be used on Python compiled in release mode.
+ It now has no effect if set to an empty string.
+
+
+.. envvar:: PYTHONLEGACYWINDOWSFSENCODING
+
+ If set to a non-empty string, the default filesystem encoding and errors mode
+ will revert to their pre-3.6 values of 'mbcs' and 'replace', respectively.
+ Otherwise, the new defaults 'utf-8' and 'surrogatepass' are used.
+
+ This may also be enabled at runtime with
+ :func:`sys._enablelegacywindowsfsencoding()`.
+
+ Availability: Windows
+
+ .. versionadded:: 3.6
+ See :pep:`529` for more details.
+
+.. envvar:: PYTHONLEGACYWINDOWSIOENCODING
+
+ If set to a non-empty string, does not use the new console reader and
+ writer. This means that Unicode characters will be encoded according to
+ the active console code page, rather than using utf-8.
+
+ This variable is ignored if the standard streams are redirected (to files
+ or pipes) rather than referring to console buffers.
+
+ Availability: Windows
+
+ .. versionadded:: 3.6
+
Debug-mode variables
~~~~~~~~~~~~~~~~~~~~
@@ -634,9 +718,3 @@ if Python was configured with the ``--with-pydebug`` build option.
If set, Python will dump objects and reference counts still alive after
shutting down the interpreter.
-
-
-.. envvar:: PYTHONMALLOCSTATS
-
- If set, Python will print memory allocation statistics every time a new
- object arena is created, and on shutdown.
diff --git a/Doc/using/index.rst b/Doc/using/index.rst
index 502afa9..a5df713 100644
--- a/Doc/using/index.rst
+++ b/Doc/using/index.rst
@@ -17,4 +17,3 @@ interpreter and things that make working with Python easier.
unix.rst
windows.rst
mac.rst
- scripts.rst
diff --git a/Doc/using/mac.rst b/Doc/using/mac.rst
index 05c91bb..8f1ac3f 100644
--- a/Doc/using/mac.rst
+++ b/Doc/using/mac.rst
@@ -25,7 +25,7 @@ there.
What you get after installing is a number of things:
-* A :file:`MacPython 3.5` folder in your :file:`Applications` folder. In here
+* A :file:`MacPython 3.6` folder in your :file:`Applications` folder. In here
you find IDLE, the development environment that is a standard part of official
Python distributions; PythonLauncher, which handles double-clicking Python
scripts from the Finder; and the "Build Applet" tool, which allows you to
@@ -93,7 +93,7 @@ aware of: programs that talk to the Aqua window manager (in other words,
anything that has a GUI) need to be run in a special way. Use :program:`pythonw`
instead of :program:`python` to start such scripts.
-With Python 3.5, you can use either :program:`python` or :program:`pythonw`.
+With Python 3.6, you can use either :program:`python` or :program:`pythonw`.
Configuration
@@ -159,7 +159,7 @@ https://riverbankcomputing.com/software/pyqt/intro.
Distributing Python Applications on the Mac
===========================================
-The "Build Applet" tool that is placed in the MacPython 3.5 folder is fine for
+The "Build Applet" tool that is placed in the MacPython 3.6 folder is fine for
packaging small Python scripts on your own machine to run as a standard Mac
application. This tool, however, is not robust enough to distribute Python
applications to other users.
diff --git a/Doc/using/scripts.rst b/Doc/using/scripts.rst
deleted file mode 100644
index 2c87416..0000000
--- a/Doc/using/scripts.rst
+++ /dev/null
@@ -1,12 +0,0 @@
-.. _tools-and-scripts:
-
-Additional Tools and Scripts
-============================
-
-.. _scripts-pyvenv:
-
-pyvenv - Creating virtual environments
---------------------------------------
-
-.. include:: venv-create.inc
-
diff --git a/Doc/using/venv-create.inc b/Doc/using/venv-create.inc
index 7ad3008..53f431b 100644
--- a/Doc/using/venv-create.inc
+++ b/Doc/using/venv-create.inc
@@ -1,31 +1,39 @@
Creation of :ref:`virtual environments <venv-def>` is done by executing the
-``pyvenv`` script::
+command ``venv``::
- pyvenv /path/to/new/virtual/environment
+ python3 -m venv /path/to/new/virtual/environment
Running this command creates the target directory (creating any parent
directories that don't exist already) and places a ``pyvenv.cfg`` file in it
-with a ``home`` key pointing to the Python installation the command was run
-from. It also creates a ``bin`` (or ``Scripts`` on Windows) subdirectory
+with a ``home`` key pointing to the Python installation from which the command
+was run. It also creates a ``bin`` (or ``Scripts`` on Windows) subdirectory
containing a copy of the ``python`` binary (or binaries, in the case of
Windows). It also creates an (initially empty) ``lib/pythonX.Y/site-packages``
subdirectory (on Windows, this is ``Lib\site-packages``).
+.. deprecated:: 3.6
+ ``pyvenv`` was the recommended tool for creating virtual environments for
+ Python 3.3 and 3.4, and is `deprecated in Python 3.6
+ <https://docs.python.org/dev/whatsnew/3.6.html#deprecated-features>`_.
+
+.. versionchanged:: 3.5
+ The use of ``venv`` is now recommended for creating virtual environments.
+
.. seealso::
`Python Packaging User Guide: Creating and using virtual environments
- <https://packaging.python.org/en/latest/installing/#creating-virtual-environments>`__
+ <https://packaging.python.org/installing/#creating-virtual-environments>`__
.. highlight:: none
-On Windows, you may have to invoke the ``pyvenv`` script as follows, if you
-don't have the relevant PATH and PATHEXT settings::
+On Windows, invoke the ``venv`` command as follows::
- c:\Temp>c:\Python35\python c:\Python35\Tools\Scripts\pyvenv.py myenv
+ c:\>c:\Python35\python -m venv c:\path\to\myenv
-or equivalently::
+Alternatively, if you configured the ``PATH`` and ``PATHEXT`` variables for
+your :ref:`Python installation <using-on-windows>`::
- c:\Temp>c:\Python35\python -m venv myenv
+ c:\>python -m venv myenv c:\path\to\myenv
The command, if run with ``-h``, will show the available options::
@@ -36,25 +44,26 @@ The command, if run with ``-h``, will show the available options::
Creates virtual Python environments in one or more target directories.
positional arguments:
- ENV_DIR A directory to create the environment in.
+ ENV_DIR A directory to create the environment in.
optional arguments:
- -h, --help show this help message and exit
- --system-site-packages Give the virtual environment access to the system
- site-packages dir.
- --symlinks Try to use symlinks rather than copies, when symlinks
- are not the default for the platform.
- --copies Try to use copies rather than symlinks, even when
- symlinks are the default for the platform.
- --clear Delete the contents of the environment directory if it
- already exists, before environment creation.
- --upgrade Upgrade the environment directory to use this version
- of Python, assuming Python has been upgraded in-place.
- --without-pip Skips installing or upgrading pip in the virtual
- environment (pip is bootstrapped by default)
-
-Depending on how the ``venv`` functionality has been invoked, the usage message
-may vary slightly, e.g. referencing ``pyvenv`` rather than ``venv``.
+ -h, --help show this help message and exit
+ --system-site-packages
+ Give the virtual environment access to the system
+ site-packages dir.
+ --symlinks Try to use symlinks rather than copies, when symlinks
+ are not the default for the platform.
+ --copies Try to use copies rather than symlinks, even when
+ symlinks are the default for the platform.
+ --clear Delete the contents of the environment directory if it
+ already exists, before environment creation.
+ --upgrade Upgrade the environment directory to use this version
+ of Python, assuming Python has been upgraded in-place.
+ --without-pip Skips installing or upgrading pip in the virtual
+ environment (pip is bootstrapped by default)
+
+ Once an environment has been created, you may wish to activate it, e.g. by
+ sourcing an activate script in its bin directory.
.. versionchanged:: 3.4
Installs pip by default, added the ``--without-pip`` and ``--copies``
@@ -73,12 +82,13 @@ run with the ``--system-site-packages`` option, ``false`` otherwise.
Unless the ``--without-pip`` option is given, :mod:`ensurepip` will be
invoked to bootstrap ``pip`` into the virtual environment.
-Multiple paths can be given to ``pyvenv``, in which case an identical
-virtualenv will be created, according to the given options, at each
-provided path.
+Multiple paths can be given to ``venv``, in which case an identical virtual
+environment will be created, according to the given options, at each provided
+path.
-Once a venv has been created, it can be "activated" using a script in the
-venv's binary directory. The invocation of the script is platform-specific:
+Once a virtual environment has been created, it can be "activated" using a
+script in the virtual environment's binary directory. The invocation of the
+script is platform-specific:
+-------------+-----------------+-----------------------------------------+
| Platform | Shell | Command to activate virtual environment |
@@ -95,16 +105,17 @@ venv's binary directory. The invocation of the script is platform-specific:
+-------------+-----------------+-----------------------------------------+
You don't specifically *need* to activate an environment; activation just
-prepends the venv's binary directory to your path, so that "python" invokes the
-venv's Python interpreter and you can run installed scripts without having to
-use their full path. However, all scripts installed in a venv should be
-runnable without activating it, and run with the venv's Python automatically.
-
-You can deactivate a venv by typing "deactivate" in your shell. The exact
-mechanism is platform-specific: for example, the Bash activation script defines
-a "deactivate" function, whereas on Windows there are separate scripts called
-``deactivate.bat`` and ``Deactivate.ps1`` which are installed when the venv is
-created.
+prepends the virtual environment's binary directory to your path, so that
+"python" invokes the virtual environment's Python interpreter and you can run
+installed scripts without having to use their full path. However, all scripts
+installed in a virtual environment should be runnable without activating it,
+and run with the virtual environment's Python automatically.
+
+You can deactivate a virtual environment by typing "deactivate" in your shell.
+The exact mechanism is platform-specific: for example, the Bash activation
+script defines a "deactivate" function, whereas on Windows there are separate
+scripts called ``deactivate.bat`` and ``Deactivate.ps1`` which are installed
+when the virtual environment is created.
.. versionadded:: 3.4
``fish`` and ``csh`` activation scripts.
diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst
index a4a6a30..81efbb0 100644
--- a/Doc/using/windows.rst
+++ b/Doc/using/windows.rst
@@ -29,15 +29,15 @@ Supported Versions
As specified in :pep:`11`, a Python release only supports a Windows platform
while Microsoft considers the platform under extended support. This means that
-Python 3.5 supports Windows Vista and newer. If you require Windows XP support
-then please install Python 3.4.
+Python |version| supports Windows Vista and newer. If you require Windows XP
+support then please install Python 3.4.
Installation Steps
------------------
-Four Python 3.5 installers are available for download - two each for the 32-bit
-and 64-bit versions of the interpreter. The *web installer* is a small initial
-download, and it will automatically download the required components as
+Four Python |version| installers are available for download - two each for the
+32-bit and 64-bit versions of the interpreter. The *web installer* is a small
+initial download, and it will automatically download the required components as
necessary. The *offline installer* includes the components necessary for a
default installation and only requires an internet connection for optional
features. See :ref:`install-layout-option` for other ways to avoid downloading
@@ -74,6 +74,31 @@ installation". In this case:
* If selected, the install directory will be added to the system :envvar:`PATH`
* Shortcuts are available for all users
+.. _max-path:
+
+Removing the MAX_PATH Limitation
+--------------------------------
+
+Windows historically has limited path lengths to 260 characters. This meant that
+paths longer than this would not resolve and errors would result.
+
+In the latest versions of Windows, this limitation can be expanded to
+approximately 32,000 characters. Your administrator will need to activate the
+"Enable Win32 long paths" group policy, or set the registry value
+``HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled``
+to ``1``.
+
+This allows the :func:`open` function, the :mod:`os` module and most other
+path functionality to accept and return paths longer than 260 characters when
+using strings. (Use of bytes as paths is deprecated on Windows, and this feature
+is not available when using bytes.)
+
+After changing the above option, no further configuration is required.
+
+.. versionchanged:: 3.6
+
+ Support for long paths was enabled in Python.
+
.. _install-quiet-option:
Installing Without UI
@@ -168,13 +193,13 @@ of available options is shown below.
For example, to silently install a default, system-wide Python installation,
you could use the following command (from an elevated command prompt)::
- python-3.5.0.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
+ python-3.6.0.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
To allow users to easily install a personal copy of Python without the test
suite, you could provide a shortcut with the following command. This will
display a simplified initial page and disallow customization::
- python-3.5.0.exe InstallAllUsers=0 Include_launcher=0 Include_test=0
+ python-3.6.0.exe InstallAllUsers=0 Include_launcher=0 Include_test=0
SimpleInstall=1 SimpleInstallDescription="Just for me, no test suite."
(Note that omitting the launcher also omits file associations, and is only
@@ -209,13 +234,13 @@ where a large number of installations are going to be performed it is very
useful to have a locally cached copy.
Execute the following command from Command Prompt to download all possible
-required files. Remember to substitute ``python-3.5.0.exe`` for the actual
+required files. Remember to substitute ``python-3.6.0.exe`` for the actual
name of your installer, and to create layouts in their own directories to
avoid collisions between files with the same name.
::
- python-3.5.0.exe /layout [optional target directory]
+ python-3.6.0.exe /layout [optional target directory]
You may also specify the ``/quiet`` option to hide the progress display.
@@ -320,7 +345,7 @@ User level and the System level, or temporarily in a command prompt.
To temporarily set environment variables, open Command Prompt and use the
:command:`set` command::
- C:\>set PATH=C:\Program Files\Python 3.5;%PATH%
+ C:\>set PATH=C:\Program Files\Python 3.6;%PATH%
C:\>set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
C:\>python
@@ -376,10 +401,10 @@ Finding the Python executable
Besides using the automatically created start menu entry for the Python
interpreter, you might want to start Python in the command prompt. The
-installer for Python 3.5 and later has an option to set that up for you.
+installer has an option to set that up for you.
-On the first page of the installer, an option labelled "Add Python 3.5 to
-PATH" can be selected to have the installer add the install location into the
+On the first page of the installer, an option labelled "Add Python to PATH"
+may be selected to have the installer add the install location into the
:envvar:`PATH`. The location of the :file:`Scripts\\` folder is also added.
This allows you to type :command:`python` to run the interpreter, and
:command:`pip` for the package installer. Thus, you can also execute your
@@ -393,7 +418,7 @@ of your Python installation, delimited by a semicolon from other entries. An
example variable could look like this (assuming the first two entries already
existed)::
- C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Python 3.5
+ C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Python 3.6
.. _launcher:
@@ -418,6 +443,8 @@ Getting started
From the command-line
^^^^^^^^^^^^^^^^^^^^^
+.. versionchanged:: 3.6
+
System-wide installations of Python 3.3 and later will put the launcher on your
:envvar:`PATH`. The launcher is compatible with all available versions of
Python, so it does not matter which version is installed. To check that the
@@ -427,25 +454,26 @@ launcher is available, execute the following command in Command Prompt:
py
-You should find that the latest version of Python 2.x you have installed is
+You should find that the latest version of Python you have installed is
started - it can be exited as normal, and any additional command-line
arguments specified will be sent directly to Python.
-If you have multiple versions of Python 2.x installed (e.g., 2.6 and 2.7) you
-will have noticed that Python 2.7 was started - to launch Python 2.6, try the
-command:
+If you have multiple versions of Python installed (e.g., 2.7 and |version|) you
+will have noticed that Python |version| was started - to launch Python 2.7, try
+the command:
::
- py -2.6
+ py -2.7
-If you have a Python 3.x installed, try the command:
+If you want the latest version of Python 2.x you have installed, try the
+command:
::
- py -3
+ py -2
-You should find the latest version of Python 3.x starts.
+You should find the latest version of Python 2.x starts.
If you see the following error, you do not have the launcher installed:
@@ -500,6 +528,11 @@ version qualifier. Assuming you have Python 2.6 installed, try changing the
first line to ``#! python2.6`` and you should find the 2.6 version
information printed.
+Note that unlike interactive use, a bare "python" will use the latest
+version of Python 2.x that you have installed. This is for backward
+compatibility and for compatibility with Unix, where the command ``python``
+typically refers to Python 2.
+
From file associations
^^^^^^^^^^^^^^^^^^^^^^
@@ -676,7 +709,7 @@ target Python.
-.. finding_modules:
+.. _finding_modules:
Finding modules
===============
@@ -687,7 +720,24 @@ installation directory. So, if you had installed Python to
:file:`C:\\Python\\Lib\\` and third-party modules should be stored in
:file:`C:\\Python\\Lib\\site-packages\\`.
-This is how :data:`sys.path` is populated on Windows:
+To completely override :data:`sys.path`, create a ``._pth`` file with the same
+name as the DLL (``python36._pth``) or the executable (``python._pth``) and
+specify one line for each path to add to :data:`sys.path`. The file based on the
+DLL name overrides the one based on the executable, which allows paths to be
+restricted for any program loading the runtime if desired.
+
+When the file exists, all registry and environment variables are ignored,
+isolated mode is enabled, and :mod:`site` is not imported unless one line in the
+file specifies ``import site``. Blank paths and lines starting with ``#`` are
+ignored. Each path may be absolute or relative to the location of the file.
+Import statements other than to ``site`` are not permitted, and arbitrary code
+cannot be specified.
+
+Note that ``.pth`` files (without leading underscore) will be processed normally
+by the :mod:`site` module.
+
+When no ``._pth`` file is found, this is how :data:`sys.path` is populated on
+Windows:
* An empty entry is added at the start, which corresponds to the current
directory.
@@ -706,10 +756,11 @@ This is how :data:`sys.path` is populated on Windows:
* If the environment variable :envvar:`PYTHONHOME` is set, it is assumed as
"Python Home". Otherwise, the path of the main Python executable is used to
- locate a "landmark file" (``Lib\os.py``) to deduce the "Python Home". If a
- Python home is found, the relevant sub-directories added to :data:`sys.path`
- (``Lib``, ``plat-win``, etc) are based on that folder. Otherwise, the core
- Python path is constructed from the PythonPath stored in the registry.
+ locate a "landmark file" (either ``Lib\os.py`` or ``pythonXY.zip``) to deduce
+ the "Python Home". If a Python home is found, the relevant sub-directories
+ added to :data:`sys.path` (``Lib``, ``plat-win``, etc) are based on that
+ folder. Otherwise, the core Python path is constructed from the PythonPath
+ stored in the registry.
* If the Python Home cannot be located, no :envvar:`PYTHONPATH` is specified in
the environment, and no registry entries can be found, a default path with
@@ -722,10 +773,6 @@ directory one level above the executable, the following variations apply:
path is used instead of the path to the main executable when deducing the
home location.
-* If ``applocal`` is set to true, the ``home`` property or the main executable
- is always used as the home path, and all environment variables or registry
- values affecting the path are ignored. The landmark file is not checked.
-
The end result of all this is:
* When running :file:`python.exe`, or any other .exe in the main Python
@@ -744,13 +791,12 @@ The end result of all this is:
For those who want to bundle Python into their application or distribution, the
following advice will prevent conflicts with other installations:
-* Include a ``pyvenv.cfg`` file alongside your executable containing
- ``applocal = true``. This will ensure that your own directory will be used to
- resolve paths even if you have included the standard library in a ZIP file.
- It will also ignore user site-packages and other paths listed in the
- registry.
+* Include a ``._pth`` file alongside your executable containing the
+ directories to include. This will ignore paths listed in the registry and
+ environment variables, and also ignore :mod:`site` unless ``import site`` is
+ listed.
-* If you are loading :file:`python3.dll` or :file:`python35.dll` in your own
+* If you are loading :file:`python3.dll` or :file:`python36.dll` in your own
executable, explicitly call :c:func:`Py_SetPath` or (at least)
:c:func:`Py_SetProgramName` before :c:func:`Py_Initialize`.
@@ -760,7 +806,8 @@ following advice will prevent conflicts with other installations:
* If you cannot use the previous suggestions (for example, you are a
distribution that allows people to run :file:`python.exe` directly), ensure
that the landmark file (:file:`Lib\\os.py`) exists in your install directory.
- (Note that it will not be detected inside a ZIP file.)
+ (Note that it will not be detected inside a ZIP file, but a correctly named
+ ZIP file will be detected instead.)
These will ensure that the files in a system-wide installation will not take
precedence over the copy of the standard library bundled with your application.
@@ -768,6 +815,14 @@ Otherwise, your users may experience problems using your application. Note that
the first suggestion is the best, as the other may still be susceptible to
non-standard paths in the registry and user site-packages.
+.. versionchanged::
+ 3.6
+
+ * Adds ``._pth`` file support and removes ``applocal`` option from
+ ``pyvenv.cfg``.
+ * Adds ``pythonXX.zip`` as a potential landmark when directly adjacent
+ to the executable.
+
Additional modules
==================
@@ -867,7 +922,7 @@ directly accessed by end-users.
When extracted, the embedded distribution is (almost) fully isolated from the
user's system, including environment variables, system registry settings, and
installed packages. The standard library is included as pre-compiled and
-optimized ``.pyc`` files in a ZIP, and ``python3.dll``, ``python35.dll``,
+optimized ``.pyc`` files in a ZIP, and ``python3.dll``, ``python36.dll``,
``python.exe`` and ``pythonw.exe`` are all provided. Tcl/tk (including all
dependants, such as Idle), pip and the Python documentation are not included.
diff --git a/Doc/whatsnew/2.1.rst b/Doc/whatsnew/2.1.rst
index 06366b8..6aae726 100644
--- a/Doc/whatsnew/2.1.rst
+++ b/Doc/whatsnew/2.1.rst
@@ -367,7 +367,7 @@ dictionary::
This version works for simple things such as integers, but it has a side effect;
the ``_cache`` dictionary holds a reference to the return values, so they'll
-never be deallocated until the Python process exits and cleans up This isn't
+never be deallocated until the Python process exits and cleans up. This isn't
very noticeable for integers, but if :func:`f` returns an object, or a data
structure that takes up a lot of memory, this can be a problem.
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst
index 9acc734..b900e77 100644
--- a/Doc/whatsnew/3.2.rst
+++ b/Doc/whatsnew/3.2.rst
@@ -1253,9 +1253,9 @@ definition::
@contextmanager
def track_entry_and_exit(name):
- logging.info('Entering: {}'.format(name))
+ logging.info('Entering: %s', name)
yield
- logging.info('Exiting: {}'.format(name))
+ logging.info('Exiting: %s', name)
Formerly, this would have only been usable as a context manager::
diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst
index 0c9f2bb..93b297c 100644
--- a/Doc/whatsnew/3.3.rst
+++ b/Doc/whatsnew/3.3.rst
@@ -108,7 +108,7 @@ packages. Their concept and implementation are inspired by the popular
with the interpreter core.
This PEP adds the :mod:`venv` module for programmatic access, and the
-:ref:`pyvenv <scripts-pyvenv>` script for command-line access and
+``pyvenv`` script for command-line access and
administration. The Python interpreter checks for a ``pyvenv.cfg``,
file whose existence signals the base of a virtual environment's directory
tree.
diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst
index 1e5c9d1..72398f9 100644
--- a/Doc/whatsnew/3.4.rst
+++ b/Doc/whatsnew/3.4.rst
@@ -197,7 +197,7 @@ will also be installed. On other platforms, the system wide unversioned
``pip`` command typically refers to the separately installed Python 2
version.
-The :ref:`pyvenv <scripts-pyvenv>` command line utility and the :mod:`venv`
+The ``pyvenv`` command line utility and the :mod:`venv`
module make use of the :mod:`ensurepip` module to make ``pip`` readily
available in virtual environments. When using the command line utility,
``pip`` is installed by default, while when using the :mod:`venv` module
@@ -824,7 +824,7 @@ currently in the new module, which is being added as part of email's new
:term:`provisional API`. These classes provide a number of new methods that
make extracting content from and inserting content into email messages much
easier. For details, see the :mod:`~email.contentmanager` documentation and
-the :ref:`email-contentmanager-api-examples`. These API additions complete the
+the :ref:`email-examples`. These API additions complete the
bulk of the work that was planned as part of the email6 project. The currently
provisional API is scheduled to become final in Python 3.5 (possibly with a few
minor additions in the area of error handling). (Contributed by R. David
@@ -1989,11 +1989,11 @@ Other Improvements
Stinner using his :pep:`445`-based ``pyfailmalloc`` tool (:issue:`18408`,
:issue:`18520`).
-* The :ref:`pyvenv <scripts-pyvenv>` command now accepts a ``--copies`` option
+* The ``pyvenv`` command now accepts a ``--copies`` option
to use copies rather than symlinks even on systems where symlinks are the
default. (Contributed by Vinay Sajip in :issue:`18807`.)
-* The :ref:`pyvenv <scripts-pyvenv>` command also accepts a ``--without-pip``
+* The ``pyvenv`` command also accepts a ``--without-pip``
option to suppress the otherwise-automatic bootstrapping of pip into
the virtual environment. (Contributed by Nick Coghlan in :issue:`19552`
as part of the :pep:`453` implementation.)
@@ -2459,7 +2459,7 @@ Changes in the Python API
stream in :mod:`~io.TextIOWrapper` to use its *newline* argument
(:issue:`15204`).
-* If you use :ref:`pyvenv <scripts-pyvenv>` in a script and desire that pip
+* If you use ``pyvenv`` in a script and desire that pip
*not* be installed, you must add ``--without-pip`` to your command
invocation.
diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst
index 2ef4e91..246d9c5 100644
--- a/Doc/whatsnew/3.5.rst
+++ b/Doc/whatsnew/3.5.rst
@@ -46,7 +46,8 @@
This article explains the new features in Python 3.5, compared to 3.4.
Python 3.5 was released on September 13, 2015.  See the
-:ref:`changelog <changelog>` for a full list of changes.
+`changelog <https://docs.python.org/3.5/whatsnew/changelog.html>`_ for a full
+list of changes.
.. seealso::
@@ -2175,8 +2176,7 @@ New ``calloc`` functions were added:
* :c:func:`PyMem_RawCalloc`,
* :c:func:`PyMem_Calloc`,
-* :c:func:`PyObject_Calloc`,
-* :c:func:`_PyObject_GC_Calloc`.
+* :c:func:`PyObject_Calloc`.
(Contributed by Victor Stinner in :issue:`21233`.)
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
new file mode 100644
index 0000000..b7c8574
--- /dev/null
+++ b/Doc/whatsnew/3.6.rst
@@ -0,0 +1,1476 @@
+****************************
+ What's New In Python 3.6
+****************************
+
+:Release: |release|
+:Date: |today|
+
+.. Rules for maintenance:
+
+ * Anyone can add text to this document. Do not spend very much time
+ on the wording of your changes, because your text will probably
+ get rewritten to some degree.
+
+ * The maintainer will go through Misc/NEWS periodically and add
+ changes; it's therefore more important to add your changes to
+ Misc/NEWS than to this file.
+
+ * This is not a complete list of every single change; completeness
+ is the purpose of Misc/NEWS. Some changes I consider too small
+ or esoteric to include. If such a change is added to the text,
+ I'll just remove it. (This is another reason you shouldn't spend
+ too much time on writing your addition.)
+
+ * If you want to draw your new text to the attention of the
+ maintainer, add 'XXX' to the beginning of the paragraph or
+ section.
+
+ * It's OK to just add a fragmentary note about a change. For
+ example: "XXX Describe the transmogrify() function added to the
+ socket module." The maintainer will research the change and
+ write the necessary text.
+
+ * You can comment out your additions if you like, but it's not
+ necessary (especially when a final release is some months away).
+
+ * Credit the author of a patch or bugfix. Just the name is
+ sufficient; the e-mail address isn't necessary.
+
+ * It's helpful to add the bug/patch number as a comment:
+
+ XXX Describe the transmogrify() function added to the socket
+ module.
+ (Contributed by P.Y. Developer in :issue:`12345`.)
+
+ This saves the maintainer the effort of going through the Mercurial log
+ when researching a change.
+
+This article explains the new features in Python 3.6, compared to 3.5.
+
+For full details, see the :ref:`changelog <changelog>`.
+
+.. note::
+
+ Prerelease users should be aware that this document is currently in draft
+ form. It will be updated substantially as Python 3.6 moves towards release,
+ so it's worth checking back even after reading earlier versions.
+
+
+Summary -- Release highlights
+=============================
+
+.. This section singles out the most important changes in Python 3.6.
+ Brevity is key.
+
+New syntax features:
+
+* A ``global`` or ``nonlocal`` statement must now textually appear
+ before the first use of the affected name in the same scope.
+ Previously this was a SyntaxWarning.
+
+* PEP 498: :ref:`Formatted string literals <whatsnew-fstrings>`
+
+* PEP 515: Underscores in Numeric Literals
+
+* PEP 526: :ref:`Syntax for Variable Annotations <variable-annotations>`
+
+* PEP 525: Asynchronous Generators
+
+* PEP 530: Asynchronous Comprehensions
+
+Standard library improvements:
+
+Security improvements:
+
+* On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
+ is initialized to increase the security. See the :pep:`524` for the
+ rationale.
+
+* :mod:`hashlib` and :mod:`ssl` now support OpenSSL 1.1.0.
+
+* The default settings and feature set of the :mod:`ssl` have been improved.
+
+* The :mod:`hashlib` module has got support for BLAKE2, SHA-3 and SHAKE hash
+ algorithms and :func:`~hashlib.scrypt` key derivation function.
+
+Windows improvements:
+
+* PEP 529: :ref:`Change Windows filesystem encoding to UTF-8 <pep-529>`
+
+* PEP 528: :ref:`Change Windows console encoding to UTF-8 <pep-528>`
+
+* The ``py.exe`` launcher, when used interactively, no longer prefers
+ Python 2 over Python 3 when the user doesn't specify a version (via
+ command line arguments or a config file). Handling of shebang lines
+ remains unchanged - "python" refers to Python 2 in that case.
+
+* ``python.exe`` and ``pythonw.exe`` have been marked as long-path aware,
+ which means that when the 260 character path limit may no longer apply.
+ See :ref:`removing the MAX_PATH limitation <max-path>` for details.
+
+* A ``._pth`` file can be added to force isolated mode and fully specify
+ all search paths to avoid registry and environment lookup. See
+ :ref:`the documentation <finding_modules>` for more information.
+
+* A ``python36.zip`` file now works as a landmark to infer
+ :envvar:`PYTHONHOME`. See :ref:`the documentation <finding_modules>` for
+ more information.
+
+.. PEP-sized items next.
+
+.. _pep-4XX:
+
+.. PEP 4XX: Virtual Environments
+.. =============================
+
+
+.. (Implemented by Foo Bar.)
+
+.. .. seealso::
+
+ :pep:`4XX` - Python Virtual Environments
+ PEP written by Carl Meyer
+
+New built-in features:
+
+* PEP 520: :ref:`Preserving Class Attribute Definition Order<whatsnew-deforder>`
+
+* PEP 468: :ref:`Preserving Keyword Argument Order<whatsnew-kwargs>`
+
+A complete list of PEP's implemented in Python 3.6:
+
+* :pep:`468`, :ref:`Preserving Keyword Argument Order<whatsnew-kwargs>`
+* :pep:`487`, :ref:`Simpler customization of class creation<whatsnew-pep487>`
+* :pep:`495`, Local Time Disambiguation
+* :pep:`498`, :ref:`Formatted string literals <whatsnew-fstrings>`
+* :pep:`506`, Adding A Secrets Module To The Standard Library
+* :pep:`509`, :ref:`Add a private version to dict<whatsnew-pep509>`
+* :pep:`515`, :ref:`Underscores in Numeric Literals<pep-515>`
+* :pep:`519`, :ref:`Adding a file system path protocol<pep-519>`
+* :pep:`520`, :ref:`Preserving Class Attribute Definition Order<whatsnew-deforder>`
+* :pep:`523`, :ref:`Adding a frame evaluation API to CPython<pep-523>`
+* :pep:`524`, Make os.urandom() blocking on Linux (during system startup)
+* :pep:`525`, Asynchronous Generators (provisional)
+* :pep:`526`, :ref:`Syntax for Variable Annotations (provisional)<variable-annotations>`
+* :pep:`528`, :ref:`Change Windows console encoding to UTF-8 (provisional)<pep-528>`
+* :pep:`529`, :ref:`Change Windows filesystem encoding to UTF-8 (provisional)<pep-529>`
+* :pep:`530`, Asynchronous Comprehensions
+
+
+New Features
+============
+
+.. _pep-515:
+
+PEP 515: Underscores in Numeric Literals
+----------------------------------------
+
+Prior to PEP 515, there was no support for writing long numeric
+literals with some form of separator to improve readability. For
+instance, how big is ``1000000000000000``? With :pep:`515`, though,
+you can use underscores to separate digits as desired to make numeric
+literals easier to read: ``1_000_000_000_000_000``. Underscores can be
+used with other numeric literals beyond integers, e.g.
+``0x_FF_FF_FF_FF``.
+
+Single underscores are allowed between digits and after any base
+specifier. More than a single underscore in a row, leading, or
+trailing underscores are not allowed.
+
+.. seealso::
+
+ :pep:`515` -- Underscores in Numeric Literals
+ PEP written by Georg Brandl and Serhiy Storchaka.
+
+
+.. _pep-523:
+
+PEP 523: Adding a frame evaluation API to CPython
+-------------------------------------------------
+
+While Python provides extensive support to customize how code
+executes, one place it has not done so is in the evaluation of frame
+objects. If you wanted some way to intercept frame evaluation in
+Python there really wasn't any way without directly manipulating
+function pointers for defined functions.
+
+:pep:`523` changes this by providing an API to make frame
+evaluation pluggable at the C level. This will allow for tools such
+as debuggers and JITs to intercept frame evaluation before the
+execution of Python code begins. This enables the use of alternative
+evaluation implementations for Python code, tracking frame
+evaluation, etc.
+
+This API is not part of the limited C API and is marked as private to
+signal that usage of this API is expected to be limited and only
+applicable to very select, low-level use-cases. Semantics of the
+API will change with Python as necessary.
+
+.. seealso::
+
+ :pep:`523` -- Adding a frame evaluation API to CPython
+ PEP written by Brett Cannon and Dino Viehland.
+
+
+.. _pep-519:
+
+PEP 519: Adding a file system path protocol
+-------------------------------------------
+
+File system paths have historically been represented as :class:`str`
+or :class:`bytes` objects. This has led to people who write code which
+operate on file system paths to assume that such objects are only one
+of those two types (an :class:`int` representing a file descriptor
+does not count as that is not a file path). Unfortunately that
+assumption prevents alternative object representations of file system
+paths like :mod:`pathlib` from working with pre-existing code,
+including Python's standard library.
+
+To fix this situation, a new interface represented by
+:class:`os.PathLike` has been defined. By implementing the
+:meth:`~os.PathLike.__fspath__` method, an object signals that it
+represents a path. An object can then provide a low-level
+representation of a file system path as a :class:`str` or
+:class:`bytes` object. This means an object is considered
+:term:`path-like <path-like object>` if it implements
+:class:`os.PathLike` or is a :class:`str` or :class:`bytes` object
+which represents a file system path. Code can use :func:`os.fspath`,
+:func:`os.fsdecode`, or :func:`os.fsencode` to explicitly get a
+:class:`str` and/or :class:`bytes` representation of a path-like
+object.
+
+The built-in :func:`open` function has been updated to accept
+:class:`os.PathLike` objects as have all relevant functions in the
+:mod:`os` and :mod:`os.path` modules. :c:func:`PyUnicode_FSConverter`
+and :c:func:`PyUnicode_FSConverter` have been changed to accept
+path-like objects. The :class:`os.DirEntry` class
+and relevant classes in :mod:`pathlib` have also been updated to
+implement :class:`os.PathLike`.
+
+The hope in is that updating the fundamental functions for operating
+on file system paths will lead to third-party code to implicitly
+support all :term:`path-like objects <path-like object>` without any
+code changes or at least very minimal ones (e.g. calling
+:func:`os.fspath` at the beginning of code before operating on a
+path-like object).
+
+Here are some examples of how the new interface allows for
+:class:`pathlib.Path` to be used more easily and transparently with
+pre-existing code::
+
+ >>> import pathlib
+ >>> with open(pathlib.Path("README")) as f:
+ ... contents = f.read()
+ ...
+ >>> import os.path
+ >>> os.path.splitext(pathlib.Path("some_file.txt"))
+ ('some_file', '.txt')
+ >>> os.path.join("/a/b", pathlib.Path("c"))
+ '/a/b/c'
+ >>> import os
+ >>> os.fspath(pathlib.Path("some_file.txt"))
+ 'some_file.txt'
+
+(Implemented by Brett Cannon, Ethan Furman, Dusty Phillips, and Jelle Zijlstra.)
+
+.. seealso::
+
+ :pep:`519` -- Adding a file system path protocol
+ PEP written by Brett Cannon and Koos Zevenhoven.
+
+
+.. _whatsnew-fstrings:
+
+PEP 498: Formatted string literals
+----------------------------------
+
+Formatted string literals are a new kind of string literal, prefixed
+with ``'f'``. They are similar to the format strings accepted by
+:meth:`str.format`. They contain replacement fields surrounded by
+curly braces. The replacement fields are expressions, which are
+evaluated at run time, and then formatted using the :func:`format` protocol::
+
+ >>> name = "Fred"
+ >>> f"He said his name is {name}."
+ 'He said his name is Fred.'
+
+See :pep:`498` and the main documentation at :ref:`f-strings`.
+
+
+.. _variable-annotations:
+
+PEP 526: Syntax for variable annotations
+----------------------------------------
+
+:pep:`484` introduced standard for type annotations of function parameters,
+a.k.a. type hints. This PEP adds syntax to Python for annotating the
+types of variables including class variables and instance variables::
+
+ primes: List[int] = []
+
+ captain: str # Note: no initial value!
+
+ class Starship:
+ stats: Dict[str, int] = {}
+
+Just as for function annotations, the Python interpreter does not attach any
+particular meaning to variable annotations and only stores them in a special
+attribute ``__annotations__`` of a class or module.
+In contrast to variable declarations in statically typed languages,
+the goal of annotation syntax is to provide an easy way to specify structured
+type metadata for third party tools and libraries via the abstract syntax tree
+and the ``__annotations__`` attribute.
+
+.. seealso::
+
+ :pep:`526` -- Syntax for variable annotations.
+ PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
+ and Guido van Rossum. Implemented by Ivan Levkivskyi.
+
+ Tools that use or will use the new syntax:
+ `mypy <http://github.com/python/mypy>`_,
+ `pytype <http://github.com/google/pytype>`_, PyCharm, etc.
+
+
+.. _pep-529:
+
+PEP 529: Change Windows filesystem encoding to UTF-8
+----------------------------------------------------
+
+Representing filesystem paths is best performed with str (Unicode) rather than
+bytes. However, there are some situations where using bytes is sufficient and
+correct.
+
+Prior to Python 3.6, data loss could result when using bytes paths on Windows.
+With this change, using bytes to represent paths is now supported on Windows,
+provided those bytes are encoded with the encoding returned by
+:func:`sys.getfilesystemencoding()`, which now defaults to ``'utf-8'``.
+
+Applications that do not use str to represent paths should use
+:func:`os.fsencode()` and :func:`os.fsdecode()` to ensure their bytes are
+correctly encoded. To revert to the previous behaviour, set
+:envvar:`PYTHONLEGACYWINDOWSFSENCODING` or call
+:func:`sys._enablelegacywindowsfsencoding`.
+
+See :pep:`529` for more information and discussion of code modifications that
+may be required.
+
+.. note::
+
+ This change is considered experimental for 3.6.0 beta releases. The default
+ encoding may change before the final release.
+
+.. _whatsnew-pep487:
+
+PEP 487: Simpler customization of class creation
+------------------------------------------------
+
+Upon subclassing a class, the ``__init_subclass__`` classmethod (if defined) is
+called on the base class. This makes it straightforward to write classes that
+customize initialization of future subclasses without introducing the
+complexity of a full custom metaclass.
+
+The descriptor protocol has also been expanded to include a new optional method,
+``__set_name__``. Whenever a new class is defined, the new method will be called
+on all descriptors included in the definition, providing them with a reference
+to the class being defined and the name given to the descriptor within the
+class namespace.
+
+Also see :pep:`487` and the updated class customization documentation at
+:ref:`class-customization` and :ref:`descriptors`.
+
+(Contributed by Martin Teichmann in :issue:`27366`)
+
+.. _pep-528:
+
+PEP 528: Change Windows console encoding to UTF-8
+-------------------------------------------------
+
+The default console on Windows will now accept all Unicode characters and
+provide correctly read str objects to Python code. ``sys.stdin``,
+``sys.stdout`` and ``sys.stderr`` now default to utf-8 encoding.
+
+This change only applies when using an interactive console, and not when
+redirecting files or pipes. To revert to the previous behaviour for interactive
+console use, set :envvar:`PYTHONLEGACYWINDOWSIOENCODING`.
+
+.. seealso::
+
+ :pep:`528` -- Change Windows console encoding to UTF-8
+ PEP written and implemented by Steve Dower.
+
+PYTHONMALLOC environment variable
+---------------------------------
+
+The new :envvar:`PYTHONMALLOC` environment variable allows setting the Python
+memory allocators and/or install debug hooks.
+
+It is now possible to install debug hooks on Python memory allocators on Python
+compiled in release mode using ``PYTHONMALLOC=debug``. Effects of debug hooks:
+
+* Newly allocated memory is filled with the byte ``0xCB``
+* Freed memory is filled with the byte ``0xDB``
+* Detect violations of Python memory allocator API. For example,
+ :c:func:`PyObject_Free` called on a memory block allocated by
+ :c:func:`PyMem_Malloc`.
+* Detect write before the start of the buffer (buffer underflow)
+* Detect write after the end of the buffer (buffer overflow)
+* Check that the :term:`GIL <global interpreter lock>` is held when allocator
+ functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and
+ :c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called.
+
+Checking if the GIL is held is also a new feature of Python 3.6.
+
+See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python
+memory allocators.
+
+It is now also possible to force the usage of the :c:func:`malloc` allocator of
+the C library for all Python memory allocations using ``PYTHONMALLOC=malloc``.
+It helps to use external memory debuggers like Valgrind on a Python compiled in
+release mode.
+
+On error, the debug hooks on Python memory allocators now use the
+:mod:`tracemalloc` module to get the traceback where a memory block was
+allocated.
+
+Example of fatal error on buffer overflow using
+``python3.6 -X tracemalloc=5`` (store 5 frames in traces)::
+
+ Debug memory block at address p=0x7fbcd41666f8: API 'o'
+ 4 bytes originally requested
+ The 7 pad bytes at p-7 are FORBIDDENBYTE, as expected.
+ The 8 pad bytes at tail=0x7fbcd41666fc are not all FORBIDDENBYTE (0xfb):
+ at tail+0: 0x02 *** OUCH
+ at tail+1: 0xfb
+ at tail+2: 0xfb
+ at tail+3: 0xfb
+ at tail+4: 0xfb
+ at tail+5: 0xfb
+ at tail+6: 0xfb
+ at tail+7: 0xfb
+ The block was made by call #1233329 to debug malloc/realloc.
+ Data at p: 1a 2b 30 00
+
+ Memory block allocated at (most recent call first):
+ File "test/test_bytes.py", line 323
+ File "unittest/case.py", line 600
+ File "unittest/case.py", line 648
+ File "unittest/suite.py", line 122
+ File "unittest/suite.py", line 84
+
+ Fatal Python error: bad trailing pad byte
+
+ Current thread 0x00007fbcdbd32700 (most recent call first):
+ File "test/test_bytes.py", line 323 in test_hex
+ File "unittest/case.py", line 600 in run
+ File "unittest/case.py", line 648 in __call__
+ File "unittest/suite.py", line 122 in run
+ File "unittest/suite.py", line 84 in __call__
+ File "unittest/suite.py", line 122 in run
+ File "unittest/suite.py", line 84 in __call__
+ ...
+
+(Contributed by Victor Stinner in :issue:`26516` and :issue:`26564`.)
+
+
+DTrace and SystemTap probing support
+------------------------------------
+
+Python can now be built ``--with-dtrace`` which enables static markers
+for the following events in the interpreter:
+
+* function call/return
+
+* garbage collection started/finished
+
+* line of code executed.
+
+This can be used to instrument running interpreters in production,
+without the need to recompile specific debug builds or providing
+application-specific profiling/debugging code.
+
+More details in :ref:`instrumentation`.
+
+The current implementation is tested on Linux and macOS. Additional
+markers may be added in the future.
+
+(Contributed by Łukasz Langa in :issue:`21590`, based on patches by
+Jesús Cea Avión, David Malcolm, and Nikhil Benesch.)
+
+
+.. _whatsnew-deforder:
+
+PEP 520: Preserving Class Attribute Definition Order
+----------------------------------------------------
+
+Attributes in a class definition body have a natural ordering: the same
+order in which the names appear in the source. This order is now
+preserved in the new class's ``__dict__`` attribute.
+
+Also, the effective default class *execution* namespace (returned from
+``type.__prepare__()``) is now an insertion-order-preserving mapping.
+
+.. seealso::
+
+ :pep:`520` -- Preserving Class Attribute Definition Order
+ PEP written and implemented by Eric Snow.
+
+
+.. _whatsnew-kwargs:
+
+PEP 468: Preserving Keyword Argument Order
+------------------------------------------
+
+``**kwargs`` in a function signature is now guaranteed to be an
+insertion-order-preserving mapping.
+
+.. seealso::
+
+ :pep:`468` -- Preserving Keyword Argument Order
+ PEP written and implemented by Eric Snow.
+
+.. _whatsnew-pep509:
+
+PEP 509: Add a private version to dict
+--------------------------------------
+
+Add a new private version to the builtin ``dict`` type, incremented at
+each dictionary creation and at each dictionary change, to implement
+fast guards on namespaces.
+
+(Contributed by Victor Stinner in :issue:`26058`.)
+
+
+Other Language Changes
+======================
+
+Some smaller changes made to the core Python language are:
+
+* :func:`dict` now uses a "compact" representation `pioneered by PyPy
+ <https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html>`_.
+ The memory usage of the new :func:`dict` is between 20% and 25% smaller
+ compared to Python 3.5.
+ :pep:`468` (Preserving the order of ``**kwargs`` in a function.) is
+ implemented by this. The order-preserving aspect of this new
+ implementation is considered an implementation detail and should
+ not be relied upon (this may change in the future, but it is desired
+ to have this new dict implementation in the language for a few
+ releases before changing the language spec to mandate
+ order-preserving semantics for all current and future Python
+ implementations; this also helps preserve backwards-compatibility
+ with older versions of the language where random iteration order is
+ still in effect, e.g. Python 3.5).
+ (Contributed by INADA Naoki in :issue:`27350`. Idea
+ `originally suggested by Raymond Hettinger
+ <https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_.)
+
+* Long sequences of repeated traceback lines are now abbreviated as
+ ``"[Previous line repeated {count} more times]"`` (see
+ :ref:`py36-traceback` for an example).
+ (Contributed by Emanuel Barry in :issue:`26823`.)
+
+* Import now raises the new exception :exc:`ModuleNotFoundError`
+ (subclass of :exc:`ImportError`) when it cannot find a module. Code
+ that current checks for ImportError (in try-except) will still work.
+
+
+New Modules
+===========
+
+* None yet.
+
+
+Improved Modules
+================
+
+On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
+is initialized to increase the security. See the :pep:`524` for the rationale.
+
+
+asyncio
+-------
+
+Since the :mod:`asyncio` module is :term:`provisional <provisional api>`,
+all changes introduced in Python 3.6 have also been backported to Python
+3.5.x.
+
+Notable changes in the :mod:`asyncio` module since Python 3.5.0:
+
+* The :func:`~asyncio.ensure_future` function and all functions that
+ use it, such as :meth:`loop.run_until_complete() <asyncio.BaseEventLoop.run_until_complete>`,
+ now accept all kinds of :term:`awaitable objects <awaitable>`.
+ (Contributed by Yury Selivanov.)
+
+* New :func:`~asyncio.run_coroutine_threadsafe` function to submit
+ coroutines to event loops from other threads.
+ (Contributed by Vincent Michel.)
+
+* New :meth:`Transport.is_closing() <asyncio.BaseTransport.is_closing>`
+ method to check if the transport is closing or closed.
+ (Contributed by Yury Selivanov.)
+
+* The :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>`
+ method can now accept a list of hosts.
+ (Contributed by Yann Sionneau.)
+
+* New :meth:`loop.create_future() <asyncio.BaseEventLoop.create_future>`
+ method to create Future objects. This allows alternative event
+ loop implementations, such as
+ `uvloop <https://github.com/MagicStack/uvloop>`_, to provide a faster
+ :class:`asyncio.Future` implementation.
+ (Contributed by Yury Selivanov.)
+
+* New :meth:`loop.get_exception_handler() <asyncio.BaseEventLoop.get_exception_handler>`
+ method to get the current exception handler.
+ (Contributed by Yury Selivanov.)
+
+* New :meth:`StreamReader.readuntil() <asyncio.StreamReader.readuntil>`
+ method to read data from the stream until a separator bytes
+ sequence appears.
+ (Contributed by Mark Korenberg.)
+
+* The :meth:`loop.getaddrinfo() <asyncio.BaseEventLoop.getaddrinfo>`
+ method is optimized to avoid calling the system ``getaddrinfo``
+ function if the address is already resolved.
+ (Contributed by A. Jesse Jiryu Davis.)
+
+
+contextlib
+----------
+
+The :class:`contextlib.AbstractContextManager` class has been added to
+provide an abstract base class for context managers. It provides a
+sensible default implementation for `__enter__()` which returns
+``self`` and leaves `__exit__()` an abstract method. A matching
+class has been added to the :mod:`typing` module as
+:class:`typing.ContextManager`.
+(Contributed by Brett Cannon in :issue:`25609`.)
+
+
+venv
+----
+
+:mod:`venv` accepts a new parameter ``--prompt``. This parameter provides an
+alternative prefix for the virtual environment. (Proposed by Łukasz.Balcerzak
+and ported to 3.6 by Stéphane Wirtel in :issue:`22829`.)
+
+
+datetime
+--------
+
+The :meth:`datetime.strftime() <datetime.datetime.strftime>` and
+:meth:`date.strftime() <datetime.date.strftime>` methods now support ISO 8601 date
+directives ``%G``, ``%u`` and ``%V``.
+(Contributed by Ashley Anderson in :issue:`12006`.)
+
+
+distutils.command.sdist
+-----------------------
+
+The ``default_format`` attribute has been removed from
+:class:`distutils.command.sdist.sdist` and the ``formats``
+attribute defaults to ``['gztar']``. Although not anticipated,
+Any code relying on the presence of ``default_format`` may
+need to be adapted. See :issue:`27819` for more details.
+
+
+email
+-----
+
+The new email API, enabled via the *policy* keyword to various constructors, is
+no longer provisional. The :mod:`email` documentation has been reorganized and
+rewritten to focus on the new API, while retaining the old documentation for
+the legacy API. (Contributed by R. David Murray in :issue:`24277`.)
+
+The :mod:`email.mime` classes now all accept an optional *policy* keyword.
+(Contributed by Berker Peksag in :issue:`27331`.)
+
+The :class:`~email.generator.DecodedGenerator` now supports the *policy*
+keyword.
+
+There is a new :mod:`~email.policy` attribute,
+:attr:`~email.policy.Policy.message_factory`, that controls what class is used
+by default when the parser creates new message objects. For the
+:attr:`email.policy.compat32` policy this is :class:`~email.message.Message`,
+for the new policies it is :class:`~email.message.EmailMessage`.
+(Contributed by R. David Murray in :issue:`20476`.)
+
+
+encodings
+---------
+
+On Windows, added the ``'oem'`` encoding to use ``CP_OEMCP`` and the ``'ansi'``
+alias for the existing ``'mbcs'`` encoding, which uses the ``CP_ACP`` code page.
+
+
+faulthandler
+------------
+
+On Windows, the :mod:`faulthandler` module now installs a handler for Windows
+exceptions: see :func:`faulthandler.enable`. (Contributed by Victor Stinner in
+:issue:`23848`.)
+
+
+hashlib
+-------
+
+:mod:`hashlib` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
+It has been tested with 0.9.8zc, 0.9.8zh and 1.0.1t as well as LibreSSL 2.3
+and 2.4.
+(Contributed by Christian Heimes in :issue:`26470`.)
+
+BLAKE2 hash functions were added to the module. :func:`~hashlib.blake2b`
+and :func:`~hashlib.blake2s` are always available and support the full
+feature set of BLAKE2.
+(Contributed by Christian Heimes in :issue:`26798` based on code by
+Dmitry Chestnykh and Samuel Neves. Documentation written by Dmitry Chestnykh.)
+
+The SHA-3 hash functions :func:`~hashlib.sha3_224`, :func:`~hashlib.sha3_256`,
+:func:`~hashlib.sha3_384`, :func:`~hashlib.sha3_512`, and SHAKE hash functions
+:func:`~hashlib.shake_128` and :func:`~hashlib.shake_256` were added.
+(Contributed by Christian Heimes in :issue:`16113`. Keccak Code Package
+by Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche, and
+Ronny Van Keer.)
+
+The password-based key derivation function :func:`~hashlib.scrypt` is now
+available with OpenSSL 1.1.0 and newer.
+(Contributed by Christian Heimes in :issue:`27928`.)
+
+http.client
+-----------
+
+:meth:`HTTPConnection.request() <http.client.HTTPConnection.request>` and
+:meth:`~http.client.HTTPConnection.endheaders` both now support
+chunked encoding request bodies.
+(Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.)
+
+
+idlelib and IDLE
+----------------
+
+The idlelib package is being modernized and refactored to make IDLE look and work better and to make the code easier to understand, test, and improve. Part of making IDLE look better, especially on Linux and Mac, is using ttk widgets, mostly in the dialogs. As a result, IDLE no longer runs with tcl/tk 8.4. It now requires tcl/tk 8.5 or 8.6. We recommend running the latest release of either.
+
+'Modernizing' includes renaming and consolidation of idlelib modules. The renaming of files with partial uppercase names is similar to the renaming of, for instance, Tkinter and TkFont to tkinter and tkinter.font in 3.0. As a result, imports of idlelib files that worked in 3.5 will usually not work in 3.6. At least a module name change will be needed (see idlelib/README.txt), sometimes more. (Name changes contributed by Al Swiegart and Terry Reedy in :issue:`24225`. Most idlelib patches since have been and will be part of the process.)
+
+In compensation, the eventual result with be that some idlelib classes will be easier to use, with better APIs and docstrings explaining them. Additional useful information will be added to idlelib when available.
+
+
+importlib
+---------
+
+:class:`importlib.util.LazyLoader` now calls
+:meth:`~importlib.abc.Loader.create_module` on the wrapped loader, removing the
+restriction that :class:`importlib.machinery.BuiltinImporter` and
+:class:`importlib.machinery.ExtensionFileLoader` couldn't be used with
+:class:`importlib.util.LazyLoader`.
+
+:func:`importlib.util.cache_from_source`,
+:func:`importlib.util.source_from_cache`, and
+:func:`importlib.util.spec_from_file_location` now accept a
+:term:`path-like object`.
+
+
+json
+----
+
+:func:`json.load` and :func:`json.loads` now support binary input. Encoded
+JSON should be represented using either UTF-8, UTF-16, or UTF-32.
+(Contributed by Serhiy Storchaka in :issue:`17909`.)
+
+
+os
+--
+
+A new :meth:`~os.scandir.close` method allows explicitly closing a
+:func:`~os.scandir` iterator. The :func:`~os.scandir` iterator now
+supports the :term:`context manager` protocol. If a :func:`scandir`
+iterator is neither exhausted nor explicitly closed a :exc:`ResourceWarning`
+will be emitted in its destructor.
+(Contributed by Serhiy Storchaka in :issue:`25994`.)
+
+The Linux ``getrandom()`` syscall (get random bytes) is now exposed as the new
+:func:`os.getrandom` function.
+(Contributed by Victor Stinner, part of the :pep:`524`)
+
+See the summary for :ref:`PEP 519 <pep-519>` for details on how the
+:mod:`os` and :mod:`os.path` modules now support
+:term:`path-like objects <path-like object>`.
+
+
+pickle
+------
+
+Objects that need calling ``__new__`` with keyword arguments can now be pickled
+using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4.
+Protocol version 4 already supports this case. (Contributed by Serhiy
+Storchaka in :issue:`24164`.)
+
+
+re
+--
+
+Added support of modifier spans in regular expressions. Examples:
+``'(?i:p)ython'`` matches ``'python'`` and ``'Python'``, but not ``'PYTHON'``;
+``'(?i)g(?-i:v)r'`` matches ``'GvR'`` and ``'gvr'``, but not ``'GVR'``.
+(Contributed by Serhiy Storchaka in :issue:`433028`.)
+
+Match object groups can be accessed by ``__getitem__``, which is
+equivalent to ``group()``. So ``mo['name']`` is now equivalent to
+``mo.group('name')``. (Contributed by Eric Smith in :issue:`24454`.)
+
+
+readline
+--------
+
+Added :func:`~readline.set_auto_history` to enable or disable
+automatic addition of input to the history list. (Contributed by
+Tyler Crompton in :issue:`26870`.)
+
+
+rlcompleter
+-----------
+
+Private and special attribute names now are omitted unless the prefix starts
+with underscores. A space or a colon is added after some completed keywords.
+(Contributed by Serhiy Storchaka in :issue:`25011` and :issue:`25209`.)
+
+Names of most attributes listed by :func:`dir` are now completed.
+Previously, names of properties and slots which were not yet created on
+an instance were excluded. (Contributed by Martin Panter in :issue:`25590`.)
+
+
+site
+----
+
+When specifying paths to add to :attr:`sys.path` in a `.pth` file,
+you may now specify file paths on top of directories (e.g. zip files).
+(Contributed by Wolfgang Langner in :issue:`26587`).
+
+
+sqlite3
+-------
+
+:attr:`sqlite3.Cursor.lastrowid` now supports the ``REPLACE`` statement.
+(Contributed by Alex LordThorsen in :issue:`16864`.)
+
+
+socket
+------
+
+The :func:`~socket.socket.ioctl` function now supports the :data:`~socket.SIO_LOOPBACK_FAST_PATH`
+control code.
+(Contributed by Daniel Stokes in :issue:`26536`.)
+
+The :meth:`~socket.socket.getsockopt` constants ``SO_DOMAIN``,
+``SO_PROTOCOL``, ``SO_PEERSEC``, and ``SO_PASSSEC`` are now supported.
+(Contributed by Christian Heimes in :issue:`26907`.)
+
+The socket module now supports the address family
+:data:`~socket.AF_ALG` to interface with Linux Kernel crypto API. ``ALG_*``,
+``SOL_ALG`` and :meth:`~socket.socket.sendmsg_afalg` were added.
+(Contributed by Christian Heimes in :issue:`27744` with support from
+Victor Stinner.)
+
+socketserver
+------------
+
+Servers based on the :mod:`socketserver` module, including those
+defined in :mod:`http.server`, :mod:`xmlrpc.server` and
+:mod:`wsgiref.simple_server`, now support the :term:`context manager`
+protocol.
+(Contributed by Aviv Palivoda in :issue:`26404`.)
+
+The :attr:`~socketserver.StreamRequestHandler.wfile` attribute of
+:class:`~socketserver.StreamRequestHandler` classes now implements
+the :class:`io.BufferedIOBase` writable interface. In particular,
+calling :meth:`~io.BufferedIOBase.write` is now guaranteed to send the
+data in full. (Contributed by Martin Panter in :issue:`26721`.)
+
+ssl
+---
+
+:mod:`ssl` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
+It has been tested with 0.9.8zc, 0.9.8zh and 1.0.1t as well as LibreSSL 2.3
+and 2.4.
+(Contributed by Christian Heimes in :issue:`26470`.)
+
+3DES has been removed from the default cipher suites and ChaCha20 Poly1305
+cipher suites are now in the right position.
+(Contributed by Christian Heimes in :issue:`27850` and :issue:`27766`.)
+
+:class:`~ssl.SSLContext` has better default configuration for options
+and ciphers.
+(Contributed by Christian Heimes in :issue:`28043`.)
+
+SSL session can be copied from one client-side connection to another
+with :class:`~ssl.SSLSession`. TLS session resumption can speed up
+the initial handshake, reduce latency and improve performance
+(Contributed by Christian Heimes in :issue:`19500` based on a draft by
+Alex Warhawk.)
+
+All constants and flags have been converted to :class:`~enum.IntEnum` and
+:class:`~enum.IntFlags`.
+(Contributed by Christian Heimes in :issue:`28025`.)
+
+Server and client-side specific TLS protocols for :class:`~ssl.SSLContext`
+were added.
+(Contributed by Christian Heimes in :issue:`28085`.)
+
+General resource ids (``GEN_RID``) in subject alternative name extensions
+no longer case a SystemError.
+(Contributed by Christian Heimes in :issue:`27691`.)
+
+subprocess
+----------
+
+:class:`subprocess.Popen` destructor now emits a :exc:`ResourceWarning` warning
+if the child process is still running. Use the context manager protocol (``with
+proc: ...``) or call explicitly the :meth:`~subprocess.Popen.wait` method to
+read the exit status of the child process (Contributed by Victor Stinner in
+:issue:`26741`).
+
+The :class:`subprocess.Popen` constructor and all functions that pass arguments
+through to it now accept *encoding* and *errors* arguments. Specifying either
+of these will enable text mode for the *stdin*, *stdout* and *stderr* streams.
+
+telnetlib
+---------
+
+:class:`~telnetlib.Telnet` is now a context manager (contributed by
+Stéphane Wirtel in :issue:`25485`).
+
+
+tkinter
+-------
+
+Added methods :meth:`~tkinter.Variable.trace_add`,
+:meth:`~tkinter.Variable.trace_remove` and :meth:`~tkinter.Variable.trace_info`
+in the :class:`tkinter.Variable` class. They replace old methods
+:meth:`~tkinter.Variable.trace_variable`, :meth:`~tkinter.Variable.trace`,
+:meth:`~tkinter.Variable.trace_vdelete` and
+:meth:`~tkinter.Variable.trace_vinfo` that use obsolete Tcl commands and might
+not work in future versions of Tcl.
+(Contributed by Serhiy Storchaka in :issue:`22115`).
+
+
+.. _py36-traceback:
+
+traceback
+---------
+
+Both the traceback module and the interpreter's builtin exception display now
+abbreviate long sequences of repeated lines in tracebacks as shown in the
+following example::
+
+ >>> def f(): f()
+ ...
+ >>> f()
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "<stdin>", line 1, in f
+ File "<stdin>", line 1, in f
+ File "<stdin>", line 1, in f
+ [Previous line repeated 995 more times]
+ RecursionError: maximum recursion depth exceeded
+
+(Contributed by Emanuel Barry in :issue:`26823`.)
+
+
+typing
+------
+
+The :class:`typing.ContextManager` class has been added for
+representing :class:`contextlib.AbstractContextManager`.
+(Contributed by Brett Cannon in :issue:`25609`.)
+
+
+unicodedata
+-----------
+
+The internal database has been upgraded to use Unicode 9.0.0. (Contributed by
+Benjamin Peterson.)
+
+
+unittest.mock
+-------------
+
+The :class:`~unittest.mock.Mock` class has the following improvements:
+
+* Two new methods, :meth:`Mock.assert_called()
+ <unittest.mock.Mock.assert_called>` and :meth:`Mock.assert_called_once()
+ <unittest.mock.Mock.assert_called_once>` to check if the mock object
+ was called.
+ (Contributed by Amit Saha in :issue:`26323`.)
+
+
+urllib.request
+--------------
+
+If a HTTP request has a file or iterable body (other than a
+bytes object) but no Content-Length header, rather than
+throwing an error, :class:`~urllib.request.AbstractHTTPHandler` now
+falls back to use chunked transfer encoding.
+(Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.)
+
+
+urllib.robotparser
+------------------
+
+:class:`~urllib.robotparser.RobotFileParser` now supports the ``Crawl-delay`` and
+``Request-rate`` extensions.
+(Contributed by Nikolay Bogoychev in :issue:`16099`.)
+
+
+warnings
+--------
+
+A new optional *source* parameter has been added to the
+:func:`warnings.warn_explicit` function: the destroyed object which emitted a
+:exc:`ResourceWarning`. A *source* attribute has also been added to
+:class:`warnings.WarningMessage` (contributed by Victor Stinner in
+:issue:`26568` and :issue:`26567`).
+
+When a :exc:`ResourceWarning` warning is logged, the :mod:`tracemalloc` is now
+used to try to retrieve the traceback where the detroyed object was allocated.
+
+Example with the script ``example.py``::
+
+ import warnings
+
+ def func():
+ return open(__file__)
+
+ f = func()
+ f = None
+
+Output of the command ``python3.6 -Wd -X tracemalloc=5 example.py``::
+
+ example.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8'>
+ f = None
+ Object allocated at (most recent call first):
+ File "example.py", lineno 4
+ return open(__file__)
+ File "example.py", lineno 6
+ f = func()
+
+The "Object allocated at" traceback is new and only displayed if
+:mod:`tracemalloc` is tracing Python memory allocations and if the
+:mod:`warnings` was already imported.
+
+
+winreg
+------
+
+Added the 64-bit integer type :data:`REG_QWORD <winreg.REG_QWORD>`.
+(Contributed by Clement Rouault in :issue:`23026`.)
+
+
+winsound
+--------
+
+Allowed keyword arguments to be passed to :func:`Beep <winsound.Beep>`,
+:func:`MessageBeep <winsound.MessageBeep>`, and :func:`PlaySound
+<winsound.PlaySound>` (:issue:`27982`).
+
+
+xmlrpc.client
+-------------
+
+The module now supports unmarshalling additional data types used by
+Apache XML-RPC implementation for numerics and ``None``.
+(Contributed by Serhiy Storchaka in :issue:`26885`.)
+
+
+zipfile
+-------
+
+A new :meth:`ZipInfo.from_file() <zipfile.ZipInfo.from_file>` class method
+allows making a :class:`~zipfile.ZipInfo` instance from a filesystem file.
+A new :meth:`ZipInfo.is_dir() <zipfile.ZipInfo.is_dir>` method can be used
+to check if the :class:`~zipfile.ZipInfo` instance represents a directory.
+(Contributed by Thomas Kluyver in :issue:`26039`.)
+
+The :meth:`ZipFile.open() <zipfile.ZipFile.open>` method can now be used to
+write data into a ZIP file, as well as for extracting data.
+(Contributed by Thomas Kluyver in :issue:`26039`.)
+
+
+zlib
+----
+
+The :func:`~zlib.compress` function now accepts keyword arguments.
+(Contributed by Aviv Palivoda in :issue:`26243`.)
+
+
+fileinput
+---------
+
+:func:`~fileinput.hook_encoded` now supports the *errors* argument.
+(Contributed by Joseph Hackman in :issue:`25788`.)
+
+
+Optimizations
+=============
+
+* The ASCII decoder is now up to 60 times as fast for error handlers
+ ``surrogateescape``, ``ignore`` and ``replace`` (Contributed
+ by Victor Stinner in :issue:`24870`).
+
+* The ASCII and the Latin1 encoders are now up to 3 times as fast for the
+ error handler ``surrogateescape`` (Contributed by Victor Stinner in :issue:`25227`).
+
+* The UTF-8 encoder is now up to 75 times as fast for error handlers
+ ``ignore``, ``replace``, ``surrogateescape``, ``surrogatepass`` (Contributed
+ by Victor Stinner in :issue:`25267`).
+
+* The UTF-8 decoder is now up to 15 times as fast for error handlers
+ ``ignore``, ``replace`` and ``surrogateescape`` (Contributed
+ by Victor Stinner in :issue:`25301`).
+
+* ``bytes % args`` is now up to 2 times faster. (Contributed by Victor Stinner
+ in :issue:`25349`).
+
+* ``bytearray % args`` is now between 2.5 and 5 times faster. (Contributed by
+ Victor Stinner in :issue:`25399`).
+
+* Optimize :meth:`bytes.fromhex` and :meth:`bytearray.fromhex`: they are now
+ between 2x and 3.5x faster. (Contributed by Victor Stinner in :issue:`25401`).
+
+* Optimize ``bytes.replace(b'', b'.')`` and ``bytearray.replace(b'', b'.')``:
+ up to 80% faster. (Contributed by Josh Snider in :issue:`26574`).
+
+* Allocator functions of the :c:func:`PyMem_Malloc` domain
+ (:c:data:`PYMEM_DOMAIN_MEM`) now use the :ref:`pymalloc memory allocator
+ <pymalloc>` instead of :c:func:`malloc` function of the C library. The
+ pymalloc allocator is optimized for objects smaller or equal to 512 bytes
+ with a short lifetime, and use :c:func:`malloc` for larger memory blocks.
+ (Contributed by Victor Stinner in :issue:`26249`).
+
+* :func:`pickle.load` and :func:`pickle.loads` are now up to 10% faster when
+ deserializing many small objects (Contributed by Victor Stinner in
+ :issue:`27056`).
+
+- Passing :term:`keyword arguments <keyword argument>` to a function has an
+ overhead in comparison with passing :term:`positional arguments
+ <positional argument>`. Now in extension functions implemented with using
+ Argument Clinic this overhead is significantly decreased.
+ (Contributed by Serhiy Storchaka in :issue:`27574`).
+
+* Optimized :func:`~glob.glob` and :func:`~glob.iglob` functions in the
+ :mod:`glob` module; they are now about 3--6 times faster.
+ (Contributed by Serhiy Storchaka in :issue:`25596`).
+
+* Optimized globbing in :mod:`pathlib` by using :func:`os.scandir`;
+ it is now about 1.5--4 times faster.
+ (Contributed by Serhiy Storchaka in :issue:`26032`).
+
+Build and C API Changes
+=======================
+
+* Python now requires some C99 support in the toolchain to build. For more
+ information, see :pep:`7`.
+
+* Cross-compiling CPython with the Android NDK and the Android API level set to
+ 21 (Android 5.0 Lollilop) or greater, runs successfully. While Android is not
+ yet a supported platform, the Python test suite runs on the Android emulator
+ with only about 16 tests failures. See the Android meta-issue :issue:`26865`.
+
+* The ``--with-optimizations`` configure flag has been added. Turning it on
+ will activate LTO and PGO build support (when available).
+ (Original patch by Alecsandru Patrascu of Intel in :issue:`26539`.)
+
+* New :c:func:`Py_FinalizeEx` API which indicates if flushing buffered data
+ failed (:issue:`5319`).
+
+* :c:func:`PyArg_ParseTupleAndKeywords` now supports :ref:`positional-only
+ parameters <positional-only_parameter>`. Positional-only parameters are
+ defined by empty names.
+ (Contributed by Serhiy Storchaka in :issue:`26282`).
+
+* ``PyTraceback_Print`` method now abbreviates long sequences of repeated lines
+ as ``"[Previous line repeated {count} more times]"``.
+ (Contributed by Emanuel Barry in :issue:`26823`.)
+
+
+Deprecated
+==========
+
+Deprecated Build Options
+------------------------
+
+The ``--with-system-ffi`` configure flag is now on by default on non-OSX UNIX
+platforms. It may be disabled by using ``--without-system-ffi``, but using the
+flag is deprecated and will not be accepted in Python 3.7. OSX is unaffected
+by this change. Note that many OS distributors already use the
+``--with-system-ffi`` flag when building their system Python.
+
+
+New Keywords
+------------
+
+``async`` and ``await`` are not recommended to be used as variable, class,
+function or module names. Introduced by :pep:`492` in Python 3.5, they will
+become proper keywords in Python 3.7.
+
+
+Deprecated Python modules, functions and methods
+------------------------------------------------
+
+* :meth:`importlib.machinery.SourceFileLoader.load_module` and
+ :meth:`importlib.machinery.SourcelessFileLoader.load_module` are now
+ deprecated. They were the only remaining implementations of
+ :meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not
+ been deprecated in previous versions of Python in favour of
+ :meth:`importlib.abc.Loader.exec_module`.
+
+* The :mod:`tkinter.tix` module is now deprecated. :mod:`tkinter` users should
+ use :mod:`tkinter.ttk` instead.
+
+
+Deprecated functions and types of the C API
+-------------------------------------------
+
+* None yet.
+
+
+Deprecated features
+-------------------
+
+* The ``pyvenv`` script has been deprecated in favour of ``python3 -m venv``.
+ This prevents confusion as to what Python interpreter ``pyvenv`` is
+ connected to and thus what Python interpreter will be used by the virtual
+ environment. (Contributed by Brett Cannon in :issue:`25154`.)
+
+* When performing a relative import, falling back on ``__name__`` and
+ ``__path__`` from the calling module when ``__spec__`` or
+ ``__package__`` are not defined now raises an :exc:`ImportWarning`.
+ (Contributed by Rose Ames in :issue:`25791`.)
+
+* Unlike to other :mod:`dbm` implementations, the :mod:`dbm.dumb` module
+ creates database in ``'r'`` and ``'w'`` modes if it doesn't exist and
+ allows modifying database in ``'r'`` mode. This behavior is now deprecated
+ and will be removed in 3.8.
+ (Contributed by Serhiy Storchaka in :issue:`21708`.)
+
+* Undocumented support of general :term:`bytes-like objects <bytes-like object>`
+ as paths in :mod:`os` functions, :func:`compile` and similar functions is
+ now deprecated.
+ (Contributed by Serhiy Storchaka in :issue:`25791` and :issue:`26754`.)
+
+* The undocumented ``extra_path`` argument to a distutils Distribution
+ is now considered
+ deprecated, will raise a warning during install if set. Support for this
+ parameter will be dropped in a future Python release and likely earlier
+ through third party tools. See :issue:`27919` for details.
+
+* A backslash-character pair that is not a valid escape sequence now generates
+ a DeprecationWarning. Although this will eventually become a SyntaxError,
+ that will not be for several Python releases. (Contributed by Emanuel Barry
+ in :issue:`27364`.)
+
+* Inline flags ``(?letters)`` now should be used only at the start of the
+ regular expression. Inline flags in the middle of the regular expression
+ affects global flags in Python :mod:`re` module. This is an exception to
+ other regular expression engines that either apply flags to only part of
+ the regular expression or treat them as an error. To avoid distinguishing
+ inline flags in the middle of the regular expression now emit a deprecation
+ warning. It will be an error in future Python releases.
+ (Contributed by Serhiy Storchaka in :issue:`22493`.)
+
+* SSL-related arguments like ``certfile``, ``keyfile`` and ``check_hostname``
+ in :mod:`ftplib`, :mod:`http.client`, :mod:`imaplib`, :mod:`poplib`,
+ and :mod:`smtplib` have been deprecated in favor of ``context``.
+ (Contributed by Christian Heimes in :issue:`28022`.)
+
+* A couple of protocols and functions of the :mod:`ssl` module are now
+ deprecated. Some features will no longer be available in future versions
+ of OpenSSL. Other features are deprecated in favor of a different API.
+ (Contributed by Christian Heimes in :issue:`28022` and :issue:`26470`.)
+
+
+Deprecated Python behavior
+--------------------------
+
+* Raising the :exc:`StopIteration` exception inside a generator will now generate a
+ :exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError` in Python 3.7.
+ See :ref:`whatsnew-pep-479` for details.
+
+
+Removed
+=======
+
+API and Feature Removals
+------------------------
+
+* ``inspect.getmoduleinfo()`` was removed (was deprecated since CPython 3.3).
+ :func:`inspect.getmodulename` should be used for obtaining the module
+ name for a given path.
+
+* ``traceback.Ignore`` class and ``traceback.usage``, ``traceback.modname``,
+ ``traceback.fullmodname``, ``traceback.find_lines_from_code``,
+ ``traceback.find_lines``, ``traceback.find_strings``,
+ ``traceback.find_executable_lines`` methods were removed from the
+ :mod:`traceback` module. They were undocumented methods deprecated since
+ Python 3.2 and equivalent functionality is available from private methods.
+
+* The ``tk_menuBar()`` and ``tk_bindForTraversal()`` dummy methods in
+ :mod:`tkinter` widget classes were removed (corresponding Tk commands
+ were obsolete since Tk 4.0).
+
+* The :meth:`~zipfile.ZipFile.open` method of the :class:`zipfile.ZipFile`
+ class no longer supports the ``'U'`` mode (was deprecated since Python 3.4).
+ Use :class:`io.TextIOWrapper` for reading compressed text files in
+ :term:`universal newlines` mode.
+
+* The undocumented ``IN``, ``CDROM``, ``DLFCN``, ``TYPES``, ``CDIO``, and
+ ``STROPTS`` modules have been removed. They had been available in the
+ platform specific ``Lib/plat-*/`` directories, but were chronically out of
+ date, inconsistently available across platforms, and unmaintained. The
+ script that created these modules is still available in the source
+ distribution at :source:`Tools/scripts/h2py.py`.
+
+
+Porting to Python 3.6
+=====================
+
+This section lists previously described changes and other bugfixes
+that may require changes to your code.
+
+Changes in 'python' Command Behavior
+------------------------------------
+
+* The output of a special Python build with defined ``COUNT_ALLOCS``,
+ ``SHOW_ALLOC_COUNT`` or ``SHOW_TRACK_COUNT`` macros is now off by
+ default. It can be re-enabled using the ``-X showalloccount`` option.
+ It now outputs to ``stderr`` instead of ``stdout``.
+ (Contributed by Serhiy Storchaka in :issue:`23034`.)
+
+
+Changes in the Python API
+-------------------------
+
+* :mod:`sqlite3` no longer implicitly commit an open transaction before DDL
+ statements.
+
+* On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
+ is initialized to increase the security.
+
+* When :meth:`importlib.abc.Loader.exec_module` is defined,
+ :meth:`importlib.abc.Loader.create_module` must also be defined.
+
+* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
+ argument is not set. Previously only ``NULL`` was returned.
+
+* The format of the ``co_lnotab`` attribute of code objects changed to support
+ negative line number delta. By default, Python does not emit bytecode with
+ negative line number delta. Functions using ``frame.f_lineno``,
+ ``PyFrame_GetLineNumber()`` or ``PyCode_Addr2Line()`` are not affected.
+ Functions decoding directly ``co_lnotab`` should be updated to use a signed
+ 8-bit integer type for the line number delta, but it's only required to
+ support applications using negative line number delta. See
+ ``Objects/lnotab_notes.txt`` for the ``co_lnotab`` format and how to decode
+ it, and see the :pep:`511` for the rationale.
+
+* The functions in the :mod:`compileall` module now return booleans instead
+ of ``1`` or ``0`` to represent success or failure, respectively. Thanks to
+ booleans being a subclass of integers, this should only be an issue if you
+ were doing identity checks for ``1`` or ``0``. See :issue:`25768`.
+
+* Reading the :attr:`~urllib.parse.SplitResult.port` attribute of
+ :func:`urllib.parse.urlsplit` and :func:`~urllib.parse.urlparse` results
+ now raises :exc:`ValueError` for out-of-range values, rather than
+ returning :const:`None`. See :issue:`20059`.
+
+* The :mod:`imp` module now raises a :exc:`DeprecationWarning` instead of
+ :exc:`PendingDeprecationWarning`.
+
+* The following modules have had missing APIs added to their :attr:`__all__`
+ attributes to match the documented APIs:
+ :mod:`calendar`, :mod:`cgi`, :mod:`csv`,
+ :mod:`~xml.etree.ElementTree`, :mod:`enum`,
+ :mod:`fileinput`, :mod:`ftplib`, :mod:`logging`, :mod:`mailbox`,
+ :mod:`mimetypes`, :mod:`optparse`, :mod:`plistlib`, :mod:`smtpd`,
+ :mod:`subprocess`, :mod:`tarfile`, :mod:`threading` and
+ :mod:`wave`. This means they will export new symbols when ``import *``
+ is used. See :issue:`23883`.
+
+* When performing a relative import, if ``__package__`` does not compare equal
+ to ``__spec__.parent`` then :exc:`ImportWarning` is raised.
+ (Contributed by Brett Cannon in :issue:`25791`.)
+
+* When a relative import is performed and no parent package is known, then
+ :exc:`ImportError` will be raised. Previously, :exc:`SystemError` could be
+ raised. (Contributed by Brett Cannon in :issue:`18018`.)
+
+* Servers based on the :mod:`socketserver` module, including those
+ defined in :mod:`http.server`, :mod:`xmlrpc.server` and
+ :mod:`wsgiref.simple_server`, now only catch exceptions derived
+ from :exc:`Exception`. Therefore if a request handler raises
+ an exception like :exc:`SystemExit` or :exc:`KeyboardInterrupt`,
+ :meth:`~socketserver.BaseServer.handle_error` is no longer called, and
+ the exception will stop a single-threaded server. (Contributed by
+ Martin Panter in :issue:`23430`.)
+
+* :func:`spwd.getspnam` now raises a :exc:`PermissionError` instead of
+ :exc:`KeyError` if the user doesn't have privileges.
+
+* The :meth:`socket.socket.close` method now raises an exception if
+ an error (e.g. EBADF) was reported by the underlying system call.
+ See :issue:`26685`.
+
+* The *decode_data* argument for :class:`smtpd.SMTPChannel` and
+ :class:`smtpd.SMTPServer` constructors is now ``False`` by default.
+ This means that the argument passed to
+ :meth:`~smtpd.SMTPServer.process_message` is now a bytes object by
+ default, and ``process_message()`` will be passed keyword arguments.
+ Code that has already been updated in accordance with the deprecation
+ warning generated by 3.5 will not be affected.
+
+* All optional parameters of the :func:`~json.dump`, :func:`~json.dumps`,
+ :func:`~json.load` and :func:`~json.loads` functions and
+ :class:`~json.JSONEncoder` and :class:`~json.JSONDecoder` class
+ constructors in the :mod:`json` module are now :ref:`keyword-only
+ <keyword-only_parameter>`.
+ (Contributed by Serhiy Storchaka in :issue:`18726`.)
+
+* As part of :pep:`487`, the handling of keyword arguments passed to
+ :class:`type` (other than the metaclass hint, ``metaclass``) is now
+ consistently delegated to :meth:`object.__init_subclass__`. This means that
+ :meth:`type.__new__` and :meth:`type.__init__` both now accept arbitrary
+ keyword arguments, but :meth:`object.__init_subclass__` (which is called from
+ :meth:`type.__new__`) will reject them by default. Custom metaclasses
+ accepting additional keyword arguments will need to adjust their calls to
+ :meth:`type.__new__` (whether direct or via :class:`super`) accordingly.
+
+* In :class:`distutils.command.sdist.sdist`, the ``default_format``
+ attribute has been removed and is no longer honored. Instead, the
+ gzipped tarfile format is the default on all platforms and no
+ platform-specific selection is made.
+ In environments where distributions are
+ built on Windows and zip distributions are required, configure
+ the project with a ``setup.cfg`` file containing the following::
+
+ [sdist]
+ formats=zip
+
+ This behavior has also been backported to earlier Python versions
+ by Setuptools 26.0.0.
+
+* In the :mod:`urllib.request` module and the
+ :meth:`http.client.HTTPConnection.request` method, if no Content-Length
+ header field has been specified and the request body is a file object,
+ it is now sent with HTTP 1.1 chunked encoding. If a file object has to
+ be sent to a HTTP 1.0 server, the Content-Length value now has to be
+ specified by the caller. See :issue:`12319`.
+
+Changes in the C API
+--------------------
+
+* :c:func:`PyMem_Malloc` allocator family now uses the :ref:`pymalloc allocator
+ <pymalloc>` rather than system :c:func:`malloc`. Applications calling
+ :c:func:`PyMem_Malloc` without holding the GIL can now crash. Set the
+ :envvar:`PYTHONMALLOC` environment variable to ``debug`` to validate the
+ usage of memory allocators in your application. See :issue:`26249`.
+
+* :c:func:`Py_Exit` (and the main interpreter) now override the exit status
+ with 120 if flushing buffered data failed. See :issue:`5319`.
diff --git a/Doc/whatsnew/index.rst b/Doc/whatsnew/index.rst
index edb5502..7c92524 100644
--- a/Doc/whatsnew/index.rst
+++ b/Doc/whatsnew/index.rst
@@ -11,6 +11,7 @@ anyone wishing to stay up-to-date after a new release.
.. toctree::
:maxdepth: 2
+ 3.6.rst
3.5.rst
3.4.rst
3.3.rst
diff --git a/Grammar/Grammar b/Grammar/Grammar
index 4307523..b139e9f 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -27,25 +27,31 @@ async_funcdef: ASYNC funcdef
funcdef: 'def' NAME parameters ['->' test] ':' suite
parameters: '(' [typedargslist] ')'
-typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [','
- ['*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef]]
- | '*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
+typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [
+ '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
+ | '**' tfpdef [',']]]
+ | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
+ | '**' tfpdef [','])
tfpdef: NAME [':' test]
-varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [','
- ['*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef]]
- | '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
+varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
+ '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
+ | '**' vfpdef [',']]]
+ | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
+ | '**' vfpdef [',']
+)
vfpdef: NAME
stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
-expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
+expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*)
+annassign: ':' test ['=' test]
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
-# For normal assignments, additional restrictions enforced by the interpreter
+# For normal and annotated assignments, additional restrictions enforced by the interpreter
del_stmt: 'del' exprlist
pass_stmt: 'pass'
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
@@ -140,7 +146,7 @@ argument: ( test [comp_for] |
'*' test )
comp_iter: comp_for | comp_if
-comp_for: 'for' exprlist 'in' or_test [comp_iter]
+comp_for: [ASYNC] 'for' exprlist 'in' or_test [comp_iter]
comp_if: 'if' test_nocond [comp_iter]
# not used in grammar, but may appear in "node" passed from Parser to Compiler
diff --git a/Include/Python-ast.h b/Include/Python-ast.h
index 2d3eacb..70494b7 100644
--- a/Include/Python-ast.h
+++ b/Include/Python-ast.h
@@ -65,11 +65,12 @@ struct _mod {
enum _stmt_kind {FunctionDef_kind=1, AsyncFunctionDef_kind=2, ClassDef_kind=3,
Return_kind=4, Delete_kind=5, Assign_kind=6,
- AugAssign_kind=7, For_kind=8, AsyncFor_kind=9, While_kind=10,
- If_kind=11, With_kind=12, AsyncWith_kind=13, Raise_kind=14,
- Try_kind=15, Assert_kind=16, Import_kind=17,
- ImportFrom_kind=18, Global_kind=19, Nonlocal_kind=20,
- Expr_kind=21, Pass_kind=22, Break_kind=23, Continue_kind=24};
+ AugAssign_kind=7, AnnAssign_kind=8, For_kind=9,
+ AsyncFor_kind=10, While_kind=11, If_kind=12, With_kind=13,
+ AsyncWith_kind=14, Raise_kind=15, Try_kind=16,
+ Assert_kind=17, Import_kind=18, ImportFrom_kind=19,
+ Global_kind=20, Nonlocal_kind=21, Expr_kind=22, Pass_kind=23,
+ Break_kind=24, Continue_kind=25};
struct _stmt {
enum _stmt_kind kind;
union {
@@ -118,6 +119,13 @@ struct _stmt {
struct {
expr_ty target;
+ expr_ty annotation;
+ expr_ty value;
+ int simple;
+ } AnnAssign;
+
+ struct {
+ expr_ty target;
expr_ty iter;
asdl_seq *body;
asdl_seq *orelse;
@@ -201,9 +209,10 @@ enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,
SetComp_kind=9, DictComp_kind=10, GeneratorExp_kind=11,
Await_kind=12, Yield_kind=13, YieldFrom_kind=14,
Compare_kind=15, Call_kind=16, Num_kind=17, Str_kind=18,
- Bytes_kind=19, NameConstant_kind=20, Ellipsis_kind=21,
- Attribute_kind=22, Subscript_kind=23, Starred_kind=24,
- Name_kind=25, List_kind=26, Tuple_kind=27};
+ FormattedValue_kind=19, JoinedStr_kind=20, Bytes_kind=21,
+ NameConstant_kind=22, Ellipsis_kind=23, Constant_kind=24,
+ Attribute_kind=25, Subscript_kind=26, Starred_kind=27,
+ Name_kind=28, List_kind=29, Tuple_kind=30};
struct _expr {
enum _expr_kind kind;
union {
@@ -297,6 +306,16 @@ struct _expr {
} Str;
struct {
+ expr_ty value;
+ int conversion;
+ expr_ty format_spec;
+ } FormattedValue;
+
+ struct {
+ asdl_seq *values;
+ } JoinedStr;
+
+ struct {
bytes s;
} Bytes;
@@ -305,6 +324,10 @@ struct _expr {
} NameConstant;
struct {
+ constant value;
+ } Constant;
+
+ struct {
expr_ty value;
identifier attr;
expr_context_ty ctx;
@@ -366,6 +389,7 @@ struct _comprehension {
expr_ty target;
expr_ty iter;
asdl_seq *ifs;
+ int is_async;
};
enum _excepthandler_kind {ExceptHandler_kind=1};
@@ -446,6 +470,9 @@ stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, int lineno, int
#define AugAssign(a0, a1, a2, a3, a4, a5) _Py_AugAssign(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
lineno, int col_offset, PyArena *arena);
+#define AnnAssign(a0, a1, a2, a3, a4, a5, a6) _Py_AnnAssign(a0, a1, a2, a3, a4, a5, a6)
+stmt_ty _Py_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int
+ simple, int lineno, int col_offset, PyArena *arena);
#define For(a0, a1, a2, a3, a4, a5, a6) _Py_For(a0, a1, a2, a3, a4, a5, a6)
stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *
orelse, int lineno, int col_offset, PyArena *arena);
@@ -543,6 +570,12 @@ expr_ty _Py_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int
expr_ty _Py_Num(object n, int lineno, int col_offset, PyArena *arena);
#define Str(a0, a1, a2, a3) _Py_Str(a0, a1, a2, a3)
expr_ty _Py_Str(string s, int lineno, int col_offset, PyArena *arena);
+#define FormattedValue(a0, a1, a2, a3, a4, a5) _Py_FormattedValue(a0, a1, a2, a3, a4, a5)
+expr_ty _Py_FormattedValue(expr_ty value, int conversion, expr_ty format_spec,
+ int lineno, int col_offset, PyArena *arena);
+#define JoinedStr(a0, a1, a2, a3) _Py_JoinedStr(a0, a1, a2, a3)
+expr_ty _Py_JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena
+ *arena);
#define Bytes(a0, a1, a2, a3) _Py_Bytes(a0, a1, a2, a3)
expr_ty _Py_Bytes(bytes s, int lineno, int col_offset, PyArena *arena);
#define NameConstant(a0, a1, a2, a3) _Py_NameConstant(a0, a1, a2, a3)
@@ -550,6 +583,9 @@ expr_ty _Py_NameConstant(singleton value, int lineno, int col_offset, PyArena
*arena);
#define Ellipsis(a0, a1, a2) _Py_Ellipsis(a0, a1, a2)
expr_ty _Py_Ellipsis(int lineno, int col_offset, PyArena *arena);
+#define Constant(a0, a1, a2, a3) _Py_Constant(a0, a1, a2, a3)
+expr_ty _Py_Constant(constant value, int lineno, int col_offset, PyArena
+ *arena);
#define Attribute(a0, a1, a2, a3, a4, a5) _Py_Attribute(a0, a1, a2, a3, a4, a5)
expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
lineno, int col_offset, PyArena *arena);
@@ -574,9 +610,9 @@ slice_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena);
slice_ty _Py_ExtSlice(asdl_seq * dims, PyArena *arena);
#define Index(a0, a1) _Py_Index(a0, a1)
slice_ty _Py_Index(expr_ty value, PyArena *arena);
-#define comprehension(a0, a1, a2, a3) _Py_comprehension(a0, a1, a2, a3)
+#define comprehension(a0, a1, a2, a3, a4) _Py_comprehension(a0, a1, a2, a3, a4)
comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_seq *
- ifs, PyArena *arena);
+ ifs, int is_async, PyArena *arena);
#define ExceptHandler(a0, a1, a2, a3, a4, a5) _Py_ExceptHandler(a0, a1, a2, a3, a4, a5)
excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_seq *
body, int lineno, int col_offset, PyArena
diff --git a/Include/Python.h b/Include/Python.h
index 858dbd1..4c7c9a4 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -116,6 +116,7 @@
#include "pylifecycle.h"
#include "ceval.h"
#include "sysmodule.h"
+#include "osmodule.h"
#include "intrcheck.h"
#include "import.h"
diff --git a/Include/abstract.h b/Include/abstract.h
index 36df5a7..44107a8 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -7,7 +7,9 @@ extern "C" {
#ifdef PY_SSIZE_T_CLEAN
#define PyObject_CallFunction _PyObject_CallFunction_SizeT
#define PyObject_CallMethod _PyObject_CallMethod_SizeT
+#ifndef Py_LIMITED_API
#define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT
+#endif /* !Py_LIMITED_API */
#endif
/* Abstract Object Interface (many thanks to Jim Fulton) */
@@ -264,18 +266,96 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
*/
PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,
- PyObject *args, PyObject *kw);
+ PyObject *args, PyObject *kwargs);
#ifndef Py_LIMITED_API
+ PyAPI_FUNC(PyObject*) _PyStack_AsTuple(
+ PyObject **stack,
+ Py_ssize_t nargs);
+
+ /* Convert keyword arguments from the (stack, kwnames) format to a Python
+ dictionary.
+
+ kwnames must only contains str strings, no subclass, and all keys must
+ be unique. kwnames is not checked, usually these checks are done before or later
+ calling _PyStack_AsDict(). For example, _PyArg_ParseStack() raises an
+ error if a key is not a string. */
+ PyAPI_FUNC(PyObject *) _PyStack_AsDict(
+ PyObject **values,
+ PyObject *kwnames);
+
+ /* Convert (args, nargs, kwargs) into a (stack, nargs, kwnames).
+
+ Return a new stack which should be released by PyMem_Free(), or return
+ args unchanged if kwargs is NULL or an empty dictionary.
+
+ The stack uses borrowed references.
+
+ The type of keyword keys is not checked, these checks should be done
+ later (ex: _PyArg_ParseStack). */
+ PyAPI_FUNC(PyObject **) _PyStack_UnpackDict(
+ PyObject **args,
+ Py_ssize_t nargs,
+ PyObject *kwargs,
+ PyObject **kwnames,
+ PyObject *func);
+
+ /* Call the callable object func with the "fast call" calling convention:
+ args is a C array for positional arguments (nargs is the number of
+ positional arguments), kwargs is a dictionary for keyword arguments.
+
+ If nargs is equal to zero, args can be NULL. kwargs can be NULL.
+ nargs must be greater or equal to zero.
+
+ Return the result on success. Raise an exception on return NULL on
+ error. */
+ PyAPI_FUNC(PyObject *) _PyObject_FastCallDict(PyObject *func,
+ PyObject **args, Py_ssize_t nargs,
+ PyObject *kwargs);
+
+ /* Call the callable object func with the "fast call" calling convention:
+ args is a C array for positional arguments followed by values of
+ keyword arguments. Keys of keyword arguments are stored as a tuple
+ of strings in kwnames. nargs is the number of positional parameters at
+ the beginning of stack. The size of kwnames gives the number of keyword
+ values in the stack after positional arguments.
+
+ kwnames must only contains str strings, no subclass, and all keys must
+ be unique.
+
+ If nargs is equal to zero and there is no keyword argument (kwnames is
+ NULL or its size is zero), args can be NULL.
+
+ Return the result on success. Raise an exception and return NULL on
+ error. */
+ PyAPI_FUNC(PyObject *) _PyObject_FastCallKeywords
+ (PyObject *func,
+ PyObject **args,
+ Py_ssize_t nargs,
+ PyObject *kwnames);
+
+#define _PyObject_FastCall(func, args, nargs) \
+ _PyObject_FastCallDict((func), (args), (nargs), NULL)
+
+#define _PyObject_CallNoArg(func) \
+ _PyObject_FastCall((func), NULL, 0)
+
+#define _PyObject_CallArg1(func, arg) \
+ _PyObject_FastCall((func), &(arg), 1)
+
+ PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(PyObject *func,
+ PyObject *obj, PyObject *args,
+ PyObject *kwargs);
+
PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *func,
PyObject *result,
const char *where);
-#endif
+#endif /* Py_LIMITED_API */
/*
Call a callable Python object, callable_object, with
arguments and keywords arguments. The 'args' argument can not be
- NULL, but the 'kw' argument can be NULL.
+ NULL.
*/
PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,
@@ -315,6 +395,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Python expression: o.method(args).
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *o,
_Py_Identifier *method,
const char *format, ...);
@@ -323,6 +404,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Like PyObject_CallMethod, but expect a _Py_Identifier* as the
method name.
*/
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
const char *format,
@@ -331,10 +413,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
const char *name,
const char *format,
...);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *o,
_Py_Identifier *name,
const char *format,
...);
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
...);
@@ -350,9 +434,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o,
PyObject *method, ...);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs(PyObject *o,
struct _Py_Identifier *method,
...);
+#endif /* !Py_LIMITED_API */
/*
Call the method named m of object o with a variable number of
@@ -1270,13 +1356,13 @@ PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
PyAPI_FUNC(char *const *) _PySequence_BytesToCharpArray(PyObject* self);
PyAPI_FUNC(void) _Py_FreeCharPArray(char *const array[]);
-#endif
/* For internal use by buffer API functions */
PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index,
const Py_ssize_t *shape);
PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index,
const Py_ssize_t *shape);
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
diff --git a/Include/asdl.h b/Include/asdl.h
index 495153c..35e9fa1 100644
--- a/Include/asdl.h
+++ b/Include/asdl.h
@@ -6,6 +6,7 @@ typedef PyObject * string;
typedef PyObject * bytes;
typedef PyObject * object;
typedef PyObject * singleton;
+typedef PyObject * constant;
/* It would be nice if the code generated by asdl_c.py was completely
independent of Python, but it is a goal the requires too much work
diff --git a/Include/bytes_methods.h b/Include/bytes_methods.h
index 11d5f42..7fa7540 100644
--- a/Include/bytes_methods.h
+++ b/Include/bytes_methods.h
@@ -17,9 +17,18 @@ extern PyObject* _Py_bytes_istitle(const char *cptr, Py_ssize_t len);
/* These store their len sized answer in the given preallocated *result arg. */
extern void _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len);
extern void _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len);
-extern void _Py_bytes_title(char *result, char *s, Py_ssize_t len);
-extern void _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len);
-extern void _Py_bytes_swapcase(char *result, char *s, Py_ssize_t len);
+extern void _Py_bytes_title(char *result, const char *s, Py_ssize_t len);
+extern void _Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len);
+extern void _Py_bytes_swapcase(char *result, const char *s, Py_ssize_t len);
+
+extern PyObject *_Py_bytes_find(const char *str, Py_ssize_t len, PyObject *args);
+extern PyObject *_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *args);
+extern PyObject *_Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *args);
+extern PyObject *_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *args);
+extern PyObject *_Py_bytes_count(const char *str, Py_ssize_t len, PyObject *args);
+extern int _Py_bytes_contains(const char *str, Py_ssize_t len, PyObject *arg);
+extern PyObject *_Py_bytes_startswith(const char *str, Py_ssize_t len, PyObject *args);
+extern PyObject *_Py_bytes_endswith(const char *str, Py_ssize_t len, PyObject *args);
/* The maketrans() static method. */
extern PyObject* _Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to);
@@ -37,7 +46,19 @@ extern const char _Py_upper__doc__[];
extern const char _Py_title__doc__[];
extern const char _Py_capitalize__doc__[];
extern const char _Py_swapcase__doc__[];
+extern const char _Py_count__doc__[];
+extern const char _Py_find__doc__[];
+extern const char _Py_index__doc__[];
+extern const char _Py_rfind__doc__[];
+extern const char _Py_rindex__doc__[];
+extern const char _Py_startswith__doc__[];
+extern const char _Py_endswith__doc__[];
extern const char _Py_maketrans__doc__[];
+extern const char _Py_expandtabs__doc__[];
+extern const char _Py_ljust__doc__[];
+extern const char _Py_rjust__doc__[];
+extern const char _Py_center__doc__[];
+extern const char _Py_zfill__doc__[];
/* this is needed because some docs are shared from the .o, not static */
#define PyDoc_STRVAR_shared(name,str) const char name[] = PyDoc_STR(str)
diff --git a/Include/bytesobject.h b/Include/bytesobject.h
index 6c1e0c3..11d8218 100644
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -62,7 +62,14 @@ PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *);
PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *);
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t);
-PyAPI_FUNC(PyObject *) _PyBytes_Format(PyObject *, PyObject *);
+PyAPI_FUNC(PyObject*) _PyBytes_FormatEx(
+ const char *format,
+ Py_ssize_t format_len,
+ PyObject *args,
+ int use_bytearray);
+PyAPI_FUNC(PyObject*) _PyBytes_FromHex(
+ PyObject *string,
+ int use_bytearray);
#endif
PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t,
const char *, Py_ssize_t,
@@ -123,6 +130,87 @@ PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGrouping(char *buffer,
#define F_ALT (1<<3)
#define F_ZERO (1<<4)
+#ifndef Py_LIMITED_API
+/* The _PyBytesWriter structure is big: it contains an embedded "stack buffer".
+ A _PyBytesWriter variable must be declared at the end of variables in a
+ function to optimize the memory allocation on the stack. */
+typedef struct {
+ /* bytes, bytearray or NULL (when the small buffer is used) */
+ PyObject *buffer;
+
+ /* Number of allocated size. */
+ Py_ssize_t allocated;
+
+ /* Minimum number of allocated bytes,
+ incremented by _PyBytesWriter_Prepare() */
+ Py_ssize_t min_size;
+
+ /* If non-zero, use a bytearray instead of a bytes object for buffer. */
+ int use_bytearray;
+
+ /* If non-zero, overallocate the buffer (default: 0).
+ This flag must be zero if use_bytearray is non-zero. */
+ int overallocate;
+
+ /* Stack buffer */
+ int use_small_buffer;
+ char small_buffer[512];
+} _PyBytesWriter;
+
+/* Initialize a bytes writer
+
+ By default, the overallocation is disabled. Set the overallocate attribute
+ to control the allocation of the buffer. */
+PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer);
+
+/* Get the buffer content and reset the writer.
+ Return a bytes object, or a bytearray object if use_bytearray is non-zero.
+ Raise an exception and return NULL on error. */
+PyAPI_FUNC(PyObject *) _PyBytesWriter_Finish(_PyBytesWriter *writer,
+ void *str);
+
+/* Deallocate memory of a writer (clear its internal buffer). */
+PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer);
+
+/* Allocate the buffer to write size bytes.
+ Return the pointer to the beginning of buffer data.
+ Raise an exception and return NULL on error. */
+PyAPI_FUNC(void*) _PyBytesWriter_Alloc(_PyBytesWriter *writer,
+ Py_ssize_t size);
+
+/* Ensure that the buffer is large enough to write *size* bytes.
+ Add size to the writer minimum size (min_size attribute).
+
+ str is the current pointer inside the buffer.
+ Return the updated current pointer inside the buffer.
+ Raise an exception and return NULL on error. */
+PyAPI_FUNC(void*) _PyBytesWriter_Prepare(_PyBytesWriter *writer,
+ void *str,
+ Py_ssize_t size);
+
+/* Resize the buffer to make it larger.
+ The new buffer may be larger than size bytes because of overallocation.
+ Return the updated current pointer inside the buffer.
+ Raise an exception and return NULL on error.
+
+ Note: size must be greater than the number of allocated bytes in the writer.
+
+ This function doesn't use the writer minimum size (min_size attribute).
+
+ See also _PyBytesWriter_Prepare().
+ */
+PyAPI_FUNC(void*) _PyBytesWriter_Resize(_PyBytesWriter *writer,
+ void *str,
+ Py_ssize_t size);
+
+/* Write bytes.
+ Raise an exception and return NULL on error. */
+PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
+ void *str,
+ const void *bytes,
+ Py_ssize_t size);
+#endif /* Py_LIMITED_API */
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/ceval.h b/Include/ceval.h
index b5373a9..89c6062 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -8,7 +8,7 @@ extern "C" {
/* Interface to random parts in ceval.c */
PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
- PyObject *, PyObject *, PyObject *);
+ PyObject *func, PyObject *args, PyObject *kwargs);
/* Inline this */
#define PyEval_CallObject(func,arg) \
@@ -25,6 +25,10 @@ PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
PyAPI_FUNC(void) _PyEval_SetCoroutineWrapper(PyObject *);
PyAPI_FUNC(PyObject *) _PyEval_GetCoroutineWrapper(void);
+PyAPI_FUNC(void) _PyEval_SetAsyncGenFirstiter(PyObject *);
+PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFirstiter(void);
+PyAPI_FUNC(void) _PyEval_SetAsyncGenFinalizer(PyObject *);
+PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void);
#endif
struct _frame; /* Avoid including frameobject.h */
@@ -119,6 +123,9 @@ PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
+#endif
/* Interface for threads.
@@ -172,7 +179,9 @@ PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
PyAPI_FUNC(void) PyEval_InitThreads(void);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyEval_FiniThreads(void);
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(void) PyEval_AcquireLock(void);
PyAPI_FUNC(void) PyEval_ReleaseLock(void);
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
@@ -184,6 +193,10 @@ PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
#endif
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
+#endif
+
#define Py_BEGIN_ALLOW_THREADS { \
PyThreadState *_save; \
_save = PyEval_SaveThread();
@@ -206,6 +219,14 @@ PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void);
#endif
+/* Masks and values used by FORMAT_VALUE opcode. */
+#define FVC_MASK 0x3
+#define FVC_NONE 0x0
+#define FVC_STR 0x1
+#define FVC_REPR 0x2
+#define FVC_ASCII 0x3
+#define FVS_MASK 0x4
+#define FVS_HAVE_SPEC 0x4
#ifdef __cplusplus
}
diff --git a/Include/code.h b/Include/code.h
index 8ecf38a..0619029 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -7,6 +7,16 @@
extern "C" {
#endif
+typedef uint16_t _Py_CODEUNIT;
+
+#ifdef WORDS_BIGENDIAN
+# define _Py_OPCODE(word) ((word) >> 8)
+# define _Py_OPARG(word) ((word) & 255)
+#else
+# define _Py_OPCODE(word) ((word) & 255)
+# define _Py_OPARG(word) ((word) >> 8)
+#endif
+
/* Bytecode object */
typedef struct {
PyObject_HEAD
@@ -15,6 +25,7 @@ typedef struct {
int co_nlocals; /* #local variables */
int co_stacksize; /* #entries needed for evaluation stack */
int co_flags; /* CO_..., see below */
+ int co_firstlineno; /* first source line number */
PyObject *co_code; /* instruction opcodes */
PyObject *co_consts; /* list (constants used) */
PyObject *co_names; /* list of strings (names used) */
@@ -30,11 +41,14 @@ typedef struct {
unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */
PyObject *co_filename; /* unicode (where it was loaded from) */
PyObject *co_name; /* unicode (name, for reference) */
- int co_firstlineno; /* first source line number */
PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See
Objects/lnotab_notes.txt for details. */
void *co_zombieframe; /* for optimization only (see frameobject.c) */
PyObject *co_weakreflist; /* to support weakrefs to code objects */
+ /* Scratch space for extra data relating to the code object.__icc_nan
+ Type is a void* to keep the format private in codeobject.c to force
+ people to go through the proper APIs. */
+ void *co_extra;
} PyCodeObject;
/* Masks for co_flags above */
@@ -55,6 +69,7 @@ typedef struct {
``async def`` keywords) */
#define CO_COROUTINE 0x0080
#define CO_ITERABLE_COROUTINE 0x0100
+#define CO_ASYNC_GENERATOR 0x0200
/* These are no longer used. */
#if 0
@@ -126,7 +141,15 @@ PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj);
#endif
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
- PyObject *names, PyObject *lineno_obj);
+ PyObject *names, PyObject *lnotab);
+
+
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
+ void **extra);
+PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
+ void *extra);
+#endif
#ifdef __cplusplus
}
diff --git a/Include/datetime.h b/Include/datetime.h
index 06cbc4a..3bf35cb 100644
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -81,6 +81,7 @@ typedef struct
typedef struct
{
_PyDateTime_TIMEHEAD
+ unsigned char fold;
PyObject *tzinfo;
} PyDateTime_Time; /* hastzinfo true */
@@ -108,6 +109,7 @@ typedef struct
typedef struct
{
_PyDateTime_DATETIMEHEAD
+ unsigned char fold;
PyObject *tzinfo;
} PyDateTime_DateTime; /* hastzinfo true */
@@ -125,6 +127,7 @@ typedef struct
((((PyDateTime_DateTime*)o)->data[7] << 16) | \
(((PyDateTime_DateTime*)o)->data[8] << 8) | \
((PyDateTime_DateTime*)o)->data[9])
+#define PyDateTime_DATE_GET_FOLD(o) (((PyDateTime_DateTime*)o)->fold)
/* Apply for time instances. */
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
@@ -134,6 +137,7 @@ typedef struct
((((PyDateTime_Time*)o)->data[3] << 16) | \
(((PyDateTime_Time*)o)->data[4] << 8) | \
((PyDateTime_Time*)o)->data[5])
+#define PyDateTime_TIME_GET_FOLD(o) (((PyDateTime_Time*)o)->fold)
/* Apply for time delta instances */
#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days)
@@ -162,6 +166,11 @@ typedef struct {
PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*);
PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*);
+ /* PEP 495 constructors */
+ PyObject *(*DateTime_FromDateAndTimeAndFold)(int, int, int, int, int, int, int,
+ PyObject*, int, PyTypeObject*);
+ PyObject *(*Time_FromTimeAndFold)(int, int, int, int, PyObject*, int, PyTypeObject*);
+
} PyDateTime_CAPI;
#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
@@ -217,10 +226,18 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
+#define PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, min, sec, usec, fold) \
+ PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(year, month, day, hour, \
+ min, sec, usec, Py_None, fold, PyDateTimeAPI->DateTimeType)
+
#define PyTime_FromTime(hour, minute, second, usecond) \
PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
Py_None, PyDateTimeAPI->TimeType)
+#define PyTime_FromTimeAndFold(hour, minute, second, usecond, fold) \
+ PyDateTimeAPI->Time_FromTimeAndFold(hour, minute, second, usecond, \
+ Py_None, fold, PyDateTimeAPI->TimeType)
+
#define PyDelta_FromDSU(days, seconds, useconds) \
PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
PyDateTimeAPI->DeltaType)
diff --git a/Include/descrobject.h b/Include/descrobject.h
index e2ba97f..8f3e84c 100644
--- a/Include/descrobject.h
+++ b/Include/descrobject.h
@@ -78,7 +78,9 @@ PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
+#ifndef Py_LIMITED_API
PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type;
+#endif /* Py_LIMITED_API */
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
diff --git a/Include/dictobject.h b/Include/dictobject.h
index ba90aaf..f06f240 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -22,8 +22,21 @@ typedef struct _dictkeysobject PyDictKeysObject;
*/
typedef struct {
PyObject_HEAD
+
+ /* Number of items in the dictionary */
Py_ssize_t ma_used;
+
+ /* Dictionary version: globally unique, value change each time
+ the dictionary is modified */
+ uint64_t ma_version_tag;
+
PyDictKeysObject *ma_keys;
+
+ /* If ma_values is NULL, the table is "combined": keys and values
+ are stored in ma_keys.
+
+ If ma_values is not NULL, the table is splitted:
+ keys are stored in ma_keys and values are stored in ma_values */
PyObject **ma_values;
} PyDictObject;
@@ -60,9 +73,9 @@ PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
Py_hash_t hash);
#endif
PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
struct _Py_Identifier *key);
-#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
PyObject *mp, PyObject *key, PyObject *defaultobj);
#endif
@@ -119,6 +132,12 @@ PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,
int override);
#ifndef Py_LIMITED_API
+/* Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,
+ the first occurrence of a key wins, if override is 1, the last occurrence
+ of a key wins, if override is 2, a KeyError with conflicting key as
+ argument is raised.
+*/
+PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other);
#endif
@@ -132,9 +151,13 @@ PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,
int override);
PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key);
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
#ifndef Py_LIMITED_API
diff --git a/Include/fileobject.h b/Include/fileobject.h
index 03155d3..03984ba 100644
--- a/Include/fileobject.h
+++ b/Include/fileobject.h
@@ -23,6 +23,7 @@ PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
If non-NULL, this is different than the default encoding for strings
*/
PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
+PyAPI_DATA(const char *) Py_FileSystemDefaultEncodeErrors;
PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding;
/* Internal API
diff --git a/Include/fileutils.h b/Include/fileutils.h
index b4a683c..4016431 100644
--- a/Include/fileutils.h
+++ b/Include/fileutils.h
@@ -5,8 +5,6 @@
extern "C" {
#endif
-PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
-
PyAPI_FUNC(wchar_t *) Py_DecodeLocale(
const char *arg,
size_t *size);
@@ -17,6 +15,8 @@ PyAPI_FUNC(char*) Py_EncodeLocale(
#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
+
#ifdef MS_WINDOWS
struct _Py_stat_struct {
unsigned long st_dev;
@@ -46,13 +46,11 @@ PyAPI_FUNC(int) _Py_fstat(
PyAPI_FUNC(int) _Py_fstat_noraise(
int fd,
struct _Py_stat_struct *status);
-#endif /* Py_LIMITED_API */
PyAPI_FUNC(int) _Py_stat(
PyObject *path,
struct stat *status);
-#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _Py_open(
const char *pathname,
int flags);
@@ -60,7 +58,6 @@ PyAPI_FUNC(int) _Py_open(
PyAPI_FUNC(int) _Py_open_noraise(
const char *pathname,
int flags);
-#endif
PyAPI_FUNC(FILE *) _Py_wfopen(
const wchar_t *path,
@@ -107,7 +104,6 @@ PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
wchar_t *buf,
size_t size);
-#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _Py_get_inheritable(int fd);
PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
@@ -121,18 +117,6 @@ PyAPI_FUNC(int) _Py_get_blocking(int fd);
PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
#endif /* !MS_WINDOWS */
-#if defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900
-/* A routine to check if a file descriptor is valid on Windows. Returns 0
- * and sets errno to EBADF if it isn't. This is to avoid Assertions
- * from various functions in the Windows CRT beginning with
- * Visual Studio 2005
- */
-int _PyVerify_fd(int fd);
-
-#else
-#define _PyVerify_fd(A) (1) /* dummy */
-#endif
-
#endif /* Py_LIMITED_API */
#ifdef __cplusplus
diff --git a/Include/floatobject.h b/Include/floatobject.h
index e240fdb..f1044d6 100644
--- a/Include/floatobject.h
+++ b/Include/floatobject.h
@@ -74,9 +74,9 @@ PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *);
* happens in such cases is partly accidental (alas).
*/
-/* The pack routines write 4 or 8 bytes, starting at p. le is a bool
+/* The pack routines write 2, 4 or 8 bytes, starting at p. le is a bool
* argument, true if you want the string in little-endian format (exponent
- * last, at p+3 or p+7), false if you want big-endian format (exponent
+ * last, at p+1, p+3 or p+7), false if you want big-endian format (exponent
* first, at p).
* Return value: 0 if all is OK, -1 if error (and an exception is
* set, most likely OverflowError).
@@ -84,6 +84,7 @@ PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *);
* 1): What this does is undefined if x is a NaN or infinity.
* 2): -0.0 and +0.0 produce the same string.
*/
+PyAPI_FUNC(int) _PyFloat_Pack2(double x, unsigned char *p, int le);
PyAPI_FUNC(int) _PyFloat_Pack4(double x, unsigned char *p, int le);
PyAPI_FUNC(int) _PyFloat_Pack8(double x, unsigned char *p, int le);
@@ -96,14 +97,15 @@ PyAPI_FUNC(int) _PyFloat_Repr(double x, char *p, size_t len);
PyAPI_FUNC(int) _PyFloat_Digits(char *buf, double v, int *signum);
PyAPI_FUNC(void) _PyFloat_DigitsInit(void);
-/* The unpack routines read 4 or 8 bytes, starting at p. le is a bool
+/* The unpack routines read 2, 4 or 8 bytes, starting at p. le is a bool
* argument, true if the string is in little-endian format (exponent
- * last, at p+3 or p+7), false if big-endian (exponent first, at p).
+ * last, at p+1, p+3 or p+7), false if big-endian (exponent first, at p).
* Return value: The unpacked double. On error, this is -1.0 and
* PyErr_Occurred() is true (and an exception is set, most likely
* OverflowError). Note that on a non-IEEE platform this will refuse
* to unpack a string that represents a NaN or infinity.
*/
+PyAPI_FUNC(double) _PyFloat_Unpack2(const unsigned char *p, int le);
PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le);
PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le);
diff --git a/Include/funcobject.h b/Include/funcobject.h
index cc1426c..77bb8c3 100644
--- a/Include/funcobject.h
+++ b/Include/funcobject.h
@@ -58,6 +58,20 @@ PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetAnnotations(PyObject *);
PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) _PyFunction_FastCallDict(
+ PyObject *func,
+ PyObject **args,
+ Py_ssize_t nargs,
+ PyObject *kwargs);
+
+PyAPI_FUNC(PyObject *) _PyFunction_FastCallKeywords(
+ PyObject *func,
+ PyObject **stack,
+ Py_ssize_t nargs,
+ PyObject *kwnames);
+#endif
+
/* Macros for direct access to these values. Type checks are *not*
done, so use with care. */
#define PyFunction_GET_CODE(func) \
diff --git a/Include/genobject.h b/Include/genobject.h
index 1ff32a8..973bdd5 100644
--- a/Include/genobject.h
+++ b/Include/genobject.h
@@ -61,6 +61,37 @@ PyObject *_PyAIterWrapper_New(PyObject *aiter);
PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *,
PyObject *name, PyObject *qualname);
+
+/* Asynchronous Generators */
+
+typedef struct {
+ _PyGenObject_HEAD(ag)
+ PyObject *ag_finalizer;
+
+ /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks
+ were called on the generator, to avoid calling them more
+ than once. */
+ int ag_hooks_inited;
+
+ /* Flag is set to 1 when aclose() is called for the first time, or
+ when a StopAsyncIteration exception is raised. */
+ int ag_closed;
+} PyAsyncGenObject;
+
+PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
+PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
+PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
+PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
+
+PyAPI_FUNC(PyObject *) PyAsyncGen_New(struct _frame *,
+ PyObject *name, PyObject *qualname);
+
+#define PyAsyncGen_CheckExact(op) (Py_TYPE(op) == &PyAsyncGen_Type)
+
+PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
+
+int PyAsyncGen_ClearFreeLists(void);
+
#endif
#undef _PyGenObject_HEAD
diff --git a/Include/graminit.h b/Include/graminit.h
index d030bc3..e9b4a93 100644
--- a/Include/graminit.h
+++ b/Include/graminit.h
@@ -17,71 +17,72 @@
#define simple_stmt 270
#define small_stmt 271
#define expr_stmt 272
-#define testlist_star_expr 273
-#define augassign 274
-#define del_stmt 275
-#define pass_stmt 276
-#define flow_stmt 277
-#define break_stmt 278
-#define continue_stmt 279
-#define return_stmt 280
-#define yield_stmt 281
-#define raise_stmt 282
-#define import_stmt 283
-#define import_name 284
-#define import_from 285
-#define import_as_name 286
-#define dotted_as_name 287
-#define import_as_names 288
-#define dotted_as_names 289
-#define dotted_name 290
-#define global_stmt 291
-#define nonlocal_stmt 292
-#define assert_stmt 293
-#define compound_stmt 294
-#define async_stmt 295
-#define if_stmt 296
-#define while_stmt 297
-#define for_stmt 298
-#define try_stmt 299
-#define with_stmt 300
-#define with_item 301
-#define except_clause 302
-#define suite 303
-#define test 304
-#define test_nocond 305
-#define lambdef 306
-#define lambdef_nocond 307
-#define or_test 308
-#define and_test 309
-#define not_test 310
-#define comparison 311
-#define comp_op 312
-#define star_expr 313
-#define expr 314
-#define xor_expr 315
-#define and_expr 316
-#define shift_expr 317
-#define arith_expr 318
-#define term 319
-#define factor 320
-#define power 321
-#define atom_expr 322
-#define atom 323
-#define testlist_comp 324
-#define trailer 325
-#define subscriptlist 326
-#define subscript 327
-#define sliceop 328
-#define exprlist 329
-#define testlist 330
-#define dictorsetmaker 331
-#define classdef 332
-#define arglist 333
-#define argument 334
-#define comp_iter 335
-#define comp_for 336
-#define comp_if 337
-#define encoding_decl 338
-#define yield_expr 339
-#define yield_arg 340
+#define annassign 273
+#define testlist_star_expr 274
+#define augassign 275
+#define del_stmt 276
+#define pass_stmt 277
+#define flow_stmt 278
+#define break_stmt 279
+#define continue_stmt 280
+#define return_stmt 281
+#define yield_stmt 282
+#define raise_stmt 283
+#define import_stmt 284
+#define import_name 285
+#define import_from 286
+#define import_as_name 287
+#define dotted_as_name 288
+#define import_as_names 289
+#define dotted_as_names 290
+#define dotted_name 291
+#define global_stmt 292
+#define nonlocal_stmt 293
+#define assert_stmt 294
+#define compound_stmt 295
+#define async_stmt 296
+#define if_stmt 297
+#define while_stmt 298
+#define for_stmt 299
+#define try_stmt 300
+#define with_stmt 301
+#define with_item 302
+#define except_clause 303
+#define suite 304
+#define test 305
+#define test_nocond 306
+#define lambdef 307
+#define lambdef_nocond 308
+#define or_test 309
+#define and_test 310
+#define not_test 311
+#define comparison 312
+#define comp_op 313
+#define star_expr 314
+#define expr 315
+#define xor_expr 316
+#define and_expr 317
+#define shift_expr 318
+#define arith_expr 319
+#define term 320
+#define factor 321
+#define power 322
+#define atom_expr 323
+#define atom 324
+#define testlist_comp 325
+#define trailer 326
+#define subscriptlist 327
+#define subscript 328
+#define sliceop 329
+#define exprlist 330
+#define testlist 331
+#define dictorsetmaker 332
+#define classdef 333
+#define arglist 334
+#define argument 335
+#define comp_iter 336
+#define comp_for 337
+#define comp_if 338
+#define encoding_decl 339
+#define yield_expr 340
+#define yield_arg 341
diff --git a/Include/grammar.h b/Include/grammar.h
index 85120b9..f775f96 100644
--- a/Include/grammar.h
+++ b/Include/grammar.h
@@ -69,6 +69,7 @@ typedef struct {
/* FUNCTIONS */
grammar *newgrammar(int start);
+void freegrammar(grammar *g);
dfa *adddfa(grammar *g, int type, const char *name);
int addstate(dfa *d);
void addarc(dfa *d, int from, int to, int lbl);
diff --git a/Include/import.h b/Include/import.h
index afdfac2..46c0d8e 100644
--- a/Include/import.h
+++ b/Include/import.h
@@ -7,7 +7,9 @@
extern "C" {
#endif
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyImportZip_Init(void);
+#endif /* !Py_LIMITED_API */
PyMODINIT_FUNC PyInit_imp(void);
PyAPI_FUNC(long) PyImport_GetMagicNumber(void);
diff --git a/Include/intrcheck.h b/Include/intrcheck.h
index f53fee1..8fb96cf 100644
--- a/Include/intrcheck.h
+++ b/Include/intrcheck.h
@@ -8,12 +8,15 @@ extern "C" {
PyAPI_FUNC(int) PyOS_InterruptOccurred(void);
PyAPI_FUNC(void) PyOS_InitInterrupts(void);
PyAPI_FUNC(void) PyOS_AfterFork(void);
+
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyOS_IsMainThread(void);
#ifdef MS_WINDOWS
/* windows.h is not included by Python.h so use void* instead of HANDLE */
PyAPI_FUNC(void*) _PyOS_SigintEvent(void);
#endif
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/longintrepr.h b/Include/longintrepr.h
index bbba4d8..a3b74b4 100644
--- a/Include/longintrepr.h
+++ b/Include/longintrepr.h
@@ -42,14 +42,10 @@ extern "C" {
*/
#if PYLONG_BITS_IN_DIGIT == 30
-#if !(defined HAVE_UINT64_T && defined HAVE_UINT32_T && \
- defined HAVE_INT64_T && defined HAVE_INT32_T)
-#error "30-bit long digits requested, but the necessary types are not available on this platform"
-#endif
-typedef PY_UINT32_T digit;
-typedef PY_INT32_T sdigit; /* signed variant of digit */
-typedef PY_UINT64_T twodigits;
-typedef PY_INT64_T stwodigits; /* signed variant of twodigits */
+typedef uint32_t digit;
+typedef int32_t sdigit; /* signed variant of digit */
+typedef uint64_t twodigits;
+typedef int64_t stwodigits; /* signed variant of twodigits */
#define PyLong_SHIFT 30
#define _PyLong_DECIMAL_SHIFT 9 /* max(e such that 10**e fits in a digit) */
#define _PyLong_DECIMAL_BASE ((digit)1000000000) /* 10 ** DECIMAL_SHIFT */
diff --git a/Include/longobject.h b/Include/longobject.h
index 2a2eecf..efd409c 100644
--- a/Include/longobject.h
+++ b/Include/longobject.h
@@ -65,7 +65,8 @@ PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
# error "void* different in size from int, long and long long"
#endif /* SIZEOF_VOID_P */
-/* Used by Python/mystrtoul.c. */
+/* Used by Python/mystrtoul.c, _PyBytes_FromHex(),
+ _PyBytes_DecodeEscapeRecode(), etc. */
#ifndef Py_LIMITED_API
PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
#endif
@@ -84,14 +85,12 @@ PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
-#ifdef HAVE_LONG_LONG
-PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
-PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);
-PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
-PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
-PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
-PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
-#endif /* HAVE_LONG_LONG */
+PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
+PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
+PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
+PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
+PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
+PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
#ifndef Py_LIMITED_API
@@ -182,6 +181,13 @@ PyAPI_FUNC(int) _PyLong_FormatWriter(
int base,
int alternate);
+PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
+ _PyBytesWriter *writer,
+ char *str,
+ PyObject *obj,
+ int base,
+ int alternate);
+
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter(
@@ -198,8 +204,10 @@ PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter(
PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
+#ifndef Py_LIMITED_API
/* For use by the gcd function in mathmodule.c */
PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/methodobject.h b/Include/methodobject.h
index e2ad804..79fad82 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -16,6 +16,8 @@ PyAPI_DATA(PyTypeObject) PyCFunction_Type;
#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
+typedef PyObject *(*_PyCFunctionFast) (PyObject *self, PyObject **args,
+ Py_ssize_t nargs, PyObject *kwnames);
typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
PyObject *);
typedef PyObject *(*PyNoArgsFunction)(PyObject *);
@@ -37,6 +39,18 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
#endif
PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func,
+ PyObject **args,
+ Py_ssize_t nargs,
+ PyObject *kwargs);
+
+PyAPI_FUNC(PyObject *) _PyCFunction_FastCallKeywords(PyObject *func,
+ PyObject **stack,
+ Py_ssize_t nargs,
+ PyObject *kwnames);
+#endif
+
struct PyMethodDef {
const char *ml_name; /* The name of the built-in function/method */
PyCFunction ml_meth; /* The C function that implements it */
@@ -72,6 +86,8 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
#define METH_COEXIST 0x0040
#ifndef Py_LIMITED_API
+#define METH_FASTCALL 0x0080
+
typedef struct {
PyObject_HEAD
PyMethodDef *m_ml; /* Description of the C function to call */
diff --git a/Include/modsupport.h b/Include/modsupport.h
index 829aaf8..833e33d 100644
--- a/Include/modsupport.h
+++ b/Include/modsupport.h
@@ -15,12 +15,16 @@ extern "C" {
#define PyArg_Parse _PyArg_Parse_SizeT
#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT
#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT
+#ifndef Py_LIMITED_API
#define PyArg_VaParse _PyArg_VaParse_SizeT
#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT
+#endif /* !Py_LIMITED_API */
#define Py_BuildValue _Py_BuildValue_SizeT
#define Py_VaBuildValue _Py_VaBuildValue_SizeT
#else
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);
+#endif /* !Py_LIMITED_API */
#endif
/* Due to a glitch in 3.2, the _SizeT versions weren't exported from the DLL. */
@@ -44,6 +48,32 @@ PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
#endif
PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);
+#ifndef Py_LIMITED_API
+typedef struct _PyArg_Parser {
+ const char *format;
+ const char * const *keywords;
+ const char *fname;
+ const char *custom_msg;
+ int pos; /* number of positional-only arguments */
+ int min; /* minimal number of arguments */
+ int max; /* maximal number of positional arguments */
+ PyObject *kwtuple; /* tuple of keyword parameter names */
+ struct _PyArg_Parser *next;
+} _PyArg_Parser;
+#ifdef PY_SSIZE_T_CLEAN
+#define _PyArg_ParseTupleAndKeywordsFast _PyArg_ParseTupleAndKeywordsFast_SizeT
+#define _PyArg_ParseStack _PyArg_ParseStack_SizeT
+#define _PyArg_VaParseTupleAndKeywordsFast _PyArg_VaParseTupleAndKeywordsFast_SizeT
+#endif
+PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
+ struct _PyArg_Parser *, ...);
+PyAPI_FUNC(int) _PyArg_ParseStack(PyObject **args, Py_ssize_t nargs, PyObject *kwnames,
+ struct _PyArg_Parser *, ...);
+PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywordsFast(PyObject *, PyObject *,
+ struct _PyArg_Parser *, va_list);
+void _PyArg_Fini(void);
+#endif
+
PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);
PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
diff --git a/Include/namespaceobject.h b/Include/namespaceobject.h
index a412f05..0c8d95c 100644
--- a/Include/namespaceobject.h
+++ b/Include/namespaceobject.h
@@ -7,9 +7,11 @@
extern "C" {
#endif
+#ifndef Py_LIMITED_API
PyAPI_DATA(PyTypeObject) _PyNamespace_Type;
PyAPI_FUNC(PyObject *) _PyNamespace_New(PyObject *kwds);
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/object.h b/Include/object.h
index 50d9747..338ec1b 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -118,6 +118,7 @@ typedef struct {
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
+#ifndef Py_LIMITED_API
/********************* String Literals ****************************************/
/* This structure helps managing static strings. The basic usage goes like this:
Instead of doing
@@ -144,10 +145,12 @@ typedef struct _Py_Identifier {
PyObject *object;
} _Py_Identifier;
-#define _Py_static_string_init(value) { 0, value, 0 }
+#define _Py_static_string_init(value) { .next = NULL, .string = value, .object = NULL }
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
+#endif /* !Py_LIMITED_API */
+
/*
Type objects contain a string containing the type name (to help somewhat
in debugging), the allocation parameters (see PyObject_New() and
@@ -512,8 +515,8 @@ PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, con
#endif
/* Generic operations on objects */
-struct _Py_Identifier;
#ifndef Py_LIMITED_API
+struct _Py_Identifier;
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
PyAPI_FUNC(void) _Py_BreakPoint(void);
PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
@@ -530,11 +533,11 @@ PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
PyAPI_FUNC(int) _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *);
-#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
#endif
PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
@@ -557,6 +560,7 @@ PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
#endif
+#ifndef Py_LIMITED_API
/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
dict as the last parameter. */
PyAPI_FUNC(PyObject *)
@@ -564,6 +568,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int)
_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
PyObject *, PyObject *);
+#endif /* !Py_LIMITED_API */
/* Helper to look up a builtin object */
#ifndef Py_LIMITED_API
@@ -708,7 +713,6 @@ you can count such references to the type object.)
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
int lineno, PyObject *op);
-PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
#define _Py_INC_REFTOTAL _Py_RefTotal++
#define _Py_DEC_REFTOTAL _Py_RefTotal--
@@ -785,7 +789,7 @@ PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
--(_py_decref_tmp)->ob_refcnt != 0) \
_Py_CHECK_REFCNT(_py_decref_tmp) \
else \
- _Py_Dealloc(_py_decref_tmp); \
+ _Py_Dealloc(_py_decref_tmp); \
} while (0)
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
@@ -889,8 +893,10 @@ they can have object code that is not dependent on Python compilation flags.
PyAPI_FUNC(void) Py_IncRef(PyObject *);
PyAPI_FUNC(void) Py_DecRef(PyObject *);
+#ifndef Py_LIMITED_API
PyAPI_DATA(PyTypeObject) _PyNone_Type;
PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
+#endif /* !Py_LIMITED_API */
/*
_Py_NoneStruct is an object of undefined type which can be used in contexts
@@ -923,10 +929,12 @@ PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
#define Py_GT 4
#define Py_GE 5
+#ifndef Py_LIMITED_API
/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
* Defined in object.c.
*/
PyAPI_DATA(int) _Py_SwappedOp[];
+#endif /* !Py_LIMITED_API */
/*
@@ -1023,12 +1031,14 @@ chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,
with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
*/
+#ifndef Py_LIMITED_API
/* This is the old private API, invoked by the macros before 3.2.4.
Kept for binary compatibility of extensions using the stable ABI. */
PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
PyAPI_DATA(int) _PyTrash_delete_nesting;
PyAPI_DATA(PyObject *) _PyTrash_delete_later;
+#endif /* !Py_LIMITED_API */
/* The new thread-safe private API, invoked by the macros below. */
PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*);
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 65b6d91..c0ed9b7 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -99,8 +99,10 @@ PyAPI_FUNC(void *) PyObject_Calloc(size_t nelem, size_t elsize);
PyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size);
PyAPI_FUNC(void) PyObject_Free(void *ptr);
+#ifndef Py_LIMITED_API
/* This function returns the number of allocated memory blocks, regardless of size */
PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void);
+#endif /* !Py_LIMITED_API */
/* Macros */
#ifdef WITH_PYMALLOC
@@ -224,11 +226,12 @@ PyAPI_FUNC(void) PyObject_SetArenaAllocator(PyObjectArenaAllocator *allocator);
* ==========================
*/
-/* C equivalent of gc.collect(). */
+/* C equivalent of gc.collect() which ignores the state of gc.enabled. */
PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
#ifndef Py_LIMITED_API
PyAPI_FUNC(Py_ssize_t) _PyGC_CollectNoFail(void);
+PyAPI_FUNC(Py_ssize_t) _PyGC_CollectIfEnabled(void);
#endif
/* Test if a type has a GC head */
@@ -322,8 +325,10 @@ extern PyGC_Head *_PyGC_generation0;
(!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj)))
#endif /* Py_LIMITED_API */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t size);
PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size);
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);
PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);
PyAPI_FUNC(void) PyObject_GC_Track(void *);
diff --git a/Include/opcode.h b/Include/opcode.h
index 3f917fb..be360e1 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -60,6 +60,7 @@ extern "C" {
#define WITH_CLEANUP_FINISH 82
#define RETURN_VALUE 83
#define IMPORT_STAR 84
+#define SETUP_ANNOTATIONS 85
#define YIELD_VALUE 86
#define POP_BLOCK 87
#define END_FINALLY 88
@@ -98,18 +99,17 @@ extern "C" {
#define LOAD_FAST 124
#define STORE_FAST 125
#define DELETE_FAST 126
+#define STORE_ANNOTATION 127
#define RAISE_VARARGS 130
#define CALL_FUNCTION 131
#define MAKE_FUNCTION 132
#define BUILD_SLICE 133
-#define MAKE_CLOSURE 134
#define LOAD_CLOSURE 135
#define LOAD_DEREF 136
#define STORE_DEREF 137
#define DELETE_DEREF 138
-#define CALL_FUNCTION_VAR 140
#define CALL_FUNCTION_KW 141
-#define CALL_FUNCTION_VAR_KW 142
+#define CALL_FUNCTION_EX 142
#define SETUP_WITH 143
#define EXTENDED_ARG 144
#define LIST_APPEND 145
@@ -122,6 +122,10 @@ extern "C" {
#define BUILD_TUPLE_UNPACK 152
#define BUILD_SET_UNPACK 153
#define SETUP_ASYNC_WITH 154
+#define FORMAT_VALUE 155
+#define BUILD_CONST_KEY_MAP 156
+#define BUILD_STRING 157
+#define BUILD_TUPLE_UNPACK_WITH_CALL 158
/* EXCEPT_HANDLER is a special, implicit block type which is created when
entering an except handler. It is not an opcode but we define it here
diff --git a/Include/osmodule.h b/Include/osmodule.h
new file mode 100644
index 0000000..7146757
--- /dev/null
+++ b/Include/osmodule.h
@@ -0,0 +1,15 @@
+
+/* os module interface */
+
+#ifndef Py_OSMODULE_H
+#define Py_OSMODULE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_FUNC(PyObject *) PyOS_FSPath(PyObject *path);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_OSMODULE_H */
diff --git a/Include/patchlevel.h b/Include/patchlevel.h
index 45e5736..29da489 100644
--- a/Include/patchlevel.h
+++ b/Include/patchlevel.h
@@ -17,13 +17,13 @@
/* Version parsed out into numeric values */
/*--start constants--*/
#define PY_MAJOR_VERSION 3
-#define PY_MINOR_VERSION 5
-#define PY_MICRO_VERSION 2
-#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
-#define PY_RELEASE_SERIAL 0
+#define PY_MINOR_VERSION 6
+#define PY_MICRO_VERSION 0
+#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_BETA
+#define PY_RELEASE_SERIAL 2
/* Version as a string */
-#define PY_VERSION "3.5.2+"
+#define PY_VERSION "3.6.0b2+"
/*--end constants--*/
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
diff --git a/Include/pgenheaders.h b/Include/pgenheaders.h
index 2049ae3..4843de6 100644
--- a/Include/pgenheaders.h
+++ b/Include/pgenheaders.h
@@ -23,6 +23,7 @@ PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
#define delbitset _Py_delbitset
#define dumptree _Py_dumptree
#define findlabel _Py_findlabel
+#define freegrammar _Py_freegrammar
#define mergebitset _Py_mergebitset
#define meta_grammar _Py_meta_grammar
#define newbitset _Py_newbitset
diff --git a/Include/py_curses.h b/Include/py_curses.h
index f2c08f6..3c21697 100644
--- a/Include/py_curses.h
+++ b/Include/py_curses.h
@@ -103,8 +103,8 @@ static void **PyCurses_API;
#endif
/* general error messages */
-static char *catchall_ERR = "curses function returned ERR";
-static char *catchall_NULL = "curses function returned NULL";
+static const char catchall_ERR[] = "curses function returned ERR";
+static const char catchall_NULL[] = "curses function returned NULL";
/* Function Prototype Macros - They are ugly but very, very useful. ;-)
diff --git a/Include/pyatomic.h b/Include/pyatomic.h
index 89028ef..893d30d 100644
--- a/Include/pyatomic.h
+++ b/Include/pyatomic.h
@@ -61,7 +61,7 @@ typedef enum _Py_memory_order {
} _Py_memory_order;
typedef struct _Py_atomic_address {
- Py_uintptr_t _value;
+ uintptr_t _value;
} _Py_atomic_address;
typedef struct _Py_atomic_int {
@@ -98,7 +98,7 @@ typedef enum _Py_memory_order {
} _Py_memory_order;
typedef struct _Py_atomic_address {
- Py_uintptr_t _value;
+ uintptr_t _value;
} _Py_atomic_address;
typedef struct _Py_atomic_int {
diff --git a/Include/pydebug.h b/Include/pydebug.h
index 19bec2b..6e23a89 100644
--- a/Include/pydebug.h
+++ b/Include/pydebug.h
@@ -24,6 +24,10 @@ PyAPI_DATA(int) Py_UnbufferedStdioFlag;
PyAPI_DATA(int) Py_HashRandomizationFlag;
PyAPI_DATA(int) Py_IsolatedFlag;
+#ifdef MS_WINDOWS
+PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
+#endif
+
/* this is a wrapper around getenv() that pays attention to
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
PYTHONPATH and PYTHONHOME from the environment */
diff --git a/Include/pydtrace.d b/Include/pydtrace.d
new file mode 100644
index 0000000..8836055
--- /dev/null
+++ b/Include/pydtrace.d
@@ -0,0 +1,19 @@
+/* Python DTrace provider */
+
+provider python {
+ probe function__entry(const char *, const char *, int);
+ probe function__return(const char *, const char *, int);
+ probe instance__new__start(const char *, const char *);
+ probe instance__new__done(const char *, const char *);
+ probe instance__delete__start(const char *, const char *);
+ probe instance__delete__done(const char *, const char *);
+ probe line(const char *, const char *, int);
+ probe gc__start(int);
+ probe gc__done(long);
+};
+
+#pragma D attributes Evolving/Evolving/Common provider python provider
+#pragma D attributes Evolving/Evolving/Common provider python module
+#pragma D attributes Evolving/Evolving/Common provider python function
+#pragma D attributes Evolving/Evolving/Common provider python name
+#pragma D attributes Evolving/Evolving/Common provider python args
diff --git a/Include/pydtrace.h b/Include/pydtrace.h
new file mode 100644
index 0000000..c43a253
--- /dev/null
+++ b/Include/pydtrace.h
@@ -0,0 +1,53 @@
+/* Static DTrace probes interface */
+
+#ifndef Py_DTRACE_H
+#define Py_DTRACE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef WITH_DTRACE
+
+#include "pydtrace_probes.h"
+
+/* pydtrace_probes.h, on systems with DTrace, is auto-generated to include
+ `PyDTrace_{PROBE}` and `PyDTrace_{PROBE}_ENABLED()` macros for every probe
+ defined in pydtrace_provider.d.
+
+ Calling these functions must be guarded by a `PyDTrace_{PROBE}_ENABLED()`
+ check to minimize performance impact when probing is off. For example:
+
+ if (PyDTrace_FUNCTION_ENTRY_ENABLED())
+ PyDTrace_FUNCTION_ENTRY(f);
+*/
+
+#else
+
+/* Without DTrace, compile to nothing. */
+
+static inline void PyDTrace_LINE(const char *arg0, const char *arg1, int arg2) {}
+static inline void PyDTrace_FUNCTION_ENTRY(const char *arg0, const char *arg1, int arg2) {}
+static inline void PyDTrace_FUNCTION_RETURN(const char *arg0, const char *arg1, int arg2) {}
+static inline void PyDTrace_GC_START(int arg0) {}
+static inline void PyDTrace_GC_DONE(int arg0) {}
+static inline void PyDTrace_INSTANCE_NEW_START(int arg0) {}
+static inline void PyDTrace_INSTANCE_NEW_DONE(int arg0) {}
+static inline void PyDTrace_INSTANCE_DELETE_START(int arg0) {}
+static inline void PyDTrace_INSTANCE_DELETE_DONE(int arg0) {}
+
+static inline int PyDTrace_LINE_ENABLED(void) { return 0; }
+static inline int PyDTrace_FUNCTION_ENTRY_ENABLED(void) { return 0; }
+static inline int PyDTrace_FUNCTION_RETURN_ENABLED(void) { return 0; }
+static inline int PyDTrace_GC_START_ENABLED(void) { return 0; }
+static inline int PyDTrace_GC_DONE_ENABLED(void) { return 0; }
+static inline int PyDTrace_INSTANCE_NEW_START_ENABLED(void) { return 0; }
+static inline int PyDTrace_INSTANCE_NEW_DONE_ENABLED(void) { return 0; }
+static inline int PyDTrace_INSTANCE_DELETE_START_ENABLED(void) { return 0; }
+static inline int PyDTrace_INSTANCE_DELETE_DONE_ENABLED(void) { return 0; }
+
+#endif /* !WITH_DTRACE */
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_DTRACE_H */
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 35aedb7..f9f74c0 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -160,6 +160,7 @@ PyAPI_DATA(PyObject *) PyExc_EOFError;
PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
PyAPI_DATA(PyObject *) PyExc_OSError;
PyAPI_DATA(PyObject *) PyExc_ImportError;
+PyAPI_DATA(PyObject *) PyExc_ModuleNotFoundError;
PyAPI_DATA(PyObject *) PyExc_IndexError;
PyAPI_DATA(PyObject *) PyExc_KeyError;
PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
@@ -254,6 +255,17 @@ PyAPI_FUNC(PyObject *) PyErr_FormatV(
va_list vargs);
#endif
+#ifndef Py_LIMITED_API
+/* Like PyErr_Format(), but saves current exception as __context__ and
+ __cause__.
+ */
+PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
+ PyObject *exception,
+ const char *format, /* ASCII-encoded string */
+ ...
+ );
+#endif
+
#ifdef MS_WINDOWS
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
int ierr,
@@ -283,6 +295,9 @@ PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
PyAPI_FUNC(PyObject *) PyErr_SetExcWithArgsKwargs(PyObject *, PyObject *,
PyObject *);
+
+PyAPI_FUNC(PyObject *) PyErr_SetImportErrorSubclass(PyObject *, PyObject *,
+ PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetImportError(PyObject *, PyObject *,
PyObject *);
diff --git a/Include/pygetopt.h b/Include/pygetopt.h
index 425c7dd..962720c 100644
--- a/Include/pygetopt.h
+++ b/Include/pygetopt.h
@@ -11,9 +11,9 @@ PyAPI_DATA(int) _PyOS_optind;
PyAPI_DATA(wchar_t *) _PyOS_optarg;
PyAPI_FUNC(void) _PyOS_ResetGetOpt(void);
-#endif
PyAPI_FUNC(int) _PyOS_GetOpt(int argc, wchar_t **argv, wchar_t *optstring);
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/pyhash.h b/Include/pyhash.h
index a7ca937..a814af6 100644
--- a/Include/pyhash.h
+++ b/Include/pyhash.h
@@ -36,14 +36,14 @@ PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void*, Py_ssize_t);
* memory layout on 64 bit systems
* cccccccc cccccccc cccccccc uc -- unsigned char[24]
* pppppppp ssssssss ........ fnv -- two Py_hash_t
- * k0k0k0k0 k1k1k1k1 ........ siphash -- two PY_UINT64_T
+ * k0k0k0k0 k1k1k1k1 ........ siphash -- two uint64_t
* ........ ........ ssssssss djbx33a -- 16 bytes padding + one Py_hash_t
* ........ ........ eeeeeeee pyexpat XML hash salt
*
* memory layout on 32 bit systems
* cccccccc cccccccc cccccccc uc
* ppppssss ........ ........ fnv -- two Py_hash_t
- * k0k0k0k0 k1k1k1k1 ........ siphash -- two PY_UINT64_T (*)
+ * k0k0k0k0 k1k1k1k1 ........ siphash -- two uint64_t (*)
* ........ ........ ssss.... djbx33a -- 16 bytes padding + one Py_hash_t
* ........ ........ eeee.... pyexpat XML hash salt
*
@@ -59,13 +59,11 @@ typedef union {
Py_hash_t prefix;
Py_hash_t suffix;
} fnv;
-#ifdef PY_UINT64_T
/* two uint64 for SipHash24 */
struct {
- PY_UINT64_T k0;
- PY_UINT64_T k1;
+ uint64_t k0;
+ uint64_t k1;
} siphash;
-#endif
/* a different (!) Py_hash_t for small string optimization */
struct {
unsigned char padding[16];
@@ -121,8 +119,7 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
* configure script.
*
* - FNV is available on all platforms and architectures.
- * - SIPHASH24 only works on plaforms that provide PY_UINT64_T and doesn't
- * require aligned memory for integers.
+ * - SIPHASH24 only works on plaforms that don't require aligned memory for integers.
* - With EXTERNAL embedders can provide an alternative implementation with::
*
* PyHash_FuncDef PyHash_Func = {...};
@@ -134,8 +131,7 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
#define Py_HASH_FNV 2
#ifndef Py_HASH_ALGORITHM
-# if (defined(PY_UINT64_T) && defined(PY_UINT32_T) \
- && !defined(HAVE_ALIGNED_REQUIRED))
+# ifndef HAVE_ALIGNED_REQUIRED
# define Py_HASH_ALGORITHM Py_HASH_SIPHASH24
# else
# define Py_HASH_ALGORITHM Py_HASH_FNV
diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h
index ccdebe2..5a67666 100644
--- a/Include/pylifecycle.h
+++ b/Include/pylifecycle.h
@@ -27,6 +27,7 @@ PyAPI_FUNC(void) Py_InitializeEx(int);
PyAPI_FUNC(void) _Py_InitializeEx_Private(int, int);
#endif
PyAPI_FUNC(void) Py_Finalize(void);
+PyAPI_FUNC(int) Py_FinalizeEx(void);
PyAPI_FUNC(int) Py_IsInitialized(void);
PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
@@ -106,6 +107,7 @@ PyAPI_FUNC(void) _PyGC_Fini(void);
PyAPI_FUNC(void) PySlice_Fini(void);
PyAPI_FUNC(void) _PyType_Fini(void);
PyAPI_FUNC(void) _PyRandom_Fini(void);
+PyAPI_FUNC(void) PyAsyncGen_Fini(void);
PyAPI_DATA(PyThreadState *) _Py_Finalizing;
#endif
@@ -115,8 +117,11 @@ typedef void (*PyOS_sighandler_t)(int);
PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
+#ifndef Py_LIMITED_API
/* Random */
-PyAPI_FUNC(int) _PyOS_URandom (void *buffer, Py_ssize_t size);
+PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
+PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/pymacro.h b/Include/pymacro.h
index 3f6f5dc..2a839ab 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -18,6 +18,9 @@
by "__LINE__". */
#define Py_STRINGIFY(x) _Py_XSTRINGIFY(x)
+/* Get the size of a structure member in bytes */
+#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
+
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
@@ -36,6 +39,10 @@
#define Py_BUILD_ASSERT_EXPR(cond) \
(sizeof(char [1 - 2*!(cond)]) - 1)
+#define Py_BUILD_ASSERT(cond) do { \
+ (void)Py_BUILD_ASSERT_EXPR(cond); \
+ } while(0)
+
/* Get the number of elements in a visible array
This does not work on pointers, or arrays declared as [], or function
@@ -75,12 +82,12 @@
#define _Py_SIZE_ROUND_UP(n, a) (((size_t)(n) + \
(size_t)((a) - 1)) & ~(size_t)((a) - 1))
/* Round pointer "p" down to the closest "a"-aligned address <= "p". */
-#define _Py_ALIGN_DOWN(p, a) ((void *)((Py_uintptr_t)(p) & ~(Py_uintptr_t)((a) - 1)))
+#define _Py_ALIGN_DOWN(p, a) ((void *)((uintptr_t)(p) & ~(uintptr_t)((a) - 1)))
/* Round pointer "p" up to the closest "a"-aligned address >= "p". */
-#define _Py_ALIGN_UP(p, a) ((void *)(((Py_uintptr_t)(p) + \
- (Py_uintptr_t)((a) - 1)) & ~(Py_uintptr_t)((a) - 1)))
+#define _Py_ALIGN_UP(p, a) ((void *)(((uintptr_t)(p) + \
+ (uintptr_t)((a) - 1)) & ~(uintptr_t)((a) - 1)))
/* Check if pointer "p" is aligned to "a"-bytes boundary. */
-#define _Py_IS_ALIGNED(p, a) (!((Py_uintptr_t)(p) & (Py_uintptr_t)((a) - 1)))
+#define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))
#ifdef __GNUC__
#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
diff --git a/Include/pymath.h b/Include/pymath.h
index 1c8d718..7216a09 100644
--- a/Include/pymath.h
+++ b/Include/pymath.h
@@ -55,6 +55,12 @@ extern double pow(double, double);
#define Py_MATH_E 2.7182818284590452354
#endif
+/* Tau (2pi) to 40 digits, taken from tauday.com/tau-digits. */
+#ifndef Py_MATH_TAU
+#define Py_MATH_TAU 6.2831853071795864769252867665590057683943L
+#endif
+
+
/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU
register and into a 64-bit memory location, rounding from extended
precision to double precision in the process. On other platforms it does
@@ -169,7 +175,7 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
#pragma float_control (pop)
#define Py_NAN __icc_nan()
#else /* ICC_NAN_RELAXED as default for Intel Compiler */
- static union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
+ static const union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
#define Py_NAN (__nan_store.__icc_nan)
#endif /* ICC_NAN_STRICT */
#endif /* __INTEL_COMPILER */
diff --git a/Include/pymem.h b/Include/pymem.h
index 043db64..ce63bf8 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -16,8 +16,51 @@ PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);
PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize);
PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);
PyAPI_FUNC(void) PyMem_RawFree(void *ptr);
+
+/* Configure the Python memory allocators. Pass NULL to use default
+ allocators. */
+PyAPI_FUNC(int) _PyMem_SetupAllocators(const char *opt);
+
+#ifdef WITH_PYMALLOC
+PyAPI_FUNC(int) _PyMem_PymallocEnabled(void);
#endif
+/* Identifier of an address space (domain) in tracemalloc */
+typedef unsigned int _PyTraceMalloc_domain_t;
+
+/* Track an allocated memory block in the tracemalloc module.
+ Return 0 on success, return -1 on error (failed to allocate memory to store
+ the trace).
+
+ Return -2 if tracemalloc is disabled.
+
+ If memory block is already tracked, update the existing trace. */
+PyAPI_FUNC(int) _PyTraceMalloc_Track(
+ _PyTraceMalloc_domain_t domain,
+ uintptr_t ptr,
+ size_t size);
+
+/* Untrack an allocated memory block in the tracemalloc module.
+ Do nothing if the block was not tracked.
+
+ Return -2 if tracemalloc is disabled, otherwise return 0. */
+PyAPI_FUNC(int) _PyTraceMalloc_Untrack(
+ _PyTraceMalloc_domain_t domain,
+ uintptr_t ptr);
+
+/* Get the traceback where a memory block was allocated.
+
+ Return a tuple of (filename: str, lineno: int) tuples.
+
+ Return None if the tracemalloc module is disabled or if the memory block
+ is not tracked by tracemalloc.
+
+ Raise an exception and return NULL on error. */
+PyAPI_FUNC(PyObject*) _PyTraceMalloc_GetTraceback(
+ _PyTraceMalloc_domain_t domain,
+ uintptr_t ptr);
+#endif /* !Py_LIMITED_API */
+
/* BEWARE:
diff --git a/Include/pyport.h b/Include/pyport.h
index e7e5178..20f3db7 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -3,15 +3,7 @@
#include "pyconfig.h" /* include for defines */
-/* Some versions of HP-UX & Solaris need inttypes.h for int32_t,
- INT32_MAX, etc. */
-#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
-#endif
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to basic
@@ -31,14 +23,6 @@ Py_DEBUG
Meaning: Extra checks compiled in for debug mode.
Used in: Py_SAFE_DOWNCAST
-HAVE_UINTPTR_T
-Meaning: The C9X type uintptr_t is supported by the compiler
-Used in: Py_uintptr_t
-
-HAVE_LONG_LONG
-Meaning: The compiler supports the C type "long long"
-Used in: PY_LONG_LONG
-
**************************************************************************/
/* typedefs for some C9X-defined synonyms for integral types.
@@ -53,91 +37,30 @@ Used in: PY_LONG_LONG
* integral synonyms. Only define the ones we actually need.
*/
-#ifdef HAVE_LONG_LONG
+// long long is required now. Define HAVE_LONG_LONG unconditionally for
+// compatibility.
+#define HAVE_LONG_LONG
#ifndef PY_LONG_LONG
#define PY_LONG_LONG long long
-#if defined(LLONG_MAX)
/* If LLONG_MAX is defined in limits.h, use that. */
#define PY_LLONG_MIN LLONG_MIN
#define PY_LLONG_MAX LLONG_MAX
#define PY_ULLONG_MAX ULLONG_MAX
-#elif defined(__LONG_LONG_MAX__)
-/* Otherwise, if GCC has a builtin define, use that. (Definition of
- * PY_LLONG_MIN assumes two's complement with no trap representation.) */
-#define PY_LLONG_MAX __LONG_LONG_MAX__
-#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
-#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
-#elif defined(SIZEOF_LONG_LONG)
-/* Otherwise compute from SIZEOF_LONG_LONG, assuming two's complement, no
- padding bits, and no trap representation. Note: PY_ULLONG_MAX was
- previously #defined as (~0ULL) here; but that'll give the wrong value in a
- preprocessor expression on systems where long long != intmax_t. */
-#define PY_LLONG_MAX \
- (1 + 2 * ((Py_LL(1) << (CHAR_BIT * SIZEOF_LONG_LONG - 2)) - 1))
-#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
-#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
-#endif /* LLONG_MAX */
-#endif
-#endif /* HAVE_LONG_LONG */
-
-/* a build with 30-bit digits for Python integers needs an exact-width
- * 32-bit unsigned integer type to store those digits. (We could just use
- * type 'unsigned long', but that would be wasteful on a system where longs
- * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines
- * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
- * However, it doesn't set HAVE_UINT32_T, so we do that here.
- */
-#ifdef uint32_t
-#define HAVE_UINT32_T 1
#endif
-#ifdef HAVE_UINT32_T
-#ifndef PY_UINT32_T
#define PY_UINT32_T uint32_t
-#endif
-#endif
-
-/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
- * integer implementation, when 30-bit digits are enabled.
- */
-#ifdef uint64_t
-#define HAVE_UINT64_T 1
-#endif
-
-#ifdef HAVE_UINT64_T
-#ifndef PY_UINT64_T
#define PY_UINT64_T uint64_t
-#endif
-#endif
/* Signed variants of the above */
-#ifdef int32_t
-#define HAVE_INT32_T 1
-#endif
-
-#ifdef HAVE_INT32_T
-#ifndef PY_INT32_T
#define PY_INT32_T int32_t
-#endif
-#endif
-
-#ifdef int64_t
-#define HAVE_INT64_T 1
-#endif
-
-#ifdef HAVE_INT64_T
-#ifndef PY_INT64_T
#define PY_INT64_T int64_t
-#endif
-#endif
/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
the necessary integer types are available, and we're on a 64-bit platform
(as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
#ifndef PYLONG_BITS_IN_DIGIT
-#if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \
- defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)
+#if SIZEOF_VOID_P >= 8
#define PYLONG_BITS_IN_DIGIT 30
#else
#define PYLONG_BITS_IN_DIGIT 15
@@ -149,26 +72,9 @@ Used in: PY_LONG_LONG
* without loss of information. Similarly for intptr_t, wrt a signed
* integral type.
*/
-#ifdef HAVE_UINTPTR_T
typedef uintptr_t Py_uintptr_t;
typedef intptr_t Py_intptr_t;
-#elif SIZEOF_VOID_P <= SIZEOF_INT
-typedef unsigned int Py_uintptr_t;
-typedef int Py_intptr_t;
-
-#elif SIZEOF_VOID_P <= SIZEOF_LONG
-typedef unsigned long Py_uintptr_t;
-typedef long Py_intptr_t;
-
-#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
-typedef unsigned PY_LONG_LONG Py_uintptr_t;
-typedef PY_LONG_LONG Py_intptr_t;
-
-#else
-# error "Python needs a typedef for Py_uintptr_t in pyport.h."
-#endif /* HAVE_UINTPTR_T */
-
/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
* sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
* unsigned integral type). See PEP 353 for details.
@@ -195,16 +101,8 @@ typedef Py_ssize_t Py_ssize_clean_t;
typedef int Py_ssize_clean_t;
#endif
-/* Largest possible value of size_t.
- SIZE_MAX is part of C99, so it might be defined on some
- platforms. If it is not defined, (size_t)-1 is a portable
- definition for C89, due to the way signed->unsigned
- conversion is defined. */
-#ifdef SIZE_MAX
+/* Largest possible value of size_t. */
#define PY_SIZE_MAX SIZE_MAX
-#else
-#define PY_SIZE_MAX ((size_t)-1)
-#endif
/* Largest positive value of type Py_ssize_t. */
#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
@@ -247,22 +145,6 @@ typedef int Py_ssize_clean_t;
# endif
#endif
-/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for
- * the long long type instead of the size_t type. It's only available
- * when HAVE_LONG_LONG is defined. The "high level" Python format
- * functions listed above will interpret "lld" or "llu" correctly on
- * all platforms.
- */
-#ifdef HAVE_LONG_LONG
-# ifndef PY_FORMAT_LONG_LONG
-# ifdef MS_WINDOWS
-# define PY_FORMAT_LONG_LONG "I64"
-# else
-# error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
-# endif
-# endif
-#endif
-
/* Py_LOCAL can be used instead of static to get the fastest possible calling
* convention for functions that are local to a given module.
*
@@ -298,26 +180,9 @@ typedef int Py_ssize_clean_t;
#define Py_LOCAL_INLINE(type) static type
#endif
-/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
- * are often very short. While most platforms have highly optimized code for
- * large transfers, the setup costs for memcpy are often quite high. MEMCPY
- * solves this by doing short copies "in line".
- */
-
-#if defined(_MSC_VER)
-#define Py_MEMCPY(target, source, length) do { \
- size_t i_, n_ = (length); \
- char *t_ = (void*) (target); \
- const char *s_ = (void*) (source); \
- if (n_ >= 16) \
- memcpy(t_, s_, n_); \
- else \
- for (i_ = 0; i_ < n_; i_++) \
- t_[i_] = s_[i_]; \
- } while (0)
-#else
+/* Py_MEMCPY is kept for backwards compatibility,
+ * see https://bugs.python.org/issue28126 */
#define Py_MEMCPY memcpy
-#endif
#include <stdlib.h>
@@ -570,18 +435,18 @@ extern "C" {
#define HAVE_PY_SET_53BIT_PRECISION 1
#define _Py_SET_53BIT_PRECISION_HEADER \
unsigned int old_fpcr, new_fpcr
-#define _Py_SET_53BIT_PRECISION_START \
- do { \
- __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
- /* Set double precision / round to nearest. */ \
- new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
- if (new_fpcr != old_fpcr) \
- __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \
+#define _Py_SET_53BIT_PRECISION_START \
+ do { \
+ __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
+ /* Set double precision / round to nearest. */ \
+ new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
+ if (new_fpcr != old_fpcr) \
+ __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \
} while (0)
-#define _Py_SET_53BIT_PRECISION_END \
- do { \
- if (new_fpcr != old_fpcr) \
- __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
+#define _Py_SET_53BIT_PRECISION_END \
+ do { \
+ if (new_fpcr != old_fpcr) \
+ __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
} while (0)
#endif
@@ -850,10 +715,6 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
#endif
-/*
- * Older Microsoft compilers don't support the C99 long long literal suffixes,
- * so these will be defined in PC/pyconfig.h for those compilers.
- */
#ifndef Py_LL
#define Py_LL(x) x##LL
#endif
@@ -862,15 +723,7 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
#define Py_ULL(x) Py_LL(x##U)
#endif
-#ifdef VA_LIST_IS_ARRAY
-#define Py_VA_COPY(x, y) Py_MEMCPY((x), (y), sizeof(va_list))
-#else
-#ifdef __va_copy
-#define Py_VA_COPY __va_copy
-#else
-#define Py_VA_COPY(x, y) (x) = (y)
-#endif
-#endif
+#define Py_VA_COPY va_copy
/*
* Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is
@@ -906,4 +759,8 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
#endif /* _MSC_VER >= 1900 */
#endif /* Py_BUILD_CORE */
+#ifdef __ANDROID__
+#include <android/api-level.h>
+#endif
+
#endif /* Py_PYPORT_H */
diff --git a/Include/pystate.h b/Include/pystate.h
index 0499a74..afc3c0c 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -8,14 +8,21 @@
extern "C" {
#endif
+/* This limitation is for performance and simplicity. If needed it can be
+removed (with effort). */
+#define MAX_CO_EXTRA_USERS 255
+
/* State shared between threads */
struct _ts; /* Forward */
struct _is; /* Forward */
+struct _frame; /* Forward declaration for PyFrameObject. */
#ifdef Py_LIMITED_API
typedef struct _is PyInterpreterState;
#else
+typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
+
typedef struct _is {
struct _is *next;
@@ -36,19 +43,17 @@ typedef struct _is {
#ifdef HAVE_DLOPEN
int dlopenflags;
#endif
-#ifdef WITH_TSC
- int tscdump;
-#endif
PyObject *builtins_copy;
+ PyObject *import_func;
+ /* Initialized to PyEval_EvalFrameDefault(). */
+ _PyFrameEvalFunction eval_frame;
} PyInterpreterState;
#endif
/* State unique per thread */
-struct _frame; /* Avoid including frameobject.h */
-
#ifndef Py_LIMITED_API
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
@@ -137,6 +142,12 @@ typedef struct _ts {
PyObject *coroutine_wrapper;
int in_coroutine_wrapper;
+ Py_ssize_t co_extra_user_count;
+ freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS];
+
+ PyObject *async_gen_firstiter;
+ PyObject *async_gen_finalizer;
+
/* XXX signal handlers should also be here */
} PyThreadState;
@@ -146,7 +157,9 @@ typedef struct _ts {
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyState_AddModule(PyObject*, struct PyModuleDef*);
+#endif /* !Py_LIMITED_API */
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
/* New in 3.3 */
PyAPI_FUNC(int) PyState_AddModule(PyObject*, struct PyModuleDef*);
@@ -158,14 +171,20 @@ PyAPI_FUNC(void) _PyState_ClearModules(void);
#endif
PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *);
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate);
+#endif /* !Py_LIMITED_API */
#ifdef WITH_THREAD
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyGILState_Reinit(void);
+#endif /* !Py_LIMITED_API */
#endif
/* Return the current thread state. The global interpreter lock must be held.
@@ -173,9 +192,11 @@ PyAPI_FUNC(void) _PyGILState_Reinit(void);
* the caller needn't check for NULL). */
PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
+#ifndef Py_LIMITED_API
/* Similar to PyThreadState_Get(), but don't issue a fatal error
* if it is NULL. */
PyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void);
+#endif /* !Py_LIMITED_API */
PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
@@ -241,11 +262,23 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
*/
PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
-/* Helper/diagnostic function - return 1 if the current thread
- * currently holds the GIL, 0 otherwise
- */
#ifndef Py_LIMITED_API
+/* Issue #26558: Flag to disable PyGILState_Check().
+ If set to non-zero, PyGILState_Check() always return 1. */
+PyAPI_DATA(int) _PyGILState_check_enabled;
+
+/* Helper/diagnostic function - return 1 if the current thread
+ currently holds the GIL, 0 otherwise.
+
+ The function returns 1 if _PyGILState_check_enabled is non-zero. */
PyAPI_FUNC(int) PyGILState_Check(void);
+
+/* Unsafe function to get the single PyInterpreterState used by this process'
+ GILState implementation.
+
+ Return NULL before _PyGILState_Init() is called and after _PyGILState_Fini()
+ is called. */
+PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void);
#endif
#endif /* #ifdef WITH_THREAD */
diff --git a/Include/pystrhex.h b/Include/pystrhex.h
index 1dc1255..66a30e2 100644
--- a/Include/pystrhex.h
+++ b/Include/pystrhex.h
@@ -5,10 +5,12 @@
extern "C" {
#endif
+#ifndef Py_LIMITED_API
/* Returns a str() containing the hex representation of argbuf. */
PyAPI_FUNC(PyObject*) _Py_strhex(const char* argbuf, const Py_ssize_t arglen);
/* Returns a bytes() containing the ASCII hex representation of argbuf. */
PyAPI_FUNC(PyObject*) _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen);
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/pystrtod.h b/Include/pystrtod.h
index 23fd1c6..c1e84de 100644
--- a/Include/pystrtod.h
+++ b/Include/pystrtod.h
@@ -19,6 +19,10 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
int *type);
#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) _Py_string_to_number_with_underscores(
+ const char *str, Py_ssize_t len, const char *what, PyObject *obj, void *arg,
+ PyObject *(*innerfunc)(const char *, Py_ssize_t, void *));
+
PyAPI_FUNC(double) _Py_parse_inf_or_nan(const char *p, char **endptr);
#endif
diff --git a/Include/pythonrun.h b/Include/pythonrun.h
index 9c2e813..cfa0a9f 100644
--- a/Include/pythonrun.h
+++ b/Include/pythonrun.h
@@ -66,8 +66,8 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
const char *filename, /* decoded from the filesystem encoding */
const char* enc,
int start,
- char *ps1,
- char *ps2,
+ const char *ps1,
+ const char *ps2,
PyCompilerFlags *flags,
int *errcode,
PyArena *arena);
@@ -76,8 +76,8 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
PyObject *filename,
const char* enc,
int start,
- char *ps1,
- char *ps2,
+ const char *ps1,
+ const char *ps2,
PyCompilerFlags *flags,
int *errcode,
PyArena *arena);
diff --git a/Include/pythread.h b/Include/pythread.h
index 6e9f303..dd681be 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -37,19 +37,14 @@ PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
module exposes a higher-level API, with timeouts expressed in seconds
and floating-point numbers allowed.
*/
-#if defined(HAVE_LONG_LONG)
-#define PY_TIMEOUT_T PY_LONG_LONG
+#define PY_TIMEOUT_T long long
#define PY_TIMEOUT_MAX PY_LLONG_MAX
-#else
-#define PY_TIMEOUT_T long
-#define PY_TIMEOUT_MAX LONG_MAX
-#endif
/* In the NT API, the timeout is a DWORD and is expressed in milliseconds */
#if defined (NT_THREADS)
-#if (Py_LL(0xFFFFFFFF) * 1000 < PY_TIMEOUT_MAX)
+#if 0xFFFFFFFFLL * 1000 < PY_TIMEOUT_MAX
#undef PY_TIMEOUT_MAX
-#define PY_TIMEOUT_MAX (Py_LL(0xFFFFFFFF) * 1000)
+#define PY_TIMEOUT_MAX (0xFFFFFFFFLL * 1000)
#endif
#endif
diff --git a/Include/pytime.h b/Include/pytime.h
index 494322c..87ac7fc 100644
--- a/Include/pytime.h
+++ b/Include/pytime.h
@@ -13,16 +13,12 @@ functions and constants
extern "C" {
#endif
-#ifdef PY_INT64_T
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
store a duration, and so indirectly a date (related to another date, like
UNIX epoch). */
-typedef PY_INT64_T _PyTime_t;
+typedef int64_t _PyTime_t;
#define _PyTime_MIN PY_LLONG_MIN
#define _PyTime_MAX PY_LLONG_MAX
-#else
-# error "_PyTime_t need signed 64-bit integer type"
-#endif
typedef enum {
/* Round towards minus infinity (-inf).
@@ -30,7 +26,10 @@ typedef enum {
_PyTime_ROUND_FLOOR=0,
/* Round towards infinity (+inf).
For example, used for timeout to wait "at least" N seconds. */
- _PyTime_ROUND_CEILING
+ _PyTime_ROUND_CEILING=1,
+ /* Round to nearest with ties going to nearest even integer.
+ For example, used to round from a Python float. */
+ _PyTime_ROUND_HALF_EVEN
} _PyTime_round_t;
/* Convert a time_t to a PyLong. */
@@ -75,7 +74,7 @@ PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds);
((_PyTime_t)(seconds) * (1000 * 1000 * 1000))
/* Create a timestamp from a number of nanoseconds. */
-PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(PY_LONG_LONG ns);
+PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(long long ns);
/* Convert a number of seconds (Python float or int) to a timetamp.
Raise an exception and return -1 on error, return 0 on success. */
@@ -185,6 +184,14 @@ PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo(
Return 0 on success, raise an exception and return -1 on error. */
PyAPI_FUNC(int) _PyTime_Init(void);
+/* Converts a timestamp to the Gregorian time, using the local time zone.
+ Return 0 on success, raise an exception and return -1 on error. */
+PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm);
+
+/* Converts a timestamp to the Gregorian time, assuming UTC.
+ Return 0 on success, raise an exception and return -1 on error. */
+PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm);
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/setobject.h b/Include/setobject.h
index f17bc1b..87ec1c8 100644
--- a/Include/setobject.h
+++ b/Include/setobject.h
@@ -10,12 +10,13 @@ extern "C" {
/* There are three kinds of entries in the table:
-1. Unused: key == NULL
-2. Active: key != NULL and key != dummy
-3. Dummy: key == dummy
+1. Unused: key == NULL and hash == 0
+2. Dummy: key == dummy and hash == -1
+3. Active: key != NULL and key != dummy and hash != -1
-The hash field of Unused slots have no meaning.
-The hash field of Dummny slots are set to -1
+The hash field of Unused slots is always zero.
+
+The hash field of Dummy slots are set to -1
meaning that dummy entries can be detected by
either entry->key==dummy or by entry->hash==-1.
*/
diff --git a/Include/structmember.h b/Include/structmember.h
index 948f690..5da8a46 100644
--- a/Include/structmember.h
+++ b/Include/structmember.h
@@ -49,10 +49,8 @@ typedef struct PyMemberDef {
#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
when the value is NULL, instead of
converting to None. */
-#ifdef HAVE_LONG_LONG
#define T_LONGLONG 17
#define T_ULONGLONG 18
-#endif /* HAVE_LONG_LONG */
#define T_PYSSIZET 19 /* Py_ssize_t */
#define T_NONE 20 /* Value is always None */
diff --git a/Include/symtable.h b/Include/symtable.h
index 1409cd9..86ae3c2 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -48,6 +48,7 @@ typedef struct _symtable_entry {
unsigned ste_child_free : 1; /* true if a child block has free vars,
including free refs to globals */
unsigned ste_generator : 1; /* true if namespace is a generator */
+ unsigned ste_coroutine : 1; /* true if namespace is a coroutine */
unsigned ste_varargs : 1; /* true if block has varargs */
unsigned ste_varkeywords : 1; /* true if block has varkeywords */
unsigned ste_returns_value : 1; /* true if namespace uses return with
@@ -91,6 +92,7 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define DEF_FREE 2<<4 /* name used but not defined in nested block */
#define DEF_FREE_CLASS 2<<5 /* free variable from class's method */
#define DEF_IMPORT 2<<6 /* assignment occurred via import */
+#define DEF_ANNOT 2<<7 /* this name is annotated */
#define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
diff --git a/Include/sysmodule.h b/Include/sysmodule.h
index cde10ac..c5547ff 100644
--- a/Include/sysmodule.h
+++ b/Include/sysmodule.h
@@ -8,11 +8,11 @@ extern "C" {
#endif
PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
+PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key);
-#endif
-PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *);
+#endif
PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);
diff --git a/Include/traceback.h b/Include/traceback.h
index c3ecbe2..b587410 100644
--- a/Include/traceback.h
+++ b/Include/traceback.h
@@ -31,6 +31,7 @@ PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int);
PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
#define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type)
+#ifndef Py_LIMITED_API
/* Write the Python traceback into the file 'fd'. For example:
Traceback (most recent call first):
@@ -53,19 +54,64 @@ PyAPI_FUNC(void) _Py_DumpTraceback(
PyThreadState *tstate);
/* Write the traceback of all threads into the file 'fd'. current_thread can be
- NULL. Return NULL on success, or an error message on error.
+ NULL.
+
+ Return NULL on success, or an error message on error.
This function is written for debug purpose only. It calls
_Py_DumpTraceback() for each thread, and so has the same limitations. It
only write the traceback of the first 100 threads: write "..." if there are
more threads.
+ If current_tstate is NULL, the function tries to get the Python thread state
+ of the current thread. It is not an error if the function is unable to get
+ the current Python thread state.
+
+ If interp is NULL, the function tries to get the interpreter state from
+ the current Python thread state, or from
+ _PyGILState_GetInterpreterStateUnsafe() in last resort.
+
+ It is better to pass NULL to interp and current_tstate, the function tries
+ different options to retrieve these informations.
+
This function is signal safe. */
PyAPI_FUNC(const char*) _Py_DumpTracebackThreads(
- int fd, PyInterpreterState *interp,
- PyThreadState *current_thread);
+ int fd,
+ PyInterpreterState *interp,
+ PyThreadState *current_tstate);
+#endif /* !Py_LIMITED_API */
+
+#ifndef Py_LIMITED_API
+
+/* Write a Unicode object into the file descriptor fd. Encode the string to
+ ASCII using the backslashreplace error handler.
+
+ Do nothing if text is not a Unicode object. The function accepts Unicode
+ string which is not ready (PyUnicode_WCHAR_KIND).
+
+ This function is signal safe. */
+PyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text);
+
+/* Format an integer as decimal into the file descriptor fd.
+
+ This function is signal safe. */
+PyAPI_FUNC(void) _Py_DumpDecimal(
+ int fd,
+ unsigned long value);
+
+/* Format an integer as hexadecimal into the file descriptor fd with at least
+ width digits.
+
+ The maximum width is sizeof(unsigned long)*2 digits.
+
+ This function is signal safe. */
+PyAPI_FUNC(void) _Py_DumpHexadecimal(
+ int fd,
+ unsigned long value,
+ Py_ssize_t width);
+#endif /* !Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 2c496ea..643d10d 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -103,10 +103,6 @@ typedef wchar_t Py_UNICODE;
# endif
#endif
-#if defined(MS_WINDOWS)
-# define HAVE_MBCS
-#endif
-
#ifdef HAVE_WCHAR_H
/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */
# ifdef _HAVE_BSDI
@@ -117,21 +113,9 @@ typedef wchar_t Py_UNICODE;
/* Py_UCS4 and Py_UCS2 are typedefs for the respective
unicode representations. */
-#if SIZEOF_INT == 4
-typedef unsigned int Py_UCS4;
-#elif SIZEOF_LONG == 4
-typedef unsigned long Py_UCS4;
-#else
-#error "Could not find a proper typedef for Py_UCS4"
-#endif
-
-#if SIZEOF_SHORT == 2
-typedef unsigned short Py_UCS2;
-#else
-#error "Could not find a proper typedef for Py_UCS2"
-#endif
-
-typedef unsigned char Py_UCS1;
+typedef uint32_t Py_UCS4;
+typedef uint16_t Py_UCS2;
+typedef uint8_t Py_UCS1;
/* --- Internal Unicode Operations ---------------------------------------- */
@@ -172,7 +156,7 @@ typedef unsigned char Py_UCS1;
Py_UNICODE_ISNUMERIC(ch))
#define Py_UNICODE_COPY(target, source, length) \
- Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE))
+ memcpy((target), (source), (length)*sizeof(Py_UNICODE))
#define Py_UNICODE_FILL(target, value, length) \
do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\
@@ -900,7 +884,7 @@ typedef struct {
/* minimum character (default: 127, ASCII) */
Py_UCS4 min_char;
- /* If non-zero, overallocate the buffer by 25% (default: 0). */
+ /* If non-zero, overallocate the buffer (default: 0). */
unsigned char overallocate;
/* If readonly is 1, buffer is a shared string (cannot be modified)
@@ -934,6 +918,23 @@ PyAPI_FUNC(int)
_PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
Py_ssize_t length, Py_UCS4 maxchar);
+/* Prepare the buffer to have at least the kind KIND.
+ For example, kind=PyUnicode_2BYTE_KIND ensures that the writer will
+ support characters in range U+000-U+FFFF.
+
+ Return 0 on success, raise an exception and return -1 on error. */
+#define _PyUnicodeWriter_PrepareKind(WRITER, KIND) \
+ (assert((KIND) != PyUnicode_WCHAR_KIND), \
+ (KIND) <= (WRITER)->kind \
+ ? 0 \
+ : _PyUnicodeWriter_PrepareKindInternal((WRITER), (KIND)))
+
+/* Don't call this function directly, use the _PyUnicodeWriter_PrepareKind()
+ macro instead. */
+PyAPI_FUNC(int)
+_PyUnicodeWriter_PrepareKindInternal(_PyUnicodeWriter *writer,
+ enum PyUnicode_Kind kind);
+
/* Append a Unicode character.
Return 0 on success, raise an exception and return -1 on error. */
PyAPI_FUNC(int)
@@ -1640,13 +1641,13 @@ PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(
);
#endif
-#ifdef HAVE_MBCS
+#ifdef MS_WINDOWS
/* --- MBCS codecs for Windows -------------------------------------------- */
PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS(
const char *string, /* MBCS encoded string */
- Py_ssize_t length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
@@ -1683,7 +1684,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeCodePage(
const char *errors /* error handling */
);
-#endif /* HAVE_MBCS */
+#endif /* MS_WINDOWS */
/* --- Decimal Encoder ---------------------------------------------------- */
@@ -1938,6 +1939,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_Join(
PyObject *seq /* Sequence object */
);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray(
+ PyObject *separator,
+ PyObject **items,
+ Py_ssize_t seqlen
+ );
+#endif /* Py_LIMITED_API */
+
/* Return 1 if substr matches str[start:end] at the given tail end, 0
otherwise. */
@@ -2248,11 +2257,17 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
int check_content);
#endif
+#ifndef Py_LIMITED_API
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
/* Clear all static strings. */
PyAPI_FUNC(void) _PyUnicode_ClearStaticStrings(void);
+/* Fast equality check when the inputs are known to be exact unicode types
+ and where the hash values are equal (i.e. a very probable match) */
+PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *);
+#endif /* !Py_LIMITED_API */
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/warnings.h b/Include/warnings.h
index effb9fad..c1c6992 100644
--- a/Include/warnings.h
+++ b/Include/warnings.h
@@ -17,6 +17,13 @@ PyAPI_FUNC(int) PyErr_WarnFormat(
Py_ssize_t stack_level,
const char *format, /* ASCII-encoded string */
...);
+
+/* Emit a ResourceWarning warning */
+PyAPI_FUNC(int) PyErr_ResourceWarning(
+ PyObject *source,
+ Py_ssize_t stack_level,
+ const char *format, /* ASCII-encoded string */
+ ...);
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyErr_WarnExplicitObject(
PyObject *category,
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 8bebd69..ee7d0f1 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -10,8 +10,8 @@ from abc import ABCMeta, abstractmethod
import sys
__all__ = ["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator",
- "Hashable", "Iterable", "Iterator", "Generator",
- "Sized", "Container", "Callable",
+ "Hashable", "Iterable", "Iterator", "Generator", "Reversible",
+ "Sized", "Container", "Callable", "Collection",
"Set", "MutableSet",
"Mapping", "MutableMapping",
"MappingView", "KeysView", "ItemsView", "ValuesView",
@@ -63,6 +63,18 @@ del _coro
### ONE-TRICK PONIES ###
+def _check_methods(C, *methods):
+ mro = C.__mro__
+ for method in methods:
+ for B in mro:
+ if method in B.__dict__:
+ if B.__dict__[method] is None:
+ return NotImplemented
+ break
+ else:
+ return NotImplemented
+ return True
+
class Hashable(metaclass=ABCMeta):
__slots__ = ()
@@ -74,11 +86,7 @@ class Hashable(metaclass=ABCMeta):
@classmethod
def __subclasshook__(cls, C):
if cls is Hashable:
- for B in C.__mro__:
- if "__hash__" in B.__dict__:
- if B.__dict__["__hash__"]:
- return True
- break
+ return _check_methods(C, "__hash__")
return NotImplemented
@@ -93,11 +101,7 @@ class Awaitable(metaclass=ABCMeta):
@classmethod
def __subclasshook__(cls, C):
if cls is Awaitable:
- for B in C.__mro__:
- if "__await__" in B.__dict__:
- if B.__dict__["__await__"]:
- return True
- break
+ return _check_methods(C, "__await__")
return NotImplemented
@@ -138,14 +142,7 @@ class Coroutine(Awaitable):
@classmethod
def __subclasshook__(cls, C):
if cls is Coroutine:
- mro = C.__mro__
- for method in ('__await__', 'send', 'throw', 'close'):
- for base in mro:
- if method in base.__dict__:
- break
- else:
- return NotImplemented
- return True
+ return _check_methods(C, '__await__', 'send', 'throw', 'close')
return NotImplemented
@@ -163,8 +160,7 @@ class AsyncIterable(metaclass=ABCMeta):
@classmethod
def __subclasshook__(cls, C):
if cls is AsyncIterable:
- if any("__aiter__" in B.__dict__ for B in C.__mro__):
- return True
+ return _check_methods(C, "__aiter__")
return NotImplemented
@@ -183,9 +179,7 @@ class AsyncIterator(AsyncIterable):
@classmethod
def __subclasshook__(cls, C):
if cls is AsyncIterator:
- if (any("__anext__" in B.__dict__ for B in C.__mro__) and
- any("__aiter__" in B.__dict__ for B in C.__mro__)):
- return True
+ return _check_methods(C, "__anext__", "__aiter__")
return NotImplemented
@@ -201,8 +195,7 @@ class Iterable(metaclass=ABCMeta):
@classmethod
def __subclasshook__(cls, C):
if cls is Iterable:
- if any("__iter__" in B.__dict__ for B in C.__mro__):
- return True
+ return _check_methods(C, "__iter__")
return NotImplemented
@@ -221,9 +214,7 @@ class Iterator(Iterable):
@classmethod
def __subclasshook__(cls, C):
if cls is Iterator:
- if (any("__next__" in B.__dict__ for B in C.__mro__) and
- any("__iter__" in B.__dict__ for B in C.__mro__)):
- return True
+ return _check_methods(C, '__iter__', '__next__')
return NotImplemented
Iterator.register(bytes_iterator)
@@ -242,6 +233,22 @@ Iterator.register(tuple_iterator)
Iterator.register(zip_iterator)
+class Reversible(Iterable):
+
+ __slots__ = ()
+
+ @abstractmethod
+ def __reversed__(self):
+ while False:
+ yield None
+
+ @classmethod
+ def __subclasshook__(cls, C):
+ if cls is Reversible:
+ return _check_methods(C, "__reversed__", "__iter__")
+ return NotImplemented
+
+
class Generator(Iterator):
__slots__ = ()
@@ -285,17 +292,10 @@ class Generator(Iterator):
@classmethod
def __subclasshook__(cls, C):
if cls is Generator:
- mro = C.__mro__
- for method in ('__iter__', '__next__', 'send', 'throw', 'close'):
- for base in mro:
- if method in base.__dict__:
- break
- else:
- return NotImplemented
- return True
+ return _check_methods(C, '__iter__', '__next__',
+ 'send', 'throw', 'close')
return NotImplemented
-
Generator.register(generator)
@@ -310,8 +310,7 @@ class Sized(metaclass=ABCMeta):
@classmethod
def __subclasshook__(cls, C):
if cls is Sized:
- if any("__len__" in B.__dict__ for B in C.__mro__):
- return True
+ return _check_methods(C, "__len__")
return NotImplemented
@@ -326,10 +325,18 @@ class Container(metaclass=ABCMeta):
@classmethod
def __subclasshook__(cls, C):
if cls is Container:
- if any("__contains__" in B.__dict__ for B in C.__mro__):
- return True
+ return _check_methods(C, "__contains__")
return NotImplemented
+class Collection(Sized, Iterable, Container):
+
+ __slots__ = ()
+
+ @classmethod
+ def __subclasshook__(cls, C):
+ if cls is Collection:
+ return _check_methods(C, "__len__", "__iter__", "__contains__")
+ return NotImplemented
class Callable(metaclass=ABCMeta):
@@ -342,15 +349,14 @@ class Callable(metaclass=ABCMeta):
@classmethod
def __subclasshook__(cls, C):
if cls is Callable:
- if any("__call__" in B.__dict__ for B in C.__mro__):
- return True
+ return _check_methods(C, "__call__")
return NotImplemented
### SETS ###
-class Set(Sized, Iterable, Container):
+class Set(Collection):
"""A set is a finite, iterable container.
@@ -575,7 +581,7 @@ MutableSet.register(set)
### MAPPINGS ###
-class Mapping(Sized, Iterable, Container):
+class Mapping(Collection):
__slots__ = ()
@@ -623,6 +629,8 @@ class Mapping(Sized, Iterable, Container):
return NotImplemented
return dict(self.items()) == dict(other.items())
+ __reversed__ = None
+
Mapping.register(mappingproxy)
@@ -672,7 +680,7 @@ class ItemsView(MappingView, Set):
except KeyError:
return False
else:
- return v == value
+ return v is value or v == value
def __iter__(self):
for key in self._mapping:
@@ -687,7 +695,8 @@ class ValuesView(MappingView):
def __contains__(self, value):
for key in self._mapping:
- if value == self._mapping[key]:
+ v = self._mapping[key]
+ if v is value or v == value:
return True
return False
@@ -796,7 +805,7 @@ MutableMapping.register(dict)
### SEQUENCES ###
-class Sequence(Sized, Iterable, Container):
+class Sequence(Reversible, Collection):
"""All the operations on a read-only sequence.
@@ -822,7 +831,7 @@ class Sequence(Sized, Iterable, Container):
def __contains__(self, value):
for v in self:
- if v == value:
+ if v is value or v == value:
return True
return False
diff --git a/Lib/_compat_pickle.py b/Lib/_compat_pickle.py
index c0e0443..f68496a 100644
--- a/Lib/_compat_pickle.py
+++ b/Lib/_compat_pickle.py
@@ -242,3 +242,10 @@ PYTHON3_OSERROR_EXCEPTIONS = (
for excname in PYTHON3_OSERROR_EXCEPTIONS:
REVERSE_NAME_MAPPING[('builtins', excname)] = ('exceptions', 'OSError')
+
+PYTHON3_IMPORTERROR_EXCEPTIONS = (
+ 'ModuleNotFoundError',
+)
+
+for excname in PYTHON3_IMPORTERROR_EXCEPTIONS:
+ REVERSE_NAME_MAPPING[('builtins', excname)] = ('exceptions', 'ImportError')
diff --git a/Lib/_osx_support.py b/Lib/_osx_support.py
index 13fcd8b..eadf06f 100644
--- a/Lib/_osx_support.py
+++ b/Lib/_osx_support.py
@@ -210,7 +210,7 @@ def _remove_universal_flags(_config_vars):
# Do not alter a config var explicitly overridden by env var
if cv in _config_vars and cv not in os.environ:
flags = _config_vars[cv]
- flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
+ flags = re.sub(r'-arch\s+\w+\s', ' ', flags, re.ASCII)
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
_save_modified_value(_config_vars, cv, flags)
@@ -232,7 +232,7 @@ def _remove_unsupported_archs(_config_vars):
if 'CC' in os.environ:
return _config_vars
- if re.search('-arch\s+ppc', _config_vars['CFLAGS']) is not None:
+ if re.search(r'-arch\s+ppc', _config_vars['CFLAGS']) is not None:
# NOTE: Cannot use subprocess here because of bootstrap
# issues when building Python itself
status = os.system(
@@ -251,7 +251,7 @@ def _remove_unsupported_archs(_config_vars):
for cv in _UNIVERSAL_CONFIG_VARS:
if cv in _config_vars and cv not in os.environ:
flags = _config_vars[cv]
- flags = re.sub('-arch\s+ppc\w*\s', ' ', flags)
+ flags = re.sub(r'-arch\s+ppc\w*\s', ' ', flags)
_save_modified_value(_config_vars, cv, flags)
return _config_vars
@@ -267,7 +267,7 @@ def _override_all_archs(_config_vars):
for cv in _UNIVERSAL_CONFIG_VARS:
if cv in _config_vars and '-arch' in _config_vars[cv]:
flags = _config_vars[cv]
- flags = re.sub('-arch\s+\w+\s', ' ', flags)
+ flags = re.sub(r'-arch\s+\w+\s', ' ', flags)
flags = flags + ' ' + arch
_save_modified_value(_config_vars, cv, flags)
@@ -465,7 +465,7 @@ def get_platform_osx(_config_vars, osname, release, machine):
machine = 'fat'
- archs = re.findall('-arch\s+(\S+)', cflags)
+ archs = re.findall(r'-arch\s+(\S+)', cflags)
archs = tuple(sorted(set(archs)))
if len(archs) == 1:
diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py
index a5ea340..0b40928 100644
--- a/Lib/_pydecimal.py
+++ b/Lib/_pydecimal.py
@@ -148,7 +148,7 @@ __xname__ = __name__ # sys.modules lookup (--without-threads)
__name__ = 'decimal' # For pickling
__version__ = '1.70' # Highest version of the spec this complies with
# See http://speleotrove.com/decimal/
-__libmpdec_version__ = "2.4.1" # compatible libmpdec version
+__libmpdec_version__ = "2.4.2" # compatible libmpdec version
import math as _math
import numbers as _numbers
@@ -589,7 +589,7 @@ class Decimal(object):
# From a string
# REs insist on real strings, so we can too.
if isinstance(value, str):
- m = _parser(value.strip())
+ m = _parser(value.strip().replace("_", ""))
if m is None:
if context is None:
context = getcontext()
@@ -1010,6 +1010,56 @@ class Decimal(object):
"""
return DecimalTuple(self._sign, tuple(map(int, self._int)), self._exp)
+ def as_integer_ratio(self):
+ """Express a finite Decimal instance in the form n / d.
+
+ Returns a pair (n, d) of integers. When called on an infinity
+ or NaN, raises OverflowError or ValueError respectively.
+
+ >>> Decimal('3.14').as_integer_ratio()
+ (157, 50)
+ >>> Decimal('-123e5').as_integer_ratio()
+ (-12300000, 1)
+ >>> Decimal('0.00').as_integer_ratio()
+ (0, 1)
+
+ """
+ if self._is_special:
+ if self.is_nan():
+ raise ValueError("cannot convert NaN to integer ratio")
+ else:
+ raise OverflowError("cannot convert Infinity to integer ratio")
+
+ if not self:
+ return 0, 1
+
+ # Find n, d in lowest terms such that abs(self) == n / d;
+ # we'll deal with the sign later.
+ n = int(self._int)
+ if self._exp >= 0:
+ # self is an integer.
+ n, d = n * 10**self._exp, 1
+ else:
+ # Find d2, d5 such that abs(self) = n / (2**d2 * 5**d5).
+ d5 = -self._exp
+ while d5 > 0 and n % 5 == 0:
+ n //= 5
+ d5 -= 1
+
+ # (n & -n).bit_length() - 1 counts trailing zeros in binary
+ # representation of n (provided n is nonzero).
+ d2 = -self._exp
+ shift2 = min((n & -n).bit_length() - 1, d2)
+ if shift2:
+ n >>= shift2
+ d2 -= shift2
+
+ d = 5**d5 << d2
+
+ if self._sign:
+ n = -n
+ return n, d
+
def __repr__(self):
"""Represents the number as an instance of Decimal."""
# Invariant: eval(repr(d)) == d
@@ -4075,7 +4125,7 @@ class Context(object):
This will make it round up for that operation.
"""
rounding = self.rounding
- self.rounding= type
+ self.rounding = type
return rounding
def create_decimal(self, num='0'):
@@ -4084,10 +4134,10 @@ class Context(object):
This method implements the to-number operation of the
IBM Decimal specification."""
- if isinstance(num, str) and num != num.strip():
+ if isinstance(num, str) and (num != num.strip() or '_' in num):
return self._raise_error(ConversionSyntax,
- "no trailing or leading whitespace is "
- "permitted.")
+ "trailing or leading whitespace and "
+ "underscores are not permitted.")
d = Decimal(num, context=self)
if d._isnan() and len(d._int) > self.prec - self.clamp:
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 0d98b74..d0947f0 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -6,7 +6,6 @@ import os
import abc
import codecs
import errno
-import array
import stat
import sys
# Import _thread instead of threading to reduce startup cost
@@ -161,6 +160,8 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
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, int):
+ file = os.fspath(file)
if not isinstance(file, (str, bytes, int)):
raise TypeError("invalid file: %r" % file)
if not isinstance(mode, str):
@@ -182,8 +183,8 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
text = "t" in modes
binary = "b" in modes
if "U" in modes:
- if creating or writing or appending:
- raise ValueError("can't use U and writing mode at once")
+ if creating or writing or appending or updating:
+ raise ValueError("mode U cannot be combined with 'x', 'w', 'a', or '+'")
import warnings
warnings.warn("'U' mode is deprecated",
DeprecationWarning, 2)
@@ -1516,7 +1517,7 @@ class FileIO(RawIOBase):
if self._fd >= 0 and self._closefd and not self.closed:
import warnings
warnings.warn('unclosed file %r' % (self,), ResourceWarning,
- stacklevel=2)
+ stacklevel=2, source=self)
self.close()
def __getstate__(self):
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index f84227b..fe94361 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -199,12 +199,15 @@ class TimeRE(dict):
'f': r"(?P<f>[0-9]{1,6})",
'H': r"(?P<H>2[0-3]|[0-1]\d|\d)",
'I': r"(?P<I>1[0-2]|0[1-9]|[1-9])",
+ 'G': r"(?P<G>\d\d\d\d)",
'j': r"(?P<j>36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]|[1-9]\d|0[1-9]|[1-9])",
'm': r"(?P<m>1[0-2]|0[1-9]|[1-9])",
'M': r"(?P<M>[0-5]\d|\d)",
'S': r"(?P<S>6[0-1]|[0-5]\d|\d)",
'U': r"(?P<U>5[0-3]|[0-4]\d|\d)",
'w': r"(?P<w>[0-6])",
+ 'u': r"(?P<u>[1-7])",
+ 'V': r"(?P<V>5[0-3]|0[1-9]|[1-4]\d|\d)",
# W is set below by using 'U'
'y': r"(?P<y>\d\d)",
#XXX: Does 'Y' need to worry about having less or more than
@@ -299,6 +302,22 @@ def _calc_julian_from_U_or_W(year, week_of_year, day_of_week, week_starts_Mon):
return 1 + days_to_week + day_of_week
+def _calc_julian_from_V(iso_year, iso_week, iso_weekday):
+ """Calculate the Julian day based on the ISO 8601 year, week, and weekday.
+ ISO weeks start on Mondays, with week 01 being the week containing 4 Jan.
+ ISO week days range from 1 (Monday) to 7 (Sunday).
+ """
+ correction = datetime_date(iso_year, 1, 4).isoweekday() + 3
+ ordinal = (iso_week * 7) + iso_weekday - correction
+ # ordinal may be negative or 0 now, which means the date is in the previous
+ # calendar year
+ if ordinal < 1:
+ ordinal += datetime_date(iso_year, 1, 1).toordinal()
+ iso_year -= 1
+ ordinal -= datetime_date(iso_year, 1, 1).toordinal()
+ return iso_year, ordinal
+
+
def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a 2-tuple consisting of a time struct and an int containing
the number of microseconds based on the input string and the
@@ -345,15 +364,15 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
raise ValueError("unconverted data remains: %s" %
data_string[found.end():])
- year = None
+ iso_year = year = None
month = day = 1
hour = minute = second = fraction = 0
tz = -1
tzoffset = None
# Default to -1 to signify that values not known; not critical to have,
# though
- week_of_year = -1
- week_of_year_start = -1
+ iso_week = week_of_year = None
+ week_of_year_start = None
# weekday and julian defaulted to None so as to signal need to calculate
# values
weekday = julian = None
@@ -375,6 +394,8 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
year += 1900
elif group_key == 'Y':
year = int(found_dict['Y'])
+ elif group_key == 'G':
+ iso_year = int(found_dict['G'])
elif group_key == 'm':
month = int(found_dict['m'])
elif group_key == 'B':
@@ -420,6 +441,9 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
weekday = 6
else:
weekday -= 1
+ elif group_key == 'u':
+ weekday = int(found_dict['u'])
+ weekday -= 1
elif group_key == 'j':
julian = int(found_dict['j'])
elif group_key in ('U', 'W'):
@@ -430,6 +454,8 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
else:
# W starts week on Monday.
week_of_year_start = 0
+ elif group_key == 'V':
+ iso_week = int(found_dict['V'])
elif group_key == 'z':
z = found_dict['z']
tzoffset = int(z[1:3]) * 60 + int(z[3:5])
@@ -450,32 +476,61 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
else:
tz = value
break
+ # Deal with the cases where ambiguities arize
+ # don't assume default values for ISO week/year
+ if year is None and iso_year is not None:
+ if iso_week is None or weekday is None:
+ raise ValueError("ISO year directive '%G' must be used with "
+ "the ISO week directive '%V' and a weekday "
+ "directive ('%A', '%a', '%w', or '%u').")
+ if julian is not None:
+ raise ValueError("Day of the year directive '%j' is not "
+ "compatible with ISO year directive '%G'. "
+ "Use '%Y' instead.")
+ elif week_of_year is None and iso_week is not None:
+ if weekday is None:
+ raise ValueError("ISO week directive '%V' must be used with "
+ "the ISO year directive '%G' and a weekday "
+ "directive ('%A', '%a', '%w', or '%u').")
+ else:
+ raise ValueError("ISO week directive '%V' is incompatible with "
+ "the year directive '%Y'. Use the ISO year '%G' "
+ "instead.")
+
leap_year_fix = False
if year is None and month == 2 and day == 29:
year = 1904 # 1904 is first leap year of 20th century
leap_year_fix = True
elif year is None:
year = 1900
+
+
# If we know the week of the year and what day of that week, we can figure
# out the Julian day of the year.
- if julian is None and week_of_year != -1 and weekday is not None:
- week_starts_Mon = True if week_of_year_start == 0 else False
- julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
- week_starts_Mon)
- if julian <= 0:
+ if julian is None and weekday is not None:
+ if week_of_year is not None:
+ week_starts_Mon = True if week_of_year_start == 0 else False
+ julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
+ week_starts_Mon)
+ elif iso_year is not None and iso_week is not None:
+ year, julian = _calc_julian_from_V(iso_year, iso_week, weekday + 1)
+ if julian is not None and julian <= 0:
year -= 1
yday = 366 if calendar.isleap(year) else 365
julian += yday
- # Cannot pre-calculate datetime_date() since can change in Julian
- # calculation and thus could have different value for the day of the week
- # calculation.
+
if julian is None:
+ # Cannot pre-calculate datetime_date() since can change in Julian
+ # calculation and thus could have different value for the day of
+ # the week calculation.
# Need to add 1 to result since first day of the year is 1, not 0.
julian = datetime_date(year, month, day).toordinal() - \
datetime_date(year, 1, 1).toordinal() + 1
- else: # Assume that if they bothered to include Julian day it will
- # be accurate.
- datetime_result = datetime_date.fromordinal((julian - 1) + datetime_date(year, 1, 1).toordinal())
+ else: # Assume that if they bothered to include Julian day (or if it was
+ # calculated above with year/week/weekday) it will be accurate.
+ datetime_result = datetime_date.fromordinal(
+ (julian - 1) +
+ datetime_date(year, 1, 1).toordinal())
year = datetime_result.year
month = datetime_result.month
day = datetime_result.day
diff --git a/Lib/aifc.py b/Lib/aifc.py
index 7ebdbeb..692d0bf 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -257,6 +257,15 @@ from collections import namedtuple
_aifc_params = namedtuple('_aifc_params',
'nchannels sampwidth framerate nframes comptype compname')
+_aifc_params.nchannels.__doc__ = 'Number of audio channels (1 for mono, 2 for stereo)'
+_aifc_params.sampwidth.__doc__ = 'Sample width in bytes'
+_aifc_params.framerate.__doc__ = 'Sampling frequency'
+_aifc_params.nframes.__doc__ = 'Number of audio frames'
+_aifc_params.comptype.__doc__ = 'Compression type ("NONE" for AIFF files)'
+_aifc_params.compname.__doc__ = ("""\
+A human-readable version of the compression type
+('not compressed' for AIFF files)""")
+
class Aifc_read:
# Variables used in this class:
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 9a06719..209b4e9 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -118,10 +118,16 @@ class _AttributeHolder(object):
def __repr__(self):
type_name = type(self).__name__
arg_strings = []
+ star_args = {}
for arg in self._get_args():
arg_strings.append(repr(arg))
for name, value in self._get_kwargs():
- arg_strings.append('%s=%r' % (name, value))
+ if name.isidentifier():
+ arg_strings.append('%s=%r' % (name, value))
+ else:
+ star_args[name] = value
+ if star_args:
+ arg_strings.append('**%s' % repr(star_args))
return '%s(%s)' % (type_name, ', '.join(arg_strings))
def _get_kwargs(self):
@@ -204,8 +210,6 @@ class HelpFormatter(object):
if self.parent is not None:
self.formatter._indent()
join = self.formatter._join_parts
- for func, args in self.items:
- func(*args)
item_help = join([func(*args) for func, args in self.items])
if self.parent is not None:
self.formatter._dedent()
diff --git a/Lib/ast.py b/Lib/ast.py
index 0170472..156a1f2 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -35,6 +35,8 @@ def parse(source, filename='<unknown>', mode='exec'):
return compile(source, filename, mode, PyCF_ONLY_AST)
+_NUM_TYPES = (int, float, complex)
+
def literal_eval(node_or_string):
"""
Safely evaluate an expression node or a string containing a Python
@@ -47,7 +49,9 @@ def literal_eval(node_or_string):
if isinstance(node_or_string, Expression):
node_or_string = node_or_string.body
def _convert(node):
- if isinstance(node, (Str, Bytes)):
+ if isinstance(node, Constant):
+ return node.value
+ elif isinstance(node, (Str, Bytes)):
return node.s
elif isinstance(node, Num):
return node.n
@@ -62,24 +66,21 @@ def literal_eval(node_or_string):
in zip(node.keys, node.values))
elif isinstance(node, NameConstant):
return node.value
- elif isinstance(node, UnaryOp) and \
- isinstance(node.op, (UAdd, USub)) and \
- isinstance(node.operand, (Num, UnaryOp, BinOp)):
+ elif isinstance(node, UnaryOp) and isinstance(node.op, (UAdd, USub)):
operand = _convert(node.operand)
- if isinstance(node.op, UAdd):
- return + operand
- else:
- return - operand
- elif isinstance(node, BinOp) and \
- isinstance(node.op, (Add, Sub)) and \
- isinstance(node.right, (Num, UnaryOp, BinOp)) and \
- isinstance(node.left, (Num, UnaryOp, BinOp)):
+ if isinstance(operand, _NUM_TYPES):
+ if isinstance(node.op, UAdd):
+ return + operand
+ else:
+ return - operand
+ elif isinstance(node, BinOp) and isinstance(node.op, (Add, Sub)):
left = _convert(node.left)
right = _convert(node.right)
- if isinstance(node.op, Add):
- return left + right
- else:
- return left - right
+ if isinstance(left, _NUM_TYPES) and isinstance(right, _NUM_TYPES):
+ if isinstance(node.op, Add):
+ return left + right
+ else:
+ return left - right
raise ValueError('malformed node or string: ' + repr(node))
return _convert(node_or_string)
@@ -196,12 +197,19 @@ def get_docstring(node, clean=True):
"""
if not isinstance(node, (AsyncFunctionDef, FunctionDef, ClassDef, Module)):
raise TypeError("%r can't have docstrings" % node.__class__.__name__)
- if node.body and isinstance(node.body[0], Expr) and \
- isinstance(node.body[0].value, Str):
- if clean:
- import inspect
- return inspect.cleandoc(node.body[0].value.s)
- return node.body[0].value.s
+ if not(node.body and isinstance(node.body[0], Expr)):
+ return
+ node = node.body[0].value
+ if isinstance(node, Str):
+ text = node.s
+ elif isinstance(node, Constant) and isinstance(node.value, str):
+ text = node.value
+ else:
+ return
+ if clean:
+ import inspect
+ text = inspect.cleandoc(text)
+ return text
def walk(node):
diff --git a/Lib/asynchat.py b/Lib/asynchat.py
index f728d1b..fc1146a 100644
--- a/Lib/asynchat.py
+++ b/Lib/asynchat.py
@@ -285,35 +285,6 @@ class simple_producer:
return result
-class fifo:
- def __init__(self, list=None):
- import warnings
- warnings.warn('fifo class will be removed in Python 3.6',
- DeprecationWarning, stacklevel=2)
- if not list:
- self.list = deque()
- else:
- self.list = deque(list)
-
- def __len__(self):
- return len(self.list)
-
- def is_empty(self):
- return not self.list
-
- def first(self):
- return self.list[0]
-
- def push(self, data):
- self.list.append(data)
-
- def pop(self):
- if self.list:
- return (1, self.list.popleft())
- else:
- return (0, None)
-
-
# Given 'haystack', see if any prefix of 'needle' is at its end. This
# assumes an exact match has already been checked. Return the number of
# characters matched.
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index b3e318e..5880061 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -348,6 +348,9 @@ class BaseEventLoop(events.AbstractEventLoop):
self._asyncgens.discard(agen)
if not self.is_closed():
self.create_task(agen.aclose())
+ # Wake up the loop if the finalizer was called from
+ # a different thread.
+ self._write_to_self()
def _asyncgen_firstiter_hook(self, agen):
if self._asyncgens_shutdown_called:
@@ -485,7 +488,8 @@ class BaseEventLoop(events.AbstractEventLoop):
if compat.PY34:
def __del__(self):
if not self.is_closed():
- warnings.warn("unclosed event loop %r" % self, ResourceWarning)
+ warnings.warn("unclosed event loop %r" % self, ResourceWarning,
+ source=self)
if not self.is_running():
self.close()
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py
index 23742a1..a00d9d5 100644
--- a/Lib/asyncio/base_subprocess.py
+++ b/Lib/asyncio/base_subprocess.py
@@ -127,7 +127,8 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
if compat.PY34:
def __del__(self):
if not self._closed:
- warnings.warn("unclosed transport %r" % self, ResourceWarning)
+ warnings.warn("unclosed transport %r" % self, ResourceWarning,
+ source=self)
self.close()
def get_pid(self):
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index bcd4d16..e45d6aa 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -120,6 +120,46 @@ def isfuture(obj):
return getattr(obj, '_asyncio_future_blocking', None) is not None
+def _format_callbacks(cb):
+ """helper function for Future.__repr__"""
+ size = len(cb)
+ if not size:
+ cb = ''
+
+ def format_cb(callback):
+ return events._format_callback_source(callback, ())
+
+ if size == 1:
+ cb = format_cb(cb[0])
+ elif size == 2:
+ cb = '{}, {}'.format(format_cb(cb[0]), format_cb(cb[1]))
+ elif size > 2:
+ cb = '{}, <{} more>, {}'.format(format_cb(cb[0]),
+ size-2,
+ format_cb(cb[-1]))
+ return 'cb=[%s]' % cb
+
+
+def _future_repr_info(future):
+ # (Future) -> str
+ """helper function for Future.__repr__"""
+ info = [future._state.lower()]
+ if future._state == _FINISHED:
+ if future._exception is not None:
+ info.append('exception={!r}'.format(future._exception))
+ else:
+ # use reprlib to limit the length of the output, especially
+ # for very long strings
+ result = reprlib.repr(future._result)
+ info.append('result={}'.format(result))
+ if future._callbacks:
+ info.append(_format_callbacks(future._callbacks))
+ if future._source_traceback:
+ frame = future._source_traceback[-1]
+ info.append('created at %s:%s' % (frame[0], frame[1]))
+ return info
+
+
class Future:
"""This class is *almost* compatible with concurrent.futures.Future.
@@ -172,45 +212,10 @@ class Future:
if self._loop.get_debug():
self._source_traceback = traceback.extract_stack(sys._getframe(1))
- def __format_callbacks(self):
- cb = self._callbacks
- size = len(cb)
- if not size:
- cb = ''
-
- def format_cb(callback):
- return events._format_callback_source(callback, ())
-
- if size == 1:
- cb = format_cb(cb[0])
- elif size == 2:
- cb = '{}, {}'.format(format_cb(cb[0]), format_cb(cb[1]))
- elif size > 2:
- cb = '{}, <{} more>, {}'.format(format_cb(cb[0]),
- size-2,
- format_cb(cb[-1]))
- return 'cb=[%s]' % cb
-
- def _repr_info(self):
- info = [self._state.lower()]
- if self._state == _FINISHED:
- if self._exception is not None:
- info.append('exception={!r}'.format(self._exception))
- else:
- # use reprlib to limit the length of the output, especially
- # for very long strings
- result = reprlib.repr(self._result)
- info.append('result={}'.format(result))
- if self._callbacks:
- info.append(self.__format_callbacks())
- if self._source_traceback:
- frame = self._source_traceback[-1]
- info.append('created at %s:%s' % (frame[0], frame[1]))
- return info
+ _repr_info = _future_repr_info
def __repr__(self):
- info = self._repr_info()
- return '<%s %s>' % (self.__class__.__name__, ' '.join(info))
+ return '<%s %s>' % (self.__class__.__name__, ' '.join(self._repr_info()))
# On Python 3.3 and older, objects with a destructor part of a reference
# cycle are never destroyed. It's not more the case on Python 3.4 thanks
@@ -242,10 +247,10 @@ class Future:
if self._state != _PENDING:
return False
self._state = _CANCELLED
- self._schedule_callbacks()
+ self.__schedule_callbacks()
return True
- def _schedule_callbacks(self):
+ def __schedule_callbacks(self):
"""Internal: Ask the event loop to call all callbacks.
The callbacks are scheduled to be called as soon as possible. Also
@@ -347,7 +352,7 @@ class Future:
raise InvalidStateError('{}: {!r}'.format(self._state, self))
self._result = result
self._state = _FINISHED
- self._schedule_callbacks()
+ self.__schedule_callbacks()
def set_exception(self, exception):
"""Mark the future done and set an exception.
@@ -364,7 +369,7 @@ class Future:
"and cannot be raised into a Future")
self._exception = exception
self._state = _FINISHED
- self._schedule_callbacks()
+ self.__schedule_callbacks()
if compat.PY34:
self._log_traceback = True
else:
@@ -476,3 +481,11 @@ def wrap_future(future, *, loop=None):
new_future = loop.create_future()
_chain_future(future, new_future)
return new_future
+
+
+try:
+ import _asyncio
+except ImportError:
+ pass
+else:
+ Future = _asyncio.Future
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index fef3205..ff12877 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -92,7 +92,8 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
if compat.PY34:
def __del__(self):
if self._sock is not None:
- warnings.warn("unclosed transport %r" % self, ResourceWarning)
+ warnings.warn("unclosed transport %r" % self, ResourceWarning,
+ source=self)
self.close()
def _fatal_error(self, exc, message='Fatal error on pipe transport'):
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 12d357b..9dbe550 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -627,7 +627,8 @@ class _SelectorTransport(transports._FlowControlMixin,
if compat.PY34:
def __del__(self):
if self._sock is not None:
- warnings.warn("unclosed transport %r" % self, ResourceWarning)
+ warnings.warn("unclosed transport %r" % self, ResourceWarning,
+ source=self)
self._sock.close()
def _fatal_error(self, exc, message='Fatal error on transport'):
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 804c5c3..991c77b 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -331,7 +331,8 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
if compat.PY34:
def __del__(self):
if not self._closed:
- warnings.warn("unclosed transport %r" % self, ResourceWarning)
+ warnings.warn("unclosed transport %r" % self, ResourceWarning,
+ source=self)
self.close()
def pause_reading(self):
diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py
index 307fffc..fdd3ba0 100644
--- a/Lib/asyncio/test_utils.py
+++ b/Lib/asyncio/test_utils.py
@@ -119,10 +119,10 @@ class SSLWSGIServerMixin:
'test', 'test_asyncio')
keyfile = os.path.join(here, 'ssl_key.pem')
certfile = os.path.join(here, 'ssl_cert.pem')
- ssock = ssl.wrap_socket(request,
- keyfile=keyfile,
- certfile=certfile,
- server_side=True)
+ context = ssl.SSLContext()
+ context.load_cert_chain(certfile, keyfile)
+
+ ssock = context.wrap_socket(request, server_side=True)
try:
self.RequestHandlerClass(ssock, client_address, self)
ssock.close()
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 65b61db..2843678 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -411,7 +411,8 @@ class _UnixReadPipeTransport(transports.ReadTransport):
if compat.PY34:
def __del__(self):
if self._pipe is not None:
- warnings.warn("unclosed transport %r" % self, ResourceWarning)
+ warnings.warn("unclosed transport %r" % self, ResourceWarning,
+ source=self)
self._pipe.close()
def _fatal_error(self, exc, message='Fatal error on pipe transport'):
@@ -611,7 +612,8 @@ class _UnixWritePipeTransport(transports._FlowControlMixin,
if compat.PY34:
def __del__(self):
if self._pipe is not None:
- warnings.warn("unclosed transport %r" % self, ResourceWarning)
+ warnings.warn("unclosed transport %r" % self, ResourceWarning,
+ source=self)
self._pipe.close()
def abort(self):
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py
index 668fe14..b777dd0 100644
--- a/Lib/asyncio/windows_events.py
+++ b/Lib/asyncio/windows_events.py
@@ -171,8 +171,13 @@ class _WaitCancelFuture(_BaseWaitHandleFuture):
def cancel(self):
raise RuntimeError("_WaitCancelFuture must not be cancelled")
- def _schedule_callbacks(self):
- super(_WaitCancelFuture, self)._schedule_callbacks()
+ def set_result(self, result):
+ super().set_result(result)
+ if self._done_callback is not None:
+ self._done_callback(self)
+
+ def set_exception(self, exception):
+ super().set_exception(exception)
if self._done_callback is not None:
self._done_callback(self)
diff --git a/Lib/asyncio/windows_utils.py b/Lib/asyncio/windows_utils.py
index 870cd13..7c63fb9 100644
--- a/Lib/asyncio/windows_utils.py
+++ b/Lib/asyncio/windows_utils.py
@@ -159,7 +159,8 @@ class PipeHandle:
def __del__(self):
if self._handle is not None:
- warnings.warn("unclosed %r" % self, ResourceWarning)
+ warnings.warn("unclosed %r" % self, ResourceWarning,
+ source=self)
self.close()
def __enter__(self):
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 3b51f0f..705e406 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -333,7 +333,7 @@ class dispatcher:
self.connecting = True
err = self.socket.connect_ex(address)
if err in (EINPROGRESS, EALREADY, EWOULDBLOCK) \
- or err == EINVAL and os.name in ('nt', 'ce'):
+ or err == EINVAL and os.name == 'nt':
self.addr = address
return
if err in (0, EISCONN):
@@ -595,7 +595,8 @@ if os.name == 'posix':
def __del__(self):
if self.fd >= 0:
- warnings.warn("unclosed file %r" % self, ResourceWarning)
+ warnings.warn("unclosed file %r" % self, ResourceWarning,
+ source=self)
self.close()
def recv(self, *args):
diff --git a/Lib/base64.py b/Lib/base64.py
index adaec1d..58f6ad6 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -55,8 +55,7 @@ def b64encode(s, altchars=None):
alternative alphabet for the '+' and '/' characters. This allows an
application to e.g. generate url or filesystem safe Base64 strings.
"""
- # Strip off the trailing newline
- encoded = binascii.b2a_base64(s)[:-1]
+ encoded = binascii.b2a_base64(s, newline=False)
if altchars is not None:
assert len(altchars) == 2, repr(altchars)
return encoded.translate(bytes.maketrans(b'+/', altchars))
@@ -156,7 +155,7 @@ def b32encode(s):
leftover = len(s) % 5
# Pad the last quantum with zero bits if necessary
if leftover:
- s = s + bytes(5 - leftover) # Don't use += !
+ s = s + b'\0' * (5 - leftover) # Don't use += !
encoded = bytearray()
from_bytes = int.from_bytes
b32tab2 = _b32tab2
diff --git a/Lib/bz2.py b/Lib/bz2.py
index bc78c54..6f56328 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -11,6 +11,7 @@ __author__ = "Nadeem Vawda <nadeem.vawda@gmail.com>"
from builtins import open as _builtin_open
import io
+import os
import warnings
import _compression
@@ -42,9 +43,9 @@ class BZ2File(_compression.BaseStream):
def __init__(self, filename, mode="r", buffering=None, compresslevel=9):
"""Open a bzip2-compressed file.
- If filename is a str or bytes object, it gives the name
- of the file to be opened. Otherwise, it should be a file object,
- which will be used to read or write the compressed data.
+ If filename is a str, bytes, or PathLike object, it gives the
+ name of the file to be opened. Otherwise, it should be a file
+ object, which will be used to read or write the compressed data.
mode can be 'r' for reading (default), 'w' for (over)writing,
'x' for creating exclusively, or 'a' for appending. These can
@@ -91,7 +92,7 @@ class BZ2File(_compression.BaseStream):
else:
raise ValueError("Invalid mode: %r" % (mode,))
- if isinstance(filename, (str, bytes)):
+ if isinstance(filename, (str, bytes, os.PathLike)):
self._fp = _builtin_open(filename, mode)
self._closefp = True
self._mode = mode_code
@@ -99,7 +100,7 @@ class BZ2File(_compression.BaseStream):
self._fp = filename
self._mode = mode_code
else:
- raise TypeError("filename must be a str or bytes object, or a file")
+ raise TypeError("filename must be a str, bytes, file or PathLike object")
if self._mode == _MODE_READ:
raw = _compression.DecompressReader(self._fp,
@@ -289,8 +290,9 @@ def open(filename, mode="rb", compresslevel=9,
encoding=None, errors=None, newline=None):
"""Open a bzip2-compressed file in binary or text mode.
- The filename argument can be an actual filename (a str or bytes
- object), or an existing file object to read from or write to.
+ The filename argument can be an actual filename (a str, bytes, or
+ PathLike object), or an existing file object to read from or write
+ to.
The mode argument can be "r", "rb", "w", "wb", "x", "xb", "a" or
"ab" for binary mode, or "rt", "wt", "xt" or "at" for text mode.
diff --git a/Lib/calendar.py b/Lib/calendar.py
index b5472f3..92149b7 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -13,7 +13,9 @@ from itertools import repeat
__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
"monthcalendar", "prmonth", "month", "prcal", "calendar",
- "timegm", "month_name", "month_abbr", "day_name", "day_abbr"]
+ "timegm", "month_name", "month_abbr", "day_name", "day_abbr",
+ "Calendar", "TextCalendar", "HTMLCalendar", "LocaleTextCalendar",
+ "LocaleHTMLCalendar", "weekheader"]
# Exception raised for bad input (with string parameter for details)
error = ValueError
@@ -604,51 +606,63 @@ def timegm(tuple):
def main(args):
- import optparse
- parser = optparse.OptionParser(usage="usage: %prog [options] [year [month]]")
- parser.add_option(
+ import argparse
+ parser = argparse.ArgumentParser()
+ textgroup = parser.add_argument_group('text only arguments')
+ htmlgroup = parser.add_argument_group('html only arguments')
+ textgroup.add_argument(
"-w", "--width",
- dest="width", type="int", default=2,
- help="width of date column (default 2, text only)"
+ type=int, default=2,
+ help="width of date column (default 2)"
)
- parser.add_option(
+ textgroup.add_argument(
"-l", "--lines",
- dest="lines", type="int", default=1,
- help="number of lines for each week (default 1, text only)"
+ type=int, default=1,
+ help="number of lines for each week (default 1)"
)
- parser.add_option(
+ textgroup.add_argument(
"-s", "--spacing",
- dest="spacing", type="int", default=6,
- help="spacing between months (default 6, text only)"
+ type=int, default=6,
+ help="spacing between months (default 6)"
)
- parser.add_option(
+ textgroup.add_argument(
"-m", "--months",
- dest="months", type="int", default=3,
- help="months per row (default 3, text only)"
+ type=int, default=3,
+ help="months per row (default 3)"
)
- parser.add_option(
+ htmlgroup.add_argument(
"-c", "--css",
- dest="css", default="calendar.css",
- help="CSS to use for page (html only)"
+ default="calendar.css",
+ help="CSS to use for page"
)
- parser.add_option(
+ parser.add_argument(
"-L", "--locale",
- dest="locale", default=None,
+ default=None,
help="locale to be used from month and weekday names"
)
- parser.add_option(
+ parser.add_argument(
"-e", "--encoding",
- dest="encoding", default=None,
- help="Encoding to use for output."
+ default=None,
+ help="encoding to use for output"
)
- parser.add_option(
+ parser.add_argument(
"-t", "--type",
- dest="type", default="text",
+ default="text",
choices=("text", "html"),
help="output type (text or html)"
)
+ parser.add_argument(
+ "year",
+ nargs='?', type=int,
+ help="year number (1-9999)"
+ )
+ parser.add_argument(
+ "month",
+ nargs='?', type=int,
+ help="month number (1-12, text only)"
+ )
- (options, args) = parser.parse_args(args)
+ options = parser.parse_args(args[1:])
if options.locale and not options.encoding:
parser.error("if --locale is specified --encoding is required")
@@ -666,10 +680,10 @@ def main(args):
encoding = sys.getdefaultencoding()
optdict = dict(encoding=encoding, css=options.css)
write = sys.stdout.buffer.write
- if len(args) == 1:
+ if options.year is None:
write(cal.formatyearpage(datetime.date.today().year, **optdict))
- elif len(args) == 2:
- write(cal.formatyearpage(int(args[1]), **optdict))
+ elif options.month is None:
+ write(cal.formatyearpage(options.year, **optdict))
else:
parser.error("incorrect number of arguments")
sys.exit(1)
@@ -679,18 +693,15 @@ def main(args):
else:
cal = TextCalendar()
optdict = dict(w=options.width, l=options.lines)
- if len(args) != 3:
+ if options.month is None:
optdict["c"] = options.spacing
optdict["m"] = options.months
- if len(args) == 1:
+ if options.year is None:
result = cal.formatyear(datetime.date.today().year, **optdict)
- elif len(args) == 2:
- result = cal.formatyear(int(args[1]), **optdict)
- elif len(args) == 3:
- result = cal.formatmonth(int(args[1]), int(args[2]), **optdict)
+ elif options.month is None:
+ result = cal.formatyear(options.year, **optdict)
else:
- parser.error("incorrect number of arguments")
- sys.exit(1)
+ result = cal.formatmonth(options.year, options.month, **optdict)
write = sys.stdout.write
if options.encoding:
result = result.encode(options.encoding)
diff --git a/Lib/cgi.py b/Lib/cgi.py
index 189c6d5..233a496 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -45,7 +45,7 @@ import tempfile
__all__ = ["MiniFieldStorage", "FieldStorage",
"parse", "parse_qs", "parse_qsl", "parse_multipart",
- "parse_header", "print_exception", "print_environ",
+ "parse_header", "test", "print_exception", "print_environ",
"print_form", "print_directory", "print_arguments",
"print_environ_usage", "escape"]
diff --git a/Lib/code.py b/Lib/code.py
index 53244e3..23295f4 100644
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -186,7 +186,7 @@ class InteractiveConsole(InteractiveInterpreter):
"""Reset the input buffer."""
self.buffer = []
- def interact(self, banner=None):
+ def interact(self, banner=None, exitmsg=None):
"""Closely emulate the interactive Python console.
The optional banner argument specifies the banner to print
@@ -196,6 +196,11 @@ class InteractiveConsole(InteractiveInterpreter):
to confuse this with the real interpreter -- since it's so
close!).
+ The optional exitmsg argument specifies the exit message
+ printed when exiting. Pass the empty string to suppress
+ printing an exit message. If exitmsg is not given or None,
+ a default message is printed.
+
"""
try:
sys.ps1
@@ -230,6 +235,10 @@ class InteractiveConsole(InteractiveInterpreter):
self.write("\nKeyboardInterrupt\n")
self.resetbuffer()
more = 0
+ if exitmsg is None:
+ self.write('now exiting %s...\n' % self.__class__.__name__)
+ elif exitmsg != '':
+ self.write('%s\n' % exitmsg)
def push(self, line):
"""Push a line to the interpreter.
@@ -267,7 +276,7 @@ class InteractiveConsole(InteractiveInterpreter):
-def interact(banner=None, readfunc=None, local=None):
+def interact(banner=None, readfunc=None, local=None, exitmsg=None):
"""Closely emulate the interactive Python interpreter.
This is a backwards compatible interface to the InteractiveConsole
@@ -279,6 +288,7 @@ def interact(banner=None, readfunc=None, local=None):
banner -- passed to InteractiveConsole.interact()
readfunc -- if not None, replaces InteractiveConsole.raw_input()
local -- passed to InteractiveInterpreter.__init__()
+ exitmsg -- passed to InteractiveConsole.interact()
"""
console = InteractiveConsole(local)
@@ -289,7 +299,7 @@ def interact(banner=None, readfunc=None, local=None):
import readline
except ImportError:
pass
- console.interact(banner)
+ console.interact(banner, exitmsg)
if __name__ == "__main__":
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index ebe8ee7..bcc4291 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -353,7 +353,7 @@ _field_template = '''\
{name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
'''
-def namedtuple(typename, field_names, verbose=False, rename=False):
+def namedtuple(typename, field_names, *, verbose=False, rename=False, module=None):
"""Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', ['x', 'y'])
@@ -393,7 +393,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
field_names[index] = '_%d' % index
seen.add(name)
for name in [typename] + field_names:
- if type(name) != str:
+ if type(name) is not str:
raise TypeError('Type names and field names must be strings')
if not name.isidentifier():
raise ValueError('Type names and field names must be valid '
@@ -434,11 +434,15 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
# For pickling to work, the __module__ variable needs to be set to the frame
# where the named tuple is created. Bypass this step in environments where
# sys._getframe is not defined (Jython for example) or sys._getframe is not
- # defined for arguments greater than 0 (IronPython).
- try:
- result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
- except (AttributeError, ValueError):
- pass
+ # defined for arguments greater than 0 (IronPython), or where the user has
+ # specified a particular module.
+ if module is None:
+ try:
+ module = _sys._getframe(1).f_globals.get('__name__', '__main__')
+ except (AttributeError, ValueError):
+ pass
+ if module is not None:
+ result.__module__ = module
return result
@@ -842,7 +846,7 @@ class Counter(dict):
########################################################################
-### ChainMap (helper for configparser and string.Template)
+### ChainMap
########################################################################
class ChainMap(MutableMapping):
@@ -969,7 +973,7 @@ class UserDict(MutableMapping):
dict = kwargs.pop('dict')
import warnings
warnings.warn("Passing 'dict' as keyword argument is deprecated",
- PendingDeprecationWarning, stacklevel=2)
+ DeprecationWarning, stacklevel=2)
else:
dict = None
self.data = {}
diff --git a/Lib/collections/__main__.py b/Lib/collections/__main__.py
deleted file mode 100644
index 763e38e..0000000
--- a/Lib/collections/__main__.py
+++ /dev/null
@@ -1,38 +0,0 @@
-################################################################################
-### Simple tests
-################################################################################
-
-# verify that instances can be pickled
-from collections import namedtuple
-from pickle import loads, dumps
-Point = namedtuple('Point', 'x, y', True)
-p = Point(x=10, y=20)
-assert p == loads(dumps(p))
-
-# test and demonstrate ability to override methods
-class Point(namedtuple('Point', 'x y')):
- __slots__ = ()
- @property
- def hypot(self):
- return (self.x ** 2 + self.y ** 2) ** 0.5
- 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.):
- print (p)
-
-class Point(namedtuple('Point', 'x y')):
- 'Point class with optimized _make() and _replace() without error-checking'
- __slots__ = ()
- _make = classmethod(tuple.__new__)
- def _replace(self, _map=map, **kwds):
- return self._make(_map(kwds.get, ('x', 'y'), self))
-
-print(Point(11, 22)._replace(x=100))
-
-Point3D = namedtuple('Point3D', Point._fields + ('z',))
-print(Point3D.__doc__)
-
-import doctest, collections
-TestResults = namedtuple('TestResults', 'failed attempted')
-print(TestResults(*doctest.testmod(collections)))
diff --git a/Lib/compileall.py b/Lib/compileall.py
index 0cc0c1d..3e45785 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -25,6 +25,8 @@ from functools import partial
__all__ = ["compile_dir","compile_file","compile_path"]
def _walk_dir(dir, ddir=None, maxlevels=10, quiet=0):
+ if quiet < 2 and isinstance(dir, os.PathLike):
+ dir = os.fspath(dir)
if not quiet:
print('Listing {!r}...'.format(dir))
try:
@@ -68,7 +70,7 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
"""
files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels,
ddir=ddir)
- success = 1
+ success = True
if workers is not None and workers != 1 and ProcessPoolExecutor is not None:
if workers < 0:
raise ValueError('workers must be greater or equal to 0')
@@ -81,12 +83,12 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None,
legacy=legacy,
optimize=optimize),
files)
- success = min(results, default=1)
+ success = min(results, default=True)
else:
for file in files:
if not compile_file(file, ddir, force, rx, quiet,
legacy, optimize):
- success = 0
+ success = False
return success
def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
@@ -104,7 +106,9 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
legacy: if True, produce legacy pyc paths instead of PEP 3147 paths
optimize: optimization level or -1 for level of the interpreter
"""
- success = 1
+ success = True
+ if quiet < 2 and isinstance(fullname, os.PathLike):
+ fullname = os.fspath(fullname)
name = os.path.basename(fullname)
if ddir is not None:
dfile = os.path.join(ddir, name)
@@ -144,7 +148,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
ok = py_compile.compile(fullname, cfile, dfile, True,
optimize=optimize)
except py_compile.PyCompileError as err:
- success = 0
+ success = False
if quiet >= 2:
return success
elif quiet:
@@ -157,7 +161,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
msg = msg.decode(sys.stdout.encoding)
print(msg)
except (SyntaxError, UnicodeError, OSError) as e:
- success = 0
+ success = False
if quiet >= 2:
return success
elif quiet:
@@ -167,7 +171,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
print(e.__class__.__name__ + ':', e)
else:
if ok == 0:
- success = 0
+ success = False
return success
def compile_path(skip_curdir=1, maxlevels=0, force=False, quiet=0,
@@ -183,7 +187,7 @@ def compile_path(skip_curdir=1, maxlevels=0, force=False, quiet=0,
legacy: as for compile_dir() (default False)
optimize: as for compile_dir() (default -1)
"""
- success = 1
+ success = True
for dir in sys.path:
if (not dir or dir == os.curdir) and skip_curdir:
if quiet < 2:
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index 9c3aec9..03d276b 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -81,12 +81,13 @@ def _worker(executor_reference, work_queue):
_base.LOGGER.critical('Exception in worker', exc_info=True)
class ThreadPoolExecutor(_base.Executor):
- def __init__(self, max_workers=None):
+ def __init__(self, max_workers=None, thread_name_prefix=''):
"""Initializes a new ThreadPoolExecutor instance.
Args:
max_workers: The maximum number of threads that can be used to
execute the given calls.
+ thread_name_prefix: An optional name prefix to give our threads.
"""
if max_workers is None:
# Use this number because ThreadPoolExecutor is often
@@ -100,6 +101,7 @@ class ThreadPoolExecutor(_base.Executor):
self._threads = set()
self._shutdown = False
self._shutdown_lock = threading.Lock()
+ self._thread_name_prefix = thread_name_prefix
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
@@ -121,8 +123,11 @@ class ThreadPoolExecutor(_base.Executor):
q.put(None)
# TODO(bquinlan): Should avoid creating new threads if there are more
# idle threads than items in the work queue.
- if len(self._threads) < self._max_workers:
- t = threading.Thread(target=_worker,
+ num_threads = len(self._threads)
+ if num_threads < self._max_workers:
+ thread_name = '%s_%d' % (self._thread_name_prefix or self,
+ num_threads)
+ t = threading.Thread(name=thread_name, target=_worker,
args=(weakref.ref(self, weakref_cb),
self._work_queue))
t.daemon = True
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index d44edd6..7d94a57 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -1,11 +1,34 @@
"""Utilities for with-statement contexts. See PEP 343."""
-
+import abc
import sys
from collections import deque
from functools import wraps
-__all__ = ["contextmanager", "closing", "ContextDecorator", "ExitStack",
- "redirect_stdout", "redirect_stderr", "suppress"]
+__all__ = ["contextmanager", "closing", "AbstractContextManager",
+ "ContextDecorator", "ExitStack", "redirect_stdout",
+ "redirect_stderr", "suppress"]
+
+
+class AbstractContextManager(abc.ABC):
+
+ """An abstract base class for context managers."""
+
+ def __enter__(self):
+ """Return `self` upon entering the runtime context."""
+ return self
+
+ @abc.abstractmethod
+ def __exit__(self, exc_type, exc_value, traceback):
+ """Raise any exception triggered within the runtime context."""
+ return None
+
+ @classmethod
+ def __subclasshook__(cls, C):
+ if cls is AbstractContextManager:
+ if (any("__enter__" in B.__dict__ for B in C.__mro__) and
+ any("__exit__" in B.__dict__ for B in C.__mro__)):
+ return True
+ return NotImplemented
class ContextDecorator(object):
@@ -31,7 +54,7 @@ class ContextDecorator(object):
return inner
-class _GeneratorContextManager(ContextDecorator):
+class _GeneratorContextManager(ContextDecorator, AbstractContextManager):
"""Helper for @contextmanager decorator."""
def __init__(self, func, args, kwds):
@@ -137,7 +160,7 @@ def contextmanager(func):
return helper
-class closing(object):
+class closing(AbstractContextManager):
"""Context to automatically close something at the end of a block.
Code like this:
@@ -162,7 +185,7 @@ class closing(object):
self.thing.close()
-class _RedirectStream:
+class _RedirectStream(AbstractContextManager):
_stream = None
@@ -202,7 +225,7 @@ class redirect_stderr(_RedirectStream):
_stream = "stderr"
-class suppress:
+class suppress(AbstractContextManager):
"""Context manager to suppress specified exceptions
After the exception is suppressed, execution proceeds with the next
@@ -233,7 +256,7 @@ class suppress:
# Inspired by discussions on http://bugs.python.org/issue13585
-class ExitStack(object):
+class ExitStack(AbstractContextManager):
"""Context manager for dynamic management of a stack of exit callbacks
For example:
@@ -312,9 +335,6 @@ class ExitStack(object):
"""Immediately unwind the context stack"""
self.__exit__(None, None, None)
- def __enter__(self):
- return self
-
def __exit__(self, *exc_details):
received_exc = exc_details[0] is not None
diff --git a/Lib/copy.py b/Lib/copy.py
index 972b94a..f86040a 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -51,7 +51,6 @@ __getstate__() and __setstate__(). See the documentation for module
import types
import weakref
from copyreg import dispatch_table
-import builtins
class Error(Exception):
pass
@@ -102,37 +101,33 @@ def copy(x):
else:
raise Error("un(shallow)copyable object of type %s" % cls)
- return _reconstruct(x, rv, 0)
+ if isinstance(rv, str):
+ return x
+ return _reconstruct(x, None, *rv)
_copy_dispatch = d = {}
def _copy_immutable(x):
return x
-for t in (type(None), int, float, bool, str, tuple,
- bytes, frozenset, type, range,
- types.BuiltinFunctionType, type(Ellipsis),
+for t in (type(None), int, float, bool, complex, str, tuple,
+ bytes, frozenset, type, range, slice,
+ types.BuiltinFunctionType, type(Ellipsis), type(NotImplemented),
types.FunctionType, weakref.ref):
d[t] = _copy_immutable
t = getattr(types, "CodeType", None)
if t is not None:
d[t] = _copy_immutable
-for name in ("complex", "unicode"):
- t = getattr(builtins, name, None)
- if t is not None:
- d[t] = _copy_immutable
-
-def _copy_with_constructor(x):
- return type(x)(x)
-for t in (list, dict, set):
- d[t] = _copy_with_constructor
-
-def _copy_with_copy_method(x):
- return x.copy()
+
+d[list] = list.copy
+d[dict] = dict.copy
+d[set] = set.copy
+d[bytearray] = bytearray.copy
+
if PyStringMap is not None:
- d[PyStringMap] = _copy_with_copy_method
+ d[PyStringMap] = PyStringMap.copy
-del d
+del d, t
def deepcopy(x, memo=None, _nil=[]):
"""Deep copy operation on arbitrary Python objects.
@@ -179,7 +174,10 @@ def deepcopy(x, memo=None, _nil=[]):
else:
raise Error(
"un(deep)copyable object of type %s" % cls)
- y = _reconstruct(x, rv, 1, memo)
+ if isinstance(rv, str):
+ y = x
+ else:
+ y = _reconstruct(x, memo, *rv)
# If is its own copy, don't memoize.
if y is not x:
@@ -193,13 +191,11 @@ def _deepcopy_atomic(x, memo):
return x
d[type(None)] = _deepcopy_atomic
d[type(Ellipsis)] = _deepcopy_atomic
+d[type(NotImplemented)] = _deepcopy_atomic
d[int] = _deepcopy_atomic
d[float] = _deepcopy_atomic
d[bool] = _deepcopy_atomic
-try:
- d[complex] = _deepcopy_atomic
-except NameError:
- pass
+d[complex] = _deepcopy_atomic
d[bytes] = _deepcopy_atomic
d[str] = _deepcopy_atomic
try:
@@ -211,15 +207,16 @@ d[types.BuiltinFunctionType] = _deepcopy_atomic
d[types.FunctionType] = _deepcopy_atomic
d[weakref.ref] = _deepcopy_atomic
-def _deepcopy_list(x, memo):
+def _deepcopy_list(x, memo, deepcopy=deepcopy):
y = []
memo[id(x)] = y
+ append = y.append
for a in x:
- y.append(deepcopy(a, memo))
+ append(deepcopy(a, memo))
return y
d[list] = _deepcopy_list
-def _deepcopy_tuple(x, memo):
+def _deepcopy_tuple(x, memo, deepcopy=deepcopy):
y = [deepcopy(a, memo) for a in x]
# We're not going to put the tuple in the memo, but it's still important we
# check for it, in case the tuple contains recursive mutable structures.
@@ -236,7 +233,7 @@ def _deepcopy_tuple(x, memo):
return y
d[tuple] = _deepcopy_tuple
-def _deepcopy_dict(x, memo):
+def _deepcopy_dict(x, memo, deepcopy=deepcopy):
y = {}
memo[id(x)] = y
for key, value in x.items():
@@ -248,7 +245,9 @@ if PyStringMap is not None:
def _deepcopy_method(x, memo): # Copy instance methods
return type(x)(x.__func__, deepcopy(x.__self__, memo))
-_deepcopy_dispatch[types.MethodType] = _deepcopy_method
+d[types.MethodType] = _deepcopy_method
+
+del d
def _keep_alive(x, memo):
"""Keeps a reference to the object x in the memo.
@@ -266,31 +265,15 @@ def _keep_alive(x, memo):
# aha, this is the first one :-)
memo[id(memo)]=[x]
-def _reconstruct(x, info, deep, memo=None):
- if isinstance(info, str):
- return x
- assert isinstance(info, tuple)
- if memo is None:
- memo = {}
- n = len(info)
- assert n in (2, 3, 4, 5)
- callable, args = info[:2]
- if n > 2:
- state = info[2]
- else:
- state = None
- if n > 3:
- listiter = info[3]
- else:
- listiter = None
- if n > 4:
- dictiter = info[4]
- else:
- dictiter = None
+def _reconstruct(x, memo, func, args,
+ state=None, listiter=None, dictiter=None,
+ deepcopy=deepcopy):
+ deep = memo is not None
+ if deep and args:
+ args = (deepcopy(arg, memo) for arg in args)
+ y = func(*args)
if deep:
- args = deepcopy(args, memo)
- y = callable(*args)
- memo[id(x)] = y
+ memo[id(x)] = y
if state is not None:
if deep:
@@ -309,22 +292,22 @@ def _reconstruct(x, info, deep, memo=None):
setattr(y, key, value)
if listiter is not None:
- for item in listiter:
- if deep:
+ if deep:
+ for item in listiter:
item = deepcopy(item, memo)
- y.append(item)
+ y.append(item)
+ else:
+ for item in listiter:
+ y.append(item)
if dictiter is not None:
- for key, value in dictiter:
- if deep:
+ if deep:
+ for key, value in dictiter:
key = deepcopy(key, memo)
value = deepcopy(value, memo)
- y[key] = value
+ y[key] = value
+ else:
+ for key, value in dictiter:
+ y[key] = value
return y
-del d
-
-del types
-
-# Helper for instance creation without calling __init__
-class _EmptyClass:
- pass
+del types, weakref, PyStringMap
diff --git a/Lib/crypt.py b/Lib/crypt.py
index 49ab96e..fbc5f4c 100644
--- a/Lib/crypt.py
+++ b/Lib/crypt.py
@@ -54,9 +54,8 @@ METHOD_SHA256 = _Method('SHA256', '5', 16, 63)
METHOD_SHA512 = _Method('SHA512', '6', 16, 106)
methods = []
-for _method in (METHOD_SHA512, METHOD_SHA256, METHOD_MD5):
+for _method in (METHOD_SHA512, METHOD_SHA256, METHOD_MD5, METHOD_CRYPT):
_result = crypt('', _method)
if _result and len(_result) == _method.total_size:
methods.append(_method)
-methods.append(METHOD_CRYPT)
del _result, _method
diff --git a/Lib/csv.py b/Lib/csv.py
index ca40e5e..0349e0b 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -11,13 +11,15 @@ from _csv import Error, __version__, writer, reader, register_dialect, \
__doc__
from _csv import Dialect as _Dialect
+from collections import OrderedDict
from io import StringIO
-__all__ = [ "QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
- "Error", "Dialect", "__doc__", "excel", "excel_tab",
- "field_size_limit", "reader", "writer",
- "register_dialect", "get_dialect", "list_dialects", "Sniffer",
- "unregister_dialect", "__version__", "DictReader", "DictWriter" ]
+__all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
+ "Error", "Dialect", "__doc__", "excel", "excel_tab",
+ "field_size_limit", "reader", "writer",
+ "register_dialect", "get_dialect", "list_dialects", "Sniffer",
+ "unregister_dialect", "__version__", "DictReader", "DictWriter",
+ "unix_dialect"]
class Dialect:
"""Describe a CSV dialect.
@@ -115,7 +117,7 @@ class DictReader:
# values
while row == []:
row = next(self.reader)
- d = dict(zip(self.fieldnames, row))
+ d = OrderedDict(zip(self.fieldnames, row))
lf = len(self.fieldnames)
lr = len(row)
if lf < lr:
@@ -143,7 +145,7 @@ class DictWriter:
def _dict_to_list(self, rowdict):
if self.extrasaction == "raise":
- wrong_fields = [k for k in rowdict if k not in self.fieldnames]
+ wrong_fields = rowdict.keys() - self.fieldnames
if wrong_fields:
raise ValueError("dict contains fields not in fieldnames: "
+ ", ".join([repr(x) for x in wrong_fields]))
@@ -213,10 +215,10 @@ class Sniffer:
"""
matches = []
- for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
- '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
- '(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
- '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
+ for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
+ r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
+ r'(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
+ r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
matches = regexp.findall(data)
if matches:
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index 0d86078..1c9d3a5 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -16,7 +16,7 @@ from struct import calcsize as _calcsize
if __version__ != _ctypes_version:
raise Exception("Version number mismatch", __version__, _ctypes_version)
-if _os.name in ("nt", "ce"):
+if _os.name == "nt":
from _ctypes import FormatError
DEFAULT_MODE = RTLD_LOCAL
@@ -103,12 +103,9 @@ def CFUNCTYPE(restype, *argtypes, **kw):
_c_functype_cache[(restype, argtypes, flags)] = CFunctionType
return CFunctionType
-if _os.name in ("nt", "ce"):
+if _os.name == "nt":
from _ctypes import LoadLibrary as _dlopen
from _ctypes import FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL
- if _os.name == "ce":
- # 'ce' doesn't have the stdcall calling convention
- _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL
_win_functype_cache = {}
def WINFUNCTYPE(restype, *argtypes, **kw):
@@ -262,7 +259,7 @@ class c_wchar(_SimpleCData):
def _reset_cache():
_pointer_type_cache.clear()
_c_functype_cache.clear()
- if _os.name in ("nt", "ce"):
+ if _os.name == "nt":
_win_functype_cache.clear()
# _SimpleCData.c_wchar_p_from_param
POINTER(c_wchar).from_param = c_wchar_p.from_param
@@ -374,7 +371,7 @@ class PyDLL(CDLL):
"""
_func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
-if _os.name in ("nt", "ce"):
+if _os.name == "nt":
class WinDLL(CDLL):
"""This class represents a dll exporting functions using the
@@ -427,7 +424,7 @@ class LibraryLoader(object):
cdll = LibraryLoader(CDLL)
pydll = LibraryLoader(PyDLL)
-if _os.name in ("nt", "ce"):
+if _os.name == "nt":
pythonapi = PyDLL("python dll", None, _sys.dllhandle)
elif _sys.platform == "cygwin":
pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2])
@@ -435,7 +432,7 @@ else:
pythonapi = PyDLL(None)
-if _os.name in ("nt", "ce"):
+if _os.name == "nt":
windll = LibraryLoader(WinDLL)
oledll = LibraryLoader(OleDLL)
@@ -503,7 +500,7 @@ else:
return _wstring_at(ptr, size)
-if _os.name in ("nt", "ce"): # COM stuff
+if _os.name == "nt": # COM stuff
def DllGetClassObject(rclsid, riid, ppv):
try:
ccom = __import__("comtypes.server.inprocserver", globals(), locals(), ['*'])
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py
index b39d82c..c71d71d 100644
--- a/Lib/ctypes/test/test_bitfields.py
+++ b/Lib/ctypes/test/test_bitfields.py
@@ -3,7 +3,6 @@ from ctypes.test import need_symbol
import unittest
import os
-import ctypes
import _ctypes_test
class BITS(Structure):
@@ -197,7 +196,7 @@ class BitFieldTest(unittest.TestCase):
class X(Structure):
_fields_ = [("a", c_byte, 4),
("b", c_int, 4)]
- if os.name in ("nt", "ce"):
+ if os.name == "nt":
self.assertEqual(sizeof(X), sizeof(c_int)*2)
else:
self.assertEqual(sizeof(X), sizeof(c_int))
@@ -225,7 +224,7 @@ class BitFieldTest(unittest.TestCase):
# MSVC does NOT combine c_short and c_int into one field, GCC
# does (unless GCC is run with '-mms-bitfields' which
# produces code compatible with MSVC).
- if os.name in ("nt", "ce"):
+ if os.name == "nt":
self.assertEqual(sizeof(X), sizeof(c_int) * 4)
else:
self.assertEqual(sizeof(X), sizeof(c_int) * 2)
diff --git a/Lib/ctypes/test/test_find.py b/Lib/ctypes/test/test_find.py
index 94b0b89..b99fdcb 100644
--- a/Lib/ctypes/test/test_find.py
+++ b/Lib/ctypes/test/test_find.py
@@ -69,5 +69,48 @@ class Test_OpenGL_libs(unittest.TestCase):
self.assertFalse(os.path.lexists(test.support.TESTFN))
self.assertIsNone(result)
+
+@unittest.skipUnless(sys.platform.startswith('linux'),
+ 'Test only valid for Linux')
+class LibPathFindTest(unittest.TestCase):
+ def test_find_on_libpath(self):
+ import subprocess
+ import tempfile
+
+ try:
+ p = subprocess.Popen(['gcc', '--version'], stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL)
+ out, _ = p.communicate()
+ except OSError:
+ raise unittest.SkipTest('gcc, needed for test, not available')
+ with tempfile.TemporaryDirectory() as d:
+ # create an empty temporary file
+ srcname = os.path.join(d, 'dummy.c')
+ libname = 'py_ctypes_test_dummy'
+ dstname = os.path.join(d, 'lib%s.so' % libname)
+ with open(srcname, 'w') as f:
+ pass
+ self.assertTrue(os.path.exists(srcname))
+ # compile the file to a shared library
+ cmd = ['gcc', '-o', dstname, '--shared',
+ '-Wl,-soname,lib%s.so' % libname, srcname]
+ out = subprocess.check_output(cmd)
+ self.assertTrue(os.path.exists(dstname))
+ # now check that the .so can't be found (since not in
+ # LD_LIBRARY_PATH)
+ self.assertIsNone(find_library(libname))
+ # now add the location to LD_LIBRARY_PATH
+ with test.support.EnvironmentVarGuard() as env:
+ KEY = 'LD_LIBRARY_PATH'
+ if KEY not in env:
+ v = d
+ else:
+ v = '%s:%s' % (env[KEY], d)
+ env.set(KEY, v)
+ # now check that the .so can be found (since in
+ # LD_LIBRARY_PATH)
+ self.assertEqual(find_library(libname), 'lib%s.so' % libname)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/ctypes/test/test_funcptr.py b/Lib/ctypes/test/test_funcptr.py
index ff25c8f..f34734b 100644
--- a/Lib/ctypes/test/test_funcptr.py
+++ b/Lib/ctypes/test/test_funcptr.py
@@ -1,4 +1,4 @@
-import os, unittest
+import unittest
from ctypes import *
try:
@@ -39,7 +39,7 @@ class CFuncPtrTestCase(unittest.TestCase):
# possible, as in C, to call cdecl functions with more parameters.
#self.assertRaises(TypeError, c, 1, 2, 3)
self.assertEqual(c(1, 2, 3, 4, 5, 6), 3)
- if not WINFUNCTYPE is CFUNCTYPE and os.name != "ce":
+ if not WINFUNCTYPE is CFUNCTYPE:
self.assertRaises(TypeError, s, 1, 2, 3)
def test_structures(self):
diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py
index 28468c1..45571f3 100644
--- a/Lib/ctypes/test/test_loading.py
+++ b/Lib/ctypes/test/test_loading.py
@@ -11,8 +11,6 @@ def setUpModule():
global libc_name
if os.name == "nt":
libc_name = find_library("c")
- elif os.name == "ce":
- libc_name = "coredll"
elif sys.platform == "cygwin":
libc_name = "cygwin1.dll"
else:
@@ -49,8 +47,8 @@ class LoaderTest(unittest.TestCase):
cdll.LoadLibrary(lib)
CDLL(lib)
- @unittest.skipUnless(os.name in ("nt", "ce"),
- 'test specific to Windows (NT/CE)')
+ @unittest.skipUnless(os.name == "nt",
+ 'test specific to Windows')
def test_load_library(self):
# CRT is no longer directly loadable. See issue23606 for the
# discussion about alternative approaches.
@@ -64,14 +62,9 @@ class LoaderTest(unittest.TestCase):
windll["kernel32"].GetModuleHandleW
windll.LoadLibrary("kernel32").GetModuleHandleW
WinDLL("kernel32").GetModuleHandleW
- elif os.name == "ce":
- windll.coredll.GetModuleHandleW
- windll["coredll"].GetModuleHandleW
- windll.LoadLibrary("coredll").GetModuleHandleW
- WinDLL("coredll").GetModuleHandleW
-
- @unittest.skipUnless(os.name in ("nt", "ce"),
- 'test specific to Windows (NT/CE)')
+
+ @unittest.skipUnless(os.name == "nt",
+ 'test specific to Windows')
def test_load_ordinal_functions(self):
import _ctypes_test
dll = WinDLL(_ctypes_test.__file__)
diff --git a/Lib/ctypes/test/test_objects.py b/Lib/ctypes/test/test_objects.py
index ef7b20b..19e3dc1 100644
--- a/Lib/ctypes/test/test_objects.py
+++ b/Lib/ctypes/test/test_objects.py
@@ -54,7 +54,7 @@ of 'x' ('_b_base_' is either None, or the root object owning the memory block):
'''
-import unittest, doctest, sys
+import unittest, doctest
import ctypes.test.test_objects
diff --git a/Lib/ctypes/test/test_parameters.py b/Lib/ctypes/test/test_parameters.py
index e56bccf..363f586 100644
--- a/Lib/ctypes/test/test_parameters.py
+++ b/Lib/ctypes/test/test_parameters.py
@@ -1,4 +1,4 @@
-import unittest, sys
+import unittest
from ctypes.test import need_symbol
class SimpleTypesTestCase(unittest.TestCase):
@@ -49,7 +49,7 @@ class SimpleTypesTestCase(unittest.TestCase):
# XXX Replace by c_char_p tests
def test_cstrings(self):
- from ctypes import c_char_p, byref
+ from ctypes import c_char_p
# c_char_p.from_param on a Python String packs the string
# into a cparam object
@@ -68,7 +68,7 @@ class SimpleTypesTestCase(unittest.TestCase):
@need_symbol('c_wchar_p')
def test_cw_strings(self):
- from ctypes import byref, c_wchar_p
+ from ctypes import c_wchar_p
c_wchar_p.from_param("123")
@@ -98,7 +98,7 @@ class SimpleTypesTestCase(unittest.TestCase):
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
- from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
+ from ctypes import c_short, c_uint, c_int, c_long, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
diff --git a/Lib/ctypes/test/test_pep3118.py b/Lib/ctypes/test/test_pep3118.py
index 32f802c..d68397e 100644
--- a/Lib/ctypes/test/test_pep3118.py
+++ b/Lib/ctypes/test/test_pep3118.py
@@ -1,6 +1,6 @@
import unittest
from ctypes import *
-import re, struct, sys
+import re, sys
if sys.byteorder == "little":
THIS_ENDIAN = "<"
diff --git a/Lib/ctypes/test/test_returnfuncptrs.py b/Lib/ctypes/test/test_returnfuncptrs.py
index 93eba6b..1974f40 100644
--- a/Lib/ctypes/test/test_returnfuncptrs.py
+++ b/Lib/ctypes/test/test_returnfuncptrs.py
@@ -1,6 +1,5 @@
import unittest
from ctypes import *
-import os
import _ctypes_test
diff --git a/Lib/ctypes/test/test_sizes.py b/Lib/ctypes/test/test_sizes.py
index f9b5e97..4ceacbc 100644
--- a/Lib/ctypes/test/test_sizes.py
+++ b/Lib/ctypes/test/test_sizes.py
@@ -2,7 +2,6 @@
from ctypes import *
-import sys
import unittest
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
index c4a651c..8f6fe5f 100644
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -326,11 +326,8 @@ class StructureTestCase(unittest.TestCase):
cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c"))
self.assertEqual(cls, RuntimeError)
- if issubclass(Exception, object):
- self.assertEqual(msg,
- "(Phone) <class 'TypeError'>: too many initializers")
- else:
- self.assertEqual(msg, "(Phone) TypeError: too many initializers")
+ self.assertEqual(msg,
+ "(Phone) <class 'TypeError'>: too many initializers")
def test_huge_field_name(self):
# issue12881: segfault with large structure field names
diff --git a/Lib/ctypes/test/test_values.py b/Lib/ctypes/test/test_values.py
index 5a3a47f..e71b480 100644
--- a/Lib/ctypes/test/test_values.py
+++ b/Lib/ctypes/test/test_values.py
@@ -79,9 +79,9 @@ class PythonValuesTestCase(unittest.TestCase):
continue
items.append((entry.name.decode("ascii"), entry.size))
- expected = [("__hello__", 161),
- ("__phello__", -161),
- ("__phello__.spam", 161),
+ expected = [("__hello__", 139),
+ ("__phello__", -139),
+ ("__phello__.spam", 139),
]
self.assertEqual(items, expected, "PyImport_FrozenModules example "
"in Doc/library/ctypes.rst may be out of date")
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 7684eab..339ae8a 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -67,16 +67,6 @@ if os.name == "nt":
return fname
return None
-if os.name == "ce":
- # search path according to MSDN:
- # - absolute path specified by filename
- # - The .exe launch directory
- # - the Windows directory
- # - ROM dll files (where are they?)
- # - OEM specified search path: HKLM\Loader\SystemPath
- def find_library(name):
- return name
-
if os.name == "posix" and sys.platform == "darwin":
from ctypes.macholib.dyld import dyld_find as _dyld_find
def find_library(name):
@@ -271,8 +261,8 @@ elif os.name == "posix":
abi_type = mach_map.get(machine, 'libc6')
# XXX assuming GLIBC's ldconfig (with option -p)
- regex = os.fsencode(
- '\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type))
+ regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
+ regex = os.fsencode(regex % (re.escape(name), abi_type))
try:
with subprocess.Popen(['/sbin/ldconfig', '-p'],
stdin=subprocess.DEVNULL,
@@ -285,8 +275,32 @@ elif os.name == "posix":
except OSError:
pass
+ def _findLib_ld(name):
+ # See issue #9998 for why this is needed
+ expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
+ cmd = ['ld', '-t']
+ libpath = os.environ.get('LD_LIBRARY_PATH')
+ if libpath:
+ for d in libpath.split(':'):
+ cmd.extend(['-L', d])
+ cmd.extend(['-o', os.devnull, '-l%s' % name])
+ result = None
+ try:
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ universal_newlines=True)
+ out, _ = p.communicate()
+ res = re.search(expr, os.fsdecode(out))
+ if res:
+ result = res.group(0)
+ except Exception as e:
+ pass # result will be None
+ return result
+
def find_library(name):
- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
+ # See issue #9998
+ return _findSoname_ldconfig(name) or \
+ _get_soname(_findLib_gcc(name) or _findLib_ld(name))
################################################################
# test code
diff --git a/Lib/datetime.py b/Lib/datetime.py
index a2178c7..36374aa 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -152,12 +152,26 @@ def _build_struct_time(y, m, d, hh, mm, ss, dstflag):
dnum = _days_before_month(y, m) + d
return _time.struct_time((y, m, d, hh, mm, ss, wday, dnum, dstflag))
-def _format_time(hh, mm, ss, us):
- # Skip trailing microseconds when us==0.
- result = "%02d:%02d:%02d" % (hh, mm, ss)
- if us:
- result += ".%06d" % us
- return result
+def _format_time(hh, mm, ss, us, timespec='auto'):
+ specs = {
+ 'hours': '{:02d}',
+ 'minutes': '{:02d}:{:02d}',
+ 'seconds': '{:02d}:{:02d}:{:02d}',
+ 'milliseconds': '{:02d}:{:02d}:{:02d}.{:03d}',
+ 'microseconds': '{:02d}:{:02d}:{:02d}.{:06d}'
+ }
+
+ if timespec == 'auto':
+ # Skip trailing microseconds when us==0.
+ timespec = 'microseconds' if us else 'seconds'
+ elif timespec == 'milliseconds':
+ us //= 1000
+ try:
+ fmt = specs[timespec]
+ except KeyError:
+ raise ValueError('Unknown timespec value')
+ else:
+ return fmt.format(hh, mm, ss, us)
# Correctly substitute for %z and %Z escapes in strftime formats.
def _wrap_strftime(object, format, timetuple):
@@ -236,11 +250,11 @@ def _check_utc_offset(name, offset):
if not isinstance(offset, timedelta):
raise TypeError("tzinfo.%s() must return None "
"or timedelta, not '%s'" % (name, type(offset)))
- if offset % timedelta(minutes=1) or offset.microseconds:
+ if offset.microseconds:
raise ValueError("tzinfo.%s() must return a whole number "
- "of minutes, got %s" % (name, offset))
+ "of seconds, got %s" % (name, offset))
if not -timedelta(1) < offset < timedelta(1):
- raise ValueError("%s()=%s, must be must be strictly between "
+ raise ValueError("%s()=%s, must be strictly between "
"-timedelta(hours=24) and timedelta(hours=24)" %
(name, offset))
@@ -274,7 +288,7 @@ def _check_date_fields(year, month, day):
raise ValueError('day must be in 1..%d' % dim, day)
return year, month, day
-def _check_time_fields(hour, minute, second, microsecond):
+def _check_time_fields(hour, minute, second, microsecond, fold):
hour = _check_int_field(hour)
minute = _check_int_field(minute)
second = _check_int_field(second)
@@ -287,7 +301,9 @@ def _check_time_fields(hour, minute, second, microsecond):
raise ValueError('second must be in 0..59', second)
if not 0 <= microsecond <= 999999:
raise ValueError('microsecond must be in 0..999999', microsecond)
- return hour, minute, second, microsecond
+ if fold not in (0, 1):
+ raise ValueError('fold must be either 0 or 1', fold)
+ return hour, minute, second, microsecond, fold
def _check_tzinfo_arg(tz):
if tz is not None and not isinstance(tz, tzinfo):
@@ -316,6 +332,7 @@ def _divide_and_round(a, b):
return q
+
class timedelta:
"""Represent the difference between two datetime objects.
@@ -915,7 +932,7 @@ class date:
# Pickle support.
- def _getstate(self):
+ def _getstate(self, protocol=3):
yhi, ylo = divmod(self._year, 256)
return bytes([yhi, ylo, self._month, self._day]),
@@ -923,8 +940,8 @@ class date:
yhi, ylo, self._month, self._day = string
self._year = yhi * 256 + ylo
- def __reduce__(self):
- return (self.__class__, self._getstate())
+ def __reduce_ex__(self, protocol):
+ return (self.__class__, self._getstate(protocol))
_date_class = date # so functions w/ args named "date" can get at the class
@@ -932,6 +949,7 @@ date.min = date(1, 1, 1)
date.max = date(9999, 12, 31)
date.resolution = timedelta(days=1)
+
class tzinfo:
"""Abstract base class for time zone info classes.
@@ -1023,11 +1041,11 @@ class time:
dst()
Properties (readonly):
- hour, minute, second, microsecond, tzinfo
+ hour, minute, second, microsecond, tzinfo, fold
"""
- __slots__ = '_hour', '_minute', '_second', '_microsecond', '_tzinfo', '_hashcode'
+ __slots__ = '_hour', '_minute', '_second', '_microsecond', '_tzinfo', '_hashcode', '_fold'
- def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
+ def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0):
"""Constructor.
Arguments:
@@ -1035,15 +1053,16 @@ class time:
hour, minute (required)
second, microsecond (default to zero)
tzinfo (default to None)
+ fold (keyword only, default to True)
"""
- if isinstance(hour, bytes) and len(hour) == 6 and hour[0] < 24:
+ if isinstance(hour, bytes) and len(hour) == 6 and hour[0]&0x7F < 24:
# Pickle support
self = object.__new__(cls)
self.__setstate(hour, minute or None)
self._hashcode = -1
return self
- hour, minute, second, microsecond = _check_time_fields(
- hour, minute, second, microsecond)
+ hour, minute, second, microsecond, fold = _check_time_fields(
+ hour, minute, second, microsecond, fold)
_check_tzinfo_arg(tzinfo)
self = object.__new__(cls)
self._hour = hour
@@ -1052,6 +1071,7 @@ class time:
self._microsecond = microsecond
self._tzinfo = tzinfo
self._hashcode = -1
+ self._fold = fold
return self
# Read-only field accessors
@@ -1080,6 +1100,10 @@ class time:
"""timezone info object"""
return self._tzinfo
+ @property
+ def fold(self):
+ return self._fold
+
# Standard conversions, __hash__ (and helpers)
# Comparisons of time objects with other.
@@ -1145,9 +1169,13 @@ class time:
def __hash__(self):
"""Hash."""
if self._hashcode == -1:
- tzoff = self.utcoffset()
+ if self.fold:
+ t = self.replace(fold=0)
+ else:
+ t = self
+ tzoff = t.utcoffset()
if not tzoff: # zero or None
- self._hashcode = hash(self._getstate()[0])
+ self._hashcode = hash(t._getstate()[0])
else:
h, m = divmod(timedelta(hours=self.hour, minutes=self.minute) - tzoff,
timedelta(hours=1))
@@ -1171,10 +1199,11 @@ class time:
else:
sign = "+"
hh, mm = divmod(off, timedelta(hours=1))
- assert not mm % timedelta(minutes=1), "whole minute"
- mm //= timedelta(minutes=1)
+ mm, ss = divmod(mm, timedelta(minutes=1))
assert 0 <= hh < 24
off = "%s%02d%s%02d" % (sign, hh, sep, mm)
+ if ss:
+ off += ':%02d' % ss.seconds
return off
def __repr__(self):
@@ -1191,16 +1220,22 @@ class time:
if self._tzinfo is not None:
assert s[-1:] == ")"
s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
+ if self._fold:
+ assert s[-1:] == ")"
+ s = s[:-1] + ", fold=1)"
return s
- def isoformat(self):
+ def isoformat(self, timespec='auto'):
"""Return the time formatted according to ISO.
- This is 'HH:MM:SS.mmmmmm+zz:zz', or 'HH:MM:SS+zz:zz' if
- self.microsecond == 0.
+ The full format is 'HH:MM:SS.mmmmmm+zz:zz'. By default, the fractional
+ part is omitted if self.microsecond == 0.
+
+ The optional argument timespec specifies the number of additional
+ terms of the time to include.
"""
s = _format_time(self._hour, self._minute, self._second,
- self._microsecond)
+ self._microsecond, timespec)
tz = self._tzstr()
if tz:
s += tz
@@ -1266,7 +1301,7 @@ class time:
return offset
def replace(self, hour=None, minute=None, second=None, microsecond=None,
- tzinfo=True):
+ tzinfo=True, *, fold=None):
"""Return a new time with new values for the specified fields."""
if hour is None:
hour = self.hour
@@ -1278,14 +1313,19 @@ class time:
microsecond = self.microsecond
if tzinfo is True:
tzinfo = self.tzinfo
- return time(hour, minute, second, microsecond, tzinfo)
+ if fold is None:
+ fold = self._fold
+ return time(hour, minute, second, microsecond, tzinfo, fold=fold)
# Pickle support.
- def _getstate(self):
+ def _getstate(self, protocol=3):
us2, us3 = divmod(self._microsecond, 256)
us1, us2 = divmod(us2, 256)
- basestate = bytes([self._hour, self._minute, self._second,
+ h = self._hour
+ if self._fold and protocol > 3:
+ h += 128
+ basestate = bytes([h, self._minute, self._second,
us1, us2, us3])
if self._tzinfo is None:
return (basestate,)
@@ -1295,12 +1335,18 @@ class time:
def __setstate(self, string, tzinfo):
if tzinfo is not None and not isinstance(tzinfo, _tzinfo_class):
raise TypeError("bad tzinfo state arg")
- self._hour, self._minute, self._second, us1, us2, us3 = string
+ h, self._minute, self._second, us1, us2, us3 = string
+ if h > 127:
+ self._fold = 1
+ self._hour = h - 128
+ else:
+ self._fold = 0
+ self._hour = h
self._microsecond = (((us1 << 8) | us2) << 8) | us3
self._tzinfo = tzinfo
- def __reduce__(self):
- return (time, self._getstate())
+ def __reduce_ex__(self, protocol):
+ return (time, self._getstate(protocol))
_time_class = time # so functions w/ args named "time" can get at the class
@@ -1317,16 +1363,16 @@ class datetime(date):
__slots__ = date.__slots__ + time.__slots__
def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
- microsecond=0, tzinfo=None):
- if isinstance(year, bytes) and len(year) == 10 and 1 <= year[2] <= 12:
+ microsecond=0, tzinfo=None, *, fold=0):
+ if isinstance(year, bytes) and len(year) == 10 and 1 <= year[2]&0x7F <= 12:
# Pickle support
self = object.__new__(cls)
self.__setstate(year, month)
self._hashcode = -1
return self
year, month, day = _check_date_fields(year, month, day)
- hour, minute, second, microsecond = _check_time_fields(
- hour, minute, second, microsecond)
+ hour, minute, second, microsecond, fold = _check_time_fields(
+ hour, minute, second, microsecond, fold)
_check_tzinfo_arg(tzinfo)
self = object.__new__(cls)
self._year = year
@@ -1338,6 +1384,7 @@ class datetime(date):
self._microsecond = microsecond
self._tzinfo = tzinfo
self._hashcode = -1
+ self._fold = fold
return self
# Read-only field accessors
@@ -1366,6 +1413,10 @@ class datetime(date):
"""timezone info object"""
return self._tzinfo
+ @property
+ def fold(self):
+ return self._fold
+
@classmethod
def _fromtimestamp(cls, t, utc, tz):
"""Construct a datetime from a POSIX timestamp (like time.time()).
@@ -1384,7 +1435,23 @@ class datetime(date):
converter = _time.gmtime if utc else _time.localtime
y, m, d, hh, mm, ss, weekday, jday, dst = converter(t)
ss = min(ss, 59) # clamp out leap seconds if the platform has them
- return cls(y, m, d, hh, mm, ss, us, tz)
+ result = cls(y, m, d, hh, mm, ss, us, tz)
+ if tz is None:
+ # As of version 2015f max fold in IANA database is
+ # 23 hours at 1969-09-30 13:00:00 in Kwajalein.
+ # Let's probe 24 hours in the past to detect a transition:
+ max_fold_seconds = 24 * 3600
+ y, m, d, hh, mm, ss = converter(t - max_fold_seconds)[:6]
+ probe1 = cls(y, m, d, hh, mm, ss, us, tz)
+ trans = result - probe1 - timedelta(0, max_fold_seconds)
+ if trans.days < 0:
+ y, m, d, hh, mm, ss = converter(t + trans // timedelta(0, 1))[:6]
+ probe2 = cls(y, m, d, hh, mm, ss, us, tz)
+ if probe2 == result:
+ result._fold = 1
+ else:
+ result = tz.fromutc(result)
+ return result
@classmethod
def fromtimestamp(cls, t, tz=None):
@@ -1394,10 +1461,7 @@ class datetime(date):
"""
_check_tzinfo_arg(tz)
- result = cls._fromtimestamp(t, tz is not None, tz)
- if tz is not None:
- result = tz.fromutc(result)
- return result
+ return cls._fromtimestamp(t, tz is not None, tz)
@classmethod
def utcfromtimestamp(cls, t):
@@ -1417,15 +1481,17 @@ class datetime(date):
return cls.utcfromtimestamp(t)
@classmethod
- def combine(cls, date, time):
+ def combine(cls, date, time, tzinfo=True):
"Construct a datetime from a given date and a given time."
if not isinstance(date, _date_class):
raise TypeError("date argument must be a date instance")
if not isinstance(time, _time_class):
raise TypeError("time argument must be a time instance")
+ if tzinfo is True:
+ tzinfo = time.tzinfo
return cls(date.year, date.month, date.day,
time.hour, time.minute, time.second, time.microsecond,
- time.tzinfo)
+ tzinfo, fold=time.fold)
def timetuple(self):
"Return local time tuple compatible with time.localtime()."
@@ -1440,12 +1506,46 @@ class datetime(date):
self.hour, self.minute, self.second,
dst)
+ def _mktime(self):
+ """Return integer POSIX timestamp."""
+ epoch = datetime(1970, 1, 1)
+ max_fold_seconds = 24 * 3600
+ t = (self - epoch) // timedelta(0, 1)
+ def local(u):
+ y, m, d, hh, mm, ss = _time.localtime(u)[:6]
+ return (datetime(y, m, d, hh, mm, ss) - epoch) // timedelta(0, 1)
+
+ # Our goal is to solve t = local(u) for u.
+ a = local(t) - t
+ u1 = t - a
+ t1 = local(u1)
+ if t1 == t:
+ # We found one solution, but it may not be the one we need.
+ # Look for an earlier solution (if `fold` is 0), or a
+ # later one (if `fold` is 1).
+ u2 = u1 + (-max_fold_seconds, max_fold_seconds)[self.fold]
+ b = local(u2) - u2
+ if a == b:
+ return u1
+ else:
+ b = t1 - u1
+ assert a != b
+ u2 = t - b
+ t2 = local(u2)
+ if t2 == t:
+ return u2
+ if t1 == t:
+ return u1
+ # We have found both offsets a and b, but neither t - a nor t - b is
+ # a solution. This means t is in the gap.
+ return (max, min)[self.fold](u1, u2)
+
+
def timestamp(self):
"Return POSIX timestamp as float"
if self._tzinfo is None:
- return _time.mktime((self.year, self.month, self.day,
- self.hour, self.minute, self.second,
- -1, -1, -1)) + self.microsecond / 1e6
+ s = self._mktime()
+ return s + self.microsecond / 1e6
else:
return (self - _EPOCH).total_seconds()
@@ -1464,15 +1564,16 @@ class datetime(date):
def time(self):
"Return the time part, with tzinfo None."
- return time(self.hour, self.minute, self.second, self.microsecond)
+ return time(self.hour, self.minute, self.second, self.microsecond, fold=self.fold)
def timetz(self):
"Return the time part, with same tzinfo."
return time(self.hour, self.minute, self.second, self.microsecond,
- self._tzinfo)
+ self._tzinfo, fold=self.fold)
def replace(self, year=None, month=None, day=None, hour=None,
- minute=None, second=None, microsecond=None, tzinfo=True):
+ minute=None, second=None, microsecond=None, tzinfo=True,
+ *, fold=None):
"""Return a new datetime with new values for the specified fields."""
if year is None:
year = self.year
@@ -1490,46 +1591,45 @@ class datetime(date):
microsecond = self.microsecond
if tzinfo is True:
tzinfo = self.tzinfo
- return datetime(year, month, day, hour, minute, second, microsecond,
- tzinfo)
+ if fold is None:
+ fold = self.fold
+ return datetime(year, month, day, hour, minute, second,
+ microsecond, tzinfo, fold=fold)
+
+ def _local_timezone(self):
+ if self.tzinfo is None:
+ ts = self._mktime()
+ else:
+ ts = (self - _EPOCH) // timedelta(seconds=1)
+ localtm = _time.localtime(ts)
+ local = datetime(*localtm[:6])
+ try:
+ # Extract TZ data if available
+ gmtoff = localtm.tm_gmtoff
+ zone = localtm.tm_zone
+ except AttributeError:
+ delta = local - datetime(*_time.gmtime(ts)[:6])
+ zone = _time.strftime('%Z', localtm)
+ tz = timezone(delta, zone)
+ else:
+ tz = timezone(timedelta(seconds=gmtoff), zone)
+ return tz
def astimezone(self, tz=None):
if tz is None:
- if self.tzinfo is None:
- raise ValueError("astimezone() requires an aware datetime")
- ts = (self - _EPOCH) // timedelta(seconds=1)
- localtm = _time.localtime(ts)
- local = datetime(*localtm[:6])
- try:
- # Extract TZ data if available
- gmtoff = localtm.tm_gmtoff
- zone = localtm.tm_zone
- except AttributeError:
- # Compute UTC offset and compare with the value implied
- # by tm_isdst. If the values match, use the zone name
- # implied by tm_isdst.
- delta = local - datetime(*_time.gmtime(ts)[:6])
- dst = _time.daylight and localtm.tm_isdst > 0
- gmtoff = -(_time.altzone if dst else _time.timezone)
- if delta == timedelta(seconds=gmtoff):
- tz = timezone(delta, _time.tzname[dst])
- else:
- tz = timezone(delta)
- else:
- tz = timezone(timedelta(seconds=gmtoff), zone)
-
+ tz = self._local_timezone()
elif not isinstance(tz, tzinfo):
raise TypeError("tz argument must be an instance of tzinfo")
mytz = self.tzinfo
if mytz is None:
- raise ValueError("astimezone() requires an aware datetime")
+ mytz = self._local_timezone()
if tz is mytz:
return self
# Convert self to UTC, and attach the new time zone object.
- myoffset = self.utcoffset()
+ myoffset = mytz.utcoffset(self)
if myoffset is None:
raise ValueError("astimezone() requires an aware datetime")
utc = (self - myoffset).replace(tzinfo=tz)
@@ -1549,21 +1649,25 @@ class datetime(date):
self._hour, self._minute, self._second,
self._year)
- def isoformat(self, sep='T'):
+ def isoformat(self, sep='T', timespec='auto'):
"""Return the time formatted according to ISO.
- This is 'YYYY-MM-DD HH:MM:SS.mmmmmm', or 'YYYY-MM-DD HH:MM:SS' if
- self.microsecond == 0.
+ The full format looks like 'YYYY-MM-DD HH:MM:SS.mmmmmm'.
+ By default, the fractional part is omitted if self.microsecond == 0.
If self.tzinfo is not None, the UTC offset is also attached, giving
- 'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM' or 'YYYY-MM-DD HH:MM:SS+HH:MM'.
+ giving a full format of 'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM'.
Optional argument sep specifies the separator between date and
time, default 'T'.
+
+ The optional argument timespec specifies the number of additional
+ terms of the time to include.
"""
s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) +
_format_time(self._hour, self._minute, self._second,
- self._microsecond))
+ self._microsecond, timespec))
+
off = self.utcoffset()
if off is not None:
if off.days < 0:
@@ -1572,9 +1676,11 @@ class datetime(date):
else:
sign = "+"
hh, mm = divmod(off, timedelta(hours=1))
- assert not mm % timedelta(minutes=1), "whole minute"
- mm //= timedelta(minutes=1)
+ mm, ss = divmod(mm, timedelta(minutes=1))
s += "%s%02d:%02d" % (sign, hh, mm)
+ if ss:
+ assert not ss.microseconds
+ s += ":%02d" % ss.seconds
return s
def __repr__(self):
@@ -1591,6 +1697,9 @@ class datetime(date):
if self._tzinfo is not None:
assert s[-1:] == ")"
s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
+ if self._fold:
+ assert s[-1:] == ")"
+ s = s[:-1] + ", fold=1)"
return s
def __str__(self):
@@ -1693,6 +1802,12 @@ class datetime(date):
else:
myoff = self.utcoffset()
otoff = other.utcoffset()
+ # Assume that allow_mixed means that we are called from __eq__
+ if allow_mixed:
+ if myoff != self.replace(fold=not self.fold).utcoffset():
+ return 2
+ if otoff != other.replace(fold=not other.fold).utcoffset():
+ return 2
base_compare = myoff == otoff
if base_compare:
@@ -1760,9 +1875,13 @@ class datetime(date):
def __hash__(self):
if self._hashcode == -1:
- tzoff = self.utcoffset()
+ if self.fold:
+ t = self.replace(fold=0)
+ else:
+ t = self
+ tzoff = t.utcoffset()
if tzoff is None:
- self._hashcode = hash(self._getstate()[0])
+ self._hashcode = hash(t._getstate()[0])
else:
days = _ymd2ord(self.year, self.month, self.day)
seconds = self.hour * 3600 + self.minute * 60 + self.second
@@ -1771,11 +1890,14 @@ class datetime(date):
# Pickle support.
- def _getstate(self):
+ def _getstate(self, protocol=3):
yhi, ylo = divmod(self._year, 256)
us2, us3 = divmod(self._microsecond, 256)
us1, us2 = divmod(us2, 256)
- basestate = bytes([yhi, ylo, self._month, self._day,
+ m = self._month
+ if self._fold and protocol > 3:
+ m += 128
+ basestate = bytes([yhi, ylo, m, self._day,
self._hour, self._minute, self._second,
us1, us2, us3])
if self._tzinfo is None:
@@ -1786,14 +1908,20 @@ class datetime(date):
def __setstate(self, string, tzinfo):
if tzinfo is not None and not isinstance(tzinfo, _tzinfo_class):
raise TypeError("bad tzinfo state arg")
- (yhi, ylo, self._month, self._day, self._hour,
+ (yhi, ylo, m, self._day, self._hour,
self._minute, self._second, us1, us2, us3) = string
+ if m > 127:
+ self._fold = 1
+ self._month = m - 128
+ else:
+ self._fold = 0
+ self._month = m
self._year = yhi * 256 + ylo
self._microsecond = (((us1 << 8) | us2) << 8) | us3
self._tzinfo = tzinfo
- def __reduce__(self):
- return (self.__class__, self._getstate())
+ def __reduce_ex__(self, protocol):
+ return (self.__class__, self._getstate(protocol))
datetime.min = datetime(1, 1, 1)
@@ -1913,6 +2041,8 @@ class timezone(tzinfo):
@staticmethod
def _name_from_offset(delta):
+ if not delta:
+ return 'UTC'
if delta < timedelta(0):
sign = '-'
delta = -delta
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index 7777a7c..e7c6440 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -47,6 +47,7 @@ class _Database(collections.MutableMapping):
def __init__(self, filebasename, mode, flag='c'):
self._mode = mode
+ self._readonly = (flag == 'r')
# The directory file is a text file. Each line looks like
# "%r, (%d, %d)\n" % (key, pos, siz)
@@ -80,6 +81,11 @@ class _Database(collections.MutableMapping):
try:
f = _io.open(self._datfile, 'r', encoding="Latin-1")
except OSError:
+ if flag not in ('c', 'n'):
+ import warnings
+ warnings.warn("The database file is missing, the "
+ "semantics of the 'c' flag will be used.",
+ DeprecationWarning, stacklevel=4)
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
self._chmod(self._datfile)
else:
@@ -178,6 +184,10 @@ class _Database(collections.MutableMapping):
f.write("%r, %r\n" % (key.decode("Latin-1"), pos_and_siz_pair))
def __setitem__(self, key, val):
+ if self._readonly:
+ import warnings
+ warnings.warn('The database is opened for reading only',
+ DeprecationWarning, stacklevel=2)
if isinstance(key, str):
key = key.encode('utf-8')
elif not isinstance(key, (bytes, bytearray)):
@@ -212,6 +222,10 @@ class _Database(collections.MutableMapping):
# (so that _commit() never gets called).
def __delitem__(self, key):
+ if self._readonly:
+ import warnings
+ warnings.warn('The database is opened for reading only',
+ DeprecationWarning, stacklevel=2)
if isinstance(key, str):
key = key.encode('utf-8')
self._verify_open()
@@ -300,4 +314,8 @@ def open(file, flag='c', mode=0o666):
else:
# Turn off any bits that are set in the umask
mode = mode & (~um)
+ if flag not in ('r', 'w', 'c', 'n'):
+ import warnings
+ warnings.warn("Flag must be one of 'r', 'w', 'c', or 'n'",
+ DeprecationWarning, stacklevel=2)
return _Database(file, mode, flag=flag)
diff --git a/Lib/difflib.py b/Lib/difflib.py
index 076bbac..2095a5e 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1415,7 +1415,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
import re
# regular expression for finding intraline change indices
- change_re = re.compile('(\++|\-+|\^+)')
+ change_re = re.compile(r'(\++|\-+|\^+)')
# create the difference iterator to generate the differences
diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)
diff --git a/Lib/dis.py b/Lib/dis.py
index f7e3c7f..0794b7f 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -16,6 +16,8 @@ del _opcodes_all
_have_code = (types.MethodType, types.FunctionType, types.CodeType,
classmethod, staticmethod, type)
+FORMAT_VALUE = opmap['FORMAT_VALUE']
+
def _try_compile(source, name):
"""Attempts to compile the given source, first as an expression and
then as a statement if the first approach fails.
@@ -87,6 +89,7 @@ COMPILER_FLAG_NAMES = {
64: "NOFREE",
128: "COROUTINE",
256: "ITERABLE_COROUTINE",
+ 512: "ASYNC_GENERATOR",
}
def pretty_flags(flags):
@@ -163,6 +166,15 @@ def show_code(co, *, file=None):
_Instruction = collections.namedtuple("_Instruction",
"opname opcode arg argval argrepr offset starts_line is_jump_target")
+_Instruction.opname.__doc__ = "Human readable name for operation"
+_Instruction.opcode.__doc__ = "Numeric code for operation"
+_Instruction.arg.__doc__ = "Numeric argument to operation (if any), otherwise None"
+_Instruction.argval.__doc__ = "Resolved arg value (if known), otherwise same as arg"
+_Instruction.argrepr.__doc__ = "Human readable description of operation argument"
+_Instruction.offset.__doc__ = "Start index of operation within bytecode sequence"
+_Instruction.starts_line.__doc__ = "Line started by this opcode (if any), otherwise None"
+_Instruction.is_jump_target.__doc__ = "True if other code jumps to here, otherwise False"
+
class Instruction(_Instruction):
"""Details for a bytecode operation
@@ -276,7 +288,6 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
"""
labels = findlabels(code)
starts_line = None
- free = None
for offset, op, arg in _unpack_opargs(code):
if linestarts is not None:
starts_line = linestarts.get(offset, None)
@@ -296,7 +307,7 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
elif op in hasname:
argval, argrepr = _get_name_info(arg, names)
elif op in hasjrel:
- argval = offset + 3 + arg
+ argval = offset + 2 + arg
argrepr = "to " + repr(argval)
elif op in haslocal:
argval, argrepr = _get_name_info(arg, varnames)
@@ -305,8 +316,13 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
argrepr = argval
elif op in hasfree:
argval, argrepr = _get_name_info(arg, cells)
- elif op in hasnargs:
- argrepr = "%d positional, %d keyword pair" % (arg%256, arg//256)
+ elif op == FORMAT_VALUE:
+ argval = ((None, str, repr, ascii)[arg & 0x3], bool(arg & 0x4))
+ argrepr = ('', 'str', 'repr', 'ascii')[arg & 0x3]
+ if argval[1]:
+ if argrepr:
+ argrepr += ', '
+ argrepr += 'with format'
yield Instruction(opname[op], op,
arg, argval, argrepr,
offset, starts_line, is_jump_target)
@@ -343,23 +359,15 @@ def _disassemble_str(source, *, file=None):
disco = disassemble # XXX For backwards compatibility
def _unpack_opargs(code):
- # enumerate() is not an option, since we sometimes process
- # multiple elements on a single pass through the loop
extended_arg = 0
- n = len(code)
- i = 0
- while i < n:
+ for i in range(0, len(code), 2):
op = code[i]
- offset = i
- i = i+1
- arg = None
if op >= HAVE_ARGUMENT:
- arg = code[i] + code[i+1]*256 + extended_arg
- extended_arg = 0
- i = i+2
- if op == EXTENDED_ARG:
- extended_arg = arg*65536
- yield (offset, op, arg)
+ arg = code[i+1] | extended_arg
+ extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
+ else:
+ arg = None
+ yield (i, op, arg)
def findlabels(code):
"""Detect all offsets in a byte code which are jump targets.
@@ -370,14 +378,14 @@ def findlabels(code):
labels = []
for offset, op, arg in _unpack_opargs(code):
if arg is not None:
- label = -1
if op in hasjrel:
- label = offset + 3 + arg
+ label = offset + 2 + arg
elif op in hasjabs:
label = arg
- if label >= 0:
- if label not in labels:
- labels.append(label)
+ else:
+ continue
+ if label not in labels:
+ labels.append(label)
return labels
def findlinestarts(code):
@@ -386,8 +394,8 @@ def findlinestarts(code):
Generate pairs (offset, lineno) as described in Python/compile.c.
"""
- byte_increments = list(code.co_lnotab[0::2])
- line_increments = list(code.co_lnotab[1::2])
+ byte_increments = code.co_lnotab[0::2]
+ line_increments = code.co_lnotab[1::2]
lastlineno = None
lineno = code.co_firstlineno
@@ -398,6 +406,9 @@ def findlinestarts(code):
yield (addr, lineno)
lastlineno = lineno
addr += byte_incr
+ if line_incr >= 0x80:
+ # line_increments is an array of 8-bit signed integers
+ line_incr -= 0x100
lineno += line_incr
if lineno != lastlineno:
yield (addr, lineno)
diff --git a/Lib/distutils/archive_util.py b/Lib/distutils/archive_util.py
index bed1384..78ae575 100644
--- a/Lib/distutils/archive_util.py
+++ b/Lib/distutils/archive_util.py
@@ -171,7 +171,7 @@ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
path = os.path.normpath(os.path.join(dirpath, name))
if os.path.isfile(path):
zip.write(path, path)
- log.info("adding '%s'" % path)
+ log.info("adding '%s'", path)
zip.close()
return zip_filename
diff --git a/Lib/distutils/cmd.py b/Lib/distutils/cmd.py
index c89d5ef..939f795 100644
--- a/Lib/distutils/cmd.py
+++ b/Lib/distutils/cmd.py
@@ -221,7 +221,7 @@ class Command:
self._ensure_stringlike(option, "string", default)
def ensure_string_list(self, option):
- """Ensure that 'option' is a list of strings. If 'option' is
+ r"""Ensure that 'option' is a list of strings. If 'option' is
currently a string, we split it either on /,\s*/ or /\s+/, so
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
["foo", "bar", "baz"].
@@ -329,8 +329,7 @@ class Command:
# -- External world manipulation -----------------------------------
def warn(self, msg):
- log.warn("warning: %s: %s\n" %
- (self.get_command_name(), msg))
+ log.warn("warning: %s: %s\n", self.get_command_name(), msg)
def execute(self, func, args, msg=None, level=1):
util.execute(func, args, msg, dry_run=self.dry_run)
diff --git a/Lib/distutils/command/bdist_dumb.py b/Lib/distutils/command/bdist_dumb.py
index f1bfb24..e9274d9 100644
--- a/Lib/distutils/command/bdist_dumb.py
+++ b/Lib/distutils/command/bdist_dumb.py
@@ -85,7 +85,7 @@ class bdist_dumb(Command):
install.skip_build = self.skip_build
install.warn_dir = 0
- log.info("installing to %s" % self.bdist_dir)
+ log.info("installing to %s", self.bdist_dir)
self.run_command('install')
# And make an archive relative to the root of the
diff --git a/Lib/distutils/command/bdist_msi.py b/Lib/distutils/command/bdist_msi.py
index b3cfe9c..a4bd5a5 100644
--- a/Lib/distutils/command/bdist_msi.py
+++ b/Lib/distutils/command/bdist_msi.py
@@ -199,7 +199,7 @@ class bdist_msi(Command):
target_version = self.target_version
if not target_version:
assert self.skip_build, "Should have already checked this"
- target_version = sys.version[0:3]
+ target_version = '%d.%d' % sys.version_info[:2]
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
build = self.get_finalized_command('build')
build.build_lib = os.path.join(build.build_base,
@@ -623,7 +623,7 @@ class bdist_msi(Command):
cost = PyDialog(db, "DiskCostDlg", x, y, w, h, modal, title,
"OK", "OK", "OK", bitmap=False)
cost.text("Title", 15, 6, 200, 15, 0x30003,
- "{\DlgFontBold8}Disk Space Requirements")
+ r"{\DlgFontBold8}Disk Space Requirements")
cost.text("Description", 20, 20, 280, 20, 0x30003,
"The disk space required for the installation of the selected features.")
cost.text("Text", 20, 53, 330, 60, 3,
@@ -670,7 +670,7 @@ class bdist_msi(Command):
progress = PyDialog(db, "ProgressDlg", x, y, w, h, modeless, title,
"Cancel", "Cancel", "Cancel", bitmap=False)
progress.text("Title", 20, 15, 200, 15, 0x30003,
- "{\DlgFontBold8}[Progress1] [ProductName]")
+ r"{\DlgFontBold8}[Progress1] [ProductName]")
progress.text("Text", 35, 65, 300, 30, 3,
"Please wait while the Installer [Progress2] [ProductName]. "
"This may take several minutes.")
diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py
index 0c0e2c1..d3e1d3a 100644
--- a/Lib/distutils/command/bdist_wininst.py
+++ b/Lib/distutils/command/bdist_wininst.py
@@ -141,7 +141,7 @@ class bdist_wininst(Command):
target_version = self.target_version
if not target_version:
assert self.skip_build, "Should have already checked this"
- target_version = sys.version[0:3]
+ target_version = '%d.%d' % sys.version_info[:2]
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
build = self.get_finalized_command('build')
build.build_lib = os.path.join(build.build_base,
diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py
index 337dd0b..c6f52e6 100644
--- a/Lib/distutils/command/build.py
+++ b/Lib/distutils/command/build.py
@@ -81,7 +81,7 @@ class build(Command):
"--plat-name only supported on Windows (try "
"using './configure --help' on your platform)")
- plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
+ plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
# Make it so Python 2.x and Python 2.x with --with-pydebug don't
# share the same build directories. Doing so confuses the build
@@ -114,7 +114,7 @@ class build(Command):
'temp' + plat_specifier)
if self.build_scripts is None:
self.build_scripts = os.path.join(self.build_base,
- 'scripts-' + sys.version[0:3])
+ 'scripts-%d.%d' % sys.version_info[:2])
if self.executable is None:
self.executable = os.path.normpath(sys.executable)
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 7c278ef..74de782 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -364,9 +364,9 @@ class build_ext(Command):
ext_name, build_info = ext
- log.warn(("old-style (ext_name, build_info) tuple found in "
- "ext_modules for extension '%s'"
- "-- please convert to Extension instance" % ext_name))
+ log.warn("old-style (ext_name, build_info) tuple found in "
+ "ext_modules for extension '%s'"
+ "-- please convert to Extension instance", ext_name)
if not (isinstance(ext_name, str) and
extension_name_re.match(ext_name)):
diff --git a/Lib/distutils/command/build_scripts.py b/Lib/distutils/command/build_scripts.py
index 90a8380..ccc70e6 100644
--- a/Lib/distutils/command/build_scripts.py
+++ b/Lib/distutils/command/build_scripts.py
@@ -51,7 +51,7 @@ class build_scripts(Command):
def copy_scripts(self):
- """Copy each script listed in 'self.scripts'; if it's marked as a
+ r"""Copy each script listed in 'self.scripts'; if it's marked as a
Python script in the Unix way (first line matches 'first_line_re',
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py
index 847e858..4ae153d 100644
--- a/Lib/distutils/command/config.py
+++ b/Lib/distutils/command/config.py
@@ -9,7 +9,7 @@ configure-like tasks: "try to compile this C code", or "figure out where
this header file lives".
"""
-import sys, os, re
+import os, re
from distutils.core import Command
from distutils.errors import DistutilsExecError
@@ -337,7 +337,7 @@ def dump_file(filename, head=None):
If head is not None, will be dumped before the file content.
"""
if head is None:
- log.info('%s' % filename)
+ log.info('%s', filename)
else:
log.info(head)
file = open(filename)
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index 67db007..0258d3de 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -175,6 +175,7 @@ class install(Command):
self.compile = None
self.optimize = None
+ # Deprecated
# These two are for putting non-packagized distributions into their
# own directory and creating a .pth file if it makes sense.
# 'extra_path' comes from the setup file; 'install_path_file' can
@@ -290,8 +291,8 @@ class install(Command):
'dist_version': self.distribution.get_version(),
'dist_fullname': self.distribution.get_fullname(),
'py_version': py_version,
- 'py_version_short': py_version[0:3],
- 'py_version_nodot': py_version[0] + py_version[2],
+ 'py_version_short': '%d.%d' % sys.version_info[:2],
+ 'py_version_nodot': '%d%d' % sys.version_info[:2],
'sys_prefix': prefix,
'prefix': prefix,
'sys_exec_prefix': exec_prefix,
@@ -344,6 +345,7 @@ class install(Command):
'scripts', 'data', 'headers',
'userbase', 'usersite')
+ # Deprecated
# Well, we're not actually fully completely finalized yet: we still
# have to deal with 'extra_path', which is the hack for allowing
# non-packagized module distributions (hello, Numerical Python!) to
@@ -385,7 +387,7 @@ class install(Command):
else:
opt_name = opt_name.translate(longopt_xlate)
val = getattr(self, opt_name)
- log.debug(" %s: %s" % (opt_name, val))
+ log.debug(" %s: %s", opt_name, val)
def finalize_unix(self):
"""Finalizes options for posix platforms."""
@@ -490,6 +492,10 @@ class install(Command):
self.extra_path = self.distribution.extra_path
if self.extra_path is not None:
+ log.warn(
+ "Distribution option extra_path is deprecated. "
+ "See issue27919 for details."
+ )
if isinstance(self.extra_path, str):
self.extra_path = self.extra_path.split(',')
diff --git a/Lib/distutils/command/install_egg_info.py b/Lib/distutils/command/install_egg_info.py
index c2a7d64..0ddc736 100644
--- a/Lib/distutils/command/install_egg_info.py
+++ b/Lib/distutils/command/install_egg_info.py
@@ -21,10 +21,10 @@ class install_egg_info(Command):
def finalize_options(self):
self.set_undefined_options('install_lib',('install_dir','install_dir'))
- basename = "%s-%s-py%s.egg-info" % (
+ basename = "%s-%s-py%d.%d.egg-info" % (
to_filename(safe_name(self.distribution.get_name())),
to_filename(safe_version(self.distribution.get_version())),
- sys.version[:3]
+ *sys.version_info[:2]
)
self.target = os.path.join(self.install_dir, basename)
self.outputs = [self.target]
diff --git a/Lib/distutils/command/register.py b/Lib/distutils/command/register.py
index 86343c8..0fac94e 100644
--- a/Lib/distutils/command/register.py
+++ b/Lib/distutils/command/register.py
@@ -5,7 +5,7 @@ Implements the Distutils 'register' command (register with the repository).
# created 2002/10/21, Richard Jones
-import os, string, getpass
+import getpass
import io
import urllib.parse, urllib.request
from warnings import warn
@@ -94,7 +94,7 @@ class register(PyPIRCCommand):
'''
# send the info to the server and report the result
(code, result) = self.post_to_server(self.build_post_data('verify'))
- log.info('Server response (%s): %s' % (code, result))
+ log.info('Server response (%s): %s', code, result)
def send_metadata(self):
''' Send the metadata to the package index server.
@@ -205,7 +205,7 @@ Your selection [default 1]: ''', log.INFO)
data['email'] = input(' EMail: ')
code, result = self.post_to_server(data)
if code != 200:
- log.info('Server response (%s): %s' % (code, result))
+ log.info('Server response (%s): %s', code, result)
else:
log.info('You will receive an email shortly.')
log.info(('Follow the instructions in it to '
@@ -216,7 +216,7 @@ Your selection [default 1]: ''', log.INFO)
while not data['email']:
data['email'] = input('Your email address: ')
code, result = self.post_to_server(data)
- log.info('Server response (%s): %s' % (code, result))
+ log.info('Server response (%s): %s', code, result)
def build_post_data(self, action):
# figure the data to send - the metadata plus some additional
diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py
index 7ea3d5f..4fd1d47 100644
--- a/Lib/distutils/command/sdist.py
+++ b/Lib/distutils/command/sdist.py
@@ -3,7 +3,6 @@
Implements the Distutils 'sdist' command (create a source distribution)."""
import os
-import string
import sys
from types import *
from glob import glob
@@ -92,9 +91,6 @@ class sdist(Command):
negative_opt = {'no-defaults': 'use-defaults',
'no-prune': 'prune' }
- default_format = {'posix': 'gztar',
- 'nt': 'zip' }
-
sub_commands = [('check', checking_metadata)]
def initialize_options(self):
@@ -111,7 +107,7 @@ class sdist(Command):
self.manifest_only = 0
self.force_manifest = 0
- self.formats = None
+ self.formats = ['gztar']
self.keep_temp = 0
self.dist_dir = None
@@ -127,13 +123,6 @@ class sdist(Command):
self.template = "MANIFEST.in"
self.ensure_string_list('formats')
- if self.formats is None:
- try:
- self.formats = [self.default_format[os.name]]
- except KeyError:
- raise DistutilsPlatformError(
- "don't know how to create source distributions "
- "on platform %s" % os.name)
bad_format = archive_util.check_archive_formats(self.formats)
if bad_format:
@@ -423,7 +412,7 @@ class sdist(Command):
log.info(msg)
for file in files:
if not os.path.isfile(file):
- log.warn("'%s' not a regular file -- skipping" % file)
+ log.warn("'%s' not a regular file -- skipping", file)
else:
dest = os.path.join(base_dir, file)
self.copy_file(file, dest, link=link)
diff --git a/Lib/distutils/core.py b/Lib/distutils/core.py
index f05b34b..d603d4a 100644
--- a/Lib/distutils/core.py
+++ b/Lib/distutils/core.py
@@ -204,16 +204,15 @@ def run_setup (script_name, script_args=None, stop_after="run"):
global _setup_stop_after, _setup_distribution
_setup_stop_after = stop_after
- save_argv = sys.argv
+ save_argv = sys.argv.copy()
g = {'__file__': script_name}
- l = {}
try:
try:
sys.argv[0] = script_name
if script_args is not None:
sys.argv[1:] = script_args
with open(script_name, 'rb') as f:
- exec(f.read(), g, l)
+ exec(f.read(), g)
finally:
sys.argv = save_argv
_setup_stop_after = None
diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py
index c879646..1c36990 100644
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -368,7 +368,7 @@ def check_config_h():
return (CONFIG_H_UNCERTAIN,
"couldn't read '%s': %s" % (fn, exc.strerror))
-RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
+RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
def _find_exe_version(cmd):
"""Find the version of an executable by running `cmd` in the shell.
diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py
index ffb33ff6..62a2451 100644
--- a/Lib/distutils/dist.py
+++ b/Lib/distutils/dist.py
@@ -1018,8 +1018,7 @@ class DistributionMetadata:
"maintainer", "maintainer_email", "url",
"license", "description", "long_description",
"keywords", "platforms", "fullname", "contact",
- "contact_email", "license", "classifiers",
- "download_url",
+ "contact_email", "classifiers", "download_url",
# PEP 314
"provides", "requires", "obsoletes",
)
diff --git a/Lib/distutils/extension.py b/Lib/distutils/extension.py
index 7efbb74..c507da3 100644
--- a/Lib/distutils/extension.py
+++ b/Lib/distutils/extension.py
@@ -4,7 +4,6 @@ Provides the Extension class, used to describe C/C++ extension
modules in setup scripts."""
import os
-import sys
import warnings
# This class is really only used by the "build_ext" command, so it might
diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py
index 6522e69..c92d5fd 100644
--- a/Lib/distutils/filelist.py
+++ b/Lib/distutils/filelist.py
@@ -302,21 +302,26 @@ def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
else:
return pattern
+ # ditch start and end characters
+ start, _, end = glob_to_re('_').partition('_')
+
if pattern:
pattern_re = glob_to_re(pattern)
+ assert pattern_re.startswith(start) and pattern_re.endswith(end)
else:
pattern_re = ''
if prefix is not None:
- # ditch end of pattern character
- empty_pattern = glob_to_re('')
- prefix_re = glob_to_re(prefix)[:-len(empty_pattern)]
+ prefix_re = glob_to_re(prefix)
+ assert prefix_re.startswith(start) and prefix_re.endswith(end)
+ prefix_re = prefix_re[len(start): len(prefix_re) - len(end)]
sep = os.sep
if os.sep == '\\':
sep = r'\\'
- pattern_re = "^" + sep.join((prefix_re, ".*" + pattern_re))
+ pattern_re = pattern_re[len(start): len(pattern_re) - len(end)]
+ pattern_re = r'%s\A%s%s.*%s%s' % (start, prefix_re, sep, pattern_re, end)
else: # no prefix -- respect anchor flag
if anchor:
- pattern_re = "^" + pattern_re
+ pattern_re = r'%s\A%s' % (start, pattern_re[len(start):])
return re.compile(pattern_re)
diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
index 0b1fd19..2119127 100644
--- a/Lib/distutils/msvc9compiler.py
+++ b/Lib/distutils/msvc9compiler.py
@@ -716,7 +716,7 @@ class MSVCCompiler(CCompiler) :
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
re.DOTALL)
manifest_buf = re.sub(pattern, "", manifest_buf)
- pattern = "<dependentAssembly>\s*</dependentAssembly>"
+ pattern = r"<dependentAssembly>\s*</dependentAssembly>"
manifest_buf = re.sub(pattern, "", manifest_buf)
# Now see if any other assemblies are referenced - if not, we
# don't want a manifest embedded.
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 573724d..8bf1a70 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -70,7 +70,7 @@ def get_python_version():
leaving off the patchlevel. Sample return values could be '1.5'
or '2.2'.
"""
- return sys.version[:3]
+ return '%d.%d' % sys.version_info[:2]
def get_python_inc(plat_specific=0, prefix=None):
@@ -242,6 +242,8 @@ def get_makefile_filename():
return os.path.join(_sys_home or project_base, "Makefile")
lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
config_file = 'config-{}{}'.format(get_python_version(), build_flags)
+ if hasattr(sys.implementation, '_multiarch'):
+ config_file += '-%s' % sys.implementation._multiarch
return os.path.join(lib_dir, config_file, 'Makefile')
@@ -276,7 +278,7 @@ def parse_config_h(fp, g=None):
# Regexes needed for parsing Makefile (and similar syntaxes,
# like old-style Setup files).
-_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
+_variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
@@ -415,38 +417,18 @@ _config_vars = None
def _init_posix():
"""Initialize the module as appropriate for POSIX systems."""
- g = {}
- # load the installed Makefile:
- try:
- filename = get_makefile_filename()
- parse_makefile(filename, g)
- except OSError as msg:
- my_msg = "invalid Python installation: unable to open %s" % filename
- if hasattr(msg, "strerror"):
- my_msg = my_msg + " (%s)" % msg.strerror
-
- raise DistutilsPlatformError(my_msg)
-
- # load the installed pyconfig.h:
- try:
- filename = get_config_h_filename()
- with open(filename) as file:
- parse_config_h(file, g)
- except OSError as msg:
- my_msg = "invalid Python installation: unable to open %s" % filename
- if hasattr(msg, "strerror"):
- my_msg = my_msg + " (%s)" % msg.strerror
-
- raise DistutilsPlatformError(my_msg)
-
- # On AIX, there are wrong paths to the linker scripts in the Makefile
- # -- these paths are relative to the Python source, but when installed
- # the scripts are in another directory.
- if python_build:
- g['LDSHARED'] = g['BLDSHARED']
-
+ # _sysconfigdata is generated at build time, see the sysconfig module
+ name = os.environ.get('_PYTHON_SYSCONFIGDATA_NAME',
+ '_sysconfigdata_{abi}_{platform}_{multiarch}'.format(
+ abi=sys.abiflags,
+ platform=sys.platform,
+ multiarch=getattr(sys.implementation, '_multiarch', ''),
+ ))
+ _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
+ build_time_vars = _temp.build_time_vars
global _config_vars
- _config_vars = g
+ _config_vars = {}
+ _config_vars.update(build_time_vars)
def _init_nt():
diff --git a/Lib/distutils/tests/test_bdist_rpm.py b/Lib/distutils/tests/test_bdist_rpm.py
index 25c14ab..c1a2a04 100644
--- a/Lib/distutils/tests/test_bdist_rpm.py
+++ b/Lib/distutils/tests/test_bdist_rpm.py
@@ -3,16 +3,12 @@
import unittest
import sys
import os
-import tempfile
-import shutil
from test.support import run_unittest
from distutils.core import Distribution
from distutils.command.bdist_rpm import bdist_rpm
from distutils.tests import support
from distutils.spawn import find_executable
-from distutils import spawn
-from distutils.errors import DistutilsExecError
SETUP_PY = """\
from distutils.core import setup
diff --git a/Lib/distutils/tests/test_build.py b/Lib/distutils/tests/test_build.py
index 3391f36..b020a5b 100644
--- a/Lib/distutils/tests/test_build.py
+++ b/Lib/distutils/tests/test_build.py
@@ -27,7 +27,7 @@ class BuildTestCase(support.TempdirManager,
# build_platlib is 'build/lib.platform-x.x[-pydebug]'
# examples:
# build/lib.macosx-10.3-i386-2.7
- plat_spec = '.%s-%s' % (cmd.plat_name, sys.version[0:3])
+ plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2])
if hasattr(sys, 'gettotalrefcount'):
self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
plat_spec += '-pydebug'
@@ -42,7 +42,8 @@ class BuildTestCase(support.TempdirManager,
self.assertEqual(cmd.build_temp, wanted)
# build_scripts is build/scripts-x.x
- wanted = os.path.join(cmd.build_base, 'scripts-' + sys.version[0:3])
+ wanted = os.path.join(cmd.build_base,
+ 'scripts-%d.%d' % sys.version_info[:2])
self.assertEqual(cmd.build_scripts, wanted)
# executable is os.path.normpath(sys.executable)
diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index f3df564..6be0ca2 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -166,7 +166,6 @@ class BuildExtTestCase(TempdirManager,
cmd = self.build_ext(dist)
cmd.finalize_options()
- from distutils import sysconfig
py_include = sysconfig.get_python_inc()
self.assertIn(py_include, cmd.include_dirs)
diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py
index 18283dc..0712e92 100644
--- a/Lib/distutils/tests/test_build_py.py
+++ b/Lib/distutils/tests/test_build_py.py
@@ -168,7 +168,8 @@ class BuildPyTestCase(support.TempdirManager,
finally:
sys.dont_write_bytecode = old_dont_write_bytecode
- self.assertIn('byte-compiling is disabled', self.logs[0][1])
+ self.assertIn('byte-compiling is disabled',
+ self.logs[0][1] % self.logs[0][2])
def test_suite():
diff --git a/Lib/distutils/tests/test_clean.py b/Lib/distutils/tests/test_clean.py
index b64f300..c605afd 100644
--- a/Lib/distutils/tests/test_clean.py
+++ b/Lib/distutils/tests/test_clean.py
@@ -1,8 +1,6 @@
"""Tests for distutils.command.clean."""
-import sys
import os
import unittest
-import getpass
from distutils.command.clean import clean
from distutils.tests import support
diff --git a/Lib/distutils/tests/test_config.py b/Lib/distutils/tests/test_config.py
index a384497..77ef788 100644
--- a/Lib/distutils/tests/test_config.py
+++ b/Lib/distutils/tests/test_config.py
@@ -1,8 +1,6 @@
"""Tests for distutils.pypirc.pypirc."""
-import sys
import os
import unittest
-import tempfile
from distutils.core import PyPIRCCommand
from distutils.core import Distribution
diff --git a/Lib/distutils/tests/test_core.py b/Lib/distutils/tests/test_core.py
index 654227c..27ce732 100644
--- a/Lib/distutils/tests/test_core.py
+++ b/Lib/distutils/tests/test_core.py
@@ -29,6 +29,21 @@ from distutils.core import setup
setup()
"""
+setup_does_nothing = """\
+from distutils.core import setup
+setup()
+"""
+
+
+setup_defines_subclass = """\
+from distutils.core import setup
+from distutils.command.install import install as _install
+
+class install(_install):
+ sub_commands = _install.sub_commands + ['cmd']
+
+setup(cmdclass={'install': install})
+"""
class CoreTestCase(support.EnvironGuard, unittest.TestCase):
@@ -67,6 +82,21 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
distutils.core.run_setup(
self.write_setup(setup_using___file__))
+ def test_run_setup_preserves_sys_argv(self):
+ # Make sure run_setup does not clobber sys.argv
+ argv_copy = sys.argv.copy()
+ distutils.core.run_setup(
+ self.write_setup(setup_does_nothing))
+ self.assertEqual(sys.argv, argv_copy)
+
+ def test_run_setup_defines_subclass(self):
+ # Make sure the script can use __file__; if that's missing, the test
+ # setup.py script will raise NameError.
+ dist = distutils.core.run_setup(
+ self.write_setup(setup_defines_subclass))
+ install = dist.get_command_obj('install')
+ self.assertIn('cmd', install.sub_commands)
+
def test_run_setup_uses_current_dir(self):
# This tests that the setup script is run with the current directory
# as its own current directory; this was temporarily broken by a
diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py
index 8569216..9dc869d 100644
--- a/Lib/distutils/tests/test_cygwinccompiler.py
+++ b/Lib/distutils/tests/test_cygwinccompiler.py
@@ -3,11 +3,10 @@ import unittest
import sys
import os
from io import BytesIO
-import subprocess
from test.support import run_unittest
from distutils import cygwinccompiler
-from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h,
+from distutils.cygwinccompiler import (check_config_h,
CONFIG_H_OK, CONFIG_H_NOTOK,
CONFIG_H_UNCERTAIN, get_versions,
get_msvcr)
diff --git a/Lib/distutils/tests/test_dep_util.py b/Lib/distutils/tests/test_dep_util.py
index 3e1c366..c6fae39 100644
--- a/Lib/distutils/tests/test_dep_util.py
+++ b/Lib/distutils/tests/test_dep_util.py
@@ -1,7 +1,6 @@
"""Tests for distutils.dep_util."""
import unittest
import os
-import time
from distutils.dep_util import newer, newer_pairwise, newer_group
from distutils.errors import DistutilsFileError
diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py
index a6d04f0..03040af 100644
--- a/Lib/distutils/tests/test_file_util.py
+++ b/Lib/distutils/tests/test_file_util.py
@@ -1,7 +1,6 @@
"""Tests for distutils.file_util."""
import unittest
import os
-import shutil
import errno
from unittest.mock import patch
diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py
index 391af3c..c71342d 100644
--- a/Lib/distutils/tests/test_filelist.py
+++ b/Lib/distutils/tests/test_filelist.py
@@ -51,14 +51,14 @@ class FileListTestCase(support.LoggingSilencer,
for glob, regex in (
# simple cases
- ('foo*', r'foo[^%(sep)s]*\Z(?ms)'),
- ('foo?', r'foo[^%(sep)s]\Z(?ms)'),
- ('foo??', r'foo[^%(sep)s][^%(sep)s]\Z(?ms)'),
+ ('foo*', r'(?s:foo[^%(sep)s]*)\Z'),
+ ('foo?', r'(?s:foo[^%(sep)s])\Z'),
+ ('foo??', r'(?s:foo[^%(sep)s][^%(sep)s])\Z'),
# special cases
- (r'foo\\*', r'foo\\\\[^%(sep)s]*\Z(?ms)'),
- (r'foo\\\*', r'foo\\\\\\[^%(sep)s]*\Z(?ms)'),
- ('foo????', r'foo[^%(sep)s][^%(sep)s][^%(sep)s][^%(sep)s]\Z(?ms)'),
- (r'foo\\??', r'foo\\\\[^%(sep)s][^%(sep)s]\Z(?ms)')):
+ (r'foo\\*', r'(?s:foo\\\\[^%(sep)s]*)\Z'),
+ (r'foo\\\*', r'(?s:foo\\\\\\[^%(sep)s]*)\Z'),
+ ('foo????', r'(?s:foo[^%(sep)s][^%(sep)s][^%(sep)s][^%(sep)s])\Z'),
+ (r'foo\\??', r'(?s:foo\\\\[^%(sep)s][^%(sep)s])\Z')):
regex = regex % {'sep': sep}
self.assertEqual(glob_to_re(glob), regex)
diff --git a/Lib/distutils/tests/test_install_data.py b/Lib/distutils/tests/test_install_data.py
index 4d8c00a..32ab296 100644
--- a/Lib/distutils/tests/test_install_data.py
+++ b/Lib/distutils/tests/test_install_data.py
@@ -1,8 +1,6 @@
"""Tests for distutils.command.install_data."""
-import sys
import os
import unittest
-import getpass
from distutils.command.install_data import install_data
from distutils.tests import support
diff --git a/Lib/distutils/tests/test_install_headers.py b/Lib/distutils/tests/test_install_headers.py
index d953157..2217b32 100644
--- a/Lib/distutils/tests/test_install_headers.py
+++ b/Lib/distutils/tests/test_install_headers.py
@@ -1,8 +1,6 @@
"""Tests for distutils.command.install_headers."""
-import sys
import os
import unittest
-import getpass
from distutils.command.install_headers import install_headers
from distutils.tests import support
diff --git a/Lib/distutils/tests/test_install_lib.py b/Lib/distutils/tests/test_install_lib.py
index 5378aa8..fda6315 100644
--- a/Lib/distutils/tests/test_install_lib.py
+++ b/Lib/distutils/tests/test_install_lib.py
@@ -104,7 +104,8 @@ class InstallLibTestCase(support.TempdirManager,
finally:
sys.dont_write_bytecode = old_dont_write_bytecode
- self.assertIn('byte-compiling is disabled', self.logs[0][1])
+ self.assertIn('byte-compiling is disabled',
+ self.logs[0][1] % self.logs[0][2])
def test_suite():
diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py
index 6c7eb20..5edc24a 100644
--- a/Lib/distutils/tests/test_spawn.py
+++ b/Lib/distutils/tests/test_spawn.py
@@ -1,11 +1,11 @@
"""Tests for distutils.spawn."""
import unittest
+import sys
import os
-import time
-from test.support import captured_stdout, run_unittest
+from test.support import run_unittest, unix_shell
from distutils.spawn import _nt_quote_args
-from distutils.spawn import spawn, find_executable
+from distutils.spawn import spawn
from distutils.errors import DistutilsExecError
from distutils.tests import support
@@ -30,9 +30,9 @@ class SpawnTestCase(support.TempdirManager,
# creating something executable
# through the shell that returns 1
- if os.name == 'posix':
+ if sys.platform != 'win32':
exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!/bin/sh\nexit 1')
+ self.write_file(exe, '#!%s\nexit 1' % unix_shell)
else:
exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 1')
@@ -41,9 +41,9 @@ class SpawnTestCase(support.TempdirManager,
self.assertRaises(DistutilsExecError, spawn, [exe])
# now something that works
- if os.name == 'posix':
+ if sys.platform != 'win32':
exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!/bin/sh\nexit 0')
+ self.write_file(exe, '#!%s\nexit 0' % unix_shell)
else:
exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 0')
diff --git a/Lib/distutils/tests/test_unixccompiler.py b/Lib/distutils/tests/test_unixccompiler.py
index e171ee9..efba27e 100644
--- a/Lib/distutils/tests/test_unixccompiler.py
+++ b/Lib/distutils/tests/test_unixccompiler.py
@@ -1,5 +1,4 @@
"""Tests for distutils.unixccompiler."""
-import os
import sys
import unittest
from test.support import EnvironmentVarGuard, run_unittest
diff --git a/Lib/distutils/text_file.py b/Lib/distutils/text_file.py
index 478336f..93abad3 100644
--- a/Lib/distutils/text_file.py
+++ b/Lib/distutils/text_file.py
@@ -4,7 +4,7 @@ provides the TextFile class, which gives an interface to text files
that (optionally) takes care of stripping comments, ignoring blank
lines, and joining lines with backslashes."""
-import sys, os, io
+import sys, io
class TextFile:
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index e423325..fdcf6fa 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -7,8 +7,8 @@ one of the other *util.py modules.
import os
import re
import importlib.util
-import sys
import string
+import sys
from distutils.errors import DistutilsPlatformError
from distutils.dep_util import newer
from distutils.spawn import spawn
@@ -350,6 +350,11 @@ def byte_compile (py_files,
generated in indirect mode; unless you know what you're doing, leave
it set to None.
"""
+
+ # Late import to fix a bootstrap issue: _posixsubprocess is built by
+ # setup.py, but setup.py uses distutils.
+ import subprocess
+
# nothing is done if sys.dont_write_bytecode is True
if sys.dont_write_bytecode:
raise DistutilsByteCompileError('byte-compiling is disabled.')
@@ -412,11 +417,9 @@ byte_compile(files, optimize=%r, force=%r,
script.close()
- cmd = [sys.executable, script_name]
- if optimize == 1:
- cmd.insert(1, "-O")
- elif optimize == 2:
- cmd.insert(1, "-OO")
+ cmd = [sys.executable]
+ cmd.extend(subprocess._optim_args_from_interpreter_flags())
+ cmd.append(script_name)
spawn(cmd, dry_run=dry_run)
execute(os.remove, (script_name,), "removing %s" % script_name,
dry_run=dry_run)
diff --git a/Lib/distutils/versionpredicate.py b/Lib/distutils/versionpredicate.py
index b0dd9f4..062c98f 100644
--- a/Lib/distutils/versionpredicate.py
+++ b/Lib/distutils/versionpredicate.py
@@ -154,7 +154,7 @@ def split_provision(value):
global _provision_rx
if _provision_rx is None:
_provision_rx = re.compile(
- "([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$",
+ r"([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$",
re.ASCII)
value = value.strip()
m = _provision_rx.match(value)
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 38fdd80..0b78544 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -381,12 +381,15 @@ class _OutputRedirectingPdb(pdb.Pdb):
sys.stdout = save_stdout
# [XX] Normalize with respect to os.path.pardir?
-def _module_relative_path(module, path):
+def _module_relative_path(module, test_path):
if not inspect.ismodule(module):
raise TypeError('Expected a module: %r' % module)
- if path.startswith('/'):
+ if test_path.startswith('/'):
raise ValueError('Module-relative files may not have absolute paths')
+ # Normalize the path. On Windows, replace "/" with "\".
+ test_path = os.path.join(*(test_path.split('/')))
+
# Find the base directory for the path.
if hasattr(module, '__file__'):
# A normal module/package
@@ -398,13 +401,19 @@ def _module_relative_path(module, path):
else:
basedir = os.curdir
else:
+ if hasattr(module, '__path__'):
+ for directory in module.__path__:
+ fullpath = os.path.join(directory, test_path)
+ if os.path.exists(fullpath):
+ return fullpath
+
# A module w/o __file__ (this includes builtins)
raise ValueError("Can't resolve paths relative to the module "
"%r (it has no __file__)"
% module.__name__)
- # Combine the base directory and the path.
- return os.path.join(basedir, *(path.split('/')))
+ # Combine the base directory and the test path.
+ return os.path.join(basedir, test_path)
######################################################################
## 2. Example & DocTest
@@ -756,7 +765,7 @@ class DocTestParser:
# This regular expression finds the indentation of every non-blank
# line in a string.
- _INDENT_RE = re.compile('^([ ]*)(?=\S)', re.MULTILINE)
+ _INDENT_RE = re.compile(r'^([ ]*)(?=\S)', re.MULTILINE)
def _min_indent(self, s):
"Return the minimum indentation of any non-blank line in `s`"
@@ -1097,7 +1106,7 @@ class DocTestFinder:
if lineno is not None:
if source_lines is None:
return lineno+1
- pat = re.compile('(^|.*:)\s*\w*("|\')')
+ pat = re.compile(r'(^|.*:)\s*\w*("|\')')
for lineno in range(lineno, len(source_lines)):
if pat.match(source_lines[lineno]):
return lineno
@@ -1599,11 +1608,11 @@ class OutputChecker:
# blank line, unless the DONT_ACCEPT_BLANKLINE flag is used.
if not (optionflags & DONT_ACCEPT_BLANKLINE):
# Replace <BLANKLINE> in want with a blank line.
- want = re.sub('(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER),
+ want = re.sub(r'(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER),
'', want)
# If a line in got contains only spaces, then remove the
# spaces.
- got = re.sub('(?m)^\s*?$', '', got)
+ got = re.sub(r'(?m)^\s*?$', '', got)
if got == want:
return True
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index 5df9511..57d01fb 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -652,8 +652,8 @@ class Comment(WhiteSpaceTokenList):
if value.token_type == 'comment':
return str(value)
return str(value).replace('\\', '\\\\').replace(
- '(', '\(').replace(
- ')', '\)')
+ '(', r'\(').replace(
+ ')', r'\)')
@property
def content(self):
@@ -1356,15 +1356,15 @@ RouteComponentMarker = ValueTerminal('@', 'route-component-marker')
_wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split
_non_atom_end_matcher = re.compile(r"[^{}]+".format(
- ''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\]'))).match
+ ''.join(ATOM_ENDS).replace('\\','\\\\').replace(']',r'\]'))).match
_non_printable_finder = re.compile(r"[\x00-\x20\x7F]").findall
_non_token_end_matcher = re.compile(r"[^{}]+".format(
- ''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\]'))).match
+ ''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']',r'\]'))).match
_non_attribute_end_matcher = re.compile(r"[^{}]+".format(
- ''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\]'))).match
+ ''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']',r'\]'))).match
_non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format(
''.join(EXTENDED_ATTRIBUTE_ENDS).replace(
- '\\','\\\\').replace(']','\]'))).match
+ '\\','\\\\').replace(']',r'\]'))).match
def _validate_xtext(xtext):
"""If input token contains ASCII non-printables, register a defect."""
@@ -1517,7 +1517,7 @@ def get_unstructured(value):
return unstructured
def get_qp_ctext(value):
- """ctext = <printable ascii except \ ( )>
+ r"""ctext = <printable ascii except \ ( )>
This is not the RFC ctext, since we are handling nested comments in comment
and unquoting quoted-pairs here. We allow anything except the '()'
@@ -1878,7 +1878,7 @@ def get_obs_local_part(value):
return obs_local_part, value
def get_dtext(value):
- """ dtext = <printable ascii except \ [ ]> / obs-dtext
+ r""" dtext = <printable ascii except \ [ ]> / obs-dtext
obs-dtext = obs-NO-WS-CTL / quoted-pair
We allow anything except the excluded characters, but if we find any
diff --git a/Lib/email/_policybase.py b/Lib/email/_policybase.py
index c0d98a4..df46496 100644
--- a/Lib/email/_policybase.py
+++ b/Lib/email/_policybase.py
@@ -154,6 +154,9 @@ class Policy(_PolicyBase, metaclass=abc.ABCMeta):
them. This is used when the message is being
serialized by a generator. Default: True.
+ message_factory -- the class to use to create new message objects.
+ If the value is None, the default is Message.
+
"""
raise_on_defect = False
@@ -161,6 +164,7 @@ class Policy(_PolicyBase, metaclass=abc.ABCMeta):
cte_type = '8bit'
max_line_length = 78
mangle_from_ = False
+ message_factory = None
def handle_defect(self, obj, defect):
"""Based on policy, either raise defect or call register_defect.
diff --git a/Lib/email/contentmanager.py b/Lib/email/contentmanager.py
index b98ce27..b904ded 100644
--- a/Lib/email/contentmanager.py
+++ b/Lib/email/contentmanager.py
@@ -142,7 +142,7 @@ def _encode_base64(data, max_line_length):
def _encode_text(string, charset, cte, policy):
lines = string.encode(charset).splitlines()
linesep = policy.linesep.encode('ascii')
- def embeded_body(lines): return linesep.join(lines) + linesep
+ def embedded_body(lines): return linesep.join(lines) + linesep
def normal_body(lines): return b'\n'.join(lines) + b'\n'
if cte==None:
# Use heuristics to decide on the "best" encoding.
@@ -153,7 +153,7 @@ def _encode_text(string, charset, cte, policy):
if (policy.cte_type == '8bit' and
max(len(x) for x in lines) <= policy.max_line_length):
return '8bit', normal_body(lines).decode('ascii', 'surrogateescape')
- sniff = embeded_body(lines[:10])
+ sniff = embedded_body(lines[:10])
sniff_qp = quoprimime.body_encode(sniff.decode('latin-1'),
policy.max_line_length)
sniff_base64 = binascii.b2a_base64(sniff)
@@ -172,7 +172,7 @@ def _encode_text(string, charset, cte, policy):
data = quoprimime.body_encode(normal_body(lines).decode('latin-1'),
policy.max_line_length)
elif cte == 'base64':
- data = _encode_base64(embeded_body(lines), policy.max_line_length)
+ data = _encode_base64(embedded_body(lines), policy.max_line_length)
else:
raise ValueError("Unknown content transfer encoding {}".format(cte))
return cte, data
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
index 0b312e5..7c07ca8 100644
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -24,15 +24,14 @@ __all__ = ['FeedParser', 'BytesFeedParser']
import re
from email import errors
-from email import message
from email._policybase import compat32
from collections import deque
from io import StringIO
-NLCRE = re.compile('\r\n|\r|\n')
-NLCRE_bol = re.compile('(\r\n|\r|\n)')
-NLCRE_eol = re.compile('(\r\n|\r|\n)\Z')
-NLCRE_crack = re.compile('(\r\n|\r|\n)')
+NLCRE = re.compile(r'\r\n|\r|\n')
+NLCRE_bol = re.compile(r'(\r\n|\r|\n)')
+NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z')
+NLCRE_crack = re.compile(r'(\r\n|\r|\n)')
# RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character
# except controls, SP, and ":".
headerRE = re.compile(r'^(From |[\041-\071\073-\176]*:|[\t ])')
@@ -148,13 +147,11 @@ class FeedParser:
self.policy = policy
self._old_style_factory = False
if _factory is None:
- # What this should be:
- #self._factory = policy.default_message_factory
- # but, because we are post 3.4 feature freeze, fix with temp hack:
- if self.policy is compat32:
- self._factory = message.Message
+ if policy.message_factory is None:
+ from email.message import Message
+ self._factory = Message
else:
- self._factory = message.EmailMessage
+ self._factory = policy.message_factory
else:
self._factory = _factory
try:
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
index 256278d..ae670c2 100644
--- a/Lib/email/generator.py
+++ b/Lib/email/generator.py
@@ -448,7 +448,8 @@ class DecodedGenerator(Generator):
Like the Generator base class, except that non-text parts are substituted
with a format string representing the part.
"""
- def __init__(self, outfp, mangle_from_=None, maxheaderlen=78, fmt=None):
+ def __init__(self, outfp, mangle_from_=None, maxheaderlen=None, fmt=None, *,
+ policy=None):
"""Like Generator.__init__() except that an additional optional
argument is allowed.
@@ -470,7 +471,8 @@ class DecodedGenerator(Generator):
[Non-text (%(type)s) part of message omitted, filename %(filename)s]
"""
- Generator.__init__(self, outfp, mangle_from_, maxheaderlen)
+ Generator.__init__(self, outfp, mangle_from_, maxheaderlen,
+ policy=policy)
if fmt is None:
self._fmt = _FMT
else:
diff --git a/Lib/email/header.py b/Lib/email/header.py
index 6820ea1..c7b2dd9 100644
--- a/Lib/email/header.py
+++ b/Lib/email/header.py
@@ -49,7 +49,7 @@ fcre = re.compile(r'[\041-\176]+:$')
# Find a header embedded in a putative header value. Used to check for
# header injection attack.
-_embeded_header = re.compile(r'\n[^ \t]+:')
+_embedded_header = re.compile(r'\n[^ \t]+:')
@@ -385,7 +385,7 @@ class Header:
if self._chunks:
formatter.add_transition()
value = formatter._str(linesep)
- if _embeded_header.search(value):
+ if _embedded_header.search(value):
raise HeaderParseError("header value appears to contain "
"an embedded header: {!r}".format(value))
return value
diff --git a/Lib/email/message.py b/Lib/email/message.py
index 4b04283..b6512f2 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -4,18 +4,17 @@
"""Basic message object for the email package object model."""
-__all__ = ['Message']
+__all__ = ['Message', 'EmailMessage']
import re
import uu
import quopri
-import warnings
from io import BytesIO, StringIO
# Intrapackage imports
from email import utils
from email import errors
-from email._policybase import compat32
+from email._policybase import Policy, compat32
from email import charset as _charset
from email._encoded_words import decode_b
Charset = _charset.Charset
@@ -951,6 +950,26 @@ class MIMEPart(Message):
policy = default
Message.__init__(self, policy)
+
+ def as_string(self, unixfrom=False, maxheaderlen=None, policy=None):
+ """Return the entire formatted message as a string.
+
+ Optional 'unixfrom', when true, means include the Unix From_ envelope
+ header. maxheaderlen is retained for backward compatibility with the
+ base Message class, but defaults to None, meaning that the policy value
+ for max_line_length controls the header maximum length. 'policy' is
+ passed to the Generator instance used to serialize the mesasge; if it
+ is not specified the policy associated with the message instance is
+ used.
+ """
+ policy = self.policy if policy is None else policy
+ if maxheaderlen is None:
+ maxheaderlen = policy.max_line_length
+ return super().as_string(maxheaderlen=maxheaderlen, policy=policy)
+
+ def __str__(self):
+ return self.as_string(policy=self.policy.clone(utf8=True))
+
def is_attachment(self):
c_d = self.get('content-disposition')
return False if c_d is None else c_d.content_disposition == 'attachment'
diff --git a/Lib/email/mime/application.py b/Lib/email/mime/application.py
index f5c5905..6877e55 100644
--- a/Lib/email/mime/application.py
+++ b/Lib/email/mime/application.py
@@ -14,7 +14,7 @@ class MIMEApplication(MIMENonMultipart):
"""Class for generating application/* MIME documents."""
def __init__(self, _data, _subtype='octet-stream',
- _encoder=encoders.encode_base64, **_params):
+ _encoder=encoders.encode_base64, *, policy=None, **_params):
"""Create an application/* type MIME document.
_data is a string containing the raw application data.
@@ -31,6 +31,7 @@ class MIMEApplication(MIMENonMultipart):
"""
if _subtype is None:
raise TypeError('Invalid application MIME subtype')
- MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
+ MIMENonMultipart.__init__(self, 'application', _subtype, policy=policy,
+ **_params)
self.set_payload(_data)
_encoder(self)
diff --git a/Lib/email/mime/audio.py b/Lib/email/mime/audio.py
index fbc1189..4bcd7b2 100644
--- a/Lib/email/mime/audio.py
+++ b/Lib/email/mime/audio.py
@@ -43,7 +43,7 @@ class MIMEAudio(MIMENonMultipart):
"""Class for generating audio/* MIME documents."""
def __init__(self, _audiodata, _subtype=None,
- _encoder=encoders.encode_base64, **_params):
+ _encoder=encoders.encode_base64, *, policy=None, **_params):
"""Create an audio/* type MIME document.
_audiodata is a string containing the raw audio data. If this data
@@ -68,6 +68,7 @@ class MIMEAudio(MIMENonMultipart):
_subtype = _whatsnd(_audiodata)
if _subtype is None:
raise TypeError('Could not find audio MIME subtype')
- MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
+ MIMENonMultipart.__init__(self, 'audio', _subtype, policy=policy,
+ **_params)
self.set_payload(_audiodata)
_encoder(self)
diff --git a/Lib/email/mime/base.py b/Lib/email/mime/base.py
index ac91925..1a3f9b5 100644
--- a/Lib/email/mime/base.py
+++ b/Lib/email/mime/base.py
@@ -6,6 +6,8 @@
__all__ = ['MIMEBase']
+import email.policy
+
from email import message
@@ -13,14 +15,16 @@ from email import message
class MIMEBase(message.Message):
"""Base class for MIME specializations."""
- def __init__(self, _maintype, _subtype, **_params):
+ def __init__(self, _maintype, _subtype, *, policy=None, **_params):
"""This constructor adds a Content-Type: and a MIME-Version: header.
The Content-Type: header is taken from the _maintype and _subtype
arguments. Additional parameters for this header are taken from the
keyword arguments.
"""
- message.Message.__init__(self)
+ if policy is None:
+ policy = email.policy.compat32
+ message.Message.__init__(self, policy=policy)
ctype = '%s/%s' % (_maintype, _subtype)
self.add_header('Content-Type', ctype, **_params)
self['MIME-Version'] = '1.0'
diff --git a/Lib/email/mime/image.py b/Lib/email/mime/image.py
index 5563823..9272464 100644
--- a/Lib/email/mime/image.py
+++ b/Lib/email/mime/image.py
@@ -17,7 +17,7 @@ class MIMEImage(MIMENonMultipart):
"""Class for generating image/* type MIME documents."""
def __init__(self, _imagedata, _subtype=None,
- _encoder=encoders.encode_base64, **_params):
+ _encoder=encoders.encode_base64, *, policy=None, **_params):
"""Create an image/* type MIME document.
_imagedata is a string containing the raw image data. If this data
@@ -41,6 +41,7 @@ class MIMEImage(MIMENonMultipart):
_subtype = imghdr.what(None, _imagedata)
if _subtype is None:
raise TypeError('Could not guess image MIME subtype')
- MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
+ MIMENonMultipart.__init__(self, 'image', _subtype, policy=policy,
+ **_params)
self.set_payload(_imagedata)
_encoder(self)
diff --git a/Lib/email/mime/message.py b/Lib/email/mime/message.py
index 275dbfd..07e4f2d 100644
--- a/Lib/email/mime/message.py
+++ b/Lib/email/mime/message.py
@@ -14,7 +14,7 @@ from email.mime.nonmultipart import MIMENonMultipart
class MIMEMessage(MIMENonMultipart):
"""Class representing message/* MIME documents."""
- def __init__(self, _msg, _subtype='rfc822'):
+ def __init__(self, _msg, _subtype='rfc822', *, policy=None):
"""Create a message/* type MIME document.
_msg is a message object and must be an instance of Message, or a
@@ -24,7 +24,7 @@ class MIMEMessage(MIMENonMultipart):
default is "rfc822" (this is defined by the MIME standard, even though
the term "rfc822" is technically outdated by RFC 2822).
"""
- MIMENonMultipart.__init__(self, 'message', _subtype)
+ MIMENonMultipart.__init__(self, 'message', _subtype, policy=policy)
if not isinstance(_msg, message.Message):
raise TypeError('Argument is not an instance of Message')
# It's convenient to use this base class method. We need to do it
diff --git a/Lib/email/mime/multipart.py b/Lib/email/mime/multipart.py
index 9661865..2d3f288 100644
--- a/Lib/email/mime/multipart.py
+++ b/Lib/email/mime/multipart.py
@@ -14,6 +14,7 @@ class MIMEMultipart(MIMEBase):
"""Base class for MIME multipart/* type messages."""
def __init__(self, _subtype='mixed', boundary=None, _subparts=None,
+ *, policy=None,
**_params):
"""Creates a multipart/* type message.
@@ -33,7 +34,7 @@ class MIMEMultipart(MIMEBase):
Additional parameters for the Content-Type header are taken from the
keyword arguments (or passed into the _params argument).
"""
- MIMEBase.__init__(self, 'multipart', _subtype, **_params)
+ MIMEBase.__init__(self, 'multipart', _subtype, policy=policy, **_params)
# Initialise _payload to an empty list as the Message superclass's
# implementation of is_multipart assumes that _payload is a list for
diff --git a/Lib/email/mime/text.py b/Lib/email/mime/text.py
index da03086..35b4423 100644
--- a/Lib/email/mime/text.py
+++ b/Lib/email/mime/text.py
@@ -14,7 +14,7 @@ from email.mime.nonmultipart import MIMENonMultipart
class MIMEText(MIMENonMultipart):
"""Class for generating text/* type MIME documents."""
- def __init__(self, _text, _subtype='plain', _charset=None):
+ def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None):
"""Create a text/* type MIME document.
_text is the string for this message object.
@@ -36,7 +36,7 @@ class MIMEText(MIMENonMultipart):
except UnicodeEncodeError:
_charset = 'utf-8'
- MIMENonMultipart.__init__(self, 'text', _subtype,
+ MIMENonMultipart.__init__(self, 'text', _subtype, policy=policy,
**{'charset': str(_charset)})
self.set_payload(_text, _charset)
diff --git a/Lib/email/policy.py b/Lib/email/policy.py
index 35d0e69..5131311ac 100644
--- a/Lib/email/policy.py
+++ b/Lib/email/policy.py
@@ -7,6 +7,7 @@ from email._policybase import Policy, Compat32, compat32, _extend_docstrings
from email.utils import _has_surrogates
from email.headerregistry import HeaderRegistry as HeaderRegistry
from email.contentmanager import raw_data_manager
+from email.message import EmailMessage
__all__ = [
'Compat32',
@@ -82,6 +83,7 @@ class EmailPolicy(Policy):
"""
+ message_factory = EmailMessage
utf8 = False
refold_source = 'long'
header_factory = HeaderRegistry()
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py
index 8dd7130..aa2fb7c 100644
--- a/Lib/encodings/__init__.py
+++ b/Lib/encodings/__init__.py
@@ -29,6 +29,7 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
"""#"
import codecs
+import sys
from . import aliases
_cache = {}
@@ -54,6 +55,7 @@ def normalize_encoding(encoding):
"""
if isinstance(encoding, bytes):
encoding = str(encoding, "ascii")
+
chars = []
punct = False
for c in encoding:
@@ -97,6 +99,8 @@ def search_function(encoding):
mod = __import__('encodings.' + modname, fromlist=_import_tail,
level=0)
except ImportError:
+ # ImportError may occur because 'encodings.(modname)' does not exist,
+ # or because it imports a name that does not exist (see mbcs and oem)
pass
else:
break
@@ -150,3 +154,16 @@ def search_function(encoding):
# Register the search_function in the Python codec registry
codecs.register(search_function)
+
+if sys.platform == 'win32':
+ def _alias_mbcs(encoding):
+ try:
+ import _bootlocale
+ if encoding == _bootlocale.getpreferredencoding(False):
+ import encodings.mbcs
+ return encodings.mbcs.getregentry()
+ except ImportError:
+ # Imports may fail while we are shutting down
+ pass
+
+ codecs.register(_alias_mbcs)
diff --git a/Lib/encodings/aliases.py b/Lib/encodings/aliases.py
index 67c828d..2e63c2f 100644
--- a/Lib/encodings/aliases.py
+++ b/Lib/encodings/aliases.py
@@ -458,6 +458,7 @@ aliases = {
'macturkish' : 'mac_turkish',
# mbcs codec
+ 'ansi' : 'mbcs',
'dbcs' : 'mbcs',
# ptcp154 codec
diff --git a/Lib/encodings/oem.py b/Lib/encodings/oem.py
new file mode 100644
index 0000000..2c3426b
--- /dev/null
+++ b/Lib/encodings/oem.py
@@ -0,0 +1,41 @@
+""" Python 'oem' Codec for Windows
+
+"""
+# Import them explicitly to cause an ImportError
+# on non-Windows systems
+from codecs import oem_encode, oem_decode
+# for IncrementalDecoder, IncrementalEncoder, ...
+import codecs
+
+### Codec APIs
+
+encode = oem_encode
+
+def decode(input, errors='strict'):
+ return oem_decode(input, errors, True)
+
+class IncrementalEncoder(codecs.IncrementalEncoder):
+ def encode(self, input, final=False):
+ return oem_encode(input, self.errors)[0]
+
+class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
+ _buffer_decode = oem_decode
+
+class StreamWriter(codecs.StreamWriter):
+ encode = oem_encode
+
+class StreamReader(codecs.StreamReader):
+ decode = oem_decode
+
+### encodings module API
+
+def getregentry():
+ return codecs.CodecInfo(
+ name='oem',
+ encode=encode,
+ decode=decode,
+ incrementalencoder=IncrementalEncoder,
+ incrementaldecoder=IncrementalDecoder,
+ streamreader=StreamReader,
+ streamwriter=StreamWriter,
+ )
diff --git a/Lib/enum.py b/Lib/enum.py
index b8787d1..4beb187 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -1,8 +1,20 @@
import sys
-from collections import OrderedDict
from types import MappingProxyType, DynamicClassAttribute
+from functools import reduce
+from operator import or_ as _or_, and_ as _and_, xor, neg
-__all__ = ['Enum', 'IntEnum', 'unique']
+# try _collections first to reduce startup cost
+try:
+ from _collections import OrderedDict
+except ImportError:
+ from collections import OrderedDict
+
+
+__all__ = [
+ 'EnumMeta',
+ 'Enum', 'IntEnum', 'Flag', 'IntFlag',
+ 'auto', 'unique',
+ ]
def _is_descriptor(obj):
@@ -28,7 +40,6 @@ def _is_sunder(name):
name[-2:-1] != '_' and
len(name) > 2)
-
def _make_class_unpicklable(cls):
"""Make the given class un-picklable."""
def _break_on_call_reduce(self, proto):
@@ -36,6 +47,13 @@ def _make_class_unpicklable(cls):
cls.__reduce_ex__ = _break_on_call_reduce
cls.__module__ = '<unknown>'
+_auto_null = object()
+class auto:
+ """
+ Instances are replaced with an appropriate value in Enum class suites.
+ """
+ value = _auto_null
+
class _EnumDict(dict):
"""Track enum member order and ensure member names are not reused.
@@ -47,6 +65,7 @@ class _EnumDict(dict):
def __init__(self):
super().__init__()
self._member_names = []
+ self._last_values = []
def __setitem__(self, key, value):
"""Changes anything not dundered or not a descriptor.
@@ -58,21 +77,32 @@ class _EnumDict(dict):
"""
if _is_sunder(key):
- raise ValueError('_names_ are reserved for future Enum use')
+ if key not in (
+ '_order_', '_create_pseudo_member_',
+ '_generate_next_value_', '_missing_',
+ ):
+ raise ValueError('_names_ are reserved for future Enum use')
+ if key == '_generate_next_value_':
+ setattr(self, '_generate_next_value', value)
elif _is_dunder(key):
- pass
+ if key == '__order__':
+ key = '_order_'
elif key in self._member_names:
# descriptor overwriting an enum?
raise TypeError('Attempted to reuse key: %r' % key)
elif not _is_descriptor(value):
if key in self:
# enum overwriting a descriptor?
- raise TypeError('Key already defined as: %r' % self[key])
+ raise TypeError('%r already defined as: %r' % (key, self[key]))
+ if isinstance(value, auto):
+ if value.value == _auto_null:
+ value.value = self._generate_next_value(key, 1, len(self._member_names), self._last_values[:])
+ value = value.value
self._member_names.append(key)
+ self._last_values.append(value)
super().__setitem__(key, value)
-
# Dummy value for Enum as EnumMeta explicitly checks for it, but of course
# until EnumMeta finishes running the first time the Enum class doesn't exist.
# This is also why there are checks in EnumMeta like `if Enum is not None`
@@ -83,7 +113,13 @@ class EnumMeta(type):
"""Metaclass for Enum"""
@classmethod
def __prepare__(metacls, cls, bases):
- return _EnumDict()
+ # create the namespace dict
+ enum_dict = _EnumDict()
+ # inherit previous flags and _generate_next_value_ function
+ member_type, first_enum = metacls._get_mixins_(bases)
+ if first_enum is not None:
+ enum_dict['_generate_next_value_'] = getattr(first_enum, '_generate_next_value_', None)
+ return enum_dict
def __new__(metacls, cls, bases, classdict):
# an Enum class is final once enumeration items have been defined; it
@@ -96,12 +132,15 @@ class EnumMeta(type):
# save enum items into separate mapping so they don't get baked into
# the new class
- members = {k: classdict[k] for k in classdict._member_names}
+ enum_members = {k: classdict[k] for k in classdict._member_names}
for name in classdict._member_names:
del classdict[name]
+ # adjust the sunders
+ _order_ = classdict.pop('_order_', None)
+
# check for illegal enum names (any others?)
- invalid_names = set(members) & {'mro', }
+ invalid_names = set(enum_members) & {'mro', }
if invalid_names:
raise ValueError('Invalid enum member name: {0}'.format(
','.join(invalid_names)))
@@ -145,7 +184,7 @@ class EnumMeta(type):
# a custom __new__ is doing something funky with the values -- such as
# auto-numbering ;)
for member_name in classdict._member_names:
- value = members[member_name]
+ value = enum_members[member_name]
if not isinstance(value, tuple):
args = (value, )
else:
@@ -159,7 +198,10 @@ class EnumMeta(type):
else:
enum_member = __new__(enum_class, *args)
if not hasattr(enum_member, '_value_'):
- enum_member._value_ = member_type(*args)
+ if member_type is object:
+ enum_member._value_ = value
+ else:
+ enum_member._value_ = member_type(*args)
value = enum_member._value_
enum_member._name_ = member_name
enum_member.__objclass__ = enum_class
@@ -204,6 +246,14 @@ class EnumMeta(type):
if save_new:
enum_class.__new_member__ = __new__
enum_class.__new__ = Enum.__new__
+
+ # py3 support for definition order (helps keep py2/py3 code in sync)
+ if _order_ is not None:
+ if isinstance(_order_, str):
+ _order_ = _order_.replace(',', ' ').split()
+ if _order_ != enum_class._member_names_:
+ raise TypeError('member order does not match _order_')
+
return enum_class
def __bool__(self):
@@ -325,13 +375,19 @@ class EnumMeta(type):
"""
metacls = cls.__class__
bases = (cls, ) if type is None else (type, cls)
+ _, first_enum = cls._get_mixins_(bases)
classdict = metacls.__prepare__(class_name, bases)
# special processing needed for names?
if isinstance(names, str):
names = names.replace(',', ' ').split()
if isinstance(names, (tuple, list)) and isinstance(names[0], str):
- names = [(e, i) for (i, e) in enumerate(names, start)]
+ original_names, names = names, []
+ last_values = []
+ for count, name in enumerate(original_names):
+ value = first_enum._generate_next_value_(name, start, count, last_values[:])
+ last_values.append(value)
+ names.append((name, value))
# Here, names is either an iterable of (name, value) or a mapping.
for item in names:
@@ -473,6 +529,20 @@ class Enum(metaclass=EnumMeta):
for member in cls._member_map_.values():
if member._value_ == value:
return member
+ # still not found -- try _missing_ hook
+ return cls._missing_(value)
+
+ def _generate_next_value_(name, start, count, last_values):
+ for last_value in reversed(last_values):
+ try:
+ return last_value + 1
+ except TypeError:
+ pass
+ else:
+ return start
+
+ @classmethod
+ def _missing_(cls, value):
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
def __repr__(self):
@@ -544,8 +614,21 @@ class Enum(metaclass=EnumMeta):
source = vars(source)
else:
source = module_globals
- members = {name: value for name, value in source.items()
- if filter(name)}
+ # We use an OrderedDict of sorted source keys so that the
+ # _value2member_map is populated in the same order every time
+ # for a consistent reverse mapping of number to name when there
+ # are multiple names for the same number rather than varying
+ # between runs due to hash randomization of the module dictionary.
+ members = [
+ (name, source[name])
+ for name in source.keys()
+ if filter(name)]
+ try:
+ # sort by value
+ members.sort(key=lambda t: (t[1], t[0]))
+ except TypeError:
+ # unless some values aren't comparable, in which case sort by name
+ members.sort(key=lambda t: t[0])
cls = cls(name, members, module=module)
cls.__reduce_ex__ = _reduce_ex_by_name
module_globals.update(cls.__members__)
@@ -560,6 +643,180 @@ class IntEnum(int, Enum):
def _reduce_ex_by_name(self, proto):
return self.name
+class Flag(Enum):
+ """Support for flags"""
+
+ def _generate_next_value_(name, start, count, last_values):
+ """
+ Generate the next value when not given.
+
+ name: the name of the member
+ start: the initital start value or None
+ count: the number of existing members
+ last_value: the last value assigned or None
+ """
+ if not count:
+ return start if start is not None else 1
+ for last_value in reversed(last_values):
+ try:
+ high_bit = _high_bit(last_value)
+ break
+ except Exception:
+ raise TypeError('Invalid Flag value: %r' % last_value) from None
+ return 2 ** (high_bit+1)
+
+ @classmethod
+ def _missing_(cls, value):
+ original_value = value
+ if value < 0:
+ value = ~value
+ possible_member = cls._create_pseudo_member_(value)
+ if original_value < 0:
+ possible_member = ~possible_member
+ return possible_member
+
+ @classmethod
+ def _create_pseudo_member_(cls, value):
+ """
+ Create a composite member iff value contains only members.
+ """
+ pseudo_member = cls._value2member_map_.get(value, None)
+ if pseudo_member is None:
+ # verify all bits are accounted for
+ _, extra_flags = _decompose(cls, value)
+ if extra_flags:
+ raise ValueError("%r is not a valid %s" % (value, cls.__name__))
+ # construct a singleton enum pseudo-member
+ pseudo_member = object.__new__(cls)
+ pseudo_member._name_ = None
+ pseudo_member._value_ = value
+ cls._value2member_map_[value] = pseudo_member
+ return pseudo_member
+
+ def __contains__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return other._value_ & self._value_ == other._value_
+
+ def __repr__(self):
+ cls = self.__class__
+ if self._name_ is not None:
+ return '<%s.%s: %r>' % (cls.__name__, self._name_, self._value_)
+ members, uncovered = _decompose(cls, self._value_)
+ return '<%s.%s: %r>' % (
+ cls.__name__,
+ '|'.join([str(m._name_ or m._value_) for m in members]),
+ self._value_,
+ )
+
+ def __str__(self):
+ cls = self.__class__
+ if self._name_ is not None:
+ return '%s.%s' % (cls.__name__, self._name_)
+ members, uncovered = _decompose(cls, self._value_)
+ if len(members) == 1 and members[0]._name_ is None:
+ return '%s.%r' % (cls.__name__, members[0]._value_)
+ else:
+ return '%s.%s' % (
+ cls.__name__,
+ '|'.join([str(m._name_ or m._value_) for m in members]),
+ )
+
+ def __bool__(self):
+ return bool(self._value_)
+
+ def __or__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return self.__class__(self._value_ | other._value_)
+
+ def __and__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return self.__class__(self._value_ & other._value_)
+
+ def __xor__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return self.__class__(self._value_ ^ other._value_)
+
+ def __invert__(self):
+ members, uncovered = _decompose(self.__class__, self._value_)
+ inverted_members = [
+ m for m in self.__class__
+ if m not in members and not m._value_ & self._value_
+ ]
+ inverted = reduce(_or_, inverted_members, self.__class__(0))
+ return self.__class__(inverted)
+
+
+class IntFlag(int, Flag):
+ """Support for integer-based Flags"""
+
+ @classmethod
+ def _missing_(cls, value):
+ if not isinstance(value, int):
+ raise ValueError("%r is not a valid %s" % (value, cls.__name__))
+ new_member = cls._create_pseudo_member_(value)
+ return new_member
+
+ @classmethod
+ def _create_pseudo_member_(cls, value):
+ pseudo_member = cls._value2member_map_.get(value, None)
+ if pseudo_member is None:
+ need_to_create = [value]
+ # get unaccounted for bits
+ _, extra_flags = _decompose(cls, value)
+ # timer = 10
+ while extra_flags:
+ # timer -= 1
+ bit = _high_bit(extra_flags)
+ flag_value = 2 ** bit
+ if (flag_value not in cls._value2member_map_ and
+ flag_value not in need_to_create
+ ):
+ need_to_create.append(flag_value)
+ if extra_flags == -flag_value:
+ extra_flags = 0
+ else:
+ extra_flags ^= flag_value
+ for value in reversed(need_to_create):
+ # construct singleton pseudo-members
+ pseudo_member = int.__new__(cls, value)
+ pseudo_member._name_ = None
+ pseudo_member._value_ = value
+ cls._value2member_map_[value] = pseudo_member
+ return pseudo_member
+
+ def __or__(self, other):
+ if not isinstance(other, (self.__class__, int)):
+ return NotImplemented
+ result = self.__class__(self._value_ | self.__class__(other)._value_)
+ return result
+
+ def __and__(self, other):
+ if not isinstance(other, (self.__class__, int)):
+ return NotImplemented
+ return self.__class__(self._value_ & self.__class__(other)._value_)
+
+ def __xor__(self, other):
+ if not isinstance(other, (self.__class__, int)):
+ return NotImplemented
+ return self.__class__(self._value_ ^ self.__class__(other)._value_)
+
+ __ror__ = __or__
+ __rand__ = __and__
+ __rxor__ = __xor__
+
+ def __invert__(self):
+ result = self.__class__(~self._value_)
+ return result
+
+
+def _high_bit(value):
+ """returns index of highest bit, or -1 if value is zero or negative"""
+ return value.bit_length() - 1
+
def unique(enumeration):
"""Class decorator for enumerations ensuring unique member values."""
duplicates = []
@@ -572,3 +829,40 @@ def unique(enumeration):
raise ValueError('duplicate values found in %r: %s' %
(enumeration, alias_details))
return enumeration
+
+def _decompose(flag, value):
+ """Extract all members from the value."""
+ # _decompose is only called if the value is not named
+ not_covered = value
+ negative = value < 0
+ if negative:
+ # only check for named flags
+ flags_to_check = [
+ (m, v)
+ for v, m in flag._value2member_map_.items()
+ if m.name is not None
+ ]
+ else:
+ # check for named flags and powers-of-two flags
+ flags_to_check = [
+ (m, v)
+ for v, m in flag._value2member_map_.items()
+ if m.name is not None or _power_of_two(v)
+ ]
+ members = []
+ for member, member_value in flags_to_check:
+ if member_value and member_value & value == member_value:
+ members.append(member)
+ not_covered &= ~member_value
+ if not members and value in flag._value2member_map_:
+ members.append(flag._value2member_map_[value])
+ members.sort(key=lambda m: m._value_, reverse=True)
+ if len(members) > 1 and members[0].value == value:
+ # we have the breakdown, don't need the value member itself
+ members.pop(0)
+ return members, not_covered
+
+def _power_of_two(value):
+ if value < 1:
+ return False
+ return value == 2 ** _high_bit(value)
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index d2b5206..721fe9c 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -75,13 +75,11 @@ XXX Possible additions:
import sys, os
__all__ = ["input", "close", "nextfile", "filename", "lineno", "filelineno",
- "isfirstline", "isstdin", "FileInput"]
+ "fileno", "isfirstline", "isstdin", "FileInput", "hook_compressed",
+ "hook_encoded"]
_state = None
-# No longer used
-DEFAULT_BUFSIZE = 8*1024
-
def input(files=None, inplace=False, backup="", bufsize=0,
mode="r", openhook=None):
"""Return an instance of the FileInput class, which can be iterated.
@@ -201,6 +199,10 @@ class FileInput:
self._files = files
self._inplace = inplace
self._backup = backup
+ if bufsize:
+ import warnings
+ warnings.warn('bufsize is deprecated and ignored',
+ DeprecationWarning, stacklevel=2)
self._savestdout = None
self._output = None
self._filename = None
@@ -398,9 +400,9 @@ def hook_compressed(filename, mode):
return open(filename, mode)
-def hook_encoded(encoding):
+def hook_encoded(encoding, errors=None):
def openhook(filename, mode):
- return open(filename, mode, encoding=encoding)
+ return open(filename, mode, encoding=encoding, errors=errors)
return openhook
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index 6330b0c..fd3b514 100644
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -106,4 +106,4 @@ def translate(pat):
res = '%s[%s]' % (res, stuff)
else:
res = res + re.escape(c)
- return res + '\Z(?ms)'
+ return r'(?s:%s)\Z' % res
diff --git a/Lib/fractions.py b/Lib/fractions.py
index 9aabab3..8330202 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -81,7 +81,7 @@ class Fraction(numbers.Rational):
__slots__ = ('_numerator', '_denominator')
# We're immutable, so use __new__ not __init__
- def __new__(cls, numerator=0, denominator=None, _normalize=True):
+ def __new__(cls, numerator=0, denominator=None, *, _normalize=True):
"""Constructs a Rational.
Takes a string like '3/2' or '1.5', another Rational instance, a
@@ -125,17 +125,9 @@ class Fraction(numbers.Rational):
self._denominator = numerator.denominator
return self
- elif isinstance(numerator, float):
- # Exact conversion from float
- value = Fraction.from_float(numerator)
- self._numerator = value._numerator
- self._denominator = value._denominator
- return self
-
- elif isinstance(numerator, Decimal):
- value = Fraction.from_decimal(numerator)
- self._numerator = value._numerator
- self._denominator = value._denominator
+ elif isinstance(numerator, (float, Decimal)):
+ # Exact conversion
+ self._numerator, self._denominator = numerator.as_integer_ratio()
return self
elif isinstance(numerator, str):
@@ -210,10 +202,6 @@ class Fraction(numbers.Rational):
elif not isinstance(f, float):
raise TypeError("%s.from_float() only takes floats, not %r (%s)" %
(cls.__name__, f, type(f).__name__))
- if math.isnan(f):
- raise ValueError("Cannot convert %r to %s." % (f, cls.__name__))
- if math.isinf(f):
- raise OverflowError("Cannot convert %r to %s." % (f, cls.__name__))
return cls(*f.as_integer_ratio())
@classmethod
@@ -226,19 +214,7 @@ class Fraction(numbers.Rational):
raise TypeError(
"%s.from_decimal() only takes Decimals, not %r (%s)" %
(cls.__name__, dec, type(dec).__name__))
- if dec.is_infinite():
- raise OverflowError(
- "Cannot convert %s to %s." % (dec, cls.__name__))
- if dec.is_nan():
- raise ValueError("Cannot convert %s to %s." % (dec, cls.__name__))
- sign, digits, exp = dec.as_tuple()
- digits = int(''.join(map(str, digits)))
- if sign:
- digits = -digits
- if exp >= 0:
- return cls(digits * 10 ** exp)
- else:
- return cls(digits, 10 ** -exp)
+ return cls(*dec.as_integer_ratio())
def limit_denominator(self, max_denominator=1000000):
"""Closest Fraction to self with denominator at most max_denominator.
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index c416d85..8f36f53 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -36,13 +36,12 @@ python ftplib.py -d localhost -l -p -l
# Modified by Giampaolo Rodola' to add TLS support.
#
-import os
import sys
import socket
-import warnings
from socket import _GLOBAL_DEFAULT_TIMEOUT
-__all__ = ["FTP"]
+__all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto",
+ "all_errors"]
# Magic number from <socket.h>
MSG_OOB = 0x1 # Process data out of band
@@ -729,6 +728,10 @@ else:
if context is not None and certfile is not None:
raise ValueError("context and certfile arguments are mutually "
"exclusive")
+ if keyfile is not None or certfile is not None:
+ import warnings
+ warnings.warn("keyfile and certfile are deprecated, use a"
+ "custom context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
if context is None:
@@ -822,7 +825,7 @@ def parse150(resp):
if _150_re is None:
import re
_150_re = re.compile(
- "150 .* \((\d+) bytes\)", re.IGNORECASE | re.ASCII)
+ r"150 .* \((\d+) bytes\)", re.IGNORECASE | re.ASCII)
m = _150_re.match(resp)
if not m:
return None
diff --git a/Lib/functools.py b/Lib/functools.py
index 214523c..9845df2 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -21,6 +21,7 @@ from abc import get_cache_token
from collections import namedtuple
from types import MappingProxyType
from weakref import WeakKeyDictionary
+from reprlib import recursive_repr
try:
from _thread import RLock
except ImportError:
@@ -237,26 +238,83 @@ except ImportError:
################################################################################
# Purely functional, no descriptor behaviour
-def partial(func, *args, **keywords):
+class partial:
"""New function with partial application of the given arguments
and keywords.
"""
- if hasattr(func, 'func'):
- args = func.args + args
- tmpkw = func.keywords.copy()
- tmpkw.update(keywords)
- keywords = tmpkw
- del tmpkw
- func = func.func
-
- def newfunc(*fargs, **fkeywords):
- newkeywords = keywords.copy()
- newkeywords.update(fkeywords)
- return func(*(args + fargs), **newkeywords)
- newfunc.func = func
- newfunc.args = args
- newfunc.keywords = keywords
- return newfunc
+
+ __slots__ = "func", "args", "keywords", "__dict__", "__weakref__"
+
+ def __new__(*args, **keywords):
+ if not args:
+ raise TypeError("descriptor '__new__' of partial needs an argument")
+ if len(args) < 2:
+ raise TypeError("type 'partial' takes at least one argument")
+ cls, func, *args = args
+ if not callable(func):
+ raise TypeError("the first argument must be callable")
+ args = tuple(args)
+
+ if hasattr(func, "func"):
+ args = func.args + args
+ tmpkw = func.keywords.copy()
+ tmpkw.update(keywords)
+ keywords = tmpkw
+ del tmpkw
+ func = func.func
+
+ self = super(partial, cls).__new__(cls)
+
+ self.func = func
+ self.args = args
+ self.keywords = keywords
+ return self
+
+ def __call__(*args, **keywords):
+ if not args:
+ raise TypeError("descriptor '__call__' of partial needs an argument")
+ self, *args = args
+ newkeywords = self.keywords.copy()
+ newkeywords.update(keywords)
+ return self.func(*self.args, *args, **newkeywords)
+
+ @recursive_repr()
+ def __repr__(self):
+ qualname = type(self).__qualname__
+ args = [repr(self.func)]
+ args.extend(repr(x) for x in self.args)
+ args.extend(f"{k}={v!r}" for (k, v) in self.keywords.items())
+ if type(self).__module__ == "functools":
+ return f"functools.{qualname}({', '.join(args)})"
+ return f"{qualname}({', '.join(args)})"
+
+ def __reduce__(self):
+ return type(self), (self.func,), (self.func, self.args,
+ self.keywords or None, self.__dict__ or None)
+
+ def __setstate__(self, state):
+ if not isinstance(state, tuple):
+ raise TypeError("argument to __setstate__ must be a tuple")
+ if len(state) != 4:
+ raise TypeError(f"expected 4 items in state, got {len(state)}")
+ func, args, kwds, namespace = state
+ if (not callable(func) or not isinstance(args, tuple) or
+ (kwds is not None and not isinstance(kwds, dict)) or
+ (namespace is not None and not isinstance(namespace, dict))):
+ raise TypeError("invalid partial state")
+
+ args = tuple(args) # just in case it's a subclass
+ if kwds is None:
+ kwds = {}
+ elif type(kwds) is not dict: # XXX does it need to be *exactly* dict?
+ kwds = dict(kwds)
+ if namespace is None:
+ namespace = {}
+
+ self.__dict__ = namespace
+ self.func = func
+ self.args = args
+ self.keywords = kwds
try:
from _functools import partial
diff --git a/Lib/genericpath.py b/Lib/genericpath.py
index 6714061..303b3b3 100644
--- a/Lib/genericpath.py
+++ b/Lib/genericpath.py
@@ -69,6 +69,12 @@ def getctime(filename):
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
+ # Some people pass in a list of pathname parts to operate in an OS-agnostic
+ # fashion; don't try to translate in that case as that's an abuse of the
+ # API and they are already doing what they need to be OS-agnostic and so
+ # they most likely won't be using an os.PathLike object in the sublists.
+ if not isinstance(m[0], (list, tuple)):
+ m = tuple(map(os.fspath, m))
s1 = min(m)
s2 = max(m)
for i, c in enumerate(s1):
diff --git a/Lib/glob.py b/Lib/glob.py
index 16330d8..002cd92 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -30,15 +30,16 @@ def iglob(pathname, *, recursive=False):
If recursive is true, the pattern '**' will match any files and
zero or more directories and subdirectories.
"""
- it = _iglob(pathname, recursive)
+ it = _iglob(pathname, recursive, False)
if recursive and _isrecursive(pathname):
s = next(it) # skip empty string
assert not s
return it
-def _iglob(pathname, recursive):
+def _iglob(pathname, recursive, dironly):
dirname, basename = os.path.split(pathname)
if not has_magic(pathname):
+ assert not dironly
if basename:
if os.path.lexists(pathname):
yield pathname
@@ -49,47 +50,39 @@ def _iglob(pathname, recursive):
return
if not dirname:
if recursive and _isrecursive(basename):
- yield from glob2(dirname, basename)
+ yield from _glob2(dirname, basename, dironly)
else:
- yield from glob1(dirname, basename)
+ yield from _glob1(dirname, basename, dironly)
return
# `os.path.split()` returns the argument itself as a dirname if it is a
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
# contains magic characters (i.e. r'\\?\C:').
if dirname != pathname and has_magic(dirname):
- dirs = _iglob(dirname, recursive)
+ dirs = _iglob(dirname, recursive, True)
else:
dirs = [dirname]
if has_magic(basename):
if recursive and _isrecursive(basename):
- glob_in_dir = glob2
+ glob_in_dir = _glob2
else:
- glob_in_dir = glob1
+ glob_in_dir = _glob1
else:
- glob_in_dir = glob0
+ glob_in_dir = _glob0
for dirname in dirs:
- for name in glob_in_dir(dirname, basename):
+ for name in glob_in_dir(dirname, basename, dironly):
yield os.path.join(dirname, name)
# These 2 helper functions non-recursively glob inside a literal directory.
-# They return a list of basenames. `glob1` accepts a pattern while `glob0`
+# They return a list of basenames. _glob1 accepts a pattern while _glob0
# takes a literal basename (so it only has to check for its existence).
-def glob1(dirname, pattern):
- if not dirname:
- if isinstance(pattern, bytes):
- dirname = bytes(os.curdir, 'ASCII')
- else:
- dirname = os.curdir
- try:
- names = os.listdir(dirname)
- except OSError:
- return []
+def _glob1(dirname, pattern, dironly):
+ names = list(_iterdir(dirname, dironly))
if not _ishidden(pattern):
- names = [x for x in names if not _ishidden(x)]
+ names = (x for x in names if not _ishidden(x))
return fnmatch.filter(names, pattern)
-def glob0(dirname, basename):
+def _glob0(dirname, basename, dironly):
if not basename:
# `os.path.split()` returns an empty basename for paths ending with a
# directory separator. 'q*x/' should match only directories.
@@ -100,30 +93,49 @@ def glob0(dirname, basename):
return [basename]
return []
+# Following functions are not public but can be used by third-party code.
+
+def glob0(dirname, pattern):
+ return _glob0(dirname, pattern, False)
+
+def glob1(dirname, pattern):
+ return _glob1(dirname, pattern, False)
+
# This helper function recursively yields relative pathnames inside a literal
# directory.
-def glob2(dirname, pattern):
+def _glob2(dirname, pattern, dironly):
assert _isrecursive(pattern)
yield pattern[:0]
- yield from _rlistdir(dirname)
+ yield from _rlistdir(dirname, dironly)
-# Recursively yields relative pathnames inside a literal directory.
-def _rlistdir(dirname):
+# If dironly is false, yields all file names inside a directory.
+# If dironly is true, yields only directory names.
+def _iterdir(dirname, dironly):
if not dirname:
if isinstance(dirname, bytes):
dirname = bytes(os.curdir, 'ASCII')
else:
dirname = os.curdir
try:
- names = os.listdir(dirname)
- except os.error:
+ with os.scandir(dirname) as it:
+ for entry in it:
+ try:
+ if not dironly or entry.is_dir():
+ yield entry.name
+ except OSError:
+ pass
+ except OSError:
return
+
+# Recursively yields relative pathnames inside a literal directory.
+def _rlistdir(dirname, dironly):
+ names = list(_iterdir(dirname, dironly))
for x in names:
if not _ishidden(x):
yield x
path = os.path.join(dirname, x) if dirname else x
- for y in _rlistdir(path):
+ for y in _rlistdir(path, dironly):
yield os.path.join(x, y)
diff --git a/Lib/gzip.py b/Lib/gzip.py
index da4479e..76ab497 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -49,7 +49,7 @@ def open(filename, mode="rb", compresslevel=9,
raise ValueError("Argument 'newline' not supported in binary mode")
gz_mode = mode.replace("t", "")
- if isinstance(filename, (str, bytes)):
+ if isinstance(filename, (str, bytes, os.PathLike)):
binary_file = GzipFile(filename, gz_mode, compresslevel)
elif hasattr(filename, "read") or hasattr(filename, "write"):
binary_file = GzipFile(None, gz_mode, compresslevel, filename)
@@ -165,6 +165,8 @@ class GzipFile(_compression.BaseStream):
filename = getattr(fileobj, 'name', '')
if not isinstance(filename, (str, bytes)):
filename = ''
+ else:
+ filename = os.fspath(filename)
if mode is None:
mode = getattr(fileobj, 'mode', 'rb')
@@ -357,10 +359,10 @@ class GzipFile(_compression.BaseStream):
if offset < self.offset:
raise OSError('Negative seek in write mode')
count = offset - self.offset
- chunk = bytes(1024)
+ chunk = b'\0' * 1024
for i in range(count // 1024):
self.write(chunk)
- self.write(bytes(count % 1024))
+ self.write(b'\0' * (count % 1024))
elif self.mode == READ:
self._check_not_closed()
return self._buffer.seek(offset, whence)
diff --git a/Lib/hashlib.py b/Lib/hashlib.py
index 316cece..053a7ad 100644
--- a/Lib/hashlib.py
+++ b/Lib/hashlib.py
@@ -4,14 +4,15 @@
__doc__ = """hashlib module - A common interface to many hash functions.
-new(name, data=b'') - returns a new hash object implementing the
- given hash function; initializing the hash
- using the given binary data.
+new(name, data=b'', **kwargs) - returns a new hash object implementing the
+ given hash function; initializing the hash
+ using the given binary data.
Named constructor functions are also available, these are faster
than using new(name):
-md5(), sha1(), sha224(), sha256(), sha384(), and sha512()
+md5(), sha1(), sha224(), sha256(), sha384(), sha512(), blake2b(), blake2s(),
+sha3_224, sha3_256, sha3_384, sha3_512, shake_128, and shake_256.
More algorithms may be available on your platform but the above are guaranteed
to exist. See the algorithms_guaranteed and algorithms_available attributes
@@ -54,7 +55,11 @@ More condensed:
# This tuple and __get_builtin_constructor() must be modified if a new
# always available algorithm is added.
-__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
+__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
+ 'blake2b', 'blake2s',
+ 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
+ 'shake_128', 'shake_256')
+
algorithms_guaranteed = set(__always_supported)
algorithms_available = set(__always_supported)
@@ -85,6 +90,19 @@ def __get_builtin_constructor(name):
import _sha512
cache['SHA384'] = cache['sha384'] = _sha512.sha384
cache['SHA512'] = cache['sha512'] = _sha512.sha512
+ elif name in ('blake2b', 'blake2s'):
+ import _blake2
+ cache['blake2b'] = _blake2.blake2b
+ cache['blake2s'] = _blake2.blake2s
+ elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
+ 'shake_128', 'shake_256'}:
+ import _sha3
+ cache['sha3_224'] = _sha3.sha3_224
+ cache['sha3_256'] = _sha3.sha3_256
+ cache['sha3_384'] = _sha3.sha3_384
+ cache['sha3_512'] = _sha3.sha3_512
+ cache['shake_128'] = _sha3.shake_128
+ cache['shake_256'] = _sha3.shake_256
except ImportError:
pass # no extension module, this hash is unsupported.
@@ -96,6 +114,9 @@ def __get_builtin_constructor(name):
def __get_openssl_constructor(name):
+ if name in {'blake2b', 'blake2s'}:
+ # Prefer our blake2 implementation.
+ return __get_builtin_constructor(name)
try:
f = getattr(_hashlib, 'openssl_' + name)
# Allow the C module to raise ValueError. The function will be
@@ -107,17 +128,23 @@ def __get_openssl_constructor(name):
return __get_builtin_constructor(name)
-def __py_new(name, data=b''):
- """new(name, data=b'') - Return a new hashing object using the named algorithm;
- optionally initialized with data (which must be bytes).
+def __py_new(name, data=b'', **kwargs):
+ """new(name, data=b'', **kwargs) - Return a new hashing object using the
+ named algorithm; optionally initialized with data (which must be bytes).
"""
- return __get_builtin_constructor(name)(data)
+ return __get_builtin_constructor(name)(data, **kwargs)
-def __hash_new(name, data=b''):
+def __hash_new(name, data=b'', **kwargs):
"""new(name, data=b'') - Return a new hashing object using the named algorithm;
optionally initialized with data (which must be bytes).
"""
+ if name in {'blake2b', 'blake2s'}:
+ # Prefer our blake2 implementation.
+ # OpenSSL 1.1.0 comes with a limited implementation of blake2b/s.
+ # It does neither support keyed blake2 nor advanced features like
+ # salt, personal, tree hashing or SSE.
+ return __get_builtin_constructor(name)(data, **kwargs)
try:
return _hashlib.new(name, data)
except ValueError:
@@ -202,6 +229,12 @@ except ImportError:
return dkey[:dklen]
+try:
+ # OpenSSL's scrypt requires OpenSSL 1.1+
+ from _hashlib import scrypt
+except ImportError:
+ pass
+
for __func_name in __always_supported:
# try them all, some may not work due to the OpenSSL
@@ -212,6 +245,7 @@ for __func_name in __always_supported:
import logging
logging.exception('code for hash %s was not found.', __func_name)
+
# Cleanup locals()
del __always_supported, __func_name, __get_hash
del __py_new, __hash_new, __get_openssl_constructor
diff --git a/Lib/hmac.py b/Lib/hmac.py
index 77785a2..121029a 100644
--- a/Lib/hmac.py
+++ b/Lib/hmac.py
@@ -77,7 +77,7 @@ class HMAC:
if len(key) > blocksize:
key = self.digest_cons(key).digest()
- key = key + bytes(blocksize - len(key))
+ key = key.ljust(blocksize, b'\0')
self.outer.update(key.translate(trans_5C))
self.inner.update(key.translate(trans_36))
if msg is not None:
diff --git a/Lib/html/parser.py b/Lib/html/parser.py
index b781c63..ef869bc 100644
--- a/Lib/html/parser.py
+++ b/Lib/html/parser.py
@@ -34,7 +34,7 @@ commentclose = re.compile(r'--\s*>')
# explode, so don't do it.
# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
-tagfind_tolerant = re.compile('([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
+tagfind_tolerant = re.compile(r'([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
attrfind_tolerant = re.compile(
r'((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*'
r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*')
@@ -56,7 +56,7 @@ locatestarttagend_tolerant = re.compile(r"""
endendtag = re.compile('>')
# the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
# </ and the tag name, so maybe this should be fixed
-endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
+endtagfind = re.compile(r'</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 352c101..a8e59b9 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -1,4 +1,4 @@
-"""HTTP/1.1 client library
+r"""HTTP/1.1 client library
<intro stuff goes here>
<other stuff, too>
@@ -420,6 +420,7 @@ class HTTPResponse(io.BufferedIOBase):
self.fp.flush()
def readable(self):
+ """Always returns True"""
return True
# End of "raw stream" methods
@@ -467,6 +468,10 @@ class HTTPResponse(io.BufferedIOBase):
return s
def readinto(self, b):
+ """Read up to len(b) bytes into bytearray b and return the number
+ of bytes read.
+ """
+
if self.fp is None:
return 0
@@ -706,6 +711,17 @@ class HTTPResponse(io.BufferedIOBase):
return self.fp.fileno()
def getheader(self, name, default=None):
+ '''Returns the value of the header matching *name*.
+
+ If there are multiple matching headers, the values are
+ combined into a single string separated by commas and spaces.
+
+ If no matching header is found, returns *default* or None if
+ the *default* is not specified.
+
+ If the headers are unknown, raises http.client.ResponseNotReady.
+
+ '''
if self.headers is None:
raise ResponseNotReady()
headers = self.headers.get_all(name) or default
@@ -728,12 +744,45 @@ class HTTPResponse(io.BufferedIOBase):
# For compatibility with old-style urllib responses.
def info(self):
+ '''Returns an instance of the class mimetools.Message containing
+ meta-information associated with the URL.
+
+ When the method is HTTP, these headers are those returned by
+ the server at the head of the retrieved HTML page (including
+ Content-Length and Content-Type).
+
+ When the method is FTP, a Content-Length header will be
+ present if (as is now usual) the server passed back a file
+ length in response to the FTP retrieval request. A
+ Content-Type header will be present if the MIME type can be
+ guessed.
+
+ When the method is local-file, returned headers will include
+ a Date representing the file's last-modified time, a
+ Content-Length giving file size, and a Content-Type
+ containing a guess at the file's type. See also the
+ description of the mimetools module.
+
+ '''
return self.headers
def geturl(self):
+ '''Return the real URL of the page.
+
+ In some cases, the HTTP server redirects a client to another
+ URL. The urlopen() function handles this transparently, but in
+ some cases the caller needs to know which URL the client was
+ redirected to. The geturl() method can be used to get at this
+ redirected URL.
+
+ '''
return self.url
def getcode(self):
+ '''Return the HTTP status code that was sent with the response,
+ or None if the URL is not an HTTP URL.
+
+ '''
return self.status
class HTTPConnection:
@@ -746,6 +795,44 @@ class HTTPConnection:
auto_open = 1
debuglevel = 0
+ @staticmethod
+ def _is_textIO(stream):
+ """Test whether a file-like object is a text or a binary stream.
+ """
+ return isinstance(stream, io.TextIOBase)
+
+ @staticmethod
+ def _get_content_length(body, method):
+ """Get the content-length based on the body.
+
+ If the body is None, we set Content-Length: 0 for methods that expect
+ a body (RFC 7230, Section 3.3.2). We also set the Content-Length for
+ any method if the body is a str or bytes-like object and not a file.
+ """
+ if body is None:
+ # do an explicit check for not None here to distinguish
+ # between unset and set but empty
+ if method.upper() in _METHODS_EXPECTING_BODY:
+ return 0
+ else:
+ return None
+
+ if hasattr(body, 'read'):
+ # file-like object.
+ return None
+
+ try:
+ # does it implement the buffer protocol (bytes, bytearray, array)?
+ mv = memoryview(body)
+ return mv.nbytes
+ except TypeError:
+ pass
+
+ if isinstance(body, str):
+ return len(body)
+
+ return None
+
def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
self.timeout = timeout
@@ -884,18 +971,9 @@ class HTTPConnection:
if hasattr(data, "read") :
if self.debuglevel > 0:
print("sendIng a read()able")
- encode = False
- try:
- mode = data.mode
- except AttributeError:
- # io.BytesIO and other file-like objects don't have a `mode`
- # attribute.
- pass
- else:
- if "b" not in mode:
- encode = True
- if self.debuglevel > 0:
- print("encoding file using iso-8859-1")
+ encode = self._is_textIO(data)
+ if encode and self.debuglevel > 0:
+ print("encoding file using iso-8859-1")
while 1:
datablock = data.read(blocksize)
if not datablock:
@@ -921,7 +999,22 @@ class HTTPConnection:
"""
self._buffer.append(s)
- def _send_output(self, message_body=None):
+ def _read_readable(self, readable):
+ blocksize = 8192
+ if self.debuglevel > 0:
+ print("sendIng a read()able")
+ encode = self._is_textIO(readable)
+ if encode and self.debuglevel > 0:
+ print("encoding file using iso-8859-1")
+ while True:
+ datablock = readable.read(blocksize)
+ if not datablock:
+ break
+ if encode:
+ datablock = datablock.encode("iso-8859-1")
+ yield datablock
+
+ def _send_output(self, message_body=None, encode_chunked=False):
"""Send the currently buffered request and clear the buffer.
Appends an extra \\r\\n to the buffer.
@@ -930,10 +1023,50 @@ class HTTPConnection:
self._buffer.extend((b"", b""))
msg = b"\r\n".join(self._buffer)
del self._buffer[:]
-
self.send(msg)
+
if message_body is not None:
- self.send(message_body)
+
+ # create a consistent interface to message_body
+ if hasattr(message_body, 'read'):
+ # Let file-like take precedence over byte-like. This
+ # is needed to allow the current position of mmap'ed
+ # files to be taken into account.
+ chunks = self._read_readable(message_body)
+ else:
+ try:
+ # this is solely to check to see if message_body
+ # implements the buffer API. it /would/ be easier
+ # to capture if PyObject_CheckBuffer was exposed
+ # to Python.
+ memoryview(message_body)
+ except TypeError:
+ try:
+ chunks = iter(message_body)
+ except TypeError:
+ raise TypeError("message_body should be a bytes-like "
+ "object or an iterable, got %r"
+ % type(message_body))
+ else:
+ # the object implements the buffer interface and
+ # can be passed directly into socket methods
+ chunks = (message_body,)
+
+ for chunk in chunks:
+ if not chunk:
+ if self.debuglevel > 0:
+ print('Zero length chunk ignored')
+ continue
+
+ if encode_chunked and self._http_vsn == 11:
+ # chunked encoding
+ chunk = f'{len(chunk):X}\r\n'.encode('ascii') + chunk \
+ + b'\r\n'
+ self.send(chunk)
+
+ if encode_chunked and self._http_vsn == 11:
+ # end chunked transfer
+ self.send(b'0\r\n\r\n')
def putrequest(self, method, url, skip_host=False,
skip_accept_encoding=False):
@@ -1087,52 +1220,27 @@ class HTTPConnection:
header = header + b': ' + value
self._output(header)
- def endheaders(self, message_body=None):
+ def endheaders(self, message_body=None, *, encode_chunked=False):
"""Indicate that the last header line has been sent to the server.
This method sends the request to the server. The optional message_body
argument can be used to pass a message body associated with the
- request. The message body will be sent in the same packet as the
- message headers if it is a string, otherwise it is sent as a separate
- packet.
+ request.
"""
if self.__state == _CS_REQ_STARTED:
self.__state = _CS_REQ_SENT
else:
raise CannotSendHeader()
- self._send_output(message_body)
+ self._send_output(message_body, encode_chunked=encode_chunked)
- def request(self, method, url, body=None, headers={}):
+ def request(self, method, url, body=None, headers={}, *,
+ encode_chunked=False):
"""Send a complete request to the server."""
- self._send_request(method, url, body, headers)
-
- def _set_content_length(self, body, method):
- # Set the content-length based on the body. If the body is "empty", we
- # set Content-Length: 0 for methods that expect a body (RFC 7230,
- # Section 3.3.2). If the body is set for other methods, we set the
- # header provided we can figure out what the length is.
- thelen = None
- method_expects_body = method.upper() in _METHODS_EXPECTING_BODY
- if body is None and method_expects_body:
- thelen = '0'
- elif body is not None:
- try:
- thelen = str(len(body))
- except TypeError:
- # If this is a file-like object, try to
- # fstat its file descriptor
- try:
- thelen = str(os.fstat(body.fileno()).st_size)
- except (AttributeError, OSError):
- # Don't send a length if this failed
- if self.debuglevel > 0: print("Cannot stat!!")
-
- if thelen is not None:
- self.putheader('Content-Length', thelen)
+ self._send_request(method, url, body, headers, encode_chunked)
- def _send_request(self, method, url, body, headers):
+ def _send_request(self, method, url, body, headers, encode_chunked):
# Honor explicitly requested Host: and Accept-Encoding: headers.
- header_names = dict.fromkeys([k.lower() for k in headers])
+ header_names = frozenset(k.lower() for k in headers)
skips = {}
if 'host' in header_names:
skips['skip_host'] = 1
@@ -1141,15 +1249,40 @@ class HTTPConnection:
self.putrequest(method, url, **skips)
+ # chunked encoding will happen if HTTP/1.1 is used and either
+ # the caller passes encode_chunked=True or the following
+ # conditions hold:
+ # 1. content-length has not been explicitly set
+ # 2. the body is a file or iterable, but not a str or bytes-like
+ # 3. Transfer-Encoding has NOT been explicitly set by the caller
+
if 'content-length' not in header_names:
- self._set_content_length(body, method)
+ # only chunk body if not explicitly set for backwards
+ # compatibility, assuming the client code is already handling the
+ # chunking
+ if 'transfer-encoding' not in header_names:
+ # if content-length cannot be automatically determined, fall
+ # back to chunked encoding
+ encode_chunked = False
+ content_length = self._get_content_length(body, method)
+ if content_length is None:
+ if body is not None:
+ if self.debuglevel > 0:
+ print('Unable to determine size of %r' % body)
+ encode_chunked = True
+ self.putheader('Transfer-Encoding', 'chunked')
+ else:
+ self.putheader('Content-Length', str(content_length))
+ else:
+ encode_chunked = False
+
for hdr, value in headers.items():
self.putheader(hdr, value)
if isinstance(body, str):
# RFC 2616 Section 3.7.1 says that text default has a
# default charset of iso-8859-1.
body = _encode(body, 'body')
- self.endheaders(body)
+ self.endheaders(body, encode_chunked=encode_chunked)
def getresponse(self):
"""Get the response from the server.
@@ -1232,6 +1365,12 @@ else:
check_hostname=None):
super(HTTPSConnection, self).__init__(host, port, timeout,
source_address)
+ if (key_file is not None or cert_file is not None or
+ check_hostname is not None):
+ import warnings
+ warnings.warn("key_file, cert_file and check_hostname are "
+ "deprecated, use a custom context instead.",
+ DeprecationWarning, 2)
self.key_file = key_file
self.cert_file = cert_file
if context is None:
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index 6d4572a..adf956d 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -200,7 +200,7 @@ def _str2time(day, mon, yr, hr, min, sec, tz):
STRICT_DATE_RE = re.compile(
r"^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) "
- "(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
+ r"(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
WEEKDAY_RE = re.compile(
r"^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*", re.I | re.ASCII)
LOOSE_HTTP_DATE_RE = re.compile(
@@ -277,7 +277,7 @@ def http2time(text):
return _str2time(day, mon, yr, hr, min, sec, tz)
ISO_DATE_RE = re.compile(
- """^
+ r"""^
(\d{4}) # year
[-\/]?
(\d\d?) # numerical month
@@ -411,7 +411,7 @@ def split_header_words(header_values):
pairs = []
else:
# skip junk
- non_junk, nr_junk_chars = re.subn("^[=\s;]*", "", text)
+ non_junk, nr_junk_chars = re.subn(r"^[=\s;]*", "", text)
assert nr_junk_chars > 0, (
"split_header_words bug: '%s', '%s', %s" %
(orig_text, text, pairs))
diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py
index a73fe38..be3b080 100644
--- a/Lib/http/cookies.py
+++ b/Lib/http/cookies.py
@@ -456,9 +456,8 @@ class Morsel(dict):
#
_LegalKeyChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
-_LegalValueChars = _LegalKeyChars + '\[\]'
+_LegalValueChars = _LegalKeyChars + r'\[\]'
_CookiePattern = re.compile(r"""
- (?x) # This is a verbose pattern
\s* # Optional whitespace at start of cookie
(?P<key> # Start of group 'key'
[""" + _LegalKeyChars + r"""]+? # Any word of at least one letter
@@ -475,7 +474,7 @@ _CookiePattern = re.compile(r"""
)? # End of optional value group
\s* # Any number of spaces.
(\s+|;|$) # Ending either at space, semicolon, or EOS.
- """, re.ASCII) # May be removed if safe.
+ """, re.ASCII | re.VERBOSE) # re.ASCII may be removed if safe.
# At long last, here is the cookie class. Using this class is almost just like
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 00620d1..e12e45b 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -87,6 +87,7 @@ __all__ = [
"SimpleHTTPRequestHandler", "CGIHTTPRequestHandler",
]
+import email.utils
import html
import http.client
import io
@@ -126,9 +127,6 @@ DEFAULT_ERROR_MESSAGE = """\
DEFAULT_ERROR_CONTENT_TYPE = "text/html;charset=utf-8"
-def _quote_html(html):
- return html.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
-
class HTTPServer(socketserver.TCPServer):
allow_reuse_address = 1 # Seems to make sense in testing environment
@@ -136,7 +134,7 @@ class HTTPServer(socketserver.TCPServer):
def server_bind(self):
"""Override server_bind to store the server name."""
socketserver.TCPServer.server_bind(self)
- host, port = self.socket.getsockname()[:2]
+ host, port = self.server_address[:2]
self.server_name = socket.getfqdn(host)
self.server_port = port
@@ -282,12 +280,9 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
words = requestline.split()
if len(words) == 3:
command, path, version = words
- if version[:5] != 'HTTP/':
- self.send_error(
- HTTPStatus.BAD_REQUEST,
- "Bad request version (%r)" % version)
- return False
try:
+ if version[:5] != 'HTTP/':
+ raise ValueError
base_version_number = version.split('/', 1)[1]
version_number = base_version_number.split(".")
# RFC 2145 section 3.1 says there can be only one "." and
@@ -309,7 +304,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
if version_number >= (2, 0):
self.send_error(
HTTPStatus.HTTP_VERSION_NOT_SUPPORTED,
- "Invalid HTTP Version (%s)" % base_version_number)
+ "Invalid HTTP version (%s)" % base_version_number)
return False
elif len(words) == 2:
command, path = words
@@ -332,10 +327,11 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
try:
self.headers = http.client.parse_headers(self.rfile,
_class=self.MessageClass)
- except http.client.LineTooLong:
+ except http.client.LineTooLong as err:
self.send_error(
- HTTPStatus.BAD_REQUEST,
- "Line too long")
+ HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE,
+ "Line too long",
+ str(err))
return False
except http.client.HTTPException as err:
self.send_error(
@@ -465,8 +461,8 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
# (see bug #1100201)
content = (self.error_message_format % {
'code': code,
- 'message': _quote_html(message),
- 'explain': _quote_html(explain)
+ 'message': html.escape(message, quote=False),
+ 'explain': html.escape(explain, quote=False)
})
body = content.encode('UTF-8', 'replace')
self.send_header("Content-Type", self.error_content_type)
@@ -491,12 +487,12 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
def send_response_only(self, code, message=None):
"""Send the response header only."""
- if message is None:
- if code in self.responses:
- message = self.responses[code][0]
- else:
- message = ''
if self.request_version != 'HTTP/0.9':
+ if message is None:
+ if code in self.responses:
+ message = self.responses[code][0]
+ else:
+ message = ''
if not hasattr(self, '_headers_buffer'):
self._headers_buffer = []
self._headers_buffer.append(("%s %d %s\r\n" %
@@ -583,12 +579,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
"""Return the current date and time formatted for a message header."""
if timestamp is None:
timestamp = time.time()
- year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
- s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
- self.weekdayname[wd],
- day, self.monthname[month], year,
- hh, mm, ss)
- return s
+ return email.utils.formatdate(timestamp, usegmt=True)
def log_date_time_string(self):
"""Return the current time formatted for logging."""
@@ -726,7 +717,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
errors='surrogatepass')
except UnicodeDecodeError:
displaypath = urllib.parse.unquote(path)
- displaypath = html.escape(displaypath)
+ displaypath = html.escape(displaypath, quote=False)
enc = sys.getfilesystemencoding()
title = 'Directory listing for %s' % displaypath
r.append('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" '
@@ -750,7 +741,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
r.append('<li><a href="%s">%s</a></li>'
% (urllib.parse.quote(linkname,
errors='surrogatepass'),
- html.escape(displayname)))
+ html.escape(displayname, quote=False)))
r.append('</ul>\n<hr>\n</body>\n</html>\n')
encoded = '\n'.join(r).encode(enc, 'surrogateescape')
f = io.BytesIO()
@@ -1191,16 +1182,15 @@ def test(HandlerClass=BaseHTTPRequestHandler,
server_address = (bind, port)
HandlerClass.protocol_version = protocol
- httpd = ServerClass(server_address, HandlerClass)
-
- sa = httpd.socket.getsockname()
- print("Serving HTTP on", sa[0], "port", sa[1], "...")
- try:
- httpd.serve_forever()
- except KeyboardInterrupt:
- print("\nKeyboard interrupt received, exiting.")
- httpd.server_close()
- sys.exit(0)
+ with ServerClass(server_address, HandlerClass) as httpd:
+ sa = httpd.socket.getsockname()
+ serve_message = "Serving HTTP on {host} port {port} (http://{host}:{port}/) ..."
+ print(serve_message.format(host=sa[0], port=sa[1]))
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ print("\nKeyboard interrupt received, exiting.")
+ sys.exit(0)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 72905c1..a3fc501 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -1,45 +1,101 @@
-What's New in IDLE 3.5.3?
-=========================
-*Release date: 2017-01-01?*
+What's New in IDLE 3.6.0?
+===========================
+*Release date: 2016-12-16?*
- Issue #15308: Add 'interrupt execution' (^C) to Shell menu.
Patch by Roger Serwy, updated by Bayard Randel.
- Issue #27922: Stop IDLE tests from 'flashing' gui widgets on the screen.
+- Issue #27891: Consistently group and sort imports within idlelib modules.
+
+- Issue #17642: add larger font sizes for classroom projection.
+
- Add version to title of IDLE help window.
- Issue #25564: In section on IDLE -- console differences, mention that
using exec means that __builtins__ is defined for each statement.
+- Issue #27821: Fix 3.6.0a3 regression that prevented custom key sets
+ from being selected when no custom theme was defined.
+
- Issue #27714: text_textview and test_autocomplete now pass when re-run
in the same process. This occurs when test_idle fails when run with the
-w option but without -jn. Fix warning from test_config.
+- Issue #27621: Put query response validation error messages in the query
+ box itself instead of in a separate massagebox. Redo tests to match.
+ Add Mac OSX refinements. Original patch by Mark Roseman.
+
+- Issue #27620: Escape key now closes Query box as cancelled.
+
+- Issue #27609: IDLE: tab after initial whitespace should tab, not
+ autocomplete. This fixes problem with writing docstrings at least
+ twice indented.
+
+- Issue #27609: Explicitly return None when there are also non-None
+ returns. In a few cases, reverse a condition and eliminate a return.
+
- Issue #25507: IDLE no longer runs buggy code because of its tkinter imports.
Users must include the same imports required to run directly in Python.
+- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
+ Make the default key set depend on the platform.
+ Add tests for the changes to the config module.
+
+- Issue #27452: add line counter and crc to IDLE configHandler test dump.
+
+- Issue #27477: IDLE search dialogs now use ttk widgets.
+
+- Issue #27173: Add 'IDLE Modern Unix' to the built-in key sets.
+ Make the default key set depend on the platform.
+ Add tests for the changes to the config module.
+
+- Issue #27452: make command line "idle-test> python test_help.py" work.
+ __file__ is relative when python is started in the file's directory.
+
- Issue #27452: add line counter and crc to IDLE configHandler test dump.
+- Issue #27380: IDLE: add query.py with base Query dialog and ttk widgets.
+ Module had subclasses SectionName, ModuleName, and HelpSource, which are
+ used to get information from users by configdialog and file =>Load Module.
+ Each subclass has itw own validity checks. Using ModuleName allows users
+ to edit bad module names instead of starting over.
+ Add tests and delete the two files combined into the new one.
+
+- Issue #27372: Test_idle no longer changes the locale.
+
- Issue #27365: Allow non-ascii chars in IDLE NEWS.txt, for contributor names.
- Issue #27245: IDLE: Cleanly delete custom themes and key bindings.
Previously, when IDLE was started from a console or by import, a cascade
of warnings was emitted. Patch by Serhiy Storchaka.
+- Issue #24137: Run IDLE, test_idle, and htest with tkinter default root disabled.
+ Fix code and tests that fail with this restriction.
+ Fix htests to not create a second and redundant root and mainloop.
-What's New in IDLE 3.5.2?
-=========================
-*Release date: 2016-06-26*
+- Issue #27310: Fix IDLE.app failure to launch on OS X due to vestigial import.
- Issue #5124: Paste with text selected now replaces the selection on X11.
This matches how paste works on Windows, Mac, most modern Linux apps,
and ttk widgets. Original patch by Serhiy Storchaka.
+- Issue #24750: Switch all scrollbars in IDLE to ttk versions.
+ Where needed, minimal tests are added to cover changes.
+
+- Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.
+ Delete now unneeded tk version tests and code for older versions.
+ Add test for IDLE syntax colorizer.
+
+- Issue #27239: idlelib.macosx.isXyzTk functions initialize as needed.
+
+- Issue #27262: move Aqua unbinding code, which enable context menus, to maxosx.
+
- Issue #24759: Make clear in idlelib.idle_test.__init__ that the directory
is a private implementation of test.test_idle and tool for maintainers.
-- Issue #27196: Stop 'ThemeChangef' warnings when running IDLE tests.
+- Issue #27196: Stop 'ThemeChanged' warnings when running IDLE tests.
These persisted after other warnings were suppressed in #20567.
Apply Serhiy Storchaka's update_idletasks solution to four test files.
Record this additional advice in idle_test/README.txt
@@ -47,9 +103,26 @@ What's New in IDLE 3.5.2?
- Issue #20567: Revise idle_test/README.txt with advice about avoiding
tk warning messages from tests. Apply advice to several IDLE tests.
+- Issue # 24225: Update idlelib/README.txt with new file names
+ and event handlers.
+
+- Issue #27156: Remove obsolete code not used by IDLE. Replacements:
+ 1. help.txt, replaced by help.html, is out-of-date and should not be used.
+ Its dedicated viewer has be replaced by the html viewer in help.py.
+ 2. 'import idlever; I = idlever.IDLE_VERSION' is the same as
+ 'import sys; I = version[:version.index(' ')]'
+ 3. After 'ob = stackviewer.VariablesTreeItem(*args)',
+ 'ob.keys()' == 'list(ob.object.keys).
+ 4. In macosc, runningAsOSXAPP == isAquaTk; idCarbonAquaTk == isCarbonTk
+
- Issue #27117: Make colorizer htest and turtledemo work with dark themes.
Move code for configuring text widget colors to a new function.
+- Issue #24225: Rename many idlelib/*.py and idle_test/test_*.py files.
+ Edit files to replace old names with new names when the old name
+ referred to the module rather than the class it contained.
+ See the issue and IDLE section in What's New in 3.6 for more.
+
- Issue #26673: When tk reports font size as 0, change to size 10.
Such fonts on Linux prevented the configuration dialog from opening.
@@ -62,8 +135,8 @@ What's New in IDLE 3.5.2?
- Issue #18410: Add test for IDLE's search dialog.
Original patch by Westley Martínez.
-- Issue #21703: Add test for undo delegator.
- Original patch by Saimadhav Heblikar .
+- Issue #21703: Add test for undo delegator. Patch mostly by
+ Saimadhav Heblikar .
- Issue #27044: Add ConfigDialog.remove_var_callbacks to stop memory leaks.
@@ -82,11 +155,6 @@ What's New in IDLE 3.5.2?
MARK in README.txt and open this and NEWS.txt with 'ascii'.
Re-encode CREDITS.txt to utf-8 and open it with 'utf-8'.
-
-What's New in IDLE 3.5.1?
-=========================
-*Release date: 2015-12-06*
-
- Issue 15348: Stop the debugger engine (normally in a user process)
before closing the debugger window (running in the IDLE process).
This prevents the RuntimeErrors that were being caught and ignored.
diff --git a/Lib/idlelib/README.txt b/Lib/idlelib/README.txt
index ff44504..51e8ef5 100644
--- a/Lib/idlelib/README.txt
+++ b/Lib/idlelib/README.txt
@@ -29,61 +29,61 @@ idle.pyw
Implementation
--------------
-AutoComplete.py # Complete attribute names or filenames.
-AutoCompleteWindow.py # Display completions.
-AutoExpand.py # Expand word with previous word in file.
-Bindings.py # Define most of IDLE menu.
-CallTipWindow.py # Display calltip.
-CallTips.py # Create calltip text.
-ClassBrowser.py # Create module browser window.
-CodeContext.py # Show compound statement headers otherwise not visible.
-ColorDelegator.py # Colorize text (nim).
-Debugger.py # Debug code run from editor; show window.
-Delegator.py # Define base class for delegators (nim).
-EditorWindow.py # Define most of editor and utility functions.
-FileList.py # Open files and manage list of open windows (nim).
-FormatParagraph.py# Re-wrap multiline strings and comments.
-GrepDialog.py # Find all occurrences of pattern in multiple files.
-HyperParser.py # Parse code around a given index.
-IOBinding.py # Open, read, and write files
-IdleHistory.py # Get previous or next user input in shell (nim)
-MultiCall.py # Wrap tk widget to allow multiple calls per event (nim).
-MultiStatusBar.py # Define status bar for windows (nim).
-ObjectBrowser.py # Define class used in StackViewer (nim).
-OutputWindow.py # Create window for grep output.
-ParenMatch.py # Match fenceposts: (), [], and {}.
-PathBrowser.py # Create path browser window.
-Percolator.py # Manage delegator stack (nim).
-PyParse.py # Give information on code indentation
-PyShell.py # Start IDLE, manage shell, complete editor window
-RemoteDebugger.py # Debug code run in remote process.
-RemoteObjectBrowser.py # Communicate objects between processes with rpc (nim).
-ReplaceDialog.py # Search and replace pattern in text.
-RstripExtension.py# Strip trailing whitespace
-ScriptBinding.py # Check and run user code.
-ScrolledList.py # Define ScrolledList widget for IDLE (nim).
-SearchDialog.py # Search for pattern in text.
-SearchDialogBase.py # Define base for search, replace, and grep dialogs.
-SearchEngine.py # Define engine for all 3 search dialogs.
-StackViewer.py # View stack after exception.
-TreeWidget.py # Define tree widger, used in browsers (nim).
-UndoDelegator.py # Manage undo stack.
-WidgetRedirector.py # Intercept widget subcommands (for percolator) (nim).
-WindowList.py # Manage window list and define listed top level.
-ZoomHeight.py # Zoom window to full height of screen.
-aboutDialog.py # Display About IDLE dialog.
-configDialog.py # Display user configuration dialogs.
-configHandler.py # Load, fetch, and save configuration (nim).
-configHelpSourceEdit.py # Specify help source.
-configSectionNameDialog.py # Spefify user config section name
-dynOptionMenuWidget.py # define mutable OptionMenu widget (nim).
+autocomplete.py # Complete attribute names or filenames.
+autocomplete_w.py # Display completions.
+autoexpand.py # Expand word with previous word in file.
+browser.py # Create module browser window.
+calltip_w.py # Display calltip.
+calltips.py # Create calltip text.
+codecontext.py # Show compound statement headers otherwise not visible.
+colorizer.py # Colorize text (nim)
+config.py # Load, fetch, and save configuration (nim).
+configdialog.py # Display user configuration dialogs.
+config_help.py # Specify help source in configdialog.
+config_key.py # Change keybindings.
+dynoption.py # Define mutable OptionMenu widget (nim).
+debugobj.py # Define class used in stackviewer.
+debugobj_r.py # Communicate objects between processes with rpc (nim).
+debugger.py # Debug code run from shell or editor; show window.
+debugger_r.py # Debug code run in remote process.
+delegator.py # Define base class for delegators (nim).
+editor.py # Define most of editor and utility functions.
+filelist.py # Open files and manage list of open windows (nim).
+grep.py # Find all occurrences of pattern in multiple files.
help.py # Display IDLE's html doc.
-keybindingDialog.py # Change keybindings.
-macosxSupport.py # Help IDLE run on Macs (nim).
+help_about.py # Display About IDLE dialog.
+history.py # Get previous or next user input in shell (nim)
+hyperparser.py # Parse code around a given index.
+iomenu.py # Open, read, and write files
+macosx.py # Help IDLE run on Macs (nim).
+mainmenu.py # Define most of IDLE menu.
+multicall.py # Wrap tk widget to allow multiple calls per event (nim).
+outwin.py # Create window for grep output.
+paragraph.py # Re-wrap multiline strings and comments.
+parenmatch.py # Match fenceposts: (), [], and {}.
+pathbrowser.py # Create path browser window.
+percolator.py # Manage delegator stack (nim).
+pyparse.py # Give information on code indentation
+pyshell.py # Start IDLE, manage shell, complete editor window
+query.py # Query user for information
+redirector.py # Intercept widget subcommands (for percolator) (nim).
+replace.py # Search and replace pattern in text.
rpc.py # Commuicate between idle and user processes (nim).
+rstrip.py # Strip trailing whitespace.
run.py # Manage user code execution subprocess.
+runscript.py # Check and run user code.
+scrolledlist.py # Define scrolledlist widget for IDLE (nim).
+search.py # Search for pattern in text.
+searchbase.py # Define base for search, replace, and grep dialogs.
+searchengine.py # Define engine for all 3 search dialogs.
+stackviewer.py # View stack after exception.
+statusbar.py # Define status bar for windows (nim).
tabbedpages.py # Define tabbed pages widget (nim).
-textView.py # Define read-only text widget (nim).
+textview.py # Define read-only text widget (nim).
+tree.py # Define tree widger, used in browsers (nim).
+undo.py # Manage undo stack.
+windows.py # Manage window list and define listed top level.
+zoomheight.py # Zoom window to full height of screen.
Configuration
-------------
@@ -104,127 +104,148 @@ help.html # copy of idle.html in docs, displayed by IDLE Help
Subdirectories
--------------
-Icons # small image files
-idle_test # files for human test and automated unit tests
+Icons # small image files
+idle_test # files for human test and automated unit tests
Unused and Deprecated files and objects (nim)
---------------------------------------------
-EditorWindow.py: Helpdialog and helpDialog
-ToolTip.py: unused.
-help.txt
-idlever.py
+tooltip.py # unused
+
IDLE MENUS
-Top level items and most submenu items are defined in Bindings.
+Top level items and most submenu items are defined in mainmenu.
Extenstions add submenu items when active. The names given are
found, quoted, in one of these modules, paired with a '<<pseudoevent>>'.
Each pseudoevent is bound to an event handler. Some event handlers
call another function that does the actual work. The annotations below
are intended to at least give the module where the actual work is done.
+'eEW' = editor.EditorWindow
-File # IOBindig except as noted
- New File
- Open... # IOBinding.open
- Open Module
+File
+ New File # eEW.new_callback
+ Open... # iomenu.open
+ Open Module # eEw.open_module
Recent Files
- Class Browser # Class Browser
- Path Browser # Path Browser
+ Class Browser # eEW.open_class_browser, browser.ClassBrowser
+ Path Browser # eEW.open_path_browser, pathbrowser
---
- Save # IDBinding.save
- Save As... # IOBinding.save_as
- Save Copy As... # IOBindling.save_a_copy
+ Save # iomenu.save
+ Save As... # iomenu.save_as
+ Save Copy As... # iomenu.save_a_copy
---
- Print Window # IOBinding.print_window
+ Print Window # iomenu.print_window
---
- Close
- Exit
+ Close # eEW.close_event
+ Exit # flist.close_all_callback (bound in eEW)
Edit
- Undo # undoDelegator
- Redo # undoDelegator
- ---
- Cut
- Copy
- Paste
- Select All
- --- # Next 5 items use SearchEngine; dialogs use SearchDialogBase
- Find # Search Dialog
- Find Again
- Find Selection
- Find in Files... # GrepDialog
- Replace... # ReplaceDialog
- Go to Line
- Show Completions # AutoComplete extension and AutoCompleteWidow (&HP)
- Expand Word # AutoExpand extension
- Show call tip # Calltips extension and CalltipWindow (& Hyperparser)
- Show surrounding parens # ParenMatch (& Hyperparser)
-
-Shell # PyShell
- View Last Restart # PyShell.PyShell.view_restart_mark
- Restart Shell # PyShell.PyShell.restart_shell
+ Undo # undodelegator
+ Redo # undodelegator
+ --- # eEW.right_menu_event
+ Cut # eEW.cut
+ Copy # eEW.copy
+ Paste # eEW.past
+ Select All # eEW.select_all (+ see eEW.remove_selection)
+ --- # Next 5 items use searchengine; dialogs use searchbase
+ Find # eEW.find_event, search.SearchDialog.find
+ Find Again # eEW.find_again_event, sSD.find_again
+ Find Selection # eEW.find_selection_event, sSD.find_selection
+ Find in Files... # eEW.find_in_files_event, grep
+ Replace... # eEW.replace_event, replace.ReplaceDialog.replace
+ Go to Line # eEW.goto_line_event
+ Show Completions # autocomplete extension and autocompleteWidow (&HP)
+ Expand Word # autoexpand extension
+ Show call tip # Calltips extension and CalltipWindow (& Hyperparser)
+ Show surrounding parens # parenmatch (& Hyperparser)
+
+Shell # pyshell
+ View Last Restart # pyshell.PyShell.view_restart_mark
+ Restart Shell # pyshell.PyShell.restart_shell
Interrupt Execution # pyshell.PyShell.cancel_callback
Debug (Shell only)
Go to File/Line
- Debugger # Debugger, RemoteDebugger, PyShell.toggle_debuger
- Stack Viewer # StackViewer, PyShell.open_stack_viewer
- Auto-open Stack Viewer # StackViewer
+ debugger # debugger, debugger_r, PyShell.toggle_debuger
+ Stack Viewer # stackviewer, PyShell.open_stack_viewer
+ Auto-open Stack Viewer # stackviewer
Format (Editor only)
- Indent Region
- Dedent Region
- Comment Out Region
- Uncomment Region
- Tabify Region
- Untabify Region
- Toggle Tabs
- New Indent Width
- Format Paragraph # FormatParagraph extension
+ Indent Region # eEW.indent_region_event
+ Dedent Region # eEW.dedent_region_event
+ Comment Out Reg. # eEW.comment_region_event
+ Uncomment Region # eEW.uncomment_region_event
+ Tabify Region # eEW.tabify_region_event
+ Untabify Region # eEW.untabify_region_event
+ Toggle Tabs # eEW.toggle_tabs_event
+ New Indent Width # eEW.change_indentwidth_event
+ Format Paragraph # paragraph extension
---
- Strip tailing whitespace # RstripExtension extension
+ Strip tailing whitespace # rstrip extension
Run (Editor only)
- Python Shell # PyShell
+ Python Shell # pyshell
---
- Check Module # ScriptBinding
- Run Module # ScriptBinding
+ Check Module # runscript
+ Run Module # runscript
Options
- Configure IDLE # configDialog
+ Configure IDLE # eEW.config_dialog, configdialog
(tabs in the dialog)
- Font tab # onfig-main.def
- Highlight tab # configSectionNameDialog, config-highlight.def
- Keys tab # keybindingDialog, configSectionNameDialog, onfig-keus.def
- General tab # configHelpSourceEdit, config-main.def
- Configure Extensions # configDialog
- Xyz tab # xyz.py, config-extensions.def
+ Font tab # config-main.def
+ Highlight tab # query, config-highlight.def
+ Keys tab # query, config_key, config_keys.def
+ General tab # config_help, config-main.def
+ Extensions tab # config-extensions.def, corresponding .py
---
- Code Context (editor only) # CodeContext extension
+ Code Context (ed)# codecontext extension
Window
- Zoomheight # ZoomHeight extension
+ Zoomheight # zoomheight extension
---
- <open windows> # WindowList
+ <open windows> # windows
Help
- About IDLE # aboutDialog
+ About IDLE # eEW.about_dialog, help_about.AboutDialog
---
- IDLE Help # help
- Python Doc
- Turtle Demo
+ IDLE Help # eEW.help_dialog, helpshow_idlehelp
+ Python Doc # eEW.python_docs
+ Turtle Demo # eEW.open_turtle_demo
---
<other help sources>
<Context Menu> (right click)
-Defined in EditorWindow, PyShell, Output
- Cut
- Copy
- Paste
- ---
- Go to file/line (shell and output only)
- Set Breakpoint (editor only)
- Clear Breakpoint (editor only)
- Defined in Debugger
- Go to source line
- Show stack frame
+ Defined in editor, PyShelpyshellut
+ Cut
+ Copy
+ Paste
+ ---
+ Go to file/line (shell and output only)
+ Set Breakpoint (editor only)
+ Clear Breakpoint (editor only)
+ Defined in debugger
+ Go to source line
+ Show stack frame
+
+<No menu>
+Center Insert # eEW.center_insert_event
+
+
+CODE STYLE -- Generally PEP 8.
+
+import
+------
+Put import at the top, unless there is a good reason otherwise.
+PEP 8 says to group stdlib, 3rd-party dependencies, and package imports.
+For idlelib, the groups are general stdlib, tkinter, and idlelib.
+Sort modules within each group, except that tkinter.ttk follows tkinter.
+Sort 'from idlelib import mod1' and 'from idlelib.mod2 import object'
+together by module, ignoring within module objects.
+Put 'import __main__' after other idlelib imports.
+
+Imports only needed for testing are put not at the top but in an
+htest function def or "if __name__ == '__main__'" clause.
+
+Within module imports like "from idlelib.mod import class" may cause
+circular imports to deadlock. Even without this, circular imports may
+require at least one of the imports to be delayed until a function call.
diff --git a/Lib/idlelib/__init__.py b/Lib/idlelib/__init__.py
index 711f61b..791ddea 100644
--- a/Lib/idlelib/__init__.py
+++ b/Lib/idlelib/__init__.py
@@ -1,8 +1,10 @@
"""The idlelib package implements the Idle application.
Idle includes an interactive shell and editor.
+Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
Use the files named idle.* to start Idle.
The other files are private implementations. Their details are subject to
change. See PEP 434 for more. Import them at your own risk.
"""
+testing = False # Set True by test.test_idle.
diff --git a/Lib/idlelib/__main__.py b/Lib/idlelib/__main__.py
index 2edf5f7..6349ec7 100644
--- a/Lib/idlelib/__main__.py
+++ b/Lib/idlelib/__main__.py
@@ -3,6 +3,6 @@ IDLE main entry point
Run IDLE as python -m idlelib
"""
-import idlelib.PyShell
-idlelib.PyShell.main()
+import idlelib.pyshell
+idlelib.pyshell.main()
# This file does not work for 2.7; See issue 24212.
diff --git a/Lib/idlelib/AutoComplete.py b/Lib/idlelib/autocomplete.py
index ff085d5..1e44fa5 100644
--- a/Lib/idlelib/AutoComplete.py
+++ b/Lib/idlelib/autocomplete.py
@@ -1,29 +1,30 @@
-"""AutoComplete.py - An IDLE extension for automatically completing names.
+"""autocomplete.py - An IDLE extension for automatically completing names.
This extension can complete either attribute names or file names. It can pop
a window with all available names, for the user to select from.
"""
import os
-import sys
import string
+import sys
-from idlelib.configHandler import idleConf
-
-# This string includes all chars that may be in an identifier
-ID_CHARS = string.ascii_letters + string.digits + "_"
-
-# These constants represent the two different types of completions
+# These constants represent the two different types of completions.
+# They must be defined here so autocomple_w can import them.
COMPLETE_ATTRIBUTES, COMPLETE_FILES = range(1, 2+1)
-from idlelib import AutoCompleteWindow
-from idlelib.HyperParser import HyperParser
-
+from idlelib import autocomplete_w
+from idlelib.config import idleConf
+from idlelib.hyperparser import HyperParser
import __main__
+# This string includes all chars that may be in an identifier.
+# TODO Update this here and elsewhere.
+ID_CHARS = string.ascii_letters + string.digits + "_"
+
SEPS = os.sep
if os.altsep: # e.g. '/' on Windows...
SEPS += os.altsep
+
class AutoComplete:
menudefs = [
@@ -37,19 +38,17 @@ class AutoComplete:
def __init__(self, editwin=None):
self.editwin = editwin
- if editwin is None: # subprocess and test
- return
- self.text = editwin.text
- self.autocompletewindow = None
-
- # id of delayed call, and the index of the text insert when the delayed
- # call was issued. If _delayed_completion_id is None, there is no
- # delayed call.
- self._delayed_completion_id = None
- self._delayed_completion_index = None
+ if editwin is not None: # not in subprocess or test
+ self.text = editwin.text
+ self.autocompletewindow = None
+ # id of delayed call, and the index of the text insert when
+ # the delayed call was issued. If _delayed_completion_id is
+ # None, there is no delayed call.
+ self._delayed_completion_id = None
+ self._delayed_completion_index = None
def _make_autocomplete_window(self):
- return AutoCompleteWindow.AutoCompleteWindow(self.text)
+ return autocomplete_w.AutoCompleteWindow(self.text)
def _remove_autocomplete_window(self, event=None):
if self.autocompletewindow:
@@ -80,16 +79,17 @@ class AutoComplete:
open a completion list after that (if there is more than one
completion)
"""
- if hasattr(event, "mc_state") and event.mc_state:
- # A modifier was pressed along with the tab, continue as usual.
- return
+ if hasattr(event, "mc_state") and event.mc_state or\
+ not self.text.get("insert linestart", "insert").strip():
+ # A modifier was pressed along with the tab or
+ # there is only previous whitespace on this line, so tab.
+ return None
if self.autocompletewindow and self.autocompletewindow.is_active():
self.autocompletewindow.complete()
return "break"
else:
opened = self.open_completions(False, True, True)
- if opened:
- return "break"
+ return "break" if opened else None
def _open_completions_later(self, *args):
self._delayed_completion_index = self.text.index("insert")
@@ -101,9 +101,8 @@ class AutoComplete:
def _delayed_open_completions(self, *args):
self._delayed_completion_id = None
- if self.text.index("insert") != self._delayed_completion_index:
- return
- self.open_completions(*args)
+ if self.text.index("insert") == self._delayed_completion_index:
+ self.open_completions(*args)
def open_completions(self, evalfuncs, complete, userWantsWin, mode=None):
"""Find the completions and create the AutoCompleteWindow.
@@ -148,17 +147,17 @@ class AutoComplete:
comp_what = hp.get_expression()
if not comp_what or \
(not evalfuncs and comp_what.find('(') != -1):
- return
+ return None
else:
comp_what = ""
else:
- return
+ return None
if complete and not comp_what and not comp_start:
- return
+ return None
comp_lists = self.fetch_completions(comp_what, mode)
if not comp_lists[0]:
- return
+ return None
self.autocompletewindow = self._make_autocomplete_window()
return not self.autocompletewindow.show_window(
comp_lists, "insert-%dc" % len(comp_start),
diff --git a/Lib/idlelib/AutoCompleteWindow.py b/Lib/idlelib/autocomplete_w.py
index 2ee6878..3374c6e 100644
--- a/Lib/idlelib/AutoCompleteWindow.py
+++ b/Lib/idlelib/autocomplete_w.py
@@ -1,9 +1,11 @@
"""
-An auto-completion window for IDLE, used by the AutoComplete extension
+An auto-completion window for IDLE, used by the autocomplete extension
"""
from tkinter import *
-from idlelib.MultiCall import MC_SHIFT
-from idlelib.AutoComplete import COMPLETE_FILES, COMPLETE_ATTRIBUTES
+from tkinter.ttk import Scrollbar
+
+from idlelib.autocomplete import COMPLETE_FILES, COMPLETE_ATTRIBUTES
+from idlelib.multicall import MC_SHIFT
HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
HIDE_SEQUENCES = ("<FocusOut>", "<ButtonPress>")
@@ -34,8 +36,8 @@ class AutoCompleteWindow:
self.completions = None
# A list with more completions, or None
self.morecompletions = None
- # The completion mode. Either AutoComplete.COMPLETE_ATTRIBUTES or
- # AutoComplete.COMPLETE_FILES
+ # The completion mode. Either autocomplete.COMPLETE_ATTRIBUTES or
+ # autocomplete.COMPLETE_FILES
self.mode = None
# The current completion start, on the text box (a string)
self.start = None
@@ -215,6 +217,7 @@ class AutoCompleteWindow:
self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
self.doubleclick_event)
+ return None
def winconfig_event(self, event):
if not self.is_active():
@@ -238,16 +241,14 @@ class AutoCompleteWindow:
acw.wm_geometry("+%d+%d" % (new_x, new_y))
def hide_event(self, event):
- if not self.is_active():
- return
- self.hide_window()
+ if self.is_active():
+ self.hide_window()
def listselect_event(self, event):
- if not self.is_active():
- return
- self.userwantswindow = True
- cursel = int(self.listbox.curselection()[0])
- self._change_start(self.completions[cursel])
+ if self.is_active():
+ self.userwantswindow = True
+ cursel = int(self.listbox.curselection()[0])
+ self._change_start(self.completions[cursel])
def doubleclick_event(self, event):
# Put the selected completion in the text, and close the list
@@ -257,7 +258,7 @@ class AutoCompleteWindow:
def keypress_event(self, event):
if not self.is_active():
- return
+ return None
keysym = event.keysym
if hasattr(event, "mc_state"):
state = event.mc_state
@@ -282,7 +283,7 @@ class AutoCompleteWindow:
# keysym == "BackSpace"
if len(self.start) == 0:
self.hide_window()
- return
+ return None
self._change_start(self.start[:-1])
self.lasttypedstart = self.start
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
@@ -292,7 +293,7 @@ class AutoCompleteWindow:
elif keysym == "Return":
self.hide_window()
- return
+ return None
elif (self.mode == COMPLETE_ATTRIBUTES and keysym in
("period", "space", "parenleft", "parenright", "bracketleft",
@@ -308,7 +309,7 @@ class AutoCompleteWindow:
and (self.mode == COMPLETE_ATTRIBUTES or self.start):
self._change_start(self.completions[cursel])
self.hide_window()
- return
+ return None
elif keysym in ("Home", "End", "Prior", "Next", "Up", "Down") and \
not state:
@@ -349,12 +350,12 @@ class AutoCompleteWindow:
# first tab; let AutoComplete handle the completion
self.userwantswindow = True
self.lastkey_was_tab = True
- return
+ return None
elif any(s in keysym for s in ("Shift", "Control", "Alt",
"Meta", "Command", "Option")):
# A modifier key, so ignore
- return
+ return None
elif event.char and event.char >= ' ':
# Regular character with a non-length-1 keycode
@@ -368,7 +369,7 @@ class AutoCompleteWindow:
else:
# Unknown event, close the window and let it through.
self.hide_window()
- return
+ return None
def keyrelease_event(self, event):
if not self.is_active():
diff --git a/Lib/idlelib/AutoExpand.py b/Lib/idlelib/autoexpand.py
index 7059054..6b46bee 100644
--- a/Lib/idlelib/AutoExpand.py
+++ b/Lib/idlelib/autoexpand.py
@@ -12,8 +12,8 @@ its state.
This is an extension file and there is only one instance of AutoExpand.
'''
-import string
import re
+import string
###$ event <<expand-word>>
###$ win <Alt-slash>
@@ -31,6 +31,7 @@ class AutoExpand:
def __init__(self, editwin):
self.text = editwin.text
+ self.bell = self.text.bell
self.state = None
def expand_word_event(self, event):
@@ -46,14 +47,14 @@ class AutoExpand:
words = self.getwords()
index = 0
if not words:
- self.text.bell()
+ self.bell()
return "break"
word = self.getprevword()
self.text.delete("insert - %d chars" % len(word), "insert")
newword = words[index]
index = (index + 1) % len(words)
if index == 0:
- self.text.bell() # Warn we cycled around
+ self.bell() # Warn we cycled around
self.text.insert("insert", newword)
curinsert = self.text.index("insert")
curline = self.text.get("insert linestart", "insert lineend")
diff --git a/Lib/idlelib/ClassBrowser.py b/Lib/idlelib/browser.py
index d09c52f..ea05638 100644
--- a/Lib/idlelib/ClassBrowser.py
+++ b/Lib/idlelib/browser.py
@@ -11,16 +11,16 @@ XXX TO DO:
"""
import os
-import sys
import pyclbr
+import sys
-from idlelib import PyShell
-from idlelib.WindowList import ListedToplevel
-from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas
-from idlelib.configHandler import idleConf
+from idlelib.config import idleConf
+from idlelib import pyshell
+from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
+from idlelib.windows import ListedToplevel
file_open = None # Method...Item and Class...Item use this.
-# Normally PyShell.flist.open, but there is no PyShell.flist for htest.
+# Normally pyshell.flist.open, but there is no pyshell.flist for htest.
class ClassBrowser:
@@ -32,7 +32,7 @@ class ClassBrowser:
"""
global file_open
if not _htest:
- file_open = PyShell.flist.open
+ file_open = pyshell.flist.open
self.name = name
self.file = os.path.join(path[0], self.name + ".py")
self._htest = _htest
@@ -95,7 +95,7 @@ class ModuleBrowserTreeItem(TreeItem):
return
if not os.path.exists(self.file):
return
- PyShell.flist.open(self.file)
+ pyshell.flist.open(self.file)
def IsExpandable(self):
return os.path.normcase(self.file[-3:]) == ".py"
@@ -226,7 +226,7 @@ def _class_browser(parent): #Wrapper for htest
file = sys.argv[0]
dir, file = os.path.split(file)
name = os.path.splitext(file)[0]
- flist = PyShell.PyShellFileList(parent)
+ flist = pyshell.PyShellFileList(parent)
global file_open
file_open = flist.open
ClassBrowser(flist, name, [dir], _htest=True)
diff --git a/Lib/idlelib/CallTipWindow.py b/Lib/idlelib/calltip_w.py
index 9eec175..c7361d1 100644
--- a/Lib/idlelib/CallTipWindow.py
+++ b/Lib/idlelib/calltip_w.py
@@ -1,7 +1,7 @@
"""A CallTip window class for Tkinter/IDLE.
-After ToolTip.py, which uses ideas gleaned from PySol
-Used by the CallTips IDLE extension.
+After tooltip.py, which uses ideas gleaned from PySol
+Used by the calltips IDLE extension.
"""
from tkinter import Toplevel, Label, LEFT, SOLID, TclError
@@ -138,8 +138,8 @@ def _calltip_window(parent): # htest #
top = Toplevel(parent)
top.title("Test calltips")
- top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
- parent.winfo_rooty() + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("200x100+%d+%d" % (x + 250, y + 175))
text = Text(top)
text.pack(side=LEFT, fill=BOTH, expand=1)
text.insert("insert", "string.split")
diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/calltips.py
index 81bd5f1..4c5aea2 100644
--- a/Lib/idlelib/CallTips.py
+++ b/Lib/idlelib/calltips.py
@@ -1,19 +1,19 @@
-"""CallTips.py - An IDLE Extension to Jog Your Memory
+"""calltips.py - An IDLE Extension to Jog Your Memory
Call Tips are floating windows which display function, class, and method
parameter and docstring information when you type an opening parenthesis, and
which disappear when you type a closing parenthesis.
"""
-import __main__
import inspect
import re
import sys
import textwrap
import types
-from idlelib import CallTipWindow
-from idlelib.HyperParser import HyperParser
+from idlelib import calltip_w
+from idlelib.hyperparser import HyperParser
+import __main__
class CallTips:
@@ -37,7 +37,7 @@ class CallTips:
def _make_tk_calltip_window(self):
# See __init__ for usage
- return CallTipWindow.CallTip(self.text)
+ return calltip_w.CallTip(self.text)
def _remove_calltip_window(self, event=None):
if self.active_calltip:
@@ -120,7 +120,7 @@ def get_entity(expression):
_MAX_COLS = 85
_MAX_LINES = 5 # enough for bytes
_INDENT = ' '*4 # for wrapped signatures
-_first_param = re.compile('(?<=\()\w*\,?\s*')
+_first_param = re.compile(r'(?<=\()\w*\,?\s*')
_default_callable_argspec = "See source or doc"
diff --git a/Lib/idlelib/CodeContext.py b/Lib/idlelib/codecontext.py
index 7d25ada..f25e1b3 100644
--- a/Lib/idlelib/CodeContext.py
+++ b/Lib/idlelib/codecontext.py
@@ -1,19 +1,21 @@
-"""CodeContext - Extension to display the block context above the edit window
+"""codecontext - Extension to display the block context above the edit window
Once code has scrolled off the top of a window, it can be difficult to
determine which block you are in. This extension implements a pane at the top
of each IDLE edit window which provides block structure hints. These hints are
the lines which contain the block opening keywords, e.g. 'if', for the
enclosing block. The number of hint lines is determined by the numlines
-variable in the CodeContext section of config-extensions.def. Lines which do
+variable in the codecontext section of config-extensions.def. Lines which do
not open blocks are not shown in the context hints pane.
"""
-import tkinter
-from tkinter.constants import TOP, LEFT, X, W, SUNKEN
import re
from sys import maxsize as INFINITY
-from idlelib.configHandler import idleConf
+
+import tkinter
+from tkinter.constants import TOP, LEFT, X, W, SUNKEN
+
+from idlelib.config import idleConf
BLOCKOPENERS = {"class", "def", "elif", "else", "except", "finally", "for",
"if", "try", "while", "with"}
diff --git a/Lib/idlelib/ColorDelegator.py b/Lib/idlelib/colorizer.py
index 02eac47..7310bb2 100644
--- a/Lib/idlelib/ColorDelegator.py
+++ b/Lib/idlelib/colorizer.py
@@ -1,10 +1,10 @@
-import time
-import re
-import keyword
import builtins
-from tkinter import TkVersion
-from idlelib.Delegator import Delegator
-from idlelib.configHandler import idleConf
+import keyword
+import re
+import time
+
+from idlelib.config import idleConf
+from idlelib.delegator import Delegator
DEBUG = False
@@ -49,11 +49,8 @@ def color_config(text): # Called from htest, Editor, and Turtle Demo.
insertbackground=cursor_color,
selectforeground=select_colors['foreground'],
selectbackground=select_colors['background'],
- )
- if TkVersion >= 8.5:
- text.config(
- inactiveselectbackground=select_colors['background'])
-
+ inactiveselectbackground=select_colors['background'], # new in 8.5
+ )
class ColorDelegator(Delegator):
@@ -259,12 +256,12 @@ class ColorDelegator(Delegator):
def _color_delegator(parent): # htest #
from tkinter import Toplevel, Text
- from idlelib.Percolator import Percolator
+ from idlelib.percolator import Percolator
top = Toplevel(parent)
top.title("Test ColorDelegator")
- top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
- parent.winfo_rooty() + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("200x100+%d+%d" % (x + 250, y + 175))
source = "if somename: x = 'abc' # comment\nprint\n"
text = Text(top, background="white")
text.pack(expand=1, fill="both")
@@ -277,5 +274,9 @@ def _color_delegator(parent): # htest #
p.insertfilter(d)
if __name__ == "__main__":
+ import unittest
+ unittest.main('idlelib.idle_test.test_colorizer',
+ verbosity=2, exit=False)
+
from idlelib.idle_test.htest import run
run(_color_delegator)
diff --git a/Lib/idlelib/config-keys.def b/Lib/idlelib/config-keys.def
index 3bfcb69..64788f9 100644
--- a/Lib/idlelib/config-keys.def
+++ b/Lib/idlelib/config-keys.def
@@ -109,6 +109,57 @@ change-indentwidth=<Alt-Key-u>
del-word-left=<Alt-Key-BackSpace>
del-word-right=<Alt-Key-d>
+[IDLE Modern Unix]
+copy = <Control-Shift-Key-C> <Control-Key-Insert>
+cut = <Control-Key-x> <Shift-Key-Delete>
+paste = <Control-Key-v> <Shift-Key-Insert>
+beginning-of-line = <Key-Home>
+center-insert = <Control-Key-l>
+close-all-windows = <Control-Key-q>
+close-window = <Control-Key-w> <Control-Shift-Key-W>
+do-nothing = <Control-Key-F12>
+end-of-file = <Control-Key-d>
+history-next = <Alt-Key-n> <Meta-Key-n>
+history-previous = <Alt-Key-p> <Meta-Key-p>
+interrupt-execution = <Control-Key-c>
+view-restart = <Key-F6>
+restart-shell = <Control-Key-F6>
+open-class-browser = <Control-Key-b>
+open-module = <Control-Key-m>
+open-new-window = <Control-Key-n>
+open-window-from-file = <Control-Key-o>
+plain-newline-and-indent = <Control-Key-j>
+print-window = <Control-Key-p>
+python-context-help = <Shift-Key-F1>
+python-docs = <Key-F1>
+redo = <Control-Shift-Key-Z>
+remove-selection = <Key-Escape>
+save-copy-of-window-as-file = <Alt-Shift-Key-S>
+save-window-as-file = <Control-Shift-Key-S>
+save-window = <Control-Key-s>
+select-all = <Control-Key-a>
+toggle-auto-coloring = <Control-Key-slash>
+undo = <Control-Key-z>
+find = <Control-Key-f>
+find-again = <Key-F3>
+find-in-files = <Control-Shift-Key-f>
+find-selection = <Control-Key-h>
+replace = <Control-Key-r>
+goto-line = <Control-Key-g>
+smart-backspace = <Key-BackSpace>
+newline-and-indent = <Key-Return> <Key-KP_Enter>
+smart-indent = <Key-Tab>
+indent-region = <Control-Key-bracketright>
+dedent-region = <Control-Key-bracketleft>
+comment-region = <Control-Key-d>
+uncomment-region = <Control-Shift-Key-D>
+tabify-region = <Alt-Key-5>
+untabify-region = <Alt-Key-6>
+toggle-tabs = <Control-Key-T>
+change-indentwidth = <Alt-Key-u>
+del-word-left = <Control-Key-BackSpace>
+del-word-right = <Control-Key-Delete>
+
[IDLE Classic Mac]
copy=<Command-Key-c>
cut=<Command-Key-x>
diff --git a/Lib/idlelib/config-main.def b/Lib/idlelib/config-main.def
index 8ebbc1b..a61bba7 100644
--- a/Lib/idlelib/config-main.def
+++ b/Lib/idlelib/config-main.def
@@ -70,7 +70,9 @@ name2=
[Keys]
default= 1
-name= IDLE Classic Windows
+name=
+name2=
+# name2 set in user config-main.cfg for keys added after 2016 July 1
[History]
cyclic=1
diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/config.py
index 8954488..10fe3ba 100644
--- a/Lib/idlelib/configHandler.py
+++ b/Lib/idlelib/config.py
@@ -7,7 +7,7 @@ duplicate the defaults will be removed from the user's configuration files,
and if a file becomes empty, it will be deleted.
The contents of the user files may be altered using the Options/Configure IDLE
-menu to access the configuration GUI (configDialog.py), or manually.
+menu to access the configuration GUI (configdialog.py), or manually.
Throughout this module there is an emphasis on returning useable defaults
when a problem occurs in returning a requested configuration value back to
@@ -18,11 +18,10 @@ configuration problem notification and resolution.
"""
# TODOs added Oct 2014, tjr
+from configparser import ConfigParser
import os
import sys
-from configparser import ConfigParser
-from tkinter import TkVersion
from tkinter.font import Font, nametofont
class InvalidConfigType(Exception): pass
@@ -230,15 +229,12 @@ class IdleConf:
return self.userCfg[configType].Get(section, option,
type=type, raw=raw)
except ValueError:
- warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
+ warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
' invalid %r value for configuration option %r\n'
' from section %r: %r' %
(type, option, section,
self.userCfg[configType].Get(section, option, raw=raw)))
- try:
- print(warning, file=sys.stderr)
- except OSError:
- pass
+ _warn(warning, configType, section, option)
try:
if self.defaultCfg[configType].has_option(section,option):
return self.defaultCfg[configType].Get(
@@ -247,15 +243,12 @@ class IdleConf:
pass
#returning default, print warning
if warn_on_default:
- warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
+ warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
' problem retrieving configuration option %r\n'
' from section %r.\n'
' returning default value: %r' %
(option, section, default))
- try:
- print(warning, file=sys.stderr)
- except OSError:
- pass
+ _warn(warning, configType, section, option)
return default
def SetOption(self, configType, section, option, value):
@@ -358,52 +351,73 @@ class IdleConf:
for element in theme:
if not cfgParser.has_option(themeName, element):
# Print warning that will return a default color
- warning = ('\n Warning: configHandler.IdleConf.GetThemeDict'
+ warning = ('\n Warning: config.IdleConf.GetThemeDict'
' -\n problem retrieving theme element %r'
'\n from theme %r.\n'
' returning default color: %r' %
(element, themeName, theme[element]))
- try:
- print(warning, file=sys.stderr)
- except OSError:
- pass
+ _warn(warning, 'highlight', themeName, element)
theme[element] = cfgParser.Get(
themeName, element, default=theme[element])
return theme
def CurrentTheme(self):
- """Return the name of the currently active text color theme.
+ "Return the name of the currently active text color theme."
+ return self.current_colors_and_keys('Theme')
+
+ def CurrentKeys(self):
+ """Return the name of the currently active key set."""
+ return self.current_colors_and_keys('Keys')
+
+ def current_colors_and_keys(self, section):
+ """Return the currently active name for Theme or Keys section.
+
+ idlelib.config-main.def ('default') includes these sections
- idlelib.config-main.def includes this section
[Theme]
default= 1
name= IDLE Classic
name2=
- # name2 set in user config-main.cfg for themes added after 2015 Oct 1
- Item name2 is needed because setting name to a new builtin
- causes older IDLEs to display multiple error messages or quit.
+ [Keys]
+ default= 1
+ name=
+ name2=
+
+ Item 'name2', is used for built-in ('default') themes and keys
+ added after 2015 Oct 1 and 2016 July 1. This kludge is needed
+ because setting 'name' to a builtin not defined in older IDLEs
+ to display multiple error messages or quit.
See https://bugs.python.org/issue25313.
- When default = True, name2 takes precedence over name,
- while older IDLEs will just use name.
+ When default = True, 'name2' takes precedence over 'name',
+ while older IDLEs will just use name. When default = False,
+ 'name2' may still be set, but it is ignored.
"""
- default = self.GetOption('main', 'Theme', 'default',
+ cfgname = 'highlight' if section == 'Theme' else 'keys'
+ default = self.GetOption('main', section, 'default',
type='bool', default=True)
+ name = ''
if default:
- theme = self.GetOption('main', 'Theme', 'name2', default='')
- if default and not theme or not default:
- theme = self.GetOption('main', 'Theme', 'name', default='')
- source = self.defaultCfg if default else self.userCfg
- if source['highlight'].has_section(theme):
- return theme
+ name = self.GetOption('main', section, 'name2', default='')
+ if not name:
+ name = self.GetOption('main', section, 'name', default='')
+ if name:
+ source = self.defaultCfg if default else self.userCfg
+ if source[cfgname].has_section(name):
+ return name
+ return "IDLE Classic" if section == 'Theme' else self.default_keys()
+
+ @staticmethod
+ def default_keys():
+ if sys.platform[:3] == 'win':
+ return 'IDLE Classic Windows'
+ elif sys.platform == 'darwin':
+ return 'IDLE Classic OSX'
else:
- return "IDLE Classic"
+ return 'IDLE Modern Unix'
- def CurrentKeys(self):
- "Return the name of the currently active key set."
- return self.GetOption('main', 'Keys', 'name', default='')
-
- def GetExtensions(self, active_only=True, editor_only=False, shell_only=False):
+ def GetExtensions(self, active_only=True,
+ editor_only=False, shell_only=False):
"""Return extensions in default and user config-extensions files.
If active_only True, only return active (enabled) extensions
@@ -423,7 +437,7 @@ class IdleConf:
if self.GetOption('extensions', extn, 'enable', default=True,
type='bool'):
#the extension is enabled
- if editor_only or shell_only: # TODO if both, contradictory
+ if editor_only or shell_only: # TODO both True contradict
if editor_only:
option = "enable_editor"
else:
@@ -528,7 +542,8 @@ class IdleConf:
eventStr - virtual event, including brackets, as in '<<event>>'.
"""
eventName = eventStr[2:-2] #trim off the angle brackets
- binding = self.GetOption('keys', keySetName, eventName, default='').split()
+ binding = self.GetOption('keys', keySetName, eventName, default='',
+ warn_on_default=False).split()
return binding
def GetCurrentKeySet(self):
@@ -639,20 +654,28 @@ class IdleConf:
'<<del-word-right>>': ['<Control-Key-Delete>']
}
if keySetName:
- for event in keyBindings:
- binding = self.GetKeyBinding(keySetName, event)
- if binding:
- keyBindings[event] = binding
- else: #we are going to return a default, print warning
- warning=('\n Warning: configHandler.py - IdleConf.GetCoreKeys'
- ' -\n problem retrieving key binding for event %r'
- '\n from key set %r.\n'
- ' returning default value: %r' %
- (event, keySetName, keyBindings[event]))
- try:
- print(warning, file=sys.stderr)
- except OSError:
- pass
+ if not (self.userCfg['keys'].has_section(keySetName) or
+ self.defaultCfg['keys'].has_section(keySetName)):
+ warning = (
+ '\n Warning: config.py - IdleConf.GetCoreKeys -\n'
+ ' key set %r is not defined, using default bindings.' %
+ (keySetName,)
+ )
+ _warn(warning, 'keys', keySetName)
+ else:
+ for event in keyBindings:
+ binding = self.GetKeyBinding(keySetName, event)
+ if binding:
+ keyBindings[event] = binding
+ else: #we are going to return a default, print warning
+ warning = (
+ '\n Warning: config.py - IdleConf.GetCoreKeys -\n'
+ ' problem retrieving key binding for event %r\n'
+ ' from key set %r.\n'
+ ' returning default value: %r' %
+ (event, keySetName, keyBindings[event])
+ )
+ _warn(warning, 'keys', keySetName, event)
return keyBindings
def GetExtraHelpSourceList(self, configSet):
@@ -713,16 +736,13 @@ class IdleConf:
bold = self.GetOption(configType, section, 'font-bold', default=0,
type='bool')
if (family == 'TkFixedFont'):
- if TkVersion < 8.5:
- family = 'Courier'
- else:
- f = Font(name='TkFixedFont', exists=True, root=root)
- actualFont = Font.actual(f)
- family = actualFont['family']
- size = actualFont['size']
- if size <= 0:
- size = 10 # if font in pixels, ignore actual size
- bold = actualFont['weight']=='bold'
+ f = Font(name='TkFixedFont', exists=True, root=root)
+ actualFont = Font.actual(f)
+ family = actualFont['family']
+ size = actualFont['size']
+ if size <= 0:
+ size = 10 # if font in pixels, ignore actual size
+ bold = actualFont['weight'] == 'bold'
return (family, size, 'bold' if bold else 'normal')
def LoadCfgFiles(self):
@@ -739,6 +759,18 @@ class IdleConf:
idleConf = IdleConf()
+
+_warned = set()
+def _warn(msg, *key):
+ key = (msg,) + key
+ if key not in _warned:
+ try:
+ print(msg, file=sys.stderr)
+ except OSError:
+ pass
+ _warned.add(key)
+
+
# TODO Revise test output, write expanded unittest
#
if __name__ == '__main__':
diff --git a/Lib/idlelib/configHelpSourceEdit.py b/Lib/idlelib/configHelpSourceEdit.py
deleted file mode 100644
index cde8118..0000000
--- a/Lib/idlelib/configHelpSourceEdit.py
+++ /dev/null
@@ -1,170 +0,0 @@
-"Dialog to specify or edit the parameters for a user configured help source."
-
-import os
-import sys
-
-from tkinter import *
-import tkinter.messagebox as tkMessageBox
-import tkinter.filedialog as tkFileDialog
-
-class GetHelpSourceDialog(Toplevel):
- def __init__(self, parent, title, menuItem='', filePath='', _htest=False):
- """Get menu entry and url/ local file location for Additional Help
-
- User selects a name for the Help resource and provides a web url
- or a local file as its source. The user can enter a url or browse
- for the file.
-
- _htest - bool, change box location when running htest
- """
- Toplevel.__init__(self, parent)
- self.configure(borderwidth=5)
- self.resizable(height=FALSE, width=FALSE)
- self.title(title)
- self.transient(parent)
- self.grab_set()
- self.protocol("WM_DELETE_WINDOW", self.cancel)
- self.parent = parent
- self.result = None
- self.create_widgets()
- self.menu.set(menuItem)
- self.path.set(filePath)
- self.withdraw() #hide while setting geometry
- #needs to be done here so that the winfo_reqwidth is valid
- self.update_idletasks()
- #centre dialog over parent. below parent if running htest.
- self.geometry(
- "+%d+%d" % (
- parent.winfo_rootx() +
- (parent.winfo_width()/2 - self.winfo_reqwidth()/2),
- parent.winfo_rooty() +
- ((parent.winfo_height()/2 - self.winfo_reqheight()/2)
- if not _htest else 150)))
- self.deiconify() #geometry set, unhide
- self.bind('<Return>', self.ok)
- self.wait_window()
-
- def create_widgets(self):
- self.menu = StringVar(self)
- self.path = StringVar(self)
- self.fontSize = StringVar(self)
- self.frameMain = Frame(self, borderwidth=2, relief=GROOVE)
- self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
- labelMenu = Label(self.frameMain, anchor=W, justify=LEFT,
- text='Menu Item:')
- self.entryMenu = Entry(self.frameMain, textvariable=self.menu,
- width=30)
- self.entryMenu.focus_set()
- labelPath = Label(self.frameMain, anchor=W, justify=LEFT,
- text='Help File Path: Enter URL or browse for file')
- self.entryPath = Entry(self.frameMain, textvariable=self.path,
- width=40)
- self.entryMenu.focus_set()
- labelMenu.pack(anchor=W, padx=5, pady=3)
- self.entryMenu.pack(anchor=W, padx=5, pady=3)
- labelPath.pack(anchor=W, padx=5, pady=3)
- self.entryPath.pack(anchor=W, padx=5, pady=3)
- browseButton = Button(self.frameMain, text='Browse', width=8,
- command=self.browse_file)
- browseButton.pack(pady=3)
- frameButtons = Frame(self)
- frameButtons.pack(side=BOTTOM, fill=X)
- self.buttonOk = Button(frameButtons, text='OK',
- width=8, default=ACTIVE, command=self.ok)
- self.buttonOk.grid(row=0, column=0, padx=5,pady=5)
- self.buttonCancel = Button(frameButtons, text='Cancel',
- width=8, command=self.cancel)
- self.buttonCancel.grid(row=0, column=1, padx=5, pady=5)
-
- def browse_file(self):
- filetypes = [
- ("HTML Files", "*.htm *.html", "TEXT"),
- ("PDF Files", "*.pdf", "TEXT"),
- ("Windows Help Files", "*.chm"),
- ("Text Files", "*.txt", "TEXT"),
- ("All Files", "*")]
- path = self.path.get()
- if path:
- dir, base = os.path.split(path)
- else:
- base = None
- if sys.platform[:3] == 'win':
- dir = os.path.join(os.path.dirname(sys.executable), 'Doc')
- if not os.path.isdir(dir):
- dir = os.getcwd()
- else:
- dir = os.getcwd()
- opendialog = tkFileDialog.Open(parent=self, filetypes=filetypes)
- file = opendialog.show(initialdir=dir, initialfile=base)
- if file:
- self.path.set(file)
-
- def menu_ok(self):
- "Simple validity check for a sensible menu item name"
- menu_ok = True
- menu = self.menu.get()
- menu.strip()
- if not menu:
- tkMessageBox.showerror(title='Menu Item Error',
- message='No menu item specified',
- parent=self)
- self.entryMenu.focus_set()
- menu_ok = False
- elif len(menu) > 30:
- tkMessageBox.showerror(title='Menu Item Error',
- message='Menu item too long:'
- '\nLimit 30 characters.',
- parent=self)
- self.entryMenu.focus_set()
- menu_ok = False
- return menu_ok
-
- def path_ok(self):
- "Simple validity check for menu file path"
- path_ok = True
- path = self.path.get()
- path.strip()
- if not path: #no path specified
- tkMessageBox.showerror(title='File Path Error',
- message='No help file path specified.',
- parent=self)
- self.entryPath.focus_set()
- path_ok = False
- elif path.startswith(('www.', 'http')):
- pass
- else:
- if path[:5] == 'file:':
- path = path[5:]
- if not os.path.exists(path):
- tkMessageBox.showerror(title='File Path Error',
- message='Help file path does not exist.',
- parent=self)
- self.entryPath.focus_set()
- path_ok = False
- return path_ok
-
- def ok(self, event=None):
- if self.menu_ok() and self.path_ok():
- self.result = (self.menu.get().strip(),
- self.path.get().strip())
- if sys.platform == 'darwin':
- path = self.result[1]
- if path.startswith(('www', 'file:', 'http:', 'https:')):
- pass
- else:
- # Mac Safari insists on using the URI form for local files
- self.result = list(self.result)
- self.result[1] = "file://" + path
- self.destroy()
-
- def cancel(self, event=None):
- self.result = None
- self.destroy()
-
-if __name__ == '__main__':
- import unittest
- unittest.main('idlelib.idle_test.test_config_help',
- verbosity=2, exit=False)
-
- from idlelib.idle_test.htest import run
- run(GetHelpSourceDialog)
diff --git a/Lib/idlelib/configSectionNameDialog.py b/Lib/idlelib/configSectionNameDialog.py
deleted file mode 100644
index 5137836..0000000
--- a/Lib/idlelib/configSectionNameDialog.py
+++ /dev/null
@@ -1,98 +0,0 @@
-"""
-Dialog that allows user to specify a new config file section name.
-Used to get new highlight theme and keybinding set names.
-The 'return value' for the dialog, used two placed in configDialog.py,
-is the .result attribute set in the Ok and Cancel methods.
-"""
-from tkinter import *
-import tkinter.messagebox as tkMessageBox
-
-class GetCfgSectionNameDialog(Toplevel):
- def __init__(self, parent, title, message, used_names, _htest=False):
- """
- message - string, informational message to display
- used_names - string collection, names already in use for validity check
- _htest - bool, change box location when running htest
- """
- Toplevel.__init__(self, parent)
- self.configure(borderwidth=5)
- self.resizable(height=FALSE, width=FALSE)
- self.title(title)
- self.transient(parent)
- self.grab_set()
- self.protocol("WM_DELETE_WINDOW", self.Cancel)
- self.parent = parent
- self.message = message
- self.used_names = used_names
- self.create_widgets()
- self.withdraw() #hide while setting geometry
- self.update_idletasks()
- #needs to be done here so that the winfo_reqwidth is valid
- self.messageInfo.config(width=self.frameMain.winfo_reqwidth())
- self.geometry(
- "+%d+%d" % (
- parent.winfo_rootx() +
- (parent.winfo_width()/2 - self.winfo_reqwidth()/2),
- parent.winfo_rooty() +
- ((parent.winfo_height()/2 - self.winfo_reqheight()/2)
- if not _htest else 100)
- ) ) #centre dialog over parent (or below htest box)
- self.deiconify() #geometry set, unhide
- self.wait_window()
-
- def create_widgets(self):
- self.name = StringVar(self.parent)
- self.fontSize = StringVar(self.parent)
- self.frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
- self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
- self.messageInfo = Message(self.frameMain, anchor=W, justify=LEFT,
- padx=5, pady=5, text=self.message) #,aspect=200)
- entryName = Entry(self.frameMain, textvariable=self.name, width=30)
- entryName.focus_set()
- self.messageInfo.pack(padx=5, pady=5) #, expand=TRUE, fill=BOTH)
- entryName.pack(padx=5, pady=5)
-
- frameButtons = Frame(self, pady=2)
- frameButtons.pack(side=BOTTOM)
- self.buttonOk = Button(frameButtons, text='Ok',
- width=8, command=self.Ok)
- self.buttonOk.pack(side=LEFT, padx=5)
- self.buttonCancel = Button(frameButtons, text='Cancel',
- width=8, command=self.Cancel)
- self.buttonCancel.pack(side=RIGHT, padx=5)
-
- def name_ok(self):
- ''' After stripping entered name, check that it is a sensible
- ConfigParser file section name. Return it if it is, '' if not.
- '''
- name = self.name.get().strip()
- if not name: #no name specified
- tkMessageBox.showerror(title='Name Error',
- message='No name specified.', parent=self)
- elif len(name)>30: #name too long
- tkMessageBox.showerror(title='Name Error',
- message='Name too long. It should be no more than '+
- '30 characters.', parent=self)
- name = ''
- elif name in self.used_names:
- tkMessageBox.showerror(title='Name Error',
- message='This name is already in use.', parent=self)
- name = ''
- return name
-
- def Ok(self, event=None):
- name = self.name_ok()
- if name:
- self.result = name
- self.destroy()
-
- def Cancel(self, event=None):
- self.result = ''
- self.destroy()
-
-if __name__ == '__main__':
- import unittest
- unittest.main('idlelib.idle_test.test_config_name', verbosity=2, exit=False)
-
- from idlelib.idle_test.htest import run
- run(GetCfgSectionNameDialog)
diff --git a/Lib/idlelib/keybindingDialog.py b/Lib/idlelib/config_key.py
index e6438bf..2602293 100644
--- a/Lib/idlelib/keybindingDialog.py
+++ b/Lib/idlelib/config_key.py
@@ -2,31 +2,35 @@
Dialog for building Tkinter accelerator key bindings
"""
from tkinter import *
+from tkinter.ttk import Scrollbar
import tkinter.messagebox as tkMessageBox
import string
import sys
class GetKeysDialog(Toplevel):
- def __init__(self,parent,title,action,currentKeySequences,_htest=False):
+ def __init__(self, parent, title, action, currentKeySequences,
+ _htest=False, _utest=False):
"""
action - string, the name of the virtual event these keys will be
mapped to
currentKeys - list, a list of all key sequence lists currently mapped
to virtual events, for overlap checking
+ _utest - bool, do not wait when running unittest
_htest - bool, change box location when running htest
"""
Toplevel.__init__(self, parent)
+ self.withdraw() #hide while setting geometry
self.configure(borderwidth=5)
- self.resizable(height=FALSE,width=FALSE)
+ self.resizable(height=FALSE, width=FALSE)
self.title(title)
self.transient(parent)
self.grab_set()
self.protocol("WM_DELETE_WINDOW", self.Cancel)
self.parent = parent
self.action=action
- self.currentKeySequences=currentKeySequences
- self.result=''
- self.keyString=StringVar(self)
+ self.currentKeySequences = currentKeySequences
+ self.result = ''
+ self.keyString = StringVar(self)
self.keyString.set('')
self.SetModifiersForPlatform() # set self.modifiers, self.modifier_label
self.modifier_vars = []
@@ -37,7 +41,6 @@ class GetKeysDialog(Toplevel):
self.advanced = False
self.CreateWidgets()
self.LoadFinalKeyList()
- self.withdraw() #hide while setting geometry
self.update_idletasks()
self.geometry(
"+%d+%d" % (
@@ -47,8 +50,9 @@ class GetKeysDialog(Toplevel):
((parent.winfo_height()/2 - self.winfo_reqheight()/2)
if not _htest else 150)
) ) #centre dialog over parent (or below htest box)
- self.deiconify() #geometry set, unhide
- self.wait_window()
+ if not _utest:
+ self.deiconify() #geometry set, unhide
+ self.wait_window()
def CreateWidgets(self):
frameMain = Frame(self,borderwidth=2,relief=SUNKEN)
@@ -261,6 +265,7 @@ class GetKeysDialog(Toplevel):
keysOK = True
return keysOK
+
if __name__ == '__main__':
from idlelib.idle_test.htest import run
run(GetKeysDialog)
diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configdialog.py
index 5f5bd36..fa47aaa 100644
--- a/Lib/idlelib/configDialog.py
+++ b/Lib/idlelib/configdialog.py
@@ -10,18 +10,18 @@ Refer to comments in EditorWindow autoindent code for details.
"""
from tkinter import *
-import tkinter.messagebox as tkMessageBox
+from tkinter.ttk import Scrollbar
import tkinter.colorchooser as tkColorChooser
import tkinter.font as tkFont
+import tkinter.messagebox as tkMessageBox
-from idlelib.configHandler import idleConf
-from idlelib.dynOptionMenuWidget import DynOptionMenu
-from idlelib.keybindingDialog import GetKeysDialog
-from idlelib.configSectionNameDialog import GetCfgSectionNameDialog
-from idlelib.configHelpSourceEdit import GetHelpSourceDialog
+from idlelib.config import idleConf
+from idlelib.config_key import GetKeysDialog
+from idlelib.dynoption import DynOptionMenu
+from idlelib import macosx
+from idlelib.query import SectionName, HelpSource
from idlelib.tabbedpages import TabbedPageSet
-from idlelib.textView import view_text
-from idlelib import macosxSupport
+from idlelib.textview import view_text
class ConfigDialog(Toplevel):
@@ -91,7 +91,7 @@ class ConfigDialog(Toplevel):
self.create_action_buttons().pack(side=BOTTOM)
def create_action_buttons(self):
- if macosxSupport.isAquaTk():
+ if macosx.isAquaTk():
# Changing the default padding on OSX results in unreadable
# text in the buttons
paddingArgs = {}
@@ -341,6 +341,7 @@ class ConfigDialog(Toplevel):
buttonSaveCustomKeys = Button(
frames[1], text='Save as New Custom Key Set',
command=self.SaveAsNewKeySet)
+ self.new_custom_keys = Label(frames[0], bd=2)
##widget packing
#body
@@ -361,6 +362,7 @@ class ConfigDialog(Toplevel):
self.radioKeysCustom.grid(row=1, column=0, sticky=W+NS)
self.optMenuKeysBuiltin.grid(row=0, column=1, sticky=NSEW)
self.optMenuKeysCustom.grid(row=1, column=1, sticky=NSEW)
+ self.new_custom_keys.grid(row=0, column=2, sticky=NSEW, padx=5, pady=5)
self.buttonDeleteCustomKeys.pack(side=LEFT, fill=X, expand=True, padx=2)
buttonSaveCustomKeys.pack(side=LEFT, fill=X, expand=True, padx=2)
frames[0].pack(side=TOP, fill=BOTH, expand=True)
@@ -464,24 +466,24 @@ class ConfigDialog(Toplevel):
return frame
def AttachVarCallbacks(self):
- self.fontSize.trace_variable('w', self.VarChanged_font)
- self.fontName.trace_variable('w', self.VarChanged_font)
- self.fontBold.trace_variable('w', self.VarChanged_font)
- self.spaceNum.trace_variable('w', self.VarChanged_spaceNum)
- self.colour.trace_variable('w', self.VarChanged_colour)
- self.builtinTheme.trace_variable('w', self.VarChanged_builtinTheme)
- self.customTheme.trace_variable('w', self.VarChanged_customTheme)
- self.themeIsBuiltin.trace_variable('w', self.VarChanged_themeIsBuiltin)
- self.highlightTarget.trace_variable('w', self.VarChanged_highlightTarget)
- self.keyBinding.trace_variable('w', self.VarChanged_keyBinding)
- self.builtinKeys.trace_variable('w', self.VarChanged_builtinKeys)
- self.customKeys.trace_variable('w', self.VarChanged_customKeys)
- self.keysAreBuiltin.trace_variable('w', self.VarChanged_keysAreBuiltin)
- self.winWidth.trace_variable('w', self.VarChanged_winWidth)
- self.winHeight.trace_variable('w', self.VarChanged_winHeight)
- self.startupEdit.trace_variable('w', self.VarChanged_startupEdit)
- self.autoSave.trace_variable('w', self.VarChanged_autoSave)
- self.encoding.trace_variable('w', self.VarChanged_encoding)
+ self.fontSize.trace_add('write', self.VarChanged_font)
+ self.fontName.trace_add('write', self.VarChanged_font)
+ self.fontBold.trace_add('write', self.VarChanged_font)
+ self.spaceNum.trace_add('write', self.VarChanged_spaceNum)
+ self.colour.trace_add('write', self.VarChanged_colour)
+ self.builtinTheme.trace_add('write', self.VarChanged_builtinTheme)
+ self.customTheme.trace_add('write', self.VarChanged_customTheme)
+ self.themeIsBuiltin.trace_add('write', self.VarChanged_themeIsBuiltin)
+ self.highlightTarget.trace_add('write', self.VarChanged_highlightTarget)
+ self.keyBinding.trace_add('write', self.VarChanged_keyBinding)
+ self.builtinKeys.trace_add('write', self.VarChanged_builtinKeys)
+ self.customKeys.trace_add('write', self.VarChanged_customKeys)
+ self.keysAreBuiltin.trace_add('write', self.VarChanged_keysAreBuiltin)
+ self.winWidth.trace_add('write', self.VarChanged_winWidth)
+ self.winHeight.trace_add('write', self.VarChanged_winHeight)
+ self.startupEdit.trace_add('write', self.VarChanged_startupEdit)
+ self.autoSave.trace_add('write', self.VarChanged_autoSave)
+ self.encoding.trace_add('write', self.VarChanged_encoding)
def remove_var_callbacks(self):
"Remove callbacks to prevent memory leaks."
@@ -492,7 +494,7 @@ class ConfigDialog(Toplevel):
self.keyBinding, self.builtinKeys, self.customKeys,
self.keysAreBuiltin, self.winWidth, self.winHeight,
self.startupEdit, self.autoSave, self.encoding,):
- var.trace_vdelete('w', var.trace_vinfo()[0][1])
+ var.trace_remove('write', var.trace_info()[0][1])
def VarChanged_font(self, *params):
'''When one font attribute changes, save them all, as they are
@@ -514,10 +516,11 @@ class ConfigDialog(Toplevel):
self.OnNewColourSet()
def VarChanged_builtinTheme(self, *params):
+ oldthemes = ('IDLE Classic', 'IDLE New')
value = self.builtinTheme.get()
- if value == 'IDLE Dark':
- if idleConf.GetOption('main', 'Theme', 'name') != 'IDLE New':
- self.AddChangedItem('main', 'Theme', 'name', 'IDLE Classic')
+ if value not in oldthemes:
+ if idleConf.GetOption('main', 'Theme', 'name') not in oldthemes:
+ self.AddChangedItem('main', 'Theme', 'name', oldthemes[0])
self.AddChangedItem('main', 'Theme', 'name2', value)
self.new_custom_theme.config(text='New theme, see Help',
fg='#500000')
@@ -557,8 +560,23 @@ class ConfigDialog(Toplevel):
self.AddChangedItem('extensions', extKeybindSection, event, value)
def VarChanged_builtinKeys(self, *params):
+ oldkeys = (
+ 'IDLE Classic Windows',
+ 'IDLE Classic Unix',
+ 'IDLE Classic Mac',
+ 'IDLE Classic OSX',
+ )
value = self.builtinKeys.get()
- self.AddChangedItem('main', 'Keys', 'name', value)
+ if value not in oldkeys:
+ if idleConf.GetOption('main', 'Keys', 'name') not in oldkeys:
+ self.AddChangedItem('main', 'Keys', 'name', oldkeys[0])
+ self.AddChangedItem('main', 'Keys', 'name2', value)
+ self.new_custom_keys.config(text='New key set, see Help',
+ fg='#500000')
+ else:
+ self.AddChangedItem('main', 'Keys', 'name', value)
+ self.AddChangedItem('main', 'Keys', 'name2', '')
+ self.new_custom_keys.config(text='', fg='black')
self.LoadKeysList(value)
def VarChanged_customKeys(self, *params):
@@ -683,7 +701,7 @@ class ConfigDialog(Toplevel):
def GetNewKeysName(self, message):
usedNames = (idleConf.GetSectionList('user', 'keys') +
idleConf.GetSectionList('default', 'keys'))
- newKeySet = GetCfgSectionNameDialog(
+ newKeySet = SectionName(
self, 'New Custom Key Set', message, usedNames).result
return newKeySet
@@ -767,8 +785,10 @@ class ConfigDialog(Toplevel):
else:
self.optMenuKeysCustom.SetMenu(itemList, itemList[0])
#revert to default key set
- self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys', 'default'))
- self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys', 'name'))
+ self.keysAreBuiltin.set(idleConf.defaultCfg['main']
+ .Get('Keys', 'default'))
+ self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys', 'name')
+ or idleConf.default_keys())
#user can't back out of these changes, they must be applied now
self.SaveAllChangedConfigs()
self.ActivateConfigChanges()
@@ -836,7 +856,7 @@ class ConfigDialog(Toplevel):
def GetNewThemeName(self, message):
usedNames = (idleConf.GetSectionList('user', 'highlight') +
idleConf.GetSectionList('default', 'highlight'))
- newTheme = GetCfgSectionNameDialog(
+ newTheme = SectionName(
self, 'New Custom Theme', message, usedNames).result
return newTheme
@@ -939,7 +959,8 @@ class ConfigDialog(Toplevel):
self.buttonHelpListRemove.config(state=DISABLED)
def HelpListItemAdd(self):
- helpSource = GetHelpSourceDialog(self, 'New Help Source').result
+ helpSource = HelpSource(self, 'New Help Source',
+ ).result
if helpSource:
self.userHelpList.append((helpSource[0], helpSource[1]))
self.listHelp.insert(END, helpSource[0])
@@ -949,16 +970,17 @@ class ConfigDialog(Toplevel):
def HelpListItemEdit(self):
itemIndex = self.listHelp.index(ANCHOR)
helpSource = self.userHelpList[itemIndex]
- newHelpSource = GetHelpSourceDialog(
- self, 'Edit Help Source', menuItem=helpSource[0],
- filePath=helpSource[1]).result
- if (not newHelpSource) or (newHelpSource == helpSource):
- return #no changes
- self.userHelpList[itemIndex] = newHelpSource
- self.listHelp.delete(itemIndex)
- self.listHelp.insert(itemIndex, newHelpSource[0])
- self.UpdateUserHelpChangedItems()
- self.SetHelpListButtonStates()
+ newHelpSource = HelpSource(
+ self, 'Edit Help Source',
+ menuitem=helpSource[0],
+ filepath=helpSource[1],
+ ).result
+ if newHelpSource and newHelpSource != helpSource:
+ self.userHelpList[itemIndex] = newHelpSource
+ self.listHelp.delete(itemIndex)
+ self.listHelp.insert(itemIndex, newHelpSource[0])
+ self.UpdateUserHelpChangedItems()
+ self.SetHelpListButtonStates()
def HelpListItemRemove(self):
itemIndex = self.listHelp.index(ANCHOR)
@@ -996,7 +1018,8 @@ class ConfigDialog(Toplevel):
pass
##font size dropdown
self.optMenuFontSize.SetMenu(('7', '8', '9', '10', '11', '12', '13',
- '14', '16', '18', '20', '22'), fontSize )
+ '14', '16', '18', '20', '22',
+ '25', '29', '34', '40'), fontSize )
##fontWeight
self.fontBold.set(fontBold)
##font sample
@@ -1065,7 +1088,7 @@ class ConfigDialog(Toplevel):
self.optMenuKeysCustom.SetMenu(itemList, currentOption)
itemList = idleConf.GetSectionList('default', 'keys')
itemList.sort()
- self.optMenuKeysBuiltin.SetMenu(itemList, itemList[0])
+ self.optMenuKeysBuiltin.SetMenu(itemList, idleConf.default_keys())
self.SetKeysType()
##load keyset element list
keySetName = idleConf.CurrentKeys()
@@ -1367,12 +1390,18 @@ machine. Some do not take affect until IDLE is restarted.
[Cancel] only cancels changes made since the last save.
'''
help_pages = {
- 'Highlighting':'''
+ 'Highlighting': '''
Highlighting:
The IDLE Dark color theme is new in October 2015. It can only
be used with older IDLE releases if it is saved as a custom
theme, with a different name.
-'''
+''',
+ 'Keys': '''
+Keys:
+The IDLE Modern Unix key set is new in June 2016. It can only
+be used with older IDLE releases if it is saved as a custom
+key set, with a different name.
+''',
}
diff --git a/Lib/idlelib/Debugger.py b/Lib/idlelib/debugger.py
index d5e217d..114d0d1 100644
--- a/Lib/idlelib/Debugger.py
+++ b/Lib/idlelib/debugger.py
@@ -1,9 +1,12 @@
-import os
import bdb
+import os
+
from tkinter import *
-from idlelib.WindowList import ListedToplevel
-from idlelib.ScrolledList import ScrolledList
-from idlelib import macosxSupport
+from tkinter.ttk import Scrollbar
+
+from idlelib import macosx
+from idlelib.scrolledlist import ScrolledList
+from idlelib.windows import ListedToplevel
class Idb(bdb.Bdb):
@@ -34,8 +37,10 @@ class Idb(bdb.Bdb):
return True
else:
prev_frame = frame.f_back
- if prev_frame.f_code.co_filename.count('Debugger.py'):
- # (that test will catch both Debugger.py and RemoteDebugger.py)
+ prev_name = prev_frame.f_code.co_filename
+ if 'idlelib' in prev_name and 'debugger' in prev_name:
+ # catch both idlelib/debugger.py and idlelib/debugger_r.py
+ # on both posix and windows
return False
return self.in_rpc_code(prev_frame)
@@ -370,7 +375,7 @@ class Debugger:
class StackViewer(ScrolledList):
def __init__(self, master, flist, gui):
- if macosxSupport.isAquaTk():
+ if macosx.isAquaTk():
# At least on with the stock AquaTk version on OSX 10.4 you'll
# get a shaking GUI that eventually kills IDLE if the width
# argument is specified.
@@ -502,7 +507,7 @@ class NamespaceViewer:
#
# There is also an obscure bug in sorted(dict) where the
# interpreter gets into a loop requesting non-existing dict[0],
- # dict[1], dict[2], etc from the RemoteDebugger.DictProxy.
+ # dict[1], dict[2], etc from the debugger_r.DictProxy.
###
keys_list = dict.keys()
names = sorted(keys_list)
diff --git a/Lib/idlelib/RemoteDebugger.py b/Lib/idlelib/debugger_r.py
index be2262f..bc97127 100644
--- a/Lib/idlelib/RemoteDebugger.py
+++ b/Lib/idlelib/debugger_r.py
@@ -21,7 +21,7 @@ barrier, in particular frame and traceback objects.
"""
import types
-from idlelib import Debugger
+from idlelib import debugger
debugging = 0
@@ -187,7 +187,7 @@ def start_debugger(rpchandler, gui_adap_oid):
"""
gui_proxy = GUIProxy(rpchandler, gui_adap_oid)
- idb = Debugger.Idb(gui_proxy)
+ idb = debugger.Idb(gui_proxy)
idb_adap = IdbAdapter(idb)
rpchandler.register(idb_adap_oid, idb_adap)
return idb_adap_oid
@@ -362,7 +362,7 @@ def start_remote_debugger(rpcclt, pyshell):
idb_adap_oid = rpcclt.remotecall("exec", "start_the_debugger",\
(gui_adap_oid,), {})
idb_proxy = IdbProxy(rpcclt, pyshell, idb_adap_oid)
- gui = Debugger.Debugger(pyshell, idb_proxy)
+ gui = debugger.Debugger(pyshell, idb_proxy)
gui_adap = GUIAdapter(rpcclt, gui)
rpcclt.register(gui_adap_oid, gui_adap)
return gui
@@ -373,7 +373,7 @@ def close_remote_debugger(rpcclt):
Request that the RPCServer shut down the subprocess debugger and link.
Unregister the GUIAdapter, which will cause a GC on the Idle process
debugger and RPC link objects. (The second reference to the debugger GUI
- is deleted in PyShell.close_remote_debugger().)
+ is deleted in pyshell.close_remote_debugger().)
"""
close_subprocess_debugger(rpcclt)
diff --git a/Lib/idlelib/ObjectBrowser.py b/Lib/idlelib/debugobj.py
index 7b57aa4..b70b13c 100644
--- a/Lib/idlelib/ObjectBrowser.py
+++ b/Lib/idlelib/debugobj.py
@@ -8,13 +8,10 @@
# XXX TO DO:
# - for classes/modules, add "open source" to object browser
-
-import re
-
-from idlelib.TreeWidget import TreeItem, TreeNode, ScrolledCanvas
-
from reprlib import Repr
+from idlelib.tree import TreeItem, TreeNode, ScrolledCanvas
+
myrepr = Repr()
myrepr.maxstring = 100
myrepr.maxother = 100
@@ -122,21 +119,20 @@ def make_objecttreeitem(labeltext, object, setfunction=None):
return c(labeltext, object, setfunction)
-def _object_browser(parent):
+def _object_browser(parent): # htest #
import sys
- from tkinter import Tk
- root = Tk()
- root.title("Test ObjectBrowser")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
- root.configure(bd=0, bg="yellow")
- root.focus_set()
- sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
+ from tkinter import Toplevel
+ top = Toplevel(parent)
+ top.title("Test debug object browser")
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x + 100, y + 175))
+ top.configure(bd=0, bg="yellow")
+ top.focus_set()
+ sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
sc.frame.pack(expand=1, fill="both")
item = make_objecttreeitem("sys", sys)
node = TreeNode(sc.canvas, None, item)
node.update()
- root.mainloop()
if __name__ == '__main__':
from idlelib.idle_test.htest import run
diff --git a/Lib/idlelib/RemoteObjectBrowser.py b/Lib/idlelib/debugobj_r.py
index 8031aae..8031aae 100644
--- a/Lib/idlelib/RemoteObjectBrowser.py
+++ b/Lib/idlelib/debugobj_r.py
diff --git a/Lib/idlelib/Delegator.py b/Lib/idlelib/delegator.py
index dc2a1aa..dc2a1aa 100644
--- a/Lib/idlelib/Delegator.py
+++ b/Lib/idlelib/delegator.py
diff --git a/Lib/idlelib/dynOptionMenuWidget.py b/Lib/idlelib/dynoption.py
index 515b4ba..9c6ffa4 100644
--- a/Lib/idlelib/dynOptionMenuWidget.py
+++ b/Lib/idlelib/dynoption.py
@@ -3,6 +3,7 @@ OptionMenu widget modified to allow dynamic menu reconfiguration
and setting of highlightthickness
"""
import copy
+
from tkinter import OptionMenu, _setit, StringVar, Button
class DynOptionMenu(OptionMenu):
@@ -34,12 +35,12 @@ class DynOptionMenu(OptionMenu):
self.variable.set(value)
def _dyn_option_menu(parent): # htest #
- from tkinter import Toplevel
+ from tkinter import Toplevel # + StringVar, Button
- top = Toplevel()
+ top = Toplevel(parent)
top.title("Tets dynamic option menu")
- top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
- parent.winfo_rooty() + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("200x100+%d+%d" % (x + 250, y + 175))
top.focus_set()
var = StringVar(top)
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/editor.py
index 9944da3..ae475cb 100644
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/editor.py
@@ -6,28 +6,34 @@ import platform
import re
import string
import sys
+import tokenize
+import traceback
+import webbrowser
+
from tkinter import *
+from tkinter.ttk import Scrollbar
import tkinter.simpledialog as tkSimpleDialog
import tkinter.messagebox as tkMessageBox
-import traceback
-import webbrowser
-from idlelib.MultiCall import MultiCallCreator
-from idlelib import WindowList
-from idlelib import SearchDialog
-from idlelib import GrepDialog
-from idlelib import ReplaceDialog
-from idlelib import PyParse
-from idlelib.configHandler import idleConf
-from idlelib import aboutDialog, textView, configDialog
-from idlelib import macosxSupport
+from idlelib.config import idleConf
+from idlelib import configdialog
+from idlelib import grep
from idlelib import help
+from idlelib import help_about
+from idlelib import macosx
+from idlelib.multicall import MultiCallCreator
+from idlelib import pyparse
+from idlelib import query
+from idlelib import replace
+from idlelib import search
+from idlelib import textview
+from idlelib import windows
# The default tab setting for a Text widget, in average-width characters.
TK_TABWIDTH_DEFAULT = 8
-
_py_version = ' (%s)' % platform.python_version()
+
def _sphinx_version():
"Format sys.version_info to produce the Sphinx version string used to install the chm docs"
major, minor, micro, level, serial = sys.version_info
@@ -40,63 +46,16 @@ def _sphinx_version():
return release
-class HelpDialog(object):
-
- def __init__(self):
- self.parent = None # parent of help window
- self.dlg = None # the help window iteself
-
- def display(self, parent, near=None):
- """ Display the help dialog.
-
- parent - parent widget for the help window
-
- near - a Toplevel widget (e.g. EditorWindow or PyShell)
- to use as a reference for placing the help window
- """
- import warnings as w
- w.warn("EditorWindow.HelpDialog is no longer used by Idle.\n"
- "It will be removed in 3.6 or later.\n"
- "It has been replaced by private help.HelpWindow\n",
- DeprecationWarning, stacklevel=2)
- if self.dlg is None:
- self.show_dialog(parent)
- if near:
- self.nearwindow(near)
-
- def show_dialog(self, parent):
- self.parent = parent
- fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
- self.dlg = dlg = textView.view_file(parent,'Help',fn, modal=False)
- dlg.bind('<Destroy>', self.destroy, '+')
-
- def nearwindow(self, near):
- # Place the help dialog near the window specified by parent.
- # Note - this may not reposition the window in Metacity
- # if "/apps/metacity/general/disable_workarounds" is enabled
- dlg = self.dlg
- geom = (near.winfo_rootx() + 10, near.winfo_rooty() + 10)
- dlg.withdraw()
- dlg.geometry("=+%d+%d" % geom)
- dlg.deiconify()
- dlg.lift()
-
- def destroy(self, ev=None):
- self.dlg = None
- self.parent = None
-
-helpDialog = HelpDialog() # singleton instance, no longer used
-
-
class EditorWindow(object):
- from idlelib.Percolator import Percolator
- from idlelib.ColorDelegator import ColorDelegator, color_config
- from idlelib.UndoDelegator import UndoDelegator
- from idlelib.IOBinding import IOBinding, filesystemencoding, encoding
- from idlelib import Bindings
+ from idlelib.percolator import Percolator
+ from idlelib.colorizer import ColorDelegator, color_config
+ from idlelib.undo import UndoDelegator
+ from idlelib.iomenu import IOBinding, encoding
+ from idlelib import mainmenu
from tkinter import Toplevel
- from idlelib.MultiStatusBar import MultiStatusBar
+ from idlelib.statusbar import MultiStatusBar
+ filesystemencoding = sys.getfilesystemencoding() # for file names
help_url = None
def __init__(self, flist=None, filename=None, key=None, root=None):
@@ -136,11 +95,11 @@ class EditorWindow(object):
except AttributeError:
sys.ps1 = '>>> '
self.menubar = Menu(root)
- self.top = top = WindowList.ListedToplevel(root, menu=self.menubar)
+ self.top = top = windows.ListedToplevel(root, menu=self.menubar)
if flist:
self.tkinter_vars = flist.vars
#self.top.instance_dict makes flist.inversedict available to
- #configDialog.py so it can access all EditorWindow instances
+ #configdialog.py so it can access all EditorWindow instances
self.top.instance_dict = flist.inversedict
else:
self.tkinter_vars = {} # keys: Tkinter event names
@@ -158,13 +117,10 @@ class EditorWindow(object):
'wrap': 'none',
'highlightthickness': 0,
'width': self.width,
- 'height': idleConf.GetOption('main', 'EditorWindow',
- 'height', type='int')}
- if TkVersion >= 8.5:
- # Starting with tk 8.5 we have to set the new tabstyle option
- # to 'wordprocessor' to achieve the same display of tabs as in
- # older tk versions.
- text_options['tabstyle'] = 'wordprocessor'
+ 'tabstyle': 'wordprocessor', # new in 8.5
+ 'height': idleConf.GetOption(
+ 'main', 'EditorWindow', 'height', type='int'),
+ }
self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
self.top.focused_widget = self.text
@@ -173,7 +129,7 @@ class EditorWindow(object):
self.top.protocol("WM_DELETE_WINDOW", self.close)
self.top.bind("<<close-window>>", self.close_event)
- if macosxSupport.isAquaTk():
+ if macosx.isAquaTk():
# Command-W on editorwindows doesn't work without this.
text.bind('<<close-window>>', self.close_event)
# Some OS X systems have only one mouse button, so use
@@ -309,7 +265,7 @@ class EditorWindow(object):
menu.add_separator()
end = end + 1
self.wmenu_end = end
- WindowList.register_callback(self.postwindowsmenu)
+ windows.register_callback(self.postwindowsmenu)
# Some abstractions so IDLE extensions are cross-IDE
self.askyesno = tkMessageBox.askyesno
@@ -418,7 +374,7 @@ class EditorWindow(object):
underline, label = prepstr(label)
menudict[name] = menu = Menu(mbar, name=name, tearoff=0)
mbar.add_cascade(label=label, menu=menu, underline=underline)
- if macosxSupport.isCarbonTk():
+ if macosx.isCarbonTk():
# Insert the application menu
menudict['application'] = menu = Menu(mbar, name='apple',
tearoff=0)
@@ -439,7 +395,7 @@ class EditorWindow(object):
end = -1
if end > self.wmenu_end:
menu.delete(self.wmenu_end+1, end)
- WindowList.add_windows_to_menu(menu)
+ windows.add_windows_to_menu(menu)
rmenu = None
@@ -507,17 +463,17 @@ class EditorWindow(object):
def about_dialog(self, event=None):
"Handle Help 'About IDLE' event."
- # Synchronize with macosxSupport.overrideRootMenu.about_dialog.
- aboutDialog.AboutDialog(self.top,'About IDLE')
+ # Synchronize with macosx.overrideRootMenu.about_dialog.
+ help_about.AboutDialog(self.top,'About IDLE')
def config_dialog(self, event=None):
"Handle Options 'Configure IDLE' event."
- # Synchronize with macosxSupport.overrideRootMenu.config_dialog.
- configDialog.ConfigDialog(self.top,'Settings')
+ # Synchronize with macosx.overrideRootMenu.config_dialog.
+ configdialog.ConfigDialog(self.top,'Settings')
def help_dialog(self, event=None):
"Handle Help 'IDLE Help' event."
- # Synchronize with macosxSupport.overrideRootMenu.help_dialog.
+ # Synchronize with macosx.overrideRootMenu.help_dialog.
if self.root:
parent = self.root
else:
@@ -590,23 +546,23 @@ class EditorWindow(object):
return "break"
def find_event(self, event):
- SearchDialog.find(self.text)
+ search.find(self.text)
return "break"
def find_again_event(self, event):
- SearchDialog.find_again(self.text)
+ search.find_again(self.text)
return "break"
def find_selection_event(self, event):
- SearchDialog.find_selection(self.text)
+ search.find_selection(self.text)
return "break"
def find_in_files_event(self, event):
- GrepDialog.grep(self.text, self.io, self.flist)
+ grep.grep(self.text, self.io, self.flist)
return "break"
def replace_event(self, event):
- ReplaceDialog.replace(self.text)
+ replace.replace(self.text)
return "break"
def goto_line_event(self, event):
@@ -622,46 +578,27 @@ class EditorWindow(object):
text.see("insert")
def open_module(self, event=None):
- # XXX Shouldn't this be in IOBinding?
+ """Get module name from user and open it.
+
+ Return module path or None for calls by open_class_browser
+ when latter is not invoked in named editor window.
+ """
+ # XXX This, open_class_browser, and open_path_browser
+ # would fit better in iomenu.IOBinding.
try:
- name = self.text.get("sel.first", "sel.last")
+ name = self.text.get("sel.first", "sel.last").strip()
except TclError:
- name = ""
- else:
- name = name.strip()
- name = tkSimpleDialog.askstring("Module",
- "Enter the name of a Python module\n"
- "to search on sys.path and open:",
- parent=self.text, initialvalue=name)
- if name:
- name = name.strip()
- if not name:
- return
- # XXX Ought to insert current file's directory in front of path
- try:
- spec = importlib.util.find_spec(name)
- except (ValueError, ImportError) as msg:
- tkMessageBox.showerror("Import error", str(msg), parent=self.text)
- return
- if spec is None:
- tkMessageBox.showerror("Import error", "module not found",
- parent=self.text)
- return
- if not isinstance(spec.loader, importlib.abc.SourceLoader):
- tkMessageBox.showerror("Import error", "not a source-based module",
- parent=self.text)
- return
- try:
- file_path = spec.loader.get_filename(name)
- except AttributeError:
- tkMessageBox.showerror("Import error",
- "loader does not support get_filename",
- parent=self.text)
- return
- if self.flist:
- self.flist.open(file_path)
- else:
- self.io.loadfile(file_path)
+ name = ''
+ file_path = query.ModuleName(
+ self.text, "Open Module",
+ "Enter the name of a Python module\n"
+ "to search on sys.path and open:",
+ name).result
+ if file_path is not None:
+ if self.flist:
+ self.flist.open(file_path)
+ else:
+ self.io.loadfile(file_path)
return file_path
def open_class_browser(self, event=None):
@@ -673,12 +610,12 @@ class EditorWindow(object):
return
head, tail = os.path.split(filename)
base, ext = os.path.splitext(tail)
- from idlelib import ClassBrowser
- ClassBrowser.ClassBrowser(self.flist, base, [head])
+ from idlelib import browser
+ browser.ClassBrowser(self.flist, base, [head])
def open_path_browser(self, event=None):
- from idlelib import PathBrowser
- PathBrowser.PathBrowser(self.flist)
+ from idlelib import pathbrowser
+ pathbrowser.PathBrowser(self.flist)
def open_turtle_demo(self, event = None):
import subprocess
@@ -739,7 +676,7 @@ class EditorWindow(object):
def ResetColorizer(self):
"Update the color theme"
- # Called from self.filename_change_hook and from configDialog.py
+ # Called from self.filename_change_hook and from configdialog.py
self._rmcolorizer()
self._addcolorizer()
EditorWindow.color_config(self.text)
@@ -759,14 +696,14 @@ class EditorWindow(object):
def ResetFont(self):
"Update the text widgets' font if it is changed"
- # Called from configDialog.py
+ # Called from configdialog.py
self.text['font'] = idleConf.GetFont(self.root, 'main','EditorWindow')
def RemoveKeybindings(self):
"Remove the keybindings before they are changed."
- # Called from configDialog.py
- self.Bindings.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
+ # Called from configdialog.py
+ self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
for event, keylist in keydefs.items():
self.text.event_delete(event, *keylist)
for extensionName in self.get_standard_extension_names():
@@ -777,8 +714,8 @@ class EditorWindow(object):
def ApplyKeybindings(self):
"Update the keybindings after they are changed"
- # Called from configDialog.py
- self.Bindings.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
+ # Called from configdialog.py
+ self.mainmenu.default_keydefs = keydefs = idleConf.GetCurrentKeySet()
self.apply_bindings()
for extensionName in self.get_standard_extension_names():
xkeydefs = idleConf.GetExtensionBindings(extensionName)
@@ -786,7 +723,7 @@ class EditorWindow(object):
self.apply_bindings(xkeydefs)
#update menu accelerators
menuEventDict = {}
- for menu in self.Bindings.menudefs:
+ for menu in self.mainmenu.menudefs:
menuEventDict[menu[0]] = {}
for item in menu[1]:
if item:
@@ -813,7 +750,7 @@ class EditorWindow(object):
def set_notabs_indentwidth(self):
"Update the indentwidth if changed and not using tabs in this window"
- # Called from configDialog.py
+ # Called from configdialog.py
if not self.usetabs:
self.indentwidth = idleConf.GetOption('main', 'Indent','num-spaces',
type='int')
@@ -993,7 +930,7 @@ class EditorWindow(object):
def _close(self):
if self.io.filename:
self.update_recent_files_list(new_file=self.io.filename)
- WindowList.unregister_callback(self.postwindowsmenu)
+ windows.unregister_callback(self.postwindowsmenu)
self.unload_extensions()
self.io.close()
self.io = None
@@ -1031,12 +968,25 @@ class EditorWindow(object):
def get_standard_extension_names(self):
return idleConf.GetExtensions(editor_only=True)
+ extfiles = { # map config-extension section names to new file names
+ 'AutoComplete': 'autocomplete',
+ 'AutoExpand': 'autoexpand',
+ 'CallTips': 'calltips',
+ 'CodeContext': 'codecontext',
+ 'FormatParagraph': 'paragraph',
+ 'ParenMatch': 'parenmatch',
+ 'RstripExtension': 'rstrip',
+ 'ScriptBinding': 'runscript',
+ 'ZoomHeight': 'zoomheight',
+ }
+
def load_extension(self, name):
+ fname = self.extfiles.get(name, name)
try:
try:
- mod = importlib.import_module('.' + name, package=__package__)
+ mod = importlib.import_module('.' + fname, package=__package__)
except (ImportError, TypeError):
- mod = importlib.import_module(name)
+ mod = importlib.import_module(fname)
except ImportError:
print("\nFailed to import extension: ", name)
raise
@@ -1060,7 +1010,7 @@ class EditorWindow(object):
def apply_bindings(self, keydefs=None):
if keydefs is None:
- keydefs = self.Bindings.default_keydefs
+ keydefs = self.mainmenu.default_keydefs
text = self.text
text.keydefs = keydefs
for event, keylist in keydefs.items():
@@ -1073,9 +1023,9 @@ class EditorWindow(object):
Menus that are absent or None in self.menudict are ignored.
"""
if menudefs is None:
- menudefs = self.Bindings.menudefs
+ menudefs = self.mainmenu.menudefs
if keydefs is None:
- keydefs = self.Bindings.default_keydefs
+ keydefs = self.mainmenu.default_keydefs
menudict = self.menudict
text = self.text
for mname, entrylist in menudefs:
@@ -1302,7 +1252,7 @@ class EditorWindow(object):
# adjust indentation for continuations and block
# open/close first need to find the last stmt
lno = index2line(text.index('insert'))
- y = PyParse.Parser(self.indentwidth, self.tabwidth)
+ y = pyparse.Parser(self.indentwidth, self.tabwidth)
if not self.context_use_ps1:
for context in self.num_context_lines:
startat = max(lno - context, 1)
@@ -1326,22 +1276,22 @@ class EditorWindow(object):
y.set_lo(0)
c = y.get_continuation_type()
- if c != PyParse.C_NONE:
+ if c != pyparse.C_NONE:
# The current stmt hasn't ended yet.
- if c == PyParse.C_STRING_FIRST_LINE:
+ if c == pyparse.C_STRING_FIRST_LINE:
# after the first line of a string; do not indent at all
pass
- elif c == PyParse.C_STRING_NEXT_LINES:
+ elif c == pyparse.C_STRING_NEXT_LINES:
# inside a string which started before this line;
# just mimic the current indent
text.insert("insert", indent)
- elif c == PyParse.C_BRACKET:
+ elif c == pyparse.C_BRACKET:
# line up with the first (if any) element of the
# last open bracket structure; else indent one
# level beyond the indent of the line with the
# last open bracket
self.reindent_to(y.compute_bracket_indent())
- elif c == PyParse.C_BACKSLASH:
+ elif c == pyparse.C_BACKSLASH:
# if more than one line in this stmt already, just
# mimic the current indent; else if initial line
# has a start on an assignment stmt, indent to
@@ -1569,9 +1519,6 @@ def classifyws(s, tabwidth):
break
return raw, effective
-import tokenize
-_tokenize = tokenize
-del tokenize
class IndentSearcher(object):
@@ -1596,8 +1543,8 @@ class IndentSearcher(object):
return self.text.get(mark, mark + " lineend+1c")
def tokeneater(self, type, token, start, end, line,
- INDENT=_tokenize.INDENT,
- NAME=_tokenize.NAME,
+ INDENT=tokenize.INDENT,
+ NAME=tokenize.NAME,
OPENERS=('class', 'def', 'for', 'if', 'try', 'while')):
if self.finished:
pass
@@ -1608,19 +1555,19 @@ class IndentSearcher(object):
self.finished = 1
def run(self):
- save_tabsize = _tokenize.tabsize
- _tokenize.tabsize = self.tabwidth
+ save_tabsize = tokenize.tabsize
+ tokenize.tabsize = self.tabwidth
try:
try:
- tokens = _tokenize.generate_tokens(self.readline)
+ tokens = tokenize.generate_tokens(self.readline)
for token in tokens:
self.tokeneater(*token)
- except (_tokenize.TokenError, SyntaxError):
+ except (tokenize.TokenError, SyntaxError):
# since we cut off the tokenizer early, we can trigger
# spurious errors
pass
finally:
- _tokenize.tabsize = save_tabsize
+ tokenize.tabsize = save_tabsize
return self.blkopenline, self.indentedline
### end autoindent code ###
@@ -1644,7 +1591,7 @@ def get_accelerator(keydefs, eventname):
keylist = keydefs.get(eventname)
# issue10940: temporary workaround to prevent hang with OS X Cocoa Tk 8.5
# if not keylist:
- if (not keylist) or (macosxSupport.isCocoaTk() and eventname in {
+ if (not keylist) or (macosx.isCocoaTk() and eventname in {
"<<open-module>>",
"<<goto-line>>",
"<<change-indentwidth>>"}):
@@ -1679,12 +1626,15 @@ def _editor_window(parent): # htest #
filename = sys.argv[1]
else:
filename = None
- macosxSupport.setupApp(root, None)
+ macosx.setupApp(root, None)
edit = EditorWindow(root=root, filename=filename)
edit.text.bind("<<close-all-windows>>", edit.close_event)
# Does not stop error, neither does following
# edit.text.bind("<<close-window>>", edit.close_event)
if __name__ == '__main__':
+ import unittest
+ unittest.main('idlelib.idle_test.test_editor', verbosity=2, exit=False)
+
from idlelib.idle_test.htest import run
run(_editor_window)
diff --git a/Lib/idlelib/FileList.py b/Lib/idlelib/filelist.py
index a9989a8..f46ad7c 100644
--- a/Lib/idlelib/FileList.py
+++ b/Lib/idlelib/filelist.py
@@ -1,4 +1,5 @@
import os
+
from tkinter import *
import tkinter.messagebox as tkMessageBox
@@ -6,7 +7,7 @@ import tkinter.messagebox as tkMessageBox
class FileList:
# N.B. this import overridden in PyShellFileList.
- from idlelib.EditorWindow import EditorWindow
+ from idlelib.editor import EditorWindow
def __init__(self, root):
self.root = root
@@ -111,7 +112,7 @@ class FileList:
def _test():
- from idlelib.EditorWindow import fixwordbreaks
+ from idlelib.editor import fixwordbreaks
import sys
root = Tk()
fixwordbreaks(root)
diff --git a/Lib/idlelib/GrepDialog.py b/Lib/idlelib/grep.py
index 721b231..64ba28d 100644
--- a/Lib/idlelib/GrepDialog.py
+++ b/Lib/idlelib/grep.py
@@ -1,17 +1,19 @@
-import os
import fnmatch
-import re # for htest
+import os
import sys
-from tkinter import StringVar, BooleanVar, Checkbutton # for GrepDialog
-from tkinter import Tk, Text, Button, SEL, END # for htest
-from idlelib import SearchEngine
-from idlelib.SearchDialogBase import SearchDialogBase
-# Importing OutputWindow fails due to import loop
+
+from tkinter import StringVar, BooleanVar
+from tkinter.ttk import Checkbutton
+
+from idlelib.searchbase import SearchDialogBase
+from idlelib import searchengine
+
+# Importing OutputWindow here fails due to import loop
# EditorWindow -> GrepDialop -> OutputWindow -> EditorWindow
def grep(text, io=None, flist=None):
root = text._root()
- engine = SearchEngine.get(root)
+ engine = searchengine.get(root)
if not hasattr(engine, "_grepdialog"):
engine._grepdialog = GrepDialog(root, engine, flist)
dialog = engine._grepdialog
@@ -47,13 +49,10 @@ class GrepDialog(SearchDialogBase):
self.globent = self.make_entry("In files:", self.globvar)[0]
def create_other_buttons(self):
- f = self.make_frame()[0]
-
- btn = Checkbutton(f, anchor="w",
- variable=self.recvar,
+ btn = Checkbutton(
+ self.make_frame()[0], variable=self.recvar,
text="Recurse down subdirectories")
btn.pack(side="top", fill="both")
- btn.select()
def create_command_buttons(self):
SearchDialogBase.create_command_buttons(self)
@@ -67,7 +66,7 @@ class GrepDialog(SearchDialogBase):
if not path:
self.top.bell()
return
- from idlelib.OutputWindow import OutputWindow # leave here!
+ from idlelib.outwin import OutputWindow # leave here!
save = sys.stdout
try:
sys.stdout = OutputWindow(self.flist)
@@ -131,14 +130,16 @@ class GrepDialog(SearchDialogBase):
def _grep_dialog(parent): # htest #
- from idlelib.PyShell import PyShellFileList
- root = Tk()
- root.title("Test GrepDialog")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
-
- flist = PyShellFileList(root)
- text = Text(root, height=5)
+ from tkinter import Toplevel, Text, SEL, END
+ from tkinter.ttk import Button
+ from idlelib.pyshell import PyShellFileList
+ top = Toplevel(parent)
+ top.title("Test GrepDialog")
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x, y + 175))
+
+ flist = PyShellFileList(top)
+ text = Text(top, height=5)
text.pack()
def show_grep_dialog():
@@ -146,9 +147,8 @@ def _grep_dialog(parent): # htest #
grep(text, flist=flist)
text.tag_remove(SEL, "1.0", END)
- button = Button(root, text="Show GrepDialog", command=show_grep_dialog)
+ button = Button(top, text="Show GrepDialog", command=show_grep_dialog)
button.pack()
- root.mainloop()
if __name__ == "__main__":
import unittest
diff --git a/Lib/idlelib/help.py b/Lib/idlelib/help.py
index a7008e9..77e01a3 100644
--- a/Lib/idlelib/help.py
+++ b/Lib/idlelib/help.py
@@ -4,7 +4,7 @@ Contents are subject to revision at any time, without notice.
Help => About IDLE: diplay About Idle dialog
-<to be moved here from aboutDialog.py>
+<to be moved here from help_about.py>
Help => IDLE Help: Display help.html with proper formatting.
@@ -25,15 +25,14 @@ copy_strip - Copy idle.html to help.html, rstripping each line.
show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog.
"""
from html.parser import HTMLParser
-from os.path import abspath, dirname, isdir, isfile, join
+from os.path import abspath, dirname, isfile, join
from platform import python_version
-from tkinter import Tk, Toplevel, Frame, Text, Scrollbar, Menu, Menubutton
+
+from tkinter import Toplevel, Frame, Text, Menu
+from tkinter.ttk import Menubutton, Scrollbar
from tkinter import font as tkfont
-from idlelib.configHandler import idleConf
-use_ttk = False # until available to import
-if use_ttk:
- from tkinter.ttk import Menubutton
+from idlelib.config import idleConf
## About IDLE ##
@@ -197,15 +196,18 @@ class HelpFrame(Frame):
"Display html text, scrollbar, and toc."
def __init__(self, parent, filename):
Frame.__init__(self, parent)
- text = HelpText(self, filename)
+ # keep references to widgets for test access.
+ self.text = text = HelpText(self, filename)
self['background'] = text['background']
- scroll = Scrollbar(self, command=text.yview)
+ self.toc = toc = self.toc_menu(text)
+ self.scroll = scroll = Scrollbar(self, command=text.yview)
text['yscrollcommand'] = scroll.set
+
self.rowconfigure(0, weight=1)
self.columnconfigure(1, weight=1) # text
- self.toc_menu(text).grid(column=0, row=0, sticky='nw')
- text.grid(column=1, row=0, sticky='nsew')
- scroll.grid(column=2, row=0, sticky='ns')
+ toc.grid(row=0, column=0, sticky='nw')
+ text.grid(row=0, column=1, sticky='nsew')
+ scroll.grid(row=0, column=2, sticky='ns')
def toc_menu(self, text):
"Create table of contents as drop-down menu."
diff --git a/Lib/idlelib/help.txt b/Lib/idlelib/help.txt
deleted file mode 100644
index 89fbe0b..0000000
--- a/Lib/idlelib/help.txt
+++ /dev/null
@@ -1,372 +0,0 @@
-This file, idlelib/help.txt is out-of-date and no longer used by Idle.
-It is deprecated and will be removed in the future, possibly in 3.6
-----------------------------------------------------------------------
-
-[See the end of this file for ** TIPS ** on using IDLE !!]
-
-IDLE is the Python IDE built with the tkinter GUI toolkit.
-
-IDLE has the following features:
--coded in 100% pure Python, using the tkinter GUI toolkit
--cross-platform: works on Windows, Unix, and OS X
--multi-window text editor with multiple undo, Python colorizing, smart indent,
-call tips, and many other features
--Python shell window (a.k.a interactive interpreter)
--debugger (not complete, but you can set breakpoints, view and step)
-
-Menus:
-
-IDLE has two window types the Shell window and the Editor window. It is
-possible to have multiple editor windows simultaneously. IDLE's
-menus dynamically change based on which window is currently selected. Each menu
-documented below indicates which window type it is associated with.
-
-File Menu (Shell and Editor):
-
- New File -- Create a new file editing window
- Open... -- Open an existing file
- Open Module... -- Open an existing module (searches sys.path)
- Recent Files... -- Open a list of recent files
- Class Browser -- Show classes and methods in current file
- Path Browser -- Show sys.path directories, modules, classes,
- and methods
- ---
- Save -- Save current window to the associated file (unsaved
- windows have a * before and after the window title)
-
- Save As... -- Save current window to new file, which becomes
- the associated file
- Save Copy As... -- Save current window to different file
- without changing the associated file
- ---
- Print Window -- Print the current window
- ---
- Close -- Close current window (asks to save if unsaved)
- Exit -- Close all windows, quit (asks to save if unsaved)
-
-Edit Menu (Shell and Editor):
-
- Undo -- Undo last change to current window
- (a maximum of 1000 changes may be undone)
- Redo -- Redo last undone change to current window
- ---
- Cut -- Copy a selection into system-wide clipboard,
- then delete the selection
- Copy -- Copy selection into system-wide clipboard
- Paste -- Insert system-wide clipboard into window
- Select All -- Select the entire contents of the edit buffer
- ---
- Find... -- Open a search dialog box with many options
- Find Again -- Repeat last search
- Find Selection -- Search for the string in the selection
- Find in Files... -- Open a search dialog box for searching files
- Replace... -- Open a search-and-replace dialog box
- Go to Line -- Ask for a line number and show that line
- Expand Word -- Expand the word you have typed to match another
- word in the same buffer; repeat to get a
- different expansion
- Show Calltip -- After an unclosed parenthesis for a function, open
- a small window with function parameter hints
- Show Parens -- Highlight the surrounding parenthesis
- Show Completions -- Open a scroll window allowing selection keywords
- and attributes. (see '*TIPS*', below)
-
-Format Menu (Editor window only):
-
- Indent Region -- Shift selected lines right by the indent width
- (default 4 spaces)
- Dedent Region -- Shift selected lines left by the indent width
- (default 4 spaces)
- Comment Out Region -- Insert ## in front of selected lines
- Uncomment Region -- Remove leading # or ## from selected lines
- Tabify Region -- Turns *leading* stretches of spaces into tabs.
- (Note: We recommend using 4 space blocks to indent Python code.)
- Untabify Region -- Turn *all* tabs into the corrent number of spaces
- Toggle tabs -- Open a dialog to switch between indenting with
- spaces and tabs.
- New Indent Width... -- Open a dialog to change indent width. The
- accepted default by the Python community is 4
- spaces.
- Format Paragraph -- Reformat the current blank-line-separated
- paragraph. All lines in the paragraph will be
- formatted to less than 80 columns.
- ---
- Strip trailing whitespace -- Removed any space characters after the end
- of the last non-space character
-
-Run Menu (Editor window only):
-
- Python Shell -- Open or wake up the Python shell window
- ---
- Check Module -- Check the syntax of the module currently open in the
- Editor window. If the module has not been saved IDLE
- will prompt the user to save the code.
- Run Module -- Restart the shell to clean the environment, then
- execute the currently open module. If the module has
- not been saved IDLE will prompt the user to save the
- code.
-
-Shell Menu (Shell window only):
-
- View Last Restart -- Scroll the shell window to the last Shell restart
- Restart Shell -- Restart the shell to clean the environment
-
-Debug Menu (Shell window only):
-
- Go to File/Line -- Look around the insert point for a filename
- and line number, open the file, and show the line.
- Useful to view the source lines referenced in an
- exception traceback. Available in the context
- menu of the Shell window.
- Debugger (toggle) -- This feature is not complete and considered
- experimental. Run commands in the shell under the
- debugger.
- Stack Viewer -- Show the stack traceback of the last exception
- Auto-open Stack Viewer (toggle) -- Toggle automatically opening the
- stack viewer on unhandled
- exception
-
-Options Menu (Shell and Editor):
-
- Configure IDLE -- Open a configuration dialog. Fonts, indentation,
- keybindings, and color themes may be altered.
- Startup Preferences may be set, and additional Help
- sources can be specified. On OS X, open the
- configuration dialog by selecting Preferences
- in the application menu.
-
- ---
- Code Context (toggle) -- Open a pane at the top of the edit window
- which shows the block context of the section
- of code which is scrolling off the top or the
- window. This is not present in the Shell
- window only the Editor window.
-
-Window Menu (Shell and Editor):
-
- Zoom Height -- Toggles the window between normal size (40x80 initial
- setting) and maximum height. The initial size is in the Configure
- IDLE dialog under the general tab.
- ---
- The rest of this menu lists the names of all open windows;
- select one to bring it to the foreground (deiconifying it if
- necessary).
-
-Help Menu:
-
- About IDLE -- Version, copyright, license, credits
- ---
- IDLE Help -- Display this file which is a help file for IDLE
- detailing the menu options, basic editing and navigation,
- and other tips.
- Python Docs -- Access local Python documentation, if
- installed. Or will start a web browser and open
- docs.python.org showing the latest Python documentation.
- ---
- Additional help sources may be added here with the Configure IDLE
- dialog under the General tab.
-
-Editor context menu (Right-click / Control-click on OS X in Edit window):
-
- Cut -- Copy a selection into system-wide clipboard,
- then delete the selection
- Copy -- Copy selection into system-wide clipboard
- Paste -- Insert system-wide clipboard into window
- Set Breakpoint -- Sets a breakpoint. Breakpoints are only enabled
- when the debugger is open.
- Clear Breakpoint -- Clears the breakpoint on that line
-
-Shell context menu (Right-click / Control-click on OS X in Shell window):
-
- Cut -- Copy a selection into system-wide clipboard,
- then delete the selection
- Copy -- Copy selection into system-wide clipboard
- Paste -- Insert system-wide clipboard into window
- ---
- Go to file/line -- Same as in Debug menu
-
-
-** TIPS **
-==========
-
-Additional Help Sources:
-
- Windows users can Google on zopeshelf.chm to access Zope help files in
- the Windows help format. The Additional Help Sources feature of the
- configuration GUI supports .chm, along with any other filetypes
- supported by your browser. Supply a Menu Item title, and enter the
- location in the Help File Path slot of the New Help Source dialog. Use
- http:// and/or www. to identify external URLs, or download the file and
- browse for its path on your machine using the Browse button.
-
- All users can access the extensive sources of help, including
- tutorials, available at docs.python.org. Selected URLs can be added
- or removed from the Help menu at any time using Configure IDLE.
-
-Basic editing and navigation:
-
- Backspace deletes char to the left; DEL deletes char to the right.
- Control-backspace deletes word left, Control-DEL deletes word right.
- Arrow keys and Page Up/Down move around.
- Control-left/right Arrow moves by words in a strange but useful way.
- Home/End go to begin/end of line.
- Control-Home/End go to begin/end of file.
- Some useful Emacs bindings are inherited from Tcl/Tk:
- Control-a beginning of line
- Control-e end of line
- Control-k kill line (but doesn't put it in clipboard)
- Control-l center window around the insertion point
- Standard keybindings (like Control-c to copy and Control-v to
- paste) may work. Keybindings are selected in the Configure IDLE
- dialog.
-
-Automatic indentation:
-
- After a block-opening statement, the next line is indented by 4 spaces
- (in the Python Shell window by one tab). After certain keywords
- (break, return etc.) the next line is dedented. In leading
- indentation, Backspace deletes up to 4 spaces if they are there. Tab
- inserts spaces (in the Python Shell window one tab), number depends on
- Indent Width. Currently tabs are restricted to four spaces due
- to Tcl/Tk limitations.
-
- See also the indent/dedent region commands in the edit menu.
-
-Completions:
-
- Completions are supplied for functions, classes, and attributes of
- classes, both built-in and user-defined. Completions are also provided
- for filenames.
-
- The AutoCompleteWindow (ACW) will open after a predefined delay
- (default is two seconds) after a '.' or (in a string) an os.sep is
- typed. If after one of those characters (plus zero or more other
- characters) a tab is typed the ACW will open immediately if a possible
- continuation is found.
-
- If there is only one possible completion for the characters entered, a
- tab will supply that completion without opening the ACW.
-
- 'Show Completions' will force open a completions window, by default the
- Control-space keys will open a completions window. In an empty
- string, this will contain the files in the current directory. On a
- blank line, it will contain the built-in and user-defined functions and
- classes in the current name spaces, plus any modules imported. If some
- characters have been entered, the ACW will attempt to be more specific.
-
- If string of characters is typed, the ACW selection will jump to the
- entry most closely matching those characters. Entering a tab will cause
- the longest non-ambiguous match to be entered in the Edit window or
- Shell. Two tabs in a row will supply the current ACW selection, as
- will return or a double click. Cursor keys, Page Up/Down, mouse
- selection, and the scroll wheel all operate on the ACW.
-
- "Hidden" attributes can be accessed by typing the beginning of hidden
- name after a '.', e.g. '_'. This allows access to modules with
- '__all__' set, or to class-private attributes.
-
- Completions and the 'Expand Word' facility can save a lot of typing!
-
- Completions are currently limited to those in the namespaces. Names in
- an Editor window which are not via __main__ or sys.modules will not be
- found. Run the module once with your imports to correct this
- situation. Note that IDLE itself places quite a few modules in
- sys.modules, so much can be found by default, e.g. the re module.
-
- If you don't like the ACW popping up unbidden, simply make the delay
- longer or disable the extension. Or another option is the delay could
- be set to zero. Another alternative to preventing ACW popups is to
- disable the call tips extension.
-
-Python Shell window:
-
- Control-c interrupts executing command.
- Control-d sends end-of-file; closes window if typed at >>> prompt.
- Alt-/ expand word is also useful to reduce typing.
-
- Command history:
-
- Alt-p retrieves previous command matching what you have typed. On OS X
- use Control-p.
- Alt-n retrieves next. On OS X use Control-n.
- Return while cursor is on a previous command retrieves that command.
-
- Syntax colors:
-
- The coloring is applied in a background "thread", so you may
- occasionally see uncolorized text. To change the color
- scheme, use the Configure IDLE / Highlighting dialog.
-
- Python default syntax colors:
-
- Keywords orange
- Builtins royal purple
- Strings green
- Comments red
- Definitions blue
-
- Shell default colors:
-
- Console output brown
- stdout blue
- stderr red
- stdin black
-
-Other preferences:
-
- The font preferences, highlighting, keys, and general preferences can
- be changed via the Configure IDLE menu option. Be sure to note that
- keys can be user defined, IDLE ships with four built in key sets. In
- addition a user can create a custom key set in the Configure IDLE
- dialog under the keys tab.
-
-Command line usage:
-
- Enter idle -h at the command prompt to get a usage message.
-
- idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
-
- -c command run this command
- -d enable debugger
- -e edit mode; arguments are files to be edited
- -s run $IDLESTARTUP or $PYTHONSTARTUP first
- -t title set title of shell window
-
- If there are arguments:
- 1. If -e is used, arguments are files opened for editing and sys.argv
- reflects the arguments passed to IDLE itself.
- 2. Otherwise, if -c is used, all arguments are placed in
- sys.argv[1:...], with sys.argv[0] set to -c.
- 3. Otherwise, if neither -e nor -c is used, the first argument is a
- script which is executed with the remaining arguments in
- sys.argv[1:...] and sys.argv[0] set to the script name. If the
- script name is -, no script is executed but an interactive Python
- session is started; the arguments are still available in sys.argv.
-
-Running without a subprocess: (DEPRECATED in Python 3.4 see Issue 16123)
-
- If IDLE is started with the -n command line switch it will run in a
- single process and will not create the subprocess which runs the RPC
- Python execution server. This can be useful if Python cannot create
- the subprocess or the RPC socket interface on your platform. However,
- in this mode user code is not isolated from IDLE itself. Also, the
- environment is not restarted when Run/Run Module (F5) is selected. If
- your code has been modified, you must reload() the affected modules and
- re-import any specific items (e.g. from foo import baz) if the changes
- are to take effect. For these reasons, it is preferable to run IDLE
- with the default subprocess if at all possible.
-
-Extensions:
-
- IDLE contains an extension facility. See the beginning of
- config-extensions.def in the idlelib directory for further information.
- The default extensions are currently:
-
- FormatParagraph
- AutoExpand
- ZoomHeight
- ScriptBinding
- CallTips
- ParenMatch
- AutoComplete
- CodeContext
diff --git a/Lib/idlelib/aboutDialog.py b/Lib/idlelib/help_about.py
index a8f75d2..071bd3e 100644
--- a/Lib/idlelib/aboutDialog.py
+++ b/Lib/idlelib/help_about.py
@@ -1,11 +1,13 @@
"""About Dialog for IDLE
"""
-
import os
from sys import version
+
from tkinter import *
-from idlelib import textView
+
+from idlelib import textview
+
class AboutDialog(Toplevel):
"""Modal about dialog for idle
@@ -135,17 +137,18 @@ class AboutDialog(Toplevel):
def display_printer_text(self, title, printer):
printer._Printer__setup()
text = '\n'.join(printer._Printer__lines)
- textView.view_text(self, title, text)
+ textview.view_text(self, title, text)
def display_file_text(self, title, filename, encoding=None):
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
- textView.view_file(self, title, fn, encoding)
+ textview.view_file(self, title, fn, encoding)
def Ok(self, event=None):
self.destroy()
+
if __name__ == '__main__':
import unittest
- unittest.main('idlelib.idle_test.test_helpabout', verbosity=2, exit=False)
+ unittest.main('idlelib.idle_test.test_help_about', verbosity=2, exit=False)
from idlelib.idle_test.htest import run
run(AboutDialog)
diff --git a/Lib/idlelib/IdleHistory.py b/Lib/idlelib/history.py
index 078af29..56f53a0 100644
--- a/Lib/idlelib/IdleHistory.py
+++ b/Lib/idlelib/history.py
@@ -1,11 +1,12 @@
"Implement Idle Shell history mechanism with History class"
-from idlelib.configHandler import idleConf
+from idlelib.config import idleConf
+
class History:
''' Implement Idle Shell history mechanism.
- store - Store source statement (called from PyShell.resetoutput).
+ store - Store source statement (called from pyshell.resetoutput).
fetch - Fetch stored statement matching prefix already entered.
history_next - Bound to <<history-next>> event (default Alt-N).
history_prev - Bound to <<history-prev>> event (default Alt-P).
@@ -99,6 +100,7 @@ class History:
self.pointer = None
self.prefix = None
+
if __name__ == "__main__":
from unittest import main
- main('idlelib.idle_test.test_idlehistory', verbosity=2, exit=False)
+ main('idlelib.idle_test.test_history', verbosity=2, exit=False)
diff --git a/Lib/idlelib/HyperParser.py b/Lib/idlelib/hyperparser.py
index 77cb057..450a709 100644
--- a/Lib/idlelib/HyperParser.py
+++ b/Lib/idlelib/hyperparser.py
@@ -4,11 +4,10 @@ HyperParser uses PyParser. PyParser mostly gives information on the
proper indentation of code. HyperParser gives additional information on
the structure of code.
"""
-
-import string
from keyword import iskeyword
-from idlelib import PyParse
+import string
+from idlelib import pyparse
# all ASCII chars that may be in an identifier
_ASCII_ID_CHARS = frozenset(string.ascii_letters + string.digits + "_")
@@ -30,7 +29,7 @@ class HyperParser:
self.editwin = editwin
self.text = text = editwin.text
- parser = PyParse.Parser(editwin.indentwidth, editwin.tabwidth)
+ parser = pyparse.Parser(editwin.indentwidth, editwin.tabwidth)
def index2line(index):
return int(float(index))
diff --git a/Lib/idlelib/idle.py b/Lib/idlelib/idle.py
index 141534d..485d5a7 100644
--- a/Lib/idlelib/idle.py
+++ b/Lib/idlelib/idle.py
@@ -1,6 +1,7 @@
import os.path
import sys
+
# Enable running IDLE with idlelib in a non-standard location.
# This was once used to run development versions of IDLE.
# Because PEP 434 declared idle.py a public interface,
@@ -9,5 +10,5 @@ idlelib_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if idlelib_dir not in sys.path:
sys.path.insert(0, idlelib_dir)
-from idlelib.PyShell import main # This is subject to change
+from idlelib.pyshell import main # This is subject to change
main()
diff --git a/Lib/idlelib/idle.pyw b/Lib/idlelib/idle.pyw
index 142cb32..e73c049 100644
--- a/Lib/idlelib/idle.pyw
+++ b/Lib/idlelib/idle.pyw
@@ -1,10 +1,10 @@
try:
- import idlelib.PyShell
+ import idlelib.pyshell
except ImportError:
- # IDLE is not installed, but maybe PyShell is on sys.path:
- from . import PyShell
+ # IDLE is not installed, but maybe pyshell is on sys.path:
+ from . import pyshell
import os
- idledir = os.path.dirname(os.path.abspath(PyShell.__file__))
+ idledir = os.path.dirname(os.path.abspath(pyshell.__file__))
if idledir != os.getcwd():
# We're not in the IDLE directory, help the subprocess find run.py
pypath = os.environ.get('PYTHONPATH', '')
@@ -12,6 +12,6 @@ except ImportError:
os.environ['PYTHONPATH'] = pypath + ':' + idledir
else:
os.environ['PYTHONPATH'] = idledir
- PyShell.main()
+ pyshell.main()
else:
- idlelib.PyShell.main()
+ idlelib.pyshell.main()
diff --git a/Lib/idlelib/idle_test/__init__.py b/Lib/idlelib/idle_test/__init__.py
index 845c92d..ad067b4 100644
--- a/Lib/idlelib/idle_test/__init__.py
+++ b/Lib/idlelib/idle_test/__init__.py
@@ -1,6 +1,8 @@
'''idlelib.idle_test is a private implementation of test.test_idle,
which tests the IDLE application as part of the stdlib test suite.
Run IDLE tests alone with "python -m test.test_idle".
+Starting with Python 3.6, IDLE requires tcl/tk 8.5 or later.
+
This package and its contained modules are subject to change and
any direct use is at your own risk.
'''
diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py
index 58e62cb..6f676ae 100644
--- a/Lib/idlelib/idle_test/htest.py
+++ b/Lib/idlelib/idle_test/htest.py
@@ -59,19 +59,20 @@ msg: master window hints about testing the widget.
Modules and classes not being tested at the moment:
-PyShell.PyShellEditorWindow
-Debugger.Debugger
-AutoCompleteWindow.AutoCompleteWindow
-OutputWindow.OutputWindow (indirectly being tested with grep test)
+pyshell.PyShellEditorWindow
+debugger.Debugger
+autocomplete_w.AutoCompleteWindow
+outwin.OutputWindow (indirectly being tested with grep test)
'''
from importlib import import_module
-from idlelib.macosxSupport import _initializeTkVariantTests
import tkinter as tk
+from tkinter.ttk import Scrollbar
+tk.NoDefaultRoot()
AboutDialog_spec = {
- 'file': 'aboutDialog',
- 'kwds': {'title': 'aboutDialog test',
+ 'file': 'help_about',
+ 'kwds': {'title': 'help_about test',
'_htest': True,
},
'msg': "Test every button. Ensure Python, TK and IDLE versions "
@@ -79,14 +80,14 @@ AboutDialog_spec = {
}
_calltip_window_spec = {
- 'file': 'CallTipWindow',
+ 'file': 'calltip_w',
'kwds': {},
'msg': "Typing '(' should display a calltip.\n"
"Typing ') should hide the calltip.\n"
}
_class_browser_spec = {
- 'file': 'ClassBrowser',
+ 'file': 'browser',
'kwds': {},
'msg': "Inspect names of module, class(with superclass if "
"applicable), methods and functions.\nToggle nested items.\n"
@@ -95,7 +96,7 @@ _class_browser_spec = {
}
_color_delegator_spec = {
- 'file': 'ColorDelegator',
+ 'file': 'colorizer',
'kwds': {},
'msg': "The text is sample Python code.\n"
"Ensure components like comments, keywords, builtins,\n"
@@ -104,7 +105,7 @@ _color_delegator_spec = {
}
ConfigDialog_spec = {
- 'file': 'configDialog',
+ 'file': 'configdialog',
'kwds': {'title': 'ConfigDialogTest',
'_htest': True,},
'msg': "IDLE preferences dialog.\n"
@@ -121,7 +122,7 @@ ConfigDialog_spec = {
# TODO Improve message
_dyn_option_menu_spec = {
- 'file': 'dynOptionMenuWidget',
+ 'file': 'dynoption',
'kwds': {},
'msg': "Select one of the many options in the 'old option set'.\n"
"Click the button to change the option set.\n"
@@ -130,39 +131,15 @@ _dyn_option_menu_spec = {
# TODO edit wrapper
_editor_window_spec = {
- 'file': 'EditorWindow',
+ 'file': 'editor',
'kwds': {},
'msg': "Test editor functions of interest.\n"
"Best to close editor first."
}
-GetCfgSectionNameDialog_spec = {
- 'file': 'configSectionNameDialog',
- 'kwds': {'title':'Get Name',
- 'message':'Enter something',
- 'used_names': {'abc'},
- '_htest': True},
- 'msg': "After the text entered with [Ok] is stripped, <nothing>, "
- "'abc', or more that 30 chars are errors.\n"
- "Close 'Get Name' with a valid entry (printed to Shell), "
- "[Cancel], or [X]",
- }
-
-GetHelpSourceDialog_spec = {
- 'file': 'configHelpSourceEdit',
- 'kwds': {'title': 'Get helpsource',
- '_htest': True},
- 'msg': "Enter menu item name and help file path\n "
- "<nothing> and more than 30 chars are invalid menu item names.\n"
- "<nothing>, file does not exist are invalid path items.\n"
- "Test for incomplete web address for help file path.\n"
- "A valid entry will be printed to shell with [0k].\n"
- "[Cancel] will print None to shell",
- }
-
# Update once issue21519 is resolved.
GetKeysDialog_spec = {
- 'file': 'keybindingDialog',
+ 'file': 'config_key',
'kwds': {'title': 'Test keybindings',
'action': 'find-again',
'currentKeySequences': [''] ,
@@ -177,7 +154,7 @@ GetKeysDialog_spec = {
}
_grep_dialog_spec = {
- 'file': 'GrepDialog',
+ 'file': 'grep',
'kwds': {},
'msg': "Click the 'Show GrepDialog' button.\n"
"Test the various 'Find-in-files' functions.\n"
@@ -186,8 +163,24 @@ _grep_dialog_spec = {
"should open that file \nin a new EditorWindow."
}
+HelpSource_spec = {
+ 'file': 'query',
+ 'kwds': {'title': 'Help name and source',
+ 'menuitem': 'test',
+ 'filepath': __file__,
+ 'used_names': {'abc'},
+ '_htest': True},
+ 'msg': "Enter menu item name and help file path\n"
+ "'', > than 30 chars, and 'abc' are invalid menu item names.\n"
+ "'' and file does not exist are invalid path items.\n"
+ "Any url ('www...', 'http...') is accepted.\n"
+ "Test Browse with and without path, as cannot unittest.\n"
+ "[Ok] or <Return> prints valid entry to shell\n"
+ "[Cancel] or <Escape> prints None to shell"
+ }
+
_io_binding_spec = {
- 'file': 'IOBinding',
+ 'file': 'iomenu',
'kwds': {},
'msg': "Test the following bindings.\n"
"<Control-o> to open file from dialog.\n"
@@ -200,7 +193,7 @@ _io_binding_spec = {
}
_multi_call_spec = {
- 'file': 'MultiCall',
+ 'file': 'multicall',
'kwds': {},
'msg': "The following actions should trigger a print to console or IDLE"
" Shell.\nEntering and leaving the text area, key entry, "
@@ -210,14 +203,14 @@ _multi_call_spec = {
}
_multistatus_bar_spec = {
- 'file': 'MultiStatusBar',
+ 'file': 'statusbar',
'kwds': {},
'msg': "Ensure presence of multi-status bar below text area.\n"
"Click 'Update Status' to change the multi-status text"
}
_object_browser_spec = {
- 'file': 'ObjectBrowser',
+ 'file': 'debugobj',
'kwds': {},
'msg': "Double click on items upto the lowest level.\n"
"Attributes of the objects and related information "
@@ -225,7 +218,7 @@ _object_browser_spec = {
}
_path_browser_spec = {
- 'file': 'PathBrowser',
+ 'file': 'pathbrowser',
'kwds': {},
'msg': "Test for correct display of all paths in sys.path.\n"
"Toggle nested items upto the lowest level.\n"
@@ -234,7 +227,7 @@ _path_browser_spec = {
}
_percolator_spec = {
- 'file': 'Percolator',
+ 'file': 'percolator',
'kwds': {},
'msg': "There are two tracers which can be toggled using a checkbox.\n"
"Toggling a tracer 'on' by checking it should print tracer"
@@ -244,8 +237,20 @@ _percolator_spec = {
"Test for actions like text entry, and removal."
}
+Query_spec = {
+ 'file': 'query',
+ 'kwds': {'title': 'Query',
+ 'message': 'Enter something',
+ 'text0': 'Go',
+ '_htest': True},
+ 'msg': "Enter with <Return> or [Ok]. Print valid entry to Shell\n"
+ "Blank line, after stripping, is ignored\n"
+ "Close dialog with valid entry, <Escape>, [Cancel], [X]"
+ }
+
+
_replace_dialog_spec = {
- 'file': 'ReplaceDialog',
+ 'file': 'replace',
'kwds': {},
'msg': "Click the 'Replace' button.\n"
"Test various replace options in the 'Replace dialog'.\n"
@@ -253,15 +258,22 @@ _replace_dialog_spec = {
}
_search_dialog_spec = {
- 'file': 'SearchDialog',
+ 'file': 'search',
'kwds': {},
'msg': "Click the 'Search' button.\n"
"Test various search options in the 'Search dialog'.\n"
"Click [Close] or [X] to close the 'Search Dialog'."
}
+_searchbase_spec = {
+ 'file': 'searchbase',
+ 'kwds': {},
+ 'msg': "Check the appearance of the base search dialog\n"
+ "Its only action is to close."
+ }
+
_scrolled_list_spec = {
- 'file': 'ScrolledList',
+ 'file': 'scrolledlist',
'kwds': {},
'msg': "You should see a scrollable list of items\n"
"Selecting (clicking) or double clicking an item "
@@ -277,7 +289,7 @@ show_idlehelp_spec = {
}
_stack_viewer_spec = {
- 'file': 'StackViewer',
+ 'file': 'stackviewer',
'kwds': {},
'msg': "A stacktrace for a NameError exception.\n"
"Expand 'idlelib ...' and '<locals>'.\n"
@@ -295,8 +307,8 @@ _tabbed_pages_spec = {
}
TextViewer_spec = {
- 'file': 'textView',
- 'kwds': {'title': 'Test textView',
+ 'file': 'textview',
+ 'kwds': {'title': 'Test textview',
'text':'The quick brown fox jumps over the lazy dog.\n'*35,
'_htest': True},
'msg': "Test for read-only property of text.\n"
@@ -304,21 +316,21 @@ TextViewer_spec = {
}
_tooltip_spec = {
- 'file': 'ToolTip',
+ 'file': 'tooltip',
'kwds': {},
'msg': "Place mouse cursor over both the buttons\n"
"A tooltip should appear with some text."
}
_tree_widget_spec = {
- 'file': 'TreeWidget',
+ 'file': 'tree',
'kwds': {},
'msg': "The canvas is scrollable.\n"
"Click on folders upto to the lowest level."
}
_undo_delegator_spec = {
- 'file': 'UndoDelegator',
+ 'file': 'undo',
'kwds': {},
'msg': "Click [Undo] to undo any action.\n"
"Click [Redo] to redo any action.\n"
@@ -327,7 +339,7 @@ _undo_delegator_spec = {
}
_widget_redirector_spec = {
- 'file': 'WidgetRedirector',
+ 'file': 'redirector',
'kwds': {},
'msg': "Every text insert should be printed to the console."
"or the IDLE shell."
@@ -337,14 +349,13 @@ def run(*tests):
root = tk.Tk()
root.title('IDLE htest')
root.resizable(0, 0)
- _initializeTkVariantTests(root)
# a scrollable Label like constant width text widget.
frameLabel = tk.Frame(root, padx=10)
frameLabel.pack()
text = tk.Text(frameLabel, wrap='word')
text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70)
- scrollbar = tk.Scrollbar(frameLabel, command=text.yview)
+ scrollbar = Scrollbar(frameLabel, command=text.yview)
text.config(yscrollcommand=scrollbar.set)
scrollbar.pack(side='right', fill='y', expand=False)
text.pack(side='left', fill='both', expand=True)
@@ -365,11 +376,11 @@ def run(*tests):
test = getattr(mod, test_name)
test_list.append((test_spec, test))
- test_name = tk.StringVar('')
+ test_name = tk.StringVar(root)
callable_object = None
test_kwds = None
- def next():
+ def next_test():
nonlocal test_name, callable_object, test_kwds
if len(test_list) == 1:
@@ -384,20 +395,26 @@ def run(*tests):
text.insert("1.0",test_spec['msg'])
text.configure(state='disabled') # preserve read-only property
- def run_test():
+ def run_test(_=None):
widget = callable_object(**test_kwds)
try:
print(widget.result)
except AttributeError:
pass
- button = tk.Button(root, textvariable=test_name, command=run_test)
+ def close(_=None):
+ root.destroy()
+
+ button = tk.Button(root, textvariable=test_name,
+ default='active', command=run_test)
+ next_button = tk.Button(root, text="Next", command=next_test)
button.pack()
- next_button = tk.Button(root, text="Next", command=next)
next_button.pack()
+ next_button.focus_set()
+ root.bind('<Key-Return>', run_test)
+ root.bind('<Key-Escape>', close)
- next()
-
+ next_test()
root.mainloop()
if __name__ == '__main__':
diff --git a/Lib/idlelib/idle_test/mock_idle.py b/Lib/idlelib/idle_test/mock_idle.py
index 1672a34..c7b49ef 100644
--- a/Lib/idlelib/idle_test/mock_idle.py
+++ b/Lib/idlelib/idle_test/mock_idle.py
@@ -33,7 +33,7 @@ class Func:
class Editor:
- '''Minimally imitate EditorWindow.EditorWindow class.
+ '''Minimally imitate editor.EditorWindow class.
'''
def __init__(self, flist=None, filename=None, key=None, root=None):
self.text = Text()
@@ -46,7 +46,7 @@ class Editor:
class UndoDelegator:
- '''Minimally imitate UndoDelegator,UndoDelegator class.
+ '''Minimally imitate undo.UndoDelegator class.
'''
# A real undo block is only needed for user interaction.
def undo_block_start(*args):
diff --git a/Lib/idlelib/idle_test/test_autocomplete.py b/Lib/idlelib/idle_test/test_autocomplete.py
index 5fc899d..f3f2dea 100644
--- a/Lib/idlelib/idle_test/test_autocomplete.py
+++ b/Lib/idlelib/idle_test/test_autocomplete.py
@@ -1,9 +1,13 @@
+''' Test autocomplete and autocomple_w
+
+Coverage of autocomple: 56%
+'''
import unittest
from test.support import requires
from tkinter import Tk, Text
-import idlelib.AutoComplete as ac
-import idlelib.AutoCompleteWindow as acw
+import idlelib.autocomplete as ac
+import idlelib.autocomplete_w as acw
from idlelib.idle_test.mock_idle import Func
from idlelib.idle_test.mock_tk import Event
@@ -91,6 +95,11 @@ class AutoCompleteTest(unittest.TestCase):
self.assertIsNone(autocomplete.autocomplete_event(ev))
del ev.mc_state
+ # Test that tab after whitespace is ignored.
+ self.text.insert('1.0', ' """Docstring.\n ')
+ self.assertIsNone(autocomplete.autocomplete_event(ev))
+ self.text.delete('1.0', 'end')
+
# If autocomplete window is open, complete() method is called
self.text.insert('1.0', 're.')
# This must call autocomplete._make_autocomplete_window()
diff --git a/Lib/idlelib/idle_test/test_autoexpand.py b/Lib/idlelib/idle_test/test_autoexpand.py
index d2a3156..ae8186c 100644
--- a/Lib/idlelib/idle_test/test_autoexpand.py
+++ b/Lib/idlelib/idle_test/test_autoexpand.py
@@ -1,9 +1,9 @@
-"""Unit tests for idlelib.AutoExpand"""
+"""Unit tests for idlelib.autoexpand"""
import unittest
from test.support import requires
from tkinter import Text, Tk
#from idlelib.idle_test.mock_tk import Text
-from idlelib.AutoExpand import AutoExpand
+from idlelib.autoexpand import AutoExpand
class Dummy_Editwin:
@@ -22,6 +22,7 @@ class AutoExpandTest(unittest.TestCase):
else:
cls.text = Text()
cls.auto_expand = AutoExpand(Dummy_Editwin(cls.text))
+ cls.auto_expand.bell = lambda: None
@classmethod
def tearDownClass(cls):
@@ -137,5 +138,6 @@ class AutoExpandTest(unittest.TestCase):
new_state = self.auto_expand.state
self.assertNotEqual(initial_state, new_state)
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_calltips.py b/Lib/idlelib/idle_test/test_calltips.py
index b2a733c..0b11602 100644
--- a/Lib/idlelib/idle_test/test_calltips.py
+++ b/Lib/idlelib/idle_test/test_calltips.py
@@ -1,5 +1,5 @@
import unittest
-import idlelib.CallTips as ct
+import idlelib.calltips as ct
import textwrap
import types
diff --git a/Lib/idlelib/idle_test/test_colorizer.py b/Lib/idlelib/idle_test/test_colorizer.py
new file mode 100644
index 0000000..238bc3e
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_colorizer.py
@@ -0,0 +1,56 @@
+'''Test idlelib/colorizer.py
+
+Perform minimal sanity checks that module imports and some things run.
+
+Coverage 22%.
+'''
+from idlelib import colorizer # always test import
+from test.support import requires
+from tkinter import Tk, Text
+import unittest
+
+
+class FunctionTest(unittest.TestCase):
+
+ def test_any(self):
+ self.assertTrue(colorizer.any('test', ('a', 'b')))
+
+ def test_make_pat(self):
+ self.assertTrue(colorizer.make_pat())
+
+
+class ColorConfigTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+ cls.root = Tk()
+ cls.text = Text(cls.root)
+
+ @classmethod
+ def tearDownClass(cls):
+ del cls.text
+ cls.root.destroy()
+ del cls.root
+
+ def test_colorizer(self):
+ colorizer.color_config(self.text)
+
+class ColorDelegatorTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+ cls.root = Tk()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.destroy()
+ del cls.root
+
+ def test_colorizer(self):
+ colorizer.ColorDelegator()
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_config.py b/Lib/idlelib/idle_test/test_config.py
new file mode 100644
index 0000000..a3fa1a3
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_config.py
@@ -0,0 +1,160 @@
+'''Test idlelib.config.
+
+Much is tested by opening config dialog live or in test_configdialog.
+Coverage: 27%
+'''
+from sys import modules
+from test.support import captured_stderr
+from tkinter import Tk
+import unittest
+from idlelib import config
+
+# Tests should not depend on fortuitous user configurations.
+# They must not affect actual user .cfg files.
+# Replace user parsers with empty parsers that cannot be saved.
+
+idleConf = config.idleConf
+usercfg = idleConf.userCfg
+testcfg = {}
+usermain = testcfg['main'] = config.IdleUserConfParser('') # filename
+userhigh = testcfg['highlight'] = config.IdleUserConfParser('')
+userkeys = testcfg['keys'] = config.IdleUserConfParser('')
+
+def setUpModule():
+ idleConf.userCfg = testcfg
+
+def tearDownModule():
+ idleConf.userCfg = usercfg
+
+
+class CurrentColorKeysTest(unittest.TestCase):
+ """ Test colorkeys function with user config [Theme] and [Keys] patterns.
+
+ colorkeys = config.IdleConf.current_colors_and_keys
+ Test all patterns written by IDLE and some errors
+ Item 'default' should really be 'builtin' (versus 'custom).
+ """
+ colorkeys = idleConf.current_colors_and_keys
+ default_theme = 'IDLE Classic'
+ default_keys = idleConf.default_keys()
+
+ def test_old_builtin_theme(self):
+ # On initial installation, user main is blank.
+ self.assertEqual(self.colorkeys('Theme'), self.default_theme)
+ # For old default, name2 must be blank.
+ usermain.read_string('''
+ [Theme]
+ default = True
+ ''')
+ # IDLE omits 'name' for default old builtin theme.
+ self.assertEqual(self.colorkeys('Theme'), self.default_theme)
+ # IDLE adds 'name' for non-default old builtin theme.
+ usermain['Theme']['name'] = 'IDLE New'
+ self.assertEqual(self.colorkeys('Theme'), 'IDLE New')
+ # Erroneous non-default old builtin reverts to default.
+ usermain['Theme']['name'] = 'non-existent'
+ self.assertEqual(self.colorkeys('Theme'), self.default_theme)
+ usermain.remove_section('Theme')
+
+ def test_new_builtin_theme(self):
+ # IDLE writes name2 for new builtins.
+ usermain.read_string('''
+ [Theme]
+ default = True
+ name2 = IDLE Dark
+ ''')
+ self.assertEqual(self.colorkeys('Theme'), 'IDLE Dark')
+ # Leftover 'name', not removed, is ignored.
+ usermain['Theme']['name'] = 'IDLE New'
+ self.assertEqual(self.colorkeys('Theme'), 'IDLE Dark')
+ # Erroneous non-default new builtin reverts to default.
+ usermain['Theme']['name2'] = 'non-existent'
+ self.assertEqual(self.colorkeys('Theme'), self.default_theme)
+ usermain.remove_section('Theme')
+
+ def test_user_override_theme(self):
+ # Erroneous custom name (no definition) reverts to default.
+ usermain.read_string('''
+ [Theme]
+ default = False
+ name = Custom Dark
+ ''')
+ self.assertEqual(self.colorkeys('Theme'), self.default_theme)
+ # Custom name is valid with matching Section name.
+ userhigh.read_string('[Custom Dark]\na=b')
+ self.assertEqual(self.colorkeys('Theme'), 'Custom Dark')
+ # Name2 is ignored.
+ usermain['Theme']['name2'] = 'non-existent'
+ self.assertEqual(self.colorkeys('Theme'), 'Custom Dark')
+ usermain.remove_section('Theme')
+ userhigh.remove_section('Custom Dark')
+
+ def test_old_builtin_keys(self):
+ # On initial installation, user main is blank.
+ self.assertEqual(self.colorkeys('Keys'), self.default_keys)
+ # For old default, name2 must be blank, name is always used.
+ usermain.read_string('''
+ [Keys]
+ default = True
+ name = IDLE Classic Unix
+ ''')
+ self.assertEqual(self.colorkeys('Keys'), 'IDLE Classic Unix')
+ # Erroneous non-default old builtin reverts to default.
+ usermain['Keys']['name'] = 'non-existent'
+ self.assertEqual(self.colorkeys('Keys'), self.default_keys)
+ usermain.remove_section('Keys')
+
+ def test_new_builtin_keys(self):
+ # IDLE writes name2 for new builtins.
+ usermain.read_string('''
+ [Keys]
+ default = True
+ name2 = IDLE Modern Unix
+ ''')
+ self.assertEqual(self.colorkeys('Keys'), 'IDLE Modern Unix')
+ # Leftover 'name', not removed, is ignored.
+ usermain['Keys']['name'] = 'IDLE Classic Unix'
+ self.assertEqual(self.colorkeys('Keys'), 'IDLE Modern Unix')
+ # Erroneous non-default new builtin reverts to default.
+ usermain['Keys']['name2'] = 'non-existent'
+ self.assertEqual(self.colorkeys('Keys'), self.default_keys)
+ usermain.remove_section('Keys')
+
+ def test_user_override_keys(self):
+ # Erroneous custom name (no definition) reverts to default.
+ usermain.read_string('''
+ [Keys]
+ default = False
+ name = Custom Keys
+ ''')
+ self.assertEqual(self.colorkeys('Keys'), self.default_keys)
+ # Custom name is valid with matching Section name.
+ userkeys.read_string('[Custom Keys]\na=b')
+ self.assertEqual(self.colorkeys('Keys'), 'Custom Keys')
+ # Name2 is ignored.
+ usermain['Keys']['name2'] = 'non-existent'
+ self.assertEqual(self.colorkeys('Keys'), 'Custom Keys')
+ usermain.remove_section('Keys')
+ userkeys.remove_section('Custom Keys')
+
+
+class WarningTest(unittest.TestCase):
+
+ def test_warn(self):
+ Equal = self.assertEqual
+ config._warned = set()
+ with captured_stderr() as stderr:
+ config._warn('warning', 'key')
+ Equal(config._warned, {('warning','key')})
+ Equal(stderr.getvalue(), 'warning'+'\n')
+ with captured_stderr() as stderr:
+ config._warn('warning', 'key')
+ Equal(stderr.getvalue(), '')
+ with captured_stderr() as stderr:
+ config._warn('warn2', 'yek')
+ Equal(config._warned, {('warning','key'), ('warn2','yek')})
+ Equal(stderr.getvalue(), 'warn2'+'\n')
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_config_help.py b/Lib/idlelib/idle_test/test_config_help.py
deleted file mode 100644
index 664f8ed..0000000
--- a/Lib/idlelib/idle_test/test_config_help.py
+++ /dev/null
@@ -1,106 +0,0 @@
-"""Unittests for idlelib.configHelpSourceEdit"""
-import unittest
-from idlelib.idle_test.mock_tk import Var, Mbox, Entry
-from idlelib import configHelpSourceEdit as help_dialog_module
-
-help_dialog = help_dialog_module.GetHelpSourceDialog
-
-
-class Dummy_help_dialog:
- # Mock for testing the following methods of help_dialog
- menu_ok = help_dialog.menu_ok
- path_ok = help_dialog.path_ok
- ok = help_dialog.ok
- cancel = help_dialog.cancel
- # Attributes, constant or variable, needed for tests
- menu = Var()
- entryMenu = Entry()
- path = Var()
- entryPath = Entry()
- result = None
- destroyed = False
-
- def destroy(self):
- self.destroyed = True
-
-
-# menu_ok and path_ok call Mbox.showerror if menu and path are not ok.
-orig_mbox = help_dialog_module.tkMessageBox
-showerror = Mbox.showerror
-
-
-class ConfigHelpTest(unittest.TestCase):
- dialog = Dummy_help_dialog()
-
- @classmethod
- def setUpClass(cls):
- help_dialog_module.tkMessageBox = Mbox
-
- @classmethod
- def tearDownClass(cls):
- help_dialog_module.tkMessageBox = orig_mbox
-
- def test_blank_menu(self):
- self.dialog.menu.set('')
- self.assertFalse(self.dialog.menu_ok())
- self.assertEqual(showerror.title, 'Menu Item Error')
- self.assertIn('No', showerror.message)
-
- def test_long_menu(self):
- self.dialog.menu.set('hello' * 10)
- self.assertFalse(self.dialog.menu_ok())
- self.assertEqual(showerror.title, 'Menu Item Error')
- self.assertIn('long', showerror.message)
-
- def test_good_menu(self):
- self.dialog.menu.set('help')
- showerror.title = 'No Error' # should not be called
- self.assertTrue(self.dialog.menu_ok())
- self.assertEqual(showerror.title, 'No Error')
-
- def test_blank_path(self):
- self.dialog.path.set('')
- self.assertFalse(self.dialog.path_ok())
- self.assertEqual(showerror.title, 'File Path Error')
- self.assertIn('No', showerror.message)
-
- def test_invalid_file_path(self):
- self.dialog.path.set('foobar' * 100)
- self.assertFalse(self.dialog.path_ok())
- self.assertEqual(showerror.title, 'File Path Error')
- self.assertIn('not exist', showerror.message)
-
- def test_invalid_url_path(self):
- self.dialog.path.set('ww.foobar.com')
- self.assertFalse(self.dialog.path_ok())
- self.assertEqual(showerror.title, 'File Path Error')
- self.assertIn('not exist', showerror.message)
-
- self.dialog.path.set('htt.foobar.com')
- self.assertFalse(self.dialog.path_ok())
- self.assertEqual(showerror.title, 'File Path Error')
- self.assertIn('not exist', showerror.message)
-
- def test_good_path(self):
- self.dialog.path.set('https://docs.python.org')
- showerror.title = 'No Error' # should not be called
- self.assertTrue(self.dialog.path_ok())
- self.assertEqual(showerror.title, 'No Error')
-
- def test_ok(self):
- self.dialog.destroyed = False
- self.dialog.menu.set('help')
- self.dialog.path.set('https://docs.python.org')
- self.dialog.ok()
- self.assertEqual(self.dialog.result, ('help',
- 'https://docs.python.org'))
- self.assertTrue(self.dialog.destroyed)
-
- def test_cancel(self):
- self.dialog.destroyed = False
- self.dialog.cancel()
- self.assertEqual(self.dialog.result, None)
- self.assertTrue(self.dialog.destroyed)
-
-if __name__ == '__main__':
- unittest.main(verbosity=2, exit=False)
diff --git a/Lib/idlelib/idle_test/test_config_key.py b/Lib/idlelib/idle_test/test_config_key.py
new file mode 100644
index 0000000..ee3f2c8
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_config_key.py
@@ -0,0 +1,33 @@
+''' Test idlelib.config_key.
+
+Coverage: 56% from creating and closing dialog.
+'''
+from idlelib import config_key
+from test.support import requires
+requires('gui')
+import unittest
+from tkinter import Tk, Text
+
+
+class GetKeysTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.root = Tk()
+ cls.root.withdraw()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.update() # Stop "can't run event command" warning.
+ cls.root.destroy()
+ del cls.root
+
+
+ def test_init(self):
+ dia = config_key.GetKeysDialog(
+ self.root, 'test', '<<Test>>', ['<Key-F12>'], _utest=True)
+ dia.Cancel()
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_config_name.py b/Lib/idlelib/idle_test/test_config_name.py
deleted file mode 100644
index 40e72b9..0000000
--- a/Lib/idlelib/idle_test/test_config_name.py
+++ /dev/null
@@ -1,75 +0,0 @@
-"""Unit tests for idlelib.configSectionNameDialog"""
-import unittest
-from idlelib.idle_test.mock_tk import Var, Mbox
-from idlelib import configSectionNameDialog as name_dialog_module
-
-name_dialog = name_dialog_module.GetCfgSectionNameDialog
-
-class Dummy_name_dialog:
- # Mock for testing the following methods of name_dialog
- name_ok = name_dialog.name_ok
- Ok = name_dialog.Ok
- Cancel = name_dialog.Cancel
- # Attributes, constant or variable, needed for tests
- used_names = ['used']
- name = Var()
- result = None
- destroyed = False
- def destroy(self):
- self.destroyed = True
-
-# name_ok calls Mbox.showerror if name is not ok
-orig_mbox = name_dialog_module.tkMessageBox
-showerror = Mbox.showerror
-
-class ConfigNameTest(unittest.TestCase):
- dialog = Dummy_name_dialog()
-
- @classmethod
- def setUpClass(cls):
- name_dialog_module.tkMessageBox = Mbox
-
- @classmethod
- def tearDownClass(cls):
- name_dialog_module.tkMessageBox = orig_mbox
-
- def test_blank_name(self):
- self.dialog.name.set(' ')
- self.assertEqual(self.dialog.name_ok(), '')
- self.assertEqual(showerror.title, 'Name Error')
- self.assertIn('No', showerror.message)
-
- def test_used_name(self):
- self.dialog.name.set('used')
- self.assertEqual(self.dialog.name_ok(), '')
- self.assertEqual(showerror.title, 'Name Error')
- self.assertIn('use', showerror.message)
-
- def test_long_name(self):
- self.dialog.name.set('good'*8)
- self.assertEqual(self.dialog.name_ok(), '')
- self.assertEqual(showerror.title, 'Name Error')
- self.assertIn('too long', showerror.message)
-
- def test_good_name(self):
- self.dialog.name.set(' good ')
- showerror.title = 'No Error' # should not be called
- self.assertEqual(self.dialog.name_ok(), 'good')
- self.assertEqual(showerror.title, 'No Error')
-
- def test_ok(self):
- self.dialog.destroyed = False
- self.dialog.name.set('good')
- self.dialog.Ok()
- self.assertEqual(self.dialog.result, 'good')
- self.assertTrue(self.dialog.destroyed)
-
- def test_cancel(self):
- self.dialog.destroyed = False
- self.dialog.Cancel()
- self.assertEqual(self.dialog.result, '')
- self.assertTrue(self.dialog.destroyed)
-
-
-if __name__ == '__main__':
- unittest.main(verbosity=2, exit=False)
diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py
index 5c09790..70bd14e 100644
--- a/Lib/idlelib/idle_test/test_configdialog.py
+++ b/Lib/idlelib/idle_test/test_configdialog.py
@@ -1,14 +1,13 @@
-'''Test idlelib.configDialog.
+'''Test idlelib.configdialog.
Coverage: 46% just by creating dialog.
The other half is code for working with user customizations.
'''
-from idlelib.configDialog import ConfigDialog # always test import
+from idlelib.configdialog import ConfigDialog # always test import
from test.support import requires
requires('gui')
from tkinter import Tk
import unittest
-from idlelib import macosxSupport as macosx
class ConfigDialogTest(unittest.TestCase):
@@ -16,7 +15,6 @@ class ConfigDialogTest(unittest.TestCase):
def setUpClass(cls):
cls.root = Tk()
cls.root.withdraw()
- macosx._initializeTkVariantTests(cls.root)
@classmethod
def tearDownClass(cls):
@@ -24,7 +22,7 @@ class ConfigDialogTest(unittest.TestCase):
cls.root.destroy()
del cls.root
- def test_dialog(self):
+ def test_configdialog(self):
d = ConfigDialog(self.root, 'Test', _utest=True)
d.remove_var_callbacks()
diff --git a/Lib/idlelib/idle_test/test_debugger.py b/Lib/idlelib/idle_test/test_debugger.py
new file mode 100644
index 0000000..bcba9a4
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_debugger.py
@@ -0,0 +1,29 @@
+''' Test idlelib.debugger.
+
+Coverage: 19%
+'''
+from idlelib import debugger
+from test.support import requires
+requires('gui')
+import unittest
+from tkinter import Tk
+
+
+class NameSpaceTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.root = Tk()
+ cls.root.withdraw()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.destroy()
+ del cls.root
+
+ def test_init(self):
+ debugger.NamespaceViewer(self.root, 'Test')
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_delegator.py b/Lib/idlelib/idle_test/test_delegator.py
index 1f0baa9..85624fb 100644
--- a/Lib/idlelib/idle_test/test_delegator.py
+++ b/Lib/idlelib/idle_test/test_delegator.py
@@ -1,5 +1,5 @@
import unittest
-from idlelib.Delegator import Delegator
+from idlelib.delegator import Delegator
class DelegatorTest(unittest.TestCase):
diff --git a/Lib/idlelib/idle_test/test_editmenu.py b/Lib/idlelib/idle_test/test_editmenu.py
index a258e29..17eb25c 100644
--- a/Lib/idlelib/idle_test/test_editmenu.py
+++ b/Lib/idlelib/idle_test/test_editmenu.py
@@ -5,8 +5,9 @@ Edit modules have their own test files files
from test.support import requires
requires('gui')
import tkinter as tk
+from tkinter import ttk
import unittest
-from idlelib import PyShell
+from idlelib import pyshell
class PasteTest(unittest.TestCase):
'''Test pasting into widgets that allow pasting.
@@ -16,17 +17,18 @@ class PasteTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.root = root = tk.Tk()
- root.withdraw()
- PyShell.fix_x11_paste(root)
+ cls.root.withdraw()
+ pyshell.fix_x11_paste(root)
cls.text = tk.Text(root)
cls.entry = tk.Entry(root)
+ cls.tentry = ttk.Entry(root)
cls.spin = tk.Spinbox(root)
root.clipboard_clear()
root.clipboard_append('two')
@classmethod
def tearDownClass(cls):
- del cls.text, cls.entry, cls.spin
+ del cls.text, cls.entry, cls.tentry
cls.root.clipboard_clear()
cls.root.update_idletasks()
cls.root.destroy()
@@ -44,16 +46,16 @@ class PasteTest(unittest.TestCase):
def test_paste_entry(self):
"Test pasting into an entry with and without a selection."
- # On 3.6, generated <<Paste>> fails without empty select range
- # for 'no selection'. Live widget works fine.
- entry = self.entry
- for end, ans in (0, 'onetwo'), ('end', 'two'):
- with self.subTest(entry=entry, end=end, ans=ans):
- entry.delete(0, 'end')
- entry.insert(0, 'one')
- entry.select_range(0, end) # see note
- entry.event_generate('<<Paste>>')
- self.assertEqual(entry.get(), ans)
+ # Generated <<Paste>> fails for tk entry without empty select
+ # range for 'no selection'. Live widget works fine.
+ for entry in self.entry, self.tentry:
+ for end, ans in (0, 'onetwo'), ('end', 'two'):
+ with self.subTest(entry=entry, end=end, ans=ans):
+ entry.delete(0, 'end')
+ entry.insert(0, 'one')
+ entry.select_range(0, end)
+ entry.event_generate('<<Paste>>')
+ self.assertEqual(entry.get(), ans)
def test_paste_spin(self):
"Test pasting into a spinbox with and without a selection."
diff --git a/Lib/idlelib/idle_test/test_editor.py b/Lib/idlelib/idle_test/test_editor.py
index a31d26d..e9d29d4 100644
--- a/Lib/idlelib/idle_test/test_editor.py
+++ b/Lib/idlelib/idle_test/test_editor.py
@@ -1,6 +1,6 @@
import unittest
from tkinter import Tk, Text
-from idlelib.EditorWindow import EditorWindow
+from idlelib.editor import EditorWindow
from test.support import requires
class Editor_func_test(unittest.TestCase):
diff --git a/Lib/idlelib/idle_test/test_grep.py b/Lib/idlelib/idle_test/test_grep.py
index 0d8ff0d..6b54c13 100644
--- a/Lib/idlelib/idle_test/test_grep.py
+++ b/Lib/idlelib/idle_test/test_grep.py
@@ -1,5 +1,5 @@
""" !Changing this line will break Test_findfile.test_found!
-Non-gui unit tests for idlelib.GrepDialog methods.
+Non-gui unit tests for grep.GrepDialog methods.
dummy_command calls grep_it calls findfiles.
An exception raised in one method will fail callers.
Otherwise, tests are mostly independent.
@@ -8,7 +8,7 @@ Otherwise, tests are mostly independent.
import unittest
from test.support import captured_stdout
from idlelib.idle_test.mock_tk import Var
-from idlelib.GrepDialog import GrepDialog
+from idlelib.grep import GrepDialog
import re
class Dummy_searchengine:
@@ -72,7 +72,7 @@ class Grep_itTest(unittest.TestCase):
self.assertTrue(lines[4].startswith('(Hint:'))
class Default_commandTest(unittest.TestCase):
- # To write this, mode OutputWindow import to top of GrepDialog
+ # To write this, move outwin import to top of GrepDialog
# so it can be replaced by captured_stdout in class setup/teardown.
pass
diff --git a/Lib/idlelib/idle_test/test_help.py b/Lib/idlelib/idle_test/test_help.py
new file mode 100644
index 0000000..2c68e23
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_help.py
@@ -0,0 +1,34 @@
+'''Test idlelib.help.
+
+Coverage: 87%
+'''
+from idlelib import help
+from test.support import requires
+requires('gui')
+from os.path import abspath, dirname, join
+from tkinter import Tk
+import unittest
+
+class HelpFrameTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ "By itself, this tests that file parsed without exception."
+ cls.root = root = Tk()
+ root.withdraw()
+ helpfile = join(dirname(dirname(abspath(__file__))), 'help.html')
+ cls.frame = help.HelpFrame(root, helpfile)
+
+ @classmethod
+ def tearDownClass(cls):
+ del cls.frame
+ cls.root.update_idletasks()
+ cls.root.destroy()
+ del cls.root
+
+ def test_line1(self):
+ text = self.frame.text
+ self.assertEqual(text.get('1.0', '1.end'), ' IDLE ')
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_help_about.py b/Lib/idlelib/idle_test/test_help_about.py
index d0a0127..843efb9 100644
--- a/Lib/idlelib/idle_test/test_help_about.py
+++ b/Lib/idlelib/idle_test/test_help_about.py
@@ -2,10 +2,10 @@
Coverage:
'''
-from idlelib import aboutDialog as help_about
-from idlelib import textView as textview
+from idlelib import help_about
+from idlelib import textview
from idlelib.idle_test.mock_idle import Func
-from idlelib.idle_test.mock_tk import Mbox
+from idlelib.idle_test.mock_tk import Mbox_func
import unittest
About = help_about.AboutDialog
@@ -19,33 +19,33 @@ class Dummy_about_dialog():
class DisplayFileTest(unittest.TestCase):
- "Test that .txt files are found and properly decoded."
dialog = Dummy_about_dialog()
@classmethod
def setUpClass(cls):
- cls.orig_mbox = textview.tkMessageBox
+ cls.orig_error = textview.showerror
cls.orig_view = textview.view_text
- cls.mbox = Mbox()
+ cls.error = Mbox_func()
cls.view = Func()
- textview.tkMessageBox = cls.mbox
+ textview.showerror = cls.error
textview.view_text = cls.view
cls.About = Dummy_about_dialog()
@classmethod
def tearDownClass(cls):
- textview.tkMessageBox = cls.orig_mbox
+ textview.showerror = cls.orig_error
textview.view_text = cls.orig_view
def test_file_isplay(self):
for handler in (self.dialog.idle_credits,
self.dialog.idle_readme,
self.dialog.idle_news):
- self.mbox.showerror.message = ''
+ self.error.message = ''
self.view.called = False
- handler()
- self.assertEqual(self.mbox.showerror.message, '')
- self.assertEqual(self.view.called, True)
+ with self.subTest(handler=handler):
+ handler()
+ self.assertEqual(self.error.message, '')
+ self.assertEqual(self.view.called, True)
if __name__ == '__main__':
diff --git a/Lib/idlelib/idle_test/test_idlehistory.py b/Lib/idlelib/idle_test/test_history.py
index 6e7c6c3..b278010 100644
--- a/Lib/idlelib/idle_test/test_idlehistory.py
+++ b/Lib/idlelib/idle_test/test_history.py
@@ -4,8 +4,8 @@ from test.support import requires
import tkinter as tk
from tkinter import Text as tkText
from idlelib.idle_test.mock_tk import Text as mkText
-from idlelib.IdleHistory import History
-from idlelib.configHandler import idleConf
+from idlelib.history import History
+from idlelib.config import idleConf
line1 = 'a = 7'
line2 = 'b = a'
diff --git a/Lib/idlelib/idle_test/test_hyperparser.py b/Lib/idlelib/idle_test/test_hyperparser.py
index 9ce3f2c..73c8281 100644
--- a/Lib/idlelib/idle_test/test_hyperparser.py
+++ b/Lib/idlelib/idle_test/test_hyperparser.py
@@ -1,9 +1,9 @@
-"""Unittest for idlelib.HyperParser"""
+"""Unittest for idlelib.hyperparser.py."""
import unittest
from test.support import requires
from tkinter import Tk, Text
-from idlelib.EditorWindow import EditorWindow
-from idlelib.HyperParser import HyperParser
+from idlelib.editor import EditorWindow
+from idlelib.hyperparser import HyperParser
class DummyEditwin:
def __init__(self, text):
diff --git a/Lib/idlelib/idle_test/test_io.py b/Lib/idlelib/idle_test/test_iomenu.py
index e0e3b98..65bf593 100644
--- a/Lib/idlelib/idle_test/test_io.py
+++ b/Lib/idlelib/idle_test/test_iomenu.py
@@ -1,6 +1,7 @@
import unittest
import io
-from idlelib.PyShell import PseudoInputFile, PseudoOutputFile
+
+from idlelib.run import PseudoInputFile, PseudoOutputFile
class S(str):
@@ -230,4 +231,4 @@ class PseudeInputFilesTest(unittest.TestCase):
if __name__ == '__main__':
- unittest.main()
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
new file mode 100644
index 0000000..fae75d8
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -0,0 +1,103 @@
+'''Test idlelib.macosx.py.
+
+Coverage: 71% on Windows.
+'''
+from idlelib import macosx
+from test.support import requires
+import sys
+import tkinter as tk
+import unittest
+import unittest.mock as mock
+from idlelib.filelist import FileList
+
+mactypes = {'carbon', 'cocoa', 'xquartz'}
+nontypes = {'other'}
+alltypes = mactypes | nontypes
+
+
+class InitTktypeTest(unittest.TestCase):
+ "Test _init_tk_type."
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+ cls.root = tk.Tk()
+ cls.root.withdraw()
+ cls.orig_platform = macosx.platform
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.update_idletasks()
+ cls.root.destroy()
+ del cls.root
+ macosx.platform = cls.orig_platform
+
+ def test_init_sets_tktype(self):
+ "Test that _init_tk_type sets _tk_type according to platform."
+ for platform, types in ('darwin', alltypes), ('other', nontypes):
+ with self.subTest(platform=platform):
+ macosx.platform = platform
+ macosx._tk_type == None
+ macosx._init_tk_type()
+ self.assertIn(macosx._tk_type, types)
+
+
+class IsTypeTkTest(unittest.TestCase):
+ "Test each of the four isTypeTk predecates."
+ isfuncs = ((macosx.isAquaTk, ('carbon', 'cocoa')),
+ (macosx.isCarbonTk, ('carbon')),
+ (macosx.isCocoaTk, ('cocoa')),
+ (macosx.isXQuartz, ('xquartz')),
+ )
+
+ @mock.patch('idlelib.macosx._init_tk_type')
+ def test_is_calls_init(self, mockinit):
+ "Test that each isTypeTk calls _init_tk_type when _tk_type is None."
+ macosx._tk_type = None
+ for func, whentrue in self.isfuncs:
+ with self.subTest(func=func):
+ func()
+ self.assertTrue(mockinit.called)
+ mockinit.reset_mock()
+
+ def test_isfuncs(self):
+ "Test that each isTypeTk return correct bool."
+ for func, whentrue in self.isfuncs:
+ for tktype in alltypes:
+ with self.subTest(func=func, whentrue=whentrue, tktype=tktype):
+ macosx._tk_type = tktype
+ (self.assertTrue if tktype in whentrue else self.assertFalse)\
+ (func())
+
+
+class SetupTest(unittest.TestCase):
+ "Test setupApp."
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+ cls.root = tk.Tk()
+ cls.root.withdraw()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.update_idletasks()
+ cls.root.destroy()
+ del cls.root
+
+ @mock.patch('idlelib.macosx.overrideRootMenu') #27312
+ def test_setupapp(self, overrideRootMenu):
+ "Call setupApp with each possible graphics type."
+ root = self.root
+ flist = FileList(root)
+ for tktype in alltypes:
+ with self.subTest(tktype=tktype):
+ macosx._tk_type = tktype
+ macosx.setupApp(root, flist)
+ if tktype in ('carbon', 'cocoa'):
+ self.assertTrue(overrideRootMenu.called)
+ overrideRootMenu.reset_mock()
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_formatparagraph.py b/Lib/idlelib/idle_test/test_paragraph.py
index b6eb2f3..ba350c9 100644
--- a/Lib/idlelib/idle_test/test_formatparagraph.py
+++ b/Lib/idlelib/idle_test/test_paragraph.py
@@ -1,7 +1,7 @@
-# Test the functions and main class method of FormatParagraph.py
+# Test the functions and main class method of paragraph.py
import unittest
-from idlelib import FormatParagraph as fp
-from idlelib.EditorWindow import EditorWindow
+from idlelib import paragraph as fp
+from idlelib.editor import EditorWindow
from tkinter import Tk, Text
from test.support import requires
@@ -38,7 +38,7 @@ class Is_Get_Test(unittest.TestCase):
class FindTest(unittest.TestCase):
- """Test the find_paragraph function in FormatParagraph.
+ """Test the find_paragraph function in paragraph module.
Using the runcase() function, find_paragraph() is called with 'mark' set at
multiple indexes before and inside the test paragraph.
diff --git a/Lib/idlelib/idle_test/test_parenmatch.py b/Lib/idlelib/idle_test/test_parenmatch.py
index 95cc22c..051f7ea 100644
--- a/Lib/idlelib/idle_test/test_parenmatch.py
+++ b/Lib/idlelib/idle_test/test_parenmatch.py
@@ -1,4 +1,4 @@
-'''Test idlelib.ParenMatch.
+'''Test idlelib.parenmatch.
This must currently be a gui test because ParenMatch methods use
several text methods not defined on idlelib.idle_test.mock_tk.Text.
@@ -9,7 +9,7 @@ requires('gui')
import unittest
from unittest.mock import Mock
from tkinter import Tk, Text
-from idlelib.ParenMatch import ParenMatch
+from idlelib.parenmatch import ParenMatch
class DummyEditwin:
def __init__(self, text):
@@ -38,12 +38,17 @@ class ParenMatchTest(unittest.TestCase):
def tearDown(self):
self.text.delete('1.0', 'end')
+ def get_parenmatch(self):
+ pm = ParenMatch(self.editwin)
+ pm.bell = lambda: None
+ return pm
+
def test_paren_expression(self):
"""
Test ParenMatch with 'expression' style.
"""
text = self.text
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
pm.set_style('expression')
text.insert('insert', 'def foobar(a, b')
@@ -66,7 +71,7 @@ class ParenMatchTest(unittest.TestCase):
Test ParenMatch with 'default' style.
"""
text = self.text
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
pm.set_style('default')
text.insert('insert', 'def foobar(a, b')
@@ -86,7 +91,7 @@ class ParenMatchTest(unittest.TestCase):
These cases force conditional expression and alternate paths.
"""
text = self.text
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
text.insert('insert', '# this is a commen)')
self.assertIsNone(pm.paren_closed_event('event'))
@@ -99,7 +104,7 @@ class ParenMatchTest(unittest.TestCase):
self.assertIsNone(pm.paren_closed_event('event'))
def test_handle_restore_timer(self):
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
pm.restore_event = Mock()
pm.handle_restore_timer(0)
self.assertTrue(pm.restore_event.called)
diff --git a/Lib/idlelib/idle_test/test_pathbrowser.py b/Lib/idlelib/idle_test/test_pathbrowser.py
index afb886f..813cbcc 100644
--- a/Lib/idlelib/idle_test/test_pathbrowser.py
+++ b/Lib/idlelib/idle_test/test_pathbrowser.py
@@ -2,13 +2,13 @@ import unittest
import os
import sys
import idlelib
-from idlelib import PathBrowser
+from idlelib import pathbrowser
class PathBrowserTest(unittest.TestCase):
def test_DirBrowserTreeItem(self):
# Issue16226 - make sure that getting a sublist works
- d = PathBrowser.DirBrowserTreeItem('')
+ d = pathbrowser.DirBrowserTreeItem('')
d.GetSubList()
self.assertEqual('', d.GetText())
@@ -17,11 +17,11 @@ class PathBrowserTest(unittest.TestCase):
self.assertEqual(d.ispackagedir(dir + '/Icons'), False)
def test_PathBrowserTreeItem(self):
- p = PathBrowser.PathBrowserTreeItem()
+ p = pathbrowser.PathBrowserTreeItem()
self.assertEqual(p.GetText(), 'sys.path')
sub = p.GetSubList()
self.assertEqual(len(sub), len(sys.path))
- self.assertEqual(type(sub[0]), PathBrowser.DirBrowserTreeItem)
+ self.assertEqual(type(sub[0]), pathbrowser.DirBrowserTreeItem)
if __name__ == '__main__':
unittest.main(verbosity=2, exit=False)
diff --git a/Lib/idlelib/idle_test/test_percolator.py b/Lib/idlelib/idle_test/test_percolator.py
index 4c0a7ad..573b9a1 100644
--- a/Lib/idlelib/idle_test/test_percolator.py
+++ b/Lib/idlelib/idle_test/test_percolator.py
@@ -1,10 +1,10 @@
-'''Test Percolator'''
+'''Test percolator.py.'''
from test.support import requires
requires('gui')
import unittest
from tkinter import Text, Tk, END
-from idlelib.Percolator import Percolator, Delegator
+from idlelib.percolator import Percolator, Delegator
class MyFilter(Delegator):
diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py
new file mode 100644
index 0000000..66af8eb
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_query.py
@@ -0,0 +1,353 @@
+"""Test idlelib.query.
+
+Non-gui tests for Query, SectionName, ModuleName, and HelpSource use
+dummy versions that extract the non-gui methods and add other needed
+attributes. GUI tests create an instance of each class and simulate
+entries and button clicks. Subclass tests only target the new code in
+the subclass definition.
+
+The appearance of the widgets is checked by the Query and
+HelpSource htests. These are run by running query.py.
+
+Coverage: 94% (100% for Query and SectionName).
+6 of 8 missing are ModuleName exceptions I don't know how to trigger.
+"""
+from test.support import requires
+import sys
+from tkinter import Tk
+import unittest
+from unittest import mock
+from idlelib.idle_test.mock_tk import Var
+from idlelib import query
+
+
+# NON-GUI TESTS
+
+class QueryTest(unittest.TestCase):
+ "Test Query base class."
+
+ class Dummy_Query:
+ # Test the following Query methods.
+ entry_ok = query.Query.entry_ok
+ ok = query.Query.ok
+ cancel = query.Query.cancel
+ # Add attributes and initialization needed for tests.
+ entry = Var()
+ entry_error = {}
+ def __init__(self, dummy_entry):
+ self.entry.set(dummy_entry)
+ self.entry_error['text'] = ''
+ self.result = None
+ self.destroyed = False
+ def showerror(self, message):
+ self.entry_error['text'] = message
+ def destroy(self):
+ self.destroyed = True
+
+ def test_entry_ok_blank(self):
+ dialog = self.Dummy_Query(' ')
+ self.assertEqual(dialog.entry_ok(), None)
+ self.assertEqual((dialog.result, dialog.destroyed), (None, False))
+ self.assertIn('blank line', dialog.entry_error['text'])
+
+ def test_entry_ok_good(self):
+ dialog = self.Dummy_Query(' good ')
+ Equal = self.assertEqual
+ Equal(dialog.entry_ok(), 'good')
+ Equal((dialog.result, dialog.destroyed), (None, False))
+ Equal(dialog.entry_error['text'], '')
+
+ def test_ok_blank(self):
+ dialog = self.Dummy_Query('')
+ dialog.entry.focus_set = mock.Mock()
+ self.assertEqual(dialog.ok(), None)
+ self.assertTrue(dialog.entry.focus_set.called)
+ del dialog.entry.focus_set
+ self.assertEqual((dialog.result, dialog.destroyed), (None, False))
+
+ def test_ok_good(self):
+ dialog = self.Dummy_Query('good')
+ self.assertEqual(dialog.ok(), None)
+ self.assertEqual((dialog.result, dialog.destroyed), ('good', True))
+
+ def test_cancel(self):
+ dialog = self.Dummy_Query('does not matter')
+ self.assertEqual(dialog.cancel(), None)
+ self.assertEqual((dialog.result, dialog.destroyed), (None, True))
+
+
+class SectionNameTest(unittest.TestCase):
+ "Test SectionName subclass of Query."
+
+ class Dummy_SectionName:
+ entry_ok = query.SectionName.entry_ok # Function being tested.
+ used_names = ['used']
+ entry = Var()
+ entry_error = {}
+ def __init__(self, dummy_entry):
+ self.entry.set(dummy_entry)
+ self.entry_error['text'] = ''
+ def showerror(self, message):
+ self.entry_error['text'] = message
+
+ def test_blank_section_name(self):
+ dialog = self.Dummy_SectionName(' ')
+ self.assertEqual(dialog.entry_ok(), None)
+ self.assertIn('no name', dialog.entry_error['text'])
+
+ def test_used_section_name(self):
+ dialog = self.Dummy_SectionName('used')
+ self.assertEqual(dialog.entry_ok(), None)
+ self.assertIn('use', dialog.entry_error['text'])
+
+ def test_long_section_name(self):
+ dialog = self.Dummy_SectionName('good'*8)
+ self.assertEqual(dialog.entry_ok(), None)
+ self.assertIn('longer than 30', dialog.entry_error['text'])
+
+ def test_good_section_name(self):
+ dialog = self.Dummy_SectionName(' good ')
+ self.assertEqual(dialog.entry_ok(), 'good')
+ self.assertEqual(dialog.entry_error['text'], '')
+
+
+class ModuleNameTest(unittest.TestCase):
+ "Test ModuleName subclass of Query."
+
+ class Dummy_ModuleName:
+ entry_ok = query.ModuleName.entry_ok # Function being tested.
+ text0 = ''
+ entry = Var()
+ entry_error = {}
+ def __init__(self, dummy_entry):
+ self.entry.set(dummy_entry)
+ self.entry_error['text'] = ''
+ def showerror(self, message):
+ self.entry_error['text'] = message
+
+ def test_blank_module_name(self):
+ dialog = self.Dummy_ModuleName(' ')
+ self.assertEqual(dialog.entry_ok(), None)
+ self.assertIn('no name', dialog.entry_error['text'])
+
+ def test_bogus_module_name(self):
+ dialog = self.Dummy_ModuleName('__name_xyz123_should_not_exist__')
+ self.assertEqual(dialog.entry_ok(), None)
+ self.assertIn('not found', dialog.entry_error['text'])
+
+ def test_c_source_name(self):
+ dialog = self.Dummy_ModuleName('itertools')
+ self.assertEqual(dialog.entry_ok(), None)
+ self.assertIn('source-based', dialog.entry_error['text'])
+
+ def test_good_module_name(self):
+ dialog = self.Dummy_ModuleName('idlelib')
+ self.assertTrue(dialog.entry_ok().endswith('__init__.py'))
+ self.assertEqual(dialog.entry_error['text'], '')
+
+
+# 3 HelpSource test classes each test one function.
+
+orig_platform = query.platform
+
+class HelpsourceBrowsefileTest(unittest.TestCase):
+ "Test browse_file method of ModuleName subclass of Query."
+
+ class Dummy_HelpSource:
+ browse_file = query.HelpSource.browse_file
+ pathvar = Var()
+
+ def test_file_replaces_path(self):
+ dialog = self.Dummy_HelpSource()
+ # Path is widget entry, either '' or something.
+ # Func return is file dialog return, either '' or something.
+ # Func return should override widget entry.
+ # We need all 4 combination to test all (most) code paths.
+ for path, func, result in (
+ ('', lambda a,b,c:'', ''),
+ ('', lambda a,b,c: __file__, __file__),
+ ('htest', lambda a,b,c:'', 'htest'),
+ ('htest', lambda a,b,c: __file__, __file__)):
+ with self.subTest():
+ dialog.pathvar.set(path)
+ dialog.askfilename = func
+ dialog.browse_file()
+ self.assertEqual(dialog.pathvar.get(), result)
+
+
+class HelpsourcePathokTest(unittest.TestCase):
+ "Test path_ok method of HelpSource subclass of Query."
+
+ class Dummy_HelpSource:
+ path_ok = query.HelpSource.path_ok
+ path = Var()
+ path_error = {}
+ def __init__(self, dummy_path):
+ self.path.set(dummy_path)
+ self.path_error['text'] = ''
+ def showerror(self, message, widget=None):
+ self.path_error['text'] = message
+
+ @classmethod
+ def tearDownClass(cls):
+ query.platform = orig_platform
+
+ def test_path_ok_blank(self):
+ dialog = self.Dummy_HelpSource(' ')
+ self.assertEqual(dialog.path_ok(), None)
+ self.assertIn('no help file', dialog.path_error['text'])
+
+ def test_path_ok_bad(self):
+ dialog = self.Dummy_HelpSource(__file__ + 'bad-bad-bad')
+ self.assertEqual(dialog.path_ok(), None)
+ self.assertIn('not exist', dialog.path_error['text'])
+
+ def test_path_ok_web(self):
+ dialog = self.Dummy_HelpSource('')
+ Equal = self.assertEqual
+ for url in 'www.py.org', 'http://py.org':
+ with self.subTest():
+ dialog.path.set(url)
+ self.assertEqual(dialog.path_ok(), url)
+ self.assertEqual(dialog.path_error['text'], '')
+
+ def test_path_ok_file(self):
+ dialog = self.Dummy_HelpSource('')
+ for platform, prefix in ('darwin', 'file://'), ('other', ''):
+ with self.subTest():
+ query.platform = platform
+ dialog.path.set(__file__)
+ self.assertEqual(dialog.path_ok(), prefix + __file__)
+ self.assertEqual(dialog.path_error['text'], '')
+
+
+class HelpsourceEntryokTest(unittest.TestCase):
+ "Test entry_ok method of HelpSource subclass of Query."
+
+ class Dummy_HelpSource:
+ entry_ok = query.HelpSource.entry_ok
+ entry_error = {}
+ path_error = {}
+ def item_ok(self):
+ return self.name
+ def path_ok(self):
+ return self.path
+
+ def test_entry_ok_helpsource(self):
+ dialog = self.Dummy_HelpSource()
+ for name, path, result in ((None, None, None),
+ (None, 'doc.txt', None),
+ ('doc', None, None),
+ ('doc', 'doc.txt', ('doc', 'doc.txt'))):
+ with self.subTest():
+ dialog.name, dialog.path = name, path
+ self.assertEqual(dialog.entry_ok(), result)
+
+
+# GUI TESTS
+
+class QueryGuiTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+ cls.root = root = Tk()
+ cls.root.withdraw()
+ cls.dialog = query.Query(root, 'TEST', 'test', _utest=True)
+ cls.dialog.destroy = mock.Mock()
+
+ @classmethod
+ def tearDownClass(cls):
+ del cls.dialog
+ cls.root.destroy()
+ del cls.root
+
+ def setUp(self):
+ self.dialog.entry.delete(0, 'end')
+ self.dialog.result = None
+ self.dialog.destroy.reset_mock()
+
+ def test_click_ok(self):
+ dialog = self.dialog
+ dialog.entry.insert(0, 'abc')
+ dialog.button_ok.invoke()
+ self.assertEqual(dialog.result, 'abc')
+ self.assertTrue(dialog.destroy.called)
+
+ def test_click_blank(self):
+ dialog = self.dialog
+ dialog.button_ok.invoke()
+ self.assertEqual(dialog.result, None)
+ self.assertFalse(dialog.destroy.called)
+
+ def test_click_cancel(self):
+ dialog = self.dialog
+ dialog.entry.insert(0, 'abc')
+ dialog.button_cancel.invoke()
+ self.assertEqual(dialog.result, None)
+ self.assertTrue(dialog.destroy.called)
+
+
+class SectionnameGuiTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+
+ def test_click_section_name(self):
+ root = Tk()
+ root.withdraw()
+ dialog = query.SectionName(root, 'T', 't', {'abc'}, _utest=True)
+ Equal = self.assertEqual
+ self.assertEqual(dialog.used_names, {'abc'})
+ dialog.entry.insert(0, 'okay')
+ dialog.button_ok.invoke()
+ self.assertEqual(dialog.result, 'okay')
+ del dialog
+ root.destroy()
+ del root
+
+
+class ModulenameGuiTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+
+ def test_click_module_name(self):
+ root = Tk()
+ root.withdraw()
+ dialog = query.ModuleName(root, 'T', 't', 'idlelib', _utest=True)
+ self.assertEqual(dialog.text0, 'idlelib')
+ self.assertEqual(dialog.entry.get(), 'idlelib')
+ dialog.button_ok.invoke()
+ self.assertTrue(dialog.result.endswith('__init__.py'))
+ del dialog
+ root.destroy()
+ del root
+
+
+class HelpsourceGuiTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ requires('gui')
+
+ def test_click_help_source(self):
+ root = Tk()
+ root.withdraw()
+ dialog = query.HelpSource(root, 'T', menuitem='__test__',
+ filepath=__file__, _utest=True)
+ Equal = self.assertEqual
+ Equal(dialog.entry.get(), '__test__')
+ Equal(dialog.path.get(), __file__)
+ dialog.button_ok.invoke()
+ prefix = "file://" if sys.platform == 'darwin' else ''
+ Equal(dialog.result, ('__test__', prefix + __file__))
+ del dialog
+ root.destroy()
+ del root
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2, exit=False)
diff --git a/Lib/idlelib/idle_test/test_widgetredir.py b/Lib/idlelib/idle_test/test_redirector.py
index baa975d..b0385fa 100644
--- a/Lib/idlelib/idle_test/test_widgetredir.py
+++ b/Lib/idlelib/idle_test/test_redirector.py
@@ -1,4 +1,4 @@
-'''Test idlelib.WidgetRedirector.
+'''Test idlelib.redirector.
100% coverage
'''
@@ -6,7 +6,7 @@ from test.support import requires
import unittest
from idlelib.idle_test.mock_idle import Func
from tkinter import Tk, Text, TclError
-from idlelib.WidgetRedirector import WidgetRedirector
+from idlelib.redirector import WidgetRedirector
class InitCloseTest(unittest.TestCase):
@@ -120,6 +120,5 @@ class WidgetRedirectorTest(unittest.TestCase):
self.assertEqual(self.root.call(self.text._w, 'insert', 'boo'), '')
-
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_replacedialog.py b/Lib/idlelib/idle_test/test_replace.py
index ff44820..9913ed2 100644
--- a/Lib/idlelib/idle_test/test_replacedialog.py
+++ b/Lib/idlelib/idle_test/test_replace.py
@@ -1,4 +1,4 @@
-"""Unittest for idlelib.ReplaceDialog"""
+"""Unittest for idlelib.replace.py"""
from test.support import requires
requires('gui')
@@ -6,8 +6,8 @@ import unittest
from unittest.mock import Mock
from tkinter import Tk, Text
from idlelib.idle_test.mock_tk import Mbox
-import idlelib.SearchEngine as se
-import idlelib.ReplaceDialog as rd
+import idlelib.searchengine as se
+from idlelib.replace import ReplaceDialog
orig_mbox = se.tkMessageBox
showerror = Mbox.showerror
@@ -21,7 +21,8 @@ class ReplaceDialogTest(unittest.TestCase):
cls.root.withdraw()
se.tkMessageBox = Mbox
cls.engine = se.SearchEngine(cls.root)
- cls.dialog = rd.ReplaceDialog(cls.root, cls.engine)
+ cls.dialog = ReplaceDialog(cls.root, cls.engine)
+ cls.dialog.bell = lambda: None
cls.dialog.ok = Mock()
cls.text = Text(cls.root)
cls.text.undo_block_start = Mock()
@@ -70,7 +71,6 @@ class ReplaceDialogTest(unittest.TestCase):
# text found and replaced
pv.set('a')
rv.set('asdf')
- self.dialog.open(self.text)
replace()
equal(text.get('1.8', '1.12'), 'asdf')
@@ -91,7 +91,7 @@ class ReplaceDialogTest(unittest.TestCase):
text.mark_set('insert', 'end')
text.insert('insert', '\nline42:')
before_text = text.get('1.0', 'end')
- pv.set('[a-z][\d]+')
+ pv.set(r'[a-z][\d]+')
replace()
after_text = text.get('1.0', 'end')
equal(before_text, after_text)
@@ -192,7 +192,7 @@ class ReplaceDialogTest(unittest.TestCase):
self.engine.revar.set(True)
before_text = text.get('1.0', 'end')
- pv.set('[a-z][\d]+')
+ pv.set(r'[a-z][\d]+')
rv.set('hello')
replace()
after_text = text.get('1.0', 'end')
@@ -207,7 +207,7 @@ class ReplaceDialogTest(unittest.TestCase):
self.assertIn('error', showerror.title)
self.assertIn('Empty', showerror.message)
- pv.set('[\d')
+ pv.set(r'[\d')
replace()
self.assertIn('error', showerror.title)
self.assertIn('Pattern', showerror.message)
diff --git a/Lib/idlelib/idle_test/test_rstrip.py b/Lib/idlelib/idle_test/test_rstrip.py
index 1c90b93..130e6be 100644
--- a/Lib/idlelib/idle_test/test_rstrip.py
+++ b/Lib/idlelib/idle_test/test_rstrip.py
@@ -1,5 +1,5 @@
import unittest
-import idlelib.RstripExtension as rs
+import idlelib.rstrip as rs
from idlelib.idle_test.mock_idle import Editor
class rstripTest(unittest.TestCase):
@@ -21,7 +21,7 @@ class rstripTest(unittest.TestCase):
def test_rstrip_multiple(self):
editor = Editor()
# Uncomment following to verify that test passes with real widgets.
-## from idlelib.EditorWindow import EditorWindow as Editor
+## from idlelib.editor import EditorWindow as Editor
## from tkinter import Tk
## editor = Editor(root=Tk())
text = editor.text
diff --git a/Lib/idlelib/idle_test/test_scrolledlist.py b/Lib/idlelib/idle_test/test_scrolledlist.py
new file mode 100644
index 0000000..56aabfe
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_scrolledlist.py
@@ -0,0 +1,29 @@
+''' Test idlelib.scrolledlist.
+
+Coverage: 39%
+'''
+from idlelib import scrolledlist
+from test.support import requires
+requires('gui')
+import unittest
+from tkinter import Tk
+
+
+class ScrolledListTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.root = Tk()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.destroy()
+ del cls.root
+
+
+ def test_init(self):
+ scrolledlist.ScrolledList(self.root)
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_searchdialog.py b/Lib/idlelib/idle_test/test_search.py
index 190c866..80fa93a 100644
--- a/Lib/idlelib/idle_test/test_searchdialog.py
+++ b/Lib/idlelib/idle_test/test_search.py
@@ -1,4 +1,4 @@
-"""Test SearchDialog class in SearchDialogue.py"""
+"""Test SearchDialog class in idlelib.search.py"""
# Does not currently test the event handler wrappers.
# A usage test should simulate clicks and check hilighting.
@@ -11,8 +11,8 @@ requires('gui')
import unittest
import tkinter as tk
from tkinter import BooleanVar
-import idlelib.SearchEngine as se
-import idlelib.SearchDialog as sd
+import idlelib.searchengine as se
+import idlelib.search as sd
class SearchDialogTest(unittest.TestCase):
@@ -29,6 +29,7 @@ class SearchDialogTest(unittest.TestCase):
def setUp(self):
self.engine = se.SearchEngine(self.root)
self.dialog = sd.SearchDialog(self.root, self.engine)
+ self.dialog.bell = lambda: None
self.text = tk.Text(self.root)
self.text.insert('1.0', 'Hello World!')
@@ -38,6 +39,7 @@ class SearchDialogTest(unittest.TestCase):
self.engine.setpat('')
self.assertFalse(self.dialog.find_again(text))
+ self.dialog.bell = lambda: None
self.engine.setpat('Hello')
self.assertTrue(self.dialog.find_again(text))
diff --git a/Lib/idlelib/idle_test/test_searchdialogbase.py b/Lib/idlelib/idle_test/test_searchbase.py
index 8036b91..d769fa2 100644
--- a/Lib/idlelib/idle_test/test_searchdialogbase.py
+++ b/Lib/idlelib/idle_test/test_searchbase.py
@@ -1,14 +1,13 @@
-'''Unittests for idlelib/SearchDialogBase.py
+'''tests idlelib.searchbase.
Coverage: 99%. The only thing not covered is inconsequential --
testing skipping of suite when self.needwrapbutton is false.
-
'''
import unittest
from test.support import requires
from tkinter import Tk, Toplevel, Frame ##, BooleanVar, StringVar
-from idlelib import SearchEngine as se
-from idlelib import SearchDialogBase as sdb
+from idlelib import searchengine as se
+from idlelib import searchbase as sdb
from idlelib.idle_test.mock_idle import Func
## from idlelib.idle_test.mock_tk import Var
@@ -74,7 +73,7 @@ class SearchDialogBaseTest(unittest.TestCase):
def test_make_entry(self):
equal = self.assertEqual
self.dialog.row = 0
- self.dialog.top = Toplevel(self.root)
+ self.dialog.top = self.root
entry, label = self.dialog.make_entry("Test:", 'hello')
equal(label['text'], 'Test:')
@@ -87,6 +86,7 @@ class SearchDialogBaseTest(unittest.TestCase):
equal(self.dialog.row, 1)
def test_create_entries(self):
+ self.dialog.top = self.root
self.dialog.row = 0
self.engine.setpat('hello')
self.dialog.create_entries()
@@ -94,7 +94,7 @@ class SearchDialogBaseTest(unittest.TestCase):
def test_make_frame(self):
self.dialog.row = 0
- self.dialog.top = Toplevel(self.root)
+ self.dialog.top = self.root
frame, label = self.dialog.make_frame()
self.assertEqual(label, '')
self.assertIsInstance(frame, Frame)
@@ -104,7 +104,7 @@ class SearchDialogBaseTest(unittest.TestCase):
self.assertIsInstance(frame, Frame)
def btn_test_setup(self, meth):
- self.dialog.top = Toplevel(self.root)
+ self.dialog.top = self.root
self.dialog.row = 0
return meth()
@@ -119,11 +119,6 @@ class SearchDialogBaseTest(unittest.TestCase):
var, label = spec
self.assertEqual(button['text'], label)
self.assertEqual(var.get(), state)
- if state == 1:
- button.deselect()
- else:
- button.select()
- self.assertEqual(var.get(), 1 - state)
def test_create_other_buttons(self):
for state in (False, True):
@@ -139,18 +134,15 @@ class SearchDialogBaseTest(unittest.TestCase):
# hit other button, then this one
# indexes depend on button order
self.assertEqual(var.get(), state)
- buttons[val].select()
- self.assertEqual(var.get(), 1 - state)
- buttons[1-val].select()
- self.assertEqual(var.get(), state)
def test_make_button(self):
- self.dialog.top = Toplevel(self.root)
+ self.dialog.top = self.root
self.dialog.buttonframe = Frame(self.dialog.top)
btn = self.dialog.make_button('Test', self.dialog.close)
self.assertEqual(btn['text'], 'Test')
def test_create_command_buttons(self):
+ self.dialog.top = self.root
self.dialog.create_command_buttons()
# Look for close button command in buttonframe
closebuttoncommand = ''
@@ -160,6 +152,5 @@ class SearchDialogBaseTest(unittest.TestCase):
self.assertIn('close', closebuttoncommand)
-
if __name__ == '__main__':
unittest.main(verbosity=2, exit=2)
diff --git a/Lib/idlelib/idle_test/test_searchengine.py b/Lib/idlelib/idle_test/test_searchengine.py
index edbd558..b3aa8eb 100644
--- a/Lib/idlelib/idle_test/test_searchengine.py
+++ b/Lib/idlelib/idle_test/test_searchengine.py
@@ -1,4 +1,4 @@
-'''Test functions and SearchEngine class in SearchEngine.py.'''
+'''Test functions and SearchEngine class in idlelib.searchengine.py.'''
# With mock replacements, the module does not use any gui widgets.
# The use of tk.Text is avoided (for now, until mock Text is improved)
@@ -10,7 +10,7 @@ import unittest
# from test.support import requires
from tkinter import BooleanVar, StringVar, TclError # ,Tk, Text
import tkinter.messagebox as tkMessageBox
-from idlelib import SearchEngine as se
+from idlelib import searchengine as se
from idlelib.idle_test.mock_tk import Var, Mbox
from idlelib.idle_test.mock_tk import Text as mockText
@@ -139,10 +139,10 @@ class SearchEngineTest(unittest.TestCase):
def test_setcookedpat(self):
engine = self.engine
- engine.setcookedpat('\s')
- self.assertEqual(engine.getpat(), '\s')
+ engine.setcookedpat(r'\s')
+ self.assertEqual(engine.getpat(), r'\s')
engine.revar.set(1)
- engine.setcookedpat('\s')
+ engine.setcookedpat(r'\s')
self.assertEqual(engine.getpat(), r'\\s')
def test_getcookedpat(self):
@@ -156,10 +156,10 @@ class SearchEngineTest(unittest.TestCase):
Equal(engine.getcookedpat(), r'\bhello\b')
engine.wordvar.set(False)
- engine.setpat('\s')
+ engine.setpat(r'\s')
Equal(engine.getcookedpat(), r'\\s')
engine.revar.set(True)
- Equal(engine.getcookedpat(), '\s')
+ Equal(engine.getcookedpat(), r'\s')
def test_getprog(self):
engine = self.engine
@@ -282,7 +282,7 @@ class ForwardBackwardTest(unittest.TestCase):
cls.pat = re.compile('target')
cls.res = (2, (10, 16)) # line, slice indexes of 'target'
cls.failpat = re.compile('xyz') # not in text
- cls.emptypat = re.compile('\w*') # empty match possible
+ cls.emptypat = re.compile(r'\w*') # empty match possible
def make_search(self, func):
def search(pat, line, col, wrap, ok=0):
diff --git a/Lib/idlelib/idle_test/test_text.py b/Lib/idlelib/idle_test/test_text.py
index 7e823df..a5ba7bb 100644
--- a/Lib/idlelib/idle_test/test_text.py
+++ b/Lib/idlelib/idle_test/test_text.py
@@ -1,17 +1,19 @@
-# Test mock_tk.Text class against tkinter.Text class by running same tests with both.
+''' Test mock_tk.Text class against tkinter.Text class
+
+Run same tests with both by creating a mixin class.
+'''
import unittest
from test.support import requires
-
from _tkinter import TclError
class TextTest(object):
+ "Define items common to both sets of tests."
- hw = 'hello\nworld' # usual initial insert after initialization
+ hw = 'hello\nworld' # Several tests insert this after after initialization.
hwn = hw+'\n' # \n present at initialization, before insert
- Text = None
- def setUp(self):
- self.text = self.Text()
+ # setUpClass defines cls.Text and maybe cls.root.
+ # setUp defines self.text from Text and maybe root.
def test_init(self):
self.assertEqual(self.text.get('1.0'), '\n')
@@ -196,6 +198,10 @@ class MockTextTest(TextTest, unittest.TestCase):
from idlelib.idle_test.mock_tk import Text
cls.Text = Text
+ def setUp(self):
+ self.text = self.Text()
+
+
def test_decode(self):
# test endflags (-1, 0) not tested by test_index (which uses +1)
decode = self.text._decode
@@ -222,6 +228,9 @@ class TkTextTest(TextTest, unittest.TestCase):
cls.root.destroy()
del cls.root
+ def setUp(self):
+ self.text = self.Text(self.root)
+
if __name__ == '__main__':
unittest.main(verbosity=2, exit=False)
diff --git a/Lib/idlelib/idle_test/test_textview.py b/Lib/idlelib/idle_test/test_textview.py
index 5d2e600..f018f5e 100644
--- a/Lib/idlelib/idle_test/test_textview.py
+++ b/Lib/idlelib/idle_test/test_textview.py
@@ -1,21 +1,21 @@
-'''Test idlelib.textView.
+'''Test idlelib.textview.
Since all methods and functions create (or destroy) a TextViewer, which
is a widget containing multiple widgets, all tests must be gui tests.
Using mock Text would not change this. Other mocks are used to retrieve
information about calls.
-The coverage is essentially 100%.
+Coverage: 94%.
'''
+from idlelib import textview as tv
from test.support import requires
requires('gui')
import unittest
import os
from tkinter import Tk
-from idlelib import textView as tv
from idlelib.idle_test.mock_idle import Func
-from idlelib.idle_test.mock_tk import Mbox
+from idlelib.idle_test.mock_tk import Mbox_func
def setUpModule():
global root
@@ -64,17 +64,17 @@ class TextViewTest(unittest.TestCase):
view.destroy()
-class textviewTest(unittest.TestCase):
+class ViewFunctionTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
- cls.orig_mbox = tv.tkMessageBox
- tv.tkMessageBox = Mbox
+ cls.orig_error = tv.showerror
+ tv.showerror = Mbox_func()
@classmethod
def tearDownClass(cls):
- tv.tkMessageBox = cls.orig_mbox
- del cls.orig_mbox
+ tv.showerror = cls.orig_error
+ del cls.orig_error
def test_view_text(self):
# If modal True, get tk error 'can't invoke "event" command'.
@@ -90,7 +90,7 @@ class textviewTest(unittest.TestCase):
self.assertIn('Test', view.textView.get('1.0', '1.end'))
view.Ok()
- # Mock messagebox will be used and view_file will not return anything
+ # Mock showerror will be used; view_file will return None.
testfile = os.path.join(test_dir, '../notthere.py')
view = tv.view_file(root, 'Title', testfile, modal=False)
self.assertIsNone(view)
diff --git a/Lib/idlelib/idle_test/test_tree.py b/Lib/idlelib/idle_test/test_tree.py
new file mode 100644
index 0000000..09ba964
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_tree.py
@@ -0,0 +1,36 @@
+''' Test idlelib.tree.
+
+Coverage: 56%
+'''
+from idlelib import tree
+from test.support import requires
+requires('gui')
+import os
+import unittest
+from tkinter import Tk
+
+
+class TreeTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.root = Tk()
+ cls.root.withdraw()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.destroy()
+ del cls.root
+
+ def test_init(self):
+ # Start with code slightly adapted from htest.
+ sc = tree.ScrolledCanvas(
+ self.root, bg="white", highlightthickness=0, takefocus=1)
+ sc.frame.pack(expand=1, fill="both", side='left')
+ item = tree.FileTreeItem(tree.ICONDIR)
+ node = tree.TreeNode(sc.canvas, None, item)
+ node.expand()
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_undodelegator.py b/Lib/idlelib/idle_test/test_undo.py
index 2b83c99..e872927 100644
--- a/Lib/idlelib/idle_test/test_undodelegator.py
+++ b/Lib/idlelib/idle_test/test_undo.py
@@ -1,4 +1,4 @@
-"""Unittest for UndoDelegator in idlelib.UndoDelegator.
+"""Unittest for UndoDelegator in idlelib.undo.py.
Coverage about 80% (retest).
"""
@@ -8,8 +8,8 @@ requires('gui')
import unittest
from unittest.mock import Mock
from tkinter import Text, Tk
-from idlelib.UndoDelegator import UndoDelegator
-from idlelib.Percolator import Percolator
+from idlelib.undo import UndoDelegator
+from idlelib.percolator import Percolator
class UndoDelegatorTest(unittest.TestCase):
@@ -29,8 +29,8 @@ class UndoDelegatorTest(unittest.TestCase):
def setUp(self):
self.delegator = UndoDelegator()
+ self.delegator.bell = Mock()
self.percolator.insertfilter(self.delegator)
- self.delegator.bell = Mock(wraps=self.delegator.bell)
def tearDown(self):
self.percolator.removefilter(self.delegator)
diff --git a/Lib/idlelib/idle_test/test_warning.py b/Lib/idlelib/idle_test/test_warning.py
index 18627dd..f3269f1 100644
--- a/Lib/idlelib/idle_test/test_warning.py
+++ b/Lib/idlelib/idle_test/test_warning.py
@@ -1,4 +1,4 @@
-'''Test warnings replacement in PyShell.py and run.py.
+'''Test warnings replacement in pyshell.py and run.py.
This file could be expanded to include traceback overrides
(in same two modules). If so, change name.
@@ -17,9 +17,9 @@ showwarning = warnings.showwarning
running_in_idle = 'idle' in showwarning.__name__
from idlelib import run
-from idlelib import PyShell as shell
+from idlelib import pyshell as shell
-# The following was generated from PyShell.idle_formatwarning
+# The following was generated from pyshell.idle_formatwarning
# and checked as matching expectation.
idlemsg = '''
Warning (from warnings module):
diff --git a/Lib/idlelib/idlever.py b/Lib/idlelib/idlever.py
deleted file mode 100644
index 3e9f69a..0000000
--- a/Lib/idlelib/idlever.py
+++ /dev/null
@@ -1,12 +0,0 @@
-"""
-The separate Idle version was eliminated years ago;
-idlelib.idlever is no longer used by Idle
-and will be removed in 3.6 or later. Use
- from sys import version
- IDLE_VERSION = version[:version.index(' ')]
-"""
-# Kept for now only for possible existing extension use
-import warnings as w
-w.warn(__doc__, DeprecationWarning, stacklevel=2)
-from sys import version
-IDLE_VERSION = version[:version.index(' ')]
diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/iomenu.py
index 84f39a2..3414c7b 100644
--- a/Lib/idlelib/IOBinding.py
+++ b/Lib/idlelib/iomenu.py
@@ -10,57 +10,60 @@ import tkinter.filedialog as tkFileDialog
import tkinter.messagebox as tkMessageBox
from tkinter.simpledialog import askstring
-from idlelib.configHandler import idleConf
+import idlelib
+from idlelib.config import idleConf
-
-# Try setting the locale, so that we can find out
-# what encoding to use
-try:
- import locale
- locale.setlocale(locale.LC_CTYPE, "")
-except (ImportError, locale.Error):
- pass
-
-# Encoding for file names
-filesystemencoding = sys.getfilesystemencoding() ### currently unused
-
-locale_encoding = 'ascii'
-if sys.platform == 'win32':
- # On Windows, we could use "mbcs". However, to give the user
- # a portable encoding name, we need to find the code page
- try:
- locale_encoding = locale.getdefaultlocale()[1]
- codecs.lookup(locale_encoding)
- except LookupError:
- pass
+if idlelib.testing: # Set True by test.test_idle to avoid setlocale.
+ encoding = 'utf-8'
else:
+ # Try setting the locale, so that we can find out
+ # what encoding to use
try:
- # Different things can fail here: the locale module may not be
- # loaded, it may not offer nl_langinfo, or CODESET, or the
- # resulting codeset may be unknown to Python. We ignore all
- # these problems, falling back to ASCII
- locale_encoding = locale.nl_langinfo(locale.CODESET)
- if locale_encoding is None or locale_encoding is '':
- # situation occurs on Mac OS X
- locale_encoding = 'ascii'
- codecs.lookup(locale_encoding)
- except (NameError, AttributeError, LookupError):
- # Try getdefaultlocale: it parses environment variables,
- # which may give a clue. Unfortunately, getdefaultlocale has
- # bugs that can cause ValueError.
+ import locale
+ locale.setlocale(locale.LC_CTYPE, "")
+ except (ImportError, locale.Error):
+ pass
+
+ locale_decode = 'ascii'
+ if sys.platform == 'win32':
+ # On Windows, we could use "mbcs". However, to give the user
+ # a portable encoding name, we need to find the code page
try:
locale_encoding = locale.getdefaultlocale()[1]
+ codecs.lookup(locale_encoding)
+ except LookupError:
+ pass
+ else:
+ try:
+ # Different things can fail here: the locale module may not be
+ # loaded, it may not offer nl_langinfo, or CODESET, or the
+ # resulting codeset may be unknown to Python. We ignore all
+ # these problems, falling back to ASCII
+ locale_encoding = locale.nl_langinfo(locale.CODESET)
if locale_encoding is None or locale_encoding is '':
# situation occurs on Mac OS X
locale_encoding = 'ascii'
codecs.lookup(locale_encoding)
- except (ValueError, LookupError):
- pass
+ except (NameError, AttributeError, LookupError):
+ # Try getdefaultlocale: it parses environment variables,
+ # which may give a clue. Unfortunately, getdefaultlocale has
+ # bugs that can cause ValueError.
+ try:
+ locale_encoding = locale.getdefaultlocale()[1]
+ if locale_encoding is None or locale_encoding is '':
+ # situation occurs on Mac OS X
+ locale_encoding = 'ascii'
+ codecs.lookup(locale_encoding)
+ except (ValueError, LookupError):
+ pass
-locale_encoding = locale_encoding.lower()
+ locale_encoding = locale_encoding.lower()
-encoding = locale_encoding ### KBK 07Sep07 This is used all over IDLE, check!
- ### 'encoding' is used below in encode(), check!
+ encoding = locale_encoding
+ # Encoding is used in multiple files; locale_encoding nowhere.
+ # The only use of 'encoding' below is in _decode as initial value
+ # of deprecated block asking user for encoding.
+ # Perhaps use elsewhere should be reviewed.
coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII)
@@ -107,6 +110,9 @@ def coding_spec(data):
class IOBinding:
+# One instance per editor Window so methods know which to save, close.
+# Open returns focus to self.editwin if aborted.
+# EditorWindow.open_module, others, belong here.
def __init__(self, editwin):
self.editwin = editwin
@@ -301,7 +307,7 @@ class IOBinding:
"The file's encoding is invalid for Python 3.x.\n"
"IDLE will convert it to UTF-8.\n"
"What is the current encoding of the file?",
- initialvalue = locale_encoding,
+ initialvalue = encoding,
parent = self.editwin.text)
if enc:
@@ -529,8 +535,8 @@ def _io_binding(parent): # htest #
root = Toplevel(parent)
root.title("Test IOBinding")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ root.geometry("+%d+%d" % (x, y + 175))
class MyEditWin:
def __init__(self, text):
self.text = text
@@ -561,5 +567,8 @@ def _io_binding(parent): # htest #
IOBinding(editwin)
if __name__ == "__main__":
+ import unittest
+ unittest.main('idlelib.idle_test.test_iomenu', verbosity=2, exit=False)
+
from idlelib.idle_test.htest import run
run(_io_binding)
diff --git a/Lib/idlelib/macosxSupport.py b/Lib/idlelib/macosx.py
index b96bae1..c225dd9 100644
--- a/Lib/idlelib/macosxSupport.py
+++ b/Lib/idlelib/macosx.py
@@ -1,30 +1,25 @@
"""
A number of functions that enhance IDLE on Mac OSX.
"""
-import sys
-import tkinter
-from os import path
+from sys import platform # Used in _init_tk_type, changed by test.
import warnings
-def runningAsOSXApp():
- warnings.warn("runningAsOSXApp() is deprecated, use isAquaTk()",
- DeprecationWarning, stacklevel=2)
- return isAquaTk()
+import tkinter
+
-def isCarbonAquaTk(root):
- warnings.warn("isCarbonAquaTk(root) is deprecated, use isCarbonTk()",
- DeprecationWarning, stacklevel=2)
- return isCarbonTk()
+## Define functions that query the Mac graphics type.
+## _tk_type and its initializer are private to this section.
_tk_type = None
-def _initializeTkVariantTests(root):
+def _init_tk_type():
"""
Initializes OS X Tk variant values for
isAquaTk(), isCarbonTk(), isCocoaTk(), and isXQuartz().
"""
global _tk_type
- if sys.platform == 'darwin':
+ if platform == 'darwin':
+ root = tkinter.Tk()
ws = root.tk.call('tk', 'windowingsystem')
if 'x11' in ws:
_tk_type = "xquartz"
@@ -34,6 +29,7 @@ def _initializeTkVariantTests(root):
_tk_type = "cocoa"
else:
_tk_type = "carbon"
+ root.destroy()
else:
_tk_type = "other"
@@ -41,7 +37,8 @@ def isAquaTk():
"""
Returns True if IDLE is using a native OS X Tk (Cocoa or Carbon).
"""
- assert _tk_type is not None
+ if not _tk_type:
+ _init_tk_type()
return _tk_type == "cocoa" or _tk_type == "carbon"
def isCarbonTk():
@@ -49,23 +46,27 @@ def isCarbonTk():
Returns True if IDLE is using a Carbon Aqua Tk (instead of the
newer Cocoa Aqua Tk).
"""
- assert _tk_type is not None
+ if not _tk_type:
+ _init_tk_type()
return _tk_type == "carbon"
def isCocoaTk():
"""
Returns True if IDLE is using a Cocoa Aqua Tk.
"""
- assert _tk_type is not None
+ if not _tk_type:
+ _init_tk_type()
return _tk_type == "cocoa"
def isXQuartz():
"""
Returns True if IDLE is using an OS X X11 Tk.
"""
- assert _tk_type is not None
+ if not _tk_type:
+ _init_tk_type()
return _tk_type == "xquartz"
+
def tkVersionWarning(root):
"""
Returns a string warning message if the Tk version in use appears to
@@ -86,6 +87,9 @@ def tkVersionWarning(root):
else:
return False
+
+## Fix the menu and related functions.
+
def addOpenEventSupport(root, flist):
"""
This ensures that the application will respond to open AppleEvents, which
@@ -124,23 +128,23 @@ def overrideRootMenu(root, flist):
# Due to a (mis-)feature of TkAqua the user will also see an empty Help
# menu.
from tkinter import Menu
- from idlelib import Bindings
- from idlelib import WindowList
+ from idlelib import mainmenu
+ from idlelib import windows
- closeItem = Bindings.menudefs[0][1][-2]
+ closeItem = mainmenu.menudefs[0][1][-2]
# Remove the last 3 items of the file menu: a separator, close window and
# quit. Close window will be reinserted just above the save item, where
# it should be according to the HIG. Quit is in the application menu.
- del Bindings.menudefs[0][1][-3:]
- Bindings.menudefs[0][1].insert(6, closeItem)
+ del mainmenu.menudefs[0][1][-3:]
+ mainmenu.menudefs[0][1].insert(6, closeItem)
# Remove the 'About' entry from the help menu, it is in the application
# menu
- del Bindings.menudefs[-1][1][0:2]
+ del mainmenu.menudefs[-1][1][0:2]
# Remove the 'Configure Idle' entry from the options menu, it is in the
# application menu as 'Preferences'
- del Bindings.menudefs[-2][1][0]
+ del mainmenu.menudefs[-2][1][0]
menubar = Menu(root)
root.configure(menu=menubar)
menudict = {}
@@ -155,30 +159,30 @@ def overrideRootMenu(root, flist):
if end > 0:
menu.delete(0, end)
- WindowList.add_windows_to_menu(menu)
- WindowList.register_callback(postwindowsmenu)
+ windows.add_windows_to_menu(menu)
+ windows.register_callback(postwindowsmenu)
def about_dialog(event=None):
"Handle Help 'About IDLE' event."
- # Synchronize with EditorWindow.EditorWindow.about_dialog.
- from idlelib import aboutDialog
- aboutDialog.AboutDialog(root, 'About IDLE')
+ # Synchronize with editor.EditorWindow.about_dialog.
+ from idlelib import help_about
+ help_about.AboutDialog(root, 'About IDLE')
def config_dialog(event=None):
"Handle Options 'Configure IDLE' event."
- # Synchronize with EditorWindow.EditorWindow.config_dialog.
- from idlelib import configDialog
+ # Synchronize with editor.EditorWindow.config_dialog.
+ from idlelib import configdialog
# Ensure that the root object has an instance_dict attribute,
# mirrors code in EditorWindow (although that sets the attribute
# on an EditorWindow instance that is then passed as the first
# argument to ConfigDialog)
root.instance_dict = flist.inversedict
- configDialog.ConfigDialog(root, 'Settings')
+ configdialog.ConfigDialog(root, 'Settings')
def help_dialog(event=None):
"Handle Help 'IDLE Help' event."
- # Synchronize with EditorWindow.EditorWindow.help_dialog.
+ # Synchronize with editor.EditorWindow.help_dialog.
from idlelib import help
help.show_idlehelp(root)
@@ -198,29 +202,33 @@ def overrideRootMenu(root, flist):
menudict['application'] = menu = Menu(menubar, name='apple',
tearoff=0)
menubar.add_cascade(label='IDLE', menu=menu)
- Bindings.menudefs.insert(0,
+ mainmenu.menudefs.insert(0,
('application', [
('About IDLE', '<<about-idle>>'),
None,
]))
- tkversion = root.tk.eval('info patchlevel')
- if tuple(map(int, tkversion.split('.'))) < (8, 4, 14):
- # for earlier AquaTk versions, supply a Preferences menu item
- Bindings.menudefs[0][1].append(
- ('_Preferences....', '<<open-config-dialog>>'),
- )
if isCocoaTk():
# replace default About dialog with About IDLE one
root.createcommand('tkAboutDialog', about_dialog)
# replace default "Help" item in Help menu
root.createcommand('::tk::mac::ShowHelp', help_dialog)
# remove redundant "IDLE Help" from menu
- del Bindings.menudefs[-1][1][0]
+ del mainmenu.menudefs[-1][1][0]
+
+def fixb2context(root):
+ '''Removed bad AquaTk Button-2 (right) and Paste bindings.
+
+ They prevent context menu access and seem to be gone in AquaTk8.6.
+ See issue #24801.
+ '''
+ root.unbind_class('Text', '<B2>')
+ root.unbind_class('Text', '<B2-Motion>')
+ root.unbind_class('Text', '<<PasteSelection>>')
def setupApp(root, flist):
"""
Perform initial OS X customizations if needed.
- Called from PyShell.main() after initial calls to Tk()
+ Called from pyshell.main() after initial calls to Tk()
There are currently three major versions of Tk in use on OS X:
1. Aqua Cocoa Tk (native default since OS X 10.6)
@@ -233,8 +241,13 @@ def setupApp(root, flist):
isAquaTk(), isCarbonTk(), isCocoaTk(), isXQuartz() functions which
are initialized here as well.
"""
- _initializeTkVariantTests(root)
if isAquaTk():
hideTkConsole(root)
overrideRootMenu(root, flist)
addOpenEventSupport(root, flist)
+ fixb2context(root)
+
+
+if __name__ == '__main__':
+ from unittest import main
+ main('idlelib.idle_test.test_macosx', verbosity=2)
diff --git a/Lib/idlelib/Bindings.py b/Lib/idlelib/mainmenu.py
index e19a279..65345cd 100644
--- a/Lib/idlelib/Bindings.py
+++ b/Lib/idlelib/mainmenu.py
@@ -10,9 +10,9 @@ windows.
"""
from importlib.util import find_spec
-from idlelib.configHandler import idleConf
+from idlelib.config import idleConf
-# Warning: menudefs is altered in macosxSupport.overrideRootMenu()
+# Warning: menudefs is altered in macosx.overrideRootMenu()
# after it is determined that an OS X Aqua Tk is in use,
# which cannot be done until after Tk() is first called.
# Do not alter the 'file', 'options', or 'help' cascades here
diff --git a/Lib/idlelib/MultiCall.py b/Lib/idlelib/multicall.py
index 8462854..b74fed4 100644
--- a/Lib/idlelib/MultiCall.py
+++ b/Lib/idlelib/multicall.py
@@ -28,9 +28,9 @@ The order by which events are called is defined by these rules:
unless this conflicts with the first rule.
Each function will be called at most once for each event.
"""
-
-import sys
import re
+import sys
+
import tkinter
# the event type constants, which define the meaning of mc_type
@@ -414,12 +414,12 @@ def MultiCallCreator(widget):
return MultiCall
-def _multi_call(parent):
- root = tkinter.Tk()
- root.title("Test MultiCall")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
- text = MultiCallCreator(tkinter.Text)(root)
+def _multi_call(parent): # htest #
+ top = tkinter.Toplevel(parent)
+ top.title("Test MultiCall")
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x, y + 175))
+ text = MultiCallCreator(tkinter.Text)(top)
text.pack()
def bindseq(seq, n=[0]):
def handler(event):
@@ -439,7 +439,6 @@ def _multi_call(parent):
bindseq("<FocusOut>")
bindseq("<Enter>")
bindseq("<Leave>")
- root.mainloop()
if __name__ == "__main__":
from idlelib.idle_test.htest import run
diff --git a/Lib/idlelib/OutputWindow.py b/Lib/idlelib/outwin.py
index e614f9b..f6d2915 100644
--- a/Lib/idlelib/OutputWindow.py
+++ b/Lib/idlelib/outwin.py
@@ -1,8 +1,11 @@
-from tkinter import *
-from idlelib.EditorWindow import EditorWindow
import re
+
+from tkinter import *
import tkinter.messagebox as tkMessageBox
-from idlelib import IOBinding
+
+from idlelib.editor import EditorWindow
+from idlelib import iomenu
+
class OutputWindow(EditorWindow):
@@ -36,7 +39,7 @@ class OutputWindow(EditorWindow):
def write(self, s, tags=(), mark="insert"):
if isinstance(s, (bytes, bytes)):
- s = s.decode(IOBinding.encoding, "replace")
+ s = s.decode(iomenu.encoding, "replace")
self.text.insert(mark, s, tags)
self.text.see(mark)
self.text.update()
diff --git a/Lib/idlelib/FormatParagraph.py b/Lib/idlelib/paragraph.py
index 7a9d185..f11bdae 100644
--- a/Lib/idlelib/FormatParagraph.py
+++ b/Lib/idlelib/paragraph.py
@@ -14,9 +14,10 @@ Known problems with comment reformatting:
spaces, they will not be considered part of the same block.
* Fancy comments, like this bulleted list, aren't handled :-)
"""
-
import re
-from idlelib.configHandler import idleConf
+
+from idlelib.config import idleConf
+
class FormatParagraph:
@@ -129,7 +130,7 @@ def reformat_paragraph(data, limit):
partial = indent1
while i < n and not is_all_white(lines[i]):
# XXX Should take double space after period (etc.) into account
- words = re.split("(\s+)", lines[i])
+ words = re.split(r"(\s+)", lines[i])
for j in range(0, len(words), 2):
word = words[j]
if not word:
@@ -189,7 +190,8 @@ def get_comment_header(line):
if m is None: return ""
return m.group(1)
+
if __name__ == "__main__":
import unittest
- unittest.main('idlelib.idle_test.test_formatparagraph',
+ unittest.main('idlelib.idle_test.test_paragraph',
verbosity=2, exit=False)
diff --git a/Lib/idlelib/ParenMatch.py b/Lib/idlelib/parenmatch.py
index 47e10f3..ccec708 100644
--- a/Lib/idlelib/ParenMatch.py
+++ b/Lib/idlelib/parenmatch.py
@@ -4,9 +4,8 @@ When you hit a right paren, the cursor should move briefly to the left
paren. Paren here is used generically; the matching applies to
parentheses, square brackets, and curly braces.
"""
-
-from idlelib.HyperParser import HyperParser
-from idlelib.configHandler import idleConf
+from idlelib.hyperparser import HyperParser
+from idlelib.config import idleConf
_openers = {')':'(',']':'[','}':'{'}
CHECK_DELAY = 100 # milliseconds
@@ -64,6 +63,7 @@ class ParenMatch:
# and deactivate_restore (which calls event_delete).
editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
self.restore_event)
+ self.bell = self.text.bell if self.BELL else lambda: None
self.counter = 0
self.is_restore_active = 0
self.set_style(self.STYLE)
@@ -93,7 +93,7 @@ class ParenMatch:
indices = (HyperParser(self.editwin, "insert")
.get_surrounding_brackets())
if indices is None:
- self.warn_mismatched()
+ self.bell()
return
self.activate_restore()
self.create_tag(indices)
@@ -109,7 +109,7 @@ class ParenMatch:
return
indices = hp.get_surrounding_brackets(_openers[closer], True)
if indices is None:
- self.warn_mismatched()
+ self.bell()
return
self.activate_restore()
self.create_tag(indices)
@@ -124,10 +124,6 @@ class ParenMatch:
if timer_count == self.counter:
self.restore_event()
- def warn_mismatched(self):
- if self.BELL:
- self.text.bell()
-
# any one of the create_tag_XXX methods can be used depending on
# the style
diff --git a/Lib/idlelib/PathBrowser.py b/Lib/idlelib/pathbrowser.py
index 9ab7632..6c19508 100644
--- a/Lib/idlelib/PathBrowser.py
+++ b/Lib/idlelib/pathbrowser.py
@@ -1,10 +1,10 @@
+import importlib.machinery
import os
import sys
-import importlib.machinery
-from idlelib.TreeWidget import TreeItem
-from idlelib.ClassBrowser import ClassBrowser, ModuleBrowserTreeItem
-from idlelib.PyShell import PyShellFileList
+from idlelib.browser import ClassBrowser, ModuleBrowserTreeItem
+from idlelib.pyshell import PyShellFileList
+from idlelib.tree import TreeItem
class PathBrowser(ClassBrowser):
@@ -24,6 +24,7 @@ class PathBrowser(ClassBrowser):
def rootnode(self):
return PathBrowserTreeItem()
+
class PathBrowserTreeItem(TreeItem):
def GetText(self):
@@ -36,6 +37,7 @@ class PathBrowserTreeItem(TreeItem):
sublist.append(item)
return sublist
+
class DirBrowserTreeItem(TreeItem):
def __init__(self, dir, packages=[]):
@@ -95,6 +97,7 @@ class DirBrowserTreeItem(TreeItem):
sorted.sort()
return sorted
+
def _path_browser(parent): # htest #
flist = PyShellFileList(parent)
PathBrowser(flist, _htest=True)
diff --git a/Lib/idlelib/Percolator.py b/Lib/idlelib/percolator.py
index b8be2aa..d18daf0 100644
--- a/Lib/idlelib/Percolator.py
+++ b/Lib/idlelib/percolator.py
@@ -1,5 +1,5 @@
-from idlelib.WidgetRedirector import WidgetRedirector
-from idlelib.Delegator import Delegator
+from idlelib.delegator import Delegator
+from idlelib.redirector import WidgetRedirector
class Percolator:
@@ -57,7 +57,6 @@ class Percolator:
def _percolator(parent): # htest #
import tkinter as tk
- import re
class Tracer(Delegator):
def __init__(self, name):
@@ -74,8 +73,8 @@ def _percolator(parent): # htest #
box = tk.Toplevel(parent)
box.title("Test Percolator")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- box.geometry("+%d+%d" % (x, y + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ box.geometry("+%d+%d" % (x, y + 175))
text = tk.Text(box)
p = Percolator(text)
pin = p.insertfilter
@@ -89,10 +88,10 @@ def _percolator(parent): # htest #
(pin if var2.get() else pout)(t2)
text.pack()
- var1 = tk.IntVar()
+ var1 = tk.IntVar(parent)
cb1 = tk.Checkbutton(box, text="Tracer1", command=toggle1, variable=var1)
cb1.pack()
- var2 = tk.IntVar()
+ var2 = tk.IntVar(parent)
cb2 = tk.Checkbutton(box, text="Tracer2", command=toggle2, variable=var2)
cb2.pack()
diff --git a/Lib/idlelib/PyParse.py b/Lib/idlelib/pyparse.py
index 9ccbb25..6739dfd 100644
--- a/Lib/idlelib/PyParse.py
+++ b/Lib/idlelib/pyparse.py
@@ -1,6 +1,6 @@
+from collections import Mapping
import re
import sys
-from collections import Mapping
# Reason last stmt is continued (or C_NONE if it's not).
(C_NONE, C_BACKSLASH, C_STRING_FIRST_LINE,
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/pyshell.py
index 5dec68e..e1eade1 100755
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/pyshell.py
@@ -1,8 +1,27 @@
#! /usr/bin/env python3
+try:
+ from tkinter import *
+except ImportError:
+ print("** IDLE can't import Tkinter.\n"
+ "Your Python may not be configured for Tk. **", file=sys.__stderr__)
+ sys.exit(1)
+import tkinter.messagebox as tkMessageBox
+if TkVersion < 8.5:
+ root = Tk() # otherwise create root in main
+ root.withdraw()
+ tkMessageBox.showerror("Idle Cannot Start",
+ "Idle requires tcl/tk 8.5+, not $s." % TkVersion,
+ parent=root)
+ sys.exit(1)
+
+from code import InteractiveInterpreter
import getopt
+import io
+import linecache
import os
import os.path
+from platform import python_version, system
import re
import socket
import subprocess
@@ -10,30 +29,20 @@ import sys
import threading
import time
import tokenize
-import io
-
-import linecache
-from code import InteractiveInterpreter
-from platform import python_version, system
-
-try:
- from tkinter import *
-except ImportError:
- print("** IDLE can't import Tkinter.\n"
- "Your Python may not be configured for Tk. **", file=sys.__stderr__)
- sys.exit(1)
-import tkinter.messagebox as tkMessageBox
+import warnings
-from idlelib.EditorWindow import EditorWindow, fixwordbreaks
-from idlelib.FileList import FileList
-from idlelib.ColorDelegator import ColorDelegator
-from idlelib.UndoDelegator import UndoDelegator
-from idlelib.OutputWindow import OutputWindow
-from idlelib.configHandler import idleConf
+from idlelib import testing # bool value
+from idlelib.colorizer import ColorDelegator
+from idlelib.config import idleConf
+from idlelib import debugger
+from idlelib import debugger_r
+from idlelib.editor import EditorWindow, fixwordbreaks
+from idlelib.filelist import FileList
+from idlelib import macosx
+from idlelib.outwin import OutputWindow
from idlelib import rpc
-from idlelib import Debugger
-from idlelib import RemoteDebugger
-from idlelib import macosxSupport
+from idlelib.run import idle_formatwarning, PseudoInputFile, PseudoOutputFile
+from idlelib.undo import UndoDelegator
HOST = '127.0.0.1' # python execution server on localhost loopback
PORT = 0 # someday pass in host, port for remote debug capability
@@ -43,20 +52,6 @@ PORT = 0 # someday pass in host, port for remote debug capability
# temporarily redirect the stream to the shell window to display warnings when
# checking user's code.
warning_stream = sys.__stderr__ # None, at least on Windows, if no console.
-import warnings
-
-def idle_formatwarning(message, category, filename, lineno, line=None):
- """Format warnings the IDLE way."""
-
- s = "\nWarning (from warnings module):\n"
- s += ' File \"%s\", line %s\n' % (filename, lineno)
- if line is None:
- line = linecache.getline(filename, lineno)
- line = line.strip()
- if line:
- s += " %s\n" % line
- s += "%s: %s\n" % (category.__name__, message)
- return s
def idle_showwarning(
message, category, filename, lineno, file=None, line=None):
@@ -410,7 +405,7 @@ class ModifiedInterpreter(InteractiveInterpreter):
# run from the IDLE source directory.
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
default=False, type='bool')
- if __name__ == 'idlelib.PyShell':
+ if __name__ == 'idlelib.pyshell':
command = "__import__('idlelib.run').run.main(%r)" % (del_exitf,)
else:
command = "__import__('run').main(%r)" % (del_exitf,)
@@ -468,7 +463,7 @@ class ModifiedInterpreter(InteractiveInterpreter):
if debug:
try:
# Only close subprocess debugger, don't unregister gui_adap!
- RemoteDebugger.close_subprocess_debugger(self.rpcclt)
+ debugger_r.close_subprocess_debugger(self.rpcclt)
except:
pass
# Kill subprocess, spawn a new one, accept connection.
@@ -497,7 +492,7 @@ class ModifiedInterpreter(InteractiveInterpreter):
# restart subprocess debugger
if debug:
# Restarted debugger connects to current instance of debug GUI
- RemoteDebugger.restart_subprocess_debugger(self.rpcclt)
+ debugger_r.restart_subprocess_debugger(self.rpcclt)
# reload remote debugger breakpoints for all PyShellEditWindows
debug.load_breakpoints()
self.compile.compiler.flags = self.original_compiler_flags
@@ -578,7 +573,7 @@ class ModifiedInterpreter(InteractiveInterpreter):
if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
self.remote_stack_viewer()
elif how == "ERROR":
- errmsg = "PyShell.ModifiedInterpreter: Subprocess ERROR:\n"
+ errmsg = "pyshell.ModifiedInterpreter: Subprocess ERROR:\n"
print(errmsg, what, file=sys.__stderr__)
print(errmsg, what, file=console)
# we received a response to the currently active seq number:
@@ -613,13 +608,13 @@ class ModifiedInterpreter(InteractiveInterpreter):
return
def remote_stack_viewer(self):
- from idlelib import RemoteObjectBrowser
+ from idlelib import debugobj_r
oid = self.rpcclt.remotequeue("exec", "stackviewer", ("flist",), {})
if oid is None:
self.tkconsole.root.bell()
return
- item = RemoteObjectBrowser.StubObjectTreeItem(self.rpcclt, oid)
- from idlelib.TreeWidget import ScrolledCanvas, TreeNode
+ item = debugobj_r.StubObjectTreeItem(self.rpcclt, oid)
+ from idlelib.tree import ScrolledCanvas, TreeNode
top = Toplevel(self.tkconsole.root)
theme = idleConf.CurrentTheme()
background = idleConf.GetHighlight(theme, 'normal')['background']
@@ -662,9 +657,9 @@ class ModifiedInterpreter(InteractiveInterpreter):
# at the moment, InteractiveInterpreter expects str
assert isinstance(source, str)
#if isinstance(source, str):
- # from idlelib import IOBinding
+ # from idlelib import iomenu
# try:
- # source = source.encode(IOBinding.encoding)
+ # source = source.encode(iomenu.encoding)
# except UnicodeError:
# self.tkconsole.resetoutput()
# self.write("Unsupported characters in input\n")
@@ -850,7 +845,7 @@ class PyShell(OutputWindow):
# New classes
- from idlelib.IdleHistory import History
+ from idlelib.history import History
def __init__(self, flist=None):
if use_subprocess:
@@ -888,11 +883,11 @@ class PyShell(OutputWindow):
self.save_stdout = sys.stdout
self.save_stderr = sys.stderr
self.save_stdin = sys.stdin
- from idlelib import IOBinding
- self.stdin = PseudoInputFile(self, "stdin", IOBinding.encoding)
- self.stdout = PseudoOutputFile(self, "stdout", IOBinding.encoding)
- self.stderr = PseudoOutputFile(self, "stderr", IOBinding.encoding)
- self.console = PseudoOutputFile(self, "console", IOBinding.encoding)
+ from idlelib import iomenu
+ self.stdin = PseudoInputFile(self, "stdin", iomenu.encoding)
+ self.stdout = PseudoOutputFile(self, "stdout", iomenu.encoding)
+ self.stderr = PseudoOutputFile(self, "stderr", iomenu.encoding)
+ self.console = PseudoOutputFile(self, "console", iomenu.encoding)
if not use_subprocess:
sys.stdout = self.stdout
sys.stderr = self.stderr
@@ -900,7 +895,7 @@ class PyShell(OutputWindow):
try:
# page help() text to shell.
import pydoc # import must be done here to capture i/o rebinding.
- # XXX KBK 27Dec07 use a textView someday, but must work w/o subproc
+ # XXX KBK 27Dec07 use TextViewer someday, but must work w/o subproc
pydoc.pager = pydoc.plainpager
except:
sys.stderr = sys.__stderr__
@@ -954,7 +949,7 @@ class PyShell(OutputWindow):
self.interp.setdebugger(None)
db.close()
if self.interp.rpcclt:
- RemoteDebugger.close_remote_debugger(self.interp.rpcclt)
+ debugger_r.close_remote_debugger(self.interp.rpcclt)
self.resetoutput()
self.console.write("[DEBUG OFF]\n")
sys.ps1 = ">>> "
@@ -963,10 +958,10 @@ class PyShell(OutputWindow):
def open_debugger(self):
if self.interp.rpcclt:
- dbg_gui = RemoteDebugger.start_remote_debugger(self.interp.rpcclt,
+ dbg_gui = debugger_r.start_remote_debugger(self.interp.rpcclt,
self)
else:
- dbg_gui = Debugger.Debugger(self)
+ dbg_gui = debugger.Debugger(self)
self.interp.setdebugger(dbg_gui)
dbg_gui.load_breakpoints()
sys.ps1 = "[DEBUG ON]\n>>> "
@@ -1241,7 +1236,7 @@ class PyShell(OutputWindow):
"(sys.last_traceback is not defined)",
parent=self.text)
return
- from idlelib.StackViewer import StackBrowser
+ from idlelib.stackviewer import StackBrowser
StackBrowser(self.root, self.flist)
def view_restart_mark(self, event=None):
@@ -1309,92 +1304,6 @@ class PyShell(OutputWindow):
return 'disabled'
return super().rmenu_check_paste()
-class PseudoFile(io.TextIOBase):
-
- def __init__(self, shell, tags, encoding=None):
- self.shell = shell
- self.tags = tags
- self._encoding = encoding
-
- @property
- def encoding(self):
- return self._encoding
-
- @property
- def name(self):
- return '<%s>' % self.tags
-
- def isatty(self):
- return True
-
-
-class PseudoOutputFile(PseudoFile):
-
- def writable(self):
- return True
-
- def write(self, s):
- if self.closed:
- raise ValueError("write to closed file")
- if type(s) is not str:
- if not isinstance(s, str):
- raise TypeError('must be str, not ' + type(s).__name__)
- # See issue #19481
- s = str.__str__(s)
- return self.shell.write(s, self.tags)
-
-
-class PseudoInputFile(PseudoFile):
-
- def __init__(self, shell, tags, encoding=None):
- PseudoFile.__init__(self, shell, tags, encoding)
- self._line_buffer = ''
-
- def readable(self):
- return True
-
- def read(self, size=-1):
- if self.closed:
- raise ValueError("read from closed file")
- if size is None:
- size = -1
- elif not isinstance(size, int):
- raise TypeError('must be int, not ' + type(size).__name__)
- result = self._line_buffer
- self._line_buffer = ''
- if size < 0:
- while True:
- line = self.shell.readline()
- if not line: break
- result += line
- else:
- while len(result) < size:
- line = self.shell.readline()
- if not line: break
- result += line
- self._line_buffer = result[size:]
- result = result[:size]
- return result
-
- def readline(self, size=-1):
- if self.closed:
- raise ValueError("read from closed file")
- if size is None:
- size = -1
- elif not isinstance(size, int):
- raise TypeError('must be int, not ' + type(size).__name__)
- line = self._line_buffer or self.shell.readline()
- if size < 0:
- size = len(line)
- eol = line.find('\n', 0, size)
- if eol >= 0:
- size = eol + 1
- self._line_buffer = line[size:]
- return line[:size]
-
- def close(self):
- self.shell.close()
-
def fix_x11_paste(root):
"Make paste replace selection on x11. See issue #5124."
@@ -1540,7 +1449,10 @@ def main():
enable_edit = enable_edit or edit_start
enable_shell = enable_shell or not enable_edit
- # start editor and/or shell windows:
+ # Setup root. Don't break user code run in IDLE process.
+ # Don't change environment when testing.
+ if use_subprocess and not testing:
+ NoDefaultRoot()
root = Tk(className="Idle")
root.withdraw()
@@ -1549,25 +1461,19 @@ def main():
if system() == 'Windows':
iconfile = os.path.join(icondir, 'idle.ico')
root.wm_iconbitmap(default=iconfile)
- elif TkVersion >= 8.5:
+ else:
ext = '.png' if TkVersion >= 8.6 else '.gif'
iconfiles = [os.path.join(icondir, 'idle_%d%s' % (size, ext))
for size in (16, 32, 48)]
- icons = [PhotoImage(file=iconfile) for iconfile in iconfiles]
+ icons = [PhotoImage(master=root, file=iconfile)
+ for iconfile in iconfiles]
root.wm_iconphoto(True, *icons)
+ # start editor and/or shell windows:
fixwordbreaks(root)
fix_x11_paste(root)
flist = PyShellFileList(root)
- macosxSupport.setupApp(root, flist)
-
- if macosxSupport.isAquaTk():
- # There are some screwed up <2> class bindings for text
- # widgets defined in Tk which we need to do away with.
- # See issue #24801.
- root.unbind_class('Text', '<B2>')
- root.unbind_class('Text', '<B2-Motion>')
- root.unbind_class('Text', '<<PasteSelection>>')
+ macosx.setupApp(root, flist)
if enable_edit:
if not (cmd or script):
@@ -1582,7 +1488,7 @@ def main():
shell = flist.open_shell()
if not shell:
return # couldn't open shell
- if macosxSupport.isAquaTk() and flist.dict:
+ if macosx.isAquaTk() and flist.dict:
# On OSX: when the user has double-clicked on a file that causes
# IDLE to be launched the shell window will open just in front of
# the file she wants to see. Lower the interpreter window when
@@ -1616,7 +1522,7 @@ def main():
# check for problematic OS X Tk versions and print a warning
# message in the IDLE shell window; this is less intrusive
# than always opening a separate window.
- tkversionwarning = macosxSupport.tkVersionWarning(root)
+ tkversionwarning = macosx.tkVersionWarning(root)
if tkversionwarning:
shell.interp.runcommand("print('%s')" % tkversionwarning)
@@ -1626,7 +1532,7 @@ def main():
capture_warnings(False)
if __name__ == "__main__":
- sys.modules['PyShell'] = sys.modules['__main__']
+ sys.modules['pyshell'] = sys.modules['__main__']
main()
capture_warnings(False) # Make sure turned off; see issue 18081
diff --git a/Lib/idlelib/query.py b/Lib/idlelib/query.py
new file mode 100644
index 0000000..3b1f1e2
--- /dev/null
+++ b/Lib/idlelib/query.py
@@ -0,0 +1,308 @@
+"""
+Dialogs that query users and verify the answer before accepting.
+Use ttk widgets, limiting use to tcl/tk 8.5+, as in IDLE 3.6+.
+
+Query is the generic base class for a popup dialog.
+The user must either enter a valid answer or close the dialog.
+Entries are validated when <Return> is entered or [Ok] is clicked.
+Entries are ignored when [Cancel] or [X] are clicked.
+The 'return value' is .result set to either a valid answer or None.
+
+Subclass SectionName gets a name for a new config file section.
+Configdialog uses it for new highlight theme and keybinding set names.
+Subclass ModuleName gets a name for File => Open Module.
+Subclass HelpSource gets menu item and path for additions to Help menu.
+"""
+# Query and Section name result from splitting GetCfgSectionNameDialog
+# of configSectionNameDialog.py (temporarily config_sec.py) into
+# generic and specific parts. 3.6 only, July 2016.
+# ModuleName.entry_ok came from editor.EditorWindow.load_module.
+# HelpSource was extracted from configHelpSourceEdit.py (temporarily
+# config_help.py), with darwin code moved from ok to path_ok.
+
+import importlib
+import os
+from sys import executable, platform # Platform is set for one test.
+
+from tkinter import Toplevel, StringVar, W, E, N, S
+from tkinter.ttk import Frame, Button, Entry, Label
+from tkinter import filedialog
+from tkinter.font import Font
+
+class Query(Toplevel):
+ """Base class for getting verified answer from a user.
+
+ For this base class, accept any non-blank string.
+ """
+ def __init__(self, parent, title, message, *, text0='', used_names={},
+ _htest=False, _utest=False):
+ """Create popup, do not return until tk widget destroyed.
+
+ Additional subclass init must be done before calling this
+ unless _utest=True is passed to suppress wait_window().
+
+ title - string, title of popup dialog
+ message - string, informational message to display
+ text0 - initial value for entry
+ used_names - names already in use
+ _htest - bool, change box location when running htest
+ _utest - bool, leave window hidden and not modal
+ """
+ Toplevel.__init__(self, parent)
+ self.withdraw() # Hide while configuring, especially geometry.
+ self.parent = parent
+ self.title(title)
+ self.message = message
+ self.text0 = text0
+ self.used_names = used_names
+ self.transient(parent)
+ self.grab_set()
+ windowingsystem = self.tk.call('tk', 'windowingsystem')
+ if windowingsystem == 'aqua':
+ try:
+ self.tk.call('::tk::unsupported::MacWindowStyle', 'style',
+ self._w, 'moveableModal', '')
+ except:
+ pass
+ self.bind("<Command-.>", self.cancel)
+ self.bind('<Key-Escape>', self.cancel)
+ self.protocol("WM_DELETE_WINDOW", self.cancel)
+ self.bind('<Key-Return>', self.ok)
+ self.bind("<KP_Enter>", self.ok)
+ self.resizable(height=False, width=False)
+ self.create_widgets()
+ self.update_idletasks() # Needed here for winfo_reqwidth below.
+ self.geometry( # Center dialog over parent (or below htest box).
+ "+%d+%d" % (
+ parent.winfo_rootx() +
+ (parent.winfo_width()/2 - self.winfo_reqwidth()/2),
+ parent.winfo_rooty() +
+ ((parent.winfo_height()/2 - self.winfo_reqheight()/2)
+ if not _htest else 150)
+ ) )
+ if not _utest:
+ self.deiconify() # Unhide now that geometry set.
+ self.wait_window()
+
+ def create_widgets(self): # Call from override, if any.
+ # Bind to self widgets needed for entry_ok or unittest.
+ self.frame = frame = Frame(self, padding=10)
+ frame.grid(column=0, row=0, sticky='news')
+ frame.grid_columnconfigure(0, weight=1)
+
+ entrylabel = Label(frame, anchor='w', justify='left',
+ text=self.message)
+ self.entryvar = StringVar(self, self.text0)
+ self.entry = Entry(frame, width=30, textvariable=self.entryvar)
+ self.entry.focus_set()
+ self.error_font = Font(name='TkCaptionFont',
+ exists=True, root=self.parent)
+ self.entry_error = Label(frame, text=' ', foreground='red',
+ font=self.error_font)
+ self.button_ok = Button(
+ frame, text='OK', default='active', command=self.ok)
+ self.button_cancel = Button(
+ frame, text='Cancel', command=self.cancel)
+
+ entrylabel.grid(column=0, row=0, columnspan=3, padx=5, sticky=W)
+ self.entry.grid(column=0, row=1, columnspan=3, padx=5, sticky=W+E,
+ pady=[10,0])
+ self.entry_error.grid(column=0, row=2, columnspan=3, padx=5,
+ sticky=W+E)
+ self.button_ok.grid(column=1, row=99, padx=5)
+ self.button_cancel.grid(column=2, row=99, padx=5)
+
+ def showerror(self, message, widget=None):
+ #self.bell(displayof=self)
+ (widget or self.entry_error)['text'] = 'ERROR: ' + message
+
+ def entry_ok(self): # Example: usually replace.
+ "Return non-blank entry or None."
+ self.entry_error['text'] = ''
+ entry = self.entry.get().strip()
+ if not entry:
+ self.showerror('blank line.')
+ return None
+ return entry
+
+ def ok(self, event=None): # Do not replace.
+ '''If entry is valid, bind it to 'result' and destroy tk widget.
+
+ Otherwise leave dialog open for user to correct entry or cancel.
+ '''
+ entry = self.entry_ok()
+ if entry is not None:
+ self.result = entry
+ self.destroy()
+ else:
+ # [Ok] moves focus. (<Return> does not.) Move it back.
+ self.entry.focus_set()
+
+ def cancel(self, event=None): # Do not replace.
+ "Set dialog result to None and destroy tk widget."
+ self.result = None
+ self.destroy()
+
+
+class SectionName(Query):
+ "Get a name for a config file section name."
+ # Used in ConfigDialog.GetNewKeysName, .GetNewThemeName (837)
+
+ def __init__(self, parent, title, message, used_names,
+ *, _htest=False, _utest=False):
+ super().__init__(parent, title, message, used_names=used_names,
+ _htest=_htest, _utest=_utest)
+
+ def entry_ok(self):
+ "Return sensible ConfigParser section name or None."
+ self.entry_error['text'] = ''
+ name = self.entry.get().strip()
+ if not name:
+ self.showerror('no name specified.')
+ return None
+ elif len(name)>30:
+ self.showerror('name is longer than 30 characters.')
+ return None
+ elif name in self.used_names:
+ self.showerror('name is already in use.')
+ return None
+ return name
+
+
+class ModuleName(Query):
+ "Get a module name for Open Module menu entry."
+ # Used in open_module (editor.EditorWindow until move to iobinding).
+
+ def __init__(self, parent, title, message, text0,
+ *, _htest=False, _utest=False):
+ super().__init__(parent, title, message, text0=text0,
+ _htest=_htest, _utest=_utest)
+
+ def entry_ok(self):
+ "Return entered module name as file path or None."
+ self.entry_error['text'] = ''
+ name = self.entry.get().strip()
+ if not name:
+ self.showerror('no name specified.')
+ return None
+ # XXX Ought to insert current file's directory in front of path.
+ try:
+ spec = importlib.util.find_spec(name)
+ except (ValueError, ImportError) as msg:
+ self.showerror(str(msg))
+ return None
+ if spec is None:
+ self.showerror("module not found")
+ return None
+ if not isinstance(spec.loader, importlib.abc.SourceLoader):
+ self.showerror("not a source-based module")
+ return None
+ try:
+ file_path = spec.loader.get_filename(name)
+ except AttributeError:
+ self.showerror("loader does not support get_filename",
+ parent=self)
+ return None
+ return file_path
+
+
+class HelpSource(Query):
+ "Get menu name and help source for Help menu."
+ # Used in ConfigDialog.HelpListItemAdd/Edit, (941/9)
+
+ def __init__(self, parent, title, *, menuitem='', filepath='',
+ used_names={}, _htest=False, _utest=False):
+ """Get menu entry and url/local file for Additional Help.
+
+ User enters a name for the Help resource and a web url or file
+ name. The user can browse for the file.
+ """
+ self.filepath = filepath
+ message = 'Name for item on Help menu:'
+ super().__init__(
+ parent, title, message, text0=menuitem,
+ used_names=used_names, _htest=_htest, _utest=_utest)
+
+ def create_widgets(self):
+ super().create_widgets()
+ frame = self.frame
+ pathlabel = Label(frame, anchor='w', justify='left',
+ text='Help File Path: Enter URL or browse for file')
+ self.pathvar = StringVar(self, self.filepath)
+ self.path = Entry(frame, textvariable=self.pathvar, width=40)
+ browse = Button(frame, text='Browse', width=8,
+ command=self.browse_file)
+ self.path_error = Label(frame, text=' ', foreground='red',
+ font=self.error_font)
+
+ pathlabel.grid(column=0, row=10, columnspan=3, padx=5, pady=[10,0],
+ sticky=W)
+ self.path.grid(column=0, row=11, columnspan=2, padx=5, sticky=W+E,
+ pady=[10,0])
+ browse.grid(column=2, row=11, padx=5, sticky=W+S)
+ self.path_error.grid(column=0, row=12, columnspan=3, padx=5,
+ sticky=W+E)
+
+ def askfilename(self, filetypes, initdir, initfile): # htest #
+ # Extracted from browse_file so can mock for unittests.
+ # Cannot unittest as cannot simulate button clicks.
+ # Test by running htest, such as by running this file.
+ return filedialog.Open(parent=self, filetypes=filetypes)\
+ .show(initialdir=initdir, initialfile=initfile)
+
+ def browse_file(self):
+ filetypes = [
+ ("HTML Files", "*.htm *.html", "TEXT"),
+ ("PDF Files", "*.pdf", "TEXT"),
+ ("Windows Help Files", "*.chm"),
+ ("Text Files", "*.txt", "TEXT"),
+ ("All Files", "*")]
+ path = self.pathvar.get()
+ if path:
+ dir, base = os.path.split(path)
+ else:
+ base = None
+ if platform[:3] == 'win':
+ dir = os.path.join(os.path.dirname(executable), 'Doc')
+ if not os.path.isdir(dir):
+ dir = os.getcwd()
+ else:
+ dir = os.getcwd()
+ file = self.askfilename(filetypes, dir, base)
+ if file:
+ self.pathvar.set(file)
+
+ item_ok = SectionName.entry_ok # localize for test override
+
+ def path_ok(self):
+ "Simple validity check for menu file path"
+ path = self.path.get().strip()
+ if not path: #no path specified
+ self.showerror('no help file path specified.', self.path_error)
+ return None
+ elif not path.startswith(('www.', 'http')):
+ if path[:5] == 'file:':
+ path = path[5:]
+ if not os.path.exists(path):
+ self.showerror('help file path does not exist.',
+ self.path_error)
+ return None
+ if platform == 'darwin': # for Mac Safari
+ path = "file://" + path
+ return path
+
+ def entry_ok(self):
+ "Return apparently valid (name, path) or None"
+ self.entry_error['text'] = ''
+ self.path_error['text'] = ''
+ name = self.item_ok()
+ path = self.path_ok()
+ return None if name is None or path is None else (name, path)
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main('idlelib.idle_test.test_query', verbosity=2, exit=False)
+
+ from idlelib.idle_test.htest import run
+ run(Query, HelpSource)
diff --git a/Lib/idlelib/WidgetRedirector.py b/Lib/idlelib/redirector.py
index b66be9e..ec681de 100644
--- a/Lib/idlelib/WidgetRedirector.py
+++ b/Lib/idlelib/redirector.py
@@ -104,7 +104,7 @@ class WidgetRedirector:
Note that if a registered function is called, the operation is not
passed through to Tk. Apply the function returned by self.register()
- to *args to accomplish that. For an example, see ColorDelegator.py.
+ to *args to accomplish that. For an example, see colorizer.py.
'''
m = self._operations.get(operation)
@@ -151,14 +151,13 @@ class OriginalCommand:
def _widget_redirector(parent): # htest #
- from tkinter import Tk, Text
- import re
-
- root = Tk()
- root.title("Test WidgetRedirector")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
- text = Text(root)
+ from tkinter import Toplevel, Text
+
+ top = Toplevel(parent)
+ top.title("Test WidgetRedirector")
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x, y + 175))
+ text = Text(top)
text.pack()
text.focus_set()
redir = WidgetRedirector(text)
@@ -166,11 +165,11 @@ def _widget_redirector(parent): # htest #
print("insert", args)
original_insert(*args)
original_insert = redir.register("insert", my_insert)
- root.mainloop()
if __name__ == "__main__":
import unittest
- unittest.main('idlelib.idle_test.test_widgetredir',
+ unittest.main('idlelib.idle_test.test_redirector',
verbosity=2, exit=False)
+
from idlelib.idle_test.htest import run
run(_widget_redirector)
diff --git a/Lib/idlelib/ReplaceDialog.py b/Lib/idlelib/replace.py
index f2ea22e..abd9e59 100644
--- a/Lib/idlelib/ReplaceDialog.py
+++ b/Lib/idlelib/replace.py
@@ -3,18 +3,18 @@ Uses idlelib.SearchEngine for search capability.
Defines various replace related functions like replace, replace all,
replace+find.
"""
-from tkinter import *
-
-from idlelib import SearchEngine
-from idlelib.SearchDialogBase import SearchDialogBase
import re
+from tkinter import StringVar, TclError
+
+from idlelib.searchbase import SearchDialogBase
+from idlelib import searchengine
def replace(text):
"""Returns a singleton ReplaceDialog instance.The single dialog
saves user entries and preferences across instances."""
root = text._root()
- engine = SearchEngine.get(root)
+ engine = searchengine.get(root)
if not hasattr(engine, "_replacedialog"):
engine._replacedialog = ReplaceDialog(root, engine)
dialog = engine._replacedialog
@@ -95,7 +95,7 @@ class ReplaceDialog(SearchDialogBase):
text = self.text
res = self.engine.search_text(text, prog)
if not res:
- text.bell()
+ self.bell()
return
text.tag_remove("sel", "1.0", "end")
text.tag_remove("hit", "1.0", "end")
@@ -142,7 +142,7 @@ class ReplaceDialog(SearchDialogBase):
text = self.text
res = self.engine.search_text(text, None, ok)
if not res:
- text.bell()
+ self.bell()
return False
line, m = res
i, j = m.span()
@@ -164,7 +164,7 @@ class ReplaceDialog(SearchDialogBase):
pos = None
if not pos:
first = last = pos = text.index("insert")
- line, col = SearchEngine.get_line_col(pos)
+ line, col = searchengine.get_line_col(pos)
chars = text.get("%d.0" % line, "%d.0" % (line+1))
m = prog.match(chars, col)
if not prog:
@@ -204,11 +204,13 @@ class ReplaceDialog(SearchDialogBase):
def _replace_dialog(parent): # htest #
- """htest wrapper function"""
+ from tkinter import Toplevel, Text, END, SEL
+ from tkinter.ttk import Button
+
box = Toplevel(parent)
box.title("Test ReplaceDialog")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- box.geometry("+%d+%d"%(x, y + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ box.geometry("+%d+%d" % (x, y + 175))
# mock undo delegator methods
def undo_block_start():
@@ -234,7 +236,7 @@ def _replace_dialog(parent): # htest #
if __name__ == '__main__':
import unittest
- unittest.main('idlelib.idle_test.test_replacedialog',
+ unittest.main('idlelib.idle_test.test_replace',
verbosity=2, exit=False)
from idlelib.idle_test.htest import run
diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py
index 48105f2..8f57edb8 100644
--- a/Lib/idlelib/rpc.py
+++ b/Lib/idlelib/rpc.py
@@ -26,23 +26,21 @@ See the Idle run.main() docstring for further information on how this was
accomplished in Idle.
"""
-
-import sys
-import os
+import builtins
+import copyreg
import io
-import socket
+import marshal
+import os
+import pickle
+import queue
import select
+import socket
import socketserver
import struct
-import pickle
+import sys
import threading
-import queue
import traceback
-import copyreg
import types
-import marshal
-import builtins
-
def unpickle_code(ms):
co = marshal.loads(ms)
@@ -60,10 +58,12 @@ def dumps(obj, protocol=None):
p.dump(obj)
return f.getvalue()
+
class CodePickler(pickle.Pickler):
dispatch_table = {types.CodeType: pickle_code}
dispatch_table.update(copyreg.dispatch_table)
+
BUFSIZE = 8*1024
LOCALHOST = '127.0.0.1'
@@ -487,16 +487,19 @@ class RemoteObject(object):
# Token mix-in class
pass
+
def remoteref(obj):
oid = id(obj)
objecttable[oid] = obj
return RemoteProxy(oid)
+
class RemoteProxy(object):
def __init__(self, oid):
self.oid = oid
+
class RPCHandler(socketserver.BaseRequestHandler, SocketIO):
debugging = False
@@ -514,6 +517,7 @@ class RPCHandler(socketserver.BaseRequestHandler, SocketIO):
def get_remote_proxy(self, oid):
return RPCProxy(self, oid)
+
class RPCClient(SocketIO):
debugging = False
@@ -539,6 +543,7 @@ class RPCClient(SocketIO):
def get_remote_proxy(self, oid):
return RPCProxy(self, oid)
+
class RPCProxy(object):
__methods = None
@@ -587,6 +592,7 @@ def _getattributes(obj, attributes):
if not callable(attr):
attributes[name] = 1
+
class MethodProxy(object):
def __init__(self, sockio, oid, name):
diff --git a/Lib/idlelib/RstripExtension.py b/Lib/idlelib/rstrip.py
index 2ce3c7e..2ce3c7e 100644
--- a/Lib/idlelib/RstripExtension.py
+++ b/Lib/idlelib/rstrip.py
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 28ce420..afa9744 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -1,33 +1,45 @@
-import sys
+import io
import linecache
+import queue
+import sys
import time
import traceback
import _thread as thread
import threading
-import queue
-import tkinter
-
-from idlelib import CallTips
-from idlelib import AutoComplete
+import warnings
-from idlelib import RemoteDebugger
-from idlelib import RemoteObjectBrowser
-from idlelib import StackViewer
-from idlelib import rpc
-from idlelib import PyShell
-from idlelib import IOBinding
+import tkinter # Tcl, deletions, messagebox if startup fails
+from idlelib import autocomplete # AutoComplete, fetch_encodings
+from idlelib import calltips # CallTips
+from idlelib import debugger_r # start_debugger
+from idlelib import debugobj_r # remote_object_tree_item
+from idlelib import iomenu # encoding
+from idlelib import rpc # multiple objects
+from idlelib import stackviewer # StackTreeItem
import __main__
for mod in ('simpledialog', 'messagebox', 'font',
'dialog', 'filedialog', 'commondialog',
- 'colorchooser'):
+ 'ttk'):
delattr(tkinter, mod)
del sys.modules['tkinter.' + mod]
LOCALHOST = '127.0.0.1'
-import warnings
+
+def idle_formatwarning(message, category, filename, lineno, line=None):
+ """Format warnings the IDLE way."""
+
+ s = "\nWarning (from warnings module):\n"
+ s += ' File \"%s\", line %s\n' % (filename, lineno)
+ if line is None:
+ line = linecache.getline(filename, lineno)
+ line = line.strip()
+ if line:
+ s += " %s\n" % line
+ s += "%s: %s\n" % (category.__name__, message)
+ return s
def idle_showwarning_subproc(
message, category, filename, lineno, file=None, line=None):
@@ -38,7 +50,7 @@ def idle_showwarning_subproc(
if file is None:
file = sys.stderr
try:
- file.write(PyShell.idle_formatwarning(
+ file.write(idle_formatwarning(
message, category, filename, lineno, line))
except IOError:
pass # the file (probably stderr) is invalid - this warning gets lost.
@@ -88,7 +100,7 @@ def main(del_exitfunc=False):
MyHandler object. That reference is saved as attribute rpchandler of the
Executive instance. The Executive methods have access to the reference and
can pass it on to entities that they command
- (e.g. RemoteDebugger.Debugger.start_debugger()). The latter, in turn, can
+ (e.g. debugger_r.Debugger.start_debugger()). The latter, in turn, can
call MyHandler(SocketIO) register/unregister methods via the reference to
register and unregister themselves.
@@ -210,7 +222,7 @@ def print_exception():
tbe = traceback.extract_tb(tb)
print('Traceback (most recent call last):', file=efile)
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
- "RemoteDebugger.py", "bdb.py")
+ "debugger_r.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = traceback.format_exception_only(typ, exc)
@@ -267,6 +279,7 @@ def exit():
capture_warnings(False)
sys.exit(0)
+
class MyRPCServer(rpc.RPCServer):
def handle_error(self, request, client_address):
@@ -297,6 +310,96 @@ class MyRPCServer(rpc.RPCServer):
quitting = True
thread.interrupt_main()
+
+# Pseudofiles for shell-remote communication (also used in pyshell)
+
+class PseudoFile(io.TextIOBase):
+
+ def __init__(self, shell, tags, encoding=None):
+ self.shell = shell
+ self.tags = tags
+ self._encoding = encoding
+
+ @property
+ def encoding(self):
+ return self._encoding
+
+ @property
+ def name(self):
+ return '<%s>' % self.tags
+
+ def isatty(self):
+ return True
+
+
+class PseudoOutputFile(PseudoFile):
+
+ def writable(self):
+ return True
+
+ def write(self, s):
+ if self.closed:
+ raise ValueError("write to closed file")
+ if type(s) is not str:
+ if not isinstance(s, str):
+ raise TypeError('must be str, not ' + type(s).__name__)
+ # See issue #19481
+ s = str.__str__(s)
+ return self.shell.write(s, self.tags)
+
+
+class PseudoInputFile(PseudoFile):
+
+ def __init__(self, shell, tags, encoding=None):
+ PseudoFile.__init__(self, shell, tags, encoding)
+ self._line_buffer = ''
+
+ def readable(self):
+ return True
+
+ def read(self, size=-1):
+ if self.closed:
+ raise ValueError("read from closed file")
+ if size is None:
+ size = -1
+ elif not isinstance(size, int):
+ raise TypeError('must be int, not ' + type(size).__name__)
+ result = self._line_buffer
+ self._line_buffer = ''
+ if size < 0:
+ while True:
+ line = self.shell.readline()
+ if not line: break
+ result += line
+ else:
+ while len(result) < size:
+ line = self.shell.readline()
+ if not line: break
+ result += line
+ self._line_buffer = result[size:]
+ result = result[:size]
+ return result
+
+ def readline(self, size=-1):
+ if self.closed:
+ raise ValueError("read from closed file")
+ if size is None:
+ size = -1
+ elif not isinstance(size, int):
+ raise TypeError('must be int, not ' + type(size).__name__)
+ line = self._line_buffer or self.shell.readline()
+ if size < 0:
+ size = len(line)
+ eol = line.find('\n', 0, size)
+ if eol >= 0:
+ size = eol + 1
+ self._line_buffer = line[size:]
+ return line[:size]
+
+ def close(self):
+ self.shell.close()
+
+
class MyHandler(rpc.RPCHandler):
def handle(self):
@@ -304,12 +407,12 @@ class MyHandler(rpc.RPCHandler):
executive = Executive(self)
self.register("exec", executive)
self.console = self.get_remote_proxy("console")
- sys.stdin = PyShell.PseudoInputFile(self.console, "stdin",
- IOBinding.encoding)
- sys.stdout = PyShell.PseudoOutputFile(self.console, "stdout",
- IOBinding.encoding)
- sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr",
- IOBinding.encoding)
+ sys.stdin = PseudoInputFile(self.console, "stdin",
+ iomenu.encoding)
+ sys.stdout = PseudoOutputFile(self.console, "stdout",
+ iomenu.encoding)
+ sys.stderr = PseudoOutputFile(self.console, "stderr",
+ iomenu.encoding)
sys.displayhook = rpc.displayhook
# page help() text to shell.
@@ -345,8 +448,8 @@ class Executive(object):
def __init__(self, rpchandler):
self.rpchandler = rpchandler
self.locals = __main__.__dict__
- self.calltip = CallTips.CallTips()
- self.autocomplete = AutoComplete.AutoComplete()
+ self.calltip = calltips.CallTips()
+ self.autocomplete = autocomplete.AutoComplete()
def runcode(self, code):
global interruptable
@@ -378,7 +481,7 @@ class Executive(object):
thread.interrupt_main()
def start_the_debugger(self, gui_adap_oid):
- return RemoteDebugger.start_debugger(self.rpchandler, gui_adap_oid)
+ return debugger_r.start_debugger(self.rpchandler, gui_adap_oid)
def stop_the_debugger(self, idb_adap_oid):
"Unregister the Idb Adapter. Link objects and Idb then subject to GC"
@@ -402,7 +505,7 @@ class Executive(object):
tb = tb.tb_next
sys.last_type = typ
sys.last_value = val
- item = StackViewer.StackTreeItem(flist, tb)
- return RemoteObjectBrowser.remote_object_tree_item(item)
+ item = stackviewer.StackTreeItem(flist, tb)
+ return debugobj_r.remote_object_tree_item(item)
capture_warnings(False) # Make sure turned off; see issue 18081
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/runscript.py
index 5cb818d..79d86ad 100644
--- a/Lib/idlelib/ScriptBinding.py
+++ b/Lib/idlelib/runscript.py
@@ -20,11 +20,12 @@ XXX GvR Redesign this interface (yet again) as follows:
import os
import tabnanny
import tokenize
+
import tkinter.messagebox as tkMessageBox
-from idlelib import PyShell
-from idlelib.configHandler import idleConf
-from idlelib import macosxSupport
+from idlelib.config import idleConf
+from idlelib import macosx
+from idlelib import pyshell
indent_message = """Error: Inconsistent indentation detected!
@@ -46,12 +47,12 @@ class ScriptBinding:
def __init__(self, editwin):
self.editwin = editwin
- # Provide instance variables referenced by Debugger
+ # Provide instance variables referenced by debugger
# XXX This should be done differently
self.flist = self.editwin.flist
self.root = self.editwin.root
- if macosxSupport.isCocoaTk():
+ if macosx.isCocoaTk():
self.editwin.text_frame.bind('<<run-module-event-2>>', self._run_module_event)
def check_module_event(self, event):
@@ -112,7 +113,7 @@ class ScriptBinding:
shell.set_warning_stream(saved_stream)
def run_module_event(self, event):
- if macosxSupport.isCocoaTk():
+ if macosx.isCocoaTk():
# Tk-Cocoa in MacOSX is broken until at least
# Tk 8.5.9, and without this rather
# crude workaround IDLE would hang when a user
@@ -142,7 +143,7 @@ class ScriptBinding:
if not self.tabnanny(filename):
return 'break'
interp = self.shell.interp
- if PyShell.use_subprocess:
+ if pyshell.use_subprocess:
interp.restart_subprocess(with_cwd=False, filename=
self.editwin._filename_to_unicode(filename))
dirname = os.path.dirname(filename)
@@ -161,7 +162,7 @@ class ScriptBinding:
interp.prepend_syspath(filename)
# XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
# go to __stderr__. With subprocess, they go to the shell.
- # Need to change streams in PyShell.ModifiedInterpreter.
+ # Need to change streams in pyshell.ModifiedInterpreter.
interp.runcode(code)
return 'break'
diff --git a/Lib/idlelib/ScrolledList.py b/Lib/idlelib/scrolledlist.py
index 53576b5..cc08c26 100644
--- a/Lib/idlelib/ScrolledList.py
+++ b/Lib/idlelib/scrolledlist.py
@@ -1,5 +1,8 @@
from tkinter import *
-from idlelib import macosxSupport
+from tkinter.ttk import Scrollbar
+
+from idlelib import macosx
+
class ScrolledList:
@@ -23,7 +26,7 @@ class ScrolledList:
# Bind events to the list box
listbox.bind("<ButtonRelease-1>", self.click_event)
listbox.bind("<Double-ButtonRelease-1>", self.double_click_event)
- if macosxSupport.isAquaTk():
+ if macosx.isAquaTk():
listbox.bind("<ButtonPress-2>", self.popup_event)
listbox.bind("<Control-Button-1>", self.popup_event)
else:
@@ -124,22 +127,20 @@ class ScrolledList:
pass
-def _scrolled_list(parent):
- root = Tk()
- root.title("Test ScrolledList")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
+def _scrolled_list(parent): # htest #
+ top = Toplevel(parent)
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x+200, y + 175))
class MyScrolledList(ScrolledList):
def fill_menu(self): self.menu.add_command(label="right click")
def on_select(self, index): print("select", self.get(index))
def on_double(self, index): print("double", self.get(index))
- scrolled_list = MyScrolledList(root)
+ scrolled_list = MyScrolledList(top)
for i in range(30):
scrolled_list.append("Item %02d" % i)
- root.mainloop()
-
if __name__ == '__main__':
+ # At the moment, test_scrolledlist merely creates instance, like htest.
from idlelib.idle_test.htest import run
run(_scrolled_list)
diff --git a/Lib/idlelib/SearchDialog.py b/Lib/idlelib/search.py
index 765d53f..4b90659 100644
--- a/Lib/idlelib/SearchDialog.py
+++ b/Lib/idlelib/search.py
@@ -1,12 +1,12 @@
-from tkinter import *
+from tkinter import TclError
-from idlelib import SearchEngine
-from idlelib.SearchDialogBase import SearchDialogBase
+from idlelib import searchengine
+from idlelib.searchbase import SearchDialogBase
def _setup(text):
"Create or find the singleton SearchDialog instance."
root = text._root()
- engine = SearchEngine.get(root)
+ engine = searchengine.get(root)
if not hasattr(engine, "_searchdialog"):
engine._searchdialog = SearchDialog(root, engine)
return engine._searchdialog
@@ -24,6 +24,7 @@ def find_selection(text):
"Handle the editor edit menu item and corresponding event."
return _setup(text).find_selection(text)
+
class SearchDialog(SearchDialogBase):
def create_widgets(self):
@@ -51,7 +52,7 @@ class SearchDialog(SearchDialogBase):
selfirst = text.index("sel.first")
sellast = text.index("sel.last")
if selfirst == first and sellast == last:
- text.bell()
+ self.bell()
return False
except TclError:
pass
@@ -61,7 +62,7 @@ class SearchDialog(SearchDialogBase):
text.see("insert")
return True
else:
- text.bell()
+ self.bell()
return False
def find_selection(self, text):
@@ -72,26 +73,30 @@ class SearchDialog(SearchDialogBase):
def _search_dialog(parent): # htest #
- '''Display search test box.'''
+ "Display search test box."
+ from tkinter import Toplevel, Text
+ from tkinter.ttk import Button
+
box = Toplevel(parent)
box.title("Test SearchDialog")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- box.geometry("+%d+%d"%(x, y + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ box.geometry("+%d+%d" % (x, y + 175))
text = Text(box, inactiveselectbackground='gray')
text.pack()
text.insert("insert","This is a sample string.\n"*5)
def show_find():
- text.tag_add(SEL, "1.0", END)
+ text.tag_add('sel', '1.0', 'end')
_setup(text).open(text)
- text.tag_remove(SEL, "1.0", END)
+ text.tag_remove('sel', '1.0', 'end')
button = Button(box, text="Search (selection ignored)", command=show_find)
button.pack()
if __name__ == '__main__':
import unittest
- unittest.main('idlelib.idle_test.test_searchdialog',
+ unittest.main('idlelib.idle_test.test_search',
verbosity=2, exit=False)
+
from idlelib.idle_test.htest import run
run(_search_dialog)
diff --git a/Lib/idlelib/SearchDialogBase.py b/Lib/idlelib/searchbase.py
index 5fa84e2..5f81785 100644
--- a/Lib/idlelib/SearchDialogBase.py
+++ b/Lib/idlelib/searchbase.py
@@ -1,7 +1,8 @@
'''Define SearchDialogBase used by Search, Replace, and Grep dialogs.'''
-from tkinter import (Toplevel, Frame, Entry, Label, Button,
- Checkbutton, Radiobutton)
+from tkinter import Toplevel, Frame
+from tkinter.ttk import Entry, Label, Button, Checkbutton, Radiobutton
+
class SearchDialogBase:
'''Create most of a 3 or 4 row, 3 column search dialog.
@@ -79,6 +80,7 @@ class SearchDialogBase:
top.wm_title(self.title)
top.wm_iconname(self.icon)
self.top = top
+ self.bell = top.bell
self.row = 0
self.top.grid_columnconfigure(0, pad=2, weight=0)
@@ -125,7 +127,7 @@ class SearchDialogBase:
def create_option_buttons(self):
'''Return (filled frame, options) for testing.
- Options is a list of SearchEngine booleanvar, label pairs.
+ Options is a list of searchengine booleanvar, label pairs.
A gridded frame from make_frame is filled with a Checkbutton
for each pair, bound to the var, with the corresponding label.
'''
@@ -137,10 +139,8 @@ class SearchDialogBase:
if self.needwrapbutton:
options.append((engine.wrapvar, "Wrap around"))
for var, label in options:
- btn = Checkbutton(frame, anchor="w", variable=var, text=label)
+ btn = Checkbutton(frame, variable=var, text=label)
btn.pack(side="left", fill="both")
- if var.get():
- btn.select()
return frame, options
def create_other_buttons(self):
@@ -153,11 +153,8 @@ class SearchDialogBase:
var = self.engine.backvar
others = [(1, 'Up'), (0, 'Down')]
for val, label in others:
- btn = Radiobutton(frame, anchor="w",
- variable=var, value=val, text=label)
+ btn = Radiobutton(frame, variable=var, value=val, text=label)
btn.pack(side="left", fill="both")
- if var.get() == val:
- btn.select()
return frame, others
def make_button(self, label, command, isdef=0):
@@ -178,7 +175,26 @@ class SearchDialogBase:
b = self.make_button("close", self.close)
b.lower()
+
+class _searchbase(SearchDialogBase): # htest #
+ "Create auto-opening dialog with no text connection."
+
+ def __init__(self, parent):
+ import re
+ from idlelib import searchengine
+
+ self.root = parent
+ self.engine = searchengine.get(parent)
+ self.create_widgets()
+ print(parent.geometry())
+ width,height, x,y = list(map(int, re.split('[x+]', parent.geometry())))
+ self.top.geometry("+%d+%d" % (x + 40, y + 175))
+
+ def default_command(self, dummy): pass
+
if __name__ == '__main__':
import unittest
- unittest.main(
- 'idlelib.idle_test.test_searchdialogbase', verbosity=2)
+ unittest.main('idlelib.idle_test.test_searchbase', verbosity=2, exit=False)
+
+ from idlelib.idle_test.htest import run
+ run(_searchbase)
diff --git a/Lib/idlelib/SearchEngine.py b/Lib/idlelib/searchengine.py
index 37883bf..253f1b0 100644
--- a/Lib/idlelib/SearchEngine.py
+++ b/Lib/idlelib/searchengine.py
@@ -1,5 +1,6 @@
'''Define SearchEngine for search dialogs.'''
import re
+
from tkinter import StringVar, BooleanVar, TclError
import tkinter.messagebox as tkMessageBox
@@ -14,6 +15,7 @@ def get(root):
# This creates a cycle that persists until root is deleted.
return root._searchengine
+
class SearchEngine:
"""Handles searching a text widget for Find, Replace, and Grep."""
@@ -57,7 +59,7 @@ class SearchEngine:
def setcookedpat(self, pat):
"Set pattern after escaping if re."
- # called only in SearchDialog.py: 66
+ # called only in search.py: 66
if self.isre():
pat = re.escape(pat)
self.setpat(pat)
@@ -186,6 +188,7 @@ class SearchEngine:
col = len(chars) - 1
return None
+
def search_reverse(prog, chars, col):
'''Search backwards and return an re match object or None.
diff --git a/Lib/idlelib/StackViewer.py b/Lib/idlelib/stackviewer.py
index ccc755c..0698def 100644
--- a/Lib/idlelib/StackViewer.py
+++ b/Lib/idlelib/stackviewer.py
@@ -1,12 +1,12 @@
-import os
-import sys
import linecache
+import os
import re
+import sys
+
import tkinter as tk
-from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas
-from idlelib.ObjectBrowser import ObjectTreeItem, make_objecttreeitem
-from idlelib.PyShell import PyShellFileList
+from idlelib.debugobj import ObjectTreeItem, make_objecttreeitem
+from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas
def StackBrowser(root, flist=None, tb=None, top=None):
if top is None:
@@ -17,6 +17,7 @@ def StackBrowser(root, flist=None, tb=None, top=None):
node = TreeNode(sc.canvas, None, item)
node.expand()
+
class StackTreeItem(TreeItem):
def __init__(self, flist=None, tb=None):
@@ -55,6 +56,7 @@ class StackTreeItem(TreeItem):
sublist.append(item)
return sublist
+
class FrameTreeItem(TreeItem):
def __init__(self, info, flist):
@@ -96,6 +98,7 @@ class FrameTreeItem(TreeItem):
if os.path.isfile(filename):
self.flist.gotofileline(filename, lineno)
+
class VariablesTreeItem(ObjectTreeItem):
def GetText(self):
@@ -120,15 +123,14 @@ class VariablesTreeItem(ObjectTreeItem):
sublist.append(item)
return sublist
- def keys(self): # unused, left for possible 3rd party use
- return list(self.object.keys())
-def _stack_viewer(parent):
- root = tk.Tk()
- root.title("Test StackViewer")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
- flist = PyShellFileList(root)
+def _stack_viewer(parent): # htest #
+ from idlelib.pyshell import PyShellFileList
+ top = tk.Toplevel(parent)
+ top.title("Test StackViewer")
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x + 50, y + 175))
+ flist = PyShellFileList(top)
try: # to obtain a traceback object
intentional_name_error
except NameError:
@@ -139,7 +141,7 @@ def _stack_viewer(parent):
sys.last_value = exc_value
sys.last_traceback = exc_tb
- StackBrowser(root, flist=flist, top=root, tb=exc_tb)
+ StackBrowser(top, flist=flist, top=top, tb=exc_tb)
# restore sys to original state
del sys.last_type
diff --git a/Lib/idlelib/MultiStatusBar.py b/Lib/idlelib/statusbar.py
index e82ba9a..8618528 100644
--- a/Lib/idlelib/MultiStatusBar.py
+++ b/Lib/idlelib/statusbar.py
@@ -1,16 +1,15 @@
-from tkinter import *
+from tkinter import Frame, Label
+
class MultiStatusBar(Frame):
- def __init__(self, master=None, **kw):
- if master is None:
- master = Tk()
+ def __init__(self, master, **kw):
Frame.__init__(self, master, **kw)
self.labels = {}
- def set_label(self, name, text='', side=LEFT, width=0):
+ def set_label(self, name, text='', side='left', width=0):
if name not in self.labels:
- label = Label(self, borderwidth=0, anchor=W)
+ label = Label(self, borderwidth=0, anchor='w')
label.pack(side=side, pady=0, padx=4)
self.labels[name] = label
else:
@@ -19,28 +18,28 @@ class MultiStatusBar(Frame):
label.config(width=width)
label.config(text=text)
-def _multistatus_bar(parent):
- root = Tk()
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d" %(x, y + 150))
- root.title("Test multistatus bar")
- frame = Frame(root)
- text = Text(frame)
+
+def _multistatus_bar(parent): # htest #
+ from tkinter import Toplevel, Frame, Text, Button
+ top = Toplevel(parent)
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" %(x, y + 175))
+ top.title("Test multistatus bar")
+ frame = Frame(top)
+ text = Text(frame, height=5, width=40)
text.pack()
msb = MultiStatusBar(frame)
msb.set_label("one", "hello")
msb.set_label("two", "world")
- msb.pack(side=BOTTOM, fill=X)
+ msb.pack(side='bottom', fill='x')
def change():
msb.set_label("one", "foo")
msb.set_label("two", "bar")
- button = Button(root, text="Update status", command=change)
- button.pack(side=BOTTOM)
+ button = Button(top, text="Update status", command=change)
+ button.pack(side='bottom')
frame.pack()
- frame.mainloop()
- root.mainloop()
if __name__ == '__main__':
from idlelib.idle_test.htest import run
diff --git a/Lib/idlelib/tabbedpages.py b/Lib/idlelib/tabbedpages.py
index 965f9f8..4186fa2 100644
--- a/Lib/idlelib/tabbedpages.py
+++ b/Lib/idlelib/tabbedpages.py
@@ -285,6 +285,7 @@ class TabSet(Frame):
# placed hide it
self.tab_set.lower()
+
class TabbedPageSet(Frame):
"""A Tkinter tabbed-pane widget.
@@ -302,6 +303,7 @@ class TabbedPageSet(Frame):
remove_page() methods.
"""
+
class Page(object):
"""Abstract base class for TabbedPageSet's pages.
@@ -467,31 +469,29 @@ class TabbedPageSet(Frame):
self._tab_set.set_selected_tab(page_name)
-def _tabbed_pages(parent):
- # test dialog
- root=Tk()
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 175))
- root.title("Test tabbed pages")
- tabPage=TabbedPageSet(root, page_names=['Foobar','Baz'], n_rows=0,
+
+def _tabbed_pages(parent): # htest #
+ top=Toplevel(parent)
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x, y + 175))
+ top.title("Test tabbed pages")
+ tabPage=TabbedPageSet(top, page_names=['Foobar','Baz'], n_rows=0,
expand_tabs=False,
)
tabPage.pack(side=TOP, expand=TRUE, fill=BOTH)
Label(tabPage.pages['Foobar'].frame, text='Foo', pady=20).pack()
Label(tabPage.pages['Foobar'].frame, text='Bar', pady=20).pack()
Label(tabPage.pages['Baz'].frame, text='Baz').pack()
- entryPgName=Entry(root)
- buttonAdd=Button(root, text='Add Page',
+ entryPgName=Entry(top)
+ buttonAdd=Button(top, text='Add Page',
command=lambda:tabPage.add_page(entryPgName.get()))
- buttonRemove=Button(root, text='Remove Page',
+ buttonRemove=Button(top, text='Remove Page',
command=lambda:tabPage.remove_page(entryPgName.get()))
- labelPgName=Label(root, text='name of page to add/remove:')
+ labelPgName=Label(top, text='name of page to add/remove:')
buttonAdd.pack(padx=5, pady=5)
buttonRemove.pack(padx=5, pady=5)
labelPgName.pack(padx=5)
entryPgName.pack(padx=5)
- root.mainloop()
-
if __name__ == '__main__':
from idlelib.idle_test.htest import run
diff --git a/Lib/idlelib/textView.py b/Lib/idlelib/textview.py
index 12ac319..adee326 100644
--- a/Lib/idlelib/textView.py
+++ b/Lib/idlelib/textview.py
@@ -1,14 +1,14 @@
"""Simple text browser for IDLE
"""
-
from tkinter import *
-import tkinter.messagebox as tkMessageBox
+from tkinter.ttk import Scrollbar
+from tkinter.messagebox import showerror
+
class TextViewer(Toplevel):
- """A simple text viewer dialog for IDLE
+ "A simple text viewer dialog for IDLE."
- """
def __init__(self, parent, title, text, modal=True, _htest=False):
"""Show the given text in a scrollable window with a 'close' button
@@ -20,11 +20,11 @@ class TextViewer(Toplevel):
"""
Toplevel.__init__(self, parent)
self.configure(borderwidth=5)
- # place dialog below parent if running htest
+ # Place dialog below parent if running htest.
self.geometry("=%dx%d+%d+%d" % (750, 500,
parent.winfo_rootx() + 10,
parent.winfo_rooty() + (10 if not _htest else 100)))
- #elguavas - config placeholders til config stuff completed
+ # TODO: get fg/bg from theme.
self.bg = '#ffffff'
self.fg = '#000000'
@@ -33,9 +33,9 @@ class TextViewer(Toplevel):
self.protocol("WM_DELETE_WINDOW", self.Ok)
self.parent = parent
self.textView.focus_set()
- #key bindings for this dialog
- self.bind('<Return>',self.Ok) #dismiss dialog
- self.bind('<Escape>',self.Ok) #dismiss dialog
+ # Bind keys for closing this dialog.
+ self.bind('<Return>',self.Ok)
+ self.bind('<Escape>',self.Ok)
self.textView.insert(0.0, text)
self.textView.config(state=DISABLED)
@@ -50,7 +50,7 @@ class TextViewer(Toplevel):
self.buttonOk = Button(frameButtons, text='Close',
command=self.Ok, takefocus=FALSE)
self.scrollbarView = Scrollbar(frameText, orient=VERTICAL,
- takefocus=FALSE, highlightthickness=0)
+ takefocus=FALSE)
self.textView = Text(frameText, wrap=WORD, highlightthickness=0,
fg=self.fg, bg=self.bg)
self.scrollbarView.config(command=self.textView.yview)
@@ -72,14 +72,14 @@ def view_file(parent, title, filename, encoding=None, modal=True):
try:
with open(filename, 'r', encoding=encoding) as file:
contents = file.read()
- except IOError:
- tkMessageBox.showerror(title='File Load Error',
- message='Unable to load file %r .' % filename,
- parent=parent)
+ except OSError:
+ showerror(title='File Load Error',
+ message='Unable to load file %r .' % filename,
+ parent=parent)
except UnicodeDecodeError as err:
- tkMessageBox.showerror(title='Unicode Decode Error',
- message=str(err),
- parent=parent)
+ showerror(title='Unicode Decode Error',
+ message=str(err),
+ parent=parent)
else:
return view_text(parent, title, contents, modal)
diff --git a/Lib/idlelib/ToolTip.py b/Lib/idlelib/tooltip.py
index 964107e..843fb4a 100644
--- a/Lib/idlelib/ToolTip.py
+++ b/Lib/idlelib/tooltip.py
@@ -1,4 +1,4 @@
-# general purpose 'tooltip' routines - currently unused in idlefork
+# general purpose 'tooltip' routines - currently unused in idlelib
# (although the 'calltips' extension is partly based on this code)
# may be useful for some purposes in (or almost in ;) the current project scope
# Ideas gleaned from PySol
@@ -76,21 +76,20 @@ class ListboxToolTip(ToolTipBase):
for item in self.items:
listbox.insert(END, item)
-def _tooltip(parent):
- root = Tk()
- root.title("Test tooltip")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
- label = Label(root, text="Place your mouse over buttons")
+def _tooltip(parent): # htest #
+ top = Toplevel(parent)
+ top.title("Test tooltip")
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x, y + 150))
+ label = Label(top, text="Place your mouse over buttons")
label.pack()
- button1 = Button(root, text="Button 1")
- button2 = Button(root, text="Button 2")
+ button1 = Button(top, text="Button 1")
+ button2 = Button(top, text="Button 2")
button1.pack()
button2.pack()
ToolTip(button1, "This is tooltip text for button1.")
ListboxToolTip(button2, ["This is","multiple line",
"tooltip text","for button2"])
- root.mainloop()
if __name__ == '__main__':
from idlelib.idle_test.htest import run
diff --git a/Lib/idlelib/TreeWidget.py b/Lib/idlelib/tree.py
index a19578f..292ce36 100644
--- a/Lib/idlelib/TreeWidget.py
+++ b/Lib/idlelib/tree.py
@@ -15,10 +15,12 @@
# - optimize tree redraw after expand of subnode
import os
+
from tkinter import *
+from tkinter.ttk import Scrollbar
-from idlelib import ZoomHeight
-from idlelib.configHandler import idleConf
+from idlelib.config import idleConf
+from idlelib import zoomheight
ICONDIR = "Icons"
@@ -445,22 +447,21 @@ class ScrolledCanvas:
self.canvas.yview_scroll(1, "unit")
return "break"
def zoom_height(self, event):
- ZoomHeight.zoom_height(self.master)
+ zoomheight.zoom_height(self.master)
return "break"
-def _tree_widget(parent):
- root = Tk()
- root.title("Test TreeWidget")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- root.geometry("+%d+%d"%(x, y + 150))
- sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
+def _tree_widget(parent): # htest #
+ top = Toplevel(parent)
+ x, y = map(int, parent.geometry().split('+')[1:])
+ top.geometry("+%d+%d" % (x+50, y+175))
+ sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
sc.frame.pack(expand=1, fill="both", side=LEFT)
- item = FileTreeItem(os.getcwd())
+ item = FileTreeItem(ICONDIR)
node = TreeNode(sc.canvas, None, item)
node.expand()
- root.mainloop()
if __name__ == '__main__':
+ # test_tree is currently a copy of this
from idlelib.idle_test.htest import run
run(_tree_widget)
diff --git a/Lib/idlelib/UndoDelegator.py b/Lib/idlelib/undo.py
index 1c2502d..4332f10 100644
--- a/Lib/idlelib/UndoDelegator.py
+++ b/Lib/idlelib/undo.py
@@ -1,7 +1,9 @@
import string
-from tkinter import *
-from idlelib.Delegator import Delegator
+from idlelib.delegator import Delegator
+
+# tkintter import not needed because module does not create widgets,
+# although many methods operate on text widget arguments.
#$ event <<redo>>
#$ win <Control-y>
@@ -158,7 +160,6 @@ class UndoDelegator(Delegator):
class Command:
-
# Base class for Undoable commands
tags = None
@@ -204,7 +205,6 @@ class Command:
class InsertCommand(Command):
-
# Undoable insert command
def __init__(self, index1, chars, tags=None):
@@ -262,7 +262,6 @@ class InsertCommand(Command):
class DeleteCommand(Command):
-
# Undoable delete command
def __init__(self, index1, index2=None):
@@ -297,8 +296,8 @@ class DeleteCommand(Command):
text.see('insert')
##sys.__stderr__.write("undo: %s\n" % self)
-class CommandSequence(Command):
+class CommandSequence(Command):
# Wrapper for a sequence of undoable cmds to be undone/redone
# as a unit
@@ -338,13 +337,12 @@ class CommandSequence(Command):
def _undo_delegator(parent): # htest #
- import re
- import tkinter as tk
- from idlelib.Percolator import Percolator
- undowin = tk.Toplevel()
+ from tkinter import Toplevel, Text, Button
+ from idlelib.percolator import Percolator
+ undowin = Toplevel(parent)
undowin.title("Test UndoDelegator")
- width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
- undowin.geometry("+%d+%d"%(x, y + 150))
+ x, y = map(int, parent.geometry().split('+')[1:])
+ undowin.geometry("+%d+%d" % (x, y + 175))
text = Text(undowin, height=10)
text.pack()
@@ -362,7 +360,7 @@ def _undo_delegator(parent): # htest #
if __name__ == "__main__":
import unittest
- unittest.main('idlelib.idle_test.test_undodelegator', verbosity=2,
- exit=False)
+ unittest.main('idlelib.idle_test.test_undo', verbosity=2, exit=False)
+
from idlelib.idle_test.htest import run
run(_undo_delegator)
diff --git a/Lib/idlelib/WindowList.py b/Lib/idlelib/windows.py
index bc74348..a3f858a 100644
--- a/Lib/idlelib/WindowList.py
+++ b/Lib/idlelib/windows.py
@@ -1,5 +1,6 @@
from tkinter import *
+
class WindowList:
def __init__(self):
@@ -48,6 +49,7 @@ class WindowList:
t, v, tb = sys.exc_info()
print("warning: callback failed in WindowList", t, ":", v)
+
registry = WindowList()
add_windows_to_menu = registry.add_windows_to_menu
diff --git a/Lib/idlelib/ZoomHeight.py b/Lib/idlelib/zoomheight.py
index a5d679e..aa4a427 100644
--- a/Lib/idlelib/ZoomHeight.py
+++ b/Lib/idlelib/zoomheight.py
@@ -3,7 +3,8 @@
import re
import sys
-from idlelib import macosxSupport
+from idlelib import macosx
+
class ZoomHeight:
@@ -20,6 +21,7 @@ class ZoomHeight:
top = self.editwin.top
zoom_height(top)
+
def zoom_height(top):
geom = top.wm_geometry()
m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
@@ -32,7 +34,7 @@ def zoom_height(top):
newy = 0
newheight = newheight - 72
- elif macosxSupport.isAquaTk():
+ elif macosx.isAquaTk():
# The '88' below is a magic number that avoids placing the bottom
# of the window below the panel on my machine. I don't know how
# to calculate the correct value for this with tkinter.
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 4e8a4bb..cad508a 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -111,7 +111,15 @@ InternalDate = re.compile(br'.*INTERNALDATE "'
# Literal is no longer used; kept for backward compatibility.
Literal = re.compile(br'.*{(?P<size>\d+)}$', re.ASCII)
MapCRLF = re.compile(br'\r\n|\r|\n')
-Response_code = re.compile(br'\[(?P<type>[A-Z-]+)( (?P<data>[^\]]*))?\]')
+# We no longer exclude the ']' character from the data portion of the response
+# code, even though it violates the RFC. Popular IMAP servers such as Gmail
+# allow flags with ']', and there are programs (including imaplib!) that can
+# produce them. The problem with this is if the 'text' portion of the response
+# includes a ']' we'll parse the response wrong (which is the point of the RFC
+# restriction). However, that seems less likely to be a problem in practice
+# than being unable to correctly parse flags that include ']' chars, which
+# was reported as a real-world problem in issue #21815.
+Response_code = re.compile(br'\[(?P<type>[A-Z-]+)( (?P<data>.*))?\]')
Untagged_response = re.compile(br'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
# Untagged_status is no longer used; kept for backward compatibility
Untagged_status = re.compile(
@@ -124,7 +132,7 @@ _Untagged_status = br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?'
class IMAP4:
- """IMAP4 client class.
+ r"""IMAP4 client class.
Instantiate with: IMAP4([host[, port]])
@@ -1259,7 +1267,10 @@ if HAVE_SSL:
if ssl_context is not None and certfile is not None:
raise ValueError("ssl_context and certfile arguments are mutually "
"exclusive")
-
+ if keyfile is not None or certfile is not None:
+ import warnings
+ warnings.warn("keyfile and certfile are deprecated, use a"
+ "custom ssl_context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
if ssl_context is None:
@@ -1527,7 +1538,7 @@ if __name__ == '__main__':
('select', ('/tmp/yyz 2',)),
('search', (None, 'SUBJECT', 'test')),
('fetch', ('1', '(FLAGS INTERNALDATE RFC822)')),
- ('store', ('1', 'FLAGS', '(\Deleted)')),
+ ('store', ('1', 'FLAGS', r'(\Deleted)')),
('namespace', ()),
('expunge', ()),
('recent', ()),
diff --git a/Lib/imghdr.py b/Lib/imghdr.py
index b267925..76e8abb 100644
--- a/Lib/imghdr.py
+++ b/Lib/imghdr.py
@@ -1,5 +1,7 @@
"""Recognize image file formats based on their first few bytes."""
+from os import PathLike
+
__all__ = ["what"]
#-------------------------#
@@ -10,7 +12,7 @@ def what(file, h=None):
f = None
try:
if h is None:
- if isinstance(file, str):
+ if isinstance(file, (str, PathLike)):
f = open(file, 'rb')
h = f.read(32)
else:
diff --git a/Lib/imp.py b/Lib/imp.py
index e264391..781ff23 100644
--- a/Lib/imp.py
+++ b/Lib/imp.py
@@ -30,7 +30,7 @@ import warnings
warnings.warn("the imp module is deprecated in favour of importlib; "
"see the module's documentation for alternative uses",
- PendingDeprecationWarning, stacklevel=2)
+ DeprecationWarning, stacklevel=2)
# DEPRECATED
SEARCH_ERROR = 0
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 9eecbfe..a531a03 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -36,23 +36,6 @@ def _new_module(name):
return type(sys)(name)
-class _ManageReload:
-
- """Manages the possible clean-up of sys.modules for load_module()."""
-
- def __init__(self, name):
- self._name = name
-
- def __enter__(self):
- self._is_reload = self._name in sys.modules
-
- def __exit__(self, *args):
- if any(arg is not None for arg in args) and not self._is_reload:
- try:
- del sys.modules[self._name]
- except KeyError:
- pass
-
# Module-level locking ########################################################
# A dict mapping module names to weakrefs of _ModuleLock instances
@@ -270,7 +253,7 @@ def _load_module_shim(self, fullname):
# Module specifications #######################################################
def _module_repr(module):
- # The implementation of ModuleType__repr__().
+ # The implementation of ModuleType.__repr__().
loader = getattr(module, '__loader__', None)
if hasattr(loader, 'module_repr'):
# As soon as BuiltinImporter, FrozenImporter, and NamespaceLoader
@@ -576,9 +559,8 @@ def module_from_spec(spec):
# module creation should be used.
module = spec.loader.create_module(spec)
elif hasattr(spec.loader, 'exec_module'):
- _warnings.warn('starting in Python 3.6, loaders defining exec_module() '
- 'must also define create_module()',
- DeprecationWarning, stacklevel=2)
+ raise ImportError('loaders that define exec_module() '
+ 'must also define create_module()')
if module is None:
module = _new_module(spec.name)
_init_module_attrs(spec, module)
@@ -603,7 +585,7 @@ def _module_repr_from_spec(spec):
# Used by importlib.reload() and _load_module_shim().
def _exec(spec, module):
- """Execute the spec in an existing module's namespace."""
+ """Execute the spec's specified module in an existing module's namespace."""
name = spec.name
_imp.acquire_lock()
with _ModuleLockManager(name):
@@ -877,14 +859,21 @@ def _find_spec_legacy(finder, name, path):
def _find_spec(name, path, target=None):
- """Find a module's loader."""
- if sys.meta_path is not None and not sys.meta_path:
+ """Find a module's spec."""
+ meta_path = sys.meta_path
+ if meta_path is None:
+ # PyImport_Cleanup() is running or has been called.
+ raise ImportError("sys.meta_path is None, Python is likely "
+ "shutting down")
+
+ if not meta_path:
_warnings.warn('sys.meta_path is empty', ImportWarning)
+
# We check sys.modules here for the reload case. While a passed-in
# target will usually indicate a reload there is no guarantee, whereas
# sys.modules provides one.
is_reload = name in sys.modules
- for finder in sys.meta_path:
+ for finder in meta_path:
with _ImportLockContext():
try:
find_spec = finder.find_spec
@@ -925,6 +914,9 @@ def _sanity_check(name, package, level):
if level > 0:
if not isinstance(package, str):
raise TypeError('__package__ not set to a string')
+ elif not package:
+ raise ImportError('attempted relative import with no known parent '
+ 'package')
elif package not in sys.modules:
msg = ('Parent module {!r} not loaded, cannot perform relative '
'import')
@@ -950,10 +942,10 @@ def _find_and_load_unlocked(name, import_):
path = parent_module.__path__
except AttributeError:
msg = (_ERR_MSG + '; {!r} is not a package').format(name, parent)
- raise ImportError(msg, name=name) from None
+ raise ModuleNotFoundError(msg, name=name) from None
spec = _find_spec(name, path)
if spec is None:
- raise ImportError(_ERR_MSG.format(name), name=name)
+ raise ModuleNotFoundError(_ERR_MSG.format(name), name=name)
else:
module = _load_unlocked(spec)
if parent:
@@ -989,10 +981,11 @@ def _gcd_import(name, package=None, level=0):
_imp.release_lock()
message = ('import of {} halted; '
'None in sys.modules'.format(name))
- raise ImportError(message, name=name)
+ raise ModuleNotFoundError(message, name=name)
_lock_unlock_module(name)
return module
+
def _handle_fromlist(module, fromlist, import_):
"""Figure out what __import__ should return.
@@ -1014,13 +1007,12 @@ def _handle_fromlist(module, fromlist, import_):
from_name = '{}.{}'.format(module.__name__, x)
try:
_call_with_frames_removed(import_, from_name)
- except ImportError as exc:
+ except ModuleNotFoundError as exc:
# Backwards-compatibility dictates we ignore failed
# imports triggered by fromlist for modules that don't
# exist.
- if str(exc).startswith(_ERR_MSG_PREFIX):
- if exc.name == from_name:
- continue
+ if exc.name == from_name:
+ continue
raise
return module
@@ -1033,7 +1025,19 @@ def _calc___package__(globals):
"""
package = globals.get('__package__')
- if package is None:
+ spec = globals.get('__spec__')
+ if package is not None:
+ if spec is not None and package != spec.parent:
+ _warnings.warn("__package__ != __spec__.parent "
+ f"({package!r} != {spec.parent!r})",
+ ImportWarning, stacklevel=3)
+ return package
+ elif spec is not None:
+ return spec.parent
+ else:
+ _warnings.warn("can't resolve package from __spec__ or __package__, "
+ "falling back on __name__ and __path__",
+ ImportWarning, stacklevel=3)
package = globals['__name__']
if '__path__' not in globals:
package = package.rpartition('.')[0]
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index e54d691..5cb58ab 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -137,10 +137,6 @@ _code_type = type(_write_atomic.__code__)
# a .pyc file in text mode the magic number will be wrong; also, the
# Apple MPW compiler swaps their values, botching string constants.
#
-# The magic numbers must be spaced apart at least 2 values, as the
-# -U interpeter flag will cause MAGIC+1 being used. They have been
-# odd numbers for some time now.
-#
# There were a variety of old schemes for setting the magic number.
# The current working scheme is to increment the previous value by
# 10.
@@ -231,6 +227,18 @@ _code_type = type(_write_atomic.__code__)
# Python 3.5b2 3340 (fix dictionary display evaluation order #11205)
# Python 3.5b2 3350 (add GET_YIELD_FROM_ITER opcode #24400)
# Python 3.5.2 3351 (fix BUILD_MAP_UNPACK_WITH_CALL opcode #27286)
+# Python 3.6a0 3360 (add FORMAT_VALUE opcode #25483
+# Python 3.6a0 3361 (lineno delta of code.co_lnotab becomes signed)
+# Python 3.6a1 3370 (16 bit wordcode)
+# Python 3.6a1 3371 (add BUILD_CONST_KEY_MAP opcode #27140)
+# Python 3.6a1 3372 (MAKE_FUNCTION simplification, remove MAKE_CLOSURE
+# #27095)
+# Python 3.6b1 3373 (add BUILD_STRING opcode #27078)
+# Python 3.6b1 3375 (add SETUP_ANNOTATIONS and STORE_ANNOTATION opcodes
+# #27985)
+# Python 3.6b1 3376 (simplify CALL_FUNCTIONs & BUILD_MAP_UNPACK_WITH_CALL)
+# Python 3.6b1 3377 (set __class__ cell from type.__new__ #23722)
+# Python 3.6b2 3378 (add BUILD_TUPLE_UNPACK_WITH_CALL #28257)
#
# MAGIC must change whenever the bytecode emitted by the compiler may no
# longer be understood by older implementations of the eval loop (usually
@@ -239,7 +247,7 @@ _code_type = type(_write_atomic.__code__)
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
-MAGIC_NUMBER = (3351).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3378).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
_PYCACHE = '__pycache__'
@@ -276,6 +284,7 @@ def cache_from_source(path, debug_override=None, *, optimization=None):
message = 'debug_override or optimization must be set to None'
raise TypeError(message)
optimization = '' if debug_override else 1
+ path = _os.fspath(path)
head, tail = _path_split(path)
base, sep, rest = tail.rpartition('.')
tag = sys.implementation.cache_tag
@@ -306,6 +315,7 @@ def source_from_cache(path):
"""
if sys.implementation.cache_tag is None:
raise NotImplementedError('sys.implementation.cache_tag is None')
+ path = _os.fspath(path)
head, pycache_filename = _path_split(path)
head, pycache = _path_split(head)
if pycache != _PYCACHE:
@@ -371,14 +381,6 @@ def _calc_mode(path):
return mode
-def _verbose_message(message, *args, verbosity=1):
- """Print the message to stderr if -v/PYTHONVERBOSE is turned on."""
- if sys.flags.verbose >= verbosity:
- if not message.startswith(('#', 'import ')):
- message = '# ' + message
- print(message.format(*args), file=sys.stderr)
-
-
def _check_name(method):
"""Decorator to verify that the module being requested matches the one the
loader can handle.
@@ -448,15 +450,15 @@ def _validate_bytecode_header(data, source_stats=None, name=None, path=None):
raw_size = data[8:12]
if magic != MAGIC_NUMBER:
message = 'bad magic number in {!r}: {!r}'.format(name, magic)
- _verbose_message('{}', message)
+ _bootstrap._verbose_message('{}', message)
raise ImportError(message, **exc_details)
elif len(raw_timestamp) != 4:
message = 'reached EOF while reading timestamp in {!r}'.format(name)
- _verbose_message('{}', message)
+ _bootstrap._verbose_message('{}', message)
raise EOFError(message)
elif len(raw_size) != 4:
message = 'reached EOF while reading size of source in {!r}'.format(name)
- _verbose_message('{}', message)
+ _bootstrap._verbose_message('{}', message)
raise EOFError(message)
if source_stats is not None:
try:
@@ -466,7 +468,7 @@ def _validate_bytecode_header(data, source_stats=None, name=None, path=None):
else:
if _r_long(raw_timestamp) != source_mtime:
message = 'bytecode is stale for {!r}'.format(name)
- _verbose_message('{}', message)
+ _bootstrap._verbose_message('{}', message)
raise ImportError(message, **exc_details)
try:
source_size = source_stats['size'] & 0xFFFFFFFF
@@ -483,7 +485,7 @@ def _compile_bytecode(data, name=None, bytecode_path=None, source_path=None):
"""Compile bytecode as returned by _validate_bytecode_header()."""
code = marshal.loads(data)
if isinstance(code, _code_type):
- _verbose_message('code object from {!r}', bytecode_path)
+ _bootstrap._verbose_message('code object from {!r}', bytecode_path)
if source_path is not None:
_imp._fix_co_filename(code, source_path)
return code
@@ -541,6 +543,8 @@ def spec_from_file_location(name, location=None, *, loader=None,
location = loader.get_filename(name)
except ImportError:
pass
+ else:
+ location = _os.fspath(location)
# If the location is on the filesystem, but doesn't actually exist,
# we could return None here, indicating that the location is not
@@ -610,7 +614,7 @@ class WindowsRegistryFinder:
else:
registry_key = cls.REGISTRY_KEY
key = registry_key.format(fullname=fullname,
- sys_version=sys.version[:3])
+ sys_version='%d.%d' % sys.version_info[:2])
try:
with cls._open_registry(key) as hkey:
filepath = _winreg.QueryValue(hkey, '')
@@ -673,6 +677,7 @@ class _LoaderBasics:
_bootstrap._call_with_frames_removed(exec, code, module.__dict__)
def load_module(self, fullname):
+ """This module is deprecated."""
return _bootstrap._load_module_shim(self, fullname)
@@ -766,21 +771,21 @@ class SourceLoader(_LoaderBasics):
except (ImportError, EOFError):
pass
else:
- _verbose_message('{} matches {}', bytecode_path,
- source_path)
+ _bootstrap._verbose_message('{} matches {}', bytecode_path,
+ source_path)
return _compile_bytecode(bytes_data, name=fullname,
bytecode_path=bytecode_path,
source_path=source_path)
source_bytes = self.get_data(source_path)
code_object = self.source_to_code(source_bytes, source_path)
- _verbose_message('code object from {}', source_path)
+ _bootstrap._verbose_message('code object from {}', source_path)
if (not sys.dont_write_bytecode and bytecode_path is not None and
source_mtime is not None):
data = _code_to_bytecode(code_object, source_mtime,
len(source_bytes))
try:
self._cache_bytecode(source_path, bytecode_path, data)
- _verbose_message('wrote {!r}', bytecode_path)
+ _bootstrap._verbose_message('wrote {!r}', bytecode_path)
except NotImplementedError:
pass
return code_object
@@ -860,14 +865,16 @@ class SourceFileLoader(FileLoader, SourceLoader):
except OSError as exc:
# Could be a permission error, read-only filesystem: just forget
# about writing the data.
- _verbose_message('could not create {!r}: {!r}', parent, exc)
+ _bootstrap._verbose_message('could not create {!r}: {!r}',
+ parent, exc)
return
try:
_write_atomic(path, data, _mode)
- _verbose_message('created {!r}', path)
+ _bootstrap._verbose_message('created {!r}', path)
except OSError as exc:
# Same as above: just don't write the bytecode.
- _verbose_message('could not create {!r}: {!r}', path, exc)
+ _bootstrap._verbose_message('could not create {!r}: {!r}', path,
+ exc)
class SourcelessFileLoader(FileLoader, _LoaderBasics):
@@ -912,14 +919,14 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics):
"""Create an unitialized extension module"""
module = _bootstrap._call_with_frames_removed(
_imp.create_dynamic, spec)
- _verbose_message('extension module {!r} loaded from {!r}',
+ _bootstrap._verbose_message('extension module {!r} loaded from {!r}',
spec.name, self.path)
return module
def exec_module(self, module):
"""Initialize an extension module"""
_bootstrap._call_with_frames_removed(_imp.exec_dynamic, module)
- _verbose_message('extension module {!r} executed from {!r}',
+ _bootstrap._verbose_message('extension module {!r} executed from {!r}',
self.name, self.path)
def is_package(self, fullname):
@@ -985,6 +992,9 @@ class _NamespacePath:
def __iter__(self):
return iter(self._recalculate())
+ def __setitem__(self, index, path):
+ self._path[index] = path
+
def __len__(self):
return len(self._recalculate())
@@ -1034,7 +1044,8 @@ class _NamespaceLoader:
"""
# The import system never calls this method.
- _verbose_message('namespace module loaded with path {!r}', self._path)
+ _bootstrap._verbose_message('namespace module loaded with path {!r}',
+ self._path)
return _bootstrap._load_module_shim(self, fullname)
@@ -1054,11 +1065,7 @@ class PathFinder:
@classmethod
def _path_hooks(cls, path):
- """Search sequence of hooks for a finder for 'path'.
-
- If 'hooks' is false then use sys.path_hooks.
-
- """
+ """Search sys.path_hooks for a finder for 'path'."""
if sys.path_hooks is not None and not sys.path_hooks:
_warnings.warn('sys.path_hooks is empty', ImportWarning)
for hook in sys.path_hooks:
@@ -1140,8 +1147,10 @@ class PathFinder:
@classmethod
def find_spec(cls, fullname, path=None, target=None):
- """find the module on sys.path or 'path' based on sys.path_hooks and
- sys.path_importer_cache."""
+ """Try to find a spec for 'fullname' on sys.path or 'path'.
+
+ The search is based on sys.path_hooks and sys.path_importer_cache.
+ """
if path is None:
path = sys.path
spec = cls._get_spec(fullname, path, target)
@@ -1221,8 +1230,10 @@ class FileFinder:
submodule_search_locations=smsl)
def find_spec(self, fullname, target=None):
- """Try to find a spec for the specified module. Returns the
- matching spec, or None if not found."""
+ """Try to find a spec for the specified module.
+
+ Returns the matching spec, or None if not found.
+ """
is_namespace = False
tail_module = fullname.rpartition('.')[2]
try:
@@ -1254,12 +1265,13 @@ class FileFinder:
# Check for a file w/ a proper suffix exists.
for suffix, loader_class in self._loaders:
full_path = _path_join(self.path, tail_module + suffix)
- _verbose_message('trying {}'.format(full_path), verbosity=2)
+ _bootstrap._verbose_message('trying {}', full_path, verbosity=2)
if cache_module + suffix in cache:
if _path_isfile(full_path):
- return self._get_spec(loader_class, fullname, full_path, None, target)
+ return self._get_spec(loader_class, fullname, full_path,
+ None, target)
if is_namespace:
- _verbose_message('possible namespace for {}'.format(base_path))
+ _bootstrap._verbose_message('possible namespace for {}', base_path)
spec = _bootstrap.ModuleSpec(fullname, None)
spec.submodule_search_locations = [base_path]
return spec
@@ -1430,8 +1442,3 @@ def _install(_bootstrap_module):
if _os.__name__ == 'nt':
sys.meta_path.append(WindowsRegistryFinder)
sys.meta_path.append(PathFinder)
-
- # XXX We expose a couple of classes in _bootstrap for the sake of
- # a setuptools bug (https://bitbucket.org/pypa/setuptools/issue/378).
- _bootstrap_module.FileFinder = FileFinder
- _bootstrap_module.SourceFileLoader = SourceFileLoader
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py
index e1fa07a..6bdf0d4 100644
--- a/Lib/importlib/util.py
+++ b/Lib/importlib/util.py
@@ -22,8 +22,8 @@ def resolve_name(name, package):
if not name.startswith('.'):
return name
elif not package:
- raise ValueError('{!r} is not a relative name '
- '(no leading dot)'.format(name))
+ raise ValueError(f'no package specified for {repr(name)} '
+ '(required for relative module names)')
level = 0
for character in name:
if character != '.':
@@ -204,11 +204,6 @@ def module_for_loader(fxn):
return module_for_loader_wrapper
-class _Module(types.ModuleType):
-
- """A subclass of the module type to allow __class__ manipulation."""
-
-
class _LazyModule(types.ModuleType):
"""A subclass of the module type which triggers loading upon attribute access."""
@@ -218,13 +213,14 @@ class _LazyModule(types.ModuleType):
# All module metadata must be garnered from __spec__ in order to avoid
# using mutated values.
# Stop triggering this method.
- self.__class__ = _Module
+ self.__class__ = types.ModuleType
# Get the original name to make sure no object substitution occurred
# in sys.modules.
original_name = self.__spec__.name
# Figure out exactly what attributes were mutated between the creation
# of the module and now.
- attrs_then = self.__spec__.loader_state
+ attrs_then = self.__spec__.loader_state['__dict__']
+ original_type = self.__spec__.loader_state['__class__']
attrs_now = self.__dict__
attrs_updated = {}
for key, value in attrs_now.items():
@@ -239,9 +235,9 @@ class _LazyModule(types.ModuleType):
# object was put into sys.modules.
if original_name in sys.modules:
if id(self) != id(sys.modules[original_name]):
- msg = ('module object for {!r} substituted in sys.modules '
- 'during a lazy load')
- raise ValueError(msg.format(original_name))
+ raise ValueError(f"module object for {original_name!r} "
+ "substituted in sys.modules during a lazy "
+ "load")
# Update after loading since that's what would happen in an eager
# loading situation.
self.__dict__.update(attrs_updated)
@@ -275,8 +271,7 @@ class LazyLoader(abc.Loader):
self.loader = loader
def create_module(self, spec):
- """Create a module which can have its __class__ manipulated."""
- return _Module(spec.name)
+ return self.loader.create_module(spec)
def exec_module(self, module):
"""Make the module load lazily."""
@@ -286,5 +281,8 @@ class LazyLoader(abc.Loader):
# on an object would have triggered the load,
# e.g. ``module.__spec__.loader = None`` would trigger a load from
# trying to access module.__spec__.
- module.__spec__.loader_state = module.__dict__.copy()
+ loader_state = {}
+ loader_state['__dict__'] = module.__dict__.copy()
+ loader_state['__class__'] = module.__class__
+ module.__spec__.loader_state = loader_state
module.__class__ = _LazyModule
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 0fd0382..2923d6d 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -16,7 +16,7 @@ Here are some of the useful functions provided by this module:
getmodule() - determine the module that an object came from
getclasstree() - arrange classes so as to represent their hierarchy
- getargspec(), getargvalues(), getcallargs() - get info about function arguments
+ getargvalues(), getcallargs() - get info about function arguments
getfullargspec() - same, with support for Python 3 features
formatargspec(), formatargvalues() - format an argument spec
getouterframes(), getinnerframes() - get info about frames
@@ -185,6 +185,13 @@ def iscoroutinefunction(object):
return bool((isfunction(object) or ismethod(object)) and
object.__code__.co_flags & CO_COROUTINE)
+def isasyncgenfunction(object):
+ return bool((isfunction(object) or ismethod(object)) and
+ object.__code__.co_flags & CO_ASYNC_GENERATOR)
+
+def isasyncgen(object):
+ return isinstance(object, types.AsyncGeneratorType)
+
def isgenerator(object):
"""Return true if the object is a generator.
@@ -623,23 +630,6 @@ def getfile(object):
raise TypeError('{!r} is not a module, class, method, '
'function, traceback, frame, or code object'.format(object))
-ModuleInfo = namedtuple('ModuleInfo', 'name suffix mode module_type')
-
-def getmoduleinfo(path):
- """Get the module name, suffix, mode, and module type for a given file."""
- warnings.warn('inspect.getmoduleinfo() is deprecated', DeprecationWarning,
- 2)
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', PendingDeprecationWarning)
- import imp
- filename = os.path.basename(path)
- suffixes = [(-len(suffix), suffix, mode, mtype)
- for suffix, mode, mtype in imp.get_suffixes()]
- suffixes.sort() # try longest suffixes first, in case they overlap
- for neglen, suffix, mode, mtype in suffixes:
- if filename[neglen:] == suffix:
- return ModuleInfo(filename[:neglen], suffix, mode, mtype)
-
def getmodulename(path):
"""Return the module name for a given file, or None."""
fname = os.path.basename(path)
@@ -1060,8 +1050,6 @@ def getfullargspec(func):
'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults.
'annotations' is a dictionary mapping argument names to annotations.
- The first four items in the tuple correspond to getargspec().
-
This function is deprecated, use inspect.signature() instead.
"""
@@ -1174,8 +1162,7 @@ def formatargspec(args, varargs=None, varkw=None, defaults=None,
formatvalue=lambda value: '=' + repr(value),
formatreturns=lambda text: ' -> ' + text,
formatannotation=formatannotation):
- """Format an argument spec from the values returned by getargspec
- or getfullargspec.
+ """Format an argument spec from the values returned by getfullargspec.
The first seven arguments are (args, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, annotations). The other five arguments
@@ -2417,6 +2404,20 @@ class Parameter:
if not isinstance(name, str):
raise TypeError("name must be a str, not a {!r}".format(name))
+ if name[0] == '.' and name[1:].isdigit():
+ # These are implicit arguments generated by comprehensions. In
+ # order to provide a friendlier interface to users, we recast
+ # their name as "implicitN" and treat them as positional-only.
+ # See issue 19611.
+ if kind != _POSITIONAL_OR_KEYWORD:
+ raise ValueError(
+ 'implicit arguments must be passed in as {}'.format(
+ _POSITIONAL_OR_KEYWORD
+ )
+ )
+ self._kind = _POSITIONAL_ONLY
+ name = 'implicit{}'.format(name[1:])
+
if not name.isidentifier():
raise ValueError('{!r} is not a valid parameter name'.format(name))
diff --git a/Lib/io.py b/Lib/io.py
index e03db97..968ee50 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -90,3 +90,10 @@ for klass in (BytesIO, BufferedReader, BufferedWriter, BufferedRandom,
for klass in (StringIO, TextIOWrapper):
TextIOBase.register(klass)
del klass
+
+try:
+ from _io import _WindowsConsoleIO
+except ImportError:
+ pass
+else:
+ RawIOBase.register(_WindowsConsoleIO)
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
index 1f90058..20f33cb 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -636,12 +636,12 @@ class _BaseNetwork(_IPAddressBase):
broadcast = int(self.broadcast_address)
if n >= 0:
if network + n > broadcast:
- raise IndexError
+ raise IndexError('address out of range')
return self._address_class(network + n)
else:
n += 1
if broadcast + n < network:
- raise IndexError
+ raise IndexError('address out of range')
return self._address_class(broadcast + n)
def __lt__(self, other):
diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py
index f72b058..8dcc678 100644
--- a/Lib/json/__init__.py
+++ b/Lib/json/__init__.py
@@ -105,6 +105,7 @@ __author__ = 'Bob Ippolito <bob@redivi.com>'
from .decoder import JSONDecoder, JSONDecodeError
from .encoder import JSONEncoder
+import codecs
_default_encoder = JSONEncoder(
skipkeys=False,
@@ -116,7 +117,7 @@ _default_encoder = JSONEncoder(
default=None,
)
-def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
+def dump(obj, fp, *, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
default=None, sort_keys=False, **kw):
"""Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
@@ -179,7 +180,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
fp.write(chunk)
-def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
+def dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
default=None, sort_keys=False, **kw):
"""Serialize ``obj`` to a JSON formatted ``str``.
@@ -240,7 +241,36 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
_default_decoder = JSONDecoder(object_hook=None, object_pairs_hook=None)
-def load(fp, cls=None, object_hook=None, parse_float=None,
+def detect_encoding(b):
+ bstartswith = b.startswith
+ if bstartswith((codecs.BOM_UTF32_BE, codecs.BOM_UTF32_LE)):
+ return 'utf-32'
+ if bstartswith((codecs.BOM_UTF16_BE, codecs.BOM_UTF16_LE)):
+ return 'utf-16'
+ if bstartswith(codecs.BOM_UTF8):
+ return 'utf-8-sig'
+
+ if len(b) >= 4:
+ if not b[0]:
+ # 00 00 -- -- - utf-32-be
+ # 00 XX -- -- - utf-16-be
+ return 'utf-16-be' if b[1] else 'utf-32-be'
+ if not b[1]:
+ # XX 00 00 00 - utf-32-le
+ # XX 00 XX XX - utf-16-le
+ return 'utf-16-le' if b[2] or b[3] else 'utf-32-le'
+ elif len(b) == 2:
+ if not b[0]:
+ # 00 XX - utf-16-be
+ return 'utf-16-be'
+ if not b[1]:
+ # XX 00 - utf-16-le
+ return 'utf-16-le'
+ # default
+ return 'utf-8'
+
+
+def load(fp, *, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
a JSON document) to a Python object.
@@ -268,10 +298,10 @@ def load(fp, cls=None, object_hook=None, parse_float=None,
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
-def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
+def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
- """Deserialize ``s`` (a ``str`` instance containing a JSON
- document) to a Python object.
+ """Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance
+ containing a JSON document) to a Python object.
``object_hook`` is an optional function that will be called with the
result of any object literal decode (a ``dict``). The return value of
@@ -307,12 +337,16 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
The ``encoding`` argument is ignored and deprecated.
"""
- if not isinstance(s, str):
- raise TypeError('the JSON object must be str, not {!r}'.format(
- s.__class__.__name__))
- if s.startswith(u'\ufeff'):
- raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",
- s, 0)
+ if isinstance(s, str):
+ if s.startswith('\ufeff'):
+ raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",
+ s, 0)
+ else:
+ if not isinstance(s, (bytes, bytearray)):
+ raise TypeError('the JSON object must be str, bytes or bytearray, '
+ 'not {!r}'.format(s.__class__.__name__))
+ s = s.decode(detect_encoding(s), 'surrogatepass')
+
if (cls is None and object_hook is None and
parse_int is None and parse_float is None and
parse_constant is None and object_pairs_hook is None and not kw):
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
index 0f03f20..2422c6a 100644
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -280,7 +280,7 @@ class JSONDecoder(object):
"""
- def __init__(self, object_hook=None, parse_float=None,
+ def __init__(self, *, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, strict=True,
object_pairs_hook=None):
"""``object_hook``, if specified, will be called with the result
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index d596489..41a497c 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -101,7 +101,7 @@ class JSONEncoder(object):
"""
item_separator = ', '
key_separator = ': '
- def __init__(self, skipkeys=False, ensure_ascii=True,
+ def __init__(self, *, skipkeys=False, ensure_ascii=True,
check_circular=True, allow_nan=True, sort_keys=False,
indent=None, separators=None, default=None):
"""Constructor for JSONEncoder, with sensible defaults.
@@ -176,7 +176,8 @@ class JSONEncoder(object):
return JSONEncoder.default(self, o)
"""
- raise TypeError(repr(o) + " is not JSON serializable")
+ raise TypeError("Object of type '%s' is not JSON serializable" %
+ o.__class__.__name__)
def encode(self, o):
"""Return a JSON string representation of a Python data structure.
diff --git a/Lib/lib2to3/Grammar.txt b/Lib/lib2to3/Grammar.txt
index 60503dd..2abd5ee 100644
--- a/Lib/lib2to3/Grammar.txt
+++ b/Lib/lib2to3/Grammar.txt
@@ -54,12 +54,13 @@ stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | exec_stmt | assert_stmt)
-expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
+expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*)
+annassign: ':' test ['=' test]
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
-# For normal assignments, additional restrictions enforced by the interpreter
+# For normal and annotated assignments, additional restrictions enforced by the interpreter
print_stmt: 'print' ( [ test (',' test)* [','] ] |
'>>' test [ (',' test)+ [','] ] )
del_stmt: 'del' exprlist
@@ -160,7 +161,7 @@ argument: ( test [comp_for] |
star_expr )
comp_iter: comp_for | comp_if
-comp_for: 'for' exprlist 'in' testlist_safe [comp_iter]
+comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [comp_iter]
comp_if: 'if' old_test [comp_iter]
testlist1: test (',' test)*
diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py
index 44502bf..babe6cb 100644
--- a/Lib/lib2to3/fixer_util.py
+++ b/Lib/lib2to3/fixer_util.py
@@ -1,8 +1,6 @@
"""Utility functions, node construction macros, etc."""
# Author: Collin Winter
-from itertools import islice
-
# Local imports
from .pgen2 import token
from .pytree import Leaf, Node
diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py
index 963f952..d3655c9 100644
--- a/Lib/lib2to3/fixes/fix_dict.py
+++ b/Lib/lib2to3/fixes/fix_dict.py
@@ -30,9 +30,8 @@ as an argument to a function that introspects the argument).
# Local imports
from .. import pytree
from .. import patcomp
-from ..pgen2 import token
from .. import fixer_base
-from ..fixer_util import Name, Call, LParen, RParen, ArgList, Dot
+from ..fixer_util import Name, Call, Dot
from .. import fixer_util
diff --git a/Lib/lib2to3/fixes/fix_exec.py b/Lib/lib2to3/fixes/fix_exec.py
index 2c9b72d..ab921ee 100644
--- a/Lib/lib2to3/fixes/fix_exec.py
+++ b/Lib/lib2to3/fixes/fix_exec.py
@@ -10,7 +10,6 @@ exec code in ns1, ns2 -> exec(code, ns1, ns2)
"""
# Local imports
-from .. import pytree
from .. import fixer_base
from ..fixer_util import Comma, Name, Call
diff --git a/Lib/lib2to3/fixes/fix_filter.py b/Lib/lib2to3/fixes/fix_filter.py
index 391889f..bb6718c 100644
--- a/Lib/lib2to3/fixes/fix_filter.py
+++ b/Lib/lib2to3/fixes/fix_filter.py
@@ -14,7 +14,6 @@ Python 2.6 figure it out.
"""
# Local imports
-from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, Call, ListComp, in_special_context
diff --git a/Lib/lib2to3/fixes/fix_has_key.py b/Lib/lib2to3/fixes/fix_has_key.py
index 18c560f..439708c 100644
--- a/Lib/lib2to3/fixes/fix_has_key.py
+++ b/Lib/lib2to3/fixes/fix_has_key.py
@@ -31,7 +31,6 @@ CAVEATS:
# Local imports
from .. import pytree
-from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, parenthesize
diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py
index 46c7aaf..8e34463 100644
--- a/Lib/lib2to3/fixes/fix_metaclass.py
+++ b/Lib/lib2to3/fixes/fix_metaclass.py
@@ -20,7 +20,7 @@
# Local imports
from .. import fixer_base
from ..pygram import token
-from ..fixer_util import Name, syms, Node, Leaf
+from ..fixer_util import syms, Node, Leaf
def has_metaclass(parent):
diff --git a/Lib/lib2to3/fixes/fix_nonzero.py b/Lib/lib2to3/fixes/fix_nonzero.py
index ad91a29..c229596 100644
--- a/Lib/lib2to3/fixes/fix_nonzero.py
+++ b/Lib/lib2to3/fixes/fix_nonzero.py
@@ -3,7 +3,7 @@
# Local imports
from .. import fixer_base
-from ..fixer_util import Name, syms
+from ..fixer_util import Name
class FixNonzero(fixer_base.BaseFix):
BM_compatible = True
diff --git a/Lib/lib2to3/fixes/fix_print.py b/Lib/lib2to3/fixes/fix_print.py
index a1fe2f5..8780322 100644
--- a/Lib/lib2to3/fixes/fix_print.py
+++ b/Lib/lib2to3/fixes/fix_print.py
@@ -18,7 +18,7 @@ from .. import patcomp
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
-from ..fixer_util import Name, Call, Comma, String, is_tuple
+from ..fixer_util import Name, Call, Comma, String
parend_expr = patcomp.compile_pattern(
diff --git a/Lib/lib2to3/fixes/fix_types.py b/Lib/lib2to3/fixes/fix_types.py
index db34104..67bf51f 100644
--- a/Lib/lib2to3/fixes/fix_types.py
+++ b/Lib/lib2to3/fixes/fix_types.py
@@ -20,7 +20,6 @@ There should be another fixer that handles at least the following constants:
"""
# Local imports
-from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name
@@ -42,7 +41,7 @@ _TYPE_MAPPING = {
'NotImplementedType' : 'type(NotImplemented)',
'SliceType' : 'slice',
'StringType': 'bytes', # XXX ?
- 'StringTypes' : 'str', # XXX ?
+ 'StringTypes' : '(str,)', # XXX ?
'TupleType': 'tuple',
'TypeType' : 'type',
'UnicodeType': 'str',
diff --git a/Lib/lib2to3/fixes/fix_urllib.py b/Lib/lib2to3/fixes/fix_urllib.py
index 1481cd9..5a36049 100644
--- a/Lib/lib2to3/fixes/fix_urllib.py
+++ b/Lib/lib2to3/fixes/fix_urllib.py
@@ -6,7 +6,6 @@
# Local imports
from lib2to3.fixes.fix_imports import alternates, FixImports
-from lib2to3 import fixer_base
from lib2to3.fixer_util import (Name, Comma, FromImport, Newline,
find_indentation, Node, syms)
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 0728083..c5a1aa2 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -8,8 +8,6 @@ recursively descend down directories. Imported as a module, this
provides infrastructure to write your own refactoring tool.
"""
-from __future__ import with_statement
-
__author__ = "Guido van Rossum <guido@python.org>"
@@ -26,7 +24,6 @@ from itertools import chain
from .pgen2 import driver, tokenize, token
from .fixer_util import find_root
from . import pytree, pygram
-from . import btm_utils as bu
from . import btm_matcher as bm
diff --git a/Lib/lib2to3/tests/data/py3_test_grammar.py b/Lib/lib2to3/tests/data/py3_test_grammar.py
index c0bf7f2..cf31a54 100644
--- a/Lib/lib2to3/tests/data/py3_test_grammar.py
+++ b/Lib/lib2to3/tests/data/py3_test_grammar.py
@@ -319,7 +319,7 @@ class GrammarTests(unittest.TestCase):
def f(x) -> list: pass
self.assertEquals(f.__annotations__, {'return': list})
- # test MAKE_CLOSURE with a variety of oparg's
+ # test closures with a variety of oparg's
closure = 1
def f(): return closure
def f(x=1): return closure
diff --git a/Lib/lib2to3/tests/support.py b/Lib/lib2to3/tests/support.py
index 0897177..ae7cfe8 100644
--- a/Lib/lib2to3/tests/support.py
+++ b/Lib/lib2to3/tests/support.py
@@ -3,10 +3,8 @@
# Python imports
import unittest
-import sys
import os
import os.path
-import re
from textwrap import dedent
# Local imports
diff --git a/Lib/lib2to3/tests/test_all_fixers.py b/Lib/lib2to3/tests/test_all_fixers.py
index 15079fe..c0507cf 100644
--- a/Lib/lib2to3/tests/test_all_fixers.py
+++ b/Lib/lib2to3/tests/test_all_fixers.py
@@ -10,7 +10,6 @@ import unittest
import test.support
# Local imports
-from lib2to3 import refactor
from . import support
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
index 640dcef..b3f2680 100644
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -2,12 +2,11 @@
# Python imports
import os
-import unittest
from itertools import chain
from operator import itemgetter
# Local imports
-from lib2to3 import pygram, pytree, refactor, fixer_util
+from lib2to3 import pygram, fixer_util
from lib2to3.tests import support
@@ -3234,6 +3233,10 @@ class Test_types(FixerTestCase):
a = """type(None)"""
self.check(b, a)
+ b = "types.StringTypes"
+ a = "(str,)"
+ self.check(b, a)
+
class Test_idioms(FixerTestCase):
fixer = "idioms"
diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
index e4a0194..9a969e8 100644
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -8,7 +8,7 @@ test_grammar.py files from both Python 2 and Python 3.
# Testing imports
from . import support
-from .support import driver, test_dir
+from .support import driver
from test.support import verbose
# Python imports
@@ -134,6 +134,24 @@ class TestAsyncAwait(GrammarTest):
""")
self.validate("""async def foo():
+ [i async for i in b]
+ """)
+
+ self.validate("""async def foo():
+ {i for i in b
+ async for i in a if await i
+ for b in i}
+ """)
+
+ self.validate("""async def foo():
+ [await i for i in b if await c]
+ """)
+
+ self.validate("""async def foo():
+ [ i for i in b if c]
+ """)
+
+ self.validate("""async def foo():
def foo(): pass
@@ -272,6 +290,36 @@ class TestFunctionAnnotations(GrammarTest):
self.validate(s)
+# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.test_var_annot
+class TestVarAnnotations(GrammarTest):
+ def test_1(self):
+ self.validate("var1: int = 5")
+
+ def test_2(self):
+ self.validate("var2: [int, str]")
+
+ def test_3(self):
+ self.validate("def f():\n"
+ " st: str = 'Hello'\n"
+ " a.b: int = (1, 2)\n"
+ " return st\n")
+
+ def test_4(self):
+ self.validate("def fbad():\n"
+ " x: int\n"
+ " print(x)\n")
+
+ def test_5(self):
+ self.validate("class C:\n"
+ " x: int\n"
+ " s: str = 'attr'\n"
+ " z = 2\n"
+ " def __init__(self, x):\n"
+ " self.x: int = x\n")
+
+ def test_6(self):
+ self.validate("lst: List[int] = []")
+
class TestExcept(GrammarTest):
def test_new(self):
s = """
diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/lib2to3/tests/test_pytree.py
index 4d585a8..177126d 100644
--- a/Lib/lib2to3/tests/test_pytree.py
+++ b/Lib/lib2to3/tests/test_pytree.py
@@ -9,11 +9,6 @@ more helpful than printing of (the first line of) the docstring,
especially when debugging a test.
"""
-from __future__ import with_statement
-
-import sys
-import warnings
-
# Testing imports
from . import support
diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/lib2to3/tests/test_refactor.py
index 8563001..e9bae5e 100644
--- a/Lib/lib2to3/tests/test_refactor.py
+++ b/Lib/lib2to3/tests/test_refactor.py
@@ -2,24 +2,18 @@
Unit tests for refactor.py.
"""
-from __future__ import with_statement
-
import sys
import os
import codecs
-import operator
import io
import re
import tempfile
import shutil
import unittest
-import warnings
from lib2to3 import refactor, pygram, fixer_base
from lib2to3.pgen2 import token
-from . import support
-
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers")
diff --git a/Lib/lib2to3/tests/test_util.py b/Lib/lib2to3/tests/test_util.py
index d2be82c..c6c6139 100644
--- a/Lib/lib2to3/tests/test_util.py
+++ b/Lib/lib2to3/tests/test_util.py
@@ -3,9 +3,6 @@
# Testing imports
from . import support
-# Python imports
-import os.path
-
# Local imports
from lib2to3.pytree import Node, Leaf
from lib2to3 import fixer_util
diff --git a/Lib/locale.py b/Lib/locale.py
index 6d59cd8..4de0090 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -302,12 +302,16 @@ def str(val):
def delocalize(string):
"Parses a string as a normalized number according to the locale settings."
+
+ conv = localeconv()
+
#First, get rid of the grouping
- ts = localeconv()['thousands_sep']
+ ts = conv['thousands_sep']
if ts:
string = string.replace(ts, '')
+
#next, replace the decimal point with a dot
- dd = localeconv()['decimal_point']
+ dd = conv['decimal_point']
if dd:
string = string.replace(dd, '.')
return string
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 22744e1..2590d65 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -33,8 +33,9 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'StreamHandler', 'WARN', 'WARNING', 'addLevelName', 'basicConfig',
'captureWarnings', 'critical', 'debug', 'disable', 'error',
'exception', 'fatal', 'getLevelName', 'getLogger', 'getLoggerClass',
- 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'warn', 'warning',
- 'getLogRecordFactory', 'setLogRecordFactory', 'lastResort']
+ 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'shutdown',
+ 'warn', 'warning', 'getLogRecordFactory', 'setLogRecordFactory',
+ 'lastResort', 'raiseExceptions']
try:
import threading
@@ -107,6 +108,7 @@ _levelToName = {
}
_nameToLevel = {
'CRITICAL': CRITICAL,
+ 'FATAL': FATAL,
'ERROR': ERROR,
'WARN': WARNING,
'WARNING': WARNING,
@@ -935,6 +937,10 @@ class Handler(Filterer):
finally:
del t, v, tb
+ def __repr__(self):
+ level = getLevelName(self.level)
+ return '<%s (%s)>' % (self.__class__.__name__, level)
+
class StreamHandler(Handler):
"""
A handler class which writes logging records, appropriately formatted,
@@ -986,6 +992,14 @@ class StreamHandler(Handler):
except Exception:
self.handleError(record)
+ def __repr__(self):
+ level = getLevelName(self.level)
+ name = getattr(self.stream, 'name', '')
+ if name:
+ name += ' '
+ return '<%s %s(%s)>' % (self.__class__.__name__, name, level)
+
+
class FileHandler(StreamHandler):
"""
A handler class which writes formatted logging records to disk files.
@@ -994,6 +1008,8 @@ class FileHandler(StreamHandler):
"""
Open the specified file and use it as the stream for logging.
"""
+ # Issue #27493: add support for Path objects to be passed in
+ filename = os.fspath(filename)
#keep the absolute path, otherwise derived classes which use this
#may come a cropper when the current directory changes
self.baseFilename = os.path.abspath(filename)
@@ -1048,6 +1064,11 @@ class FileHandler(StreamHandler):
self.stream = self._open()
StreamHandler.emit(self, record)
+ def __repr__(self):
+ level = getLevelName(self.level)
+ return '<%s %s (%s)>' % (self.__class__.__name__, self.baseFilename, level)
+
+
class _StderrHandler(StreamHandler):
"""
This class is like a StreamHandler using sys.stderr, but always uses
@@ -1540,6 +1561,11 @@ class Logger(Filterer):
suffix = '.'.join((self.name, suffix))
return self.manager.getLogger(suffix)
+ def __repr__(self):
+ level = getLevelName(self.getEffectiveLevel())
+ return '<%s %s (%s)>' % (self.__class__.__name__, self.name, level)
+
+
class RootLogger(Logger):
"""
A root logger is not that different to any other logger, except that
@@ -1666,6 +1692,11 @@ class LoggerAdapter(object):
"""
return self.logger.hasHandlers()
+ def __repr__(self):
+ logger = self.logger
+ level = getLevelName(logger.getEffectiveLevel())
+ return '<%s %s (%s)>' % (self.__class__.__name__, logger.name, level)
+
root = RootLogger(WARNING)
Logger.root = root
Logger.manager = Manager(Logger.root)
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index c39a56f..7d77973 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -246,6 +246,9 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
self.extMatch = re.compile(self.extMatch, re.ASCII)
self.interval = self.interval * interval # multiply by units requested
+ # The following line added because the filename passed in could be a
+ # path object (see Issue #27493), but self.baseFilename will be a string
+ filename = self.baseFilename
if os.path.exists(filename):
t = os.stat(filename)[ST_MTIME]
else:
@@ -440,11 +443,11 @@ class WatchedFileHandler(logging.FileHandler):
sres = os.fstat(self.stream.fileno())
self.dev, self.ino = sres[ST_DEV], sres[ST_INO]
- def emit(self, record):
+ def reopenIfNeeded(self):
"""
- Emit a record.
+ Reopen log file if needed.
- First check if the underlying file has changed, and if it
+ Checks if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
@@ -467,6 +470,15 @@ class WatchedFileHandler(logging.FileHandler):
# open a new file handle and get new stat info from that fd
self.stream = self._open()
self._statstream()
+
+ def emit(self, record):
+ """
+ Emit a record.
+
+ If underlying file has changed, reopen the file before emitting the
+ record to it.
+ """
+ self.reopenIfNeeded()
logging.FileHandler.emit(self, record)
@@ -1229,17 +1241,25 @@ class MemoryHandler(BufferingHandler):
flushing them to a target handler. Flushing occurs whenever the buffer
is full, or when an event of a certain severity or greater is seen.
"""
- def __init__(self, capacity, flushLevel=logging.ERROR, target=None):
+ def __init__(self, capacity, flushLevel=logging.ERROR, target=None,
+ flushOnClose=True):
"""
Initialize the handler with the buffer size, the level at which
flushing should occur and an optional target.
Note that without a target being set either here or via setTarget(),
a MemoryHandler is no use to anyone!
+
+ The ``flushOnClose`` argument is ``True`` for backward compatibility
+ reasons - the old behaviour is that when the handler is closed, the
+ buffer is flushed, even if the flush level hasn't been exceeded nor the
+ capacity exceeded. To prevent this, set ``flushOnClose`` to ``False``.
"""
BufferingHandler.__init__(self, capacity)
self.flushLevel = flushLevel
self.target = target
+ # See Issue #26559 for why this has been added
+ self.flushOnClose = flushOnClose
def shouldFlush(self, record):
"""
@@ -1273,10 +1293,12 @@ class MemoryHandler(BufferingHandler):
def close(self):
"""
- Flush, set the target to None and lose the buffer.
+ Flush, if appropriately configured, set the target to None and lose the
+ buffer.
"""
try:
- self.flush()
+ if self.flushOnClose:
+ self.flush()
finally:
self.acquire()
try:
diff --git a/Lib/lzma.py b/Lib/lzma.py
index 7dff1c3..0817b87 100644
--- a/Lib/lzma.py
+++ b/Lib/lzma.py
@@ -23,6 +23,7 @@ __all__ = [
import builtins
import io
+import os
from _lzma import *
from _lzma import _encode_filter_properties, _decode_filter_properties
import _compression
@@ -49,9 +50,10 @@ class LZMAFile(_compression.BaseStream):
format=None, check=-1, preset=None, filters=None):
"""Open an LZMA-compressed file in binary mode.
- filename can be either an actual file name (given as a str or
- bytes object), in which case the named file is opened, or it can
- be an existing file object to read from or write to.
+ filename can be either an actual file name (given as a str,
+ bytes, or PathLike object), in which case the named file is
+ opened, or it can be an existing file object to read from or
+ write to.
mode can be "r" for reading (default), "w" for (over)writing,
"x" for creating exclusively, or "a" for appending. These can
@@ -112,7 +114,7 @@ class LZMAFile(_compression.BaseStream):
else:
raise ValueError("Invalid mode: {!r}".format(mode))
- if isinstance(filename, (str, bytes)):
+ if isinstance(filename, (str, bytes, os.PathLike)):
if "b" not in mode:
mode += "b"
self._fp = builtins.open(filename, mode)
@@ -122,7 +124,7 @@ class LZMAFile(_compression.BaseStream):
self._fp = filename
self._mode = mode_code
else:
- raise TypeError("filename must be a str or bytes object, or a file")
+ raise TypeError("filename must be a str, bytes, file or PathLike object")
if self._mode == _MODE_READ:
raw = _compression.DecompressReader(self._fp, LZMADecompressor,
@@ -263,9 +265,9 @@ def open(filename, mode="rb", *,
encoding=None, errors=None, newline=None):
"""Open an LZMA-compressed file in binary or text mode.
- filename can be either an actual file name (given as a str or bytes
- object), in which case the named file is opened, or it can be an
- existing file object to read from or write to.
+ filename can be either an actual file name (given as a str, bytes,
+ or PathLike object), in which case the named file is opened, or it
+ can be an existing file object to read from or write to.
The mode argument can be "r", "rb" (default), "w", "wb", "x", "xb",
"a", or "ab" for binary mode, or "rt", "wt", "xt", or "at" for text
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 0270e25..0e23987 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -23,9 +23,10 @@ try:
except ImportError:
fcntl = None
-__all__ = [ 'Mailbox', 'Maildir', 'mbox', 'MH', 'Babyl', 'MMDF',
- 'Message', 'MaildirMessage', 'mboxMessage', 'MHMessage',
- 'BabylMessage', 'MMDFMessage']
+__all__ = ['Mailbox', 'Maildir', 'mbox', 'MH', 'Babyl', 'MMDF',
+ 'Message', 'MaildirMessage', 'mboxMessage', 'MHMessage',
+ 'BabylMessage', 'MMDFMessage', 'Error', 'NoSuchMailboxError',
+ 'NotEmptyError', 'ExternalClashError', 'FormatError']
linesep = os.linesep.encode('ascii')
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 0be76ad..9a88680 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -33,8 +33,10 @@ except ImportError:
_winreg = None
__all__ = [
- "guess_type","guess_extension","guess_all_extensions",
- "add_type","read_mime_types","init"
+ "knownfiles", "inited", "MimeTypes",
+ "guess_type", "guess_all_extensions", "guess_extension",
+ "add_type", "init", "read_mime_types",
+ "suffix_map", "encodings_map", "types_map", "common_types"
]
knownfiles = [
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py
index 8103502..e220315 100644
--- a/Lib/modulefinder.py
+++ b/Lib/modulefinder.py
@@ -10,7 +10,7 @@ import types
import struct
import warnings
with warnings.catch_warnings():
- warnings.simplefilter('ignore', PendingDeprecationWarning)
+ warnings.simplefilter('ignore', DeprecationWarning)
import imp
LOAD_CONST = dis.opmap['LOAD_CONST']
@@ -336,8 +336,7 @@ class ModuleFinder:
fullname = name + "." + sub
self._add_badmodule(fullname, caller)
- def scan_opcodes_25(self, co,
- unpack = struct.unpack):
+ def scan_opcodes(self, co):
# Scan the code, and yield 'interesting' opcode combinations
code = co.co_code
names = co.co_names
@@ -360,7 +359,7 @@ class ModuleFinder:
def scan_code(self, co, m):
code = co.co_code
- scanner = self.scan_opcodes_25
+ scanner = self.scan_opcodes
for what, args in scanner(co):
if what == "store":
name, = args
diff --git a/Lib/msilib/__init__.py b/Lib/msilib/__init__.py
index 6d0a28f..f0370c2 100644
--- a/Lib/msilib/__init__.py
+++ b/Lib/msilib/__init__.py
@@ -1,7 +1,7 @@
# Copyright (C) 2005 Martin v. Löwis
# Licensed to PSF under a Contributor Agreement.
from _msi import *
-import glob
+import fnmatch
import os
import re
import string
@@ -289,7 +289,7 @@ class Directory:
def make_short(self, file):
oldfile = file
file = file.replace('+', '_')
- file = ''.join(c for c in file if not c in ' "/\[]:;=,')
+ file = ''.join(c for c in file if not c in r' "/\[]:;=,')
parts = file.split(".")
if len(parts) > 1:
prefix = "".join(parts[:-1]).upper()
@@ -379,7 +379,13 @@ class Directory:
def glob(self, pattern, exclude = None):
"""Add a list of files to the current component as specified in the
glob pattern. Individual files can be excluded in the exclude list."""
- files = glob.glob1(self.absolute, pattern)
+ try:
+ files = os.listdir(self.absolute)
+ except OSError:
+ return []
+ if pattern[:1] != '.':
+ files = (f for f in files if f[0] != '.')
+ files = fnmatch.filter(files, pattern)
for f in files:
if exclude and f in exclude: continue
self.add_file(f)
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
index d0a1b86..d49e8f0 100644
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -20,11 +20,11 @@ import itertools
import _multiprocessing
-from . import reduction
from . import util
from . import AuthenticationError, BufferTooShort
-from .reduction import ForkingPickler
+from .context import reduction
+_ForkingPickler = reduction.ForkingPickler
try:
import _winapi
@@ -203,7 +203,7 @@ class _ConnectionBase:
"""Send a (picklable) object"""
self._check_closed()
self._check_writable()
- self._send_bytes(ForkingPickler.dumps(obj))
+ self._send_bytes(_ForkingPickler.dumps(obj))
def recv_bytes(self, maxlength=None):
"""
@@ -248,7 +248,7 @@ class _ConnectionBase:
self._check_closed()
self._check_readable()
buf = self._recv_bytes()
- return ForkingPickler.loads(buf.getbuffer())
+ return _ForkingPickler.loads(buf.getbuffer())
def poll(self, timeout=0.0):
"""Whether there is any input available to be read"""
diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py
index 63849f9..09455e2 100644
--- a/Lib/multiprocessing/context.py
+++ b/Lib/multiprocessing/context.py
@@ -3,6 +3,7 @@ import sys
import threading
from . import process
+from . import reduction
__all__ = [] # things are copied from here to __init__.py
@@ -198,6 +199,16 @@ class BaseContext(object):
def set_start_method(self, method=None):
raise ValueError('cannot set start method of concrete context')
+ @property
+ def reducer(self):
+ '''Controls how objects will be reduced to a form that can be
+ shared with other processes.'''
+ return globals().get('reduction')
+
+ @reducer.setter
+ def reducer(self, reduction):
+ globals()['reduction'] = reduction
+
def _check_available(self):
pass
@@ -245,7 +256,6 @@ class DefaultContext(BaseContext):
if sys.platform == 'win32':
return ['spawn']
else:
- from . import reduction
if reduction.HAVE_SEND_HANDLE:
return ['fork', 'spawn', 'forkserver']
else:
@@ -292,7 +302,6 @@ if sys.platform != 'win32':
_name = 'forkserver'
Process = ForkServerProcess
def _check_available(self):
- from . import reduction
if not reduction.HAVE_SEND_HANDLE:
raise ValueError('forkserver start method not available')
diff --git a/Lib/multiprocessing/forkserver.py b/Lib/multiprocessing/forkserver.py
index ad01ede..f2c179e 100644
--- a/Lib/multiprocessing/forkserver.py
+++ b/Lib/multiprocessing/forkserver.py
@@ -9,7 +9,7 @@ import threading
from . import connection
from . import process
-from . import reduction
+from .context import reduction
from . import semaphore_tracker
from . import spawn
from . import util
diff --git a/Lib/multiprocessing/heap.py b/Lib/multiprocessing/heap.py
index 44d9638..4433215 100644
--- a/Lib/multiprocessing/heap.py
+++ b/Lib/multiprocessing/heap.py
@@ -14,8 +14,7 @@ import sys
import tempfile
import threading
-from . import context
-from . import reduction
+from .context import reduction, assert_spawning
from . import util
__all__ = ['BufferWrapper']
@@ -48,7 +47,7 @@ if sys.platform == 'win32':
self._state = (self.size, self.name)
def __getstate__(self):
- context.assert_spawning(self)
+ assert_spawning(self)
return self._state
def __setstate__(self, state):
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index b175470..b9ce84b 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -23,10 +23,9 @@ from time import time as _time
from traceback import format_exc
from . import connection
-from . import context
+from .context import reduction, get_spawning_popen
from . import pool
from . import process
-from . import reduction
from . import util
from . import get_context
@@ -142,7 +141,8 @@ class Server(object):
self.id_to_obj = {'0': (None, ())}
self.id_to_refcount = {}
- self.mutex = threading.RLock()
+ self.id_to_local_proxy_obj = {}
+ self.mutex = threading.Lock()
def serve_forever(self):
'''
@@ -227,7 +227,14 @@ class Server(object):
methodname = obj = None
request = recv()
ident, methodname, args, kwds = request
- obj, exposed, gettypeid = id_to_obj[ident]
+ try:
+ obj, exposed, gettypeid = id_to_obj[ident]
+ except KeyError as ke:
+ try:
+ obj, exposed, gettypeid = \
+ self.id_to_local_proxy_obj[ident]
+ except KeyError as second_ke:
+ raise ke
if methodname not in exposed:
raise AttributeError(
@@ -308,7 +315,7 @@ class Server(object):
'''
with self.mutex:
result = []
- keys = list(self.id_to_obj.keys())
+ keys = list(self.id_to_refcount.keys())
keys.sort()
for ident in keys:
if ident != '0':
@@ -321,7 +328,8 @@ class Server(object):
'''
Number of shared objects
'''
- return len(self.id_to_obj) - 1 # don't count ident='0'
+ # Doesn't use (len(self.id_to_obj) - 1) as we shouldn't count ident='0'
+ return len(self.id_to_refcount)
def shutdown(self, c):
'''
@@ -363,13 +371,9 @@ class Server(object):
self.id_to_obj[ident] = (obj, set(exposed), method_to_typeid)
if ident not in self.id_to_refcount:
self.id_to_refcount[ident] = 0
- # increment the reference count immediately, to avoid
- # this object being garbage collected before a Proxy
- # object for it can be created. The caller of create()
- # is responsible for doing a decref once the Proxy object
- # has been created.
- self.incref(c, ident)
- return ident, tuple(exposed)
+
+ self.incref(c, ident)
+ return ident, tuple(exposed)
def get_methods(self, c, token):
'''
@@ -387,15 +391,45 @@ class Server(object):
def incref(self, c, ident):
with self.mutex:
- self.id_to_refcount[ident] += 1
+ try:
+ self.id_to_refcount[ident] += 1
+ except KeyError as ke:
+ # If no external references exist but an internal (to the
+ # manager) still does and a new external reference is created
+ # from it, restore the manager's tracking of it from the
+ # previously stashed internal ref.
+ if ident in self.id_to_local_proxy_obj:
+ self.id_to_refcount[ident] = 1
+ self.id_to_obj[ident] = \
+ self.id_to_local_proxy_obj[ident]
+ obj, exposed, gettypeid = self.id_to_obj[ident]
+ util.debug('Server re-enabled tracking & INCREF %r', ident)
+ else:
+ raise ke
def decref(self, c, ident):
+ if ident not in self.id_to_refcount and \
+ ident in self.id_to_local_proxy_obj:
+ util.debug('Server DECREF skipping %r', ident)
+ return
+
with self.mutex:
assert self.id_to_refcount[ident] >= 1
self.id_to_refcount[ident] -= 1
if self.id_to_refcount[ident] == 0:
- del self.id_to_obj[ident], self.id_to_refcount[ident]
- util.debug('disposing of obj with id %r', ident)
+ del self.id_to_refcount[ident]
+
+ if ident not in self.id_to_refcount:
+ # Two-step process in case the object turns out to contain other
+ # proxy objects (e.g. a managed list of managed lists).
+ # Otherwise, deleting self.id_to_obj[ident] would trigger the
+ # deleting of the stored value (another managed object) which would
+ # in turn attempt to acquire the mutex that is already held here.
+ self.id_to_obj[ident] = (None, (), None) # thread-safe
+ util.debug('disposing of obj with id %r', ident)
+ with self.mutex:
+ del self.id_to_obj[ident]
+
#
# Class to represent state of a manager
@@ -658,7 +692,7 @@ class BaseProxy(object):
_mutex = util.ForkAwareThreadLock()
def __init__(self, token, serializer, manager=None,
- authkey=None, exposed=None, incref=True):
+ authkey=None, exposed=None, incref=True, manager_owned=False):
with BaseProxy._mutex:
tls_idset = BaseProxy._address_to_local.get(token.address, None)
if tls_idset is None:
@@ -680,6 +714,12 @@ class BaseProxy(object):
self._serializer = serializer
self._Client = listener_client[serializer][1]
+ # Should be set to True only when a proxy object is being created
+ # on the manager server; primary use case: nested proxy objects.
+ # RebuildProxy detects when a proxy is being created on the manager
+ # and sets this value appropriately.
+ self._owned_by_manager = manager_owned
+
if authkey is not None:
self._authkey = process.AuthenticationString(authkey)
elif self._manager is not None:
@@ -738,6 +778,10 @@ class BaseProxy(object):
return self._callmethod('#GETVALUE')
def _incref(self):
+ if self._owned_by_manager:
+ util.debug('owned_by_manager skipped INCREF of %r', self._token.id)
+ return
+
conn = self._Client(self._token.address, authkey=self._authkey)
dispatch(conn, None, 'incref', (self._id,))
util.debug('INCREF %r', self._token.id)
@@ -788,7 +832,7 @@ class BaseProxy(object):
def __reduce__(self):
kwds = {}
- if context.get_spawning_popen() is not None:
+ if get_spawning_popen() is not None:
kwds['authkey'] = self._authkey
if getattr(self, '_isauto', False):
@@ -822,19 +866,19 @@ class BaseProxy(object):
def RebuildProxy(func, token, serializer, kwds):
'''
Function used for unpickling proxy objects.
-
- If possible the shared object is returned, or otherwise a proxy for it.
'''
server = getattr(process.current_process(), '_manager_server', None)
-
if server and server.address == token.address:
- return server.id_to_obj[token.id][0]
- else:
- incref = (
- kwds.pop('incref', True) and
- not getattr(process.current_process(), '_inheriting', False)
- )
- return func(token, serializer, incref=incref, **kwds)
+ util.debug('Rebuild a proxy owned by manager, token=%r', token)
+ kwds['manager_owned'] = True
+ if token.id not in server.id_to_local_proxy_obj:
+ server.id_to_local_proxy_obj[token.id] = \
+ server.id_to_obj[token.id]
+ incref = (
+ kwds.pop('incref', True) and
+ not getattr(process.current_process(), '_inheriting', False)
+ )
+ return func(token, serializer, incref=incref, **kwds)
#
# Functions to create proxies and proxy types
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index 6d25469..ffdf426 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -638,22 +638,26 @@ class MapResult(ApplyResult):
self._number_left = length//chunksize + bool(length % chunksize)
def _set(self, i, success_result):
+ self._number_left -= 1
success, result = success_result
- if success:
+ if success and self._success:
self._value[i*self._chunksize:(i+1)*self._chunksize] = result
- self._number_left -= 1
if self._number_left == 0:
if self._callback:
self._callback(self._value)
del self._cache[self._job]
self._event.set()
else:
- self._success = False
- self._value = result
- if self._error_callback:
- self._error_callback(self._value)
- del self._cache[self._job]
- self._event.set()
+ if not success and self._success:
+ # only store first exception
+ self._success = False
+ self._value = result
+ if self._number_left == 0:
+ # only consider the result ready once all jobs are done
+ if self._error_callback:
+ self._error_callback(self._value)
+ del self._cache[self._job]
+ self._event.set()
#
# Class whose instances are returned by `Pool.imap()`
diff --git a/Lib/multiprocessing/popen_forkserver.py b/Lib/multiprocessing/popen_forkserver.py
index e792194..222db2d 100644
--- a/Lib/multiprocessing/popen_forkserver.py
+++ b/Lib/multiprocessing/popen_forkserver.py
@@ -1,10 +1,9 @@
import io
import os
-from . import reduction
+from .context import reduction, set_spawning_popen
if not reduction.HAVE_SEND_HANDLE:
raise ImportError('No support for sending fds between processes')
-from . import context
from . import forkserver
from . import popen_fork
from . import spawn
@@ -42,12 +41,12 @@ class Popen(popen_fork.Popen):
def _launch(self, process_obj):
prep_data = spawn.get_preparation_data(process_obj._name)
buf = io.BytesIO()
- context.set_spawning_popen(self)
+ set_spawning_popen(self)
try:
reduction.dump(prep_data, buf)
reduction.dump(process_obj, buf)
finally:
- context.set_spawning_popen(None)
+ set_spawning_popen(None)
self.sentinel, w = forkserver.connect_to_new_process(self._fds)
util.Finalize(self, os.close, (self.sentinel,))
diff --git a/Lib/multiprocessing/popen_spawn_posix.py b/Lib/multiprocessing/popen_spawn_posix.py
index 6b0a8d6..98f8f0a 100644
--- a/Lib/multiprocessing/popen_spawn_posix.py
+++ b/Lib/multiprocessing/popen_spawn_posix.py
@@ -1,9 +1,8 @@
import io
import os
-from . import context
+from .context import reduction, set_spawning_popen
from . import popen_fork
-from . import reduction
from . import spawn
from . import util
@@ -42,12 +41,12 @@ class Popen(popen_fork.Popen):
self._fds.append(tracker_fd)
prep_data = spawn.get_preparation_data(process_obj._name)
fp = io.BytesIO()
- context.set_spawning_popen(self)
+ set_spawning_popen(self)
try:
reduction.dump(prep_data, fp)
reduction.dump(process_obj, fp)
finally:
- context.set_spawning_popen(None)
+ set_spawning_popen(None)
parent_r = child_w = child_r = parent_w = None
try:
diff --git a/Lib/multiprocessing/popen_spawn_win32.py b/Lib/multiprocessing/popen_spawn_win32.py
index 3b53068..6fd588f 100644
--- a/Lib/multiprocessing/popen_spawn_win32.py
+++ b/Lib/multiprocessing/popen_spawn_win32.py
@@ -4,9 +4,8 @@ import signal
import sys
import _winapi
-from . import context
+from .context import reduction, get_spawning_popen, set_spawning_popen
from . import spawn
-from . import reduction
from . import util
__all__ = ['Popen']
@@ -60,15 +59,15 @@ class Popen(object):
util.Finalize(self, _winapi.CloseHandle, (self.sentinel,))
# send information to child
- context.set_spawning_popen(self)
+ set_spawning_popen(self)
try:
reduction.dump(prep_data, to_child)
reduction.dump(process_obj, to_child)
finally:
- context.set_spawning_popen(None)
+ set_spawning_popen(None)
def duplicate_for_child(self, handle):
- assert self is context.get_spawning_popen()
+ assert self is get_spawning_popen()
return reduction.duplicate(handle, self.sentinel)
def wait(self, timeout=None):
diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py
index 786a303..dda03dd 100644
--- a/Lib/multiprocessing/queues.py
+++ b/Lib/multiprocessing/queues.py
@@ -23,9 +23,9 @@ import _multiprocessing
from . import connection
from . import context
+_ForkingPickler = context.reduction.ForkingPickler
from .util import debug, info, Finalize, register_after_fork, is_exiting
-from .reduction import ForkingPickler
#
# Queue type using a pipe, buffer and thread
@@ -110,7 +110,7 @@ class Queue(object):
finally:
self._rlock.release()
# unserialize the data after having released the lock
- return ForkingPickler.loads(res)
+ return _ForkingPickler.loads(res)
def qsize(self):
# Raises NotImplementedError on Mac OSX because of broken sem_getvalue()
@@ -238,7 +238,7 @@ class Queue(object):
return
# serialize the data before acquiring the lock
- obj = ForkingPickler.dumps(obj)
+ obj = _ForkingPickler.dumps(obj)
if wacquire is None:
send_bytes(obj)
else:
@@ -342,11 +342,11 @@ class SimpleQueue(object):
with self._rlock:
res = self._reader.recv_bytes()
# unserialize the data after having released the lock
- return ForkingPickler.loads(res)
+ return _ForkingPickler.loads(res)
def put(self, obj):
# serialize the data before acquiring the lock
- obj = ForkingPickler.dumps(obj)
+ obj = _ForkingPickler.dumps(obj)
if self._wlock is None:
# writes to a message oriented win32 pipe are atomic
self._writer.send_bytes(obj)
diff --git a/Lib/multiprocessing/reduction.py b/Lib/multiprocessing/reduction.py
index 8f209b4..c043c9a 100644
--- a/Lib/multiprocessing/reduction.py
+++ b/Lib/multiprocessing/reduction.py
@@ -7,6 +7,7 @@
# Licensed to PSF under a Contributor Agreement.
#
+from abc import ABCMeta, abstractmethod
import copyreg
import functools
import io
@@ -238,3 +239,36 @@ else:
fd = df.detach()
return socket.socket(family, type, proto, fileno=fd)
register(socket.socket, _reduce_socket)
+
+
+class AbstractReducer(metaclass=ABCMeta):
+ '''Abstract base class for use in implementing a Reduction class
+ suitable for use in replacing the standard reduction mechanism
+ used in multiprocessing.'''
+ ForkingPickler = ForkingPickler
+ register = register
+ dump = dump
+ send_handle = send_handle
+ recv_handle = recv_handle
+
+ if sys.platform == 'win32':
+ steal_handle = steal_handle
+ duplicate = duplicate
+ DupHandle = DupHandle
+ else:
+ sendfds = sendfds
+ recvfds = recvfds
+ DupFd = DupFd
+
+ _reduce_method = _reduce_method
+ _reduce_method_descriptor = _reduce_method_descriptor
+ _rebuild_partial = _rebuild_partial
+ _reduce_socket = _reduce_socket
+ _rebuild_socket = _rebuild_socket
+
+ def __init__(self, *args):
+ register(type(_C().f), _reduce_method)
+ register(type(list.append), _reduce_method_descriptor)
+ register(type(int.__add__), _reduce_method_descriptor)
+ register(functools.partial, _reduce_partial)
+ register(socket.socket, _reduce_socket)
diff --git a/Lib/multiprocessing/resource_sharer.py b/Lib/multiprocessing/resource_sharer.py
index 5e46fc6..e44a728 100644
--- a/Lib/multiprocessing/resource_sharer.py
+++ b/Lib/multiprocessing/resource_sharer.py
@@ -15,7 +15,7 @@ import sys
import threading
from . import process
-from . import reduction
+from .context import reduction
from . import util
__all__ = ['stop']
diff --git a/Lib/multiprocessing/sharedctypes.py b/Lib/multiprocessing/sharedctypes.py
index 4258f59..25cbcf2 100644
--- a/Lib/multiprocessing/sharedctypes.py
+++ b/Lib/multiprocessing/sharedctypes.py
@@ -13,8 +13,8 @@ import weakref
from . import heap
from . import get_context
-from .context import assert_spawning
-from .reduction import ForkingPickler
+from .context import reduction, assert_spawning
+_ForkingPickler = reduction.ForkingPickler
__all__ = ['RawValue', 'RawArray', 'Value', 'Array', 'copy', 'synchronized']
@@ -134,7 +134,7 @@ def reduce_ctype(obj):
def rebuild_ctype(type_, wrapper, length):
if length is not None:
type_ = type_ * length
- ForkingPickler.register(type_, reduce_ctype)
+ _ForkingPickler.register(type_, reduce_ctype)
buf = wrapper.create_memoryview()
obj = type_.from_buffer(buf)
obj._wrapper = wrapper
diff --git a/Lib/multiprocessing/spawn.py b/Lib/multiprocessing/spawn.py
index 4d76951..dfb9f65 100644
--- a/Lib/multiprocessing/spawn.py
+++ b/Lib/multiprocessing/spawn.py
@@ -9,13 +9,13 @@
#
import os
-import pickle
import sys
import runpy
import types
from . import get_start_method, set_start_method
from . import process
+from .context import reduction
from . import util
__all__ = ['_main', 'freeze_support', 'set_executable', 'get_executable',
@@ -96,8 +96,7 @@ def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None):
assert is_forking(sys.argv)
if sys.platform == 'win32':
import msvcrt
- from .reduction import steal_handle
- new_handle = steal_handle(parent_pid, pipe_handle)
+ new_handle = reduction.steal_handle(parent_pid, pipe_handle)
fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY)
else:
from . import semaphore_tracker
@@ -111,9 +110,9 @@ def _main(fd):
with os.fdopen(fd, 'rb', closefd=True) as from_parent:
process.current_process()._inheriting = True
try:
- preparation_data = pickle.load(from_parent)
+ preparation_data = reduction.pickle.load(from_parent)
prepare(preparation_data)
- self = pickle.load(from_parent)
+ self = reduction.pickle.load(from_parent)
finally:
del process.current_process()._inheriting
return self._bootstrap()
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index af6a709..a8f4b37 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -28,8 +28,6 @@ sep = '\\'
pathsep = ';'
altsep = '/'
defpath = '.;C:\\bin'
-if 'ce' in sys.builtin_module_names:
- defpath = '\\Windows'
devnull = 'nul'
def _get_bothseps(path):
@@ -46,6 +44,7 @@ def normcase(s):
"""Normalize case of pathname.
Makes all characters lowercase and all slashes into backslashes."""
+ s = os.fspath(s)
try:
if isinstance(s, bytes):
return s.replace(b'/', b'\\').lower()
@@ -66,12 +65,14 @@ def normcase(s):
def isabs(s):
"""Test whether a path is absolute"""
+ s = os.fspath(s)
s = splitdrive(s)[1]
return len(s) > 0 and s[0] in _get_bothseps(s)
# Join two (or more) paths.
def join(path, *paths):
+ path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
seps = b'\\/'
@@ -84,7 +85,7 @@ def join(path, *paths):
if not paths:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
result_drive, result_path = splitdrive(path)
- for p in paths:
+ for p in map(os.fspath, paths):
p_drive, p_path = splitdrive(p)
if p_path and p_path[0] in seps:
# Second path is absolute
@@ -136,6 +137,7 @@ def splitdrive(p):
Paths cannot contain both a drive letter and a UNC path.
"""
+ p = os.fspath(p)
if len(p) >= 2:
if isinstance(p, bytes):
sep = b'\\'
@@ -199,7 +201,7 @@ def split(p):
Return tuple (head, tail) where tail is everything after the final slash.
Either part may be empty."""
-
+ p = os.fspath(p)
seps = _get_bothseps(p)
d, p = splitdrive(p)
# set i to index beyond p's last slash
@@ -218,6 +220,7 @@ def split(p):
# It is always true that root + ext == p.
def splitext(p):
+ p = os.fspath(p)
if isinstance(p, bytes):
return genericpath._splitext(p, b'\\', b'/', b'.')
else:
@@ -278,6 +281,7 @@ except ImportError:
def ismount(path):
"""Test whether a path is a mount point (a drive root, the root of a
share, or a mounted volume)"""
+ path = os.fspath(path)
seps = _get_bothseps(path)
path = abspath(path)
root, rest = splitdrive(path)
@@ -305,6 +309,7 @@ def expanduser(path):
"""Expand ~ and ~user constructs.
If user or $HOME is unknown, do nothing."""
+ path = os.fspath(path)
if isinstance(path, bytes):
tilde = b'~'
else:
@@ -354,6 +359,7 @@ def expandvars(path):
"""Expand shell variables of the forms $var, ${var} and %var%.
Unknown variables are left unchanged."""
+ path = os.fspath(path)
if isinstance(path, bytes):
if b'$' not in path and b'%' not in path:
return path
@@ -464,6 +470,7 @@ def expandvars(path):
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
+ path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
altsep = b'/'
@@ -518,6 +525,7 @@ try:
except ImportError: # not running on Windows - mock up something sensible
def abspath(path):
"""Return the absolute version of a path."""
+ path = os.fspath(path)
if not isabs(path):
if isinstance(path, bytes):
cwd = os.getcwdb()
@@ -531,6 +539,7 @@ else: # use native Windows method on Windows
"""Return the absolute version of a path."""
if path: # Empty path must return current working directory.
+ path = os.fspath(path)
try:
path = _getfullpathname(path)
except OSError:
@@ -549,6 +558,7 @@ supports_unicode_filenames = (hasattr(sys, "getwindowsversion") and
def relpath(path, start=None):
"""Return a relative version of a path"""
+ path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
curdir = b'.'
@@ -564,6 +574,7 @@ def relpath(path, start=None):
if not path:
raise ValueError("no path specified")
+ start = os.fspath(start)
try:
start_abs = abspath(normpath(start))
path_abs = abspath(normpath(path))
@@ -607,6 +618,7 @@ def commonpath(paths):
if not paths:
raise ValueError('commonpath() arg is an empty sequence')
+ paths = tuple(map(os.fspath, paths))
if isinstance(paths[0], bytes):
sep = b'\\'
altsep = b'/'
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 4c826a7..b5916b6 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -31,12 +31,10 @@ hasjabs = []
haslocal = []
hascompare = []
hasfree = []
-hasnargs = []
+hasnargs = [] # unused
opmap = {}
-opname = [''] * 256
-for op in range(256): opname[op] = '<%r>' % (op,)
-del op
+opname = ['<%r>' % (op,) for op in range(256)]
def def_op(name, op):
opname[op] = name
@@ -121,7 +119,7 @@ def_op('WITH_CLEANUP_FINISH', 82)
def_op('RETURN_VALUE', 83)
def_op('IMPORT_STAR', 84)
-
+def_op('SETUP_ANNOTATIONS', 85)
def_op('YIELD_VALUE', 86)
def_op('POP_BLOCK', 87)
def_op('END_FINALLY', 88)
@@ -171,13 +169,12 @@ def_op('STORE_FAST', 125) # Local variable number
haslocal.append(125)
def_op('DELETE_FAST', 126) # Local variable number
haslocal.append(126)
+name_op('STORE_ANNOTATION', 127) # Index in name list
def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
-def_op('CALL_FUNCTION', 131) # #args + (#kwargs << 8)
-hasnargs.append(131)
-def_op('MAKE_FUNCTION', 132) # Number of args with default values
+def_op('CALL_FUNCTION', 131) # #args
+def_op('MAKE_FUNCTION', 132) # Flags
def_op('BUILD_SLICE', 133) # Number of items
-def_op('MAKE_CLOSURE', 134)
def_op('LOAD_CLOSURE', 135)
hasfree.append(135)
def_op('LOAD_DEREF', 136)
@@ -187,12 +184,8 @@ hasfree.append(137)
def_op('DELETE_DEREF', 138)
hasfree.append(138)
-def_op('CALL_FUNCTION_VAR', 140) # #args + (#kwargs << 8)
-hasnargs.append(140)
-def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8)
-hasnargs.append(141)
-def_op('CALL_FUNCTION_VAR_KW', 142) # #args + (#kwargs << 8)
-hasnargs.append(142)
+def_op('CALL_FUNCTION_KW', 141) # #args + #kwargs
+def_op('CALL_FUNCTION_EX', 142) # Flags
jrel_op('SETUP_WITH', 143)
@@ -203,8 +196,6 @@ def_op('MAP_ADD', 147)
def_op('LOAD_CLASSDEREF', 148)
hasfree.append(148)
-jrel_op('SETUP_ASYNC_WITH', 154)
-
def_op('EXTENDED_ARG', 144)
EXTENDED_ARG = 144
@@ -214,4 +205,11 @@ def_op('BUILD_MAP_UNPACK_WITH_CALL', 151)
def_op('BUILD_TUPLE_UNPACK', 152)
def_op('BUILD_SET_UNPACK', 153)
+jrel_op('SETUP_ASYNC_WITH', 154)
+
+def_op('FORMAT_VALUE', 155)
+def_op('BUILD_CONST_KEY_MAP', 156)
+def_op('BUILD_STRING', 157)
+def_op('BUILD_TUPLE_UNPACK_WITH_CALL', 158)
+
del def_op, name_op, jrel_op, jabs_op
diff --git a/Lib/optparse.py b/Lib/optparse.py
index 74b3b36..e8ac1e1 100644
--- a/Lib/optparse.py
+++ b/Lib/optparse.py
@@ -38,7 +38,8 @@ __all__ = ['Option',
'OptionError',
'OptionConflictError',
'OptionValueError',
- 'BadOptionError']
+ 'BadOptionError',
+ 'check_choice']
__copyright__ = """
Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved.
diff --git a/Lib/os.py b/Lib/os.py
index b4c651d..0c9107c 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -1,12 +1,12 @@
r"""OS routines for NT or Posix depending on what system we're on.
This exports:
- - all functions from posix, nt or ce, e.g. unlink, stat, etc.
+ - all functions from posix or nt, e.g. unlink, stat, etc.
- os.path is either posixpath or ntpath
- - os.name is either 'posix', 'nt' or 'ce'.
- - os.curdir is a string representing the current directory ('.' or ':')
- - os.pardir is a string representing the parent directory ('..' or '::')
- - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
+ - os.name is either 'posix' or 'nt'
+ - os.curdir is a string representing the current directory (always '.')
+ - os.pardir is a string representing the parent directory (always '..')
+ - os.sep is the (or a most common) pathname separator ('/' or '\\')
- os.extsep is the extension separator (always '.')
- os.altsep is the alternate pathname separator (None or '/')
- os.pathsep is the component separator used in $PATH etc
@@ -22,7 +22,7 @@ and opendir), and leave all pathname manipulation to os.path
"""
#'
-
+import abc
import sys, errno
import stat as st
@@ -85,27 +85,6 @@ elif 'nt' in _names:
except ImportError:
pass
-elif 'ce' in _names:
- name = 'ce'
- linesep = '\r\n'
- from ce import *
- try:
- from ce import _exit
- __all__.append('_exit')
- except ImportError:
- pass
- # We can use the standard Windows path.
- import ntpath as path
-
- import ce
- __all__.extend(_get_exports_list(ce))
- del ce
-
- try:
- from ce import _have_functions
- except ImportError:
- pass
-
else:
raise ImportError('no os specific module found')
@@ -353,9 +332,10 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
dirs.remove('CVS') # don't visit CVS directories
"""
-
+ top = fspath(top)
dirs = []
nondirs = []
+ walk_dirs = []
# We may not have read permission for top, in which case we can't
# get a list of the files the directory contains. os.walk
@@ -363,48 +343,55 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# minor reason when (say) a thousand readable directories are still
# left to visit. That logic is copied here.
try:
- if name == 'nt' and isinstance(top, bytes):
- scandir_it = _dummy_scandir(top)
- else:
- # Note that scandir is global in this module due
- # to earlier import-*.
- scandir_it = scandir(top)
- entries = list(scandir_it)
+ # Note that scandir is global in this module due
+ # to earlier import-*.
+ scandir_it = scandir(top)
except OSError as error:
if onerror is not None:
onerror(error)
return
- for entry in entries:
- try:
- is_dir = entry.is_dir()
- except OSError:
- # If is_dir() raises an OSError, consider that the entry is not
- # a directory, same behaviour than os.path.isdir().
- is_dir = False
-
- if is_dir:
- dirs.append(entry.name)
- else:
- nondirs.append(entry.name)
+ with scandir_it:
+ while True:
+ try:
+ try:
+ entry = next(scandir_it)
+ except StopIteration:
+ break
+ except OSError as error:
+ if onerror is not None:
+ onerror(error)
+ return
- if not topdown and is_dir:
- # Bottom-up: recurse into sub-directory, but exclude symlinks to
- # directories if followlinks is False
- if followlinks:
- walk_into = True
+ try:
+ is_dir = entry.is_dir()
+ except OSError:
+ # If is_dir() raises an OSError, consider that the entry is not
+ # a directory, same behaviour than os.path.isdir().
+ is_dir = False
+
+ if is_dir:
+ dirs.append(entry.name)
else:
- try:
- is_symlink = entry.is_symlink()
- except OSError:
- # If is_symlink() raises an OSError, consider that the
- # entry is not a symbolic link, same behaviour than
- # os.path.islink().
- is_symlink = False
- walk_into = not is_symlink
+ nondirs.append(entry.name)
- if walk_into:
- yield from walk(entry.path, topdown, onerror, followlinks)
+ if not topdown and is_dir:
+ # Bottom-up: recurse into sub-directory, but exclude symlinks to
+ # directories if followlinks is False
+ if followlinks:
+ walk_into = True
+ else:
+ try:
+ is_symlink = entry.is_symlink()
+ except OSError:
+ # If is_symlink() raises an OSError, consider that the
+ # entry is not a symbolic link, same behaviour than
+ # os.path.islink().
+ is_symlink = False
+ walk_into = not is_symlink
+
+ if walk_into:
+ walk_dirs.append(entry.path)
# Yield before recursion if going top down
if topdown:
@@ -421,57 +408,12 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
if followlinks or not islink(new_path):
yield from walk(new_path, topdown, onerror, followlinks)
else:
+ # Recurse into sub-directories
+ for new_path in walk_dirs:
+ yield from walk(new_path, topdown, onerror, followlinks)
# Yield after recursion if going bottom up
yield top, dirs, nondirs
-class _DummyDirEntry:
- """Dummy implementation of DirEntry
-
- Only used internally by os.walk(bytes). Since os.walk() doesn't need the
- follow_symlinks parameter: don't implement it, always follow symbolic
- links.
- """
-
- def __init__(self, dir, name):
- self.name = name
- self.path = path.join(dir, name)
- # Mimick FindFirstFile/FindNextFile: we should get file attributes
- # while iterating on a directory
- self._stat = None
- self._lstat = None
- try:
- self.stat(follow_symlinks=False)
- except OSError:
- pass
-
- def stat(self, *, follow_symlinks=True):
- if follow_symlinks:
- if self._stat is None:
- self._stat = stat(self.path)
- return self._stat
- else:
- if self._lstat is None:
- self._lstat = stat(self.path, follow_symlinks=False)
- return self._lstat
-
- def is_dir(self):
- if self._lstat is not None and not self.is_symlink():
- # use the cache lstat
- stat = self.stat(follow_symlinks=False)
- return st.S_ISDIR(stat.st_mode)
-
- stat = self.stat()
- return st.S_ISDIR(stat.st_mode)
-
- def is_symlink(self):
- stat = self.stat(follow_symlinks=False)
- return st.S_ISLNK(stat.st_mode)
-
-def _dummy_scandir(dir):
- # listdir-based implementation for bytes patches on Windows
- for name in listdir(dir):
- yield _DummyDirEntry(dir, name)
-
__all__.append("walk")
if {open, stat} <= supports_dir_fd and {listdir, stat} <= supports_fd:
@@ -509,6 +451,8 @@ if {open, stat} <= supports_dir_fd and {listdir, stat} <= supports_fd:
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
"""
+ if not isinstance(top, int) or not hasattr(top, '__index__'):
+ top = fspath(top)
# Note: To guard against symlink races, we use the standard
# lstat()/open()/fstat() trick.
orig_st = stat(top, follow_symlinks=False, dir_fd=dir_fd)
@@ -843,36 +787,31 @@ if supports_bytes_environ:
def _fscodec():
encoding = sys.getfilesystemencoding()
- if encoding == 'mbcs':
- errors = 'strict'
- else:
- errors = 'surrogateescape'
+ errors = sys.getfilesystemencodeerrors()
def fsencode(filename):
+ """Encode filename (an os.PathLike, bytes, or str) to the filesystem
+ encoding with 'surrogateescape' error handler, return bytes unchanged.
+ On Windows, use 'strict' error handler if the file system encoding is
+ 'mbcs' (which is the default encoding).
"""
- Encode filename to the filesystem encoding with 'surrogateescape' error
- handler, return bytes unchanged. On Windows, use 'strict' error handler if
- the file system encoding is 'mbcs' (which is the default encoding).
- """
- if isinstance(filename, bytes):
- return filename
- elif isinstance(filename, str):
+ filename = fspath(filename) # Does type-checking of `filename`.
+ if isinstance(filename, str):
return filename.encode(encoding, errors)
else:
- raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
+ return filename
def fsdecode(filename):
+ """Decode filename (an os.PathLike, bytes, or str) from the filesystem
+ encoding with 'surrogateescape' error handler, return str unchanged. On
+ Windows, use 'strict' error handler if the file system encoding is
+ 'mbcs' (which is the default encoding).
"""
- Decode filename from the filesystem encoding with 'surrogateescape' error
- handler, return str unchanged. On Windows, use 'strict' error handler if
- the file system encoding is 'mbcs' (which is the default encoding).
- """
- if isinstance(filename, str):
- return filename
- elif isinstance(filename, bytes):
+ filename = fspath(filename) # Does type-checking of `filename`.
+ if isinstance(filename, bytes):
return filename.decode(encoding, errors)
else:
- raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
+ return filename
return fsencode, fsdecode
@@ -1070,3 +1009,55 @@ def fdopen(fd, *args, **kwargs):
raise TypeError("invalid fd type (%s, expected integer)" % type(fd))
import io
return io.open(fd, *args, **kwargs)
+
+
+# For testing purposes, make sure the function is available when the C
+# implementation exists.
+def _fspath(path):
+ """Return the path representation of a path-like object.
+
+ If str or bytes is passed in, it is returned unchanged. Otherwise the
+ os.PathLike interface is used to get the path representation. If the
+ path representation is not str or bytes, TypeError is raised. If the
+ provided path is not str, bytes, or os.PathLike, TypeError is raised.
+ """
+ if isinstance(path, (str, bytes)):
+ return path
+
+ # Work from the object's type to match method resolution of other magic
+ # methods.
+ path_type = type(path)
+ try:
+ path_repr = path_type.__fspath__(path)
+ except AttributeError:
+ if hasattr(path_type, '__fspath__'):
+ raise
+ else:
+ raise TypeError("expected str, bytes or os.PathLike object, "
+ "not " + path_type.__name__)
+ if isinstance(path_repr, (str, bytes)):
+ return path_repr
+ else:
+ raise TypeError("expected {}.__fspath__() to return str or bytes, "
+ "not {}".format(path_type.__name__,
+ type(path_repr).__name__))
+
+# If there is no C implementation, make the pure Python version the
+# implementation as transparently as possible.
+if not _exists('fspath'):
+ fspath = _fspath
+ fspath.__name__ = "fspath"
+
+
+class PathLike(abc.ABC):
+
+ """Abstract base class for implementing the file system path protocol."""
+
+ @abc.abstractmethod
+ def __fspath__(self):
+ """Return the file system path representation of the object."""
+ raise NotImplementedError
+
+ @classmethod
+ def __subclasshook__(cls, subclass):
+ return hasattr(subclass, '__fspath__')
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 1480e2f..1b5ab38 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -385,6 +385,8 @@ class _NormalAccessor(_Accessor):
listdir = _wrap_strfunc(os.listdir)
+ scandir = _wrap_strfunc(os.scandir)
+
chmod = _wrap_strfunc(os.chmod)
if hasattr(os, "lchmod"):
@@ -429,25 +431,6 @@ _normal_accessor = _NormalAccessor()
# Globbing helpers
#
-@contextmanager
-def _cached(func):
- try:
- func.__cached__
- yield func
- except AttributeError:
- cache = {}
- def wrapper(*args):
- try:
- return cache[args]
- except KeyError:
- value = cache[args] = func(*args)
- return value
- wrapper.__cached__ = True
- try:
- yield wrapper
- finally:
- cache.clear()
-
def _make_selector(pattern_parts):
pat = pattern_parts[0]
child_parts = pattern_parts[1:]
@@ -473,8 +456,10 @@ class _Selector:
self.child_parts = child_parts
if child_parts:
self.successor = _make_selector(child_parts)
+ self.dironly = True
else:
self.successor = _TerminatingSelector()
+ self.dironly = False
def select_from(self, parent_path):
"""Iterate over all child paths of `parent_path` matched by this
@@ -482,13 +467,15 @@ class _Selector:
path_cls = type(parent_path)
is_dir = path_cls.is_dir
exists = path_cls.exists
- listdir = parent_path._accessor.listdir
- return self._select_from(parent_path, is_dir, exists, listdir)
+ scandir = parent_path._accessor.scandir
+ if not is_dir(parent_path):
+ return iter([])
+ return self._select_from(parent_path, is_dir, exists, scandir)
class _TerminatingSelector:
- def _select_from(self, parent_path, is_dir, exists, listdir):
+ def _select_from(self, parent_path, is_dir, exists, scandir):
yield parent_path
@@ -498,13 +485,11 @@ class _PreciseSelector(_Selector):
self.name = name
_Selector.__init__(self, child_parts)
- def _select_from(self, parent_path, is_dir, exists, listdir):
+ def _select_from(self, parent_path, is_dir, exists, scandir):
try:
- if not is_dir(parent_path):
- return
path = parent_path._make_child_relpath(self.name)
- if exists(path):
- for p in self.successor._select_from(path, is_dir, exists, listdir):
+ if (is_dir if self.dironly else exists)(path):
+ for p in self.successor._select_from(path, is_dir, exists, scandir):
yield p
except PermissionError:
return
@@ -516,17 +501,18 @@ class _WildcardSelector(_Selector):
self.pat = re.compile(fnmatch.translate(pat))
_Selector.__init__(self, child_parts)
- def _select_from(self, parent_path, is_dir, exists, listdir):
+ def _select_from(self, parent_path, is_dir, exists, scandir):
try:
- if not is_dir(parent_path):
- return
cf = parent_path._flavour.casefold
- for name in listdir(parent_path):
- casefolded = cf(name)
- if self.pat.match(casefolded):
- path = parent_path._make_child_relpath(name)
- for p in self.successor._select_from(path, is_dir, exists, listdir):
- yield p
+ entries = list(scandir(parent_path))
+ for entry in entries:
+ if not self.dironly or entry.is_dir():
+ name = entry.name
+ casefolded = cf(name)
+ if self.pat.match(casefolded):
+ path = parent_path._make_child_relpath(name)
+ for p in self.successor._select_from(path, is_dir, exists, scandir):
+ yield p
except PermissionError:
return
@@ -537,32 +523,30 @@ class _RecursiveWildcardSelector(_Selector):
def __init__(self, pat, child_parts):
_Selector.__init__(self, child_parts)
- def _iterate_directories(self, parent_path, is_dir, listdir):
+ def _iterate_directories(self, parent_path, is_dir, scandir):
yield parent_path
try:
- for name in listdir(parent_path):
- path = parent_path._make_child_relpath(name)
- if is_dir(path) and not path.is_symlink():
- for p in self._iterate_directories(path, is_dir, listdir):
+ entries = list(scandir(parent_path))
+ for entry in entries:
+ if entry.is_dir() and not entry.is_symlink():
+ path = parent_path._make_child_relpath(entry.name)
+ for p in self._iterate_directories(path, is_dir, scandir):
yield p
except PermissionError:
return
- def _select_from(self, parent_path, is_dir, exists, listdir):
+ def _select_from(self, parent_path, is_dir, exists, scandir):
try:
- if not is_dir(parent_path):
- return
- with _cached(listdir) as listdir:
- yielded = set()
- try:
- successor_select = self.successor._select_from
- for starting_point in self._iterate_directories(parent_path, is_dir, listdir):
- for p in successor_select(starting_point, is_dir, exists, listdir):
- if p not in yielded:
- yield p
- yielded.add(p)
- finally:
- yielded.clear()
+ yielded = set()
+ try:
+ successor_select = self.successor._select_from
+ for starting_point in self._iterate_directories(parent_path, is_dir, scandir):
+ for p in successor_select(starting_point, is_dir, exists, scandir):
+ if p not in yielded:
+ yield p
+ yielded.add(p)
+ finally:
+ yielded.clear()
except PermissionError:
return
@@ -634,13 +618,16 @@ class PurePath(object):
for a in args:
if isinstance(a, PurePath):
parts += a._parts
- elif isinstance(a, str):
- # Force-cast str subclasses to str (issue #21127)
- parts.append(str(a))
else:
- raise TypeError(
- "argument should be a path or str object, not %r"
- % type(a))
+ a = os.fspath(a)
+ if isinstance(a, str):
+ # Force-cast str subclasses to str (issue #21127)
+ parts.append(str(a))
+ else:
+ raise TypeError(
+ "argument should be a str object or an os.PathLike "
+ "object returning str, not %r"
+ % type(a))
return cls._flavour.parse_parts(parts)
@classmethod
@@ -693,6 +680,9 @@ class PurePath(object):
self._parts) or '.'
return self._str
+ def __fspath__(self):
+ return str(self)
+
def as_posix(self):
"""Return the string representation of the path with forward (/)
slashes."""
@@ -943,6 +933,10 @@ class PurePath(object):
return False
return True
+# Can't subclass os.PathLike from PurePath and keep the constructor
+# optimizations in PurePath._parse_args().
+os.PathLike.register(PurePath)
+
class PurePosixPath(PurePath):
_flavour = _posix_flavour
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 4797265..97618b0 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -52,7 +52,8 @@ If a file ".pdbrc" exists in your home directory or in the current
directory, it is read in and executed as if it had been typed at the
debugger prompt. This is particularly useful for aliases. If both
files exist, the one in the home directory is read first and aliases
-defined there can be overridden by the local file.
+defined there can be overridden by the local file. This behavior can be
+disabled by passing the "readrc=False" argument to the Pdb constructor.
Aside from aliases, the debugger is not directly programmable; but it
is implemented as a class from which you can derive your own debugger
@@ -137,7 +138,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
_previous_sigint_handler = None
def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
- nosigint=False):
+ nosigint=False, readrc=True):
bdb.Bdb.__init__(self, skip=skip)
cmd.Cmd.__init__(self, completekey, stdin, stdout)
if stdout:
@@ -160,18 +161,19 @@ class Pdb(bdb.Bdb, cmd.Cmd):
# Read $HOME/.pdbrc and ./.pdbrc
self.rcLines = []
- if 'HOME' in os.environ:
- envHome = os.environ['HOME']
+ if readrc:
+ if 'HOME' in os.environ:
+ envHome = os.environ['HOME']
+ try:
+ with open(os.path.join(envHome, ".pdbrc")) as rcFile:
+ self.rcLines.extend(rcFile)
+ except OSError:
+ pass
try:
- with open(os.path.join(envHome, ".pdbrc")) as rcFile:
+ with open(".pdbrc") as rcFile:
self.rcLines.extend(rcFile)
except OSError:
pass
- try:
- with open(".pdbrc") as rcFile:
- self.rcLines.extend(rcFile)
- except OSError:
- pass
self.commands = {} # associates a command list to breakpoint numbers
self.commands_doprompt = {} # for each bp num, tells if the prompt
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 040ecb2..c8370c9 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -27,6 +27,7 @@ from types import FunctionType
from copyreg import dispatch_table
from copyreg import _extension_registry, _inverted_registry, _extension_cache
from itertools import islice
+from functools import partial
import sys
from sys import maxsize
from struct import pack, unpack
@@ -548,7 +549,7 @@ class _Pickler:
write = self.write
func_name = getattr(func, "__name__", "")
- if self.proto >= 4 and func_name == "__newobj_ex__":
+ if self.proto >= 2 and func_name == "__newobj_ex__":
cls, args, kwargs = args
if not hasattr(cls, "__new__"):
raise PicklingError("args[0] from {} args has no __new__"
@@ -556,10 +557,16 @@ class _Pickler:
if obj is not None and cls is not obj.__class__:
raise PicklingError("args[0] from {} args has the wrong class"
.format(func_name))
- save(cls)
- save(args)
- save(kwargs)
- write(NEWOBJ_EX)
+ if self.proto >= 4:
+ save(cls)
+ save(args)
+ save(kwargs)
+ write(NEWOBJ_EX)
+ else:
+ func = partial(cls.__new__, cls, *args, **kwargs)
+ save(func)
+ save(())
+ write(REDUCE)
elif self.proto >= 2 and func_name == "__newobj__":
# A __reduce__ implementation can direct protocol 2 or newer to
# use the more efficient NEWOBJ opcode, while still
@@ -1028,7 +1035,7 @@ class _Unpickler:
self._unframer = _Unframer(self._file_read, self._file_readline)
self.read = self._unframer.read
self.readline = self._unframer.readline
- self.mark = object() # any new unique object
+ self.metastack = []
self.stack = []
self.append = self.stack.append
self.proto = 0
@@ -1044,20 +1051,12 @@ class _Unpickler:
except _Stop as stopinst:
return stopinst.value
- # Return largest index k such that self.stack[k] is self.mark.
- # If the stack doesn't contain a mark, eventually raises IndexError.
- # This could be sped by maintaining another stack, of indices at which
- # the mark appears. For that matter, the latter stack would suffice,
- # and we wouldn't need to push mark objects on self.stack at all.
- # Doing so is probably a good thing, though, since if the pickle is
- # corrupt (or hostile) we may get a clue from finding self.mark embedded
- # in unpickled objects.
- def marker(self):
- stack = self.stack
- mark = self.mark
- k = len(stack)-1
- while stack[k] is not mark: k = k-1
- return k
+ # Return a list of items pushed in the stack after last MARK instruction.
+ def pop_mark(self):
+ items = self.stack
+ self.stack = self.metastack.pop()
+ self.append = self.stack.append
+ return items
def persistent_load(self, pid):
raise UnpicklingError("unsupported persistent id encountered")
@@ -1238,8 +1237,8 @@ class _Unpickler:
dispatch[SHORT_BINUNICODE[0]] = load_short_binunicode
def load_tuple(self):
- k = self.marker()
- self.stack[k:] = [tuple(self.stack[k+1:])]
+ items = self.pop_mark()
+ self.append(tuple(items))
dispatch[TUPLE[0]] = load_tuple
def load_empty_tuple(self):
@@ -1271,21 +1270,20 @@ class _Unpickler:
dispatch[EMPTY_SET[0]] = load_empty_set
def load_frozenset(self):
- k = self.marker()
- self.stack[k:] = [frozenset(self.stack[k+1:])]
+ items = self.pop_mark()
+ self.append(frozenset(items))
dispatch[FROZENSET[0]] = load_frozenset
def load_list(self):
- k = self.marker()
- self.stack[k:] = [self.stack[k+1:]]
+ items = self.pop_mark()
+ self.append(items)
dispatch[LIST[0]] = load_list
def load_dict(self):
- k = self.marker()
- items = self.stack[k+1:]
+ items = self.pop_mark()
d = {items[i]: items[i+1]
for i in range(0, len(items), 2)}
- self.stack[k:] = [d]
+ self.append(d)
dispatch[DICT[0]] = load_dict
# INST and OBJ differ only in how they get a class object. It's not
@@ -1293,9 +1291,7 @@ class _Unpickler:
# previously diverged and grew different bugs.
# klass is the class to instantiate, and k points to the topmost mark
# object, following which are the arguments for klass.__init__.
- def _instantiate(self, klass, k):
- args = tuple(self.stack[k+1:])
- del self.stack[k:]
+ def _instantiate(self, klass, args):
if (args or not isinstance(klass, type) or
hasattr(klass, "__getinitargs__")):
try:
@@ -1311,14 +1307,14 @@ class _Unpickler:
module = self.readline()[:-1].decode("ascii")
name = self.readline()[:-1].decode("ascii")
klass = self.find_class(module, name)
- self._instantiate(klass, self.marker())
+ self._instantiate(klass, self.pop_mark())
dispatch[INST[0]] = load_inst
def load_obj(self):
# Stack is ... markobject classobject arg1 arg2 ...
- k = self.marker()
- klass = self.stack.pop(k+1)
- self._instantiate(klass, k)
+ args = self.pop_mark()
+ cls = args.pop(0)
+ self._instantiate(cls, args)
dispatch[OBJ[0]] = load_obj
def load_newobj(self):
@@ -1403,12 +1399,14 @@ class _Unpickler:
dispatch[REDUCE[0]] = load_reduce
def load_pop(self):
- del self.stack[-1]
+ if self.stack:
+ del self.stack[-1]
+ else:
+ self.pop_mark()
dispatch[POP[0]] = load_pop
def load_pop_mark(self):
- k = self.marker()
- del self.stack[k:]
+ self.pop_mark()
dispatch[POP_MARK[0]] = load_pop_mark
def load_dup(self):
@@ -1464,17 +1462,14 @@ class _Unpickler:
dispatch[APPEND[0]] = load_append
def load_appends(self):
- stack = self.stack
- mark = self.marker()
- list_obj = stack[mark - 1]
- items = stack[mark + 1:]
+ items = self.pop_mark()
+ list_obj = self.stack[-1]
if isinstance(list_obj, list):
list_obj.extend(items)
else:
append = list_obj.append
for item in items:
append(item)
- del stack[mark:]
dispatch[APPENDS[0]] = load_appends
def load_setitem(self):
@@ -1486,27 +1481,21 @@ class _Unpickler:
dispatch[SETITEM[0]] = load_setitem
def load_setitems(self):
- stack = self.stack
- mark = self.marker()
- dict = stack[mark - 1]
- for i in range(mark + 1, len(stack), 2):
- dict[stack[i]] = stack[i + 1]
-
- del stack[mark:]
+ items = self.pop_mark()
+ dict = self.stack[-1]
+ for i in range(0, len(items), 2):
+ dict[items[i]] = items[i + 1]
dispatch[SETITEMS[0]] = load_setitems
def load_additems(self):
- stack = self.stack
- mark = self.marker()
- set_obj = stack[mark - 1]
- items = stack[mark + 1:]
+ items = self.pop_mark()
+ set_obj = self.stack[-1]
if isinstance(set_obj, set):
set_obj.update(items)
else:
add = set_obj.add
for item in items:
add(item)
- del stack[mark:]
dispatch[ADDITEMS[0]] = load_additems
def load_build(self):
@@ -1534,7 +1523,9 @@ class _Unpickler:
dispatch[BUILD[0]] = load_build
def load_mark(self):
- self.append(self.mark)
+ self.metastack.append(self.stack)
+ self.stack = []
+ self.append = self.stack.append
dispatch[MARK[0]] = load_mark
def load_stop(self):
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index 16ae7d5..5e129b5 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -707,7 +707,7 @@ def read_unicodestring8(f):
>>> enc = s.encode('utf-8')
>>> enc
b'abcd\xea\xaf\x8d'
- >>> n = bytes([len(enc)]) + bytes(7) # little-endian 8-byte length
+ >>> n = bytes([len(enc)]) + b'\0' * 7 # little-endian 8-byte length
>>> t = read_unicodestring8(io.BytesIO(n + enc + b'junk'))
>>> s == t
True
@@ -2440,6 +2440,7 @@ def dis(pickle, out=None, memo=None, indentlevel=4, annotate=0):
if opcode.name in ("PUT", "BINPUT", "LONG_BINPUT", "MEMOIZE"):
if opcode.name == "MEMOIZE":
memo_idx = len(memo)
+ markmsg = "(as %d)" % memo_idx
else:
assert arg is not None
memo_idx = arg
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 81d418d..e37ad45 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -1,5 +1,6 @@
"""Utilities to support packages."""
+from collections import namedtuple
from functools import singledispatch as simplegeneric
import importlib
import importlib.util
@@ -14,9 +15,14 @@ __all__ = [
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
'walk_packages', 'iter_modules', 'get_data',
'ImpImporter', 'ImpLoader', 'read_code', 'extend_path',
+ 'ModuleInfo',
]
+ModuleInfo = namedtuple('ModuleInfo', 'module_finder name ispkg')
+ModuleInfo.__doc__ = 'A namedtuple with minimal info about a module.'
+
+
def _get_spec(finder, name):
"""Return the finder-specific module spec."""
# Works with legacy finders.
@@ -45,7 +51,7 @@ def read_code(stream):
def walk_packages(path=None, prefix='', onerror=None):
- """Yields (module_finder, name, ispkg) for all modules recursively
+ """Yields ModuleInfo for all modules recursively
on path, or, if path is None, all accessible modules.
'path' should be either None or a list of paths to look for
@@ -78,31 +84,31 @@ def walk_packages(path=None, prefix='', onerror=None):
return True
m[p] = True
- for importer, name, ispkg in iter_modules(path, prefix):
- yield importer, name, ispkg
+ for info in iter_modules(path, prefix):
+ yield info
- if ispkg:
+ if info.ispkg:
try:
- __import__(name)
+ __import__(info.name)
except ImportError:
if onerror is not None:
- onerror(name)
+ onerror(info.name)
except Exception:
if onerror is not None:
- onerror(name)
+ onerror(info.name)
else:
raise
else:
- path = getattr(sys.modules[name], '__path__', None) or []
+ path = getattr(sys.modules[info.name], '__path__', None) or []
# don't traverse path items we've seen before
path = [p for p in path if not seen(p)]
- yield from walk_packages(path, name+'.', onerror)
+ yield from walk_packages(path, info.name+'.', onerror)
def iter_modules(path=None, prefix=''):
- """Yields (module_finder, name, ispkg) for all submodules on path,
+ """Yields ModuleInfo for all submodules on path,
or, if path is None, all top-level modules on sys.path.
'path' should be either None or a list of paths to look for
@@ -111,7 +117,6 @@ def iter_modules(path=None, prefix=''):
'prefix' is a string to output on the front of every module name
on output.
"""
-
if path is None:
importers = iter_importers()
else:
@@ -122,7 +127,7 @@ def iter_modules(path=None, prefix=''):
for name, ispkg in iter_importer_modules(i, prefix):
if name not in yielded:
yielded[name] = 1
- yield i, name, ispkg
+ yield ModuleInfo(i, name, ispkg)
@simplegeneric
@@ -180,7 +185,7 @@ iter_importer_modules.register(
def _import_imp():
global imp
with warnings.catch_warnings():
- warnings.simplefilter('ignore', PendingDeprecationWarning)
+ warnings.simplefilter('ignore', DeprecationWarning)
imp = importlib.import_module('imp')
class ImpImporter:
diff --git a/Lib/plat-aix4/IN.py b/Lib/plat-aix4/IN.py
deleted file mode 100644
index 43f8f23..0000000
--- a/Lib/plat-aix4/IN.py
+++ /dev/null
@@ -1,165 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-
-# Included from net/nh.h
-
-# Included from sys/machine.h
-LITTLE_ENDIAN = 1234
-BIG_ENDIAN = 4321
-PDP_ENDIAN = 3412
-BYTE_ORDER = BIG_ENDIAN
-DEFAULT_GPR = 0xDEADBEEF
-MSR_EE = 0x8000
-MSR_PR = 0x4000
-MSR_FP = 0x2000
-MSR_ME = 0x1000
-MSR_FE = 0x0800
-MSR_FE0 = 0x0800
-MSR_SE = 0x0400
-MSR_BE = 0x0200
-MSR_IE = 0x0100
-MSR_FE1 = 0x0100
-MSR_AL = 0x0080
-MSR_IP = 0x0040
-MSR_IR = 0x0020
-MSR_DR = 0x0010
-MSR_PM = 0x0004
-DEFAULT_MSR = (MSR_EE | MSR_ME | MSR_AL | MSR_IR | MSR_DR)
-DEFAULT_USER_MSR = (DEFAULT_MSR | MSR_PR)
-CR_LT = 0x80000000
-CR_GT = 0x40000000
-CR_EQ = 0x20000000
-CR_SO = 0x10000000
-CR_FX = 0x08000000
-CR_FEX = 0x04000000
-CR_VX = 0x02000000
-CR_OX = 0x01000000
-XER_SO = 0x80000000
-XER_OV = 0x40000000
-XER_CA = 0x20000000
-def XER_COMP_BYTE(xer): return ((xer >> 8) & 0x000000FF)
-
-def XER_LENGTH(xer): return (xer & 0x0000007F)
-
-DSISR_IO = 0x80000000
-DSISR_PFT = 0x40000000
-DSISR_LOCK = 0x20000000
-DSISR_FPIO = 0x10000000
-DSISR_PROT = 0x08000000
-DSISR_LOOP = 0x04000000
-DSISR_DRST = 0x04000000
-DSISR_ST = 0x02000000
-DSISR_SEGB = 0x01000000
-DSISR_DABR = 0x00400000
-DSISR_EAR = 0x00100000
-SRR_IS_PFT = 0x40000000
-SRR_IS_ISPEC = 0x20000000
-SRR_IS_IIO = 0x10000000
-SRR_IS_GUARD = 0x10000000
-SRR_IS_PROT = 0x08000000
-SRR_IS_LOOP = 0x04000000
-SRR_PR_FPEN = 0x00100000
-SRR_PR_INVAL = 0x00080000
-SRR_PR_PRIV = 0x00040000
-SRR_PR_TRAP = 0x00020000
-SRR_PR_IMPRE = 0x00010000
-def BUID_7F_SRVAL(raddr): return (0x87F00000 | (((uint)(raddr)) >> 28))
-
-BT_256M = 0x1FFC
-BT_128M = 0x0FFC
-BT_64M = 0x07FC
-BT_32M = 0x03FC
-BT_16M = 0x01FC
-BT_8M = 0x00FC
-BT_4M = 0x007C
-BT_2M = 0x003C
-BT_1M = 0x001C
-BT_512K = 0x000C
-BT_256K = 0x0004
-BT_128K = 0x0000
-BT_NOACCESS = 0x0
-BT_RDONLY = 0x1
-BT_WRITE = 0x2
-BT_VS = 0x2
-BT_VP = 0x1
-def BAT_ESEG(dbatu): return (((uint)(dbatu) >> 28))
-
-MIN_BAT_SIZE = 0x00020000
-MAX_BAT_SIZE = 0x10000000
-def ntohl(x): return (x)
-
-def ntohs(x): return (x)
-
-def htonl(x): return (x)
-
-def htons(x): return (x)
-
-IPPROTO_IP = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_TCP = 6
-IPPROTO_EGP = 8
-IPPROTO_PUP = 12
-IPPROTO_UDP = 17
-IPPROTO_IDP = 22
-IPPROTO_TP = 29
-IPPROTO_LOCAL = 63
-IPPROTO_EON = 80
-IPPROTO_BIP = 0x53
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 5000
-IPPORT_TIMESERVER = 37
-def IN_CLASSA(i): return (((int)(i) & 0x80000000) == 0)
-
-IN_CLASSA_NET = 0xff000000
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((int)(i) & 0xc0000000) == 0x80000000)
-
-IN_CLASSB_NET = 0xffff0000
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((int)(i) & 0xe0000000) == 0xc0000000)
-
-IN_CLASSC_NET = 0xffffff00
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((int)(i) & 0xf0000000) == 0xe0000000)
-
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-IN_CLASSD_NET = 0xf0000000
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-INADDR_UNSPEC_GROUP = 0xe0000000
-INADDR_ALLHOSTS_GROUP = 0xe0000001
-INADDR_MAX_LOCAL_GROUP = 0xe00000ff
-def IN_EXPERIMENTAL(i): return (((int)(i) & 0xe0000000) == 0xe0000000)
-
-def IN_BADCLASS(i): return (((int)(i) & 0xf0000000) == 0xf0000000)
-
-INADDR_ANY = 0x00000000
-INADDR_BROADCAST = 0xffffffff
-INADDR_LOOPBACK = 0x7f000001
-INADDR_NONE = 0xffffffff
-IN_LOOPBACKNET = 127
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
diff --git a/Lib/plat-aix4/regen b/Lib/plat-aix4/regen
deleted file mode 100755
index 57a71c4..0000000
--- a/Lib/plat-aix4/regen
+++ /dev/null
@@ -1,8 +0,0 @@
-#! /bin/sh
-case `uname -sv` in
-'AIX 4'*) ;;
-*) echo Probably not on an AIX 4 system 1>&2
- exit 1;;
-esac
-set -v
-h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-darwin/IN.py b/Lib/plat-darwin/IN.py
deleted file mode 100644
index 6b6be33..0000000
--- a/Lib/plat-darwin/IN.py
+++ /dev/null
@@ -1,662 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-
-# Included from sys/appleapiopts.h
-
-# Included from sys/_types.h
-
-# Included from sys/cdefs.h
-def __P(protos): return protos
-
-def __STRING(x): return #x
-
-def __P(protos): return ()
-
-def __STRING(x): return "x"
-
-def __attribute__(x): return
-
-def __COPYRIGHT(s): return __IDSTRING(copyright,s)
-
-def __RCSID(s): return __IDSTRING(rcsid,s)
-
-def __SCCSID(s): return __IDSTRING(sccsid,s)
-
-def __PROJECT_VERSION(s): return __IDSTRING(project_version,s)
-
-__DARWIN_UNIX03 = 1
-__DARWIN_UNIX03 = 0
-__DARWIN_UNIX03 = 0
-__DARWIN_UNIX03 = 1
-__DARWIN_64_BIT_INO_T = 1
-__DARWIN_64_BIT_INO_T = 0
-__DARWIN_64_BIT_INO_T = 0
-__DARWIN_NON_CANCELABLE = 0
-__DARWIN_VERS_1050 = 1
-__DARWIN_VERS_1050 = 0
-__DARWIN_SUF_UNIX03 = "$UNIX2003"
-__DARWIN_SUF_UNIX03_SET = 1
-__DARWIN_SUF_UNIX03_SET = 0
-__DARWIN_SUF_64_BIT_INO_T = "$INODE64"
-__DARWIN_SUF_NON_CANCELABLE = "$NOCANCEL"
-__DARWIN_SUF_1050 = "$1050"
-__DARWIN_SUF_UNIX03_SET = 0
-__DARWIN_SUF_EXTSN = "$DARWIN_EXTSN"
-__DARWIN_LONG_DOUBLE_IS_DOUBLE = 0
-def __DARWIN_LDBL_COMPAT(x): return
-
-def __DARWIN_LDBL_COMPAT2(x): return
-
-__DARWIN_LONG_DOUBLE_IS_DOUBLE = 1
-def __DARWIN_LDBL_COMPAT(x): return
-
-def __DARWIN_LDBL_COMPAT2(x): return
-
-__DARWIN_LONG_DOUBLE_IS_DOUBLE = 0
-_DARWIN_FEATURE_LONG_DOUBLE_IS_DOUBLE = 1
-_DARWIN_FEATURE_UNIX_CONFORMANCE = 3
-_DARWIN_FEATURE_64_BIT_INODE = 1
-
-# Included from machine/_types.h
-__PTHREAD_SIZE__ = 1168
-__PTHREAD_ATTR_SIZE__ = 56
-__PTHREAD_MUTEXATTR_SIZE__ = 8
-__PTHREAD_MUTEX_SIZE__ = 56
-__PTHREAD_CONDATTR_SIZE__ = 8
-__PTHREAD_COND_SIZE__ = 40
-__PTHREAD_ONCE_SIZE__ = 8
-__PTHREAD_RWLOCK_SIZE__ = 192
-__PTHREAD_RWLOCKATTR_SIZE__ = 16
-__PTHREAD_SIZE__ = 596
-__PTHREAD_ATTR_SIZE__ = 36
-__PTHREAD_MUTEXATTR_SIZE__ = 8
-__PTHREAD_MUTEX_SIZE__ = 40
-__PTHREAD_CONDATTR_SIZE__ = 4
-__PTHREAD_COND_SIZE__ = 24
-__PTHREAD_ONCE_SIZE__ = 4
-__PTHREAD_RWLOCK_SIZE__ = 124
-__PTHREAD_RWLOCKATTR_SIZE__ = 12
-__DARWIN_NULL = 0
-
-# Included from stdint.h
-__WORDSIZE = 64
-__WORDSIZE = 32
-INT8_MAX = 127
-INT16_MAX = 32767
-INT32_MAX = 2147483647
-INT8_MIN = -128
-INT16_MIN = -32768
-INT32_MIN = (-INT32_MAX-1)
-UINT8_MAX = 255
-UINT16_MAX = 65535
-INT_LEAST8_MIN = INT8_MIN
-INT_LEAST16_MIN = INT16_MIN
-INT_LEAST32_MIN = INT32_MIN
-INT_LEAST8_MAX = INT8_MAX
-INT_LEAST16_MAX = INT16_MAX
-INT_LEAST32_MAX = INT32_MAX
-UINT_LEAST8_MAX = UINT8_MAX
-UINT_LEAST16_MAX = UINT16_MAX
-INT_FAST8_MIN = INT8_MIN
-INT_FAST16_MIN = INT16_MIN
-INT_FAST32_MIN = INT32_MIN
-INT_FAST8_MAX = INT8_MAX
-INT_FAST16_MAX = INT16_MAX
-INT_FAST32_MAX = INT32_MAX
-UINT_FAST8_MAX = UINT8_MAX
-UINT_FAST16_MAX = UINT16_MAX
-INTPTR_MIN = INT32_MIN
-INTPTR_MAX = INT32_MAX
-PTRDIFF_MIN = INT32_MIN
-PTRDIFF_MAX = INT32_MAX
-WCHAR_MAX = 0x7fffffff
-WCHAR_MIN = 0
-WCHAR_MIN = (-WCHAR_MAX-1)
-WINT_MIN = INT32_MIN
-WINT_MAX = INT32_MAX
-SIG_ATOMIC_MIN = INT32_MIN
-SIG_ATOMIC_MAX = INT32_MAX
-def INT8_C(v): return (v)
-
-def INT16_C(v): return (v)
-
-def INT32_C(v): return (v)
-
-
-# Included from sys/socket.h
-
-# Included from machine/_param.h
-SOCK_STREAM = 1
-SOCK_DGRAM = 2
-SOCK_RAW = 3
-SOCK_RDM = 4
-SOCK_SEQPACKET = 5
-SO_DEBUG = 0x0001
-SO_ACCEPTCONN = 0x0002
-SO_REUSEADDR = 0x0004
-SO_KEEPALIVE = 0x0008
-SO_DONTROUTE = 0x0010
-SO_BROADCAST = 0x0020
-SO_USELOOPBACK = 0x0040
-SO_LINGER = 0x0080
-SO_LINGER = 0x1080
-SO_OOBINLINE = 0x0100
-SO_REUSEPORT = 0x0200
-SO_TIMESTAMP = 0x0400
-SO_ACCEPTFILTER = 0x1000
-SO_DONTTRUNC = 0x2000
-SO_WANTMORE = 0x4000
-SO_WANTOOBFLAG = 0x8000
-SO_SNDBUF = 0x1001
-SO_RCVBUF = 0x1002
-SO_SNDLOWAT = 0x1003
-SO_RCVLOWAT = 0x1004
-SO_SNDTIMEO = 0x1005
-SO_RCVTIMEO = 0x1006
-SO_ERROR = 0x1007
-SO_TYPE = 0x1008
-SO_NREAD = 0x1020
-SO_NKE = 0x1021
-SO_NOSIGPIPE = 0x1022
-SO_NOADDRERR = 0x1023
-SO_NWRITE = 0x1024
-SO_REUSESHAREUID = 0x1025
-SO_NOTIFYCONFLICT = 0x1026
-SO_LINGER_SEC = 0x1080
-SO_RESTRICTIONS = 0x1081
-SO_RESTRICT_DENYIN = 0x00000001
-SO_RESTRICT_DENYOUT = 0x00000002
-SO_RESTRICT_DENYSET = (-2147483648)
-SO_LABEL = 0x1010
-SO_PEERLABEL = 0x1011
-SOL_SOCKET = 0xffff
-AF_UNSPEC = 0
-AF_UNIX = 1
-AF_LOCAL = AF_UNIX
-AF_INET = 2
-AF_IMPLINK = 3
-AF_PUP = 4
-AF_CHAOS = 5
-AF_NS = 6
-AF_ISO = 7
-AF_OSI = AF_ISO
-AF_ECMA = 8
-AF_DATAKIT = 9
-AF_CCITT = 10
-AF_SNA = 11
-AF_DECnet = 12
-AF_DLI = 13
-AF_LAT = 14
-AF_HYLINK = 15
-AF_APPLETALK = 16
-AF_ROUTE = 17
-AF_LINK = 18
-pseudo_AF_XTP = 19
-AF_COIP = 20
-AF_CNT = 21
-pseudo_AF_RTIP = 22
-AF_IPX = 23
-AF_SIP = 24
-pseudo_AF_PIP = 25
-AF_NDRV = 27
-AF_ISDN = 28
-AF_E164 = AF_ISDN
-pseudo_AF_KEY = 29
-AF_INET6 = 30
-AF_NATM = 31
-AF_SYSTEM = 32
-AF_NETBIOS = 33
-AF_PPP = 34
-AF_ATM = 30
-pseudo_AF_HDRCMPLT = 35
-AF_RESERVED_36 = 36
-AF_NETGRAPH = 32
-AF_MAX = 37
-SOCK_MAXADDRLEN = 255
-_SS_MAXSIZE = 128
-PF_UNSPEC = AF_UNSPEC
-PF_LOCAL = AF_LOCAL
-PF_UNIX = PF_LOCAL
-PF_INET = AF_INET
-PF_IMPLINK = AF_IMPLINK
-PF_PUP = AF_PUP
-PF_CHAOS = AF_CHAOS
-PF_NS = AF_NS
-PF_ISO = AF_ISO
-PF_OSI = AF_ISO
-PF_ECMA = AF_ECMA
-PF_DATAKIT = AF_DATAKIT
-PF_CCITT = AF_CCITT
-PF_SNA = AF_SNA
-PF_DECnet = AF_DECnet
-PF_DLI = AF_DLI
-PF_LAT = AF_LAT
-PF_HYLINK = AF_HYLINK
-PF_APPLETALK = AF_APPLETALK
-PF_ROUTE = AF_ROUTE
-PF_LINK = AF_LINK
-PF_XTP = pseudo_AF_XTP
-PF_COIP = AF_COIP
-PF_CNT = AF_CNT
-PF_SIP = AF_SIP
-PF_IPX = AF_IPX
-PF_RTIP = pseudo_AF_RTIP
-PF_PIP = pseudo_AF_PIP
-PF_NDRV = AF_NDRV
-PF_ISDN = AF_ISDN
-PF_KEY = pseudo_AF_KEY
-PF_INET6 = AF_INET6
-PF_NATM = AF_NATM
-PF_SYSTEM = AF_SYSTEM
-PF_NETBIOS = AF_NETBIOS
-PF_PPP = AF_PPP
-PF_RESERVED_36 = AF_RESERVED_36
-PF_ATM = AF_ATM
-PF_NETGRAPH = AF_NETGRAPH
-PF_MAX = AF_MAX
-NET_MAXID = AF_MAX
-NET_RT_DUMP = 1
-NET_RT_FLAGS = 2
-NET_RT_IFLIST = 3
-NET_RT_STAT = 4
-NET_RT_TRASH = 5
-NET_RT_IFLIST2 = 6
-NET_RT_DUMP2 = 7
-NET_RT_MAXID = 8
-SOMAXCONN = 128
-MSG_OOB = 0x1
-MSG_PEEK = 0x2
-MSG_DONTROUTE = 0x4
-MSG_EOR = 0x8
-MSG_TRUNC = 0x10
-MSG_CTRUNC = 0x20
-MSG_WAITALL = 0x40
-MSG_DONTWAIT = 0x80
-MSG_EOF = 0x100
-MSG_WAITSTREAM = 0x200
-MSG_FLUSH = 0x400
-MSG_HOLD = 0x800
-MSG_SEND = 0x1000
-MSG_HAVEMORE = 0x2000
-MSG_RCVMORE = 0x4000
-MSG_NEEDSA = 0x10000
-CMGROUP_MAX = 16
-SCM_RIGHTS = 0x01
-SCM_TIMESTAMP = 0x02
-SCM_CREDS = 0x03
-SHUT_RD = 0
-SHUT_WR = 1
-SHUT_RDWR = 2
-
-# Included from machine/endian.h
-
-# Included from sys/_endian.h
-def ntohl(x): return (x)
-
-def ntohs(x): return (x)
-
-def htonl(x): return (x)
-
-def htons(x): return (x)
-
-def NTOHL(x): return (x)
-
-def NTOHS(x): return (x)
-
-def HTONL(x): return (x)
-
-def HTONS(x): return (x)
-
-
-# Included from libkern/_OSByteOrder.h
-def __DARWIN_OSSwapConstInt16(x): return \
-
-def __DARWIN_OSSwapConstInt32(x): return \
-
-def __DARWIN_OSSwapConstInt64(x): return \
-
-
-# Included from libkern/i386/_OSByteOrder.h
-def __DARWIN_OSSwapInt16(x): return \
-
-def __DARWIN_OSSwapInt32(x): return \
-
-def __DARWIN_OSSwapInt64(x): return \
-
-def __DARWIN_OSSwapInt16(x): return _OSSwapInt16(x)
-
-def __DARWIN_OSSwapInt32(x): return _OSSwapInt32(x)
-
-def __DARWIN_OSSwapInt64(x): return _OSSwapInt64(x)
-
-def ntohs(x): return __DARWIN_OSSwapInt16(x)
-
-def htons(x): return __DARWIN_OSSwapInt16(x)
-
-def ntohl(x): return __DARWIN_OSSwapInt32(x)
-
-def htonl(x): return __DARWIN_OSSwapInt32(x)
-
-IPPROTO_IP = 0
-IPPROTO_HOPOPTS = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPV4 = 4
-IPPROTO_IPIP = IPPROTO_IPV4
-IPPROTO_TCP = 6
-IPPROTO_ST = 7
-IPPROTO_EGP = 8
-IPPROTO_PIGP = 9
-IPPROTO_RCCMON = 10
-IPPROTO_NVPII = 11
-IPPROTO_PUP = 12
-IPPROTO_ARGUS = 13
-IPPROTO_EMCON = 14
-IPPROTO_XNET = 15
-IPPROTO_CHAOS = 16
-IPPROTO_UDP = 17
-IPPROTO_MUX = 18
-IPPROTO_MEAS = 19
-IPPROTO_HMP = 20
-IPPROTO_PRM = 21
-IPPROTO_IDP = 22
-IPPROTO_TRUNK1 = 23
-IPPROTO_TRUNK2 = 24
-IPPROTO_LEAF1 = 25
-IPPROTO_LEAF2 = 26
-IPPROTO_RDP = 27
-IPPROTO_IRTP = 28
-IPPROTO_TP = 29
-IPPROTO_BLT = 30
-IPPROTO_NSP = 31
-IPPROTO_INP = 32
-IPPROTO_SEP = 33
-IPPROTO_3PC = 34
-IPPROTO_IDPR = 35
-IPPROTO_XTP = 36
-IPPROTO_DDP = 37
-IPPROTO_CMTP = 38
-IPPROTO_TPXX = 39
-IPPROTO_IL = 40
-IPPROTO_IPV6 = 41
-IPPROTO_SDRP = 42
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_IDRP = 45
-IPPROTO_RSVP = 46
-IPPROTO_GRE = 47
-IPPROTO_MHRP = 48
-IPPROTO_BHA = 49
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_INLSP = 52
-IPPROTO_SWIPE = 53
-IPPROTO_NHRP = 54
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_AHIP = 61
-IPPROTO_CFTP = 62
-IPPROTO_HELLO = 63
-IPPROTO_SATEXPAK = 64
-IPPROTO_KRYPTOLAN = 65
-IPPROTO_RVD = 66
-IPPROTO_IPPC = 67
-IPPROTO_ADFS = 68
-IPPROTO_SATMON = 69
-IPPROTO_VISA = 70
-IPPROTO_IPCV = 71
-IPPROTO_CPNX = 72
-IPPROTO_CPHB = 73
-IPPROTO_WSN = 74
-IPPROTO_PVP = 75
-IPPROTO_BRSATMON = 76
-IPPROTO_ND = 77
-IPPROTO_WBMON = 78
-IPPROTO_WBEXPAK = 79
-IPPROTO_EON = 80
-IPPROTO_VMTP = 81
-IPPROTO_SVMTP = 82
-IPPROTO_VINES = 83
-IPPROTO_TTP = 84
-IPPROTO_IGP = 85
-IPPROTO_DGP = 86
-IPPROTO_TCF = 87
-IPPROTO_IGRP = 88
-IPPROTO_OSPFIGP = 89
-IPPROTO_SRPC = 90
-IPPROTO_LARP = 91
-IPPROTO_MTP = 92
-IPPROTO_AX25 = 93
-IPPROTO_IPEIP = 94
-IPPROTO_MICP = 95
-IPPROTO_SCCSP = 96
-IPPROTO_ETHERIP = 97
-IPPROTO_ENCAP = 98
-IPPROTO_APES = 99
-IPPROTO_GMTP = 100
-IPPROTO_IPCOMP = 108
-IPPROTO_PIM = 103
-IPPROTO_PGM = 113
-IPPROTO_DIVERT = 254
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPROTO_DONE = 257
-__DARWIN_IPPORT_RESERVED = 1024
-IPPORT_RESERVED = __DARWIN_IPPORT_RESERVED
-IPPORT_USERRESERVED = 5000
-IPPORT_HIFIRSTAUTO = 49152
-IPPORT_HILASTAUTO = 65535
-IPPORT_RESERVEDSTART = 600
-def IN_CLASSA(i): return (((u_int32_t)(i) & (-2147483648)) == 0)
-
-IN_CLASSA_NET = (-16777216)
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((u_int32_t)(i) & (-1073741824)) == (-2147483648))
-
-IN_CLASSB_NET = (-65536)
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((u_int32_t)(i) & (-536870912)) == (-1073741824))
-
-IN_CLASSC_NET = (-256)
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((u_int32_t)(i) & (-268435456)) == (-536870912))
-
-IN_CLASSD_NET = (-268435456)
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
-
-def IN_BADCLASS(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
-
-INADDR_NONE = (-1)
-def IN_LINKLOCAL(i): return (((u_int32_t)(i) & IN_CLASSB_NET) == IN_LINKLOCALNETNUM)
-
-IN_LOOPBACKNET = 127
-INET_ADDRSTRLEN = 16
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_MULTICAST_VIF = 14
-IP_RSVP_ON = 15
-IP_RSVP_OFF = 16
-IP_RSVP_VIF_ON = 17
-IP_RSVP_VIF_OFF = 18
-IP_PORTRANGE = 19
-IP_RECVIF = 20
-IP_IPSEC_POLICY = 21
-IP_FAITH = 22
-IP_STRIPHDR = 23
-IP_RECVTTL = 24
-IP_FW_ADD = 40
-IP_FW_DEL = 41
-IP_FW_FLUSH = 42
-IP_FW_ZERO = 43
-IP_FW_GET = 44
-IP_FW_RESETLOG = 45
-IP_OLD_FW_ADD = 50
-IP_OLD_FW_DEL = 51
-IP_OLD_FW_FLUSH = 52
-IP_OLD_FW_ZERO = 53
-IP_OLD_FW_GET = 54
-IP_NAT__XXX = 55
-IP_OLD_FW_RESETLOG = 56
-IP_DUMMYNET_CONFIGURE = 60
-IP_DUMMYNET_DEL = 61
-IP_DUMMYNET_FLUSH = 62
-IP_DUMMYNET_GET = 64
-IP_TRAFFIC_MGT_BACKGROUND = 65
-IP_FORCE_OUT_IFP = 69
-TRAFFIC_MGT_SO_BACKGROUND = 0x0001
-TRAFFIC_MGT_SO_BG_SUPPRESSED = 0x0002
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
-IP_PORTRANGE_DEFAULT = 0
-IP_PORTRANGE_HIGH = 1
-IP_PORTRANGE_LOW = 2
-IPPROTO_MAXID = (IPPROTO_AH + 1)
-IPCTL_FORWARDING = 1
-IPCTL_SENDREDIRECTS = 2
-IPCTL_DEFTTL = 3
-IPCTL_DEFMTU = 4
-IPCTL_RTEXPIRE = 5
-IPCTL_RTMINEXPIRE = 6
-IPCTL_RTMAXCACHE = 7
-IPCTL_SOURCEROUTE = 8
-IPCTL_DIRECTEDBROADCAST = 9
-IPCTL_INTRQMAXLEN = 10
-IPCTL_INTRQDROPS = 11
-IPCTL_STATS = 12
-IPCTL_ACCEPTSOURCEROUTE = 13
-IPCTL_FASTFORWARDING = 14
-IPCTL_KEEPFAITH = 15
-IPCTL_GIF_TTL = 16
-IPCTL_MAXID = 17
-
-# Included from netinet6/in6.h
-__KAME_VERSION = "20010528/apple-darwin"
-IPV6PORT_RESERVED = 1024
-IPV6PORT_ANONMIN = 49152
-IPV6PORT_ANONMAX = 65535
-IPV6PORT_RESERVEDMIN = 600
-IPV6PORT_RESERVEDMAX = (IPV6PORT_RESERVED-1)
-INET6_ADDRSTRLEN = 46
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
-
-def IN6_IS_ADDR_LOOPBACK(a): return \
-
-def IN6_IS_ADDR_V4COMPAT(a): return \
-
-def IN6_IS_ADDR_V4MAPPED(a): return \
-
-__IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-__IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-__IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-__IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-__IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-def IN6_IS_ADDR_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-IPV6_OPTIONS = 1
-IPV6_RECVOPTS = 5
-IPV6_RECVRETOPTS = 6
-IPV6_RECVDSTADDR = 7
-IPV6_RETOPTS = 8
-IPV6_SOCKOPT_RESERVED1 = 3
-IPV6_UNICAST_HOPS = 4
-IPV6_MULTICAST_IF = 9
-IPV6_MULTICAST_HOPS = 10
-IPV6_MULTICAST_LOOP = 11
-IPV6_JOIN_GROUP = 12
-IPV6_LEAVE_GROUP = 13
-IPV6_PORTRANGE = 14
-ICMP6_FILTER = 18
-IPV6_PKTINFO = 19
-IPV6_HOPLIMIT = 20
-IPV6_NEXTHOP = 21
-IPV6_HOPOPTS = 22
-IPV6_DSTOPTS = 23
-IPV6_RTHDR = 24
-IPV6_PKTOPTIONS = 25
-IPV6_CHECKSUM = 26
-IPV6_V6ONLY = 27
-IPV6_BINDV6ONLY = IPV6_V6ONLY
-IPV6_IPSEC_POLICY = 28
-IPV6_FAITH = 29
-IPV6_FW_ADD = 30
-IPV6_FW_DEL = 31
-IPV6_FW_FLUSH = 32
-IPV6_FW_ZERO = 33
-IPV6_FW_GET = 34
-IPV6_RTHDR_LOOSE = 0
-IPV6_RTHDR_STRICT = 1
-IPV6_RTHDR_TYPE_0 = 0
-IPV6_DEFAULT_MULTICAST_HOPS = 1
-IPV6_DEFAULT_MULTICAST_LOOP = 1
-IPV6_PORTRANGE_DEFAULT = 0
-IPV6_PORTRANGE_HIGH = 1
-IPV6_PORTRANGE_LOW = 2
-IPV6PROTO_MAXID = (IPPROTO_PIM + 1)
-IPV6CTL_FORWARDING = 1
-IPV6CTL_SENDREDIRECTS = 2
-IPV6CTL_DEFHLIM = 3
-IPV6CTL_DEFMTU = 4
-IPV6CTL_FORWSRCRT = 5
-IPV6CTL_STATS = 6
-IPV6CTL_MRTSTATS = 7
-IPV6CTL_MRTPROTO = 8
-IPV6CTL_MAXFRAGPACKETS = 9
-IPV6CTL_SOURCECHECK = 10
-IPV6CTL_SOURCECHECK_LOGINT = 11
-IPV6CTL_ACCEPT_RTADV = 12
-IPV6CTL_KEEPFAITH = 13
-IPV6CTL_LOG_INTERVAL = 14
-IPV6CTL_HDRNESTLIMIT = 15
-IPV6CTL_DAD_COUNT = 16
-IPV6CTL_AUTO_FLOWLABEL = 17
-IPV6CTL_DEFMCASTHLIM = 18
-IPV6CTL_GIF_HLIM = 19
-IPV6CTL_KAME_VERSION = 20
-IPV6CTL_USE_DEPRECATED = 21
-IPV6CTL_RR_PRUNE = 22
-IPV6CTL_MAPPED_ADDR = 23
-IPV6CTL_V6ONLY = 24
-IPV6CTL_RTEXPIRE = 25
-IPV6CTL_RTMINEXPIRE = 26
-IPV6CTL_RTMAXCACHE = 27
-IPV6CTL_USETEMPADDR = 32
-IPV6CTL_TEMPPLTIME = 33
-IPV6CTL_TEMPVLTIME = 34
-IPV6CTL_AUTO_LINKLOCAL = 35
-IPV6CTL_RIP6STATS = 36
-IPV6CTL_MAXFRAGS = 41
-IPV6CTL_MAXID = 42
diff --git a/Lib/plat-darwin/regen b/Lib/plat-darwin/regen
deleted file mode 100755
index a20cdc1..0000000
--- a/Lib/plat-darwin/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-freebsd4/IN.py b/Lib/plat-freebsd4/IN.py
deleted file mode 100644
index bca2418..0000000
--- a/Lib/plat-freebsd4/IN.py
+++ /dev/null
@@ -1,355 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-IPPROTO_IP = 0
-IPPROTO_HOPOPTS = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPV4 = 4
-IPPROTO_IPIP = IPPROTO_IPV4
-IPPROTO_TCP = 6
-IPPROTO_ST = 7
-IPPROTO_EGP = 8
-IPPROTO_PIGP = 9
-IPPROTO_RCCMON = 10
-IPPROTO_NVPII = 11
-IPPROTO_PUP = 12
-IPPROTO_ARGUS = 13
-IPPROTO_EMCON = 14
-IPPROTO_XNET = 15
-IPPROTO_CHAOS = 16
-IPPROTO_UDP = 17
-IPPROTO_MUX = 18
-IPPROTO_MEAS = 19
-IPPROTO_HMP = 20
-IPPROTO_PRM = 21
-IPPROTO_IDP = 22
-IPPROTO_TRUNK1 = 23
-IPPROTO_TRUNK2 = 24
-IPPROTO_LEAF1 = 25
-IPPROTO_LEAF2 = 26
-IPPROTO_RDP = 27
-IPPROTO_IRTP = 28
-IPPROTO_TP = 29
-IPPROTO_BLT = 30
-IPPROTO_NSP = 31
-IPPROTO_INP = 32
-IPPROTO_SEP = 33
-IPPROTO_3PC = 34
-IPPROTO_IDPR = 35
-IPPROTO_XTP = 36
-IPPROTO_DDP = 37
-IPPROTO_CMTP = 38
-IPPROTO_TPXX = 39
-IPPROTO_IL = 40
-IPPROTO_IPV6 = 41
-IPPROTO_SDRP = 42
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_IDRP = 45
-IPPROTO_RSVP = 46
-IPPROTO_GRE = 47
-IPPROTO_MHRP = 48
-IPPROTO_BHA = 49
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_INLSP = 52
-IPPROTO_SWIPE = 53
-IPPROTO_NHRP = 54
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_AHIP = 61
-IPPROTO_CFTP = 62
-IPPROTO_HELLO = 63
-IPPROTO_SATEXPAK = 64
-IPPROTO_KRYPTOLAN = 65
-IPPROTO_RVD = 66
-IPPROTO_IPPC = 67
-IPPROTO_ADFS = 68
-IPPROTO_SATMON = 69
-IPPROTO_VISA = 70
-IPPROTO_IPCV = 71
-IPPROTO_CPNX = 72
-IPPROTO_CPHB = 73
-IPPROTO_WSN = 74
-IPPROTO_PVP = 75
-IPPROTO_BRSATMON = 76
-IPPROTO_ND = 77
-IPPROTO_WBMON = 78
-IPPROTO_WBEXPAK = 79
-IPPROTO_EON = 80
-IPPROTO_VMTP = 81
-IPPROTO_SVMTP = 82
-IPPROTO_VINES = 83
-IPPROTO_TTP = 84
-IPPROTO_IGP = 85
-IPPROTO_DGP = 86
-IPPROTO_TCF = 87
-IPPROTO_IGRP = 88
-IPPROTO_OSPFIGP = 89
-IPPROTO_SRPC = 90
-IPPROTO_LARP = 91
-IPPROTO_MTP = 92
-IPPROTO_AX25 = 93
-IPPROTO_IPEIP = 94
-IPPROTO_MICP = 95
-IPPROTO_SCCSP = 96
-IPPROTO_ETHERIP = 97
-IPPROTO_ENCAP = 98
-IPPROTO_APES = 99
-IPPROTO_GMTP = 100
-IPPROTO_IPCOMP = 108
-IPPROTO_PIM = 103
-IPPROTO_PGM = 113
-IPPROTO_DIVERT = 254
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPROTO_DONE = 257
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 5000
-IPPORT_HIFIRSTAUTO = 49152
-IPPORT_HILASTAUTO = 65535
-IPPORT_RESERVEDSTART = 600
-def IN_CLASSA(i): return (((u_int32_t)(i) & 0x80000000) == 0)
-
-IN_CLASSA_NET = 0xff000000
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((u_int32_t)(i) & 0xc0000000) == 0x80000000)
-
-IN_CLASSB_NET = 0xffff0000
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((u_int32_t)(i) & 0xe0000000) == 0xc0000000)
-
-IN_CLASSC_NET = 0xffffff00
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((u_int32_t)(i) & 0xf0000000) == 0xe0000000)
-
-IN_CLASSD_NET = 0xf0000000
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
-
-def IN_BADCLASS(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
-
-INADDR_NONE = 0xffffffff
-IN_LOOPBACKNET = 127
-INET_ADDRSTRLEN = 16
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_MULTICAST_VIF = 14
-IP_RSVP_ON = 15
-IP_RSVP_OFF = 16
-IP_RSVP_VIF_ON = 17
-IP_RSVP_VIF_OFF = 18
-IP_PORTRANGE = 19
-IP_RECVIF = 20
-IP_IPSEC_POLICY = 21
-IP_FAITH = 22
-IP_FW_ADD = 50
-IP_FW_DEL = 51
-IP_FW_FLUSH = 52
-IP_FW_ZERO = 53
-IP_FW_GET = 54
-IP_FW_RESETLOG = 55
-IP_DUMMYNET_CONFIGURE = 60
-IP_DUMMYNET_DEL = 61
-IP_DUMMYNET_FLUSH = 62
-IP_DUMMYNET_GET = 64
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
-IP_PORTRANGE_DEFAULT = 0
-IP_PORTRANGE_HIGH = 1
-IP_PORTRANGE_LOW = 2
-IPPROTO_MAXID = (IPPROTO_AH + 1)
-IPCTL_FORWARDING = 1
-IPCTL_SENDREDIRECTS = 2
-IPCTL_DEFTTL = 3
-IPCTL_DEFMTU = 4
-IPCTL_RTEXPIRE = 5
-IPCTL_RTMINEXPIRE = 6
-IPCTL_RTMAXCACHE = 7
-IPCTL_SOURCEROUTE = 8
-IPCTL_DIRECTEDBROADCAST = 9
-IPCTL_INTRQMAXLEN = 10
-IPCTL_INTRQDROPS = 11
-IPCTL_STATS = 12
-IPCTL_ACCEPTSOURCEROUTE = 13
-IPCTL_FASTFORWARDING = 14
-IPCTL_KEEPFAITH = 15
-IPCTL_GIF_TTL = 16
-IPCTL_MAXID = 17
-
-# Included from netinet6/in6.h
-
-# Included from sys/queue.h
-def SLIST_HEAD_INITIALIZER(head): return \
-
-def SLIST_ENTRY(type): return \
-
-def STAILQ_HEAD_INITIALIZER(head): return \
-
-def STAILQ_ENTRY(type): return \
-
-def LIST_HEAD_INITIALIZER(head): return \
-
-def LIST_ENTRY(type): return \
-
-def TAILQ_HEAD_INITIALIZER(head): return \
-
-def TAILQ_ENTRY(type): return \
-
-def CIRCLEQ_ENTRY(type): return \
-
-__KAME_VERSION = "20000701/FreeBSD-current"
-IPV6PORT_RESERVED = 1024
-IPV6PORT_ANONMIN = 49152
-IPV6PORT_ANONMAX = 65535
-IPV6PORT_RESERVEDMIN = 600
-IPV6PORT_RESERVEDMAX = (IPV6PORT_RESERVED-1)
-INET6_ADDRSTRLEN = 46
-IPV6_ADDR_INT32_ONE = 1
-IPV6_ADDR_INT32_TWO = 2
-IPV6_ADDR_INT32_MNL = 0xff010000
-IPV6_ADDR_INT32_MLL = 0xff020000
-IPV6_ADDR_INT32_SMP = 0x0000ffff
-IPV6_ADDR_INT16_ULL = 0xfe80
-IPV6_ADDR_INT16_USL = 0xfec0
-IPV6_ADDR_INT16_MLL = 0xff02
-IPV6_ADDR_INT32_ONE = 0x01000000
-IPV6_ADDR_INT32_TWO = 0x02000000
-IPV6_ADDR_INT32_MNL = 0x000001ff
-IPV6_ADDR_INT32_MLL = 0x000002ff
-IPV6_ADDR_INT32_SMP = 0xffff0000
-IPV6_ADDR_INT16_ULL = 0x80fe
-IPV6_ADDR_INT16_USL = 0xc0fe
-IPV6_ADDR_INT16_MLL = 0x02ff
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
-
-def IN6_IS_ADDR_LOOPBACK(a): return \
-
-def IN6_IS_ADDR_V4COMPAT(a): return \
-
-def IN6_IS_ADDR_V4MAPPED(a): return \
-
-IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-__IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-__IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-__IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-__IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-__IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-def IN6_IS_ADDR_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_SCOPE_LINKLOCAL(a): return \
-
-IPV6_OPTIONS = 1
-IPV6_RECVOPTS = 5
-IPV6_RECVRETOPTS = 6
-IPV6_RECVDSTADDR = 7
-IPV6_RETOPTS = 8
-IPV6_SOCKOPT_RESERVED1 = 3
-IPV6_UNICAST_HOPS = 4
-IPV6_MULTICAST_IF = 9
-IPV6_MULTICAST_HOPS = 10
-IPV6_MULTICAST_LOOP = 11
-IPV6_JOIN_GROUP = 12
-IPV6_LEAVE_GROUP = 13
-IPV6_PORTRANGE = 14
-ICMP6_FILTER = 18
-IPV6_PKTINFO = 19
-IPV6_HOPLIMIT = 20
-IPV6_NEXTHOP = 21
-IPV6_HOPOPTS = 22
-IPV6_DSTOPTS = 23
-IPV6_RTHDR = 24
-IPV6_PKTOPTIONS = 25
-IPV6_CHECKSUM = 26
-IPV6_BINDV6ONLY = 27
-IPV6_IPSEC_POLICY = 28
-IPV6_FAITH = 29
-IPV6_FW_ADD = 30
-IPV6_FW_DEL = 31
-IPV6_FW_FLUSH = 32
-IPV6_FW_ZERO = 33
-IPV6_FW_GET = 34
-IPV6_RTHDR_LOOSE = 0
-IPV6_RTHDR_STRICT = 1
-IPV6_RTHDR_TYPE_0 = 0
-IPV6_DEFAULT_MULTICAST_HOPS = 1
-IPV6_DEFAULT_MULTICAST_LOOP = 1
-IPV6_PORTRANGE_DEFAULT = 0
-IPV6_PORTRANGE_HIGH = 1
-IPV6_PORTRANGE_LOW = 2
-IPV6PROTO_MAXID = (IPPROTO_PIM + 1)
-IPV6CTL_FORWARDING = 1
-IPV6CTL_SENDREDIRECTS = 2
-IPV6CTL_DEFHLIM = 3
-IPV6CTL_DEFMTU = 4
-IPV6CTL_FORWSRCRT = 5
-IPV6CTL_STATS = 6
-IPV6CTL_MRTSTATS = 7
-IPV6CTL_MRTPROTO = 8
-IPV6CTL_MAXFRAGPACKETS = 9
-IPV6CTL_SOURCECHECK = 10
-IPV6CTL_SOURCECHECK_LOGINT = 11
-IPV6CTL_ACCEPT_RTADV = 12
-IPV6CTL_KEEPFAITH = 13
-IPV6CTL_LOG_INTERVAL = 14
-IPV6CTL_HDRNESTLIMIT = 15
-IPV6CTL_DAD_COUNT = 16
-IPV6CTL_AUTO_FLOWLABEL = 17
-IPV6CTL_DEFMCASTHLIM = 18
-IPV6CTL_GIF_HLIM = 19
-IPV6CTL_KAME_VERSION = 20
-IPV6CTL_USE_DEPRECATED = 21
-IPV6CTL_RR_PRUNE = 22
-IPV6CTL_MAPPED_ADDR = 23
-IPV6CTL_BINDV6ONLY = 24
-IPV6CTL_RTEXPIRE = 25
-IPV6CTL_RTMINEXPIRE = 26
-IPV6CTL_RTMAXCACHE = 27
-IPV6CTL_MAXID = 28
diff --git a/Lib/plat-freebsd4/regen b/Lib/plat-freebsd4/regen
deleted file mode 100755
index 8aa6898..0000000
--- a/Lib/plat-freebsd4/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-python ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-freebsd5/IN.py b/Lib/plat-freebsd5/IN.py
deleted file mode 100644
index bca2418..0000000
--- a/Lib/plat-freebsd5/IN.py
+++ /dev/null
@@ -1,355 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-IPPROTO_IP = 0
-IPPROTO_HOPOPTS = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPV4 = 4
-IPPROTO_IPIP = IPPROTO_IPV4
-IPPROTO_TCP = 6
-IPPROTO_ST = 7
-IPPROTO_EGP = 8
-IPPROTO_PIGP = 9
-IPPROTO_RCCMON = 10
-IPPROTO_NVPII = 11
-IPPROTO_PUP = 12
-IPPROTO_ARGUS = 13
-IPPROTO_EMCON = 14
-IPPROTO_XNET = 15
-IPPROTO_CHAOS = 16
-IPPROTO_UDP = 17
-IPPROTO_MUX = 18
-IPPROTO_MEAS = 19
-IPPROTO_HMP = 20
-IPPROTO_PRM = 21
-IPPROTO_IDP = 22
-IPPROTO_TRUNK1 = 23
-IPPROTO_TRUNK2 = 24
-IPPROTO_LEAF1 = 25
-IPPROTO_LEAF2 = 26
-IPPROTO_RDP = 27
-IPPROTO_IRTP = 28
-IPPROTO_TP = 29
-IPPROTO_BLT = 30
-IPPROTO_NSP = 31
-IPPROTO_INP = 32
-IPPROTO_SEP = 33
-IPPROTO_3PC = 34
-IPPROTO_IDPR = 35
-IPPROTO_XTP = 36
-IPPROTO_DDP = 37
-IPPROTO_CMTP = 38
-IPPROTO_TPXX = 39
-IPPROTO_IL = 40
-IPPROTO_IPV6 = 41
-IPPROTO_SDRP = 42
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_IDRP = 45
-IPPROTO_RSVP = 46
-IPPROTO_GRE = 47
-IPPROTO_MHRP = 48
-IPPROTO_BHA = 49
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_INLSP = 52
-IPPROTO_SWIPE = 53
-IPPROTO_NHRP = 54
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_AHIP = 61
-IPPROTO_CFTP = 62
-IPPROTO_HELLO = 63
-IPPROTO_SATEXPAK = 64
-IPPROTO_KRYPTOLAN = 65
-IPPROTO_RVD = 66
-IPPROTO_IPPC = 67
-IPPROTO_ADFS = 68
-IPPROTO_SATMON = 69
-IPPROTO_VISA = 70
-IPPROTO_IPCV = 71
-IPPROTO_CPNX = 72
-IPPROTO_CPHB = 73
-IPPROTO_WSN = 74
-IPPROTO_PVP = 75
-IPPROTO_BRSATMON = 76
-IPPROTO_ND = 77
-IPPROTO_WBMON = 78
-IPPROTO_WBEXPAK = 79
-IPPROTO_EON = 80
-IPPROTO_VMTP = 81
-IPPROTO_SVMTP = 82
-IPPROTO_VINES = 83
-IPPROTO_TTP = 84
-IPPROTO_IGP = 85
-IPPROTO_DGP = 86
-IPPROTO_TCF = 87
-IPPROTO_IGRP = 88
-IPPROTO_OSPFIGP = 89
-IPPROTO_SRPC = 90
-IPPROTO_LARP = 91
-IPPROTO_MTP = 92
-IPPROTO_AX25 = 93
-IPPROTO_IPEIP = 94
-IPPROTO_MICP = 95
-IPPROTO_SCCSP = 96
-IPPROTO_ETHERIP = 97
-IPPROTO_ENCAP = 98
-IPPROTO_APES = 99
-IPPROTO_GMTP = 100
-IPPROTO_IPCOMP = 108
-IPPROTO_PIM = 103
-IPPROTO_PGM = 113
-IPPROTO_DIVERT = 254
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPROTO_DONE = 257
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 5000
-IPPORT_HIFIRSTAUTO = 49152
-IPPORT_HILASTAUTO = 65535
-IPPORT_RESERVEDSTART = 600
-def IN_CLASSA(i): return (((u_int32_t)(i) & 0x80000000) == 0)
-
-IN_CLASSA_NET = 0xff000000
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((u_int32_t)(i) & 0xc0000000) == 0x80000000)
-
-IN_CLASSB_NET = 0xffff0000
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((u_int32_t)(i) & 0xe0000000) == 0xc0000000)
-
-IN_CLASSC_NET = 0xffffff00
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((u_int32_t)(i) & 0xf0000000) == 0xe0000000)
-
-IN_CLASSD_NET = 0xf0000000
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
-
-def IN_BADCLASS(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
-
-INADDR_NONE = 0xffffffff
-IN_LOOPBACKNET = 127
-INET_ADDRSTRLEN = 16
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_MULTICAST_VIF = 14
-IP_RSVP_ON = 15
-IP_RSVP_OFF = 16
-IP_RSVP_VIF_ON = 17
-IP_RSVP_VIF_OFF = 18
-IP_PORTRANGE = 19
-IP_RECVIF = 20
-IP_IPSEC_POLICY = 21
-IP_FAITH = 22
-IP_FW_ADD = 50
-IP_FW_DEL = 51
-IP_FW_FLUSH = 52
-IP_FW_ZERO = 53
-IP_FW_GET = 54
-IP_FW_RESETLOG = 55
-IP_DUMMYNET_CONFIGURE = 60
-IP_DUMMYNET_DEL = 61
-IP_DUMMYNET_FLUSH = 62
-IP_DUMMYNET_GET = 64
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
-IP_PORTRANGE_DEFAULT = 0
-IP_PORTRANGE_HIGH = 1
-IP_PORTRANGE_LOW = 2
-IPPROTO_MAXID = (IPPROTO_AH + 1)
-IPCTL_FORWARDING = 1
-IPCTL_SENDREDIRECTS = 2
-IPCTL_DEFTTL = 3
-IPCTL_DEFMTU = 4
-IPCTL_RTEXPIRE = 5
-IPCTL_RTMINEXPIRE = 6
-IPCTL_RTMAXCACHE = 7
-IPCTL_SOURCEROUTE = 8
-IPCTL_DIRECTEDBROADCAST = 9
-IPCTL_INTRQMAXLEN = 10
-IPCTL_INTRQDROPS = 11
-IPCTL_STATS = 12
-IPCTL_ACCEPTSOURCEROUTE = 13
-IPCTL_FASTFORWARDING = 14
-IPCTL_KEEPFAITH = 15
-IPCTL_GIF_TTL = 16
-IPCTL_MAXID = 17
-
-# Included from netinet6/in6.h
-
-# Included from sys/queue.h
-def SLIST_HEAD_INITIALIZER(head): return \
-
-def SLIST_ENTRY(type): return \
-
-def STAILQ_HEAD_INITIALIZER(head): return \
-
-def STAILQ_ENTRY(type): return \
-
-def LIST_HEAD_INITIALIZER(head): return \
-
-def LIST_ENTRY(type): return \
-
-def TAILQ_HEAD_INITIALIZER(head): return \
-
-def TAILQ_ENTRY(type): return \
-
-def CIRCLEQ_ENTRY(type): return \
-
-__KAME_VERSION = "20000701/FreeBSD-current"
-IPV6PORT_RESERVED = 1024
-IPV6PORT_ANONMIN = 49152
-IPV6PORT_ANONMAX = 65535
-IPV6PORT_RESERVEDMIN = 600
-IPV6PORT_RESERVEDMAX = (IPV6PORT_RESERVED-1)
-INET6_ADDRSTRLEN = 46
-IPV6_ADDR_INT32_ONE = 1
-IPV6_ADDR_INT32_TWO = 2
-IPV6_ADDR_INT32_MNL = 0xff010000
-IPV6_ADDR_INT32_MLL = 0xff020000
-IPV6_ADDR_INT32_SMP = 0x0000ffff
-IPV6_ADDR_INT16_ULL = 0xfe80
-IPV6_ADDR_INT16_USL = 0xfec0
-IPV6_ADDR_INT16_MLL = 0xff02
-IPV6_ADDR_INT32_ONE = 0x01000000
-IPV6_ADDR_INT32_TWO = 0x02000000
-IPV6_ADDR_INT32_MNL = 0x000001ff
-IPV6_ADDR_INT32_MLL = 0x000002ff
-IPV6_ADDR_INT32_SMP = 0xffff0000
-IPV6_ADDR_INT16_ULL = 0x80fe
-IPV6_ADDR_INT16_USL = 0xc0fe
-IPV6_ADDR_INT16_MLL = 0x02ff
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
-
-def IN6_IS_ADDR_LOOPBACK(a): return \
-
-def IN6_IS_ADDR_V4COMPAT(a): return \
-
-def IN6_IS_ADDR_V4MAPPED(a): return \
-
-IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-__IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-__IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-__IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-__IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-__IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-def IN6_IS_ADDR_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_SCOPE_LINKLOCAL(a): return \
-
-IPV6_OPTIONS = 1
-IPV6_RECVOPTS = 5
-IPV6_RECVRETOPTS = 6
-IPV6_RECVDSTADDR = 7
-IPV6_RETOPTS = 8
-IPV6_SOCKOPT_RESERVED1 = 3
-IPV6_UNICAST_HOPS = 4
-IPV6_MULTICAST_IF = 9
-IPV6_MULTICAST_HOPS = 10
-IPV6_MULTICAST_LOOP = 11
-IPV6_JOIN_GROUP = 12
-IPV6_LEAVE_GROUP = 13
-IPV6_PORTRANGE = 14
-ICMP6_FILTER = 18
-IPV6_PKTINFO = 19
-IPV6_HOPLIMIT = 20
-IPV6_NEXTHOP = 21
-IPV6_HOPOPTS = 22
-IPV6_DSTOPTS = 23
-IPV6_RTHDR = 24
-IPV6_PKTOPTIONS = 25
-IPV6_CHECKSUM = 26
-IPV6_BINDV6ONLY = 27
-IPV6_IPSEC_POLICY = 28
-IPV6_FAITH = 29
-IPV6_FW_ADD = 30
-IPV6_FW_DEL = 31
-IPV6_FW_FLUSH = 32
-IPV6_FW_ZERO = 33
-IPV6_FW_GET = 34
-IPV6_RTHDR_LOOSE = 0
-IPV6_RTHDR_STRICT = 1
-IPV6_RTHDR_TYPE_0 = 0
-IPV6_DEFAULT_MULTICAST_HOPS = 1
-IPV6_DEFAULT_MULTICAST_LOOP = 1
-IPV6_PORTRANGE_DEFAULT = 0
-IPV6_PORTRANGE_HIGH = 1
-IPV6_PORTRANGE_LOW = 2
-IPV6PROTO_MAXID = (IPPROTO_PIM + 1)
-IPV6CTL_FORWARDING = 1
-IPV6CTL_SENDREDIRECTS = 2
-IPV6CTL_DEFHLIM = 3
-IPV6CTL_DEFMTU = 4
-IPV6CTL_FORWSRCRT = 5
-IPV6CTL_STATS = 6
-IPV6CTL_MRTSTATS = 7
-IPV6CTL_MRTPROTO = 8
-IPV6CTL_MAXFRAGPACKETS = 9
-IPV6CTL_SOURCECHECK = 10
-IPV6CTL_SOURCECHECK_LOGINT = 11
-IPV6CTL_ACCEPT_RTADV = 12
-IPV6CTL_KEEPFAITH = 13
-IPV6CTL_LOG_INTERVAL = 14
-IPV6CTL_HDRNESTLIMIT = 15
-IPV6CTL_DAD_COUNT = 16
-IPV6CTL_AUTO_FLOWLABEL = 17
-IPV6CTL_DEFMCASTHLIM = 18
-IPV6CTL_GIF_HLIM = 19
-IPV6CTL_KAME_VERSION = 20
-IPV6CTL_USE_DEPRECATED = 21
-IPV6CTL_RR_PRUNE = 22
-IPV6CTL_MAPPED_ADDR = 23
-IPV6CTL_BINDV6ONLY = 24
-IPV6CTL_RTEXPIRE = 25
-IPV6CTL_RTMINEXPIRE = 26
-IPV6CTL_RTMAXCACHE = 27
-IPV6CTL_MAXID = 28
diff --git a/Lib/plat-freebsd5/regen b/Lib/plat-freebsd5/regen
deleted file mode 100755
index 8aa6898..0000000
--- a/Lib/plat-freebsd5/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-python ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-freebsd6/IN.py b/Lib/plat-freebsd6/IN.py
deleted file mode 100644
index 560bf84..0000000
--- a/Lib/plat-freebsd6/IN.py
+++ /dev/null
@@ -1,551 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-
-# Included from sys/cdefs.h
-__GNUCLIKE_ASM = 3
-__GNUCLIKE_ASM = 2
-__GNUCLIKE___TYPEOF = 1
-__GNUCLIKE___OFFSETOF = 1
-__GNUCLIKE___SECTION = 1
-__GNUCLIKE_ATTRIBUTE_MODE_DI = 1
-__GNUCLIKE_CTOR_SECTION_HANDLING = 1
-__GNUCLIKE_BUILTIN_CONSTANT_P = 1
-__GNUCLIKE_BUILTIN_VARARGS = 1
-__GNUCLIKE_BUILTIN_STDARG = 1
-__GNUCLIKE_BUILTIN_VAALIST = 1
-__GNUC_VA_LIST_COMPATIBILITY = 1
-__GNUCLIKE_BUILTIN_NEXT_ARG = 1
-__GNUCLIKE_BUILTIN_MEMCPY = 1
-__CC_SUPPORTS_INLINE = 1
-__CC_SUPPORTS___INLINE = 1
-__CC_SUPPORTS___INLINE__ = 1
-__CC_SUPPORTS___FUNC__ = 1
-__CC_SUPPORTS_WARNING = 1
-__CC_SUPPORTS_VARADIC_XXX = 1
-__CC_SUPPORTS_DYNAMIC_ARRAY_INIT = 1
-__CC_INT_IS_32BIT = 1
-def __P(protos): return protos
-
-def __STRING(x): return #x
-
-def __XSTRING(x): return __STRING(x)
-
-def __P(protos): return ()
-
-def __STRING(x): return "x"
-
-def __aligned(x): return __attribute__((__aligned__(x)))
-
-def __section(x): return __attribute__((__section__(x)))
-
-def __aligned(x): return __attribute__((__aligned__(x)))
-
-def __section(x): return __attribute__((__section__(x)))
-
-def __nonnull(x): return __attribute__((__nonnull__(x)))
-
-def __predict_true(exp): return __builtin_expect((exp), 1)
-
-def __predict_false(exp): return __builtin_expect((exp), 0)
-
-def __predict_true(exp): return (exp)
-
-def __predict_false(exp): return (exp)
-
-def __format_arg(fmtarg): return __attribute__((__format_arg__ (fmtarg)))
-
-def __FBSDID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-
-def __RCSID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-
-def __RCSID_SOURCE(s): return __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
-
-def __SCCSID(s): return __IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
-
-def __COPYRIGHT(s): return __IDSTRING(__CONCAT(__copyright_,__LINE__),s)
-
-_POSIX_C_SOURCE = 199009
-_POSIX_C_SOURCE = 199209
-__XSI_VISIBLE = 600
-_POSIX_C_SOURCE = 200112
-__XSI_VISIBLE = 500
-_POSIX_C_SOURCE = 199506
-_POSIX_C_SOURCE = 198808
-__POSIX_VISIBLE = 200112
-__ISO_C_VISIBLE = 1999
-__POSIX_VISIBLE = 199506
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199309
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199209
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199009
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 198808
-__ISO_C_VISIBLE = 0
-__POSIX_VISIBLE = 0
-__XSI_VISIBLE = 0
-__BSD_VISIBLE = 0
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 0
-__XSI_VISIBLE = 0
-__BSD_VISIBLE = 0
-__ISO_C_VISIBLE = 1999
-__POSIX_VISIBLE = 200112
-__XSI_VISIBLE = 600
-__BSD_VISIBLE = 1
-__ISO_C_VISIBLE = 1999
-
-# Included from sys/_types.h
-
-# Included from machine/_types.h
-
-# Included from machine/endian.h
-_QUAD_HIGHWORD = 1
-_QUAD_LOWWORD = 0
-_LITTLE_ENDIAN = 1234
-_BIG_ENDIAN = 4321
-_PDP_ENDIAN = 3412
-_BYTE_ORDER = _LITTLE_ENDIAN
-LITTLE_ENDIAN = _LITTLE_ENDIAN
-BIG_ENDIAN = _BIG_ENDIAN
-PDP_ENDIAN = _PDP_ENDIAN
-BYTE_ORDER = _BYTE_ORDER
-def __word_swap_int_var(x): return \
-
-def __word_swap_int_const(x): return \
-
-def __word_swap_int(x): return __word_swap_int_var(x)
-
-def __byte_swap_int_var(x): return \
-
-def __byte_swap_int_const(x): return \
-
-def __byte_swap_int(x): return __byte_swap_int_var(x)
-
-def __byte_swap_long_var(x): return \
-
-def __byte_swap_long_const(x): return \
-
-def __byte_swap_long(x): return __byte_swap_long_var(x)
-
-def __byte_swap_word_var(x): return \
-
-def __byte_swap_word_const(x): return \
-
-def __byte_swap_word(x): return __byte_swap_word_var(x)
-
-def __htonl(x): return __bswap32(x)
-
-def __htons(x): return __bswap16(x)
-
-def __ntohl(x): return __bswap32(x)
-
-def __ntohs(x): return __bswap16(x)
-
-IPPROTO_IP = 0
-IPPROTO_ICMP = 1
-IPPROTO_TCP = 6
-IPPROTO_UDP = 17
-def htonl(x): return __htonl(x)
-
-def htons(x): return __htons(x)
-
-def ntohl(x): return __ntohl(x)
-
-def ntohs(x): return __ntohs(x)
-
-IPPROTO_RAW = 255
-INET_ADDRSTRLEN = 16
-IPPROTO_HOPOPTS = 0
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPV4 = 4
-IPPROTO_IPIP = IPPROTO_IPV4
-IPPROTO_ST = 7
-IPPROTO_EGP = 8
-IPPROTO_PIGP = 9
-IPPROTO_RCCMON = 10
-IPPROTO_NVPII = 11
-IPPROTO_PUP = 12
-IPPROTO_ARGUS = 13
-IPPROTO_EMCON = 14
-IPPROTO_XNET = 15
-IPPROTO_CHAOS = 16
-IPPROTO_MUX = 18
-IPPROTO_MEAS = 19
-IPPROTO_HMP = 20
-IPPROTO_PRM = 21
-IPPROTO_IDP = 22
-IPPROTO_TRUNK1 = 23
-IPPROTO_TRUNK2 = 24
-IPPROTO_LEAF1 = 25
-IPPROTO_LEAF2 = 26
-IPPROTO_RDP = 27
-IPPROTO_IRTP = 28
-IPPROTO_TP = 29
-IPPROTO_BLT = 30
-IPPROTO_NSP = 31
-IPPROTO_INP = 32
-IPPROTO_SEP = 33
-IPPROTO_3PC = 34
-IPPROTO_IDPR = 35
-IPPROTO_XTP = 36
-IPPROTO_DDP = 37
-IPPROTO_CMTP = 38
-IPPROTO_TPXX = 39
-IPPROTO_IL = 40
-IPPROTO_IPV6 = 41
-IPPROTO_SDRP = 42
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_IDRP = 45
-IPPROTO_RSVP = 46
-IPPROTO_GRE = 47
-IPPROTO_MHRP = 48
-IPPROTO_BHA = 49
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_INLSP = 52
-IPPROTO_SWIPE = 53
-IPPROTO_NHRP = 54
-IPPROTO_MOBILE = 55
-IPPROTO_TLSP = 56
-IPPROTO_SKIP = 57
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_AHIP = 61
-IPPROTO_CFTP = 62
-IPPROTO_HELLO = 63
-IPPROTO_SATEXPAK = 64
-IPPROTO_KRYPTOLAN = 65
-IPPROTO_RVD = 66
-IPPROTO_IPPC = 67
-IPPROTO_ADFS = 68
-IPPROTO_SATMON = 69
-IPPROTO_VISA = 70
-IPPROTO_IPCV = 71
-IPPROTO_CPNX = 72
-IPPROTO_CPHB = 73
-IPPROTO_WSN = 74
-IPPROTO_PVP = 75
-IPPROTO_BRSATMON = 76
-IPPROTO_ND = 77
-IPPROTO_WBMON = 78
-IPPROTO_WBEXPAK = 79
-IPPROTO_EON = 80
-IPPROTO_VMTP = 81
-IPPROTO_SVMTP = 82
-IPPROTO_VINES = 83
-IPPROTO_TTP = 84
-IPPROTO_IGP = 85
-IPPROTO_DGP = 86
-IPPROTO_TCF = 87
-IPPROTO_IGRP = 88
-IPPROTO_OSPFIGP = 89
-IPPROTO_SRPC = 90
-IPPROTO_LARP = 91
-IPPROTO_MTP = 92
-IPPROTO_AX25 = 93
-IPPROTO_IPEIP = 94
-IPPROTO_MICP = 95
-IPPROTO_SCCSP = 96
-IPPROTO_ETHERIP = 97
-IPPROTO_ENCAP = 98
-IPPROTO_APES = 99
-IPPROTO_GMTP = 100
-IPPROTO_IPCOMP = 108
-IPPROTO_SCTP = 132
-IPPROTO_PIM = 103
-IPPROTO_CARP = 112
-IPPROTO_PGM = 113
-IPPROTO_PFSYNC = 240
-IPPROTO_OLD_DIVERT = 254
-IPPROTO_MAX = 256
-IPPROTO_DONE = 257
-IPPROTO_DIVERT = 258
-IPPROTO_SPACER = 32767
-IPPORT_RESERVED = 1024
-IPPORT_HIFIRSTAUTO = 49152
-IPPORT_HILASTAUTO = 65535
-IPPORT_RESERVEDSTART = 600
-IPPORT_MAX = 65535
-def IN_CLASSA(i): return (((u_int32_t)(i) & 0x80000000) == 0)
-
-IN_CLASSA_NET = 0xff000000
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((u_int32_t)(i) & 0xc0000000) == 0x80000000)
-
-IN_CLASSB_NET = 0xffff0000
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((u_int32_t)(i) & 0xe0000000) == 0xc0000000)
-
-IN_CLASSC_NET = 0xffffff00
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((u_int32_t)(i) & 0xf0000000) == 0xe0000000)
-
-IN_CLASSD_NET = 0xf0000000
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
-
-def IN_BADCLASS(i): return (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
-
-INADDR_NONE = 0xffffffff
-IN_LOOPBACKNET = 127
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_SENDSRCADDR = IP_RECVDSTADDR
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_MULTICAST_VIF = 14
-IP_RSVP_ON = 15
-IP_RSVP_OFF = 16
-IP_RSVP_VIF_ON = 17
-IP_RSVP_VIF_OFF = 18
-IP_PORTRANGE = 19
-IP_RECVIF = 20
-IP_IPSEC_POLICY = 21
-IP_FAITH = 22
-IP_ONESBCAST = 23
-IP_FW_TABLE_ADD = 40
-IP_FW_TABLE_DEL = 41
-IP_FW_TABLE_FLUSH = 42
-IP_FW_TABLE_GETSIZE = 43
-IP_FW_TABLE_LIST = 44
-IP_FW_ADD = 50
-IP_FW_DEL = 51
-IP_FW_FLUSH = 52
-IP_FW_ZERO = 53
-IP_FW_GET = 54
-IP_FW_RESETLOG = 55
-IP_DUMMYNET_CONFIGURE = 60
-IP_DUMMYNET_DEL = 61
-IP_DUMMYNET_FLUSH = 62
-IP_DUMMYNET_GET = 64
-IP_RECVTTL = 65
-IP_MINTTL = 66
-IP_DONTFRAG = 67
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
-IP_PORTRANGE_DEFAULT = 0
-IP_PORTRANGE_HIGH = 1
-IP_PORTRANGE_LOW = 2
-IPPROTO_MAXID = (IPPROTO_AH + 1)
-IPCTL_FORWARDING = 1
-IPCTL_SENDREDIRECTS = 2
-IPCTL_DEFTTL = 3
-IPCTL_DEFMTU = 4
-IPCTL_RTEXPIRE = 5
-IPCTL_RTMINEXPIRE = 6
-IPCTL_RTMAXCACHE = 7
-IPCTL_SOURCEROUTE = 8
-IPCTL_DIRECTEDBROADCAST = 9
-IPCTL_INTRQMAXLEN = 10
-IPCTL_INTRQDROPS = 11
-IPCTL_STATS = 12
-IPCTL_ACCEPTSOURCEROUTE = 13
-IPCTL_FASTFORWARDING = 14
-IPCTL_KEEPFAITH = 15
-IPCTL_GIF_TTL = 16
-IPCTL_MAXID = 17
-def in_nullhost(x): return ((x).s_addr == INADDR_ANY)
-
-
-# Included from netinet6/in6.h
-__KAME_VERSION = "FreeBSD"
-IPV6PORT_RESERVED = 1024
-IPV6PORT_ANONMIN = 49152
-IPV6PORT_ANONMAX = 65535
-IPV6PORT_RESERVEDMIN = 600
-IPV6PORT_RESERVEDMAX = (IPV6PORT_RESERVED-1)
-INET6_ADDRSTRLEN = 46
-IPV6_ADDR_INT32_ONE = 1
-IPV6_ADDR_INT32_TWO = 2
-IPV6_ADDR_INT32_MNL = 0xff010000
-IPV6_ADDR_INT32_MLL = 0xff020000
-IPV6_ADDR_INT32_SMP = 0x0000ffff
-IPV6_ADDR_INT16_ULL = 0xfe80
-IPV6_ADDR_INT16_USL = 0xfec0
-IPV6_ADDR_INT16_MLL = 0xff02
-IPV6_ADDR_INT32_ONE = 0x01000000
-IPV6_ADDR_INT32_TWO = 0x02000000
-IPV6_ADDR_INT32_MNL = 0x000001ff
-IPV6_ADDR_INT32_MLL = 0x000002ff
-IPV6_ADDR_INT32_SMP = 0xffff0000
-IPV6_ADDR_INT16_ULL = 0x80fe
-IPV6_ADDR_INT16_USL = 0xc0fe
-IPV6_ADDR_INT16_MLL = 0x02ff
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
-
-def IN6_IS_ADDR_LOOPBACK(a): return \
-
-def IN6_IS_ADDR_V4COMPAT(a): return \
-
-def IN6_IS_ADDR_V4MAPPED(a): return \
-
-IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-IPV6_ADDR_SCOPE_INTFACELOCAL = 0x01
-IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-__IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-__IPV6_ADDR_SCOPE_INTFACELOCAL = 0x01
-__IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-__IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-__IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-__IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-def IN6_IS_ADDR_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_INTFACELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_SCOPE_LINKLOCAL(a): return \
-
-def IFA6_IS_DEPRECATED(a): return \
-
-def IFA6_IS_INVALID(a): return \
-
-IPV6_OPTIONS = 1
-IPV6_RECVOPTS = 5
-IPV6_RECVRETOPTS = 6
-IPV6_RECVDSTADDR = 7
-IPV6_RETOPTS = 8
-IPV6_SOCKOPT_RESERVED1 = 3
-IPV6_UNICAST_HOPS = 4
-IPV6_MULTICAST_IF = 9
-IPV6_MULTICAST_HOPS = 10
-IPV6_MULTICAST_LOOP = 11
-IPV6_JOIN_GROUP = 12
-IPV6_LEAVE_GROUP = 13
-IPV6_PORTRANGE = 14
-ICMP6_FILTER = 18
-IPV6_2292PKTINFO = 19
-IPV6_2292HOPLIMIT = 20
-IPV6_2292NEXTHOP = 21
-IPV6_2292HOPOPTS = 22
-IPV6_2292DSTOPTS = 23
-IPV6_2292RTHDR = 24
-IPV6_2292PKTOPTIONS = 25
-IPV6_CHECKSUM = 26
-IPV6_V6ONLY = 27
-IPV6_BINDV6ONLY = IPV6_V6ONLY
-IPV6_IPSEC_POLICY = 28
-IPV6_FAITH = 29
-IPV6_FW_ADD = 30
-IPV6_FW_DEL = 31
-IPV6_FW_FLUSH = 32
-IPV6_FW_ZERO = 33
-IPV6_FW_GET = 34
-IPV6_RTHDRDSTOPTS = 35
-IPV6_RECVPKTINFO = 36
-IPV6_RECVHOPLIMIT = 37
-IPV6_RECVRTHDR = 38
-IPV6_RECVHOPOPTS = 39
-IPV6_RECVDSTOPTS = 40
-IPV6_RECVRTHDRDSTOPTS = 41
-IPV6_USE_MIN_MTU = 42
-IPV6_RECVPATHMTU = 43
-IPV6_PATHMTU = 44
-IPV6_REACHCONF = 45
-IPV6_PKTINFO = 46
-IPV6_HOPLIMIT = 47
-IPV6_NEXTHOP = 48
-IPV6_HOPOPTS = 49
-IPV6_DSTOPTS = 50
-IPV6_RTHDR = 51
-IPV6_PKTOPTIONS = 52
-IPV6_RECVTCLASS = 57
-IPV6_AUTOFLOWLABEL = 59
-IPV6_TCLASS = 61
-IPV6_DONTFRAG = 62
-IPV6_PREFER_TEMPADDR = 63
-IPV6_RTHDR_LOOSE = 0
-IPV6_RTHDR_STRICT = 1
-IPV6_RTHDR_TYPE_0 = 0
-IPV6_DEFAULT_MULTICAST_HOPS = 1
-IPV6_DEFAULT_MULTICAST_LOOP = 1
-IPV6_PORTRANGE_DEFAULT = 0
-IPV6_PORTRANGE_HIGH = 1
-IPV6_PORTRANGE_LOW = 2
-IPV6PROTO_MAXID = (IPPROTO_PIM + 1)
-IPV6CTL_FORWARDING = 1
-IPV6CTL_SENDREDIRECTS = 2
-IPV6CTL_DEFHLIM = 3
-IPV6CTL_DEFMTU = 4
-IPV6CTL_FORWSRCRT = 5
-IPV6CTL_STATS = 6
-IPV6CTL_MRTSTATS = 7
-IPV6CTL_MRTPROTO = 8
-IPV6CTL_MAXFRAGPACKETS = 9
-IPV6CTL_SOURCECHECK = 10
-IPV6CTL_SOURCECHECK_LOGINT = 11
-IPV6CTL_ACCEPT_RTADV = 12
-IPV6CTL_KEEPFAITH = 13
-IPV6CTL_LOG_INTERVAL = 14
-IPV6CTL_HDRNESTLIMIT = 15
-IPV6CTL_DAD_COUNT = 16
-IPV6CTL_AUTO_FLOWLABEL = 17
-IPV6CTL_DEFMCASTHLIM = 18
-IPV6CTL_GIF_HLIM = 19
-IPV6CTL_KAME_VERSION = 20
-IPV6CTL_USE_DEPRECATED = 21
-IPV6CTL_RR_PRUNE = 22
-IPV6CTL_MAPPED_ADDR = 23
-IPV6CTL_V6ONLY = 24
-IPV6CTL_RTEXPIRE = 25
-IPV6CTL_RTMINEXPIRE = 26
-IPV6CTL_RTMAXCACHE = 27
-IPV6CTL_USETEMPADDR = 32
-IPV6CTL_TEMPPLTIME = 33
-IPV6CTL_TEMPVLTIME = 34
-IPV6CTL_AUTO_LINKLOCAL = 35
-IPV6CTL_RIP6STATS = 36
-IPV6CTL_PREFER_TEMPADDR = 37
-IPV6CTL_ADDRCTLPOLICY = 38
-IPV6CTL_USE_DEFAULTZONE = 39
-IPV6CTL_MAXFRAGS = 41
-IPV6CTL_IFQ = 42
-IPV6CTL_ISATAPRTR = 43
-IPV6CTL_MCAST_PMTU = 44
-IPV6CTL_STEALTH = 45
-IPV6CTL_MAXID = 46
diff --git a/Lib/plat-freebsd6/regen b/Lib/plat-freebsd6/regen
deleted file mode 100755
index 8aa6898..0000000
--- a/Lib/plat-freebsd6/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-python ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-freebsd7/IN.py b/Lib/plat-freebsd7/IN.py
deleted file mode 100644
index 4e3b3a2..0000000
--- a/Lib/plat-freebsd7/IN.py
+++ /dev/null
@@ -1,571 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-
-# Included from sys/cdefs.h
-__GNUCLIKE_ASM = 3
-__GNUCLIKE_ASM = 2
-__GNUCLIKE___TYPEOF = 1
-__GNUCLIKE___OFFSETOF = 1
-__GNUCLIKE___SECTION = 1
-__GNUCLIKE_ATTRIBUTE_MODE_DI = 1
-__GNUCLIKE_CTOR_SECTION_HANDLING = 1
-__GNUCLIKE_BUILTIN_CONSTANT_P = 1
-__GNUCLIKE_BUILTIN_VARARGS = 1
-__GNUCLIKE_BUILTIN_STDARG = 1
-__GNUCLIKE_BUILTIN_VAALIST = 1
-__GNUC_VA_LIST_COMPATIBILITY = 1
-__GNUCLIKE_BUILTIN_NEXT_ARG = 1
-__GNUCLIKE_BUILTIN_MEMCPY = 1
-__CC_SUPPORTS_INLINE = 1
-__CC_SUPPORTS___INLINE = 1
-__CC_SUPPORTS___INLINE__ = 1
-__CC_SUPPORTS___FUNC__ = 1
-__CC_SUPPORTS_WARNING = 1
-__CC_SUPPORTS_VARADIC_XXX = 1
-__CC_SUPPORTS_DYNAMIC_ARRAY_INIT = 1
-__CC_INT_IS_32BIT = 1
-def __P(protos): return protos
-
-def __STRING(x): return #x
-
-def __XSTRING(x): return __STRING(x)
-
-def __P(protos): return ()
-
-def __STRING(x): return "x"
-
-def __aligned(x): return __attribute__((__aligned__(x)))
-
-def __section(x): return __attribute__((__section__(x)))
-
-def __aligned(x): return __attribute__((__aligned__(x)))
-
-def __section(x): return __attribute__((__section__(x)))
-
-def __nonnull(x): return __attribute__((__nonnull__(x)))
-
-def __predict_true(exp): return __builtin_expect((exp), 1)
-
-def __predict_false(exp): return __builtin_expect((exp), 0)
-
-def __predict_true(exp): return (exp)
-
-def __predict_false(exp): return (exp)
-
-def __format_arg(fmtarg): return __attribute__((__format_arg__ (fmtarg)))
-
-def __FBSDID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-
-def __RCSID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-
-def __RCSID_SOURCE(s): return __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
-
-def __SCCSID(s): return __IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
-
-def __COPYRIGHT(s): return __IDSTRING(__CONCAT(__copyright_,__LINE__),s)
-
-_POSIX_C_SOURCE = 199009
-_POSIX_C_SOURCE = 199209
-__XSI_VISIBLE = 600
-_POSIX_C_SOURCE = 200112
-__XSI_VISIBLE = 500
-_POSIX_C_SOURCE = 199506
-_POSIX_C_SOURCE = 198808
-__POSIX_VISIBLE = 200112
-__ISO_C_VISIBLE = 1999
-__POSIX_VISIBLE = 199506
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199309
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199209
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199009
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 198808
-__ISO_C_VISIBLE = 0
-__POSIX_VISIBLE = 0
-__XSI_VISIBLE = 0
-__BSD_VISIBLE = 0
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 0
-__XSI_VISIBLE = 0
-__BSD_VISIBLE = 0
-__ISO_C_VISIBLE = 1999
-__POSIX_VISIBLE = 200112
-__XSI_VISIBLE = 600
-__BSD_VISIBLE = 1
-__ISO_C_VISIBLE = 1999
-
-# Included from sys/_types.h
-
-# Included from machine/_types.h
-
-# Included from machine/endian.h
-_QUAD_HIGHWORD = 1
-_QUAD_LOWWORD = 0
-_LITTLE_ENDIAN = 1234
-_BIG_ENDIAN = 4321
-_PDP_ENDIAN = 3412
-_BYTE_ORDER = _LITTLE_ENDIAN
-LITTLE_ENDIAN = _LITTLE_ENDIAN
-BIG_ENDIAN = _BIG_ENDIAN
-PDP_ENDIAN = _PDP_ENDIAN
-BYTE_ORDER = _BYTE_ORDER
-def __word_swap_int_var(x): return \
-
-def __word_swap_int_const(x): return \
-
-def __word_swap_int(x): return __word_swap_int_var(x)
-
-def __byte_swap_int_var(x): return \
-
-def __byte_swap_int_const(x): return \
-
-def __byte_swap_int(x): return __byte_swap_int_var(x)
-
-def __byte_swap_word_var(x): return \
-
-def __byte_swap_word_const(x): return \
-
-def __byte_swap_word(x): return __byte_swap_word_var(x)
-
-def __htonl(x): return __bswap32(x)
-
-def __htons(x): return __bswap16(x)
-
-def __ntohl(x): return __bswap32(x)
-
-def __ntohs(x): return __bswap16(x)
-
-IPPROTO_IP = 0
-IPPROTO_ICMP = 1
-IPPROTO_TCP = 6
-IPPROTO_UDP = 17
-def htonl(x): return __htonl(x)
-
-def htons(x): return __htons(x)
-
-def ntohl(x): return __ntohl(x)
-
-def ntohs(x): return __ntohs(x)
-
-IPPROTO_RAW = 255
-INET_ADDRSTRLEN = 16
-IPPROTO_HOPOPTS = 0
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPV4 = 4
-IPPROTO_IPIP = IPPROTO_IPV4
-IPPROTO_ST = 7
-IPPROTO_EGP = 8
-IPPROTO_PIGP = 9
-IPPROTO_RCCMON = 10
-IPPROTO_NVPII = 11
-IPPROTO_PUP = 12
-IPPROTO_ARGUS = 13
-IPPROTO_EMCON = 14
-IPPROTO_XNET = 15
-IPPROTO_CHAOS = 16
-IPPROTO_MUX = 18
-IPPROTO_MEAS = 19
-IPPROTO_HMP = 20
-IPPROTO_PRM = 21
-IPPROTO_IDP = 22
-IPPROTO_TRUNK1 = 23
-IPPROTO_TRUNK2 = 24
-IPPROTO_LEAF1 = 25
-IPPROTO_LEAF2 = 26
-IPPROTO_RDP = 27
-IPPROTO_IRTP = 28
-IPPROTO_TP = 29
-IPPROTO_BLT = 30
-IPPROTO_NSP = 31
-IPPROTO_INP = 32
-IPPROTO_SEP = 33
-IPPROTO_3PC = 34
-IPPROTO_IDPR = 35
-IPPROTO_XTP = 36
-IPPROTO_DDP = 37
-IPPROTO_CMTP = 38
-IPPROTO_TPXX = 39
-IPPROTO_IL = 40
-IPPROTO_IPV6 = 41
-IPPROTO_SDRP = 42
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_IDRP = 45
-IPPROTO_RSVP = 46
-IPPROTO_GRE = 47
-IPPROTO_MHRP = 48
-IPPROTO_BHA = 49
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_INLSP = 52
-IPPROTO_SWIPE = 53
-IPPROTO_NHRP = 54
-IPPROTO_MOBILE = 55
-IPPROTO_TLSP = 56
-IPPROTO_SKIP = 57
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_AHIP = 61
-IPPROTO_CFTP = 62
-IPPROTO_HELLO = 63
-IPPROTO_SATEXPAK = 64
-IPPROTO_KRYPTOLAN = 65
-IPPROTO_RVD = 66
-IPPROTO_IPPC = 67
-IPPROTO_ADFS = 68
-IPPROTO_SATMON = 69
-IPPROTO_VISA = 70
-IPPROTO_IPCV = 71
-IPPROTO_CPNX = 72
-IPPROTO_CPHB = 73
-IPPROTO_WSN = 74
-IPPROTO_PVP = 75
-IPPROTO_BRSATMON = 76
-IPPROTO_ND = 77
-IPPROTO_WBMON = 78
-IPPROTO_WBEXPAK = 79
-IPPROTO_EON = 80
-IPPROTO_VMTP = 81
-IPPROTO_SVMTP = 82
-IPPROTO_VINES = 83
-IPPROTO_TTP = 84
-IPPROTO_IGP = 85
-IPPROTO_DGP = 86
-IPPROTO_TCF = 87
-IPPROTO_IGRP = 88
-IPPROTO_OSPFIGP = 89
-IPPROTO_SRPC = 90
-IPPROTO_LARP = 91
-IPPROTO_MTP = 92
-IPPROTO_AX25 = 93
-IPPROTO_IPEIP = 94
-IPPROTO_MICP = 95
-IPPROTO_SCCSP = 96
-IPPROTO_ETHERIP = 97
-IPPROTO_ENCAP = 98
-IPPROTO_APES = 99
-IPPROTO_GMTP = 100
-IPPROTO_IPCOMP = 108
-IPPROTO_SCTP = 132
-IPPROTO_PIM = 103
-IPPROTO_CARP = 112
-IPPROTO_PGM = 113
-IPPROTO_PFSYNC = 240
-IPPROTO_OLD_DIVERT = 254
-IPPROTO_MAX = 256
-IPPROTO_DONE = 257
-IPPROTO_DIVERT = 258
-IPPROTO_SPACER = 32767
-IPPORT_RESERVED = 1024
-IPPORT_HIFIRSTAUTO = 49152
-IPPORT_HILASTAUTO = 65535
-IPPORT_RESERVEDSTART = 600
-IPPORT_MAX = 65535
-def IN_CLASSA(i): return (((u_int32_t)(i) & (-2147483648)) == 0)
-
-IN_CLASSA_NET = (-16777216)
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((u_int32_t)(i) & (-1073741824)) == (-2147483648))
-
-IN_CLASSB_NET = (-65536)
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((u_int32_t)(i) & (-536870912)) == (-1073741824))
-
-IN_CLASSC_NET = (-256)
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((u_int32_t)(i) & (-268435456)) == (-536870912))
-
-IN_CLASSD_NET = (-268435456)
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
-
-def IN_BADCLASS(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
-
-def IN_LINKLOCAL(i): return (((u_int32_t)(i) & (-65536)) == (-1442971648))
-
-def IN_LOCAL_GROUP(i): return (((u_int32_t)(i) & (-256)) == (-536870912))
-
-INADDR_NONE = (-1)
-IN_LOOPBACKNET = 127
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_SENDSRCADDR = IP_RECVDSTADDR
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_MULTICAST_VIF = 14
-IP_RSVP_ON = 15
-IP_RSVP_OFF = 16
-IP_RSVP_VIF_ON = 17
-IP_RSVP_VIF_OFF = 18
-IP_PORTRANGE = 19
-IP_RECVIF = 20
-IP_IPSEC_POLICY = 21
-IP_FAITH = 22
-IP_ONESBCAST = 23
-IP_FW_TABLE_ADD = 40
-IP_FW_TABLE_DEL = 41
-IP_FW_TABLE_FLUSH = 42
-IP_FW_TABLE_GETSIZE = 43
-IP_FW_TABLE_LIST = 44
-IP_FW_ADD = 50
-IP_FW_DEL = 51
-IP_FW_FLUSH = 52
-IP_FW_ZERO = 53
-IP_FW_GET = 54
-IP_FW_RESETLOG = 55
-IP_FW_NAT_CFG = 56
-IP_FW_NAT_DEL = 57
-IP_FW_NAT_GET_CONFIG = 58
-IP_FW_NAT_GET_LOG = 59
-IP_DUMMYNET_CONFIGURE = 60
-IP_DUMMYNET_DEL = 61
-IP_DUMMYNET_FLUSH = 62
-IP_DUMMYNET_GET = 64
-IP_RECVTTL = 65
-IP_MINTTL = 66
-IP_DONTFRAG = 67
-IP_ADD_SOURCE_MEMBERSHIP = 70
-IP_DROP_SOURCE_MEMBERSHIP = 71
-IP_BLOCK_SOURCE = 72
-IP_UNBLOCK_SOURCE = 73
-IP_MSFILTER = 74
-MCAST_JOIN_GROUP = 80
-MCAST_LEAVE_GROUP = 81
-MCAST_JOIN_SOURCE_GROUP = 82
-MCAST_LEAVE_SOURCE_GROUP = 83
-MCAST_BLOCK_SOURCE = 84
-MCAST_UNBLOCK_SOURCE = 85
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MIN_MEMBERSHIPS = 31
-IP_MAX_MEMBERSHIPS = 4095
-IP_MAX_SOURCE_FILTER = 1024
-MCAST_INCLUDE = 1
-MCAST_EXCLUDE = 2
-IP_PORTRANGE_DEFAULT = 0
-IP_PORTRANGE_HIGH = 1
-IP_PORTRANGE_LOW = 2
-IPPROTO_MAXID = (IPPROTO_AH + 1)
-IPCTL_FORWARDING = 1
-IPCTL_SENDREDIRECTS = 2
-IPCTL_DEFTTL = 3
-IPCTL_DEFMTU = 4
-IPCTL_RTEXPIRE = 5
-IPCTL_RTMINEXPIRE = 6
-IPCTL_RTMAXCACHE = 7
-IPCTL_SOURCEROUTE = 8
-IPCTL_DIRECTEDBROADCAST = 9
-IPCTL_INTRQMAXLEN = 10
-IPCTL_INTRQDROPS = 11
-IPCTL_STATS = 12
-IPCTL_ACCEPTSOURCEROUTE = 13
-IPCTL_FASTFORWARDING = 14
-IPCTL_KEEPFAITH = 15
-IPCTL_GIF_TTL = 16
-IPCTL_MAXID = 17
-def in_nullhost(x): return ((x).s_addr == INADDR_ANY)
-
-
-# Included from netinet6/in6.h
-__KAME_VERSION = "FreeBSD"
-IPV6PORT_RESERVED = 1024
-IPV6PORT_ANONMIN = 49152
-IPV6PORT_ANONMAX = 65535
-IPV6PORT_RESERVEDMIN = 600
-IPV6PORT_RESERVEDMAX = (IPV6PORT_RESERVED-1)
-INET6_ADDRSTRLEN = 46
-IPV6_ADDR_INT32_ONE = 1
-IPV6_ADDR_INT32_TWO = 2
-IPV6_ADDR_INT32_MNL = (-16711680)
-IPV6_ADDR_INT32_MLL = (-16646144)
-IPV6_ADDR_INT32_SMP = 0x0000ffff
-IPV6_ADDR_INT16_ULL = 0xfe80
-IPV6_ADDR_INT16_USL = 0xfec0
-IPV6_ADDR_INT16_MLL = 0xff02
-IPV6_ADDR_INT32_ONE = 0x01000000
-IPV6_ADDR_INT32_TWO = 0x02000000
-IPV6_ADDR_INT32_MNL = 0x000001ff
-IPV6_ADDR_INT32_MLL = 0x000002ff
-IPV6_ADDR_INT32_SMP = (-65536)
-IPV6_ADDR_INT16_ULL = 0x80fe
-IPV6_ADDR_INT16_USL = 0xc0fe
-IPV6_ADDR_INT16_MLL = 0x02ff
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
-
-def IN6_IS_ADDR_LOOPBACK(a): return \
-
-def IN6_IS_ADDR_V4COMPAT(a): return \
-
-def IN6_IS_ADDR_V4MAPPED(a): return \
-
-IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-IPV6_ADDR_SCOPE_INTFACELOCAL = 0x01
-IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-__IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-__IPV6_ADDR_SCOPE_INTFACELOCAL = 0x01
-__IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-__IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-__IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-__IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-def IN6_IS_ADDR_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_INTFACELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_SCOPE_LINKLOCAL(a): return \
-
-def IN6_IS_SCOPE_EMBED(a): return \
-
-def IFA6_IS_DEPRECATED(a): return \
-
-def IFA6_IS_INVALID(a): return \
-
-IPV6_OPTIONS = 1
-IPV6_RECVOPTS = 5
-IPV6_RECVRETOPTS = 6
-IPV6_RECVDSTADDR = 7
-IPV6_RETOPTS = 8
-IPV6_SOCKOPT_RESERVED1 = 3
-IPV6_UNICAST_HOPS = 4
-IPV6_MULTICAST_IF = 9
-IPV6_MULTICAST_HOPS = 10
-IPV6_MULTICAST_LOOP = 11
-IPV6_JOIN_GROUP = 12
-IPV6_LEAVE_GROUP = 13
-IPV6_PORTRANGE = 14
-ICMP6_FILTER = 18
-IPV6_2292PKTINFO = 19
-IPV6_2292HOPLIMIT = 20
-IPV6_2292NEXTHOP = 21
-IPV6_2292HOPOPTS = 22
-IPV6_2292DSTOPTS = 23
-IPV6_2292RTHDR = 24
-IPV6_2292PKTOPTIONS = 25
-IPV6_CHECKSUM = 26
-IPV6_V6ONLY = 27
-IPV6_BINDV6ONLY = IPV6_V6ONLY
-IPV6_IPSEC_POLICY = 28
-IPV6_FAITH = 29
-IPV6_FW_ADD = 30
-IPV6_FW_DEL = 31
-IPV6_FW_FLUSH = 32
-IPV6_FW_ZERO = 33
-IPV6_FW_GET = 34
-IPV6_RTHDRDSTOPTS = 35
-IPV6_RECVPKTINFO = 36
-IPV6_RECVHOPLIMIT = 37
-IPV6_RECVRTHDR = 38
-IPV6_RECVHOPOPTS = 39
-IPV6_RECVDSTOPTS = 40
-IPV6_RECVRTHDRDSTOPTS = 41
-IPV6_USE_MIN_MTU = 42
-IPV6_RECVPATHMTU = 43
-IPV6_PATHMTU = 44
-IPV6_REACHCONF = 45
-IPV6_PKTINFO = 46
-IPV6_HOPLIMIT = 47
-IPV6_NEXTHOP = 48
-IPV6_HOPOPTS = 49
-IPV6_DSTOPTS = 50
-IPV6_RTHDR = 51
-IPV6_PKTOPTIONS = 52
-IPV6_RECVTCLASS = 57
-IPV6_AUTOFLOWLABEL = 59
-IPV6_TCLASS = 61
-IPV6_DONTFRAG = 62
-IPV6_PREFER_TEMPADDR = 63
-IPV6_MSFILTER = 74
-IPV6_RTHDR_LOOSE = 0
-IPV6_RTHDR_STRICT = 1
-IPV6_RTHDR_TYPE_0 = 0
-IPV6_DEFAULT_MULTICAST_HOPS = 1
-IPV6_DEFAULT_MULTICAST_LOOP = 1
-IPV6_PORTRANGE_DEFAULT = 0
-IPV6_PORTRANGE_HIGH = 1
-IPV6_PORTRANGE_LOW = 2
-IPV6PROTO_MAXID = (IPPROTO_PIM + 1)
-IPV6CTL_FORWARDING = 1
-IPV6CTL_SENDREDIRECTS = 2
-IPV6CTL_DEFHLIM = 3
-IPV6CTL_DEFMTU = 4
-IPV6CTL_FORWSRCRT = 5
-IPV6CTL_STATS = 6
-IPV6CTL_MRTSTATS = 7
-IPV6CTL_MRTPROTO = 8
-IPV6CTL_MAXFRAGPACKETS = 9
-IPV6CTL_SOURCECHECK = 10
-IPV6CTL_SOURCECHECK_LOGINT = 11
-IPV6CTL_ACCEPT_RTADV = 12
-IPV6CTL_KEEPFAITH = 13
-IPV6CTL_LOG_INTERVAL = 14
-IPV6CTL_HDRNESTLIMIT = 15
-IPV6CTL_DAD_COUNT = 16
-IPV6CTL_AUTO_FLOWLABEL = 17
-IPV6CTL_DEFMCASTHLIM = 18
-IPV6CTL_GIF_HLIM = 19
-IPV6CTL_KAME_VERSION = 20
-IPV6CTL_USE_DEPRECATED = 21
-IPV6CTL_RR_PRUNE = 22
-IPV6CTL_MAPPED_ADDR = 23
-IPV6CTL_V6ONLY = 24
-IPV6CTL_RTEXPIRE = 25
-IPV6CTL_RTMINEXPIRE = 26
-IPV6CTL_RTMAXCACHE = 27
-IPV6CTL_USETEMPADDR = 32
-IPV6CTL_TEMPPLTIME = 33
-IPV6CTL_TEMPVLTIME = 34
-IPV6CTL_AUTO_LINKLOCAL = 35
-IPV6CTL_RIP6STATS = 36
-IPV6CTL_PREFER_TEMPADDR = 37
-IPV6CTL_ADDRCTLPOLICY = 38
-IPV6CTL_USE_DEFAULTZONE = 39
-IPV6CTL_MAXFRAGS = 41
-IPV6CTL_IFQ = 42
-IPV6CTL_ISATAPRTR = 43
-IPV6CTL_MCAST_PMTU = 44
-IPV6CTL_STEALTH = 45
-IPV6CTL_MAXID = 46
diff --git a/Lib/plat-freebsd7/regen b/Lib/plat-freebsd7/regen
deleted file mode 100755
index 8aa6898..0000000
--- a/Lib/plat-freebsd7/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-python ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-freebsd8/IN.py b/Lib/plat-freebsd8/IN.py
deleted file mode 100644
index 4e3b3a2..0000000
--- a/Lib/plat-freebsd8/IN.py
+++ /dev/null
@@ -1,571 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-
-# Included from sys/cdefs.h
-__GNUCLIKE_ASM = 3
-__GNUCLIKE_ASM = 2
-__GNUCLIKE___TYPEOF = 1
-__GNUCLIKE___OFFSETOF = 1
-__GNUCLIKE___SECTION = 1
-__GNUCLIKE_ATTRIBUTE_MODE_DI = 1
-__GNUCLIKE_CTOR_SECTION_HANDLING = 1
-__GNUCLIKE_BUILTIN_CONSTANT_P = 1
-__GNUCLIKE_BUILTIN_VARARGS = 1
-__GNUCLIKE_BUILTIN_STDARG = 1
-__GNUCLIKE_BUILTIN_VAALIST = 1
-__GNUC_VA_LIST_COMPATIBILITY = 1
-__GNUCLIKE_BUILTIN_NEXT_ARG = 1
-__GNUCLIKE_BUILTIN_MEMCPY = 1
-__CC_SUPPORTS_INLINE = 1
-__CC_SUPPORTS___INLINE = 1
-__CC_SUPPORTS___INLINE__ = 1
-__CC_SUPPORTS___FUNC__ = 1
-__CC_SUPPORTS_WARNING = 1
-__CC_SUPPORTS_VARADIC_XXX = 1
-__CC_SUPPORTS_DYNAMIC_ARRAY_INIT = 1
-__CC_INT_IS_32BIT = 1
-def __P(protos): return protos
-
-def __STRING(x): return #x
-
-def __XSTRING(x): return __STRING(x)
-
-def __P(protos): return ()
-
-def __STRING(x): return "x"
-
-def __aligned(x): return __attribute__((__aligned__(x)))
-
-def __section(x): return __attribute__((__section__(x)))
-
-def __aligned(x): return __attribute__((__aligned__(x)))
-
-def __section(x): return __attribute__((__section__(x)))
-
-def __nonnull(x): return __attribute__((__nonnull__(x)))
-
-def __predict_true(exp): return __builtin_expect((exp), 1)
-
-def __predict_false(exp): return __builtin_expect((exp), 0)
-
-def __predict_true(exp): return (exp)
-
-def __predict_false(exp): return (exp)
-
-def __format_arg(fmtarg): return __attribute__((__format_arg__ (fmtarg)))
-
-def __FBSDID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-
-def __RCSID(s): return __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-
-def __RCSID_SOURCE(s): return __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
-
-def __SCCSID(s): return __IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
-
-def __COPYRIGHT(s): return __IDSTRING(__CONCAT(__copyright_,__LINE__),s)
-
-_POSIX_C_SOURCE = 199009
-_POSIX_C_SOURCE = 199209
-__XSI_VISIBLE = 600
-_POSIX_C_SOURCE = 200112
-__XSI_VISIBLE = 500
-_POSIX_C_SOURCE = 199506
-_POSIX_C_SOURCE = 198808
-__POSIX_VISIBLE = 200112
-__ISO_C_VISIBLE = 1999
-__POSIX_VISIBLE = 199506
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199309
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199209
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 199009
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 198808
-__ISO_C_VISIBLE = 0
-__POSIX_VISIBLE = 0
-__XSI_VISIBLE = 0
-__BSD_VISIBLE = 0
-__ISO_C_VISIBLE = 1990
-__POSIX_VISIBLE = 0
-__XSI_VISIBLE = 0
-__BSD_VISIBLE = 0
-__ISO_C_VISIBLE = 1999
-__POSIX_VISIBLE = 200112
-__XSI_VISIBLE = 600
-__BSD_VISIBLE = 1
-__ISO_C_VISIBLE = 1999
-
-# Included from sys/_types.h
-
-# Included from machine/_types.h
-
-# Included from machine/endian.h
-_QUAD_HIGHWORD = 1
-_QUAD_LOWWORD = 0
-_LITTLE_ENDIAN = 1234
-_BIG_ENDIAN = 4321
-_PDP_ENDIAN = 3412
-_BYTE_ORDER = _LITTLE_ENDIAN
-LITTLE_ENDIAN = _LITTLE_ENDIAN
-BIG_ENDIAN = _BIG_ENDIAN
-PDP_ENDIAN = _PDP_ENDIAN
-BYTE_ORDER = _BYTE_ORDER
-def __word_swap_int_var(x): return \
-
-def __word_swap_int_const(x): return \
-
-def __word_swap_int(x): return __word_swap_int_var(x)
-
-def __byte_swap_int_var(x): return \
-
-def __byte_swap_int_const(x): return \
-
-def __byte_swap_int(x): return __byte_swap_int_var(x)
-
-def __byte_swap_word_var(x): return \
-
-def __byte_swap_word_const(x): return \
-
-def __byte_swap_word(x): return __byte_swap_word_var(x)
-
-def __htonl(x): return __bswap32(x)
-
-def __htons(x): return __bswap16(x)
-
-def __ntohl(x): return __bswap32(x)
-
-def __ntohs(x): return __bswap16(x)
-
-IPPROTO_IP = 0
-IPPROTO_ICMP = 1
-IPPROTO_TCP = 6
-IPPROTO_UDP = 17
-def htonl(x): return __htonl(x)
-
-def htons(x): return __htons(x)
-
-def ntohl(x): return __ntohl(x)
-
-def ntohs(x): return __ntohs(x)
-
-IPPROTO_RAW = 255
-INET_ADDRSTRLEN = 16
-IPPROTO_HOPOPTS = 0
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPV4 = 4
-IPPROTO_IPIP = IPPROTO_IPV4
-IPPROTO_ST = 7
-IPPROTO_EGP = 8
-IPPROTO_PIGP = 9
-IPPROTO_RCCMON = 10
-IPPROTO_NVPII = 11
-IPPROTO_PUP = 12
-IPPROTO_ARGUS = 13
-IPPROTO_EMCON = 14
-IPPROTO_XNET = 15
-IPPROTO_CHAOS = 16
-IPPROTO_MUX = 18
-IPPROTO_MEAS = 19
-IPPROTO_HMP = 20
-IPPROTO_PRM = 21
-IPPROTO_IDP = 22
-IPPROTO_TRUNK1 = 23
-IPPROTO_TRUNK2 = 24
-IPPROTO_LEAF1 = 25
-IPPROTO_LEAF2 = 26
-IPPROTO_RDP = 27
-IPPROTO_IRTP = 28
-IPPROTO_TP = 29
-IPPROTO_BLT = 30
-IPPROTO_NSP = 31
-IPPROTO_INP = 32
-IPPROTO_SEP = 33
-IPPROTO_3PC = 34
-IPPROTO_IDPR = 35
-IPPROTO_XTP = 36
-IPPROTO_DDP = 37
-IPPROTO_CMTP = 38
-IPPROTO_TPXX = 39
-IPPROTO_IL = 40
-IPPROTO_IPV6 = 41
-IPPROTO_SDRP = 42
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_IDRP = 45
-IPPROTO_RSVP = 46
-IPPROTO_GRE = 47
-IPPROTO_MHRP = 48
-IPPROTO_BHA = 49
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_INLSP = 52
-IPPROTO_SWIPE = 53
-IPPROTO_NHRP = 54
-IPPROTO_MOBILE = 55
-IPPROTO_TLSP = 56
-IPPROTO_SKIP = 57
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_AHIP = 61
-IPPROTO_CFTP = 62
-IPPROTO_HELLO = 63
-IPPROTO_SATEXPAK = 64
-IPPROTO_KRYPTOLAN = 65
-IPPROTO_RVD = 66
-IPPROTO_IPPC = 67
-IPPROTO_ADFS = 68
-IPPROTO_SATMON = 69
-IPPROTO_VISA = 70
-IPPROTO_IPCV = 71
-IPPROTO_CPNX = 72
-IPPROTO_CPHB = 73
-IPPROTO_WSN = 74
-IPPROTO_PVP = 75
-IPPROTO_BRSATMON = 76
-IPPROTO_ND = 77
-IPPROTO_WBMON = 78
-IPPROTO_WBEXPAK = 79
-IPPROTO_EON = 80
-IPPROTO_VMTP = 81
-IPPROTO_SVMTP = 82
-IPPROTO_VINES = 83
-IPPROTO_TTP = 84
-IPPROTO_IGP = 85
-IPPROTO_DGP = 86
-IPPROTO_TCF = 87
-IPPROTO_IGRP = 88
-IPPROTO_OSPFIGP = 89
-IPPROTO_SRPC = 90
-IPPROTO_LARP = 91
-IPPROTO_MTP = 92
-IPPROTO_AX25 = 93
-IPPROTO_IPEIP = 94
-IPPROTO_MICP = 95
-IPPROTO_SCCSP = 96
-IPPROTO_ETHERIP = 97
-IPPROTO_ENCAP = 98
-IPPROTO_APES = 99
-IPPROTO_GMTP = 100
-IPPROTO_IPCOMP = 108
-IPPROTO_SCTP = 132
-IPPROTO_PIM = 103
-IPPROTO_CARP = 112
-IPPROTO_PGM = 113
-IPPROTO_PFSYNC = 240
-IPPROTO_OLD_DIVERT = 254
-IPPROTO_MAX = 256
-IPPROTO_DONE = 257
-IPPROTO_DIVERT = 258
-IPPROTO_SPACER = 32767
-IPPORT_RESERVED = 1024
-IPPORT_HIFIRSTAUTO = 49152
-IPPORT_HILASTAUTO = 65535
-IPPORT_RESERVEDSTART = 600
-IPPORT_MAX = 65535
-def IN_CLASSA(i): return (((u_int32_t)(i) & (-2147483648)) == 0)
-
-IN_CLASSA_NET = (-16777216)
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((u_int32_t)(i) & (-1073741824)) == (-2147483648))
-
-IN_CLASSB_NET = (-65536)
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((u_int32_t)(i) & (-536870912)) == (-1073741824))
-
-IN_CLASSC_NET = (-256)
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((u_int32_t)(i) & (-268435456)) == (-536870912))
-
-IN_CLASSD_NET = (-268435456)
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-def IN_EXPERIMENTAL(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
-
-def IN_BADCLASS(i): return (((u_int32_t)(i) & (-268435456)) == (-268435456))
-
-def IN_LINKLOCAL(i): return (((u_int32_t)(i) & (-65536)) == (-1442971648))
-
-def IN_LOCAL_GROUP(i): return (((u_int32_t)(i) & (-256)) == (-536870912))
-
-INADDR_NONE = (-1)
-IN_LOOPBACKNET = 127
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_SENDSRCADDR = IP_RECVDSTADDR
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_MULTICAST_VIF = 14
-IP_RSVP_ON = 15
-IP_RSVP_OFF = 16
-IP_RSVP_VIF_ON = 17
-IP_RSVP_VIF_OFF = 18
-IP_PORTRANGE = 19
-IP_RECVIF = 20
-IP_IPSEC_POLICY = 21
-IP_FAITH = 22
-IP_ONESBCAST = 23
-IP_FW_TABLE_ADD = 40
-IP_FW_TABLE_DEL = 41
-IP_FW_TABLE_FLUSH = 42
-IP_FW_TABLE_GETSIZE = 43
-IP_FW_TABLE_LIST = 44
-IP_FW_ADD = 50
-IP_FW_DEL = 51
-IP_FW_FLUSH = 52
-IP_FW_ZERO = 53
-IP_FW_GET = 54
-IP_FW_RESETLOG = 55
-IP_FW_NAT_CFG = 56
-IP_FW_NAT_DEL = 57
-IP_FW_NAT_GET_CONFIG = 58
-IP_FW_NAT_GET_LOG = 59
-IP_DUMMYNET_CONFIGURE = 60
-IP_DUMMYNET_DEL = 61
-IP_DUMMYNET_FLUSH = 62
-IP_DUMMYNET_GET = 64
-IP_RECVTTL = 65
-IP_MINTTL = 66
-IP_DONTFRAG = 67
-IP_ADD_SOURCE_MEMBERSHIP = 70
-IP_DROP_SOURCE_MEMBERSHIP = 71
-IP_BLOCK_SOURCE = 72
-IP_UNBLOCK_SOURCE = 73
-IP_MSFILTER = 74
-MCAST_JOIN_GROUP = 80
-MCAST_LEAVE_GROUP = 81
-MCAST_JOIN_SOURCE_GROUP = 82
-MCAST_LEAVE_SOURCE_GROUP = 83
-MCAST_BLOCK_SOURCE = 84
-MCAST_UNBLOCK_SOURCE = 85
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MIN_MEMBERSHIPS = 31
-IP_MAX_MEMBERSHIPS = 4095
-IP_MAX_SOURCE_FILTER = 1024
-MCAST_INCLUDE = 1
-MCAST_EXCLUDE = 2
-IP_PORTRANGE_DEFAULT = 0
-IP_PORTRANGE_HIGH = 1
-IP_PORTRANGE_LOW = 2
-IPPROTO_MAXID = (IPPROTO_AH + 1)
-IPCTL_FORWARDING = 1
-IPCTL_SENDREDIRECTS = 2
-IPCTL_DEFTTL = 3
-IPCTL_DEFMTU = 4
-IPCTL_RTEXPIRE = 5
-IPCTL_RTMINEXPIRE = 6
-IPCTL_RTMAXCACHE = 7
-IPCTL_SOURCEROUTE = 8
-IPCTL_DIRECTEDBROADCAST = 9
-IPCTL_INTRQMAXLEN = 10
-IPCTL_INTRQDROPS = 11
-IPCTL_STATS = 12
-IPCTL_ACCEPTSOURCEROUTE = 13
-IPCTL_FASTFORWARDING = 14
-IPCTL_KEEPFAITH = 15
-IPCTL_GIF_TTL = 16
-IPCTL_MAXID = 17
-def in_nullhost(x): return ((x).s_addr == INADDR_ANY)
-
-
-# Included from netinet6/in6.h
-__KAME_VERSION = "FreeBSD"
-IPV6PORT_RESERVED = 1024
-IPV6PORT_ANONMIN = 49152
-IPV6PORT_ANONMAX = 65535
-IPV6PORT_RESERVEDMIN = 600
-IPV6PORT_RESERVEDMAX = (IPV6PORT_RESERVED-1)
-INET6_ADDRSTRLEN = 46
-IPV6_ADDR_INT32_ONE = 1
-IPV6_ADDR_INT32_TWO = 2
-IPV6_ADDR_INT32_MNL = (-16711680)
-IPV6_ADDR_INT32_MLL = (-16646144)
-IPV6_ADDR_INT32_SMP = 0x0000ffff
-IPV6_ADDR_INT16_ULL = 0xfe80
-IPV6_ADDR_INT16_USL = 0xfec0
-IPV6_ADDR_INT16_MLL = 0xff02
-IPV6_ADDR_INT32_ONE = 0x01000000
-IPV6_ADDR_INT32_TWO = 0x02000000
-IPV6_ADDR_INT32_MNL = 0x000001ff
-IPV6_ADDR_INT32_MLL = 0x000002ff
-IPV6_ADDR_INT32_SMP = (-65536)
-IPV6_ADDR_INT16_ULL = 0x80fe
-IPV6_ADDR_INT16_USL = 0xc0fe
-IPV6_ADDR_INT16_MLL = 0x02ff
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
-
-def IN6_IS_ADDR_LOOPBACK(a): return \
-
-def IN6_IS_ADDR_V4COMPAT(a): return \
-
-def IN6_IS_ADDR_V4MAPPED(a): return \
-
-IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-IPV6_ADDR_SCOPE_INTFACELOCAL = 0x01
-IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-__IPV6_ADDR_SCOPE_NODELOCAL = 0x01
-__IPV6_ADDR_SCOPE_INTFACELOCAL = 0x01
-__IPV6_ADDR_SCOPE_LINKLOCAL = 0x02
-__IPV6_ADDR_SCOPE_SITELOCAL = 0x05
-__IPV6_ADDR_SCOPE_ORGLOCAL = 0x08
-__IPV6_ADDR_SCOPE_GLOBAL = 0x0e
-def IN6_IS_ADDR_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_INTFACELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-def IN6_IS_SCOPE_LINKLOCAL(a): return \
-
-def IN6_IS_SCOPE_EMBED(a): return \
-
-def IFA6_IS_DEPRECATED(a): return \
-
-def IFA6_IS_INVALID(a): return \
-
-IPV6_OPTIONS = 1
-IPV6_RECVOPTS = 5
-IPV6_RECVRETOPTS = 6
-IPV6_RECVDSTADDR = 7
-IPV6_RETOPTS = 8
-IPV6_SOCKOPT_RESERVED1 = 3
-IPV6_UNICAST_HOPS = 4
-IPV6_MULTICAST_IF = 9
-IPV6_MULTICAST_HOPS = 10
-IPV6_MULTICAST_LOOP = 11
-IPV6_JOIN_GROUP = 12
-IPV6_LEAVE_GROUP = 13
-IPV6_PORTRANGE = 14
-ICMP6_FILTER = 18
-IPV6_2292PKTINFO = 19
-IPV6_2292HOPLIMIT = 20
-IPV6_2292NEXTHOP = 21
-IPV6_2292HOPOPTS = 22
-IPV6_2292DSTOPTS = 23
-IPV6_2292RTHDR = 24
-IPV6_2292PKTOPTIONS = 25
-IPV6_CHECKSUM = 26
-IPV6_V6ONLY = 27
-IPV6_BINDV6ONLY = IPV6_V6ONLY
-IPV6_IPSEC_POLICY = 28
-IPV6_FAITH = 29
-IPV6_FW_ADD = 30
-IPV6_FW_DEL = 31
-IPV6_FW_FLUSH = 32
-IPV6_FW_ZERO = 33
-IPV6_FW_GET = 34
-IPV6_RTHDRDSTOPTS = 35
-IPV6_RECVPKTINFO = 36
-IPV6_RECVHOPLIMIT = 37
-IPV6_RECVRTHDR = 38
-IPV6_RECVHOPOPTS = 39
-IPV6_RECVDSTOPTS = 40
-IPV6_RECVRTHDRDSTOPTS = 41
-IPV6_USE_MIN_MTU = 42
-IPV6_RECVPATHMTU = 43
-IPV6_PATHMTU = 44
-IPV6_REACHCONF = 45
-IPV6_PKTINFO = 46
-IPV6_HOPLIMIT = 47
-IPV6_NEXTHOP = 48
-IPV6_HOPOPTS = 49
-IPV6_DSTOPTS = 50
-IPV6_RTHDR = 51
-IPV6_PKTOPTIONS = 52
-IPV6_RECVTCLASS = 57
-IPV6_AUTOFLOWLABEL = 59
-IPV6_TCLASS = 61
-IPV6_DONTFRAG = 62
-IPV6_PREFER_TEMPADDR = 63
-IPV6_MSFILTER = 74
-IPV6_RTHDR_LOOSE = 0
-IPV6_RTHDR_STRICT = 1
-IPV6_RTHDR_TYPE_0 = 0
-IPV6_DEFAULT_MULTICAST_HOPS = 1
-IPV6_DEFAULT_MULTICAST_LOOP = 1
-IPV6_PORTRANGE_DEFAULT = 0
-IPV6_PORTRANGE_HIGH = 1
-IPV6_PORTRANGE_LOW = 2
-IPV6PROTO_MAXID = (IPPROTO_PIM + 1)
-IPV6CTL_FORWARDING = 1
-IPV6CTL_SENDREDIRECTS = 2
-IPV6CTL_DEFHLIM = 3
-IPV6CTL_DEFMTU = 4
-IPV6CTL_FORWSRCRT = 5
-IPV6CTL_STATS = 6
-IPV6CTL_MRTSTATS = 7
-IPV6CTL_MRTPROTO = 8
-IPV6CTL_MAXFRAGPACKETS = 9
-IPV6CTL_SOURCECHECK = 10
-IPV6CTL_SOURCECHECK_LOGINT = 11
-IPV6CTL_ACCEPT_RTADV = 12
-IPV6CTL_KEEPFAITH = 13
-IPV6CTL_LOG_INTERVAL = 14
-IPV6CTL_HDRNESTLIMIT = 15
-IPV6CTL_DAD_COUNT = 16
-IPV6CTL_AUTO_FLOWLABEL = 17
-IPV6CTL_DEFMCASTHLIM = 18
-IPV6CTL_GIF_HLIM = 19
-IPV6CTL_KAME_VERSION = 20
-IPV6CTL_USE_DEPRECATED = 21
-IPV6CTL_RR_PRUNE = 22
-IPV6CTL_MAPPED_ADDR = 23
-IPV6CTL_V6ONLY = 24
-IPV6CTL_RTEXPIRE = 25
-IPV6CTL_RTMINEXPIRE = 26
-IPV6CTL_RTMAXCACHE = 27
-IPV6CTL_USETEMPADDR = 32
-IPV6CTL_TEMPPLTIME = 33
-IPV6CTL_TEMPVLTIME = 34
-IPV6CTL_AUTO_LINKLOCAL = 35
-IPV6CTL_RIP6STATS = 36
-IPV6CTL_PREFER_TEMPADDR = 37
-IPV6CTL_ADDRCTLPOLICY = 38
-IPV6CTL_USE_DEFAULTZONE = 39
-IPV6CTL_MAXFRAGS = 41
-IPV6CTL_IFQ = 42
-IPV6CTL_ISATAPRTR = 43
-IPV6CTL_MCAST_PMTU = 44
-IPV6CTL_STEALTH = 45
-IPV6CTL_MAXID = 46
diff --git a/Lib/plat-freebsd8/regen b/Lib/plat-freebsd8/regen
deleted file mode 100755
index 8aa6898..0000000
--- a/Lib/plat-freebsd8/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-python ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-generic/regen b/Lib/plat-generic/regen
deleted file mode 100755
index c96167d..0000000
--- a/Lib/plat-generic/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-eval $PYTHON_FOR_BUILD ../../Tools/scripts/h2py.py -i "'(u_long)'" /usr/include/netinet/in.h
diff --git a/Lib/plat-linux/CDROM.py b/Lib/plat-linux/CDROM.py
deleted file mode 100644
index 4340936..0000000
--- a/Lib/plat-linux/CDROM.py
+++ /dev/null
@@ -1,207 +0,0 @@
-# Generated by h2py from /usr/include/linux/cdrom.h
-
-CDROMPAUSE = 0x5301
-CDROMRESUME = 0x5302
-CDROMPLAYMSF = 0x5303
-CDROMPLAYTRKIND = 0x5304
-CDROMREADTOCHDR = 0x5305
-CDROMREADTOCENTRY = 0x5306
-CDROMSTOP = 0x5307
-CDROMSTART = 0x5308
-CDROMEJECT = 0x5309
-CDROMVOLCTRL = 0x530a
-CDROMSUBCHNL = 0x530b
-CDROMREADMODE2 = 0x530c
-CDROMREADMODE1 = 0x530d
-CDROMREADAUDIO = 0x530e
-CDROMEJECT_SW = 0x530f
-CDROMMULTISESSION = 0x5310
-CDROM_GET_MCN = 0x5311
-CDROM_GET_UPC = CDROM_GET_MCN
-CDROMRESET = 0x5312
-CDROMVOLREAD = 0x5313
-CDROMREADRAW = 0x5314
-CDROMREADCOOKED = 0x5315
-CDROMSEEK = 0x5316
-CDROMPLAYBLK = 0x5317
-CDROMREADALL = 0x5318
-CDROMGETSPINDOWN = 0x531d
-CDROMSETSPINDOWN = 0x531e
-CDROMCLOSETRAY = 0x5319
-CDROM_SET_OPTIONS = 0x5320
-CDROM_CLEAR_OPTIONS = 0x5321
-CDROM_SELECT_SPEED = 0x5322
-CDROM_SELECT_DISC = 0x5323
-CDROM_MEDIA_CHANGED = 0x5325
-CDROM_DRIVE_STATUS = 0x5326
-CDROM_DISC_STATUS = 0x5327
-CDROM_CHANGER_NSLOTS = 0x5328
-CDROM_LOCKDOOR = 0x5329
-CDROM_DEBUG = 0x5330
-CDROM_GET_CAPABILITY = 0x5331
-CDROMAUDIOBUFSIZ = 0x5382
-DVD_READ_STRUCT = 0x5390
-DVD_WRITE_STRUCT = 0x5391
-DVD_AUTH = 0x5392
-CDROM_SEND_PACKET = 0x5393
-CDROM_NEXT_WRITABLE = 0x5394
-CDROM_LAST_WRITTEN = 0x5395
-CDROM_PACKET_SIZE = 12
-CGC_DATA_UNKNOWN = 0
-CGC_DATA_WRITE = 1
-CGC_DATA_READ = 2
-CGC_DATA_NONE = 3
-CD_MINS = 74
-CD_SECS = 60
-CD_FRAMES = 75
-CD_SYNC_SIZE = 12
-CD_MSF_OFFSET = 150
-CD_CHUNK_SIZE = 24
-CD_NUM_OF_CHUNKS = 98
-CD_FRAMESIZE_SUB = 96
-CD_HEAD_SIZE = 4
-CD_SUBHEAD_SIZE = 8
-CD_EDC_SIZE = 4
-CD_ZERO_SIZE = 8
-CD_ECC_SIZE = 276
-CD_FRAMESIZE = 2048
-CD_FRAMESIZE_RAW = 2352
-CD_FRAMESIZE_RAWER = 2646
-CD_FRAMESIZE_RAW1 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE)
-CD_FRAMESIZE_RAW0 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE)
-CD_XA_HEAD = (CD_HEAD_SIZE+CD_SUBHEAD_SIZE)
-CD_XA_TAIL = (CD_EDC_SIZE+CD_ECC_SIZE)
-CD_XA_SYNC_HEAD = (CD_SYNC_SIZE+CD_XA_HEAD)
-CDROM_LBA = 0x01
-CDROM_MSF = 0x02
-CDROM_DATA_TRACK = 0x04
-CDROM_LEADOUT = 0xAA
-CDROM_AUDIO_INVALID = 0x00
-CDROM_AUDIO_PLAY = 0x11
-CDROM_AUDIO_PAUSED = 0x12
-CDROM_AUDIO_COMPLETED = 0x13
-CDROM_AUDIO_ERROR = 0x14
-CDROM_AUDIO_NO_STATUS = 0x15
-CDC_CLOSE_TRAY = 0x1
-CDC_OPEN_TRAY = 0x2
-CDC_LOCK = 0x4
-CDC_SELECT_SPEED = 0x8
-CDC_SELECT_DISC = 0x10
-CDC_MULTI_SESSION = 0x20
-CDC_MCN = 0x40
-CDC_MEDIA_CHANGED = 0x80
-CDC_PLAY_AUDIO = 0x100
-CDC_RESET = 0x200
-CDC_IOCTLS = 0x400
-CDC_DRIVE_STATUS = 0x800
-CDC_GENERIC_PACKET = 0x1000
-CDC_CD_R = 0x2000
-CDC_CD_RW = 0x4000
-CDC_DVD = 0x8000
-CDC_DVD_R = 0x10000
-CDC_DVD_RAM = 0x20000
-CDS_NO_INFO = 0
-CDS_NO_DISC = 1
-CDS_TRAY_OPEN = 2
-CDS_DRIVE_NOT_READY = 3
-CDS_DISC_OK = 4
-CDS_AUDIO = 100
-CDS_DATA_1 = 101
-CDS_DATA_2 = 102
-CDS_XA_2_1 = 103
-CDS_XA_2_2 = 104
-CDS_MIXED = 105
-CDO_AUTO_CLOSE = 0x1
-CDO_AUTO_EJECT = 0x2
-CDO_USE_FFLAGS = 0x4
-CDO_LOCK = 0x8
-CDO_CHECK_TYPE = 0x10
-CD_PART_MAX = 64
-CD_PART_MASK = (CD_PART_MAX - 1)
-GPCMD_BLANK = 0xa1
-GPCMD_CLOSE_TRACK = 0x5b
-GPCMD_FLUSH_CACHE = 0x35
-GPCMD_FORMAT_UNIT = 0x04
-GPCMD_GET_CONFIGURATION = 0x46
-GPCMD_GET_EVENT_STATUS_NOTIFICATION = 0x4a
-GPCMD_GET_PERFORMANCE = 0xac
-GPCMD_INQUIRY = 0x12
-GPCMD_LOAD_UNLOAD = 0xa6
-GPCMD_MECHANISM_STATUS = 0xbd
-GPCMD_MODE_SELECT_10 = 0x55
-GPCMD_MODE_SENSE_10 = 0x5a
-GPCMD_PAUSE_RESUME = 0x4b
-GPCMD_PLAY_AUDIO_10 = 0x45
-GPCMD_PLAY_AUDIO_MSF = 0x47
-GPCMD_PLAY_AUDIO_TI = 0x48
-GPCMD_PLAY_CD = 0xbc
-GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e
-GPCMD_READ_10 = 0x28
-GPCMD_READ_12 = 0xa8
-GPCMD_READ_CDVD_CAPACITY = 0x25
-GPCMD_READ_CD = 0xbe
-GPCMD_READ_CD_MSF = 0xb9
-GPCMD_READ_DISC_INFO = 0x51
-GPCMD_READ_DVD_STRUCTURE = 0xad
-GPCMD_READ_FORMAT_CAPACITIES = 0x23
-GPCMD_READ_HEADER = 0x44
-GPCMD_READ_TRACK_RZONE_INFO = 0x52
-GPCMD_READ_SUBCHANNEL = 0x42
-GPCMD_READ_TOC_PMA_ATIP = 0x43
-GPCMD_REPAIR_RZONE_TRACK = 0x58
-GPCMD_REPORT_KEY = 0xa4
-GPCMD_REQUEST_SENSE = 0x03
-GPCMD_RESERVE_RZONE_TRACK = 0x53
-GPCMD_SCAN = 0xba
-GPCMD_SEEK = 0x2b
-GPCMD_SEND_DVD_STRUCTURE = 0xad
-GPCMD_SEND_EVENT = 0xa2
-GPCMD_SEND_KEY = 0xa3
-GPCMD_SEND_OPC = 0x54
-GPCMD_SET_READ_AHEAD = 0xa7
-GPCMD_SET_STREAMING = 0xb6
-GPCMD_START_STOP_UNIT = 0x1b
-GPCMD_STOP_PLAY_SCAN = 0x4e
-GPCMD_TEST_UNIT_READY = 0x00
-GPCMD_VERIFY_10 = 0x2f
-GPCMD_WRITE_10 = 0x2a
-GPCMD_WRITE_AND_VERIFY_10 = 0x2e
-GPCMD_SET_SPEED = 0xbb
-GPCMD_PLAYAUDIO_TI = 0x48
-GPCMD_GET_MEDIA_STATUS = 0xda
-GPMODE_R_W_ERROR_PAGE = 0x01
-GPMODE_WRITE_PARMS_PAGE = 0x05
-GPMODE_AUDIO_CTL_PAGE = 0x0e
-GPMODE_POWER_PAGE = 0x1a
-GPMODE_FAULT_FAIL_PAGE = 0x1c
-GPMODE_TO_PROTECT_PAGE = 0x1d
-GPMODE_CAPABILITIES_PAGE = 0x2a
-GPMODE_ALL_PAGES = 0x3f
-GPMODE_CDROM_PAGE = 0x0d
-DVD_STRUCT_PHYSICAL = 0x00
-DVD_STRUCT_COPYRIGHT = 0x01
-DVD_STRUCT_DISCKEY = 0x02
-DVD_STRUCT_BCA = 0x03
-DVD_STRUCT_MANUFACT = 0x04
-DVD_LAYERS = 4
-DVD_LU_SEND_AGID = 0
-DVD_HOST_SEND_CHALLENGE = 1
-DVD_LU_SEND_KEY1 = 2
-DVD_LU_SEND_CHALLENGE = 3
-DVD_HOST_SEND_KEY2 = 4
-DVD_AUTH_ESTABLISHED = 5
-DVD_AUTH_FAILURE = 6
-DVD_LU_SEND_TITLE_KEY = 7
-DVD_LU_SEND_ASF = 8
-DVD_INVALIDATE_AGID = 9
-DVD_LU_SEND_RPC_STATE = 10
-DVD_HOST_SEND_RPC_STATE = 11
-DVD_CPM_NO_COPYRIGHT = 0
-DVD_CPM_COPYRIGHTED = 1
-DVD_CP_SEC_NONE = 0
-DVD_CP_SEC_EXIST = 1
-DVD_CGMS_UNRESTRICTED = 0
-DVD_CGMS_SINGLE = 2
-DVD_CGMS_RESTRICTED = 3
-
-CDROM_MAX_SLOTS = 256
diff --git a/Lib/plat-linux/DLFCN.py b/Lib/plat-linux/DLFCN.py
deleted file mode 100644
index dd10ac4..0000000
--- a/Lib/plat-linux/DLFCN.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# Generated by h2py from /usr/include/dlfcn.h
-_DLFCN_H = 1
-
-# Included from features.h
-_FEATURES_H = 1
-__USE_ANSI = 1
-__FAVOR_BSD = 1
-_ISOC99_SOURCE = 1
-_POSIX_SOURCE = 1
-_POSIX_C_SOURCE = 199506
-_XOPEN_SOURCE = 600
-_XOPEN_SOURCE_EXTENDED = 1
-_LARGEFILE64_SOURCE = 1
-_BSD_SOURCE = 1
-_SVID_SOURCE = 1
-_BSD_SOURCE = 1
-_SVID_SOURCE = 1
-__USE_ISOC99 = 1
-_POSIX_SOURCE = 1
-_POSIX_C_SOURCE = 2
-_POSIX_C_SOURCE = 199506
-__USE_POSIX = 1
-__USE_POSIX2 = 1
-__USE_POSIX199309 = 1
-__USE_POSIX199506 = 1
-__USE_XOPEN = 1
-__USE_XOPEN_EXTENDED = 1
-__USE_UNIX98 = 1
-_LARGEFILE_SOURCE = 1
-__USE_XOPEN2K = 1
-__USE_ISOC99 = 1
-__USE_XOPEN_EXTENDED = 1
-__USE_LARGEFILE = 1
-__USE_LARGEFILE64 = 1
-__USE_FILE_OFFSET64 = 1
-__USE_MISC = 1
-__USE_BSD = 1
-__USE_SVID = 1
-__USE_GNU = 1
-__USE_REENTRANT = 1
-__STDC_IEC_559__ = 1
-__STDC_IEC_559_COMPLEX__ = 1
-__STDC_ISO_10646__ = 200009
-__GNU_LIBRARY__ = 6
-__GLIBC__ = 2
-__GLIBC_MINOR__ = 2
-
-# Included from sys/cdefs.h
-_SYS_CDEFS_H = 1
-def __PMT(args): return args
-
-def __P(args): return args
-
-def __PMT(args): return args
-
-def __STRING(x): return #x
-
-__flexarr = []
-__flexarr = [0]
-__flexarr = []
-__flexarr = [1]
-def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
-
-def __attribute__(xyz): return
-
-def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
-
-def __attribute_format_arg__(x): return
-
-__USE_LARGEFILE = 1
-__USE_LARGEFILE64 = 1
-__USE_EXTERN_INLINES = 1
-
-# Included from gnu/stubs.h
-
-# Included from bits/dlfcn.h
-RTLD_LAZY = 0x00001
-RTLD_NOW = 0x00002
-RTLD_BINDING_MASK = 0x3
-RTLD_NOLOAD = 0x00004
-RTLD_GLOBAL = 0x00100
-RTLD_LOCAL = 0
-RTLD_NODELETE = 0x01000
diff --git a/Lib/plat-linux/IN.py b/Lib/plat-linux/IN.py
deleted file mode 100644
index d7d3002..0000000
--- a/Lib/plat-linux/IN.py
+++ /dev/null
@@ -1,615 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-_NETINET_IN_H = 1
-
-# Included from features.h
-_FEATURES_H = 1
-__USE_ANSI = 1
-__FAVOR_BSD = 1
-_ISOC99_SOURCE = 1
-_POSIX_SOURCE = 1
-_POSIX_C_SOURCE = 199506
-_XOPEN_SOURCE = 600
-_XOPEN_SOURCE_EXTENDED = 1
-_LARGEFILE64_SOURCE = 1
-_BSD_SOURCE = 1
-_SVID_SOURCE = 1
-_BSD_SOURCE = 1
-_SVID_SOURCE = 1
-__USE_ISOC99 = 1
-_POSIX_SOURCE = 1
-_POSIX_C_SOURCE = 2
-_POSIX_C_SOURCE = 199506
-__USE_POSIX = 1
-__USE_POSIX2 = 1
-__USE_POSIX199309 = 1
-__USE_POSIX199506 = 1
-__USE_XOPEN = 1
-__USE_XOPEN_EXTENDED = 1
-__USE_UNIX98 = 1
-_LARGEFILE_SOURCE = 1
-__USE_XOPEN2K = 1
-__USE_ISOC99 = 1
-__USE_XOPEN_EXTENDED = 1
-__USE_LARGEFILE = 1
-__USE_LARGEFILE64 = 1
-__USE_FILE_OFFSET64 = 1
-__USE_MISC = 1
-__USE_BSD = 1
-__USE_SVID = 1
-__USE_GNU = 1
-__USE_REENTRANT = 1
-__STDC_IEC_559__ = 1
-__STDC_IEC_559_COMPLEX__ = 1
-__STDC_ISO_10646__ = 200009
-__GNU_LIBRARY__ = 6
-__GLIBC__ = 2
-__GLIBC_MINOR__ = 2
-
-# Included from sys/cdefs.h
-_SYS_CDEFS_H = 1
-def __PMT(args): return args
-
-def __P(args): return args
-
-def __PMT(args): return args
-
-def __STRING(x): return #x
-
-__flexarr = []
-__flexarr = [0]
-__flexarr = []
-__flexarr = [1]
-def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
-
-def __attribute__(xyz): return
-
-def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
-
-def __attribute_format_arg__(x): return
-
-__USE_LARGEFILE = 1
-__USE_LARGEFILE64 = 1
-__USE_EXTERN_INLINES = 1
-
-# Included from gnu/stubs.h
-
-# Included from stdint.h
-_STDINT_H = 1
-
-# Included from bits/wchar.h
-_BITS_WCHAR_H = 1
-__WCHAR_MIN = (-2147483647 - 1)
-__WCHAR_MAX = (2147483647)
-
-# Included from bits/wordsize.h
-__WORDSIZE = 32
-def __INT64_C(c): return c ## L
-
-def __UINT64_C(c): return c ## UL
-
-def __INT64_C(c): return c ## LL
-
-def __UINT64_C(c): return c ## ULL
-
-INT8_MIN = (-128)
-INT16_MIN = (-32767-1)
-INT32_MIN = (-2147483647-1)
-INT64_MIN = (-__INT64_C(9223372036854775807)-1)
-INT8_MAX = (127)
-INT16_MAX = (32767)
-INT32_MAX = (2147483647)
-INT64_MAX = (__INT64_C(9223372036854775807))
-UINT8_MAX = (255)
-UINT16_MAX = (65535)
-UINT64_MAX = (__UINT64_C(18446744073709551615))
-INT_LEAST8_MIN = (-128)
-INT_LEAST16_MIN = (-32767-1)
-INT_LEAST32_MIN = (-2147483647-1)
-INT_LEAST64_MIN = (-__INT64_C(9223372036854775807)-1)
-INT_LEAST8_MAX = (127)
-INT_LEAST16_MAX = (32767)
-INT_LEAST32_MAX = (2147483647)
-INT_LEAST64_MAX = (__INT64_C(9223372036854775807))
-UINT_LEAST8_MAX = (255)
-UINT_LEAST16_MAX = (65535)
-UINT_LEAST64_MAX = (__UINT64_C(18446744073709551615))
-INT_FAST8_MIN = (-128)
-INT_FAST16_MIN = (-9223372036854775807-1)
-INT_FAST32_MIN = (-9223372036854775807-1)
-INT_FAST16_MIN = (-2147483647-1)
-INT_FAST32_MIN = (-2147483647-1)
-INT_FAST64_MIN = (-__INT64_C(9223372036854775807)-1)
-INT_FAST8_MAX = (127)
-INT_FAST16_MAX = (9223372036854775807)
-INT_FAST32_MAX = (9223372036854775807)
-INT_FAST16_MAX = (2147483647)
-INT_FAST32_MAX = (2147483647)
-INT_FAST64_MAX = (__INT64_C(9223372036854775807))
-UINT_FAST8_MAX = (255)
-UINT_FAST64_MAX = (__UINT64_C(18446744073709551615))
-INTPTR_MIN = (-9223372036854775807-1)
-INTPTR_MAX = (9223372036854775807)
-INTPTR_MIN = (-2147483647-1)
-INTPTR_MAX = (2147483647)
-INTMAX_MIN = (-__INT64_C(9223372036854775807)-1)
-INTMAX_MAX = (__INT64_C(9223372036854775807))
-UINTMAX_MAX = (__UINT64_C(18446744073709551615))
-PTRDIFF_MIN = (-9223372036854775807-1)
-PTRDIFF_MAX = (9223372036854775807)
-PTRDIFF_MIN = (-2147483647-1)
-PTRDIFF_MAX = (2147483647)
-SIG_ATOMIC_MIN = (-2147483647-1)
-SIG_ATOMIC_MAX = (2147483647)
-WCHAR_MIN = __WCHAR_MIN
-WCHAR_MAX = __WCHAR_MAX
-def INT8_C(c): return c
-
-def INT16_C(c): return c
-
-def INT32_C(c): return c
-
-def INT64_C(c): return c ## L
-
-def INT64_C(c): return c ## LL
-
-def UINT8_C(c): return c ## U
-
-def UINT16_C(c): return c ## U
-
-def UINT32_C(c): return c ## U
-
-def UINT64_C(c): return c ## UL
-
-def UINT64_C(c): return c ## ULL
-
-def INTMAX_C(c): return c ## L
-
-def UINTMAX_C(c): return c ## UL
-
-def INTMAX_C(c): return c ## LL
-
-def UINTMAX_C(c): return c ## ULL
-
-
-# Included from bits/types.h
-_BITS_TYPES_H = 1
-__FD_SETSIZE = 1024
-
-# Included from bits/pthreadtypes.h
-_BITS_PTHREADTYPES_H = 1
-
-# Included from bits/sched.h
-SCHED_OTHER = 0
-SCHED_FIFO = 1
-SCHED_RR = 2
-CSIGNAL = 0x000000ff
-CLONE_VM = 0x00000100
-CLONE_FS = 0x00000200
-CLONE_FILES = 0x00000400
-CLONE_SIGHAND = 0x00000800
-CLONE_PID = 0x00001000
-CLONE_PTRACE = 0x00002000
-CLONE_VFORK = 0x00004000
-__defined_schedparam = 1
-def IN_CLASSA(a): return ((((in_addr_t)(a)) & (-2147483648)) == 0)
-
-IN_CLASSA_NET = (-16777216)
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = ((-1) & ~IN_CLASSA_NET)
-IN_CLASSA_MAX = 128
-def IN_CLASSB(a): return ((((in_addr_t)(a)) & (-1073741824)) == (-2147483648))
-
-IN_CLASSB_NET = (-65536)
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = ((-1) & ~IN_CLASSB_NET)
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(a): return ((((in_addr_t)(a)) & (-536870912)) == (-1073741824))
-
-IN_CLASSC_NET = (-256)
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = ((-1) & ~IN_CLASSC_NET)
-def IN_CLASSD(a): return ((((in_addr_t)(a)) & (-268435456)) == (-536870912))
-
-def IN_MULTICAST(a): return IN_CLASSD(a)
-
-def IN_EXPERIMENTAL(a): return ((((in_addr_t)(a)) & (-536870912)) == (-536870912))
-
-def IN_BADCLASS(a): return ((((in_addr_t)(a)) & (-268435456)) == (-268435456))
-
-IN_LOOPBACKNET = 127
-INET_ADDRSTRLEN = 16
-INET6_ADDRSTRLEN = 46
-
-# Included from bits/socket.h
-
-# Included from limits.h
-_LIBC_LIMITS_H_ = 1
-MB_LEN_MAX = 16
-_LIMITS_H = 1
-CHAR_BIT = 8
-SCHAR_MIN = (-128)
-SCHAR_MAX = 127
-UCHAR_MAX = 255
-CHAR_MIN = 0
-CHAR_MAX = UCHAR_MAX
-CHAR_MIN = SCHAR_MIN
-CHAR_MAX = SCHAR_MAX
-SHRT_MIN = (-32768)
-SHRT_MAX = 32767
-USHRT_MAX = 65535
-INT_MAX = 2147483647
-LONG_MAX = 9223372036854775807
-LONG_MAX = 2147483647
-LONG_MIN = (-LONG_MAX - 1)
-
-# Included from bits/posix1_lim.h
-_BITS_POSIX1_LIM_H = 1
-_POSIX_AIO_LISTIO_MAX = 2
-_POSIX_AIO_MAX = 1
-_POSIX_ARG_MAX = 4096
-_POSIX_CHILD_MAX = 6
-_POSIX_DELAYTIMER_MAX = 32
-_POSIX_LINK_MAX = 8
-_POSIX_MAX_CANON = 255
-_POSIX_MAX_INPUT = 255
-_POSIX_MQ_OPEN_MAX = 8
-_POSIX_MQ_PRIO_MAX = 32
-_POSIX_NGROUPS_MAX = 0
-_POSIX_OPEN_MAX = 16
-_POSIX_FD_SETSIZE = _POSIX_OPEN_MAX
-_POSIX_NAME_MAX = 14
-_POSIX_PATH_MAX = 256
-_POSIX_PIPE_BUF = 512
-_POSIX_RTSIG_MAX = 8
-_POSIX_SEM_NSEMS_MAX = 256
-_POSIX_SEM_VALUE_MAX = 32767
-_POSIX_SIGQUEUE_MAX = 32
-_POSIX_SSIZE_MAX = 32767
-_POSIX_STREAM_MAX = 8
-_POSIX_TZNAME_MAX = 6
-_POSIX_QLIMIT = 1
-_POSIX_HIWAT = _POSIX_PIPE_BUF
-_POSIX_UIO_MAXIOV = 16
-_POSIX_TTY_NAME_MAX = 9
-_POSIX_TIMER_MAX = 32
-_POSIX_LOGIN_NAME_MAX = 9
-_POSIX_CLOCKRES_MIN = 20000000
-
-# Included from bits/local_lim.h
-
-# Included from linux/limits.h
-NR_OPEN = 1024
-NGROUPS_MAX = 32
-ARG_MAX = 131072
-CHILD_MAX = 999
-OPEN_MAX = 256
-LINK_MAX = 127
-MAX_CANON = 255
-MAX_INPUT = 255
-NAME_MAX = 255
-PATH_MAX = 4096
-PIPE_BUF = 4096
-RTSIG_MAX = 32
-_POSIX_THREAD_KEYS_MAX = 128
-PTHREAD_KEYS_MAX = 1024
-_POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4
-PTHREAD_DESTRUCTOR_ITERATIONS = _POSIX_THREAD_DESTRUCTOR_ITERATIONS
-_POSIX_THREAD_THREADS_MAX = 64
-PTHREAD_THREADS_MAX = 1024
-AIO_PRIO_DELTA_MAX = 20
-PTHREAD_STACK_MIN = 16384
-TIMER_MAX = 256
-SSIZE_MAX = LONG_MAX
-NGROUPS_MAX = _POSIX_NGROUPS_MAX
-
-# Included from bits/posix2_lim.h
-_BITS_POSIX2_LIM_H = 1
-_POSIX2_BC_BASE_MAX = 99
-_POSIX2_BC_DIM_MAX = 2048
-_POSIX2_BC_SCALE_MAX = 99
-_POSIX2_BC_STRING_MAX = 1000
-_POSIX2_COLL_WEIGHTS_MAX = 2
-_POSIX2_EXPR_NEST_MAX = 32
-_POSIX2_LINE_MAX = 2048
-_POSIX2_RE_DUP_MAX = 255
-_POSIX2_CHARCLASS_NAME_MAX = 14
-BC_BASE_MAX = _POSIX2_BC_BASE_MAX
-BC_DIM_MAX = _POSIX2_BC_DIM_MAX
-BC_SCALE_MAX = _POSIX2_BC_SCALE_MAX
-BC_STRING_MAX = _POSIX2_BC_STRING_MAX
-COLL_WEIGHTS_MAX = 255
-EXPR_NEST_MAX = _POSIX2_EXPR_NEST_MAX
-LINE_MAX = _POSIX2_LINE_MAX
-CHARCLASS_NAME_MAX = 2048
-RE_DUP_MAX = (0x7fff)
-
-# Included from bits/xopen_lim.h
-_XOPEN_LIM_H = 1
-
-# Included from bits/stdio_lim.h
-L_tmpnam = 20
-TMP_MAX = 238328
-FILENAME_MAX = 4096
-L_ctermid = 9
-L_cuserid = 9
-FOPEN_MAX = 16
-IOV_MAX = 1024
-_XOPEN_IOV_MAX = _POSIX_UIO_MAXIOV
-NL_ARGMAX = _POSIX_ARG_MAX
-NL_LANGMAX = _POSIX2_LINE_MAX
-NL_MSGMAX = INT_MAX
-NL_NMAX = INT_MAX
-NL_SETMAX = INT_MAX
-NL_TEXTMAX = INT_MAX
-NZERO = 20
-WORD_BIT = 16
-WORD_BIT = 32
-WORD_BIT = 64
-WORD_BIT = 16
-WORD_BIT = 32
-WORD_BIT = 64
-WORD_BIT = 32
-LONG_BIT = 32
-LONG_BIT = 64
-LONG_BIT = 32
-LONG_BIT = 64
-LONG_BIT = 64
-LONG_BIT = 32
-from TYPES import *
-PF_UNSPEC = 0
-PF_LOCAL = 1
-PF_UNIX = PF_LOCAL
-PF_FILE = PF_LOCAL
-PF_INET = 2
-PF_AX25 = 3
-PF_IPX = 4
-PF_APPLETALK = 5
-PF_NETROM = 6
-PF_BRIDGE = 7
-PF_ATMPVC = 8
-PF_X25 = 9
-PF_INET6 = 10
-PF_ROSE = 11
-PF_DECnet = 12
-PF_NETBEUI = 13
-PF_SECURITY = 14
-PF_KEY = 15
-PF_NETLINK = 16
-PF_ROUTE = PF_NETLINK
-PF_PACKET = 17
-PF_ASH = 18
-PF_ECONET = 19
-PF_ATMSVC = 20
-PF_SNA = 22
-PF_IRDA = 23
-PF_PPPOX = 24
-PF_WANPIPE = 25
-PF_BLUETOOTH = 31
-PF_MAX = 32
-AF_UNSPEC = PF_UNSPEC
-AF_LOCAL = PF_LOCAL
-AF_UNIX = PF_UNIX
-AF_FILE = PF_FILE
-AF_INET = PF_INET
-AF_AX25 = PF_AX25
-AF_IPX = PF_IPX
-AF_APPLETALK = PF_APPLETALK
-AF_NETROM = PF_NETROM
-AF_BRIDGE = PF_BRIDGE
-AF_ATMPVC = PF_ATMPVC
-AF_X25 = PF_X25
-AF_INET6 = PF_INET6
-AF_ROSE = PF_ROSE
-AF_DECnet = PF_DECnet
-AF_NETBEUI = PF_NETBEUI
-AF_SECURITY = PF_SECURITY
-AF_KEY = PF_KEY
-AF_NETLINK = PF_NETLINK
-AF_ROUTE = PF_ROUTE
-AF_PACKET = PF_PACKET
-AF_ASH = PF_ASH
-AF_ECONET = PF_ECONET
-AF_ATMSVC = PF_ATMSVC
-AF_SNA = PF_SNA
-AF_IRDA = PF_IRDA
-AF_PPPOX = PF_PPPOX
-AF_WANPIPE = PF_WANPIPE
-AF_BLUETOOTH = PF_BLUETOOTH
-AF_MAX = PF_MAX
-SOL_RAW = 255
-SOL_DECNET = 261
-SOL_X25 = 262
-SOL_PACKET = 263
-SOL_ATM = 264
-SOL_AAL = 265
-SOL_IRDA = 266
-SOMAXCONN = 128
-
-# Included from bits/sockaddr.h
-_BITS_SOCKADDR_H = 1
-def __SOCKADDR_COMMON(sa_prefix): return \
-
-_SS_SIZE = 128
-def CMSG_FIRSTHDR(mhdr): return \
-
-
-# Included from asm/socket.h
-
-# Included from asm/sockios.h
-FIOSETOWN = 0x8901
-SIOCSPGRP = 0x8902
-FIOGETOWN = 0x8903
-SIOCGPGRP = 0x8904
-SIOCATMARK = 0x8905
-SIOCGSTAMP = 0x8906
-SOL_SOCKET = 1
-SO_DEBUG = 1
-SO_REUSEADDR = 2
-SO_TYPE = 3
-SO_ERROR = 4
-SO_DONTROUTE = 5
-SO_BROADCAST = 6
-SO_SNDBUF = 7
-SO_RCVBUF = 8
-SO_KEEPALIVE = 9
-SO_OOBINLINE = 10
-SO_NO_CHECK = 11
-SO_PRIORITY = 12
-SO_LINGER = 13
-SO_BSDCOMPAT = 14
-SO_PASSCRED = 16
-SO_PEERCRED = 17
-SO_RCVLOWAT = 18
-SO_SNDLOWAT = 19
-SO_RCVTIMEO = 20
-SO_SNDTIMEO = 21
-SO_SECURITY_AUTHENTICATION = 22
-SO_SECURITY_ENCRYPTION_TRANSPORT = 23
-SO_SECURITY_ENCRYPTION_NETWORK = 24
-SO_BINDTODEVICE = 25
-SO_ATTACH_FILTER = 26
-SO_DETACH_FILTER = 27
-SO_PEERNAME = 28
-SO_TIMESTAMP = 29
-SCM_TIMESTAMP = SO_TIMESTAMP
-SO_ACCEPTCONN = 30
-SOCK_STREAM = 1
-SOCK_DGRAM = 2
-SOCK_RAW = 3
-SOCK_RDM = 4
-SOCK_SEQPACKET = 5
-SOCK_PACKET = 10
-SOCK_MAX = (SOCK_PACKET+1)
-
-# Included from bits/in.h
-IP_TOS = 1
-IP_TTL = 2
-IP_HDRINCL = 3
-IP_OPTIONS = 4
-IP_ROUTER_ALERT = 5
-IP_RECVOPTS = 6
-IP_RETOPTS = 7
-IP_PKTINFO = 8
-IP_PKTOPTIONS = 9
-IP_PMTUDISC = 10
-IP_MTU_DISCOVER = 10
-IP_RECVERR = 11
-IP_RECVTTL = 12
-IP_RECVTOS = 13
-IP_MULTICAST_IF = 32
-IP_MULTICAST_TTL = 33
-IP_MULTICAST_LOOP = 34
-IP_ADD_MEMBERSHIP = 35
-IP_DROP_MEMBERSHIP = 36
-IP_RECVRETOPTS = IP_RETOPTS
-IP_PMTUDISC_DONT = 0
-IP_PMTUDISC_WANT = 1
-IP_PMTUDISC_DO = 2
-SOL_IP = 0
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
-IPV6_ADDRFORM = 1
-IPV6_PKTINFO = 2
-IPV6_HOPOPTS = 3
-IPV6_DSTOPTS = 4
-IPV6_RTHDR = 5
-IPV6_PKTOPTIONS = 6
-IPV6_CHECKSUM = 7
-IPV6_HOPLIMIT = 8
-IPV6_NEXTHOP = 9
-IPV6_AUTHHDR = 10
-IPV6_UNICAST_HOPS = 16
-IPV6_MULTICAST_IF = 17
-IPV6_MULTICAST_HOPS = 18
-IPV6_MULTICAST_LOOP = 19
-IPV6_JOIN_GROUP = 20
-IPV6_LEAVE_GROUP = 21
-IPV6_ROUTER_ALERT = 22
-IPV6_MTU_DISCOVER = 23
-IPV6_MTU = 24
-IPV6_RECVERR = 25
-IPV6_RXHOPOPTS = IPV6_HOPOPTS
-IPV6_RXDSTOPTS = IPV6_DSTOPTS
-IPV6_ADD_MEMBERSHIP = IPV6_JOIN_GROUP
-IPV6_DROP_MEMBERSHIP = IPV6_LEAVE_GROUP
-IPV6_PMTUDISC_DONT = 0
-IPV6_PMTUDISC_WANT = 1
-IPV6_PMTUDISC_DO = 2
-SOL_IPV6 = 41
-SOL_ICMPV6 = 58
-IPV6_RTHDR_LOOSE = 0
-IPV6_RTHDR_STRICT = 1
-IPV6_RTHDR_TYPE_0 = 0
-
-# Included from endian.h
-_ENDIAN_H = 1
-__LITTLE_ENDIAN = 1234
-__BIG_ENDIAN = 4321
-__PDP_ENDIAN = 3412
-
-# Included from bits/endian.h
-__BYTE_ORDER = __LITTLE_ENDIAN
-__FLOAT_WORD_ORDER = __BYTE_ORDER
-LITTLE_ENDIAN = __LITTLE_ENDIAN
-BIG_ENDIAN = __BIG_ENDIAN
-PDP_ENDIAN = __PDP_ENDIAN
-BYTE_ORDER = __BYTE_ORDER
-
-# Included from bits/byteswap.h
-_BITS_BYTESWAP_H = 1
-def __bswap_constant_16(x): return \
-
-def __bswap_16(x): return \
-
-def __bswap_16(x): return __bswap_constant_16 (x)
-
-def __bswap_constant_32(x): return \
-
-def __bswap_32(x): return \
-
-def __bswap_32(x): return \
-
-def __bswap_32(x): return __bswap_constant_32 (x)
-
-def __bswap_constant_64(x): return \
-
-def __bswap_64(x): return \
-
-def ntohl(x): return (x)
-
-def ntohs(x): return (x)
-
-def htonl(x): return (x)
-
-def htons(x): return (x)
-
-def ntohl(x): return __bswap_32 (x)
-
-def ntohs(x): return __bswap_16 (x)
-
-def htonl(x): return __bswap_32 (x)
-
-def htons(x): return __bswap_16 (x)
-
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
-
-def IN6_IS_ADDR_LOOPBACK(a): return \
-
-def IN6_IS_ADDR_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_V4MAPPED(a): return \
-
-def IN6_IS_ADDR_V4COMPAT(a): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return
diff --git a/Lib/plat-linux/TYPES.py b/Lib/plat-linux/TYPES.py
deleted file mode 100644
index e7a324b..0000000
--- a/Lib/plat-linux/TYPES.py
+++ /dev/null
@@ -1,170 +0,0 @@
-# Generated by h2py from /usr/include/sys/types.h
-_SYS_TYPES_H = 1
-
-# Included from features.h
-_FEATURES_H = 1
-__USE_ANSI = 1
-__FAVOR_BSD = 1
-_ISOC99_SOURCE = 1
-_POSIX_SOURCE = 1
-_POSIX_C_SOURCE = 199506
-_XOPEN_SOURCE = 600
-_XOPEN_SOURCE_EXTENDED = 1
-_LARGEFILE64_SOURCE = 1
-_BSD_SOURCE = 1
-_SVID_SOURCE = 1
-_BSD_SOURCE = 1
-_SVID_SOURCE = 1
-__USE_ISOC99 = 1
-_POSIX_SOURCE = 1
-_POSIX_C_SOURCE = 2
-_POSIX_C_SOURCE = 199506
-__USE_POSIX = 1
-__USE_POSIX2 = 1
-__USE_POSIX199309 = 1
-__USE_POSIX199506 = 1
-__USE_XOPEN = 1
-__USE_XOPEN_EXTENDED = 1
-__USE_UNIX98 = 1
-_LARGEFILE_SOURCE = 1
-__USE_XOPEN2K = 1
-__USE_ISOC99 = 1
-__USE_XOPEN_EXTENDED = 1
-__USE_LARGEFILE = 1
-__USE_LARGEFILE64 = 1
-__USE_FILE_OFFSET64 = 1
-__USE_MISC = 1
-__USE_BSD = 1
-__USE_SVID = 1
-__USE_GNU = 1
-__USE_REENTRANT = 1
-__STDC_IEC_559__ = 1
-__STDC_IEC_559_COMPLEX__ = 1
-__STDC_ISO_10646__ = 200009
-__GNU_LIBRARY__ = 6
-__GLIBC__ = 2
-__GLIBC_MINOR__ = 2
-
-# Included from sys/cdefs.h
-_SYS_CDEFS_H = 1
-def __PMT(args): return args
-
-def __P(args): return args
-
-def __PMT(args): return args
-
-def __STRING(x): return #x
-
-__flexarr = []
-__flexarr = [0]
-__flexarr = []
-__flexarr = [1]
-def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
-
-def __attribute__(xyz): return
-
-def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
-
-def __attribute_format_arg__(x): return
-
-__USE_LARGEFILE = 1
-__USE_LARGEFILE64 = 1
-__USE_EXTERN_INLINES = 1
-
-# Included from gnu/stubs.h
-
-# Included from bits/types.h
-_BITS_TYPES_H = 1
-__FD_SETSIZE = 1024
-
-# Included from bits/pthreadtypes.h
-_BITS_PTHREADTYPES_H = 1
-
-# Included from bits/sched.h
-SCHED_OTHER = 0
-SCHED_FIFO = 1
-SCHED_RR = 2
-CSIGNAL = 0x000000ff
-CLONE_VM = 0x00000100
-CLONE_FS = 0x00000200
-CLONE_FILES = 0x00000400
-CLONE_SIGHAND = 0x00000800
-CLONE_PID = 0x00001000
-CLONE_PTRACE = 0x00002000
-CLONE_VFORK = 0x00004000
-__defined_schedparam = 1
-
-# Included from time.h
-_TIME_H = 1
-
-# Included from bits/time.h
-_BITS_TIME_H = 1
-CLOCKS_PER_SEC = 1000000
-CLOCK_REALTIME = 0
-CLOCK_PROCESS_CPUTIME_ID = 2
-CLOCK_THREAD_CPUTIME_ID = 3
-TIMER_ABSTIME = 1
-_STRUCT_TIMEVAL = 1
-CLK_TCK = CLOCKS_PER_SEC
-__clock_t_defined = 1
-__time_t_defined = 1
-__clockid_t_defined = 1
-__timer_t_defined = 1
-__timespec_defined = 1
-def __isleap(year): return \
-
-__BIT_TYPES_DEFINED__ = 1
-
-# Included from endian.h
-_ENDIAN_H = 1
-__LITTLE_ENDIAN = 1234
-__BIG_ENDIAN = 4321
-__PDP_ENDIAN = 3412
-
-# Included from bits/endian.h
-__BYTE_ORDER = __LITTLE_ENDIAN
-__FLOAT_WORD_ORDER = __BYTE_ORDER
-LITTLE_ENDIAN = __LITTLE_ENDIAN
-BIG_ENDIAN = __BIG_ENDIAN
-PDP_ENDIAN = __PDP_ENDIAN
-BYTE_ORDER = __BYTE_ORDER
-
-# Included from sys/select.h
-_SYS_SELECT_H = 1
-
-# Included from bits/select.h
-def __FD_ZERO(fdsp): return \
-
-def __FD_ZERO(set): return \
-
-
-# Included from bits/sigset.h
-_SIGSET_H_types = 1
-_SIGSET_H_fns = 1
-def __sigmask(sig): return \
-
-def __sigemptyset(set): return \
-
-def __sigfillset(set): return \
-
-def __sigisemptyset(set): return \
-
-def __FDELT(d): return ((d) / __NFDBITS)
-
-FD_SETSIZE = __FD_SETSIZE
-def FD_ZERO(fdsetp): return __FD_ZERO (fdsetp)
-
-
-# Included from sys/sysmacros.h
-_SYS_SYSMACROS_H = 1
-def major(dev): return ((int)(((dev) >> 8) & 0xff))
-
-def minor(dev): return ((int)((dev) & 0xff))
-
-def major(dev): return (((dev).__val[1] >> 8) & 0xff)
-
-def minor(dev): return ((dev).__val[1] & 0xff)
-
-def major(dev): return (((dev).__val[0] >> 8) & 0xff)
-
-def minor(dev): return ((dev).__val[0] & 0xff)
diff --git a/Lib/plat-linux/regen b/Lib/plat-linux/regen
deleted file mode 100755
index c76950e..0000000
--- a/Lib/plat-linux/regen
+++ /dev/null
@@ -1,8 +0,0 @@
-#! /bin/sh
-case `uname` in
-Linux*) ;;
-*) echo Probably not on a Linux system 1>&2
- exit 1;;
-esac
-set -v
-h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/dlfcn.h
diff --git a/Lib/plat-netbsd1/IN.py b/Lib/plat-netbsd1/IN.py
deleted file mode 100644
index 474c51e..0000000
--- a/Lib/plat-netbsd1/IN.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-IPPROTO_IP = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPIP = 4
-IPPROTO_TCP = 6
-IPPROTO_EGP = 8
-IPPROTO_PUP = 12
-IPPROTO_UDP = 17
-IPPROTO_IDP = 22
-IPPROTO_TP = 29
-IPPROTO_EON = 80
-IPPROTO_ENCAP = 98
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 5000
-def __IPADDR(x): return ((u_int32_t)(x))
-
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_MAX = 128
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_MAX = 65536
-IN_CLASSC_NSHIFT = 8
-IN_CLASSD_NSHIFT = 28
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-IN_LOOPBACKNET = 127
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_TTL = 10
-IP_MULTICAST_LOOP = 11
-IP_ADD_MEMBERSHIP = 12
-IP_DROP_MEMBERSHIP = 13
-IP_RECVIF = 20
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
-IPPROTO_MAXID = (IPPROTO_IDP + 1)
-IPCTL_FORWARDING = 1
-IPCTL_SENDREDIRECTS = 2
-IPCTL_DEFTTL = 3
-IPCTL_DEFMTU = 4
-IPCTL_FORWSRCRT = 5
-IPCTL_DIRECTEDBCAST = 6
-IPCTL_ALLOWSRCRT = 7
-IPCTL_MAXID = 8
-def in_nullhost(x): return ((x).s_addr == INADDR_ANY)
diff --git a/Lib/plat-netbsd1/regen b/Lib/plat-netbsd1/regen
deleted file mode 100755
index 8aa6898..0000000
--- a/Lib/plat-netbsd1/regen
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-set -v
-python ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/plat-next3/regen b/Lib/plat-next3/regen
deleted file mode 100755
index 7a03613..0000000
--- a/Lib/plat-next3/regen
+++ /dev/null
@@ -1,6 +0,0 @@
-#! /bin/sh
-set -v
-INCLUDE="/NextDeveloper/Headers;/NextDeveloper/Headers/ansi;/NextDeveloper/Headers/bsd"
-export INCLUDE
-
-python ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/bsd/netinet/in.h
diff --git a/Lib/plat-sunos5/CDIO.py b/Lib/plat-sunos5/CDIO.py
deleted file mode 100644
index d766b50..0000000
--- a/Lib/plat-sunos5/CDIO.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# Generated by h2py from /usr/include/sys/cdio.h
-CDROM_LBA = 0x01
-CDROM_MSF = 0x02
-CDROM_DATA_TRACK = 0x04
-CDROM_LEADOUT = 0xAA
-CDROM_AUDIO_INVALID = 0x00
-CDROM_AUDIO_PLAY = 0x11
-CDROM_AUDIO_PAUSED = 0x12
-CDROM_AUDIO_COMPLETED = 0x13
-CDROM_AUDIO_ERROR = 0x14
-CDROM_AUDIO_NO_STATUS = 0x15
-CDROM_DA_NO_SUBCODE = 0x00
-CDROM_DA_SUBQ = 0x01
-CDROM_DA_ALL_SUBCODE = 0x02
-CDROM_DA_SUBCODE_ONLY = 0x03
-CDROM_XA_DATA = 0x00
-CDROM_XA_SECTOR_DATA = 0x01
-CDROM_XA_DATA_W_ERROR = 0x02
-CDROM_BLK_512 = 512
-CDROM_BLK_1024 = 1024
-CDROM_BLK_2048 = 2048
-CDROM_BLK_2056 = 2056
-CDROM_BLK_2336 = 2336
-CDROM_BLK_2340 = 2340
-CDROM_BLK_2352 = 2352
-CDROM_BLK_2368 = 2368
-CDROM_BLK_2448 = 2448
-CDROM_BLK_2646 = 2646
-CDROM_BLK_2647 = 2647
-CDROM_BLK_SUBCODE = 96
-CDROM_NORMAL_SPEED = 0x00
-CDROM_DOUBLE_SPEED = 0x01
-CDROM_QUAD_SPEED = 0x03
-CDROM_TWELVE_SPEED = 0x0C
-CDROM_MAXIMUM_SPEED = 0xff
-CDIOC = (0x04 << 8)
-CDROMPAUSE = (CDIOC|151)
-CDROMRESUME = (CDIOC|152)
-CDROMPLAYMSF = (CDIOC|153)
-CDROMPLAYTRKIND = (CDIOC|154)
-CDROMREADTOCHDR = (CDIOC|155)
-CDROMREADTOCENTRY = (CDIOC|156)
-CDROMSTOP = (CDIOC|157)
-CDROMSTART = (CDIOC|158)
-CDROMEJECT = (CDIOC|159)
-CDROMVOLCTRL = (CDIOC|160)
-CDROMSUBCHNL = (CDIOC|161)
-CDROMREADMODE2 = (CDIOC|162)
-CDROMREADMODE1 = (CDIOC|163)
-CDROMREADOFFSET = (CDIOC|164)
-CDROMGBLKMODE = (CDIOC|165)
-CDROMSBLKMODE = (CDIOC|166)
-CDROMCDDA = (CDIOC|167)
-CDROMCDXA = (CDIOC|168)
-CDROMSUBCODE = (CDIOC|169)
-CDROMGDRVSPEED = (CDIOC|170)
-CDROMSDRVSPEED = (CDIOC|171)
-SCMD_READ_TOC = 0x43
-SCMD_PLAYAUDIO_MSF = 0x47
-SCMD_PLAYAUDIO_TI = 0x48
-SCMD_PAUSE_RESUME = 0x4B
-SCMD_READ_SUBCHANNEL = 0x42
-SCMD_PLAYAUDIO10 = 0x45
-SCMD_PLAYTRACK_REL10 = 0x49
-SCMD_READ_HEADER = 0x44
-SCMD_PLAYAUDIO12 = 0xA5
-SCMD_PLAYTRACK_REL12 = 0xA9
-SCMD_CD_PLAYBACK_CONTROL = 0xC9
-SCMD_CD_PLAYBACK_STATUS = 0xC4
-SCMD_READ_CDDA = 0xD8
-SCMD_READ_CDXA = 0xDB
-SCMD_READ_ALL_SUBCODES = 0xDF
-CDROM_MODE2_SIZE = 2336
diff --git a/Lib/plat-sunos5/DLFCN.py b/Lib/plat-sunos5/DLFCN.py
deleted file mode 100644
index f492350..0000000
--- a/Lib/plat-sunos5/DLFCN.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Generated by h2py from /usr/include/dlfcn.h
-from TYPES import *
-RTLD_LAZY = 0x00001
-RTLD_NOW = 0x00002
-RTLD_NOLOAD = 0x00004
-RTLD_GLOBAL = 0x00100
-RTLD_LOCAL = 0x00000
-RTLD_PARENT = 0x00200
-RTLD_GROUP = 0x00400
-RTLD_WORLD = 0x00800
-RTLD_NODELETE = 0x01000
-RTLD_CONFGEN = 0x10000
-RTLD_REL_RELATIVE = 0x00001
-RTLD_REL_EXEC = 0x00002
-RTLD_REL_DEPENDS = 0x00004
-RTLD_REL_PRELOAD = 0x00008
-RTLD_REL_SELF = 0x00010
-RTLD_REL_WEAK = 0x00020
-RTLD_REL_ALL = 0x00fff
-RTLD_MEMORY = 0x01000
-RTLD_STRIP = 0x02000
-RTLD_NOHEAP = 0x04000
-RTLD_CONFSET = 0x10000
-RTLD_DI_LMID = 1
-RTLD_DI_LINKMAP = 2
-RTLD_DI_CONFIGADDR = 3
-RTLD_DI_MAX = 3
diff --git a/Lib/plat-sunos5/IN.py b/Lib/plat-sunos5/IN.py
deleted file mode 100644
index 9572ead..0000000
--- a/Lib/plat-sunos5/IN.py
+++ /dev/null
@@ -1,1421 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-
-# Included from sys/feature_tests.h
-
-# Included from sys/isa_defs.h
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_ALIGNMENT = 8
-_LONG_LONG_ALIGNMENT = 8
-_DOUBLE_ALIGNMENT = 8
-_LONG_DOUBLE_ALIGNMENT = 16
-_POINTER_ALIGNMENT = 8
-_MAX_ALIGNMENT = 16
-_ALIGNMENT_REQUIRED = 1
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_ALIGNMENT = 4
-_LONG_LONG_ALIGNMENT = 4
-_DOUBLE_ALIGNMENT = 4
-_LONG_DOUBLE_ALIGNMENT = 4
-_POINTER_ALIGNMENT = 4
-_MAX_ALIGNMENT = 4
-_ALIGNMENT_REQUIRED = 0
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_LONG_ALIGNMENT = 8
-_DOUBLE_ALIGNMENT = 8
-_ALIGNMENT_REQUIRED = 1
-_LONG_ALIGNMENT = 4
-_LONG_DOUBLE_ALIGNMENT = 8
-_POINTER_ALIGNMENT = 4
-_MAX_ALIGNMENT = 8
-_LONG_ALIGNMENT = 8
-_LONG_DOUBLE_ALIGNMENT = 16
-_POINTER_ALIGNMENT = 8
-_MAX_ALIGNMENT = 16
-_POSIX_C_SOURCE = 1
-_LARGEFILE64_SOURCE = 1
-_LARGEFILE_SOURCE = 1
-_FILE_OFFSET_BITS = 64
-_FILE_OFFSET_BITS = 32
-_POSIX_C_SOURCE = 199506
-_POSIX_PTHREAD_SEMANTICS = 1
-_XOPEN_VERSION = 500
-_XOPEN_VERSION = 4
-_XOPEN_VERSION = 3
-from TYPES import *
-
-# Included from sys/stream.h
-
-# Included from sys/vnode.h
-from TYPES import *
-
-# Included from sys/t_lock.h
-
-# Included from sys/machlock.h
-from TYPES import *
-LOCK_HELD_VALUE = 0xff
-def SPIN_LOCK(pl): return ((pl) > ipltospl(LOCK_LEVEL))
-
-def LOCK_SAMPLE_INTERVAL(i): return (((i) & 0xff) == 0)
-
-CLOCK_LEVEL = 10
-LOCK_LEVEL = 10
-DISP_LEVEL = (LOCK_LEVEL + 1)
-PTR24_LSB = 5
-PTR24_MSB = (PTR24_LSB + 24)
-PTR24_ALIGN = 32
-PTR24_BASE = 0xe0000000
-
-# Included from sys/param.h
-from TYPES import *
-_POSIX_VDISABLE = 0
-MAX_INPUT = 512
-MAX_CANON = 256
-UID_NOBODY = 60001
-GID_NOBODY = UID_NOBODY
-UID_NOACCESS = 60002
-MAX_TASKID = 999999
-MAX_MAXPID = 999999
-DEFAULT_MAXPID = 999999
-DEFAULT_JUMPPID = 100000
-DEFAULT_MAXPID = 30000
-DEFAULT_JUMPPID = 0
-MAXUID = 2147483647
-MAXPROJID = MAXUID
-MAXLINK = 32767
-NMOUNT = 40
-CANBSIZ = 256
-NOFILE = 20
-NGROUPS_UMIN = 0
-NGROUPS_UMAX = 32
-NGROUPS_MAX_DEFAULT = 16
-NZERO = 20
-NULL = 0
-NULL = 0
-CMASK = 0o22
-CDLIMIT = (1<<11)
-NBPS = 0x20000
-NBPSCTR = 512
-UBSIZE = 512
-SCTRSHFT = 9
-SYSNAME = 9
-PREMOTE = 39
-MAXPATHLEN = 1024
-MAXSYMLINKS = 20
-MAXNAMELEN = 256
-NADDR = 13
-PIPE_BUF = 5120
-PIPE_MAX = 5120
-NBBY = 8
-MAXBSIZE = 8192
-DEV_BSIZE = 512
-DEV_BSHIFT = 9
-MAXFRAG = 8
-MAXOFF32_T = 0x7fffffff
-MAXOFF_T = 0x7fffffffffffffff
-MAXOFFSET_T = 0x7fffffffffffffff
-MAXOFF_T = 0x7fffffff
-MAXOFFSET_T = 0x7fffffff
-def btodb(bytes): return \
-
-def dbtob(db): return \
-
-def lbtodb(bytes): return \
-
-def ldbtob(db): return \
-
-NCARGS32 = 0x100000
-NCARGS64 = 0x200000
-NCARGS = NCARGS64
-NCARGS = NCARGS32
-FSHIFT = 8
-FSCALE = (1<<FSHIFT)
-def DELAY(n): return drv_usecwait(n)
-
-def mmu_ptob(x): return ((x) << MMU_PAGESHIFT)
-
-def mmu_btop(x): return (((x)) >> MMU_PAGESHIFT)
-
-def mmu_btopr(x): return ((((x) + MMU_PAGEOFFSET) >> MMU_PAGESHIFT))
-
-def mmu_ptod(x): return ((x) << (MMU_PAGESHIFT - DEV_BSHIFT))
-
-def ptod(x): return ((x) << (PAGESHIFT - DEV_BSHIFT))
-
-def ptob(x): return ((x) << PAGESHIFT)
-
-def btop(x): return (((x) >> PAGESHIFT))
-
-def btopr(x): return ((((x) + PAGEOFFSET) >> PAGESHIFT))
-
-def dtop(DD): return (((DD) + NDPP - 1) >> (PAGESHIFT - DEV_BSHIFT))
-
-def dtopt(DD): return ((DD) >> (PAGESHIFT - DEV_BSHIFT))
-
-_AIO_LISTIO_MAX = (4096)
-_AIO_MAX = (-1)
-_MQ_OPEN_MAX = (32)
-_MQ_PRIO_MAX = (32)
-_SEM_NSEMS_MAX = INT_MAX
-_SEM_VALUE_MAX = INT_MAX
-
-# Included from sys/unistd.h
-_CS_PATH = 65
-_CS_LFS_CFLAGS = 68
-_CS_LFS_LDFLAGS = 69
-_CS_LFS_LIBS = 70
-_CS_LFS_LINTFLAGS = 71
-_CS_LFS64_CFLAGS = 72
-_CS_LFS64_LDFLAGS = 73
-_CS_LFS64_LIBS = 74
-_CS_LFS64_LINTFLAGS = 75
-_CS_XBS5_ILP32_OFF32_CFLAGS = 700
-_CS_XBS5_ILP32_OFF32_LDFLAGS = 701
-_CS_XBS5_ILP32_OFF32_LIBS = 702
-_CS_XBS5_ILP32_OFF32_LINTFLAGS = 703
-_CS_XBS5_ILP32_OFFBIG_CFLAGS = 705
-_CS_XBS5_ILP32_OFFBIG_LDFLAGS = 706
-_CS_XBS5_ILP32_OFFBIG_LIBS = 707
-_CS_XBS5_ILP32_OFFBIG_LINTFLAGS = 708
-_CS_XBS5_LP64_OFF64_CFLAGS = 709
-_CS_XBS5_LP64_OFF64_LDFLAGS = 710
-_CS_XBS5_LP64_OFF64_LIBS = 711
-_CS_XBS5_LP64_OFF64_LINTFLAGS = 712
-_CS_XBS5_LPBIG_OFFBIG_CFLAGS = 713
-_CS_XBS5_LPBIG_OFFBIG_LDFLAGS = 714
-_CS_XBS5_LPBIG_OFFBIG_LIBS = 715
-_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS = 716
-_SC_ARG_MAX = 1
-_SC_CHILD_MAX = 2
-_SC_CLK_TCK = 3
-_SC_NGROUPS_MAX = 4
-_SC_OPEN_MAX = 5
-_SC_JOB_CONTROL = 6
-_SC_SAVED_IDS = 7
-_SC_VERSION = 8
-_SC_PASS_MAX = 9
-_SC_LOGNAME_MAX = 10
-_SC_PAGESIZE = 11
-_SC_XOPEN_VERSION = 12
-_SC_NPROCESSORS_CONF = 14
-_SC_NPROCESSORS_ONLN = 15
-_SC_STREAM_MAX = 16
-_SC_TZNAME_MAX = 17
-_SC_AIO_LISTIO_MAX = 18
-_SC_AIO_MAX = 19
-_SC_AIO_PRIO_DELTA_MAX = 20
-_SC_ASYNCHRONOUS_IO = 21
-_SC_DELAYTIMER_MAX = 22
-_SC_FSYNC = 23
-_SC_MAPPED_FILES = 24
-_SC_MEMLOCK = 25
-_SC_MEMLOCK_RANGE = 26
-_SC_MEMORY_PROTECTION = 27
-_SC_MESSAGE_PASSING = 28
-_SC_MQ_OPEN_MAX = 29
-_SC_MQ_PRIO_MAX = 30
-_SC_PRIORITIZED_IO = 31
-_SC_PRIORITY_SCHEDULING = 32
-_SC_REALTIME_SIGNALS = 33
-_SC_RTSIG_MAX = 34
-_SC_SEMAPHORES = 35
-_SC_SEM_NSEMS_MAX = 36
-_SC_SEM_VALUE_MAX = 37
-_SC_SHARED_MEMORY_OBJECTS = 38
-_SC_SIGQUEUE_MAX = 39
-_SC_SIGRT_MIN = 40
-_SC_SIGRT_MAX = 41
-_SC_SYNCHRONIZED_IO = 42
-_SC_TIMERS = 43
-_SC_TIMER_MAX = 44
-_SC_2_C_BIND = 45
-_SC_2_C_DEV = 46
-_SC_2_C_VERSION = 47
-_SC_2_FORT_DEV = 48
-_SC_2_FORT_RUN = 49
-_SC_2_LOCALEDEF = 50
-_SC_2_SW_DEV = 51
-_SC_2_UPE = 52
-_SC_2_VERSION = 53
-_SC_BC_BASE_MAX = 54
-_SC_BC_DIM_MAX = 55
-_SC_BC_SCALE_MAX = 56
-_SC_BC_STRING_MAX = 57
-_SC_COLL_WEIGHTS_MAX = 58
-_SC_EXPR_NEST_MAX = 59
-_SC_LINE_MAX = 60
-_SC_RE_DUP_MAX = 61
-_SC_XOPEN_CRYPT = 62
-_SC_XOPEN_ENH_I18N = 63
-_SC_XOPEN_SHM = 64
-_SC_2_CHAR_TERM = 66
-_SC_XOPEN_XCU_VERSION = 67
-_SC_ATEXIT_MAX = 76
-_SC_IOV_MAX = 77
-_SC_XOPEN_UNIX = 78
-_SC_PAGE_SIZE = _SC_PAGESIZE
-_SC_T_IOV_MAX = 79
-_SC_PHYS_PAGES = 500
-_SC_AVPHYS_PAGES = 501
-_SC_COHER_BLKSZ = 503
-_SC_SPLIT_CACHE = 504
-_SC_ICACHE_SZ = 505
-_SC_DCACHE_SZ = 506
-_SC_ICACHE_LINESZ = 507
-_SC_DCACHE_LINESZ = 508
-_SC_ICACHE_BLKSZ = 509
-_SC_DCACHE_BLKSZ = 510
-_SC_DCACHE_TBLKSZ = 511
-_SC_ICACHE_ASSOC = 512
-_SC_DCACHE_ASSOC = 513
-_SC_MAXPID = 514
-_SC_STACK_PROT = 515
-_SC_THREAD_DESTRUCTOR_ITERATIONS = 568
-_SC_GETGR_R_SIZE_MAX = 569
-_SC_GETPW_R_SIZE_MAX = 570
-_SC_LOGIN_NAME_MAX = 571
-_SC_THREAD_KEYS_MAX = 572
-_SC_THREAD_STACK_MIN = 573
-_SC_THREAD_THREADS_MAX = 574
-_SC_TTY_NAME_MAX = 575
-_SC_THREADS = 576
-_SC_THREAD_ATTR_STACKADDR = 577
-_SC_THREAD_ATTR_STACKSIZE = 578
-_SC_THREAD_PRIORITY_SCHEDULING = 579
-_SC_THREAD_PRIO_INHERIT = 580
-_SC_THREAD_PRIO_PROTECT = 581
-_SC_THREAD_PROCESS_SHARED = 582
-_SC_THREAD_SAFE_FUNCTIONS = 583
-_SC_XOPEN_LEGACY = 717
-_SC_XOPEN_REALTIME = 718
-_SC_XOPEN_REALTIME_THREADS = 719
-_SC_XBS5_ILP32_OFF32 = 720
-_SC_XBS5_ILP32_OFFBIG = 721
-_SC_XBS5_LP64_OFF64 = 722
-_SC_XBS5_LPBIG_OFFBIG = 723
-_PC_LINK_MAX = 1
-_PC_MAX_CANON = 2
-_PC_MAX_INPUT = 3
-_PC_NAME_MAX = 4
-_PC_PATH_MAX = 5
-_PC_PIPE_BUF = 6
-_PC_NO_TRUNC = 7
-_PC_VDISABLE = 8
-_PC_CHOWN_RESTRICTED = 9
-_PC_ASYNC_IO = 10
-_PC_PRIO_IO = 11
-_PC_SYNC_IO = 12
-_PC_FILESIZEBITS = 67
-_PC_LAST = 67
-_POSIX_VERSION = 199506
-_POSIX2_VERSION = 199209
-_POSIX2_C_VERSION = 199209
-_XOPEN_XCU_VERSION = 4
-_XOPEN_REALTIME = 1
-_XOPEN_ENH_I18N = 1
-_XOPEN_SHM = 1
-_POSIX2_C_BIND = 1
-_POSIX2_CHAR_TERM = 1
-_POSIX2_LOCALEDEF = 1
-_POSIX2_C_DEV = 1
-_POSIX2_SW_DEV = 1
-_POSIX2_UPE = 1
-
-# Included from sys/mutex.h
-from TYPES import *
-def MUTEX_HELD(x): return (mutex_owned(x))
-
-
-# Included from sys/rwlock.h
-from TYPES import *
-def RW_READ_HELD(x): return (rw_read_held((x)))
-
-def RW_WRITE_HELD(x): return (rw_write_held((x)))
-
-def RW_LOCK_HELD(x): return (rw_lock_held((x)))
-
-def RW_ISWRITER(x): return (rw_iswriter(x))
-
-
-# Included from sys/semaphore.h
-
-# Included from sys/thread.h
-from TYPES import *
-
-# Included from sys/klwp.h
-from TYPES import *
-
-# Included from sys/condvar.h
-from TYPES import *
-
-# Included from sys/time.h
-
-# Included from sys/types32.h
-
-# Included from sys/int_types.h
-TIME32_MAX = INT32_MAX
-TIME32_MIN = INT32_MIN
-def TIMEVAL_OVERFLOW(tv): return \
-
-from TYPES import *
-DST_NONE = 0
-DST_USA = 1
-DST_AUST = 2
-DST_WET = 3
-DST_MET = 4
-DST_EET = 5
-DST_CAN = 6
-DST_GB = 7
-DST_RUM = 8
-DST_TUR = 9
-DST_AUSTALT = 10
-ITIMER_REAL = 0
-ITIMER_VIRTUAL = 1
-ITIMER_PROF = 2
-ITIMER_REALPROF = 3
-def ITIMERVAL_OVERFLOW(itv): return \
-
-SEC = 1
-MILLISEC = 1000
-MICROSEC = 1000000
-NANOSEC = 1000000000
-
-# Included from sys/time_impl.h
-def TIMESPEC_OVERFLOW(ts): return \
-
-def ITIMERSPEC_OVERFLOW(it): return \
-
-__CLOCK_REALTIME0 = 0
-CLOCK_VIRTUAL = 1
-CLOCK_PROF = 2
-__CLOCK_REALTIME3 = 3
-CLOCK_HIGHRES = 4
-CLOCK_MAX = 5
-CLOCK_REALTIME = __CLOCK_REALTIME3
-CLOCK_REALTIME = __CLOCK_REALTIME0
-TIMER_RELTIME = 0x0
-TIMER_ABSTIME = 0x1
-def TICK_TO_SEC(tick): return ((tick) / hz)
-
-def SEC_TO_TICK(sec): return ((sec) * hz)
-
-def TICK_TO_MSEC(tick): return \
-
-def MSEC_TO_TICK(msec): return \
-
-def MSEC_TO_TICK_ROUNDUP(msec): return \
-
-def TICK_TO_USEC(tick): return ((tick) * usec_per_tick)
-
-def USEC_TO_TICK(usec): return ((usec) / usec_per_tick)
-
-def USEC_TO_TICK_ROUNDUP(usec): return \
-
-def TICK_TO_NSEC(tick): return ((tick) * nsec_per_tick)
-
-def NSEC_TO_TICK(nsec): return ((nsec) / nsec_per_tick)
-
-def NSEC_TO_TICK_ROUNDUP(nsec): return \
-
-def TIMEVAL_TO_TICK(tvp): return \
-
-def TIMESTRUC_TO_TICK(tsp): return \
-
-
-# Included from time.h
-from TYPES import *
-
-# Included from iso/time_iso.h
-NULL = 0
-NULL = 0
-CLOCKS_PER_SEC = 1000000
-
-# Included from sys/select.h
-FD_SETSIZE = 65536
-FD_SETSIZE = 1024
-_NBBY = 8
-NBBY = _NBBY
-def FD_ZERO(p): return bzero((p), sizeof (*(p)))
-
-
-# Included from sys/signal.h
-
-# Included from sys/iso/signal_iso.h
-SIGHUP = 1
-SIGINT = 2
-SIGQUIT = 3
-SIGILL = 4
-SIGTRAP = 5
-SIGIOT = 6
-SIGABRT = 6
-SIGEMT = 7
-SIGFPE = 8
-SIGKILL = 9
-SIGBUS = 10
-SIGSEGV = 11
-SIGSYS = 12
-SIGPIPE = 13
-SIGALRM = 14
-SIGTERM = 15
-SIGUSR1 = 16
-SIGUSR2 = 17
-SIGCLD = 18
-SIGCHLD = 18
-SIGPWR = 19
-SIGWINCH = 20
-SIGURG = 21
-SIGPOLL = 22
-SIGIO = SIGPOLL
-SIGSTOP = 23
-SIGTSTP = 24
-SIGCONT = 25
-SIGTTIN = 26
-SIGTTOU = 27
-SIGVTALRM = 28
-SIGPROF = 29
-SIGXCPU = 30
-SIGXFSZ = 31
-SIGWAITING = 32
-SIGLWP = 33
-SIGFREEZE = 34
-SIGTHAW = 35
-SIGCANCEL = 36
-SIGLOST = 37
-_SIGRTMIN = 38
-_SIGRTMAX = 45
-SIG_BLOCK = 1
-SIG_UNBLOCK = 2
-SIG_SETMASK = 3
-SIGNO_MASK = 0xFF
-SIGDEFER = 0x100
-SIGHOLD = 0x200
-SIGRELSE = 0x400
-SIGIGNORE = 0x800
-SIGPAUSE = 0x1000
-
-# Included from sys/siginfo.h
-from TYPES import *
-SIGEV_NONE = 1
-SIGEV_SIGNAL = 2
-SIGEV_THREAD = 3
-SI_NOINFO = 32767
-SI_USER = 0
-SI_LWP = (-1)
-SI_QUEUE = (-2)
-SI_TIMER = (-3)
-SI_ASYNCIO = (-4)
-SI_MESGQ = (-5)
-
-# Included from sys/machsig.h
-ILL_ILLOPC = 1
-ILL_ILLOPN = 2
-ILL_ILLADR = 3
-ILL_ILLTRP = 4
-ILL_PRVOPC = 5
-ILL_PRVREG = 6
-ILL_COPROC = 7
-ILL_BADSTK = 8
-NSIGILL = 8
-EMT_TAGOVF = 1
-EMT_CPCOVF = 2
-NSIGEMT = 2
-FPE_INTDIV = 1
-FPE_INTOVF = 2
-FPE_FLTDIV = 3
-FPE_FLTOVF = 4
-FPE_FLTUND = 5
-FPE_FLTRES = 6
-FPE_FLTINV = 7
-FPE_FLTSUB = 8
-NSIGFPE = 8
-SEGV_MAPERR = 1
-SEGV_ACCERR = 2
-NSIGSEGV = 2
-BUS_ADRALN = 1
-BUS_ADRERR = 2
-BUS_OBJERR = 3
-NSIGBUS = 3
-TRAP_BRKPT = 1
-TRAP_TRACE = 2
-TRAP_RWATCH = 3
-TRAP_WWATCH = 4
-TRAP_XWATCH = 5
-NSIGTRAP = 5
-CLD_EXITED = 1
-CLD_KILLED = 2
-CLD_DUMPED = 3
-CLD_TRAPPED = 4
-CLD_STOPPED = 5
-CLD_CONTINUED = 6
-NSIGCLD = 6
-POLL_IN = 1
-POLL_OUT = 2
-POLL_MSG = 3
-POLL_ERR = 4
-POLL_PRI = 5
-POLL_HUP = 6
-NSIGPOLL = 6
-PROF_SIG = 1
-NSIGPROF = 1
-SI_MAXSZ = 256
-SI_MAXSZ = 128
-
-# Included from sys/time_std_impl.h
-from TYPES import *
-SI32_MAXSZ = 128
-def SI_CANQUEUE(c): return ((c) <= SI_QUEUE)
-
-SA_NOCLDSTOP = 0x00020000
-SA_ONSTACK = 0x00000001
-SA_RESETHAND = 0x00000002
-SA_RESTART = 0x00000004
-SA_SIGINFO = 0x00000008
-SA_NODEFER = 0x00000010
-SA_NOCLDWAIT = 0x00010000
-SA_WAITSIG = 0x00010000
-NSIG = 46
-MAXSIG = 45
-S_SIGNAL = 1
-S_SIGSET = 2
-S_SIGACTION = 3
-S_NONE = 4
-MINSIGSTKSZ = 2048
-SIGSTKSZ = 8192
-SS_ONSTACK = 0x00000001
-SS_DISABLE = 0x00000002
-SN_PROC = 1
-SN_CANCEL = 2
-SN_SEND = 3
-
-# Included from sys/ucontext.h
-from TYPES import *
-
-# Included from sys/regset.h
-REG_CCR = (0)
-REG_PSR = (0)
-REG_PSR = (0)
-REG_PC = (1)
-REG_nPC = (2)
-REG_Y = (3)
-REG_G1 = (4)
-REG_G2 = (5)
-REG_G3 = (6)
-REG_G4 = (7)
-REG_G5 = (8)
-REG_G6 = (9)
-REG_G7 = (10)
-REG_O0 = (11)
-REG_O1 = (12)
-REG_O2 = (13)
-REG_O3 = (14)
-REG_O4 = (15)
-REG_O5 = (16)
-REG_O6 = (17)
-REG_O7 = (18)
-REG_ASI = (19)
-REG_FPRS = (20)
-REG_PS = REG_PSR
-REG_SP = REG_O6
-REG_R0 = REG_O0
-REG_R1 = REG_O1
-_NGREG = 21
-_NGREG = 19
-NGREG = _NGREG
-_NGREG32 = 19
-_NGREG64 = 21
-SPARC_MAXREGWINDOW = 31
-MAXFPQ = 16
-XRS_ID = 0x78727300
-
-# Included from v7/sys/privregs.h
-
-# Included from v7/sys/psr.h
-PSR_CWP = 0x0000001F
-PSR_ET = 0x00000020
-PSR_PS = 0x00000040
-PSR_S = 0x00000080
-PSR_PIL = 0x00000F00
-PSR_EF = 0x00001000
-PSR_EC = 0x00002000
-PSR_RSV = 0x000FC000
-PSR_ICC = 0x00F00000
-PSR_C = 0x00100000
-PSR_V = 0x00200000
-PSR_Z = 0x00400000
-PSR_N = 0x00800000
-PSR_VER = 0x0F000000
-PSR_IMPL = 0xF0000000
-PSL_ALLCC = PSR_ICC
-PSL_USER = (PSR_S)
-PSL_USERMASK = (PSR_ICC)
-PSL_UBITS = (PSR_ICC|PSR_EF)
-def USERMODE(ps): return (((ps) & PSR_PS) == 0)
-
-
-# Included from sys/fsr.h
-FSR_CEXC = 0x0000001f
-FSR_AEXC = 0x000003e0
-FSR_FCC = 0x00000c00
-FSR_PR = 0x00001000
-FSR_QNE = 0x00002000
-FSR_FTT = 0x0001c000
-FSR_VER = 0x000e0000
-FSR_TEM = 0x0f800000
-FSR_RP = 0x30000000
-FSR_RD = 0xc0000000
-FSR_VER_SHIFT = 17
-FSR_FCC1 = 0x00000003
-FSR_FCC2 = 0x0000000C
-FSR_FCC3 = 0x00000030
-FSR_CEXC_NX = 0x00000001
-FSR_CEXC_DZ = 0x00000002
-FSR_CEXC_UF = 0x00000004
-FSR_CEXC_OF = 0x00000008
-FSR_CEXC_NV = 0x00000010
-FSR_AEXC_NX = (0x1 << 5)
-FSR_AEXC_DZ = (0x2 << 5)
-FSR_AEXC_UF = (0x4 << 5)
-FSR_AEXC_OF = (0x8 << 5)
-FSR_AEXC_NV = (0x10 << 5)
-FTT_NONE = 0
-FTT_IEEE = 1
-FTT_UNFIN = 2
-FTT_UNIMP = 3
-FTT_SEQ = 4
-FTT_ALIGN = 5
-FTT_DFAULT = 6
-FSR_FTT_SHIFT = 14
-FSR_FTT_IEEE = (FTT_IEEE << FSR_FTT_SHIFT)
-FSR_FTT_UNFIN = (FTT_UNFIN << FSR_FTT_SHIFT)
-FSR_FTT_UNIMP = (FTT_UNIMP << FSR_FTT_SHIFT)
-FSR_FTT_SEQ = (FTT_SEQ << FSR_FTT_SHIFT)
-FSR_FTT_ALIGN = (FTT_ALIGN << FSR_FTT_SHIFT)
-FSR_FTT_DFAULT = (FTT_DFAULT << FSR_FTT_SHIFT)
-FSR_TEM_NX = (0x1 << 23)
-FSR_TEM_DZ = (0x2 << 23)
-FSR_TEM_UF = (0x4 << 23)
-FSR_TEM_OF = (0x8 << 23)
-FSR_TEM_NV = (0x10 << 23)
-RP_DBLEXT = 0
-RP_SINGLE = 1
-RP_DOUBLE = 2
-RP_RESERVED = 3
-RD_NEAR = 0
-RD_ZER0 = 1
-RD_POSINF = 2
-RD_NEGINF = 3
-FPRS_DL = 0x1
-FPRS_DU = 0x2
-FPRS_FEF = 0x4
-PIL_MAX = 0xf
-def SAVE_GLOBALS(RP): return \
-
-def RESTORE_GLOBALS(RP): return \
-
-def SAVE_OUTS(RP): return \
-
-def RESTORE_OUTS(RP): return \
-
-def SAVE_WINDOW(SBP): return \
-
-def RESTORE_WINDOW(SBP): return \
-
-def STORE_FPREGS(FP): return \
-
-def LOAD_FPREGS(FP): return \
-
-_SPARC_MAXREGWINDOW = 31
-_XRS_ID = 0x78727300
-GETCONTEXT = 0
-SETCONTEXT = 1
-UC_SIGMASK = 0o01
-UC_STACK = 0o02
-UC_CPU = 0o04
-UC_MAU = 0o10
-UC_FPU = UC_MAU
-UC_INTR = 0o20
-UC_ASR = 0o40
-UC_MCONTEXT = (UC_CPU|UC_FPU|UC_ASR)
-UC_ALL = (UC_SIGMASK|UC_STACK|UC_MCONTEXT)
-_SIGQUEUE_MAX = 32
-_SIGNOTIFY_MAX = 32
-
-# Included from sys/pcb.h
-INSTR_VALID = 0x02
-NORMAL_STEP = 0x04
-WATCH_STEP = 0x08
-CPC_OVERFLOW = 0x10
-ASYNC_HWERR = 0x20
-STEP_NONE = 0
-STEP_REQUESTED = 1
-STEP_ACTIVE = 2
-STEP_WASACTIVE = 3
-
-# Included from sys/msacct.h
-LMS_USER = 0
-LMS_SYSTEM = 1
-LMS_TRAP = 2
-LMS_TFAULT = 3
-LMS_DFAULT = 4
-LMS_KFAULT = 5
-LMS_USER_LOCK = 6
-LMS_SLEEP = 7
-LMS_WAIT_CPU = 8
-LMS_STOPPED = 9
-NMSTATES = 10
-
-# Included from sys/lwp.h
-
-# Included from sys/synch.h
-from TYPES import *
-USYNC_THREAD = 0x00
-USYNC_PROCESS = 0x01
-LOCK_NORMAL = 0x00
-LOCK_ERRORCHECK = 0x02
-LOCK_RECURSIVE = 0x04
-USYNC_PROCESS_ROBUST = 0x08
-LOCK_PRIO_NONE = 0x00
-LOCK_PRIO_INHERIT = 0x10
-LOCK_PRIO_PROTECT = 0x20
-LOCK_STALL_NP = 0x00
-LOCK_ROBUST_NP = 0x40
-LOCK_OWNERDEAD = 0x1
-LOCK_NOTRECOVERABLE = 0x2
-LOCK_INITED = 0x4
-LOCK_UNMAPPED = 0x8
-LWP_DETACHED = 0x00000040
-LWP_SUSPENDED = 0x00000080
-__LWP_ASLWP = 0x00000100
-MAXSYSARGS = 8
-NORMALRETURN = 0
-JUSTRETURN = 1
-LWP_USER = 0x01
-LWP_SYS = 0x02
-TS_FREE = 0x00
-TS_SLEEP = 0x01
-TS_RUN = 0x02
-TS_ONPROC = 0x04
-TS_ZOMB = 0x08
-TS_STOPPED = 0x10
-T_INTR_THREAD = 0x0001
-T_WAKEABLE = 0x0002
-T_TOMASK = 0x0004
-T_TALLOCSTK = 0x0008
-T_WOULDBLOCK = 0x0020
-T_DONTBLOCK = 0x0040
-T_DONTPEND = 0x0080
-T_SYS_PROF = 0x0100
-T_WAITCVSEM = 0x0200
-T_WATCHPT = 0x0400
-T_PANIC = 0x0800
-TP_HOLDLWP = 0x0002
-TP_TWAIT = 0x0004
-TP_LWPEXIT = 0x0008
-TP_PRSTOP = 0x0010
-TP_CHKPT = 0x0020
-TP_EXITLWP = 0x0040
-TP_PRVSTOP = 0x0080
-TP_MSACCT = 0x0100
-TP_STOPPING = 0x0200
-TP_WATCHPT = 0x0400
-TP_PAUSE = 0x0800
-TP_CHANGEBIND = 0x1000
-TS_LOAD = 0x0001
-TS_DONT_SWAP = 0x0002
-TS_SWAPENQ = 0x0004
-TS_ON_SWAPQ = 0x0008
-TS_CSTART = 0x0100
-TS_UNPAUSE = 0x0200
-TS_XSTART = 0x0400
-TS_PSTART = 0x0800
-TS_RESUME = 0x1000
-TS_CREATE = 0x2000
-TS_ALLSTART = \
- (TS_CSTART|TS_UNPAUSE|TS_XSTART|TS_PSTART|TS_RESUME|TS_CREATE)
-def CPR_VSTOPPED(t): return \
-
-def THREAD_TRANSITION(tp): return thread_transition(tp);
-
-def THREAD_STOP(tp): return \
-
-def THREAD_ZOMB(tp): return THREAD_SET_STATE(tp, TS_ZOMB, NULL)
-
-def SEMA_HELD(x): return (sema_held((x)))
-
-NO_LOCKS_HELD = 1
-NO_COMPETING_THREADS = 1
-
-# Included from sys/cred.h
-
-# Included from sys/uio.h
-from TYPES import *
-
-# Included from sys/resource.h
-from TYPES import *
-PRIO_PROCESS = 0
-PRIO_PGRP = 1
-PRIO_USER = 2
-RLIMIT_CPU = 0
-RLIMIT_FSIZE = 1
-RLIMIT_DATA = 2
-RLIMIT_STACK = 3
-RLIMIT_CORE = 4
-RLIMIT_NOFILE = 5
-RLIMIT_VMEM = 6
-RLIMIT_AS = RLIMIT_VMEM
-RLIM_NLIMITS = 7
-RLIM_INFINITY = (-3)
-RLIM_SAVED_MAX = (-2)
-RLIM_SAVED_CUR = (-1)
-RLIM_INFINITY = 0x7fffffff
-RLIM_SAVED_MAX = 0x7ffffffe
-RLIM_SAVED_CUR = 0x7ffffffd
-RLIM32_INFINITY = 0x7fffffff
-RLIM32_SAVED_MAX = 0x7ffffffe
-RLIM32_SAVED_CUR = 0x7ffffffd
-
-# Included from sys/model.h
-
-# Included from sys/debug.h
-def ASSERT64(x): return ASSERT(x)
-
-def ASSERT32(x): return ASSERT(x)
-
-DATAMODEL_MASK = 0x0FF00000
-DATAMODEL_ILP32 = 0x00100000
-DATAMODEL_LP64 = 0x00200000
-DATAMODEL_NONE = 0
-DATAMODEL_NATIVE = DATAMODEL_LP64
-DATAMODEL_NATIVE = DATAMODEL_ILP32
-def STRUCT_SIZE(handle): return \
-
-def STRUCT_BUF(handle): return ((handle).ptr.m64)
-
-def SIZEOF_PTR(umodel): return \
-
-def STRUCT_SIZE(handle): return (sizeof (*(handle).ptr))
-
-def STRUCT_BUF(handle): return ((handle).ptr)
-
-def SIZEOF_PTR(umodel): return sizeof (caddr_t)
-
-def lwp_getdatamodel(t): return DATAMODEL_ILP32
-
-RUSAGE_SELF = 0
-RUSAGE_CHILDREN = -1
-
-# Included from vm/seg_enum.h
-
-# Included from sys/buf.h
-
-# Included from sys/kstat.h
-from TYPES import *
-KSTAT_STRLEN = 31
-def KSTAT_ENTER(k): return \
-
-def KSTAT_EXIT(k): return \
-
-KSTAT_TYPE_RAW = 0
-KSTAT_TYPE_NAMED = 1
-KSTAT_TYPE_INTR = 2
-KSTAT_TYPE_IO = 3
-KSTAT_TYPE_TIMER = 4
-KSTAT_NUM_TYPES = 5
-KSTAT_FLAG_VIRTUAL = 0x01
-KSTAT_FLAG_VAR_SIZE = 0x02
-KSTAT_FLAG_WRITABLE = 0x04
-KSTAT_FLAG_PERSISTENT = 0x08
-KSTAT_FLAG_DORMANT = 0x10
-KSTAT_FLAG_INVALID = 0x20
-KSTAT_READ = 0
-KSTAT_WRITE = 1
-KSTAT_DATA_CHAR = 0
-KSTAT_DATA_INT32 = 1
-KSTAT_DATA_UINT32 = 2
-KSTAT_DATA_INT64 = 3
-KSTAT_DATA_UINT64 = 4
-KSTAT_DATA_LONG = KSTAT_DATA_INT32
-KSTAT_DATA_ULONG = KSTAT_DATA_UINT32
-KSTAT_DATA_LONG = KSTAT_DATA_INT64
-KSTAT_DATA_ULONG = KSTAT_DATA_UINT64
-KSTAT_DATA_LONG = 7
-KSTAT_DATA_ULONG = 8
-KSTAT_DATA_LONGLONG = KSTAT_DATA_INT64
-KSTAT_DATA_ULONGLONG = KSTAT_DATA_UINT64
-KSTAT_DATA_FLOAT = 5
-KSTAT_DATA_DOUBLE = 6
-KSTAT_INTR_HARD = 0
-KSTAT_INTR_SOFT = 1
-KSTAT_INTR_WATCHDOG = 2
-KSTAT_INTR_SPURIOUS = 3
-KSTAT_INTR_MULTSVC = 4
-KSTAT_NUM_INTRS = 5
-B_BUSY = 0x0001
-B_DONE = 0x0002
-B_ERROR = 0x0004
-B_PAGEIO = 0x0010
-B_PHYS = 0x0020
-B_READ = 0x0040
-B_WRITE = 0x0100
-B_KERNBUF = 0x0008
-B_WANTED = 0x0080
-B_AGE = 0x000200
-B_ASYNC = 0x000400
-B_DELWRI = 0x000800
-B_STALE = 0x001000
-B_DONTNEED = 0x002000
-B_REMAPPED = 0x004000
-B_FREE = 0x008000
-B_INVAL = 0x010000
-B_FORCE = 0x020000
-B_HEAD = 0x040000
-B_NOCACHE = 0x080000
-B_TRUNC = 0x100000
-B_SHADOW = 0x200000
-B_RETRYWRI = 0x400000
-def notavail(bp): return \
-
-def BWRITE(bp): return \
-
-def BWRITE2(bp): return \
-
-VROOT = 0x01
-VNOCACHE = 0x02
-VNOMAP = 0x04
-VDUP = 0x08
-VNOSWAP = 0x10
-VNOMOUNT = 0x20
-VISSWAP = 0x40
-VSWAPLIKE = 0x80
-VVFSLOCK = 0x100
-VVFSWAIT = 0x200
-VVMLOCK = 0x400
-VDIROPEN = 0x800
-VVMEXEC = 0x1000
-VPXFS = 0x2000
-AT_TYPE = 0x0001
-AT_MODE = 0x0002
-AT_UID = 0x0004
-AT_GID = 0x0008
-AT_FSID = 0x0010
-AT_NODEID = 0x0020
-AT_NLINK = 0x0040
-AT_SIZE = 0x0080
-AT_ATIME = 0x0100
-AT_MTIME = 0x0200
-AT_CTIME = 0x0400
-AT_RDEV = 0x0800
-AT_BLKSIZE = 0x1000
-AT_NBLOCKS = 0x2000
-AT_VCODE = 0x4000
-AT_ALL = (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
- AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
- AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
-AT_STAT = (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
- AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV)
-AT_TIMES = (AT_ATIME|AT_MTIME|AT_CTIME)
-AT_NOSET = (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
- AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
-VSUID = 0o4000
-VSGID = 0o2000
-VSVTX = 0o1000
-VREAD = 0o0400
-VWRITE = 0o0200
-VEXEC = 0o0100
-MODEMASK = 0o7777
-PERMMASK = 0o0777
-def MANDMODE(mode): return (((mode) & (VSGID|(VEXEC>>3))) == VSGID)
-
-VSA_ACL = 0x0001
-VSA_ACLCNT = 0x0002
-VSA_DFACL = 0x0004
-VSA_DFACLCNT = 0x0008
-LOOKUP_DIR = 0x01
-DUMP_ALLOC = 0
-DUMP_FREE = 1
-DUMP_SCAN = 2
-ATTR_UTIME = 0x01
-ATTR_EXEC = 0x02
-ATTR_COMM = 0x04
-ATTR_HINT = 0x08
-ATTR_REAL = 0x10
-
-# Included from sys/poll.h
-POLLIN = 0x0001
-POLLPRI = 0x0002
-POLLOUT = 0x0004
-POLLRDNORM = 0x0040
-POLLWRNORM = POLLOUT
-POLLRDBAND = 0x0080
-POLLWRBAND = 0x0100
-POLLNORM = POLLRDNORM
-POLLERR = 0x0008
-POLLHUP = 0x0010
-POLLNVAL = 0x0020
-POLLREMOVE = 0x0800
-POLLRDDATA = 0x0200
-POLLNOERR = 0x0400
-POLLCLOSED = 0x8000
-
-# Included from sys/strmdep.h
-def str_aligned(X): return (((ulong_t)(X) & (sizeof (int) - 1)) == 0)
-
-
-# Included from sys/strft.h
-tdelta_t_sz = 12
-FTEV_MASK = 0x1FFF
-FTEV_ISWR = 0x8000
-FTEV_CS = 0x4000
-FTEV_PS = 0x2000
-FTEV_QMASK = 0x1F00
-FTEV_ALLOCMASK = 0x1FF8
-FTEV_ALLOCB = 0x0000
-FTEV_ESBALLOC = 0x0001
-FTEV_DESBALLOC = 0x0002
-FTEV_ESBALLOCA = 0x0003
-FTEV_DESBALLOCA = 0x0004
-FTEV_ALLOCBIG = 0x0005
-FTEV_ALLOCBW = 0x0006
-FTEV_FREEB = 0x0008
-FTEV_DUPB = 0x0009
-FTEV_COPYB = 0x000A
-FTEV_CALLER = 0x000F
-FTEV_PUT = 0x0100
-FTEV_FSYNCQ = 0x0103
-FTEV_DSYNCQ = 0x0104
-FTEV_PUTQ = 0x0105
-FTEV_GETQ = 0x0106
-FTEV_RMVQ = 0x0107
-FTEV_INSQ = 0x0108
-FTEV_PUTBQ = 0x0109
-FTEV_FLUSHQ = 0x010A
-FTEV_REPLYQ = 0x010B
-FTEV_PUTNEXT = 0x010D
-FTEV_RWNEXT = 0x010E
-FTEV_QWINNER = 0x010F
-FTEV_GEWRITE = 0x0101
-def FTFLW_HASH(h): return (((unsigned)(h))%ftflw_hash_sz)
-
-FTBLK_EVNTS = 0x9
-QENAB = 0x00000001
-QWANTR = 0x00000002
-QWANTW = 0x00000004
-QFULL = 0x00000008
-QREADR = 0x00000010
-QUSE = 0x00000020
-QNOENB = 0x00000040
-QBACK = 0x00000100
-QHLIST = 0x00000200
-QPAIR = 0x00000800
-QPERQ = 0x00001000
-QPERMOD = 0x00002000
-QMTSAFE = 0x00004000
-QMTOUTPERIM = 0x00008000
-QMT_TYPEMASK = (QPAIR|QPERQ|QPERMOD|QMTSAFE|QMTOUTPERIM)
-QINSERVICE = 0x00010000
-QWCLOSE = 0x00020000
-QEND = 0x00040000
-QWANTWSYNC = 0x00080000
-QSYNCSTR = 0x00100000
-QISDRV = 0x00200000
-QHOT = 0x00400000
-QNEXTHOT = 0x00800000
-_QINSERTING = 0x04000000
-_QREMOVING = 0x08000000
-Q_SQQUEUED = 0x01
-Q_SQDRAINING = 0x02
-QB_FULL = 0x01
-QB_WANTW = 0x02
-QB_BACK = 0x04
-NBAND = 256
-STRUIOT_NONE = -1
-STRUIOT_DONTCARE = 0
-STRUIOT_STANDARD = 1
-STRUIOT_IP = 2
-DBLK_REFMIN = 0x01
-STRUIO_SPEC = 0x01
-STRUIO_DONE = 0x02
-STRUIO_IP = 0x04
-STRUIO_ZC = 0x08
-STRUIO_ICK = 0x10
-MSGMARK = 0x01
-MSGNOLOOP = 0x02
-MSGDELIM = 0x04
-MSGNOGET = 0x08
-MSGMARKNEXT = 0x10
-MSGNOTMARKNEXT = 0x20
-M_DATA = 0x00
-M_PROTO = 0x01
-M_BREAK = 0x08
-M_PASSFP = 0x09
-M_EVENT = 0x0a
-M_SIG = 0x0b
-M_DELAY = 0x0c
-M_CTL = 0x0d
-M_IOCTL = 0x0e
-M_SETOPTS = 0x10
-M_RSE = 0x11
-M_IOCACK = 0x81
-M_IOCNAK = 0x82
-M_PCPROTO = 0x83
-M_PCSIG = 0x84
-M_READ = 0x85
-M_FLUSH = 0x86
-M_STOP = 0x87
-M_START = 0x88
-M_HANGUP = 0x89
-M_ERROR = 0x8a
-M_COPYIN = 0x8b
-M_COPYOUT = 0x8c
-M_IOCDATA = 0x8d
-M_PCRSE = 0x8e
-M_STOPI = 0x8f
-M_STARTI = 0x90
-M_PCEVENT = 0x91
-M_UNHANGUP = 0x92
-QNORM = 0x00
-QPCTL = 0x80
-IOC_MODELS = DATAMODEL_MASK
-IOC_ILP32 = DATAMODEL_ILP32
-IOC_LP64 = DATAMODEL_LP64
-IOC_NATIVE = DATAMODEL_NATIVE
-IOC_NONE = DATAMODEL_NONE
-STRCANON = 0x01
-RECOPY = 0x02
-SO_ALL = 0x003f
-SO_READOPT = 0x0001
-SO_WROFF = 0x0002
-SO_MINPSZ = 0x0004
-SO_MAXPSZ = 0x0008
-SO_HIWAT = 0x0010
-SO_LOWAT = 0x0020
-SO_MREADON = 0x0040
-SO_MREADOFF = 0x0080
-SO_NDELON = 0x0100
-SO_NDELOFF = 0x0200
-SO_ISTTY = 0x0400
-SO_ISNTTY = 0x0800
-SO_TOSTOP = 0x1000
-SO_TONSTOP = 0x2000
-SO_BAND = 0x4000
-SO_DELIM = 0x8000
-SO_NODELIM = 0x010000
-SO_STRHOLD = 0x020000
-SO_ERROPT = 0x040000
-SO_COPYOPT = 0x080000
-SO_MAXBLK = 0x100000
-DEF_IOV_MAX = 16
-INFOD_FIRSTBYTES = 0x02
-INFOD_BYTES = 0x04
-INFOD_COUNT = 0x08
-INFOD_COPYOUT = 0x10
-MODOPEN = 0x1
-CLONEOPEN = 0x2
-CONSOPEN = 0x4
-OPENFAIL = -1
-BPRI_LO = 1
-BPRI_MED = 2
-BPRI_HI = 3
-BPRI_FT = 4
-INFPSZ = -1
-FLUSHALL = 1
-FLUSHDATA = 0
-STRHIGH = 5120
-STRLOW = 1024
-MAXIOCBSZ = 1024
-PERIM_INNER = 1
-PERIM_OUTER = 2
-def datamsg(type): return \
-
-def straln(a): return (caddr_t)((intptr_t)(a) & ~(sizeof (int)-1))
-
-
-# Included from sys/byteorder.h
-def ntohl(x): return (x)
-
-def ntohs(x): return (x)
-
-def htonl(x): return (x)
-
-def htons(x): return (x)
-
-IPPROTO_IP = 0
-IPPROTO_HOPOPTS = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_ENCAP = 4
-IPPROTO_TCP = 6
-IPPROTO_EGP = 8
-IPPROTO_PUP = 12
-IPPROTO_UDP = 17
-IPPROTO_IDP = 22
-IPPROTO_IPV6 = 41
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_RSVP = 46
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_HELLO = 63
-IPPROTO_ND = 77
-IPPROTO_EON = 80
-IPPROTO_PIM = 103
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPORT_ECHO = 7
-IPPORT_DISCARD = 9
-IPPORT_SYSTAT = 11
-IPPORT_DAYTIME = 13
-IPPORT_NETSTAT = 15
-IPPORT_FTP = 21
-IPPORT_TELNET = 23
-IPPORT_SMTP = 25
-IPPORT_TIMESERVER = 37
-IPPORT_NAMESERVER = 42
-IPPORT_WHOIS = 43
-IPPORT_MTP = 57
-IPPORT_BOOTPS = 67
-IPPORT_BOOTPC = 68
-IPPORT_TFTP = 69
-IPPORT_RJE = 77
-IPPORT_FINGER = 79
-IPPORT_TTYLINK = 87
-IPPORT_SUPDUP = 95
-IPPORT_EXECSERVER = 512
-IPPORT_LOGINSERVER = 513
-IPPORT_CMDSERVER = 514
-IPPORT_EFSSERVER = 520
-IPPORT_BIFFUDP = 512
-IPPORT_WHOSERVER = 513
-IPPORT_ROUTESERVER = 520
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 5000
-IMPLINK_IP = 155
-IMPLINK_LOWEXPER = 156
-IMPLINK_HIGHEXPER = 158
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_MAX = 128
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_MAX = 65536
-IN_CLASSC_NSHIFT = 8
-IN_CLASSD_NSHIFT = 28
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-IN_LOOPBACKNET = 127
-def IN_SET_LOOPBACK_ADDR(a): return \
-
-def IN6_IS_ADDR_UNSPECIFIED(addr): return \
-
-def IN6_IS_ADDR_LOOPBACK(addr): return \
-
-def IN6_IS_ADDR_LOOPBACK(addr): return \
-
-def IN6_IS_ADDR_MULTICAST(addr): return \
-
-def IN6_IS_ADDR_MULTICAST(addr): return \
-
-def IN6_IS_ADDR_LINKLOCAL(addr): return \
-
-def IN6_IS_ADDR_LINKLOCAL(addr): return \
-
-def IN6_IS_ADDR_SITELOCAL(addr): return \
-
-def IN6_IS_ADDR_SITELOCAL(addr): return \
-
-def IN6_IS_ADDR_V4MAPPED(addr): return \
-
-def IN6_IS_ADDR_V4MAPPED(addr): return \
-
-def IN6_IS_ADDR_V4MAPPED_ANY(addr): return \
-
-def IN6_IS_ADDR_V4MAPPED_ANY(addr): return \
-
-def IN6_IS_ADDR_V4COMPAT(addr): return \
-
-def IN6_IS_ADDR_V4COMPAT(addr): return \
-
-def IN6_IS_ADDR_MC_RESERVED(addr): return \
-
-def IN6_IS_ADDR_MC_RESERVED(addr): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_NODELOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(addr): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(addr): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(addr): return \
-
-IP_OPTIONS = 1
-IP_HDRINCL = 2
-IP_TOS = 3
-IP_TTL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 0x10
-IP_MULTICAST_TTL = 0x11
-IP_MULTICAST_LOOP = 0x12
-IP_ADD_MEMBERSHIP = 0x13
-IP_DROP_MEMBERSHIP = 0x14
-IP_SEC_OPT = 0x22
-IPSEC_PREF_NEVER = 0x01
-IPSEC_PREF_REQUIRED = 0x02
-IPSEC_PREF_UNIQUE = 0x04
-IP_ADD_PROXY_ADDR = 0x40
-IP_BOUND_IF = 0x41
-IP_UNSPEC_SRC = 0x42
-IP_REUSEADDR = 0x104
-IP_DONTROUTE = 0x105
-IP_BROADCAST = 0x106
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IPV6_RTHDR_TYPE_0 = 0
-IPV6_UNICAST_HOPS = 0x5
-IPV6_MULTICAST_IF = 0x6
-IPV6_MULTICAST_HOPS = 0x7
-IPV6_MULTICAST_LOOP = 0x8
-IPV6_JOIN_GROUP = 0x9
-IPV6_LEAVE_GROUP = 0xa
-IPV6_ADD_MEMBERSHIP = 0x9
-IPV6_DROP_MEMBERSHIP = 0xa
-IPV6_PKTINFO = 0xb
-IPV6_HOPLIMIT = 0xc
-IPV6_NEXTHOP = 0xd
-IPV6_HOPOPTS = 0xe
-IPV6_DSTOPTS = 0xf
-IPV6_RTHDR = 0x10
-IPV6_RTHDRDSTOPTS = 0x11
-IPV6_RECVPKTINFO = 0x12
-IPV6_RECVHOPLIMIT = 0x13
-IPV6_RECVHOPOPTS = 0x14
-IPV6_RECVDSTOPTS = 0x15
-IPV6_RECVRTHDR = 0x16
-IPV6_RECVRTHDRDSTOPTS = 0x17
-IPV6_CHECKSUM = 0x18
-IPV6_BOUND_IF = 0x41
-IPV6_UNSPEC_SRC = 0x42
-INET_ADDRSTRLEN = 16
-INET6_ADDRSTRLEN = 46
-IPV6_PAD1_OPT = 0
diff --git a/Lib/plat-sunos5/STROPTS.py b/Lib/plat-sunos5/STROPTS.py
deleted file mode 100644
index 8f735c4..0000000
--- a/Lib/plat-sunos5/STROPTS.py
+++ /dev/null
@@ -1,1813 +0,0 @@
-# Generated by h2py from /usr/include/sys/stropts.h
-
-# Included from sys/feature_tests.h
-
-# Included from sys/isa_defs.h
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_ALIGNMENT = 8
-_LONG_LONG_ALIGNMENT = 8
-_DOUBLE_ALIGNMENT = 8
-_LONG_DOUBLE_ALIGNMENT = 16
-_POINTER_ALIGNMENT = 8
-_MAX_ALIGNMENT = 16
-_ALIGNMENT_REQUIRED = 1
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_ALIGNMENT = 4
-_LONG_LONG_ALIGNMENT = 4
-_DOUBLE_ALIGNMENT = 4
-_LONG_DOUBLE_ALIGNMENT = 4
-_POINTER_ALIGNMENT = 4
-_MAX_ALIGNMENT = 4
-_ALIGNMENT_REQUIRED = 0
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_LONG_ALIGNMENT = 8
-_DOUBLE_ALIGNMENT = 8
-_ALIGNMENT_REQUIRED = 1
-_LONG_ALIGNMENT = 4
-_LONG_DOUBLE_ALIGNMENT = 8
-_POINTER_ALIGNMENT = 4
-_MAX_ALIGNMENT = 8
-_LONG_ALIGNMENT = 8
-_LONG_DOUBLE_ALIGNMENT = 16
-_POINTER_ALIGNMENT = 8
-_MAX_ALIGNMENT = 16
-_POSIX_C_SOURCE = 1
-_LARGEFILE64_SOURCE = 1
-_LARGEFILE_SOURCE = 1
-_FILE_OFFSET_BITS = 64
-_FILE_OFFSET_BITS = 32
-_POSIX_C_SOURCE = 199506
-_POSIX_PTHREAD_SEMANTICS = 1
-_XOPEN_VERSION = 500
-_XOPEN_VERSION = 4
-_XOPEN_VERSION = 3
-from TYPES import *
-
-# Included from sys/conf.h
-
-# Included from sys/t_lock.h
-
-# Included from sys/machlock.h
-from TYPES import *
-LOCK_HELD_VALUE = 0xff
-def SPIN_LOCK(pl): return ((pl) > ipltospl(LOCK_LEVEL))
-
-def LOCK_SAMPLE_INTERVAL(i): return (((i) & 0xff) == 0)
-
-CLOCK_LEVEL = 10
-LOCK_LEVEL = 10
-DISP_LEVEL = (LOCK_LEVEL + 1)
-PTR24_LSB = 5
-PTR24_MSB = (PTR24_LSB + 24)
-PTR24_ALIGN = 32
-PTR24_BASE = 0xe0000000
-
-# Included from sys/param.h
-from TYPES import *
-_POSIX_VDISABLE = 0
-MAX_INPUT = 512
-MAX_CANON = 256
-UID_NOBODY = 60001
-GID_NOBODY = UID_NOBODY
-UID_NOACCESS = 60002
-MAX_TASKID = 999999
-MAX_MAXPID = 999999
-DEFAULT_MAXPID = 999999
-DEFAULT_JUMPPID = 100000
-DEFAULT_MAXPID = 30000
-DEFAULT_JUMPPID = 0
-MAXUID = 2147483647
-MAXPROJID = MAXUID
-MAXLINK = 32767
-NMOUNT = 40
-CANBSIZ = 256
-NOFILE = 20
-NGROUPS_UMIN = 0
-NGROUPS_UMAX = 32
-NGROUPS_MAX_DEFAULT = 16
-NZERO = 20
-NULL = 0
-NULL = 0
-CMASK = 0o22
-CDLIMIT = (1<<11)
-NBPS = 0x20000
-NBPSCTR = 512
-UBSIZE = 512
-SCTRSHFT = 9
-SYSNAME = 9
-PREMOTE = 39
-MAXPATHLEN = 1024
-MAXSYMLINKS = 20
-MAXNAMELEN = 256
-NADDR = 13
-PIPE_BUF = 5120
-PIPE_MAX = 5120
-NBBY = 8
-MAXBSIZE = 8192
-DEV_BSIZE = 512
-DEV_BSHIFT = 9
-MAXFRAG = 8
-MAXOFF32_T = 0x7fffffff
-MAXOFF_T = 0x7fffffffffffffff
-MAXOFFSET_T = 0x7fffffffffffffff
-MAXOFF_T = 0x7fffffff
-MAXOFFSET_T = 0x7fffffff
-def btodb(bytes): return \
-
-def dbtob(db): return \
-
-def lbtodb(bytes): return \
-
-def ldbtob(db): return \
-
-NCARGS32 = 0x100000
-NCARGS64 = 0x200000
-NCARGS = NCARGS64
-NCARGS = NCARGS32
-FSHIFT = 8
-FSCALE = (1<<FSHIFT)
-def DELAY(n): return drv_usecwait(n)
-
-def mmu_ptob(x): return ((x) << MMU_PAGESHIFT)
-
-def mmu_btop(x): return (((x)) >> MMU_PAGESHIFT)
-
-def mmu_btopr(x): return ((((x) + MMU_PAGEOFFSET) >> MMU_PAGESHIFT))
-
-def mmu_ptod(x): return ((x) << (MMU_PAGESHIFT - DEV_BSHIFT))
-
-def ptod(x): return ((x) << (PAGESHIFT - DEV_BSHIFT))
-
-def ptob(x): return ((x) << PAGESHIFT)
-
-def btop(x): return (((x) >> PAGESHIFT))
-
-def btopr(x): return ((((x) + PAGEOFFSET) >> PAGESHIFT))
-
-def dtop(DD): return (((DD) + NDPP - 1) >> (PAGESHIFT - DEV_BSHIFT))
-
-def dtopt(DD): return ((DD) >> (PAGESHIFT - DEV_BSHIFT))
-
-_AIO_LISTIO_MAX = (4096)
-_AIO_MAX = (-1)
-_MQ_OPEN_MAX = (32)
-_MQ_PRIO_MAX = (32)
-_SEM_NSEMS_MAX = INT_MAX
-_SEM_VALUE_MAX = INT_MAX
-
-# Included from sys/unistd.h
-_CS_PATH = 65
-_CS_LFS_CFLAGS = 68
-_CS_LFS_LDFLAGS = 69
-_CS_LFS_LIBS = 70
-_CS_LFS_LINTFLAGS = 71
-_CS_LFS64_CFLAGS = 72
-_CS_LFS64_LDFLAGS = 73
-_CS_LFS64_LIBS = 74
-_CS_LFS64_LINTFLAGS = 75
-_CS_XBS5_ILP32_OFF32_CFLAGS = 700
-_CS_XBS5_ILP32_OFF32_LDFLAGS = 701
-_CS_XBS5_ILP32_OFF32_LIBS = 702
-_CS_XBS5_ILP32_OFF32_LINTFLAGS = 703
-_CS_XBS5_ILP32_OFFBIG_CFLAGS = 705
-_CS_XBS5_ILP32_OFFBIG_LDFLAGS = 706
-_CS_XBS5_ILP32_OFFBIG_LIBS = 707
-_CS_XBS5_ILP32_OFFBIG_LINTFLAGS = 708
-_CS_XBS5_LP64_OFF64_CFLAGS = 709
-_CS_XBS5_LP64_OFF64_LDFLAGS = 710
-_CS_XBS5_LP64_OFF64_LIBS = 711
-_CS_XBS5_LP64_OFF64_LINTFLAGS = 712
-_CS_XBS5_LPBIG_OFFBIG_CFLAGS = 713
-_CS_XBS5_LPBIG_OFFBIG_LDFLAGS = 714
-_CS_XBS5_LPBIG_OFFBIG_LIBS = 715
-_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS = 716
-_SC_ARG_MAX = 1
-_SC_CHILD_MAX = 2
-_SC_CLK_TCK = 3
-_SC_NGROUPS_MAX = 4
-_SC_OPEN_MAX = 5
-_SC_JOB_CONTROL = 6
-_SC_SAVED_IDS = 7
-_SC_VERSION = 8
-_SC_PASS_MAX = 9
-_SC_LOGNAME_MAX = 10
-_SC_PAGESIZE = 11
-_SC_XOPEN_VERSION = 12
-_SC_NPROCESSORS_CONF = 14
-_SC_NPROCESSORS_ONLN = 15
-_SC_STREAM_MAX = 16
-_SC_TZNAME_MAX = 17
-_SC_AIO_LISTIO_MAX = 18
-_SC_AIO_MAX = 19
-_SC_AIO_PRIO_DELTA_MAX = 20
-_SC_ASYNCHRONOUS_IO = 21
-_SC_DELAYTIMER_MAX = 22
-_SC_FSYNC = 23
-_SC_MAPPED_FILES = 24
-_SC_MEMLOCK = 25
-_SC_MEMLOCK_RANGE = 26
-_SC_MEMORY_PROTECTION = 27
-_SC_MESSAGE_PASSING = 28
-_SC_MQ_OPEN_MAX = 29
-_SC_MQ_PRIO_MAX = 30
-_SC_PRIORITIZED_IO = 31
-_SC_PRIORITY_SCHEDULING = 32
-_SC_REALTIME_SIGNALS = 33
-_SC_RTSIG_MAX = 34
-_SC_SEMAPHORES = 35
-_SC_SEM_NSEMS_MAX = 36
-_SC_SEM_VALUE_MAX = 37
-_SC_SHARED_MEMORY_OBJECTS = 38
-_SC_SIGQUEUE_MAX = 39
-_SC_SIGRT_MIN = 40
-_SC_SIGRT_MAX = 41
-_SC_SYNCHRONIZED_IO = 42
-_SC_TIMERS = 43
-_SC_TIMER_MAX = 44
-_SC_2_C_BIND = 45
-_SC_2_C_DEV = 46
-_SC_2_C_VERSION = 47
-_SC_2_FORT_DEV = 48
-_SC_2_FORT_RUN = 49
-_SC_2_LOCALEDEF = 50
-_SC_2_SW_DEV = 51
-_SC_2_UPE = 52
-_SC_2_VERSION = 53
-_SC_BC_BASE_MAX = 54
-_SC_BC_DIM_MAX = 55
-_SC_BC_SCALE_MAX = 56
-_SC_BC_STRING_MAX = 57
-_SC_COLL_WEIGHTS_MAX = 58
-_SC_EXPR_NEST_MAX = 59
-_SC_LINE_MAX = 60
-_SC_RE_DUP_MAX = 61
-_SC_XOPEN_CRYPT = 62
-_SC_XOPEN_ENH_I18N = 63
-_SC_XOPEN_SHM = 64
-_SC_2_CHAR_TERM = 66
-_SC_XOPEN_XCU_VERSION = 67
-_SC_ATEXIT_MAX = 76
-_SC_IOV_MAX = 77
-_SC_XOPEN_UNIX = 78
-_SC_PAGE_SIZE = _SC_PAGESIZE
-_SC_T_IOV_MAX = 79
-_SC_PHYS_PAGES = 500
-_SC_AVPHYS_PAGES = 501
-_SC_COHER_BLKSZ = 503
-_SC_SPLIT_CACHE = 504
-_SC_ICACHE_SZ = 505
-_SC_DCACHE_SZ = 506
-_SC_ICACHE_LINESZ = 507
-_SC_DCACHE_LINESZ = 508
-_SC_ICACHE_BLKSZ = 509
-_SC_DCACHE_BLKSZ = 510
-_SC_DCACHE_TBLKSZ = 511
-_SC_ICACHE_ASSOC = 512
-_SC_DCACHE_ASSOC = 513
-_SC_MAXPID = 514
-_SC_STACK_PROT = 515
-_SC_THREAD_DESTRUCTOR_ITERATIONS = 568
-_SC_GETGR_R_SIZE_MAX = 569
-_SC_GETPW_R_SIZE_MAX = 570
-_SC_LOGIN_NAME_MAX = 571
-_SC_THREAD_KEYS_MAX = 572
-_SC_THREAD_STACK_MIN = 573
-_SC_THREAD_THREADS_MAX = 574
-_SC_TTY_NAME_MAX = 575
-_SC_THREADS = 576
-_SC_THREAD_ATTR_STACKADDR = 577
-_SC_THREAD_ATTR_STACKSIZE = 578
-_SC_THREAD_PRIORITY_SCHEDULING = 579
-_SC_THREAD_PRIO_INHERIT = 580
-_SC_THREAD_PRIO_PROTECT = 581
-_SC_THREAD_PROCESS_SHARED = 582
-_SC_THREAD_SAFE_FUNCTIONS = 583
-_SC_XOPEN_LEGACY = 717
-_SC_XOPEN_REALTIME = 718
-_SC_XOPEN_REALTIME_THREADS = 719
-_SC_XBS5_ILP32_OFF32 = 720
-_SC_XBS5_ILP32_OFFBIG = 721
-_SC_XBS5_LP64_OFF64 = 722
-_SC_XBS5_LPBIG_OFFBIG = 723
-_PC_LINK_MAX = 1
-_PC_MAX_CANON = 2
-_PC_MAX_INPUT = 3
-_PC_NAME_MAX = 4
-_PC_PATH_MAX = 5
-_PC_PIPE_BUF = 6
-_PC_NO_TRUNC = 7
-_PC_VDISABLE = 8
-_PC_CHOWN_RESTRICTED = 9
-_PC_ASYNC_IO = 10
-_PC_PRIO_IO = 11
-_PC_SYNC_IO = 12
-_PC_FILESIZEBITS = 67
-_PC_LAST = 67
-_POSIX_VERSION = 199506
-_POSIX2_VERSION = 199209
-_POSIX2_C_VERSION = 199209
-_XOPEN_XCU_VERSION = 4
-_XOPEN_REALTIME = 1
-_XOPEN_ENH_I18N = 1
-_XOPEN_SHM = 1
-_POSIX2_C_BIND = 1
-_POSIX2_CHAR_TERM = 1
-_POSIX2_LOCALEDEF = 1
-_POSIX2_C_DEV = 1
-_POSIX2_SW_DEV = 1
-_POSIX2_UPE = 1
-
-# Included from sys/mutex.h
-from TYPES import *
-def MUTEX_HELD(x): return (mutex_owned(x))
-
-
-# Included from sys/rwlock.h
-from TYPES import *
-def RW_READ_HELD(x): return (rw_read_held((x)))
-
-def RW_WRITE_HELD(x): return (rw_write_held((x)))
-
-def RW_LOCK_HELD(x): return (rw_lock_held((x)))
-
-def RW_ISWRITER(x): return (rw_iswriter(x))
-
-
-# Included from sys/semaphore.h
-
-# Included from sys/thread.h
-from TYPES import *
-
-# Included from sys/klwp.h
-from TYPES import *
-
-# Included from sys/condvar.h
-from TYPES import *
-
-# Included from sys/time.h
-
-# Included from sys/types32.h
-
-# Included from sys/int_types.h
-TIME32_MAX = INT32_MAX
-TIME32_MIN = INT32_MIN
-def TIMEVAL_OVERFLOW(tv): return \
-
-from TYPES import *
-DST_NONE = 0
-DST_USA = 1
-DST_AUST = 2
-DST_WET = 3
-DST_MET = 4
-DST_EET = 5
-DST_CAN = 6
-DST_GB = 7
-DST_RUM = 8
-DST_TUR = 9
-DST_AUSTALT = 10
-ITIMER_REAL = 0
-ITIMER_VIRTUAL = 1
-ITIMER_PROF = 2
-ITIMER_REALPROF = 3
-def ITIMERVAL_OVERFLOW(itv): return \
-
-SEC = 1
-MILLISEC = 1000
-MICROSEC = 1000000
-NANOSEC = 1000000000
-
-# Included from sys/time_impl.h
-def TIMESPEC_OVERFLOW(ts): return \
-
-def ITIMERSPEC_OVERFLOW(it): return \
-
-__CLOCK_REALTIME0 = 0
-CLOCK_VIRTUAL = 1
-CLOCK_PROF = 2
-__CLOCK_REALTIME3 = 3
-CLOCK_HIGHRES = 4
-CLOCK_MAX = 5
-CLOCK_REALTIME = __CLOCK_REALTIME3
-CLOCK_REALTIME = __CLOCK_REALTIME0
-TIMER_RELTIME = 0x0
-TIMER_ABSTIME = 0x1
-def TICK_TO_SEC(tick): return ((tick) / hz)
-
-def SEC_TO_TICK(sec): return ((sec) * hz)
-
-def TICK_TO_MSEC(tick): return \
-
-def MSEC_TO_TICK(msec): return \
-
-def MSEC_TO_TICK_ROUNDUP(msec): return \
-
-def TICK_TO_USEC(tick): return ((tick) * usec_per_tick)
-
-def USEC_TO_TICK(usec): return ((usec) / usec_per_tick)
-
-def USEC_TO_TICK_ROUNDUP(usec): return \
-
-def TICK_TO_NSEC(tick): return ((tick) * nsec_per_tick)
-
-def NSEC_TO_TICK(nsec): return ((nsec) / nsec_per_tick)
-
-def NSEC_TO_TICK_ROUNDUP(nsec): return \
-
-def TIMEVAL_TO_TICK(tvp): return \
-
-def TIMESTRUC_TO_TICK(tsp): return \
-
-
-# Included from time.h
-from TYPES import *
-
-# Included from iso/time_iso.h
-NULL = 0
-NULL = 0
-CLOCKS_PER_SEC = 1000000
-
-# Included from sys/select.h
-FD_SETSIZE = 65536
-FD_SETSIZE = 1024
-_NBBY = 8
-NBBY = _NBBY
-def FD_ZERO(p): return bzero((p), sizeof (*(p)))
-
-
-# Included from sys/signal.h
-
-# Included from sys/iso/signal_iso.h
-SIGHUP = 1
-SIGINT = 2
-SIGQUIT = 3
-SIGILL = 4
-SIGTRAP = 5
-SIGIOT = 6
-SIGABRT = 6
-SIGEMT = 7
-SIGFPE = 8
-SIGKILL = 9
-SIGBUS = 10
-SIGSEGV = 11
-SIGSYS = 12
-SIGPIPE = 13
-SIGALRM = 14
-SIGTERM = 15
-SIGUSR1 = 16
-SIGUSR2 = 17
-SIGCLD = 18
-SIGCHLD = 18
-SIGPWR = 19
-SIGWINCH = 20
-SIGURG = 21
-SIGPOLL = 22
-SIGIO = SIGPOLL
-SIGSTOP = 23
-SIGTSTP = 24
-SIGCONT = 25
-SIGTTIN = 26
-SIGTTOU = 27
-SIGVTALRM = 28
-SIGPROF = 29
-SIGXCPU = 30
-SIGXFSZ = 31
-SIGWAITING = 32
-SIGLWP = 33
-SIGFREEZE = 34
-SIGTHAW = 35
-SIGCANCEL = 36
-SIGLOST = 37
-_SIGRTMIN = 38
-_SIGRTMAX = 45
-SIG_BLOCK = 1
-SIG_UNBLOCK = 2
-SIG_SETMASK = 3
-SIGNO_MASK = 0xFF
-SIGDEFER = 0x100
-SIGHOLD = 0x200
-SIGRELSE = 0x400
-SIGIGNORE = 0x800
-SIGPAUSE = 0x1000
-
-# Included from sys/siginfo.h
-from TYPES import *
-SIGEV_NONE = 1
-SIGEV_SIGNAL = 2
-SIGEV_THREAD = 3
-SI_NOINFO = 32767
-SI_USER = 0
-SI_LWP = (-1)
-SI_QUEUE = (-2)
-SI_TIMER = (-3)
-SI_ASYNCIO = (-4)
-SI_MESGQ = (-5)
-
-# Included from sys/machsig.h
-ILL_ILLOPC = 1
-ILL_ILLOPN = 2
-ILL_ILLADR = 3
-ILL_ILLTRP = 4
-ILL_PRVOPC = 5
-ILL_PRVREG = 6
-ILL_COPROC = 7
-ILL_BADSTK = 8
-NSIGILL = 8
-EMT_TAGOVF = 1
-EMT_CPCOVF = 2
-NSIGEMT = 2
-FPE_INTDIV = 1
-FPE_INTOVF = 2
-FPE_FLTDIV = 3
-FPE_FLTOVF = 4
-FPE_FLTUND = 5
-FPE_FLTRES = 6
-FPE_FLTINV = 7
-FPE_FLTSUB = 8
-NSIGFPE = 8
-SEGV_MAPERR = 1
-SEGV_ACCERR = 2
-NSIGSEGV = 2
-BUS_ADRALN = 1
-BUS_ADRERR = 2
-BUS_OBJERR = 3
-NSIGBUS = 3
-TRAP_BRKPT = 1
-TRAP_TRACE = 2
-TRAP_RWATCH = 3
-TRAP_WWATCH = 4
-TRAP_XWATCH = 5
-NSIGTRAP = 5
-CLD_EXITED = 1
-CLD_KILLED = 2
-CLD_DUMPED = 3
-CLD_TRAPPED = 4
-CLD_STOPPED = 5
-CLD_CONTINUED = 6
-NSIGCLD = 6
-POLL_IN = 1
-POLL_OUT = 2
-POLL_MSG = 3
-POLL_ERR = 4
-POLL_PRI = 5
-POLL_HUP = 6
-NSIGPOLL = 6
-PROF_SIG = 1
-NSIGPROF = 1
-SI_MAXSZ = 256
-SI_MAXSZ = 128
-
-# Included from sys/time_std_impl.h
-from TYPES import *
-SI32_MAXSZ = 128
-def SI_CANQUEUE(c): return ((c) <= SI_QUEUE)
-
-SA_NOCLDSTOP = 0x00020000
-SA_ONSTACK = 0x00000001
-SA_RESETHAND = 0x00000002
-SA_RESTART = 0x00000004
-SA_SIGINFO = 0x00000008
-SA_NODEFER = 0x00000010
-SA_NOCLDWAIT = 0x00010000
-SA_WAITSIG = 0x00010000
-NSIG = 46
-MAXSIG = 45
-S_SIGNAL = 1
-S_SIGSET = 2
-S_SIGACTION = 3
-S_NONE = 4
-MINSIGSTKSZ = 2048
-SIGSTKSZ = 8192
-SS_ONSTACK = 0x00000001
-SS_DISABLE = 0x00000002
-SN_PROC = 1
-SN_CANCEL = 2
-SN_SEND = 3
-
-# Included from sys/ucontext.h
-from TYPES import *
-
-# Included from sys/regset.h
-REG_CCR = (0)
-REG_PSR = (0)
-REG_PSR = (0)
-REG_PC = (1)
-REG_nPC = (2)
-REG_Y = (3)
-REG_G1 = (4)
-REG_G2 = (5)
-REG_G3 = (6)
-REG_G4 = (7)
-REG_G5 = (8)
-REG_G6 = (9)
-REG_G7 = (10)
-REG_O0 = (11)
-REG_O1 = (12)
-REG_O2 = (13)
-REG_O3 = (14)
-REG_O4 = (15)
-REG_O5 = (16)
-REG_O6 = (17)
-REG_O7 = (18)
-REG_ASI = (19)
-REG_FPRS = (20)
-REG_PS = REG_PSR
-REG_SP = REG_O6
-REG_R0 = REG_O0
-REG_R1 = REG_O1
-_NGREG = 21
-_NGREG = 19
-NGREG = _NGREG
-_NGREG32 = 19
-_NGREG64 = 21
-SPARC_MAXREGWINDOW = 31
-MAXFPQ = 16
-XRS_ID = 0x78727300
-
-# Included from v7/sys/privregs.h
-
-# Included from v7/sys/psr.h
-PSR_CWP = 0x0000001F
-PSR_ET = 0x00000020
-PSR_PS = 0x00000040
-PSR_S = 0x00000080
-PSR_PIL = 0x00000F00
-PSR_EF = 0x00001000
-PSR_EC = 0x00002000
-PSR_RSV = 0x000FC000
-PSR_ICC = 0x00F00000
-PSR_C = 0x00100000
-PSR_V = 0x00200000
-PSR_Z = 0x00400000
-PSR_N = 0x00800000
-PSR_VER = 0x0F000000
-PSR_IMPL = 0xF0000000
-PSL_ALLCC = PSR_ICC
-PSL_USER = (PSR_S)
-PSL_USERMASK = (PSR_ICC)
-PSL_UBITS = (PSR_ICC|PSR_EF)
-def USERMODE(ps): return (((ps) & PSR_PS) == 0)
-
-
-# Included from sys/fsr.h
-FSR_CEXC = 0x0000001f
-FSR_AEXC = 0x000003e0
-FSR_FCC = 0x00000c00
-FSR_PR = 0x00001000
-FSR_QNE = 0x00002000
-FSR_FTT = 0x0001c000
-FSR_VER = 0x000e0000
-FSR_TEM = 0x0f800000
-FSR_RP = 0x30000000
-FSR_RD = 0xc0000000
-FSR_VER_SHIFT = 17
-FSR_FCC1 = 0x00000003
-FSR_FCC2 = 0x0000000C
-FSR_FCC3 = 0x00000030
-FSR_CEXC_NX = 0x00000001
-FSR_CEXC_DZ = 0x00000002
-FSR_CEXC_UF = 0x00000004
-FSR_CEXC_OF = 0x00000008
-FSR_CEXC_NV = 0x00000010
-FSR_AEXC_NX = (0x1 << 5)
-FSR_AEXC_DZ = (0x2 << 5)
-FSR_AEXC_UF = (0x4 << 5)
-FSR_AEXC_OF = (0x8 << 5)
-FSR_AEXC_NV = (0x10 << 5)
-FTT_NONE = 0
-FTT_IEEE = 1
-FTT_UNFIN = 2
-FTT_UNIMP = 3
-FTT_SEQ = 4
-FTT_ALIGN = 5
-FTT_DFAULT = 6
-FSR_FTT_SHIFT = 14
-FSR_FTT_IEEE = (FTT_IEEE << FSR_FTT_SHIFT)
-FSR_FTT_UNFIN = (FTT_UNFIN << FSR_FTT_SHIFT)
-FSR_FTT_UNIMP = (FTT_UNIMP << FSR_FTT_SHIFT)
-FSR_FTT_SEQ = (FTT_SEQ << FSR_FTT_SHIFT)
-FSR_FTT_ALIGN = (FTT_ALIGN << FSR_FTT_SHIFT)
-FSR_FTT_DFAULT = (FTT_DFAULT << FSR_FTT_SHIFT)
-FSR_TEM_NX = (0x1 << 23)
-FSR_TEM_DZ = (0x2 << 23)
-FSR_TEM_UF = (0x4 << 23)
-FSR_TEM_OF = (0x8 << 23)
-FSR_TEM_NV = (0x10 << 23)
-RP_DBLEXT = 0
-RP_SINGLE = 1
-RP_DOUBLE = 2
-RP_RESERVED = 3
-RD_NEAR = 0
-RD_ZER0 = 1
-RD_POSINF = 2
-RD_NEGINF = 3
-FPRS_DL = 0x1
-FPRS_DU = 0x2
-FPRS_FEF = 0x4
-PIL_MAX = 0xf
-def SAVE_GLOBALS(RP): return \
-
-def RESTORE_GLOBALS(RP): return \
-
-def SAVE_OUTS(RP): return \
-
-def RESTORE_OUTS(RP): return \
-
-def SAVE_WINDOW(SBP): return \
-
-def RESTORE_WINDOW(SBP): return \
-
-def STORE_FPREGS(FP): return \
-
-def LOAD_FPREGS(FP): return \
-
-_SPARC_MAXREGWINDOW = 31
-_XRS_ID = 0x78727300
-GETCONTEXT = 0
-SETCONTEXT = 1
-UC_SIGMASK = 0o01
-UC_STACK = 0o02
-UC_CPU = 0o04
-UC_MAU = 0o10
-UC_FPU = UC_MAU
-UC_INTR = 0o20
-UC_ASR = 0o40
-UC_MCONTEXT = (UC_CPU|UC_FPU|UC_ASR)
-UC_ALL = (UC_SIGMASK|UC_STACK|UC_MCONTEXT)
-_SIGQUEUE_MAX = 32
-_SIGNOTIFY_MAX = 32
-
-# Included from sys/pcb.h
-INSTR_VALID = 0x02
-NORMAL_STEP = 0x04
-WATCH_STEP = 0x08
-CPC_OVERFLOW = 0x10
-ASYNC_HWERR = 0x20
-STEP_NONE = 0
-STEP_REQUESTED = 1
-STEP_ACTIVE = 2
-STEP_WASACTIVE = 3
-
-# Included from sys/msacct.h
-LMS_USER = 0
-LMS_SYSTEM = 1
-LMS_TRAP = 2
-LMS_TFAULT = 3
-LMS_DFAULT = 4
-LMS_KFAULT = 5
-LMS_USER_LOCK = 6
-LMS_SLEEP = 7
-LMS_WAIT_CPU = 8
-LMS_STOPPED = 9
-NMSTATES = 10
-
-# Included from sys/lwp.h
-
-# Included from sys/synch.h
-from TYPES import *
-USYNC_THREAD = 0x00
-USYNC_PROCESS = 0x01
-LOCK_NORMAL = 0x00
-LOCK_ERRORCHECK = 0x02
-LOCK_RECURSIVE = 0x04
-USYNC_PROCESS_ROBUST = 0x08
-LOCK_PRIO_NONE = 0x00
-LOCK_PRIO_INHERIT = 0x10
-LOCK_PRIO_PROTECT = 0x20
-LOCK_STALL_NP = 0x00
-LOCK_ROBUST_NP = 0x40
-LOCK_OWNERDEAD = 0x1
-LOCK_NOTRECOVERABLE = 0x2
-LOCK_INITED = 0x4
-LOCK_UNMAPPED = 0x8
-LWP_DETACHED = 0x00000040
-LWP_SUSPENDED = 0x00000080
-__LWP_ASLWP = 0x00000100
-MAXSYSARGS = 8
-NORMALRETURN = 0
-JUSTRETURN = 1
-LWP_USER = 0x01
-LWP_SYS = 0x02
-TS_FREE = 0x00
-TS_SLEEP = 0x01
-TS_RUN = 0x02
-TS_ONPROC = 0x04
-TS_ZOMB = 0x08
-TS_STOPPED = 0x10
-T_INTR_THREAD = 0x0001
-T_WAKEABLE = 0x0002
-T_TOMASK = 0x0004
-T_TALLOCSTK = 0x0008
-T_WOULDBLOCK = 0x0020
-T_DONTBLOCK = 0x0040
-T_DONTPEND = 0x0080
-T_SYS_PROF = 0x0100
-T_WAITCVSEM = 0x0200
-T_WATCHPT = 0x0400
-T_PANIC = 0x0800
-TP_HOLDLWP = 0x0002
-TP_TWAIT = 0x0004
-TP_LWPEXIT = 0x0008
-TP_PRSTOP = 0x0010
-TP_CHKPT = 0x0020
-TP_EXITLWP = 0x0040
-TP_PRVSTOP = 0x0080
-TP_MSACCT = 0x0100
-TP_STOPPING = 0x0200
-TP_WATCHPT = 0x0400
-TP_PAUSE = 0x0800
-TP_CHANGEBIND = 0x1000
-TS_LOAD = 0x0001
-TS_DONT_SWAP = 0x0002
-TS_SWAPENQ = 0x0004
-TS_ON_SWAPQ = 0x0008
-TS_CSTART = 0x0100
-TS_UNPAUSE = 0x0200
-TS_XSTART = 0x0400
-TS_PSTART = 0x0800
-TS_RESUME = 0x1000
-TS_CREATE = 0x2000
-TS_ALLSTART = \
- (TS_CSTART|TS_UNPAUSE|TS_XSTART|TS_PSTART|TS_RESUME|TS_CREATE)
-def CPR_VSTOPPED(t): return \
-
-def THREAD_TRANSITION(tp): return thread_transition(tp);
-
-def THREAD_STOP(tp): return \
-
-def THREAD_ZOMB(tp): return THREAD_SET_STATE(tp, TS_ZOMB, NULL)
-
-def SEMA_HELD(x): return (sema_held((x)))
-
-NO_LOCKS_HELD = 1
-NO_COMPETING_THREADS = 1
-FMNAMESZ = 8
-
-# Included from sys/systm.h
-from TYPES import *
-
-# Included from sys/proc.h
-
-# Included from sys/cred.h
-
-# Included from sys/user.h
-from TYPES import *
-
-# Included from sys/resource.h
-from TYPES import *
-PRIO_PROCESS = 0
-PRIO_PGRP = 1
-PRIO_USER = 2
-RLIMIT_CPU = 0
-RLIMIT_FSIZE = 1
-RLIMIT_DATA = 2
-RLIMIT_STACK = 3
-RLIMIT_CORE = 4
-RLIMIT_NOFILE = 5
-RLIMIT_VMEM = 6
-RLIMIT_AS = RLIMIT_VMEM
-RLIM_NLIMITS = 7
-RLIM_INFINITY = (-3)
-RLIM_SAVED_MAX = (-2)
-RLIM_SAVED_CUR = (-1)
-RLIM_INFINITY = 0x7fffffff
-RLIM_SAVED_MAX = 0x7ffffffe
-RLIM_SAVED_CUR = 0x7ffffffd
-RLIM32_INFINITY = 0x7fffffff
-RLIM32_SAVED_MAX = 0x7ffffffe
-RLIM32_SAVED_CUR = 0x7ffffffd
-
-# Included from sys/model.h
-
-# Included from sys/debug.h
-def ASSERT64(x): return ASSERT(x)
-
-def ASSERT32(x): return ASSERT(x)
-
-DATAMODEL_MASK = 0x0FF00000
-DATAMODEL_ILP32 = 0x00100000
-DATAMODEL_LP64 = 0x00200000
-DATAMODEL_NONE = 0
-DATAMODEL_NATIVE = DATAMODEL_LP64
-DATAMODEL_NATIVE = DATAMODEL_ILP32
-def STRUCT_SIZE(handle): return \
-
-def STRUCT_BUF(handle): return ((handle).ptr.m64)
-
-def SIZEOF_PTR(umodel): return \
-
-def STRUCT_SIZE(handle): return (sizeof (*(handle).ptr))
-
-def STRUCT_BUF(handle): return ((handle).ptr)
-
-def SIZEOF_PTR(umodel): return sizeof (caddr_t)
-
-def lwp_getdatamodel(t): return DATAMODEL_ILP32
-
-RUSAGE_SELF = 0
-RUSAGE_CHILDREN = -1
-
-# Included from sys/auxv.h
-AT_NULL = 0
-AT_IGNORE = 1
-AT_EXECFD = 2
-AT_PHDR = 3
-AT_PHENT = 4
-AT_PHNUM = 5
-AT_PAGESZ = 6
-AT_BASE = 7
-AT_FLAGS = 8
-AT_ENTRY = 9
-AT_DCACHEBSIZE = 10
-AT_ICACHEBSIZE = 11
-AT_UCACHEBSIZE = 12
-AT_SUN_UID = 2000
-AT_SUN_RUID = 2001
-AT_SUN_GID = 2002
-AT_SUN_RGID = 2003
-AT_SUN_LDELF = 2004
-AT_SUN_LDSHDR = 2005
-AT_SUN_LDNAME = 2006
-AT_SUN_LPAGESZ = 2007
-AT_SUN_PLATFORM = 2008
-AT_SUN_HWCAP = 2009
-AT_SUN_IFLUSH = 2010
-AT_SUN_CPU = 2011
-AT_SUN_EMUL_ENTRY = 2012
-AT_SUN_EMUL_EXECFD = 2013
-AT_SUN_EXECNAME = 2014
-AT_SUN_MMU = 2015
-
-# Included from sys/errno.h
-EPERM = 1
-ENOENT = 2
-ESRCH = 3
-EINTR = 4
-EIO = 5
-ENXIO = 6
-E2BIG = 7
-ENOEXEC = 8
-EBADF = 9
-ECHILD = 10
-EAGAIN = 11
-ENOMEM = 12
-EACCES = 13
-EFAULT = 14
-ENOTBLK = 15
-EBUSY = 16
-EEXIST = 17
-EXDEV = 18
-ENODEV = 19
-ENOTDIR = 20
-EISDIR = 21
-EINVAL = 22
-ENFILE = 23
-EMFILE = 24
-ENOTTY = 25
-ETXTBSY = 26
-EFBIG = 27
-ENOSPC = 28
-ESPIPE = 29
-EROFS = 30
-EMLINK = 31
-EPIPE = 32
-EDOM = 33
-ERANGE = 34
-ENOMSG = 35
-EIDRM = 36
-ECHRNG = 37
-EL2NSYNC = 38
-EL3HLT = 39
-EL3RST = 40
-ELNRNG = 41
-EUNATCH = 42
-ENOCSI = 43
-EL2HLT = 44
-EDEADLK = 45
-ENOLCK = 46
-ECANCELED = 47
-ENOTSUP = 48
-EDQUOT = 49
-EBADE = 50
-EBADR = 51
-EXFULL = 52
-ENOANO = 53
-EBADRQC = 54
-EBADSLT = 55
-EDEADLOCK = 56
-EBFONT = 57
-EOWNERDEAD = 58
-ENOTRECOVERABLE = 59
-ENOSTR = 60
-ENODATA = 61
-ETIME = 62
-ENOSR = 63
-ENONET = 64
-ENOPKG = 65
-EREMOTE = 66
-ENOLINK = 67
-EADV = 68
-ESRMNT = 69
-ECOMM = 70
-EPROTO = 71
-ELOCKUNMAPPED = 72
-ENOTACTIVE = 73
-EMULTIHOP = 74
-EBADMSG = 77
-ENAMETOOLONG = 78
-EOVERFLOW = 79
-ENOTUNIQ = 80
-EBADFD = 81
-EREMCHG = 82
-ELIBACC = 83
-ELIBBAD = 84
-ELIBSCN = 85
-ELIBMAX = 86
-ELIBEXEC = 87
-EILSEQ = 88
-ENOSYS = 89
-ELOOP = 90
-ERESTART = 91
-ESTRPIPE = 92
-ENOTEMPTY = 93
-EUSERS = 94
-ENOTSOCK = 95
-EDESTADDRREQ = 96
-EMSGSIZE = 97
-EPROTOTYPE = 98
-ENOPROTOOPT = 99
-EPROTONOSUPPORT = 120
-ESOCKTNOSUPPORT = 121
-EOPNOTSUPP = 122
-EPFNOSUPPORT = 123
-EAFNOSUPPORT = 124
-EADDRINUSE = 125
-EADDRNOTAVAIL = 126
-ENETDOWN = 127
-ENETUNREACH = 128
-ENETRESET = 129
-ECONNABORTED = 130
-ECONNRESET = 131
-ENOBUFS = 132
-EISCONN = 133
-ENOTCONN = 134
-ESHUTDOWN = 143
-ETOOMANYREFS = 144
-ETIMEDOUT = 145
-ECONNREFUSED = 146
-EHOSTDOWN = 147
-EHOSTUNREACH = 148
-EWOULDBLOCK = EAGAIN
-EALREADY = 149
-EINPROGRESS = 150
-ESTALE = 151
-PSARGSZ = 80
-PSCOMSIZ = 14
-MAXCOMLEN = 16
-__KERN_NAUXV_IMPL = 19
-__KERN_NAUXV_IMPL = 21
-__KERN_NAUXV_IMPL = 21
-PSARGSZ = 80
-
-# Included from sys/watchpoint.h
-from TYPES import *
-
-# Included from vm/seg_enum.h
-
-# Included from sys/copyops.h
-from TYPES import *
-
-# Included from sys/buf.h
-
-# Included from sys/kstat.h
-from TYPES import *
-KSTAT_STRLEN = 31
-def KSTAT_ENTER(k): return \
-
-def KSTAT_EXIT(k): return \
-
-KSTAT_TYPE_RAW = 0
-KSTAT_TYPE_NAMED = 1
-KSTAT_TYPE_INTR = 2
-KSTAT_TYPE_IO = 3
-KSTAT_TYPE_TIMER = 4
-KSTAT_NUM_TYPES = 5
-KSTAT_FLAG_VIRTUAL = 0x01
-KSTAT_FLAG_VAR_SIZE = 0x02
-KSTAT_FLAG_WRITABLE = 0x04
-KSTAT_FLAG_PERSISTENT = 0x08
-KSTAT_FLAG_DORMANT = 0x10
-KSTAT_FLAG_INVALID = 0x20
-KSTAT_READ = 0
-KSTAT_WRITE = 1
-KSTAT_DATA_CHAR = 0
-KSTAT_DATA_INT32 = 1
-KSTAT_DATA_UINT32 = 2
-KSTAT_DATA_INT64 = 3
-KSTAT_DATA_UINT64 = 4
-KSTAT_DATA_LONG = KSTAT_DATA_INT32
-KSTAT_DATA_ULONG = KSTAT_DATA_UINT32
-KSTAT_DATA_LONG = KSTAT_DATA_INT64
-KSTAT_DATA_ULONG = KSTAT_DATA_UINT64
-KSTAT_DATA_LONG = 7
-KSTAT_DATA_ULONG = 8
-KSTAT_DATA_LONGLONG = KSTAT_DATA_INT64
-KSTAT_DATA_ULONGLONG = KSTAT_DATA_UINT64
-KSTAT_DATA_FLOAT = 5
-KSTAT_DATA_DOUBLE = 6
-KSTAT_INTR_HARD = 0
-KSTAT_INTR_SOFT = 1
-KSTAT_INTR_WATCHDOG = 2
-KSTAT_INTR_SPURIOUS = 3
-KSTAT_INTR_MULTSVC = 4
-KSTAT_NUM_INTRS = 5
-B_BUSY = 0x0001
-B_DONE = 0x0002
-B_ERROR = 0x0004
-B_PAGEIO = 0x0010
-B_PHYS = 0x0020
-B_READ = 0x0040
-B_WRITE = 0x0100
-B_KERNBUF = 0x0008
-B_WANTED = 0x0080
-B_AGE = 0x000200
-B_ASYNC = 0x000400
-B_DELWRI = 0x000800
-B_STALE = 0x001000
-B_DONTNEED = 0x002000
-B_REMAPPED = 0x004000
-B_FREE = 0x008000
-B_INVAL = 0x010000
-B_FORCE = 0x020000
-B_HEAD = 0x040000
-B_NOCACHE = 0x080000
-B_TRUNC = 0x100000
-B_SHADOW = 0x200000
-B_RETRYWRI = 0x400000
-def notavail(bp): return \
-
-def BWRITE(bp): return \
-
-def BWRITE2(bp): return \
-
-
-# Included from sys/aio_req.h
-
-# Included from sys/uio.h
-from TYPES import *
-WP_NOWATCH = 0x01
-WP_SETPROT = 0x02
-
-# Included from sys/timer.h
-from TYPES import *
-_TIMER_MAX = 32
-ITLK_LOCKED = 0x01
-ITLK_WANTED = 0x02
-ITLK_REMOVE = 0x04
-IT_PERLWP = 0x01
-IT_SIGNAL = 0x02
-
-# Included from sys/utrap.h
-UT_INSTRUCTION_DISABLED = 1
-UT_INSTRUCTION_ERROR = 2
-UT_INSTRUCTION_PROTECTION = 3
-UT_ILLTRAP_INSTRUCTION = 4
-UT_ILLEGAL_INSTRUCTION = 5
-UT_PRIVILEGED_OPCODE = 6
-UT_FP_DISABLED = 7
-UT_FP_EXCEPTION_IEEE_754 = 8
-UT_FP_EXCEPTION_OTHER = 9
-UT_TAG_OVERFLOW = 10
-UT_DIVISION_BY_ZERO = 11
-UT_DATA_EXCEPTION = 12
-UT_DATA_ERROR = 13
-UT_DATA_PROTECTION = 14
-UT_MEM_ADDRESS_NOT_ALIGNED = 15
-UT_PRIVILEGED_ACTION = 16
-UT_ASYNC_DATA_ERROR = 17
-UT_TRAP_INSTRUCTION_16 = 18
-UT_TRAP_INSTRUCTION_17 = 19
-UT_TRAP_INSTRUCTION_18 = 20
-UT_TRAP_INSTRUCTION_19 = 21
-UT_TRAP_INSTRUCTION_20 = 22
-UT_TRAP_INSTRUCTION_21 = 23
-UT_TRAP_INSTRUCTION_22 = 24
-UT_TRAP_INSTRUCTION_23 = 25
-UT_TRAP_INSTRUCTION_24 = 26
-UT_TRAP_INSTRUCTION_25 = 27
-UT_TRAP_INSTRUCTION_26 = 28
-UT_TRAP_INSTRUCTION_27 = 29
-UT_TRAP_INSTRUCTION_28 = 30
-UT_TRAP_INSTRUCTION_29 = 31
-UT_TRAP_INSTRUCTION_30 = 32
-UT_TRAP_INSTRUCTION_31 = 33
-UTRAP_V8P_FP_DISABLED = UT_FP_DISABLED
-UTRAP_V8P_MEM_ADDRESS_NOT_ALIGNED = UT_MEM_ADDRESS_NOT_ALIGNED
-UT_PRECISE_MAXTRAPS = 33
-
-# Included from sys/refstr.h
-
-# Included from sys/task.h
-from TYPES import *
-TASK_NORMAL = 0x0
-TASK_FINAL = 0x1
-TASK_FINALITY = 0x1
-
-# Included from sys/id_space.h
-from TYPES import *
-
-# Included from sys/vmem.h
-from TYPES import *
-VM_SLEEP = 0x00000000
-VM_NOSLEEP = 0x00000001
-VM_PANIC = 0x00000002
-VM_KMFLAGS = 0x000000ff
-VM_BESTFIT = 0x00000100
-VMEM_ALLOC = 0x01
-VMEM_FREE = 0x02
-VMEM_SPAN = 0x10
-ISP_NORMAL = 0x0
-ISP_RESERVE = 0x1
-
-# Included from sys/exacct_impl.h
-from TYPES import *
-
-# Included from sys/kmem.h
-from TYPES import *
-KM_SLEEP = 0x0000
-KM_NOSLEEP = 0x0001
-KM_PANIC = 0x0002
-KM_VMFLAGS = 0x00ff
-KM_FLAGS = 0xffff
-KMC_NOTOUCH = 0x00010000
-KMC_NODEBUG = 0x00020000
-KMC_NOMAGAZINE = 0x00040000
-KMC_NOHASH = 0x00080000
-KMC_QCACHE = 0x00100000
-_ISA_IA32 = 0
-_ISA_IA64 = 1
-SSLEEP = 1
-SRUN = 2
-SZOMB = 3
-SSTOP = 4
-SIDL = 5
-SONPROC = 6
-CLDPEND = 0x0001
-CLDCONT = 0x0002
-SSYS = 0x00000001
-STRC = 0x00000002
-SLOAD = 0x00000008
-SLOCK = 0x00000010
-SPREXEC = 0x00000020
-SPROCTR = 0x00000040
-SPRFORK = 0x00000080
-SKILLED = 0x00000100
-SULOAD = 0x00000200
-SRUNLCL = 0x00000400
-SBPTADJ = 0x00000800
-SKILLCL = 0x00001000
-SOWEUPC = 0x00002000
-SEXECED = 0x00004000
-SPASYNC = 0x00008000
-SJCTL = 0x00010000
-SNOWAIT = 0x00020000
-SVFORK = 0x00040000
-SVFWAIT = 0x00080000
-EXITLWPS = 0x00100000
-HOLDFORK = 0x00200000
-SWAITSIG = 0x00400000
-HOLDFORK1 = 0x00800000
-COREDUMP = 0x01000000
-SMSACCT = 0x02000000
-ASLWP = 0x04000000
-SPRLOCK = 0x08000000
-NOCD = 0x10000000
-HOLDWATCH = 0x20000000
-SMSFORK = 0x40000000
-SDOCORE = 0x80000000
-FORREAL = 0
-JUSTLOOKING = 1
-SUSPEND_NORMAL = 0
-SUSPEND_PAUSE = 1
-NOCLASS = (-1)
-
-# Included from sys/dditypes.h
-DDI_DEVICE_ATTR_V0 = 0x0001
-DDI_NEVERSWAP_ACC = 0x00
-DDI_STRUCTURE_LE_ACC = 0x01
-DDI_STRUCTURE_BE_ACC = 0x02
-DDI_STRICTORDER_ACC = 0x00
-DDI_UNORDERED_OK_ACC = 0x01
-DDI_MERGING_OK_ACC = 0x02
-DDI_LOADCACHING_OK_ACC = 0x03
-DDI_STORECACHING_OK_ACC = 0x04
-DDI_DATA_SZ01_ACC = 1
-DDI_DATA_SZ02_ACC = 2
-DDI_DATA_SZ04_ACC = 4
-DDI_DATA_SZ08_ACC = 8
-VERS_ACCHDL = 0x0001
-DEVID_NONE = 0
-DEVID_SCSI3_WWN = 1
-DEVID_SCSI_SERIAL = 2
-DEVID_FAB = 3
-DEVID_ENCAP = 4
-DEVID_MAXTYPE = 4
-
-# Included from sys/varargs.h
-
-# Included from sys/va_list.h
-VA_ALIGN = 8
-def _ARGSIZEOF(t): return ((sizeof (t) + VA_ALIGN - 1) & ~(VA_ALIGN - 1))
-
-VA_ALIGN = 8
-def _ARGSIZEOF(t): return ((sizeof (t) + VA_ALIGN - 1) & ~(VA_ALIGN - 1))
-
-NSYSCALL = 256
-SE_32RVAL1 = 0x0
-SE_32RVAL2 = 0x1
-SE_64RVAL = 0x2
-SE_RVAL_MASK = 0x3
-SE_LOADABLE = 0x08
-SE_LOADED = 0x10
-SE_NOUNLOAD = 0x20
-SE_ARGC = 0x40
-
-# Included from sys/devops.h
-from TYPES import *
-
-# Included from sys/poll.h
-POLLIN = 0x0001
-POLLPRI = 0x0002
-POLLOUT = 0x0004
-POLLRDNORM = 0x0040
-POLLWRNORM = POLLOUT
-POLLRDBAND = 0x0080
-POLLWRBAND = 0x0100
-POLLNORM = POLLRDNORM
-POLLERR = 0x0008
-POLLHUP = 0x0010
-POLLNVAL = 0x0020
-POLLREMOVE = 0x0800
-POLLRDDATA = 0x0200
-POLLNOERR = 0x0400
-POLLCLOSED = 0x8000
-
-# Included from vm/as.h
-
-# Included from vm/seg.h
-
-# Included from sys/vnode.h
-from TYPES import *
-VROOT = 0x01
-VNOCACHE = 0x02
-VNOMAP = 0x04
-VDUP = 0x08
-VNOSWAP = 0x10
-VNOMOUNT = 0x20
-VISSWAP = 0x40
-VSWAPLIKE = 0x80
-VVFSLOCK = 0x100
-VVFSWAIT = 0x200
-VVMLOCK = 0x400
-VDIROPEN = 0x800
-VVMEXEC = 0x1000
-VPXFS = 0x2000
-AT_TYPE = 0x0001
-AT_MODE = 0x0002
-AT_UID = 0x0004
-AT_GID = 0x0008
-AT_FSID = 0x0010
-AT_NODEID = 0x0020
-AT_NLINK = 0x0040
-AT_SIZE = 0x0080
-AT_ATIME = 0x0100
-AT_MTIME = 0x0200
-AT_CTIME = 0x0400
-AT_RDEV = 0x0800
-AT_BLKSIZE = 0x1000
-AT_NBLOCKS = 0x2000
-AT_VCODE = 0x4000
-AT_ALL = (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
- AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
- AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
-AT_STAT = (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
- AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV)
-AT_TIMES = (AT_ATIME|AT_MTIME|AT_CTIME)
-AT_NOSET = (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
- AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
-VSUID = 0o4000
-VSGID = 0o2000
-VSVTX = 0o1000
-VREAD = 0o0400
-VWRITE = 0o0200
-VEXEC = 0o0100
-MODEMASK = 0o7777
-PERMMASK = 0o0777
-def MANDMODE(mode): return (((mode) & (VSGID|(VEXEC>>3))) == VSGID)
-
-VSA_ACL = 0x0001
-VSA_ACLCNT = 0x0002
-VSA_DFACL = 0x0004
-VSA_DFACLCNT = 0x0008
-LOOKUP_DIR = 0x01
-DUMP_ALLOC = 0
-DUMP_FREE = 1
-DUMP_SCAN = 2
-ATTR_UTIME = 0x01
-ATTR_EXEC = 0x02
-ATTR_COMM = 0x04
-ATTR_HINT = 0x08
-ATTR_REAL = 0x10
-
-# Included from vm/faultcode.h
-FC_HWERR = 0x1
-FC_ALIGN = 0x2
-FC_OBJERR = 0x3
-FC_PROT = 0x4
-FC_NOMAP = 0x5
-FC_NOSUPPORT = 0x6
-def FC_MAKE_ERR(e): return (((e) << 8) | FC_OBJERR)
-
-def FC_CODE(fc): return ((fc) & 0xff)
-
-def FC_ERRNO(fc): return ((unsigned)(fc) >> 8)
-
-
-# Included from vm/hat.h
-from TYPES import *
-
-# Included from vm/page.h
-PAGE_HASHAVELEN = 4
-PAGE_HASHVPSHIFT = 6
-PG_EXCL = 0x0001
-PG_WAIT = 0x0002
-PG_PHYSCONTIG = 0x0004
-PG_MATCH_COLOR = 0x0008
-PG_NORELOC = 0x0010
-PG_FREE_LIST = 1
-PG_CACHE_LIST = 2
-PG_LIST_TAIL = 0
-PG_LIST_HEAD = 1
-def page_next_raw(PP): return page_nextn_raw((PP), 1)
-
-PAGE_IO_INUSE = 0x1
-PAGE_IO_WANTED = 0x2
-PGREL_NOTREL = 0x1
-PGREL_CLEAN = 0x2
-PGREL_MOD = 0x3
-P_FREE = 0x80
-P_NORELOC = 0x40
-def PP_SETAGED(pp): return ASSERT(PP_ISAGED(pp))
-
-HAT_FLAGS_RESV = 0xFF000000
-HAT_LOAD = 0x00
-HAT_LOAD_LOCK = 0x01
-HAT_LOAD_ADV = 0x04
-HAT_LOAD_CONTIG = 0x10
-HAT_LOAD_NOCONSIST = 0x20
-HAT_LOAD_SHARE = 0x40
-HAT_LOAD_REMAP = 0x80
-HAT_RELOAD_SHARE = 0x100
-HAT_PLAT_ATTR_MASK = 0xF00000
-HAT_PROT_MASK = 0x0F
-HAT_NOFAULT = 0x10
-HAT_NOSYNC = 0x20
-HAT_STRICTORDER = 0x0000
-HAT_UNORDERED_OK = 0x0100
-HAT_MERGING_OK = 0x0200
-HAT_LOADCACHING_OK = 0x0300
-HAT_STORECACHING_OK = 0x0400
-HAT_ORDER_MASK = 0x0700
-HAT_NEVERSWAP = 0x0000
-HAT_STRUCTURE_BE = 0x1000
-HAT_STRUCTURE_LE = 0x2000
-HAT_ENDIAN_MASK = 0x3000
-HAT_COW = 0x0001
-HAT_UNLOAD = 0x00
-HAT_UNLOAD_NOSYNC = 0x02
-HAT_UNLOAD_UNLOCK = 0x04
-HAT_UNLOAD_OTHER = 0x08
-HAT_UNLOAD_UNMAP = 0x10
-HAT_SYNC_DONTZERO = 0x00
-HAT_SYNC_ZERORM = 0x01
-HAT_SYNC_STOPON_REF = 0x02
-HAT_SYNC_STOPON_MOD = 0x04
-HAT_SYNC_STOPON_RM = (HAT_SYNC_STOPON_REF | HAT_SYNC_STOPON_MOD)
-HAT_DUP_ALL = 1
-HAT_DUP_COW = 2
-HAT_MAP = 0x00
-HAT_ADV_PGUNLOAD = 0x00
-HAT_FORCE_PGUNLOAD = 0x01
-P_MOD = 0x1
-P_REF = 0x2
-P_RO = 0x4
-def hat_ismod(pp): return (hat_page_getattr(pp, P_MOD))
-
-def hat_isref(pp): return (hat_page_getattr(pp, P_REF))
-
-def hat_isro(pp): return (hat_page_getattr(pp, P_RO))
-
-def hat_setmod(pp): return (hat_page_setattr(pp, P_MOD))
-
-def hat_setref(pp): return (hat_page_setattr(pp, P_REF))
-
-def hat_setrefmod(pp): return (hat_page_setattr(pp, P_REF|P_MOD))
-
-def hat_clrmod(pp): return (hat_page_clrattr(pp, P_MOD))
-
-def hat_clrref(pp): return (hat_page_clrattr(pp, P_REF))
-
-def hat_clrrefmod(pp): return (hat_page_clrattr(pp, P_REF|P_MOD))
-
-def hat_page_is_mapped(pp): return (hat_page_getshare(pp))
-
-HAT_DONTALLOC = 0
-HAT_ALLOC = 1
-HRM_SHIFT = 4
-HRM_BYTES = (1 << HRM_SHIFT)
-HRM_PAGES = ((HRM_BYTES * NBBY) / 2)
-HRM_PGPERBYTE = (NBBY/2)
-HRM_PGBYTEMASK = (HRM_PGPERBYTE-1)
-HRM_HASHSIZE = 0x200
-HRM_HASHMASK = (HRM_HASHSIZE - 1)
-HRM_BLIST_INCR = 0x200
-HRM_SWSMONID = 1
-SSL_NLEVELS = 4
-SSL_BFACTOR = 4
-SSL_LOG2BF = 2
-SEGP_ASYNC_FLUSH = 0x1
-SEGP_FORCE_WIRED = 0x2
-SEGP_SUCCESS = 0
-SEGP_FAIL = 1
-def seg_pages(seg): return \
-
-IE_NOMEM = -1
-AS_PAGLCK = 0x80
-AS_CLAIMGAP = 0x40
-AS_UNMAPWAIT = 0x20
-def AS_TYPE_64BIT(as_): return \
-
-AS_LREP_LINKEDLIST = 0
-AS_LREP_SKIPLIST = 1
-AS_MUTATION_THRESH = 225
-AH_DIR = 0x1
-AH_LO = 0x0
-AH_HI = 0x1
-AH_CONTAIN = 0x2
-
-# Included from sys/ddidmareq.h
-DMA_UNIT_8 = 1
-DMA_UNIT_16 = 2
-DMA_UNIT_32 = 4
-DMALIM_VER0 = ((0x86000000) + 0)
-DDI_DMA_FORCE_PHYSICAL = 0x0100
-DMA_ATTR_V0 = 0
-DMA_ATTR_VERSION = DMA_ATTR_V0
-DDI_DMA_CALLBACK_RUNOUT = 0
-DDI_DMA_CALLBACK_DONE = 1
-DDI_DMA_WRITE = 0x0001
-DDI_DMA_READ = 0x0002
-DDI_DMA_RDWR = (DDI_DMA_READ | DDI_DMA_WRITE)
-DDI_DMA_REDZONE = 0x0004
-DDI_DMA_PARTIAL = 0x0008
-DDI_DMA_CONSISTENT = 0x0010
-DDI_DMA_EXCLUSIVE = 0x0020
-DDI_DMA_STREAMING = 0x0040
-DDI_DMA_SBUS_64BIT = 0x2000
-DDI_DMA_MAPPED = 0
-DDI_DMA_MAPOK = 0
-DDI_DMA_PARTIAL_MAP = 1
-DDI_DMA_DONE = 2
-DDI_DMA_NORESOURCES = -1
-DDI_DMA_NOMAPPING = -2
-DDI_DMA_TOOBIG = -3
-DDI_DMA_TOOSMALL = -4
-DDI_DMA_LOCKED = -5
-DDI_DMA_BADLIMITS = -6
-DDI_DMA_STALE = -7
-DDI_DMA_BADATTR = -8
-DDI_DMA_INUSE = -9
-DDI_DMA_SYNC_FORDEV = 0x0
-DDI_DMA_SYNC_FORCPU = 0x1
-DDI_DMA_SYNC_FORKERNEL = 0x2
-
-# Included from sys/ddimapreq.h
-
-# Included from sys/mman.h
-PROT_READ = 0x1
-PROT_WRITE = 0x2
-PROT_EXEC = 0x4
-PROT_USER = 0x8
-PROT_ZFOD = (PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
-PROT_ALL = (PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
-PROT_NONE = 0x0
-MAP_SHARED = 1
-MAP_PRIVATE = 2
-MAP_TYPE = 0xf
-MAP_FIXED = 0x10
-MAP_NORESERVE = 0x40
-MAP_ANON = 0x100
-MAP_ANONYMOUS = MAP_ANON
-MAP_RENAME = 0x20
-PROC_TEXT = (PROT_EXEC | PROT_READ)
-PROC_DATA = (PROT_READ | PROT_WRITE | PROT_EXEC)
-SHARED = 0x10
-PRIVATE = 0x20
-VALID_ATTR = (PROT_READ|PROT_WRITE|PROT_EXEC|SHARED|PRIVATE)
-PROT_EXCL = 0x20
-_MAP_LOW32 = 0x80
-_MAP_NEW = 0x80000000
-from TYPES import *
-MADV_NORMAL = 0
-MADV_RANDOM = 1
-MADV_SEQUENTIAL = 2
-MADV_WILLNEED = 3
-MADV_DONTNEED = 4
-MADV_FREE = 5
-MS_OLDSYNC = 0x0
-MS_SYNC = 0x4
-MS_ASYNC = 0x1
-MS_INVALIDATE = 0x2
-MC_SYNC = 1
-MC_LOCK = 2
-MC_UNLOCK = 3
-MC_ADVISE = 4
-MC_LOCKAS = 5
-MC_UNLOCKAS = 6
-MCL_CURRENT = 0x1
-MCL_FUTURE = 0x2
-DDI_MAP_VERSION = 0x0001
-DDI_MF_USER_MAPPING = 0x1
-DDI_MF_KERNEL_MAPPING = 0x2
-DDI_MF_DEVICE_MAPPING = 0x4
-DDI_ME_GENERIC = (-1)
-DDI_ME_UNIMPLEMENTED = (-2)
-DDI_ME_NORESOURCES = (-3)
-DDI_ME_UNSUPPORTED = (-4)
-DDI_ME_REGSPEC_RANGE = (-5)
-DDI_ME_RNUMBER_RANGE = (-6)
-DDI_ME_INVAL = (-7)
-
-# Included from sys/ddipropdefs.h
-def CELLS_1275_TO_BYTES(n): return ((n) * PROP_1275_CELL_SIZE)
-
-def BYTES_TO_1275_CELLS(n): return ((n) / PROP_1275_CELL_SIZE)
-
-PH_FROM_PROM = 0x01
-DDI_PROP_SUCCESS = 0
-DDI_PROP_NOT_FOUND = 1
-DDI_PROP_UNDEFINED = 2
-DDI_PROP_NO_MEMORY = 3
-DDI_PROP_INVAL_ARG = 4
-DDI_PROP_BUF_TOO_SMALL = 5
-DDI_PROP_CANNOT_DECODE = 6
-DDI_PROP_CANNOT_ENCODE = 7
-DDI_PROP_END_OF_DATA = 8
-DDI_PROP_FOUND_1275 = 255
-PROP_1275_INT_SIZE = 4
-DDI_PROP_DONTPASS = 0x0001
-DDI_PROP_CANSLEEP = 0x0002
-DDI_PROP_SYSTEM_DEF = 0x0004
-DDI_PROP_NOTPROM = 0x0008
-DDI_PROP_DONTSLEEP = 0x0010
-DDI_PROP_STACK_CREATE = 0x0020
-DDI_PROP_UNDEF_IT = 0x0040
-DDI_PROP_HW_DEF = 0x0080
-DDI_PROP_TYPE_INT = 0x0100
-DDI_PROP_TYPE_STRING = 0x0200
-DDI_PROP_TYPE_BYTE = 0x0400
-DDI_PROP_TYPE_COMPOSITE = 0x0800
-DDI_PROP_TYPE_ANY = (DDI_PROP_TYPE_INT | \
- DDI_PROP_TYPE_STRING | \
- DDI_PROP_TYPE_BYTE | \
- DDI_PROP_TYPE_COMPOSITE)
-DDI_PROP_TYPE_MASK = (DDI_PROP_TYPE_INT | \
- DDI_PROP_TYPE_STRING | \
- DDI_PROP_TYPE_BYTE | \
- DDI_PROP_TYPE_COMPOSITE)
-DDI_RELATIVE_ADDRESSING = "relative-addressing"
-DDI_GENERIC_ADDRESSING = "generic-addressing"
-
-# Included from sys/ddidevmap.h
-KMEM_PAGEABLE = 0x100
-KMEM_NON_PAGEABLE = 0x200
-UMEM_LOCKED = 0x400
-UMEM_TRASH = 0x800
-DEVMAP_OPS_REV = 1
-DEVMAP_DEFAULTS = 0x00
-DEVMAP_MAPPING_INVALID = 0x01
-DEVMAP_ALLOW_REMAP = 0x02
-DEVMAP_USE_PAGESIZE = 0x04
-DEVMAP_SETUP_FLAGS = \
- (DEVMAP_MAPPING_INVALID | DEVMAP_ALLOW_REMAP | DEVMAP_USE_PAGESIZE)
-DEVMAP_SETUP_DONE = 0x100
-DEVMAP_LOCK_INITED = 0x200
-DEVMAP_FAULTING = 0x400
-DEVMAP_LOCKED = 0x800
-DEVMAP_FLAG_LARGE = 0x1000
-DDI_UMEM_SLEEP = 0x0
-DDI_UMEM_NOSLEEP = 0x01
-DDI_UMEM_PAGEABLE = 0x02
-DDI_UMEM_TRASH = 0x04
-DDI_UMEMLOCK_READ = 0x01
-DDI_UMEMLOCK_WRITE = 0x02
-
-# Included from sys/nexusdefs.h
-
-# Included from sys/nexusintr.h
-BUSO_REV = 4
-BUSO_REV_3 = 3
-BUSO_REV_4 = 4
-DEVO_REV = 3
-CB_REV = 1
-DDI_IDENTIFIED = (0)
-DDI_NOT_IDENTIFIED = (-1)
-DDI_PROBE_FAILURE = ENXIO
-DDI_PROBE_DONTCARE = 0
-DDI_PROBE_PARTIAL = 1
-DDI_PROBE_SUCCESS = 2
-MAPDEV_REV = 1
-from TYPES import *
-D_NEW = 0x00
-_D_OLD = 0x01
-D_TAPE = 0x08
-D_MTSAFE = 0x0020
-_D_QNEXTLESS = 0x0040
-_D_MTOCSHARED = 0x0080
-D_MTOCEXCL = 0x0800
-D_MTPUTSHARED = 0x1000
-D_MTPERQ = 0x2000
-D_MTQPAIR = 0x4000
-D_MTPERMOD = 0x6000
-D_MTOUTPERIM = 0x8000
-_D_MTCBSHARED = 0x10000
-D_MTINNER_MOD = (D_MTPUTSHARED|_D_MTOCSHARED|_D_MTCBSHARED)
-D_MTOUTER_MOD = (D_MTOCEXCL)
-D_MP = D_MTSAFE
-D_64BIT = 0x200
-D_SYNCSTR = 0x400
-D_DEVMAP = 0x100
-D_HOTPLUG = 0x4
-SNDZERO = 0x001
-SNDPIPE = 0x002
-RNORM = 0x000
-RMSGD = 0x001
-RMSGN = 0x002
-RMODEMASK = 0x003
-RPROTDAT = 0x004
-RPROTDIS = 0x008
-RPROTNORM = 0x010
-RPROTMASK = 0x01c
-RFLUSHMASK = 0x020
-RFLUSHPCPROT = 0x020
-RERRNORM = 0x001
-RERRNONPERSIST = 0x002
-RERRMASK = (RERRNORM|RERRNONPERSIST)
-WERRNORM = 0x004
-WERRNONPERSIST = 0x008
-WERRMASK = (WERRNORM|WERRNONPERSIST)
-FLUSHR = 0x01
-FLUSHW = 0x02
-FLUSHRW = 0x03
-FLUSHBAND = 0x04
-MAPINOK = 0x01
-NOMAPIN = 0x02
-REMAPOK = 0x04
-NOREMAP = 0x08
-S_INPUT = 0x0001
-S_HIPRI = 0x0002
-S_OUTPUT = 0x0004
-S_MSG = 0x0008
-S_ERROR = 0x0010
-S_HANGUP = 0x0020
-S_RDNORM = 0x0040
-S_WRNORM = S_OUTPUT
-S_RDBAND = 0x0080
-S_WRBAND = 0x0100
-S_BANDURG = 0x0200
-RS_HIPRI = 0x01
-STRUIO_POSTPONE = 0x08
-STRUIO_MAPIN = 0x10
-MSG_HIPRI = 0x01
-MSG_ANY = 0x02
-MSG_BAND = 0x04
-MSG_XPG4 = 0x08
-MSG_IPEEK = 0x10
-MSG_DISCARDTAIL = 0x20
-MSG_HOLDSIG = 0x40
-MSG_IGNERROR = 0x80
-MSG_DELAYERROR = 0x100
-MSG_IGNFLOW = 0x200
-MSG_NOMARK = 0x400
-MORECTL = 1
-MOREDATA = 2
-MUXID_ALL = (-1)
-ANYMARK = 0x01
-LASTMARK = 0x02
-_INFTIM = -1
-INFTIM = _INFTIM
diff --git a/Lib/plat-sunos5/TYPES.py b/Lib/plat-sunos5/TYPES.py
deleted file mode 100644
index da4e6b1..0000000
--- a/Lib/plat-sunos5/TYPES.py
+++ /dev/null
@@ -1,313 +0,0 @@
-# Generated by h2py from /usr/include/sys/types.h
-
-# Included from sys/isa_defs.h
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_ALIGNMENT = 8
-_LONG_LONG_ALIGNMENT = 8
-_DOUBLE_ALIGNMENT = 8
-_LONG_DOUBLE_ALIGNMENT = 16
-_POINTER_ALIGNMENT = 8
-_MAX_ALIGNMENT = 16
-_ALIGNMENT_REQUIRED = 1
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_ALIGNMENT = 4
-_LONG_LONG_ALIGNMENT = 4
-_DOUBLE_ALIGNMENT = 4
-_LONG_DOUBLE_ALIGNMENT = 4
-_POINTER_ALIGNMENT = 4
-_MAX_ALIGNMENT = 4
-_ALIGNMENT_REQUIRED = 0
-_CHAR_ALIGNMENT = 1
-_SHORT_ALIGNMENT = 2
-_INT_ALIGNMENT = 4
-_LONG_LONG_ALIGNMENT = 8
-_DOUBLE_ALIGNMENT = 8
-_ALIGNMENT_REQUIRED = 1
-_LONG_ALIGNMENT = 4
-_LONG_DOUBLE_ALIGNMENT = 8
-_POINTER_ALIGNMENT = 4
-_MAX_ALIGNMENT = 8
-_LONG_ALIGNMENT = 8
-_LONG_DOUBLE_ALIGNMENT = 16
-_POINTER_ALIGNMENT = 8
-_MAX_ALIGNMENT = 16
-
-# Included from sys/feature_tests.h
-_POSIX_C_SOURCE = 1
-_LARGEFILE64_SOURCE = 1
-_LARGEFILE_SOURCE = 1
-_FILE_OFFSET_BITS = 64
-_FILE_OFFSET_BITS = 32
-_POSIX_C_SOURCE = 199506
-_POSIX_PTHREAD_SEMANTICS = 1
-_XOPEN_VERSION = 500
-_XOPEN_VERSION = 4
-_XOPEN_VERSION = 3
-
-# Included from sys/machtypes.h
-
-# Included from sys/inttypes.h
-
-# Included from sys/int_types.h
-
-# Included from sys/int_limits.h
-INT8_MAX = (127)
-INT16_MAX = (32767)
-INT32_MAX = (2147483647)
-INTMAX_MAX = INT32_MAX
-INT_LEAST8_MAX = INT8_MAX
-INT_LEAST16_MAX = INT16_MAX
-INT_LEAST32_MAX = INT32_MAX
-INT8_MIN = (-128)
-INT16_MIN = (-32767-1)
-INT32_MIN = (-2147483647-1)
-INTMAX_MIN = INT32_MIN
-INT_LEAST8_MIN = INT8_MIN
-INT_LEAST16_MIN = INT16_MIN
-INT_LEAST32_MIN = INT32_MIN
-
-# Included from sys/int_const.h
-def INT8_C(c): return (c)
-
-def INT16_C(c): return (c)
-
-def INT32_C(c): return (c)
-
-def INT64_C(c): return __CONCAT__(c,l)
-
-def INT64_C(c): return __CONCAT__(c,ll)
-
-def UINT8_C(c): return __CONCAT__(c,u)
-
-def UINT16_C(c): return __CONCAT__(c,u)
-
-def UINT32_C(c): return __CONCAT__(c,u)
-
-def UINT64_C(c): return __CONCAT__(c,ul)
-
-def UINT64_C(c): return __CONCAT__(c,ull)
-
-def INTMAX_C(c): return __CONCAT__(c,l)
-
-def UINTMAX_C(c): return __CONCAT__(c,ul)
-
-def INTMAX_C(c): return __CONCAT__(c,ll)
-
-def UINTMAX_C(c): return __CONCAT__(c,ull)
-
-def INTMAX_C(c): return (c)
-
-def UINTMAX_C(c): return (c)
-
-
-# Included from sys/int_fmtio.h
-PRId8 = "d"
-PRId16 = "d"
-PRId32 = "d"
-PRId64 = "ld"
-PRId64 = "lld"
-PRIdLEAST8 = "d"
-PRIdLEAST16 = "d"
-PRIdLEAST32 = "d"
-PRIdLEAST64 = "ld"
-PRIdLEAST64 = "lld"
-PRIi8 = "i"
-PRIi16 = "i"
-PRIi32 = "i"
-PRIi64 = "li"
-PRIi64 = "lli"
-PRIiLEAST8 = "i"
-PRIiLEAST16 = "i"
-PRIiLEAST32 = "i"
-PRIiLEAST64 = "li"
-PRIiLEAST64 = "lli"
-PRIo8 = "o"
-PRIo16 = "o"
-PRIo32 = "o"
-PRIo64 = "lo"
-PRIo64 = "llo"
-PRIoLEAST8 = "o"
-PRIoLEAST16 = "o"
-PRIoLEAST32 = "o"
-PRIoLEAST64 = "lo"
-PRIoLEAST64 = "llo"
-PRIx8 = "x"
-PRIx16 = "x"
-PRIx32 = "x"
-PRIx64 = "lx"
-PRIx64 = "llx"
-PRIxLEAST8 = "x"
-PRIxLEAST16 = "x"
-PRIxLEAST32 = "x"
-PRIxLEAST64 = "lx"
-PRIxLEAST64 = "llx"
-PRIX8 = "X"
-PRIX16 = "X"
-PRIX32 = "X"
-PRIX64 = "lX"
-PRIX64 = "llX"
-PRIXLEAST8 = "X"
-PRIXLEAST16 = "X"
-PRIXLEAST32 = "X"
-PRIXLEAST64 = "lX"
-PRIXLEAST64 = "llX"
-PRIu8 = "u"
-PRIu16 = "u"
-PRIu32 = "u"
-PRIu64 = "lu"
-PRIu64 = "llu"
-PRIuLEAST8 = "u"
-PRIuLEAST16 = "u"
-PRIuLEAST32 = "u"
-PRIuLEAST64 = "lu"
-PRIuLEAST64 = "llu"
-SCNd16 = "hd"
-SCNd32 = "d"
-SCNd64 = "ld"
-SCNd64 = "lld"
-SCNi16 = "hi"
-SCNi32 = "i"
-SCNi64 = "li"
-SCNi64 = "lli"
-SCNo16 = "ho"
-SCNo32 = "o"
-SCNo64 = "lo"
-SCNo64 = "llo"
-SCNu16 = "hu"
-SCNu32 = "u"
-SCNu64 = "lu"
-SCNu64 = "llu"
-SCNx16 = "hx"
-SCNx32 = "x"
-SCNx64 = "lx"
-SCNx64 = "llx"
-PRIdMAX = "ld"
-PRIoMAX = "lo"
-PRIxMAX = "lx"
-PRIuMAX = "lu"
-PRIdMAX = "lld"
-PRIoMAX = "llo"
-PRIxMAX = "llx"
-PRIuMAX = "llu"
-PRIdMAX = "d"
-PRIoMAX = "o"
-PRIxMAX = "x"
-PRIuMAX = "u"
-SCNiMAX = "li"
-SCNdMAX = "ld"
-SCNoMAX = "lo"
-SCNxMAX = "lx"
-SCNiMAX = "lli"
-SCNdMAX = "lld"
-SCNoMAX = "llo"
-SCNxMAX = "llx"
-SCNiMAX = "i"
-SCNdMAX = "d"
-SCNoMAX = "o"
-SCNxMAX = "x"
-
-# Included from sys/types32.h
-SHRT_MIN = (-32768)
-SHRT_MAX = 32767
-USHRT_MAX = 65535
-INT_MIN = (-2147483647-1)
-INT_MAX = 2147483647
-LONG_MIN = (-9223372036854775807-1)
-LONG_MAX = 9223372036854775807
-LONG_MIN = (-2147483647-1)
-LONG_MAX = 2147483647
-P_MYID = (-1)
-
-# Included from sys/select.h
-
-# Included from sys/time.h
-TIME32_MAX = INT32_MAX
-TIME32_MIN = INT32_MIN
-def TIMEVAL_OVERFLOW(tv): return \
-
-from TYPES import *
-DST_NONE = 0
-DST_USA = 1
-DST_AUST = 2
-DST_WET = 3
-DST_MET = 4
-DST_EET = 5
-DST_CAN = 6
-DST_GB = 7
-DST_RUM = 8
-DST_TUR = 9
-DST_AUSTALT = 10
-ITIMER_REAL = 0
-ITIMER_VIRTUAL = 1
-ITIMER_PROF = 2
-ITIMER_REALPROF = 3
-def ITIMERVAL_OVERFLOW(itv): return \
-
-SEC = 1
-MILLISEC = 1000
-MICROSEC = 1000000
-NANOSEC = 1000000000
-
-# Included from sys/time_impl.h
-def TIMESPEC_OVERFLOW(ts): return \
-
-def ITIMERSPEC_OVERFLOW(it): return \
-
-__CLOCK_REALTIME0 = 0
-CLOCK_VIRTUAL = 1
-CLOCK_PROF = 2
-__CLOCK_REALTIME3 = 3
-CLOCK_HIGHRES = 4
-CLOCK_MAX = 5
-CLOCK_REALTIME = __CLOCK_REALTIME3
-CLOCK_REALTIME = __CLOCK_REALTIME0
-TIMER_RELTIME = 0x0
-TIMER_ABSTIME = 0x1
-
-# Included from sys/mutex.h
-from TYPES import *
-def MUTEX_HELD(x): return (mutex_owned(x))
-
-def TICK_TO_SEC(tick): return ((tick) / hz)
-
-def SEC_TO_TICK(sec): return ((sec) * hz)
-
-def TICK_TO_MSEC(tick): return \
-
-def MSEC_TO_TICK(msec): return \
-
-def MSEC_TO_TICK_ROUNDUP(msec): return \
-
-def TICK_TO_USEC(tick): return ((tick) * usec_per_tick)
-
-def USEC_TO_TICK(usec): return ((usec) / usec_per_tick)
-
-def USEC_TO_TICK_ROUNDUP(usec): return \
-
-def TICK_TO_NSEC(tick): return ((tick) * nsec_per_tick)
-
-def NSEC_TO_TICK(nsec): return ((nsec) / nsec_per_tick)
-
-def NSEC_TO_TICK_ROUNDUP(nsec): return \
-
-def TIMEVAL_TO_TICK(tvp): return \
-
-def TIMESTRUC_TO_TICK(tsp): return \
-
-
-# Included from time.h
-from TYPES import *
-
-# Included from iso/time_iso.h
-NULL = 0
-NULL = 0
-CLOCKS_PER_SEC = 1000000
-FD_SETSIZE = 65536
-FD_SETSIZE = 1024
-_NBBY = 8
-NBBY = _NBBY
-def FD_ZERO(p): return bzero((p), sizeof (*(p)))
diff --git a/Lib/plat-sunos5/regen b/Lib/plat-sunos5/regen
deleted file mode 100755
index 78cb7de..0000000
--- a/Lib/plat-sunos5/regen
+++ /dev/null
@@ -1,9 +0,0 @@
-#! /bin/sh
-case `uname -sr` in
-'SunOS 5.'*) ;;
-*) echo Probably not on a Solaris 2 system 1>&2
- exit 1;;
-esac
-set -v
-h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/sys/stropts.h /usr/include/dlfcn.h
-
diff --git a/Lib/plat-unixware7/IN.py b/Lib/plat-unixware7/IN.py
deleted file mode 100644
index af023b4..0000000
--- a/Lib/plat-unixware7/IN.py
+++ /dev/null
@@ -1,836 +0,0 @@
-# Generated by h2py from /usr/include/netinet/in.h
-
-# Included from netinet/in_f.h
-def IN_CLASSA(i): return (((int)(i) & 0x80000000) == 0)
-
-IN_CLASSA_NET = 0xff000000
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-def IN_CLASSB(i): return (((int)(i) & 0xc0000000) == 0x80000000)
-
-IN_CLASSB_NET = 0xffff0000
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-def IN_CLASSC(i): return (((int)(i) & 0xe0000000) == 0xc0000000)
-
-IN_CLASSC_NET = 0xffffff00
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-def IN_CLASSD(i): return (((int)(i) & 0xf0000000) == 0xe0000000)
-
-IN_CLASSD_NET = 0xf0000000
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-def IN_MULTICAST(i): return IN_CLASSD(i)
-
-def IN_EXPERIMENTAL(i): return (((int)(i) & 0xe0000000) == 0xe0000000)
-
-def IN_BADCLASS(i): return (((int)(i) & 0xf0000000) == 0xf0000000)
-
-INADDR_ANY = 0x00000000
-INADDR_LOOPBACK = 0x7f000001
-INADDR_BROADCAST = 0xffffffff
-INADDR_NONE = 0xffffffff
-IN_LOOPBACKNET = 127
-INADDR_UNSPEC_GROUP = 0xe0000000
-INADDR_ALLHOSTS_GROUP = 0xe0000001
-INADDR_ALLRTRS_GROUP = 0xe0000002
-INADDR_MAX_LOCAL_GROUP = 0xe00000ff
-
-# Included from netinet/in6.h
-
-# Included from sys/types.h
-def quad_low(x): return x.val[0]
-
-ADT_EMASKSIZE = 8
-SHRT_MIN = -32768
-SHRT_MAX = 32767
-INT_MIN = (-2147483647-1)
-INT_MAX = 2147483647
-LONG_MIN = (-2147483647-1)
-LONG_MAX = 2147483647
-OFF32_MAX = LONG_MAX
-ISTAT_ASSERTED = 0
-ISTAT_ASSUMED = 1
-ISTAT_NONE = 2
-OFF_MAX = OFF32_MAX
-CLOCK_MAX = LONG_MAX
-P_MYID = (-1)
-P_MYHOSTID = (-1)
-
-# Included from sys/select.h
-FD_SETSIZE = 4096
-NBBY = 8
-NULL = 0
-
-# Included from sys/bitypes.h
-
-# Included from netinet/in6_f.h
-def IN6_IS_ADDR_UNSPECIFIED(a): return IN6_ADDR_EQUAL_L(a, 0, 0, 0, 0)
-
-def IN6_SET_ADDR_UNSPECIFIED(a): return IN6_ADDR_COPY_L(a, 0, 0, 0, 0)
-
-def IN6_IS_ADDR_ANY(a): return IN6_ADDR_EQUAL_L(a, 0, 0, 0, 0)
-
-def IN6_SET_ADDR_ANY(a): return IN6_ADDR_COPY_L(a, 0, 0, 0, 0)
-
-def IN6_IS_ADDR_LOOPBACK(a): return IN6_ADDR_EQUAL_L(a, 0, 0, 0, 0x01000000)
-
-def IN6_SET_ADDR_LOOPBACK(a): return IN6_ADDR_COPY_L(a, 0, 0, 0, 0x01000000)
-
-IN6_MC_FLAG_PERMANENT = 0x0
-IN6_MC_FLAG_TRANSIENT = 0x1
-IN6_MC_SCOPE_NODELOCAL = 0x1
-IN6_MC_SCOPE_LINKLOCAL = 0x2
-IN6_MC_SCOPE_SITELOCAL = 0x5
-IN6_MC_SCOPE_ORGLOCAL = 0x8
-IN6_MC_SCOPE_GLOBAL = 0xE
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
-
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
-
-def IN6_IS_ADDR_MC_GLOBAL(a): return \
-
-
-# Included from sys/convsa.h
-__NETLIB_UW211_SVR4 = 1
-__NETLIB_UW211_XPG4 = 2
-__NETLIB_GEMINI_SVR4 = 3
-__NETLIB_GEMINI_XPG4 = 4
-__NETLIB_FP1_SVR4 = 5
-__NETLIB_FP1_XPG4 = 6
-__NETLIB_BASE_VERSION__ = __NETLIB_UW211_SVR4
-__NETLIB_VERSION__ = __NETLIB_FP1_SVR4
-__NETLIB_VERSION__ = __NETLIB_FP1_XPG4
-__NETLIB_VERSION__ = __NETLIB_GEMINI_SVR4
-__NETLIB_VERSION__ = __NETLIB_GEMINI_XPG4
-__NETLIB_VERSION__ = __NETLIB_UW211_SVR4
-__NETLIB_VERSION__ = __NETLIB_UW211_XPG4
-__NETLIB_VERSION__ = __NETLIB_FP1_XPG4
-
-# Included from sys/byteorder.h
-LITTLE_ENDIAN = 1234
-BIG_ENDIAN = 4321
-PDP_ENDIAN = 3412
-
-# Included from sys/byteorder_f.h
-BYTE_ORDER = LITTLE_ENDIAN
-def htonl(hl): return __htonl(hl)
-
-def ntohl(nl): return __ntohl(nl)
-
-def htons(hs): return __htons(hs)
-
-def ntohs(ns): return __ntohs(ns)
-
-def ntohl(x): return (x)
-
-def ntohs(x): return (x)
-
-def htonl(x): return (x)
-
-def htons(x): return (x)
-
-def __NETLIB_VERSION_IS_XPG4(version): return (((version) % 2) == 0)
-
-def __NETLIB_VERSION_HAS_SALEN(version): return ((version) >= __NETLIB_GEMINI_SVR4)
-
-def __NETLIB_VERSION_IS_IKS(version): return ((version) >= __NETLIB_FP1_SVR4)
-
-def SA_FAMILY_GET(sa): return \
-
-INET6_ADDRSTRLEN = 46
-IPV6_UNICAST_HOPS = 3
-IPV6_ADDRFORM = 24
-IPV6_MULTICAST_HOPS = 25
-IPV6_MULTICAST_IF = 26
-IPV6_MULTICAST_LOOP = 27
-IPV6_ADD_MEMBERSHIP = 28
-IPV6_DROP_MEMBERSHIP = 29
-
-# Included from sys/insrem.h
-def LIST_INIT(head): return \
-
-def LIST_INIT(head): return \
-
-def remque(a): return REMQUE(a)
-
-
-# Included from sys/socket.h
-
-# Included from sys/uio.h
-SHUT_RD = 0
-SHUT_WR = 1
-SHUT_RDWR = 2
-
-# Included from sys/netconfig.h
-
-# Included from sys/cdefs.h
-def __P(protos): return protos
-
-def __STRING(x): return #x
-
-def __P(protos): return ()
-
-def __STRING(x): return "x"
-
-NETCONFIG = "/etc/netconfig"
-NETPATH = "NETPATH"
-NC_TPI_CLTS = 1
-NC_TPI_COTS = 2
-NC_TPI_COTS_ORD = 3
-NC_TPI_RAW = 4
-NC_NOFLAG = 00
-NC_VISIBLE = 0o1
-NC_BROADCAST = 0o2
-NC_NOPROTOFMLY = "-"
-NC_LOOPBACK = "loopback"
-NC_INET = "inet"
-NC_INET6 = "inet6"
-NC_IMPLINK = "implink"
-NC_PUP = "pup"
-NC_CHAOS = "chaos"
-NC_NS = "ns"
-NC_NBS = "nbs"
-NC_ECMA = "ecma"
-NC_DATAKIT = "datakit"
-NC_CCITT = "ccitt"
-NC_SNA = "sna"
-NC_DECNET = "decnet"
-NC_DLI = "dli"
-NC_LAT = "lat"
-NC_HYLINK = "hylink"
-NC_APPLETALK = "appletalk"
-NC_NIT = "nit"
-NC_IEEE802 = "ieee802"
-NC_OSI = "osi"
-NC_X25 = "x25"
-NC_OSINET = "osinet"
-NC_GOSIP = "gosip"
-NC_NETWARE = "netware"
-NC_NOPROTO = "-"
-NC_TCP = "tcp"
-NC_UDP = "udp"
-NC_ICMP = "icmp"
-NC_IPX = "ipx"
-NC_SPX = "spx"
-NC_TPI_CLTS = 1
-NC_TPI_COTS = 2
-NC_TPI_COTS_ORD = 3
-NC_TPI_RAW = 4
-SOCK_STREAM = 2
-SOCK_DGRAM = 1
-SOCK_RAW = 4
-SOCK_RDM = 5
-SOCK_SEQPACKET = 6
-SO_DEBUG = 0x0001
-SO_ACCEPTCONN = 0x0002
-SO_REUSEADDR = 0x0004
-SO_KEEPALIVE = 0x0008
-SO_DONTROUTE = 0x0010
-SO_BROADCAST = 0x0020
-SO_USELOOPBACK = 0x0040
-SO_LINGER = 0x0080
-SO_OOBINLINE = 0x0100
-SO_ORDREL = 0x0200
-SO_IMASOCKET = 0x0400
-SO_MGMT = 0x0800
-SO_REUSEPORT = 0x1000
-SO_LISTENING = 0x2000
-SO_RDWR = 0x4000
-SO_SEMA = 0x8000
-SO_DONTLINGER = (~SO_LINGER)
-SO_SNDBUF = 0x1001
-SO_RCVBUF = 0x1002
-SO_SNDLOWAT = 0x1003
-SO_RCVLOWAT = 0x1004
-SO_SNDTIMEO = 0x1005
-SO_RCVTIMEO = 0x1006
-SO_ERROR = 0x1007
-SO_TYPE = 0x1008
-SO_PROTOTYPE = 0x1009
-SO_ALLRAW = 0x100a
-SOL_SOCKET = 0xffff
-AF_UNSPEC = 0
-AF_UNIX = 1
-AF_LOCAL = AF_UNIX
-AF_INET = 2
-AF_IMPLINK = 3
-AF_PUP = 4
-AF_CHAOS = 5
-AF_NS = 6
-AF_NBS = 7
-AF_ECMA = 8
-AF_DATAKIT = 9
-AF_CCITT = 10
-AF_SNA = 11
-AF_DECnet = 12
-AF_DLI = 13
-AF_LAT = 14
-AF_HYLINK = 15
-AF_APPLETALK = 16
-AF_NIT = 17
-AF_802 = 18
-AF_OSI = 19
-AF_ISO = AF_OSI
-AF_X25 = 20
-AF_OSINET = 21
-AF_GOSIP = 22
-AF_YNET = 23
-AF_ROUTE = 24
-AF_LINK = 25
-pseudo_AF_XTP = 26
-AF_INET6 = 27
-AF_MAX = 27
-AF_INET_BSWAP = 0x0200
-PF_UNSPEC = AF_UNSPEC
-PF_UNIX = AF_UNIX
-PF_LOCAL = AF_LOCAL
-PF_INET = AF_INET
-PF_IMPLINK = AF_IMPLINK
-PF_PUP = AF_PUP
-PF_CHAOS = AF_CHAOS
-PF_NS = AF_NS
-PF_NBS = AF_NBS
-PF_ECMA = AF_ECMA
-PF_DATAKIT = AF_DATAKIT
-PF_CCITT = AF_CCITT
-PF_SNA = AF_SNA
-PF_DECnet = AF_DECnet
-PF_DLI = AF_DLI
-PF_LAT = AF_LAT
-PF_HYLINK = AF_HYLINK
-PF_APPLETALK = AF_APPLETALK
-PF_NIT = AF_NIT
-PF_802 = AF_802
-PF_OSI = AF_OSI
-PF_ISO = PF_OSI
-PF_X25 = AF_X25
-PF_OSINET = AF_OSINET
-PF_GOSIP = AF_GOSIP
-PF_YNET = AF_YNET
-PF_ROUTE = AF_ROUTE
-PF_LINK = AF_LINK
-pseudo_PF_XTP = pseudo_AF_XTP
-PF_INET6 = AF_INET6
-PF_MAX = AF_MAX
-SOMAXCONN = 5
-SCM_RIGHTS = 1
-MSG_OOB = 0x1
-MSG_PEEK = 0x2
-MSG_DONTROUTE = 0x4
-MSG_CTRUNC = 0x8
-MSG_TRUNC = 0x10
-MSG_EOR = 0x30
-MSG_WAITALL = 0x20
-MSG_MAXIOVLEN = 16
-def OPTLEN(x): return ((((x) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
-
-GIARG = 0x1
-CONTI = 0x2
-GITAB = 0x4
-SOCKETSYS = 88
-SOCKETSYS = 83
-SO_ACCEPT = 1
-SO_BIND = 2
-SO_CONNECT = 3
-SO_GETPEERNAME = 4
-SO_GETSOCKNAME = 5
-SO_GETSOCKOPT = 6
-SO_LISTEN = 7
-SO_RECV = 8
-SO_RECVFROM = 9
-SO_SEND = 10
-SO_SENDTO = 11
-SO_SETSOCKOPT = 12
-SO_SHUTDOWN = 13
-SO_SOCKET = 14
-SO_SOCKPOLL = 15
-SO_GETIPDOMAIN = 16
-SO_SETIPDOMAIN = 17
-SO_ADJTIME = 18
-
-# Included from sys/stream.h
-
-# Included from sys/cred.h
-
-# Included from sys/ksynch.h
-
-# Included from sys/dl.h
-SIGNBIT = 0x80000000
-
-# Included from sys/ipl.h
-
-# Included from sys/disp_p.h
-
-# Included from sys/trap.h
-DIVERR = 0
-SGLSTP = 1
-NMIFLT = 2
-BPTFLT = 3
-INTOFLT = 4
-BOUNDFLT = 5
-INVOPFLT = 6
-NOEXTFLT = 7
-DBLFLT = 8
-EXTOVRFLT = 9
-INVTSSFLT = 10
-SEGNPFLT = 11
-STKFLT = 12
-GPFLT = 13
-PGFLT = 14
-EXTERRFLT = 16
-ALIGNFLT = 17
-MCEFLT = 18
-USERFLT = 0x100
-TRP_PREEMPT = 0x200
-TRP_UNUSED = 0x201
-PF_ERR_MASK = 0x01
-PF_ERR_PAGE = 0
-PF_ERR_PROT = 1
-PF_ERR_WRITE = 2
-PF_ERR_USER = 4
-EVT_STRSCHED = 0x04
-EVT_GLOBCALLOUT = 0x08
-EVT_LCLCALLOUT = 0x10
-EVT_SOFTINTMASK = (EVT_STRSCHED|EVT_GLOBCALLOUT|EVT_LCLCALLOUT)
-PL0 = 0
-PL1 = 1
-PL2 = 2
-PL3 = 3
-PL4 = 4
-PL5 = 5
-PL6 = 6
-PLHI = 8
-PL7 = PLHI
-PLBASE = PL0
-PLTIMEOUT = PL1
-PLDISK = PL5
-PLSTR = PL6
-PLTTY = PLSTR
-PLMIN = PL0
-PLMIN = PL1
-MAX_INTR_LEVELS = 10
-MAX_INTR_NESTING = 50
-STRSCHED = EVT_STRSCHED
-GLOBALSOFTINT = EVT_GLOBCALLOUT
-LOCALSOFTINT = EVT_LCLCALLOUT
-
-# Included from sys/ksynch_p.h
-def GET_TIME(timep): return \
-
-LK_THRESHOLD = 500000
-
-# Included from sys/list.h
-
-# Included from sys/listasm.h
-def remque_null(e): return \
-
-def LS_ISEMPTY(listp): return \
-
-LK_BASIC = 0x1
-LK_SLEEP = 0x2
-LK_NOSTATS = 0x4
-def CYCLES_SINCE(c): return CYCLES_BETWEEN((c), CYCLES())
-
-LSB_NLKDS = 92
-EVT_RUNRUN = 0x01
-EVT_KPRUNRUN = 0x02
-SP_UNLOCKED = 0
-SP_LOCKED = 1
-KS_LOCKTEST = 0x01
-KS_MPSTATS = 0x02
-KS_DEINITED = 0x04
-KS_NVLTTRACE = 0x08
-RWS_READ = (ord('r'))
-RWS_WRITE = (ord('w'))
-RWS_UNLOCKED = (ord('u'))
-RWS_BUSY = (ord('b'))
-def SLEEP_LOCKOWNED(lkp): return \
-
-def SLEEP_DISOWN(lkp): return \
-
-KS_NOPRMPT = 0x00000001
-__KS_LOCKTEST = KS_LOCKTEST
-__KS_LOCKTEST = 0
-__KS_MPSTATS = KS_MPSTATS
-__KS_MPSTATS = 0
-__KS_NVLTTRACE = KS_NVLTTRACE
-__KS_NVLTTRACE = 0
-KSFLAGS = (__KS_LOCKTEST|__KS_MPSTATS|__KS_NVLTTRACE)
-KSVUNIPROC = 1
-KSVMPDEBUG = 2
-KSVMPNODEBUG = 3
-KSVFLAG = KSVUNIPROC
-KSVFLAG = KSVMPDEBUG
-KSVFLAG = KSVMPNODEBUG
-
-# Included from sys/ksinline.h
-_A_SP_LOCKED = 1
-_A_SP_UNLOCKED = 0
-_A_INVPL = -1
-def _ATOMIC_INT_INCR(atomic_intp): return \
-
-def _ATOMIC_INT_DECR(atomic_intp): return \
-
-def ATOMIC_INT_READ(atomic_intp): return _ATOMIC_INT_READ(atomic_intp)
-
-def ATOMIC_INT_INCR(atomic_intp): return _ATOMIC_INT_INCR(atomic_intp)
-
-def ATOMIC_INT_DECR(atomic_intp): return _ATOMIC_INT_DECR(atomic_intp)
-
-def FSPIN_INIT(lp): return
-
-def FSPIN_LOCK(l): return DISABLE()
-
-def FSPIN_TRYLOCK(l): return (DISABLE(), B_TRUE)
-
-def FSPIN_UNLOCK(l): return ENABLE()
-
-def LOCK_DEINIT(lp): return
-
-def LOCK_DEALLOC(lp): return
-
-def LOCK_OWNED(lp): return (B_TRUE)
-
-def RW_DEINIT(lp): return
-
-def RW_DEALLOC(lp): return
-
-def RW_OWNED(lp): return (B_TRUE)
-
-def IS_LOCKED(lockp): return B_FALSE
-
-def LOCK_PLMIN(lockp): return \
-
-def TRYLOCK_PLMIN(lockp): return LOCK_PLMIN(lockp)
-
-def LOCK_SH_PLMIN(lockp): return LOCK_PLMIN(lockp)
-
-def RW_RDLOCK_PLMIN(lockp): return LOCK_PLMIN(lockp)
-
-def RW_WRLOCK_PLMIN(lockp): return LOCK_PLMIN(lockp)
-
-def LOCK_DEINIT(l): return
-
-def LOCK_PLMIN(lockp): return LOCK((lockp), PLMIN)
-
-def TRYLOCK_PLMIN(lockp): return TRYLOCK((lockp), PLMIN)
-
-def LOCK_SH_PLMIN(lockp): return LOCK_SH((lockp), PLMIN)
-
-def RW_RDLOCK_PLMIN(lockp): return RW_RDLOCK((lockp), PLMIN)
-
-def RW_WRLOCK_PLMIN(lockp): return RW_WRLOCK((lockp), PLMIN)
-
-def FSPIN_IS_LOCKED(fsp): return B_FALSE
-
-def SPIN_IS_LOCKED(lockp): return B_FALSE
-
-def FSPIN_OWNED(l): return (B_TRUE)
-
-CR_MLDREAL = 0x00000001
-CR_RDUMP = 0x00000002
-def crhold(credp): return crholdn((credp), 1)
-
-def crfree(credp): return crfreen((credp), 1)
-
-
-# Included from sys/strmdep.h
-def str_aligned(X): return (((uint)(X) & (sizeof(int) - 1)) == 0)
-
-
-# Included from sys/engine.h
-
-# Included from sys/clock.h
-
-# Included from sys/time.h
-DST_NONE = 0
-DST_USA = 1
-DST_AUST = 2
-DST_WET = 3
-DST_MET = 4
-DST_EET = 5
-DST_CAN = 6
-DST_GB = 7
-DST_RUM = 8
-DST_TUR = 9
-DST_AUSTALT = 10
-ITIMER_REAL = 0
-ITIMER_VIRTUAL = 1
-ITIMER_PROF = 2
-FD_SETSIZE = 4096
-FD_NBBY = 8
-
-# Included from time.h
-NULL = 0
-CLOCKS_PER_SEC = 1000000
-
-# Included from sys/clock_p.h
-CGBITS = 4
-IDBITS = 28
-def toid_unpackcg(idval): return (((idval) >> IDBITS) & 0xf)
-
-def toid_unpackid(idval): return ((idval) & 0xfffffff)
-
-def toid_unpackcg(idval): return 0
-
-def toid_unpackid(idval): return (idval)
-
-NCALLOUT_HASH = 1024
-CALLOUT_MAXVAL = 0x7fffffff
-TO_PERIODIC = 0x80000000
-TO_IMMEDIATE = 0x80000000
-SEC = 1
-MILLISEC = 1000
-MICROSEC = 1000000
-NANOSEC = 1000000000
-SECHR = (60*60)
-SECDAY = (24*SECHR)
-SECYR = (365*SECDAY)
-def TIME_OWNED_R(cgnum): return (B_TRUE)
-
-LOOPSECONDS = 1800
-LOOPMICROSECONDS = (LOOPSECONDS * MICROSEC)
-def TICKS_SINCE(t): return TICKS_BETWEEN(t, TICKS())
-
-MAXRQS = 2
-E_OFFLINE = 0x01
-E_BAD = 0x02
-E_SHUTDOWN = 0x04
-E_DRIVER = 0x08
-E_DEFAULTKEEP = 0x100
-E_DRIVERBOUND = 0x200
-E_EXCLUSIVE = 0x400
-E_CGLEADER = 0x800
-E_NOWAY = (E_OFFLINE|E_BAD|E_SHUTDOWN)
-E_BOUND = 0x01
-E_GLOBAL = 0x00
-E_UNAVAIL = -1
-ENGINE_ONLINE = 1
-def PROCESSOR_UNMAP(e): return ((e) - engine)
-
-BOOTENG = 0
-QMOVED = 0x0001
-QWANTR = 0x0002
-QWANTW = 0x0004
-QFULL = 0x0008
-QREADR = 0x0010
-QUSE = 0x0020
-QNOENB = 0x0040
-QUP = 0x0080
-QBACK = 0x0100
-QINTER = 0x0200
-QPROCSON = 0x0400
-QTOENAB = 0x0800
-QFREEZE = 0x1000
-QBOUND = 0x2000
-QDEFCNT = 0x4000
-QENAB = 0x0001
-QSVCBUSY = 0x0002
-STRM_PUTCNT_TABLES = 31
-def STRM_MYENG_PUTCNT(sdp): return STRM_PUTCNT(l.eng_num, sdp)
-
-QB_FULL = 0x01
-QB_WANTW = 0x02
-QB_BACK = 0x04
-NBAND = 256
-DB_WASDUPED = 0x1
-DB_2PIECE = 0x2
-STRLEAKHASHSZ = 1021
-MSGMARK = 0x01
-MSGNOLOOP = 0x02
-MSGDELIM = 0x04
-MSGNOGET = 0x08
-MSGLOG = 0x10
-M_DATA = 0x00
-M_PROTO = 0x01
-M_BREAK = 0x08
-M_PASSFP = 0x09
-M_SIG = 0x0b
-M_DELAY = 0x0c
-M_CTL = 0x0d
-M_IOCTL = 0x0e
-M_SETOPTS = 0x10
-M_RSE = 0x11
-M_TRAIL = 0x12
-M_IOCACK = 0x81
-M_IOCNAK = 0x82
-M_PCPROTO = 0x83
-M_PCSIG = 0x84
-M_READ = 0x85
-M_FLUSH = 0x86
-M_STOP = 0x87
-M_START = 0x88
-M_HANGUP = 0x89
-M_ERROR = 0x8a
-M_COPYIN = 0x8b
-M_COPYOUT = 0x8c
-M_IOCDATA = 0x8d
-M_PCRSE = 0x8e
-M_STOPI = 0x8f
-M_STARTI = 0x90
-M_PCCTL = 0x91
-M_PCSETOPTS = 0x92
-QNORM = 0x00
-QPCTL = 0x80
-STRCANON = 0x01
-RECOPY = 0x02
-SO_ALL = 0x003f
-SO_READOPT = 0x0001
-SO_WROFF = 0x0002
-SO_MINPSZ = 0x0004
-SO_MAXPSZ = 0x0008
-SO_HIWAT = 0x0010
-SO_LOWAT = 0x0020
-SO_MREADON = 0x0040
-SO_MREADOFF = 0x0080
-SO_NDELON = 0x0100
-SO_NDELOFF = 0x0200
-SO_ISTTY = 0x0400
-SO_ISNTTY = 0x0800
-SO_TOSTOP = 0x1000
-SO_TONSTOP = 0x2000
-SO_BAND = 0x4000
-SO_DELIM = 0x8000
-SO_NODELIM = 0x010000
-SO_STRHOLD = 0x020000
-SO_LOOP = 0x040000
-DRVOPEN = 0x0
-MODOPEN = 0x1
-CLONEOPEN = 0x2
-OPENFAIL = -1
-BPRI_LO = 1
-BPRI_MED = 2
-BPRI_HI = 3
-INFPSZ = -1
-FLUSHALL = 1
-FLUSHDATA = 0
-STRHIGH = 5120
-STRLOW = 1024
-MAXIOCBSZ = 1024
-def straln(a): return (caddr_t)((int)(a) & ~(sizeof(int)-1))
-
-IPM_ID = 200
-ICMPM_ID = 201
-TCPM_ID = 202
-UDPM_ID = 203
-ARPM_ID = 204
-APPM_ID = 205
-RIPM_ID = 206
-PPPM_ID = 207
-AHDLCM_ID = 208
-MHDLCRIPM_ID = 209
-HDLCM_ID = 210
-PPCID_ID = 211
-IGMPM_ID = 212
-IPIPM_ID = 213
-IPPROTO_IP = 0
-IPPROTO_HOPOPTS = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_IPIP = 4
-IPPROTO_TCP = 6
-IPPROTO_EGP = 8
-IPPROTO_PUP = 12
-IPPROTO_UDP = 17
-IPPROTO_IDP = 22
-IPPROTO_TP = 29
-IPPROTO_IPV6 = 41
-IPPROTO_ROUTING = 43
-IPPROTO_FRAGMENT = 44
-IPPROTO_ESP = 50
-IPPROTO_AH = 51
-IPPROTO_ICMPV6 = 58
-IPPROTO_NONE = 59
-IPPROTO_DSTOPTS = 60
-IPPROTO_HELLO = 63
-IPPROTO_ND = 77
-IPPROTO_EON = 80
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPORT_ECHO = 7
-IPPORT_DISCARD = 9
-IPPORT_SYSTAT = 11
-IPPORT_DAYTIME = 13
-IPPORT_NETSTAT = 15
-IPPORT_FTP = 21
-IPPORT_TELNET = 23
-IPPORT_SMTP = 25
-IPPORT_TIMESERVER = 37
-IPPORT_NAMESERVER = 42
-IPPORT_WHOIS = 43
-IPPORT_MTP = 57
-IPPORT_TFTP = 69
-IPPORT_RJE = 77
-IPPORT_FINGER = 79
-IPPORT_TTYLINK = 87
-IPPORT_SUPDUP = 95
-IPPORT_EXECSERVER = 512
-IPPORT_LOGINSERVER = 513
-IPPORT_CMDSERVER = 514
-IPPORT_EFSSERVER = 520
-IPPORT_BIFFUDP = 512
-IPPORT_WHOSERVER = 513
-IPPORT_ROUTESERVER = 520
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 65535
-IPPORT_RESERVED_LOW = 512
-IPPORT_RESERVED_HIGH = 1023
-IPPORT_USERRESERVED_LOW = 32768
-IPPORT_USERRESERVED_HIGH = 65535
-INET_ADDRSTRLEN = 16
-IP_OPTIONS = 1
-IP_TOS = 2
-IP_TTL = 3
-IP_HDRINCL = 4
-IP_RECVOPTS = 5
-IP_RECVRETOPTS = 6
-IP_RECVDSTADDR = 7
-IP_RETOPTS = 8
-IP_MULTICAST_IF = 9
-IP_MULTICAST_LOOP = 10
-IP_ADD_MEMBERSHIP = 11
-IP_DROP_MEMBERSHIP = 12
-IP_BROADCAST_IF = 14
-IP_RECVIFINDEX = 15
-IP_MULTICAST_TTL = 16
-MRT_INIT = 17
-MRT_DONE = 18
-MRT_ADD_VIF = 19
-MRT_DEL_VIF = 20
-MRT_ADD_MFC = 21
-MRT_DEL_MFC = 22
-MRT_VERSION = 23
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20
-INADDR_UNSPEC_GROUP = 0xe0000000
-INADDR_ALLHOSTS_GROUP = 0xe0000001
-INADDR_ALLRTRS_GROUP = 0xe0000002
-INADDR_MAX_LOCAL_GROUP = 0xe00000ff
-
-# Included from netinet/in_mp.h
-
-# Included from netinet/in_mp_ddi.h
-
-# Included from sys/inline.h
-IP_HIER_BASE = (20)
-def ASSERT_LOCK(x): return
-
-def ASSERT_WRLOCK(x): return
-
-def ASSERT_UNLOCK(x): return
-
-def CANPUT(q): return canput((q))
-
-def CANPUTNEXT(q): return canputnext((q))
-
-INET_DEBUG = 1
diff --git a/Lib/plat-unixware7/STROPTS.py b/Lib/plat-unixware7/STROPTS.py
deleted file mode 100644
index ef50a9c..0000000
--- a/Lib/plat-unixware7/STROPTS.py
+++ /dev/null
@@ -1,328 +0,0 @@
-# Generated by h2py from /usr/include/sys/stropts.h
-
-# Included from sys/types.h
-def quad_low(x): return x.val[0]
-
-ADT_EMASKSIZE = 8
-SHRT_MIN = -32768
-SHRT_MAX = 32767
-INT_MIN = (-2147483647-1)
-INT_MAX = 2147483647
-LONG_MIN = (-2147483647-1)
-LONG_MAX = 2147483647
-OFF32_MAX = LONG_MAX
-ISTAT_ASSERTED = 0
-ISTAT_ASSUMED = 1
-ISTAT_NONE = 2
-OFF_MAX = OFF32_MAX
-CLOCK_MAX = LONG_MAX
-P_MYID = (-1)
-P_MYHOSTID = (-1)
-
-# Included from sys/select.h
-FD_SETSIZE = 4096
-NBBY = 8
-NULL = 0
-
-# Included from sys/conf.h
-D_NEW = 0x00
-D_OLD = 0x01
-D_DMA = 0x02
-D_BLKOFF = 0x400
-D_LFS = 0x8000
-D_STR = 0x0800
-D_MOD = 0x1000
-D_PSEUDO = 0x2000
-D_RANDOM = 0x4000
-D_HOT = 0x10000
-D_SEEKNEG = 0x04
-D_TAPE = 0x08
-D_NOBRKUP = 0x10
-D_INITPUB = 0x20
-D_NOSPECMACDATA = 0x40
-D_RDWEQ = 0x80
-SECMASK = (D_INITPUB|D_NOSPECMACDATA|D_RDWEQ)
-DAF_REQDMA = 0x1
-DAF_PHYSREQ = 0x2
-DAF_PRE8 = 0x4
-DAF_STATIC = 0x8
-DAF_STR = 0x10
-D_MP = 0x100
-D_UPF = 0x200
-ROOTFS_NAMESZ = 7
-FMNAMESZ = 8
-MCD_VERSION = 1
-DI_BCBP = 0
-DI_MEDIA = 1
-
-# Included from sys/secsys.h
-ES_MACOPENLID = 1
-ES_MACSYSLID = 2
-ES_MACROOTLID = 3
-ES_PRVINFO = 4
-ES_PRVSETCNT = 5
-ES_PRVSETS = 6
-ES_MACADTLID = 7
-ES_PRVID = 8
-ES_TPGETMAJOR = 9
-SA_EXEC = 0o01
-SA_WRITE = 0o02
-SA_READ = 0o04
-SA_SUBSIZE = 0o10
-
-# Included from sys/stropts_f.h
-X_STR = (ord('S')<<8)
-X_I_BASE = (X_STR|0o200)
-X_I_NREAD = (X_STR|0o201)
-X_I_PUSH = (X_STR|0o202)
-X_I_POP = (X_STR|0o203)
-X_I_LOOK = (X_STR|0o204)
-X_I_FLUSH = (X_STR|0o205)
-X_I_SRDOPT = (X_STR|0o206)
-X_I_GRDOPT = (X_STR|0o207)
-X_I_STR = (X_STR|0o210)
-X_I_SETSIG = (X_STR|0o211)
-X_I_GETSIG = (X_STR|0o212)
-X_I_FIND = (X_STR|0o213)
-X_I_LINK = (X_STR|0o214)
-X_I_UNLINK = (X_STR|0o215)
-X_I_PEEK = (X_STR|0o217)
-X_I_FDINSERT = (X_STR|0o220)
-X_I_SENDFD = (X_STR|0o221)
-X_I_RECVFD = (X_STR|0o222)
-
-# Included from unistd.h
-
-# Included from sys/unistd.h
-R_OK = 0o04
-W_OK = 0o02
-X_OK = 0o01
-F_OK = 000
-EFF_ONLY_OK = 0o10
-EX_OK = 0o20
-SEEK_SET = 0
-SEEK_CUR = 1
-SEEK_END = 2
-_SC_ARG_MAX = 1
-_SC_CHILD_MAX = 2
-_SC_CLK_TCK = 3
-_SC_NGROUPS_MAX = 4
-_SC_OPEN_MAX = 5
-_SC_JOB_CONTROL = 6
-_SC_SAVED_IDS = 7
-_SC_VERSION = 8
-_SC_PASS_MAX = 9
-_SC_LOGNAME_MAX = 10
-_SC_PAGESIZE = 11
-_SC_PAGE_SIZE = _SC_PAGESIZE
-_SC_XOPEN_VERSION = 12
-_SC_NACLS_MAX = 13
-_SC_NPROCESSORS_CONF = 14
-_SC_NPROCESSORS_ONLN = 15
-_SC_NPROCESSES = 39
-_SC_TOTAL_MEMORY = 40
-_SC_USEABLE_MEMORY = 41
-_SC_GENERAL_MEMORY = 42
-_SC_DEDICATED_MEMORY = 43
-_SC_NCGS_CONF = 44
-_SC_NCGS_ONLN = 45
-_SC_MAX_CPUS_PER_CG = 46
-_SC_CG_SIMPLE_IMPL = 47
-_SC_CACHE_LINE = 48
-_SC_SYSTEM_ID = 49
-_SC_THREADS = 51
-_SC_THREAD_ATTR_STACKADDR = 52
-_SC_THREAD_ATTR_STACKSIZE = 53
-_SC_THREAD_DESTRUCTOR_ITERATIONS = 54
-_SC_THREAD_KEYS_MAX = 55
-_SC_THREAD_PRIORITY_SCHEDULING = 56
-_SC_THREAD_PRIO_INHERIT = 57
-_SC_THREAD_PRIO_PROTECT = 58
-_SC_THREAD_STACK_MIN = 59
-_SC_THREAD_PROCESS_SHARED = 60
-_SC_THREAD_SAFE_FUNCTIONS = 61
-_SC_THREAD_THREADS_MAX = 62
-_SC_KERNEL_VM = 63
-_SC_TZNAME_MAX = 320
-_SC_STREAM_MAX = 321
-_SC_XOPEN_CRYPT = 323
-_SC_XOPEN_ENH_I18N = 324
-_SC_XOPEN_SHM = 325
-_SC_XOPEN_XCU_VERSION = 327
-_SC_AES_OS_VERSION = 330
-_SC_ATEXIT_MAX = 331
-_SC_2_C_BIND = 350
-_SC_2_C_DEV = 351
-_SC_2_C_VERSION = 352
-_SC_2_CHAR_TERM = 353
-_SC_2_FORT_DEV = 354
-_SC_2_FORT_RUN = 355
-_SC_2_LOCALEDEF = 356
-_SC_2_SW_DEV = 357
-_SC_2_UPE = 358
-_SC_2_VERSION = 359
-_SC_BC_BASE_MAX = 370
-_SC_BC_DIM_MAX = 371
-_SC_BC_SCALE_MAX = 372
-_SC_BC_STRING_MAX = 373
-_SC_COLL_WEIGHTS_MAX = 380
-_SC_EXPR_NEST_MAX = 381
-_SC_LINE_MAX = 382
-_SC_RE_DUP_MAX = 383
-_SC_IOV_MAX = 390
-_SC_NPROC_CONF = 391
-_SC_NPROC_ONLN = 392
-_SC_XOPEN_UNIX = 400
-_SC_SEMAPHORES = 440
-_CS_PATH = 1
-__O_CS_HOSTNAME = 2
-_CS_RELEASE = 3
-_CS_VERSION = 4
-__O_CS_MACHINE = 5
-__O_CS_ARCHITECTURE = 6
-_CS_HW_SERIAL = 7
-__O_CS_HW_PROVIDER = 8
-_CS_SRPC_DOMAIN = 9
-_CS_INITTAB_NAME = 10
-__O_CS_SYSNAME = 11
-_CS_LFS_CFLAGS = 20
-_CS_LFS_LDFLAGS = 21
-_CS_LFS_LIBS = 22
-_CS_LFS_LINTFLAGS = 23
-_CS_LFS64_CFLAGS = 24
-_CS_LFS64_LDFLAGS = 25
-_CS_LFS64_LIBS = 26
-_CS_LFS64_LINTFLAGS = 27
-_CS_ARCHITECTURE = 100
-_CS_BUSTYPES = 101
-_CS_HOSTNAME = 102
-_CS_HW_PROVIDER = 103
-_CS_KERNEL_STAMP = 104
-_CS_MACHINE = 105
-_CS_OS_BASE = 106
-_CS_OS_PROVIDER = 107
-_CS_SYSNAME = 108
-_CS_USER_LIMIT = 109
-_PC_LINK_MAX = 1
-_PC_MAX_CANON = 2
-_PC_MAX_INPUT = 3
-_PC_NAME_MAX = 4
-_PC_PATH_MAX = 5
-_PC_PIPE_BUF = 6
-_PC_NO_TRUNC = 7
-_PC_VDISABLE = 8
-_PC_CHOWN_RESTRICTED = 9
-_PC_FILESIZEBITS = 10
-_POSIX_VERSION = 199009
-_XOPEN_VERSION = 4
-GF_PATH = "/etc/group"
-PF_PATH = "/etc/passwd"
-F_ULOCK = 0
-F_LOCK = 1
-F_TLOCK = 2
-F_TEST = 3
-_POSIX_JOB_CONTROL = 1
-_POSIX_SAVED_IDS = 1
-_POSIX_VDISABLE = 0
-NULL = 0
-STDIN_FILENO = 0
-STDOUT_FILENO = 1
-STDERR_FILENO = 2
-_XOPEN_UNIX = 1
-_XOPEN_ENH_I18N = 1
-_XOPEN_XPG4 = 1
-_POSIX2_C_VERSION = 199209
-_POSIX2_VERSION = 199209
-_XOPEN_XCU_VERSION = 4
-_POSIX_SEMAPHORES = 1
-_POSIX_THREADS = 1
-_POSIX_THREAD_ATTR_STACKADDR = 1
-_POSIX_THREAD_ATTR_STACKSIZE = 1
-_POSIX_THREAD_PRIORITY_SCHEDULING = 1
-_POSIX_THREAD_PROCESS_SHARED = 1
-_POSIX_THREAD_SAFE_FUNCTIONS = 1
-_POSIX2_C_BIND = 1
-_POSIX2_CHAR_TERM = 1
-_POSIX2_FORT_RUN = 1
-_POSIX2_LOCALEDEF = 1
-_POSIX2_UPE = 1
-_LFS_ASYNCHRONOUS_IO = 1
-_LFS_LARGEFILE = 1
-_LFS64_ASYNCHRONOUS_IO = 1
-_LFS64_LARGEFILE = 1
-_LFS64_STDIO = 1
-FMNAMESZ = 8
-SNDZERO = 0x001
-SNDPIPE = 0x002
-RNORM = 0x000
-RMSGD = 0x001
-RMSGN = 0x002
-RMODEMASK = 0x003
-RPROTDAT = 0x004
-RPROTDIS = 0x008
-RPROTNORM = 0x010
-RPROTMASK = 0x01c
-FLUSHR = 0x01
-FLUSHW = 0x02
-FLUSHRW = 0x03
-FLUSHBAND = 0x04
-S_INPUT = 0x0001
-S_HIPRI = 0x0002
-S_OUTPUT = 0x0004
-S_MSG = 0x0008
-S_ERROR = 0x0010
-S_HANGUP = 0x0020
-S_RDNORM = 0x0040
-S_WRNORM = S_OUTPUT
-S_RDBAND = 0x0080
-S_WRBAND = 0x0100
-S_BANDURG = 0x0200
-RS_HIPRI = 0x01
-MSG_HIPRI = 0x01
-MSG_ANY = 0x02
-MSG_BAND = 0x04
-MSG_DISCARD = 0x08
-MSG_PEEKIOCTL = 0x10
-MORECTL = 1
-MOREDATA = 2
-MUXID_ALL = (-1)
-ANYMARK = 0x01
-LASTMARK = 0x02
-STR = (ord('S')<<8)
-I_NREAD = (STR|0o1)
-I_PUSH = (STR|0o2)
-I_POP = (STR|0o3)
-I_LOOK = (STR|0o4)
-I_FLUSH = (STR|0o5)
-I_SRDOPT = (STR|0o6)
-I_GRDOPT = (STR|0o7)
-I_STR = (STR|0o10)
-I_SETSIG = (STR|0o11)
-I_GETSIG = (STR|0o12)
-I_FIND = (STR|0o13)
-I_LINK = (STR|0o14)
-I_UNLINK = (STR|0o15)
-I_PEEK = (STR|0o17)
-I_FDINSERT = (STR|0o20)
-I_SENDFD = (STR|0o21)
-I_RECVFD = (STR|0o22)
-I_E_RECVFD = (STR|0o16)
-I_RECVFD = (STR|0o16)
-I_RECVFD = (STR|0o22)
-I_SWROPT = (STR|0o23)
-I_GWROPT = (STR|0o24)
-I_LIST = (STR|0o25)
-I_PLINK = (STR|0o26)
-I_PUNLINK = (STR|0o27)
-I_FLUSHBAND = (STR|0o34)
-I_CKBAND = (STR|0o35)
-I_GETBAND = (STR|0o36)
-I_ATMARK = (STR|0o37)
-I_SETCLTIME = (STR|0o40)
-I_GETCLTIME = (STR|0o41)
-I_CANPUT = (STR|0o42)
-I_S_RECVFD = (STR|0o43)
-I_STATS = (STR|0o44)
-I_BIGPIPE = (STR|0o45)
-I_GETTP = (STR|0o46)
-INFTIM = -1
diff --git a/Lib/plat-unixware7/regen b/Lib/plat-unixware7/regen
deleted file mode 100755
index 68998a7..0000000
--- a/Lib/plat-unixware7/regen
+++ /dev/null
@@ -1,9 +0,0 @@
-#! /bin/sh
-case `uname -sr` in
-UnixWare*) ;;
-*) echo Probably not on a UnixWare system 1>&2
- exit 1;;
-esac
-set -v
-h2py -i '(u_long)' /usr/include/netinet/in.h
-h2py /usr/include/sys/stropts.h
diff --git a/Lib/platform.py b/Lib/platform.py
index 3e726a7..e48ad0b 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -13,7 +13,6 @@
# Python bug tracker (http://bugs.python.org) and assign them to "lemburg".
#
# Still needed:
-# * more support for WinCE
# * support for MS-DOS (PythonDX ?)
# * support for Amiga and other still unsupported platforms running Python
# * support for additional Linux distributions
@@ -252,13 +251,13 @@ def _dist_try_harder(distname, version, id):
_release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII)
_lsb_release_version = re.compile(r'(.+)'
- ' release '
- '([\d.]+)'
- '[^(]*(?:\((.+)\))?', re.ASCII)
+ r' release '
+ r'([\d.]+)'
+ r'[^(]*(?:\((.+)\))?', re.ASCII)
_release_version = re.compile(r'([^0-9]+)'
- '(?: release )?'
- '([\d.]+)'
- '[^(]*(?:\((.+)\))?', re.ASCII)
+ r'(?: release )?'
+ r'([\d.]+)'
+ r'[^(]*(?:\((.+)\))?', re.ASCII)
# See also http://www.novell.com/coolsolutions/feature/11251.html
# and http://linuxmafia.com/faq/Admin/release-files.html
@@ -408,8 +407,8 @@ def _norm_version(version, build=''):
return version
_ver_output = re.compile(r'(?:([\w ]+) ([\w.]+) '
- '.*'
- '\[.* ([\d.]+)\])')
+ r'.*'
+ r'\[.* ([\d.]+)\])')
# Examples of VER command output:
#
@@ -509,7 +508,7 @@ def win32_ver(release='', version='', csd='', ptype=''):
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
winver = getwindowsversion()
- maj, min, build = winver._platform_version or winver[:3]
+ maj, min, build = winver.platform_version or winver[:3]
version = '{0}.{1}.{2}'.format(maj, min, build)
release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or
@@ -1095,22 +1094,22 @@ _sys_version_parser = re.compile(
_ironpython_sys_version_parser = re.compile(
r'IronPython\s*'
- '([\d\.]+)'
- '(?: \(([\d\.]+)\))?'
- ' on (.NET [\d\.]+)', re.ASCII)
+ r'([\d\.]+)'
+ r'(?: \(([\d\.]+)\))?'
+ r' on (.NET [\d\.]+)', re.ASCII)
# IronPython covering 2.6 and 2.7
_ironpython26_sys_version_parser = re.compile(
r'([\d.]+)\s*'
- '\(IronPython\s*'
- '[\d.]+\s*'
- '\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)'
+ r'\(IronPython\s*'
+ r'[\d.]+\s*'
+ r'\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)'
)
_pypy_sys_version_parser = re.compile(
r'([\w.+]+)\s*'
- '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
- '\[PyPy [^\]]+\]?')
+ r'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
+ r'\[PyPy [^\]]+\]?')
_sys_version_cache = {}
@@ -1345,7 +1344,7 @@ def platform(aliased=0, terse=0):
# see issue #1322 for more information
warnings.filterwarnings(
'ignore',
- 'dist\(\) and linux_distribution\(\) '
+ r'dist\(\) and linux_distribution\(\) '
'functions are deprecated .*',
PendingDeprecationWarning,
)
diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index 2502b39..09be5fd 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -47,7 +47,7 @@ Parse Plist example:
"""
__all__ = [
"readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes",
- "Plist", "Data", "Dict", "FMT_XML", "FMT_BINARY",
+ "Plist", "Data", "Dict", "InvalidFileException", "FMT_XML", "FMT_BINARY",
"load", "dump", "loads", "dumps"
]
diff --git a/Lib/poplib.py b/Lib/poplib.py
index f672390..cae6950 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -431,6 +431,10 @@ if HAVE_SSL:
if context is not None and certfile is not None:
raise ValueError("context and certfile arguments are mutually "
"exclusive")
+ if keyfile is not None or certfile is not None:
+ import warnings
+ warnings.warn("keyfile and certfile are deprecated, use a"
+ "custom context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
if context is None:
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index d9f3f99..6dbdab2 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -49,6 +49,7 @@ def _get_sep(path):
def normcase(s):
"""Normalize case of pathname. Has no effect under Posix"""
+ s = os.fspath(s)
if not isinstance(s, (bytes, str)):
raise TypeError("normcase() argument must be str or bytes, "
"not '{}'".format(s.__class__.__name__))
@@ -60,6 +61,7 @@ def normcase(s):
def isabs(s):
"""Test whether a path is absolute"""
+ s = os.fspath(s)
sep = _get_sep(s)
return s.startswith(sep)
@@ -73,12 +75,13 @@ def join(a, *p):
If any component is an absolute path, all previous path components
will be discarded. An empty last part will result in a path that
ends with a separator."""
+ a = os.fspath(a)
sep = _get_sep(a)
path = a
try:
if not p:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
- for b in p:
+ for b in map(os.fspath, p):
if b.startswith(sep):
path = b
elif not path or path.endswith(sep):
@@ -99,6 +102,7 @@ def join(a, *p):
def split(p):
"""Split a pathname. Returns tuple "(head, tail)" where "tail" is
everything after the final slash. Either part may be empty."""
+ p = os.fspath(p)
sep = _get_sep(p)
i = p.rfind(sep) + 1
head, tail = p[:i], p[i:]
@@ -113,6 +117,7 @@ def split(p):
# It is always true that root + ext == p.
def splitext(p):
+ p = os.fspath(p)
if isinstance(p, bytes):
sep = b'/'
extsep = b'.'
@@ -128,6 +133,7 @@ splitext.__doc__ = genericpath._splitext.__doc__
def splitdrive(p):
"""Split a pathname into drive and path. On Posix, drive is always
empty."""
+ p = os.fspath(p)
return p[:0], p
@@ -135,6 +141,7 @@ def splitdrive(p):
def basename(p):
"""Returns the final component of a pathname"""
+ p = os.fspath(p)
sep = _get_sep(p)
i = p.rfind(sep) + 1
return p[i:]
@@ -144,6 +151,7 @@ def basename(p):
def dirname(p):
"""Returns the directory component of a pathname"""
+ p = os.fspath(p)
sep = _get_sep(p)
i = p.rfind(sep) + 1
head = p[:i]
@@ -222,6 +230,7 @@ def ismount(path):
def expanduser(path):
"""Expand ~ and ~user constructions. If user or $HOME is unknown,
do nothing."""
+ path = os.fspath(path)
if isinstance(path, bytes):
tilde = b'~'
else:
@@ -267,6 +276,7 @@ _varprogb = None
def expandvars(path):
"""Expand shell variables of form $var and ${var}. Unknown variables
are left unchanged."""
+ path = os.fspath(path)
global _varprog, _varprogb
if isinstance(path, bytes):
if b'$' not in path:
@@ -318,6 +328,7 @@ def expandvars(path):
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
+ path = os.fspath(path)
if isinstance(path, bytes):
sep = b'/'
empty = b''
@@ -355,6 +366,7 @@ def normpath(path):
def abspath(path):
"""Return an absolute path."""
+ path = os.fspath(path)
if not isabs(path):
if isinstance(path, bytes):
cwd = os.getcwdb()
@@ -370,6 +382,7 @@ def abspath(path):
def realpath(filename):
"""Return the canonical path of the specified filename, eliminating any
symbolic links encountered in the path."""
+ filename = os.fspath(filename)
path, ok = _joinrealpath(filename[:0], filename, {})
return abspath(path)
@@ -434,6 +447,7 @@ def relpath(path, start=None):
if not path:
raise ValueError("no path specified")
+ path = os.fspath(path)
if isinstance(path, bytes):
curdir = b'.'
sep = b'/'
@@ -445,6 +459,8 @@ def relpath(path, start=None):
if start is None:
start = curdir
+ else:
+ start = os.fspath(start)
try:
start_list = [x for x in abspath(start).split(sep) if x]
@@ -472,6 +488,7 @@ def commonpath(paths):
if not paths:
raise ValueError('commonpath() arg is an empty sequence')
+ paths = tuple(map(os.fspath, paths))
if isinstance(paths[0], bytes):
sep = b'/'
curdir = b'.'
diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py
index 4d40b87..d7dba97 100644
--- a/Lib/pyclbr.py
+++ b/Lib/pyclbr.py
@@ -40,12 +40,10 @@ Instances of this class have the following instance variables:
"""
import io
-import os
import sys
import importlib.util
import tokenize
from token import NAME, DEDENT, OP
-from operator import itemgetter
__all__ = ["readmodule", "readmodule_ex", "Class", "Function"]
@@ -328,6 +326,7 @@ def _getname(g):
def _main():
# Main program for testing.
import os
+ from operator import itemgetter
mod = sys.argv[1]
if os.path.exists(mod):
path = [os.path.dirname(mod)]
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 0d0d0ab..39db391 100755..100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -209,6 +209,18 @@ def classify_class_attrs(object):
results.append((name, kind, cls, value))
return results
+def sort_attributes(attrs, object):
+ 'Sort the attrs list in-place by _fields and then alphabetically by name'
+ # This allows data descriptors to be ordered according
+ # to a _fields attribute if present.
+ fields = getattr(object, '_fields', [])
+ try:
+ field_order = {name : i-len(fields) for (i, name) in enumerate(fields)}
+ except TypeError:
+ field_order = {}
+ keyfunc = lambda attr: (field_order.get(attr[0], 0), attr[0])
+ attrs.sort(key=keyfunc)
+
# ----------------------------------------------------- module manipulation
def ispackage(path):
@@ -338,7 +350,7 @@ def safeimport(path, forceload=0, cache={}):
elif exc is SyntaxError:
# A SyntaxError occurred before we could execute the module.
raise ErrorDuringImport(value.filename, info)
- elif exc is ImportError and value.name == path:
+ elif issubclass(exc, ImportError) and value.name == path:
# No such module in the path.
return None
else:
@@ -868,8 +880,7 @@ class HTMLDoc(Doc):
object.__module__)
tag += ':<br>\n'
- # Sort attrs by name.
- attrs.sort(key=lambda t: t[0])
+ sort_attributes(attrs, object)
# Pump out the attrs, segregated by kind.
attrs = spill('Methods %s' % tag, attrs,
@@ -1287,8 +1298,8 @@ location listed above.
else:
tag = "inherited from %s" % classname(thisclass,
object.__module__)
- # Sort attrs by name.
- attrs.sort()
+
+ sort_attributes(attrs, object)
# Pump out the attrs, segregated by kind.
attrs = spill("Methods %s:\n" % tag, attrs,
@@ -1418,13 +1429,14 @@ def getpager():
return plainpager
if not sys.stdin.isatty() or not sys.stdout.isatty():
return plainpager
- if 'PAGER' in os.environ:
+ use_pager = os.environ.get('MANPAGER') or os.environ.get('PAGER')
+ if use_pager:
if sys.platform == 'win32': # pipes completely broken in Windows
- return lambda text: tempfilepager(plain(text), os.environ['PAGER'])
+ return lambda text: tempfilepager(plain(text), use_pager)
elif os.environ.get('TERM') in ('dumb', 'emacs'):
- return lambda text: pipepager(plain(text), os.environ['PAGER'])
+ return lambda text: pipepager(plain(text), use_pager)
else:
- return lambda text: pipepager(text, os.environ['PAGER'])
+ return lambda text: pipepager(text, use_pager)
if os.environ.get('TERM') in ('dumb', 'emacs'):
return plainpager
if sys.platform == 'win32':
@@ -1901,10 +1913,10 @@ has the same effect as typing a particular string at the help> prompt.
def intro(self):
self.output.write('''
-Welcome to Python %s's help utility!
+Welcome to Python {0}'s help utility!
If this is your first time using Python, you should definitely check out
-the tutorial on the Internet at http://docs.python.org/%s/tutorial/.
+the tutorial on the Internet at http://docs.python.org/{0}/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
@@ -1914,7 +1926,7 @@ To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".
-''' % tuple([sys.version[:3]]*2))
+'''.format('%d.%d' % sys.version_info[:2]))
def list(self, items, columns=4, width=80):
items = list(sorted(items))
diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py
index d6f1366..aaf2ce6 100644
--- a/Lib/pydoc_data/topics.py
+++ b/Lib/pydoc_data/topics.py
@@ -1,79 +1,12949 @@
# -*- coding: utf-8 -*-
-# Autogenerated by Sphinx on Sat Jun 25 14:08:44 2016
-topics = {'assert': u'\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 to\n\n if __debug__:\n if not expression1: raise AssertionError(expression2)\n\nThese equivalences assume that "__debug__" and "AssertionError" refer\nto 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 (command\nline option -O). The current code generator emits no code for an\nassert statement when optimization is requested at compile time. Note\nthat it is unnecessary to include the source code for the expression\nthat failed in the error message; it will be displayed as part of the\nstack trace.\n\nAssignments to "__debug__" are illegal. The value for the built-in\nvariable is determined when the interpreter starts.\n',
- 'assignment': u'\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 "=")+ (starred_expression | 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\n*attributeref*, *subscription*, and *slicing*.)\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 empty: The object must also be an empty\n iterable.\n\n* If the target list is a single target in parentheses: The object\n is assigned to that target.\n\n* If the target list is a comma-separated list of targets, or a\n single target in square brackets: The object must be an iterable\n with the same number of items as there are targets in the target\n list, and the items are assigned, from left to right, to the\n corresponding targets.\n\n * If the target list contains one target prefixed with an\n asterisk, called a "starred" target: The object must be an\n iterable with at least as many items as there are targets in the\n target list, minus one. The first items of the iterable are\n assigned, from left to right, to the targets before the starred\n target. The final items of the iterable are assigned to the\n targets after the starred target. A list of the remaining items\n in the iterable is then assigned to the starred target (the list\n can be empty).\n\n * Else: The object must be an iterable with the same number of\n items 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" statement\n in the current code block: the name is bound to the object in the\n current local namespace.\n\n * Otherwise: the name is bound to the object in the global\n namespace or the outer namespace determined by "nonlocal",\n respectively.\n\n The name is rebound if it was already bound. This may cause the\n reference count for the object previously bound to the name to reach\n zero, causing the object to be deallocated and its destructor (if it\n has one) to be called.\n\n* If the target is an attribute reference: The primary expression in\n the reference is evaluated. It should yield an object with\n assignable attributes; if this is not the case, "TypeError" is\n raised. That object is then asked to assign the assigned object to\n the given attribute; if it cannot perform the assignment, it raises\n an exception (usually but not necessarily "AttributeError").\n\n Note: If the object is a class instance and the attribute reference\n occurs on both sides of the assignment operator, the RHS expression,\n "a.x" can access either an instance attribute or (if no instance\n attribute exists) a class attribute. The LHS target "a.x" is always\n set as an instance attribute, creating it if necessary. Thus, the\n two occurrences of "a.x" do not necessarily refer to the same\n attribute: if the RHS expression refers to a class attribute, the\n LHS creates a new instance attribute as the target of the\n assignment:\n\n class Cls:\n x = 3 # class variable\n inst = Cls()\n inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x as 3\n\n This description does not necessarily apply to descriptor\n attributes, such as properties created with "property()".\n\n* If the target is a subscription: The primary expression in the\n reference is evaluated. It should yield either a mutable sequence\n object (such as a list) or a mapping object (such as a dictionary).\n Next, the subscript expression is evaluated.\n\n If the primary is a mutable sequence object (such as a list), the\n subscript must yield an integer. If it is negative, the sequence\'s\n length is added to it. The resulting value must be a nonnegative\n integer less than the sequence\'s length, and the sequence is asked\n to assign the assigned object to its item with that index. If the\n index is out of range, "IndexError" is raised (assignment to a\n subscripted sequence cannot add new items to a list).\n\n If the primary is a mapping object (such as a dictionary), the\n subscript must have a type compatible with the mapping\'s key type,\n and the mapping is then asked to create a key/datum pair which maps\n the subscript to the assigned object. This can either replace an\n existing key/value pair with the same key value, or insert a new\n key/value pair (if no key with the same value existed).\n\n For user-defined objects, the "__setitem__()" method is called with\n appropriate arguments.\n\n* If the target is a slicing: The primary expression in the\n reference is evaluated. It should yield a mutable sequence object\n (such as a list). The assigned object should be a sequence object\n of the same type. Next, the lower and upper bound expressions are\n evaluated, insofar they are present; defaults are zero and the\n sequence\'s length. The bounds should evaluate to integers. If\n either bound is negative, the sequence\'s length is added to it. The\n resulting bounds are clipped to lie between zero and the sequence\'s\n length, inclusive. Finally, the sequence object is asked to replace\n the slice with the items of the assigned sequence. The length of\n the slice may be different from the length of the assigned sequence,\n thus changing the length of the target sequence, if the target\n sequence allows it.\n\n**CPython implementation detail:** In the current implementation, the\nsyntax for targets is taken to be the same as for expressions, and\ninvalid syntax is rejected during the code generation phase, causing\nless detailed error messages.\n\nAlthough the definition of assignment implies that overlaps between\nthe left-hand side and the right-hand side are \'simultaneous\' (for\nexample "a, b = b, a" swaps two variables), overlaps *within* the\ncollection of assigned-to variables occur left-to-right, sometimes\nresulting in confusion. For instance, the following program prints\n"[0, 2]":\n\n x = [0, 1]\n i = 0\n i, x[i] = 1, 2 # i is updated, then x[i] is updated\n print(x)\n\nSee also: **PEP 3132** - Extended Iterable Unpacking\n\n The specification for the "*target" feature.\n\n\nAugmented assignment statements\n===============================\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "@=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions of 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 the\naugmented version, "x" is only evaluated once. Also, when possible,\nthe actual operation is performed *in-place*, meaning that rather than\ncreating a new object and assigning that to the target, the old object\nis modified instead.\n\nUnlike normal assignments, augmented assignments evaluate the left-\nhand side *before* evaluating the right-hand side. For example, "a[i]\n+= f(x)" first looks-up "a[i]", then it evaluates "f(x)" and performs\nthe addition, and lastly, it writes the result back to "a[i]".\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n',
- 'atom-identifiers': u'\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, with leading underscores removed and a single underscore\ninserted, in front of the name. For example, the identifier "__spam"\noccurring in a class named "Ham" will be transformed to "_Ham__spam".\nThis transformation is independent of the syntactical context in which\nthe identifier is used. If the transformed name is extremely long\n(longer than 255 characters), implementation defined truncation may\nhappen. If the class name consists only of underscores, no\ntransformation is done.\n',
- 'atom-literals': u"\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\nAll literals correspond to immutable data types, and hence the\nobject's identity is less important than its value. Multiple\nevaluations of literals with the same value (either the same\noccurrence in the program text or a different occurrence) may obtain\nthe same object or a different object with the same value.\n",
- 'attribute-access': u'\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") for\nclass 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. This\n method should return the (computed) attribute value or raise an\n "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 for\n efficiency reasons and because otherwise "__getattr__()" would have\n no way to access other attributes of the instance. Note that at\n least for instance variables, you can fake total control by not\n 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 "__getattr__()",\n the latter will not be called unless "__getattribute__()" either\n calls it explicitly or raises an "AttributeError". This method\n should return the (computed) attribute value or raise an\n "AttributeError" exception. In order to avoid infinite recursion in\n this method, its implementation should always call the base class\n method with the same name to access any attributes it needs, for\n example, "object.__getattribute__(self, name)".\n\n Note: This method may still be bypassed when looking up special\n methods as the result of implicit invocation via language syntax\n or built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If "__setattr__()" wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n "object.__setattr__(self, name, value)".\n\nobject.__delattr__(self, name)\n\n Like "__setattr__()" but for attribute deletion instead of\n assignment. This should only be implemented if "del obj.name" is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when "dir()" is called on the object. A sequence must be\n returned. "dir()" converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n========================\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' "__dict__".\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or "None" when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an "AttributeError"\n 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\nThe attribute "__objclass__" is interpreted by the "inspect" module as\nspecifying the class where this object was defined (setting this\nappropriately can assist in runtime introspection of dynamic class\nattributes). For callables, it may indicate that an instance of the\ngiven type (or a subclass) is expected or required as the first\npositional argument (for example, CPython sets this attribute for\nunbound methods that are implemented in C).\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, it\nis 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". How\nthe 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 "A"\n immediately preceding "B" and then invokes the descriptor with the\n call: "A.__dict__[\'m\'].__get__(obj, obj.__class__)".\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of "__get__()", "__set__()" and "__delete__()". If it\ndoes not define "__get__()", then accessing the attribute will return\nthe descriptor object itself unless there is a value in the object\'s\ninstance dictionary. If the descriptor defines "__set__()" and/or\n"__delete__()", it is a data descriptor; if it defines neither, it is\na non-data descriptor. Normally, data descriptors define both\n"__get__()" and "__set__()", while non-data descriptors have just the\n"__get__()" method. Data descriptors with "__set__()" and "__get__()"\ndefined always override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances.\n\nPython methods (including "staticmethod()" and "classmethod()") are\nimplemented 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. *__slots__*\n reserves space for the declared variables and prevents the\n automatic creation of *__dict__* and *__weakref__* for each\n 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\n defining *__slots__* do not support weak references to its\n instances. If weak reference support is needed, then add\n "\'__weakref__\'" to the sequence of strings in the *__slots__*\n declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the\n instance variable defined by the base class slot is inaccessible\n (except by retrieving its descriptor directly from the base class).\n This renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as "int", "bytes" and "tuple".\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings\n may 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': u'\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. This\nproduction can be customized by overriding the "__getattr__()" method.\nIf this attribute 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': u'\nAugmented assignment statements\n*******************************\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "@=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions of 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 the\naugmented version, "x" is only evaluated once. Also, when possible,\nthe actual operation is performed *in-place*, meaning that rather than\ncreating a new object and assigning that to the target, the old object\nis modified instead.\n\nUnlike normal assignments, augmented assignments evaluate the left-\nhand side *before* evaluating the right-hand side. For example, "a[i]\n+= f(x)" first looks-up "a[i]", then it evaluates "f(x)" and performs\nthe addition, and lastly, it writes the result back to "a[i]".\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n',
- 'binary': u'\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 "@" m_expr |\n 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 arguments.\nThe arguments must either both be numbers, or one argument must be an\ninteger and the other must be a sequence. In the former case, the\nnumbers are converted to a common type and then multiplied together.\nIn the latter case, sequence repetition is performed; a negative\nrepetition factor yields an empty sequence.\n\nThe "@" (at) operator is intended to be used for matrix\nmultiplication. No builtin Python types implement this operator.\n\nNew in version 3.5.\n\nThe "/" (division) and "//" (floor division) operators yield the\nquotient of their arguments. The numeric arguments are first\nconverted to a common type. Division of integers 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 "4*0.7 +\n0.34".) The modulo operator always yields a result with the same sign\nas its second operand (or zero); the absolute value of the result is\nstrictly smaller than the absolute value of the second operand [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 also\nconnected with the built-in function "divmod()": "divmod(x, y) ==\n(x//y, x%y)". [2].\n\nIn addition to performing the modulo operation on numbers, the "%"\noperator is also overloaded by string objects to perform old-style\nstring formatting (also known as interpolation). The syntax for\nstring formatting is described in the Python Library Reference,\nsection *printf-style String Formatting*.\n\nThe floor division operator, the modulo operator, and the "divmod()"\nfunction are not defined for complex numbers. Instead, convert to a\nfloating point number using the "abs()" function if appropriate.\n\nThe "+" (addition) operator yields the sum of its arguments. The\narguments must either both be numbers or both be 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 arguments.\nThe numeric arguments are first converted to a common type.\n',
- 'bitwise': u'\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': u'\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': u'\nThe Ellipsis Object\n*******************\n\nThis object is commonly used by slicing (see *Slicings*). It supports\nno special operations. There is exactly one ellipsis object, named\n"Ellipsis" (a built-in name). "type(Ellipsis)()" produces the\n"Ellipsis" singleton.\n\nIt is written as "Ellipsis" or "...".\n',
- 'bltin-null-object': u'\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). "type(None)()" produces the\nsame singleton.\n\nIt is written as "None".\n',
- 'bltin-type-objects': u'\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: "<class \'int\'>".\n',
- 'booleans': u'\nBoolean operations\n******************\n\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, "False"\notherwise.\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 value\nis returned; otherwise, *y* is evaluated and the resulting value is\nreturned.\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 create a\nnew value, it returns a boolean value regardless of the type of its\nargument (for example, "not \'foo\'" produces "False" rather than "\'\'".)\n',
- 'break': u'\nThe "break" statement\n*********************\n\n break_stmt ::= "break"\n\n"break" may only occur syntactically nested in a "for" or "while"\nloop, but not nested in a function or class definition within that\nloop.\n\nIt terminates the nearest enclosing loop, skipping the optional "else"\nclause 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 "finally"\nclause, that "finally" clause is executed before really leaving the\nloop.\n',
- 'callable-types': u'\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': u'\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 ["," starred_and_keywords]\n ["," keywords_arguments]\n | starred_and_keywords ["," keywords_arguments]\n | keywords_arguments\n positional_arguments ::= ["*"] expression ("," ["*"] expression)*\n starred_and_keywords ::= ("*" expression | keyword_item)\n ("," "*" expression | "," keyword_item)*\n keywords_arguments ::= (keyword_item | "**" expression)\n ("," keyword_item | "**" expression)*\n keyword_item ::= identifier "=" expression\n\nAn optional trailing comma may be present after the positional and\nkeyword arguments 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 "TypeError"\nexception is raised. Otherwise, the list of filled slots is used as\nthe argument list for the call.\n\n**CPython implementation detail:** An implementation may provide\nbuilt-in functions whose positional parameters do not have names, even\nif they are \'named\' for the purpose of documentation, and which\ntherefore cannot be supplied by keyword. In CPython, this is the case\nfor functions implemented in C that use "PyArg_ParseTuple()" to parse\ntheir 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 formal\nparameter 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, "expression"\nmust evaluate to an *iterable*. Elements from these iterables are\ntreated as if they were additional positional arguments. For the call\n"f(x1, x2, *y, x3, x4)", if *y* evaluates to a sequence *y1*, ...,\n*yM*, this is equivalent to a call with M+4 positional arguments *x1*,\n*x2*, *y1*, ..., *yM*, *x3*, *x4*.\n\nA consequence of this is that although the "*expression" syntax may\nappear *after* explicit keyword arguments, it is processed *before*\nthe keyword arguments (and any "**expression" arguments -- see below).\nSo:\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 "<stdin>", 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" syntax\nto be used in the same call, so in practice this confusion does not\narise.\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. If a keyword is already\npresent (as an explicit keyword argument, or from another unpacking),\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\nChanged in version 3.5: Function calls accept any number of "*" and\n"**" unpackings, positional arguments may follow iterable unpackings\n("*"), and keyword arguments may follow dictionary unpackings ("**").\nOriginally proposed by **PEP 448**.\n\nA call always returns some value, possibly "None", unless it raises an\nexception. 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 the\n same as if that method was called.\n',
- 'class': u'\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 ::= "(" [argument_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class "object"; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with "self.name = value". Both class and\ninstance attributes are accessible through the notation ""self.name"",\nand an instance attribute hides a class attribute with the same name\nwhen accessed in this way. Class attributes can be used as defaults\nfor instance attributes, but using mutable values there can lead to\nunexpected results. *Descriptors* can be used to create instance\nvariables with different implementation details.\n\nSee also: **PEP 3115** - Metaclasses in Python 3 **PEP 3129** -\n Class Decorators\n',
- 'comparisons': u'\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 only\nonce (but in both cases "z" is not evaluated at all when "x < y" is\nfound 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", except\nthat each expression is evaluated at most once.\n\nNote that "a op1 b op2 c" doesn\'t imply any kind of comparison between\n*a* and *c*, so that, e.g., "x < y > z" is perfectly legal (though\nperhaps not pretty).\n\n\nValue comparisons\n=================\n\nThe operators "<", ">", "==", ">=", "<=", and "!=" compare the values\nof two objects. The objects do not need to have the same type.\n\nChapter *Objects, values and types* states that objects have a value\n(in addition to type and identity). The value of an object is a\nrather abstract notion in Python: For example, there is no canonical\naccess method for an object\'s value. Also, there is no requirement\nthat the value of an object should be constructed in a particular way,\ne.g. comprised of all its data attributes. Comparison operators\nimplement a particular notion of what the value of an object is. One\ncan think of them as defining the value of an object indirectly, by\nmeans of their comparison implementation.\n\nBecause all types are (direct or indirect) subtypes of "object", they\ninherit the default comparison behavior from "object". Types can\ncustomize their comparison behavior by implementing *rich comparison\nmethods* like "__lt__()", described in *Basic customization*.\n\nThe default behavior for equality comparison ("==" and "!=") is based\non the identity of the objects. Hence, equality comparison of\ninstances with the same identity results in equality, and equality\ncomparison of instances with different identities results in\ninequality. A motivation for this default behavior is the desire that\nall objects should be reflexive (i.e. "x is y" implies "x == y").\n\nA default order comparison ("<", ">", "<=", and ">=") is not provided;\nan attempt raises "TypeError". A motivation for this default behavior\nis the lack of a similar invariant as for equality.\n\nThe behavior of the default equality comparison, that instances with\ndifferent identities are always unequal, may be in contrast to what\ntypes will need that have a sensible definition of object value and\nvalue-based equality. Such types will need to customize their\ncomparison behavior, and in fact, a number of built-in types have done\nthat.\n\nThe following list describes the comparison behavior of the most\nimportant built-in types.\n\n* Numbers of built-in numeric types (*Numeric Types --- int, float,\n complex*) and of the standard library types "fractions.Fraction" and\n "decimal.Decimal" can be compared within and across their types,\n with the restriction that complex numbers do not support order\n comparison. Within the limits of the types involved, they compare\n mathematically (algorithmically) correct without loss of precision.\n\n The not-a-number values "float(\'NaN\')" and "Decimal(\'NaN\')" are\n special. They are identical to themselves ("x is x" is true) but\n are not equal to themselves ("x == x" is false). Additionally,\n comparing any number to a not-a-number value will return "False".\n For example, both "3 < float(\'NaN\')" and "float(\'NaN\') < 3" will\n return "False".\n\n* Binary sequences (instances of "bytes" or "bytearray") can be\n compared within and across their types. They compare\n lexicographically using the numeric values of their elements.\n\n* Strings (instances of "str") compare lexicographically using the\n numerical Unicode code points (the result of the built-in function\n "ord()") of their characters. [3]\n\n Strings and binary sequences cannot be directly compared.\n\n* Sequences (instances of "tuple", "list", or "range") can be\n compared only within each of their types, with the restriction that\n ranges do not support order comparison. Equality comparison across\n these types results in unequality, and ordering comparison across\n these types raises "TypeError".\n\n Sequences compare lexicographically using comparison of\n corresponding elements, whereby reflexivity of the elements is\n enforced.\n\n In enforcing reflexivity of elements, the comparison of collections\n assumes that for a collection element "x", "x == x" is always true.\n Based on that assumption, element identity is compared first, and\n element comparison is performed only for distinct elements. This\n approach yields the same result as a strict element comparison\n would, if the compared elements are reflexive. For non-reflexive\n elements, the result is different than for strict element\n comparison, and may be surprising: The non-reflexive not-a-number\n values for example result in the following comparison behavior when\n used in a list:\n\n >>> nan = float(\'NaN\')\n >>> nan is nan\n True\n >>> nan == nan\n False <-- the defined non-reflexive behavior of NaN\n >>> [nan] == [nan]\n True <-- list enforces reflexivity and tests identity first\n\n Lexicographical comparison between built-in collections works as\n follows:\n\n * For two collections to compare equal, they must be of the same\n type, have the same length, and each pair of corresponding\n elements must compare equal (for example, "[1,2] == (1,2)" is\n false because the type is not the same).\n\n * Collections that support order comparison are ordered the same\n as their first unequal elements (for example, "[1,2,x] <= [1,2,y]"\n has the same value as "x <= y"). If a corresponding element does\n not exist, the shorter collection is ordered first (for example,\n "[1,2] < [1,2,3]" is true).\n\n* Mappings (instances of "dict") compare equal if and only if they\n have equal *(key, value)* pairs. Equality comparison of the keys and\n elements enforces reflexivity.\n\n Order comparisons ("<", ">", "<=", and ">=") raise "TypeError".\n\n* Sets (instances of "set" or "frozenset") can be compared within\n and across their types.\n\n They define order comparison operators to mean subset and superset\n tests. Those relations do not define total orderings (for example,\n the two sets "{1,2}" and "{2,3}" are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering\n (for example, "min()", "max()", and "sorted()" produce undefined\n results given a list of sets as inputs).\n\n Comparison of sets enforces reflexivity of its elements.\n\n* Most other built-in types have no comparison methods implemented,\n so they inherit the default comparison behavior.\n\nUser-defined classes that customize their comparison behavior should\nfollow some consistency rules, if possible:\n\n* Equality comparison should be reflexive. In other words, identical\n objects should compare equal:\n\n "x is y" implies "x == y"\n\n* Comparison should be symmetric. In other words, the following\n expressions should have the same result:\n\n "x == y" and "y == x"\n\n "x != y" and "y != x"\n\n "x < y" and "y > x"\n\n "x <= y" and "y >= x"\n\n* Comparison should be transitive. The following (non-exhaustive)\n examples illustrate that:\n\n "x > y and y > z" implies "x > z"\n\n "x < y and y <= z" implies "x < z"\n\n* Inverse comparison should result in the boolean negation. In other\n words, the following expressions should have the same result:\n\n "x == y" and "not x != y"\n\n "x < y" and "not x >= y" (for total ordering)\n\n "x > y" and "not x <= y" (for total ordering)\n\n The last two expressions apply to totally ordered collections (e.g.\n to sequences, but not to sets or mappings). See also the\n "total_ordering()" decorator.\n\nPython does not enforce these consistency rules. In fact, the\nnot-a-number values are an example for not following these rules.\n\n\nMembership test operations\n==========================\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" tests\nwhether the dictionary has a given key. For container types such as\nlist, tuple, set, frozenset, dict, or collections.deque, the\nexpression "x in y" is equivalent to "any(x is e or x == e for e in\ny)".\n\nFor the string and bytes types, "x in y" is true if and only if *x* is\na substring of *y*. An equivalent test is "y.find(x) != -1". Empty\nstrings are always considered to be a substring of any other string,\nso """ in "abc"" will return "True".\n\nFor user-defined classes which define the "__contains__()" method, "x\nin y" is true if and only if "y.__contains__(x)" is true.\n\nFor user-defined classes which do not define "__contains__()" but do\ndefine "__iter__()", "x in y" is true if some value "z" with "x == z"\nis produced while iterating over "y". If an exception is raised\nduring the iteration, it is as if "in" raised that exception.\n\nLastly, the old-style iteration protocol is tried: if a class defines\n"__getitem__()", "x in y" is true if and only if there is a non-\nnegative integer index *i* such that "x == y[i]", and all lower\ninteger indices do not raise "IndexError" exception. (If any other\nexception is raised, it is as if "in" raised that exception).\n\nThe operator "not in" is defined to have the inverse true value of\n"in".\n\n\nIdentity comparisons\n====================\n\nThe operators "is" and "is not" test for object identity: "x is y" is\ntrue if and only if *x* and *y* are the same object. "x is not y"\nyields the inverse truth value. [4]\n',
- 'compound': u'\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 control\nflow constructs. "try" specifies exception handlers and/or cleanup\ncode for a group of statements, while the "with" statement allows the\nexecution of initialization and finalization code around a block of\ncode. Function and class definitions are also syntactically compound\nstatements.\n\nA compound statement consists 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 a 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 | async_with_stmt\n | async_for_stmt\n | async_funcdef\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 a\n"DEDENT". Also note that optional continuation clauses always begin\nwith 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 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" statement\nexecuted in the first suite skips the rest of the suite and goes back\nto testing the expression.\n\n\nThe "for" statement\n===================\n\nThe "for" statement is used to iterate over the elements of a sequence\n(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 returned by the iterator. 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" exception),\nthe suite in the "else" clause, if present, is executed, and the loop\nterminates.\n\nA "break" statement executed in the first suite terminates the loop\nwithout executing the "else" clause\'s suite. A "continue" statement\nexecuted in the first suite skips the rest of the suite and continues\nwith the next item, or with the "else" clause if there is no next\nitem.\n\nThe for-loop makes assignments to the variables(s) in the target list.\nThis overwrites all previous assignments to those variables including\nthose made in the suite of the for-loop:\n\n for i in range(10):\n print(i)\n i = 5 # this will not affect the for-loop\n # because i will be overwritten with the next\n # index in the range\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, they will not have been assigned to at\nall by the loop. Hint: the built-in function "range()" returns an\niterator of integers suitable to emulate the effect of Pascal\'s "for i\n:= a to b do"; e.g., "list(range(3))" returns the list "[0, 1, 2]".\n\nNote: There is a subtlety when the sequence is being modified by the\n loop (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" identifier]] ":" 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 no\nexception occurs in the "try" clause, no exception handler is\nexecuted. When an exception occurs in the "try" suite, a search for an\nexception handler is started. This search inspects the except clauses\nin turn until one is found that matches the exception. An expression-\nless except clause, if present, must be last; it matches any\nexception. For an except clause with an expression, that expression\nis evaluated, and the clause matches the exception if the resulting\nobject is "compatible" with the exception. An object is compatible\nwith an exception if it is the class or a base class of the exception\nobject or a tuple containing an item compatible with the exception.\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 raised\nthe 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, if\npresent, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using "as target", it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the "sys" module and can be accessed via\n"sys.exc_info()". "sys.exc_info()" returns a 3-tuple consisting of the\nexception class, the exception instance and a traceback object (see\nsection *The standard type hierarchy*) identifying the point in the\nprogram where the exception occurred. "sys.exc_info()" values are\nrestored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional "else" clause is executed if and when control flows off\nthe end of the "try" clause. [2] Exceptions in the "else" clause are\nnot handled by the preceding "except" clauses.\n\nIf "finally" is present, it specifies a \'cleanup\' handler. The "try"\nclause is executed, including any "except" and "else" clauses. If an\nexception occurs in any of the clauses and is not handled, the\nexception is temporarily saved. The "finally" clause is executed. If\nthere is a saved exception it is re-raised at the end of the "finally"\nclause. If the "finally" clause raises another exception, the saved\nexception is set as the context of the new exception. If the "finally"\nclause executes a "return" or "break" statement, the saved exception\nis discarded:\n\n >>> def f():\n ... try:\n ... 1/0\n ... finally:\n ... return 42\n ...\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the "finally" clause.\n\nWhen a "return", "break" or "continue" statement is executed in the\n"try" suite of a "try"..."finally" statement, the "finally" clause is\nalso executed \'on the way out.\' A "continue" statement is illegal in\nthe "finally" clause. (The reason is a problem with the current\nimplementation --- this restriction may be lifted in the future).\n\nThe return value of a function is determined by the last "return"\nstatement executed. Since the "finally" clause always executes, a\n"return" statement executed in the "finally" clause will always be the\nlast one executed:\n\n >>> def foo():\n ... try:\n ... return \'try\'\n ... finally:\n ... return \'finally\'\n ...\n >>> foo()\n \'finally\'\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 "try"..."except"..."finally"\nusage patterns to be encapsulated for convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the "with" statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the "with_item")\n is evaluated to obtain a context manager.\n\n2. The context manager\'s "__exit__()" is loaded for later use.\n\n3. The context manager\'s "__enter__()" method is invoked.\n\n4. If a target was included in the "with" statement, the return\n value from "__enter__()" is assigned to it.\n\n Note: The "with" statement guarantees that if the "__enter__()"\n method returns without an error, then "__exit__()" will always be\n called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s "__exit__()" method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to "__exit__()". Otherwise, three\n "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 reraised.\n If the return value was true, the exception is suppressed, and\n execution continues with the statement following the "with"\n statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from "__exit__()" is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple "with" statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also: **PEP 343** - The "with" statement\n\n The specification, background, and examples for the Python "with"\n 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)* ["," "**" 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 --- this\nis a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated from left to right when the\nfunction definition is executed.** This means that the expression is\nevaluated once, when the function is defined, and that the same "pre-\ncomputed" value is used for each call. This is especially important\nto understand when a default parameter is a mutable object, such as a\nlist or a dictionary: if the function modifies the object (e.g. by\nappending an item to a list), the default value is in effect modified.\nThis is generally not what was intended. A way around this is to use\n"None" as the default, and explicitly test for it in the body of the\nfunction, 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 any\nexcess positional parameters, defaulting to the empty tuple. If the\nform ""**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"" following\nthe parameter name. Any parameter may have an annotation even those\nof the form "*identifier" or "**identifier". Functions may have\n"return" annotation of the form ""-> expression"" after the parameter\nlist. These annotations can be any valid Python expression and are\nevaluated when the function definition is executed. Annotations may\nbe evaluated in a different order than they appear in the source code.\nThe presence of annotations does not change the semantics of a\nfunction. The annotation values are available as values of a\ndictionary keyed by the parameters\' names in the "__annotations__"\nattribute 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\nexpressions, described in section *Lambdas*. Note that the lambda\nexpression is merely a shorthand for a simplified function definition;\na function defined in a ""def"" statement can be passed around or\nassigned to another name just like a function defined by a lambda\nexpression. The ""def"" form is actually more powerful since it\nallows the execution of multiple statements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A ""def""\nstatement executed inside a function definition defines a local\nfunction that can be returned or passed around. Free variables used\nin the nested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also: **PEP 3107** - Function Annotations\n\n The original specification for function annotations.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [argument_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class "object"; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with "self.name = value". Both class and\ninstance attributes are accessible through the notation ""self.name"",\nand an instance attribute hides a class attribute with the same name\nwhen accessed in this way. Class attributes can be used as defaults\nfor instance attributes, but using mutable values there can lead to\nunexpected results. *Descriptors* can be used to create instance\nvariables with different implementation details.\n\nSee also: **PEP 3115** - Metaclasses in Python 3 **PEP 3129** -\n Class Decorators\n\n\nCoroutines\n==========\n\nNew in version 3.5.\n\n\nCoroutine function definition\n-----------------------------\n\n async_funcdef ::= [decorators] "async" "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n\nExecution of Python coroutines can be suspended and resumed at many\npoints (see *coroutine*). In the body of a coroutine, any "await" and\n"async" identifiers become reserved keywords; "await" expressions,\n"async for" and "async with" can only be used in coroutine bodies.\n\nFunctions defined with "async def" syntax are always coroutine\nfunctions, even if they do not contain "await" or "async" keywords.\n\nIt is a "SyntaxError" to use "yield" expressions in "async def"\ncoroutines.\n\nAn example of a coroutine function:\n\n async def func(param1, param2):\n do_stuff()\n await some_coroutine()\n\n\nThe "async for" statement\n-------------------------\n\n async_for_stmt ::= "async" for_stmt\n\nAn *asynchronous iterable* is able to call asynchronous code in its\n*iter* implementation, and *asynchronous iterator* can call\nasynchronous code in its *next* method.\n\nThe "async for" statement allows convenient iteration over\nasynchronous iterators.\n\nThe following code:\n\n async for TARGET in ITER:\n BLOCK\n else:\n BLOCK2\n\nIs semantically equivalent to:\n\n iter = (ITER)\n iter = type(iter).__aiter__(iter)\n running = True\n while running:\n try:\n TARGET = await type(iter).__anext__(iter)\n except StopAsyncIteration:\n running = False\n else:\n BLOCK\n else:\n BLOCK2\n\nSee also "__aiter__()" and "__anext__()" for details.\n\nIt is a "SyntaxError" to use "async for" statement outside of an\n"async def" function.\n\n\nThe "async with" statement\n--------------------------\n\n async_with_stmt ::= "async" with_stmt\n\nAn *asynchronous context manager* is a *context manager* that is able\nto suspend execution in its *enter* and *exit* methods.\n\nThe following code:\n\n async with EXPR as VAR:\n BLOCK\n\nIs semantically equivalent to:\n\n mgr = (EXPR)\n aexit = type(mgr).__aexit__\n aenter = type(mgr).__aenter__(mgr)\n exc = True\n\n VAR = await aenter\n try:\n BLOCK\n except:\n if not await aexit(mgr, *sys.exc_info()):\n raise\n else:\n await aexit(mgr, None, None, None)\n\nSee also "__aenter__()" and "__aexit__()" for details.\n\nIt is a "SyntaxError" to use "async with" statement outside of an\n"async def" function.\n\nSee also: **PEP 492** - Coroutines with async and await syntax\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless\n there is a "finally" clause which happens to raise another\n exception. That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of\n an 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\n function body is transformed into the function\'s "__doc__"\n attribute and 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': u'\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 manager\nhandles the entry into, and the exit from, the desired runtime context\nfor the execution of the block of code. Context managers are normally\ninvoked using the "with" statement (described in section *The with\nstatement*), but can also be used by directly invoking their methods.\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: **PEP 343** - The "with" statement\n\n The specification, background, and examples for the Python "with"\n statement.\n',
- 'continue': u'\nThe "continue" statement\n************************\n\n continue_stmt ::= "continue"\n\n"continue" may only occur syntactically nested in a "for" or "while"\nloop, but not nested in a function or class definition or "finally"\nclause within that loop. It continues with the next cycle of the\nnearest 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': u'\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 as follows:\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\n other 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 as a\nleft argument to the \'%\' operator). Extensions must define their own\nconversion behavior.\n',
- 'customization': u'\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 an\n 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 after the instance has been created (by "__new__()"), but\n before it is returned to the caller. 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, if\n any, must explicitly call it to ensure proper initialization of the\n base class part of the instance; for example:\n "BaseClass.__init__(self, [args...])".\n\n Because "__new__()" and "__init__()" work together in constructing\n objects ("__new__()" to create it, and "__init__()" to customise\n it), no non-"None" value may be returned by "__init__()"; doing so\n will cause a "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, the\n derived class\'s "__del__()" method, if any, must explicitly call it\n to ensure proper deletion of the base class part of the instance.\n Note that it is possible (though not recommended!) for the\n "__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 is\n only called when "x"\'s reference count reaches zero. Some common\n situations that may prevent the reference count of an object from\n going to zero include: circular references between objects (e.g.,\n a doubly-linked list or a tree data structure with parent and\n child pointers); a reference to the object on the stack frame of\n a function that caught an exception (the traceback stored in\n "sys.exc_info()[2]" keeps the stack frame alive); or a reference\n to the object on the stack frame that raised an unhandled\n 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 second can be resolved by freeing the reference to the\n traceback object when it is no longer useful, and the third can\n be resolved by storing "None" in "sys.last_traceback". Circular\n references which are garbage are detected and cleaned up when the\n cyclic garbage collector is enabled (it\'s on by default). Refer\n to the documentation for the "gc" module for more information\n about this topic.\n\n Warning: Due to the precarious circumstances under which\n "__del__()" methods are invoked, exceptions that occur during\n their execution are ignored, and a warning is printed to\n "sys.stderr" instead. Also, when "__del__()" is invoked in\n response to a module being deleted (e.g., when execution of the\n program is done), other globals referenced by the "__del__()"\n method may already have been deleted or in the process of being\n torn down (e.g. the import machinery shutting down). For this\n reason, "__del__()" methods should do the absolute minimum needed\n to maintain external invariants. Starting with version 1.5,\n Python guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the "__del__()" method is called.\n\nobject.__repr__(self)\n\n Called by the "repr()" built-in function to compute the "official"\n string representation of an object. If at all possible, this\n should look like a valid Python expression that could be used to\n recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n "<...some useful description...>" should be returned. The return\n value must be a string object. If a class defines "__repr__()" but\n not "__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 "str(object)" and the built-in functions "format()" and\n "print()" to compute the "informal" or nicely printable string\n representation of an object. The return value must be a *string*\n object.\n\n This method differs from "object.__repr__()" in that there is no\n expectation that "__str__()" return a valid Python expression: a\n more convenient or concise representation can be used.\n\n The default implementation defined by the built-in type "object"\n calls "object.__repr__()".\n\nobject.__bytes__(self)\n\n Called by "bytes()" to compute a byte-string representation of an\n object. This should return a "bytes" object.\n\nobject.__format__(self, format_spec)\n\n Called by the "format()" built-in function (and by extension, the\n "str.format()" method of class "str") to produce a "formatted"\n string representation of an object. The "format_spec" argument is a\n string that contains a description of the formatting options\n desired. The interpretation of the "format_spec" argument is up to\n the type implementing "__format__()", however most classes will\n either delegate formatting to one of the built-in types, or use a\n 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\n Changed in version 3.4: The __format__ method of "object" itself\n raises a "TypeError" if passed any non-empty string.\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: "x<y" calls "x.__lt__(y)", "x<=y" calls "x.__le__(y)",\n "x==y" calls "x.__eq__(y)", "x!=y" calls "x.__ne__(y)", "x>y" calls\n "x.__gt__(y)", and "x>=y" calls "x.__ge__(y)".\n\n A rich comparison method may return the singleton "NotImplemented"\n if it does not implement the operation for a given pair of\n arguments. By convention, "False" and "True" are returned for a\n successful comparison. However, these methods can return any value,\n so if the comparison operator is used in a Boolean context (e.g.,\n in the condition of an "if" statement), Python will call "bool()"\n on the value to determine if the result is true or false.\n\n By default, "__ne__()" delegates to "__eq__()" and inverts the\n result unless it is "NotImplemented". There are no other implied\n relationships among the comparison operators, for example, the\n truth of "(x<y or x==y)" does not imply "x<=y". To automatically\n generate ordering operations from a single root operation, see\n "functools.total_ordering()".\n\n See 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 other\'s\n reflection, "__le__()" and "__ge__()" are each other\'s reflection,\n and "__eq__()" and "__ne__()" are their own reflection. If the\n operands are of different types, and right operand\'s type is a\n direct or indirect subclass of the left operand\'s type, the\n reflected method of the right operand has priority, otherwise the\n left operand\'s method has priority. Virtual subclassing is not\n considered.\n\nobject.__hash__(self)\n\n Called by built-in function "hash()" and for operations on members\n of hashed collections including "set", "frozenset", and "dict".\n "__hash__()" should return an integer. 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 Note: "hash()" truncates the value returned from an object\'s\n custom "__hash__()" method to the size of a "Py_ssize_t". This\n is typically 8 bytes on 64-bit builds and 4 bytes on 32-bit\n builds. If an object\'s "__hash__()" must interoperate on builds\n of different bit sizes, be sure to check the width on all\n supported builds. An easy way to do this is with "python -c\n "import sys; print(sys.hash_info.width)"".\n\n If a class does not define an "__eq__()" method it should not\n define a "__hash__()" operation either; if it defines "__eq__()"\n but not "__hash__()", its instances will not be usable as items in\n hashable collections. If a class defines mutable objects and\n implements an "__eq__()" method, it should not implement\n "__hash__()", since the implementation of hashable collections\n requires that a key\'s hash value is immutable (if the object\'s hash\n value changes, it will be in the wrong hash bucket).\n\n User-defined classes have "__eq__()" and "__hash__()" methods by\n default; with them, all objects compare unequal (except with\n themselves) and "x.__hash__()" returns an appropriate value such\n that "x == y" implies both that "x is y" and "hash(x) == hash(y)".\n\n A class that overrides "__eq__()" and does not define "__hash__()"\n will have its "__hash__()" implicitly set to "None". When the\n "__hash__()" method of a class is "None", instances of the class\n will raise an appropriate "TypeError" when a program attempts to\n retrieve their hash value, and will also be correctly identified as\n unhashable when checking "isinstance(obj, collections.Hashable)".\n\n If a class that overrides "__eq__()" needs to retain the\n implementation of "__hash__()" from a parent class, the interpreter\n must be told this explicitly by setting "__hash__ =\n <ParentClass>.__hash__".\n\n If a class that does not override "__eq__()" wishes to suppress\n hash support, it should include "__hash__ = None" in the class\n definition. A class which defines its own "__hash__()" that\n explicitly raises a "TypeError" would be incorrectly identified as\n hashable by an "isinstance(obj, collections.Hashable)" call.\n\n Note: By default, the "__hash__()" values of str, bytes and\n datetime objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also "PYTHONHASHSEED".\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n "bool()"; should return "False" or "True". When this method is not\n defined, "__len__()" is called, if it is defined, and the object is\n considered true if its result is nonzero. If a class defines\n neither "__len__()" nor "__bool__()", all its instances are\n considered true.\n',
- 'debugger': u'\n"pdb" --- The Python Debugger\n*****************************\n\n**Source code:** Lib/pdb.py\n\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 reading\nthe source. The extension interface uses the modules "bdb" and "cmd".\n\nThe debugger\'s prompt is "(Pdb)". Typical usage to run a program under\ncontrol of the debugger is:\n\n >>> import pdb\n >>> import mymodule\n >>> pdb.run(\'mymodule.test()\')\n > <string>(0)?()\n (Pdb) continue\n > <string>(1)?()\n (Pdb) continue\n NameError: \'spam\'\n > <string>(1)?()\n (Pdb)\n\nChanged in version 3.3: Tab-completion via the "readline" module is\navailable for commands and command arguments, e.g. the current global\nand local names are offered as arguments of the "p" command.\n\n"pdb.py" can also be invoked as a script to debug other scripts. For\nexample:\n\n python3 -m pdb myscript.py\n\nWhen invoked as a script, pdb will automatically enter post-mortem\ndebugging if the program being debugged exits abnormally. After post-\nmortem debugging (or after normal exit of the program), pdb will\nrestart the program. Automatic restarting preserves pdb\'s state (such\nas breakpoints) and in most cases is more useful than quitting the\ndebugger upon program\'s exit.\n\nNew in version 3.2: "pdb.py" now accepts a "-c" option that executes\ncommands as if given in a ".pdbrc" file, see *Debugger Commands*.\n\nThe typical usage to break into the debugger from a running program is\nto insert\n\n import pdb; pdb.set_trace()\n\nat the location you want to break into the debugger. You can then\nstep through the code following this statement, and continue running\nwithout the debugger using the "continue" command.\n\nThe typical usage to inspect a crashed program is:\n\n >>> import pdb\n >>> import mymodule\n >>> mymodule.test()\n Traceback (most recent call last):\n File "<stdin>", line 1, in ?\n File "./mymodule.py", line 4, in test\n test2()\n File "./mymodule.py", line 3, in test2\n print(spam)\n NameError: spam\n >>> pdb.pm()\n > ./mymodule.py(3)test2()\n -> print(spam)\n (Pdb)\n\nThe module defines the following functions; each enters the debugger\nin a slightly different way:\n\npdb.run(statement, globals=None, locals=None)\n\n Execute the *statement* (given as a string or a code object) under\n debugger control. The debugger prompt appears before any code is\n executed; you can set breakpoints and type "continue", or you can\n step through the statement using "step" or "next" (all these\n commands are explained below). The optional *globals* and *locals*\n arguments specify the environment in which the code is executed; by\n default the dictionary of the module "__main__" is used. (See the\n explanation of the built-in "exec()" or "eval()" functions.)\n\npdb.runeval(expression, globals=None, locals=None)\n\n Evaluate the *expression* (given as a string or a code object)\n under debugger control. When "runeval()" returns, it returns the\n value of the expression. Otherwise this function is similar to\n "run()".\n\npdb.runcall(function, *args, **kwds)\n\n Call the *function* (a function or method object, not a string)\n with the given arguments. When "runcall()" returns, it returns\n whatever the function call returned. The debugger prompt appears\n as soon as the function is entered.\n\npdb.set_trace()\n\n Enter the debugger at the calling stack frame. This is useful to\n hard-code a breakpoint at a given point in a program, even if the\n code is not otherwise being debugged (e.g. when an assertion\n fails).\n\npdb.post_mortem(traceback=None)\n\n Enter post-mortem debugging of the given *traceback* object. If no\n *traceback* is given, it uses the one of the exception that is\n currently being handled (an exception must be being handled if the\n default is to be used).\n\npdb.pm()\n\n Enter post-mortem debugging of the traceback found in\n "sys.last_traceback".\n\nThe "run*" functions and "set_trace()" are aliases for instantiating\nthe "Pdb" class and calling the method of the same name. If you want\nto access further features, you have to do this yourself:\n\nclass class pdb.Pdb(completekey=\'tab\', stdin=None, stdout=None, skip=None, nosigint=False)\n\n "Pdb" is the debugger class.\n\n The *completekey*, *stdin* and *stdout* arguments are passed to the\n underlying "cmd.Cmd" class; see the description there.\n\n The *skip* argument, if given, must be an iterable of glob-style\n module name patterns. The debugger will not step into frames that\n originate in a module that matches one of these patterns. [1]\n\n By default, Pdb sets a handler for the SIGINT signal (which is sent\n when the user presses "Ctrl-C" on the console) when you give a\n "continue" command. This allows you to break into the debugger\n again by pressing "Ctrl-C". If you want Pdb not to touch the\n SIGINT handler, set *nosigint* tot true.\n\n Example call to enable tracing with *skip*:\n\n import pdb; pdb.Pdb(skip=[\'django.*\']).set_trace()\n\n New in version 3.1: The *skip* argument.\n\n New in version 3.2: The *nosigint* argument. Previously, a SIGINT\n handler was never set by Pdb.\n\n run(statement, globals=None, locals=None)\n runeval(expression, globals=None, locals=None)\n runcall(function, *args, **kwds)\n set_trace()\n\n See the documentation for the functions explained above.\n\n\nDebugger Commands\n=================\n\nThe commands recognized by the debugger are listed below. Most\ncommands can be abbreviated to one or two letters as indicated; e.g.\n"h(elp)" means that either "h" or "help" can be used to enter the help\ncommand (but not "he" or "hel", nor "H" or "Help" or "HELP").\nArguments to commands must be separated by whitespace (spaces or\ntabs). Optional arguments are enclosed in square brackets ("[]") in\nthe command syntax; the square brackets must not be typed.\nAlternatives in the command syntax are separated by a vertical bar\n("|").\n\nEntering a blank line repeats the last command entered. Exception: if\nthe last command was a "list" command, the next 11 lines are listed.\n\nCommands that the debugger doesn\'t recognize are assumed to be Python\nstatements and are executed in the context of the program being\ndebugged. Python statements can also be prefixed with an exclamation\npoint ("!"). This is a powerful way to inspect the program being\ndebugged; it is even possible to change a variable or call a function.\nWhen an exception occurs in such a statement, the exception name is\nprinted but the debugger\'s state is not changed.\n\nThe debugger supports *aliases*. Aliases can have parameters which\nallows one a certain level of adaptability to the context under\nexamination.\n\nMultiple commands may be entered on a single line, separated by ";;".\n(A single ";" is not used as it is the separator for multiple commands\nin a line that is passed to the Python parser.) No intelligence is\napplied to separating the commands; the input is split at the first\n";;" pair, even if it is in the middle of a quoted string.\n\nIf a file ".pdbrc" exists in the user\'s home directory or in the\ncurrent directory, it is read in and executed as if it had been typed\nat the debugger prompt. This is particularly useful for aliases. If\nboth files exist, the one in the home directory is read first and\naliases defined there can be overridden by the local file.\n\nChanged in version 3.2: ".pdbrc" can now contain commands that\ncontinue debugging, such as "continue" or "next". Previously, these\ncommands had no effect.\n\nh(elp) [command]\n\n Without argument, print the list of available commands. With a\n *command* as argument, print help about that command. "help pdb"\n displays the full documentation (the docstring of the "pdb"\n module). Since the *command* argument must be an identifier, "help\n exec" must be entered to get help on the "!" command.\n\nw(here)\n\n Print a stack trace, with the most recent frame at the bottom. An\n arrow indicates the current frame, which determines the context of\n most commands.\n\nd(own) [count]\n\n Move the current frame *count* (default one) levels down in the\n stack trace (to a newer frame).\n\nu(p) [count]\n\n Move the current frame *count* (default one) levels up in the stack\n trace (to an older frame).\n\nb(reak) [([filename:]lineno | function) [, condition]]\n\n With a *lineno* argument, set a break there in the current file.\n With a *function* argument, set a break at the first executable\n statement within that function. The line number may be prefixed\n with a filename and a colon, to specify a breakpoint in another\n file (probably one that hasn\'t been loaded yet). The file is\n searched on "sys.path". Note that each breakpoint is assigned a\n number to which all the other breakpoint commands refer.\n\n If a second argument is present, it is an expression which must\n evaluate to true before the breakpoint is honored.\n\n Without argument, list all breaks, including for each breakpoint,\n the number of times that breakpoint has been hit, the current\n ignore count, and the associated condition if any.\n\ntbreak [([filename:]lineno | function) [, condition]]\n\n Temporary breakpoint, which is removed automatically when it is\n first hit. The arguments are the same as for "break".\n\ncl(ear) [filename:lineno | bpnumber [bpnumber ...]]\n\n With a *filename:lineno* argument, clear all the breakpoints at\n this line. With a space separated list of breakpoint numbers, clear\n those breakpoints. Without argument, clear all breaks (but first\n ask confirmation).\n\ndisable [bpnumber [bpnumber ...]]\n\n Disable the breakpoints given as a space separated list of\n breakpoint numbers. Disabling a breakpoint means it cannot cause\n the program to stop execution, but unlike clearing a breakpoint, it\n remains in the list of breakpoints and can be (re-)enabled.\n\nenable [bpnumber [bpnumber ...]]\n\n Enable the breakpoints specified.\n\nignore bpnumber [count]\n\n Set the ignore count for the given breakpoint number. If count is\n omitted, the ignore count is set to 0. A breakpoint becomes active\n when the ignore count is zero. When non-zero, the count is\n decremented each time the breakpoint is reached and the breakpoint\n is not disabled and any associated condition evaluates to true.\n\ncondition bpnumber [condition]\n\n Set a new *condition* for the breakpoint, an expression which must\n evaluate to true before the breakpoint is honored. If *condition*\n is absent, any existing condition is removed; i.e., the breakpoint\n is made unconditional.\n\ncommands [bpnumber]\n\n Specify a list of commands for breakpoint number *bpnumber*. The\n commands themselves appear on the following lines. Type a line\n containing just "end" to terminate the commands. An example:\n\n (Pdb) commands 1\n (com) p some_variable\n (com) end\n (Pdb)\n\n To remove all commands from a breakpoint, type commands and follow\n it immediately with "end"; that is, give no commands.\n\n With no *bpnumber* argument, commands refers to the last breakpoint\n set.\n\n You can use breakpoint commands to start your program up again.\n Simply use the continue command, or step, or any other command that\n resumes execution.\n\n Specifying any command resuming execution (currently continue,\n step, next, return, jump, quit and their abbreviations) terminates\n the command list (as if that command was immediately followed by\n end). This is because any time you resume execution (even with a\n simple next or step), you may encounter another breakpoint--which\n could have its own command list, leading to ambiguities about which\n list to execute.\n\n If you use the \'silent\' command in the command list, the usual\n message about stopping at a breakpoint is not printed. This may be\n desirable for breakpoints that are to print a specific message and\n then continue. If none of the other commands print anything, you\n see no sign that the breakpoint was reached.\n\ns(tep)\n\n Execute the current line, stop at the first possible occasion\n (either in a function that is called or on the next line in the\n current function).\n\nn(ext)\n\n Continue execution until the next line in the current function is\n reached or it returns. (The difference between "next" and "step"\n is that "step" stops inside a called function, while "next"\n executes called functions at (nearly) full speed, only stopping at\n the next line in the current function.)\n\nunt(il) [lineno]\n\n Without argument, continue execution until the line with a number\n greater than the current one is reached.\n\n With a line number, continue execution until a line with a number\n greater or equal to that is reached. In both cases, also stop when\n the current frame returns.\n\n Changed in version 3.2: Allow giving an explicit line number.\n\nr(eturn)\n\n Continue execution until the current function returns.\n\nc(ont(inue))\n\n Continue execution, only stop when a breakpoint is encountered.\n\nj(ump) lineno\n\n Set the next line that will be executed. Only available in the\n bottom-most frame. This lets you jump back and execute code again,\n or jump forward to skip code that you don\'t want to run.\n\n It should be noted that not all jumps are allowed -- for instance\n it is not possible to jump into the middle of a "for" loop or out\n of a "finally" clause.\n\nl(ist) [first[, last]]\n\n List source code for the current file. Without arguments, list 11\n lines around the current line or continue the previous listing.\n With "." as argument, list 11 lines around the current line. With\n one argument, list 11 lines around at that line. With two\n arguments, list the given range; if the second argument is less\n than the first, it is interpreted as a count.\n\n The current line in the current frame is indicated by "->". If an\n exception is being debugged, the line where the exception was\n originally raised or propagated is indicated by ">>", if it differs\n from the current line.\n\n New in version 3.2: The ">>" marker.\n\nll | longlist\n\n List all source code for the current function or frame.\n Interesting lines are marked as for "list".\n\n New in version 3.2.\n\na(rgs)\n\n Print the argument list of the current function.\n\np expression\n\n Evaluate the *expression* in the current context and print its\n value.\n\n Note: "print()" can also be used, but is not a debugger command\n --- this executes the Python "print()" function.\n\npp expression\n\n Like the "p" command, except the value of the expression is pretty-\n printed using the "pprint" module.\n\nwhatis expression\n\n Print the type of the *expression*.\n\nsource expression\n\n Try to get source code for the given object and display it.\n\n New in version 3.2.\n\ndisplay [expression]\n\n Display the value of the expression if it changed, each time\n execution stops in the current frame.\n\n Without expression, list all display expressions for the current\n frame.\n\n New in version 3.2.\n\nundisplay [expression]\n\n Do not display the expression any more in the current frame.\n Without expression, clear all display expressions for the current\n frame.\n\n New in version 3.2.\n\ninteract\n\n Start an interative interpreter (using the "code" module) whose\n global namespace contains all the (global and local) names found in\n the current scope.\n\n New in version 3.2.\n\nalias [name [command]]\n\n Create an alias called *name* that executes *command*. The command\n must *not* be enclosed in quotes. Replaceable parameters can be\n indicated by "%1", "%2", and so on, while "%*" is replaced by all\n the parameters. If no command is given, the current alias for\n *name* is shown. If no arguments are given, all aliases are listed.\n\n Aliases may be nested and can contain anything that can be legally\n typed at the pdb prompt. Note that internal pdb commands *can* be\n overridden by aliases. Such a command is then hidden until the\n alias is removed. Aliasing is recursively applied to the first\n word of the command line; all other words in the line are left\n alone.\n\n As an example, here are two useful aliases (especially when placed\n in the ".pdbrc" file):\n\n # Print instance variables (usage "pi classInst")\n alias pi for k in %1.__dict__.keys(): print("%1.",k,"=",%1.__dict__[k])\n # Print instance variables in self\n alias ps pi self\n\nunalias name\n\n Delete the specified alias.\n\n! statement\n\n Execute the (one-line) *statement* in the context of the current\n stack frame. The exclamation point can be omitted unless the first\n word of the statement resembles a debugger command. To set a\n global variable, you can prefix the assignment command with a\n "global" statement on the same line, e.g.:\n\n (Pdb) global list_options; list_options = [\'-l\']\n (Pdb)\n\nrun [args ...]\nrestart [args ...]\n\n Restart the debugged Python program. If an argument is supplied,\n it is split with "shlex" and the result is used as the new\n "sys.argv". History, breakpoints, actions and debugger options are\n preserved. "restart" is an alias for "run".\n\nq(uit)\n\n Quit from the debugger. The program being executed is aborted.\n\n-[ Footnotes ]-\n\n[1] Whether a frame is considered to originate in a certain module\n is determined by the "__name__" in the frame globals.\n',
- 'del': u'\nThe "del" statement\n*******************\n\n del_stmt ::= "del" target_list\n\nDeletion is recursively defined very similar to the way assignment is\ndefined. Rather than spelling it out in full details, here are some\nhints.\n\nDeletion of a target list recursively deletes each target, from left\nto right.\n\nDeletion of a name removes the binding of that name from the local or\nglobal namespace, depending on whether the name occurs in a "global"\nstatement in the same code block. If the name is unbound, a\n"NameError" exception will be raised.\n\nDeletion of attribute references, subscriptions and slicings is passed\nto the primary object involved; deletion of a slicing is in general\nequivalent to assignment of an empty slice of the right type (but even\nthis is determined by the sliced object).\n\nChanged in version 3.2: Previously it was illegal to delete a name\nfrom the local namespace if it occurs as a free variable in a nested\nblock.\n',
- 'dict': u'\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 | "**" or_expr\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 double asterisk "**" denotes *dictionary unpacking*. Its operand\nmust be a *mapping*. Each mapping item is added to the new\ndictionary. Later values replace values already set by earlier\nkey/datum pairs and earlier dictionary unpackings.\n\nNew in version 3.5: Unpacking into dictionary displays, originally\nproposed by **PEP 448**.\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',
- 'dynamic-features': u'\nInteraction with dynamic features\n*********************************\n\nName resolution of free variables occurs at runtime, not at compile\ntime. This means that the following code will print 42:\n\n i = 10\n def f():\n print(i)\n i = 42\n f()\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\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',
- 'else': u'\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',
- 'exceptions': u'\nExceptions\n**********\n\nExceptions are a means of breaking out of the normal flow of control\nof a code block in order to handle errors or other exceptional\nconditions. An exception is *raised* at the point where the error is\ndetected; it may be *handled* by the surrounding code block or by any\ncode block that directly or indirectly invoked the code block where\nthe error occurred.\n\nThe Python interpreter raises an exception when it detects a run-time\nerror (such as division by zero). A Python program can also\nexplicitly raise an exception with the "raise" statement. Exception\nhandlers are specified with the "try" ... "except" statement. The\n"finally" clause of such a statement can be used to specify cleanup\ncode which does not handle the exception, but is executed whether an\nexception occurred or not in the preceding code.\n\nPython uses the "termination" model of error handling: an exception\nhandler can find out what happened and continue execution at an outer\nlevel, but it cannot repair the cause of the error and retry the\nfailing operation (except by re-entering the offending piece of code\nfrom the top).\n\nWhen an exception is not handled at all, the interpreter terminates\nexecution of the program, or returns to its interactive main loop. In\neither case, it prints a stack backtrace, except when the exception is\n"SystemExit".\n\nExceptions are identified by class instances. The "except" clause is\nselected depending on the class of the instance: it must reference the\nclass of the instance or a base class thereof. The instance can be\nreceived by the handler and can carry additional information about the\nexceptional condition.\n\nNote: Exception messages are not part of the Python API. Their\n contents may change from one version of Python to the next without\n warning and should not be relied on by code which will run under\n multiple versions of the interpreter.\n\nSee also the description of the "try" statement in section *The try\nstatement* and "raise" statement in section *The raise statement*.\n\n-[ Footnotes ]-\n\n[1] This limitation occurs because the code that is executed by\n these operations is not available at the time the module is\n compiled.\n',
- 'execmodel': u'\nExecution model\n***************\n\n\nStructure of a program\n======================\n\nA Python program is constructed from code blocks. A *block* is a piece\nof Python program text that is executed as a unit. The following are\nblocks: a module, a function body, and a class definition. Each\ncommand typed interactively is a block. A script file (a file given\nas standard input to the interpreter or specified as a command line\nargument to the interpreter) is a code block. A script command (a\ncommand specified on the interpreter command line with the \'**-c**\'\noption) is a code block. The string argument passed to the built-in\nfunctions "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\n\nNaming and binding\n==================\n\n\nBinding of names\n----------------\n\n*Names* refer to objects. Names are introduced by name binding\noperations.\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 after\n"as" in a "with" statement or "except" clause. The "import" statement\nof the form "from ... import *" binds all names defined in the\nimported module, except those beginning with an underscore. This form\nmay 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).\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 is bound in a block, it is a local variable of that block,\nunless declared as "nonlocal" or "global". If a name is bound at the\nmodule level, it is a global variable. (The variables of the module\ncode block are local and global.) If a variable is used in a code\nblock but not defined there, it is a *free variable*.\n\nEach occurrence of a name in the program text refers to the *binding*\nof that name established by the following name resolution rules.\n\n\nResolution of names\n-------------------\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.\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\nWhen a name is not found at all, a "NameError" exception is raised. If\nthe current scope is a function scope, and the name refers to a local\nvariable that has not yet been bound to a value at the point where the\nname is used, an "UnboundLocalError" exception is raised.\n"UnboundLocalError" is a subclass of "NameError".\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 name\nspecified in the statement refer to the binding of that name in the\ntop-level namespace. Names are resolved in the top-level namespace by\nsearching the global namespace, i.e. the namespace of the module\ncontaining the code block, and the builtins namespace, the namespace\nof the module "builtins". The global namespace is searched first. If\nthe name is not found there, the builtins namespace is searched. The\n"global" statement must precede all uses of the name.\n\nThe "global" statement has the same scope as a name binding operation\nin the same block. If the nearest enclosing scope for a free variable\ncontains a global statement, the free variable is treated as a global.\n\nThe "nonlocal" statement causes corresponding names to refer to\npreviously bound variables in the nearest enclosing function scope.\n"SyntaxError" is raised at compile time if the given name does not\nexist in any enclosing function scope.\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\nClass definition blocks and arguments to "exec()" and "eval()" are\nspecial in the context of name resolution. A class definition is an\nexecutable statement that may use and define names. These references\nfollow the normal rules for name resolution with an exception that\nunbound local variables are looked up in the global namespace. The\nnamespace of the class definition becomes the attribute dictionary of\nthe class. The scope of names defined in a class block is limited to\nthe class block; it does not extend to the code blocks of methods --\nthis includes comprehensions and generator expressions since they are\nimplemented using a function scope. This means that the following\nwill fail:\n\n class A:\n a = 42\n b = list(a + i for i in range(10))\n\n\nBuiltins and restricted execution\n---------------------------------\n\nThe builtins namespace associated with the execution of a code block\nis actually found by looking up the name "__builtins__" in its global\nnamespace; this should be a dictionary or a module (in the latter case\nthe module\'s dictionary is used). By default, when in the "__main__"\nmodule, "__builtins__" is the built-in module "builtins"; when in any\nother module, "__builtins__" is an alias for the dictionary of the\n"builtins" module itself. "__builtins__" can be set to a user-created\ndictionary to create a weak form of restricted execution.\n\n**CPython implementation detail:** Users should not touch\n"__builtins__"; it is strictly an implementation detail. Users\nwanting to override values in the builtins namespace should "import"\nthe "builtins" module and modify its attributes appropriately.\n\n\nInteraction with dynamic features\n---------------------------------\n\nName resolution of free variables occurs at runtime, not at compile\ntime. This means that the following code will print 42:\n\n i = 10\n def f():\n print(i)\n i = 42\n f()\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\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\n\nExceptions\n==========\n\nExceptions are a means of breaking out of the normal flow of control\nof a code block in order to handle errors or other exceptional\nconditions. An exception is *raised* at the point where the error is\ndetected; it may be *handled* by the surrounding code block or by any\ncode block that directly or indirectly invoked the code block where\nthe error occurred.\n\nThe Python interpreter raises an exception when it detects a run-time\nerror (such as division by zero). A Python program can also\nexplicitly raise an exception with the "raise" statement. Exception\nhandlers are specified with the "try" ... "except" statement. The\n"finally" clause of such a statement can be used to specify cleanup\ncode which does not handle the exception, but is executed whether an\nexception occurred or not in the preceding code.\n\nPython uses the "termination" model of error handling: an exception\nhandler can find out what happened and continue execution at an outer\nlevel, but it cannot repair the cause of the error and retry the\nfailing operation (except by re-entering the offending piece of code\nfrom the top).\n\nWhen an exception is not handled at all, the interpreter terminates\nexecution of the program, or returns to its interactive main loop. In\neither case, it prints a stack backtrace, except when the exception is\n"SystemExit".\n\nExceptions are identified by class instances. The "except" clause is\nselected depending on the class of the instance: it must reference the\nclass of the instance or a base class thereof. The instance can be\nreceived by the handler and can carry additional information about the\nexceptional condition.\n\nNote: Exception messages are not part of the Python API. Their\n contents may change from one version of Python to the next without\n warning and should not be relied on by code which will run under\n multiple versions of the interpreter.\n\nSee also the description of the "try" statement in section *The try\nstatement* and "raise" statement in section *The raise statement*.\n\n-[ Footnotes ]-\n\n[1] This limitation occurs because the code that is executed by\n these operations is not available at the time the module is\n compiled.\n',
- 'exprlists': u'\nExpression lists\n****************\n\n expression_list ::= expression ( "," expression )* [","]\n starred_list ::= starred_item ( "," starred_item )* [","]\n starred_expression ::= expression | ( starred_item "," )* [starred_item]\n starred_item ::= expression | "*" or_expr\n\nExcept when part of a list or set display, an expression list\ncontaining at least one comma yields a tuple. The length of the tuple\nis the number of expressions in the list. The expressions are\nevaluated from left to right.\n\nAn asterisk "*" denotes *iterable unpacking*. Its operand must be an\n*iterable*. The iterable is expanded into a sequence of items, which\nare included in the new tuple, list, or set, at the site of the\nunpacking.\n\nNew in version 3.5: Iterable unpacking in expression lists, originally\nproposed by **PEP 448**.\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': u'\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 number\nas "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': u'\nThe "for" statement\n*******************\n\nThe "for" statement is used to iterate over the elements of a sequence\n(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 returned by the iterator. 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" exception),\nthe suite in the "else" clause, if present, is executed, and the loop\nterminates.\n\nA "break" statement executed in the first suite terminates the loop\nwithout executing the "else" clause\'s suite. A "continue" statement\nexecuted in the first suite skips the rest of the suite and continues\nwith the next item, or with the "else" clause if there is no next\nitem.\n\nThe for-loop makes assignments to the variables(s) in the target list.\nThis overwrites all previous assignments to those variables including\nthose made in the suite of the for-loop:\n\n for i in range(10):\n print(i)\n i = 5 # this will not affect the for-loop\n # because i will be overwritten with the next\n # index in the range\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, they will not have been assigned to at\nall by the loop. Hint: the built-in function "range()" returns an\niterator of integers suitable to emulate the effect of Pascal\'s "for i\n:= a to b do"; e.g., "list(range(3))" returns the list "[0, 1, 2]".\n\nNote: There is a subtlety when the sequence is being modified by the\n loop (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': u'\nFormat String Syntax\n********************\n\nThe "str.format()" method and the "Formatter" class share the same\nsyntax for format strings (although in the case of "Formatter",\nsubclasses can define their own format string syntax).\n\nFormat strings contain "replacement fields" surrounded by curly braces\n"{}". Anything that is not contained in braces is considered literal\ntext, which is copied unchanged to the output. If you need to include\na brace character in the literal text, it can be escaped by doubling:\n"{{" and "}}".\n\nThe grammar for a replacement field is as follows:\n\n replacement_field ::= "{" [field_name] ["!" conversion] [":" format_spec] "}"\n field_name ::= arg_name ("." attribute_name | "[" element_index "]")*\n arg_name ::= [identifier | integer]\n attribute_name ::= identifier\n element_index ::= integer | index_string\n index_string ::= <any source character except "]"> +\n conversion ::= "r" | "s" | "a"\n format_spec ::= <described in the next section>\n\nIn less formal terms, the replacement field can start with a\n*field_name* that specifies the object whose value is to be formatted\nand inserted into the output instead of the replacement field. The\n*field_name* is optionally followed by a *conversion* field, which is\npreceded by an exclamation point "\'!\'", and a *format_spec*, which is\npreceded by a colon "\':\'". These specify a non-default format for the\nreplacement value.\n\nSee also the *Format Specification Mini-Language* section.\n\nThe *field_name* itself begins with an *arg_name* that is either a\nnumber or a keyword. If it\'s a number, it refers to a positional\nargument, and if it\'s a keyword, it refers to a named keyword\nargument. If the numerical arg_names in a format string are 0, 1, 2,\n... in sequence, they can all be omitted (not just some) and the\nnumbers 0, 1, 2, ... will be automatically inserted in that order.\nBecause *arg_name* is not quote-delimited, it is not possible to\nspecify arbitrary dictionary keys (e.g., the strings "\'10\'" or\n"\':-]\'") within a format string. The *arg_name* can be followed by any\nnumber of index or attribute expressions. An expression of the form\n"\'.name\'" selects the named attribute using "getattr()", while an\nexpression of the form "\'[index]\'" does an index lookup using\n"__getitem__()".\n\nChanged in version 3.1: The positional argument specifiers can be\nomitted, so "\'{} {}\'" is equivalent to "\'{0} {1}\'".\n\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\n "Bring me a {}" # Implicitly references the first positional argument\n "From {} to {}" # Same as "From {0} to {1}"\n "My quest is {name}" # References keyword argument \'name\'\n "Weight in tons {0.weight}" # \'weight\' attribute of first positional arg\n "Units destroyed: {players[0]}" # First element of keyword argument \'players\'.\n\nThe *conversion* field causes a type coercion before formatting.\nNormally, the job of formatting a value is done by the "__format__()"\nmethod of the value itself. However, in some cases it is desirable to\nforce a type to be formatted as a string, overriding its own\ndefinition of formatting. By converting the value to a string before\ncalling "__format__()", the normal formatting logic is bypassed.\n\nThree conversion flags are currently supported: "\'!s\'" which calls\n"str()" on the value, "\'!r\'" which calls "repr()" and "\'!a\'" which\ncalls "ascii()".\n\nSome examples:\n\n "Harold\'s a clever {0!s}" # Calls str() on the argument first\n "Bring out the holy {name!r}" # Calls repr() on the argument first\n "More {!a}" # Calls ascii() on the argument first\n\nThe *format_spec* field contains a specification of how the value\nshould be presented, including such details as field width, alignment,\npadding, decimal precision and so on. Each value type can define its\nown "formatting mini-language" or interpretation of the *format_spec*.\n\nMost built-in types support a common formatting mini-language, which\nis described in the next section.\n\nA *format_spec* field can also include nested replacement fields\nwithin it. These nested replacement fields may contain a field name,\nconversion flag and format specification, but deeper nesting is not\nallowed. The replacement fields within the format_spec are\nsubstituted before the *format_spec* string is interpreted. This\nallows the formatting of a value to be dynamically specified.\n\nSee the *Format examples* section for some examples.\n\n\nFormat Specification Mini-Language\n==================================\n\n"Format specifications" are used within replacement fields contained\nwithin a format string to define how individual values are presented\n(see *Format String Syntax*). They can also be passed directly to the\nbuilt-in "format()" function. Each formattable type may define how\nthe format specification is to be interpreted.\n\nMost built-in types implement the following options for format\nspecifications, although some of the formatting options are only\nsupported by the numeric types.\n\nA general convention is that an empty format string ("""") produces\nthe same result as if you had called "str()" on the value. A non-empty\nformat string typically modifies the result.\n\nThe general form of a *standard format specifier* is:\n\n format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]\n fill ::= <any character>\n align ::= "<" | ">" | "=" | "^"\n sign ::= "+" | "-" | " "\n width ::= integer\n precision ::= integer\n type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n\nIf a valid *align* value is specified, it can be preceded by a *fill*\ncharacter that can be any character and defaults to a space if\nomitted. It is not possible to use a literal curly brace (""{"" or\n""}"") as the *fill* character when using the "str.format()" method.\nHowever, it is possible to insert a curly brace with a nested\nreplacement field. This limitation doesn\'t affect the "format()"\nfunction.\n\nThe meaning of the various alignment options is as follows:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | "\'<\'" | Forces the field to be left-aligned within the available |\n | | space (this is the default for most objects). |\n +-----------+------------------------------------------------------------+\n | "\'>\'" | Forces the field to be right-aligned within the available |\n | | space (this is the default for numbers). |\n +-----------+------------------------------------------------------------+\n | "\'=\'" | Forces the padding to be placed after the sign (if any) |\n | | but before the digits. This is used for printing fields |\n | | in the form \'+000000120\'. This alignment option is only |\n | | valid for numeric types. It becomes the default when \'0\' |\n | | immediately precedes the field width. |\n +-----------+------------------------------------------------------------+\n | "\'^\'" | Forces the field to be centered within the available |\n | | space. |\n +-----------+------------------------------------------------------------+\n\nNote that unless a minimum field width is defined, the field width\nwill always be the same size as the data to fill it, so that the\nalignment option has no meaning in this case.\n\nThe *sign* option is only valid for number types, and can be one of\nthe following:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | "\'+\'" | indicates that a sign should be used for both positive as |\n | | well as negative numbers. |\n +-----------+------------------------------------------------------------+\n | "\'-\'" | indicates that a sign should be used only for negative |\n | | numbers (this is the default behavior). |\n +-----------+------------------------------------------------------------+\n | space | indicates that a leading space should be used on positive |\n | | numbers, and a minus sign on negative numbers. |\n +-----------+------------------------------------------------------------+\n\nThe "\'#\'" option causes the "alternate form" to be used for the\nconversion. The alternate form is defined differently for different\ntypes. This option is only valid for integer, float, complex and\nDecimal types. For integers, when binary, octal, or hexadecimal output\nis used, this option adds the prefix respective "\'0b\'", "\'0o\'", or\n"\'0x\'" to the output value. For floats, complex and Decimal the\nalternate form causes the result of the conversion to always contain a\ndecimal-point character, even if no digits follow it. Normally, a\ndecimal-point character appears in the result of these conversions\nonly if a digit follows it. In addition, for "\'g\'" and "\'G\'"\nconversions, trailing zeros are not removed from the result.\n\nThe "\',\'" option signals the use of a comma for a thousands separator.\nFor a locale aware separator, use the "\'n\'" integer presentation type\ninstead.\n\nChanged in version 3.1: Added the "\',\'" option (see also **PEP 378**).\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\nWhen no explicit alignment is given, preceding the *width* field by a\nzero ("\'0\'") character enables sign-aware zero-padding for numeric\ntypes. This is equivalent to a *fill* character of "\'0\'" with an\n*alignment* type of "\'=\'".\n\nThe *precision* is a decimal number indicating how many digits should\nbe displayed after the decimal point for a floating point value\nformatted with "\'f\'" and "\'F\'", or before and after the decimal point\nfor a floating point value formatted with "\'g\'" or "\'G\'". For non-\nnumber 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 not allowed for integer values.\n\nFinally, the *type* determines how the data should be presented.\n\nThe available string presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | "\'s\'" | String format. This is the default type for strings and |\n | | may be omitted. |\n +-----------+------------------------------------------------------------+\n | None | The same as "\'s\'". |\n +-----------+------------------------------------------------------------+\n\nThe available integer presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | "\'b\'" | Binary format. Outputs the number in base 2. |\n +-----------+------------------------------------------------------------+\n | "\'c\'" | Character. Converts the integer to the corresponding |\n | | unicode character before printing. |\n +-----------+------------------------------------------------------------+\n | "\'d\'" | Decimal Integer. Outputs the number in base 10. |\n +-----------+------------------------------------------------------------+\n | "\'o\'" | Octal format. Outputs the number in base 8. |\n +-----------+------------------------------------------------------------+\n | "\'x\'" | Hex format. Outputs the number in base 16, using lower- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | "\'X\'" | Hex format. Outputs the number in base 16, using upper- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | "\'n\'" | Number. This is the same as "\'d\'", except that it uses the |\n | | current locale setting to insert the appropriate number |\n | | separator characters. |\n +-----------+------------------------------------------------------------+\n | None | The same as "\'d\'". |\n +-----------+------------------------------------------------------------+\n\nIn addition to the above presentation types, integers can be formatted\nwith the floating point presentation types listed below (except "\'n\'"\nand None). When doing so, "float()" is used to convert the integer to\na floating point number before formatting.\n\nThe available presentation types for floating point and decimal values\nare:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | "\'e\'" | Exponent notation. Prints the number in scientific |\n | | notation using the letter \'e\' to indicate the exponent. |\n | | The default precision is "6". |\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 | | The default precision is "6". |\n +-----------+------------------------------------------------------------+\n | "\'F\'" | Fixed point. Same as "\'f\'", but converts "nan" to "NAN" |\n | | and "inf" to "INF". |\n +-----------+------------------------------------------------------------+\n | "\'g\'" | General format. For a given precision "p >= 1", this |\n | | rounds the number to "p" significant digits and then |\n | | formats the result in either fixed-point format or in |\n | | scientific notation, depending on its magnitude. The |\n | | precise rules are as follows: suppose that the result |\n | | formatted with presentation type "\'e\'" and precision "p-1" |\n | | would have exponent "exp". Then if "-4 <= exp < p", the |\n | | number is formatted with presentation type "\'f\'" and |\n | | precision "p-1-exp". Otherwise, the number is formatted |\n | | with presentation type "\'e\'" and precision "p-1". In both |\n | | cases insignificant trailing zeros are removed from the |\n | | significand, and the decimal point is also removed if |\n | | there are no remaining digits following it. Positive and |\n | | negative infinity, positive and negative zero, and nans, |\n | | are formatted as "inf", "-inf", "0", "-0" and "nan" |\n | | respectively, regardless of the precision. A precision of |\n | | "0" is treated as equivalent to a precision of "1". The |\n | | default precision is "6". |\n +-----------+------------------------------------------------------------+\n | "\'G\'" | General format. Same as "\'g\'" except switches to "\'E\'" if |\n | | the number gets too large. The representations of infinity |\n | | and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | "\'n\'" | Number. This is the same as "\'g\'", except that it uses the |\n | | current locale setting to insert the appropriate number |\n | | separator characters. |\n +-----------+------------------------------------------------------------+\n | "\'%\'" | Percentage. Multiplies the number by 100 and displays in |\n | | fixed ("\'f\'") format, followed by a percent sign. |\n +-----------+------------------------------------------------------------+\n | None | Similar to "\'g\'", except that fixed-point notation, when |\n | | used, has at least one digit past the decimal point. The |\n | | default precision is as high as needed to represent the |\n | | particular value. The overall effect is to match the |\n | | output of "str()" as altered by the other format |\n | | modifiers. |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the "str.format()" syntax and\ncomparison with the old "%"-formatting.\n\nIn most of the cases the syntax is similar to the old "%"-formatting,\nwith the addition of the "{}" and with ":" used instead of "%". For\nexample, "\'%03.2f\'" can be translated to "\'{:03.2f}\'".\n\nThe new format syntax also supports new and different options, shown\nin the follow examples.\n\nAccessing arguments by position:\n\n >>> \'{0}, {1}, {2}\'.format(\'a\', \'b\', \'c\')\n \'a, b, c\'\n >>> \'{}, {}, {}\'.format(\'a\', \'b\', \'c\') # 3.1+ only\n \'a, b, c\'\n >>> \'{2}, {1}, {0}\'.format(\'a\', \'b\', \'c\')\n \'c, b, a\'\n >>> \'{2}, {1}, {0}\'.format(*\'abc\') # unpacking argument sequence\n \'c, b, a\'\n >>> \'{0}{1}{0}\'.format(\'abra\', \'cad\') # arguments\' indices can be repeated\n \'abracadabra\'\n\nAccessing arguments by name:\n\n >>> \'Coordinates: {latitude}, {longitude}\'.format(latitude=\'37.24N\', longitude=\'-115.81W\')\n \'Coordinates: 37.24N, -115.81W\'\n >>> coord = {\'latitude\': \'37.24N\', \'longitude\': \'-115.81W\'}\n >>> \'Coordinates: {latitude}, {longitude}\'.format(**coord)\n \'Coordinates: 37.24N, -115.81W\'\n\nAccessing arguments\' attributes:\n\n >>> c = 3-5j\n >>> (\'The complex number {0} is formed from the real part {0.real} \'\n ... \'and the imaginary part {0.imag}.\').format(c)\n \'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.\'\n >>> class Point:\n ... def __init__(self, x, y):\n ... self.x, self.y = x, y\n ... def __str__(self):\n ... return \'Point({self.x}, {self.y})\'.format(self=self)\n ...\n >>> str(Point(4, 2))\n \'Point(4, 2)\'\n\nAccessing arguments\' items:\n\n >>> coord = (3, 5)\n >>> \'X: {0[0]}; Y: {0[1]}\'.format(coord)\n \'X: 3; Y: 5\'\n\nReplacing "%s" and "%r":\n\n >>> "repr() shows quotes: {!r}; str() doesn\'t: {!s}".format(\'test1\', \'test2\')\n "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n\nAligning the text and specifying a width:\n\n >>> \'{:<30}\'.format(\'left aligned\')\n \'left aligned \'\n >>> \'{:>30}\'.format(\'right aligned\')\n \' right aligned\'\n >>> \'{:^30}\'.format(\'centered\')\n \' centered \'\n >>> \'{:*^30}\'.format(\'centered\') # use \'*\' as a fill char\n \'***********centered***********\'\n\nReplacing "%+f", "%-f", and "% f" and specifying a sign:\n\n >>> \'{:+f}; {:+f}\'.format(3.14, -3.14) # show it always\n \'+3.140000; -3.140000\'\n >>> \'{: f}; {: f}\'.format(3.14, -3.14) # show a space for positive numbers\n \' 3.140000; -3.140000\'\n >>> \'{:-f}; {:-f}\'.format(3.14, -3.14) # show only the minus -- same as \'{:f}; {:f}\'\n \'3.140000; -3.140000\'\n\nReplacing "%x" and "%o" and converting the value to different bases:\n\n >>> # format also supports binary numbers\n >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)\n \'int: 42; hex: 2a; oct: 52; bin: 101010\'\n >>> # with 0x, 0o, or 0b as prefix:\n >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)\n \'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010\'\n\nUsing the comma as a thousands separator:\n\n >>> \'{:,}\'.format(1234567890)\n \'1,234,567,890\'\n\nExpressing a percentage:\n\n >>> points = 19\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 86.36%\'\n\nUsing type-specific formatting:\n\n >>> import datetime\n >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n >>> \'{:%Y-%m-%d %H:%M:%S}\'.format(d)\n \'2010-07-04 12:15:58\'\n\nNesting arguments and more complex examples:\n\n >>> for align, text in zip(\'<^>\', [\'left\', \'center\', \'right\']):\n ... \'{0:{fill}{align}16}\'.format(text, fill=align, align=align)\n ...\n \'left<<<<<<<<<<<<\'\n \'^^^^^center^^^^^\'\n \'>>>>>>>>>>>right\'\n >>>\n >>> octets = [192, 168, 0, 1]\n >>> \'{:02X}{:02X}{:02X}{:02X}\'.format(*octets)\n \'C0A80001\'\n >>> int(_, 16)\n 3232235521\n >>>\n >>> width = 5\n >>> for num in range(5,12): #doctest: +NORMALIZE_WHITESPACE\n ... for base in \'dXob\':\n ... print(\'{0:{width}{base}}\'.format(num, base=base, width=width), end=\' \')\n ... print()\n ...\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 8 10 1000\n 9 9 11 1001\n 10 A 12 1010\n 11 B 13 1011\n',
- 'function': u'\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)* ["," "**" 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 --- this\nis a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated from left to right when the\nfunction definition is executed.** This means that the expression is\nevaluated once, when the function is defined, and that the same "pre-\ncomputed" value is used for each call. This is especially important\nto understand when a default parameter is a mutable object, such as a\nlist or a dictionary: if the function modifies the object (e.g. by\nappending an item to a list), the default value is in effect modified.\nThis is generally not what was intended. A way around this is to use\n"None" as the default, and explicitly test for it in the body of the\nfunction, 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 any\nexcess positional parameters, defaulting to the empty tuple. If the\nform ""**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"" following\nthe parameter name. Any parameter may have an annotation even those\nof the form "*identifier" or "**identifier". Functions may have\n"return" annotation of the form ""-> expression"" after the parameter\nlist. These annotations can be any valid Python expression and are\nevaluated when the function definition is executed. Annotations may\nbe evaluated in a different order than they appear in the source code.\nThe presence of annotations does not change the semantics of a\nfunction. The annotation values are available as values of a\ndictionary keyed by the parameters\' names in the "__annotations__"\nattribute 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\nexpressions, described in section *Lambdas*. Note that the lambda\nexpression is merely a shorthand for a simplified function definition;\na function defined in a ""def"" statement can be passed around or\nassigned to another name just like a function defined by a lambda\nexpression. The ""def"" form is actually more powerful since it\nallows the execution of multiple statements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A ""def""\nstatement executed inside a function definition defines a local\nfunction that can be returned or passed around. Free variables used\nin the nested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also: **PEP 3107** - Function Annotations\n\n The original specification for function annotations.\n',
- 'global': u'\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 code\nblock textually preceding that "global" statement.\n\nNames listed in a "global" statement must not be defined as formal\nparameters or in a "for" loop control target, "class" definition,\nfunction definition, or "import" statement.\n\n**CPython implementation detail:** The current implementation does not\nenforce the two restrictions, but programs should not abuse this\nfreedom, as future implementations may enforce them or silently change\nthe meaning of the program.\n\n**Programmer\'s note:** the "global" is a directive to the parser. It\napplies only to code parsed at the same time as the "global"\nstatement. In particular, a "global" statement contained in a string\nor code object supplied to the built-in "exec()" function does not\naffect the code block *containing* the function call, and code\ncontained in such a string is unaffected by "global" statements in the\ncode containing the function call. The same applies to the "eval()"\nand "compile()" functions.\n',
- 'id-classes': u'\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 the\n last evaluation; it is stored in the "builtins" module. When not\n in interactive mode, "_" has no special meaning and is not defined.\n See section *The import statement*.\n\n Note: The name "_" is often used in conjunction with\n internationalization; refer to the documentation for the\n "gettext" module for more information on this convention.\n\n"__*__"\n System-defined names. These names are defined by the interpreter\n and its implementation (including the standard library). Current\n system names are discussed in the *Special method names* section\n and elsewhere. More will likely be defined in future versions of\n Python. *Any* use of "__*__" names, in any context, that does not\n follow explicitly documented use, is subject to breakage without\n warning.\n\n"__*"\n Class-private names. Names in this category, when used within the\n context of a class definition, are re-written to use a mangled form\n to help avoid name clashes between "private" attributes of base and\n derived classes. See section *Identifiers (Names)*.\n',
- 'identifiers': u'\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 first\ncharacter, the digits "0" through "9".\n\nPython 3.0 introduces additional characters from outside the ASCII\nrange (see **PEP 3131**). For these characters, the classification\nuses the version of the Unicode Character Database as included in the\n"unicodedata" module.\n\nIdentifiers are unlimited in length. Case is significant.\n\n identifier ::= xid_start xid_continue*\n id_start ::= <all characters in general categories Lu, Ll, Lt, Lm, Lo, Nl, the underscore, and characters with the Other_ID_Start property>\n id_continue ::= <all characters in id_start, plus characters in the categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property>\n xid_start ::= <all characters in id_start whose NFKC normalization is in "id_start xid_continue*">\n xid_continue ::= <all characters in id_continue whose NFKC normalization is in "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\n* *Other_ID_Start* - explicit list of characters in PropList.txt to\n support backwards compatibility\n\n* *Other_ID_Continue* - likewise\n\nAll identifiers are converted into the normal form NFKC while parsing;\ncomparison of identifiers is based on NFKC.\n\nA non-normative HTML file listing all valid identifier characters for\nUnicode 4.1 can be found at https://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 the\n last evaluation; it is stored in the "builtins" module. When not\n in interactive mode, "_" has no special meaning and is not defined.\n See section *The import statement*.\n\n Note: The name "_" is often used in conjunction with\n internationalization; refer to the documentation for the\n "gettext" module for more information on this convention.\n\n"__*__"\n System-defined names. These names are defined by the interpreter\n and its implementation (including the standard library). Current\n system names are discussed in the *Special method names* section\n and elsewhere. More will likely be defined in future versions of\n Python. *Any* use of "__*__" names, in any context, that does not\n follow explicitly documented use, is subject to breakage without\n warning.\n\n"__*"\n Class-private names. Names in this category, when used within the\n context of a class definition, are re-written to use a mangled form\n to help avoid name clashes between "private" attributes of base and\n derived classes. See section *Identifiers (Names)*.\n',
- 'if': u'\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': u'\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': u'\nThe "import" statement\n**********************\n\n import_stmt ::= "import" module ["as" name] ( "," module ["as" name] )*\n | "from" relative_module "import" identifier ["as" name]\n ( "," identifier ["as" name] )*\n | "from" relative_module "import" "(" identifier ["as" name]\n ( "," identifier ["as" name] )* [","] ")"\n | "from" module "import" "*"\n module ::= (identifier ".")* identifier\n relative_module ::= "."* module | "."+\n name ::= identifier\n\nThe basic import statement (no "from" clause) is executed in two\nsteps:\n\n1. find a module, loading and initializing it if necessary\n\n2. define a name or names in the local namespace for the scope\n where the "import" statement occurs.\n\nWhen the statement contains multiple clauses (separated by commas) the\ntwo steps are carried out separately for each clause, just as though\nthe clauses had been separated out into individual import statements.\n\nThe details of the first step, finding and loading modules are\ndescribed in greater detail in the section on the *import system*,\nwhich also describes the various types of packages and modules that\ncan be imported, as well as all the hooks that can be used to\ncustomize the import system. Note that failures in this step may\nindicate either that the module could not be located, *or* that an\nerror occurred while initializing the module, which includes execution\nof the module\'s code.\n\nIf the requested module is retrieved successfully, it will be made\navailable in the local namespace in one of three ways:\n\n* If the module name is followed by "as", then the name following\n "as" is bound directly to the imported module.\n\n* If no other name is specified, and the module being imported is a\n top level module, the module\'s name is bound in the local namespace\n as a reference to the imported module\n\n* If the module being imported is *not* a top level module, then the\n name of the top level package that contains the module is bound in\n the local namespace as a reference to the top level package. The\n imported module must be accessed using its full qualified name\n rather than directly\n\nThe "from" form uses a slightly more complex process:\n\n1. find the module specified in the "from" clause, loading and\n initializing it if necessary;\n\n2. for each of the identifiers specified in the "import" clauses:\n\n 1. check if the imported module has an attribute by that name\n\n 2. if not, attempt to import a submodule with that name and then\n check the imported module again for that attribute\n\n 3. if the attribute is not found, "ImportError" is raised.\n\n 4. otherwise, a reference to that value is stored in the local\n namespace, using the name in the "as" clause if it is present,\n otherwise using the attribute name\n\nExamples:\n\n import foo # foo imported and bound locally\n import foo.bar.baz # foo.bar.baz imported, foo bound locally\n import foo.bar.baz as fbb # foo.bar.baz imported and bound as fbb\n from foo.bar import baz # foo.bar.baz imported and bound as baz\n from foo import attr # foo imported and foo.attr bound as attr\n\nIf the list of identifiers is replaced by a star ("\'*\'"), all public\nnames defined in the module are bound in the local namespace for the\nscope where the "import" statement occurs.\n\nThe *public names* defined by a module are determined by checking the\nmodule\'s namespace for a variable named "__all__"; if defined, it must\nbe a sequence of strings which are names defined or imported by that\nmodule. The names given in "__all__" are all considered public and\nare required to exist. If "__all__" is not defined, the set of public\nnames includes all names found in the module\'s namespace which do not\nbegin with an underscore character ("\'_\'"). "__all__" should contain\nthe entire public API. It is intended to avoid accidentally exporting\nitems that are not part of the API (such as library modules which were\nimported and used within the module).\n\nThe wild card form of import --- "from module import *" --- is only\nallowed at the module level. Attempting to use it in class or\nfunction definitions will raise a "SyntaxError".\n\nWhen specifying what module to import you do not have to specify the\nabsolute name of the module. When a module or package is contained\nwithin another package it is possible to make a relative import within\nthe same top package without having to mention the package name. By\nusing leading dots in the specified module or package after "from" you\ncan specify how high to traverse up the current package hierarchy\nwithout specifying exact names. One leading dot means the current\npackage where the module making the import exists. Two dots means up\none package level. Three dots is up two levels, etc. So if you execute\n"from . import mod" from a module in the "pkg" package then you will\nend up importing "pkg.mod". If you execute "from ..subpkg2 import mod"\nfrom within "pkg.subpkg1" you will import "pkg.subpkg2.mod". The\nspecification for relative imports is contained within **PEP 328**.\n\n"importlib.import_module()" is provided to support applications that\ndetermine dynamically the modules to be loaded.\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 where the feature\nbecomes standard.\n\nThe future statement is intended to ease migration to future versions\nof Python that introduce incompatible changes to the language. It\nallows use of the new features on a per-module basis before the\nrelease in which the feature becomes standard.\n\n future_statement ::= "from" "__future__" "import" feature ["as" name]\n ("," feature ["as" name])*\n | "from" "__future__" "import" "(" feature ["as" name]\n ("," feature ["as" name])* [","] ")"\n feature ::= identifier\n name ::= identifier\n\nA future statement must appear near the top of the module. The only\nlines that can appear before a future statement are:\n\n* the module docstring (if any),\n\n* comments,\n\n* blank lines, and\n\n* other future statements.\n\nThe features recognized by Python 3.0 are "absolute_import",\n"division", "generators", "unicode_literals", "print_function",\n"nested_scopes" and "with_statement". They are all redundant because\nthey are always enabled, 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 will\nbe imported in the usual way at the time the future statement is\nexecuted.\n\nThe interesting runtime semantics depend on the specific feature\nenabled by the future statement.\n\nNote that there is nothing special about the statement:\n\n import __future__ [as name]\n\nThat is not a future statement; it\'s an ordinary import statement with\nno special semantics or syntax restrictions.\n\nCode compiled by calls to the built-in functions "exec()" and\n"compile()" that occur in a module "M" containing a future statement\nwill, by default, use the new syntax or semantics associated with the\nfuture statement. This can be controlled by optional arguments to\n"compile()" --- see the documentation of that function for details.\n\nA future statement typed at an interactive interpreter prompt will\ntake effect for the rest of the interpreter session. If an\ninterpreter is started with the *-i* option, is passed a script name\nto execute, and the script includes a future statement, it will be in\neffect in the interactive session started after the script is\nexecuted.\n\nSee also: **PEP 236** - Back to the __future__\n\n The original proposal for the __future__ mechanism.\n',
- 'in': u'\nMembership test operations\n**************************\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" tests\nwhether the dictionary has a given key. For container types such as\nlist, tuple, set, frozenset, dict, or collections.deque, the\nexpression "x in y" is equivalent to "any(x is e or x == e for e in\ny)".\n\nFor the string and bytes types, "x in y" is true if and only if *x* is\na substring of *y*. An equivalent test is "y.find(x) != -1". Empty\nstrings are always considered to be a substring of any other string,\nso """ in "abc"" will return "True".\n\nFor user-defined classes which define the "__contains__()" method, "x\nin y" is true if and only if "y.__contains__(x)" is true.\n\nFor user-defined classes which do not define "__contains__()" but do\ndefine "__iter__()", "x in y" is true if some value "z" with "x == z"\nis produced while iterating over "y". If an exception is raised\nduring the iteration, it is as if "in" raised that exception.\n\nLastly, the old-style iteration protocol is tried: if a class defines\n"__getitem__()", "x in y" is true if and only if there is a non-\nnegative integer index *i* such that "x == y[i]", and all lower\ninteger indices do not raise "IndexError" exception. (If any other\nexception is raised, it is as if "in" raised that exception).\n\nThe operator "not in" is defined to have the inverse true value of\n"in".\n',
- 'integers': u'\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 0xdeadbeef\n',
- 'lambda': u'\nLambdas\n*******\n\n lambda_expr ::= "lambda" [parameter_list]: expression\n lambda_expr_nocond ::= "lambda" [parameter_list]: expression_nocond\n\nLambda expressions (sometimes called lambda forms) are used to create\nanonymous functions. The expression "lambda arguments: expression"\nyields a function object. The unnamed object behaves like a function\nobject defined with\n\n def <lambda>(arguments):\n return expression\n\nSee section *Function definitions* for the syntax of parameter lists.\nNote that functions created with lambda expressions cannot contain\nstatements or annotations.\n',
- 'lists': u'\nList displays\n*************\n\nA list display is a possibly empty series of expressions enclosed in\nsquare brackets:\n\n list_display ::= "[" [starred_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': u'\nNaming and binding\n******************\n\n\nBinding of names\n================\n\n*Names* refer to objects. Names are introduced by name binding\noperations.\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 after\n"as" in a "with" statement or "except" clause. The "import" statement\nof the form "from ... import *" binds all names defined in the\nimported module, except those beginning with an underscore. This form\nmay 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).\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 is bound in a block, it is a local variable of that block,\nunless declared as "nonlocal" or "global". If a name is bound at the\nmodule level, it is a global variable. (The variables of the module\ncode block are local and global.) If a variable is used in a code\nblock but not defined there, it is a *free variable*.\n\nEach occurrence of a name in the program text refers to the *binding*\nof that name established by the following name resolution rules.\n\n\nResolution of names\n===================\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.\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\nWhen a name is not found at all, a "NameError" exception is raised. If\nthe current scope is a function scope, and the name refers to a local\nvariable that has not yet been bound to a value at the point where the\nname is used, an "UnboundLocalError" exception is raised.\n"UnboundLocalError" is a subclass of "NameError".\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 name\nspecified in the statement refer to the binding of that name in the\ntop-level namespace. Names are resolved in the top-level namespace by\nsearching the global namespace, i.e. the namespace of the module\ncontaining the code block, and the builtins namespace, the namespace\nof the module "builtins". The global namespace is searched first. If\nthe name is not found there, the builtins namespace is searched. The\n"global" statement must precede all uses of the name.\n\nThe "global" statement has the same scope as a name binding operation\nin the same block. If the nearest enclosing scope for a free variable\ncontains a global statement, the free variable is treated as a global.\n\nThe "nonlocal" statement causes corresponding names to refer to\npreviously bound variables in the nearest enclosing function scope.\n"SyntaxError" is raised at compile time if the given name does not\nexist in any enclosing function scope.\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\nClass definition blocks and arguments to "exec()" and "eval()" are\nspecial in the context of name resolution. A class definition is an\nexecutable statement that may use and define names. These references\nfollow the normal rules for name resolution with an exception that\nunbound local variables are looked up in the global namespace. The\nnamespace of the class definition becomes the attribute dictionary of\nthe class. The scope of names defined in a class block is limited to\nthe class block; it does not extend to the code blocks of methods --\nthis includes comprehensions and generator expressions since they are\nimplemented using a function scope. This means that the following\nwill fail:\n\n class A:\n a = 42\n b = list(a + i for i in range(10))\n\n\nBuiltins and restricted execution\n=================================\n\nThe builtins namespace associated with the execution of a code block\nis actually found by looking up the name "__builtins__" in its global\nnamespace; this should be a dictionary or a module (in the latter case\nthe module\'s dictionary is used). By default, when in the "__main__"\nmodule, "__builtins__" is the built-in module "builtins"; when in any\nother module, "__builtins__" is an alias for the dictionary of the\n"builtins" module itself. "__builtins__" can be set to a user-created\ndictionary to create a weak form of restricted execution.\n\n**CPython implementation detail:** Users should not touch\n"__builtins__"; it is strictly an implementation detail. Users\nwanting to override values in the builtins namespace should "import"\nthe "builtins" module and modify its attributes appropriately.\n\n\nInteraction with dynamic features\n=================================\n\nName resolution of free variables occurs at runtime, not at compile\ntime. This means that the following code will print 42:\n\n i = 10\n def f():\n print(i)\n i = 42\n f()\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\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',
- 'nonlocal': u'\nThe "nonlocal" statement\n************************\n\n nonlocal_stmt ::= "nonlocal" identifier ("," identifier)*\n\nThe "nonlocal" statement causes the listed identifiers to refer to\npreviously bound variables in the nearest enclosing scope excluding\nglobals. This is important because the default behavior for binding is\nto search the local namespace first. The statement allows\nencapsulated code to rebind variables outside of the local scope\nbesides the global (module) scope.\n\nNames listed in a "nonlocal" statement, unlike those listed in a\n"global" statement, must refer to pre-existing bindings in an\nenclosing scope (the scope in which a new binding should be created\ncannot be determined unambiguously).\n\nNames listed in a "nonlocal" statement must not collide with pre-\nexisting bindings in the local scope.\n\nSee also: **PEP 3104** - Access to Names in Outer Scopes\n\n The specification for the "nonlocal" statement.\n',
- 'numbers': u'\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 the\nliteral "1".\n',
- 'numeric-types': u'\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.__matmul__(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 ("+", "-", "*", "@", "/", "//", "%", "divmod()",\n "pow()", "**", "<<", ">>", "&", "^", "|"). For instance, to\n evaluate the expression "x + y", where *x* is an instance of a\n class that has an "__add__()" method, "x.__add__(y)" is called.\n The "__divmod__()" method should be the equivalent to using\n "__floordiv__()" and "__mod__()"; it should not be related to\n "__truediv__()". Note that "__pow__()" should be defined to accept\n an optional third argument if the ternary version of the built-in\n "pow()" function 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.__rmatmul__(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 reflected (swapped)\n operands. These functions are only called if the left operand does\n not support the corresponding operation and the operands are of\n different types. [2] For instance, to evaluate the expression "x -\n y", where *y* is an instance of a class that has an "__rsub__()"\n method, "y.__rsub__(x)" is called if "x.__sub__(y)" returns\n *NotImplemented*.\n\n Note that ternary "pow()" will not try calling "__rpow__()" (the\n coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left\n operand\'s type and that subclass provides the reflected method\n for the operation, this method will be called before the left\n operand\'s non-reflected method. This behavior allows subclasses\n to override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__imatmul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments ("+=", "-=", "*=", "@=", "/=", "//=", "%=", "**=",\n "<<=", ">>=", "&=", "^=", "|="). These methods should attempt to\n do the operation in-place (modifying *self*) and return the result\n (which could be, but does not have to be, *self*). If a specific\n method is not defined, the augmented assignment falls back to the\n normal methods. For instance, if *x* is an instance of a class\n with an "__iadd__()" method, "x += y" is equivalent to "x =\n x.__iadd__(y)" . Otherwise, "x.__add__(y)" and "y.__radd__(x)" are\n considered, as with the evaluation of "x + y". In certain\n situations, augmented assignment can result in unexpected errors\n (see *Why does a_tuple[i] += [\'item\'] raise an exception when the\n addition works?*), but this behavior is in fact part of the data\n model.\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()", "int()",\n "float()" and "round()". Should return a value of the appropriate\n type.\n\nobject.__index__(self)\n\n Called to implement "operator.index()", and whenever Python needs\n to losslessly convert the numeric object to an integer object (such\n as in slicing, or in the built-in "bin()", "hex()" and "oct()"\n functions). Presence of this method indicates that the numeric\n object is an integer type. Must return an integer.\n\n Note: In order to have a coherent integer type class, when\n "__index__()" is defined "__int__()" should also be defined, and\n both should return the same value.\n',
- 'objects': u'\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.\n\n**CPython implementation detail:** For CPython, "id(x)" is the memory\naddress where "x" is stored.\n\nAn object\'s type determines the operations that the object supports\n(e.g., "does it have a length?") and also defines the possible values\nfor objects of that type. The "type()" function returns an object\'s\ntype (which is an object itself). Like its identity, an object\'s\n*type* is also unchangeable. [1]\n\nThe *value* of some objects can change. Objects whose value can\nchange are said to be *mutable*; objects whose value is unchangeable\nonce they are created are called *immutable*. (The value of an\nimmutable container object that contains a reference to a mutable\nobject can change when the latter\'s value is changed; however the\ncontainer 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.\n\n**CPython implementation detail:** CPython currently uses a reference-\ncounting scheme with (optional) delayed detection of cyclically linked\ngarbage, which collects most objects as soon as they become\nunreachable, but is not guaranteed to collect garbage containing\ncircular references. See the documentation of the "gc" module for\ninformation on controlling the collection of cyclic garbage. Other\nimplementations act differently and CPython may change. Do not depend\non immediate finalization of objects when they become unreachable (so\nyou should always close files explicitly).\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 = 1",\n"a" and "b" may or may not refer to the same object with the value\none, depending on the implementation, but after "c = []; d = []", "c"\nand "d" are guaranteed to refer to two different, unique, newly\ncreated empty lists. (Note that "c = d = []" assigns the same object\nto both "c" and "d".)\n',
- 'operator-summary': u'\nOperator precedence\n*******************\n\nThe following table summarizes the operator precedence in Python, from\nlowest 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 exponentiation, which\ngroups from right to left).\n\nNote that comparisons, membership tests, and identity tests, all have\nthe same precedence and have a left-to-right chaining feature as\ndescribed in the *Comparisons* section.\n\n+-------------------------------------------------+---------------------------------------+\n| Operator | Description |\n+=================================================+=======================================+\n| "lambda" | Lambda expression |\n+-------------------------------------------------+---------------------------------------+\n| "if" -- "else" | Conditional expression |\n+-------------------------------------------------+---------------------------------------+\n| "or" | Boolean OR |\n+-------------------------------------------------+---------------------------------------+\n| "and" | Boolean AND |\n+-------------------------------------------------+---------------------------------------+\n| "not" "x" | Boolean NOT |\n+-------------------------------------------------+---------------------------------------+\n| "in", "not in", "is", "is not", "<", "<=", ">", | Comparisons, including membership |\n| ">=", "!=", "==" | tests and identity tests |\n+-------------------------------------------------+---------------------------------------+\n| "|" | Bitwise OR |\n+-------------------------------------------------+---------------------------------------+\n| "^" | Bitwise XOR |\n+-------------------------------------------------+---------------------------------------+\n| "&" | Bitwise AND |\n+-------------------------------------------------+---------------------------------------+\n| "<<", ">>" | Shifts |\n+-------------------------------------------------+---------------------------------------+\n| "+", "-" | Addition and subtraction |\n+-------------------------------------------------+---------------------------------------+\n| "*", "@", "/", "//", "%" | Multiplication, matrix multiplication |\n| | division, remainder [5] |\n+-------------------------------------------------+---------------------------------------+\n| "+x", "-x", "~x" | Positive, negative, bitwise NOT |\n+-------------------------------------------------+---------------------------------------+\n| "**" | Exponentiation [6] |\n+-------------------------------------------------+---------------------------------------+\n| "await" "x" | Await expression |\n+-------------------------------------------------+---------------------------------------+\n| "x[index]", "x[index:index]", | Subscription, slicing, call, |\n| "x(arguments...)", "x.attribute" | attribute reference |\n+-------------------------------------------------+---------------------------------------+\n| "(expressions...)", "[expressions...]", "{key: | Binding or tuple display, list |\n| value...}", "{expressions...}" | display, dictionary display, set |\n| | display |\n+-------------------------------------------------+---------------------------------------+\n\n-[ Footnotes ]-\n\n[1] While "abs(x%y) < abs(y)" is true mathematically, for floats\n it 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", which\n is numerically exactly equal to "1e100". The function\n "math.fmod()" returns a result whose sign matches the sign of the\n first argument instead, and so returns "-1e-100" in this case.\n Which approach is more appropriate 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 close\n to "x".\n\n[3] The Unicode standard distinguishes between *code points* (e.g.\n U+0041) and *abstract characters* (e.g. "LATIN CAPITAL LETTER A").\n While most abstract characters in Unicode are only represented\n using one code point, there is a number of abstract characters\n that can in addition be represented using a sequence of more than\n one code point. For example, the abstract character "LATIN\n CAPITAL LETTER C WITH CEDILLA" can be represented as a single\n *precomposed character* at code position U+00C7, or as a sequence\n of a *base character* at code position U+0043 (LATIN CAPITAL\n LETTER C), followed by a *combining character* at code position\n U+0327 (COMBINING CEDILLA).\n\n The comparison operators on strings compare at the level of\n Unicode code points. This may be counter-intuitive to humans. For\n example, ""\\u00C7" == "\\u0043\\u0327"" is "False", even though both\n strings represent the same abstract character "LATIN CAPITAL\n LETTER C WITH CEDILLA".\n\n To compare strings at the level of abstract characters (that is,\n in a way intuitive to humans), use "unicodedata.normalize()".\n\n[4] Due to automatic garbage-collection, free lists, and the\n dynamic nature of descriptors, you may notice seemingly unusual\n behaviour in certain uses of the "is" operator, like those\n involving comparisons between instance methods, or constants.\n Check their documentation for more info.\n\n[5] The "%" operator is also used for string formatting; the same\n precedence applies.\n\n[6] The power operator "**" binds less tightly than an arithmetic\n or bitwise unary operator on its right, that is, "2**-1" is "0.5".\n',
- 'pass': u'\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': u'\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 ::= ( await_expr | 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 "ZeroDivisionError".\nRaising a negative number to a fractional power results in a "complex"\nnumber. (In earlier versions it raised a "ValueError".)\n',
- 'raise': u'\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 "RuntimeError" exception is raised indicating\nthat this is an error.\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 returns\nthe same exception instance, with its traceback set to its argument),\nlike so:\n\n raise Exception("foo occurred").with_traceback(tracebackobj)\n\nThe "from" clause is used for exception chaining: if given, the second\n*expression* must be another exception class or instance, which will\nthen be attached to the raised exception as the "__cause__" attribute\n(which is writable). If the raised exception is not handled, both\nexceptions 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 "<stdin>", line 2, in <module>\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 "<stdin>", line 4, in <module>\n RuntimeError: Something bad happened\n\nA similar mechanism works implicitly if an exception is raised inside\nan exception handler or a "finally" clause: the previous exception is\nthen attached as the new 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 "<stdin>", line 2, in <module>\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 "<stdin>", line 4, in <module>\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': u'\nThe "return" statement\n**********************\n\n return_stmt ::= "return" [expression_list]\n\n"return" may only occur syntactically nested in a function definition,\nnot 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 (or\n"None") as return value.\n\nWhen "return" passes control out of a "try" statement with a "finally"\nclause, that "finally" clause is executed before really leaving the\nfunction.\n\nIn a generator function, the "return" statement indicates that the\ngenerator is done and will cause "StopIteration" to be raised. The\nreturned value (if any) is used as an argument to construct\n"StopIteration" and becomes the "StopIteration.value" attribute.\n',
- 'sequence-types': u'\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" where\n*N* is the length of the sequence, or slice objects, which define a\nrange of items. It is also recommended that mappings provide the\nmethods "keys()", "values()", "items()", "get()", "clear()",\n"setdefault()", "pop()", "popitem()", "copy()", and "update()"\nbehaving similar to those for Python\'s standard dictionary objects.\nThe "collections" module provides a "MutableMapping" abstract base\nclass to help create those methods from a base set of "__getitem__()",\n"__setitem__()", "__delitem__()", and "keys()". Mutable sequences\nshould provide methods "append()", "count()", "index()", "extend()",\n"insert()", "pop()", "remove()", "reverse()" and "sort()", like Python\nstandard list objects. Finally, sequence types should implement\naddition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods "__add__()", "__radd__()",\n"__iadd__()", "__mul__()", "__rmul__()" and "__imul__()" described\nbelow; they should not define other numerical operators. It is\nrecommended that both mappings and sequences implement the\n"__contains__()" method to allow efficient use of the "in" operator;\nfor mappings, "in" should search the mapping\'s keys; for sequences, it\nshould search through the values. It is further recommended that both\nmappings and sequences implement the "__iter__()" method to allow\nefficient iteration through the container; for mappings, "__iter__()"\nshould be the same as "keys()"; for sequences, it should iterate\nthrough 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 that\n doesn\'t define a "__bool__()" method and whose "__len__()" method\n returns zero is considered to be false in a Boolean context.\n\nobject.__length_hint__(self)\n\n Called to implement "operator.length_hint()". Should return an\n estimated length for the object (which may be greater or less than\n the actual length). The length must be an integer ">=" 0. This\n method is purely an optimization and is never required for\n correctness.\n\n New in version 3.4.\n\nNote: Slicing is done exclusively with the following three methods.\n A 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 "None".\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of "self[key]". For sequence types,\n the accepted keys should be integers and slice objects. Note that\n the special interpretation of negative indexes (if the class wishes\n to emulate a sequence type) is up to the "__getitem__()" method. If\n *key* is of an inappropriate type, "TypeError" may be raised; if of\n a value outside the set of indexes for the sequence (after any\n special interpretation of negative values), "IndexError" should be\n raised. For mapping types, if *key* is missing (not in the\n container), "KeyError" 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.__missing__(self, key)\n\n Called by "dict"."__getitem__()" to implement "self[key]" for dict\n subclasses when key is not in the dictionary.\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__()" 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.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the "reversed()" built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the "__reversed__()" method is not provided, the "reversed()"\n built-in will fall back to using the sequence protocol ("__len__()"\n and "__getitem__()"). Objects that support the sequence protocol\n should only provide "__reversed__()" if they can provide an\n implementation that is more efficient than the one provided by\n "reversed()".\n\nThe membership test operators ("in" and "not in") are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define "__contains__()", the membership test\n first tries iteration via "__iter__()", then the old sequence\n iteration protocol via "__getitem__()", see *this section in the\n language reference*.\n',
- 'shifting': u'\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 floor division by "pow(2,n)".\nA left shift by *n* bits is defined as multiplication with "pow(2,n)".\n\nNote: In the current implementation, the right-hand operand is\n required to be at most "sys.maxsize". If the right-hand operand is\n larger than "sys.maxsize" an "OverflowError" exception is raised.\n',
- 'slicings': u'\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 slicing:\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 is indexed\n(using the same "__getitem__()" method as normal subscription) with a\nkey that is constructed from the slice list, as follows. If the slice\nlist contains 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': u'\nSpecial Attributes\n******************\n\nThe implementation adds a few special read-only attributes to several\nobject types, where they are relevant. Some of these are not reported\nby the "dir()" built-in function.\n\nobject.__dict__\n\n A dictionary or other mapping object used to store an object\'s\n (writable) attributes.\n\ninstance.__class__\n\n The class to which a class instance belongs.\n\nclass.__bases__\n\n The tuple of base classes of a class object.\n\nclass.__name__\n\n The name of the class or type.\n\nclass.__qualname__\n\n The *qualified name* of the class or type.\n\n New in version 3.3.\n\nclass.__mro__\n\n This attribute is a tuple of classes that are considered when\n looking for base classes during method resolution.\n\nclass.mro()\n\n This method can be overridden by a metaclass to customize the\n method resolution order for its instances. It is called at class\n instantiation, and its result is stored in "__mro__".\n\nclass.__subclasses__()\n\n Each class keeps a list of weak references to its immediate\n subclasses. This method returns a list of all those references\n still alive. Example:\n\n >>> int.__subclasses__()\n [<class \'bool\'>]\n\n-[ Footnotes ]-\n\n[1] Additional information on these special methods may be found\n in the Python Reference Manual (*Basic customization*).\n\n[2] As a consequence, the list "[1, 2]" is considered equal to\n "[1.0, 2.0]", and similarly for tuples.\n\n[3] They must have since the parser can\'t tell the type of the\n operands.\n\n[4] Cased characters are those with general category property\n being one of "Lu" (Letter, uppercase), "Ll" (Letter, lowercase),\n or "Lt" (Letter, titlecase).\n\n[5] To format only a tuple you should therefore provide a\n singleton tuple whose only element is the tuple to be formatted.\n',
- 'specialnames': u'\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 class,\nthen "x[i]" is roughly equivalent to "type(x).__getitem__(x, i)".\nExcept where mentioned, attempts to execute an operation raise an\nexception 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 an\n 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 after the instance has been created (by "__new__()"), but\n before it is returned to the caller. 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, if\n any, must explicitly call it to ensure proper initialization of the\n base class part of the instance; for example:\n "BaseClass.__init__(self, [args...])".\n\n Because "__new__()" and "__init__()" work together in constructing\n objects ("__new__()" to create it, and "__init__()" to customise\n it), no non-"None" value may be returned by "__init__()"; doing so\n will cause a "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, the\n derived class\'s "__del__()" method, if any, must explicitly call it\n to ensure proper deletion of the base class part of the instance.\n Note that it is possible (though not recommended!) for the\n "__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 is\n only called when "x"\'s reference count reaches zero. Some common\n situations that may prevent the reference count of an object from\n going to zero include: circular references between objects (e.g.,\n a doubly-linked list or a tree data structure with parent and\n child pointers); a reference to the object on the stack frame of\n a function that caught an exception (the traceback stored in\n "sys.exc_info()[2]" keeps the stack frame alive); or a reference\n to the object on the stack frame that raised an unhandled\n 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 second can be resolved by freeing the reference to the\n traceback object when it is no longer useful, and the third can\n be resolved by storing "None" in "sys.last_traceback". Circular\n references which are garbage are detected and cleaned up when the\n cyclic garbage collector is enabled (it\'s on by default). Refer\n to the documentation for the "gc" module for more information\n about this topic.\n\n Warning: Due to the precarious circumstances under which\n "__del__()" methods are invoked, exceptions that occur during\n their execution are ignored, and a warning is printed to\n "sys.stderr" instead. Also, when "__del__()" is invoked in\n response to a module being deleted (e.g., when execution of the\n program is done), other globals referenced by the "__del__()"\n method may already have been deleted or in the process of being\n torn down (e.g. the import machinery shutting down). For this\n reason, "__del__()" methods should do the absolute minimum needed\n to maintain external invariants. Starting with version 1.5,\n Python guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the "__del__()" method is called.\n\nobject.__repr__(self)\n\n Called by the "repr()" built-in function to compute the "official"\n string representation of an object. If at all possible, this\n should look like a valid Python expression that could be used to\n recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n "<...some useful description...>" should be returned. The return\n value must be a string object. If a class defines "__repr__()" but\n not "__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 "str(object)" and the built-in functions "format()" and\n "print()" to compute the "informal" or nicely printable string\n representation of an object. The return value must be a *string*\n object.\n\n This method differs from "object.__repr__()" in that there is no\n expectation that "__str__()" return a valid Python expression: a\n more convenient or concise representation can be used.\n\n The default implementation defined by the built-in type "object"\n calls "object.__repr__()".\n\nobject.__bytes__(self)\n\n Called by "bytes()" to compute a byte-string representation of an\n object. This should return a "bytes" object.\n\nobject.__format__(self, format_spec)\n\n Called by the "format()" built-in function (and by extension, the\n "str.format()" method of class "str") to produce a "formatted"\n string representation of an object. The "format_spec" argument is a\n string that contains a description of the formatting options\n desired. The interpretation of the "format_spec" argument is up to\n the type implementing "__format__()", however most classes will\n either delegate formatting to one of the built-in types, or use a\n 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\n Changed in version 3.4: The __format__ method of "object" itself\n raises a "TypeError" if passed any non-empty string.\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: "x<y" calls "x.__lt__(y)", "x<=y" calls "x.__le__(y)",\n "x==y" calls "x.__eq__(y)", "x!=y" calls "x.__ne__(y)", "x>y" calls\n "x.__gt__(y)", and "x>=y" calls "x.__ge__(y)".\n\n A rich comparison method may return the singleton "NotImplemented"\n if it does not implement the operation for a given pair of\n arguments. By convention, "False" and "True" are returned for a\n successful comparison. However, these methods can return any value,\n so if the comparison operator is used in a Boolean context (e.g.,\n in the condition of an "if" statement), Python will call "bool()"\n on the value to determine if the result is true or false.\n\n By default, "__ne__()" delegates to "__eq__()" and inverts the\n result unless it is "NotImplemented". There are no other implied\n relationships among the comparison operators, for example, the\n truth of "(x<y or x==y)" does not imply "x<=y". To automatically\n generate ordering operations from a single root operation, see\n "functools.total_ordering()".\n\n See 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 other\'s\n reflection, "__le__()" and "__ge__()" are each other\'s reflection,\n and "__eq__()" and "__ne__()" are their own reflection. If the\n operands are of different types, and right operand\'s type is a\n direct or indirect subclass of the left operand\'s type, the\n reflected method of the right operand has priority, otherwise the\n left operand\'s method has priority. Virtual subclassing is not\n considered.\n\nobject.__hash__(self)\n\n Called by built-in function "hash()" and for operations on members\n of hashed collections including "set", "frozenset", and "dict".\n "__hash__()" should return an integer. 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 Note: "hash()" truncates the value returned from an object\'s\n custom "__hash__()" method to the size of a "Py_ssize_t". This\n is typically 8 bytes on 64-bit builds and 4 bytes on 32-bit\n builds. If an object\'s "__hash__()" must interoperate on builds\n of different bit sizes, be sure to check the width on all\n supported builds. An easy way to do this is with "python -c\n "import sys; print(sys.hash_info.width)"".\n\n If a class does not define an "__eq__()" method it should not\n define a "__hash__()" operation either; if it defines "__eq__()"\n but not "__hash__()", its instances will not be usable as items in\n hashable collections. If a class defines mutable objects and\n implements an "__eq__()" method, it should not implement\n "__hash__()", since the implementation of hashable collections\n requires that a key\'s hash value is immutable (if the object\'s hash\n value changes, it will be in the wrong hash bucket).\n\n User-defined classes have "__eq__()" and "__hash__()" methods by\n default; with them, all objects compare unequal (except with\n themselves) and "x.__hash__()" returns an appropriate value such\n that "x == y" implies both that "x is y" and "hash(x) == hash(y)".\n\n A class that overrides "__eq__()" and does not define "__hash__()"\n will have its "__hash__()" implicitly set to "None". When the\n "__hash__()" method of a class is "None", instances of the class\n will raise an appropriate "TypeError" when a program attempts to\n retrieve their hash value, and will also be correctly identified as\n unhashable when checking "isinstance(obj, collections.Hashable)".\n\n If a class that overrides "__eq__()" needs to retain the\n implementation of "__hash__()" from a parent class, the interpreter\n must be told this explicitly by setting "__hash__ =\n <ParentClass>.__hash__".\n\n If a class that does not override "__eq__()" wishes to suppress\n hash support, it should include "__hash__ = None" in the class\n definition. A class which defines its own "__hash__()" that\n explicitly raises a "TypeError" would be incorrectly identified as\n hashable by an "isinstance(obj, collections.Hashable)" call.\n\n Note: By default, the "__hash__()" values of str, bytes and\n datetime objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also "PYTHONHASHSEED".\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n "bool()"; should return "False" or "True". When this method is not\n defined, "__len__()" is called, if it is defined, and the object is\n considered true if its result is nonzero. If a class defines\n neither "__len__()" nor "__bool__()", all its instances are\n 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") for\nclass 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. This\n method should return the (computed) attribute value or raise an\n "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 for\n efficiency reasons and because otherwise "__getattr__()" would have\n no way to access other attributes of the instance. Note that at\n least for instance variables, you can fake total control by not\n 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 "__getattr__()",\n the latter will not be called unless "__getattribute__()" either\n calls it explicitly or raises an "AttributeError". This method\n should return the (computed) attribute value or raise an\n "AttributeError" exception. In order to avoid infinite recursion in\n this method, its implementation should always call the base class\n method with the same name to access any attributes it needs, for\n example, "object.__getattribute__(self, name)".\n\n Note: This method may still be bypassed when looking up special\n methods as the result of implicit invocation via language syntax\n or built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If "__setattr__()" wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n "object.__setattr__(self, name, value)".\n\nobject.__delattr__(self, name)\n\n Like "__setattr__()" but for attribute deletion instead of\n assignment. This should only be implemented if "del obj.name" is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when "dir()" is called on the object. A sequence must be\n returned. "dir()" converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' "__dict__".\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or "None" when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an "AttributeError"\n 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\nThe attribute "__objclass__" is interpreted by the "inspect" module as\nspecifying the class where this object was defined (setting this\nappropriately can assist in runtime introspection of dynamic class\nattributes). For callables, it may indicate that an instance of the\ngiven type (or a subclass) is expected or required as the first\npositional argument (for example, CPython sets this attribute for\nunbound methods that are implemented in C).\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, it\nis 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". How\nthe 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 "A"\n immediately preceding "B" and then invokes the descriptor with the\n call: "A.__dict__[\'m\'].__get__(obj, obj.__class__)".\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of "__get__()", "__set__()" and "__delete__()". If it\ndoes not define "__get__()", then accessing the attribute will return\nthe descriptor object itself unless there is a value in the object\'s\ninstance dictionary. If the descriptor defines "__set__()" and/or\n"__delete__()", it is a data descriptor; if it defines neither, it is\na non-data descriptor. Normally, data descriptors define both\n"__get__()" and "__set__()", while non-data descriptors have just the\n"__get__()" method. Data descriptors with "__set__()" and "__get__()"\ndefined always override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances.\n\nPython methods (including "staticmethod()" and "classmethod()") are\nimplemented 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. *__slots__*\n reserves space for the declared variables and prevents the\n automatic creation of *__dict__* and *__weakref__* for each\n 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\n defining *__slots__* do not support weak references to its\n instances. If weak reference support is needed, then add\n "\'__weakref__\'" to the sequence of strings in the *__slots__*\n declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the\n instance variable defined by the base class slot is inaccessible\n (except by retrieving its descriptor directly from the base class).\n This renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as "int", "bytes" and "tuple".\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings\n may also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using "type()". The class body is\nexecuted in a new namespace and the class name is bound locally to the\nresult of "type(name, bases, namespace)".\n\nThe class creation process can be customised by passing the\n"metaclass" keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both "MyClass" and "MySubclass" are instances\nof "Meta":\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then "type()" is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n "type()", then it is used directly as the metaclass\n\n* if an instance of "type()" is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. "type(cls)") of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with "TypeError".\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a "__prepare__" attribute,\nit is called as "namespace = metaclass.__prepare__(name, bases,\n**kwds)" (where the additional keyword arguments, if any, come from\nthe class definition).\n\nIf the metaclass has no "__prepare__" attribute, then the class\nnamespace is initialised as an empty "dict()" instance.\n\nSee also: **PEP 3115** - Metaclasses in Python 3000\n\n Introduced the "__prepare__" namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as "exec(body, globals(),\nnamespace)". The key difference from a normal call to "exec()" is that\nlexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling "metaclass(name, bases,\nnamespace, **kwds)" (the additional keywords passed here are the same\nas those passed to "__prepare__").\n\nThis class object is the one that will be referenced by the zero-\nargument form of "super()". "__class__" is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either "__class__" or "super". This allows the zero argument form\nof "super()" to correctly identify the class being defined based on\nlexical scoping, while the class or instance that was used to make the\ncurrent call is identified based on the first argument passed to the\nmethod.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nWhen a new class is created by "type.__new__", the object provided as\nthe namespace parameter is copied to a standard Python dictionary and\nthe original object is discarded. The new copy becomes the "__dict__"\nattribute of the class object.\n\nSee also: **PEP 3135** - New super\n\n Describes the implicit "__class__" closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n"collections.OrderedDict" to remember the order that class variables\nare defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s "__prepare__()" method which returns an\nempty "collections.OrderedDict". That mapping records the methods and\nattributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s "__new__()" method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called "members".\n\n\nCustomizing instance and subclass checks\n========================================\n\nThe following methods are used to override the default behavior of the\n"isinstance()" and "issubclass()" built-in functions.\n\nIn particular, the metaclass "abc.ABCMeta" implements these methods in\norder to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n "isinstance(instance, class)".\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n "issubclass(subclass, class)".\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also: **PEP 3119** - Introducing Abstract Base Classes\n\n Includes the specification for customizing "isinstance()" and\n "issubclass()" behavior through "__instancecheck__()" and\n "__subclasscheck__()", with motivation for this functionality in\n the context of adding Abstract Base Classes (see the "abc"\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, "x(arg1, arg2, ...)" is a shorthand for\n "x.__call__(arg1, arg2, ...)".\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which "0 <= k < N" where\n*N* is the length of the sequence, or slice objects, which define a\nrange of items. It is also recommended that mappings provide the\nmethods "keys()", "values()", "items()", "get()", "clear()",\n"setdefault()", "pop()", "popitem()", "copy()", and "update()"\nbehaving similar to those for Python\'s standard dictionary objects.\nThe "collections" module provides a "MutableMapping" abstract base\nclass to help create those methods from a base set of "__getitem__()",\n"__setitem__()", "__delitem__()", and "keys()". Mutable sequences\nshould provide methods "append()", "count()", "index()", "extend()",\n"insert()", "pop()", "remove()", "reverse()" and "sort()", like Python\nstandard list objects. Finally, sequence types should implement\naddition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods "__add__()", "__radd__()",\n"__iadd__()", "__mul__()", "__rmul__()" and "__imul__()" described\nbelow; they should not define other numerical operators. It is\nrecommended that both mappings and sequences implement the\n"__contains__()" method to allow efficient use of the "in" operator;\nfor mappings, "in" should search the mapping\'s keys; for sequences, it\nshould search through the values. It is further recommended that both\nmappings and sequences implement the "__iter__()" method to allow\nefficient iteration through the container; for mappings, "__iter__()"\nshould be the same as "keys()"; for sequences, it should iterate\nthrough 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 that\n doesn\'t define a "__bool__()" method and whose "__len__()" method\n returns zero is considered to be false in a Boolean context.\n\nobject.__length_hint__(self)\n\n Called to implement "operator.length_hint()". Should return an\n estimated length for the object (which may be greater or less than\n the actual length). The length must be an integer ">=" 0. This\n method is purely an optimization and is never required for\n correctness.\n\n New in version 3.4.\n\nNote: Slicing is done exclusively with the following three methods.\n A 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 "None".\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of "self[key]". For sequence types,\n the accepted keys should be integers and slice objects. Note that\n the special interpretation of negative indexes (if the class wishes\n to emulate a sequence type) is up to the "__getitem__()" method. If\n *key* is of an inappropriate type, "TypeError" may be raised; if of\n a value outside the set of indexes for the sequence (after any\n special interpretation of negative values), "IndexError" should be\n raised. For mapping types, if *key* is missing (not in the\n container), "KeyError" 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.__missing__(self, key)\n\n Called by "dict"."__getitem__()" to implement "self[key]" for dict\n subclasses when key is not in the dictionary.\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__()" 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.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the "reversed()" built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the "__reversed__()" method is not provided, the "reversed()"\n built-in will fall back to using the sequence protocol ("__len__()"\n and "__getitem__()"). Objects that support the sequence protocol\n should only provide "__reversed__()" if they can provide an\n implementation that is more efficient than the one provided by\n "reversed()".\n\nThe membership test operators ("in" and "not in") are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define "__contains__()", the membership test\n first tries iteration via "__iter__()", then the old sequence\n iteration protocol via "__getitem__()", see *this section in the\n language reference*.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__matmul__(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 ("+", "-", "*", "@", "/", "//", "%", "divmod()",\n "pow()", "**", "<<", ">>", "&", "^", "|"). For instance, to\n evaluate the expression "x + y", where *x* is an instance of a\n class that has an "__add__()" method, "x.__add__(y)" is called.\n The "__divmod__()" method should be the equivalent to using\n "__floordiv__()" and "__mod__()"; it should not be related to\n "__truediv__()". Note that "__pow__()" should be defined to accept\n an optional third argument if the ternary version of the built-in\n "pow()" function 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.__rmatmul__(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 reflected (swapped)\n operands. These functions are only called if the left operand does\n not support the corresponding operation and the operands are of\n different types. [2] For instance, to evaluate the expression "x -\n y", where *y* is an instance of a class that has an "__rsub__()"\n method, "y.__rsub__(x)" is called if "x.__sub__(y)" returns\n *NotImplemented*.\n\n Note that ternary "pow()" will not try calling "__rpow__()" (the\n coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left\n operand\'s type and that subclass provides the reflected method\n for the operation, this method will be called before the left\n operand\'s non-reflected method. This behavior allows subclasses\n to override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__imatmul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments ("+=", "-=", "*=", "@=", "/=", "//=", "%=", "**=",\n "<<=", ">>=", "&=", "^=", "|="). These methods should attempt to\n do the operation in-place (modifying *self*) and return the result\n (which could be, but does not have to be, *self*). If a specific\n method is not defined, the augmented assignment falls back to the\n normal methods. For instance, if *x* is an instance of a class\n with an "__iadd__()" method, "x += y" is equivalent to "x =\n x.__iadd__(y)" . Otherwise, "x.__add__(y)" and "y.__radd__(x)" are\n considered, as with the evaluation of "x + y". In certain\n situations, augmented assignment can result in unexpected errors\n (see *Why does a_tuple[i] += [\'item\'] raise an exception when the\n addition works?*), but this behavior is in fact part of the data\n model.\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()", "int()",\n "float()" and "round()". Should return a value of the appropriate\n type.\n\nobject.__index__(self)\n\n Called to implement "operator.index()", and whenever Python needs\n to losslessly convert the numeric object to an integer object (such\n as in slicing, or in the built-in "bin()", "hex()" and "oct()"\n functions). Presence of this method indicates that the numeric\n object is an integer type. Must return an integer.\n\n Note: In order to have a coherent integer type class, when\n "__index__()" is defined "__int__()" should also be defined, and\n both should return the same value.\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 manager\nhandles the entry into, and the exit from, the desired runtime context\nfor the execution of the block of code. Context managers are normally\ninvoked using the "with" statement (described in section *The with\nstatement*), but can also be used by directly invoking their methods.\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: **PEP 343** - The "with" statement\n\n The specification, background, and examples for the Python "with"\n statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "<stdin>", line 1, in <module>\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 by\nall objects, including type objects. If the implicit lookup of these\nmethods used the conventional lookup process, they would fail when\ninvoked 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 "<stdin>", line 1, in <module>\n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe "__getattribute__()" method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print("Metaclass getattribute invoked")\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object, metaclass=Meta):\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print("Class getattribute invoked")\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the "__getattribute__()" machinery in this fashion provides\nsignificant scope for speed optimisations within the interpreter, at\nthe cost of some flexibility in the handling of special methods (the\nspecial method *must* be set on the class object itself in order to be\nconsistently invoked by the interpreter).\n',
- 'string-methods': u'\nString Methods\n**************\n\nStrings implement all of the *common* sequence operations, along with\nthe additional methods described below.\n\nStrings also support two styles of string formatting, one providing a\nlarge degree of flexibility and customization (see "str.format()",\n*Format String Syntax* and *Custom String Formatting*) and the other\nbased on C "printf" style formatting that handles a narrower range of\ntypes and is slightly harder to use correctly, but is often faster for\nthe cases it can handle (*printf-style String Formatting*).\n\nThe *Text Processing Services* section of the standard library covers\na number of other modules that provide various text related utilities\n(including regular expression support in the "re" module).\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter "\'\xdf\'" is equivalent to ""ss"".\n Since it is already lowercase, "lower()" would do nothing to "\'\xdf\'";\n "casefold()" converts it to ""ss"".\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is an ASCII space). The\n original string is returned if *width* is less than or equal to\n "len(s)".\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is "\'utf-8\'". *errors* may be given to set a different\n error handling scheme. The default for *errors* is "\'strict\'",\n meaning that encoding errors raise a "UnicodeError". Other possible\n values are "\'ignore\'", "\'replace\'", "\'xmlcharrefreplace\'",\n "\'backslashreplace\'" and any other name registered via\n "codecs.register_error()", see section *Error Handlers*. For a list\n of possible encodings, see section *Standard Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return "True" if the string ends with the specified *suffix*,\n otherwise return "False". *suffix* can also be a tuple of suffixes\n to look for. With optional *start*, test beginning at that\n position. With optional *end*, stop comparing at that position.\n\nstr.expandtabs(tabsize=8)\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. Tab positions occur every *tabsize* characters\n (default is 8, giving tab positions at columns 0, 8, 16 and so on).\n To expand the string, the current column is set to zero and the\n string is examined character by character. If the character is a\n tab ("\\t"), one or more space characters are inserted in the result\n until the current column is equal to the next tab position. (The\n tab character itself is not copied.) If the character is a newline\n ("\\n") or return ("\\r"), it is copied and the current column is\n reset to zero. Any other character is copied unchanged and the\n current column is incremented by one regardless of how the\n character is represented when printed.\n\n >>> \'01\\t012\\t0123\\t01234\'.expandtabs()\n \'01 012 0123 01234\'\n >>> \'01\\t012\\t0123\\t01234\'.expandtabs(4)\n \'01 012 0123 01234\'\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found within the slice "s[start:end]". Optional arguments *start*\n and *end* are interpreted as in slice notation. Return "-1" if\n *sub* is not found.\n\n Note: The "find()" method should be used only if you need to know\n the position of *sub*. To check if *sub* is a substring or not,\n use the "in" operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces "{}". Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to "str.format(**mapping)", except that "mapping" is used\n directly and not copied to a "dict". This is useful if for example\n "mapping" is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like "find()", but raise "ValueError" when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character "c"\n is alphanumeric if one of the following returns "True":\n "c.isalpha()", "c.isdecimal()", "c.isdigit()", or "c.isnumeric()".\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\n Use "keyword.iskeyword()" to test for reserved identifiers such as\n "def" and "class".\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when "repr()" is\n invoked on a string. It has no bearing on the handling of strings\n written to "sys.stdout" or "sys.stderr".)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A "TypeError" will be raised if there are\n any non-string values in *iterable*, including "bytes" objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is an ASCII\n space). The original string is returned if *width* is less than or\n equal to "len(s)".\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or "None", the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n "str.translate()".\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within "s[start:end]".\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return "-1" on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like "rfind()" but raises "ValueError" when the substring *sub* is\n 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 an ASCII\n space). The original string is returned if *width* is less than or\n equal to "len(s)".\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n "None", any whitespace string is a separator. Except for splitting\n from the right, "rsplit()" behaves like "split()" which is\n described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or "None", the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most "maxsplit+1"\n elements). If *maxsplit* is not specified or "-1", then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n "\'1,,2\'.split(\',\')" returns "[\'1\', \'\', \'2\']"). The *sep* argument\n may consist of multiple characters (for example,\n "\'1<>2<>3\'.split(\'<>\')" returns "[\'1\', \'2\', \'3\']"). Splitting an\n empty string with a specified separator returns "[\'\']".\n\n For example:\n\n >>> \'1,2,3\'.split(\',\')\n [\'1\', \'2\', \'3\']\n >>> \'1,2,3\'.split(\',\', maxsplit=1)\n [\'1\', \'2,3\']\n >>> \'1,2,,3,\'.split(\',\')\n [\'1\', \'2\', \'\', \'3\', \'\']\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 For example:\n\n >>> \'1 2 3\'.split()\n [\'1\', \'2\', \'3\']\n >>> \'1 2 3\'.split(maxsplit=1)\n [\'1\', \'2 3\']\n >>> \' 1 2 3 \'.split()\n [\'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\n This method splits on the following line boundaries. In\n particular, the boundaries are a superset of *universal newlines*.\n\n +-------------------------+-------------------------------+\n | Representation | Description |\n +=========================+===============================+\n | "\\n" | Line Feed |\n +-------------------------+-------------------------------+\n | "\\r" | Carriage Return |\n +-------------------------+-------------------------------+\n | "\\r\\n" | Carriage Return + Line Feed |\n +-------------------------+-------------------------------+\n | "\\v" or "\\x0b" | Line Tabulation |\n +-------------------------+-------------------------------+\n | "\\f" or "\\x0c" | Form Feed |\n +-------------------------+-------------------------------+\n | "\\x1c" | File Separator |\n +-------------------------+-------------------------------+\n | "\\x1d" | Group Separator |\n +-------------------------+-------------------------------+\n | "\\x1e" | Record Separator |\n +-------------------------+-------------------------------+\n | "\\x85" | Next Line (C1 Control Code) |\n +-------------------------+-------------------------------+\n | "\\u2028" | Line Separator |\n +-------------------------+-------------------------------+\n | "\\u2029" | Paragraph Separator |\n +-------------------------+-------------------------------+\n\n Changed in version 3.2: "\\v" and "\\f" added to list of line\n boundaries.\n\n For example:\n\n >>> \'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()\n [\'ab c\', \'\', \'de fg\', \'kl\']\n >>> \'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines(keepends=True)\n [\'ab c\\n\', \'\\n\', \'de fg\\r\', \'kl\\r\\n\']\n\n Unlike "split()" when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line:\n\n >>> "".splitlines()\n []\n >>> "One line\\n".splitlines()\n [\'One line\']\n\n For comparison, "split(\'\\n\')" gives:\n\n >>> \'\'.split(\'\\n\')\n [\'\']\n >>> \'Two lines\\n\'.split(\'\\n\')\n [\'Two lines\', \'\']\n\nstr.startswith(prefix[, start[, end]])\n\n Return "True" if string starts with the *prefix*, otherwise return\n "False". *prefix* can also be a tuple of prefixes to look for.\n With optional *start*, test string beginning at that position.\n With optional *end*, stop comparing string at that 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 *chars*\n argument defaults to removing whitespace. The *chars* argument is\n not a prefix or suffix; rather, all combinations of its values are\n stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\n The outermost leading and trailing *chars* argument values are\n stripped from the string. Characters are removed from the leading\n end until reaching a string character that is not contained in the\n set of characters in *chars*. A similar action takes place on the\n trailing end. For example:\n\n >>> comment_string = \'#....... Section 3.2.1 Issue #32 .......\'\n >>> comment_string.strip(\'.#! \')\n \'Section 3.2.1 Issue #32\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n "s.swapcase().swapcase() == s".\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n For example:\n\n >>> \'Hello world\'.title()\n \'Hello World\'\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n ... lambda mo: mo.group(0)[0].upper() +\n ... mo.group(0)[1:].lower(),\n ... s)\n ...\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(table)\n\n Return a copy of the string in which each character has been mapped\n through the given translation table. The table must be an object\n that implements indexing via "__getitem__()", typically a *mapping*\n or *sequence*. When indexed by a Unicode ordinal (an integer), the\n table object can do any of the following: return a Unicode ordinal\n or a string, to map the character to one or more other characters;\n return "None", to delete the character from the return string; or\n raise a "LookupError" exception, to map the character to itself.\n\n You can use "str.maketrans()" to create a translation map from\n character-to-character mappings in different formats.\n\n See also the "codecs" module for a more flexible approach to custom\n character mappings.\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that "str.upper().isupper()" might be\n "False" if "s" contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return a copy of the string left filled with ASCII "\'0\'" digits to\n make a string of length *width*. A leading sign prefix\n ("\'+\'"/"\'-\'") is handled by inserting the padding *after* the sign\n character rather than before. The original string is returned if\n *width* is less than or equal to "len(s)".\n\n For example:\n\n >>> "42".zfill(5)\n \'00042\'\n >>> "-42".zfill(5)\n \'-0042\'\n',
- 'strings': u'\nString and Bytes literals\n*************************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "R" | "U"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'" | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | stringescapeseq\n longstringitem ::= longstringchar | stringescapeseq\n shortstringchar ::= <any source character except "\\" or newline or the quote>\n longstringchar ::= <any source character except "\\">\n stringescapeseq ::= "\\" <any source character>\n\n bytesliteral ::= bytesprefix(shortbytes | longbytes)\n bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"\n shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' shortbytesitem* \'"\'\n longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' longbytesitem* \'"""\'\n shortbytesitem ::= shortbyteschar | bytesescapeseq\n longbytesitem ::= longbyteschar | bytesescapeseq\n shortbyteschar ::= <any ASCII character except "\\" or newline or the quote>\n longbyteschar ::= <any ASCII character except "\\">\n bytesescapeseq ::= "\\" <any ASCII character>\n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the "stringprefix" or "bytesprefix"\nand the rest of the literal. The source character set is defined by\nthe encoding declaration; it is UTF-8 if no encoding declaration is\ngiven in the source file; see section *Encoding declarations*.\n\nIn plain English: Both types of literals can be enclosed in matching\nsingle quotes ("\'") or double quotes ("""). They can also be enclosed\nin matching groups of three single or double quotes (these are\ngenerally referred to as *triple-quoted strings*). The backslash\n("\\") character is used to escape characters that otherwise have a\nspecial meaning, such as newline, backslash itself, or the quote\ncharacter.\n\nBytes literals are always prefixed with "\'b\'" or "\'B\'"; they produce\nan instance of the "bytes" type instead of the "str" type. They may\nonly contain ASCII characters; bytes with a numeric value of 128 or\ngreater must be expressed with escapes.\n\nAs of Python 3.3 it is possible again to prefix string literals with a\n"u" prefix to simplify maintenance of dual 2.x and 3.x codebases.\n\nBoth string and bytes literals may optionally be prefixed with a\nletter "\'r\'" or "\'R\'"; such strings are called *raw strings* and treat\nbackslashes as literal characters. As a result, in string literals,\n"\'\\U\'" and "\'\\u\'" escapes in raw strings are not treated specially.\nGiven that Python 2.x\'s raw unicode literals behave differently than\nPython 3.x\'s the "\'ur\'" syntax is not supported.\n\nNew in version 3.3: The "\'rb\'" prefix of raw bytes literals has been\nadded as a synonym of "\'br\'".\n\nNew in version 3.3: Support for the unicode legacy literal\n("u\'value\'") was reintroduced to simplify the maintenance of dual\nPython 2.x and 3.x codebases. See **PEP 414** for more information.\n\nIn triple-quoted literals, unescaped newlines and quotes are allowed\n(and are retained), except that three unescaped quotes in a row\nterminate the literal. (A "quote" is the character used to open the\nliteral, i.e. either "\'" or """.)\n\nUnless an "\'r\'" or "\'R\'" prefix is present, escape sequences in string\nand bytes literals are interpreted according to rules similar to those\nused by Standard C. The recognized escape sequences are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| "\\newline" | Backslash and newline ignored | |\n+-------------------+-----------------------------------+---------+\n| "\\\\" | Backslash ("\\") | |\n+-------------------+-----------------------------------+---------+\n| "\\\'" | Single quote ("\'") | |\n+-------------------+-----------------------------------+---------+\n| "\\"" | Double quote (""") | |\n+-------------------+-----------------------------------+---------+\n| "\\a" | ASCII Bell (BEL) | |\n+-------------------+-----------------------------------+---------+\n| "\\b" | ASCII Backspace (BS) | |\n+-------------------+-----------------------------------+---------+\n| "\\f" | ASCII Formfeed (FF) | |\n+-------------------+-----------------------------------+---------+\n| "\\n" | ASCII Linefeed (LF) | |\n+-------------------+-----------------------------------+---------+\n| "\\r" | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| "\\t" | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| "\\v" | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| "\\ooo" | Character with octal value *ooo* | (1,3) |\n+-------------------+-----------------------------------+---------+\n| "\\xhh" | Character with hex value *hh* | (2,3) |\n+-------------------+-----------------------------------+---------+\n\nEscape sequences only recognized in string literals are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| "\\N{name}" | Character named *name* in the | (4) |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| "\\uxxxx" | Character with 16-bit hex value | (5) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| "\\Uxxxxxxxx" | Character with 32-bit hex value | (6) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, exactly two hex digits are required.\n\n3. In a bytes literal, hexadecimal and octal escapes denote the\n byte with the given value. In a string literal, these escapes\n denote a Unicode character with the given value.\n\n4. Changed in version 3.3: Support for name aliases [1] has been\n added.\n\n5. Exactly four hex digits are required.\n\n6. Any Unicode character can be encoded this way. Exactly eight\n hex digits are required.\n\nUnlike Standard C, all unrecognized escape sequences are left in the\nstring unchanged, i.e., *the backslash is left in the result*. (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 literal, quotes can be escaped with a backslash, but the\nbackslash remains in the result; for example, "r"\\""" is a valid\nstring literal consisting of two characters: a backslash and a double\nquote; "r"\\"" is not a valid string literal (even a raw string cannot\nend in an odd number of backslashes). Specifically, *a raw literal\ncannot end in a single backslash* (since the backslash would escape\nthe following quote character). Note also that a single backslash\nfollowed by a newline is interpreted as those two characters as part\nof the literal, *not* as a line continuation.\n',
- 'subscriptions': u'\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\n(lists or dictionaries for example). User-defined objects can support\nsubscription by defining a "__getitem__()" method.\n\nFor built-in objects, there are two types of objects that support\nsubscription:\n\nIf the primary is a mapping, the expression list must evaluate to an\nobject whose value is one of the keys of the mapping, and the\nsubscription selects the value in the mapping that corresponds to that\nkey. (The expression list is a tuple except if it has exactly one\nitem.)\n\nIf the primary is a sequence, the expression (list) must evaluate to\nan integer or a slice (as discussed in the following section).\n\nThe formal syntax makes no special provision for negative indices in\nsequences; however, built-in sequences all provide a "__getitem__()"\nmethod that interprets negative indices by adding the length of the\nsequence to the index (so that "x[-1]" selects the last item of "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). Since the support for\nnegative indices and slicing occurs in the object\'s "__getitem__()"\nmethod, subclasses overriding this method will need to explicitly add\nthat support.\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n',
- 'truth': u'\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, unless\notherwise stated. (Important exception: the Boolean operations "or"\nand "and" always return one of their operands.)\n',
- 'try': u'\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" identifier]] ":" 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 no\nexception occurs in the "try" clause, no exception handler is\nexecuted. When an exception occurs in the "try" suite, a search for an\nexception handler is started. This search inspects the except clauses\nin turn until one is found that matches the exception. An expression-\nless except clause, if present, must be last; it matches any\nexception. For an except clause with an expression, that expression\nis evaluated, and the clause matches the exception if the resulting\nobject is "compatible" with the exception. An object is compatible\nwith an exception if it is the class or a base class of the exception\nobject or a tuple containing an item compatible with the exception.\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 raised\nthe 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, if\npresent, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using "as target", it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the "sys" module and can be accessed via\n"sys.exc_info()". "sys.exc_info()" returns a 3-tuple consisting of the\nexception class, the exception instance and a traceback object (see\nsection *The standard type hierarchy*) identifying the point in the\nprogram where the exception occurred. "sys.exc_info()" values are\nrestored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional "else" clause is executed if and when control flows off\nthe end of the "try" clause. [2] Exceptions in the "else" clause are\nnot handled by the preceding "except" clauses.\n\nIf "finally" is present, it specifies a \'cleanup\' handler. The "try"\nclause is executed, including any "except" and "else" clauses. If an\nexception occurs in any of the clauses and is not handled, the\nexception is temporarily saved. The "finally" clause is executed. If\nthere is a saved exception it is re-raised at the end of the "finally"\nclause. If the "finally" clause raises another exception, the saved\nexception is set as the context of the new exception. If the "finally"\nclause executes a "return" or "break" statement, the saved exception\nis discarded:\n\n >>> def f():\n ... try:\n ... 1/0\n ... finally:\n ... return 42\n ...\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the "finally" clause.\n\nWhen a "return", "break" or "continue" statement is executed in the\n"try" suite of a "try"..."finally" statement, the "finally" clause is\nalso executed \'on the way out.\' A "continue" statement is illegal in\nthe "finally" clause. (The reason is a problem with the current\nimplementation --- this restriction may be lifted in the future).\n\nThe return value of a function is determined by the last "return"\nstatement executed. Since the "finally" clause always executes, a\n"return" statement executed in the "finally" clause will always be the\nlast one executed:\n\n >>> def foo():\n ... try:\n ... return \'try\'\n ... finally:\n ... return \'finally\'\n ...\n >>> foo()\n \'finally\'\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': u'\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". It\n is used to signify the absence of a value in many situations, e.g.,\n 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\n should return this value if they do not implement the operation for\n the operands provided. (The interpreter will then try the\n reflected operation, or some other fallback, depending on the\n operator.) Its truth value is true.\n\n See *Implementing the arithmetic operations* for more details.\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\n only Boolean objects. The Boolean type is a subtype of the\n integer type, and Boolean values behave like the values 0 and\n 1, 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 are\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 items\n of a sequence. When the length of a sequence is *n*, the index set\n contains the numbers 0, 1, ..., *n*-1. Item *i* of sequence *a* is\n 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* where\n "x = i + n*k", *n* ">=" "0" and *i* "<=" *x* "<" *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n A string is a sequence of values that represent Unicode code\n points. All the code points in the range "U+0000 - U+10FFFF"\n can be represented in a string. Python doesn\'t have a "char"\n type; instead, every code point in the string is represented\n as a string object with length "1". The built-in function\n "ord()" converts a code point from its string form to an\n integer in the range "0 - 10FFFF"; "chr()" converts an\n integer in the range "0 - 10FFFF" to the corresponding length\n "1" string object. "str.encode()" can be used to convert a\n "str" to "bytes" using the given text encoding, and\n "bytes.decode()" can be used to achieve the opposite.\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like "b\'abc\'") and the built-in function\n "bytes()" can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the "decode()"\n method.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and "del" (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in "bytearray()" constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module "array" provides an additional example of a\n 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 immutable\n and *hashable*, it can be used again as an element of another\n 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 "k"\n from the mapping "a"; this can be used in expressions and as the\n target of assignments or "del" statements. The built-in function\n "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 "1.0")\n 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 "collections"\n 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; not inherited by | |\n | | subclasses | |\n +---------------------------+---------------------------------+-------------+\n | "__name__" | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | "__qualname__" | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\n +---------------------------+---------------------------------+-------------+\n | "__module__" | The name of the module the | Writable |\n | | function was defined in, or | |\n | | "None" if unavailable. | |\n +---------------------------+---------------------------------+-------------+\n | "__defaults__" | A tuple containing default | Writable |\n | | argument values for those | |\n | | arguments that have defaults, | |\n | | or "None" if no arguments have | |\n | | 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 that | Read-only |\n | | 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 | | and "\'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__"); "__name__"\n is the method name (same as "__func__.__name__"); "__module__"\n is the name of the module the method was defined in, or "None"\n 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 object\n is said to be bound. The new method\'s "__func__" attribute is\n 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__" attribute\n is the class itself, and its "__func__" attribute is the\n 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, when\n "C" is a class which contains a definition for a function "f()",\n and "x" is an instance of "C", calling "x.f(1)" is equivalent to\n 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 actually\n be the class itself, so that calling either "x.f(1)" or "C.f(1)"\n is equivalent to calling "f(C,1)" where "f" is the underlying\n 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 "iterator.__next__()" method will cause the\n function to execute until it provides a value using the "yield"\n statement. When the function executes a "return" statement or\n falls off 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 Coroutine functions\n A function or method which is defined using "async def" is\n called a *coroutine function*. Such a function, when called,\n returns a *coroutine* object. It may contain "await"\n expressions, as well as "async with" and "async for" statements.\n See also the *Coroutine Objects* section.\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 function\'s\n name; "__self__" is set to "None" (but see the next item);\n "__module__" is the name of the module the function was defined\n in or "None" if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n "alist.append()", assuming *alist* is a list object. In this\n case, the special read-only attribute "__self__" is set to the\n object denoted by *alist*.\n\n Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override "__new__()". The arguments of the\n call are passed to "__new__()" and, in the typical case, to\n "__init__()" to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a "__call__()" method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the "import"\n statement (see "import"), or by calling functions such as\n "importlib.import_module()" and built-in "__import__()". A module\n object has a namespace implemented by a dictionary object (this is\n the dictionary referenced by the "__globals__" attribute of\n functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., "m.x" is equivalent\n to "m.__dict__["x"]". A module object does not contain the code\n object used to initialize the module (since it isn\'t needed once\n the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., "m.x = 1" is equivalent to "m.__dict__["x"] = 1".\n\n Special read-only attribute: "__dict__" is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: "__name__" is the module\'s name;\n "__doc__" is the module\'s documentation string, or "None" if\n unavailable; "__file__" is the pathname of the file from which the\n module was loaded, if it was loaded from a file. The "__file__"\n attribute may be missing for certain types of modules, such as C\n modules that are statically linked into the interpreter; for\n extension modules loaded dynamically from a shared library, it is\n the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., "C.x" is translated to\n "C.__dict__["x"]" (although there are a number of hooks which allow\n for other means of locating attributes). When the attribute name is\n 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 https://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class "C", say) would yield a\n class method object, it is transformed into an instance method\n object whose "__self__" attributes is "C". When it would yield a\n static method object, it is transformed into the object wrapped by\n 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__" is\n the module name in which the class was defined; "__dict__" is the\n dictionary containing the class\'s namespace; "__bases__" is a tuple\n (possibly empty or a singleton) containing the base classes, in the\n order of their occurrence in the base class list; "__doc__" is the\n class\'s documentation string, or None if 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 "__dict__".\n If no class attribute is found, and the object\'s class has a\n "__getattr__()" method, that is called to satisfy the 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 instead\n of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n *Special method names*.\n\n Special attributes: "__dict__" is the attribute dictionary;\n "__class__" is the instance\'s class.\n\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the "open()" built-in function,\n and also "os.popen()", "os.fdopen()", and the "makefile()" method\n of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects "sys.stdin", "sys.stdout" and "sys.stderr" are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n "io.TextIOBase" abstract class.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: "co_name" gives the function name;\n "co_argcount" is the number of positional arguments (including\n arguments with default values); "co_nlocals" is the number of\n local variables used by the function (including arguments);\n "co_varnames" is a tuple containing the names of the local\n variables (starting with the argument names); "co_cellvars" is a\n tuple containing the names of local variables that are\n referenced by nested functions; "co_freevars" is a tuple\n containing the names of free variables; "co_code" is a string\n representing the sequence of bytecode instructions; "co_consts"\n is a tuple containing the literals used by the bytecode;\n "co_names" is a tuple containing the names used by the bytecode;\n "co_filename" is 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 a\n number of flags for the interpreter.\n\n The following flag bits are defined for "co_flags": bit "0x04"\n is set if the function uses the "*arguments" syntax to accept an\n arbitrary number of positional arguments; bit "0x08" is set if\n the function uses the "**keywords" syntax to accept arbitrary\n keyword arguments; bit "0x20" is set if the function is a\n generator.\n\n Future feature declarations ("from __future__ import division")\n also use bits in "co_flags" to indicate whether a code object\n was compiled with a particular feature enabled: bit "0x2000" is\n set if the function was compiled with future division enabled;\n bits "0x10" and "0x1000" were used in earlier versions of\n 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 stack\n frame (towards the caller), or "None" if this is the bottom\n stack frame; "f_code" is the code object being executed in this\n frame; "f_locals" is the dictionary used to look up local\n variables; "f_globals" is used for global variables;\n "f_builtins" is used for built-in (intrinsic) names; "f_lasti"\n gives the precise instruction (this is an index into the\n 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 of\n the frame --- writing to this from within a trace function jumps\n to the given line (only for the bottom-most frame). A debugger\n can implement a Jump command (aka Set Next Statement) by writing\n to f_lineno.\n\n Frame objects support one method:\n\n frame.clear()\n\n This method clears all references to local variables held by\n the frame. Also, if the frame belonged to a generator, the\n generator is finalized. This helps break reference cycles\n involving frame objects (for example when catching an\n exception and storing its traceback for later use).\n\n "RuntimeError" is raised if the frame is currently executing.\n\n New in version 3.4.\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 no\n suitable handler, the stack trace is written (nicely formatted)\n to the standard error stream; if the interpreter is interactive,\n it is also made available to the user as "sys.last_traceback".\n\n Special read-only attributes: "tb_next" is the next level in the\n stack trace (towards the frame where the exception occurred), or\n "None" if there is no next level; "tb_frame" points to the\n execution frame of the current level; "tb_lineno" gives the line\n number where the exception occurred; "tb_lasti" indicates the\n precise instruction. The line number and last instruction in\n the traceback may differ from the line number of its frame\n object if the exception occurred in a "try" statement with no\n matching except clause 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; "stop"\n is the upper bound; "step" is the step value; each is "None" if\n 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': u'\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': u'\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" module.)\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 index\nthe same dictionary entry. (Note however, that since computers store\nfloating-point numbers as approximations it is usually unwise to use\nthem as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of "key:\nvalue" pairs within braces, for example: "{\'jack\': 4098, \'sjoerd\':\n4127}" or "{4098: \'jack\', 4127: \'sjoerd\'}", or by the "dict"\nconstructor.\n\nclass class dict(**kwarg)\nclass class dict(mapping, **kwarg)\nclass class dict(iterable, **kwarg)\n\n Return a new dictionary initialized from an optional positional\n argument and a possibly empty set of keyword arguments.\n\n If no positional argument is given, an empty dictionary is created.\n If a positional argument is given and it is a mapping object, a\n dictionary is created with the same key-value pairs as the mapping\n object. Otherwise, the positional argument must be an *iterable*\n object. Each item in the iterable must itself be an iterable with\n exactly two objects. The first object of each item becomes a key\n in the new dictionary, and the second object the corresponding\n value. If a key occurs more than once, the last value for that key\n becomes the corresponding value in the new dictionary.\n\n If keyword arguments are given, the keyword arguments and their\n values are added to the dictionary created from the positional\n argument. If a key being added is already present, the value from\n the keyword argument replaces the value from the positional\n argument.\n\n To illustrate, the following examples all return a dictionary equal\n to "{"one": 1, "two": 2, "three": 3}":\n\n >>> a = dict(one=1, two=2, three=3)\n >>> b = {\'one\': 1, \'two\': 2, \'three\': 3}\n >>> c = dict(zip([\'one\', \'two\', \'three\'], [1, 2, 3]))\n >>> d = dict([(\'two\', 2), (\'one\', 1), (\'three\', 3)])\n >>> e = dict({\'three\': 3, \'one\': 1, \'two\': 2})\n >>> a == b == c == d == e\n True\n\n Providing keyword arguments as in the first example only works for\n keys that are valid Python identifiers. Otherwise, any valid keys\n can be used.\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__()" and *key*\n is not present, the "d[key]" operation calls that method with\n the key *key* as argument. The "d[key]" operation then returns\n or raises whatever is returned or raised by the\n "__missing__(key)" call. No other operations or methods invoke\n "__missing__()". If "__missing__()" is not defined, "KeyError"\n is raised. "__missing__()" must be a method; it cannot be an\n instance variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n The example above shows part of the implementation of\n "collections.Counter". A different "__missing__" method is used\n by "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 not\n in the map.\n\n key in d\n\n Return "True" if *d* has a key *key*, else "False".\n\n key not in d\n\n Equivalent to "not key in d".\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for "iter(d.keys())".\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n classmethod fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n "fromkeys()" is a class method that returns a new dictionary.\n *value* defaults to "None".\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to "None", so\n that this method never raises a "KeyError".\n\n items()\n\n Return a new view of the dictionary\'s items ("(key, value)"\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a "KeyError" is raised.\n\n popitem()\n\n Remove and return an arbitrary "(key, value)" pair from the\n dictionary.\n\n "popitem()" is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling "popitem()" raises a "KeyError".\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to "None".\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return "None".\n\n "update()" accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: "d.update(red=1,\n blue=2)".\n\n values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\n Dictionaries compare equal if and only if they have the same "(key,\n value)" pairs. Order comparisons (\'<\', \'<=\', \'>=\', \'>\') raise\n "TypeError".\n\nSee also: "types.MappingProxyType" can be used to create a read-only\n view of a "dict".\n\n\nDictionary view objects\n=======================\n\nThe objects returned by "dict.keys()", "dict.values()" and\n"dict.items()" are *view objects*. They provide a dynamic view on the\ndictionary\'s entries, which means that when the dictionary changes,\nthe view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of "(key, value)") in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of "(value, key)" pairs using\n "zip()": "pairs = zip(d.values(), d.keys())". Another way to\n create the same list is "pairs = [(v, k) for (k, v) in d.items()]".\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a "RuntimeError" or fail to iterate over all entries.\n\nx in dictview\n\n Return "True" if *x* is in the underlying dictionary\'s keys, values\n or items (in the latter case, *x* should be a "(key, value)"\n tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that "(key, value)" pairs are unique\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class "collections.abc.Set" are available (for example, "==",\n"<", or "^").\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n',
- 'typesmethods': u'\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as "append()" on lists)\nand class instance methods. Built-in methods are described with the\ntypes 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 "self"\nargument to the argument list. Bound methods have two special read-\nonly attributes: "m.__self__" is the object on which the method\noperates, and "m.__func__" is the function implementing the method.\nCalling "m(arg-1, arg-2, ..., arg-n)" is completely equivalent to\ncalling "m.__func__(m.__self__, arg-1, arg-2, ..., arg-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 an\nattribute on a method results in an "AttributeError" being raised. In\norder to set a method attribute, you need to explicitly set it on the\nunderlying function object:\n\n >>> class C:\n ... def method(self):\n ... pass\n ...\n >>> c = C()\n >>> c.method.whoami = \'my name is method\' # can\'t set on the method\n Traceback (most recent call last):\n File "<stdin>", line 1, in <module>\n AttributeError: \'method\' object has no attribute \'whoami\'\n >>> c.method.__func__.whoami = \'my name is method\'\n >>> c.method.whoami\n \'my name is method\'\n\nSee *The standard type hierarchy* for more information.\n',
- 'typesmodules': u'\nModules\n*******\n\nThe only special operation on a module is attribute access: "m.name",\nwhere *m* is a module and *name* accesses a name defined in *m*\'s\nsymbol table. Module attributes can be assigned to. (Note that the\n"import" statement is not, strictly speaking, an operation on a module\nobject; "import foo" does not require a module object named *foo* to\nexist, rather it requires an (external) *definition* for a module\nnamed *foo* somewhere.)\n\nA special attribute of every module is "__dict__". This is the\ndictionary containing the module\'s symbol table. Modifying this\ndictionary will actually change the module\'s symbol table, but direct\nassignment to the "__dict__" attribute is not possible (you can write\n"m.__dict__[\'a\'] = 1", which defines "m.a" to be "1", but you can\'t\nwrite "m.__dict__ = {}"). Modifying "__dict__" directly is not\nrecommended.\n\nModules built into the interpreter are written like this: "<module\n\'sys\' (built-in)>". If loaded from a file, they are written as\n"<module \'os\' from \'/usr/local/lib/pythonX.Y/os.pyc\'>".\n',
- 'typesseq': u'\nSequence Types --- "list", "tuple", "range"\n*******************************************\n\nThere are three basic sequence types: lists, tuples, and range\nobjects. Additional sequence types tailored for processing of *binary\ndata* and *text strings* are described in dedicated sections.\n\n\nCommon Sequence Operations\n==========================\n\nThe operations in the following table are supported by most sequence\ntypes, both mutable and immutable. The "collections.abc.Sequence" ABC\nis provided to make it easier to correctly implement these operations\non custom sequence types.\n\nThis table lists the sequence operations sorted in ascending priority.\nIn the table, *s* and *t* are sequences of the same type, *n*, *i*,\n*j* and *k* are integers and *x* is an arbitrary object that meets any\ntype and value restrictions imposed by *s*.\n\nThe "in" and "not in" operations have the same priorities as the\ncomparison operations. The "+" (concatenation) and "*" (repetition)\noperations have the same priority as the corresponding numeric\noperations.\n\n+----------------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+============================+==================================+============+\n| "x in s" | "True" if an item of *s* is | (1) |\n| | equal to *x*, else "False" | |\n+----------------------------+----------------------------------+------------+\n| "x not in s" | "False" if an item of *s* is | (1) |\n| | equal to *x*, else "True" | |\n+----------------------------+----------------------------------+------------+\n| "s + t" | the concatenation of *s* and *t* | (6)(7) |\n+----------------------------+----------------------------------+------------+\n| "s * n" or "n * s" | equivalent to adding *s* to | (2)(7) |\n| | itself *n* times | |\n+----------------------------+----------------------------------+------------+\n| "s[i]" | *i*th item of *s*, origin 0 | (3) |\n+----------------------------+----------------------------------+------------+\n| "s[i:j]" | slice of *s* from *i* to *j* | (3)(4) |\n+----------------------------+----------------------------------+------------+\n| "s[i:j:k]" | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+----------------------------+----------------------------------+------------+\n| "len(s)" | length of *s* | |\n+----------------------------+----------------------------------+------------+\n| "min(s)" | smallest item of *s* | |\n+----------------------------+----------------------------------+------------+\n| "max(s)" | largest item of *s* | |\n+----------------------------+----------------------------------+------------+\n| "s.index(x[, i[, j]])" | index of the first occurrence of | (8) |\n| | *x* in *s* (at or after index | |\n| | *i* and before index *j*) | |\n+----------------------------+----------------------------------+------------+\n| "s.count(x)" | total number of occurrences of | |\n| | *x* in *s* | |\n+----------------------------+----------------------------------+------------+\n\nSequences of the same type also support comparisons. In particular,\ntuples and lists are compared lexicographically by comparing\ncorresponding elements. This means that to compare equal, every\nelement must compare equal and the two sequences must be of the same\ntype and have the same length. (For full details see *Comparisons* in\nthe language reference.)\n\nNotes:\n\n1. While the "in" and "not in" operations are used only for simple\n containment testing in the general case, some specialised sequences\n (such as "str", "bytes" and "bytearray") also use them for\n subsequence testing:\n\n >>> "gg" in "eggs"\n True\n\n2. Values of *n* less than "0" are treated as "0" (which yields an\n empty sequence of the same type as *s*). Note that items in the\n sequence *s* are not copied; they are referenced multiple times.\n This often haunts 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 references\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\n Further explanation is available in the FAQ entry *How do I create\n a multidimensional list?*.\n\n3. If *i* or *j* is negative, the index is relative to the end of\n the 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 "None",\n use "0". If *j* is omitted or "None", use "len(s)". If *i* is\n greater than or equal to *j*, the slice is 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", "i+2*k",\n "i+3*k" and so on, stopping when *j* is reached (but never\n including *j*). If *i* or *j* is greater than "len(s)", use\n "len(s)". If *i* or *j* are omitted or "None", they become "end"\n values (which end depends on the sign of *k*). Note, *k* cannot be\n zero. If *k* is "None", it is treated like "1".\n\n6. Concatenating immutable sequences always results in a new\n object. This means that building up a sequence by repeated\n concatenation will have a quadratic runtime cost in the total\n sequence length. To get a linear runtime cost, you must switch to\n one of the alternatives below:\n\n * if concatenating "str" objects, you can build a list and use\n "str.join()" at the end or else write to an "io.StringIO"\n instance and retrieve its value when complete\n\n * if concatenating "bytes" objects, you can similarly use\n "bytes.join()" or "io.BytesIO", or you can do in-place\n concatenation with a "bytearray" object. "bytearray" objects are\n mutable and have an efficient overallocation mechanism\n\n * if concatenating "tuple" objects, extend a "list" instead\n\n * for other types, investigate the relevant class documentation\n\n7. Some sequence types (such as "range") only support item\n sequences that follow specific patterns, and hence don\'t support\n sequence concatenation or repetition.\n\n8. "index" raises "ValueError" when *x* is not found in *s*. When\n supported, the additional arguments to the index method allow\n efficient searching of subsections of the sequence. Passing the\n extra arguments is roughly equivalent to using "s[i:j].index(x)",\n only without copying any data and with the returned index being\n relative to the start of the sequence rather than the start of the\n slice.\n\n\nImmutable Sequence Types\n========================\n\nThe only operation that immutable sequence types generally implement\nthat is not also implemented by mutable sequence types is support for\nthe "hash()" built-in.\n\nThis support allows immutable sequences, such as "tuple" instances, to\nbe used as "dict" keys and stored in "set" and "frozenset" instances.\n\nAttempting to hash an immutable sequence that contains unhashable\nvalues will result in "TypeError".\n\n\nMutable Sequence Types\n======================\n\nThe operations in the following table are defined on mutable sequence\ntypes. The "collections.abc.MutableSequence" ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, "bytearray" only\naccepts integers that meet the value restriction "0 <= x <= 255").\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| "s[i] = x" | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j] = t" | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j]" | same as "s[i:j] = []" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j:k] = t" | the elements of "s[i:j:k]" are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j:k]" | removes the elements of | |\n| | "s[i:j:k]" from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.append(x)" | appends *x* to the end of the | |\n| | sequence (same as | |\n| | "s[len(s):len(s)] = [x]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.clear()" | removes all items from "s" (same | (5) |\n| | as "del s[:]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.copy()" | creates a shallow copy of "s" | (5) |\n| | (same as "s[:]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.extend(t)" or "s += t" | extends *s* with the contents of | |\n| | *t* (for the most part the same | |\n| | as "s[len(s):len(s)] = t") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s *= n" | updates *s* with its contents | (6) |\n| | repeated *n* times | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.insert(i, x)" | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | "s[i:i] = [x]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.pop([i])" | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.remove(x)" | remove the first item from *s* | (3) |\n| | where "s[i] == x" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.reverse()" | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to "-1", so that by default\n the last item is removed and returned.\n\n3. "remove" raises "ValueError" when *x* is not found in *s*.\n\n4. The "reverse()" method modifies the sequence in place for\n economy of space when reversing a large sequence. To remind users\n that it operates by side effect, it does not return the reversed\n sequence.\n\n5. "clear()" and "copy()" are included for consistency with the\n interfaces of mutable containers that don\'t support slicing\n operations (such as "dict" and "set")\n\n New in version 3.3: "clear()" and "copy()" methods.\n\n6. The value *n* is an integer, or an object implementing\n "__index__()". Zero and negative values of *n* clear the sequence.\n Items in the sequence are not copied; they are referenced multiple\n times, as explained for "s * n" under *Common Sequence Operations*.\n\n\nLists\n=====\n\nLists are mutable sequences, typically used to store collections of\nhomogeneous items (where the precise degree of similarity will vary by\napplication).\n\nclass class list([iterable])\n\n Lists may be constructed in several ways:\n\n * Using a pair of square brackets to denote the empty list: "[]"\n\n * Using square brackets, separating items with commas: "[a]",\n "[a, b, c]"\n\n * Using a list comprehension: "[x for x in iterable]"\n\n * Using the type constructor: "list()" or "list(iterable)"\n\n The constructor builds a list whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a list, a copy is made and\n returned, similar to "iterable[:]". For example, "list(\'abc\')"\n returns "[\'a\', \'b\', \'c\']" and "list( (1, 2, 3) )" returns "[1, 2,\n 3]". If no argument is given, the constructor creates a new empty\n list, "[]".\n\n Many other operations also produce lists, including the "sorted()"\n built-in.\n\n Lists implement all of the *common* and *mutable* sequence\n operations. Lists also provide the following additional method:\n\n sort(*, key=None, reverse=None)\n\n This method sorts the list in place, using only "<" comparisons\n between items. Exceptions are not suppressed - if any comparison\n operations fail, the entire sort operation will fail (and the\n list will likely be left in a partially modified state).\n\n "sort()" accepts two arguments that can only be passed by\n keyword (*keyword-only arguments*):\n\n *key* specifies a function of one argument that is used to\n extract a comparison key from each list element (for example,\n "key=str.lower"). The key corresponding to each item in the list\n is calculated once and then used for the entire sorting process.\n The default value of "None" means that list items are sorted\n directly without calculating a separate key value.\n\n The "functools.cmp_to_key()" utility is available to convert a\n 2.x style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to "True", then the list\n elements are sorted as if each comparison were reversed.\n\n This method modifies the sequence in place for economy of space\n when sorting a large sequence. To remind users that it operates\n by side effect, it does not return the sorted sequence (use\n "sorted()" to explicitly request a new sorted list instance).\n\n The "sort()" method is guaranteed to be stable. A sort is\n stable if it guarantees not to change the relative order of\n elements that compare equal --- this is helpful for sorting in\n multiple passes (for example, sort by department, then by salary\n grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises "ValueError" if it can detect\n that the list has been mutated during a sort.\n\n\nTuples\n======\n\nTuples are immutable sequences, typically used to store collections of\nheterogeneous data (such as the 2-tuples produced by the "enumerate()"\nbuilt-in). Tuples are also used for cases where an immutable sequence\nof homogeneous data is needed (such as allowing storage in a "set" or\n"dict" instance).\n\nclass class tuple([iterable])\n\n Tuples may be constructed in a number of ways:\n\n * Using a pair of parentheses to denote the empty tuple: "()"\n\n * Using a trailing comma for a singleton tuple: "a," or "(a,)"\n\n * Separating items with commas: "a, b, c" or "(a, b, c)"\n\n * Using the "tuple()" built-in: "tuple()" or "tuple(iterable)"\n\n The constructor builds a tuple whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a tuple, it is returned\n unchanged. For example, "tuple(\'abc\')" returns "(\'a\', \'b\', \'c\')"\n and "tuple( [1, 2, 3] )" returns "(1, 2, 3)". If no argument is\n given, the constructor creates a new empty tuple, "()".\n\n Note that it is actually the comma which makes a tuple, not the\n parentheses. The parentheses are optional, except in the empty\n tuple case, or when they are needed to avoid syntactic ambiguity.\n For example, "f(a, b, c)" is a function call with three arguments,\n while "f((a, b, c))" is a function call with a 3-tuple as the sole\n argument.\n\n Tuples implement all of the *common* sequence operations.\n\nFor heterogeneous collections of data where access by name is clearer\nthan access by index, "collections.namedtuple()" may be a more\nappropriate choice than a simple tuple object.\n\n\nRanges\n======\n\nThe "range" type represents an immutable sequence of numbers and is\ncommonly used for looping a specific number of times in "for" loops.\n\nclass class range(stop)\nclass class range(start, stop[, step])\n\n The arguments to the range constructor must be integers (either\n built-in "int" or any object that implements the "__index__"\n special method). If the *step* argument is omitted, it defaults to\n "1". If the *start* argument is omitted, it defaults to "0". If\n *step* is zero, "ValueError" is raised.\n\n For a positive *step*, the contents of a range "r" are determined\n by the formula "r[i] = start + step*i" where "i >= 0" and "r[i] <\n stop".\n\n For a negative *step*, the contents of the range are still\n determined by the formula "r[i] = start + step*i", but the\n constraints are "i >= 0" and "r[i] > stop".\n\n A range object will be empty if "r[0]" does not meet the value\n constraint. Ranges do support negative indices, but these are\n interpreted as indexing from the end of the sequence determined by\n the positive indices.\n\n Ranges containing absolute values larger than "sys.maxsize" are\n permitted but some features (such as "len()") may raise\n "OverflowError".\n\n Range examples:\n\n >>> list(range(10))\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n >>> list(range(1, 11))\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n >>> list(range(0, 30, 5))\n [0, 5, 10, 15, 20, 25]\n >>> list(range(0, 10, 3))\n [0, 3, 6, 9]\n >>> list(range(0, -10, -1))\n [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n >>> list(range(0))\n []\n >>> list(range(1, 0))\n []\n\n Ranges implement all of the *common* sequence operations except\n concatenation and repetition (due to the fact that range objects\n can only represent sequences that follow a strict pattern and\n repetition and concatenation will usually violate that pattern).\n\n start\n\n The value of the *start* parameter (or "0" if the parameter was\n not supplied)\n\n stop\n\n The value of the *stop* parameter\n\n step\n\n The value of the *step* parameter (or "1" if the parameter was\n not supplied)\n\nThe advantage of the "range" type over a regular "list" or "tuple" is\nthat a "range" object will always take the same (small) amount of\nmemory, no matter the size of the range it represents (as it only\nstores the "start", "stop" and "step" values, calculating individual\nitems and subranges as needed).\n\nRange objects implement the "collections.abc.Sequence" ABC, and\nprovide features such as containment tests, element index lookup,\nslicing and support for negative indices (see *Sequence Types ---\nlist, tuple, range*):\n\n>>> r = range(0, 20, 2)\n>>> r\nrange(0, 20, 2)\n>>> 11 in r\nFalse\n>>> 10 in r\nTrue\n>>> r.index(10)\n5\n>>> r[5]\n10\n>>> r[:5]\nrange(0, 10, 2)\n>>> r[-1]\n18\n\nTesting range objects for equality with "==" and "!=" compares them as\nsequences. That is, two range objects are considered equal if they\nrepresent the same sequence of values. (Note that two range objects\nthat compare equal might have different "start", "stop" and "step"\nattributes, for example "range(0) == range(2, 1, 3)" or "range(0, 3,\n2) == range(0, 4, 2)".)\n\nChanged in version 3.2: Implement the Sequence ABC. Support slicing\nand negative indices. Test "int" objects for membership in constant\ntime instead of iterating through all items.\n\nChanged in version 3.3: Define \'==\' and \'!=\' to compare range objects\nbased on the sequence of values they define (instead of comparing\nbased on object identity).\n\nNew in version 3.3: The "start", "stop" and "step" attributes.\n',
- 'typesseq-mutable': u'\nMutable Sequence Types\n**********************\n\nThe operations in the following table are defined on mutable sequence\ntypes. The "collections.abc.MutableSequence" ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, "bytearray" only\naccepts integers that meet the value restriction "0 <= x <= 255").\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| "s[i] = x" | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j] = t" | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j]" | same as "s[i:j] = []" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j:k] = t" | the elements of "s[i:j:k]" are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j:k]" | removes the elements of | |\n| | "s[i:j:k]" from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.append(x)" | appends *x* to the end of the | |\n| | sequence (same as | |\n| | "s[len(s):len(s)] = [x]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.clear()" | removes all items from "s" (same | (5) |\n| | as "del s[:]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.copy()" | creates a shallow copy of "s" | (5) |\n| | (same as "s[:]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.extend(t)" or "s += t" | extends *s* with the contents of | |\n| | *t* (for the most part the same | |\n| | as "s[len(s):len(s)] = t") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s *= n" | updates *s* with its contents | (6) |\n| | repeated *n* times | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.insert(i, x)" | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | "s[i:i] = [x]") | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.pop([i])" | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.remove(x)" | remove the first item from *s* | (3) |\n| | where "s[i] == x" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.reverse()" | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to "-1", so that by default\n the last item is removed and returned.\n\n3. "remove" raises "ValueError" when *x* is not found in *s*.\n\n4. The "reverse()" method modifies the sequence in place for\n economy of space when reversing a large sequence. To remind users\n that it operates by side effect, it does not return the reversed\n sequence.\n\n5. "clear()" and "copy()" are included for consistency with the\n interfaces of mutable containers that don\'t support slicing\n operations (such as "dict" and "set")\n\n New in version 3.3: "clear()" and "copy()" methods.\n\n6. The value *n* is an integer, or an object implementing\n "__index__()". Zero and negative values of *n* clear the sequence.\n Items in the sequence are not copied; they are referenced multiple\n times, as explained for "s * n" under *Common Sequence Operations*.\n',
- 'unary': u'\nUnary arithmetic and bitwise operations\n***************************************\n\nAll unary arithmetic and bitwise operations have the same priority:\n\n u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n\nThe unary "-" (minus) operator yields the negation of its numeric\nargument.\n\nThe unary "+" (plus) operator yields its numeric argument unchanged.\n\nThe unary "~" (invert) operator yields the bitwise inversion of its\ninteger argument. The bitwise inversion of "x" is defined as\n"-(x+1)". It only applies to integral numbers.\n\nIn all three cases, if the argument does not have the proper type, a\n"TypeError" exception is raised.\n',
- 'while': u'\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 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" statement\nexecuted in the first suite skips the rest of the suite and goes back\nto testing the expression.\n',
- 'with': u'\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 "try"..."except"..."finally"\nusage patterns to be encapsulated for convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the "with" statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the "with_item")\n is evaluated to obtain a context manager.\n\n2. The context manager\'s "__exit__()" is loaded for later use.\n\n3. The context manager\'s "__enter__()" method is invoked.\n\n4. If a target was included in the "with" statement, the return\n value from "__enter__()" is assigned to it.\n\n Note: The "with" statement guarantees that if the "__enter__()"\n method returns without an error, then "__exit__()" will always be\n called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s "__exit__()" method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to "__exit__()". Otherwise, three\n "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 reraised.\n If the return value was true, the exception is suppressed, and\n execution continues with the statement following the "with"\n statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from "__exit__()" is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple "with" statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also: **PEP 343** - The "with" statement\n\n The specification, background, and examples for the Python "with"\n statement.\n',
- 'yield': u'\nThe "yield" statement\n*********************\n\n yield_stmt ::= yield_expression\n\nA "yield" statement is semantically equivalent to a *yield\nexpression*. The yield statement can be used to omit the parentheses\nthat would otherwise be required in the equivalent yield expression\nstatement. For example, the yield statements\n\n yield <expr>\n yield from <expr>\n\nare equivalent to the yield expression statements\n\n (yield <expr>)\n (yield from <expr>)\n\nYield expressions and statements are only used when defining a\n*generator* function, and are only used in the body of the generator\nfunction. Using yield in a function definition is sufficient to cause\nthat definition to create a generator function instead of a normal\nfunction.\n\nFor full details of "yield" semantics, refer to the *Yield\nexpressions* section.\n'}
+# Autogenerated by Sphinx on Mon Oct 10 15:59:17 2016
+topics = {'assert': '\n'
+ 'The "assert" statement\n'
+ '**********************\n'
+ '\n'
+ 'Assert statements are a convenient way to insert debugging '
+ 'assertions\n'
+ 'into a program:\n'
+ '\n'
+ ' assert_stmt ::= "assert" expression ["," expression]\n'
+ '\n'
+ 'The simple form, "assert expression", is equivalent to\n'
+ '\n'
+ ' if __debug__:\n'
+ ' if not expression: raise AssertionError\n'
+ '\n'
+ 'The extended form, "assert expression1, expression2", is '
+ 'equivalent to\n'
+ '\n'
+ ' if __debug__:\n'
+ ' if not expression1: raise AssertionError(expression2)\n'
+ '\n'
+ 'These equivalences assume that "__debug__" and "AssertionError" '
+ 'refer\n'
+ 'to the built-in variables with those names. In the current\n'
+ 'implementation, the built-in variable "__debug__" is "True" under\n'
+ 'normal circumstances, "False" when optimization is requested '
+ '(command\n'
+ 'line option -O). The current code generator emits no code for an\n'
+ 'assert statement when optimization is requested at compile time. '
+ 'Note\n'
+ 'that it is unnecessary to include the source code for the '
+ 'expression\n'
+ 'that failed in the error message; it will be displayed as part of '
+ 'the\n'
+ 'stack trace.\n'
+ '\n'
+ 'Assignments to "__debug__" are illegal. The value for the '
+ 'built-in\n'
+ 'variable is determined when the interpreter starts.\n',
+ 'assignment': '\n'
+ 'Assignment statements\n'
+ '*********************\n'
+ '\n'
+ 'Assignment statements are used to (re)bind names to values and '
+ 'to\n'
+ 'modify attributes or items of mutable objects:\n'
+ '\n'
+ ' assignment_stmt ::= (target_list "=")+ (starred_expression '
+ '| 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 '
+ '*attributeref*,\n'
+ '*subscription*, and *slicing*.)\n'
+ '\n'
+ 'An assignment statement evaluates the expression list '
+ '(remember that\n'
+ 'this can be a single expression or a comma-separated list, the '
+ 'latter\n'
+ 'yielding a tuple) and assigns the single resulting object to '
+ 'each of\n'
+ 'the target lists, from left to right.\n'
+ '\n'
+ 'Assignment is defined recursively depending on the form of the '
+ 'target\n'
+ '(list). When a target is part of a mutable object (an '
+ 'attribute\n'
+ 'reference, subscription or slicing), the mutable object must\n'
+ 'ultimately perform the assignment and decide about its '
+ 'validity, and\n'
+ 'may raise an exception if the assignment is unacceptable. The '
+ 'rules\n'
+ 'observed by various types and the exceptions raised are given '
+ 'with the\n'
+ 'definition of the object types (see section The standard type\n'
+ 'hierarchy).\n'
+ '\n'
+ 'Assignment of an object to a target list, optionally enclosed '
+ 'in\n'
+ 'parentheses or square brackets, is recursively defined as '
+ 'follows.\n'
+ '\n'
+ '* If the target list is empty: The object must also be an '
+ 'empty\n'
+ ' iterable.\n'
+ '\n'
+ '* If the target list is a single target in parentheses: The '
+ 'object\n'
+ ' is assigned to that target.\n'
+ '\n'
+ '* If the target list is a comma-separated list of targets, or '
+ 'a\n'
+ ' single target in square brackets: The object must be an '
+ 'iterable\n'
+ ' with the same number of items as there are targets in the '
+ 'target\n'
+ ' list, and the items are assigned, from left to right, to '
+ 'the\n'
+ ' corresponding targets.\n'
+ '\n'
+ ' * If the target list contains one target prefixed with an\n'
+ ' asterisk, called a "starred" target: The object must be '
+ 'an\n'
+ ' iterable with at least as many items as there are targets '
+ 'in the\n'
+ ' target list, minus one. The first items of the iterable '
+ 'are\n'
+ ' assigned, from left to right, to the targets before the '
+ 'starred\n'
+ ' target. The final items of the iterable are assigned to '
+ 'the\n'
+ ' targets after the starred target. A list of the remaining '
+ 'items\n'
+ ' in the iterable is then assigned to the starred target '
+ '(the list\n'
+ ' can be empty).\n'
+ '\n'
+ ' * Else: The object must be an iterable with the same number '
+ 'of\n'
+ ' items as there are targets in the target list, and the '
+ 'items are\n'
+ ' assigned, from left to right, to the corresponding '
+ 'targets.\n'
+ '\n'
+ 'Assignment of an object to a single target is recursively '
+ 'defined as\n'
+ 'follows.\n'
+ '\n'
+ '* If the target is an identifier (name):\n'
+ '\n'
+ ' * If the name does not occur in a "global" or "nonlocal" '
+ 'statement\n'
+ ' in the current code block: the name is bound to the object '
+ 'in the\n'
+ ' current local namespace.\n'
+ '\n'
+ ' * Otherwise: the name is bound to the object in the global\n'
+ ' namespace or the outer namespace determined by '
+ '"nonlocal",\n'
+ ' respectively.\n'
+ '\n'
+ ' The name is rebound if it was already bound. This may cause '
+ 'the\n'
+ ' reference count for the object previously bound to the name '
+ 'to reach\n'
+ ' zero, causing the object to be deallocated and its '
+ 'destructor (if it\n'
+ ' has one) to be called.\n'
+ '\n'
+ '* If the target is an attribute reference: The primary '
+ 'expression in\n'
+ ' the reference is evaluated. It should yield an object with\n'
+ ' assignable attributes; if this is not the case, "TypeError" '
+ 'is\n'
+ ' raised. That object is then asked to assign the assigned '
+ 'object to\n'
+ ' the given attribute; if it cannot perform the assignment, it '
+ 'raises\n'
+ ' an exception (usually but not necessarily '
+ '"AttributeError").\n'
+ '\n'
+ ' Note: If the object is a class instance and the attribute '
+ 'reference\n'
+ ' occurs on both sides of the assignment operator, the RHS '
+ 'expression,\n'
+ ' "a.x" can access either an instance attribute or (if no '
+ 'instance\n'
+ ' attribute exists) a class attribute. The LHS target "a.x" '
+ 'is always\n'
+ ' set as an instance attribute, creating it if necessary. '
+ 'Thus, the\n'
+ ' two occurrences of "a.x" do not necessarily refer to the '
+ 'same\n'
+ ' attribute: if the RHS expression refers to a class '
+ 'attribute, the\n'
+ ' LHS creates a new instance attribute as the target of the\n'
+ ' assignment:\n'
+ '\n'
+ ' class Cls:\n'
+ ' x = 3 # class variable\n'
+ ' inst = Cls()\n'
+ ' inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x '
+ 'as 3\n'
+ '\n'
+ ' This description does not necessarily apply to descriptor\n'
+ ' attributes, such as properties created with "property()".\n'
+ '\n'
+ '* If the target is a subscription: The primary expression in '
+ 'the\n'
+ ' reference is evaluated. It should yield either a mutable '
+ 'sequence\n'
+ ' object (such as a list) or a mapping object (such as a '
+ 'dictionary).\n'
+ ' Next, the subscript expression is evaluated.\n'
+ '\n'
+ ' If the primary is a mutable sequence object (such as a '
+ 'list), the\n'
+ ' subscript must yield an integer. If it is negative, the '
+ "sequence's\n"
+ ' length is added to it. The resulting value must be a '
+ 'nonnegative\n'
+ " integer less than the sequence's length, and the sequence is "
+ 'asked\n'
+ ' to assign the assigned object to its item with that index. '
+ 'If the\n'
+ ' index is out of range, "IndexError" is raised (assignment to '
+ 'a\n'
+ ' subscripted sequence cannot add new items to a list).\n'
+ '\n'
+ ' If the primary is a mapping object (such as a dictionary), '
+ 'the\n'
+ " subscript must have a type compatible with the mapping's key "
+ 'type,\n'
+ ' and the mapping is then asked to create a key/datum pair '
+ 'which maps\n'
+ ' the subscript to the assigned object. This can either '
+ 'replace an\n'
+ ' existing key/value pair with the same key value, or insert a '
+ 'new\n'
+ ' key/value pair (if no key with the same value existed).\n'
+ '\n'
+ ' For user-defined objects, the "__setitem__()" method is '
+ 'called with\n'
+ ' appropriate arguments.\n'
+ '\n'
+ '* If the target is a slicing: The primary expression in the\n'
+ ' reference is evaluated. It should yield a mutable sequence '
+ 'object\n'
+ ' (such as a list). The assigned object should be a sequence '
+ 'object\n'
+ ' of the same type. Next, the lower and upper bound '
+ 'expressions are\n'
+ ' evaluated, insofar they are present; defaults are zero and '
+ 'the\n'
+ " sequence's length. The bounds should evaluate to integers. "
+ 'If\n'
+ " either bound is negative, the sequence's length is added to "
+ 'it. The\n'
+ ' resulting bounds are clipped to lie between zero and the '
+ "sequence's\n"
+ ' length, inclusive. Finally, the sequence object is asked to '
+ 'replace\n'
+ ' the slice with the items of the assigned sequence. The '
+ 'length of\n'
+ ' the slice may be different from the length of the assigned '
+ 'sequence,\n'
+ ' thus changing the length of the target sequence, if the '
+ 'target\n'
+ ' sequence allows it.\n'
+ '\n'
+ '**CPython implementation detail:** In the current '
+ 'implementation, the\n'
+ 'syntax for targets is taken to be the same as for expressions, '
+ 'and\n'
+ 'invalid syntax is rejected during the code generation phase, '
+ 'causing\n'
+ 'less detailed error messages.\n'
+ '\n'
+ 'Although the definition of assignment implies that overlaps '
+ 'between\n'
+ "the left-hand side and the right-hand side are 'simultaneous' "
+ '(for\n'
+ 'example "a, b = b, a" swaps two variables), overlaps *within* '
+ 'the\n'
+ 'collection of assigned-to variables occur left-to-right, '
+ 'sometimes\n'
+ 'resulting in confusion. For instance, the following program '
+ 'prints\n'
+ '"[0, 2]":\n'
+ '\n'
+ ' x = [0, 1]\n'
+ ' i = 0\n'
+ ' i, x[i] = 1, 2 # i is updated, then x[i] is '
+ 'updated\n'
+ ' print(x)\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 3132** - Extended Iterable Unpacking\n'
+ ' The specification for the "*target" feature.\n'
+ '\n'
+ '\n'
+ 'Augmented assignment statements\n'
+ '===============================\n'
+ '\n'
+ 'Augmented assignment is the combination, in a single '
+ 'statement, of a\n'
+ 'binary operation and an assignment statement:\n'
+ '\n'
+ ' augmented_assignment_stmt ::= augtarget augop '
+ '(expression_list | yield_expression)\n'
+ ' augtarget ::= identifier | attributeref | '
+ 'subscription | slicing\n'
+ ' augop ::= "+=" | "-=" | "*=" | "@=" | '
+ '"/=" | "//=" | "%=" | "**="\n'
+ ' | ">>=" | "<<=" | "&=" | "^=" | "|="\n'
+ '\n'
+ '(See section Primaries for the syntax definitions of the last '
+ 'three\n'
+ 'symbols.)\n'
+ '\n'
+ 'An augmented assignment evaluates the target (which, unlike '
+ 'normal\n'
+ 'assignment statements, cannot be an unpacking) and the '
+ 'expression\n'
+ 'list, performs the binary operation specific to the type of '
+ 'assignment\n'
+ 'on the two operands, and assigns the result to the original '
+ 'target.\n'
+ 'The target is only evaluated once.\n'
+ '\n'
+ 'An augmented assignment expression like "x += 1" can be '
+ 'rewritten as\n'
+ '"x = x + 1" to achieve a similar, but not exactly equal '
+ 'effect. In the\n'
+ 'augmented version, "x" is only evaluated once. Also, when '
+ 'possible,\n'
+ 'the actual operation is performed *in-place*, meaning that '
+ 'rather than\n'
+ 'creating a new object and assigning that to the target, the '
+ 'old object\n'
+ 'is modified instead.\n'
+ '\n'
+ 'Unlike normal assignments, augmented assignments evaluate the '
+ 'left-\n'
+ 'hand side *before* evaluating the right-hand side. For '
+ 'example, "a[i]\n'
+ '+= f(x)" first looks-up "a[i]", then it evaluates "f(x)" and '
+ 'performs\n'
+ 'the addition, and lastly, it writes the result back to '
+ '"a[i]".\n'
+ '\n'
+ 'With the exception of assigning to tuples and multiple targets '
+ 'in a\n'
+ 'single statement, the assignment done by augmented assignment\n'
+ 'statements is handled the same way as normal assignments. '
+ 'Similarly,\n'
+ 'with the exception of the possible *in-place* behavior, the '
+ 'binary\n'
+ 'operation performed by augmented assignment is the same as the '
+ 'normal\n'
+ 'binary operations.\n'
+ '\n'
+ 'For targets which are attribute references, the same caveat '
+ 'about\n'
+ 'class and instance attributes applies as for regular '
+ 'assignments.\n'
+ '\n'
+ '\n'
+ 'Annotated assignment statements\n'
+ '===============================\n'
+ '\n'
+ 'Annotation assignment is the combination, in a single '
+ 'statement, of a\n'
+ 'variable or attribute annotation and an optional assignment '
+ 'statement:\n'
+ '\n'
+ ' annotated_assignment_stmt ::= augtarget ":" expression ["=" '
+ 'expression]\n'
+ '\n'
+ 'The difference from normal Assignment statements is that only '
+ 'single\n'
+ 'target and only single right hand side value is allowed.\n'
+ '\n'
+ 'For simple names as assignment targets, if in class or module '
+ 'scope,\n'
+ 'the annotations are evaluated and stored in a special class or '
+ 'module\n'
+ 'attribute "__annotations__" that is a dictionary mapping from '
+ 'variable\n'
+ 'names (mangled if private) to evaluated annotations. This '
+ 'attribute is\n'
+ 'writable and is automatically created at the start of class or '
+ 'module\n'
+ 'body execution, if annotations are found statically.\n'
+ '\n'
+ 'For expressions as assignment targets, the annotations are '
+ 'evaluated\n'
+ 'if in class or module scope, but not stored.\n'
+ '\n'
+ 'If a name is annotated in a function scope, then this name is '
+ 'local\n'
+ 'for that scope. Annotations are never evaluated and stored in '
+ 'function\n'
+ 'scopes.\n'
+ '\n'
+ 'If the right hand side is present, an annotated assignment '
+ 'performs\n'
+ 'the actual assignment before evaluating annotations (where\n'
+ 'applicable). If the right hand side is not present for an '
+ 'expression\n'
+ 'target, then the interpreter evaluates the target except for '
+ 'the last\n'
+ '"__setitem__()" or "__setattr__()" call.\n'
+ '\n'
+ 'See also: **PEP 526** - Variable and attribute annotation '
+ 'syntax\n'
+ ' **PEP 484** - Type hints\n',
+ 'atom-identifiers': '\n'
+ 'Identifiers (Names)\n'
+ '*******************\n'
+ '\n'
+ 'An identifier occurring as an atom is a name. See '
+ 'section Identifiers\n'
+ 'and keywords for lexical definition and section Naming '
+ 'and binding for\n'
+ 'documentation of naming and binding.\n'
+ '\n'
+ 'When the name is bound to an object, evaluation of the '
+ 'atom yields\n'
+ 'that object. When a name is not bound, an attempt to '
+ 'evaluate it\n'
+ 'raises a "NameError" exception.\n'
+ '\n'
+ '**Private name mangling:** When an identifier that '
+ 'textually occurs in\n'
+ 'a class definition begins with two or more underscore '
+ 'characters and\n'
+ 'does not end in two or more underscores, it is '
+ 'considered a *private\n'
+ 'name* of that class. Private names are transformed to a '
+ 'longer form\n'
+ 'before code is generated for them. The transformation '
+ 'inserts the\n'
+ 'class name, with leading underscores removed and a '
+ 'single underscore\n'
+ 'inserted, in front of the name. For example, the '
+ 'identifier "__spam"\n'
+ 'occurring in a class named "Ham" will be transformed to '
+ '"_Ham__spam".\n'
+ 'This transformation is independent of the syntactical '
+ 'context in which\n'
+ 'the identifier is used. If the transformed name is '
+ 'extremely long\n'
+ '(longer than 255 characters), implementation defined '
+ 'truncation may\n'
+ 'happen. If the class name consists only of underscores, '
+ 'no\n'
+ 'transformation is done.\n',
+ 'atom-literals': '\n'
+ 'Literals\n'
+ '********\n'
+ '\n'
+ 'Python supports string and bytes literals and various '
+ 'numeric\n'
+ 'literals:\n'
+ '\n'
+ ' literal ::= stringliteral | bytesliteral\n'
+ ' | integer | floatnumber | imagnumber\n'
+ '\n'
+ 'Evaluation of a literal yields an object of the given type '
+ '(string,\n'
+ 'bytes, integer, floating point number, complex number) with '
+ 'the given\n'
+ 'value. The value may be approximated in the case of '
+ 'floating point\n'
+ 'and imaginary (complex) literals. See section Literals for '
+ 'details.\n'
+ '\n'
+ 'All literals correspond to immutable data types, and hence '
+ 'the\n'
+ "object's identity is less important than its value. "
+ 'Multiple\n'
+ 'evaluations of literals with the same value (either the '
+ 'same\n'
+ 'occurrence in the program text or a different occurrence) '
+ 'may obtain\n'
+ 'the same object or a different object with the same '
+ 'value.\n',
+ 'attribute-access': '\n'
+ 'Customizing attribute access\n'
+ '****************************\n'
+ '\n'
+ 'The following methods can be defined to customize the '
+ 'meaning of\n'
+ 'attribute access (use of, assignment to, or deletion of '
+ '"x.name") for\n'
+ 'class instances.\n'
+ '\n'
+ 'object.__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. This\n'
+ ' method should return the (computed) attribute value '
+ 'or raise an\n'
+ ' "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 for\n'
+ ' efficiency reasons and because otherwise '
+ '"__getattr__()" would have\n'
+ ' no way to access other attributes of the instance. '
+ 'Note that at\n'
+ ' least for instance variables, you can fake total '
+ 'control by not\n'
+ ' 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'
+ '\n'
+ 'object.__getattribute__(self, name)\n'
+ '\n'
+ ' Called unconditionally to implement attribute '
+ 'accesses for\n'
+ ' instances of the class. If the class also defines '
+ '"__getattr__()",\n'
+ ' the latter will not be called unless '
+ '"__getattribute__()" either\n'
+ ' calls it explicitly or raises an "AttributeError". '
+ 'This method\n'
+ ' should return the (computed) attribute value or raise '
+ 'an\n'
+ ' "AttributeError" exception. In order to avoid '
+ 'infinite recursion in\n'
+ ' this method, its implementation should always call '
+ 'the base class\n'
+ ' method with the same name to access any attributes it '
+ 'needs, for\n'
+ ' example, "object.__getattribute__(self, name)".\n'
+ '\n'
+ ' Note: This method may still be bypassed when looking '
+ 'up special\n'
+ ' methods as the result of implicit invocation via '
+ 'language syntax\n'
+ ' or built-in functions. See Special method lookup.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__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'
+ 'object.__dir__(self)\n'
+ '\n'
+ ' Called when "dir()" is called on the object. A '
+ 'sequence must be\n'
+ ' returned. "dir()" converts the returned sequence to a '
+ 'list and\n'
+ ' sorts it.\n'
+ '\n'
+ '\n'
+ 'Implementing Descriptors\n'
+ '========================\n'
+ '\n'
+ 'The following methods only apply when an instance of the '
+ 'class\n'
+ 'containing the method (a so-called *descriptor* class) '
+ 'appears in an\n'
+ '*owner* class (the descriptor must be in either the '
+ "owner's class\n"
+ 'dictionary or in the class dictionary for one of its '
+ 'parents). In the\n'
+ 'examples below, "the attribute" refers to the attribute '
+ 'whose name is\n'
+ "the key of the property in the owner class' "
+ '"__dict__".\n'
+ '\n'
+ 'object.__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 '
+ '"AttributeError"\n'
+ ' exception.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__delete__(self, instance)\n'
+ '\n'
+ ' Called to delete the attribute on an instance '
+ '*instance* of the\n'
+ ' owner class.\n'
+ '\n'
+ 'object.__set_name__(self, owner, name)\n'
+ '\n'
+ ' Called at the time the owning class *owner* is '
+ 'created. The\n'
+ ' descriptor has been assigned to *name*.\n'
+ '\n'
+ ' New in version 3.6.\n'
+ '\n'
+ 'The attribute "__objclass__" is interpreted by the '
+ '"inspect" module as\n'
+ 'specifying the class where this object was defined '
+ '(setting this\n'
+ 'appropriately can assist in runtime introspection of '
+ 'dynamic class\n'
+ 'attributes). For callables, it may indicate that an '
+ 'instance of the\n'
+ 'given type (or a subclass) is expected or required as '
+ 'the first\n'
+ 'positional argument (for example, CPython sets this '
+ 'attribute for\n'
+ 'unbound methods that are implemented in C).\n'
+ '\n'
+ '\n'
+ 'Invoking Descriptors\n'
+ '====================\n'
+ '\n'
+ 'In general, a descriptor is an object attribute with '
+ '"binding\n'
+ 'behavior", one whose attribute access has been '
+ 'overridden by methods\n'
+ 'in the descriptor protocol: "__get__()", "__set__()", '
+ 'and\n'
+ '"__delete__()". If any of those methods are defined for '
+ 'an object, it\n'
+ 'is said to be a descriptor.\n'
+ '\n'
+ 'The default behavior for attribute access is to get, '
+ 'set, or delete\n'
+ "the attribute from an object's dictionary. For instance, "
+ '"a.x" has a\n'
+ 'lookup 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'
+ '\n'
+ 'However, if the looked-up value is an object defining '
+ 'one of the\n'
+ 'descriptor methods, then Python may override the default '
+ 'behavior and\n'
+ 'invoke the descriptor method instead. Where this occurs '
+ 'in the\n'
+ 'precedence chain depends on which descriptor methods '
+ 'were defined and\n'
+ 'how they were called.\n'
+ '\n'
+ 'The starting point for descriptor invocation is a '
+ 'binding, "a.x". How\n'
+ 'the arguments are assembled depends on "a":\n'
+ '\n'
+ 'Direct Call\n'
+ ' The simplest and least common call is when user code '
+ 'directly\n'
+ ' invokes a descriptor method: "x.__get__(a)".\n'
+ '\n'
+ 'Instance 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'
+ '\n'
+ 'Class Binding\n'
+ ' If binding to a class, "A.x" is transformed into the '
+ 'call:\n'
+ ' "A.__dict__[\'x\'].__get__(None, A)".\n'
+ '\n'
+ 'Super 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 "A"\n'
+ ' immediately preceding "B" and then invokes the '
+ 'descriptor with the\n'
+ ' call: "A.__dict__[\'m\'].__get__(obj, '
+ 'obj.__class__)".\n'
+ '\n'
+ 'For instance bindings, the precedence of descriptor '
+ 'invocation depends\n'
+ 'on the which descriptor methods are defined. A '
+ 'descriptor can define\n'
+ 'any combination of "__get__()", "__set__()" and '
+ '"__delete__()". If it\n'
+ 'does not define "__get__()", then accessing the '
+ 'attribute will return\n'
+ 'the descriptor object itself unless there is a value in '
+ "the object's\n"
+ 'instance dictionary. If the descriptor defines '
+ '"__set__()" and/or\n'
+ '"__delete__()", it is a data descriptor; if it defines '
+ 'neither, it is\n'
+ 'a non-data descriptor. Normally, data descriptors '
+ 'define both\n'
+ '"__get__()" and "__set__()", while non-data descriptors '
+ 'have just the\n'
+ '"__get__()" method. Data descriptors with "__set__()" '
+ 'and "__get__()"\n'
+ 'defined always override a redefinition in an instance '
+ 'dictionary. In\n'
+ 'contrast, non-data descriptors can be overridden by '
+ 'instances.\n'
+ '\n'
+ 'Python methods (including "staticmethod()" and '
+ '"classmethod()") are\n'
+ 'implemented as non-data descriptors. Accordingly, '
+ 'instances can\n'
+ 'redefine and override methods. This allows individual '
+ 'instances to\n'
+ 'acquire behaviors that differ from other instances of '
+ 'the same class.\n'
+ '\n'
+ 'The "property()" function is implemented as a data '
+ 'descriptor.\n'
+ 'Accordingly, instances cannot override the behavior of a '
+ 'property.\n'
+ '\n'
+ '\n'
+ '__slots__\n'
+ '=========\n'
+ '\n'
+ 'By default, instances of classes have a dictionary for '
+ 'attribute\n'
+ 'storage. This wastes space for objects having very few '
+ 'instance\n'
+ 'variables. The space consumption can become acute when '
+ 'creating large\n'
+ 'numbers of instances.\n'
+ '\n'
+ 'The default can be overridden by defining *__slots__* in '
+ 'a class\n'
+ 'definition. The *__slots__* declaration takes a sequence '
+ 'of instance\n'
+ 'variables and reserves just enough space in each '
+ 'instance to hold a\n'
+ 'value for each variable. Space is saved because '
+ '*__dict__* is not\n'
+ 'created for each instance.\n'
+ '\n'
+ 'object.__slots__\n'
+ '\n'
+ ' This class variable can be assigned a string, '
+ 'iterable, or sequence\n'
+ ' of strings with variable names used by instances. '
+ '*__slots__*\n'
+ ' reserves space for the declared variables and '
+ 'prevents the\n'
+ ' automatic creation of *__dict__* and *__weakref__* '
+ 'for each\n'
+ ' instance.\n'
+ '\n'
+ '\n'
+ 'Notes 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\n'
+ ' defining *__slots__* do not support weak references to '
+ 'its\n'
+ ' instances. If weak reference support is needed, then '
+ 'add\n'
+ ' "\'__weakref__\'" to the sequence of strings in the '
+ '*__slots__*\n'
+ ' declaration.\n'
+ '\n'
+ '* *__slots__* are implemented at the class level by '
+ 'creating\n'
+ ' descriptors (Implementing Descriptors) for each '
+ 'variable name. As a\n'
+ ' result, class attributes cannot be used to set default '
+ 'values for\n'
+ ' instance variables defined by *__slots__*; otherwise, '
+ 'the class\n'
+ ' attribute would overwrite the descriptor assignment.\n'
+ '\n'
+ '* The action of a *__slots__* declaration is limited to '
+ 'the class\n'
+ ' where it is defined. As a result, subclasses will '
+ 'have a *__dict__*\n'
+ ' unless they also define *__slots__* (which must only '
+ 'contain names\n'
+ ' of any *additional* slots).\n'
+ '\n'
+ '* If a class defines a slot also defined in a base '
+ 'class, the\n'
+ ' instance variable defined by the base class slot is '
+ 'inaccessible\n'
+ ' (except by retrieving its descriptor directly from the '
+ 'base class).\n'
+ ' This renders the meaning of the program undefined. In '
+ 'the future, a\n'
+ ' check may be added to prevent this.\n'
+ '\n'
+ '* Nonempty *__slots__* does not work for classes derived '
+ 'from\n'
+ ' "variable-length" built-in types such as "int", '
+ '"bytes" and "tuple".\n'
+ '\n'
+ '* Any non-string iterable may be assigned to '
+ '*__slots__*. Mappings\n'
+ ' may 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': '\n'
+ 'Attribute references\n'
+ '********************\n'
+ '\n'
+ 'An attribute reference is a primary followed by a '
+ 'period and a name:\n'
+ '\n'
+ ' attributeref ::= primary "." identifier\n'
+ '\n'
+ 'The primary must evaluate to an object of a type '
+ 'that supports\n'
+ 'attribute references, which most objects do. This '
+ 'object is then\n'
+ 'asked to produce the attribute whose name is the '
+ 'identifier. This\n'
+ 'production can be customized by overriding the '
+ '"__getattr__()" method.\n'
+ 'If this attribute is not available, the exception '
+ '"AttributeError" is\n'
+ 'raised. Otherwise, the type and value of the object '
+ 'produced is\n'
+ 'determined by the object. Multiple evaluations of '
+ 'the same attribute\n'
+ 'reference may yield different objects.\n',
+ 'augassign': '\n'
+ 'Augmented assignment statements\n'
+ '*******************************\n'
+ '\n'
+ 'Augmented assignment is the combination, in a single statement, '
+ 'of a\n'
+ 'binary operation and an assignment statement:\n'
+ '\n'
+ ' augmented_assignment_stmt ::= augtarget augop '
+ '(expression_list | yield_expression)\n'
+ ' augtarget ::= identifier | attributeref | '
+ 'subscription | slicing\n'
+ ' augop ::= "+=" | "-=" | "*=" | "@=" | '
+ '"/=" | "//=" | "%=" | "**="\n'
+ ' | ">>=" | "<<=" | "&=" | "^=" | "|="\n'
+ '\n'
+ '(See section Primaries for the syntax definitions of the last '
+ 'three\n'
+ 'symbols.)\n'
+ '\n'
+ 'An augmented assignment evaluates the target (which, unlike '
+ 'normal\n'
+ 'assignment statements, cannot be an unpacking) and the '
+ 'expression\n'
+ 'list, performs the binary operation specific to the type of '
+ 'assignment\n'
+ 'on the two operands, and assigns the result to the original '
+ 'target.\n'
+ 'The target is only evaluated once.\n'
+ '\n'
+ 'An augmented assignment expression like "x += 1" can be '
+ 'rewritten as\n'
+ '"x = x + 1" to achieve a similar, but not exactly equal effect. '
+ 'In the\n'
+ 'augmented version, "x" is only evaluated once. Also, when '
+ 'possible,\n'
+ 'the actual operation is performed *in-place*, meaning that '
+ 'rather than\n'
+ 'creating a new object and assigning that to the target, the old '
+ 'object\n'
+ 'is modified instead.\n'
+ '\n'
+ 'Unlike normal assignments, augmented assignments evaluate the '
+ 'left-\n'
+ 'hand side *before* evaluating the right-hand side. For '
+ 'example, "a[i]\n'
+ '+= f(x)" first looks-up "a[i]", then it evaluates "f(x)" and '
+ 'performs\n'
+ 'the addition, and lastly, it writes the result back to "a[i]".\n'
+ '\n'
+ 'With the exception of assigning to tuples and multiple targets '
+ 'in a\n'
+ 'single statement, the assignment done by augmented assignment\n'
+ 'statements is handled the same way as normal assignments. '
+ 'Similarly,\n'
+ 'with the exception of the possible *in-place* behavior, the '
+ 'binary\n'
+ 'operation performed by augmented assignment is the same as the '
+ 'normal\n'
+ 'binary operations.\n'
+ '\n'
+ 'For targets which are attribute references, the same caveat '
+ 'about\n'
+ 'class and instance attributes applies as for regular '
+ 'assignments.\n',
+ 'binary': '\n'
+ 'Binary arithmetic operations\n'
+ '****************************\n'
+ '\n'
+ 'The binary arithmetic operations have the conventional priority\n'
+ 'levels. Note that some of these operations also apply to certain '
+ 'non-\n'
+ 'numeric types. Apart from the power operator, there are only two\n'
+ 'levels, one for multiplicative operators and one for additive\n'
+ 'operators:\n'
+ '\n'
+ ' m_expr ::= u_expr | m_expr "*" u_expr | m_expr "@" m_expr |\n'
+ ' 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'
+ '\n'
+ 'The "*" (multiplication) operator yields the product of its '
+ 'arguments.\n'
+ 'The arguments must either both be numbers, or one argument must be '
+ 'an\n'
+ 'integer and the other must be a sequence. In the former case, the\n'
+ 'numbers are converted to a common type and then multiplied '
+ 'together.\n'
+ 'In the latter case, sequence repetition is performed; a negative\n'
+ 'repetition factor yields an empty sequence.\n'
+ '\n'
+ 'The "@" (at) operator is intended to be used for matrix\n'
+ 'multiplication. No builtin Python types implement this operator.\n'
+ '\n'
+ 'New in version 3.5.\n'
+ '\n'
+ 'The "/" (division) and "//" (floor division) operators yield the\n'
+ 'quotient of their arguments. The numeric arguments are first\n'
+ 'converted to a common type. Division of integers yields a float, '
+ 'while\n'
+ 'floor division of integers results in an integer; the result is '
+ 'that\n'
+ "of mathematical division with the 'floor' function applied to the\n"
+ 'result. Division by zero raises the "ZeroDivisionError" '
+ 'exception.\n'
+ '\n'
+ 'The "%" (modulo) operator yields the remainder from the division '
+ 'of\n'
+ 'the first argument by the second. The numeric arguments are '
+ 'first\n'
+ 'converted to a common type. A zero right argument raises the\n'
+ '"ZeroDivisionError" exception. The arguments may be floating '
+ 'point\n'
+ 'numbers, e.g., "3.14%0.7" equals "0.34" (since "3.14" equals '
+ '"4*0.7 +\n'
+ '0.34".) The modulo operator always yields a result with the same '
+ 'sign\n'
+ 'as its second operand (or zero); the absolute value of the result '
+ 'is\n'
+ 'strictly smaller than the absolute value of the second operand '
+ '[1].\n'
+ '\n'
+ 'The floor division and modulo operators are connected by the '
+ 'following\n'
+ 'identity: "x == (x//y)*y + (x%y)". Floor division and modulo are '
+ 'also\n'
+ 'connected with the built-in function "divmod()": "divmod(x, y) ==\n'
+ '(x//y, x%y)". [2].\n'
+ '\n'
+ 'In addition to performing the modulo operation on numbers, the '
+ '"%"\n'
+ 'operator is also overloaded by string objects to perform '
+ 'old-style\n'
+ 'string formatting (also known as interpolation). The syntax for\n'
+ 'string formatting is described in the Python Library Reference,\n'
+ 'section printf-style String Formatting.\n'
+ '\n'
+ 'The floor division operator, the modulo operator, and the '
+ '"divmod()"\n'
+ 'function are not defined for complex numbers. Instead, convert to '
+ 'a\n'
+ 'floating point number using the "abs()" function if appropriate.\n'
+ '\n'
+ 'The "+" (addition) operator yields the sum of its arguments. The\n'
+ 'arguments must either both be numbers or both be sequences of the '
+ 'same\n'
+ 'type. In the former case, the numbers are converted to a common '
+ 'type\n'
+ 'and then added together. In the latter case, the sequences are\n'
+ 'concatenated.\n'
+ '\n'
+ 'The "-" (subtraction) operator yields the difference of its '
+ 'arguments.\n'
+ 'The numeric arguments are first converted to a common type.\n',
+ 'bitwise': '\n'
+ 'Binary bitwise operations\n'
+ '*************************\n'
+ '\n'
+ 'Each 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'
+ '\n'
+ 'The "&" operator yields the bitwise AND of its arguments, which '
+ 'must\n'
+ 'be integers.\n'
+ '\n'
+ 'The "^" operator yields the bitwise XOR (exclusive OR) of its\n'
+ 'arguments, which must be integers.\n'
+ '\n'
+ 'The "|" operator yields the bitwise (inclusive) OR of its '
+ 'arguments,\n'
+ 'which must be integers.\n',
+ 'bltin-code-objects': '\n'
+ 'Code Objects\n'
+ '************\n'
+ '\n'
+ 'Code objects are used by the implementation to '
+ 'represent "pseudo-\n'
+ 'compiled" executable Python code such as a function '
+ 'body. They differ\n'
+ "from function objects because they don't contain a "
+ 'reference to their\n'
+ 'global execution environment. Code objects are '
+ 'returned by the built-\n'
+ 'in "compile()" function and can be extracted from '
+ 'function objects\n'
+ 'through their "__code__" attribute. See also the '
+ '"code" module.\n'
+ '\n'
+ 'A code object can be executed or evaluated by passing '
+ 'it (instead of a\n'
+ 'source string) to the "exec()" or "eval()" built-in '
+ 'functions.\n'
+ '\n'
+ 'See The standard type hierarchy for more '
+ 'information.\n',
+ 'bltin-ellipsis-object': '\n'
+ 'The Ellipsis Object\n'
+ '*******************\n'
+ '\n'
+ 'This object is commonly used by slicing (see '
+ 'Slicings). It supports\n'
+ 'no special operations. There is exactly one '
+ 'ellipsis object, named\n'
+ '"Ellipsis" (a built-in name). "type(Ellipsis)()" '
+ 'produces the\n'
+ '"Ellipsis" singleton.\n'
+ '\n'
+ 'It is written as "Ellipsis" or "...".\n',
+ 'bltin-null-object': '\n'
+ 'The Null Object\n'
+ '***************\n'
+ '\n'
+ "This object is returned by functions that don't "
+ 'explicitly return a\n'
+ 'value. It supports no special operations. There is '
+ 'exactly one null\n'
+ 'object, named "None" (a built-in name). "type(None)()" '
+ 'produces the\n'
+ 'same singleton.\n'
+ '\n'
+ 'It is written as "None".\n',
+ 'bltin-type-objects': '\n'
+ 'Type Objects\n'
+ '************\n'
+ '\n'
+ 'Type objects represent the various object types. An '
+ "object's type is\n"
+ 'accessed by the built-in function "type()". There are '
+ 'no special\n'
+ 'operations on types. The standard module "types" '
+ 'defines names for\n'
+ 'all standard built-in types.\n'
+ '\n'
+ 'Types are written like this: "<class \'int\'>".\n',
+ 'booleans': '\n'
+ 'Boolean operations\n'
+ '******************\n'
+ '\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'
+ '\n'
+ 'In the context of Boolean operations, and also when expressions '
+ 'are\n'
+ 'used by control flow statements, the following values are '
+ 'interpreted\n'
+ 'as false: "False", "None", numeric zero of all types, and empty\n'
+ 'strings and containers (including strings, tuples, lists,\n'
+ 'dictionaries, sets and frozensets). All other values are '
+ 'interpreted\n'
+ 'as true. User-defined objects can customize their truth value '
+ 'by\n'
+ 'providing a "__bool__()" method.\n'
+ '\n'
+ 'The operator "not" yields "True" if its argument is false, '
+ '"False"\n'
+ 'otherwise.\n'
+ '\n'
+ 'The expression "x and y" first evaluates *x*; if *x* is false, '
+ 'its\n'
+ 'value is returned; otherwise, *y* is evaluated and the resulting '
+ 'value\n'
+ 'is returned.\n'
+ '\n'
+ 'The expression "x or y" first evaluates *x*; if *x* is true, its '
+ 'value\n'
+ 'is returned; otherwise, *y* is evaluated and the resulting value '
+ 'is\n'
+ 'returned.\n'
+ '\n'
+ '(Note that neither "and" nor "or" restrict the value and type '
+ 'they\n'
+ 'return to "False" and "True", but rather return the last '
+ 'evaluated\n'
+ 'argument. This is sometimes useful, e.g., if "s" is a string '
+ 'that\n'
+ 'should be replaced by a default value if it is empty, the '
+ 'expression\n'
+ '"s or \'foo\'" yields the desired value. Because "not" has to '
+ 'create a\n'
+ 'new value, it returns a boolean value regardless of the type of '
+ 'its\n'
+ 'argument (for example, "not \'foo\'" produces "False" rather '
+ 'than "\'\'".)\n',
+ 'break': '\n'
+ 'The "break" statement\n'
+ '*********************\n'
+ '\n'
+ ' break_stmt ::= "break"\n'
+ '\n'
+ '"break" may only occur syntactically nested in a "for" or "while"\n'
+ 'loop, but not nested in a function or class definition within that\n'
+ 'loop.\n'
+ '\n'
+ 'It terminates the nearest enclosing loop, skipping the optional '
+ '"else"\n'
+ 'clause if the loop has one.\n'
+ '\n'
+ 'If a "for" loop is terminated by "break", the loop control target\n'
+ 'keeps its current value.\n'
+ '\n'
+ 'When "break" passes control out of a "try" statement with a '
+ '"finally"\n'
+ 'clause, that "finally" clause is executed before really leaving '
+ 'the\n'
+ 'loop.\n',
+ 'callable-types': '\n'
+ 'Emulating callable objects\n'
+ '**************************\n'
+ '\n'
+ 'object.__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': '\n'
+ 'Calls\n'
+ '*****\n'
+ '\n'
+ 'A call calls a callable object (e.g., a *function*) with a '
+ 'possibly\n'
+ 'empty series of *arguments*:\n'
+ '\n'
+ ' call ::= primary "(" [argument_list [","] | '
+ 'comprehension] ")"\n'
+ ' argument_list ::= positional_arguments ["," '
+ 'starred_and_keywords]\n'
+ ' ["," keywords_arguments]\n'
+ ' | starred_and_keywords ["," '
+ 'keywords_arguments]\n'
+ ' | keywords_arguments\n'
+ ' positional_arguments ::= ["*"] expression ("," ["*"] '
+ 'expression)*\n'
+ ' starred_and_keywords ::= ("*" expression | keyword_item)\n'
+ ' ("," "*" expression | "," '
+ 'keyword_item)*\n'
+ ' keywords_arguments ::= (keyword_item | "**" expression)\n'
+ ' ("," keyword_item | "**" expression)*\n'
+ ' keyword_item ::= identifier "=" expression\n'
+ '\n'
+ 'An optional trailing comma may be present after the positional and\n'
+ 'keyword arguments but does not affect the semantics.\n'
+ '\n'
+ 'The primary must evaluate to a callable object (user-defined\n'
+ 'functions, built-in functions, methods of built-in objects, class\n'
+ 'objects, methods of class instances, and all objects having a\n'
+ '"__call__()" method are callable). All argument expressions are\n'
+ 'evaluated before the call is attempted. Please refer to section\n'
+ 'Function definitions for the syntax of formal *parameter* lists.\n'
+ '\n'
+ 'If keyword arguments are present, they are first converted to\n'
+ 'positional arguments, as follows. First, a list of unfilled slots '
+ 'is\n'
+ 'created for the formal parameters. If there are N positional\n'
+ 'arguments, they are placed in the first N slots. Next, for each\n'
+ 'keyword argument, the identifier is used to determine the\n'
+ 'corresponding slot (if the identifier is the same as the first '
+ 'formal\n'
+ 'parameter name, the first slot is used, and so on). If the slot '
+ 'is\n'
+ 'already filled, a "TypeError" exception is raised. Otherwise, the\n'
+ 'value of the argument is placed in the slot, filling it (even if '
+ 'the\n'
+ 'expression is "None", it fills the slot). When all arguments have\n'
+ 'been processed, the slots that are still unfilled are filled with '
+ 'the\n'
+ 'corresponding default value from the function definition. '
+ '(Default\n'
+ 'values are calculated, once, when the function is defined; thus, a\n'
+ 'mutable object such as a list or dictionary used as default value '
+ 'will\n'
+ "be shared by all calls that don't specify an argument value for "
+ 'the\n'
+ 'corresponding slot; this should usually be avoided.) If there are '
+ 'any\n'
+ 'unfilled slots for which no default value is specified, a '
+ '"TypeError"\n'
+ 'exception is raised. Otherwise, the list of filled slots is used '
+ 'as\n'
+ 'the argument list for the call.\n'
+ '\n'
+ '**CPython implementation detail:** An implementation may provide\n'
+ 'built-in functions whose positional parameters do not have names, '
+ 'even\n'
+ "if they are 'named' for the purpose of documentation, and which\n"
+ 'therefore cannot be supplied by keyword. In CPython, this is the '
+ 'case\n'
+ 'for functions implemented in C that use "PyArg_ParseTuple()" to '
+ 'parse\n'
+ 'their arguments.\n'
+ '\n'
+ 'If there are more positional arguments than there are formal '
+ 'parameter\n'
+ 'slots, a "TypeError" exception is raised, unless a formal '
+ 'parameter\n'
+ 'using the syntax "*identifier" is present; in this case, that '
+ 'formal\n'
+ 'parameter receives a tuple containing the excess positional '
+ 'arguments\n'
+ '(or an empty tuple if there were no excess positional arguments).\n'
+ '\n'
+ 'If any keyword argument does not correspond to a formal parameter\n'
+ 'name, a "TypeError" exception is raised, unless a formal parameter\n'
+ 'using the syntax "**identifier" is present; in this case, that '
+ 'formal\n'
+ 'parameter receives a dictionary containing the excess keyword\n'
+ 'arguments (using the keywords as keys and the argument values as\n'
+ 'corresponding values), or a (new) empty dictionary if there were '
+ 'no\n'
+ 'excess keyword arguments.\n'
+ '\n'
+ 'If the syntax "*expression" appears in the function call, '
+ '"expression"\n'
+ 'must evaluate to an *iterable*. Elements from these iterables are\n'
+ 'treated as if they were additional positional arguments. For the '
+ 'call\n'
+ '"f(x1, x2, *y, x3, x4)", if *y* evaluates to a sequence *y1*, ...,\n'
+ '*yM*, this is equivalent to a call with M+4 positional arguments '
+ '*x1*,\n'
+ '*x2*, *y1*, ..., *yM*, *x3*, *x4*.\n'
+ '\n'
+ 'A consequence of this is that although the "*expression" syntax '
+ 'may\n'
+ 'appear *after* explicit keyword arguments, it is processed '
+ '*before*\n'
+ 'the keyword arguments (and any "**expression" arguments -- see '
+ 'below).\n'
+ '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 "<stdin>", line 1, in ?\n'
+ " TypeError: f() got multiple values for keyword argument 'a'\n"
+ ' >>> f(1, *(2,))\n'
+ ' 1 2\n'
+ '\n'
+ 'It is unusual for both keyword arguments and the "*expression" '
+ 'syntax\n'
+ 'to be used in the same call, so in practice this confusion does '
+ 'not\n'
+ 'arise.\n'
+ '\n'
+ 'If the syntax "**expression" appears in the function call,\n'
+ '"expression" must evaluate to a *mapping*, the contents of which '
+ 'are\n'
+ 'treated as additional keyword arguments. If a keyword is already\n'
+ 'present (as an explicit keyword argument, or from another '
+ 'unpacking),\n'
+ 'a "TypeError" exception is raised.\n'
+ '\n'
+ 'Formal parameters using the syntax "*identifier" or "**identifier"\n'
+ 'cannot be used as positional argument slots or as keyword argument\n'
+ 'names.\n'
+ '\n'
+ 'Changed in version 3.5: Function calls accept any number of "*" '
+ 'and\n'
+ '"**" unpackings, positional arguments may follow iterable '
+ 'unpackings\n'
+ '("*"), and keyword arguments may follow dictionary unpackings '
+ '("**").\n'
+ 'Originally proposed by **PEP 448**.\n'
+ '\n'
+ 'A call always returns some value, possibly "None", unless it raises '
+ 'an\n'
+ 'exception. How this value is computed depends on the type of the\n'
+ 'callable object.\n'
+ '\n'
+ 'If it is---\n'
+ '\n'
+ 'a 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'
+ '\n'
+ 'a built-in function or method:\n'
+ ' The result is up to the interpreter; see Built-in Functions for '
+ 'the\n'
+ ' descriptions of built-in functions and methods.\n'
+ '\n'
+ 'a class object:\n'
+ ' A new instance of that class is returned.\n'
+ '\n'
+ 'a 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'
+ '\n'
+ 'a class instance:\n'
+ ' The class must define a "__call__()" method; the effect is then '
+ 'the\n'
+ ' same as if that method was called.\n',
+ 'class': '\n'
+ 'Class definitions\n'
+ '*****************\n'
+ '\n'
+ 'A class definition defines a class object (see section The '
+ 'standard\n'
+ 'type hierarchy):\n'
+ '\n'
+ ' classdef ::= [decorators] "class" classname [inheritance] ":" '
+ 'suite\n'
+ ' inheritance ::= "(" [argument_list] ")"\n'
+ ' classname ::= identifier\n'
+ '\n'
+ 'A class definition is an executable statement. The inheritance '
+ 'list\n'
+ 'usually gives a list of base classes (see Metaclasses for more\n'
+ 'advanced uses), so each item in the list should evaluate to a '
+ 'class\n'
+ 'object which allows subclassing. Classes without an inheritance '
+ 'list\n'
+ 'inherit, by default, from the base class "object"; hence,\n'
+ '\n'
+ ' class Foo:\n'
+ ' pass\n'
+ '\n'
+ 'is equivalent to\n'
+ '\n'
+ ' class Foo(object):\n'
+ ' pass\n'
+ '\n'
+ "The class's suite is then executed in a new execution frame (see\n"
+ 'Naming and binding), using a newly created local namespace and the\n'
+ 'original global namespace. (Usually, the suite contains mostly\n'
+ "function definitions.) When the class's suite finishes execution, "
+ 'its\n'
+ 'execution frame is discarded but its local namespace is saved. [4] '
+ 'A\n'
+ 'class object is then created using the inheritance list for the '
+ 'base\n'
+ 'classes and the saved local namespace for the attribute '
+ 'dictionary.\n'
+ 'The class name is bound to this class object in the original local\n'
+ 'namespace.\n'
+ '\n'
+ 'The order in which attributes are defined in the class body is\n'
+ 'preserved in the new class\'s "__dict__". Note that this is '
+ 'reliable\n'
+ 'only right after the class is created and only for classes that '
+ 'were\n'
+ 'defined using the definition syntax.\n'
+ '\n'
+ 'Class creation can be customized heavily using metaclasses.\n'
+ '\n'
+ 'Classes can also be decorated: just like when decorating '
+ 'functions,\n'
+ '\n'
+ ' @f1(arg)\n'
+ ' @f2\n'
+ ' class Foo: pass\n'
+ '\n'
+ 'is roughly equivalent to\n'
+ '\n'
+ ' class Foo: pass\n'
+ ' Foo = f1(arg)(f2(Foo))\n'
+ '\n'
+ 'The evaluation rules for the decorator expressions are the same as '
+ 'for\n'
+ 'function decorators. The result is then bound to the class name.\n'
+ '\n'
+ "**Programmer's note:** Variables defined in the class definition "
+ 'are\n'
+ 'class attributes; they are shared by instances. Instance '
+ 'attributes\n'
+ 'can be set in a method with "self.name = value". Both class and\n'
+ 'instance attributes are accessible through the notation '
+ '""self.name"",\n'
+ 'and an instance attribute hides a class attribute with the same '
+ 'name\n'
+ 'when accessed in this way. Class attributes can be used as '
+ 'defaults\n'
+ 'for instance attributes, but using mutable values there can lead '
+ 'to\n'
+ 'unexpected results. Descriptors can be used to create instance\n'
+ 'variables with different implementation details.\n'
+ '\n'
+ 'See also: **PEP 3115** - Metaclasses in Python 3 **PEP 3129** -\n'
+ ' Class Decorators\n',
+ 'comparisons': '\n'
+ 'Comparisons\n'
+ '***********\n'
+ '\n'
+ 'Unlike C, all comparison operations in Python have the same '
+ 'priority,\n'
+ 'which is lower than that of any arithmetic, shifting or '
+ 'bitwise\n'
+ 'operation. Also unlike C, expressions like "a < b < c" have '
+ 'the\n'
+ 'interpretation that is conventional in mathematics:\n'
+ '\n'
+ ' comparison ::= or_expr ( comp_operator or_expr )*\n'
+ ' comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!="\n'
+ ' | "is" ["not"] | ["not"] "in"\n'
+ '\n'
+ 'Comparisons yield boolean values: "True" or "False".\n'
+ '\n'
+ 'Comparisons can be chained arbitrarily, e.g., "x < y <= z" '
+ 'is\n'
+ 'equivalent to "x < y and y <= z", except that "y" is '
+ 'evaluated only\n'
+ 'once (but in both cases "z" is not evaluated at all when "x < '
+ 'y" is\n'
+ 'found to be false).\n'
+ '\n'
+ 'Formally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and '
+ '*op1*,\n'
+ '*op2*, ..., *opN* are comparison operators, then "a op1 b op2 '
+ 'c ... y\n'
+ 'opN z" is equivalent to "a op1 b and b op2 c and ... y opN '
+ 'z", except\n'
+ 'that each expression is evaluated at most once.\n'
+ '\n'
+ 'Note that "a op1 b op2 c" doesn\'t imply any kind of '
+ 'comparison between\n'
+ '*a* and *c*, so that, e.g., "x < y > z" is perfectly legal '
+ '(though\n'
+ 'perhaps not pretty).\n'
+ '\n'
+ '\n'
+ 'Value comparisons\n'
+ '=================\n'
+ '\n'
+ 'The operators "<", ">", "==", ">=", "<=", and "!=" compare '
+ 'the values\n'
+ 'of two objects. The objects do not need to have the same '
+ 'type.\n'
+ '\n'
+ 'Chapter Objects, values and types states that objects have a '
+ 'value (in\n'
+ 'addition to type and identity). The value of an object is a '
+ 'rather\n'
+ 'abstract notion in Python: For example, there is no canonical '
+ 'access\n'
+ "method for an object's value. Also, there is no requirement "
+ 'that the\n'
+ 'value of an object should be constructed in a particular way, '
+ 'e.g.\n'
+ 'comprised of all its data attributes. Comparison operators '
+ 'implement a\n'
+ 'particular notion of what the value of an object is. One can '
+ 'think of\n'
+ 'them as defining the value of an object indirectly, by means '
+ 'of their\n'
+ 'comparison implementation.\n'
+ '\n'
+ 'Because all types are (direct or indirect) subtypes of '
+ '"object", they\n'
+ 'inherit the default comparison behavior from "object". Types '
+ 'can\n'
+ 'customize their comparison behavior by implementing *rich '
+ 'comparison\n'
+ 'methods* like "__lt__()", described in Basic customization.\n'
+ '\n'
+ 'The default behavior for equality comparison ("==" and "!=") '
+ 'is based\n'
+ 'on the identity of the objects. Hence, equality comparison '
+ 'of\n'
+ 'instances with the same identity results in equality, and '
+ 'equality\n'
+ 'comparison of instances with different identities results in\n'
+ 'inequality. A motivation for this default behavior is the '
+ 'desire that\n'
+ 'all objects should be reflexive (i.e. "x is y" implies "x == '
+ 'y").\n'
+ '\n'
+ 'A default order comparison ("<", ">", "<=", and ">=") is not '
+ 'provided;\n'
+ 'an attempt raises "TypeError". A motivation for this default '
+ 'behavior\n'
+ 'is the lack of a similar invariant as for equality.\n'
+ '\n'
+ 'The behavior of the default equality comparison, that '
+ 'instances with\n'
+ 'different identities are always unequal, may be in contrast '
+ 'to what\n'
+ 'types will need that have a sensible definition of object '
+ 'value and\n'
+ 'value-based equality. Such types will need to customize '
+ 'their\n'
+ 'comparison behavior, and in fact, a number of built-in types '
+ 'have done\n'
+ 'that.\n'
+ '\n'
+ 'The following list describes the comparison behavior of the '
+ 'most\n'
+ 'important built-in types.\n'
+ '\n'
+ '* Numbers of built-in numeric types (Numeric Types --- int, '
+ 'float,\n'
+ ' complex) and of the standard library types '
+ '"fractions.Fraction" and\n'
+ ' "decimal.Decimal" can be compared within and across their '
+ 'types,\n'
+ ' with the restriction that complex numbers do not support '
+ 'order\n'
+ ' comparison. Within the limits of the types involved, they '
+ 'compare\n'
+ ' mathematically (algorithmically) correct without loss of '
+ 'precision.\n'
+ '\n'
+ ' The not-a-number values "float(\'NaN\')" and '
+ '"Decimal(\'NaN\')" are\n'
+ ' special. They are identical to themselves ("x is x" is '
+ 'true) but\n'
+ ' are not equal to themselves ("x == x" is false). '
+ 'Additionally,\n'
+ ' comparing any number to a not-a-number value will return '
+ '"False".\n'
+ ' For example, both "3 < float(\'NaN\')" and "float(\'NaN\') '
+ '< 3" will\n'
+ ' return "False".\n'
+ '\n'
+ '* Binary sequences (instances of "bytes" or "bytearray") can '
+ 'be\n'
+ ' compared within and across their types. They compare\n'
+ ' lexicographically using the numeric values of their '
+ 'elements.\n'
+ '\n'
+ '* Strings (instances of "str") compare lexicographically '
+ 'using the\n'
+ ' numerical Unicode code points (the result of the built-in '
+ 'function\n'
+ ' "ord()") of their characters. [3]\n'
+ '\n'
+ ' Strings and binary sequences cannot be directly compared.\n'
+ '\n'
+ '* Sequences (instances of "tuple", "list", or "range") can '
+ 'be\n'
+ ' compared only within each of their types, with the '
+ 'restriction that\n'
+ ' ranges do not support order comparison. Equality '
+ 'comparison across\n'
+ ' these types results in unequality, and ordering comparison '
+ 'across\n'
+ ' these types raises "TypeError".\n'
+ '\n'
+ ' Sequences compare lexicographically using comparison of\n'
+ ' corresponding elements, whereby reflexivity of the elements '
+ 'is\n'
+ ' enforced.\n'
+ '\n'
+ ' In enforcing reflexivity of elements, the comparison of '
+ 'collections\n'
+ ' assumes that for a collection element "x", "x == x" is '
+ 'always true.\n'
+ ' Based on that assumption, element identity is compared '
+ 'first, and\n'
+ ' element comparison is performed only for distinct '
+ 'elements. This\n'
+ ' approach yields the same result as a strict element '
+ 'comparison\n'
+ ' would, if the compared elements are reflexive. For '
+ 'non-reflexive\n'
+ ' elements, the result is different than for strict element\n'
+ ' comparison, and may be surprising: The non-reflexive '
+ 'not-a-number\n'
+ ' values for example result in the following comparison '
+ 'behavior when\n'
+ ' used in a list:\n'
+ '\n'
+ " >>> nan = float('NaN')\n"
+ ' >>> nan is nan\n'
+ ' True\n'
+ ' >>> nan == nan\n'
+ ' False <-- the defined non-reflexive '
+ 'behavior of NaN\n'
+ ' >>> [nan] == [nan]\n'
+ ' True <-- list enforces reflexivity and '
+ 'tests identity first\n'
+ '\n'
+ ' Lexicographical comparison between built-in collections '
+ 'works as\n'
+ ' follows:\n'
+ '\n'
+ ' * For two collections to compare equal, they must be of the '
+ 'same\n'
+ ' type, have the same length, and each pair of '
+ 'corresponding\n'
+ ' elements must compare equal (for example, "[1,2] == '
+ '(1,2)" is\n'
+ ' false because the type is not the same).\n'
+ '\n'
+ ' * Collections that support order comparison are ordered the '
+ 'same\n'
+ ' as their first unequal elements (for example, "[1,2,x] <= '
+ '[1,2,y]"\n'
+ ' has the same value as "x <= y"). If a corresponding '
+ 'element does\n'
+ ' not exist, the shorter collection is ordered first (for '
+ 'example,\n'
+ ' "[1,2] < [1,2,3]" is true).\n'
+ '\n'
+ '* Mappings (instances of "dict") compare equal if and only if '
+ 'they\n'
+ ' have equal *(key, value)* pairs. Equality comparison of the '
+ 'keys and\n'
+ ' elements enforces reflexivity.\n'
+ '\n'
+ ' Order comparisons ("<", ">", "<=", and ">=") raise '
+ '"TypeError".\n'
+ '\n'
+ '* Sets (instances of "set" or "frozenset") can be compared '
+ 'within\n'
+ ' and across their types.\n'
+ '\n'
+ ' They define order comparison operators to mean subset and '
+ 'superset\n'
+ ' tests. Those relations do not define total orderings (for '
+ 'example,\n'
+ ' the two sets "{1,2}" and "{2,3}" are not equal, nor subsets '
+ 'of one\n'
+ ' another, nor supersets of one another). Accordingly, sets '
+ 'are not\n'
+ ' appropriate arguments for functions which depend on total '
+ 'ordering\n'
+ ' (for example, "min()", "max()", and "sorted()" produce '
+ 'undefined\n'
+ ' results given a list of sets as inputs).\n'
+ '\n'
+ ' Comparison of sets enforces reflexivity of its elements.\n'
+ '\n'
+ '* Most other built-in types have no comparison methods '
+ 'implemented,\n'
+ ' so they inherit the default comparison behavior.\n'
+ '\n'
+ 'User-defined classes that customize their comparison behavior '
+ 'should\n'
+ 'follow some consistency rules, if possible:\n'
+ '\n'
+ '* Equality comparison should be reflexive. In other words, '
+ 'identical\n'
+ ' objects should compare equal:\n'
+ '\n'
+ ' "x is y" implies "x == y"\n'
+ '\n'
+ '* Comparison should be symmetric. In other words, the '
+ 'following\n'
+ ' expressions should have the same result:\n'
+ '\n'
+ ' "x == y" and "y == x"\n'
+ '\n'
+ ' "x != y" and "y != x"\n'
+ '\n'
+ ' "x < y" and "y > x"\n'
+ '\n'
+ ' "x <= y" and "y >= x"\n'
+ '\n'
+ '* Comparison should be transitive. The following '
+ '(non-exhaustive)\n'
+ ' examples illustrate that:\n'
+ '\n'
+ ' "x > y and y > z" implies "x > z"\n'
+ '\n'
+ ' "x < y and y <= z" implies "x < z"\n'
+ '\n'
+ '* Inverse comparison should result in the boolean negation. '
+ 'In other\n'
+ ' words, the following expressions should have the same '
+ 'result:\n'
+ '\n'
+ ' "x == y" and "not x != y"\n'
+ '\n'
+ ' "x < y" and "not x >= y" (for total ordering)\n'
+ '\n'
+ ' "x > y" and "not x <= y" (for total ordering)\n'
+ '\n'
+ ' The last two expressions apply to totally ordered '
+ 'collections (e.g.\n'
+ ' to sequences, but not to sets or mappings). See also the\n'
+ ' "total_ordering()" decorator.\n'
+ '\n'
+ 'Python does not enforce these consistency rules. In fact, '
+ 'the\n'
+ 'not-a-number values are an example for not following these '
+ 'rules.\n'
+ '\n'
+ '\n'
+ 'Membership test operations\n'
+ '==========================\n'
+ '\n'
+ 'The operators "in" and "not in" test for membership. "x in '
+ 's"\n'
+ 'evaluates to true if *x* is a member of *s*, and false '
+ 'otherwise. "x\n'
+ 'not in s" returns the negation of "x in s". All built-in '
+ 'sequences\n'
+ 'and set types support this as well as dictionary, for which '
+ '"in" tests\n'
+ 'whether the dictionary has a given key. For container types '
+ 'such as\n'
+ 'list, tuple, set, frozenset, dict, or collections.deque, the\n'
+ 'expression "x in y" is equivalent to "any(x is e or x == e '
+ 'for e in\n'
+ 'y)".\n'
+ '\n'
+ 'For the string and bytes types, "x in y" is true if and only '
+ 'if *x* is\n'
+ 'a substring of *y*. An equivalent test is "y.find(x) != '
+ '-1". Empty\n'
+ 'strings are always considered to be a substring of any other '
+ 'string,\n'
+ 'so """ in "abc"" will return "True".\n'
+ '\n'
+ 'For user-defined classes which define the "__contains__()" '
+ 'method, "x\n'
+ 'in y" is true if and only if "y.__contains__(x)" is true.\n'
+ '\n'
+ 'For user-defined classes which do not define "__contains__()" '
+ 'but do\n'
+ 'define "__iter__()", "x in y" is true if some value "z" with '
+ '"x == z"\n'
+ 'is produced while iterating over "y". If an exception is '
+ 'raised\n'
+ 'during the iteration, it is as if "in" raised that '
+ 'exception.\n'
+ '\n'
+ 'Lastly, the old-style iteration protocol is tried: if a class '
+ 'defines\n'
+ '"__getitem__()", "x in y" is true if and only if there is a '
+ 'non-\n'
+ 'negative integer index *i* such that "x == y[i]", and all '
+ 'lower\n'
+ 'integer indices do not raise "IndexError" exception. (If any '
+ 'other\n'
+ 'exception is raised, it is as if "in" raised that '
+ 'exception).\n'
+ '\n'
+ 'The operator "not in" is defined to have the inverse true '
+ 'value of\n'
+ '"in".\n'
+ '\n'
+ '\n'
+ 'Identity comparisons\n'
+ '====================\n'
+ '\n'
+ 'The operators "is" and "is not" test for object identity: "x '
+ 'is y" is\n'
+ 'true if and only if *x* and *y* are the same object. Object '
+ 'identity\n'
+ 'is determined using the "id()" function. "x is not y" yields '
+ 'the\n'
+ 'inverse truth value. [4]\n',
+ 'compound': '\n'
+ 'Compound statements\n'
+ '*******************\n'
+ '\n'
+ 'Compound statements contain (groups of) other statements; they '
+ 'affect\n'
+ 'or control the execution of those other statements in some way. '
+ 'In\n'
+ 'general, compound statements span multiple lines, although in '
+ 'simple\n'
+ 'incarnations a whole compound statement may be contained in one '
+ 'line.\n'
+ '\n'
+ 'The "if", "while" and "for" statements implement traditional '
+ 'control\n'
+ 'flow constructs. "try" specifies exception handlers and/or '
+ 'cleanup\n'
+ 'code for a group of statements, while the "with" statement '
+ 'allows the\n'
+ 'execution of initialization and finalization code around a block '
+ 'of\n'
+ 'code. Function and class definitions are also syntactically '
+ 'compound\n'
+ 'statements.\n'
+ '\n'
+ "A compound statement consists of one or more 'clauses.' A "
+ 'clause\n'
+ "consists of a header and a 'suite.' The clause headers of a\n"
+ 'particular compound statement are all at the same indentation '
+ 'level.\n'
+ 'Each clause header begins with a uniquely identifying keyword '
+ 'and ends\n'
+ 'with a colon. A suite is a group of statements controlled by a\n'
+ 'clause. A suite can be one or more semicolon-separated simple\n'
+ 'statements on the same line as the header, following the '
+ "header's\n"
+ 'colon, or it can be one or more indented statements on '
+ 'subsequent\n'
+ 'lines. Only the latter form of a suite can contain nested '
+ 'compound\n'
+ "statements; the following is illegal, mostly because it wouldn't "
+ 'be\n'
+ 'clear to which "if" clause a following "else" clause would '
+ 'belong:\n'
+ '\n'
+ ' if test1: if test2: print(x)\n'
+ '\n'
+ 'Also note that the semicolon binds tighter than the colon in '
+ 'this\n'
+ 'context, 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'
+ '\n'
+ 'Summarizing:\n'
+ '\n'
+ ' compound_stmt ::= if_stmt\n'
+ ' | while_stmt\n'
+ ' | for_stmt\n'
+ ' | try_stmt\n'
+ ' | with_stmt\n'
+ ' | funcdef\n'
+ ' | classdef\n'
+ ' | async_with_stmt\n'
+ ' | async_for_stmt\n'
+ ' | async_funcdef\n'
+ ' suite ::= stmt_list NEWLINE | NEWLINE INDENT '
+ 'statement+ DEDENT\n'
+ ' statement ::= stmt_list NEWLINE | compound_stmt\n'
+ ' stmt_list ::= simple_stmt (";" simple_stmt)* [";"]\n'
+ '\n'
+ 'Note that statements always end in a "NEWLINE" possibly followed '
+ 'by a\n'
+ '"DEDENT". Also note that optional continuation clauses always '
+ 'begin\n'
+ 'with a keyword that cannot start a statement, thus there are no\n'
+ 'ambiguities (the \'dangling "else"\' problem is solved in Python '
+ 'by\n'
+ 'requiring nested "if" statements to be indented).\n'
+ '\n'
+ 'The formatting of the grammar rules in the following sections '
+ 'places\n'
+ 'each clause on a separate line for clarity.\n'
+ '\n'
+ '\n'
+ 'The "if" statement\n'
+ '==================\n'
+ '\n'
+ 'The "if" statement is used for conditional execution:\n'
+ '\n'
+ ' if_stmt ::= "if" expression ":" suite\n'
+ ' ( "elif" expression ":" suite )*\n'
+ ' ["else" ":" suite]\n'
+ '\n'
+ 'It selects exactly one of the suites by evaluating the '
+ 'expressions one\n'
+ 'by one until one is found to be true (see section Boolean '
+ 'operations\n'
+ 'for the definition of true and false); then that suite is '
+ 'executed\n'
+ '(and no other part of the "if" statement is executed or '
+ 'evaluated).\n'
+ 'If all expressions are false, the suite of the "else" clause, '
+ 'if\n'
+ 'present, is executed.\n'
+ '\n'
+ '\n'
+ 'The "while" statement\n'
+ '=====================\n'
+ '\n'
+ 'The "while" statement is used for repeated execution as long as '
+ 'an\n'
+ 'expression is true:\n'
+ '\n'
+ ' while_stmt ::= "while" expression ":" suite\n'
+ ' ["else" ":" suite]\n'
+ '\n'
+ 'This repeatedly tests the expression and, if it is true, '
+ 'executes the\n'
+ 'first suite; if the expression is false (which may be the first '
+ 'time\n'
+ 'it is tested) the suite of the "else" clause, if present, is '
+ 'executed\n'
+ 'and the loop terminates.\n'
+ '\n'
+ 'A "break" statement executed in the first suite terminates the '
+ 'loop\n'
+ 'without executing the "else" clause\'s suite. A "continue" '
+ 'statement\n'
+ 'executed in the first suite skips the rest of the suite and goes '
+ 'back\n'
+ 'to testing the expression.\n'
+ '\n'
+ '\n'
+ 'The "for" statement\n'
+ '===================\n'
+ '\n'
+ 'The "for" statement is used to iterate over the elements of a '
+ 'sequence\n'
+ '(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'
+ '\n'
+ 'The expression list is evaluated once; it should yield an '
+ 'iterable\n'
+ 'object. An iterator is created for the result of the\n'
+ '"expression_list". The suite is then executed once for each '
+ 'item\n'
+ 'provided by the iterator, in the order returned by the '
+ 'iterator. Each\n'
+ 'item in turn is assigned to the target list using the standard '
+ 'rules\n'
+ 'for assignments (see Assignment statements), and then the suite '
+ 'is\n'
+ 'executed. When the items are exhausted (which is immediately '
+ 'when the\n'
+ 'sequence is empty or an iterator raises a "StopIteration" '
+ 'exception),\n'
+ 'the suite in the "else" clause, if present, is executed, and the '
+ 'loop\n'
+ 'terminates.\n'
+ '\n'
+ 'A "break" statement executed in the first suite terminates the '
+ 'loop\n'
+ 'without executing the "else" clause\'s suite. A "continue" '
+ 'statement\n'
+ 'executed in the first suite skips the rest of the suite and '
+ 'continues\n'
+ 'with the next item, or with the "else" clause if there is no '
+ 'next\n'
+ 'item.\n'
+ '\n'
+ 'The for-loop makes assignments to the variables(s) in the target '
+ 'list.\n'
+ 'This overwrites all previous assignments to those variables '
+ 'including\n'
+ 'those made in the suite of the for-loop:\n'
+ '\n'
+ ' for i in range(10):\n'
+ ' print(i)\n'
+ ' i = 5 # this will not affect the for-loop\n'
+ ' # because i will be overwritten with '
+ 'the next\n'
+ ' # index in the range\n'
+ '\n'
+ 'Names in the target list are not deleted when the loop is '
+ 'finished,\n'
+ 'but if the sequence is empty, they will not have been assigned '
+ 'to at\n'
+ 'all by the loop. Hint: the built-in function "range()" returns '
+ 'an\n'
+ "iterator of integers suitable to emulate the effect of Pascal's "
+ '"for i\n'
+ ':= a to b do"; e.g., "list(range(3))" returns the list "[0, 1, '
+ '2]".\n'
+ '\n'
+ 'Note: There is a subtlety when the sequence is being modified by '
+ 'the\n'
+ ' loop (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'
+ '\n'
+ 'The "try" statement\n'
+ '===================\n'
+ '\n'
+ 'The "try" statement specifies exception handlers and/or cleanup '
+ 'code\n'
+ 'for a group of statements:\n'
+ '\n'
+ ' try_stmt ::= try1_stmt | try2_stmt\n'
+ ' try1_stmt ::= "try" ":" suite\n'
+ ' ("except" [expression ["as" identifier]] ":" '
+ 'suite)+\n'
+ ' ["else" ":" suite]\n'
+ ' ["finally" ":" suite]\n'
+ ' try2_stmt ::= "try" ":" suite\n'
+ ' "finally" ":" suite\n'
+ '\n'
+ 'The "except" clause(s) specify one or more exception handlers. '
+ 'When no\n'
+ 'exception occurs in the "try" clause, no exception handler is\n'
+ 'executed. When an exception occurs in the "try" suite, a search '
+ 'for an\n'
+ 'exception handler is started. This search inspects the except '
+ 'clauses\n'
+ 'in turn until one is found that matches the exception. An '
+ 'expression-\n'
+ 'less except clause, if present, must be last; it matches any\n'
+ 'exception. For an except clause with an expression, that '
+ 'expression\n'
+ 'is evaluated, and the clause matches the exception if the '
+ 'resulting\n'
+ 'object is "compatible" with the exception. An object is '
+ 'compatible\n'
+ 'with an exception if it is the class or a base class of the '
+ 'exception\n'
+ 'object or a tuple containing an item compatible with the '
+ 'exception.\n'
+ '\n'
+ 'If no except clause matches the exception, the search for an '
+ 'exception\n'
+ 'handler continues in the surrounding code and on the invocation '
+ 'stack.\n'
+ '[1]\n'
+ '\n'
+ 'If the evaluation of an expression in the header of an except '
+ 'clause\n'
+ 'raises an exception, the original search for a handler is '
+ 'canceled and\n'
+ 'a search starts for the new exception in the surrounding code '
+ 'and on\n'
+ 'the call stack (it is treated as if the entire "try" statement '
+ 'raised\n'
+ 'the exception).\n'
+ '\n'
+ 'When a matching except clause is found, the exception is '
+ 'assigned to\n'
+ 'the target specified after the "as" keyword in that except '
+ 'clause, if\n'
+ "present, and the except clause's suite is executed. All except\n"
+ 'clauses must have an executable block. When the end of this '
+ 'block is\n'
+ 'reached, execution continues normally after the entire try '
+ 'statement.\n'
+ '(This means that if two nested handlers exist for the same '
+ 'exception,\n'
+ 'and the exception occurs in the try clause of the inner handler, '
+ 'the\n'
+ 'outer handler will not handle the exception.)\n'
+ '\n'
+ 'When an exception has been assigned using "as target", it is '
+ 'cleared\n'
+ 'at the end of the except clause. This is as if\n'
+ '\n'
+ ' except E as N:\n'
+ ' foo\n'
+ '\n'
+ 'was translated to\n'
+ '\n'
+ ' except E as N:\n'
+ ' try:\n'
+ ' foo\n'
+ ' finally:\n'
+ ' del N\n'
+ '\n'
+ 'This means the exception must be assigned to a different name to '
+ 'be\n'
+ 'able to refer to it after the except clause. Exceptions are '
+ 'cleared\n'
+ 'because with the traceback attached to them, they form a '
+ 'reference\n'
+ 'cycle with the stack frame, keeping all locals in that frame '
+ 'alive\n'
+ 'until the next garbage collection occurs.\n'
+ '\n'
+ "Before an except clause's suite is executed, details about the\n"
+ 'exception are stored in the "sys" module and can be accessed '
+ 'via\n'
+ '"sys.exc_info()". "sys.exc_info()" returns a 3-tuple consisting '
+ 'of the\n'
+ 'exception class, the exception instance and a traceback object '
+ '(see\n'
+ 'section The standard type hierarchy) identifying the point in '
+ 'the\n'
+ 'program where the exception occurred. "sys.exc_info()" values '
+ 'are\n'
+ 'restored to their previous values (before the call) when '
+ 'returning\n'
+ 'from a function that handled an exception.\n'
+ '\n'
+ 'The optional "else" clause is executed if and when control flows '
+ 'off\n'
+ 'the end of the "try" clause. [2] Exceptions in the "else" clause '
+ 'are\n'
+ 'not handled by the preceding "except" clauses.\n'
+ '\n'
+ 'If "finally" is present, it specifies a \'cleanup\' handler. '
+ 'The "try"\n'
+ 'clause is executed, including any "except" and "else" clauses. '
+ 'If an\n'
+ 'exception occurs in any of the clauses and is not handled, the\n'
+ 'exception is temporarily saved. The "finally" clause is '
+ 'executed. If\n'
+ 'there is a saved exception it is re-raised at the end of the '
+ '"finally"\n'
+ 'clause. If the "finally" clause raises another exception, the '
+ 'saved\n'
+ 'exception is set as the context of the new exception. If the '
+ '"finally"\n'
+ 'clause executes a "return" or "break" statement, the saved '
+ 'exception\n'
+ 'is discarded:\n'
+ '\n'
+ ' >>> def f():\n'
+ ' ... try:\n'
+ ' ... 1/0\n'
+ ' ... finally:\n'
+ ' ... return 42\n'
+ ' ...\n'
+ ' >>> f()\n'
+ ' 42\n'
+ '\n'
+ 'The exception information is not available to the program '
+ 'during\n'
+ 'execution of the "finally" clause.\n'
+ '\n'
+ 'When a "return", "break" or "continue" statement is executed in '
+ 'the\n'
+ '"try" suite of a "try"..."finally" statement, the "finally" '
+ 'clause is\n'
+ 'also executed \'on the way out.\' A "continue" statement is '
+ 'illegal in\n'
+ 'the "finally" clause. (The reason is a problem with the current\n'
+ 'implementation --- this restriction may be lifted in the '
+ 'future).\n'
+ '\n'
+ 'The return value of a function is determined by the last '
+ '"return"\n'
+ 'statement executed. Since the "finally" clause always executes, '
+ 'a\n'
+ '"return" statement executed in the "finally" clause will always '
+ 'be the\n'
+ 'last one executed:\n'
+ '\n'
+ ' >>> def foo():\n'
+ ' ... try:\n'
+ " ... return 'try'\n"
+ ' ... finally:\n'
+ " ... return 'finally'\n"
+ ' ...\n'
+ ' >>> foo()\n'
+ " 'finally'\n"
+ '\n'
+ 'Additional information on exceptions can be found in section\n'
+ 'Exceptions, and information on using the "raise" statement to '
+ 'generate\n'
+ 'exceptions may be found in section The raise statement.\n'
+ '\n'
+ '\n'
+ 'The "with" statement\n'
+ '====================\n'
+ '\n'
+ 'The "with" statement is used to wrap the execution of a block '
+ 'with\n'
+ 'methods defined by a context manager (see section With '
+ 'Statement\n'
+ 'Context Managers). This allows common '
+ '"try"..."except"..."finally"\n'
+ 'usage patterns to be encapsulated for convenient reuse.\n'
+ '\n'
+ ' with_stmt ::= "with" with_item ("," with_item)* ":" suite\n'
+ ' with_item ::= expression ["as" target]\n'
+ '\n'
+ 'The execution of the "with" statement with one "item" proceeds '
+ 'as\n'
+ 'follows:\n'
+ '\n'
+ '1. The context expression (the expression given in the '
+ '"with_item")\n'
+ ' is evaluated to obtain a context manager.\n'
+ '\n'
+ '2. The context manager\'s "__exit__()" is loaded for later use.\n'
+ '\n'
+ '3. The context manager\'s "__enter__()" method is invoked.\n'
+ '\n'
+ '4. 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 be\n'
+ ' called. Thus, if an error occurs during the assignment to '
+ 'the\n'
+ ' target list, it will be treated the same as an error '
+ 'occurring\n'
+ ' within the suite would be. See step 6 below.\n'
+ '\n'
+ '5. The suite is executed.\n'
+ '\n'
+ '6. 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, '
+ 'three\n'
+ ' "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 '
+ 'reraised.\n'
+ ' If the return value was true, the exception is suppressed, '
+ 'and\n'
+ ' execution continues with the statement following the "with"\n'
+ ' 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'
+ '\n'
+ 'With more than one item, the context managers are processed as '
+ 'if\n'
+ 'multiple "with" statements were nested:\n'
+ '\n'
+ ' with A() as a, B() as b:\n'
+ ' suite\n'
+ '\n'
+ 'is equivalent to\n'
+ '\n'
+ ' with A() as a:\n'
+ ' with B() as b:\n'
+ ' suite\n'
+ '\n'
+ 'Changed in version 3.1: Support for multiple context '
+ 'expressions.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 343** - The "with" statement\n'
+ ' The specification, background, and examples for the Python '
+ '"with"\n'
+ ' statement.\n'
+ '\n'
+ '\n'
+ 'Function definitions\n'
+ '====================\n'
+ '\n'
+ 'A function definition defines a user-defined function object '
+ '(see\n'
+ 'section 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 ("," defparameter)* '
+ '["," [parameter_list_starargs]]\n'
+ ' | parameter_list_starargs\n'
+ ' parameter_list_starargs ::= "*" [parameter] ("," '
+ 'defparameter)* ["," ["**" parameter [","]]]\n'
+ ' | "**" parameter [","]\n'
+ ' parameter ::= identifier [":" expression]\n'
+ ' defparameter ::= parameter ["=" expression]\n'
+ ' funcname ::= identifier\n'
+ '\n'
+ 'A function definition is an executable statement. Its execution '
+ 'binds\n'
+ 'the function name in the current local namespace to a function '
+ 'object\n'
+ '(a wrapper around the executable code for the function). This\n'
+ 'function object contains a reference to the current global '
+ 'namespace\n'
+ 'as the global namespace to be used when the function is called.\n'
+ '\n'
+ 'The function definition does not execute the function body; this '
+ 'gets\n'
+ 'executed only when the function is called. [3]\n'
+ '\n'
+ 'A function definition may be wrapped by one or more *decorator*\n'
+ 'expressions. Decorator expressions are evaluated when the '
+ 'function is\n'
+ 'defined, in the scope that contains the function definition. '
+ 'The\n'
+ 'result must be a callable, which is invoked with the function '
+ 'object\n'
+ 'as the only argument. The returned value is bound to the '
+ 'function name\n'
+ 'instead of the function object. Multiple decorators are applied '
+ 'in\n'
+ 'nested fashion. For example, the following code\n'
+ '\n'
+ ' @f1(arg)\n'
+ ' @f2\n'
+ ' def func(): pass\n'
+ '\n'
+ 'is roughly equivalent to\n'
+ '\n'
+ ' def func(): pass\n'
+ ' func = f1(arg)(f2(func))\n'
+ '\n'
+ 'except that the original function is not temporarily bound to '
+ 'the name\n'
+ '"func".\n'
+ '\n'
+ 'When one or more *parameters* have the form *parameter* "="\n'
+ '*expression*, the function is said to have "default parameter '
+ 'values."\n'
+ 'For a parameter with a default value, the corresponding '
+ '*argument* may\n'
+ "be omitted from a call, in which case the parameter's default "
+ 'value is\n'
+ 'substituted. If a parameter has a default value, all following\n'
+ 'parameters up until the ""*"" must also have a default value --- '
+ 'this\n'
+ 'is a syntactic restriction that is not expressed by the '
+ 'grammar.\n'
+ '\n'
+ '**Default parameter values are evaluated from left to right when '
+ 'the\n'
+ 'function definition is executed.** This means that the '
+ 'expression is\n'
+ 'evaluated once, when the function is defined, and that the same '
+ '"pre-\n'
+ 'computed" value is used for each call. This is especially '
+ 'important\n'
+ 'to understand when a default parameter is a mutable object, such '
+ 'as a\n'
+ 'list or a dictionary: if the function modifies the object (e.g. '
+ 'by\n'
+ 'appending an item to a list), the default value is in effect '
+ 'modified.\n'
+ 'This is generally not what was intended. A way around this is '
+ 'to use\n'
+ '"None" as the default, and explicitly test for it in the body of '
+ 'the\n'
+ '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'
+ '\n'
+ 'Function call semantics are described in more detail in section '
+ 'Calls.\n'
+ 'A function call always assigns values to all parameters '
+ 'mentioned in\n'
+ 'the parameter list, either from position arguments, from '
+ 'keyword\n'
+ 'arguments, or from default values. If the form ""*identifier"" '
+ 'is\n'
+ 'present, it is initialized to a tuple receiving any excess '
+ 'positional\n'
+ 'parameters, defaulting to the empty tuple. If the form\n'
+ '""**identifier"" is present, it is initialized to a new ordered\n'
+ 'mapping receiving any excess keyword arguments, defaulting to a '
+ 'new\n'
+ 'empty mapping of the same type. Parameters after ""*"" or\n'
+ '""*identifier"" are keyword-only parameters and may only be '
+ 'passed\n'
+ 'used keyword arguments.\n'
+ '\n'
+ 'Parameters may have annotations of the form "": expression"" '
+ 'following\n'
+ 'the parameter name. Any parameter may have an annotation even '
+ 'those\n'
+ 'of the form "*identifier" or "**identifier". Functions may '
+ 'have\n'
+ '"return" annotation of the form ""-> expression"" after the '
+ 'parameter\n'
+ 'list. These annotations can be any valid Python expression and '
+ 'are\n'
+ 'evaluated when the function definition is executed. Annotations '
+ 'may\n'
+ 'be evaluated in a different order than they appear in the source '
+ 'code.\n'
+ 'The presence of annotations does not change the semantics of a\n'
+ 'function. The annotation values are available as values of a\n'
+ "dictionary keyed by the parameters' names in the "
+ '"__annotations__"\n'
+ 'attribute of the function object.\n'
+ '\n'
+ 'It is also possible to create anonymous functions (functions not '
+ 'bound\n'
+ 'to a name), for immediate use in expressions. This uses lambda\n'
+ 'expressions, described in section Lambdas. Note that the '
+ 'lambda\n'
+ 'expression is merely a shorthand for a simplified function '
+ 'definition;\n'
+ 'a function defined in a ""def"" statement can be passed around '
+ 'or\n'
+ 'assigned to another name just like a function defined by a '
+ 'lambda\n'
+ 'expression. The ""def"" form is actually more powerful since '
+ 'it\n'
+ 'allows the execution of multiple statements and annotations.\n'
+ '\n'
+ "**Programmer's note:** Functions are first-class objects. A "
+ '""def""\n'
+ 'statement executed inside a function definition defines a local\n'
+ 'function that can be returned or passed around. Free variables '
+ 'used\n'
+ 'in the nested function can access the local variables of the '
+ 'function\n'
+ 'containing the def. See section Naming and binding for '
+ 'details.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 3107** - Function Annotations\n'
+ ' The original specification for function annotations.\n'
+ '\n'
+ '\n'
+ 'Class definitions\n'
+ '=================\n'
+ '\n'
+ 'A class definition defines a class object (see section The '
+ 'standard\n'
+ 'type hierarchy):\n'
+ '\n'
+ ' classdef ::= [decorators] "class" classname [inheritance] '
+ '":" suite\n'
+ ' inheritance ::= "(" [argument_list] ")"\n'
+ ' classname ::= identifier\n'
+ '\n'
+ 'A class definition is an executable statement. The inheritance '
+ 'list\n'
+ 'usually gives a list of base classes (see Metaclasses for more\n'
+ 'advanced uses), so each item in the list should evaluate to a '
+ 'class\n'
+ 'object which allows subclassing. Classes without an inheritance '
+ 'list\n'
+ 'inherit, by default, from the base class "object"; hence,\n'
+ '\n'
+ ' class Foo:\n'
+ ' pass\n'
+ '\n'
+ 'is equivalent to\n'
+ '\n'
+ ' class Foo(object):\n'
+ ' pass\n'
+ '\n'
+ "The class's suite is then executed in a new execution frame "
+ '(see\n'
+ 'Naming and binding), using a newly created local namespace and '
+ 'the\n'
+ 'original global namespace. (Usually, the suite contains mostly\n'
+ "function definitions.) When the class's suite finishes "
+ 'execution, its\n'
+ 'execution frame is discarded but its local namespace is saved. '
+ '[4] A\n'
+ 'class object is then created using the inheritance list for the '
+ 'base\n'
+ 'classes and the saved local namespace for the attribute '
+ 'dictionary.\n'
+ 'The class name is bound to this class object in the original '
+ 'local\n'
+ 'namespace.\n'
+ '\n'
+ 'The order in which attributes are defined in the class body is\n'
+ 'preserved in the new class\'s "__dict__". Note that this is '
+ 'reliable\n'
+ 'only right after the class is created and only for classes that '
+ 'were\n'
+ 'defined using the definition syntax.\n'
+ '\n'
+ 'Class creation can be customized heavily using metaclasses.\n'
+ '\n'
+ 'Classes can also be decorated: just like when decorating '
+ 'functions,\n'
+ '\n'
+ ' @f1(arg)\n'
+ ' @f2\n'
+ ' class Foo: pass\n'
+ '\n'
+ 'is roughly equivalent to\n'
+ '\n'
+ ' class Foo: pass\n'
+ ' Foo = f1(arg)(f2(Foo))\n'
+ '\n'
+ 'The evaluation rules for the decorator expressions are the same '
+ 'as for\n'
+ 'function decorators. The result is then bound to the class '
+ 'name.\n'
+ '\n'
+ "**Programmer's note:** Variables defined in the class definition "
+ 'are\n'
+ 'class attributes; they are shared by instances. Instance '
+ 'attributes\n'
+ 'can be set in a method with "self.name = value". Both class '
+ 'and\n'
+ 'instance attributes are accessible through the notation '
+ '""self.name"",\n'
+ 'and an instance attribute hides a class attribute with the same '
+ 'name\n'
+ 'when accessed in this way. Class attributes can be used as '
+ 'defaults\n'
+ 'for instance attributes, but using mutable values there can lead '
+ 'to\n'
+ 'unexpected results. Descriptors can be used to create instance\n'
+ 'variables with different implementation details.\n'
+ '\n'
+ 'See also: **PEP 3115** - Metaclasses in Python 3 **PEP 3129** -\n'
+ ' Class Decorators\n'
+ '\n'
+ '\n'
+ 'Coroutines\n'
+ '==========\n'
+ '\n'
+ 'New in version 3.5.\n'
+ '\n'
+ '\n'
+ 'Coroutine function definition\n'
+ '-----------------------------\n'
+ '\n'
+ ' async_funcdef ::= [decorators] "async" "def" funcname "(" '
+ '[parameter_list] ")" ["->" expression] ":" suite\n'
+ '\n'
+ 'Execution of Python coroutines can be suspended and resumed at '
+ 'many\n'
+ 'points (see *coroutine*). In the body of a coroutine, any '
+ '"await" and\n'
+ '"async" identifiers become reserved keywords; "await" '
+ 'expressions,\n'
+ '"async for" and "async with" can only be used in coroutine '
+ 'bodies.\n'
+ '\n'
+ 'Functions defined with "async def" syntax are always coroutine\n'
+ 'functions, even if they do not contain "await" or "async" '
+ 'keywords.\n'
+ '\n'
+ 'It is a "SyntaxError" to use "yield" expressions in "async def"\n'
+ 'coroutines.\n'
+ '\n'
+ 'An example of a coroutine function:\n'
+ '\n'
+ ' async def func(param1, param2):\n'
+ ' do_stuff()\n'
+ ' await some_coroutine()\n'
+ '\n'
+ '\n'
+ 'The "async for" statement\n'
+ '-------------------------\n'
+ '\n'
+ ' async_for_stmt ::= "async" for_stmt\n'
+ '\n'
+ 'An *asynchronous iterable* is able to call asynchronous code in '
+ 'its\n'
+ '*iter* implementation, and *asynchronous iterator* can call\n'
+ 'asynchronous code in its *next* method.\n'
+ '\n'
+ 'The "async for" statement allows convenient iteration over\n'
+ 'asynchronous iterators.\n'
+ '\n'
+ 'The following code:\n'
+ '\n'
+ ' async for TARGET in ITER:\n'
+ ' BLOCK\n'
+ ' else:\n'
+ ' BLOCK2\n'
+ '\n'
+ 'Is semantically equivalent to:\n'
+ '\n'
+ ' iter = (ITER)\n'
+ ' iter = type(iter).__aiter__(iter)\n'
+ ' running = True\n'
+ ' while running:\n'
+ ' try:\n'
+ ' TARGET = await type(iter).__anext__(iter)\n'
+ ' except StopAsyncIteration:\n'
+ ' running = False\n'
+ ' else:\n'
+ ' BLOCK\n'
+ ' else:\n'
+ ' BLOCK2\n'
+ '\n'
+ 'See also "__aiter__()" and "__anext__()" for details.\n'
+ '\n'
+ 'It is a "SyntaxError" to use "async for" statement outside of '
+ 'an\n'
+ '"async def" function.\n'
+ '\n'
+ '\n'
+ 'The "async with" statement\n'
+ '--------------------------\n'
+ '\n'
+ ' async_with_stmt ::= "async" with_stmt\n'
+ '\n'
+ 'An *asynchronous context manager* is a *context manager* that is '
+ 'able\n'
+ 'to suspend execution in its *enter* and *exit* methods.\n'
+ '\n'
+ 'The following code:\n'
+ '\n'
+ ' async with EXPR as VAR:\n'
+ ' BLOCK\n'
+ '\n'
+ 'Is semantically equivalent to:\n'
+ '\n'
+ ' mgr = (EXPR)\n'
+ ' aexit = type(mgr).__aexit__\n'
+ ' aenter = type(mgr).__aenter__(mgr)\n'
+ ' exc = True\n'
+ '\n'
+ ' VAR = await aenter\n'
+ ' try:\n'
+ ' BLOCK\n'
+ ' except:\n'
+ ' if not await aexit(mgr, *sys.exc_info()):\n'
+ ' raise\n'
+ ' else:\n'
+ ' await aexit(mgr, None, None, None)\n'
+ '\n'
+ 'See also "__aenter__()" and "__aexit__()" for details.\n'
+ '\n'
+ 'It is a "SyntaxError" to use "async with" statement outside of '
+ 'an\n'
+ '"async def" function.\n'
+ '\n'
+ 'See also: **PEP 492** - Coroutines with async and await syntax\n'
+ '\n'
+ '-[ Footnotes ]-\n'
+ '\n'
+ '[1] The exception is propagated to the invocation stack unless\n'
+ ' there is a "finally" clause which happens to raise another\n'
+ ' exception. That new exception causes the old one to be '
+ 'lost.\n'
+ '\n'
+ '[2] Currently, control "flows off the end" except in the case '
+ 'of\n'
+ ' an 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\n'
+ ' function body is transformed into the function\'s "__doc__"\n'
+ " attribute and 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': '\n'
+ 'With Statement Context Managers\n'
+ '*******************************\n'
+ '\n'
+ 'A *context manager* is an object that defines the '
+ 'runtime context to\n'
+ 'be established when executing a "with" statement. The '
+ 'context manager\n'
+ 'handles the entry into, and the exit from, the desired '
+ 'runtime context\n'
+ 'for the execution of the block of code. Context '
+ 'managers are normally\n'
+ 'invoked using the "with" statement (described in section '
+ 'The with\n'
+ 'statement), but can also be used by directly invoking '
+ 'their methods.\n'
+ '\n'
+ 'Typical uses of context managers include saving and '
+ 'restoring various\n'
+ 'kinds of global state, locking and unlocking resources, '
+ 'closing opened\n'
+ 'files, etc.\n'
+ '\n'
+ 'For more information on context managers, see Context '
+ 'Manager Types.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__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"
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 343** - The "with" statement\n'
+ ' The specification, background, and examples for the '
+ 'Python "with"\n'
+ ' statement.\n',
+ 'continue': '\n'
+ 'The "continue" statement\n'
+ '************************\n'
+ '\n'
+ ' continue_stmt ::= "continue"\n'
+ '\n'
+ '"continue" may only occur syntactically nested in a "for" or '
+ '"while"\n'
+ 'loop, but not nested in a function or class definition or '
+ '"finally"\n'
+ 'clause within that loop. It continues with the next cycle of '
+ 'the\n'
+ 'nearest enclosing loop.\n'
+ '\n'
+ 'When "continue" passes control out of a "try" statement with a\n'
+ '"finally" clause, that "finally" clause is executed before '
+ 'really\n'
+ 'starting the next loop cycle.\n',
+ 'conversions': '\n'
+ 'Arithmetic conversions\n'
+ '**********************\n'
+ '\n'
+ 'When a description of an arithmetic operator below uses the '
+ 'phrase\n'
+ '"the numeric arguments are converted to a common type," this '
+ 'means\n'
+ 'that the operator implementation for built-in types works as '
+ 'follows:\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\n'
+ ' other is converted to floating point;\n'
+ '\n'
+ '* otherwise, both must be integers and no conversion is '
+ 'necessary.\n'
+ '\n'
+ 'Some additional rules apply for certain operators (e.g., a '
+ 'string as a\n'
+ "left argument to the '%' operator). Extensions must define "
+ 'their own\n'
+ 'conversion behavior.\n',
+ 'customization': '\n'
+ 'Basic customization\n'
+ '*******************\n'
+ '\n'
+ 'object.__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 an\n'
+ ' 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'
+ '\n'
+ 'object.__init__(self[, ...])\n'
+ '\n'
+ ' Called after the instance has been created (by '
+ '"__new__()"), but\n'
+ ' before it is returned to the caller. 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, if\n'
+ ' any, must explicitly call it to ensure proper '
+ 'initialization of the\n'
+ ' base class part of the instance; for example:\n'
+ ' "BaseClass.__init__(self, [args...])".\n'
+ '\n'
+ ' Because "__new__()" and "__init__()" work together in '
+ 'constructing\n'
+ ' objects ("__new__()" to create it, and "__init__()" to '
+ 'customize\n'
+ ' it), no non-"None" value may be returned by '
+ '"__init__()"; doing so\n'
+ ' will cause a "TypeError" to be raised at runtime.\n'
+ '\n'
+ 'object.__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, the\n'
+ ' derived class\'s "__del__()" method, if any, must '
+ 'explicitly call it\n'
+ ' to ensure proper deletion of the base class part of the '
+ 'instance.\n'
+ ' Note that it is possible (though not recommended!) for '
+ 'the\n'
+ ' "__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 is\n'
+ ' only called when "x"\'s reference count reaches zero. '
+ 'Some common\n'
+ ' situations that may prevent the reference count of an '
+ 'object from\n'
+ ' going to zero include: circular references between '
+ 'objects (e.g.,\n'
+ ' a doubly-linked list or a tree data structure with '
+ 'parent and\n'
+ ' child pointers); a reference to the object on the '
+ 'stack frame of\n'
+ ' a function that caught an exception (the traceback '
+ 'stored in\n'
+ ' "sys.exc_info()[2]" keeps the stack frame alive); or a '
+ 'reference\n'
+ ' to the object on the stack frame that raised an '
+ 'unhandled\n'
+ ' 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 second can be resolved by freeing the reference to '
+ 'the\n'
+ ' traceback object when it is no longer useful, and the '
+ 'third can\n'
+ ' be resolved by storing "None" in "sys.last_traceback". '
+ 'Circular\n'
+ ' references which are garbage are detected and cleaned '
+ 'up when the\n'
+ " cyclic garbage collector is enabled (it's on by "
+ 'default). Refer\n'
+ ' to the documentation for the "gc" module for more '
+ 'information\n'
+ ' about this topic.\n'
+ '\n'
+ ' Warning: Due to the precarious circumstances under '
+ 'which\n'
+ ' "__del__()" methods are invoked, exceptions that occur '
+ 'during\n'
+ ' their execution are ignored, and a warning is printed '
+ 'to\n'
+ ' "sys.stderr" instead. Also, when "__del__()" is '
+ 'invoked in\n'
+ ' response to a module being deleted (e.g., when '
+ 'execution of the\n'
+ ' program is done), other globals referenced by the '
+ '"__del__()"\n'
+ ' method may already have been deleted or in the process '
+ 'of being\n'
+ ' torn down (e.g. the import machinery shutting down). '
+ 'For this\n'
+ ' reason, "__del__()" methods should do the absolute '
+ 'minimum needed\n'
+ ' to maintain external invariants. Starting with '
+ 'version 1.5,\n'
+ ' Python guarantees that globals whose name begins with '
+ 'a single\n'
+ ' underscore are deleted from their module before other '
+ 'globals are\n'
+ ' deleted; if no other references to such globals exist, '
+ 'this may\n'
+ ' help in assuring that imported modules are still '
+ 'available at the\n'
+ ' time when the "__del__()" method is called.\n'
+ '\n'
+ 'object.__repr__(self)\n'
+ '\n'
+ ' Called by the "repr()" built-in function to compute the '
+ '"official"\n'
+ ' string representation of an object. If at all possible, '
+ 'this\n'
+ ' should look like a valid Python expression that could be '
+ 'used to\n'
+ ' recreate an object with the same value (given an '
+ 'appropriate\n'
+ ' environment). If this is not possible, a string of the '
+ 'form\n'
+ ' "<...some useful description...>" should be returned. '
+ 'The return\n'
+ ' value must be a string object. If a class defines '
+ '"__repr__()" but\n'
+ ' not "__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'
+ '\n'
+ 'object.__str__(self)\n'
+ '\n'
+ ' Called by "str(object)" and the built-in functions '
+ '"format()" and\n'
+ ' "print()" to compute the "informal" or nicely printable '
+ 'string\n'
+ ' representation of an object. The return value must be a '
+ 'string\n'
+ ' object.\n'
+ '\n'
+ ' This method differs from "object.__repr__()" in that '
+ 'there is no\n'
+ ' expectation that "__str__()" return a valid Python '
+ 'expression: a\n'
+ ' more convenient or concise representation can be used.\n'
+ '\n'
+ ' The default implementation defined by the built-in type '
+ '"object"\n'
+ ' calls "object.__repr__()".\n'
+ '\n'
+ 'object.__bytes__(self)\n'
+ '\n'
+ ' Called by "bytes()" to compute a byte-string '
+ 'representation of an\n'
+ ' object. This should return a "bytes" object.\n'
+ '\n'
+ 'object.__format__(self, format_spec)\n'
+ '\n'
+ ' Called by the "format()" built-in function, and by '
+ 'extension,\n'
+ ' evaluation of formatted string literals and the '
+ '"str.format()"\n'
+ ' method, to produce a "formatted" string representation '
+ 'of an\n'
+ ' object. The "format_spec" argument is a string that '
+ 'contains a\n'
+ ' description of the formatting options desired. The '
+ 'interpretation\n'
+ ' of the "format_spec" argument is up to the type '
+ 'implementing\n'
+ ' "__format__()", however most classes will either '
+ 'delegate\n'
+ ' formatting to one of the built-in types, or use a '
+ 'similar\n'
+ ' 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'
+ '\n'
+ ' Changed in version 3.4: The __format__ method of '
+ '"object" itself\n'
+ ' raises a "TypeError" if passed any non-empty string.\n'
+ '\n'
+ 'object.__lt__(self, other)\n'
+ 'object.__le__(self, other)\n'
+ 'object.__eq__(self, other)\n'
+ 'object.__ne__(self, other)\n'
+ 'object.__gt__(self, other)\n'
+ 'object.__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: "x<y" calls "x.__lt__(y)", "x<=y" calls '
+ '"x.__le__(y)",\n'
+ ' "x==y" calls "x.__eq__(y)", "x!=y" calls "x.__ne__(y)", '
+ '"x>y" calls\n'
+ ' "x.__gt__(y)", and "x>=y" calls "x.__ge__(y)".\n'
+ '\n'
+ ' A rich comparison method may return the singleton '
+ '"NotImplemented"\n'
+ ' if it does not implement the operation for a given pair '
+ 'of\n'
+ ' arguments. By convention, "False" and "True" are '
+ 'returned for a\n'
+ ' successful comparison. However, these methods can return '
+ 'any value,\n'
+ ' so if the comparison operator is used in a Boolean '
+ 'context (e.g.,\n'
+ ' in the condition of an "if" statement), Python will call '
+ '"bool()"\n'
+ ' on the value to determine if the result is true or '
+ 'false.\n'
+ '\n'
+ ' By default, "__ne__()" delegates to "__eq__()" and '
+ 'inverts the\n'
+ ' result unless it is "NotImplemented". There are no '
+ 'other implied\n'
+ ' relationships among the comparison operators, for '
+ 'example, the\n'
+ ' truth of "(x<y or x==y)" does not imply "x<=y". To '
+ 'automatically\n'
+ ' generate ordering operations from a single root '
+ 'operation, see\n'
+ ' "functools.total_ordering()".\n'
+ '\n'
+ ' See 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 other's\n"
+ ' reflection, "__le__()" and "__ge__()" are each other\'s '
+ 'reflection,\n'
+ ' and "__eq__()" and "__ne__()" are their own reflection. '
+ 'If the\n'
+ " operands are of different types, and right operand's "
+ 'type is a\n'
+ " direct or indirect subclass of the left operand's type, "
+ 'the\n'
+ ' reflected method of the right operand has priority, '
+ 'otherwise the\n'
+ " left operand's method has priority. Virtual subclassing "
+ 'is not\n'
+ ' considered.\n'
+ '\n'
+ 'object.__hash__(self)\n'
+ '\n'
+ ' Called by built-in function "hash()" and for operations '
+ 'on members\n'
+ ' of hashed collections including "set", "frozenset", and '
+ '"dict".\n'
+ ' "__hash__()" should return an integer. 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'
+ ' Note: "hash()" truncates the value returned from an '
+ "object's\n"
+ ' custom "__hash__()" method to the size of a '
+ '"Py_ssize_t". This\n'
+ ' is typically 8 bytes on 64-bit builds and 4 bytes on '
+ '32-bit\n'
+ ' builds. If an object\'s "__hash__()" must '
+ 'interoperate on builds\n'
+ ' of different bit sizes, be sure to check the width on '
+ 'all\n'
+ ' supported builds. An easy way to do this is with '
+ '"python -c\n'
+ ' "import sys; print(sys.hash_info.width)"".\n'
+ '\n'
+ ' If a class does not define an "__eq__()" method it '
+ 'should not\n'
+ ' define a "__hash__()" operation either; if it defines '
+ '"__eq__()"\n'
+ ' but not "__hash__()", its instances will not be usable '
+ 'as items in\n'
+ ' hashable collections. If a class defines mutable '
+ 'objects and\n'
+ ' implements an "__eq__()" method, it should not '
+ 'implement\n'
+ ' "__hash__()", since the implementation of hashable '
+ 'collections\n'
+ " requires that a key's hash value is immutable (if the "
+ "object's hash\n"
+ ' value changes, it will be in the wrong hash bucket).\n'
+ '\n'
+ ' User-defined classes have "__eq__()" and "__hash__()" '
+ 'methods by\n'
+ ' default; with them, all objects compare unequal (except '
+ 'with\n'
+ ' themselves) and "x.__hash__()" returns an appropriate '
+ 'value such\n'
+ ' that "x == y" implies both that "x is y" and "hash(x) == '
+ 'hash(y)".\n'
+ '\n'
+ ' A class that overrides "__eq__()" and does not define '
+ '"__hash__()"\n'
+ ' will have its "__hash__()" implicitly set to "None". '
+ 'When the\n'
+ ' "__hash__()" method of a class is "None", instances of '
+ 'the class\n'
+ ' will raise an appropriate "TypeError" when a program '
+ 'attempts to\n'
+ ' retrieve their hash value, and will also be correctly '
+ 'identified as\n'
+ ' unhashable when checking "isinstance(obj, '
+ 'collections.Hashable)".\n'
+ '\n'
+ ' If a class that overrides "__eq__()" needs to retain '
+ 'the\n'
+ ' implementation of "__hash__()" from a parent class, the '
+ 'interpreter\n'
+ ' must be told this explicitly by setting "__hash__ =\n'
+ ' <ParentClass>.__hash__".\n'
+ '\n'
+ ' If a class that does not override "__eq__()" wishes to '
+ 'suppress\n'
+ ' hash support, it should include "__hash__ = None" in the '
+ 'class\n'
+ ' definition. A class which defines its own "__hash__()" '
+ 'that\n'
+ ' explicitly raises a "TypeError" would be incorrectly '
+ 'identified as\n'
+ ' hashable by an "isinstance(obj, collections.Hashable)" '
+ 'call.\n'
+ '\n'
+ ' Note: By default, the "__hash__()" values of str, bytes '
+ 'and\n'
+ ' datetime objects are "salted" with an unpredictable '
+ 'random value.\n'
+ ' Although they remain constant within an individual '
+ 'Python\n'
+ ' process, they are not predictable between repeated '
+ 'invocations of\n'
+ ' Python.This is intended to provide protection against '
+ 'a denial-\n'
+ ' of-service caused by carefully-chosen inputs that '
+ 'exploit the\n'
+ ' worst case performance of a dict insertion, O(n^2) '
+ 'complexity.\n'
+ ' See '
+ 'http://www.ocert.org/advisories/ocert-2011-003.html for\n'
+ ' details.Changing hash values affects the iteration '
+ 'order of\n'
+ ' dicts, sets and other mappings. Python has never made '
+ 'guarantees\n'
+ ' about this ordering (and it typically varies between '
+ '32-bit and\n'
+ ' 64-bit builds).See also "PYTHONHASHSEED".\n'
+ '\n'
+ ' Changed in version 3.3: Hash randomization is enabled by '
+ 'default.\n'
+ '\n'
+ 'object.__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 is not\n'
+ ' defined, "__len__()" is called, if it is defined, and '
+ 'the object is\n'
+ ' considered true if its result is nonzero. If a class '
+ 'defines\n'
+ ' neither "__len__()" nor "__bool__()", all its instances '
+ 'are\n'
+ ' considered true.\n',
+ 'debugger': '\n'
+ '"pdb" --- The Python Debugger\n'
+ '*****************************\n'
+ '\n'
+ '**Source code:** Lib/pdb.py\n'
+ '\n'
+ '======================================================================\n'
+ '\n'
+ 'The module "pdb" defines an interactive source code debugger '
+ 'for\n'
+ 'Python programs. It supports setting (conditional) breakpoints '
+ 'and\n'
+ 'single stepping at the source line level, inspection of stack '
+ 'frames,\n'
+ 'source code listing, and evaluation of arbitrary Python code in '
+ 'the\n'
+ 'context of any stack frame. It also supports post-mortem '
+ 'debugging\n'
+ 'and can be called under program control.\n'
+ '\n'
+ 'The debugger is extensible -- it is actually defined as the '
+ 'class\n'
+ '"Pdb". This is currently undocumented but easily understood by '
+ 'reading\n'
+ 'the source. The extension interface uses the modules "bdb" and '
+ '"cmd".\n'
+ '\n'
+ 'The debugger\'s prompt is "(Pdb)". Typical usage to run a '
+ 'program under\n'
+ 'control of the debugger is:\n'
+ '\n'
+ ' >>> import pdb\n'
+ ' >>> import mymodule\n'
+ " >>> pdb.run('mymodule.test()')\n"
+ ' > <string>(0)?()\n'
+ ' (Pdb) continue\n'
+ ' > <string>(1)?()\n'
+ ' (Pdb) continue\n'
+ " NameError: 'spam'\n"
+ ' > <string>(1)?()\n'
+ ' (Pdb)\n'
+ '\n'
+ 'Changed in version 3.3: Tab-completion via the "readline" module '
+ 'is\n'
+ 'available for commands and command arguments, e.g. the current '
+ 'global\n'
+ 'and local names are offered as arguments of the "p" command.\n'
+ '\n'
+ '"pdb.py" can also be invoked as a script to debug other '
+ 'scripts. For\n'
+ 'example:\n'
+ '\n'
+ ' python3 -m pdb myscript.py\n'
+ '\n'
+ 'When invoked as a script, pdb will automatically enter '
+ 'post-mortem\n'
+ 'debugging if the program being debugged exits abnormally. After '
+ 'post-\n'
+ 'mortem debugging (or after normal exit of the program), pdb '
+ 'will\n'
+ "restart the program. Automatic restarting preserves pdb's state "
+ '(such\n'
+ 'as breakpoints) and in most cases is more useful than quitting '
+ 'the\n'
+ "debugger upon program's exit.\n"
+ '\n'
+ 'New in version 3.2: "pdb.py" now accepts a "-c" option that '
+ 'executes\n'
+ 'commands as if given in a ".pdbrc" file, see Debugger Commands.\n'
+ '\n'
+ 'The typical usage to break into the debugger from a running '
+ 'program is\n'
+ 'to insert\n'
+ '\n'
+ ' import pdb; pdb.set_trace()\n'
+ '\n'
+ 'at the location you want to break into the debugger. You can '
+ 'then\n'
+ 'step through the code following this statement, and continue '
+ 'running\n'
+ 'without the debugger using the "continue" command.\n'
+ '\n'
+ 'The typical usage to inspect a crashed program is:\n'
+ '\n'
+ ' >>> import pdb\n'
+ ' >>> import mymodule\n'
+ ' >>> mymodule.test()\n'
+ ' Traceback (most recent call last):\n'
+ ' File "<stdin>", 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'
+ '\n'
+ 'The module defines the following functions; each enters the '
+ 'debugger\n'
+ 'in a slightly different way:\n'
+ '\n'
+ 'pdb.run(statement, globals=None, locals=None)\n'
+ '\n'
+ ' Execute the *statement* (given as a string or a code object) '
+ 'under\n'
+ ' debugger control. The debugger prompt appears before any '
+ 'code is\n'
+ ' executed; you can set breakpoints and type "continue", or you '
+ 'can\n'
+ ' step through the statement using "step" or "next" (all these\n'
+ ' commands are explained below). The optional *globals* and '
+ '*locals*\n'
+ ' arguments specify the environment in which the code is '
+ 'executed; by\n'
+ ' default the dictionary of the module "__main__" is used. '
+ '(See the\n'
+ ' explanation of the built-in "exec()" or "eval()" functions.)\n'
+ '\n'
+ 'pdb.runeval(expression, globals=None, locals=None)\n'
+ '\n'
+ ' Evaluate the *expression* (given as a string or a code '
+ 'object)\n'
+ ' under debugger control. When "runeval()" returns, it returns '
+ 'the\n'
+ ' value of the expression. Otherwise this function is similar '
+ 'to\n'
+ ' "run()".\n'
+ '\n'
+ 'pdb.runcall(function, *args, **kwds)\n'
+ '\n'
+ ' Call the *function* (a function or method object, not a '
+ 'string)\n'
+ ' with the given arguments. When "runcall()" returns, it '
+ 'returns\n'
+ ' whatever the function call returned. The debugger prompt '
+ 'appears\n'
+ ' as soon as the function is entered.\n'
+ '\n'
+ 'pdb.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'
+ '\n'
+ 'pdb.post_mortem(traceback=None)\n'
+ '\n'
+ ' Enter post-mortem debugging of the given *traceback* object. '
+ 'If no\n'
+ ' *traceback* is given, it uses the one of the exception that '
+ 'is\n'
+ ' currently being handled (an exception must be being handled '
+ 'if the\n'
+ ' default is to be used).\n'
+ '\n'
+ 'pdb.pm()\n'
+ '\n'
+ ' Enter post-mortem debugging of the traceback found in\n'
+ ' "sys.last_traceback".\n'
+ '\n'
+ 'The "run*" functions and "set_trace()" are aliases for '
+ 'instantiating\n'
+ 'the "Pdb" class and calling the method of the same name. If you '
+ 'want\n'
+ 'to access further features, you have to do this yourself:\n'
+ '\n'
+ "class pdb.Pdb(completekey='tab', stdin=None, stdout=None, "
+ 'skip=None, nosigint=False, readrc=True)\n'
+ '\n'
+ ' "Pdb" is the debugger class.\n'
+ '\n'
+ ' The *completekey*, *stdin* and *stdout* arguments are passed '
+ 'to the\n'
+ ' underlying "cmd.Cmd" class; see the description there.\n'
+ '\n'
+ ' The *skip* argument, if given, must be an iterable of '
+ 'glob-style\n'
+ ' module name patterns. The debugger will not step into frames '
+ 'that\n'
+ ' originate in a module that matches one of these patterns. '
+ '[1]\n'
+ '\n'
+ ' By default, Pdb sets a handler for the SIGINT signal (which '
+ 'is sent\n'
+ ' when the user presses "Ctrl-C" on the console) when you give '
+ 'a\n'
+ ' "continue" command. This allows you to break into the '
+ 'debugger\n'
+ ' again by pressing "Ctrl-C". If you want Pdb not to touch '
+ 'the\n'
+ ' SIGINT handler, set *nosigint* to true.\n'
+ '\n'
+ ' The *readrc* argument defaults to true and controls whether '
+ 'Pdb\n'
+ ' will load .pdbrc files from the filesystem.\n'
+ '\n'
+ ' Example call to enable tracing with *skip*:\n'
+ '\n'
+ " import pdb; pdb.Pdb(skip=['django.*']).set_trace()\n"
+ '\n'
+ ' New in version 3.1: The *skip* argument.\n'
+ '\n'
+ ' New in version 3.2: The *nosigint* argument. Previously, a '
+ 'SIGINT\n'
+ ' handler was never set by Pdb.\n'
+ '\n'
+ ' Changed in version 3.6: The *readrc* argument.\n'
+ '\n'
+ ' run(statement, globals=None, locals=None)\n'
+ ' runeval(expression, globals=None, locals=None)\n'
+ ' runcall(function, *args, **kwds)\n'
+ ' set_trace()\n'
+ '\n'
+ ' See the documentation for the functions explained above.\n'
+ '\n'
+ '\n'
+ 'Debugger Commands\n'
+ '=================\n'
+ '\n'
+ 'The commands recognized by the debugger are listed below. Most\n'
+ 'commands can be abbreviated to one or two letters as indicated; '
+ 'e.g.\n'
+ '"h(elp)" means that either "h" or "help" can be used to enter '
+ 'the help\n'
+ 'command (but not "he" or "hel", nor "H" or "Help" or "HELP").\n'
+ 'Arguments to commands must be separated by whitespace (spaces '
+ 'or\n'
+ 'tabs). Optional arguments are enclosed in square brackets '
+ '("[]") in\n'
+ 'the command syntax; the square brackets must not be typed.\n'
+ 'Alternatives in the command syntax are separated by a vertical '
+ 'bar\n'
+ '("|").\n'
+ '\n'
+ 'Entering a blank line repeats the last command entered. '
+ 'Exception: if\n'
+ 'the last command was a "list" command, the next 11 lines are '
+ 'listed.\n'
+ '\n'
+ "Commands that the debugger doesn't recognize are assumed to be "
+ 'Python\n'
+ 'statements and are executed in the context of the program being\n'
+ 'debugged. Python statements can also be prefixed with an '
+ 'exclamation\n'
+ 'point ("!"). This is a powerful way to inspect the program '
+ 'being\n'
+ 'debugged; it is even possible to change a variable or call a '
+ 'function.\n'
+ 'When an exception occurs in such a statement, the exception name '
+ 'is\n'
+ "printed but the debugger's state is not changed.\n"
+ '\n'
+ 'The debugger supports aliases. Aliases can have parameters '
+ 'which\n'
+ 'allows one a certain level of adaptability to the context under\n'
+ 'examination.\n'
+ '\n'
+ 'Multiple commands may be entered on a single line, separated by '
+ '";;".\n'
+ '(A single ";" is not used as it is the separator for multiple '
+ 'commands\n'
+ 'in a line that is passed to the Python parser.) No intelligence '
+ 'is\n'
+ 'applied to separating the commands; the input is split at the '
+ 'first\n'
+ '";;" pair, even if it is in the middle of a quoted string.\n'
+ '\n'
+ 'If a file ".pdbrc" exists in the user\'s home directory or in '
+ 'the\n'
+ 'current directory, it is read in and executed as if it had been '
+ 'typed\n'
+ 'at the debugger prompt. This is particularly useful for '
+ 'aliases. If\n'
+ 'both files exist, the one in the home directory is read first '
+ 'and\n'
+ 'aliases defined there can be overridden by the local file.\n'
+ '\n'
+ 'Changed in version 3.2: ".pdbrc" can now contain commands that\n'
+ 'continue debugging, such as "continue" or "next". Previously, '
+ 'these\n'
+ 'commands had no effect.\n'
+ '\n'
+ 'h(elp) [command]\n'
+ '\n'
+ ' Without argument, print the list of available commands. With '
+ 'a\n'
+ ' *command* as argument, print help about that command. "help '
+ 'pdb"\n'
+ ' displays the full documentation (the docstring of the "pdb"\n'
+ ' module). Since the *command* argument must be an identifier, '
+ '"help\n'
+ ' exec" must be entered to get help on the "!" command.\n'
+ '\n'
+ 'w(here)\n'
+ '\n'
+ ' Print a stack trace, with the most recent frame at the '
+ 'bottom. An\n'
+ ' arrow indicates the current frame, which determines the '
+ 'context of\n'
+ ' most commands.\n'
+ '\n'
+ 'd(own) [count]\n'
+ '\n'
+ ' Move the current frame *count* (default one) levels down in '
+ 'the\n'
+ ' stack trace (to a newer frame).\n'
+ '\n'
+ 'u(p) [count]\n'
+ '\n'
+ ' Move the current frame *count* (default one) levels up in the '
+ 'stack\n'
+ ' trace (to an older frame).\n'
+ '\n'
+ 'b(reak) [([filename:]lineno | function) [, condition]]\n'
+ '\n'
+ ' With a *lineno* argument, set a break there in the current '
+ 'file.\n'
+ ' With a *function* argument, set a break at the first '
+ 'executable\n'
+ ' statement within that function. The line number may be '
+ 'prefixed\n'
+ ' with a filename and a colon, to specify a breakpoint in '
+ 'another\n'
+ " file (probably one that hasn't been loaded yet). The file "
+ 'is\n'
+ ' searched on "sys.path". Note that each breakpoint is '
+ 'assigned a\n'
+ ' number to which all the other breakpoint commands refer.\n'
+ '\n'
+ ' If a second argument is present, it is an expression which '
+ 'must\n'
+ ' evaluate to true before the breakpoint is honored.\n'
+ '\n'
+ ' Without argument, list all breaks, including for each '
+ 'breakpoint,\n'
+ ' the number of times that breakpoint has been hit, the '
+ 'current\n'
+ ' ignore count, and the associated condition if any.\n'
+ '\n'
+ 'tbreak [([filename:]lineno | function) [, condition]]\n'
+ '\n'
+ ' Temporary breakpoint, which is removed automatically when it '
+ 'is\n'
+ ' first hit. The arguments are the same as for "break".\n'
+ '\n'
+ 'cl(ear) [filename:lineno | bpnumber [bpnumber ...]]\n'
+ '\n'
+ ' With a *filename:lineno* argument, clear all the breakpoints '
+ 'at\n'
+ ' this line. With a space separated list of breakpoint numbers, '
+ 'clear\n'
+ ' those breakpoints. Without argument, clear all breaks (but '
+ 'first\n'
+ ' ask confirmation).\n'
+ '\n'
+ 'disable [bpnumber [bpnumber ...]]\n'
+ '\n'
+ ' Disable the breakpoints given as a space separated list of\n'
+ ' breakpoint numbers. Disabling a breakpoint means it cannot '
+ 'cause\n'
+ ' the program to stop execution, but unlike clearing a '
+ 'breakpoint, it\n'
+ ' remains in the list of breakpoints and can be (re-)enabled.\n'
+ '\n'
+ 'enable [bpnumber [bpnumber ...]]\n'
+ '\n'
+ ' Enable the breakpoints specified.\n'
+ '\n'
+ 'ignore bpnumber [count]\n'
+ '\n'
+ ' Set the ignore count for the given breakpoint number. If '
+ 'count is\n'
+ ' omitted, the ignore count is set to 0. A breakpoint becomes '
+ 'active\n'
+ ' when the ignore count is zero. When non-zero, the count is\n'
+ ' decremented each time the breakpoint is reached and the '
+ 'breakpoint\n'
+ ' is not disabled and any associated condition evaluates to '
+ 'true.\n'
+ '\n'
+ 'condition bpnumber [condition]\n'
+ '\n'
+ ' Set a new *condition* for the breakpoint, an expression which '
+ 'must\n'
+ ' evaluate to true before the breakpoint is honored. If '
+ '*condition*\n'
+ ' is absent, any existing condition is removed; i.e., the '
+ 'breakpoint\n'
+ ' is made unconditional.\n'
+ '\n'
+ 'commands [bpnumber]\n'
+ '\n'
+ ' Specify a list of commands for breakpoint number *bpnumber*. '
+ 'The\n'
+ ' commands themselves appear on the following lines. Type a '
+ 'line\n'
+ ' containing just "end" to terminate the commands. An example:\n'
+ '\n'
+ ' (Pdb) commands 1\n'
+ ' (com) p some_variable\n'
+ ' (com) end\n'
+ ' (Pdb)\n'
+ '\n'
+ ' To remove all commands from a breakpoint, type commands and '
+ 'follow\n'
+ ' it immediately with "end"; that is, give no commands.\n'
+ '\n'
+ ' With no *bpnumber* argument, commands refers to the last '
+ 'breakpoint\n'
+ ' set.\n'
+ '\n'
+ ' You can use breakpoint commands to start your program up '
+ 'again.\n'
+ ' Simply use the continue command, or step, or any other '
+ 'command that\n'
+ ' resumes execution.\n'
+ '\n'
+ ' Specifying any command resuming execution (currently '
+ 'continue,\n'
+ ' step, next, return, jump, quit and their abbreviations) '
+ 'terminates\n'
+ ' the command list (as if that command was immediately followed '
+ 'by\n'
+ ' end). This is because any time you resume execution (even '
+ 'with a\n'
+ ' simple next or step), you may encounter another '
+ 'breakpoint--which\n'
+ ' could have its own command list, leading to ambiguities about '
+ 'which\n'
+ ' list to execute.\n'
+ '\n'
+ " If you use the 'silent' command in the command list, the "
+ 'usual\n'
+ ' message about stopping at a breakpoint is not printed. This '
+ 'may be\n'
+ ' desirable for breakpoints that are to print a specific '
+ 'message and\n'
+ ' then continue. If none of the other commands print anything, '
+ 'you\n'
+ ' see no sign that the breakpoint was reached.\n'
+ '\n'
+ 's(tep)\n'
+ '\n'
+ ' Execute the current line, stop at the first possible '
+ 'occasion\n'
+ ' (either in a function that is called or on the next line in '
+ 'the\n'
+ ' current function).\n'
+ '\n'
+ 'n(ext)\n'
+ '\n'
+ ' Continue execution until the next line in the current '
+ 'function is\n'
+ ' reached or it returns. (The difference between "next" and '
+ '"step"\n'
+ ' is that "step" stops inside a called function, while "next"\n'
+ ' executes called functions at (nearly) full speed, only '
+ 'stopping at\n'
+ ' the next line in the current function.)\n'
+ '\n'
+ 'unt(il) [lineno]\n'
+ '\n'
+ ' Without argument, continue execution until the line with a '
+ 'number\n'
+ ' greater than the current one is reached.\n'
+ '\n'
+ ' With a line number, continue execution until a line with a '
+ 'number\n'
+ ' greater or equal to that is reached. In both cases, also '
+ 'stop when\n'
+ ' the current frame returns.\n'
+ '\n'
+ ' Changed in version 3.2: Allow giving an explicit line '
+ 'number.\n'
+ '\n'
+ 'r(eturn)\n'
+ '\n'
+ ' Continue execution until the current function returns.\n'
+ '\n'
+ 'c(ont(inue))\n'
+ '\n'
+ ' Continue execution, only stop when a breakpoint is '
+ 'encountered.\n'
+ '\n'
+ 'j(ump) lineno\n'
+ '\n'
+ ' Set the next line that will be executed. Only available in '
+ 'the\n'
+ ' bottom-most frame. This lets you jump back and execute code '
+ 'again,\n'
+ " or jump forward to skip code that you don't want to run.\n"
+ '\n'
+ ' It should be noted that not all jumps are allowed -- for '
+ 'instance\n'
+ ' it is not possible to jump into the middle of a "for" loop or '
+ 'out\n'
+ ' of a "finally" clause.\n'
+ '\n'
+ 'l(ist) [first[, last]]\n'
+ '\n'
+ ' List source code for the current file. Without arguments, '
+ 'list 11\n'
+ ' lines around the current line or continue the previous '
+ 'listing.\n'
+ ' With "." as argument, list 11 lines around the current line. '
+ 'With\n'
+ ' one argument, list 11 lines around at that line. With two\n'
+ ' arguments, list the given range; if the second argument is '
+ 'less\n'
+ ' than the first, it is interpreted as a count.\n'
+ '\n'
+ ' The current line in the current frame is indicated by "->". '
+ 'If an\n'
+ ' exception is being debugged, the line where the exception '
+ 'was\n'
+ ' originally raised or propagated is indicated by ">>", if it '
+ 'differs\n'
+ ' from the current line.\n'
+ '\n'
+ ' New in version 3.2: The ">>" marker.\n'
+ '\n'
+ 'll | longlist\n'
+ '\n'
+ ' List all source code for the current function or frame.\n'
+ ' Interesting lines are marked as for "list".\n'
+ '\n'
+ ' New in version 3.2.\n'
+ '\n'
+ 'a(rgs)\n'
+ '\n'
+ ' Print the argument list of the current function.\n'
+ '\n'
+ 'p expression\n'
+ '\n'
+ ' Evaluate the *expression* in the current context and print '
+ 'its\n'
+ ' value.\n'
+ '\n'
+ ' Note: "print()" can also be used, but is not a debugger '
+ 'command\n'
+ ' --- this executes the Python "print()" function.\n'
+ '\n'
+ 'pp expression\n'
+ '\n'
+ ' Like the "p" command, except the value of the expression is '
+ 'pretty-\n'
+ ' printed using the "pprint" module.\n'
+ '\n'
+ 'whatis expression\n'
+ '\n'
+ ' Print the type of the *expression*.\n'
+ '\n'
+ 'source expression\n'
+ '\n'
+ ' Try to get source code for the given object and display it.\n'
+ '\n'
+ ' New in version 3.2.\n'
+ '\n'
+ 'display [expression]\n'
+ '\n'
+ ' Display the value of the expression if it changed, each time\n'
+ ' execution stops in the current frame.\n'
+ '\n'
+ ' Without expression, list all display expressions for the '
+ 'current\n'
+ ' frame.\n'
+ '\n'
+ ' New in version 3.2.\n'
+ '\n'
+ 'undisplay [expression]\n'
+ '\n'
+ ' Do not display the expression any more in the current frame.\n'
+ ' Without expression, clear all display expressions for the '
+ 'current\n'
+ ' frame.\n'
+ '\n'
+ ' New in version 3.2.\n'
+ '\n'
+ 'interact\n'
+ '\n'
+ ' Start an interactive interpreter (using the "code" module) '
+ 'whose\n'
+ ' global namespace contains all the (global and local) names '
+ 'found in\n'
+ ' the current scope.\n'
+ '\n'
+ ' New in version 3.2.\n'
+ '\n'
+ 'alias [name [command]]\n'
+ '\n'
+ ' Create an alias called *name* that executes *command*. The '
+ 'command\n'
+ ' must *not* be enclosed in quotes. Replaceable parameters can '
+ 'be\n'
+ ' indicated by "%1", "%2", and so on, while "%*" is replaced by '
+ 'all\n'
+ ' the parameters. If no command is given, the current alias '
+ 'for\n'
+ ' *name* is shown. If no arguments are given, all aliases are '
+ 'listed.\n'
+ '\n'
+ ' Aliases may be nested and can contain anything that can be '
+ 'legally\n'
+ ' typed at the pdb prompt. Note that internal pdb commands '
+ '*can* be\n'
+ ' overridden by aliases. Such a command is then hidden until '
+ 'the\n'
+ ' alias is removed. Aliasing is recursively applied to the '
+ 'first\n'
+ ' word of the command line; all other words in the line are '
+ 'left\n'
+ ' alone.\n'
+ '\n'
+ ' As an example, here are two useful aliases (especially when '
+ 'placed\n'
+ ' in the ".pdbrc" file):\n'
+ '\n'
+ ' # Print instance variables (usage "pi classInst")\n'
+ ' alias pi for k in %1.__dict__.keys(): '
+ 'print("%1.",k,"=",%1.__dict__[k])\n'
+ ' # Print instance variables in self\n'
+ ' alias ps pi self\n'
+ '\n'
+ 'unalias name\n'
+ '\n'
+ ' Delete the specified alias.\n'
+ '\n'
+ '! statement\n'
+ '\n'
+ ' Execute the (one-line) *statement* in the context of the '
+ 'current\n'
+ ' stack frame. The exclamation point can be omitted unless the '
+ 'first\n'
+ ' word of the statement resembles a debugger command. To set '
+ 'a\n'
+ ' global variable, you can prefix the assignment command with '
+ 'a\n'
+ ' "global" statement on the same line, e.g.:\n'
+ '\n'
+ " (Pdb) global list_options; list_options = ['-l']\n"
+ ' (Pdb)\n'
+ '\n'
+ 'run [args ...]\n'
+ 'restart [args ...]\n'
+ '\n'
+ ' Restart the debugged Python program. If an argument is '
+ 'supplied,\n'
+ ' it is split with "shlex" and the result is used as the new\n'
+ ' "sys.argv". History, breakpoints, actions and debugger '
+ 'options are\n'
+ ' preserved. "restart" is an alias for "run".\n'
+ '\n'
+ 'q(uit)\n'
+ '\n'
+ ' Quit from the debugger. The program being executed is '
+ 'aborted.\n'
+ '\n'
+ '-[ Footnotes ]-\n'
+ '\n'
+ '[1] Whether a frame is considered to originate in a certain '
+ 'module\n'
+ ' is determined by the "__name__" in the frame globals.\n',
+ 'del': '\n'
+ 'The "del" statement\n'
+ '*******************\n'
+ '\n'
+ ' del_stmt ::= "del" target_list\n'
+ '\n'
+ 'Deletion is recursively defined very similar to the way assignment '
+ 'is\n'
+ 'defined. Rather than spelling it out in full details, here are some\n'
+ 'hints.\n'
+ '\n'
+ 'Deletion of a target list recursively deletes each target, from left\n'
+ 'to right.\n'
+ '\n'
+ 'Deletion of a name removes the binding of that name from the local '
+ 'or\n'
+ 'global namespace, depending on whether the name occurs in a "global"\n'
+ 'statement in the same code block. If the name is unbound, a\n'
+ '"NameError" exception will be raised.\n'
+ '\n'
+ 'Deletion of attribute references, subscriptions and slicings is '
+ 'passed\n'
+ 'to the primary object involved; deletion of a slicing is in general\n'
+ 'equivalent to assignment of an empty slice of the right type (but '
+ 'even\n'
+ 'this is determined by the sliced object).\n'
+ '\n'
+ 'Changed in version 3.2: Previously it was illegal to delete a name\n'
+ 'from the local namespace if it occurs as a free variable in a nested\n'
+ 'block.\n',
+ 'dict': '\n'
+ 'Dictionary displays\n'
+ '*******************\n'
+ '\n'
+ 'A dictionary display is a possibly empty series of key/datum pairs\n'
+ 'enclosed 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 | "**" or_expr\n'
+ ' dict_comprehension ::= expression ":" expression comp_for\n'
+ '\n'
+ 'A dictionary display yields a new dictionary object.\n'
+ '\n'
+ 'If a comma-separated sequence of key/datum pairs is given, they are\n'
+ 'evaluated from left to right to define the entries of the '
+ 'dictionary:\n'
+ 'each key object is used as a key into the dictionary to store the\n'
+ 'corresponding datum. This means that you can specify the same key\n'
+ "multiple times in the key/datum list, and the final dictionary's "
+ 'value\n'
+ 'for that key will be the last one given.\n'
+ '\n'
+ 'A double asterisk "**" denotes *dictionary unpacking*. Its operand\n'
+ 'must be a *mapping*. Each mapping item is added to the new\n'
+ 'dictionary. Later values replace values already set by earlier\n'
+ 'key/datum pairs and earlier dictionary unpackings.\n'
+ '\n'
+ 'New in version 3.5: Unpacking into dictionary displays, originally\n'
+ 'proposed by **PEP 448**.\n'
+ '\n'
+ 'A dict comprehension, in contrast to list and set comprehensions,\n'
+ 'needs two expressions separated with a colon followed by the usual\n'
+ '"for" and "if" clauses. When the comprehension is run, the '
+ 'resulting\n'
+ 'key and value elements are inserted in the new dictionary in the '
+ 'order\n'
+ 'they are produced.\n'
+ '\n'
+ 'Restrictions on the types of the key values are listed earlier in\n'
+ 'section The standard type hierarchy. (To summarize, the key type\n'
+ 'should be *hashable*, which excludes all mutable objects.) Clashes\n'
+ 'between duplicate keys are not detected; the last datum (textually\n'
+ 'rightmost in the display) stored for a given key value prevails.\n',
+ 'dynamic-features': '\n'
+ 'Interaction with dynamic features\n'
+ '*********************************\n'
+ '\n'
+ 'Name resolution of free variables occurs at runtime, not '
+ 'at compile\n'
+ 'time. This means that the following code will print 42:\n'
+ '\n'
+ ' i = 10\n'
+ ' def f():\n'
+ ' print(i)\n'
+ ' i = 42\n'
+ ' f()\n'
+ '\n'
+ 'There are several cases where Python statements are '
+ 'illegal when used\n'
+ 'in conjunction with nested scopes that contain free '
+ 'variables.\n'
+ '\n'
+ 'If a variable is referenced in an enclosing scope, it is '
+ 'illegal to\n'
+ 'delete the name. An error will be reported at compile '
+ 'time.\n'
+ '\n'
+ 'The "eval()" and "exec()" functions do not have access '
+ 'to the full\n'
+ 'environment for resolving names. Names may be resolved '
+ 'in the local\n'
+ 'and global namespaces of the caller. Free variables are '
+ 'not resolved\n'
+ 'in the nearest enclosing namespace, but in the global '
+ 'namespace. [1]\n'
+ 'The "exec()" and "eval()" functions have optional '
+ 'arguments to\n'
+ 'override the global and local namespace. If only one '
+ 'namespace is\n'
+ 'specified, it is used for both.\n',
+ 'else': '\n'
+ 'The "if" statement\n'
+ '******************\n'
+ '\n'
+ 'The "if" statement is used for conditional execution:\n'
+ '\n'
+ ' if_stmt ::= "if" expression ":" suite\n'
+ ' ( "elif" expression ":" suite )*\n'
+ ' ["else" ":" suite]\n'
+ '\n'
+ 'It selects exactly one of the suites by evaluating the expressions '
+ 'one\n'
+ 'by one until one is found to be true (see section Boolean '
+ 'operations\n'
+ 'for the definition of true and false); then that suite is executed\n'
+ '(and no other part of the "if" statement is executed or evaluated).\n'
+ 'If all expressions are false, the suite of the "else" clause, if\n'
+ 'present, is executed.\n',
+ 'exceptions': '\n'
+ 'Exceptions\n'
+ '**********\n'
+ '\n'
+ 'Exceptions are a means of breaking out of the normal flow of '
+ 'control\n'
+ 'of a code block in order to handle errors or other '
+ 'exceptional\n'
+ 'conditions. An exception is *raised* at the point where the '
+ 'error is\n'
+ 'detected; it may be *handled* by the surrounding code block or '
+ 'by any\n'
+ 'code block that directly or indirectly invoked the code block '
+ 'where\n'
+ 'the error occurred.\n'
+ '\n'
+ 'The Python interpreter raises an exception when it detects a '
+ 'run-time\n'
+ 'error (such as division by zero). A Python program can also\n'
+ 'explicitly raise an exception with the "raise" statement. '
+ 'Exception\n'
+ 'handlers are specified with the "try" ... "except" statement. '
+ 'The\n'
+ '"finally" clause of such a statement can be used to specify '
+ 'cleanup\n'
+ 'code which does not handle the exception, but is executed '
+ 'whether an\n'
+ 'exception occurred or not in the preceding code.\n'
+ '\n'
+ 'Python uses the "termination" model of error handling: an '
+ 'exception\n'
+ 'handler can find out what happened and continue execution at '
+ 'an outer\n'
+ 'level, but it cannot repair the cause of the error and retry '
+ 'the\n'
+ 'failing operation (except by re-entering the offending piece '
+ 'of code\n'
+ 'from the top).\n'
+ '\n'
+ 'When an exception is not handled at all, the interpreter '
+ 'terminates\n'
+ 'execution of the program, or returns to its interactive main '
+ 'loop. In\n'
+ 'either case, it prints a stack backtrace, except when the '
+ 'exception is\n'
+ '"SystemExit".\n'
+ '\n'
+ 'Exceptions are identified by class instances. The "except" '
+ 'clause is\n'
+ 'selected depending on the class of the instance: it must '
+ 'reference the\n'
+ 'class of the instance or a base class thereof. The instance '
+ 'can be\n'
+ 'received by the handler and can carry additional information '
+ 'about the\n'
+ 'exceptional condition.\n'
+ '\n'
+ 'Note: Exception messages are not part of the Python API. '
+ 'Their\n'
+ ' contents may change from one version of Python to the next '
+ 'without\n'
+ ' warning and should not be relied on by code which will run '
+ 'under\n'
+ ' multiple versions of the interpreter.\n'
+ '\n'
+ 'See also the description of the "try" statement in section The '
+ 'try\n'
+ 'statement and "raise" statement in section The raise '
+ 'statement.\n'
+ '\n'
+ '-[ Footnotes ]-\n'
+ '\n'
+ '[1] This limitation occurs because the code that is executed '
+ 'by\n'
+ ' these operations is not available at the time the module '
+ 'is\n'
+ ' compiled.\n',
+ 'execmodel': '\n'
+ 'Execution model\n'
+ '***************\n'
+ '\n'
+ '\n'
+ 'Structure of a program\n'
+ '======================\n'
+ '\n'
+ 'A Python program is constructed from code blocks. A *block* is '
+ 'a piece\n'
+ 'of Python program text that is executed as a unit. The '
+ 'following are\n'
+ 'blocks: a module, a function body, and a class definition. '
+ 'Each\n'
+ 'command typed interactively is a block. A script file (a file '
+ 'given\n'
+ 'as standard input to the interpreter or specified as a command '
+ 'line\n'
+ 'argument to the interpreter) is a code block. A script command '
+ '(a\n'
+ 'command specified on the interpreter command line with the '
+ "'**-c**'\n"
+ 'option) is a code block. The string argument passed to the '
+ 'built-in\n'
+ 'functions "eval()" and "exec()" is a code block.\n'
+ '\n'
+ 'A code block is executed in an *execution frame*. A frame '
+ 'contains\n'
+ 'some administrative information (used for debugging) and '
+ 'determines\n'
+ "where and how execution continues after the code block's "
+ 'execution has\n'
+ 'completed.\n'
+ '\n'
+ '\n'
+ 'Naming and binding\n'
+ '==================\n'
+ '\n'
+ '\n'
+ 'Binding of names\n'
+ '----------------\n'
+ '\n'
+ '*Names* refer to objects. Names are introduced by name '
+ 'binding\n'
+ 'operations.\n'
+ '\n'
+ 'The following constructs bind names: formal parameters to '
+ 'functions,\n'
+ '"import" statements, class and function definitions (these bind '
+ 'the\n'
+ 'class or function name in the defining block), and targets that '
+ 'are\n'
+ 'identifiers if occurring in an assignment, "for" loop header, '
+ 'or after\n'
+ '"as" in a "with" statement or "except" clause. The "import" '
+ 'statement\n'
+ 'of the form "from ... import *" binds all names defined in the\n'
+ 'imported module, except those beginning with an underscore. '
+ 'This form\n'
+ 'may only be used at the module level.\n'
+ '\n'
+ 'A target occurring in a "del" statement is also considered '
+ 'bound for\n'
+ 'this purpose (though the actual semantics are to unbind the '
+ 'name).\n'
+ '\n'
+ 'Each assignment or import statement occurs within a block '
+ 'defined by a\n'
+ 'class or function definition or at the module level (the '
+ 'top-level\n'
+ 'code block).\n'
+ '\n'
+ 'If a name is bound in a block, it is a local variable of that '
+ 'block,\n'
+ 'unless declared as "nonlocal" or "global". If a name is bound '
+ 'at the\n'
+ 'module level, it is a global variable. (The variables of the '
+ 'module\n'
+ 'code block are local and global.) If a variable is used in a '
+ 'code\n'
+ 'block but not defined there, it is a *free variable*.\n'
+ '\n'
+ 'Each occurrence of a name in the program text refers to the '
+ '*binding*\n'
+ 'of that name established by the following name resolution '
+ 'rules.\n'
+ '\n'
+ '\n'
+ 'Resolution of names\n'
+ '-------------------\n'
+ '\n'
+ 'A *scope* defines the visibility of a name within a block. If '
+ 'a local\n'
+ 'variable is defined in a block, its scope includes that block. '
+ 'If the\n'
+ 'definition occurs in a function block, the scope extends to any '
+ 'blocks\n'
+ 'contained within the defining one, unless a contained block '
+ 'introduces\n'
+ 'a different binding for the name.\n'
+ '\n'
+ 'When a name is used in a code block, it is resolved using the '
+ 'nearest\n'
+ 'enclosing scope. The set of all such scopes visible to a code '
+ 'block\n'
+ "is called the block's *environment*.\n"
+ '\n'
+ 'When a name is not found at all, a "NameError" exception is '
+ 'raised. If\n'
+ 'the current scope is a function scope, and the name refers to a '
+ 'local\n'
+ 'variable that has not yet been bound to a value at the point '
+ 'where the\n'
+ 'name is used, an "UnboundLocalError" exception is raised.\n'
+ '"UnboundLocalError" is a subclass of "NameError".\n'
+ '\n'
+ 'If a name binding operation occurs anywhere within a code '
+ 'block, all\n'
+ 'uses of the name within the block are treated as references to '
+ 'the\n'
+ 'current block. This can lead to errors when a name is used '
+ 'within a\n'
+ 'block before it is bound. This rule is subtle. Python lacks\n'
+ 'declarations and allows name binding operations to occur '
+ 'anywhere\n'
+ 'within a code block. The local variables of a code block can '
+ 'be\n'
+ 'determined by scanning the entire text of the block for name '
+ 'binding\n'
+ 'operations.\n'
+ '\n'
+ 'If the "global" statement occurs within a block, all uses of '
+ 'the name\n'
+ 'specified in the statement refer to the binding of that name in '
+ 'the\n'
+ 'top-level namespace. Names are resolved in the top-level '
+ 'namespace by\n'
+ 'searching the global namespace, i.e. the namespace of the '
+ 'module\n'
+ 'containing the code block, and the builtins namespace, the '
+ 'namespace\n'
+ 'of the module "builtins". The global namespace is searched '
+ 'first. If\n'
+ 'the name is not found there, the builtins namespace is '
+ 'searched. The\n'
+ '"global" statement must precede all uses of the name.\n'
+ '\n'
+ 'The "global" statement has the same scope as a name binding '
+ 'operation\n'
+ 'in the same block. If the nearest enclosing scope for a free '
+ 'variable\n'
+ 'contains a global statement, the free variable is treated as a '
+ 'global.\n'
+ '\n'
+ 'The "nonlocal" statement causes corresponding names to refer '
+ 'to\n'
+ 'previously bound variables in the nearest enclosing function '
+ 'scope.\n'
+ '"SyntaxError" is raised at compile time if the given name does '
+ 'not\n'
+ 'exist in any enclosing function scope.\n'
+ '\n'
+ 'The namespace for a module is automatically created the first '
+ 'time a\n'
+ 'module is imported. The main module for a script is always '
+ 'called\n'
+ '"__main__".\n'
+ '\n'
+ 'Class definition blocks and arguments to "exec()" and "eval()" '
+ 'are\n'
+ 'special in the context of name resolution. A class definition '
+ 'is an\n'
+ 'executable statement that may use and define names. These '
+ 'references\n'
+ 'follow the normal rules for name resolution with an exception '
+ 'that\n'
+ 'unbound local variables are looked up in the global namespace. '
+ 'The\n'
+ 'namespace of the class definition becomes the attribute '
+ 'dictionary of\n'
+ 'the class. The scope of names defined in a class block is '
+ 'limited to\n'
+ 'the class block; it does not extend to the code blocks of '
+ 'methods --\n'
+ 'this includes comprehensions and generator expressions since '
+ 'they are\n'
+ 'implemented using a function scope. This means that the '
+ 'following\n'
+ 'will fail:\n'
+ '\n'
+ ' class A:\n'
+ ' a = 42\n'
+ ' b = list(a + i for i in range(10))\n'
+ '\n'
+ '\n'
+ 'Builtins and restricted execution\n'
+ '---------------------------------\n'
+ '\n'
+ 'The builtins namespace associated with the execution of a code '
+ 'block\n'
+ 'is actually found by looking up the name "__builtins__" in its '
+ 'global\n'
+ 'namespace; this should be a dictionary or a module (in the '
+ 'latter case\n'
+ "the module's dictionary is used). By default, when in the "
+ '"__main__"\n'
+ 'module, "__builtins__" is the built-in module "builtins"; when '
+ 'in any\n'
+ 'other module, "__builtins__" is an alias for the dictionary of '
+ 'the\n'
+ '"builtins" module itself. "__builtins__" can be set to a '
+ 'user-created\n'
+ 'dictionary to create a weak form of restricted execution.\n'
+ '\n'
+ '**CPython implementation detail:** Users should not touch\n'
+ '"__builtins__"; it is strictly an implementation detail. '
+ 'Users\n'
+ 'wanting to override values in the builtins namespace should '
+ '"import"\n'
+ 'the "builtins" module and modify its attributes appropriately.\n'
+ '\n'
+ '\n'
+ 'Interaction with dynamic features\n'
+ '---------------------------------\n'
+ '\n'
+ 'Name resolution of free variables occurs at runtime, not at '
+ 'compile\n'
+ 'time. This means that the following code will print 42:\n'
+ '\n'
+ ' i = 10\n'
+ ' def f():\n'
+ ' print(i)\n'
+ ' i = 42\n'
+ ' f()\n'
+ '\n'
+ 'There are several cases where Python statements are illegal '
+ 'when used\n'
+ 'in conjunction with nested scopes that contain free variables.\n'
+ '\n'
+ 'If a variable is referenced in an enclosing scope, it is '
+ 'illegal to\n'
+ 'delete the name. An error will be reported at compile time.\n'
+ '\n'
+ 'The "eval()" and "exec()" functions do not have access to the '
+ 'full\n'
+ 'environment for resolving names. Names may be resolved in the '
+ 'local\n'
+ 'and global namespaces of the caller. Free variables are not '
+ 'resolved\n'
+ 'in the nearest enclosing namespace, but in the global '
+ 'namespace. [1]\n'
+ 'The "exec()" and "eval()" functions have optional arguments to\n'
+ 'override the global and local namespace. If only one namespace '
+ 'is\n'
+ 'specified, it is used for both.\n'
+ '\n'
+ '\n'
+ 'Exceptions\n'
+ '==========\n'
+ '\n'
+ 'Exceptions are a means of breaking out of the normal flow of '
+ 'control\n'
+ 'of a code block in order to handle errors or other exceptional\n'
+ 'conditions. An exception is *raised* at the point where the '
+ 'error is\n'
+ 'detected; it may be *handled* by the surrounding code block or '
+ 'by any\n'
+ 'code block that directly or indirectly invoked the code block '
+ 'where\n'
+ 'the error occurred.\n'
+ '\n'
+ 'The Python interpreter raises an exception when it detects a '
+ 'run-time\n'
+ 'error (such as division by zero). A Python program can also\n'
+ 'explicitly raise an exception with the "raise" statement. '
+ 'Exception\n'
+ 'handlers are specified with the "try" ... "except" statement. '
+ 'The\n'
+ '"finally" clause of such a statement can be used to specify '
+ 'cleanup\n'
+ 'code which does not handle the exception, but is executed '
+ 'whether an\n'
+ 'exception occurred or not in the preceding code.\n'
+ '\n'
+ 'Python uses the "termination" model of error handling: an '
+ 'exception\n'
+ 'handler can find out what happened and continue execution at an '
+ 'outer\n'
+ 'level, but it cannot repair the cause of the error and retry '
+ 'the\n'
+ 'failing operation (except by re-entering the offending piece of '
+ 'code\n'
+ 'from the top).\n'
+ '\n'
+ 'When an exception is not handled at all, the interpreter '
+ 'terminates\n'
+ 'execution of the program, or returns to its interactive main '
+ 'loop. In\n'
+ 'either case, it prints a stack backtrace, except when the '
+ 'exception is\n'
+ '"SystemExit".\n'
+ '\n'
+ 'Exceptions are identified by class instances. The "except" '
+ 'clause is\n'
+ 'selected depending on the class of the instance: it must '
+ 'reference the\n'
+ 'class of the instance or a base class thereof. The instance '
+ 'can be\n'
+ 'received by the handler and can carry additional information '
+ 'about the\n'
+ 'exceptional condition.\n'
+ '\n'
+ 'Note: Exception messages are not part of the Python API. '
+ 'Their\n'
+ ' contents may change from one version of Python to the next '
+ 'without\n'
+ ' warning and should not be relied on by code which will run '
+ 'under\n'
+ ' multiple versions of the interpreter.\n'
+ '\n'
+ 'See also the description of the "try" statement in section The '
+ 'try\n'
+ 'statement and "raise" statement in section The raise '
+ 'statement.\n'
+ '\n'
+ '-[ Footnotes ]-\n'
+ '\n'
+ '[1] This limitation occurs because the code that is executed '
+ 'by\n'
+ ' these operations is not available at the time the module '
+ 'is\n'
+ ' compiled.\n',
+ 'exprlists': '\n'
+ 'Expression lists\n'
+ '****************\n'
+ '\n'
+ ' expression_list ::= expression ( "," expression )* [","]\n'
+ ' starred_list ::= starred_item ( "," starred_item )* '
+ '[","]\n'
+ ' starred_expression ::= expression | ( starred_item "," )* '
+ '[starred_item]\n'
+ ' starred_item ::= expression | "*" or_expr\n'
+ '\n'
+ 'Except when part of a list or set display, an expression list\n'
+ 'containing at least one comma yields a tuple. The length of '
+ 'the tuple\n'
+ 'is the number of expressions in the list. The expressions are\n'
+ 'evaluated from left to right.\n'
+ '\n'
+ 'An asterisk "*" denotes *iterable unpacking*. Its operand must '
+ 'be an\n'
+ '*iterable*. The iterable is expanded into a sequence of items, '
+ 'which\n'
+ 'are included in the new tuple, list, or set, at the site of '
+ 'the\n'
+ 'unpacking.\n'
+ '\n'
+ 'New in version 3.5: Iterable unpacking in expression lists, '
+ 'originally\n'
+ 'proposed by **PEP 448**.\n'
+ '\n'
+ 'The 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\n'
+ "without a trailing comma doesn't create a tuple, but rather "
+ 'yields the\n'
+ 'value of that expression. (To create an empty tuple, use an '
+ 'empty pair\n'
+ 'of parentheses: "()".)\n',
+ 'floating': '\n'
+ 'Floating point literals\n'
+ '***********************\n'
+ '\n'
+ 'Floating point literals are described by the following lexical\n'
+ 'definitions:\n'
+ '\n'
+ ' floatnumber ::= pointfloat | exponentfloat\n'
+ ' pointfloat ::= [digitpart] fraction | digitpart "."\n'
+ ' exponentfloat ::= (digitpart | pointfloat) exponent\n'
+ ' digitpart ::= digit (["_"] digit)*\n'
+ ' fraction ::= "." digitpart\n'
+ ' exponent ::= ("e" | "E") ["+" | "-"] digitpart\n'
+ '\n'
+ 'Note that the integer and exponent parts are always interpreted '
+ 'using\n'
+ 'radix 10. For example, "077e010" is legal, and denotes the same '
+ 'number\n'
+ 'as "77e10". The allowed range of floating point literals is\n'
+ 'implementation-dependent. As in integer literals, underscores '
+ 'are\n'
+ 'supported for digit grouping.\n'
+ '\n'
+ 'Some examples of floating point literals:\n'
+ '\n'
+ ' 3.14 10. .001 1e100 3.14e-10 0e0 '
+ '3.14_15_93\n'
+ '\n'
+ 'Note that numeric literals do not include a sign; a phrase like '
+ '"-1"\n'
+ 'is actually an expression composed of the unary operator "-" and '
+ 'the\n'
+ 'literal "1".\n'
+ '\n'
+ 'Changed in version 3.6: Underscores are now allowed for '
+ 'grouping\n'
+ 'purposes in literals.\n',
+ 'for': '\n'
+ 'The "for" statement\n'
+ '*******************\n'
+ '\n'
+ 'The "for" statement is used to iterate over the elements of a '
+ 'sequence\n'
+ '(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'
+ '\n'
+ 'The expression list is evaluated once; it should yield an iterable\n'
+ 'object. An iterator is created for the result of the\n'
+ '"expression_list". The suite is then executed once for each item\n'
+ 'provided by the iterator, in the order returned by the iterator. '
+ 'Each\n'
+ 'item in turn is assigned to the target list using the standard rules\n'
+ 'for assignments (see Assignment statements), and then the suite is\n'
+ 'executed. When the items are exhausted (which is immediately when '
+ 'the\n'
+ 'sequence is empty or an iterator raises a "StopIteration" '
+ 'exception),\n'
+ 'the suite in the "else" clause, if present, is executed, and the '
+ 'loop\n'
+ 'terminates.\n'
+ '\n'
+ 'A "break" statement executed in the first suite terminates the loop\n'
+ 'without executing the "else" clause\'s suite. A "continue" '
+ 'statement\n'
+ 'executed in the first suite skips the rest of the suite and '
+ 'continues\n'
+ 'with the next item, or with the "else" clause if there is no next\n'
+ 'item.\n'
+ '\n'
+ 'The for-loop makes assignments to the variables(s) in the target '
+ 'list.\n'
+ 'This overwrites all previous assignments to those variables '
+ 'including\n'
+ 'those made in the suite of the for-loop:\n'
+ '\n'
+ ' for i in range(10):\n'
+ ' print(i)\n'
+ ' i = 5 # this will not affect the for-loop\n'
+ ' # because i will be overwritten with the '
+ 'next\n'
+ ' # index in the range\n'
+ '\n'
+ 'Names in the target list are not deleted when the loop is finished,\n'
+ 'but if the sequence is empty, they will not have been assigned to at\n'
+ 'all by the loop. Hint: the built-in function "range()" returns an\n'
+ 'iterator of integers suitable to emulate the effect of Pascal\'s "for '
+ 'i\n'
+ ':= a to b do"; e.g., "list(range(3))" returns the list "[0, 1, 2]".\n'
+ '\n'
+ 'Note: There is a subtlety when the sequence is being modified by the\n'
+ ' loop (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': '\n'
+ 'Format String Syntax\n'
+ '********************\n'
+ '\n'
+ 'The "str.format()" method and the "Formatter" class share '
+ 'the same\n'
+ 'syntax for format strings (although in the case of '
+ '"Formatter",\n'
+ 'subclasses can define their own format string syntax). The '
+ 'syntax is\n'
+ 'related to that of formatted string literals, but there '
+ 'are\n'
+ 'differences.\n'
+ '\n'
+ 'Format strings contain "replacement fields" surrounded by '
+ 'curly braces\n'
+ '"{}". Anything that is not contained in braces is '
+ 'considered literal\n'
+ 'text, which is copied unchanged to the output. If you need '
+ 'to include\n'
+ 'a brace character in the literal text, it can be escaped by '
+ 'doubling:\n'
+ '"{{" and "}}".\n'
+ '\n'
+ 'The grammar for a replacement field is as follows:\n'
+ '\n'
+ ' replacement_field ::= "{" [field_name] ["!" '
+ 'conversion] [":" format_spec] "}"\n'
+ ' field_name ::= arg_name ("." attribute_name | '
+ '"[" element_index "]")*\n'
+ ' arg_name ::= [identifier | integer]\n'
+ ' attribute_name ::= identifier\n'
+ ' element_index ::= integer | index_string\n'
+ ' index_string ::= <any source character except '
+ '"]"> +\n'
+ ' conversion ::= "r" | "s" | "a"\n'
+ ' format_spec ::= <described in the next '
+ 'section>\n'
+ '\n'
+ 'In less formal terms, the replacement field can start with '
+ 'a\n'
+ '*field_name* that specifies the object whose value is to be '
+ 'formatted\n'
+ 'and inserted into the output instead of the replacement '
+ 'field. The\n'
+ '*field_name* is optionally followed by a *conversion* '
+ 'field, which is\n'
+ 'preceded by an exclamation point "\'!\'", and a '
+ '*format_spec*, which is\n'
+ 'preceded by a colon "\':\'". These specify a non-default '
+ 'format for the\n'
+ 'replacement value.\n'
+ '\n'
+ 'See also the Format Specification Mini-Language section.\n'
+ '\n'
+ 'The *field_name* itself begins with an *arg_name* that is '
+ 'either a\n'
+ "number or a keyword. If it's a number, it refers to a "
+ 'positional\n'
+ "argument, and if it's a keyword, it refers to a named "
+ 'keyword\n'
+ 'argument. If the numerical arg_names in a format string '
+ 'are 0, 1, 2,\n'
+ '... in sequence, they can all be omitted (not just some) '
+ 'and the\n'
+ 'numbers 0, 1, 2, ... will be automatically inserted in that '
+ 'order.\n'
+ 'Because *arg_name* is not quote-delimited, it is not '
+ 'possible to\n'
+ 'specify arbitrary dictionary keys (e.g., the strings '
+ '"\'10\'" or\n'
+ '"\':-]\'") within a format string. The *arg_name* can be '
+ 'followed by any\n'
+ 'number of index or attribute expressions. An expression of '
+ 'the form\n'
+ '"\'.name\'" selects the named attribute using "getattr()", '
+ 'while an\n'
+ 'expression of the form "\'[index]\'" does an index lookup '
+ 'using\n'
+ '"__getitem__()".\n'
+ '\n'
+ 'Changed in version 3.1: The positional argument specifiers '
+ 'can be\n'
+ 'omitted, so "\'{} {}\'" is equivalent to "\'{0} {1}\'".\n'
+ '\n'
+ 'Some simple format string examples:\n'
+ '\n'
+ ' "First, thou shalt count to {0}" # References first '
+ 'positional argument\n'
+ ' "Bring me a {}" # Implicitly '
+ 'references the first positional argument\n'
+ ' "From {} to {}" # Same as "From {0} to '
+ '{1}"\n'
+ ' "My quest is {name}" # References keyword '
+ "argument 'name'\n"
+ ' "Weight in tons {0.weight}" # \'weight\' attribute '
+ 'of first positional arg\n'
+ ' "Units destroyed: {players[0]}" # First element of '
+ "keyword argument 'players'.\n"
+ '\n'
+ 'The *conversion* field causes a type coercion before '
+ 'formatting.\n'
+ 'Normally, the job of formatting a value is done by the '
+ '"__format__()"\n'
+ 'method of the value itself. However, in some cases it is '
+ 'desirable to\n'
+ 'force a type to be formatted as a string, overriding its '
+ 'own\n'
+ 'definition of formatting. By converting the value to a '
+ 'string before\n'
+ 'calling "__format__()", the normal formatting logic is '
+ 'bypassed.\n'
+ '\n'
+ 'Three conversion flags are currently supported: "\'!s\'" '
+ 'which calls\n'
+ '"str()" on the value, "\'!r\'" which calls "repr()" and '
+ '"\'!a\'" which\n'
+ 'calls "ascii()".\n'
+ '\n'
+ 'Some examples:\n'
+ '\n'
+ ' "Harold\'s a clever {0!s}" # Calls str() on the '
+ 'argument first\n'
+ ' "Bring out the holy {name!r}" # Calls repr() on the '
+ 'argument first\n'
+ ' "More {!a}" # Calls ascii() on the '
+ 'argument first\n'
+ '\n'
+ 'The *format_spec* field contains a specification of how the '
+ 'value\n'
+ 'should be presented, including such details as field width, '
+ 'alignment,\n'
+ 'padding, decimal precision and so on. Each value type can '
+ 'define its\n'
+ 'own "formatting mini-language" or interpretation of the '
+ '*format_spec*.\n'
+ '\n'
+ 'Most built-in types support a common formatting '
+ 'mini-language, which\n'
+ 'is described in the next section.\n'
+ '\n'
+ 'A *format_spec* field can also include nested replacement '
+ 'fields\n'
+ 'within it. These nested replacement fields may contain a '
+ 'field name,\n'
+ 'conversion flag and format specification, but deeper '
+ 'nesting is not\n'
+ 'allowed. The replacement fields within the format_spec '
+ 'are\n'
+ 'substituted before the *format_spec* string is interpreted. '
+ 'This\n'
+ 'allows the formatting of a value to be dynamically '
+ 'specified.\n'
+ '\n'
+ 'See the Format examples section for some examples.\n'
+ '\n'
+ '\n'
+ 'Format Specification Mini-Language\n'
+ '==================================\n'
+ '\n'
+ '"Format specifications" are used within replacement fields '
+ 'contained\n'
+ 'within a format string to define how individual values are '
+ 'presented\n'
+ '(see Format String Syntax and Formatted string literals). '
+ 'They can\n'
+ 'also be passed directly to the built-in "format()" '
+ 'function. Each\n'
+ 'formattable type may define how the format specification is '
+ 'to be\n'
+ 'interpreted.\n'
+ '\n'
+ 'Most built-in types implement the following options for '
+ 'format\n'
+ 'specifications, although some of the formatting options are '
+ 'only\n'
+ 'supported by the numeric types.\n'
+ '\n'
+ 'A general convention is that an empty format string ("""") '
+ 'produces\n'
+ 'the same result as if you had called "str()" on the value. '
+ 'A non-empty\n'
+ 'format string typically modifies the result.\n'
+ '\n'
+ 'The general form of a *standard format specifier* is:\n'
+ '\n'
+ ' format_spec ::= '
+ '[[fill]align][sign][#][0][width][grouping_option][.precision][type]\n'
+ ' fill ::= <any character>\n'
+ ' align ::= "<" | ">" | "=" | "^"\n'
+ ' sign ::= "+" | "-" | " "\n'
+ ' width ::= integer\n'
+ ' grouping_option ::= "_" | ","\n'
+ ' precision ::= integer\n'
+ ' type ::= "b" | "c" | "d" | "e" | "E" | "f" | '
+ '"F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n'
+ '\n'
+ 'If a valid *align* value is specified, it can be preceded '
+ 'by a *fill*\n'
+ 'character that can be any character and defaults to a space '
+ 'if\n'
+ 'omitted. It is not possible to use a literal curly brace '
+ '(""{"" or\n'
+ '""}"") as the *fill* character in a formatted string '
+ 'literal or when\n'
+ 'using the "str.format()" method. However, it is possible '
+ 'to insert a\n'
+ 'curly brace with a nested replacement field. This '
+ "limitation doesn't\n"
+ 'affect the "format()" function.\n'
+ '\n'
+ 'The meaning of the various alignment options is as '
+ 'follows:\n'
+ '\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | Option | '
+ 'Meaning '
+ '|\n'
+ ' '
+ '+===========+============================================================+\n'
+ ' | "\'<\'" | Forces the field to be left-aligned '
+ 'within the available |\n'
+ ' | | space (this is the default for most '
+ 'objects). |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'>\'" | Forces the field to be right-aligned '
+ 'within the available |\n'
+ ' | | space (this is the default for '
+ 'numbers). |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'=\'" | Forces the padding to be placed after '
+ 'the sign (if any) |\n'
+ ' | | but before the digits. This is used for '
+ 'printing fields |\n'
+ " | | in the form '+000000120'. This alignment "
+ 'option is only |\n'
+ ' | | valid for numeric types. It becomes the '
+ "default when '0' |\n"
+ ' | | immediately precedes the field '
+ 'width. |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'^\'" | Forces the field to be centered within '
+ 'the available |\n'
+ ' | | '
+ 'space. '
+ '|\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ '\n'
+ 'Note that unless a minimum field width is defined, the '
+ 'field width\n'
+ 'will always be the same size as the data to fill it, so '
+ 'that the\n'
+ 'alignment option has no meaning in this case.\n'
+ '\n'
+ 'The *sign* option is only valid for number types, and can '
+ 'be one of\n'
+ 'the 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'
+ 'The "\'#\'" option causes the "alternate form" to be used '
+ 'for the\n'
+ 'conversion. The alternate form is defined differently for '
+ 'different\n'
+ 'types. This option is only valid for integer, float, '
+ 'complex and\n'
+ 'Decimal types. For integers, when binary, octal, or '
+ 'hexadecimal output\n'
+ 'is used, this option adds the prefix respective "\'0b\'", '
+ '"\'0o\'", or\n'
+ '"\'0x\'" to the output value. For floats, complex and '
+ 'Decimal the\n'
+ 'alternate form causes the result of the conversion to '
+ 'always contain a\n'
+ 'decimal-point character, even if no digits follow it. '
+ 'Normally, a\n'
+ 'decimal-point character appears in the result of these '
+ 'conversions\n'
+ 'only if a digit follows it. In addition, for "\'g\'" and '
+ '"\'G\'"\n'
+ 'conversions, trailing zeros are not removed from the '
+ 'result.\n'
+ '\n'
+ 'The "\',\'" option signals the use of a comma for a '
+ 'thousands separator.\n'
+ 'For a locale aware separator, use the "\'n\'" integer '
+ 'presentation type\n'
+ 'instead.\n'
+ '\n'
+ 'Changed in version 3.1: Added the "\',\'" option (see also '
+ '**PEP 378**).\n'
+ '\n'
+ 'The "\'_\'" option signals the use of an underscore for a '
+ 'thousands\n'
+ 'separator for floating point presentation types and for '
+ 'integer\n'
+ 'presentation type "\'d\'". For integer presentation types '
+ '"\'b\'", "\'o\'",\n'
+ '"\'x\'", and "\'X\'", underscores will be inserted every 4 '
+ 'digits. For\n'
+ 'other presentation types, specifying this option is an '
+ 'error.\n'
+ '\n'
+ 'Changed in version 3.6: Added the "\'_\'" option (see also '
+ '**PEP 515**).\n'
+ '\n'
+ '*width* is a decimal integer defining the minimum field '
+ 'width. If not\n'
+ 'specified, then the field width will be determined by the '
+ 'content.\n'
+ '\n'
+ 'When no explicit alignment is given, preceding the *width* '
+ 'field by a\n'
+ 'zero ("\'0\'") character enables sign-aware zero-padding '
+ 'for numeric\n'
+ 'types. This is equivalent to a *fill* character of "\'0\'" '
+ 'with an\n'
+ '*alignment* type of "\'=\'".\n'
+ '\n'
+ 'The *precision* is a decimal number indicating how many '
+ 'digits should\n'
+ 'be displayed after the decimal point for a floating point '
+ 'value\n'
+ 'formatted with "\'f\'" and "\'F\'", or before and after the '
+ 'decimal point\n'
+ 'for a floating point value formatted with "\'g\'" or '
+ '"\'G\'". For non-\n'
+ 'number types the field indicates the maximum field size - '
+ 'in other\n'
+ 'words, how many characters will be used from the field '
+ 'content. The\n'
+ '*precision* is not allowed for integer values.\n'
+ '\n'
+ 'Finally, the *type* determines how the data should be '
+ 'presented.\n'
+ '\n'
+ 'The available string presentation types are:\n'
+ '\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | Type | '
+ 'Meaning '
+ '|\n'
+ ' '
+ '+===========+============================================================+\n'
+ ' | "\'s\'" | String format. This is the default type '
+ 'for strings and |\n'
+ ' | | may be '
+ 'omitted. |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | None | The same as '
+ '"\'s\'". |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ '\n'
+ 'The 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 the |\n'
+ ' | | current locale setting to insert the '
+ 'appropriate number |\n'
+ ' | | separator '
+ 'characters. |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | None | The same as '
+ '"\'d\'". |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ '\n'
+ 'In addition to the above presentation types, integers can '
+ 'be formatted\n'
+ 'with the floating point presentation types listed below '
+ '(except "\'n\'"\n'
+ 'and None). When doing so, "float()" is used to convert the '
+ 'integer to\n'
+ 'a floating point number before formatting.\n'
+ '\n'
+ 'The available presentation types for floating point and '
+ 'decimal values\n'
+ 'are:\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'
+ ' | | The default precision is '
+ '"6". |\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'
+ ' | | The default precision is '
+ '"6". |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'F\'" | Fixed point. Same as "\'f\'", but '
+ 'converts "nan" to "NAN" |\n'
+ ' | | and "inf" to '
+ '"INF". |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'g\'" | General format. For a given precision '
+ '"p >= 1", this |\n'
+ ' | | rounds the number to "p" significant '
+ 'digits and then |\n'
+ ' | | formats the result in either fixed-point '
+ 'format or in |\n'
+ ' | | scientific notation, depending on its '
+ 'magnitude. The |\n'
+ ' | | precise rules are as follows: suppose that '
+ 'the result |\n'
+ ' | | formatted with presentation type "\'e\'" '
+ 'and precision "p-1" |\n'
+ ' | | would have exponent "exp". Then if "-4 <= '
+ 'exp < p", the |\n'
+ ' | | number is formatted with presentation type '
+ '"\'f\'" and |\n'
+ ' | | precision "p-1-exp". Otherwise, the '
+ 'number is formatted |\n'
+ ' | | with presentation type "\'e\'" and '
+ 'precision "p-1". In both |\n'
+ ' | | cases insignificant trailing zeros are '
+ 'removed from the |\n'
+ ' | | significand, and the decimal point is also '
+ 'removed if |\n'
+ ' | | there are no remaining digits following '
+ 'it. Positive and |\n'
+ ' | | negative infinity, positive and negative '
+ 'zero, and nans, |\n'
+ ' | | are formatted as "inf", "-inf", "0", "-0" '
+ 'and "nan" |\n'
+ ' | | respectively, regardless of the '
+ 'precision. A precision of |\n'
+ ' | | "0" is treated as equivalent to a '
+ 'precision of "1". The |\n'
+ ' | | default precision is '
+ '"6". |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'G\'" | General format. Same as "\'g\'" except '
+ 'switches to "\'E\'" if |\n'
+ ' | | the number gets too large. The '
+ 'representations of infinity |\n'
+ ' | | and NaN are uppercased, '
+ 'too. |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'n\'" | Number. This is the same as "\'g\'", '
+ 'except that it uses the |\n'
+ ' | | current locale setting to insert the '
+ 'appropriate number |\n'
+ ' | | separator '
+ 'characters. |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | "\'%\'" | Percentage. Multiplies the number by 100 '
+ 'and displays in |\n'
+ ' | | fixed ("\'f\'") format, followed by a '
+ 'percent sign. |\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ ' | None | Similar to "\'g\'", except that '
+ 'fixed-point notation, when |\n'
+ ' | | used, has at least one digit past the '
+ 'decimal point. The |\n'
+ ' | | default precision is as high as needed to '
+ 'represent the |\n'
+ ' | | particular value. The overall effect is to '
+ 'match the |\n'
+ ' | | output of "str()" as altered by the other '
+ 'format |\n'
+ ' | | '
+ 'modifiers. '
+ '|\n'
+ ' '
+ '+-----------+------------------------------------------------------------+\n'
+ '\n'
+ '\n'
+ 'Format examples\n'
+ '===============\n'
+ '\n'
+ 'This section contains examples of the "str.format()" syntax '
+ 'and\n'
+ 'comparison with the old "%"-formatting.\n'
+ '\n'
+ 'In most of the cases the syntax is similar to the old '
+ '"%"-formatting,\n'
+ 'with the addition of the "{}" and with ":" used instead of '
+ '"%". For\n'
+ 'example, "\'%03.2f\'" can be translated to "\'{:03.2f}\'".\n'
+ '\n'
+ 'The new format syntax also supports new and different '
+ 'options, shown\n'
+ 'in the follow examples.\n'
+ '\n'
+ 'Accessing arguments by position:\n'
+ '\n'
+ " >>> '{0}, {1}, {2}'.format('a', 'b', 'c')\n"
+ " 'a, b, c'\n"
+ " >>> '{}, {}, {}'.format('a', 'b', 'c') # 3.1+ only\n"
+ " 'a, b, c'\n"
+ " >>> '{2}, {1}, {0}'.format('a', 'b', 'c')\n"
+ " 'c, b, a'\n"
+ " >>> '{2}, {1}, {0}'.format(*'abc') # unpacking "
+ 'argument sequence\n'
+ " 'c, b, a'\n"
+ " >>> '{0}{1}{0}'.format('abra', 'cad') # arguments' "
+ 'indices can be repeated\n'
+ " 'abracadabra'\n"
+ '\n'
+ 'Accessing arguments by name:\n'
+ '\n'
+ " >>> 'Coordinates: {latitude}, "
+ "{longitude}'.format(latitude='37.24N', "
+ "longitude='-115.81W')\n"
+ " 'Coordinates: 37.24N, -115.81W'\n"
+ " >>> coord = {'latitude': '37.24N', 'longitude': "
+ "'-115.81W'}\n"
+ " >>> 'Coordinates: {latitude}, "
+ "{longitude}'.format(**coord)\n"
+ " 'Coordinates: 37.24N, -115.81W'\n"
+ '\n'
+ "Accessing arguments' attributes:\n"
+ '\n'
+ ' >>> c = 3-5j\n'
+ " >>> ('The complex number {0} is formed from the real "
+ "part {0.real} '\n"
+ " ... 'and the imaginary part {0.imag}.').format(c)\n"
+ " 'The complex number (3-5j) is formed from the real part "
+ "3.0 and the imaginary part -5.0.'\n"
+ ' >>> class Point:\n'
+ ' ... def __init__(self, x, y):\n'
+ ' ... self.x, self.y = x, y\n'
+ ' ... def __str__(self):\n'
+ " ... return 'Point({self.x}, "
+ "{self.y})'.format(self=self)\n"
+ ' ...\n'
+ ' >>> str(Point(4, 2))\n'
+ " 'Point(4, 2)'\n"
+ '\n'
+ "Accessing arguments' items:\n"
+ '\n'
+ ' >>> coord = (3, 5)\n'
+ " >>> 'X: {0[0]}; Y: {0[1]}'.format(coord)\n"
+ " 'X: 3; Y: 5'\n"
+ '\n'
+ 'Replacing "%s" and "%r":\n'
+ '\n'
+ ' >>> "repr() shows quotes: {!r}; str() doesn\'t: '
+ '{!s}".format(\'test1\', \'test2\')\n'
+ ' "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n'
+ '\n'
+ 'Aligning the text and specifying a width:\n'
+ '\n'
+ " >>> '{:<30}'.format('left aligned')\n"
+ " 'left aligned '\n"
+ " >>> '{:>30}'.format('right aligned')\n"
+ " ' right aligned'\n"
+ " >>> '{:^30}'.format('centered')\n"
+ " ' centered '\n"
+ " >>> '{:*^30}'.format('centered') # use '*' as a fill "
+ 'char\n'
+ " '***********centered***********'\n"
+ '\n'
+ 'Replacing "%+f", "%-f", and "% f" and specifying a sign:\n'
+ '\n'
+ " >>> '{:+f}; {:+f}'.format(3.14, -3.14) # show it "
+ 'always\n'
+ " '+3.140000; -3.140000'\n"
+ " >>> '{: f}; {: f}'.format(3.14, -3.14) # show a space "
+ 'for positive numbers\n'
+ " ' 3.140000; -3.140000'\n"
+ " >>> '{:-f}; {:-f}'.format(3.14, -3.14) # show only the "
+ "minus -- same as '{:f}; {:f}'\n"
+ " '3.140000; -3.140000'\n"
+ '\n'
+ 'Replacing "%x" and "%o" and converting the value to '
+ 'different bases:\n'
+ '\n'
+ ' >>> # format also supports binary numbers\n'
+ ' >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: '
+ '{0:b}".format(42)\n'
+ " 'int: 42; hex: 2a; oct: 52; bin: 101010'\n"
+ ' >>> # with 0x, 0o, or 0b as prefix:\n'
+ ' >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: '
+ '{0:#b}".format(42)\n'
+ " 'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010'\n"
+ '\n'
+ 'Using the comma as a thousands separator:\n'
+ '\n'
+ " >>> '{:,}'.format(1234567890)\n"
+ " '1,234,567,890'\n"
+ '\n'
+ 'Expressing a percentage:\n'
+ '\n'
+ ' >>> points = 19\n'
+ ' >>> total = 22\n'
+ " >>> 'Correct answers: {:.2%}'.format(points/total)\n"
+ " 'Correct answers: 86.36%'\n"
+ '\n'
+ 'Using type-specific formatting:\n'
+ '\n'
+ ' >>> import datetime\n'
+ ' >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n'
+ " >>> '{:%Y-%m-%d %H:%M:%S}'.format(d)\n"
+ " '2010-07-04 12:15:58'\n"
+ '\n'
+ 'Nesting arguments and more complex examples:\n'
+ '\n'
+ " >>> for align, text in zip('<^>', ['left', 'center', "
+ "'right']):\n"
+ " ... '{0:{fill}{align}16}'.format(text, fill=align, "
+ 'align=align)\n'
+ ' ...\n'
+ " 'left<<<<<<<<<<<<'\n"
+ " '^^^^^center^^^^^'\n"
+ " '>>>>>>>>>>>right'\n"
+ ' >>>\n'
+ ' >>> octets = [192, 168, 0, 1]\n'
+ " >>> '{:02X}{:02X}{:02X}{:02X}'.format(*octets)\n"
+ " 'C0A80001'\n"
+ ' >>> int(_, 16)\n'
+ ' 3232235521\n'
+ ' >>>\n'
+ ' >>> width = 5\n'
+ ' >>> for num in range(5,12): #doctest: '
+ '+NORMALIZE_WHITESPACE\n'
+ " ... for base in 'dXob':\n"
+ " ... print('{0:{width}{base}}'.format(num, "
+ "base=base, width=width), end=' ')\n"
+ ' ... print()\n'
+ ' ...\n'
+ ' 5 5 5 101\n'
+ ' 6 6 6 110\n'
+ ' 7 7 7 111\n'
+ ' 8 8 10 1000\n'
+ ' 9 9 11 1001\n'
+ ' 10 A 12 1010\n'
+ ' 11 B 13 1011\n',
+ 'function': '\n'
+ 'Function definitions\n'
+ '********************\n'
+ '\n'
+ 'A function definition defines a user-defined function object '
+ '(see\n'
+ 'section 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 ("," defparameter)* '
+ '["," [parameter_list_starargs]]\n'
+ ' | parameter_list_starargs\n'
+ ' parameter_list_starargs ::= "*" [parameter] ("," '
+ 'defparameter)* ["," ["**" parameter [","]]]\n'
+ ' | "**" parameter [","]\n'
+ ' parameter ::= identifier [":" expression]\n'
+ ' defparameter ::= parameter ["=" expression]\n'
+ ' funcname ::= identifier\n'
+ '\n'
+ 'A function definition is an executable statement. Its execution '
+ 'binds\n'
+ 'the function name in the current local namespace to a function '
+ 'object\n'
+ '(a wrapper around the executable code for the function). This\n'
+ 'function object contains a reference to the current global '
+ 'namespace\n'
+ 'as the global namespace to be used when the function is called.\n'
+ '\n'
+ 'The function definition does not execute the function body; this '
+ 'gets\n'
+ 'executed only when the function is called. [3]\n'
+ '\n'
+ 'A function definition may be wrapped by one or more *decorator*\n'
+ 'expressions. Decorator expressions are evaluated when the '
+ 'function is\n'
+ 'defined, in the scope that contains the function definition. '
+ 'The\n'
+ 'result must be a callable, which is invoked with the function '
+ 'object\n'
+ 'as the only argument. The returned value is bound to the '
+ 'function name\n'
+ 'instead of the function object. Multiple decorators are applied '
+ 'in\n'
+ 'nested fashion. For example, the following code\n'
+ '\n'
+ ' @f1(arg)\n'
+ ' @f2\n'
+ ' def func(): pass\n'
+ '\n'
+ 'is roughly equivalent to\n'
+ '\n'
+ ' def func(): pass\n'
+ ' func = f1(arg)(f2(func))\n'
+ '\n'
+ 'except that the original function is not temporarily bound to '
+ 'the name\n'
+ '"func".\n'
+ '\n'
+ 'When one or more *parameters* have the form *parameter* "="\n'
+ '*expression*, the function is said to have "default parameter '
+ 'values."\n'
+ 'For a parameter with a default value, the corresponding '
+ '*argument* may\n'
+ "be omitted from a call, in which case the parameter's default "
+ 'value is\n'
+ 'substituted. If a parameter has a default value, all following\n'
+ 'parameters up until the ""*"" must also have a default value --- '
+ 'this\n'
+ 'is a syntactic restriction that is not expressed by the '
+ 'grammar.\n'
+ '\n'
+ '**Default parameter values are evaluated from left to right when '
+ 'the\n'
+ 'function definition is executed.** This means that the '
+ 'expression is\n'
+ 'evaluated once, when the function is defined, and that the same '
+ '"pre-\n'
+ 'computed" value is used for each call. This is especially '
+ 'important\n'
+ 'to understand when a default parameter is a mutable object, such '
+ 'as a\n'
+ 'list or a dictionary: if the function modifies the object (e.g. '
+ 'by\n'
+ 'appending an item to a list), the default value is in effect '
+ 'modified.\n'
+ 'This is generally not what was intended. A way around this is '
+ 'to use\n'
+ '"None" as the default, and explicitly test for it in the body of '
+ 'the\n'
+ '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'
+ '\n'
+ 'Function call semantics are described in more detail in section '
+ 'Calls.\n'
+ 'A function call always assigns values to all parameters '
+ 'mentioned in\n'
+ 'the parameter list, either from position arguments, from '
+ 'keyword\n'
+ 'arguments, or from default values. If the form ""*identifier"" '
+ 'is\n'
+ 'present, it is initialized to a tuple receiving any excess '
+ 'positional\n'
+ 'parameters, defaulting to the empty tuple. If the form\n'
+ '""**identifier"" is present, it is initialized to a new ordered\n'
+ 'mapping receiving any excess keyword arguments, defaulting to a '
+ 'new\n'
+ 'empty mapping of the same type. Parameters after ""*"" or\n'
+ '""*identifier"" are keyword-only parameters and may only be '
+ 'passed\n'
+ 'used keyword arguments.\n'
+ '\n'
+ 'Parameters may have annotations of the form "": expression"" '
+ 'following\n'
+ 'the parameter name. Any parameter may have an annotation even '
+ 'those\n'
+ 'of the form "*identifier" or "**identifier". Functions may '
+ 'have\n'
+ '"return" annotation of the form ""-> expression"" after the '
+ 'parameter\n'
+ 'list. These annotations can be any valid Python expression and '
+ 'are\n'
+ 'evaluated when the function definition is executed. Annotations '
+ 'may\n'
+ 'be evaluated in a different order than they appear in the source '
+ 'code.\n'
+ 'The presence of annotations does not change the semantics of a\n'
+ 'function. The annotation values are available as values of a\n'
+ "dictionary keyed by the parameters' names in the "
+ '"__annotations__"\n'
+ 'attribute of the function object.\n'
+ '\n'
+ 'It is also possible to create anonymous functions (functions not '
+ 'bound\n'
+ 'to a name), for immediate use in expressions. This uses lambda\n'
+ 'expressions, described in section Lambdas. Note that the '
+ 'lambda\n'
+ 'expression is merely a shorthand for a simplified function '
+ 'definition;\n'
+ 'a function defined in a ""def"" statement can be passed around '
+ 'or\n'
+ 'assigned to another name just like a function defined by a '
+ 'lambda\n'
+ 'expression. The ""def"" form is actually more powerful since '
+ 'it\n'
+ 'allows the execution of multiple statements and annotations.\n'
+ '\n'
+ "**Programmer's note:** Functions are first-class objects. A "
+ '""def""\n'
+ 'statement executed inside a function definition defines a local\n'
+ 'function that can be returned or passed around. Free variables '
+ 'used\n'
+ 'in the nested function can access the local variables of the '
+ 'function\n'
+ 'containing the def. See section Naming and binding for '
+ 'details.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 3107** - Function Annotations\n'
+ ' The original specification for function annotations.\n',
+ 'global': '\n'
+ 'The "global" statement\n'
+ '**********************\n'
+ '\n'
+ ' global_stmt ::= "global" identifier ("," identifier)*\n'
+ '\n'
+ 'The "global" statement is a declaration which holds for the '
+ 'entire\n'
+ 'current code block. It means that the listed identifiers are to '
+ 'be\n'
+ 'interpreted as globals. It would be impossible to assign to a '
+ 'global\n'
+ 'variable without "global", although free variables may refer to\n'
+ 'globals without being declared global.\n'
+ '\n'
+ 'Names listed in a "global" statement must not be used in the same '
+ 'code\n'
+ 'block textually preceding that "global" statement.\n'
+ '\n'
+ 'Names listed in a "global" statement must not be defined as '
+ 'formal\n'
+ 'parameters or in a "for" loop control target, "class" definition,\n'
+ 'function definition, "import" statement, or variable annotation.\n'
+ '\n'
+ '**CPython implementation detail:** The current implementation does '
+ 'not\n'
+ 'enforce some of these restriction, but programs should not abuse '
+ 'this\n'
+ 'freedom, as future implementations may enforce them or silently '
+ 'change\n'
+ 'the meaning of the program.\n'
+ '\n'
+ '**Programmer\'s note:** the "global" is a directive to the '
+ 'parser. It\n'
+ 'applies only to code parsed at the same time as the "global"\n'
+ 'statement. In particular, a "global" statement contained in a '
+ 'string\n'
+ 'or code object supplied to the built-in "exec()" function does '
+ 'not\n'
+ 'affect the code block *containing* the function call, and code\n'
+ 'contained in such a string is unaffected by "global" statements in '
+ 'the\n'
+ 'code containing the function call. The same applies to the '
+ '"eval()"\n'
+ 'and "compile()" functions.\n',
+ 'id-classes': '\n'
+ 'Reserved classes of identifiers\n'
+ '*******************************\n'
+ '\n'
+ 'Certain classes of identifiers (besides keywords) have '
+ 'special\n'
+ 'meanings. These classes are identified by the patterns of '
+ 'leading and\n'
+ 'trailing 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 the\n'
+ ' last evaluation; it is stored in the "builtins" module. '
+ 'When not\n'
+ ' in interactive mode, "_" has no special meaning and is not '
+ 'defined.\n'
+ ' See section The import statement.\n'
+ '\n'
+ ' Note: The name "_" is often used in conjunction with\n'
+ ' internationalization; refer to the documentation for the\n'
+ ' "gettext" module for more information on this '
+ 'convention.\n'
+ '\n'
+ '"__*__"\n'
+ ' System-defined names. These names are defined by the '
+ 'interpreter\n'
+ ' and its implementation (including the standard library). '
+ 'Current\n'
+ ' system names are discussed in the Special method names '
+ 'section and\n'
+ ' elsewhere. More will likely be defined in future versions '
+ 'of\n'
+ ' Python. *Any* use of "__*__" names, in any context, that '
+ 'does not\n'
+ ' follow explicitly documented use, is subject to breakage '
+ 'without\n'
+ ' warning.\n'
+ '\n'
+ '"__*"\n'
+ ' Class-private names. Names in this category, when used '
+ 'within the\n'
+ ' context of a class definition, are re-written to use a '
+ 'mangled form\n'
+ ' to help avoid name clashes between "private" attributes of '
+ 'base and\n'
+ ' derived classes. See section Identifiers (Names).\n',
+ 'identifiers': '\n'
+ 'Identifiers and keywords\n'
+ '************************\n'
+ '\n'
+ 'Identifiers (also referred to as *names*) are described by '
+ 'the\n'
+ 'following lexical definitions.\n'
+ '\n'
+ 'The syntax of identifiers in Python is based on the Unicode '
+ 'standard\n'
+ 'annex UAX-31, with elaboration and changes as defined below; '
+ 'see also\n'
+ '**PEP 3131** for further details.\n'
+ '\n'
+ 'Within the ASCII range (U+0001..U+007F), the valid characters '
+ 'for\n'
+ 'identifiers are the same as in Python 2.x: the uppercase and '
+ 'lowercase\n'
+ 'letters "A" through "Z", the underscore "_" and, except for '
+ 'the first\n'
+ 'character, the digits "0" through "9".\n'
+ '\n'
+ 'Python 3.0 introduces additional characters from outside the '
+ 'ASCII\n'
+ 'range (see **PEP 3131**). For these characters, the '
+ 'classification\n'
+ 'uses the version of the Unicode Character Database as '
+ 'included in the\n'
+ '"unicodedata" module.\n'
+ '\n'
+ 'Identifiers are unlimited in length. Case is significant.\n'
+ '\n'
+ ' identifier ::= xid_start xid_continue*\n'
+ ' id_start ::= <all characters in general categories Lu, '
+ 'Ll, Lt, Lm, Lo, Nl, the underscore, and characters with the '
+ 'Other_ID_Start property>\n'
+ ' id_continue ::= <all characters in id_start, plus '
+ 'characters in the categories Mn, Mc, Nd, Pc and others with '
+ 'the Other_ID_Continue property>\n'
+ ' xid_start ::= <all characters in id_start whose NFKC '
+ 'normalization is in "id_start xid_continue*">\n'
+ ' xid_continue ::= <all characters in id_continue whose NFKC '
+ 'normalization is in "id_continue*">\n'
+ '\n'
+ 'The Unicode category codes mentioned above stand for:\n'
+ '\n'
+ '* *Lu* - uppercase letters\n'
+ '\n'
+ '* *Ll* - lowercase letters\n'
+ '\n'
+ '* *Lt* - titlecase letters\n'
+ '\n'
+ '* *Lm* - modifier letters\n'
+ '\n'
+ '* *Lo* - other letters\n'
+ '\n'
+ '* *Nl* - letter numbers\n'
+ '\n'
+ '* *Mn* - nonspacing marks\n'
+ '\n'
+ '* *Mc* - spacing combining marks\n'
+ '\n'
+ '* *Nd* - decimal numbers\n'
+ '\n'
+ '* *Pc* - connector punctuations\n'
+ '\n'
+ '* *Other_ID_Start* - explicit list of characters in '
+ 'PropList.txt to\n'
+ ' support backwards compatibility\n'
+ '\n'
+ '* *Other_ID_Continue* - likewise\n'
+ '\n'
+ 'All identifiers are converted into the normal form NFKC while '
+ 'parsing;\n'
+ 'comparison of identifiers is based on NFKC.\n'
+ '\n'
+ 'A non-normative HTML file listing all valid identifier '
+ 'characters for\n'
+ 'Unicode 4.1 can be found at https://www.dcl.hpi.uni-\n'
+ 'potsdam.de/home/loewis/table-3131.html.\n'
+ '\n'
+ '\n'
+ 'Keywords\n'
+ '========\n'
+ '\n'
+ 'The following identifiers are used as reserved words, or '
+ '*keywords* of\n'
+ 'the language, and cannot be used as ordinary identifiers. '
+ 'They must\n'
+ 'be 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'
+ '\n'
+ 'Reserved classes of identifiers\n'
+ '===============================\n'
+ '\n'
+ 'Certain classes of identifiers (besides keywords) have '
+ 'special\n'
+ 'meanings. These classes are identified by the patterns of '
+ 'leading and\n'
+ 'trailing 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 the\n'
+ ' last evaluation; it is stored in the "builtins" module. '
+ 'When not\n'
+ ' in interactive mode, "_" has no special meaning and is not '
+ 'defined.\n'
+ ' See section The import statement.\n'
+ '\n'
+ ' Note: The name "_" is often used in conjunction with\n'
+ ' internationalization; refer to the documentation for '
+ 'the\n'
+ ' "gettext" module for more information on this '
+ 'convention.\n'
+ '\n'
+ '"__*__"\n'
+ ' System-defined names. These names are defined by the '
+ 'interpreter\n'
+ ' and its implementation (including the standard library). '
+ 'Current\n'
+ ' system names are discussed in the Special method names '
+ 'section and\n'
+ ' elsewhere. More will likely be defined in future versions '
+ 'of\n'
+ ' Python. *Any* use of "__*__" names, in any context, that '
+ 'does not\n'
+ ' follow explicitly documented use, is subject to breakage '
+ 'without\n'
+ ' warning.\n'
+ '\n'
+ '"__*"\n'
+ ' Class-private names. Names in this category, when used '
+ 'within the\n'
+ ' context of a class definition, are re-written to use a '
+ 'mangled form\n'
+ ' to help avoid name clashes between "private" attributes of '
+ 'base and\n'
+ ' derived classes. See section Identifiers (Names).\n',
+ 'if': '\n'
+ 'The "if" statement\n'
+ '******************\n'
+ '\n'
+ 'The "if" statement is used for conditional execution:\n'
+ '\n'
+ ' if_stmt ::= "if" expression ":" suite\n'
+ ' ( "elif" expression ":" suite )*\n'
+ ' ["else" ":" suite]\n'
+ '\n'
+ 'It selects exactly one of the suites by evaluating the expressions '
+ 'one\n'
+ 'by one until one is found to be true (see section Boolean operations\n'
+ 'for the definition of true and false); then that suite is executed\n'
+ '(and no other part of the "if" statement is executed or evaluated).\n'
+ 'If all expressions are false, the suite of the "else" clause, if\n'
+ 'present, is executed.\n',
+ 'imaginary': '\n'
+ 'Imaginary literals\n'
+ '******************\n'
+ '\n'
+ 'Imaginary literals are described by the following lexical '
+ 'definitions:\n'
+ '\n'
+ ' imagnumber ::= (floatnumber | digitpart) ("j" | "J")\n'
+ '\n'
+ 'An imaginary literal yields a complex number with a real part '
+ 'of 0.0.\n'
+ 'Complex numbers are represented as a pair of floating point '
+ 'numbers\n'
+ 'and have the same restrictions on their range. To create a '
+ 'complex\n'
+ 'number with a nonzero real part, add a floating point number to '
+ 'it,\n'
+ 'e.g., "(3+4j)". Some examples of imaginary literals:\n'
+ '\n'
+ ' 3.14j 10.j 10j .001j 1e100j 3.14e-10j '
+ '3.14_15_93j\n',
+ 'import': '\n'
+ 'The "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'
+ '\n'
+ 'The basic import statement (no "from" clause) is executed in two\n'
+ 'steps:\n'
+ '\n'
+ '1. find a module, loading and initializing it if necessary\n'
+ '\n'
+ '2. define a name or names in the local namespace for the scope\n'
+ ' where the "import" statement occurs.\n'
+ '\n'
+ 'When the statement contains multiple clauses (separated by commas) '
+ 'the\n'
+ 'two steps are carried out separately for each clause, just as '
+ 'though\n'
+ 'the clauses had been separated out into individual import '
+ 'statements.\n'
+ '\n'
+ 'The details of the first step, finding and loading modules are\n'
+ 'described in greater detail in the section on the import system, '
+ 'which\n'
+ 'also describes the various types of packages and modules that can '
+ 'be\n'
+ 'imported, as well as all the hooks that can be used to customize '
+ 'the\n'
+ 'import system. Note that failures in this step may indicate '
+ 'either\n'
+ 'that the module could not be located, *or* that an error occurred\n'
+ 'while initializing the module, which includes execution of the\n'
+ "module's code.\n"
+ '\n'
+ 'If the requested module is retrieved successfully, it will be '
+ 'made\n'
+ 'available in the local namespace in one of three ways:\n'
+ '\n'
+ '* If the module name is followed by "as", then the name following\n'
+ ' "as" is bound directly to the imported module.\n'
+ '\n'
+ '* If no other name is specified, and the module being imported is '
+ 'a\n'
+ " top level module, the module's name is bound in the local "
+ 'namespace\n'
+ ' as a reference to the imported module\n'
+ '\n'
+ '* If the module being imported is *not* a top level module, then '
+ 'the\n'
+ ' name of the top level package that contains the module is bound '
+ 'in\n'
+ ' the local namespace as a reference to the top level package. '
+ 'The\n'
+ ' imported module must be accessed using its full qualified name\n'
+ ' rather than directly\n'
+ '\n'
+ 'The "from" form uses a slightly more complex process:\n'
+ '\n'
+ '1. find the module specified in the "from" clause, loading and\n'
+ ' initializing it if necessary;\n'
+ '\n'
+ '2. for each of the identifiers specified in the "import" clauses:\n'
+ '\n'
+ ' 1. check if the imported module has an attribute by that name\n'
+ '\n'
+ ' 2. if not, attempt to import a submodule with that name and '
+ 'then\n'
+ ' check the imported module again for that attribute\n'
+ '\n'
+ ' 3. if the attribute is not found, "ImportError" is raised.\n'
+ '\n'
+ ' 4. otherwise, a reference to that value is stored in the local\n'
+ ' namespace, using the name in the "as" clause if it is '
+ 'present,\n'
+ ' otherwise using the attribute name\n'
+ '\n'
+ 'Examples:\n'
+ '\n'
+ ' import foo # foo imported and bound locally\n'
+ ' import foo.bar.baz # foo.bar.baz imported, foo bound '
+ 'locally\n'
+ ' import foo.bar.baz as fbb # foo.bar.baz imported and bound as '
+ 'fbb\n'
+ ' from foo.bar import baz # foo.bar.baz imported and bound as '
+ 'baz\n'
+ ' from foo import attr # foo imported and foo.attr bound as '
+ 'attr\n'
+ '\n'
+ 'If the list of identifiers is replaced by a star ("\'*\'"), all '
+ 'public\n'
+ 'names defined in the module are bound in the local namespace for '
+ 'the\n'
+ 'scope where the "import" statement occurs.\n'
+ '\n'
+ 'The *public names* defined by a module are determined by checking '
+ 'the\n'
+ 'module\'s namespace for a variable named "__all__"; if defined, it '
+ 'must\n'
+ 'be a sequence of strings which are names defined or imported by '
+ 'that\n'
+ 'module. The names given in "__all__" are all considered public '
+ 'and\n'
+ 'are required to exist. If "__all__" is not defined, the set of '
+ 'public\n'
+ "names includes all names found in the module's namespace which do "
+ 'not\n'
+ 'begin with an underscore character ("\'_\'"). "__all__" should '
+ 'contain\n'
+ 'the entire public API. It is intended to avoid accidentally '
+ 'exporting\n'
+ 'items that are not part of the API (such as library modules which '
+ 'were\n'
+ 'imported and used within the module).\n'
+ '\n'
+ 'The wild card form of import --- "from module import *" --- is '
+ 'only\n'
+ 'allowed at the module level. Attempting to use it in class or\n'
+ 'function definitions will raise a "SyntaxError".\n'
+ '\n'
+ 'When specifying what module to import you do not have to specify '
+ 'the\n'
+ 'absolute name of the module. When a module or package is '
+ 'contained\n'
+ 'within another package it is possible to make a relative import '
+ 'within\n'
+ 'the same top package without having to mention the package name. '
+ 'By\n'
+ 'using leading dots in the specified module or package after "from" '
+ 'you\n'
+ 'can specify how high to traverse up the current package hierarchy\n'
+ 'without specifying exact names. One leading dot means the current\n'
+ 'package where the module making the import exists. Two dots means '
+ 'up\n'
+ 'one package level. Three dots is up two levels, etc. So if you '
+ 'execute\n'
+ '"from . import mod" from a module in the "pkg" package then you '
+ 'will\n'
+ 'end up importing "pkg.mod". If you execute "from ..subpkg2 import '
+ 'mod"\n'
+ 'from within "pkg.subpkg1" you will import "pkg.subpkg2.mod". The\n'
+ 'specification for relative imports is contained within **PEP '
+ '328**.\n'
+ '\n'
+ '"importlib.import_module()" is provided to support applications '
+ 'that\n'
+ 'determine dynamically the modules to be loaded.\n'
+ '\n'
+ '\n'
+ 'Future statements\n'
+ '=================\n'
+ '\n'
+ 'A *future statement* is a directive to the compiler that a '
+ 'particular\n'
+ 'module should be compiled using syntax or semantics that will be\n'
+ 'available in a specified future release of Python where the '
+ 'feature\n'
+ 'becomes standard.\n'
+ '\n'
+ 'The future statement is intended to ease migration to future '
+ 'versions\n'
+ 'of Python that introduce incompatible changes to the language. '
+ 'It\n'
+ 'allows use of the new features on a per-module basis before the\n'
+ 'release in which the feature 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'
+ '\n'
+ 'A future statement must appear near the top of the module. The '
+ 'only\n'
+ 'lines 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'
+ '\n'
+ 'The features recognized by Python 3.0 are "absolute_import",\n'
+ '"division", "generators", "unicode_literals", "print_function",\n'
+ '"nested_scopes" and "with_statement". They are all redundant '
+ 'because\n'
+ 'they are always enabled, and only kept for backwards '
+ 'compatibility.\n'
+ '\n'
+ 'A future statement is recognized and treated specially at compile\n'
+ 'time: Changes to the semantics of core constructs are often\n'
+ 'implemented by generating different code. It may even be the '
+ 'case\n'
+ 'that a new feature introduces new incompatible syntax (such as a '
+ 'new\n'
+ 'reserved word), in which case the compiler may need to parse the\n'
+ 'module differently. Such decisions cannot be pushed off until\n'
+ 'runtime.\n'
+ '\n'
+ 'For any given release, the compiler knows which feature names '
+ 'have\n'
+ 'been defined, and raises a compile-time error if a future '
+ 'statement\n'
+ 'contains a feature not known to it.\n'
+ '\n'
+ 'The direct runtime semantics are the same as for any import '
+ 'statement:\n'
+ 'there is a standard module "__future__", described later, and it '
+ 'will\n'
+ 'be imported in the usual way at the time the future statement is\n'
+ 'executed.\n'
+ '\n'
+ 'The interesting runtime semantics depend on the specific feature\n'
+ 'enabled by the future statement.\n'
+ '\n'
+ 'Note that there is nothing special about the statement:\n'
+ '\n'
+ ' import __future__ [as name]\n'
+ '\n'
+ "That is not a future statement; it's an ordinary import statement "
+ 'with\n'
+ 'no special semantics or syntax restrictions.\n'
+ '\n'
+ 'Code compiled by calls to the built-in functions "exec()" and\n'
+ '"compile()" that occur in a module "M" containing a future '
+ 'statement\n'
+ 'will, by default, use the new syntax or semantics associated with '
+ 'the\n'
+ 'future statement. This can be controlled by optional arguments '
+ 'to\n'
+ '"compile()" --- see the documentation of that function for '
+ 'details.\n'
+ '\n'
+ 'A future statement typed at an interactive interpreter prompt '
+ 'will\n'
+ 'take effect for the rest of the interpreter session. If an\n'
+ 'interpreter is started with the "-i" option, is passed a script '
+ 'name\n'
+ 'to execute, and the script includes a future statement, it will be '
+ 'in\n'
+ 'effect in the interactive session started after the script is\n'
+ 'executed.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 236** - Back to the __future__\n'
+ ' The original proposal for the __future__ mechanism.\n',
+ 'in': '\n'
+ 'Membership test operations\n'
+ '**************************\n'
+ '\n'
+ 'The operators "in" and "not in" test for membership. "x in s"\n'
+ 'evaluates to true if *x* is a member of *s*, and false otherwise. "x\n'
+ 'not in s" returns the negation of "x in s". All built-in sequences\n'
+ 'and set types support this as well as dictionary, for which "in" '
+ 'tests\n'
+ 'whether the dictionary has a given key. For container types such as\n'
+ 'list, tuple, set, frozenset, dict, or collections.deque, the\n'
+ 'expression "x in y" is equivalent to "any(x is e or x == e for e in\n'
+ 'y)".\n'
+ '\n'
+ 'For the string and bytes types, "x in y" is true if and only if *x* '
+ 'is\n'
+ 'a substring of *y*. An equivalent test is "y.find(x) != -1". Empty\n'
+ 'strings are always considered to be a substring of any other string,\n'
+ 'so """ in "abc"" will return "True".\n'
+ '\n'
+ 'For user-defined classes which define the "__contains__()" method, "x\n'
+ 'in y" is true if and only if "y.__contains__(x)" is true.\n'
+ '\n'
+ 'For user-defined classes which do not define "__contains__()" but do\n'
+ 'define "__iter__()", "x in y" is true if some value "z" with "x == z"\n'
+ 'is produced while iterating over "y". If an exception is raised\n'
+ 'during the iteration, it is as if "in" raised that exception.\n'
+ '\n'
+ 'Lastly, the old-style iteration protocol is tried: if a class defines\n'
+ '"__getitem__()", "x in y" is true if and only if there is a non-\n'
+ 'negative integer index *i* such that "x == y[i]", and all lower\n'
+ 'integer indices do not raise "IndexError" exception. (If any other\n'
+ 'exception is raised, it is as if "in" raised that exception).\n'
+ '\n'
+ 'The operator "not in" is defined to have the inverse true value of\n'
+ '"in".\n',
+ 'integers': '\n'
+ 'Integer literals\n'
+ '****************\n'
+ '\n'
+ 'Integer literals are described by the following lexical '
+ 'definitions:\n'
+ '\n'
+ ' integer ::= decinteger | bininteger | octinteger | '
+ 'hexinteger\n'
+ ' decinteger ::= nonzerodigit (["_"] digit)* | "0"+ (["_"] '
+ '"0")*\n'
+ ' bininteger ::= "0" ("b" | "B") (["_"] bindigit)+\n'
+ ' octinteger ::= "0" ("o" | "O") (["_"] octdigit)+\n'
+ ' hexinteger ::= "0" ("x" | "X") (["_"] hexdigit)+\n'
+ ' nonzerodigit ::= "1"..."9"\n'
+ ' digit ::= "0"..."9"\n'
+ ' bindigit ::= "0" | "1"\n'
+ ' octdigit ::= "0"..."7"\n'
+ ' hexdigit ::= digit | "a"..."f" | "A"..."F"\n'
+ '\n'
+ 'There is no limit for the length of integer literals apart from '
+ 'what\n'
+ 'can be stored in available memory.\n'
+ '\n'
+ 'Underscores are ignored for determining the numeric value of '
+ 'the\n'
+ 'literal. They can be used to group digits for enhanced '
+ 'readability.\n'
+ 'One underscore can occur between digits, and after base '
+ 'specifiers\n'
+ 'like "0x".\n'
+ '\n'
+ 'Note that leading zeros in a non-zero decimal number are not '
+ 'allowed.\n'
+ 'This is for disambiguation with C-style octal literals, which '
+ 'Python\n'
+ 'used before version 3.0.\n'
+ '\n'
+ 'Some examples of integer literals:\n'
+ '\n'
+ ' 7 2147483647 0o177 0b100110111\n'
+ ' 3 79228162514264337593543950336 0o377 0xdeadbeef\n'
+ ' 100_000_000_000 0b_1110_0101\n'
+ '\n'
+ 'Changed in version 3.6: Underscores are now allowed for '
+ 'grouping\n'
+ 'purposes in literals.\n',
+ 'lambda': '\n'
+ 'Lambdas\n'
+ '*******\n'
+ '\n'
+ ' lambda_expr ::= "lambda" [parameter_list]: expression\n'
+ ' lambda_expr_nocond ::= "lambda" [parameter_list]: '
+ 'expression_nocond\n'
+ '\n'
+ 'Lambda expressions (sometimes called lambda forms) are used to '
+ 'create\n'
+ 'anonymous functions. The expression "lambda arguments: '
+ 'expression"\n'
+ 'yields a function object. The unnamed object behaves like a '
+ 'function\n'
+ 'object defined with:\n'
+ '\n'
+ ' def <lambda>(arguments):\n'
+ ' return expression\n'
+ '\n'
+ 'See section Function definitions for the syntax of parameter '
+ 'lists.\n'
+ 'Note that functions created with lambda expressions cannot '
+ 'contain\n'
+ 'statements or annotations.\n',
+ 'lists': '\n'
+ 'List displays\n'
+ '*************\n'
+ '\n'
+ 'A list display is a possibly empty series of expressions enclosed '
+ 'in\n'
+ 'square brackets:\n'
+ '\n'
+ ' list_display ::= "[" [starred_list | comprehension] "]"\n'
+ '\n'
+ 'A list display yields a new list object, the contents being '
+ 'specified\n'
+ 'by either a list of expressions or a comprehension. When a comma-\n'
+ 'separated list of expressions is supplied, its elements are '
+ 'evaluated\n'
+ 'from left to right and placed into the list object in that order.\n'
+ 'When a comprehension is supplied, the list is constructed from the\n'
+ 'elements resulting from the comprehension.\n',
+ 'naming': '\n'
+ 'Naming and binding\n'
+ '******************\n'
+ '\n'
+ '\n'
+ 'Binding of names\n'
+ '================\n'
+ '\n'
+ '*Names* refer to objects. Names are introduced by name binding\n'
+ 'operations.\n'
+ '\n'
+ 'The following constructs bind names: formal parameters to '
+ 'functions,\n'
+ '"import" statements, class and function definitions (these bind '
+ 'the\n'
+ 'class or function name in the defining block), and targets that '
+ 'are\n'
+ 'identifiers if occurring in an assignment, "for" loop header, or '
+ 'after\n'
+ '"as" in a "with" statement or "except" clause. The "import" '
+ 'statement\n'
+ 'of the form "from ... import *" binds all names defined in the\n'
+ 'imported module, except those beginning with an underscore. This '
+ 'form\n'
+ 'may only be used at the module level.\n'
+ '\n'
+ 'A target occurring in a "del" statement is also considered bound '
+ 'for\n'
+ 'this purpose (though the actual semantics are to unbind the '
+ 'name).\n'
+ '\n'
+ 'Each assignment or import statement occurs within a block defined '
+ 'by a\n'
+ 'class or function definition or at the module level (the '
+ 'top-level\n'
+ 'code block).\n'
+ '\n'
+ 'If a name is bound in a block, it is a local variable of that '
+ 'block,\n'
+ 'unless declared as "nonlocal" or "global". If a name is bound at '
+ 'the\n'
+ 'module level, it is a global variable. (The variables of the '
+ 'module\n'
+ 'code block are local and global.) If a variable is used in a '
+ 'code\n'
+ 'block but not defined there, it is a *free variable*.\n'
+ '\n'
+ 'Each occurrence of a name in the program text refers to the '
+ '*binding*\n'
+ 'of that name established by the following name resolution rules.\n'
+ '\n'
+ '\n'
+ 'Resolution of names\n'
+ '===================\n'
+ '\n'
+ 'A *scope* defines the visibility of a name within a block. If a '
+ 'local\n'
+ 'variable is defined in a block, its scope includes that block. If '
+ 'the\n'
+ 'definition occurs in a function block, the scope extends to any '
+ 'blocks\n'
+ 'contained within the defining one, unless a contained block '
+ 'introduces\n'
+ 'a different binding for the name.\n'
+ '\n'
+ 'When a name is used in a code block, it is resolved using the '
+ 'nearest\n'
+ 'enclosing scope. The set of all such scopes visible to a code '
+ 'block\n'
+ "is called the block's *environment*.\n"
+ '\n'
+ 'When a name is not found at all, a "NameError" exception is '
+ 'raised. If\n'
+ 'the current scope is a function scope, and the name refers to a '
+ 'local\n'
+ 'variable that has not yet been bound to a value at the point where '
+ 'the\n'
+ 'name is used, an "UnboundLocalError" exception is raised.\n'
+ '"UnboundLocalError" is a subclass of "NameError".\n'
+ '\n'
+ 'If a name binding operation occurs anywhere within a code block, '
+ 'all\n'
+ 'uses of the name within the block are treated as references to '
+ 'the\n'
+ 'current block. This can lead to errors when a name is used within '
+ 'a\n'
+ 'block before it is bound. This rule is subtle. Python lacks\n'
+ 'declarations and allows name binding operations to occur anywhere\n'
+ 'within a code block. The local variables of a code block can be\n'
+ 'determined by scanning the entire text of the block for name '
+ 'binding\n'
+ 'operations.\n'
+ '\n'
+ 'If the "global" statement occurs within a block, all uses of the '
+ 'name\n'
+ 'specified in the statement refer to the binding of that name in '
+ 'the\n'
+ 'top-level namespace. Names are resolved in the top-level '
+ 'namespace by\n'
+ 'searching the global namespace, i.e. the namespace of the module\n'
+ 'containing the code block, and the builtins namespace, the '
+ 'namespace\n'
+ 'of the module "builtins". The global namespace is searched '
+ 'first. If\n'
+ 'the name is not found there, the builtins namespace is searched. '
+ 'The\n'
+ '"global" statement must precede all uses of the name.\n'
+ '\n'
+ 'The "global" statement has the same scope as a name binding '
+ 'operation\n'
+ 'in the same block. If the nearest enclosing scope for a free '
+ 'variable\n'
+ 'contains a global statement, the free variable is treated as a '
+ 'global.\n'
+ '\n'
+ 'The "nonlocal" statement causes corresponding names to refer to\n'
+ 'previously bound variables in the nearest enclosing function '
+ 'scope.\n'
+ '"SyntaxError" is raised at compile time if the given name does '
+ 'not\n'
+ 'exist in any enclosing function scope.\n'
+ '\n'
+ 'The namespace for a module is automatically created the first time '
+ 'a\n'
+ 'module is imported. The main module for a script is always '
+ 'called\n'
+ '"__main__".\n'
+ '\n'
+ 'Class definition blocks and arguments to "exec()" and "eval()" '
+ 'are\n'
+ 'special in the context of name resolution. A class definition is '
+ 'an\n'
+ 'executable statement that may use and define names. These '
+ 'references\n'
+ 'follow the normal rules for name resolution with an exception '
+ 'that\n'
+ 'unbound local variables are looked up in the global namespace. '
+ 'The\n'
+ 'namespace of the class definition becomes the attribute dictionary '
+ 'of\n'
+ 'the class. The scope of names defined in a class block is limited '
+ 'to\n'
+ 'the class block; it does not extend to the code blocks of methods '
+ '--\n'
+ 'this includes comprehensions and generator expressions since they '
+ 'are\n'
+ 'implemented using a function scope. This means that the '
+ 'following\n'
+ 'will fail:\n'
+ '\n'
+ ' class A:\n'
+ ' a = 42\n'
+ ' b = list(a + i for i in range(10))\n'
+ '\n'
+ '\n'
+ 'Builtins and restricted execution\n'
+ '=================================\n'
+ '\n'
+ 'The builtins namespace associated with the execution of a code '
+ 'block\n'
+ 'is actually found by looking up the name "__builtins__" in its '
+ 'global\n'
+ 'namespace; this should be a dictionary or a module (in the latter '
+ 'case\n'
+ "the module's dictionary is used). By default, when in the "
+ '"__main__"\n'
+ 'module, "__builtins__" is the built-in module "builtins"; when in '
+ 'any\n'
+ 'other module, "__builtins__" is an alias for the dictionary of '
+ 'the\n'
+ '"builtins" module itself. "__builtins__" can be set to a '
+ 'user-created\n'
+ 'dictionary to create a weak form of restricted execution.\n'
+ '\n'
+ '**CPython implementation detail:** Users should not touch\n'
+ '"__builtins__"; it is strictly an implementation detail. Users\n'
+ 'wanting to override values in the builtins namespace should '
+ '"import"\n'
+ 'the "builtins" module and modify its attributes appropriately.\n'
+ '\n'
+ '\n'
+ 'Interaction with dynamic features\n'
+ '=================================\n'
+ '\n'
+ 'Name resolution of free variables occurs at runtime, not at '
+ 'compile\n'
+ 'time. This means that the following code will print 42:\n'
+ '\n'
+ ' i = 10\n'
+ ' def f():\n'
+ ' print(i)\n'
+ ' i = 42\n'
+ ' f()\n'
+ '\n'
+ 'There are several cases where Python statements are illegal when '
+ 'used\n'
+ 'in conjunction with nested scopes that contain free variables.\n'
+ '\n'
+ 'If a variable is referenced in an enclosing scope, it is illegal '
+ 'to\n'
+ 'delete the name. An error will be reported at compile time.\n'
+ '\n'
+ 'The "eval()" and "exec()" functions do not have access to the '
+ 'full\n'
+ 'environment for resolving names. Names may be resolved in the '
+ 'local\n'
+ 'and global namespaces of the caller. Free variables are not '
+ 'resolved\n'
+ 'in the nearest enclosing namespace, but in the global namespace. '
+ '[1]\n'
+ 'The "exec()" and "eval()" functions have optional arguments to\n'
+ 'override the global and local namespace. If only one namespace '
+ 'is\n'
+ 'specified, it is used for both.\n',
+ 'nonlocal': '\n'
+ 'The "nonlocal" statement\n'
+ '************************\n'
+ '\n'
+ ' nonlocal_stmt ::= "nonlocal" identifier ("," identifier)*\n'
+ '\n'
+ 'The "nonlocal" statement causes the listed identifiers to refer '
+ 'to\n'
+ 'previously bound variables in the nearest enclosing scope '
+ 'excluding\n'
+ 'globals. This is important because the default behavior for '
+ 'binding is\n'
+ 'to search the local namespace first. The statement allows\n'
+ 'encapsulated code to rebind variables outside of the local '
+ 'scope\n'
+ 'besides the global (module) scope.\n'
+ '\n'
+ 'Names listed in a "nonlocal" statement, unlike those listed in '
+ 'a\n'
+ '"global" statement, must refer to pre-existing bindings in an\n'
+ 'enclosing scope (the scope in which a new binding should be '
+ 'created\n'
+ 'cannot be determined unambiguously).\n'
+ '\n'
+ 'Names listed in a "nonlocal" statement must not collide with '
+ 'pre-\n'
+ 'existing bindings in the local scope.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 3104** - Access to Names in Outer Scopes\n'
+ ' The specification for the "nonlocal" statement.\n',
+ 'numbers': '\n'
+ 'Numeric literals\n'
+ '****************\n'
+ '\n'
+ 'There are three types of numeric literals: integers, floating '
+ 'point\n'
+ 'numbers, and imaginary numbers. There are no complex literals\n'
+ '(complex numbers can be formed by adding a real number and an\n'
+ 'imaginary number).\n'
+ '\n'
+ 'Note that numeric literals do not include a sign; a phrase like '
+ '"-1"\n'
+ 'is actually an expression composed of the unary operator \'"-"\' '
+ 'and the\n'
+ 'literal "1".\n',
+ 'numeric-types': '\n'
+ 'Emulating numeric types\n'
+ '***********************\n'
+ '\n'
+ 'The following methods can be defined to emulate numeric '
+ 'objects.\n'
+ 'Methods corresponding to operations that are not supported '
+ 'by the\n'
+ 'particular kind of number implemented (e.g., bitwise '
+ 'operations for\n'
+ 'non-integral numbers) should be left undefined.\n'
+ '\n'
+ 'object.__add__(self, other)\n'
+ 'object.__sub__(self, other)\n'
+ 'object.__mul__(self, other)\n'
+ 'object.__matmul__(self, other)\n'
+ 'object.__truediv__(self, other)\n'
+ 'object.__floordiv__(self, other)\n'
+ 'object.__mod__(self, other)\n'
+ 'object.__divmod__(self, other)\n'
+ 'object.__pow__(self, other[, modulo])\n'
+ 'object.__lshift__(self, other)\n'
+ 'object.__rshift__(self, other)\n'
+ 'object.__and__(self, other)\n'
+ 'object.__xor__(self, other)\n'
+ 'object.__or__(self, other)\n'
+ '\n'
+ ' These methods are called to implement the binary '
+ 'arithmetic\n'
+ ' operations ("+", "-", "*", "@", "/", "//", "%", '
+ '"divmod()",\n'
+ ' "pow()", "**", "<<", ">>", "&", "^", "|"). For '
+ 'instance, to\n'
+ ' evaluate the expression "x + y", where *x* is an '
+ 'instance of a\n'
+ ' class that has an "__add__()" method, "x.__add__(y)" is '
+ 'called.\n'
+ ' The "__divmod__()" method should be the equivalent to '
+ 'using\n'
+ ' "__floordiv__()" and "__mod__()"; it should not be '
+ 'related to\n'
+ ' "__truediv__()". Note that "__pow__()" should be '
+ 'defined to accept\n'
+ ' an optional third argument if the ternary version of the '
+ 'built-in\n'
+ ' "pow()" function 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'
+ '\n'
+ 'object.__radd__(self, other)\n'
+ 'object.__rsub__(self, other)\n'
+ 'object.__rmul__(self, other)\n'
+ 'object.__rmatmul__(self, other)\n'
+ 'object.__rtruediv__(self, other)\n'
+ 'object.__rfloordiv__(self, other)\n'
+ 'object.__rmod__(self, other)\n'
+ 'object.__rdivmod__(self, other)\n'
+ 'object.__rpow__(self, other)\n'
+ 'object.__rlshift__(self, other)\n'
+ 'object.__rrshift__(self, other)\n'
+ 'object.__rand__(self, other)\n'
+ 'object.__rxor__(self, other)\n'
+ 'object.__ror__(self, other)\n'
+ '\n'
+ ' These methods are called to implement the binary '
+ 'arithmetic\n'
+ ' operations ("+", "-", "*", "@", "/", "//", "%", '
+ '"divmod()",\n'
+ ' "pow()", "**", "<<", ">>", "&", "^", "|") with reflected '
+ '(swapped)\n'
+ ' operands. These functions are only called if the left '
+ 'operand does\n'
+ ' not support the corresponding operation [3] and the '
+ 'operands are of\n'
+ ' different types. [4] For instance, to evaluate the '
+ 'expression "x -\n'
+ ' y", where *y* is an instance of a class that has an '
+ '"__rsub__()"\n'
+ ' method, "y.__rsub__(x)" is called if "x.__sub__(y)" '
+ 'returns\n'
+ ' *NotImplemented*.\n'
+ '\n'
+ ' Note that ternary "pow()" will not try calling '
+ '"__rpow__()" (the\n'
+ ' coercion rules would become too complicated).\n'
+ '\n'
+ " Note: If the right operand's type is a subclass of the "
+ 'left\n'
+ " operand's type and that subclass provides the "
+ 'reflected method\n'
+ ' for the operation, this method will be called before '
+ 'the left\n'
+ " operand's non-reflected method. This behavior allows "
+ 'subclasses\n'
+ " to override their ancestors' operations.\n"
+ '\n'
+ 'object.__iadd__(self, other)\n'
+ 'object.__isub__(self, other)\n'
+ 'object.__imul__(self, other)\n'
+ 'object.__imatmul__(self, other)\n'
+ 'object.__itruediv__(self, other)\n'
+ 'object.__ifloordiv__(self, other)\n'
+ 'object.__imod__(self, other)\n'
+ 'object.__ipow__(self, other[, modulo])\n'
+ 'object.__ilshift__(self, other)\n'
+ 'object.__irshift__(self, other)\n'
+ 'object.__iand__(self, other)\n'
+ 'object.__ixor__(self, other)\n'
+ 'object.__ior__(self, other)\n'
+ '\n'
+ ' These methods are called to implement the augmented '
+ 'arithmetic\n'
+ ' assignments ("+=", "-=", "*=", "@=", "/=", "//=", "%=", '
+ '"**=",\n'
+ ' "<<=", ">>=", "&=", "^=", "|="). These methods should '
+ 'attempt to\n'
+ ' do the operation in-place (modifying *self*) and return '
+ 'the result\n'
+ ' (which could be, but does not have to be, *self*). If a '
+ 'specific\n'
+ ' method is not defined, the augmented assignment falls '
+ 'back to the\n'
+ ' normal methods. For instance, if *x* is an instance of '
+ 'a class\n'
+ ' with an "__iadd__()" method, "x += y" is equivalent to '
+ '"x =\n'
+ ' x.__iadd__(y)" . Otherwise, "x.__add__(y)" and '
+ '"y.__radd__(x)" are\n'
+ ' considered, as with the evaluation of "x + y". In '
+ 'certain\n'
+ ' situations, augmented assignment can result in '
+ 'unexpected errors\n'
+ " (see Why does a_tuple[i] += ['item'] raise an exception "
+ 'when the\n'
+ ' addition works?), but this behavior is in fact part of '
+ 'the data\n'
+ ' model.\n'
+ '\n'
+ 'object.__neg__(self)\n'
+ 'object.__pos__(self)\n'
+ 'object.__abs__(self)\n'
+ 'object.__invert__(self)\n'
+ '\n'
+ ' Called to implement the unary arithmetic operations '
+ '("-", "+",\n'
+ ' "abs()" and "~").\n'
+ '\n'
+ 'object.__complex__(self)\n'
+ 'object.__int__(self)\n'
+ 'object.__float__(self)\n'
+ 'object.__round__(self[, n])\n'
+ '\n'
+ ' Called to implement the built-in functions "complex()", '
+ '"int()",\n'
+ ' "float()" and "round()". Should return a value of the '
+ 'appropriate\n'
+ ' type.\n'
+ '\n'
+ 'object.__index__(self)\n'
+ '\n'
+ ' Called to implement "operator.index()", and whenever '
+ 'Python needs\n'
+ ' to losslessly convert the numeric object to an integer '
+ 'object (such\n'
+ ' as in slicing, or in the built-in "bin()", "hex()" and '
+ '"oct()"\n'
+ ' functions). Presence of this method indicates that the '
+ 'numeric\n'
+ ' object is an integer type. Must return an integer.\n'
+ '\n'
+ ' Note: In order to have a coherent integer type class, '
+ 'when\n'
+ ' "__index__()" is defined "__int__()" should also be '
+ 'defined, and\n'
+ ' both should return the same value.\n',
+ 'objects': '\n'
+ 'Objects, values and types\n'
+ '*************************\n'
+ '\n'
+ "*Objects* are Python's abstraction for data. All data in a "
+ 'Python\n'
+ 'program is represented by objects or by relations between '
+ 'objects. (In\n'
+ 'a sense, and in conformance to Von Neumann\'s model of a "stored\n'
+ 'program computer," code is also represented by objects.)\n'
+ '\n'
+ "Every 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\n'
+ 'as the object\'s address in memory. The \'"is"\' operator '
+ 'compares the\n'
+ 'identity of two objects; the "id()" function returns an integer\n'
+ 'representing its identity.\n'
+ '\n'
+ '**CPython implementation detail:** For CPython, "id(x)" is the '
+ 'memory\n'
+ 'address where "x" is stored.\n'
+ '\n'
+ "An object's type determines the operations that the object "
+ 'supports\n'
+ '(e.g., "does it have a length?") and also defines the possible '
+ 'values\n'
+ 'for objects of that type. The "type()" function returns an '
+ "object's\n"
+ 'type (which is an object itself). Like its identity, an '
+ "object's\n"
+ '*type* is also unchangeable. [1]\n'
+ '\n'
+ 'The *value* of some objects can change. Objects whose value can\n'
+ 'change are said to be *mutable*; objects whose value is '
+ 'unchangeable\n'
+ 'once they are created are called *immutable*. (The value of an\n'
+ 'immutable container object that contains a reference to a '
+ 'mutable\n'
+ "object can change when the latter's value is changed; however "
+ 'the\n'
+ 'container is still considered immutable, because the collection '
+ 'of\n'
+ 'objects it contains cannot be changed. So, immutability is not\n'
+ 'strictly the same as having an unchangeable value, it is more '
+ 'subtle.)\n'
+ "An object's mutability is determined by its type; for instance,\n"
+ 'numbers, strings and tuples are immutable, while dictionaries '
+ 'and\n'
+ 'lists are mutable.\n'
+ '\n'
+ 'Objects are never explicitly destroyed; however, when they '
+ 'become\n'
+ 'unreachable they may be garbage-collected. An implementation is\n'
+ 'allowed to postpone garbage collection or omit it altogether --- '
+ 'it is\n'
+ 'a matter of implementation quality how garbage collection is\n'
+ 'implemented, as long as no objects are collected that are still\n'
+ 'reachable.\n'
+ '\n'
+ '**CPython implementation detail:** CPython currently uses a '
+ 'reference-\n'
+ 'counting scheme with (optional) delayed detection of cyclically '
+ 'linked\n'
+ 'garbage, which collects most objects as soon as they become\n'
+ 'unreachable, but is not guaranteed to collect garbage containing\n'
+ 'circular references. See the documentation of the "gc" module '
+ 'for\n'
+ 'information on controlling the collection of cyclic garbage. '
+ 'Other\n'
+ 'implementations act differently and CPython may change. Do not '
+ 'depend\n'
+ 'on immediate finalization of objects when they become unreachable '
+ '(so\n'
+ 'you should always close files explicitly).\n'
+ '\n'
+ "Note that the use of the implementation's tracing or debugging\n"
+ 'facilities may keep objects alive that would normally be '
+ 'collectable.\n'
+ 'Also note that catching an exception with a \'"try"..."except"\'\n'
+ 'statement may keep objects alive.\n'
+ '\n'
+ 'Some objects contain references to "external" resources such as '
+ 'open\n'
+ 'files or windows. It is understood that these resources are '
+ 'freed\n'
+ 'when the object is garbage-collected, but since garbage '
+ 'collection is\n'
+ 'not guaranteed to happen, such objects also provide an explicit '
+ 'way to\n'
+ 'release the external resource, usually a "close()" method. '
+ 'Programs\n'
+ 'are strongly recommended to explicitly close such objects. The\n'
+ '\'"try"..."finally"\' statement and the \'"with"\' statement '
+ 'provide\n'
+ 'convenient ways to do this.\n'
+ '\n'
+ 'Some objects contain references to other objects; these are '
+ 'called\n'
+ '*containers*. Examples of containers are tuples, lists and\n'
+ "dictionaries. The references are part of a container's value. "
+ 'In\n'
+ 'most cases, when we talk about the value of a container, we imply '
+ 'the\n'
+ 'values, not the identities of the contained objects; however, '
+ 'when we\n'
+ 'talk about the mutability of a container, only the identities of '
+ 'the\n'
+ 'immediately contained objects are implied. So, if an immutable\n'
+ 'container (like a tuple) contains a reference to a mutable '
+ 'object, its\n'
+ 'value changes if that mutable object is changed.\n'
+ '\n'
+ 'Types affect almost all aspects of object behavior. Even the\n'
+ 'importance of object identity is affected in some sense: for '
+ 'immutable\n'
+ 'types, operations that compute new values may actually return a\n'
+ 'reference to any existing object with the same type and value, '
+ 'while\n'
+ 'for mutable objects this is not allowed. E.g., after "a = 1; b = '
+ '1",\n'
+ '"a" and "b" may or may not refer to the same object with the '
+ 'value\n'
+ 'one, depending on the implementation, but after "c = []; d = []", '
+ '"c"\n'
+ 'and "d" are guaranteed to refer to two different, unique, newly\n'
+ 'created empty lists. (Note that "c = d = []" assigns the same '
+ 'object\n'
+ 'to both "c" and "d".)\n',
+ 'operator-summary': '\n'
+ 'Operator precedence\n'
+ '*******************\n'
+ '\n'
+ 'The following table summarizes the operator precedence '
+ 'in Python, from\n'
+ 'lowest precedence (least binding) to highest precedence '
+ '(most\n'
+ 'binding). Operators in the same box have the same '
+ 'precedence. Unless\n'
+ 'the syntax is explicitly given, operators are binary. '
+ 'Operators in\n'
+ 'the same box group left to right (except for '
+ 'exponentiation, which\n'
+ 'groups from right to left).\n'
+ '\n'
+ 'Note that comparisons, membership tests, and identity '
+ 'tests, all have\n'
+ 'the same precedence and have a left-to-right chaining '
+ 'feature as\n'
+ 'described in the Comparisons section.\n'
+ '\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| Operator | '
+ 'Description |\n'
+ '+=================================================+=======================================+\n'
+ '| "lambda" | '
+ 'Lambda expression |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "if" -- "else" | '
+ 'Conditional expression |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "or" | '
+ 'Boolean OR |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "and" | '
+ 'Boolean AND |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "not" "x" | '
+ 'Boolean NOT |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "in", "not in", "is", "is not", "<", "<=", ">", | '
+ 'Comparisons, including membership |\n'
+ '| ">=", "!=", "==" | '
+ 'tests and identity tests |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "|" | '
+ 'Bitwise OR |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "^" | '
+ 'Bitwise XOR |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "&" | '
+ 'Bitwise AND |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "<<", ">>" | '
+ 'Shifts |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "+", "-" | '
+ 'Addition and subtraction |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "*", "@", "/", "//", "%" | '
+ 'Multiplication, matrix multiplication |\n'
+ '| | '
+ 'division, remainder [5] |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "+x", "-x", "~x" | '
+ 'Positive, negative, bitwise NOT |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "**" | '
+ 'Exponentiation [6] |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "await" "x" | '
+ 'Await expression |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "x[index]", "x[index:index]", | '
+ 'Subscription, slicing, call, |\n'
+ '| "x(arguments...)", "x.attribute" | '
+ 'attribute reference |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '| "(expressions...)", "[expressions...]", "{key: | '
+ 'Binding or tuple display, list |\n'
+ '| value...}", "{expressions...}" | '
+ 'display, dictionary display, set |\n'
+ '| | '
+ 'display |\n'
+ '+-------------------------------------------------+---------------------------------------+\n'
+ '\n'
+ '-[ Footnotes ]-\n'
+ '\n'
+ '[1] While "abs(x%y) < abs(y)" is true mathematically, '
+ 'for floats\n'
+ ' it 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", which\n'
+ ' is numerically exactly equal to "1e100". The '
+ 'function\n'
+ ' "math.fmod()" returns a result whose sign matches '
+ 'the sign of the\n'
+ ' first argument instead, and so returns "-1e-100" in '
+ 'this case.\n'
+ ' Which approach is more appropriate 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 close\n'
+ ' to "x".\n'
+ '\n'
+ '[3] The Unicode standard distinguishes between *code '
+ 'points* (e.g.\n'
+ ' U+0041) and *abstract characters* (e.g. "LATIN '
+ 'CAPITAL LETTER A").\n'
+ ' While most abstract characters in Unicode are only '
+ 'represented\n'
+ ' using one code point, there is a number of abstract '
+ 'characters\n'
+ ' that can in addition be represented using a sequence '
+ 'of more than\n'
+ ' one code point. For example, the abstract character '
+ '"LATIN\n'
+ ' CAPITAL LETTER C WITH CEDILLA" can be represented as '
+ 'a single\n'
+ ' *precomposed character* at code position U+00C7, or '
+ 'as a sequence\n'
+ ' of a *base character* at code position U+0043 (LATIN '
+ 'CAPITAL\n'
+ ' LETTER C), followed by a *combining character* at '
+ 'code position\n'
+ ' U+0327 (COMBINING CEDILLA).\n'
+ '\n'
+ ' The comparison operators on strings compare at the '
+ 'level of\n'
+ ' Unicode code points. This may be counter-intuitive '
+ 'to humans. For\n'
+ ' example, ""\\u00C7" == "\\u0043\\u0327"" is "False", '
+ 'even though both\n'
+ ' strings represent the same abstract character "LATIN '
+ 'CAPITAL\n'
+ ' LETTER C WITH CEDILLA".\n'
+ '\n'
+ ' To compare strings at the level of abstract '
+ 'characters (that is,\n'
+ ' in a way intuitive to humans), use '
+ '"unicodedata.normalize()".\n'
+ '\n'
+ '[4] Due to automatic garbage-collection, free lists, and '
+ 'the\n'
+ ' dynamic nature of descriptors, you may notice '
+ 'seemingly unusual\n'
+ ' behaviour in certain uses of the "is" operator, like '
+ 'those\n'
+ ' involving comparisons between instance methods, or '
+ 'constants.\n'
+ ' Check their documentation for more info.\n'
+ '\n'
+ '[5] The "%" operator is also used for string formatting; '
+ 'the same\n'
+ ' precedence applies.\n'
+ '\n'
+ '[6] The power operator "**" binds less tightly than an '
+ 'arithmetic\n'
+ ' or bitwise unary operator on its right, that is, '
+ '"2**-1" is "0.5".\n',
+ 'pass': '\n'
+ 'The "pass" statement\n'
+ '********************\n'
+ '\n'
+ ' pass_stmt ::= "pass"\n'
+ '\n'
+ '"pass" is a null operation --- when it is executed, nothing '
+ 'happens.\n'
+ 'It is useful as a placeholder when a statement is required\n'
+ 'syntactically, 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': '\n'
+ 'The power operator\n'
+ '******************\n'
+ '\n'
+ 'The power operator binds more tightly than unary operators on its\n'
+ 'left; it binds less tightly than unary operators on its right. '
+ 'The\n'
+ 'syntax is:\n'
+ '\n'
+ ' power ::= ( await_expr | primary ) ["**" u_expr]\n'
+ '\n'
+ 'Thus, in an unparenthesized sequence of power and unary operators, '
+ 'the\n'
+ 'operators are evaluated from right to left (this does not '
+ 'constrain\n'
+ 'the evaluation order for the operands): "-1**2" results in "-1".\n'
+ '\n'
+ 'The power operator has the same semantics as the built-in "pow()"\n'
+ 'function, when called with two arguments: it yields its left '
+ 'argument\n'
+ 'raised to the power of its right argument. The numeric arguments '
+ 'are\n'
+ 'first converted to a common type, and the result is of that type.\n'
+ '\n'
+ 'For int operands, the result has the same type as the operands '
+ 'unless\n'
+ 'the second argument is negative; in that case, all arguments are\n'
+ 'converted to float and a float result is delivered. For example,\n'
+ '"10**2" returns "100", but "10**-2" returns "0.01".\n'
+ '\n'
+ 'Raising "0.0" to a negative power results in a '
+ '"ZeroDivisionError".\n'
+ 'Raising a negative number to a fractional power results in a '
+ '"complex"\n'
+ 'number. (In earlier versions it raised a "ValueError".)\n',
+ 'raise': '\n'
+ 'The "raise" statement\n'
+ '*********************\n'
+ '\n'
+ ' raise_stmt ::= "raise" [expression ["from" expression]]\n'
+ '\n'
+ 'If no expressions are present, "raise" re-raises the last '
+ 'exception\n'
+ 'that was active in the current scope. If no exception is active '
+ 'in\n'
+ 'the current scope, a "RuntimeError" exception is raised indicating\n'
+ 'that this is an error.\n'
+ '\n'
+ 'Otherwise, "raise" evaluates the first expression as the exception\n'
+ 'object. It must be either a subclass or an instance of\n'
+ '"BaseException". If it is a class, the exception instance will be\n'
+ 'obtained when needed by instantiating the class with no arguments.\n'
+ '\n'
+ "The *type* of the exception is the exception instance's class, the\n"
+ '*value* is the instance itself.\n'
+ '\n'
+ 'A traceback object is normally created automatically when an '
+ 'exception\n'
+ 'is raised and attached to it as the "__traceback__" attribute, '
+ 'which\n'
+ 'is writable. You can create an exception and set your own traceback '
+ 'in\n'
+ 'one step using the "with_traceback()" exception method (which '
+ 'returns\n'
+ 'the same exception instance, with its traceback set to its '
+ 'argument),\n'
+ 'like so:\n'
+ '\n'
+ ' raise Exception("foo occurred").with_traceback(tracebackobj)\n'
+ '\n'
+ 'The "from" clause is used for exception chaining: if given, the '
+ 'second\n'
+ '*expression* must be another exception class or instance, which '
+ 'will\n'
+ 'then be attached to the raised exception as the "__cause__" '
+ 'attribute\n'
+ '(which is writable). If the raised exception is not handled, both\n'
+ '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 "<stdin>", line 2, in <module>\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 "<stdin>", line 4, in <module>\n'
+ ' RuntimeError: Something bad happened\n'
+ '\n'
+ 'A similar mechanism works implicitly if an exception is raised '
+ 'inside\n'
+ 'an exception handler or a "finally" clause: the previous exception '
+ 'is\n'
+ 'then attached as the new 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 "<stdin>", line 2, in <module>\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 "<stdin>", line 4, in <module>\n'
+ ' RuntimeError: Something bad happened\n'
+ '\n'
+ 'Additional information on exceptions can be found in section\n'
+ 'Exceptions, and information about handling exceptions is in '
+ 'section\n'
+ 'The try statement.\n',
+ 'return': '\n'
+ 'The "return" statement\n'
+ '**********************\n'
+ '\n'
+ ' return_stmt ::= "return" [expression_list]\n'
+ '\n'
+ '"return" may only occur syntactically nested in a function '
+ 'definition,\n'
+ 'not within a nested class definition.\n'
+ '\n'
+ 'If an expression list is present, it is evaluated, else "None" is\n'
+ 'substituted.\n'
+ '\n'
+ '"return" leaves the current function call with the expression list '
+ '(or\n'
+ '"None") as return value.\n'
+ '\n'
+ 'When "return" passes control out of a "try" statement with a '
+ '"finally"\n'
+ 'clause, that "finally" clause is executed before really leaving '
+ 'the\n'
+ 'function.\n'
+ '\n'
+ 'In a generator function, the "return" statement indicates that '
+ 'the\n'
+ 'generator is done and will cause "StopIteration" to be raised. '
+ 'The\n'
+ 'returned value (if any) is used as an argument to construct\n'
+ '"StopIteration" and becomes the "StopIteration.value" attribute.\n',
+ 'sequence-types': '\n'
+ 'Emulating container types\n'
+ '*************************\n'
+ '\n'
+ 'The following methods can be defined to implement '
+ 'container objects.\n'
+ 'Containers usually are sequences (such as lists or tuples) '
+ 'or mappings\n'
+ '(like dictionaries), but can represent other containers as '
+ 'well. The\n'
+ 'first set of methods is used either to emulate a sequence '
+ 'or to\n'
+ 'emulate a mapping; the difference is that for a sequence, '
+ 'the\n'
+ 'allowable keys should be the integers *k* for which "0 <= '
+ 'k < N" where\n'
+ '*N* is the length of the sequence, or slice objects, which '
+ 'define a\n'
+ 'range of items. It is also recommended that mappings '
+ 'provide the\n'
+ 'methods "keys()", "values()", "items()", "get()", '
+ '"clear()",\n'
+ '"setdefault()", "pop()", "popitem()", "copy()", and '
+ '"update()"\n'
+ "behaving similar to those for Python's standard dictionary "
+ 'objects.\n'
+ 'The "collections" module provides a "MutableMapping" '
+ 'abstract base\n'
+ 'class to help create those methods from a base set of '
+ '"__getitem__()",\n'
+ '"__setitem__()", "__delitem__()", and "keys()". Mutable '
+ 'sequences\n'
+ 'should provide methods "append()", "count()", "index()", '
+ '"extend()",\n'
+ '"insert()", "pop()", "remove()", "reverse()" and "sort()", '
+ 'like Python\n'
+ 'standard list objects. Finally, sequence types should '
+ 'implement\n'
+ 'addition (meaning concatenation) and multiplication '
+ '(meaning\n'
+ 'repetition) by defining the methods "__add__()", '
+ '"__radd__()",\n'
+ '"__iadd__()", "__mul__()", "__rmul__()" and "__imul__()" '
+ 'described\n'
+ 'below; they should not define other numerical operators. '
+ 'It is\n'
+ 'recommended that both mappings and sequences implement '
+ 'the\n'
+ '"__contains__()" method to allow efficient use of the "in" '
+ 'operator;\n'
+ 'for mappings, "in" should search the mapping\'s keys; for '
+ 'sequences, it\n'
+ 'should search through the values. It is further '
+ 'recommended that both\n'
+ 'mappings and sequences implement the "__iter__()" method '
+ 'to allow\n'
+ 'efficient iteration through the container; for mappings, '
+ '"__iter__()"\n'
+ 'should be the same as "keys()"; for sequences, it should '
+ 'iterate\n'
+ 'through the values.\n'
+ '\n'
+ 'object.__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 that\n'
+ ' doesn\'t define a "__bool__()" method and whose '
+ '"__len__()" method\n'
+ ' returns zero is considered to be false in a Boolean '
+ 'context.\n'
+ '\n'
+ 'object.__length_hint__(self)\n'
+ '\n'
+ ' Called to implement "operator.length_hint()". Should '
+ 'return an\n'
+ ' estimated length for the object (which may be greater '
+ 'or less than\n'
+ ' the actual length). The length must be an integer ">=" '
+ '0. This\n'
+ ' method is purely an optimization and is never required '
+ 'for\n'
+ ' correctness.\n'
+ '\n'
+ ' New in version 3.4.\n'
+ '\n'
+ 'Note: Slicing is done exclusively with the following three '
+ 'methods.\n'
+ ' A 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 "None".\n'
+ '\n'
+ 'object.__getitem__(self, key)\n'
+ '\n'
+ ' Called to implement evaluation of "self[key]". For '
+ 'sequence types,\n'
+ ' the accepted keys should be integers and slice '
+ 'objects. Note that\n'
+ ' the special interpretation of negative indexes (if the '
+ 'class wishes\n'
+ ' to emulate a sequence type) is up to the '
+ '"__getitem__()" method. If\n'
+ ' *key* is of an inappropriate type, "TypeError" may be '
+ 'raised; if of\n'
+ ' a value outside the set of indexes for the sequence '
+ '(after any\n'
+ ' special interpretation of negative values), '
+ '"IndexError" should be\n'
+ ' raised. For mapping types, if *key* is missing (not in '
+ 'the\n'
+ ' container), "KeyError" 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'
+ '\n'
+ 'object.__missing__(self, key)\n'
+ '\n'
+ ' Called by "dict"."__getitem__()" to implement '
+ '"self[key]" for dict\n'
+ ' subclasses when key is not in the dictionary.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__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__()" method.\n'
+ '\n'
+ 'object.__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.\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'
+ '\n'
+ 'object.__reversed__(self)\n'
+ '\n'
+ ' Called (if present) by the "reversed()" built-in to '
+ 'implement\n'
+ ' reverse iteration. It should return a new iterator '
+ 'object that\n'
+ ' iterates over all the objects in the container in '
+ 'reverse order.\n'
+ '\n'
+ ' If the "__reversed__()" method is not provided, the '
+ '"reversed()"\n'
+ ' built-in will fall back to using the sequence protocol '
+ '("__len__()"\n'
+ ' and "__getitem__()"). Objects that support the '
+ 'sequence protocol\n'
+ ' should only provide "__reversed__()" if they can '
+ 'provide an\n'
+ ' implementation that is more efficient than the one '
+ 'provided by\n'
+ ' "reversed()".\n'
+ '\n'
+ 'The membership test operators ("in" and "not in") are '
+ 'normally\n'
+ 'implemented as an iteration through a sequence. However, '
+ 'container\n'
+ 'objects can supply the following special method with a '
+ 'more efficient\n'
+ 'implementation, which also does not require the object be '
+ 'a sequence.\n'
+ '\n'
+ 'object.__contains__(self, item)\n'
+ '\n'
+ ' Called to implement membership test operators. Should '
+ 'return true\n'
+ ' if *item* is in *self*, false otherwise. For mapping '
+ 'objects, this\n'
+ ' should consider the keys of the mapping rather than the '
+ 'values or\n'
+ ' the key-item pairs.\n'
+ '\n'
+ ' For objects that don\'t define "__contains__()", the '
+ 'membership test\n'
+ ' first tries iteration via "__iter__()", then the old '
+ 'sequence\n'
+ ' iteration protocol via "__getitem__()", see this '
+ 'section in the\n'
+ ' language reference.\n',
+ 'shifting': '\n'
+ 'Shifting operations\n'
+ '*******************\n'
+ '\n'
+ 'The shifting operations have lower priority than the arithmetic\n'
+ 'operations:\n'
+ '\n'
+ ' shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr\n'
+ '\n'
+ 'These operators accept integers as arguments. They shift the '
+ 'first\n'
+ 'argument to the left or right by the number of bits given by '
+ 'the\n'
+ 'second argument.\n'
+ '\n'
+ 'A right shift by *n* bits is defined as floor division by '
+ '"pow(2,n)".\n'
+ 'A left shift by *n* bits is defined as multiplication with '
+ '"pow(2,n)".\n'
+ '\n'
+ 'Note: In the current implementation, the right-hand operand is\n'
+ ' required to be at most "sys.maxsize". If the right-hand '
+ 'operand is\n'
+ ' larger than "sys.maxsize" an "OverflowError" exception is '
+ 'raised.\n',
+ 'slicings': '\n'
+ 'Slicings\n'
+ '********\n'
+ '\n'
+ 'A slicing selects a range of items in a sequence object (e.g., '
+ 'a\n'
+ 'string, tuple or list). Slicings may be used as expressions or '
+ 'as\n'
+ 'targets in assignment or "del" statements. The syntax for a '
+ 'slicing:\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'
+ '\n'
+ 'There is ambiguity in the formal syntax here: anything that '
+ 'looks like\n'
+ 'an expression list also looks like a slice list, so any '
+ 'subscription\n'
+ 'can be interpreted as a slicing. Rather than further '
+ 'complicating the\n'
+ 'syntax, this is disambiguated by defining that in this case the\n'
+ 'interpretation as a subscription takes priority over the\n'
+ 'interpretation as a slicing (this is the case if the slice list\n'
+ 'contains no proper slice).\n'
+ '\n'
+ 'The semantics for a slicing are as follows. The primary is '
+ 'indexed\n'
+ '(using the same "__getitem__()" method as normal subscription) '
+ 'with a\n'
+ 'key that is constructed from the slice list, as follows. If the '
+ 'slice\n'
+ 'list contains at least one comma, the key is a tuple containing '
+ 'the\n'
+ 'conversion of the slice items; otherwise, the conversion of the '
+ 'lone\n'
+ 'slice item is the key. The conversion of a slice item that is '
+ 'an\n'
+ 'expression is that expression. The conversion of a proper slice '
+ 'is a\n'
+ 'slice object (see section The standard type hierarchy) whose '
+ '"start",\n'
+ '"stop" and "step" attributes are the values of the expressions '
+ 'given\n'
+ 'as lower bound, upper bound and stride, respectively, '
+ 'substituting\n'
+ '"None" for missing expressions.\n',
+ 'specialattrs': '\n'
+ 'Special Attributes\n'
+ '******************\n'
+ '\n'
+ 'The implementation adds a few special read-only attributes '
+ 'to several\n'
+ 'object types, where they are relevant. Some of these are '
+ 'not reported\n'
+ 'by the "dir()" built-in function.\n'
+ '\n'
+ 'object.__dict__\n'
+ '\n'
+ ' A dictionary or other mapping object used to store an '
+ "object's\n"
+ ' (writable) attributes.\n'
+ '\n'
+ 'instance.__class__\n'
+ '\n'
+ ' The class to which a class instance belongs.\n'
+ '\n'
+ 'class.__bases__\n'
+ '\n'
+ ' The tuple of base classes of a class object.\n'
+ '\n'
+ 'definition.__name__\n'
+ '\n'
+ ' The name of the class, function, method, descriptor, or '
+ 'generator\n'
+ ' instance.\n'
+ '\n'
+ 'definition.__qualname__\n'
+ '\n'
+ ' The *qualified name* of the class, function, method, '
+ 'descriptor, or\n'
+ ' generator instance.\n'
+ '\n'
+ ' New in version 3.3.\n'
+ '\n'
+ 'class.__mro__\n'
+ '\n'
+ ' This attribute is a tuple of classes that are considered '
+ 'when\n'
+ ' looking for base classes during method resolution.\n'
+ '\n'
+ 'class.mro()\n'
+ '\n'
+ ' This method can be overridden by a metaclass to customize '
+ 'the\n'
+ ' method resolution order for its instances. It is called '
+ 'at class\n'
+ ' instantiation, and its result is stored in "__mro__".\n'
+ '\n'
+ 'class.__subclasses__()\n'
+ '\n'
+ ' Each class keeps a list of weak references to its '
+ 'immediate\n'
+ ' subclasses. This method returns a list of all those '
+ 'references\n'
+ ' still alive. Example:\n'
+ '\n'
+ ' >>> int.__subclasses__()\n'
+ " [<class 'bool'>]\n"
+ '\n'
+ '-[ Footnotes ]-\n'
+ '\n'
+ '[1] Additional information on these special methods may be '
+ 'found\n'
+ ' in the Python Reference Manual (Basic customization).\n'
+ '\n'
+ '[2] As a consequence, the list "[1, 2]" is considered equal '
+ 'to\n'
+ ' "[1.0, 2.0]", and similarly for tuples.\n'
+ '\n'
+ "[3] They must have since the parser can't tell the type of "
+ 'the\n'
+ ' operands.\n'
+ '\n'
+ '[4] Cased characters are those with general category '
+ 'property\n'
+ ' being one of "Lu" (Letter, uppercase), "Ll" (Letter, '
+ 'lowercase),\n'
+ ' or "Lt" (Letter, titlecase).\n'
+ '\n'
+ '[5] To format only a tuple you should therefore provide a\n'
+ ' singleton tuple whose only element is the tuple to be '
+ 'formatted.\n',
+ 'specialnames': '\n'
+ 'Special method names\n'
+ '********************\n'
+ '\n'
+ 'A class can implement certain operations that are invoked by '
+ 'special\n'
+ 'syntax (such as arithmetic operations or subscripting and '
+ 'slicing) by\n'
+ "defining methods with special names. This is Python's "
+ 'approach to\n'
+ '*operator overloading*, allowing classes to define their own '
+ 'behavior\n'
+ 'with respect to language operators. For instance, if a '
+ 'class defines\n'
+ 'a method named "__getitem__()", and "x" is an instance of '
+ 'this class,\n'
+ 'then "x[i]" is roughly equivalent to "type(x).__getitem__(x, '
+ 'i)".\n'
+ 'Except where mentioned, attempts to execute an operation '
+ 'raise an\n'
+ 'exception when no appropriate method is defined (typically\n'
+ '"AttributeError" or "TypeError").\n'
+ '\n'
+ 'Setting a special method to "None" indicates that the '
+ 'corresponding\n'
+ 'operation is not available. For example, if a class sets '
+ '"__iter__()"\n'
+ 'to "None", the class is not iterable, so calling "iter()" on '
+ 'its\n'
+ 'instances will raise a "TypeError" (without falling back to\n'
+ '"__getitem__()"). [2]\n'
+ '\n'
+ 'When implementing a class that emulates any built-in type, '
+ 'it is\n'
+ 'important that the emulation only be implemented to the '
+ 'degree that it\n'
+ 'makes sense for the object being modelled. For example, '
+ 'some\n'
+ 'sequences may work well with retrieval of individual '
+ 'elements, but\n'
+ 'extracting a slice may not make sense. (One example of this '
+ 'is the\n'
+ '"NodeList" interface in the W3C\'s Document Object Model.)\n'
+ '\n'
+ '\n'
+ 'Basic customization\n'
+ '===================\n'
+ '\n'
+ 'object.__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 an\n'
+ ' 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'
+ '\n'
+ 'object.__init__(self[, ...])\n'
+ '\n'
+ ' Called after the instance has been created (by '
+ '"__new__()"), but\n'
+ ' before it is returned to the caller. 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, if\n'
+ ' any, must explicitly call it to ensure proper '
+ 'initialization of the\n'
+ ' base class part of the instance; for example:\n'
+ ' "BaseClass.__init__(self, [args...])".\n'
+ '\n'
+ ' Because "__new__()" and "__init__()" work together in '
+ 'constructing\n'
+ ' objects ("__new__()" to create it, and "__init__()" to '
+ 'customize\n'
+ ' it), no non-"None" value may be returned by "__init__()"; '
+ 'doing so\n'
+ ' will cause a "TypeError" to be raised at runtime.\n'
+ '\n'
+ 'object.__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, the\n'
+ ' derived class\'s "__del__()" method, if any, must '
+ 'explicitly call it\n'
+ ' to ensure proper deletion of the base class part of the '
+ 'instance.\n'
+ ' Note that it is possible (though not recommended!) for '
+ 'the\n'
+ ' "__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 is\n'
+ ' only called when "x"\'s reference count reaches zero. '
+ 'Some common\n'
+ ' situations that may prevent the reference count of an '
+ 'object from\n'
+ ' going to zero include: circular references between '
+ 'objects (e.g.,\n'
+ ' a doubly-linked list or a tree data structure with '
+ 'parent and\n'
+ ' child pointers); a reference to the object on the stack '
+ 'frame of\n'
+ ' a function that caught an exception (the traceback '
+ 'stored in\n'
+ ' "sys.exc_info()[2]" keeps the stack frame alive); or a '
+ 'reference\n'
+ ' to the object on the stack frame that raised an '
+ 'unhandled\n'
+ ' 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 second can be resolved by freeing the reference to '
+ 'the\n'
+ ' traceback object when it is no longer useful, and the '
+ 'third can\n'
+ ' be resolved by storing "None" in "sys.last_traceback". '
+ 'Circular\n'
+ ' references which are garbage are detected and cleaned '
+ 'up when the\n'
+ " cyclic garbage collector is enabled (it's on by "
+ 'default). Refer\n'
+ ' to the documentation for the "gc" module for more '
+ 'information\n'
+ ' about this topic.\n'
+ '\n'
+ ' Warning: Due to the precarious circumstances under which\n'
+ ' "__del__()" methods are invoked, exceptions that occur '
+ 'during\n'
+ ' their execution are ignored, and a warning is printed '
+ 'to\n'
+ ' "sys.stderr" instead. Also, when "__del__()" is invoked '
+ 'in\n'
+ ' response to a module being deleted (e.g., when '
+ 'execution of the\n'
+ ' program is done), other globals referenced by the '
+ '"__del__()"\n'
+ ' method may already have been deleted or in the process '
+ 'of being\n'
+ ' torn down (e.g. the import machinery shutting down). '
+ 'For this\n'
+ ' reason, "__del__()" methods should do the absolute '
+ 'minimum needed\n'
+ ' to maintain external invariants. Starting with version '
+ '1.5,\n'
+ ' Python guarantees that globals whose name begins with a '
+ 'single\n'
+ ' underscore are deleted from their module before other '
+ 'globals are\n'
+ ' deleted; if no other references to such globals exist, '
+ 'this may\n'
+ ' help in assuring that imported modules are still '
+ 'available at the\n'
+ ' time when the "__del__()" method is called.\n'
+ '\n'
+ 'object.__repr__(self)\n'
+ '\n'
+ ' Called by the "repr()" built-in function to compute the '
+ '"official"\n'
+ ' string representation of an object. If at all possible, '
+ 'this\n'
+ ' should look like a valid Python expression that could be '
+ 'used to\n'
+ ' recreate an object with the same value (given an '
+ 'appropriate\n'
+ ' environment). If this is not possible, a string of the '
+ 'form\n'
+ ' "<...some useful description...>" should be returned. The '
+ 'return\n'
+ ' value must be a string object. If a class defines '
+ '"__repr__()" but\n'
+ ' not "__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'
+ '\n'
+ 'object.__str__(self)\n'
+ '\n'
+ ' Called by "str(object)" and the built-in functions '
+ '"format()" and\n'
+ ' "print()" to compute the "informal" or nicely printable '
+ 'string\n'
+ ' representation of an object. The return value must be a '
+ 'string\n'
+ ' object.\n'
+ '\n'
+ ' This method differs from "object.__repr__()" in that '
+ 'there is no\n'
+ ' expectation that "__str__()" return a valid Python '
+ 'expression: a\n'
+ ' more convenient or concise representation can be used.\n'
+ '\n'
+ ' The default implementation defined by the built-in type '
+ '"object"\n'
+ ' calls "object.__repr__()".\n'
+ '\n'
+ 'object.__bytes__(self)\n'
+ '\n'
+ ' Called by "bytes()" to compute a byte-string '
+ 'representation of an\n'
+ ' object. This should return a "bytes" object.\n'
+ '\n'
+ 'object.__format__(self, format_spec)\n'
+ '\n'
+ ' Called by the "format()" built-in function, and by '
+ 'extension,\n'
+ ' evaluation of formatted string literals and the '
+ '"str.format()"\n'
+ ' method, to produce a "formatted" string representation of '
+ 'an\n'
+ ' object. The "format_spec" argument is a string that '
+ 'contains a\n'
+ ' description of the formatting options desired. The '
+ 'interpretation\n'
+ ' of the "format_spec" argument is up to the type '
+ 'implementing\n'
+ ' "__format__()", however most classes will either '
+ 'delegate\n'
+ ' formatting to one of the built-in types, or use a '
+ 'similar\n'
+ ' 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'
+ '\n'
+ ' Changed in version 3.4: The __format__ method of "object" '
+ 'itself\n'
+ ' raises a "TypeError" if passed any non-empty string.\n'
+ '\n'
+ 'object.__lt__(self, other)\n'
+ 'object.__le__(self, other)\n'
+ 'object.__eq__(self, other)\n'
+ 'object.__ne__(self, other)\n'
+ 'object.__gt__(self, other)\n'
+ 'object.__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: "x<y" calls "x.__lt__(y)", "x<=y" calls '
+ '"x.__le__(y)",\n'
+ ' "x==y" calls "x.__eq__(y)", "x!=y" calls "x.__ne__(y)", '
+ '"x>y" calls\n'
+ ' "x.__gt__(y)", and "x>=y" calls "x.__ge__(y)".\n'
+ '\n'
+ ' A rich comparison method may return the singleton '
+ '"NotImplemented"\n'
+ ' if it does not implement the operation for a given pair '
+ 'of\n'
+ ' arguments. By convention, "False" and "True" are returned '
+ 'for a\n'
+ ' successful comparison. However, these methods can return '
+ 'any value,\n'
+ ' so if the comparison operator is used in a Boolean '
+ 'context (e.g.,\n'
+ ' in the condition of an "if" statement), Python will call '
+ '"bool()"\n'
+ ' on the value to determine if the result is true or '
+ 'false.\n'
+ '\n'
+ ' By default, "__ne__()" delegates to "__eq__()" and '
+ 'inverts the\n'
+ ' result unless it is "NotImplemented". There are no other '
+ 'implied\n'
+ ' relationships among the comparison operators, for '
+ 'example, the\n'
+ ' truth of "(x<y or x==y)" does not imply "x<=y". To '
+ 'automatically\n'
+ ' generate ordering operations from a single root '
+ 'operation, see\n'
+ ' "functools.total_ordering()".\n'
+ '\n'
+ ' See 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 other's\n"
+ ' reflection, "__le__()" and "__ge__()" are each other\'s '
+ 'reflection,\n'
+ ' and "__eq__()" and "__ne__()" are their own reflection. '
+ 'If the\n'
+ " operands are of different types, and right operand's type "
+ 'is a\n'
+ " direct or indirect subclass of the left operand's type, "
+ 'the\n'
+ ' reflected method of the right operand has priority, '
+ 'otherwise the\n'
+ " left operand's method has priority. Virtual subclassing "
+ 'is not\n'
+ ' considered.\n'
+ '\n'
+ 'object.__hash__(self)\n'
+ '\n'
+ ' Called by built-in function "hash()" and for operations '
+ 'on members\n'
+ ' of hashed collections including "set", "frozenset", and '
+ '"dict".\n'
+ ' "__hash__()" should return an integer. 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'
+ ' Note: "hash()" truncates the value returned from an '
+ "object's\n"
+ ' custom "__hash__()" method to the size of a '
+ '"Py_ssize_t". This\n'
+ ' is typically 8 bytes on 64-bit builds and 4 bytes on '
+ '32-bit\n'
+ ' builds. If an object\'s "__hash__()" must '
+ 'interoperate on builds\n'
+ ' of different bit sizes, be sure to check the width on '
+ 'all\n'
+ ' supported builds. An easy way to do this is with '
+ '"python -c\n'
+ ' "import sys; print(sys.hash_info.width)"".\n'
+ '\n'
+ ' If a class does not define an "__eq__()" method it should '
+ 'not\n'
+ ' define a "__hash__()" operation either; if it defines '
+ '"__eq__()"\n'
+ ' but not "__hash__()", its instances will not be usable as '
+ 'items in\n'
+ ' hashable collections. If a class defines mutable objects '
+ 'and\n'
+ ' implements an "__eq__()" method, it should not implement\n'
+ ' "__hash__()", since the implementation of hashable '
+ 'collections\n'
+ " requires that a key's hash value is immutable (if the "
+ "object's hash\n"
+ ' value changes, it will be in the wrong hash bucket).\n'
+ '\n'
+ ' User-defined classes have "__eq__()" and "__hash__()" '
+ 'methods by\n'
+ ' default; with them, all objects compare unequal (except '
+ 'with\n'
+ ' themselves) and "x.__hash__()" returns an appropriate '
+ 'value such\n'
+ ' that "x == y" implies both that "x is y" and "hash(x) == '
+ 'hash(y)".\n'
+ '\n'
+ ' A class that overrides "__eq__()" and does not define '
+ '"__hash__()"\n'
+ ' will have its "__hash__()" implicitly set to "None". '
+ 'When the\n'
+ ' "__hash__()" method of a class is "None", instances of '
+ 'the class\n'
+ ' will raise an appropriate "TypeError" when a program '
+ 'attempts to\n'
+ ' retrieve their hash value, and will also be correctly '
+ 'identified as\n'
+ ' unhashable when checking "isinstance(obj, '
+ 'collections.Hashable)".\n'
+ '\n'
+ ' If a class that overrides "__eq__()" needs to retain the\n'
+ ' implementation of "__hash__()" from a parent class, the '
+ 'interpreter\n'
+ ' must be told this explicitly by setting "__hash__ =\n'
+ ' <ParentClass>.__hash__".\n'
+ '\n'
+ ' If a class that does not override "__eq__()" wishes to '
+ 'suppress\n'
+ ' hash support, it should include "__hash__ = None" in the '
+ 'class\n'
+ ' definition. A class which defines its own "__hash__()" '
+ 'that\n'
+ ' explicitly raises a "TypeError" would be incorrectly '
+ 'identified as\n'
+ ' hashable by an "isinstance(obj, collections.Hashable)" '
+ 'call.\n'
+ '\n'
+ ' Note: By default, the "__hash__()" values of str, bytes '
+ 'and\n'
+ ' datetime objects are "salted" with an unpredictable '
+ 'random value.\n'
+ ' Although they remain constant within an individual '
+ 'Python\n'
+ ' process, they are not predictable between repeated '
+ 'invocations of\n'
+ ' Python.This is intended to provide protection against a '
+ 'denial-\n'
+ ' of-service caused by carefully-chosen inputs that '
+ 'exploit the\n'
+ ' worst case performance of a dict insertion, O(n^2) '
+ 'complexity.\n'
+ ' See http://www.ocert.org/advisories/ocert-2011-003.html '
+ 'for\n'
+ ' details.Changing hash values affects the iteration '
+ 'order of\n'
+ ' dicts, sets and other mappings. Python has never made '
+ 'guarantees\n'
+ ' about this ordering (and it typically varies between '
+ '32-bit and\n'
+ ' 64-bit builds).See also "PYTHONHASHSEED".\n'
+ '\n'
+ ' Changed in version 3.3: Hash randomization is enabled by '
+ 'default.\n'
+ '\n'
+ 'object.__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 is not\n'
+ ' defined, "__len__()" is called, if it is defined, and the '
+ 'object is\n'
+ ' considered true if its result is nonzero. If a class '
+ 'defines\n'
+ ' neither "__len__()" nor "__bool__()", all its instances '
+ 'are\n'
+ ' considered true.\n'
+ '\n'
+ '\n'
+ 'Customizing attribute access\n'
+ '============================\n'
+ '\n'
+ 'The following methods can be defined to customize the '
+ 'meaning of\n'
+ 'attribute access (use of, assignment to, or deletion of '
+ '"x.name") for\n'
+ 'class instances.\n'
+ '\n'
+ 'object.__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. This\n'
+ ' method should return the (computed) attribute value or '
+ 'raise an\n'
+ ' "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 for\n'
+ ' efficiency reasons and because otherwise "__getattr__()" '
+ 'would have\n'
+ ' no way to access other attributes of the instance. Note '
+ 'that at\n'
+ ' least for instance variables, you can fake total control '
+ 'by not\n'
+ ' 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'
+ '\n'
+ 'object.__getattribute__(self, name)\n'
+ '\n'
+ ' Called unconditionally to implement attribute accesses '
+ 'for\n'
+ ' instances of the class. If the class also defines '
+ '"__getattr__()",\n'
+ ' the latter will not be called unless "__getattribute__()" '
+ 'either\n'
+ ' calls it explicitly or raises an "AttributeError". This '
+ 'method\n'
+ ' should return the (computed) attribute value or raise an\n'
+ ' "AttributeError" exception. In order to avoid infinite '
+ 'recursion in\n'
+ ' this method, its implementation should always call the '
+ 'base class\n'
+ ' method with the same name to access any attributes it '
+ 'needs, for\n'
+ ' example, "object.__getattribute__(self, name)".\n'
+ '\n'
+ ' Note: This method may still be bypassed when looking up '
+ 'special\n'
+ ' methods as the result of implicit invocation via '
+ 'language syntax\n'
+ ' or built-in functions. See Special method lookup.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__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'
+ 'object.__dir__(self)\n'
+ '\n'
+ ' Called when "dir()" is called on the object. A sequence '
+ 'must be\n'
+ ' returned. "dir()" converts the returned sequence to a '
+ 'list and\n'
+ ' sorts it.\n'
+ '\n'
+ '\n'
+ 'Implementing Descriptors\n'
+ '------------------------\n'
+ '\n'
+ 'The following methods only apply when an instance of the '
+ 'class\n'
+ 'containing the method (a so-called *descriptor* class) '
+ 'appears in an\n'
+ "*owner* class (the descriptor must be in either the owner's "
+ 'class\n'
+ 'dictionary or in the class dictionary for one of its '
+ 'parents). In the\n'
+ 'examples below, "the attribute" refers to the attribute '
+ 'whose name is\n'
+ 'the key of the property in the owner class\' "__dict__".\n'
+ '\n'
+ 'object.__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 '
+ '"AttributeError"\n'
+ ' exception.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__delete__(self, instance)\n'
+ '\n'
+ ' Called to delete the attribute on an instance *instance* '
+ 'of the\n'
+ ' owner class.\n'
+ '\n'
+ 'object.__set_name__(self, owner, name)\n'
+ '\n'
+ ' Called at the time the owning class *owner* is created. '
+ 'The\n'
+ ' descriptor has been assigned to *name*.\n'
+ '\n'
+ ' New in version 3.6.\n'
+ '\n'
+ 'The attribute "__objclass__" is interpreted by the "inspect" '
+ 'module as\n'
+ 'specifying the class where this object was defined (setting '
+ 'this\n'
+ 'appropriately can assist in runtime introspection of dynamic '
+ 'class\n'
+ 'attributes). For callables, it may indicate that an instance '
+ 'of the\n'
+ 'given type (or a subclass) is expected or required as the '
+ 'first\n'
+ 'positional argument (for example, CPython sets this '
+ 'attribute for\n'
+ 'unbound methods that are implemented in C).\n'
+ '\n'
+ '\n'
+ 'Invoking Descriptors\n'
+ '--------------------\n'
+ '\n'
+ 'In general, a descriptor is an object attribute with '
+ '"binding\n'
+ 'behavior", one whose attribute access has been overridden by '
+ 'methods\n'
+ 'in the descriptor protocol: "__get__()", "__set__()", and\n'
+ '"__delete__()". If any of those methods are defined for an '
+ 'object, it\n'
+ 'is said to be a descriptor.\n'
+ '\n'
+ 'The default behavior for attribute access is to get, set, or '
+ 'delete\n'
+ "the attribute from an object's dictionary. For instance, "
+ '"a.x" has a\n'
+ 'lookup 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'
+ '\n'
+ 'However, if the looked-up value is an object defining one of '
+ 'the\n'
+ 'descriptor methods, then Python may override the default '
+ 'behavior and\n'
+ 'invoke the descriptor method instead. Where this occurs in '
+ 'the\n'
+ 'precedence chain depends on which descriptor methods were '
+ 'defined and\n'
+ 'how they were called.\n'
+ '\n'
+ 'The starting point for descriptor invocation is a binding, '
+ '"a.x". How\n'
+ 'the arguments are assembled depends on "a":\n'
+ '\n'
+ 'Direct Call\n'
+ ' The simplest and least common call is when user code '
+ 'directly\n'
+ ' invokes a descriptor method: "x.__get__(a)".\n'
+ '\n'
+ 'Instance 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'
+ '\n'
+ 'Class Binding\n'
+ ' If binding to a class, "A.x" is transformed into the '
+ 'call:\n'
+ ' "A.__dict__[\'x\'].__get__(None, A)".\n'
+ '\n'
+ 'Super 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 "A"\n'
+ ' immediately preceding "B" and then invokes the descriptor '
+ 'with the\n'
+ ' call: "A.__dict__[\'m\'].__get__(obj, obj.__class__)".\n'
+ '\n'
+ 'For instance bindings, the precedence of descriptor '
+ 'invocation depends\n'
+ 'on the which descriptor methods are defined. A descriptor '
+ 'can define\n'
+ 'any combination of "__get__()", "__set__()" and '
+ '"__delete__()". If it\n'
+ 'does not define "__get__()", then accessing the attribute '
+ 'will return\n'
+ 'the descriptor object itself unless there is a value in the '
+ "object's\n"
+ 'instance dictionary. If the descriptor defines "__set__()" '
+ 'and/or\n'
+ '"__delete__()", it is a data descriptor; if it defines '
+ 'neither, it is\n'
+ 'a non-data descriptor. Normally, data descriptors define '
+ 'both\n'
+ '"__get__()" and "__set__()", while non-data descriptors have '
+ 'just the\n'
+ '"__get__()" method. Data descriptors with "__set__()" and '
+ '"__get__()"\n'
+ 'defined always override a redefinition in an instance '
+ 'dictionary. In\n'
+ 'contrast, non-data descriptors can be overridden by '
+ 'instances.\n'
+ '\n'
+ 'Python methods (including "staticmethod()" and '
+ '"classmethod()") are\n'
+ 'implemented as non-data descriptors. Accordingly, instances '
+ 'can\n'
+ 'redefine and override methods. This allows individual '
+ 'instances to\n'
+ 'acquire behaviors that differ from other instances of the '
+ 'same class.\n'
+ '\n'
+ 'The "property()" function is implemented as a data '
+ 'descriptor.\n'
+ 'Accordingly, instances cannot override the behavior of a '
+ 'property.\n'
+ '\n'
+ '\n'
+ '__slots__\n'
+ '---------\n'
+ '\n'
+ 'By default, instances of classes have a dictionary for '
+ 'attribute\n'
+ 'storage. This wastes space for objects having very few '
+ 'instance\n'
+ 'variables. The space consumption can become acute when '
+ 'creating large\n'
+ 'numbers of instances.\n'
+ '\n'
+ 'The default can be overridden by defining *__slots__* in a '
+ 'class\n'
+ 'definition. The *__slots__* declaration takes a sequence of '
+ 'instance\n'
+ 'variables and reserves just enough space in each instance to '
+ 'hold a\n'
+ 'value for each variable. Space is saved because *__dict__* '
+ 'is not\n'
+ 'created for each instance.\n'
+ '\n'
+ 'object.__slots__\n'
+ '\n'
+ ' This class variable can be assigned a string, iterable, '
+ 'or sequence\n'
+ ' of strings with variable names used by instances. '
+ '*__slots__*\n'
+ ' reserves space for the declared variables and prevents '
+ 'the\n'
+ ' automatic creation of *__dict__* and *__weakref__* for '
+ 'each\n'
+ ' instance.\n'
+ '\n'
+ '\n'
+ 'Notes 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\n'
+ ' defining *__slots__* do not support weak references to '
+ 'its\n'
+ ' instances. If weak reference support is needed, then add\n'
+ ' "\'__weakref__\'" to the sequence of strings in the '
+ '*__slots__*\n'
+ ' declaration.\n'
+ '\n'
+ '* *__slots__* are implemented at the class level by '
+ 'creating\n'
+ ' descriptors (Implementing Descriptors) for each variable '
+ 'name. As a\n'
+ ' result, class attributes cannot be used to set default '
+ 'values for\n'
+ ' instance variables defined by *__slots__*; otherwise, the '
+ 'class\n'
+ ' attribute would overwrite the descriptor assignment.\n'
+ '\n'
+ '* The action of a *__slots__* declaration is limited to the '
+ 'class\n'
+ ' where it is defined. As a result, subclasses will have a '
+ '*__dict__*\n'
+ ' unless they also define *__slots__* (which must only '
+ 'contain names\n'
+ ' of any *additional* slots).\n'
+ '\n'
+ '* If a class defines a slot also defined in a base class, '
+ 'the\n'
+ ' instance variable defined by the base class slot is '
+ 'inaccessible\n'
+ ' (except by retrieving its descriptor directly from the '
+ 'base class).\n'
+ ' This renders the meaning of the program undefined. In the '
+ 'future, a\n'
+ ' check may be added to prevent this.\n'
+ '\n'
+ '* Nonempty *__slots__* does not work for classes derived '
+ 'from\n'
+ ' "variable-length" built-in types such as "int", "bytes" '
+ 'and "tuple".\n'
+ '\n'
+ '* Any non-string iterable may be assigned to *__slots__*. '
+ 'Mappings\n'
+ ' may 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'
+ '\n'
+ 'Customizing class creation\n'
+ '==========================\n'
+ '\n'
+ 'Whenever a class inherits from another class, '
+ '*__init_subclass__* is\n'
+ 'called on that class. This way, it is possible to write '
+ 'classes which\n'
+ 'change the behavior of subclasses. This is closely related '
+ 'to class\n'
+ 'decorators, but where class decorators only affect the '
+ 'specific class\n'
+ 'they\'re applied to, "__init_subclass__" solely applies to '
+ 'future\n'
+ 'subclasses of the class defining the method.\n'
+ '\n'
+ 'classmethod object.__init_subclass__(cls)\n'
+ '\n'
+ ' This method is called whenever the containing class is '
+ 'subclassed.\n'
+ ' *cls* is then the new subclass. If defined as a normal '
+ 'instance\n'
+ ' method, this method is implicitly converted to a class '
+ 'method.\n'
+ '\n'
+ ' Keyword arguments which are given to a new class are '
+ 'passed to the\n'
+ ' parent\'s class "__init_subclass__". For compatibility '
+ 'with other\n'
+ ' classes using "__init_subclass__", one should take out '
+ 'the needed\n'
+ ' keyword arguments and pass the others over to the base '
+ 'class, as\n'
+ ' in:\n'
+ '\n'
+ ' class Philosopher:\n'
+ ' def __init_subclass__(cls, default_name, '
+ '**kwargs):\n'
+ ' super().__init_subclass__(**kwargs)\n'
+ ' cls.default_name = default_name\n'
+ '\n'
+ ' class AustralianPhilosopher(Philosopher, '
+ 'default_name="Bruce"):\n'
+ ' pass\n'
+ '\n'
+ ' The default implementation "object.__init_subclass__" '
+ 'does nothing,\n'
+ ' but raises an error if it is called with any arguments.\n'
+ '\n'
+ ' Note: The metaclass hint "metaclass" is consumed by the '
+ 'rest of\n'
+ ' the type machinery, and is never passed to '
+ '"__init_subclass__"\n'
+ ' implementations. The actual metaclass (rather than the '
+ 'explicit\n'
+ ' hint) can be accessed as "type(cls)".\n'
+ '\n'
+ ' New in version 3.6.\n'
+ '\n'
+ '\n'
+ 'Metaclasses\n'
+ '-----------\n'
+ '\n'
+ 'By default, classes are constructed using "type()". The '
+ 'class body is\n'
+ 'executed in a new namespace and the class name is bound '
+ 'locally to the\n'
+ 'result of "type(name, bases, namespace)".\n'
+ '\n'
+ 'The class creation process can be customized by passing the\n'
+ '"metaclass" keyword argument in the class definition line, '
+ 'or by\n'
+ 'inheriting from an existing class that included such an '
+ 'argument. In\n'
+ 'the following example, both "MyClass" and "MySubclass" are '
+ 'instances\n'
+ 'of "Meta":\n'
+ '\n'
+ ' class Meta(type):\n'
+ ' pass\n'
+ '\n'
+ ' class MyClass(metaclass=Meta):\n'
+ ' pass\n'
+ '\n'
+ ' class MySubclass(MyClass):\n'
+ ' pass\n'
+ '\n'
+ 'Any other keyword arguments that are specified in the class '
+ 'definition\n'
+ 'are passed through to all metaclass operations described '
+ 'below.\n'
+ '\n'
+ 'When a class definition is executed, the following steps '
+ 'occur:\n'
+ '\n'
+ '* the appropriate metaclass is determined\n'
+ '\n'
+ '* the class namespace is prepared\n'
+ '\n'
+ '* the class body is executed\n'
+ '\n'
+ '* the class object is created\n'
+ '\n'
+ '\n'
+ 'Determining the appropriate metaclass\n'
+ '-------------------------------------\n'
+ '\n'
+ 'The appropriate metaclass for a class definition is '
+ 'determined as\n'
+ 'follows:\n'
+ '\n'
+ '* if no bases and no explicit metaclass are given, then '
+ '"type()" is\n'
+ ' used\n'
+ '\n'
+ '* if an explicit metaclass is given and it is *not* an '
+ 'instance of\n'
+ ' "type()", then it is used directly as the metaclass\n'
+ '\n'
+ '* if an instance of "type()" is given as the explicit '
+ 'metaclass, or\n'
+ ' bases are defined, then the most derived metaclass is '
+ 'used\n'
+ '\n'
+ 'The most derived metaclass is selected from the explicitly '
+ 'specified\n'
+ 'metaclass (if any) and the metaclasses (i.e. "type(cls)") of '
+ 'all\n'
+ 'specified base classes. The most derived metaclass is one '
+ 'which is a\n'
+ 'subtype of *all* of these candidate metaclasses. If none of '
+ 'the\n'
+ 'candidate metaclasses meets that criterion, then the class '
+ 'definition\n'
+ 'will fail with "TypeError".\n'
+ '\n'
+ '\n'
+ 'Preparing the class namespace\n'
+ '-----------------------------\n'
+ '\n'
+ 'Once the appropriate metaclass has been identified, then the '
+ 'class\n'
+ 'namespace is prepared. If the metaclass has a "__prepare__" '
+ 'attribute,\n'
+ 'it is called as "namespace = metaclass.__prepare__(name, '
+ 'bases,\n'
+ '**kwds)" (where the additional keyword arguments, if any, '
+ 'come from\n'
+ 'the class definition).\n'
+ '\n'
+ 'If the metaclass has no "__prepare__" attribute, then the '
+ 'class\n'
+ 'namespace is initialised as an empty ordered mapping.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 3115** - Metaclasses in Python 3000\n'
+ ' Introduced the "__prepare__" namespace hook\n'
+ '\n'
+ '\n'
+ 'Executing the class body\n'
+ '------------------------\n'
+ '\n'
+ 'The class body is executed (approximately) as "exec(body, '
+ 'globals(),\n'
+ 'namespace)". The key difference from a normal call to '
+ '"exec()" is that\n'
+ 'lexical scoping allows the class body (including any '
+ 'methods) to\n'
+ 'reference names from the current and outer scopes when the '
+ 'class\n'
+ 'definition occurs inside a function.\n'
+ '\n'
+ 'However, even when the class definition occurs inside the '
+ 'function,\n'
+ 'methods defined inside the class still cannot see names '
+ 'defined at the\n'
+ 'class scope. Class variables must be accessed through the '
+ 'first\n'
+ 'parameter of instance or class methods, and cannot be '
+ 'accessed at all\n'
+ 'from static methods.\n'
+ '\n'
+ '\n'
+ 'Creating the class object\n'
+ '-------------------------\n'
+ '\n'
+ 'Once the class namespace has been populated by executing the '
+ 'class\n'
+ 'body, the class object is created by calling '
+ '"metaclass(name, bases,\n'
+ 'namespace, **kwds)" (the additional keywords passed here are '
+ 'the same\n'
+ 'as those passed to "__prepare__").\n'
+ '\n'
+ 'This class object is the one that will be referenced by the '
+ 'zero-\n'
+ 'argument form of "super()". "__class__" is an implicit '
+ 'closure\n'
+ 'reference created by the compiler if any methods in a class '
+ 'body refer\n'
+ 'to either "__class__" or "super". This allows the zero '
+ 'argument form\n'
+ 'of "super()" to correctly identify the class being defined '
+ 'based on\n'
+ 'lexical scoping, while the class or instance that was used '
+ 'to make the\n'
+ 'current call is identified based on the first argument '
+ 'passed to the\n'
+ 'method.\n'
+ '\n'
+ 'After the class object is created, it is passed to the '
+ 'class\n'
+ 'decorators included in the class definition (if any) and the '
+ 'resulting\n'
+ 'object is bound in the local namespace as the defined '
+ 'class.\n'
+ '\n'
+ 'When a new class is created by "type.__new__", the object '
+ 'provided as\n'
+ 'the namespace parameter is copied to a new ordered mapping '
+ 'and the\n'
+ 'original object is discarded. The new copy is wrapped in a '
+ 'read-only\n'
+ 'proxy, which becomes the "__dict__" attribute of the class '
+ 'object.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 3135** - New super\n'
+ ' Describes the implicit "__class__" closure reference\n'
+ '\n'
+ '\n'
+ 'Metaclass example\n'
+ '-----------------\n'
+ '\n'
+ 'The potential uses for metaclasses are boundless. Some ideas '
+ 'that have\n'
+ 'been explored include logging, interface checking, '
+ 'automatic\n'
+ 'delegation, automatic property creation, proxies, '
+ 'frameworks, and\n'
+ 'automatic resource locking/synchronization.\n'
+ '\n'
+ 'Here is an example of a metaclass that uses an\n'
+ '"collections.OrderedDict" to remember the order that class '
+ 'variables\n'
+ 'are defined:\n'
+ '\n'
+ ' class OrderedClass(type):\n'
+ '\n'
+ ' @classmethod\n'
+ ' def __prepare__(metacls, name, bases, **kwds):\n'
+ ' return collections.OrderedDict()\n'
+ '\n'
+ ' def __new__(cls, name, bases, namespace, **kwds):\n'
+ ' result = type.__new__(cls, name, bases, '
+ 'dict(namespace))\n'
+ ' result.members = tuple(namespace)\n'
+ ' return result\n'
+ '\n'
+ ' class A(metaclass=OrderedClass):\n'
+ ' def one(self): pass\n'
+ ' def two(self): pass\n'
+ ' def three(self): pass\n'
+ ' def four(self): pass\n'
+ '\n'
+ ' >>> A.members\n'
+ " ('__module__', 'one', 'two', 'three', 'four')\n"
+ '\n'
+ 'When the class definition for *A* gets executed, the process '
+ 'begins\n'
+ 'with calling the metaclass\'s "__prepare__()" method which '
+ 'returns an\n'
+ 'empty "collections.OrderedDict". That mapping records the '
+ 'methods and\n'
+ 'attributes of *A* as they are defined within the body of the '
+ 'class\n'
+ 'statement. Once those definitions are executed, the ordered '
+ 'dictionary\n'
+ 'is fully populated and the metaclass\'s "__new__()" method '
+ 'gets\n'
+ 'invoked. That method builds the new type and it saves the '
+ 'ordered\n'
+ 'dictionary keys in an attribute called "members".\n'
+ '\n'
+ '\n'
+ 'Customizing instance and subclass checks\n'
+ '========================================\n'
+ '\n'
+ 'The following methods are used to override the default '
+ 'behavior of the\n'
+ '"isinstance()" and "issubclass()" built-in functions.\n'
+ '\n'
+ 'In particular, the metaclass "abc.ABCMeta" implements these '
+ 'methods in\n'
+ 'order to allow the addition of Abstract Base Classes (ABCs) '
+ 'as\n'
+ '"virtual base classes" to any class or type (including '
+ 'built-in\n'
+ 'types), including other ABCs.\n'
+ '\n'
+ 'class.__instancecheck__(self, instance)\n'
+ '\n'
+ ' Return true if *instance* should be considered a (direct '
+ 'or\n'
+ ' indirect) instance of *class*. If defined, called to '
+ 'implement\n'
+ ' "isinstance(instance, class)".\n'
+ '\n'
+ 'class.__subclasscheck__(self, subclass)\n'
+ '\n'
+ ' Return true if *subclass* should be considered a (direct '
+ 'or\n'
+ ' indirect) subclass of *class*. If defined, called to '
+ 'implement\n'
+ ' "issubclass(subclass, class)".\n'
+ '\n'
+ 'Note that these methods are looked up on the type '
+ '(metaclass) of a\n'
+ 'class. They cannot be defined as class methods in the '
+ 'actual class.\n'
+ 'This is consistent with the lookup of special methods that '
+ 'are called\n'
+ 'on instances, only in this case the instance is itself a '
+ 'class.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 3119** - Introducing Abstract Base Classes\n'
+ ' Includes the specification for customizing '
+ '"isinstance()" and\n'
+ ' "issubclass()" behavior through "__instancecheck__()" '
+ 'and\n'
+ ' "__subclasscheck__()", with motivation for this '
+ 'functionality in\n'
+ ' the context of adding Abstract Base Classes (see the '
+ '"abc"\n'
+ ' module) to the language.\n'
+ '\n'
+ '\n'
+ 'Emulating callable objects\n'
+ '==========================\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'Emulating container types\n'
+ '=========================\n'
+ '\n'
+ 'The following methods can be defined to implement container '
+ 'objects.\n'
+ 'Containers usually are sequences (such as lists or tuples) '
+ 'or mappings\n'
+ '(like dictionaries), but can represent other containers as '
+ 'well. The\n'
+ 'first set of methods is used either to emulate a sequence or '
+ 'to\n'
+ 'emulate a mapping; the difference is that for a sequence, '
+ 'the\n'
+ 'allowable keys should be the integers *k* for which "0 <= k '
+ '< N" where\n'
+ '*N* is the length of the sequence, or slice objects, which '
+ 'define a\n'
+ 'range of items. It is also recommended that mappings '
+ 'provide the\n'
+ 'methods "keys()", "values()", "items()", "get()", '
+ '"clear()",\n'
+ '"setdefault()", "pop()", "popitem()", "copy()", and '
+ '"update()"\n'
+ "behaving similar to those for Python's standard dictionary "
+ 'objects.\n'
+ 'The "collections" module provides a "MutableMapping" '
+ 'abstract base\n'
+ 'class to help create those methods from a base set of '
+ '"__getitem__()",\n'
+ '"__setitem__()", "__delitem__()", and "keys()". Mutable '
+ 'sequences\n'
+ 'should provide methods "append()", "count()", "index()", '
+ '"extend()",\n'
+ '"insert()", "pop()", "remove()", "reverse()" and "sort()", '
+ 'like Python\n'
+ 'standard list objects. Finally, sequence types should '
+ 'implement\n'
+ 'addition (meaning concatenation) and multiplication '
+ '(meaning\n'
+ 'repetition) by defining the methods "__add__()", '
+ '"__radd__()",\n'
+ '"__iadd__()", "__mul__()", "__rmul__()" and "__imul__()" '
+ 'described\n'
+ 'below; they should not define other numerical operators. It '
+ 'is\n'
+ 'recommended that both mappings and sequences implement the\n'
+ '"__contains__()" method to allow efficient use of the "in" '
+ 'operator;\n'
+ 'for mappings, "in" should search the mapping\'s keys; for '
+ 'sequences, it\n'
+ 'should search through the values. It is further recommended '
+ 'that both\n'
+ 'mappings and sequences implement the "__iter__()" method to '
+ 'allow\n'
+ 'efficient iteration through the container; for mappings, '
+ '"__iter__()"\n'
+ 'should be the same as "keys()"; for sequences, it should '
+ 'iterate\n'
+ 'through the values.\n'
+ '\n'
+ 'object.__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 that\n'
+ ' doesn\'t define a "__bool__()" method and whose '
+ '"__len__()" method\n'
+ ' returns zero is considered to be false in a Boolean '
+ 'context.\n'
+ '\n'
+ 'object.__length_hint__(self)\n'
+ '\n'
+ ' Called to implement "operator.length_hint()". Should '
+ 'return an\n'
+ ' estimated length for the object (which may be greater or '
+ 'less than\n'
+ ' the actual length). The length must be an integer ">=" 0. '
+ 'This\n'
+ ' method is purely an optimization and is never required '
+ 'for\n'
+ ' correctness.\n'
+ '\n'
+ ' New in version 3.4.\n'
+ '\n'
+ 'Note: Slicing is done exclusively with the following three '
+ 'methods.\n'
+ ' A 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 "None".\n'
+ '\n'
+ 'object.__getitem__(self, key)\n'
+ '\n'
+ ' Called to implement evaluation of "self[key]". For '
+ 'sequence types,\n'
+ ' the accepted keys should be integers and slice objects. '
+ 'Note that\n'
+ ' the special interpretation of negative indexes (if the '
+ 'class wishes\n'
+ ' to emulate a sequence type) is up to the "__getitem__()" '
+ 'method. If\n'
+ ' *key* is of an inappropriate type, "TypeError" may be '
+ 'raised; if of\n'
+ ' a value outside the set of indexes for the sequence '
+ '(after any\n'
+ ' special interpretation of negative values), "IndexError" '
+ 'should be\n'
+ ' raised. For mapping types, if *key* is missing (not in '
+ 'the\n'
+ ' container), "KeyError" 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'
+ '\n'
+ 'object.__missing__(self, key)\n'
+ '\n'
+ ' Called by "dict"."__getitem__()" to implement "self[key]" '
+ 'for dict\n'
+ ' subclasses when key is not in the dictionary.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__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__()" method.\n'
+ '\n'
+ 'object.__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.\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'
+ '\n'
+ 'object.__reversed__(self)\n'
+ '\n'
+ ' Called (if present) by the "reversed()" built-in to '
+ 'implement\n'
+ ' reverse iteration. It should return a new iterator '
+ 'object that\n'
+ ' iterates over all the objects in the container in reverse '
+ 'order.\n'
+ '\n'
+ ' If the "__reversed__()" method is not provided, the '
+ '"reversed()"\n'
+ ' built-in will fall back to using the sequence protocol '
+ '("__len__()"\n'
+ ' and "__getitem__()"). Objects that support the sequence '
+ 'protocol\n'
+ ' should only provide "__reversed__()" if they can provide '
+ 'an\n'
+ ' implementation that is more efficient than the one '
+ 'provided by\n'
+ ' "reversed()".\n'
+ '\n'
+ 'The membership test operators ("in" and "not in") are '
+ 'normally\n'
+ 'implemented as an iteration through a sequence. However, '
+ 'container\n'
+ 'objects can supply the following special method with a more '
+ 'efficient\n'
+ 'implementation, which also does not require the object be a '
+ 'sequence.\n'
+ '\n'
+ 'object.__contains__(self, item)\n'
+ '\n'
+ ' Called to implement membership test operators. Should '
+ 'return true\n'
+ ' if *item* is in *self*, false otherwise. For mapping '
+ 'objects, this\n'
+ ' should consider the keys of the mapping rather than the '
+ 'values or\n'
+ ' the key-item pairs.\n'
+ '\n'
+ ' For objects that don\'t define "__contains__()", the '
+ 'membership test\n'
+ ' first tries iteration via "__iter__()", then the old '
+ 'sequence\n'
+ ' iteration protocol via "__getitem__()", see this section '
+ 'in the\n'
+ ' language reference.\n'
+ '\n'
+ '\n'
+ 'Emulating numeric types\n'
+ '=======================\n'
+ '\n'
+ 'The following methods can be defined to emulate numeric '
+ 'objects.\n'
+ 'Methods corresponding to operations that are not supported '
+ 'by the\n'
+ 'particular kind of number implemented (e.g., bitwise '
+ 'operations for\n'
+ 'non-integral numbers) should be left undefined.\n'
+ '\n'
+ 'object.__add__(self, other)\n'
+ 'object.__sub__(self, other)\n'
+ 'object.__mul__(self, other)\n'
+ 'object.__matmul__(self, other)\n'
+ 'object.__truediv__(self, other)\n'
+ 'object.__floordiv__(self, other)\n'
+ 'object.__mod__(self, other)\n'
+ 'object.__divmod__(self, other)\n'
+ 'object.__pow__(self, other[, modulo])\n'
+ 'object.__lshift__(self, other)\n'
+ 'object.__rshift__(self, other)\n'
+ 'object.__and__(self, other)\n'
+ 'object.__xor__(self, other)\n'
+ 'object.__or__(self, other)\n'
+ '\n'
+ ' These methods are called to implement the binary '
+ 'arithmetic\n'
+ ' operations ("+", "-", "*", "@", "/", "//", "%", '
+ '"divmod()",\n'
+ ' "pow()", "**", "<<", ">>", "&", "^", "|"). For instance, '
+ 'to\n'
+ ' evaluate the expression "x + y", where *x* is an instance '
+ 'of a\n'
+ ' class that has an "__add__()" method, "x.__add__(y)" is '
+ 'called.\n'
+ ' The "__divmod__()" method should be the equivalent to '
+ 'using\n'
+ ' "__floordiv__()" and "__mod__()"; it should not be '
+ 'related to\n'
+ ' "__truediv__()". Note that "__pow__()" should be defined '
+ 'to accept\n'
+ ' an optional third argument if the ternary version of the '
+ 'built-in\n'
+ ' "pow()" function 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'
+ '\n'
+ 'object.__radd__(self, other)\n'
+ 'object.__rsub__(self, other)\n'
+ 'object.__rmul__(self, other)\n'
+ 'object.__rmatmul__(self, other)\n'
+ 'object.__rtruediv__(self, other)\n'
+ 'object.__rfloordiv__(self, other)\n'
+ 'object.__rmod__(self, other)\n'
+ 'object.__rdivmod__(self, other)\n'
+ 'object.__rpow__(self, other)\n'
+ 'object.__rlshift__(self, other)\n'
+ 'object.__rrshift__(self, other)\n'
+ 'object.__rand__(self, other)\n'
+ 'object.__rxor__(self, other)\n'
+ 'object.__ror__(self, other)\n'
+ '\n'
+ ' These methods are called to implement the binary '
+ 'arithmetic\n'
+ ' operations ("+", "-", "*", "@", "/", "//", "%", '
+ '"divmod()",\n'
+ ' "pow()", "**", "<<", ">>", "&", "^", "|") with reflected '
+ '(swapped)\n'
+ ' operands. These functions are only called if the left '
+ 'operand does\n'
+ ' not support the corresponding operation [3] and the '
+ 'operands are of\n'
+ ' different types. [4] For instance, to evaluate the '
+ 'expression "x -\n'
+ ' y", where *y* is an instance of a class that has an '
+ '"__rsub__()"\n'
+ ' method, "y.__rsub__(x)" is called if "x.__sub__(y)" '
+ 'returns\n'
+ ' *NotImplemented*.\n'
+ '\n'
+ ' Note that ternary "pow()" will not try calling '
+ '"__rpow__()" (the\n'
+ ' coercion rules would become too complicated).\n'
+ '\n'
+ " Note: If the right operand's type is a subclass of the "
+ 'left\n'
+ " operand's type and that subclass provides the reflected "
+ 'method\n'
+ ' for the operation, this method will be called before '
+ 'the left\n'
+ " operand's non-reflected method. This behavior allows "
+ 'subclasses\n'
+ " to override their ancestors' operations.\n"
+ '\n'
+ 'object.__iadd__(self, other)\n'
+ 'object.__isub__(self, other)\n'
+ 'object.__imul__(self, other)\n'
+ 'object.__imatmul__(self, other)\n'
+ 'object.__itruediv__(self, other)\n'
+ 'object.__ifloordiv__(self, other)\n'
+ 'object.__imod__(self, other)\n'
+ 'object.__ipow__(self, other[, modulo])\n'
+ 'object.__ilshift__(self, other)\n'
+ 'object.__irshift__(self, other)\n'
+ 'object.__iand__(self, other)\n'
+ 'object.__ixor__(self, other)\n'
+ 'object.__ior__(self, other)\n'
+ '\n'
+ ' These methods are called to implement the augmented '
+ 'arithmetic\n'
+ ' assignments ("+=", "-=", "*=", "@=", "/=", "//=", "%=", '
+ '"**=",\n'
+ ' "<<=", ">>=", "&=", "^=", "|="). These methods should '
+ 'attempt to\n'
+ ' do the operation in-place (modifying *self*) and return '
+ 'the result\n'
+ ' (which could be, but does not have to be, *self*). If a '
+ 'specific\n'
+ ' method is not defined, the augmented assignment falls '
+ 'back to the\n'
+ ' normal methods. For instance, if *x* is an instance of a '
+ 'class\n'
+ ' with an "__iadd__()" method, "x += y" is equivalent to "x '
+ '=\n'
+ ' x.__iadd__(y)" . Otherwise, "x.__add__(y)" and '
+ '"y.__radd__(x)" are\n'
+ ' considered, as with the evaluation of "x + y". In '
+ 'certain\n'
+ ' situations, augmented assignment can result in unexpected '
+ 'errors\n'
+ " (see Why does a_tuple[i] += ['item'] raise an exception "
+ 'when the\n'
+ ' addition works?), but this behavior is in fact part of '
+ 'the data\n'
+ ' model.\n'
+ '\n'
+ 'object.__neg__(self)\n'
+ 'object.__pos__(self)\n'
+ 'object.__abs__(self)\n'
+ 'object.__invert__(self)\n'
+ '\n'
+ ' Called to implement the unary arithmetic operations ("-", '
+ '"+",\n'
+ ' "abs()" and "~").\n'
+ '\n'
+ 'object.__complex__(self)\n'
+ 'object.__int__(self)\n'
+ 'object.__float__(self)\n'
+ 'object.__round__(self[, n])\n'
+ '\n'
+ ' Called to implement the built-in functions "complex()", '
+ '"int()",\n'
+ ' "float()" and "round()". Should return a value of the '
+ 'appropriate\n'
+ ' type.\n'
+ '\n'
+ 'object.__index__(self)\n'
+ '\n'
+ ' Called to implement "operator.index()", and whenever '
+ 'Python needs\n'
+ ' to losslessly convert the numeric object to an integer '
+ 'object (such\n'
+ ' as in slicing, or in the built-in "bin()", "hex()" and '
+ '"oct()"\n'
+ ' functions). Presence of this method indicates that the '
+ 'numeric\n'
+ ' object is an integer type. Must return an integer.\n'
+ '\n'
+ ' Note: In order to have a coherent integer type class, '
+ 'when\n'
+ ' "__index__()" is defined "__int__()" should also be '
+ 'defined, and\n'
+ ' both should return the same value.\n'
+ '\n'
+ '\n'
+ 'With Statement Context Managers\n'
+ '===============================\n'
+ '\n'
+ 'A *context manager* is an object that defines the runtime '
+ 'context to\n'
+ 'be established when executing a "with" statement. The '
+ 'context manager\n'
+ 'handles the entry into, and the exit from, the desired '
+ 'runtime context\n'
+ 'for the execution of the block of code. Context managers '
+ 'are normally\n'
+ 'invoked using the "with" statement (described in section The '
+ 'with\n'
+ 'statement), but can also be used by directly invoking their '
+ 'methods.\n'
+ '\n'
+ 'Typical uses of context managers include saving and '
+ 'restoring various\n'
+ 'kinds of global state, locking and unlocking resources, '
+ 'closing opened\n'
+ 'files, etc.\n'
+ '\n'
+ 'For more information on context managers, see Context '
+ 'Manager Types.\n'
+ '\n'
+ 'object.__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'
+ '\n'
+ 'object.__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"
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 343** - The "with" statement\n'
+ ' The specification, background, and examples for the '
+ 'Python "with"\n'
+ ' statement.\n'
+ '\n'
+ '\n'
+ 'Special method lookup\n'
+ '=====================\n'
+ '\n'
+ 'For custom classes, implicit invocations of special methods '
+ 'are only\n'
+ "guaranteed to work correctly if defined on an object's type, "
+ 'not in\n'
+ "the object's instance dictionary. That behaviour is the "
+ 'reason why\n'
+ 'the following code raises an exception:\n'
+ '\n'
+ ' >>> class C:\n'
+ ' ... pass\n'
+ ' ...\n'
+ ' >>> c = C()\n'
+ ' >>> c.__len__ = lambda: 5\n'
+ ' >>> len(c)\n'
+ ' Traceback (most recent call last):\n'
+ ' File "<stdin>", line 1, in <module>\n'
+ " TypeError: object of type 'C' has no len()\n"
+ '\n'
+ 'The rationale behind this behaviour lies with a number of '
+ 'special\n'
+ 'methods such as "__hash__()" and "__repr__()" that are '
+ 'implemented by\n'
+ 'all objects, including type objects. If the implicit lookup '
+ 'of these\n'
+ 'methods used the conventional lookup process, they would '
+ 'fail when\n'
+ '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 "<stdin>", line 1, in <module>\n'
+ " TypeError: descriptor '__hash__' of 'int' object needs an "
+ 'argument\n'
+ '\n'
+ 'Incorrectly attempting to invoke an unbound method of a '
+ 'class in this\n'
+ "way is sometimes referred to as 'metaclass confusion', and "
+ 'is avoided\n'
+ 'by 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'
+ '\n'
+ 'In addition to bypassing any instance attributes in the '
+ 'interest of\n'
+ 'correctness, implicit special method lookup generally also '
+ 'bypasses\n'
+ 'the "__getattribute__()" method even of the object\'s '
+ 'metaclass:\n'
+ '\n'
+ ' >>> class Meta(type):\n'
+ ' ... def __getattribute__(*args):\n'
+ ' ... print("Metaclass getattribute invoked")\n'
+ ' ... return type.__getattribute__(*args)\n'
+ ' ...\n'
+ ' >>> class C(object, metaclass=Meta):\n'
+ ' ... def __len__(self):\n'
+ ' ... return 10\n'
+ ' ... def __getattribute__(*args):\n'
+ ' ... print("Class getattribute invoked")\n'
+ ' ... return object.__getattribute__(*args)\n'
+ ' ...\n'
+ ' >>> c = C()\n'
+ ' >>> c.__len__() # Explicit lookup via '
+ 'instance\n'
+ ' Class getattribute invoked\n'
+ ' 10\n'
+ ' >>> type(c).__len__(c) # Explicit lookup via '
+ 'type\n'
+ ' Metaclass getattribute invoked\n'
+ ' 10\n'
+ ' >>> len(c) # Implicit lookup\n'
+ ' 10\n'
+ '\n'
+ 'Bypassing the "__getattribute__()" machinery in this fashion '
+ 'provides\n'
+ 'significant scope for speed optimisations within the '
+ 'interpreter, at\n'
+ 'the cost of some flexibility in the handling of special '
+ 'methods (the\n'
+ 'special method *must* be set on the class object itself in '
+ 'order to be\n'
+ 'consistently invoked by the interpreter).\n',
+ 'string-methods': '\n'
+ 'String Methods\n'
+ '**************\n'
+ '\n'
+ 'Strings implement all of the common sequence operations, '
+ 'along with\n'
+ 'the additional methods described below.\n'
+ '\n'
+ 'Strings also support two styles of string formatting, one '
+ 'providing a\n'
+ 'large degree of flexibility and customization (see '
+ '"str.format()",\n'
+ 'Format String Syntax and Custom String Formatting) and the '
+ 'other based\n'
+ 'on C "printf" style formatting that handles a narrower '
+ 'range of types\n'
+ 'and is slightly harder to use correctly, but is often '
+ 'faster for the\n'
+ 'cases it can handle (printf-style String Formatting).\n'
+ '\n'
+ 'The Text Processing Services section of the standard '
+ 'library covers a\n'
+ 'number of other modules that provide various text related '
+ 'utilities\n'
+ '(including regular expression support in the "re" '
+ 'module).\n'
+ '\n'
+ 'str.capitalize()\n'
+ '\n'
+ ' Return a copy of the string with its first character '
+ 'capitalized\n'
+ ' and the rest lowercased.\n'
+ '\n'
+ 'str.casefold()\n'
+ '\n'
+ ' Return a casefolded copy of the string. Casefolded '
+ 'strings may be\n'
+ ' used for caseless matching.\n'
+ '\n'
+ ' Casefolding is similar to lowercasing but more '
+ 'aggressive because\n'
+ ' it is intended to remove all case distinctions in a '
+ 'string. For\n'
+ ' example, the German lowercase letter "\'ß\'" is '
+ 'equivalent to ""ss"".\n'
+ ' Since it is already lowercase, "lower()" would do '
+ 'nothing to "\'ß\'";\n'
+ ' "casefold()" converts it to ""ss"".\n'
+ '\n'
+ ' The casefolding algorithm is described in section 3.13 '
+ 'of the\n'
+ ' Unicode Standard.\n'
+ '\n'
+ ' New in version 3.3.\n'
+ '\n'
+ 'str.center(width[, fillchar])\n'
+ '\n'
+ ' Return centered in a string of length *width*. Padding '
+ 'is done\n'
+ ' using the specified *fillchar* (default is an ASCII '
+ 'space). The\n'
+ ' original string is returned if *width* is less than or '
+ 'equal to\n'
+ ' "len(s)".\n'
+ '\n'
+ 'str.count(sub[, start[, end]])\n'
+ '\n'
+ ' Return the number of non-overlapping occurrences of '
+ 'substring *sub*\n'
+ ' in the range [*start*, *end*]. Optional arguments '
+ '*start* and\n'
+ ' *end* are interpreted as in slice notation.\n'
+ '\n'
+ 'str.encode(encoding="utf-8", errors="strict")\n'
+ '\n'
+ ' Return an encoded version of the string as a bytes '
+ 'object. Default\n'
+ ' encoding is "\'utf-8\'". *errors* may be given to set a '
+ 'different\n'
+ ' error handling scheme. The default for *errors* is '
+ '"\'strict\'",\n'
+ ' meaning that encoding errors raise a "UnicodeError". '
+ 'Other possible\n'
+ ' values are "\'ignore\'", "\'replace\'", '
+ '"\'xmlcharrefreplace\'",\n'
+ ' "\'backslashreplace\'" and any other name registered '
+ 'via\n'
+ ' "codecs.register_error()", see section Error Handlers. '
+ 'For a list\n'
+ ' of possible encodings, see section Standard Encodings.\n'
+ '\n'
+ ' Changed in version 3.1: Support for keyword arguments '
+ 'added.\n'
+ '\n'
+ 'str.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 suffixes\n'
+ ' to look for. With optional *start*, test beginning at '
+ 'that\n'
+ ' position. With optional *end*, stop comparing at that '
+ 'position.\n'
+ '\n'
+ 'str.expandtabs(tabsize=8)\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. Tab positions occur every *tabsize* '
+ 'characters\n'
+ ' (default is 8, giving tab positions at columns 0, 8, 16 '
+ 'and so on).\n'
+ ' To expand the string, the current column is set to zero '
+ 'and the\n'
+ ' string is examined character by character. If the '
+ 'character is a\n'
+ ' tab ("\\t"), one or more space characters are inserted '
+ 'in the result\n'
+ ' until the current column is equal to the next tab '
+ 'position. (The\n'
+ ' tab character itself is not copied.) If the character '
+ 'is a newline\n'
+ ' ("\\n") or return ("\\r"), it is copied and the current '
+ 'column is\n'
+ ' reset to zero. Any other character is copied unchanged '
+ 'and the\n'
+ ' current column is incremented by one regardless of how '
+ 'the\n'
+ ' character is represented when printed.\n'
+ '\n'
+ " >>> '01\\t012\\t0123\\t01234'.expandtabs()\n"
+ " '01 012 0123 01234'\n"
+ " >>> '01\\t012\\t0123\\t01234'.expandtabs(4)\n"
+ " '01 012 0123 01234'\n"
+ '\n'
+ 'str.find(sub[, start[, end]])\n'
+ '\n'
+ ' Return the lowest index in the string where substring '
+ '*sub* is\n'
+ ' found within the slice "s[start:end]". Optional '
+ 'arguments *start*\n'
+ ' and *end* are interpreted as in slice notation. Return '
+ '"-1" if\n'
+ ' *sub* is not found.\n'
+ '\n'
+ ' Note: The "find()" method should be used only if you '
+ 'need to know\n'
+ ' the position of *sub*. To check if *sub* is a '
+ 'substring or not,\n'
+ ' use the "in" operator:\n'
+ '\n'
+ " >>> 'Py' in 'Python'\n"
+ ' True\n'
+ '\n'
+ 'str.format(*args, **kwargs)\n'
+ '\n'
+ ' Perform a string formatting operation. The string on '
+ 'which this\n'
+ ' method is called can contain literal text or '
+ 'replacement fields\n'
+ ' delimited by braces "{}". Each replacement field '
+ 'contains either\n'
+ ' the numeric index of a positional argument, or the name '
+ 'of a\n'
+ ' keyword argument. Returns a copy of the string where '
+ 'each\n'
+ ' replacement field is replaced with the string value of '
+ 'the\n'
+ ' corresponding argument.\n'
+ '\n'
+ ' >>> "The sum of 1 + 2 is {0}".format(1+2)\n'
+ " 'The sum of 1 + 2 is 3'\n"
+ '\n'
+ ' See Format String Syntax for a description of the '
+ 'various\n'
+ ' formatting options that can be specified in format '
+ 'strings.\n'
+ '\n'
+ 'str.format_map(mapping)\n'
+ '\n'
+ ' Similar to "str.format(**mapping)", except that '
+ '"mapping" is used\n'
+ ' directly and not copied to a "dict". This is useful if '
+ 'for example\n'
+ ' "mapping" is a dict subclass:\n'
+ '\n'
+ ' >>> class Default(dict):\n'
+ ' ... def __missing__(self, key):\n'
+ ' ... return key\n'
+ ' ...\n'
+ " >>> '{name} was born in "
+ "{country}'.format_map(Default(name='Guido'))\n"
+ " 'Guido was born in country'\n"
+ '\n'
+ ' New in version 3.2.\n'
+ '\n'
+ 'str.index(sub[, start[, end]])\n'
+ '\n'
+ ' Like "find()", but raise "ValueError" when the '
+ 'substring is not\n'
+ ' found.\n'
+ '\n'
+ 'str.isalnum()\n'
+ '\n'
+ ' Return true if all characters in the string are '
+ 'alphanumeric and\n'
+ ' there is at least one character, false otherwise. A '
+ 'character "c"\n'
+ ' is alphanumeric if one of the following returns '
+ '"True":\n'
+ ' "c.isalpha()", "c.isdecimal()", "c.isdigit()", or '
+ '"c.isnumeric()".\n'
+ '\n'
+ 'str.isalpha()\n'
+ '\n'
+ ' Return true if all characters in the string are '
+ 'alphabetic and\n'
+ ' there is at least one character, false otherwise. '
+ 'Alphabetic\n'
+ ' characters are those characters defined in the Unicode '
+ 'character\n'
+ ' database as "Letter", i.e., those with general category '
+ 'property\n'
+ ' being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note '
+ 'that this is\n'
+ ' different from the "Alphabetic" property defined in the '
+ 'Unicode\n'
+ ' Standard.\n'
+ '\n'
+ 'str.isdecimal()\n'
+ '\n'
+ ' Return true if all characters in the string are decimal '
+ 'characters\n'
+ ' and there is at least one character, false otherwise. '
+ 'Decimal\n'
+ ' characters are those from general category "Nd". This '
+ 'category\n'
+ ' includes digit characters, and all characters that can '
+ 'be used to\n'
+ ' form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC '
+ 'DIGIT ZERO.\n'
+ '\n'
+ 'str.isdigit()\n'
+ '\n'
+ ' Return true if all characters in the string are digits '
+ 'and there is\n'
+ ' at least one character, false otherwise. Digits '
+ 'include decimal\n'
+ ' characters and digits that need special handling, such '
+ 'as the\n'
+ ' compatibility superscript digits. Formally, a digit is '
+ 'a character\n'
+ ' that has the property value Numeric_Type=Digit or\n'
+ ' Numeric_Type=Decimal.\n'
+ '\n'
+ 'str.isidentifier()\n'
+ '\n'
+ ' Return true if the string is a valid identifier '
+ 'according to the\n'
+ ' language definition, section Identifiers and keywords.\n'
+ '\n'
+ ' Use "keyword.iskeyword()" to test for reserved '
+ 'identifiers such as\n'
+ ' "def" and "class".\n'
+ '\n'
+ 'str.islower()\n'
+ '\n'
+ ' Return true if all cased characters [4] in the string '
+ 'are lowercase\n'
+ ' and there is at least one cased character, false '
+ 'otherwise.\n'
+ '\n'
+ 'str.isnumeric()\n'
+ '\n'
+ ' Return true if all characters in the string are numeric '
+ 'characters,\n'
+ ' and there is at least one character, false otherwise. '
+ 'Numeric\n'
+ ' characters include digit characters, and all characters '
+ 'that have\n'
+ ' the Unicode numeric value property, e.g. U+2155, VULGAR '
+ 'FRACTION\n'
+ ' ONE FIFTH. Formally, numeric characters are those with '
+ 'the\n'
+ ' property value Numeric_Type=Digit, Numeric_Type=Decimal '
+ 'or\n'
+ ' Numeric_Type=Numeric.\n'
+ '\n'
+ 'str.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'
+ '\n'
+ 'str.isspace()\n'
+ '\n'
+ ' Return true if there are only whitespace characters in '
+ 'the string\n'
+ ' and there is at least one character, false otherwise. '
+ 'Whitespace\n'
+ ' characters are those characters defined in the Unicode '
+ 'character\n'
+ ' database as "Other" or "Separator" and those with '
+ 'bidirectional\n'
+ ' property being one of "WS", "B", or "S".\n'
+ '\n'
+ 'str.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'
+ '\n'
+ 'str.isupper()\n'
+ '\n'
+ ' Return true if all cased characters [4] in the string '
+ 'are uppercase\n'
+ ' and there is at least one cased character, false '
+ 'otherwise.\n'
+ '\n'
+ 'str.join(iterable)\n'
+ '\n'
+ ' Return a string which is the concatenation of the '
+ 'strings in the\n'
+ ' *iterable* *iterable*. A "TypeError" will be raised if '
+ 'there are\n'
+ ' any non-string values in *iterable*, including "bytes" '
+ 'objects.\n'
+ ' The separator between elements is the string providing '
+ 'this method.\n'
+ '\n'
+ 'str.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 an ASCII\n'
+ ' space). The original string is returned if *width* is '
+ 'less than or\n'
+ ' equal to "len(s)".\n'
+ '\n'
+ 'str.lower()\n'
+ '\n'
+ ' Return a copy of the string with all the cased '
+ 'characters [4]\n'
+ ' converted to lowercase.\n'
+ '\n'
+ ' The lowercasing algorithm used is described in section '
+ '3.13 of the\n'
+ ' Unicode Standard.\n'
+ '\n'
+ 'str.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"
+ '\n'
+ 'static str.maketrans(x[, y[, z]])\n'
+ '\n'
+ ' This static method returns a translation table usable '
+ 'for\n'
+ ' "str.translate()".\n'
+ '\n'
+ ' If there is only one argument, it must be a dictionary '
+ 'mapping\n'
+ ' Unicode ordinals (integers) or characters (strings of '
+ 'length 1) to\n'
+ ' Unicode ordinals, strings (of arbitrary lengths) or '
+ 'None.\n'
+ ' Character keys will then be converted to ordinals.\n'
+ '\n'
+ ' If there are two arguments, they must be strings of '
+ 'equal length,\n'
+ ' and in the resulting dictionary, each character in x '
+ 'will be mapped\n'
+ ' to the character at the same position in y. If there '
+ 'is a third\n'
+ ' argument, it must be a string, whose characters will be '
+ 'mapped to\n'
+ ' None in the result.\n'
+ '\n'
+ 'str.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'
+ '\n'
+ 'str.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'
+ '\n'
+ 'str.rfind(sub[, start[, end]])\n'
+ '\n'
+ ' Return the highest index in the string where substring '
+ '*sub* is\n'
+ ' found, such that *sub* is contained within '
+ '"s[start:end]".\n'
+ ' Optional arguments *start* and *end* are interpreted as '
+ 'in slice\n'
+ ' notation. Return "-1" on failure.\n'
+ '\n'
+ 'str.rindex(sub[, start[, end]])\n'
+ '\n'
+ ' Like "rfind()" but raises "ValueError" when the '
+ 'substring *sub* is\n'
+ ' not found.\n'
+ '\n'
+ 'str.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 an ASCII\n'
+ ' space). The original string is returned if *width* is '
+ 'less than or\n'
+ ' equal to "len(s)".\n'
+ '\n'
+ 'str.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'
+ '\n'
+ 'str.rsplit(sep=None, maxsplit=-1)\n'
+ '\n'
+ ' Return a list of the words in the string, using *sep* '
+ 'as the\n'
+ ' delimiter string. If *maxsplit* is given, at most '
+ '*maxsplit* splits\n'
+ ' are done, the *rightmost* ones. If *sep* is not '
+ 'specified or\n'
+ ' "None", any whitespace string is a separator. Except '
+ 'for splitting\n'
+ ' from the right, "rsplit()" behaves like "split()" which '
+ 'is\n'
+ ' described in detail below.\n'
+ '\n'
+ 'str.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"
+ '\n'
+ 'str.split(sep=None, maxsplit=-1)\n'
+ '\n'
+ ' Return a list of the words in the string, using *sep* '
+ 'as the\n'
+ ' delimiter string. If *maxsplit* is given, at most '
+ '*maxsplit*\n'
+ ' splits are done (thus, the list will have at most '
+ '"maxsplit+1"\n'
+ ' elements). If *maxsplit* is not specified or "-1", '
+ 'then there is\n'
+ ' no limit on the number of splits (all possible splits '
+ 'are made).\n'
+ '\n'
+ ' If *sep* is given, consecutive delimiters are not '
+ 'grouped together\n'
+ ' and are deemed to delimit empty strings (for example,\n'
+ ' "\'1,,2\'.split(\',\')" returns "[\'1\', \'\', '
+ '\'2\']"). The *sep* argument\n'
+ ' may consist of multiple characters (for example,\n'
+ ' "\'1<>2<>3\'.split(\'<>\')" returns "[\'1\', \'2\', '
+ '\'3\']"). Splitting an\n'
+ ' empty string with a specified separator returns '
+ '"[\'\']".\n'
+ '\n'
+ ' For example:\n'
+ '\n'
+ " >>> '1,2,3'.split(',')\n"
+ " ['1', '2', '3']\n"
+ " >>> '1,2,3'.split(',', maxsplit=1)\n"
+ " ['1', '2,3']\n"
+ " >>> '1,2,,3,'.split(',')\n"
+ " ['1', '2', '', '3', '']\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'
+ ' For example:\n'
+ '\n'
+ " >>> '1 2 3'.split()\n"
+ " ['1', '2', '3']\n"
+ " >>> '1 2 3'.split(maxsplit=1)\n"
+ " ['1', '2 3']\n"
+ " >>> ' 1 2 3 '.split()\n"
+ " ['1', '2', '3']\n"
+ '\n'
+ 'str.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'
+ '\n'
+ ' This method splits on the following line boundaries. '
+ 'In\n'
+ ' particular, the boundaries are a superset of *universal '
+ 'newlines*.\n'
+ '\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | Representation | '
+ 'Description |\n'
+ ' '
+ '+=========================+===============================+\n'
+ ' | "\\n" | Line '
+ 'Feed |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\r" | Carriage '
+ 'Return |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\r\\n" | Carriage Return + Line '
+ 'Feed |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\v" or "\\x0b" | Line '
+ 'Tabulation |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\f" or "\\x0c" | Form '
+ 'Feed |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\x1c" | File '
+ 'Separator |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\x1d" | Group '
+ 'Separator |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\x1e" | Record '
+ 'Separator |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\x85" | Next Line (C1 Control '
+ 'Code) |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\u2028" | Line '
+ 'Separator |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ ' | "\\u2029" | Paragraph '
+ 'Separator |\n'
+ ' '
+ '+-------------------------+-------------------------------+\n'
+ '\n'
+ ' Changed in version 3.2: "\\v" and "\\f" added to list '
+ 'of line\n'
+ ' boundaries.\n'
+ '\n'
+ ' For example:\n'
+ '\n'
+ " >>> 'ab c\\n\\nde fg\\rkl\\r\\n'.splitlines()\n"
+ " ['ab c', '', 'de fg', 'kl']\n"
+ " >>> 'ab c\\n\\nde "
+ "fg\\rkl\\r\\n'.splitlines(keepends=True)\n"
+ " ['ab c\\n', '\\n', 'de fg\\r', 'kl\\r\\n']\n"
+ '\n'
+ ' Unlike "split()" when a delimiter string *sep* is '
+ 'given, this\n'
+ ' method returns an empty list for the empty string, and '
+ 'a terminal\n'
+ ' line break does not result in an extra line:\n'
+ '\n'
+ ' >>> "".splitlines()\n'
+ ' []\n'
+ ' >>> "One line\\n".splitlines()\n'
+ " ['One line']\n"
+ '\n'
+ ' For comparison, "split(\'\\n\')" gives:\n'
+ '\n'
+ " >>> ''.split('\\n')\n"
+ " ['']\n"
+ " >>> 'Two lines\\n'.split('\\n')\n"
+ " ['Two lines', '']\n"
+ '\n'
+ 'str.startswith(prefix[, start[, end]])\n'
+ '\n'
+ ' Return "True" if string starts with the *prefix*, '
+ 'otherwise return\n'
+ ' "False". *prefix* can also be a tuple of prefixes to '
+ 'look for.\n'
+ ' With optional *start*, test string beginning at that '
+ 'position.\n'
+ ' With optional *end*, stop comparing string at that '
+ 'position.\n'
+ '\n'
+ 'str.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 *chars*\n'
+ ' argument defaults to removing whitespace. The *chars* '
+ 'argument is\n'
+ ' not a prefix or suffix; rather, all combinations of its '
+ 'values are\n'
+ ' stripped:\n'
+ '\n'
+ " >>> ' spacious '.strip()\n"
+ " 'spacious'\n"
+ " >>> 'www.example.com'.strip('cmowz.')\n"
+ " 'example'\n"
+ '\n'
+ ' The outermost leading and trailing *chars* argument '
+ 'values are\n'
+ ' stripped from the string. Characters are removed from '
+ 'the leading\n'
+ ' end until reaching a string character that is not '
+ 'contained in the\n'
+ ' set of characters in *chars*. A similar action takes '
+ 'place on the\n'
+ ' trailing end. For example:\n'
+ '\n'
+ " >>> comment_string = '#....... Section 3.2.1 Issue "
+ "#32 .......'\n"
+ " >>> comment_string.strip('.#! ')\n"
+ " 'Section 3.2.1 Issue #32'\n"
+ '\n'
+ 'str.swapcase()\n'
+ '\n'
+ ' Return a copy of the string with uppercase characters '
+ 'converted to\n'
+ ' lowercase and vice versa. Note that it is not '
+ 'necessarily true that\n'
+ ' "s.swapcase().swapcase() == s".\n'
+ '\n'
+ 'str.title()\n'
+ '\n'
+ ' Return a titlecased version of the string where words '
+ 'start with an\n'
+ ' uppercase character and the remaining characters are '
+ 'lowercase.\n'
+ '\n'
+ ' For example:\n'
+ '\n'
+ " >>> 'Hello world'.title()\n"
+ " 'Hello World'\n"
+ '\n'
+ ' The algorithm uses a simple language-independent '
+ 'definition of a\n'
+ ' word as groups of consecutive letters. The definition '
+ 'works in\n'
+ ' many contexts but it means that apostrophes in '
+ 'contractions and\n'
+ ' possessives form word boundaries, which may not be the '
+ 'desired\n'
+ ' result:\n'
+ '\n'
+ ' >>> "they\'re bill\'s friends from the UK".title()\n'
+ ' "They\'Re Bill\'S Friends From The Uk"\n'
+ '\n'
+ ' A workaround for apostrophes can be constructed using '
+ 'regular\n'
+ ' expressions:\n'
+ '\n'
+ ' >>> import re\n'
+ ' >>> def titlecase(s):\n'
+ ' ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n'
+ ' ... lambda mo: '
+ 'mo.group(0)[0].upper() +\n'
+ ' ... '
+ 'mo.group(0)[1:].lower(),\n'
+ ' ... s)\n'
+ ' ...\n'
+ ' >>> titlecase("they\'re bill\'s friends.")\n'
+ ' "They\'re Bill\'s Friends."\n'
+ '\n'
+ 'str.translate(table)\n'
+ '\n'
+ ' Return a copy of the string in which each character has '
+ 'been mapped\n'
+ ' through the given translation table. The table must be '
+ 'an object\n'
+ ' that implements indexing via "__getitem__()", typically '
+ 'a *mapping*\n'
+ ' or *sequence*. When indexed by a Unicode ordinal (an '
+ 'integer), the\n'
+ ' table object can do any of the following: return a '
+ 'Unicode ordinal\n'
+ ' or a string, to map the character to one or more other '
+ 'characters;\n'
+ ' return "None", to delete the character from the return '
+ 'string; or\n'
+ ' raise a "LookupError" exception, to map the character '
+ 'to itself.\n'
+ '\n'
+ ' You can use "str.maketrans()" to create a translation '
+ 'map from\n'
+ ' character-to-character mappings in different formats.\n'
+ '\n'
+ ' See also the "codecs" module for a more flexible '
+ 'approach to custom\n'
+ ' character mappings.\n'
+ '\n'
+ 'str.upper()\n'
+ '\n'
+ ' Return a copy of the string with all the cased '
+ 'characters [4]\n'
+ ' converted to uppercase. Note that '
+ '"str.upper().isupper()" might be\n'
+ ' "False" if "s" contains uncased characters or if the '
+ 'Unicode\n'
+ ' category of the resulting character(s) is not "Lu" '
+ '(Letter,\n'
+ ' uppercase), but e.g. "Lt" (Letter, titlecase).\n'
+ '\n'
+ ' The uppercasing algorithm used is described in section '
+ '3.13 of the\n'
+ ' Unicode Standard.\n'
+ '\n'
+ 'str.zfill(width)\n'
+ '\n'
+ ' Return a copy of the string left filled with ASCII '
+ '"\'0\'" digits to\n'
+ ' make a string of length *width*. A leading sign prefix\n'
+ ' ("\'+\'"/"\'-\'") is handled by inserting the padding '
+ '*after* the sign\n'
+ ' character rather than before. The original string is '
+ 'returned if\n'
+ ' *width* is less than or equal to "len(s)".\n'
+ '\n'
+ ' For example:\n'
+ '\n'
+ ' >>> "42".zfill(5)\n'
+ " '00042'\n"
+ ' >>> "-42".zfill(5)\n'
+ " '-0042'\n",
+ 'strings': '\n'
+ 'String and Bytes literals\n'
+ '*************************\n'
+ '\n'
+ 'String literals are described by the following lexical '
+ 'definitions:\n'
+ '\n'
+ ' stringliteral ::= [stringprefix](shortstring | longstring)\n'
+ ' stringprefix ::= "r" | "u" | "R" | "U" | "f" | "F"\n'
+ ' | "fr" | "Fr" | "fR" | "FR" | "rf" | "rF" | '
+ '"Rf" | "RF"\n'
+ ' shortstring ::= "\'" shortstringitem* "\'" | \'"\' '
+ 'shortstringitem* \'"\'\n'
+ ' longstring ::= "\'\'\'" longstringitem* "\'\'\'" | '
+ '\'"""\' longstringitem* \'"""\'\n'
+ ' shortstringitem ::= shortstringchar | stringescapeseq\n'
+ ' longstringitem ::= longstringchar | stringescapeseq\n'
+ ' shortstringchar ::= <any source character except "\\" or '
+ 'newline or the quote>\n'
+ ' longstringchar ::= <any source character except "\\">\n'
+ ' stringescapeseq ::= "\\" <any source character>\n'
+ '\n'
+ ' bytesliteral ::= bytesprefix(shortbytes | longbytes)\n'
+ ' bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | '
+ '"rb" | "rB" | "Rb" | "RB"\n'
+ ' shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' '
+ 'shortbytesitem* \'"\'\n'
+ ' longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' '
+ 'longbytesitem* \'"""\'\n'
+ ' shortbytesitem ::= shortbyteschar | bytesescapeseq\n'
+ ' longbytesitem ::= longbyteschar | bytesescapeseq\n'
+ ' shortbyteschar ::= <any ASCII character except "\\" or newline '
+ 'or the quote>\n'
+ ' longbyteschar ::= <any ASCII character except "\\">\n'
+ ' bytesescapeseq ::= "\\" <any ASCII character>\n'
+ '\n'
+ 'One syntactic restriction not indicated by these productions is '
+ 'that\n'
+ 'whitespace is not allowed between the "stringprefix" or '
+ '"bytesprefix"\n'
+ 'and the rest of the literal. The source character set is defined '
+ 'by\n'
+ 'the encoding declaration; it is UTF-8 if no encoding declaration '
+ 'is\n'
+ 'given in the source file; see section Encoding declarations.\n'
+ '\n'
+ 'In plain English: Both types of literals can be enclosed in '
+ 'matching\n'
+ 'single quotes ("\'") or double quotes ("""). They can also be '
+ 'enclosed\n'
+ 'in matching groups of three single or double quotes (these are\n'
+ 'generally referred to as *triple-quoted strings*). The '
+ 'backslash\n'
+ '("\\") character is used to escape characters that otherwise have '
+ 'a\n'
+ 'special meaning, such as newline, backslash itself, or the quote\n'
+ 'character.\n'
+ '\n'
+ 'Bytes literals are always prefixed with "\'b\'" or "\'B\'"; they '
+ 'produce\n'
+ 'an instance of the "bytes" type instead of the "str" type. They '
+ 'may\n'
+ 'only contain ASCII characters; bytes with a numeric value of 128 '
+ 'or\n'
+ 'greater must be expressed with escapes.\n'
+ '\n'
+ 'As of Python 3.3 it is possible again to prefix string literals '
+ 'with a\n'
+ '"u" prefix to simplify maintenance of dual 2.x and 3.x '
+ 'codebases.\n'
+ '\n'
+ 'Both string and bytes literals may optionally be prefixed with a\n'
+ 'letter "\'r\'" or "\'R\'"; such strings are called *raw strings* '
+ 'and treat\n'
+ 'backslashes as literal characters. As a result, in string '
+ 'literals,\n'
+ '"\'\\U\'" and "\'\\u\'" escapes in raw strings are not treated '
+ 'specially.\n'
+ "Given that Python 2.x's raw unicode literals behave differently "
+ 'than\n'
+ 'Python 3.x\'s the "\'ur\'" syntax is not supported.\n'
+ '\n'
+ 'New in version 3.3: The "\'rb\'" prefix of raw bytes literals has '
+ 'been\n'
+ 'added as a synonym of "\'br\'".\n'
+ '\n'
+ 'New in version 3.3: Support for the unicode legacy literal\n'
+ '("u\'value\'") was reintroduced to simplify the maintenance of '
+ 'dual\n'
+ 'Python 2.x and 3.x codebases. See **PEP 414** for more '
+ 'information.\n'
+ '\n'
+ 'A string literal with "\'f\'" or "\'F\'" in its prefix is a '
+ '*formatted\n'
+ 'string literal*; see Formatted string literals. The "\'f\'" may '
+ 'be\n'
+ 'combined with "\'r\'", but not with "\'b\'" or "\'u\'", therefore '
+ 'raw\n'
+ 'formatted strings are possible, but formatted bytes literals are '
+ 'not.\n'
+ '\n'
+ 'In triple-quoted literals, unescaped newlines and quotes are '
+ 'allowed\n'
+ '(and are retained), except that three unescaped quotes in a row\n'
+ 'terminate the literal. (A "quote" is the character used to open '
+ 'the\n'
+ 'literal, i.e. either "\'" or """.)\n'
+ '\n'
+ 'Unless an "\'r\'" or "\'R\'" prefix is present, escape sequences '
+ 'in string\n'
+ 'and bytes literals are interpreted according to rules similar to '
+ 'those\n'
+ 'used by Standard 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'
+ '\n'
+ 'Escape sequences only recognized in string literals are:\n'
+ '\n'
+ '+-------------------+-----------------------------------+---------+\n'
+ '| Escape Sequence | Meaning | Notes '
+ '|\n'
+ '+===================+===================================+=========+\n'
+ '| "\\N{name}" | Character named *name* in the | '
+ '(4) |\n'
+ '| | Unicode database | '
+ '|\n'
+ '+-------------------+-----------------------------------+---------+\n'
+ '| "\\uxxxx" | Character with 16-bit hex value | '
+ '(5) |\n'
+ '| | *xxxx* | '
+ '|\n'
+ '+-------------------+-----------------------------------+---------+\n'
+ '| "\\Uxxxxxxxx" | Character with 32-bit hex value | '
+ '(6) |\n'
+ '| | *xxxxxxxx* | '
+ '|\n'
+ '+-------------------+-----------------------------------+---------+\n'
+ '\n'
+ 'Notes:\n'
+ '\n'
+ '1. As in Standard C, up to three octal digits are accepted.\n'
+ '\n'
+ '2. Unlike in Standard C, exactly two hex digits are required.\n'
+ '\n'
+ '3. In a bytes literal, hexadecimal and octal escapes denote the\n'
+ ' byte with the given value. In a string literal, these escapes\n'
+ ' denote a Unicode character with the given value.\n'
+ '\n'
+ '4. Changed in version 3.3: Support for name aliases [1] has been\n'
+ ' added.\n'
+ '\n'
+ '5. Exactly four hex digits are required.\n'
+ '\n'
+ '6. Any Unicode character can be encoded this way. Exactly eight\n'
+ ' hex digits are required.\n'
+ '\n'
+ 'Unlike Standard C, all unrecognized escape sequences are left in '
+ 'the\n'
+ 'string unchanged, i.e., *the backslash is left in the result*. '
+ '(This\n'
+ 'behavior is useful when debugging: if an escape sequence is '
+ 'mistyped,\n'
+ 'the resulting output is more easily recognized as broken.) It is '
+ 'also\n'
+ 'important to note that the escape sequences only recognized in '
+ 'string\n'
+ 'literals fall into the category of unrecognized escapes for '
+ 'bytes\n'
+ 'literals.\n'
+ '\n'
+ ' Changed in version 3.6: Unrecognized escape sequences produce '
+ 'a\n'
+ ' DeprecationWarning. In some future version of Python they '
+ 'will be\n'
+ ' a SyntaxError.\n'
+ '\n'
+ 'Even in a raw literal, quotes can be escaped with a backslash, '
+ 'but the\n'
+ 'backslash remains in the result; for example, "r"\\""" is a '
+ 'valid\n'
+ 'string literal consisting of two characters: a backslash and a '
+ 'double\n'
+ 'quote; "r"\\"" is not a valid string literal (even a raw string '
+ 'cannot\n'
+ 'end in an odd number of backslashes). Specifically, *a raw '
+ 'literal\n'
+ 'cannot end in a single backslash* (since the backslash would '
+ 'escape\n'
+ 'the following quote character). Note also that a single '
+ 'backslash\n'
+ 'followed by a newline is interpreted as those two characters as '
+ 'part\n'
+ 'of the literal, *not* as a line continuation.\n',
+ 'subscriptions': '\n'
+ 'Subscriptions\n'
+ '*************\n'
+ '\n'
+ 'A subscription selects an item of a sequence (string, tuple '
+ 'or list)\n'
+ 'or mapping (dictionary) object:\n'
+ '\n'
+ ' subscription ::= primary "[" expression_list "]"\n'
+ '\n'
+ 'The primary must evaluate to an object that supports '
+ 'subscription\n'
+ '(lists or dictionaries for example). User-defined objects '
+ 'can support\n'
+ 'subscription by defining a "__getitem__()" method.\n'
+ '\n'
+ 'For built-in objects, there are two types of objects that '
+ 'support\n'
+ 'subscription:\n'
+ '\n'
+ 'If the primary is a mapping, the expression list must '
+ 'evaluate to an\n'
+ 'object whose value is one of the keys of the mapping, and '
+ 'the\n'
+ 'subscription selects the value in the mapping that '
+ 'corresponds to that\n'
+ 'key. (The expression list is a tuple except if it has '
+ 'exactly one\n'
+ 'item.)\n'
+ '\n'
+ 'If the primary is a sequence, the expression (list) must '
+ 'evaluate to\n'
+ 'an integer or a slice (as discussed in the following '
+ 'section).\n'
+ '\n'
+ 'The formal syntax makes no special provision for negative '
+ 'indices in\n'
+ 'sequences; however, built-in sequences all provide a '
+ '"__getitem__()"\n'
+ 'method that interprets negative indices by adding the '
+ 'length of the\n'
+ 'sequence to the index (so that "x[-1]" selects the last '
+ 'item of "x").\n'
+ 'The resulting value must be a nonnegative integer less than '
+ 'the number\n'
+ 'of items in the sequence, and the subscription selects the '
+ 'item whose\n'
+ 'index is that value (counting from zero). Since the support '
+ 'for\n'
+ "negative indices and slicing occurs in the object's "
+ '"__getitem__()"\n'
+ 'method, subclasses overriding this method will need to '
+ 'explicitly add\n'
+ 'that support.\n'
+ '\n'
+ "A string's items are characters. A character is not a "
+ 'separate data\n'
+ 'type but a string of exactly one character.\n',
+ 'truth': '\n'
+ 'Truth Value Testing\n'
+ '*******************\n'
+ '\n'
+ 'Any 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\n'
+ 'following 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'
+ '\n'
+ 'All other values are considered true --- so objects of many types '
+ 'are\n'
+ 'always true.\n'
+ '\n'
+ 'Operations and built-in functions that have a Boolean result '
+ 'always\n'
+ 'return "0" or "False" for false and "1" or "True" for true, unless\n'
+ 'otherwise stated. (Important exception: the Boolean operations '
+ '"or"\n'
+ 'and "and" always return one of their operands.)\n',
+ 'try': '\n'
+ 'The "try" statement\n'
+ '*******************\n'
+ '\n'
+ 'The "try" statement specifies exception handlers and/or cleanup code\n'
+ 'for a group of statements:\n'
+ '\n'
+ ' try_stmt ::= try1_stmt | try2_stmt\n'
+ ' try1_stmt ::= "try" ":" suite\n'
+ ' ("except" [expression ["as" identifier]] ":" '
+ 'suite)+\n'
+ ' ["else" ":" suite]\n'
+ ' ["finally" ":" suite]\n'
+ ' try2_stmt ::= "try" ":" suite\n'
+ ' "finally" ":" suite\n'
+ '\n'
+ 'The "except" clause(s) specify one or more exception handlers. When '
+ 'no\n'
+ 'exception occurs in the "try" clause, no exception handler is\n'
+ 'executed. When an exception occurs in the "try" suite, a search for '
+ 'an\n'
+ 'exception handler is started. This search inspects the except '
+ 'clauses\n'
+ 'in turn until one is found that matches the exception. An '
+ 'expression-\n'
+ 'less except clause, if present, must be last; it matches any\n'
+ 'exception. For an except clause with an expression, that expression\n'
+ 'is evaluated, and the clause matches the exception if the resulting\n'
+ 'object is "compatible" with the exception. An object is compatible\n'
+ 'with an exception if it is the class or a base class of the '
+ 'exception\n'
+ 'object or a tuple containing an item compatible with the exception.\n'
+ '\n'
+ 'If no except clause matches the exception, the search for an '
+ 'exception\n'
+ 'handler continues in the surrounding code and on the invocation '
+ 'stack.\n'
+ '[1]\n'
+ '\n'
+ 'If the evaluation of an expression in the header of an except clause\n'
+ 'raises an exception, the original search for a handler is canceled '
+ 'and\n'
+ 'a search starts for the new exception in the surrounding code and on\n'
+ 'the call stack (it is treated as if the entire "try" statement '
+ 'raised\n'
+ 'the exception).\n'
+ '\n'
+ 'When a matching except clause is found, the exception is assigned to\n'
+ 'the target specified after the "as" keyword in that except clause, '
+ 'if\n'
+ "present, and the except clause's suite is executed. All except\n"
+ 'clauses must have an executable block. When the end of this block '
+ 'is\n'
+ 'reached, execution continues normally after the entire try '
+ 'statement.\n'
+ '(This means that if two nested handlers exist for the same '
+ 'exception,\n'
+ 'and the exception occurs in the try clause of the inner handler, the\n'
+ 'outer handler will not handle the exception.)\n'
+ '\n'
+ 'When an exception has been assigned using "as target", it is cleared\n'
+ 'at the end of the except clause. This is as if\n'
+ '\n'
+ ' except E as N:\n'
+ ' foo\n'
+ '\n'
+ 'was translated to\n'
+ '\n'
+ ' except E as N:\n'
+ ' try:\n'
+ ' foo\n'
+ ' finally:\n'
+ ' del N\n'
+ '\n'
+ 'This means the exception must be assigned to a different name to be\n'
+ 'able to refer to it after the except clause. Exceptions are cleared\n'
+ 'because with the traceback attached to them, they form a reference\n'
+ 'cycle with the stack frame, keeping all locals in that frame alive\n'
+ 'until the next garbage collection occurs.\n'
+ '\n'
+ "Before an except clause's suite is executed, details about the\n"
+ 'exception are stored in the "sys" module and can be accessed via\n'
+ '"sys.exc_info()". "sys.exc_info()" returns a 3-tuple consisting of '
+ 'the\n'
+ 'exception class, the exception instance and a traceback object (see\n'
+ 'section The standard type hierarchy) identifying the point in the\n'
+ 'program where the exception occurred. "sys.exc_info()" values are\n'
+ 'restored to their previous values (before the call) when returning\n'
+ 'from a function that handled an exception.\n'
+ '\n'
+ 'The optional "else" clause is executed if and when control flows off\n'
+ 'the end of the "try" clause. [2] Exceptions in the "else" clause are\n'
+ 'not handled by the preceding "except" clauses.\n'
+ '\n'
+ 'If "finally" is present, it specifies a \'cleanup\' handler. The '
+ '"try"\n'
+ 'clause is executed, including any "except" and "else" clauses. If '
+ 'an\n'
+ 'exception occurs in any of the clauses and is not handled, the\n'
+ 'exception is temporarily saved. The "finally" clause is executed. '
+ 'If\n'
+ 'there is a saved exception it is re-raised at the end of the '
+ '"finally"\n'
+ 'clause. If the "finally" clause raises another exception, the saved\n'
+ 'exception is set as the context of the new exception. If the '
+ '"finally"\n'
+ 'clause executes a "return" or "break" statement, the saved exception\n'
+ 'is discarded:\n'
+ '\n'
+ ' >>> def f():\n'
+ ' ... try:\n'
+ ' ... 1/0\n'
+ ' ... finally:\n'
+ ' ... return 42\n'
+ ' ...\n'
+ ' >>> f()\n'
+ ' 42\n'
+ '\n'
+ 'The exception information is not available to the program during\n'
+ 'execution of the "finally" clause.\n'
+ '\n'
+ 'When a "return", "break" or "continue" statement is executed in the\n'
+ '"try" suite of a "try"..."finally" statement, the "finally" clause '
+ 'is\n'
+ 'also executed \'on the way out.\' A "continue" statement is illegal '
+ 'in\n'
+ 'the "finally" clause. (The reason is a problem with the current\n'
+ 'implementation --- this restriction may be lifted in the future).\n'
+ '\n'
+ 'The return value of a function is determined by the last "return"\n'
+ 'statement executed. Since the "finally" clause always executes, a\n'
+ '"return" statement executed in the "finally" clause will always be '
+ 'the\n'
+ 'last one executed:\n'
+ '\n'
+ ' >>> def foo():\n'
+ ' ... try:\n'
+ " ... return 'try'\n"
+ ' ... finally:\n'
+ " ... return 'finally'\n"
+ ' ...\n'
+ ' >>> foo()\n'
+ " 'finally'\n"
+ '\n'
+ 'Additional information on exceptions can be found in section\n'
+ 'Exceptions, and information on using the "raise" statement to '
+ 'generate\n'
+ 'exceptions may be found in section The raise statement.\n',
+ 'types': '\n'
+ 'The standard type hierarchy\n'
+ '***************************\n'
+ '\n'
+ 'Below is a list of the types that are built into Python. '
+ 'Extension\n'
+ 'modules (written in C, Java, or other languages, depending on the\n'
+ 'implementation) can define additional types. Future versions of\n'
+ 'Python may add types to the type hierarchy (e.g., rational '
+ 'numbers,\n'
+ 'efficiently stored arrays of integers, etc.), although such '
+ 'additions\n'
+ 'will often be provided via the standard library instead.\n'
+ '\n'
+ 'Some of the type descriptions below contain a paragraph listing\n'
+ "'special attributes.' These are attributes that provide access to "
+ 'the\n'
+ 'implementation and are not intended for general use. Their '
+ 'definition\n'
+ 'may change in the future.\n'
+ '\n'
+ 'None\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". '
+ 'It\n'
+ ' is used to signify the absence of a value in many situations, '
+ 'e.g.,\n'
+ " it is returned from functions that don't explicitly return\n"
+ ' anything. Its truth value is false.\n'
+ '\n'
+ 'NotImplemented\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\n'
+ ' should return this value if they do not implement the operation '
+ 'for\n'
+ ' the operands provided. (The interpreter will then try the\n'
+ ' reflected operation, or some other fallback, depending on the\n'
+ ' operator.) Its truth value is true.\n'
+ '\n'
+ ' See Implementing the arithmetic operations for more details.\n'
+ '\n'
+ 'Ellipsis\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\n'
+ ' only Boolean objects. The Boolean type is a subtype of '
+ 'the\n'
+ ' integer type, and Boolean values behave like the values 0 '
+ 'and\n'
+ ' 1, 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 are\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'
+ '\n'
+ 'Sequences\n'
+ ' These represent finite ordered sets indexed by non-negative\n'
+ ' numbers. The built-in function "len()" returns the number of '
+ 'items\n'
+ ' of a sequence. When the length of a sequence is *n*, the index '
+ 'set\n'
+ ' contains the numbers 0, 1, ..., *n*-1. Item *i* of sequence *a* '
+ 'is\n'
+ ' 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* '
+ 'where\n'
+ ' "x = i + n*k", *n* ">=" "0" and *i* "<=" *x* "<" *j*.\n'
+ '\n'
+ ' Sequences are distinguished according to their mutability:\n'
+ '\n'
+ ' Immutable sequences\n'
+ ' An object of an immutable sequence type cannot change once it '
+ 'is\n'
+ ' created. (If the object contains references to other '
+ 'objects,\n'
+ ' these other objects may be mutable and may be changed; '
+ 'however,\n'
+ ' the collection of objects directly referenced by an '
+ 'immutable\n'
+ ' object cannot change.)\n'
+ '\n'
+ ' The following types are immutable sequences:\n'
+ '\n'
+ ' Strings\n'
+ ' A string is a sequence of values that represent Unicode '
+ 'code\n'
+ ' points. All the code points in the range "U+0000 - '
+ 'U+10FFFF"\n'
+ " can be represented in a string. Python doesn't have a "
+ '"char"\n'
+ ' type; instead, every code point in the string is '
+ 'represented\n'
+ ' as a string object with length "1". The built-in '
+ 'function\n'
+ ' "ord()" converts a code point from its string form to an\n'
+ ' integer in the range "0 - 10FFFF"; "chr()" converts an\n'
+ ' integer in the range "0 - 10FFFF" to the corresponding '
+ 'length\n'
+ ' "1" string object. "str.encode()" can be used to convert '
+ 'a\n'
+ ' "str" to "bytes" using the given text encoding, and\n'
+ ' "bytes.decode()" can be used to achieve the opposite.\n'
+ '\n'
+ ' Tuples\n'
+ ' The items of a tuple are arbitrary Python objects. Tuples '
+ 'of\n'
+ ' two or more items are formed by comma-separated lists of\n'
+ " expressions. A tuple of one item (a 'singleton') can be\n"
+ ' formed by affixing a comma to an expression (an expression '
+ 'by\n'
+ ' itself does not create a tuple, since parentheses must be\n'
+ ' usable for grouping of expressions). An empty tuple can '
+ 'be\n'
+ ' formed by an empty pair of parentheses.\n'
+ '\n'
+ ' Bytes\n'
+ ' A bytes object is an immutable array. The items are '
+ '8-bit\n'
+ ' bytes, represented by integers in the range 0 <= x < 256.\n'
+ ' Bytes literals (like "b\'abc\'") and the built-in '
+ 'function\n'
+ ' "bytes()" can be used to construct bytes objects. Also,\n'
+ ' bytes objects can be decoded to strings via the '
+ '"decode()"\n'
+ ' method.\n'
+ '\n'
+ ' Mutable sequences\n'
+ ' Mutable sequences can be changed after they are created. '
+ 'The\n'
+ ' subscription and slicing notations can be used as the target '
+ 'of\n'
+ ' assignment and "del" (delete) statements.\n'
+ '\n'
+ ' There are currently two intrinsic mutable sequence types:\n'
+ '\n'
+ ' Lists\n'
+ ' The items of a list are arbitrary Python objects. Lists '
+ 'are\n'
+ ' formed by placing a comma-separated list of expressions '
+ 'in\n'
+ ' square brackets. (Note that there are no special cases '
+ 'needed\n'
+ ' to form lists of length 0 or 1.)\n'
+ '\n'
+ ' Byte Arrays\n'
+ ' A bytearray object is a mutable array. They are created '
+ 'by\n'
+ ' the built-in "bytearray()" constructor. Aside from being\n'
+ ' mutable (and hence unhashable), byte arrays otherwise '
+ 'provide\n'
+ ' the same interface and functionality as immutable bytes\n'
+ ' objects.\n'
+ '\n'
+ ' The extension module "array" provides an additional example '
+ 'of a\n'
+ ' mutable sequence type, as does the "collections" module.\n'
+ '\n'
+ 'Set 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 '
+ 'immutable\n'
+ ' and *hashable*, it can be used again as an element of '
+ 'another\n'
+ ' set, or as a dictionary key.\n'
+ '\n'
+ 'Mappings\n'
+ ' These represent finite sets of objects indexed by arbitrary '
+ 'index\n'
+ ' sets. The subscript notation "a[k]" selects the item indexed by '
+ '"k"\n'
+ ' from the mapping "a"; this can be used in expressions and as '
+ 'the\n'
+ ' target of assignments or "del" statements. The built-in '
+ 'function\n'
+ ' "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 '
+ '"1.0")\n'
+ ' 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 '
+ '"collections"\n'
+ ' module.\n'
+ '\n'
+ 'Callable 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; not inherited by '
+ '| |\n'
+ ' | | subclasses '
+ '| |\n'
+ ' '
+ '+---------------------------+---------------------------------+-------------+\n'
+ ' | "__name__" | The function\'s '
+ 'name | Writable |\n'
+ ' '
+ '+---------------------------+---------------------------------+-------------+\n'
+ ' | "__qualname__" | The function\'s *qualified '
+ 'name* | Writable |\n'
+ ' | | New in version 3.3. '
+ '| |\n'
+ ' '
+ '+---------------------------+---------------------------------+-------------+\n'
+ ' | "__module__" | The name of the module the '
+ '| Writable |\n'
+ ' | | function was defined in, or '
+ '| |\n'
+ ' | | "None" if unavailable. '
+ '| |\n'
+ ' '
+ '+---------------------------+---------------------------------+-------------+\n'
+ ' | "__defaults__" | A tuple containing default '
+ '| Writable |\n'
+ ' | | argument values for those '
+ '| |\n'
+ ' | | arguments that have defaults, '
+ '| |\n'
+ ' | | or "None" if no arguments have '
+ '| |\n'
+ ' | | 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 that '
+ '| Read-only |\n'
+ ' | | 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'
+ ' | | and "\'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__"); '
+ '"__name__"\n'
+ ' is the method name (same as "__func__.__name__"); '
+ '"__module__"\n'
+ ' is the name of the module the method was defined in, or '
+ '"None"\n'
+ ' 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 '
+ 'object\n'
+ ' is said to be bound. The new method\'s "__func__" attribute '
+ 'is\n'
+ ' 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__" '
+ 'attribute\n'
+ ' is the class itself, and its "__func__" attribute is the\n'
+ ' 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, '
+ 'when\n'
+ ' "C" is a class which contains a definition for a function '
+ '"f()",\n'
+ ' and "x" is an instance of "C", calling "x.f(1)" is equivalent '
+ 'to\n'
+ ' 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 '
+ 'actually\n'
+ ' be the class itself, so that calling either "x.f(1)" or '
+ '"C.f(1)"\n'
+ ' is equivalent to calling "f(C,1)" where "f" is the '
+ 'underlying\n'
+ ' 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 "iterator.__next__()" method will cause the\n'
+ ' function to execute until it provides a value using the '
+ '"yield"\n'
+ ' statement. When the function executes a "return" statement '
+ 'or\n'
+ ' falls off 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'
+ ' Coroutine functions\n'
+ ' A function or method which is defined using "async def" is\n'
+ ' called a *coroutine function*. Such a function, when '
+ 'called,\n'
+ ' returns a *coroutine* object. It may contain "await"\n'
+ ' expressions, as well as "async with" and "async for" '
+ 'statements.\n'
+ ' See also the Coroutine Objects section.\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 '
+ "function's\n"
+ ' name; "__self__" is set to "None" (but see the next item);\n'
+ ' "__module__" is the name of the module the function was '
+ 'defined\n'
+ ' in or "None" if unavailable.\n'
+ '\n'
+ ' Built-in methods\n'
+ ' This is really a different disguise of a built-in function, '
+ 'this\n'
+ ' time containing an object passed to the C function as an\n'
+ ' implicit extra argument. An example of a built-in method is\n'
+ ' "alist.append()", assuming *alist* is a list object. In this\n'
+ ' case, the special read-only attribute "__self__" is set to '
+ 'the\n'
+ ' object denoted by *alist*.\n'
+ '\n'
+ ' Classes\n'
+ ' Classes are callable. These objects normally act as '
+ 'factories\n'
+ ' for new instances of themselves, but variations are possible '
+ 'for\n'
+ ' class types that override "__new__()". The arguments of the\n'
+ ' call are passed to "__new__()" and, in the typical case, to\n'
+ ' "__init__()" to initialize the new instance.\n'
+ '\n'
+ ' Class Instances\n'
+ ' Instances of arbitrary classes can be made callable by '
+ 'defining\n'
+ ' a "__call__()" method in their class.\n'
+ '\n'
+ 'Modules\n'
+ ' Modules are a basic organizational unit of Python code, and are\n'
+ ' created by the import system as invoked either by the "import"\n'
+ ' statement (see "import"), or by calling functions such as\n'
+ ' "importlib.import_module()" and built-in "__import__()". A '
+ 'module\n'
+ ' object has a namespace implemented by a dictionary object (this '
+ 'is\n'
+ ' the dictionary referenced by the "__globals__" attribute of\n'
+ ' functions defined in the module). Attribute references are\n'
+ ' translated to lookups in this dictionary, e.g., "m.x" is '
+ 'equivalent\n'
+ ' to "m.__dict__["x"]". A module object does not contain the code\n'
+ " object used to initialize the module (since it isn't needed "
+ 'once\n'
+ ' 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'
+ ' Predefined (writable) attributes: "__name__" is the module\'s '
+ 'name;\n'
+ ' "__doc__" is the module\'s documentation string, or "None" if\n'
+ ' unavailable; "__annotations__" (optional) is a dictionary\n'
+ ' containing *variable annotations* collected during module body\n'
+ ' execution; "__file__" is the pathname of the file from which '
+ 'the\n'
+ ' module was loaded, if it was loaded from a file. The "__file__"\n'
+ ' attribute may be missing for certain types of modules, such as '
+ 'C\n'
+ ' modules that are statically linked into the interpreter; for\n'
+ ' extension modules loaded dynamically from a shared library, it '
+ 'is\n'
+ ' the pathname of the shared library file.\n'
+ '\n'
+ ' Special read-only attribute: "__dict__" is the module\'s '
+ 'namespace\n'
+ ' as a dictionary object.\n'
+ '\n'
+ ' **CPython implementation detail:** Because of the way CPython\n'
+ ' clears module dictionaries, the module dictionary will be '
+ 'cleared\n'
+ ' when the module falls out of scope even if the dictionary still '
+ 'has\n'
+ ' live references. To avoid this, copy the dictionary or keep '
+ 'the\n'
+ ' module around while using its dictionary directly.\n'
+ '\n'
+ 'Custom classes\n'
+ ' Custom class types are typically created by class definitions '
+ '(see\n'
+ ' section Class definitions). A class has a namespace implemented '
+ 'by\n'
+ ' a dictionary object. Class attribute references are translated '
+ 'to\n'
+ ' lookups in this dictionary, e.g., "C.x" is translated to\n'
+ ' "C.__dict__["x"]" (although there are a number of hooks which '
+ 'allow\n'
+ ' for other means of locating attributes). When the attribute name '
+ 'is\n'
+ ' 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'
+ ' https://www.python.org/download/releases/2.3/mro/.\n'
+ '\n'
+ ' When a class attribute reference (for class "C", say) would '
+ 'yield a\n'
+ ' class method object, it is transformed into an instance method\n'
+ ' object whose "__self__" attributes is "C". When it would yield '
+ 'a\n'
+ ' static method object, it is transformed into the object wrapped '
+ 'by\n'
+ ' the static method object. See section Implementing Descriptors '
+ 'for\n'
+ ' another way in which attributes retrieved from a class may '
+ 'differ\n'
+ ' 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__" '
+ 'is\n'
+ ' the module name in which the class was defined; "__dict__" is '
+ 'the\n'
+ ' dictionary containing the class\'s namespace; "__bases__" is a '
+ 'tuple\n'
+ ' (possibly empty or a singleton) containing the base classes, in '
+ 'the\n'
+ ' order of their occurrence in the base class list; "__doc__" is '
+ 'the\n'
+ " class's documentation string, or None if undefined;\n"
+ ' "__annotations__" (optional) is a dictionary containing '
+ '*variable\n'
+ ' annotations* collected during class body execution.\n'
+ '\n'
+ 'Class 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 '
+ 'in\n'
+ ' which attributes of a class retrieved via its instances may '
+ 'differ\n'
+ ' from the objects actually stored in the class\'s "__dict__". If '
+ 'no\n'
+ " class attribute is found, and the object's class has a\n"
+ ' "__getattr__()" method, that is called to satisfy the 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 '
+ 'instead\n'
+ ' 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'
+ '\n'
+ 'I/O objects (also known as file objects)\n'
+ ' A *file object* represents an open file. Various shortcuts are\n'
+ ' available to create file objects: the "open()" built-in '
+ 'function,\n'
+ ' and also "os.popen()", "os.fdopen()", and the "makefile()" '
+ 'method\n'
+ ' of socket objects (and perhaps by other functions or methods\n'
+ ' provided by extension modules).\n'
+ '\n'
+ ' The objects "sys.stdin", "sys.stdout" and "sys.stderr" are\n'
+ " initialized to file objects corresponding to the interpreter's\n"
+ ' standard input, output and error streams; they are all open in '
+ 'text\n'
+ ' mode and therefore follow the interface defined by the\n'
+ ' "io.TextIOBase" abstract class.\n'
+ '\n'
+ 'Internal 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 '
+ 'name;\n'
+ ' "co_argcount" is the number of positional arguments '
+ '(including\n'
+ ' arguments with default values); "co_nlocals" is the number '
+ 'of\n'
+ ' local variables used by the function (including arguments);\n'
+ ' "co_varnames" is a tuple containing the names of the local\n'
+ ' variables (starting with the argument names); "co_cellvars" '
+ 'is a\n'
+ ' tuple containing the names of local variables that are\n'
+ ' referenced by nested functions; "co_freevars" is a tuple\n'
+ ' containing the names of free variables; "co_code" is a '
+ 'string\n'
+ ' representing the sequence of bytecode instructions; '
+ '"co_consts"\n'
+ ' is a tuple containing the literals used by the bytecode;\n'
+ ' "co_names" is a tuple containing the names used by the '
+ 'bytecode;\n'
+ ' "co_filename" is 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 a\n'
+ ' number of flags for the interpreter.\n'
+ '\n'
+ ' The following flag bits are defined for "co_flags": bit '
+ '"0x04"\n'
+ ' is set if the function uses the "*arguments" syntax to accept '
+ 'an\n'
+ ' arbitrary number of positional arguments; bit "0x08" is set '
+ 'if\n'
+ ' the function uses the "**keywords" syntax to accept '
+ 'arbitrary\n'
+ ' keyword arguments; bit "0x20" is set if the function is a\n'
+ ' generator.\n'
+ '\n'
+ ' Future feature declarations ("from __future__ import '
+ 'division")\n'
+ ' also use bits in "co_flags" to indicate whether a code '
+ 'object\n'
+ ' was compiled with a particular feature enabled: bit "0x2000" '
+ 'is\n'
+ ' set if the function was compiled with future division '
+ 'enabled;\n'
+ ' bits "0x10" and "0x1000" were used in earlier versions of\n'
+ ' 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 '
+ 'stack\n'
+ ' frame (towards the caller), or "None" if this is the bottom\n'
+ ' stack frame; "f_code" is the code object being executed in '
+ 'this\n'
+ ' frame; "f_locals" is the dictionary used to look up local\n'
+ ' variables; "f_globals" is used for global variables;\n'
+ ' "f_builtins" is used for built-in (intrinsic) names; '
+ '"f_lasti"\n'
+ ' gives the precise instruction (this is an index into the\n'
+ ' 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 '
+ 'of\n'
+ ' the frame --- writing to this from within a trace function '
+ 'jumps\n'
+ ' to the given line (only for the bottom-most frame). A '
+ 'debugger\n'
+ ' can implement a Jump command (aka Set Next Statement) by '
+ 'writing\n'
+ ' to f_lineno.\n'
+ '\n'
+ ' Frame objects support one method:\n'
+ '\n'
+ ' frame.clear()\n'
+ '\n'
+ ' This method clears all references to local variables held '
+ 'by\n'
+ ' the frame. Also, if the frame belonged to a generator, '
+ 'the\n'
+ ' generator is finalized. This helps break reference '
+ 'cycles\n'
+ ' involving frame objects (for example when catching an\n'
+ ' exception and storing its traceback for later use).\n'
+ '\n'
+ ' "RuntimeError" is raised if the frame is currently '
+ 'executing.\n'
+ '\n'
+ ' New in version 3.4.\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 '
+ 'no\n'
+ ' suitable handler, the stack trace is written (nicely '
+ 'formatted)\n'
+ ' to the standard error stream; if the interpreter is '
+ 'interactive,\n'
+ ' it is also made available to the user as '
+ '"sys.last_traceback".\n'
+ '\n'
+ ' Special read-only attributes: "tb_next" is the next level in '
+ 'the\n'
+ ' stack trace (towards the frame where the exception occurred), '
+ 'or\n'
+ ' "None" if there is no next level; "tb_frame" points to the\n'
+ ' execution frame of the current level; "tb_lineno" gives the '
+ 'line\n'
+ ' number where the exception occurred; "tb_lasti" indicates '
+ 'the\n'
+ ' precise instruction. The line number and last instruction '
+ 'in\n'
+ ' the traceback may differ from the line number of its frame\n'
+ ' object if the exception occurred in a "try" statement with '
+ 'no\n'
+ ' matching except clause 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; '
+ '"stop"\n'
+ ' is the upper bound; "step" is the step value; each is "None" '
+ 'if\n'
+ ' 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': '\n'
+ 'Functions\n'
+ '*********\n'
+ '\n'
+ 'Function objects are created by function definitions. The '
+ 'only\n'
+ 'operation on a function object is to call it: '
+ '"func(argument-list)".\n'
+ '\n'
+ 'There are really two flavors of function objects: built-in '
+ 'functions\n'
+ 'and user-defined functions. Both support the same '
+ 'operation (to call\n'
+ 'the function), but the implementation is different, hence '
+ 'the\n'
+ 'different object types.\n'
+ '\n'
+ 'See Function definitions for more information.\n',
+ 'typesmapping': '\n'
+ 'Mapping Types --- "dict"\n'
+ '************************\n'
+ '\n'
+ 'A *mapping* object maps *hashable* values to arbitrary '
+ 'objects.\n'
+ 'Mappings are mutable objects. There is currently only one '
+ 'standard\n'
+ 'mapping type, the *dictionary*. (For other containers see '
+ 'the built-\n'
+ 'in "list", "set", and "tuple" classes, and the "collections" '
+ 'module.)\n'
+ '\n'
+ "A dictionary's keys are *almost* arbitrary values. Values "
+ 'that are\n'
+ 'not *hashable*, that is, values containing lists, '
+ 'dictionaries or\n'
+ 'other mutable types (that are compared by value rather than '
+ 'by object\n'
+ 'identity) may not be used as keys. Numeric types used for '
+ 'keys obey\n'
+ 'the normal rules for numeric comparison: if two numbers '
+ 'compare equal\n'
+ '(such as "1" and "1.0") then they can be used '
+ 'interchangeably to index\n'
+ 'the same dictionary entry. (Note however, that since '
+ 'computers store\n'
+ 'floating-point numbers as approximations it is usually '
+ 'unwise to use\n'
+ 'them as dictionary keys.)\n'
+ '\n'
+ 'Dictionaries can be created by placing a comma-separated '
+ 'list of "key:\n'
+ 'value" pairs within braces, for example: "{\'jack\': 4098, '
+ "'sjoerd':\n"
+ '4127}" or "{4098: \'jack\', 4127: \'sjoerd\'}", or by the '
+ '"dict"\n'
+ 'constructor.\n'
+ '\n'
+ 'class dict(**kwarg)\n'
+ 'class dict(mapping, **kwarg)\n'
+ 'class dict(iterable, **kwarg)\n'
+ '\n'
+ ' Return a new dictionary initialized from an optional '
+ 'positional\n'
+ ' argument and a possibly empty set of keyword arguments.\n'
+ '\n'
+ ' If no positional argument is given, an empty dictionary '
+ 'is created.\n'
+ ' If a positional argument is given and it is a mapping '
+ 'object, a\n'
+ ' dictionary is created with the same key-value pairs as '
+ 'the mapping\n'
+ ' object. Otherwise, the positional argument must be an '
+ '*iterable*\n'
+ ' object. Each item in the iterable must itself be an '
+ 'iterable with\n'
+ ' exactly two objects. The first object of each item '
+ 'becomes a key\n'
+ ' in the new dictionary, and the second object the '
+ 'corresponding\n'
+ ' value. If a key occurs more than once, the last value '
+ 'for that key\n'
+ ' becomes the corresponding value in the new dictionary.\n'
+ '\n'
+ ' If keyword arguments are given, the keyword arguments and '
+ 'their\n'
+ ' values are added to the dictionary created from the '
+ 'positional\n'
+ ' argument. If a key being added is already present, the '
+ 'value from\n'
+ ' the keyword argument replaces the value from the '
+ 'positional\n'
+ ' argument.\n'
+ '\n'
+ ' To illustrate, the following examples all return a '
+ 'dictionary equal\n'
+ ' to "{"one": 1, "two": 2, "three": 3}":\n'
+ '\n'
+ ' >>> a = dict(one=1, two=2, three=3)\n'
+ " >>> b = {'one': 1, 'two': 2, 'three': 3}\n"
+ " >>> c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))\n"
+ " >>> d = dict([('two', 2), ('one', 1), ('three', 3)])\n"
+ " >>> e = dict({'three': 3, 'one': 1, 'two': 2})\n"
+ ' >>> a == b == c == d == e\n'
+ ' True\n'
+ '\n'
+ ' Providing keyword arguments as in the first example only '
+ 'works for\n'
+ ' keys that are valid Python identifiers. Otherwise, any '
+ 'valid keys\n'
+ ' can be used.\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__()" '
+ 'and *key*\n'
+ ' is not present, the "d[key]" operation calls that '
+ 'method with\n'
+ ' the key *key* as argument. The "d[key]" operation '
+ 'then returns\n'
+ ' or raises whatever is returned or raised by the\n'
+ ' "__missing__(key)" call. No other operations or '
+ 'methods invoke\n'
+ ' "__missing__()". If "__missing__()" is not defined, '
+ '"KeyError"\n'
+ ' is raised. "__missing__()" must be a method; it cannot '
+ 'be an\n'
+ ' instance variable:\n'
+ '\n'
+ ' >>> class Counter(dict):\n'
+ ' ... def __missing__(self, key):\n'
+ ' ... return 0\n'
+ ' >>> c = Counter()\n'
+ " >>> c['red']\n"
+ ' 0\n'
+ " >>> c['red'] += 1\n"
+ " >>> c['red']\n"
+ ' 1\n'
+ '\n'
+ ' The example above shows part of the implementation of\n'
+ ' "collections.Counter". A different "__missing__" '
+ 'method is used\n'
+ ' by "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 not\n'
+ ' in the map.\n'
+ '\n'
+ ' key in d\n'
+ '\n'
+ ' Return "True" if *d* has a key *key*, else "False".\n'
+ '\n'
+ ' key not in d\n'
+ '\n'
+ ' Equivalent to "not key in d".\n'
+ '\n'
+ ' iter(d)\n'
+ '\n'
+ ' Return an iterator over the keys of the dictionary. '
+ 'This is a\n'
+ ' shortcut for "iter(d.keys())".\n'
+ '\n'
+ ' clear()\n'
+ '\n'
+ ' Remove all items from the dictionary.\n'
+ '\n'
+ ' copy()\n'
+ '\n'
+ ' Return a shallow copy of the dictionary.\n'
+ '\n'
+ ' classmethod fromkeys(seq[, value])\n'
+ '\n'
+ ' Create a new dictionary with keys from *seq* and '
+ 'values set to\n'
+ ' *value*.\n'
+ '\n'
+ ' "fromkeys()" is a class method that returns a new '
+ 'dictionary.\n'
+ ' *value* defaults to "None".\n'
+ '\n'
+ ' get(key[, default])\n'
+ '\n'
+ ' Return the value for *key* if *key* is in the '
+ 'dictionary, else\n'
+ ' *default*. If *default* is not given, it defaults to '
+ '"None", so\n'
+ ' that this method never raises a "KeyError".\n'
+ '\n'
+ ' items()\n'
+ '\n'
+ ' Return a new view of the dictionary\'s items ("(key, '
+ 'value)"\n'
+ ' pairs). See the documentation of view objects.\n'
+ '\n'
+ ' keys()\n'
+ '\n'
+ " Return a new view of the dictionary's keys. See the\n"
+ ' documentation of view objects.\n'
+ '\n'
+ ' pop(key[, default])\n'
+ '\n'
+ ' If *key* is in the dictionary, remove it and return '
+ 'its value,\n'
+ ' else return *default*. If *default* is not given and '
+ '*key* is\n'
+ ' not in the dictionary, a "KeyError" is raised.\n'
+ '\n'
+ ' popitem()\n'
+ '\n'
+ ' Remove and return an arbitrary "(key, value)" pair '
+ 'from the\n'
+ ' dictionary.\n'
+ '\n'
+ ' "popitem()" is useful to destructively iterate over a\n'
+ ' dictionary, as often used in set algorithms. If the '
+ 'dictionary\n'
+ ' is empty, calling "popitem()" raises a "KeyError".\n'
+ '\n'
+ ' setdefault(key[, default])\n'
+ '\n'
+ ' If *key* is in the dictionary, return its value. If '
+ 'not, insert\n'
+ ' *key* with a value of *default* and return *default*. '
+ '*default*\n'
+ ' defaults to "None".\n'
+ '\n'
+ ' update([other])\n'
+ '\n'
+ ' Update the dictionary with the key/value pairs from '
+ '*other*,\n'
+ ' overwriting existing keys. Return "None".\n'
+ '\n'
+ ' "update()" accepts either another dictionary object or '
+ 'an\n'
+ ' iterable of key/value pairs (as tuples or other '
+ 'iterables of\n'
+ ' length two). If keyword arguments are specified, the '
+ 'dictionary\n'
+ ' is then updated with those key/value pairs: '
+ '"d.update(red=1,\n'
+ ' blue=2)".\n'
+ '\n'
+ ' values()\n'
+ '\n'
+ " Return a new view of the dictionary's values. See "
+ 'the\n'
+ ' documentation of view objects.\n'
+ '\n'
+ ' Dictionaries compare equal if and only if they have the '
+ 'same "(key,\n'
+ ' value)" pairs. Order comparisons (\'<\', \'<=\', \'>=\', '
+ "'>') raise\n"
+ ' "TypeError".\n'
+ '\n'
+ 'See also: "types.MappingProxyType" can be used to create a '
+ 'read-only\n'
+ ' view of a "dict".\n'
+ '\n'
+ '\n'
+ 'Dictionary view objects\n'
+ '=======================\n'
+ '\n'
+ 'The objects returned by "dict.keys()", "dict.values()" and\n'
+ '"dict.items()" are *view objects*. They provide a dynamic '
+ 'view on the\n'
+ "dictionary's entries, which means that when the dictionary "
+ 'changes,\n'
+ 'the view reflects these changes.\n'
+ '\n'
+ 'Dictionary views can be iterated over to yield their '
+ 'respective data,\n'
+ 'and support membership tests:\n'
+ '\n'
+ 'len(dictview)\n'
+ '\n'
+ ' Return the number of entries in the dictionary.\n'
+ '\n'
+ 'iter(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 using\n'
+ ' "zip()": "pairs = zip(d.values(), d.keys())". Another '
+ 'way to\n'
+ ' create the same list is "pairs = [(v, k) for (k, v) in '
+ 'd.items()]".\n'
+ '\n'
+ ' Iterating views while adding or deleting entries in the '
+ 'dictionary\n'
+ ' may raise a "RuntimeError" or fail to iterate over all '
+ 'entries.\n'
+ '\n'
+ 'x in dictview\n'
+ '\n'
+ ' Return "True" if *x* is in the underlying dictionary\'s '
+ 'keys, values\n'
+ ' or items (in the latter case, *x* should be a "(key, '
+ 'value)"\n'
+ ' tuple).\n'
+ '\n'
+ 'Keys views are set-like since their entries are unique and '
+ 'hashable.\n'
+ 'If all values are hashable, so that "(key, value)" pairs are '
+ 'unique\n'
+ 'and hashable, then the items view is also set-like. (Values '
+ 'views are\n'
+ 'not treated as set-like since the entries are generally not '
+ 'unique.)\n'
+ 'For set-like views, all of the operations defined for the '
+ 'abstract\n'
+ 'base class "collections.abc.Set" are available (for example, '
+ '"==",\n'
+ '"<", or "^").\n'
+ '\n'
+ 'An example of dictionary view usage:\n'
+ '\n'
+ " >>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, "
+ "'spam': 500}\n"
+ ' >>> keys = dishes.keys()\n'
+ ' >>> values = dishes.values()\n'
+ '\n'
+ ' >>> # iteration\n'
+ ' >>> n = 0\n'
+ ' >>> for val in values:\n'
+ ' ... n += val\n'
+ ' >>> print(n)\n'
+ ' 504\n'
+ '\n'
+ ' >>> # keys and values are iterated over in the same '
+ 'order\n'
+ ' >>> list(keys)\n'
+ " ['eggs', 'bacon', 'sausage', 'spam']\n"
+ ' >>> list(values)\n'
+ ' [2, 1, 1, 500]\n'
+ '\n'
+ ' >>> # view objects are dynamic and reflect dict changes\n'
+ " >>> del dishes['eggs']\n"
+ " >>> del dishes['sausage']\n"
+ ' >>> list(keys)\n'
+ " ['spam', 'bacon']\n"
+ '\n'
+ ' >>> # set operations\n'
+ " >>> keys & {'eggs', 'bacon', 'salad'}\n"
+ " {'bacon'}\n"
+ " >>> keys ^ {'sausage', 'juice'}\n"
+ " {'juice', 'sausage', 'bacon', 'spam'}\n",
+ 'typesmethods': '\n'
+ 'Methods\n'
+ '*******\n'
+ '\n'
+ 'Methods are functions that are called using the attribute '
+ 'notation.\n'
+ 'There are two flavors: built-in methods (such as "append()" '
+ 'on lists)\n'
+ 'and class instance methods. Built-in methods are described '
+ 'with the\n'
+ 'types that support them.\n'
+ '\n'
+ 'If you access a method (a function defined in a class '
+ 'namespace)\n'
+ 'through an instance, you get a special object: a *bound '
+ 'method* (also\n'
+ 'called *instance method*) object. When called, it will add '
+ 'the "self"\n'
+ 'argument to the argument list. Bound methods have two '
+ 'special read-\n'
+ 'only attributes: "m.__self__" is the object on which the '
+ 'method\n'
+ 'operates, and "m.__func__" is the function implementing the '
+ 'method.\n'
+ 'Calling "m(arg-1, arg-2, ..., arg-n)" is completely '
+ 'equivalent to\n'
+ 'calling "m.__func__(m.__self__, arg-1, arg-2, ..., arg-n)".\n'
+ '\n'
+ 'Like function objects, bound method objects support getting '
+ 'arbitrary\n'
+ 'attributes. However, since method attributes are actually '
+ 'stored on\n'
+ 'the underlying function object ("meth.__func__"), setting '
+ 'method\n'
+ 'attributes on bound methods is disallowed. Attempting to '
+ 'set an\n'
+ 'attribute on a method results in an "AttributeError" being '
+ 'raised. In\n'
+ 'order to set a method attribute, you need to explicitly set '
+ 'it on the\n'
+ 'underlying function object:\n'
+ '\n'
+ ' >>> class C:\n'
+ ' ... def method(self):\n'
+ ' ... pass\n'
+ ' ...\n'
+ ' >>> c = C()\n'
+ " >>> c.method.whoami = 'my name is method' # can't set on "
+ 'the method\n'
+ ' Traceback (most recent call last):\n'
+ ' File "<stdin>", line 1, in <module>\n'
+ " AttributeError: 'method' object has no attribute "
+ "'whoami'\n"
+ " >>> c.method.__func__.whoami = 'my name is method'\n"
+ ' >>> c.method.whoami\n'
+ " 'my name is method'\n"
+ '\n'
+ 'See The standard type hierarchy for more information.\n',
+ 'typesmodules': '\n'
+ 'Modules\n'
+ '*******\n'
+ '\n'
+ 'The only special operation on a module is attribute access: '
+ '"m.name",\n'
+ 'where *m* is a module and *name* accesses a name defined in '
+ "*m*'s\n"
+ 'symbol table. Module attributes can be assigned to. (Note '
+ 'that the\n'
+ '"import" statement is not, strictly speaking, an operation '
+ 'on a module\n'
+ 'object; "import foo" does not require a module object named '
+ '*foo* to\n'
+ 'exist, rather it requires an (external) *definition* for a '
+ 'module\n'
+ 'named *foo* somewhere.)\n'
+ '\n'
+ 'A special attribute of every module is "__dict__". This is '
+ 'the\n'
+ "dictionary containing the module's symbol table. Modifying "
+ 'this\n'
+ "dictionary will actually change the module's symbol table, "
+ 'but direct\n'
+ 'assignment to the "__dict__" attribute is not possible (you '
+ 'can write\n'
+ '"m.__dict__[\'a\'] = 1", which defines "m.a" to be "1", but '
+ "you can't\n"
+ 'write "m.__dict__ = {}"). Modifying "__dict__" directly is '
+ 'not\n'
+ 'recommended.\n'
+ '\n'
+ 'Modules built into the interpreter are written like this: '
+ '"<module\n'
+ '\'sys\' (built-in)>". If loaded from a file, they are '
+ 'written as\n'
+ '"<module \'os\' from '
+ '\'/usr/local/lib/pythonX.Y/os.pyc\'>".\n',
+ 'typesseq': '\n'
+ 'Sequence Types --- "list", "tuple", "range"\n'
+ '*******************************************\n'
+ '\n'
+ 'There are three basic sequence types: lists, tuples, and range\n'
+ 'objects. Additional sequence types tailored for processing of '
+ 'binary\n'
+ 'data and text strings are described in dedicated sections.\n'
+ '\n'
+ '\n'
+ 'Common Sequence Operations\n'
+ '==========================\n'
+ '\n'
+ 'The operations in the following table are supported by most '
+ 'sequence\n'
+ 'types, both mutable and immutable. The '
+ '"collections.abc.Sequence" ABC\n'
+ 'is provided to make it easier to correctly implement these '
+ 'operations\n'
+ 'on custom sequence types.\n'
+ '\n'
+ 'This table lists the sequence operations sorted in ascending '
+ 'priority.\n'
+ 'In the table, *s* and *t* are sequences of the same type, *n*, '
+ '*i*,\n'
+ '*j* and *k* are integers and *x* is an arbitrary object that '
+ 'meets any\n'
+ 'type and value restrictions imposed by *s*.\n'
+ '\n'
+ 'The "in" and "not in" operations have the same priorities as '
+ 'the\n'
+ 'comparison operations. The "+" (concatenation) and "*" '
+ '(repetition)\n'
+ 'operations have the same priority as the corresponding numeric\n'
+ 'operations.\n'
+ '\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| Operation | Result '
+ '| Notes |\n'
+ '+============================+==================================+============+\n'
+ '| "x in s" | "True" if an item of *s* is '
+ '| (1) |\n'
+ '| | equal to *x*, else "False" '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "x not in s" | "False" if an item of *s* is '
+ '| (1) |\n'
+ '| | equal to *x*, else "True" '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "s + t" | the concatenation of *s* and *t* '
+ '| (6)(7) |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "s * n" or "n * s" | equivalent to adding *s* to '
+ '| (2)(7) |\n'
+ '| | itself *n* times '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "s[i]" | *i*th item of *s*, origin 0 '
+ '| (3) |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "s[i:j]" | slice of *s* from *i* to *j* '
+ '| (3)(4) |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "s[i:j:k]" | slice of *s* from *i* to *j* '
+ '| (3)(5) |\n'
+ '| | with step *k* '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "len(s)" | length of *s* '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "min(s)" | smallest item of *s* '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "max(s)" | largest item of *s* '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "s.index(x[, i[, j]])" | index of the first occurrence of '
+ '| (8) |\n'
+ '| | *x* in *s* (at or after index '
+ '| |\n'
+ '| | *i* and before index *j*) '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '| "s.count(x)" | total number of occurrences of '
+ '| |\n'
+ '| | *x* in *s* '
+ '| |\n'
+ '+----------------------------+----------------------------------+------------+\n'
+ '\n'
+ 'Sequences of the same type also support comparisons. In '
+ 'particular,\n'
+ 'tuples and lists are compared lexicographically by comparing\n'
+ 'corresponding elements. This means that to compare equal, every\n'
+ 'element must compare equal and the two sequences must be of the '
+ 'same\n'
+ 'type and have the same length. (For full details see '
+ 'Comparisons in\n'
+ 'the language reference.)\n'
+ '\n'
+ 'Notes:\n'
+ '\n'
+ '1. While the "in" and "not in" operations are used only for '
+ 'simple\n'
+ ' containment testing in the general case, some specialised '
+ 'sequences\n'
+ ' (such as "str", "bytes" and "bytearray") also use them for\n'
+ ' subsequence testing:\n'
+ '\n'
+ ' >>> "gg" in "eggs"\n'
+ ' True\n'
+ '\n'
+ '2. Values of *n* less than "0" are treated as "0" (which yields '
+ 'an\n'
+ ' empty sequence of the same type as *s*). Note that items in '
+ 'the\n'
+ ' sequence *s* are not copied; they are referenced multiple '
+ 'times.\n'
+ ' This often haunts 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 '
+ 'references\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'
+ '\n'
+ ' Further explanation is available in the FAQ entry How do I '
+ 'create a\n'
+ ' multidimensional list?.\n'
+ '\n'
+ '3. If *i* or *j* is negative, the index is relative to the end '
+ 'of\n'
+ ' the string: "len(s) + i" or "len(s) + j" is substituted. But '
+ 'note\n'
+ ' that "-0" is still "0".\n'
+ '\n'
+ '4. 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 '
+ '"None",\n'
+ ' use "0". If *j* is omitted or "None", use "len(s)". If *i* '
+ 'is\n'
+ ' greater than or equal to *j*, the slice is empty.\n'
+ '\n'
+ '5. 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", '
+ '"i+2*k",\n'
+ ' "i+3*k" and so on, stopping when *j* is reached (but never\n'
+ ' including *j*). If *i* or *j* is greater than "len(s)", use\n'
+ ' "len(s)". If *i* or *j* are omitted or "None", they become '
+ '"end"\n'
+ ' values (which end depends on the sign of *k*). Note, *k* '
+ 'cannot be\n'
+ ' zero. If *k* is "None", it is treated like "1".\n'
+ '\n'
+ '6. Concatenating immutable sequences always results in a new\n'
+ ' object. This means that building up a sequence by repeated\n'
+ ' concatenation will have a quadratic runtime cost in the '
+ 'total\n'
+ ' sequence length. To get a linear runtime cost, you must '
+ 'switch to\n'
+ ' one of the alternatives below:\n'
+ '\n'
+ ' * if concatenating "str" objects, you can build a list and '
+ 'use\n'
+ ' "str.join()" at the end or else write to an "io.StringIO"\n'
+ ' instance and retrieve its value when complete\n'
+ '\n'
+ ' * if concatenating "bytes" objects, you can similarly use\n'
+ ' "bytes.join()" or "io.BytesIO", or you can do in-place\n'
+ ' concatenation with a "bytearray" object. "bytearray" '
+ 'objects are\n'
+ ' mutable and have an efficient overallocation mechanism\n'
+ '\n'
+ ' * if concatenating "tuple" objects, extend a "list" instead\n'
+ '\n'
+ ' * for other types, investigate the relevant class '
+ 'documentation\n'
+ '\n'
+ '7. Some sequence types (such as "range") only support item\n'
+ " sequences that follow specific patterns, and hence don't "
+ 'support\n'
+ ' sequence concatenation or repetition.\n'
+ '\n'
+ '8. "index" raises "ValueError" when *x* is not found in *s*. '
+ 'When\n'
+ ' supported, the additional arguments to the index method '
+ 'allow\n'
+ ' efficient searching of subsections of the sequence. Passing '
+ 'the\n'
+ ' extra arguments is roughly equivalent to using '
+ '"s[i:j].index(x)",\n'
+ ' only without copying any data and with the returned index '
+ 'being\n'
+ ' relative to the start of the sequence rather than the start '
+ 'of the\n'
+ ' slice.\n'
+ '\n'
+ '\n'
+ 'Immutable Sequence Types\n'
+ '========================\n'
+ '\n'
+ 'The only operation that immutable sequence types generally '
+ 'implement\n'
+ 'that is not also implemented by mutable sequence types is '
+ 'support for\n'
+ 'the "hash()" built-in.\n'
+ '\n'
+ 'This support allows immutable sequences, such as "tuple" '
+ 'instances, to\n'
+ 'be used as "dict" keys and stored in "set" and "frozenset" '
+ 'instances.\n'
+ '\n'
+ 'Attempting to hash an immutable sequence that contains '
+ 'unhashable\n'
+ 'values will result in "TypeError".\n'
+ '\n'
+ '\n'
+ 'Mutable Sequence Types\n'
+ '======================\n'
+ '\n'
+ 'The operations in the following table are defined on mutable '
+ 'sequence\n'
+ 'types. The "collections.abc.MutableSequence" ABC is provided to '
+ 'make\n'
+ 'it easier to correctly implement these operations on custom '
+ 'sequence\n'
+ 'types.\n'
+ '\n'
+ 'In the table *s* is an instance of a mutable sequence type, *t* '
+ 'is any\n'
+ 'iterable object and *x* is an arbitrary object that meets any '
+ 'type and\n'
+ 'value restrictions imposed by *s* (for example, "bytearray" '
+ 'only\n'
+ 'accepts integers that meet the value restriction "0 <= x <= '
+ '255").\n'
+ '\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| Operation | '
+ 'Result | Notes |\n'
+ '+================================+==================================+=======================+\n'
+ '| "s[i] = x" | item *i* of *s* is replaced '
+ 'by | |\n'
+ '| | '
+ '*x* | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s[i:j] = t" | slice of *s* from *i* to *j* '
+ 'is | |\n'
+ '| | replaced by the contents of '
+ 'the | |\n'
+ '| | iterable '
+ '*t* | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "del s[i:j]" | same as "s[i:j] = '
+ '[]" | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s[i:j:k] = t" | the elements of "s[i:j:k]" '
+ 'are | (1) |\n'
+ '| | replaced by those of '
+ '*t* | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "del s[i:j:k]" | removes the elements '
+ 'of | |\n'
+ '| | "s[i:j:k]" from the '
+ 'list | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.append(x)" | appends *x* to the end of '
+ 'the | |\n'
+ '| | sequence (same '
+ 'as | |\n'
+ '| | "s[len(s):len(s)] = '
+ '[x]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.clear()" | removes all items from "s" '
+ '(same | (5) |\n'
+ '| | as "del '
+ 's[:]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.copy()" | creates a shallow copy of '
+ '"s" | (5) |\n'
+ '| | (same as '
+ '"s[:]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.extend(t)" or "s += t" | extends *s* with the contents '
+ 'of | |\n'
+ '| | *t* (for the most part the '
+ 'same | |\n'
+ '| | as "s[len(s):len(s)] = '
+ 't") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s *= n" | updates *s* with its '
+ 'contents | (6) |\n'
+ '| | repeated *n* '
+ 'times | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.insert(i, x)" | inserts *x* into *s* at '
+ 'the | |\n'
+ '| | index given by *i* (same '
+ 'as | |\n'
+ '| | "s[i:i] = '
+ '[x]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.pop([i])" | retrieves the item at *i* '
+ 'and | (2) |\n'
+ '| | also removes it from '
+ '*s* | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.remove(x)" | remove the first item from '
+ '*s* | (3) |\n'
+ '| | where "s[i] == '
+ 'x" | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.reverse()" | reverses the items of *s* '
+ 'in | (4) |\n'
+ '| | '
+ 'place | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '\n'
+ 'Notes:\n'
+ '\n'
+ '1. *t* must have the same length as the slice it is replacing.\n'
+ '\n'
+ '2. The optional argument *i* defaults to "-1", so that by '
+ 'default\n'
+ ' the last item is removed and returned.\n'
+ '\n'
+ '3. "remove" raises "ValueError" when *x* is not found in *s*.\n'
+ '\n'
+ '4. The "reverse()" method modifies the sequence in place for\n'
+ ' economy of space when reversing a large sequence. To remind '
+ 'users\n'
+ ' that it operates by side effect, it does not return the '
+ 'reversed\n'
+ ' sequence.\n'
+ '\n'
+ '5. "clear()" and "copy()" are included for consistency with the\n'
+ " interfaces of mutable containers that don't support slicing\n"
+ ' operations (such as "dict" and "set")\n'
+ '\n'
+ ' New in version 3.3: "clear()" and "copy()" methods.\n'
+ '\n'
+ '6. The value *n* is an integer, or an object implementing\n'
+ ' "__index__()". Zero and negative values of *n* clear the '
+ 'sequence.\n'
+ ' Items in the sequence are not copied; they are referenced '
+ 'multiple\n'
+ ' times, as explained for "s * n" under Common Sequence '
+ 'Operations.\n'
+ '\n'
+ '\n'
+ 'Lists\n'
+ '=====\n'
+ '\n'
+ 'Lists are mutable sequences, typically used to store collections '
+ 'of\n'
+ 'homogeneous items (where the precise degree of similarity will '
+ 'vary by\n'
+ 'application).\n'
+ '\n'
+ 'class list([iterable])\n'
+ '\n'
+ ' Lists may be constructed in several ways:\n'
+ '\n'
+ ' * Using a pair of square brackets to denote the empty list: '
+ '"[]"\n'
+ '\n'
+ ' * Using square brackets, separating items with commas: '
+ '"[a]",\n'
+ ' "[a, b, c]"\n'
+ '\n'
+ ' * Using a list comprehension: "[x for x in iterable]"\n'
+ '\n'
+ ' * Using the type constructor: "list()" or "list(iterable)"\n'
+ '\n'
+ ' The constructor builds a list whose items are the same and in '
+ 'the\n'
+ " same order as *iterable*'s items. *iterable* may be either "
+ 'a\n'
+ ' sequence, a container that supports iteration, or an '
+ 'iterator\n'
+ ' object. If *iterable* is already a list, a copy is made and\n'
+ ' returned, similar to "iterable[:]". For example, '
+ '"list(\'abc\')"\n'
+ ' returns "[\'a\', \'b\', \'c\']" and "list( (1, 2, 3) )" '
+ 'returns "[1, 2,\n'
+ ' 3]". If no argument is given, the constructor creates a new '
+ 'empty\n'
+ ' list, "[]".\n'
+ '\n'
+ ' Many other operations also produce lists, including the '
+ '"sorted()"\n'
+ ' built-in.\n'
+ '\n'
+ ' Lists implement all of the common and mutable sequence '
+ 'operations.\n'
+ ' Lists also provide the following additional method:\n'
+ '\n'
+ ' sort(*, key=None, reverse=None)\n'
+ '\n'
+ ' This method sorts the list in place, using only "<" '
+ 'comparisons\n'
+ ' between items. Exceptions are not suppressed - if any '
+ 'comparison\n'
+ ' operations fail, the entire sort operation will fail (and '
+ 'the\n'
+ ' list will likely be left in a partially modified state).\n'
+ '\n'
+ ' "sort()" accepts two arguments that can only be passed by\n'
+ ' keyword (keyword-only arguments):\n'
+ '\n'
+ ' *key* specifies a function of one argument that is used '
+ 'to\n'
+ ' extract a comparison key from each list element (for '
+ 'example,\n'
+ ' "key=str.lower"). The key corresponding to each item in '
+ 'the list\n'
+ ' is calculated once and then used for the entire sorting '
+ 'process.\n'
+ ' The default value of "None" means that list items are '
+ 'sorted\n'
+ ' directly without calculating a separate key value.\n'
+ '\n'
+ ' The "functools.cmp_to_key()" utility is available to '
+ 'convert a\n'
+ ' 2.x style *cmp* function to a *key* function.\n'
+ '\n'
+ ' *reverse* is a boolean value. If set to "True", then the '
+ 'list\n'
+ ' elements are sorted as if each comparison were reversed.\n'
+ '\n'
+ ' This method modifies the sequence in place for economy of '
+ 'space\n'
+ ' when sorting a large sequence. To remind users that it '
+ 'operates\n'
+ ' by side effect, it does not return the sorted sequence '
+ '(use\n'
+ ' "sorted()" to explicitly request a new sorted list '
+ 'instance).\n'
+ '\n'
+ ' The "sort()" method is guaranteed to be stable. A sort '
+ 'is\n'
+ ' stable if it guarantees not to change the relative order '
+ 'of\n'
+ ' elements that compare equal --- this is helpful for '
+ 'sorting in\n'
+ ' multiple passes (for example, sort by department, then by '
+ 'salary\n'
+ ' grade).\n'
+ '\n'
+ ' **CPython implementation detail:** While a list is being '
+ 'sorted,\n'
+ ' the effect of attempting to mutate, or even inspect, the '
+ 'list is\n'
+ ' undefined. The C implementation of Python makes the list '
+ 'appear\n'
+ ' empty for the duration, and raises "ValueError" if it can '
+ 'detect\n'
+ ' that the list has been mutated during a sort.\n'
+ '\n'
+ '\n'
+ 'Tuples\n'
+ '======\n'
+ '\n'
+ 'Tuples are immutable sequences, typically used to store '
+ 'collections of\n'
+ 'heterogeneous data (such as the 2-tuples produced by the '
+ '"enumerate()"\n'
+ 'built-in). Tuples are also used for cases where an immutable '
+ 'sequence\n'
+ 'of homogeneous data is needed (such as allowing storage in a '
+ '"set" or\n'
+ '"dict" instance).\n'
+ '\n'
+ 'class tuple([iterable])\n'
+ '\n'
+ ' Tuples may be constructed in a number of ways:\n'
+ '\n'
+ ' * Using a pair of parentheses to denote the empty tuple: '
+ '"()"\n'
+ '\n'
+ ' * Using a trailing comma for a singleton tuple: "a," or '
+ '"(a,)"\n'
+ '\n'
+ ' * Separating items with commas: "a, b, c" or "(a, b, c)"\n'
+ '\n'
+ ' * Using the "tuple()" built-in: "tuple()" or '
+ '"tuple(iterable)"\n'
+ '\n'
+ ' The constructor builds a tuple whose items are the same and '
+ 'in the\n'
+ " same order as *iterable*'s items. *iterable* may be either "
+ 'a\n'
+ ' sequence, a container that supports iteration, or an '
+ 'iterator\n'
+ ' object. If *iterable* is already a tuple, it is returned\n'
+ ' unchanged. For example, "tuple(\'abc\')" returns "(\'a\', '
+ '\'b\', \'c\')"\n'
+ ' and "tuple( [1, 2, 3] )" returns "(1, 2, 3)". If no argument '
+ 'is\n'
+ ' given, the constructor creates a new empty tuple, "()".\n'
+ '\n'
+ ' Note that it is actually the comma which makes a tuple, not '
+ 'the\n'
+ ' parentheses. The parentheses are optional, except in the '
+ 'empty\n'
+ ' tuple case, or when they are needed to avoid syntactic '
+ 'ambiguity.\n'
+ ' For example, "f(a, b, c)" is a function call with three '
+ 'arguments,\n'
+ ' while "f((a, b, c))" is a function call with a 3-tuple as the '
+ 'sole\n'
+ ' argument.\n'
+ '\n'
+ ' Tuples implement all of the common sequence operations.\n'
+ '\n'
+ 'For heterogeneous collections of data where access by name is '
+ 'clearer\n'
+ 'than access by index, "collections.namedtuple()" may be a more\n'
+ 'appropriate choice than a simple tuple object.\n'
+ '\n'
+ '\n'
+ 'Ranges\n'
+ '======\n'
+ '\n'
+ 'The "range" type represents an immutable sequence of numbers and '
+ 'is\n'
+ 'commonly used for looping a specific number of times in "for" '
+ 'loops.\n'
+ '\n'
+ 'class range(stop)\n'
+ 'class range(start, stop[, step])\n'
+ '\n'
+ ' The arguments to the range constructor must be integers '
+ '(either\n'
+ ' built-in "int" or any object that implements the "__index__"\n'
+ ' special method). If the *step* argument is omitted, it '
+ 'defaults to\n'
+ ' "1". If the *start* argument is omitted, it defaults to "0". '
+ 'If\n'
+ ' *step* is zero, "ValueError" is raised.\n'
+ '\n'
+ ' For a positive *step*, the contents of a range "r" are '
+ 'determined\n'
+ ' by the formula "r[i] = start + step*i" where "i >= 0" and '
+ '"r[i] <\n'
+ ' stop".\n'
+ '\n'
+ ' For a negative *step*, the contents of the range are still\n'
+ ' determined by the formula "r[i] = start + step*i", but the\n'
+ ' constraints are "i >= 0" and "r[i] > stop".\n'
+ '\n'
+ ' A range object will be empty if "r[0]" does not meet the '
+ 'value\n'
+ ' constraint. Ranges do support negative indices, but these '
+ 'are\n'
+ ' interpreted as indexing from the end of the sequence '
+ 'determined by\n'
+ ' the positive indices.\n'
+ '\n'
+ ' Ranges containing absolute values larger than "sys.maxsize" '
+ 'are\n'
+ ' permitted but some features (such as "len()") may raise\n'
+ ' "OverflowError".\n'
+ '\n'
+ ' Range examples:\n'
+ '\n'
+ ' >>> list(range(10))\n'
+ ' [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n'
+ ' >>> list(range(1, 11))\n'
+ ' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n'
+ ' >>> list(range(0, 30, 5))\n'
+ ' [0, 5, 10, 15, 20, 25]\n'
+ ' >>> list(range(0, 10, 3))\n'
+ ' [0, 3, 6, 9]\n'
+ ' >>> list(range(0, -10, -1))\n'
+ ' [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n'
+ ' >>> list(range(0))\n'
+ ' []\n'
+ ' >>> list(range(1, 0))\n'
+ ' []\n'
+ '\n'
+ ' Ranges implement all of the common sequence operations '
+ 'except\n'
+ ' concatenation and repetition (due to the fact that range '
+ 'objects\n'
+ ' can only represent sequences that follow a strict pattern '
+ 'and\n'
+ ' repetition and concatenation will usually violate that '
+ 'pattern).\n'
+ '\n'
+ ' start\n'
+ '\n'
+ ' The value of the *start* parameter (or "0" if the '
+ 'parameter was\n'
+ ' not supplied)\n'
+ '\n'
+ ' stop\n'
+ '\n'
+ ' The value of the *stop* parameter\n'
+ '\n'
+ ' step\n'
+ '\n'
+ ' The value of the *step* parameter (or "1" if the parameter '
+ 'was\n'
+ ' not supplied)\n'
+ '\n'
+ 'The advantage of the "range" type over a regular "list" or '
+ '"tuple" is\n'
+ 'that a "range" object will always take the same (small) amount '
+ 'of\n'
+ 'memory, no matter the size of the range it represents (as it '
+ 'only\n'
+ 'stores the "start", "stop" and "step" values, calculating '
+ 'individual\n'
+ 'items and subranges as needed).\n'
+ '\n'
+ 'Range objects implement the "collections.abc.Sequence" ABC, and\n'
+ 'provide features such as containment tests, element index '
+ 'lookup,\n'
+ 'slicing and support for negative indices (see Sequence Types --- '
+ 'list,\n'
+ 'tuple, range):\n'
+ '\n'
+ '>>> r = range(0, 20, 2)\n'
+ '>>> r\n'
+ 'range(0, 20, 2)\n'
+ '>>> 11 in r\n'
+ 'False\n'
+ '>>> 10 in r\n'
+ 'True\n'
+ '>>> r.index(10)\n'
+ '5\n'
+ '>>> r[5]\n'
+ '10\n'
+ '>>> r[:5]\n'
+ 'range(0, 10, 2)\n'
+ '>>> r[-1]\n'
+ '18\n'
+ '\n'
+ 'Testing range objects for equality with "==" and "!=" compares '
+ 'them as\n'
+ 'sequences. That is, two range objects are considered equal if '
+ 'they\n'
+ 'represent the same sequence of values. (Note that two range '
+ 'objects\n'
+ 'that compare equal might have different "start", "stop" and '
+ '"step"\n'
+ 'attributes, for example "range(0) == range(2, 1, 3)" or '
+ '"range(0, 3,\n'
+ '2) == range(0, 4, 2)".)\n'
+ '\n'
+ 'Changed in version 3.2: Implement the Sequence ABC. Support '
+ 'slicing\n'
+ 'and negative indices. Test "int" objects for membership in '
+ 'constant\n'
+ 'time instead of iterating through all items.\n'
+ '\n'
+ "Changed in version 3.3: Define '==' and '!=' to compare range "
+ 'objects\n'
+ 'based on the sequence of values they define (instead of '
+ 'comparing\n'
+ 'based on object identity).\n'
+ '\n'
+ 'New in version 3.3: The "start", "stop" and "step" attributes.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' * The linspace recipe shows how to implement a lazy version '
+ 'of\n'
+ ' range that suitable for floating point applications.\n',
+ 'typesseq-mutable': '\n'
+ 'Mutable Sequence Types\n'
+ '**********************\n'
+ '\n'
+ 'The operations in the following table are defined on '
+ 'mutable sequence\n'
+ 'types. The "collections.abc.MutableSequence" ABC is '
+ 'provided to make\n'
+ 'it easier to correctly implement these operations on '
+ 'custom sequence\n'
+ 'types.\n'
+ '\n'
+ 'In the table *s* is an instance of a mutable sequence '
+ 'type, *t* is any\n'
+ 'iterable object and *x* is an arbitrary object that '
+ 'meets any type and\n'
+ 'value restrictions imposed by *s* (for example, '
+ '"bytearray" only\n'
+ 'accepts integers that meet the value restriction "0 <= x '
+ '<= 255").\n'
+ '\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| Operation | '
+ 'Result | Notes '
+ '|\n'
+ '+================================+==================================+=======================+\n'
+ '| "s[i] = x" | item *i* of *s* is '
+ 'replaced by | |\n'
+ '| | '
+ '*x* | '
+ '|\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s[i:j] = t" | slice of *s* from *i* '
+ 'to *j* is | |\n'
+ '| | replaced by the '
+ 'contents of the | |\n'
+ '| | iterable '
+ '*t* | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "del s[i:j]" | same as "s[i:j] = '
+ '[]" | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s[i:j:k] = t" | the elements of '
+ '"s[i:j:k]" are | (1) |\n'
+ '| | replaced by those of '
+ '*t* | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "del s[i:j:k]" | removes the elements '
+ 'of | |\n'
+ '| | "s[i:j:k]" from the '
+ 'list | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.append(x)" | appends *x* to the '
+ 'end of the | |\n'
+ '| | sequence (same '
+ 'as | |\n'
+ '| | "s[len(s):len(s)] = '
+ '[x]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.clear()" | removes all items '
+ 'from "s" (same | (5) |\n'
+ '| | as "del '
+ 's[:]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.copy()" | creates a shallow '
+ 'copy of "s" | (5) |\n'
+ '| | (same as '
+ '"s[:]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.extend(t)" or "s += t" | extends *s* with the '
+ 'contents of | |\n'
+ '| | *t* (for the most '
+ 'part the same | |\n'
+ '| | as "s[len(s):len(s)] '
+ '= t") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s *= n" | updates *s* with its '
+ 'contents | (6) |\n'
+ '| | repeated *n* '
+ 'times | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.insert(i, x)" | inserts *x* into *s* '
+ 'at the | |\n'
+ '| | index given by *i* '
+ '(same as | |\n'
+ '| | "s[i:i] = '
+ '[x]") | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.pop([i])" | retrieves the item at '
+ '*i* and | (2) |\n'
+ '| | also removes it from '
+ '*s* | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.remove(x)" | remove the first item '
+ 'from *s* | (3) |\n'
+ '| | where "s[i] == '
+ 'x" | |\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '| "s.reverse()" | reverses the items of '
+ '*s* in | (4) |\n'
+ '| | '
+ 'place | '
+ '|\n'
+ '+--------------------------------+----------------------------------+-----------------------+\n'
+ '\n'
+ 'Notes:\n'
+ '\n'
+ '1. *t* must have the same length as the slice it is '
+ 'replacing.\n'
+ '\n'
+ '2. The optional argument *i* defaults to "-1", so that '
+ 'by default\n'
+ ' the last item is removed and returned.\n'
+ '\n'
+ '3. "remove" raises "ValueError" when *x* is not found in '
+ '*s*.\n'
+ '\n'
+ '4. The "reverse()" method modifies the sequence in place '
+ 'for\n'
+ ' economy of space when reversing a large sequence. To '
+ 'remind users\n'
+ ' that it operates by side effect, it does not return '
+ 'the reversed\n'
+ ' sequence.\n'
+ '\n'
+ '5. "clear()" and "copy()" are included for consistency '
+ 'with the\n'
+ " interfaces of mutable containers that don't support "
+ 'slicing\n'
+ ' operations (such as "dict" and "set")\n'
+ '\n'
+ ' New in version 3.3: "clear()" and "copy()" methods.\n'
+ '\n'
+ '6. The value *n* is an integer, or an object '
+ 'implementing\n'
+ ' "__index__()". Zero and negative values of *n* clear '
+ 'the sequence.\n'
+ ' Items in the sequence are not copied; they are '
+ 'referenced multiple\n'
+ ' times, as explained for "s * n" under Common Sequence '
+ 'Operations.\n',
+ 'unary': '\n'
+ 'Unary arithmetic and bitwise operations\n'
+ '***************************************\n'
+ '\n'
+ 'All unary arithmetic and bitwise operations have the same '
+ 'priority:\n'
+ '\n'
+ ' u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n'
+ '\n'
+ 'The unary "-" (minus) operator yields the negation of its numeric\n'
+ 'argument.\n'
+ '\n'
+ 'The unary "+" (plus) operator yields its numeric argument '
+ 'unchanged.\n'
+ '\n'
+ 'The unary "~" (invert) operator yields the bitwise inversion of '
+ 'its\n'
+ 'integer argument. The bitwise inversion of "x" is defined as\n'
+ '"-(x+1)". It only applies to integral numbers.\n'
+ '\n'
+ 'In all three cases, if the argument does not have the proper type, '
+ 'a\n'
+ '"TypeError" exception is raised.\n',
+ 'while': '\n'
+ 'The "while" statement\n'
+ '*********************\n'
+ '\n'
+ 'The "while" statement is used for repeated execution as long as an\n'
+ 'expression is true:\n'
+ '\n'
+ ' while_stmt ::= "while" expression ":" suite\n'
+ ' ["else" ":" suite]\n'
+ '\n'
+ 'This repeatedly tests the expression and, if it is true, executes '
+ 'the\n'
+ 'first suite; if the expression is false (which may be the first '
+ 'time\n'
+ 'it is tested) the suite of the "else" clause, if present, is '
+ 'executed\n'
+ 'and the loop terminates.\n'
+ '\n'
+ 'A "break" statement executed in the first suite terminates the '
+ 'loop\n'
+ 'without executing the "else" clause\'s suite. A "continue" '
+ 'statement\n'
+ 'executed in the first suite skips the rest of the suite and goes '
+ 'back\n'
+ 'to testing the expression.\n',
+ 'with': '\n'
+ 'The "with" statement\n'
+ '********************\n'
+ '\n'
+ 'The "with" statement is used to wrap the execution of a block with\n'
+ 'methods defined by a context manager (see section With Statement\n'
+ 'Context Managers). This allows common "try"..."except"..."finally"\n'
+ 'usage patterns to be encapsulated for convenient reuse.\n'
+ '\n'
+ ' with_stmt ::= "with" with_item ("," with_item)* ":" suite\n'
+ ' with_item ::= expression ["as" target]\n'
+ '\n'
+ 'The execution of the "with" statement with one "item" proceeds as\n'
+ 'follows:\n'
+ '\n'
+ '1. The context expression (the expression given in the "with_item")\n'
+ ' is evaluated to obtain a context manager.\n'
+ '\n'
+ '2. The context manager\'s "__exit__()" is loaded for later use.\n'
+ '\n'
+ '3. The context manager\'s "__enter__()" method is invoked.\n'
+ '\n'
+ '4. 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 '
+ 'be\n'
+ ' called. Thus, if an error occurs during the assignment to the\n'
+ ' target list, it will be treated the same as an error occurring\n'
+ ' within the suite would be. See step 6 below.\n'
+ '\n'
+ '5. The suite is executed.\n'
+ '\n'
+ '6. 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, '
+ 'three\n'
+ ' "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 '
+ 'reraised.\n'
+ ' If the return value was true, the exception is suppressed, and\n'
+ ' execution continues with the statement following the "with"\n'
+ ' 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'
+ '\n'
+ 'With more than one item, the context managers are processed as if\n'
+ 'multiple "with" statements were nested:\n'
+ '\n'
+ ' with A() as a, B() as b:\n'
+ ' suite\n'
+ '\n'
+ 'is equivalent to\n'
+ '\n'
+ ' with A() as a:\n'
+ ' with B() as b:\n'
+ ' suite\n'
+ '\n'
+ 'Changed in version 3.1: Support for multiple context expressions.\n'
+ '\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 343** - The "with" statement\n'
+ ' The specification, background, and examples for the Python '
+ '"with"\n'
+ ' statement.\n',
+ 'yield': '\n'
+ 'The "yield" statement\n'
+ '*********************\n'
+ '\n'
+ ' yield_stmt ::= yield_expression\n'
+ '\n'
+ 'A "yield" statement is semantically equivalent to a yield '
+ 'expression.\n'
+ 'The yield statement can be used to omit the parentheses that would\n'
+ 'otherwise be required in the equivalent yield expression '
+ 'statement.\n'
+ 'For example, the yield statements\n'
+ '\n'
+ ' yield <expr>\n'
+ ' yield from <expr>\n'
+ '\n'
+ 'are equivalent to the yield expression statements\n'
+ '\n'
+ ' (yield <expr>)\n'
+ ' (yield from <expr>)\n'
+ '\n'
+ 'Yield expressions and statements are only used when defining a\n'
+ '*generator* function, and are only used in the body of the '
+ 'generator\n'
+ 'function. Using yield in a function definition is sufficient to '
+ 'cause\n'
+ 'that definition to create a generator function instead of a normal\n'
+ 'function.\n'
+ '\n'
+ 'For full details of "yield" semantics, refer to the Yield '
+ 'expressions\n'
+ 'section.\n'}
diff --git a/Lib/random.py b/Lib/random.py
index 4efbb0a..ef8cb05 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -8,6 +8,7 @@
---------
pick random element
pick random sample
+ pick weighted random sample
generate random permutation
distributions on the real line:
@@ -43,12 +44,14 @@ from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from os import urandom as _urandom
from _collections_abc import Set as _Set, Sequence as _Sequence
from hashlib import sha512 as _sha512
+import itertools as _itertools
+import bisect as _bisect
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
"randrange","shuffle","normalvariate","lognormvariate",
"expovariate","vonmisesvariate","gammavariate","triangular",
"gauss","betavariate","paretovariate","weibullvariate",
- "getstate","setstate", "getrandbits",
+ "getstate","setstate", "getrandbits", "choices",
"SystemRandom"]
NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0)
@@ -105,15 +108,6 @@ class Random(_random.Random):
"""
- if a is None:
- try:
- # Seed with enough bytes to span the 19937 bit
- # state space for the Mersenne Twister
- a = int.from_bytes(_urandom(2500), 'big')
- except NotImplementedError:
- import time
- a = int(time.time() * 256) # use fractional seconds
-
if version == 1 and isinstance(a, (str, bytes)):
x = ord(a[0]) << 7 if a else 0
for c in a:
@@ -121,12 +115,11 @@ class Random(_random.Random):
x ^= len(a)
a = -2 if x == -1 else x
- if version == 2:
- if isinstance(a, (str, bytes, bytearray)):
- if isinstance(a, str):
- a = a.encode()
- a += _sha512(a).digest()
- a = int.from_bytes(a, 'big')
+ if version == 2 and isinstance(a, (str, bytes, bytearray)):
+ if isinstance(a, str):
+ a = a.encode()
+ a += _sha512(a).digest()
+ a = int.from_bytes(a, 'big')
super().seed(a)
self.gauss_next = None
@@ -344,6 +337,28 @@ class Random(_random.Random):
result[i] = population[j]
return result
+ def choices(self, population, weights=None, *, cum_weights=None, k=1):
+ """Return a k sized list of population elements chosen with replacement.
+
+ If the relative weights or cumulative weights are not specified,
+ the selections are made with equal probability.
+
+ """
+ if cum_weights is None:
+ if weights is None:
+ choice = self.choice
+ return [choice(population) for i in range(k)]
+ else:
+ cum_weights = list(_itertools.accumulate(weights))
+ elif weights is not None:
+ raise TypeError('Cannot specify both weights and cumulative_weights')
+ if len(cum_weights) != len(population):
+ raise ValueError('The number of weights does not match the population')
+ bisect = _bisect.bisect
+ random = self.random
+ total = cum_weights[-1]
+ return [population[bisect(cum_weights, random() * total)] for i in range(k)]
+
## -------------------- real-valued distributions -------------------
## -------------------- uniform distribution -------------------
@@ -615,11 +630,11 @@ class Random(_random.Random):
# This version due to Janne Sinkkonen, and matches all the std
# texts (e.g., Knuth Vol 2 Ed 3 pg 134 "the beta distribution").
- y = self.gammavariate(alpha, 1.)
+ y = self.gammavariate(alpha, 1.0)
if y == 0:
return 0.0
else:
- return y / (y + self.gammavariate(beta, 1.))
+ return y / (y + self.gammavariate(beta, 1.0))
## -------------------- Pareto --------------------
@@ -734,6 +749,7 @@ choice = _inst.choice
randrange = _inst.randrange
sample = _inst.sample
shuffle = _inst.shuffle
+choices = _inst.choices
normalvariate = _inst.normalvariate
lognormvariate = _inst.lognormvariate
expovariate = _inst.expovariate
diff --git a/Lib/re.py b/Lib/re.py
index dde8901..d321cff 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -119,9 +119,10 @@ This module also defines an exception 'error'.
"""
-import sys
+import enum
import sre_compile
import sre_parse
+import functools
try:
import _locale
except ImportError:
@@ -138,18 +139,26 @@ __all__ = [
__version__ = "2.2.1"
-# flags
-A = ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
-I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
-L = LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
-U = UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
-M = MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
-S = DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
-X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
-
-# sre extensions (experimental, don't rely on these)
-T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
-DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
+class RegexFlag(enum.IntFlag):
+ ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
+ IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
+ LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
+ UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
+ MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
+ DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
+ VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
+ A = ASCII
+ I = IGNORECASE
+ L = LOCALE
+ U = UNICODE
+ M = MULTILINE
+ S = DOTALL
+ X = VERBOSE
+ # sre extensions (experimental, don't rely on these)
+ TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
+ T = TEMPLATE
+ DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
+globals().update(RegexFlag.__members__)
# sre exception
error = sre_compile.error
@@ -226,7 +235,7 @@ def compile(pattern, flags=0):
def purge():
"Clear the regular expression caches"
_cache.clear()
- _cache_repl.clear()
+ _compile_repl.cache_clear()
def template(pattern, flags=0):
"Compile a template pattern, returning a pattern object"
@@ -270,7 +279,6 @@ def escape(pattern):
# internals
_cache = {}
-_cache_repl = {}
_pattern_type = type(sre_compile.compile("", 0))
@@ -303,17 +311,10 @@ def _compile(pattern, flags):
_cache[type(pattern), pattern, flags] = p, loc
return p
+@functools.lru_cache(_MAXCACHE)
def _compile_repl(repl, pattern):
# internal: compile replacement pattern
- try:
- return _cache_repl[repl, pattern]
- except KeyError:
- pass
- p = sre_parse.parse_template(repl, pattern)
- if len(_cache_repl) >= _MAXCACHE:
- _cache_repl.clear()
- _cache_repl[repl, pattern] = p
- return p
+ return sre_parse.parse_template(repl, pattern)
def _expand(pattern, match, template):
# internal: match.expand implementation hook
@@ -353,7 +354,7 @@ class Scanner:
for phrase, action in lexicon:
gid = s.opengroup()
p.append(sre_parse.SubPattern(s, [
- (SUBPATTERN, (gid, sre_parse.parse(phrase, flags))),
+ (SUBPATTERN, (gid, 0, 0, sre_parse.parse(phrase, flags))),
]))
s.closegroup(gid, p[-1])
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py
index 401a626..bca4a7b 100644
--- a/Lib/rlcompleter.py
+++ b/Lib/rlcompleter.py
@@ -113,6 +113,12 @@ class Completer:
for word in keyword.kwlist:
if word[:n] == text:
seen.add(word)
+ if word in {'finally', 'try'}:
+ word = word + ':'
+ elif word not in {'False', 'None', 'True',
+ 'break', 'continue', 'pass',
+ 'else'}:
+ word = word + ' '
matches.append(word)
for nspace in [self.namespace, builtins.__dict__]:
for word, val in nspace.items():
@@ -152,14 +158,30 @@ class Completer:
words.update(get_class_members(thisobject.__class__))
matches = []
n = len(attr)
- for word in words:
- if word[:n] == attr:
- try:
- val = getattr(thisobject, word)
- except Exception:
- continue # Exclude properties that are not set
- word = self._callable_postfix(val, "%s.%s" % (expr, word))
- matches.append(word)
+ if attr == '':
+ noprefix = '_'
+ elif attr == '_':
+ noprefix = '__'
+ else:
+ noprefix = None
+ while True:
+ for word in words:
+ if (word[:n] == attr and
+ not (noprefix and word[:n+1] == noprefix)):
+ match = "%s.%s" % (expr, word)
+ try:
+ val = getattr(thisobject, word)
+ except Exception:
+ pass # Include even if attribute not set
+ else:
+ match = self._callable_postfix(val, match)
+ matches.append(match)
+ if matches or not noprefix:
+ break
+ if noprefix == '_':
+ noprefix = '__'
+ else:
+ noprefix = None
matches.sort()
return matches
diff --git a/Lib/sched.py b/Lib/sched.py
index b47648d..bd7c0f1 100644
--- a/Lib/sched.py
+++ b/Lib/sched.py
@@ -46,6 +46,17 @@ class Event(namedtuple('Event', 'time, priority, action, argument, kwargs')):
def __gt__(s, o): return (s.time, s.priority) > (o.time, o.priority)
def __ge__(s, o): return (s.time, s.priority) >= (o.time, o.priority)
+Event.time.__doc__ = ('''Numeric type compatible with the return value of the
+timefunc function passed to the constructor.''')
+Event.priority.__doc__ = ('''Events scheduled for the same time will be executed
+in the order of their priority.''')
+Event.action.__doc__ = ('''Executing the event means executing
+action(*argument, **kwargs)''')
+Event.argument.__doc__ = ('''argument is a sequence holding the positional
+arguments for the action.''')
+Event.kwargs.__doc__ = ('''kwargs is a dictionary holding the keyword
+arguments for the action.''')
+
_sentinel = object()
class scheduler:
diff --git a/Lib/secrets.py b/Lib/secrets.py
new file mode 100644
index 0000000..27fa450
--- /dev/null
+++ b/Lib/secrets.py
@@ -0,0 +1,71 @@
+"""Generate cryptographically strong pseudo-random numbers suitable for
+managing secrets such as account authentication, tokens, and similar.
+
+See PEP 506 for more information.
+https://www.python.org/dev/peps/pep-0506/
+
+"""
+
+__all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom',
+ 'token_bytes', 'token_hex', 'token_urlsafe',
+ 'compare_digest',
+ ]
+
+
+import base64
+import binascii
+import os
+
+from hmac import compare_digest
+from random import SystemRandom
+
+_sysrand = SystemRandom()
+
+randbits = _sysrand.getrandbits
+choice = _sysrand.choice
+
+def randbelow(exclusive_upper_bound):
+ """Return a random int in the range [0, n)."""
+ return _sysrand._randbelow(exclusive_upper_bound)
+
+DEFAULT_ENTROPY = 32 # number of bytes to return by default
+
+def token_bytes(nbytes=None):
+ """Return a random byte string containing *nbytes* bytes.
+
+ If *nbytes* is ``None`` or not supplied, a reasonable
+ default is used.
+
+ >>> token_bytes(16) #doctest:+SKIP
+ b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b'
+
+ """
+ if nbytes is None:
+ nbytes = DEFAULT_ENTROPY
+ return os.urandom(nbytes)
+
+def token_hex(nbytes=None):
+ """Return a random text string, in hexadecimal.
+
+ The string has *nbytes* random bytes, each byte converted to two
+ hex digits. If *nbytes* is ``None`` or not supplied, a reasonable
+ default is used.
+
+ >>> token_hex(16) #doctest:+SKIP
+ 'f9bf78b9a18ce6d46a0cd2b0b86df9da'
+
+ """
+ return binascii.hexlify(token_bytes(nbytes)).decode('ascii')
+
+def token_urlsafe(nbytes=None):
+ """Return a random URL-safe text string, in Base64 encoding.
+
+ The string has *nbytes* random bytes. If *nbytes* is ``None``
+ or not supplied, a reasonable default is used.
+
+ >>> token_urlsafe(16) #doctest:+SKIP
+ 'Drmhze6EPcv0fN_81Bj-nA'
+
+ """
+ tok = token_bytes(nbytes)
+ return base64.urlsafe_b64encode(tok).rstrip(b'=').decode('ascii')
diff --git a/Lib/shlex.py b/Lib/shlex.py
index ecd2efd..e87266f 100644
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -5,6 +5,7 @@
# push_source() and pop_source() made explicit by ESR, January 2001.
# Posix compliance, split(), string arguments, and
# iterator interface by Gustavo Niemeyer, April 2003.
+# changes to tokenize more like Posix shells by Vinay Sajip, July 2016.
import os
import re
@@ -17,7 +18,8 @@ __all__ = ["shlex", "split", "quote"]
class shlex:
"A lexical analyzer class for simple shell-like syntaxes."
- def __init__(self, instream=None, infile=None, posix=False):
+ def __init__(self, instream=None, infile=None, posix=False,
+ punctuation_chars=False):
if isinstance(instream, str):
instream = StringIO(instream)
if instream is not None:
@@ -49,6 +51,19 @@ class shlex:
self.token = ''
self.filestack = deque()
self.source = None
+ if not punctuation_chars:
+ punctuation_chars = ''
+ elif punctuation_chars is True:
+ punctuation_chars = '();<>|&'
+ self.punctuation_chars = punctuation_chars
+ if punctuation_chars:
+ # _pushback_chars is a push back queue used by lookahead logic
+ self._pushback_chars = deque()
+ # these chars added because allowed in file names, args, wildcards
+ self.wordchars += '~-./*?='
+ #remove any punctuation chars from wordchars
+ t = self.wordchars.maketrans(dict.fromkeys(punctuation_chars))
+ self.wordchars = self.wordchars.translate(t)
def push_token(self, tok):
"Push a token onto the stack popped by the get_token method"
@@ -115,12 +130,15 @@ class shlex:
quoted = False
escapedstate = ' '
while True:
- nextchar = self.instream.read(1)
+ if self.punctuation_chars and self._pushback_chars:
+ nextchar = self._pushback_chars.pop()
+ else:
+ nextchar = self.instream.read(1)
if nextchar == '\n':
- self.lineno = self.lineno + 1
+ self.lineno += 1
if self.debug >= 3:
- print("shlex: in state", repr(self.state), \
- "I see character:", repr(nextchar))
+ print("shlex: in state %r I see character: %r" % (self.state,
+ nextchar))
if self.state is None:
self.token = '' # past end of file
break
@@ -137,13 +155,16 @@ class shlex:
continue
elif nextchar in self.commenters:
self.instream.readline()
- self.lineno = self.lineno + 1
+ self.lineno += 1
elif self.posix and nextchar in self.escape:
escapedstate = 'a'
self.state = nextchar
elif nextchar in self.wordchars:
self.token = nextchar
self.state = 'a'
+ elif nextchar in self.punctuation_chars:
+ self.token = nextchar
+ self.state = 'c'
elif nextchar in self.quotes:
if not self.posix:
self.token = nextchar
@@ -166,17 +187,17 @@ class shlex:
raise ValueError("No closing quotation")
if nextchar == self.state:
if not self.posix:
- self.token = self.token + nextchar
+ self.token += nextchar
self.state = ' '
break
else:
self.state = 'a'
- elif self.posix and nextchar in self.escape and \
- self.state in self.escapedquotes:
+ elif (self.posix and nextchar in self.escape and self.state
+ in self.escapedquotes):
escapedstate = self.state
self.state = nextchar
else:
- self.token = self.token + nextchar
+ self.token += nextchar
elif self.state in self.escape:
if not nextchar: # end of file
if self.debug >= 2:
@@ -185,12 +206,12 @@ class shlex:
raise ValueError("No escaped character")
# In posix shells, only the quote itself or the escape
# character may be escaped within quotes.
- if escapedstate in self.quotes and \
- nextchar != self.state and nextchar != escapedstate:
- self.token = self.token + self.state
- self.token = self.token + nextchar
+ if (escapedstate in self.quotes and
+ nextchar != self.state and nextchar != escapedstate):
+ self.token += self.state
+ self.token += nextchar
self.state = escapedstate
- elif self.state == 'a':
+ elif self.state in ('a', 'c'):
if not nextchar:
self.state = None # end of file
break
@@ -204,7 +225,7 @@ class shlex:
continue
elif nextchar in self.commenters:
self.instream.readline()
- self.lineno = self.lineno + 1
+ self.lineno += 1
if self.posix:
self.state = ' '
if self.token or (self.posix and quoted):
@@ -216,11 +237,22 @@ class shlex:
elif self.posix and nextchar in self.escape:
escapedstate = 'a'
self.state = nextchar
- elif nextchar in self.wordchars or nextchar in self.quotes \
- or self.whitespace_split:
- self.token = self.token + nextchar
+ elif self.state == 'c':
+ if nextchar in self.punctuation_chars:
+ self.token += nextchar
+ else:
+ if nextchar not in self.whitespace:
+ self._pushback_chars.append(nextchar)
+ self.state = ' '
+ break
+ elif (nextchar in self.wordchars or nextchar in self.quotes
+ or self.whitespace_split):
+ self.token += nextchar
else:
- self.pushback.appendleft(nextchar)
+ if self.punctuation_chars:
+ self._pushback_chars.append(nextchar)
+ else:
+ self.pushback.appendleft(nextchar)
if self.debug >= 2:
print("shlex: I see punctuation in word state")
self.state = ' '
diff --git a/Lib/shutil.py b/Lib/shutil.py
index dc9f2eb..9d193b5 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -974,6 +974,9 @@ if hasattr(os, 'statvfs'):
__all__.append('disk_usage')
_ntuple_diskusage = collections.namedtuple('usage', 'total used free')
+ _ntuple_diskusage.total.__doc__ = 'Total space in bytes'
+ _ntuple_diskusage.used.__doc__ = 'Used space in bytes'
+ _ntuple_diskusage.free.__doc__ = 'Free space in bytes'
def disk_usage(path):
"""Return disk usage statistics about the given path.
diff --git a/Lib/site-packages/README.txt b/Lib/site-packages/README.txt
new file mode 100644
index 0000000..273f625
--- /dev/null
+++ b/Lib/site-packages/README.txt
@@ -0,0 +1,2 @@
+This directory exists so that 3rd party packages can be installed
+here. Read the source for site.py for more details.
diff --git a/Lib/site.py b/Lib/site.py
index 3f78ef5..0859f28 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -60,7 +60,8 @@ omitted because it is not mentioned in either path configuration file.
The readline module is also automatically configured to enable
completion for systems that support it. This can be overridden in
-sitecustomize, usercustomize or PYTHONSTARTUP.
+sitecustomize, usercustomize or PYTHONSTARTUP. Starting Python in
+isolated mode (-I) disables automatic readline configuration.
After these operations, an attempt is made to import a module
named sitecustomize, which can perform arbitrary additional
@@ -131,13 +132,13 @@ def removeduppaths():
def _init_pathinfo():
- """Return a set containing all existing directory entries from sys.path"""
+ """Return a set containing all existing file system items from sys.path."""
d = set()
- for dir in sys.path:
+ for item in sys.path:
try:
- if os.path.isdir(dir):
- dir, dircase = makepath(dir)
- d.add(dircase)
+ if os.path.exists(item):
+ _, itemcase = makepath(item)
+ d.add(itemcase)
except TypeError:
continue
return d
@@ -150,9 +151,9 @@ def addpackage(sitedir, name, known_paths):
"""
if known_paths is None:
known_paths = _init_pathinfo()
- reset = 1
+ reset = True
else:
- reset = 0
+ reset = False
fullname = os.path.join(sitedir, name)
try:
f = open(fullname, "r")
@@ -190,9 +191,9 @@ def addsitedir(sitedir, known_paths=None):
'sitedir'"""
if known_paths is None:
known_paths = _init_pathinfo()
- reset = 1
+ reset = True
else:
- reset = 0
+ reset = False
sitedir, sitedircase = makepath(sitedir)
if not sitedircase in known_paths:
sys.path.append(sitedir) # Add path component
@@ -304,7 +305,7 @@ def getsitepackages(prefixes=None):
if os.sep == '/':
sitepackages.append(os.path.join(prefix, "lib",
- "python" + sys.version[:3],
+ "python%d.%d" % sys.version_info[:2],
"site-packages"))
else:
sitepackages.append(prefix)
@@ -317,7 +318,7 @@ def getsitepackages(prefixes=None):
if framework:
sitepackages.append(
os.path.join("/Library", framework,
- sys.version[:3], "site-packages"))
+ '%d.%d' % sys.version_info[:2], "site-packages"))
return sitepackages
def addsitepackages(known_paths, prefixes=None):
@@ -335,9 +336,7 @@ def setquit():
The repr of each object contains a hint at how it works.
"""
- if os.sep == ':':
- eof = 'Cmd-Q'
- elif os.sep == '\\':
+ if os.sep == '\\':
eof = 'Ctrl-Z plus Return'
else:
eof = 'Ctrl-D (i.e. EOF)'
@@ -423,21 +422,6 @@ def enablerlcompleter():
sys.__interactivehook__ = register_readline
-def aliasmbcs():
- """On Windows, some default encodings are not provided by Python,
- while they are always available as "mbcs" in each locale. Make
- them usable by aliasing to "mbcs" in such a case."""
- if sys.platform == 'win32':
- import _bootlocale, codecs
- enc = _bootlocale.getpreferredencoding(False)
- if enc.startswith('cp'): # "cp***" ?
- try:
- codecs.lookup(enc)
- except LookupError:
- import encodings
- encodings._cache[enc] = encodings._unknown
- encodings.aliases.aliases[enc] = 'mbcs'
-
CONFIG_LINE = r'^(?P<key>(\w|[-_])+)\s*=\s*(?P<value>.*)\s*$'
def venv(known_paths):
@@ -478,12 +462,6 @@ def venv(known_paths):
system_site = value.lower()
elif key == 'home':
sys._home = value
- elif key == 'applocal' and value.lower() == 'true':
- # App-local installs use the exe_dir as prefix,
- # not one level higher, and do not use system
- # site packages.
- site_prefix = exe_dir
- system_site = 'false'
sys.prefix = sys.exec_prefix = site_prefix
@@ -504,11 +482,15 @@ def venv(known_paths):
def execsitecustomize():
"""Run custom site specific code, if available."""
try:
- import sitecustomize
- except ImportError:
- pass
+ try:
+ import sitecustomize
+ except ImportError as exc:
+ if exc.name == 'sitecustomize':
+ pass
+ else:
+ raise
except Exception as err:
- if os.environ.get("PYTHONVERBOSE"):
+ if sys.flags.verbose:
sys.excepthook(*sys.exc_info())
else:
sys.stderr.write(
@@ -520,11 +502,15 @@ def execsitecustomize():
def execusercustomize():
"""Run custom user specific code, if available."""
try:
- import usercustomize
- except ImportError:
- pass
+ try:
+ import usercustomize
+ except ImportError as exc:
+ if exc.name == 'usercustomize':
+ pass
+ else:
+ raise
except Exception as err:
- if os.environ.get("PYTHONVERBOSE"):
+ if sys.flags.verbose:
sys.excepthook(*sys.exc_info())
else:
sys.stderr.write(
@@ -551,13 +537,13 @@ def main():
setquit()
setcopyright()
sethelper()
- enablerlcompleter()
- aliasmbcs()
+ if not sys.flags.isolated:
+ enablerlcompleter()
execsitecustomize()
if ENABLE_USER_SITE:
execusercustomize()
-# Prevent edition of sys.path when python was started with -S and
+# Prevent extending of sys.path when python was started with -S and
# site is imported later.
if not sys.flags.no_site:
main()
diff --git a/Lib/smtpd.py b/Lib/smtpd.py
index 732066e..8103ca9 100755
--- a/Lib/smtpd.py
+++ b/Lib/smtpd.py
@@ -89,7 +89,10 @@ import collections
from warnings import warn
from email._header_value_parser import get_addr_spec, get_angle_addr
-__all__ = ["SMTPServer","DebuggingServer","PureProxy","MailmanProxy"]
+__all__ = [
+ "SMTPChannel", "SMTPServer", "DebuggingServer", "PureProxy",
+ "MailmanProxy",
+]
program = sys.argv[0]
__version__ = 'Python SMTP proxy version 0.3'
@@ -128,24 +131,17 @@ class SMTPChannel(asynchat.async_chat):
return self.command_size_limit
def __init__(self, server, conn, addr, data_size_limit=DATA_SIZE_DEFAULT,
- map=None, enable_SMTPUTF8=False, decode_data=None):
+ map=None, enable_SMTPUTF8=False, decode_data=False):
asynchat.async_chat.__init__(self, conn, map=map)
self.smtp_server = server
self.conn = conn
self.addr = addr
self.data_size_limit = data_size_limit
self.enable_SMTPUTF8 = enable_SMTPUTF8
- if enable_SMTPUTF8:
- if decode_data:
- raise ValueError("decode_data and enable_SMTPUTF8 cannot"
- " be set to True at the same time")
- decode_data = False
- if decode_data is None:
- warn("The decode_data default of True will change to False in 3.6;"
- " specify an explicit value for this keyword",
- DeprecationWarning, 2)
- decode_data = True
self._decode_data = decode_data
+ if enable_SMTPUTF8 and decode_data:
+ raise ValueError("decode_data and enable_SMTPUTF8 cannot"
+ " be set to True at the same time")
if decode_data:
self._emptystring = ''
self._linesep = '\r\n'
@@ -635,23 +631,15 @@ class SMTPServer(asyncore.dispatcher):
def __init__(self, localaddr, remoteaddr,
data_size_limit=DATA_SIZE_DEFAULT, map=None,
- enable_SMTPUTF8=False, decode_data=None):
+ enable_SMTPUTF8=False, decode_data=False):
self._localaddr = localaddr
self._remoteaddr = remoteaddr
self.data_size_limit = data_size_limit
self.enable_SMTPUTF8 = enable_SMTPUTF8
- if enable_SMTPUTF8:
- if decode_data:
- raise ValueError("The decode_data and enable_SMTPUTF8"
- " parameters cannot be set to True at the"
- " same time.")
- decode_data = False
- if decode_data is None:
- warn("The decode_data default of True will change to False in 3.6;"
- " specify an explicit value for this keyword",
- DeprecationWarning, 2)
- decode_data = True
self._decode_data = decode_data
+ if enable_SMTPUTF8 and decode_data:
+ raise ValueError("decode_data and enable_SMTPUTF8 cannot"
+ " be set to True at the same time")
asyncore.dispatcher.__init__(self, map=map)
try:
gai_results = socket.getaddrinfo(*localaddr,
@@ -698,9 +686,9 @@ class SMTPServer(asyncore.dispatcher):
containing a `.' followed by other text has had the leading dot
removed.
- kwargs is a dictionary containing additional information. It is empty
- unless decode_data=False or enable_SMTPUTF8=True was given as init
- parameter, in which case ut will contain the following keys:
+ kwargs is a dictionary containing additional information. It is
+ empty if decode_data=True was given as init parameter, otherwise
+ it will contain the following keys:
'mail_options': list of parameters to the mail command. All
elements are uppercase strings. Example:
['BODY=8BITMIME', 'SMTPUTF8'].
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 5b9e665..f7c2c77 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -759,6 +759,10 @@ class SMTP:
if context is not None and certfile is not None:
raise ValueError("context and certfile arguments are mutually "
"exclusive")
+ if keyfile is not None or certfile is not None:
+ import warnings
+ warnings.warn("keyfile and certfile are deprecated, use a"
+ "custom context instead", DeprecationWarning, 2)
if context is None:
context = ssl._create_stdlib_context(certfile=certfile,
keyfile=keyfile)
@@ -1011,6 +1015,10 @@ if _have_ssl:
if context is not None and certfile is not None:
raise ValueError("context and certfile arguments are mutually "
"exclusive")
+ if keyfile is not None or certfile is not None:
+ import warnings
+ warnings.warn("keyfile and certfile are deprecated, use a"
+ "custom context instead", DeprecationWarning, 2)
self.keyfile = keyfile
self.certfile = certfile
if context is None:
diff --git a/Lib/sndhdr.py b/Lib/sndhdr.py
index e5901ec..7ecafb4 100644
--- a/Lib/sndhdr.py
+++ b/Lib/sndhdr.py
@@ -37,6 +37,18 @@ from collections import namedtuple
SndHeaders = namedtuple('SndHeaders',
'filetype framerate nchannels nframes sampwidth')
+SndHeaders.filetype.__doc__ = ("""The value for type indicates the data type
+and will be one of the strings 'aifc', 'aiff', 'au','hcom',
+'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub', or 'ul'.""")
+SndHeaders.framerate.__doc__ = ("""The sampling_rate will be either the actual
+value or 0 if unknown or difficult to decode.""")
+SndHeaders.nchannels.__doc__ = ("""The number of channels or 0 if it cannot be
+determined or if the value is difficult to decode.""")
+SndHeaders.nframes.__doc__ = ("""The value for frames will be either the number
+of frames or -1.""")
+SndHeaders.sampwidth.__doc__ = ("""Either the sample size in bits or
+'A' for A-LAW or 'U' for u-LAW.""")
+
def what(filename):
"""Guess the type of a sound file."""
res = whathdr(filename)
diff --git a/Lib/socket.py b/Lib/socket.py
index a9cab32..740e717 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -50,7 +50,7 @@ import _socket
from _socket import *
import os, sys, io, selectors
-from enum import IntEnum
+from enum import IntEnum, IntFlag
try:
import errno
@@ -80,6 +80,16 @@ IntEnum._convert(
__name__,
lambda C: C.isupper() and C.startswith('SOCK_'))
+IntFlag._convert(
+ 'MsgFlag',
+ __name__,
+ lambda C: C.isupper() and C.startswith('MSG_'))
+
+IntFlag._convert(
+ 'AddressInfo',
+ __name__,
+ lambda C: C.isupper() and C.startswith('AI_'))
+
_LOCALHOST = '127.0.0.1'
_LOCALHOST_V6 = '::1'
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index 8808813..41a3766 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -127,16 +127,20 @@ import socket
import selectors
import os
import errno
+import sys
try:
import threading
except ImportError:
import dummy_threading as threading
+from io import BufferedIOBase
from time import monotonic as time
-__all__ = ["BaseServer", "TCPServer", "UDPServer", "ForkingUDPServer",
- "ForkingTCPServer", "ThreadingUDPServer", "ThreadingTCPServer",
+__all__ = ["BaseServer", "TCPServer", "UDPServer",
+ "ThreadingUDPServer", "ThreadingTCPServer",
"BaseRequestHandler", "StreamRequestHandler",
- "DatagramRequestHandler", "ThreadingMixIn", "ForkingMixIn"]
+ "DatagramRequestHandler", "ThreadingMixIn"]
+if hasattr(os, "fork"):
+ __all__.extend(["ForkingUDPServer","ForkingTCPServer", "ForkingMixIn"])
if hasattr(socket, "AF_UNIX"):
__all__.extend(["UnixStreamServer","UnixDatagramServer",
"ThreadingUnixStreamServer",
@@ -311,9 +315,12 @@ class BaseServer:
if self.verify_request(request, client_address):
try:
self.process_request(request, client_address)
- except:
+ except Exception:
self.handle_error(request, client_address)
self.shutdown_request(request)
+ except:
+ self.shutdown_request(request)
+ raise
else:
self.shutdown_request(request)
@@ -367,12 +374,18 @@ class BaseServer:
The default is to print a traceback and continue.
"""
- print('-'*40)
- print('Exception happened during processing of request from', end=' ')
- print(client_address)
+ print('-'*40, file=sys.stderr)
+ print('Exception happened during processing of request from',
+ client_address, file=sys.stderr)
import traceback
- traceback.print_exc() # XXX But this goes to stderr!
- print('-'*40)
+ traceback.print_exc()
+ print('-'*40, file=sys.stderr)
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ self.server_close()
class TCPServer(BaseServer):
@@ -527,85 +540,86 @@ class UDPServer(TCPServer):
# No need to close anything.
pass
-class ForkingMixIn:
-
- """Mix-in class to handle each request in a new process."""
-
- timeout = 300
- active_children = None
- max_children = 40
-
- def collect_children(self):
- """Internal routine to wait for children that have exited."""
- if self.active_children is None:
- return
-
- # If we're above the max number of children, wait and reap them until
- # we go back below threshold. Note that we use waitpid(-1) below to be
- # able to collect children in size(<defunct children>) syscalls instead
- # of size(<children>): the downside is that this might reap children
- # which we didn't spawn, which is why we only resort to this when we're
- # above max_children.
- while len(self.active_children) >= self.max_children:
- try:
- pid, _ = os.waitpid(-1, 0)
- self.active_children.discard(pid)
- except ChildProcessError:
- # we don't have any children, we're done
- self.active_children.clear()
- except OSError:
- break
-
- # Now reap all defunct children.
- for pid in self.active_children.copy():
- try:
- pid, _ = os.waitpid(pid, os.WNOHANG)
- # if the child hasn't exited yet, pid will be 0 and ignored by
- # discard() below
- self.active_children.discard(pid)
- except ChildProcessError:
- # someone else reaped it
- self.active_children.discard(pid)
- except OSError:
- pass
-
- def handle_timeout(self):
- """Wait for zombies after self.timeout seconds of inactivity.
+if hasattr(os, "fork"):
+ class ForkingMixIn:
+ """Mix-in class to handle each request in a new process."""
- May be extended, do not override.
- """
- self.collect_children()
+ timeout = 300
+ active_children = None
+ max_children = 40
- def service_actions(self):
- """Collect the zombie child processes regularly in the ForkingMixIn.
-
- service_actions is called in the BaseServer's serve_forver loop.
- """
- self.collect_children()
-
- def process_request(self, request, client_address):
- """Fork a new subprocess to process the request."""
- pid = os.fork()
- if pid:
- # Parent process
+ def collect_children(self):
+ """Internal routine to wait for children that have exited."""
if self.active_children is None:
- self.active_children = set()
- self.active_children.add(pid)
- self.close_request(request)
- return
- else:
- # Child process.
- # This must never return, hence os._exit()!
- try:
- self.finish_request(request, client_address)
- self.shutdown_request(request)
- os._exit(0)
- except:
+ return
+
+ # If we're above the max number of children, wait and reap them until
+ # we go back below threshold. Note that we use waitpid(-1) below to be
+ # able to collect children in size(<defunct children>) syscalls instead
+ # of size(<children>): the downside is that this might reap children
+ # which we didn't spawn, which is why we only resort to this when we're
+ # above max_children.
+ while len(self.active_children) >= self.max_children:
+ try:
+ pid, _ = os.waitpid(-1, 0)
+ self.active_children.discard(pid)
+ except ChildProcessError:
+ # we don't have any children, we're done
+ self.active_children.clear()
+ except OSError:
+ break
+
+ # Now reap all defunct children.
+ for pid in self.active_children.copy():
try:
+ pid, _ = os.waitpid(pid, os.WNOHANG)
+ # if the child hasn't exited yet, pid will be 0 and ignored by
+ # discard() below
+ self.active_children.discard(pid)
+ except ChildProcessError:
+ # someone else reaped it
+ self.active_children.discard(pid)
+ except OSError:
+ pass
+
+ def handle_timeout(self):
+ """Wait for zombies after self.timeout seconds of inactivity.
+
+ May be extended, do not override.
+ """
+ self.collect_children()
+
+ def service_actions(self):
+ """Collect the zombie child processes regularly in the ForkingMixIn.
+
+ service_actions is called in the BaseServer's serve_forver loop.
+ """
+ self.collect_children()
+
+ def process_request(self, request, client_address):
+ """Fork a new subprocess to process the request."""
+ pid = os.fork()
+ if pid:
+ # Parent process
+ if self.active_children is None:
+ self.active_children = set()
+ self.active_children.add(pid)
+ self.close_request(request)
+ return
+ else:
+ # Child process.
+ # This must never return, hence os._exit()!
+ status = 1
+ try:
+ self.finish_request(request, client_address)
+ status = 0
+ except Exception:
self.handle_error(request, client_address)
- self.shutdown_request(request)
finally:
- os._exit(1)
+ try:
+ self.shutdown_request(request)
+ finally:
+ os._exit(status)
class ThreadingMixIn:
@@ -623,9 +637,9 @@ class ThreadingMixIn:
"""
try:
self.finish_request(request, client_address)
- self.shutdown_request(request)
- except:
+ except Exception:
self.handle_error(request, client_address)
+ finally:
self.shutdown_request(request)
def process_request(self, request, client_address):
@@ -636,8 +650,9 @@ class ThreadingMixIn:
t.start()
-class ForkingUDPServer(ForkingMixIn, UDPServer): pass
-class ForkingTCPServer(ForkingMixIn, TCPServer): pass
+if hasattr(os, "fork"):
+ class ForkingUDPServer(ForkingMixIn, UDPServer): pass
+ class ForkingTCPServer(ForkingMixIn, TCPServer): pass
class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass
class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass
@@ -729,7 +744,10 @@ class StreamRequestHandler(BaseRequestHandler):
self.connection.setsockopt(socket.IPPROTO_TCP,
socket.TCP_NODELAY, True)
self.rfile = self.connection.makefile('rb', self.rbufsize)
- self.wfile = self.connection.makefile('wb', self.wbufsize)
+ if self.wbufsize == 0:
+ self.wfile = _SocketWriter(self.connection)
+ else:
+ self.wfile = self.connection.makefile('wb', self.wbufsize)
def finish(self):
if not self.wfile.closed:
@@ -742,6 +760,24 @@ class StreamRequestHandler(BaseRequestHandler):
self.wfile.close()
self.rfile.close()
+class _SocketWriter(BufferedIOBase):
+ """Simple writable BufferedIOBase implementation for a socket
+
+ Does not hold data in a buffer, avoiding any need to call flush()."""
+
+ def __init__(self, sock):
+ self._sock = sock
+
+ def writable(self):
+ return True
+
+ def write(self, b):
+ self._sock.sendall(b)
+ with memoryview(b) as view:
+ return view.nbytes
+
+ def fileno(self):
+ return self._sock.fileno()
class DatagramRequestHandler(BaseRequestHandler):
diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py
index 7fb8d7e..cb85814 100644
--- a/Lib/sqlite3/test/dbapi.py
+++ b/Lib/sqlite3/test/dbapi.py
@@ -188,7 +188,10 @@ class CursorTests(unittest.TestCase):
def setUp(self):
self.cx = sqlite.connect(":memory:")
self.cu = self.cx.cursor()
- self.cu.execute("create table test(id integer primary key, name text, income number)")
+ self.cu.execute(
+ "create table test(id integer primary key, name text, "
+ "income number, unique_test text unique)"
+ )
self.cu.execute("insert into test(name) values (?)", ("foo",))
def tearDown(self):
@@ -462,6 +465,44 @@ class CursorTests(unittest.TestCase):
with self.assertRaises(TypeError):
cur = sqlite.Cursor(foo)
+ def CheckLastRowIDOnReplace(self):
+ """
+ INSERT OR REPLACE and REPLACE INTO should produce the same behavior.
+ """
+ sql = '{} INTO test(id, unique_test) VALUES (?, ?)'
+ for statement in ('INSERT OR REPLACE', 'REPLACE'):
+ with self.subTest(statement=statement):
+ self.cu.execute(sql.format(statement), (1, 'foo'))
+ self.assertEqual(self.cu.lastrowid, 1)
+
+ def CheckLastRowIDOnIgnore(self):
+ self.cu.execute(
+ "insert or ignore into test(unique_test) values (?)",
+ ('test',))
+ self.assertEqual(self.cu.lastrowid, 2)
+ self.cu.execute(
+ "insert or ignore into test(unique_test) values (?)",
+ ('test',))
+ self.assertEqual(self.cu.lastrowid, 2)
+
+ def CheckLastRowIDInsertOR(self):
+ results = []
+ for statement in ('FAIL', 'ABORT', 'ROLLBACK'):
+ sql = 'INSERT OR {} INTO test(unique_test) VALUES (?)'
+ with self.subTest(statement='INSERT OR {}'.format(statement)):
+ self.cu.execute(sql.format(statement), (statement,))
+ results.append((statement, self.cu.lastrowid))
+ with self.assertRaises(sqlite.IntegrityError):
+ self.cu.execute(sql.format(statement), (statement,))
+ results.append((statement, self.cu.lastrowid))
+ expected = [
+ ('FAIL', 2), ('FAIL', 2),
+ ('ABORT', 3), ('ABORT', 3),
+ ('ROLLBACK', 4), ('ROLLBACK', 4),
+ ]
+ self.assertEqual(results, expected)
+
+
@unittest.skipUnless(threading, 'This test requires threading.')
class ThreadTests(unittest.TestCase):
def setUp(self):
diff --git a/Lib/sqlite3/test/transactions.py b/Lib/sqlite3/test/transactions.py
index a25360a..45f1b04 100644
--- a/Lib/sqlite3/test/transactions.py
+++ b/Lib/sqlite3/test/transactions.py
@@ -52,13 +52,13 @@ class TransactionTests(unittest.TestCase):
except OSError:
pass
- def CheckDMLdoesAutoCommitBefore(self):
+ def CheckDMLDoesNotAutoCommitBefore(self):
self.cur1.execute("create table test(i)")
self.cur1.execute("insert into test(i) values (5)")
self.cur1.execute("create table test2(j)")
self.cur2.execute("select i from test")
res = self.cur2.fetchall()
- self.assertEqual(len(res), 1)
+ self.assertEqual(len(res), 0)
def CheckInsertStartsTransaction(self):
self.cur1.execute("create table test(i)")
@@ -153,11 +153,6 @@ class SpecialCommandTests(unittest.TestCase):
self.con = sqlite.connect(":memory:")
self.cur = self.con.cursor()
- def CheckVacuum(self):
- self.cur.execute("create table test(i)")
- self.cur.execute("insert into test(i) values (5)")
- self.cur.execute("vacuum")
-
def CheckDropTable(self):
self.cur.execute("create table test(i)")
self.cur.execute("insert into test(i) values (5)")
@@ -172,10 +167,35 @@ class SpecialCommandTests(unittest.TestCase):
self.cur.close()
self.con.close()
+class TransactionalDDL(unittest.TestCase):
+ def setUp(self):
+ self.con = sqlite.connect(":memory:")
+
+ def CheckDdlDoesNotAutostartTransaction(self):
+ # For backwards compatibility reasons, DDL statements should not
+ # implicitly start a transaction.
+ self.con.execute("create table test(i)")
+ self.con.rollback()
+ result = self.con.execute("select * from test").fetchall()
+ self.assertEqual(result, [])
+
+ def CheckTransactionalDDL(self):
+ # You can achieve transactional DDL by issuing a BEGIN
+ # statement manually.
+ self.con.execute("begin")
+ self.con.execute("create table test(i)")
+ self.con.rollback()
+ with self.assertRaises(sqlite.OperationalError):
+ self.con.execute("select * from test")
+
+ def tearDown(self):
+ self.con.close()
+
def suite():
default_suite = unittest.makeSuite(TransactionTests, "Check")
special_command_suite = unittest.makeSuite(SpecialCommandTests, "Check")
- return unittest.TestSuite((default_suite, special_command_suite))
+ ddl_suite = unittest.makeSuite(TransactionalDDL, "Check")
+ return unittest.TestSuite((default_suite, special_command_suite, ddl_suite))
def test():
runner = unittest.TextTestRunner()
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index 502b061..420d83d 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -71,7 +71,8 @@ def _compile(code, pattern, flags):
ASSERT_CODES = _ASSERT_CODES
if (flags & SRE_FLAG_IGNORECASE and
not (flags & SRE_FLAG_LOCALE) and
- flags & SRE_FLAG_UNICODE):
+ flags & SRE_FLAG_UNICODE and
+ not (flags & SRE_FLAG_ASCII)):
fixes = _ignorecase_fixes
else:
fixes = None
@@ -137,14 +138,15 @@ def _compile(code, pattern, flags):
else:
emit(MIN_UNTIL)
elif op is SUBPATTERN:
- if av[0]:
+ group, add_flags, del_flags, p = av
+ if group:
emit(MARK)
- emit((av[0]-1)*2)
- # _compile_info(code, av[1], flags)
- _compile(code, av[1], flags)
- if av[0]:
+ emit((group-1)*2)
+ # _compile_info(code, p, (flags | add_flags) & ~del_flags)
+ _compile(code, p, (flags | add_flags) & ~del_flags)
+ if group:
emit(MARK)
- emit((av[0]-1)*2+1)
+ emit((group-1)*2+1)
elif op in SUCCESS_CODES:
emit(op)
elif op in ASSERT_CODES:
@@ -172,7 +174,7 @@ def _compile(code, pattern, flags):
av = AT_MULTILINE.get(av, av)
if flags & SRE_FLAG_LOCALE:
av = AT_LOCALE.get(av, av)
- elif flags & SRE_FLAG_UNICODE:
+ elif (flags & SRE_FLAG_UNICODE) and not (flags & SRE_FLAG_ASCII):
av = AT_UNICODE.get(av, av)
emit(av)
elif op is BRANCH:
@@ -193,7 +195,7 @@ def _compile(code, pattern, flags):
emit(op)
if flags & SRE_FLAG_LOCALE:
av = CH_LOCALE[av]
- elif flags & SRE_FLAG_UNICODE:
+ elif (flags & SRE_FLAG_UNICODE) and not (flags & SRE_FLAG_ASCII):
av = CH_UNICODE[av]
emit(av)
elif op is GROUPREF:
@@ -237,7 +239,7 @@ def _compile_charset(charset, flags, code, fixup=None, fixes=None):
elif op is CATEGORY:
if flags & SRE_FLAG_LOCALE:
emit(CH_LOCALE[av])
- elif flags & SRE_FLAG_UNICODE:
+ elif (flags & SRE_FLAG_UNICODE) and not (flags & SRE_FLAG_ASCII):
emit(CH_UNICODE[av])
else:
emit(av)
@@ -409,42 +411,42 @@ def _generate_overlap_table(prefix):
table[i] = idx + 1
return table
-def _compile_info(code, pattern, flags):
- # internal: compile an info block. in the current version,
- # this contains min/max pattern width, and an optional literal
- # prefix or a character map
- lo, hi = pattern.getwidth()
- if hi > MAXCODE:
- hi = MAXCODE
- if lo == 0:
- code.extend([INFO, 4, 0, lo, hi])
- return
- # look for a literal prefix
+def _get_literal_prefix(pattern):
+ # look for literal prefix
prefix = []
prefixappend = prefix.append
- prefix_skip = 0
+ prefix_skip = None
+ for op, av in pattern.data:
+ if op is LITERAL:
+ prefixappend(av)
+ elif op is SUBPATTERN:
+ group, add_flags, del_flags, p = av
+ if add_flags & SRE_FLAG_IGNORECASE:
+ break
+ prefix1, prefix_skip1, got_all = _get_literal_prefix(p)
+ if prefix_skip is None:
+ if group is not None:
+ prefix_skip = len(prefix)
+ elif prefix_skip1 is not None:
+ prefix_skip = len(prefix) + prefix_skip1
+ prefix.extend(prefix1)
+ if not got_all:
+ break
+ else:
+ break
+ else:
+ return prefix, prefix_skip, True
+ return prefix, prefix_skip, False
+
+def _get_charset_prefix(pattern):
charset = [] # not used
charsetappend = charset.append
- if not (flags & SRE_FLAG_IGNORECASE):
- # look for literal prefix
- for op, av in pattern.data:
- if op is LITERAL:
- if len(prefix) == prefix_skip:
- prefix_skip = prefix_skip + 1
- prefixappend(av)
- elif op is SUBPATTERN and len(av[1]) == 1:
- op, av = av[1][0]
- if op is LITERAL:
- prefixappend(av)
- else:
- break
- else:
- break
- # if no prefix, look for charset prefix
- if not prefix and pattern.data:
- op, av = pattern.data[0]
- if op is SUBPATTERN and av[1]:
- op, av = av[1][0]
+ if pattern.data:
+ op, av = pattern.data[0]
+ if op is SUBPATTERN:
+ group, add_flags, del_flags, p = av
+ if p and not (add_flags & SRE_FLAG_IGNORECASE):
+ op, av = p[0]
if op is LITERAL:
charsetappend((op, av))
elif op is BRANCH:
@@ -460,21 +462,43 @@ def _compile_info(code, pattern, flags):
break
else:
charset = c
- elif op is BRANCH:
- c = []
- cappend = c.append
- for p in av[1]:
- if not p:
- break
- op, av = p[0]
- if op is LITERAL:
- cappend((op, av))
- else:
- break
+ elif op is BRANCH:
+ c = []
+ cappend = c.append
+ for p in av[1]:
+ if not p:
+ break
+ op, av = p[0]
+ if op is LITERAL:
+ cappend((op, av))
else:
- charset = c
- elif op is IN:
- charset = av
+ break
+ else:
+ charset = c
+ elif op is IN:
+ charset = av
+ return charset
+
+def _compile_info(code, pattern, flags):
+ # internal: compile an info block. in the current version,
+ # this contains min/max pattern width, and an optional literal
+ # prefix or a character map
+ lo, hi = pattern.getwidth()
+ if hi > MAXCODE:
+ hi = MAXCODE
+ if lo == 0:
+ code.extend([INFO, 4, 0, lo, hi])
+ return
+ # look for a literal prefix
+ prefix = []
+ prefix_skip = 0
+ charset = [] # not used
+ if not (flags & SRE_FLAG_IGNORECASE):
+ # look for literal prefix
+ prefix, prefix_skip, got_all = _get_literal_prefix(pattern)
+ # if no prefix, look for charset prefix
+ if not prefix:
+ charset = _get_charset_prefix(pattern)
## if prefix:
## print("*** PREFIX", prefix, prefix_skip)
## if charset:
@@ -487,7 +511,7 @@ def _compile_info(code, pattern, flags):
mask = 0
if prefix:
mask = SRE_INFO_PREFIX
- if len(prefix) == prefix_skip == len(pattern.data):
+ if prefix_skip is None and got_all:
mask = mask | SRE_INFO_LITERAL
elif charset:
mask = mask | SRE_INFO_CHARSET
@@ -502,6 +526,8 @@ def _compile_info(code, pattern, flags):
# add literal prefix
if prefix:
emit(len(prefix)) # length
+ if prefix_skip is None:
+ prefix_skip = len(prefix)
emit(prefix_skip) # skip
code.extend(prefix)
# generate overlap table
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 4ff50d1..3d38673 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -65,6 +65,12 @@ FLAGS = {
"u": SRE_FLAG_UNICODE,
}
+GLOBAL_FLAGS = (SRE_FLAG_ASCII | SRE_FLAG_LOCALE | SRE_FLAG_UNICODE |
+ SRE_FLAG_DEBUG | SRE_FLAG_TEMPLATE)
+
+class Verbose(Exception):
+ pass
+
class Pattern:
# master pattern object. keeps track of global attributes
def __init__(self):
@@ -184,7 +190,7 @@ class SubPattern:
lo = lo + i
hi = hi + j
elif op is SUBPATTERN:
- i, j = av[1].getwidth()
+ i, j = av[-1].getwidth()
lo = lo + i
hi = hi + j
elif op in _REPEATCODES:
@@ -273,6 +279,9 @@ class Tokenizer:
break
result += c
return result
+ @property
+ def pos(self):
+ return self.index - len(self.next or '')
def tell(self):
return self.index - len(self.next or '')
def seek(self, index):
@@ -282,33 +291,6 @@ class Tokenizer:
def error(self, msg, offset=0):
return error(msg, self.string, self.tell() - offset)
-# The following three functions are not used in this module anymore, but we keep
-# them here (with DeprecationWarnings) for backwards compatibility.
-
-def isident(char):
- import warnings
- warnings.warn('sre_parse.isident() will be removed in 3.5',
- DeprecationWarning, stacklevel=2)
- return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_"
-
-def isdigit(char):
- import warnings
- warnings.warn('sre_parse.isdigit() will be removed in 3.5',
- DeprecationWarning, stacklevel=2)
- return "0" <= char <= "9"
-
-def isname(name):
- import warnings
- warnings.warn('sre_parse.isname() will be removed in 3.5',
- DeprecationWarning, stacklevel=2)
- # check that group name is a valid string
- if not isident(name[0]):
- return False
- for char in name[1:]:
- if not isident(char) and not isdigit(char):
- return False
- return True
-
def _class_escape(source, escape):
# handle escape code inside character class
code = ESCAPES.get(escape)
@@ -351,9 +333,7 @@ def _class_escape(source, escape):
raise ValueError
if len(escape) == 2:
if c in ASCIILETTERS:
- import warnings
- warnings.warn('bad escape %s' % escape,
- DeprecationWarning, stacklevel=8)
+ raise source.error('bad escape %s' % escape, len(escape))
return LITERAL, ord(escape[1])
except ValueError:
pass
@@ -418,15 +398,13 @@ def _escape(source, escape, state):
raise source.error("invalid group reference", len(escape))
if len(escape) == 2:
if c in ASCIILETTERS:
- import warnings
- warnings.warn('bad escape %s' % escape,
- DeprecationWarning, stacklevel=8)
+ raise source.error("bad escape %s" % escape, len(escape))
return LITERAL, ord(escape[1])
except ValueError:
pass
raise source.error("bad escape %s" % escape, len(escape))
-def _parse_sub(source, state, nested=True):
+def _parse_sub(source, state, verbose, nested=True):
# parse an alternation: a|b|c
items = []
@@ -434,7 +412,7 @@ def _parse_sub(source, state, nested=True):
sourcematch = source.match
start = source.tell()
while True:
- itemsappend(_parse(source, state))
+ itemsappend(_parse(source, state, verbose))
if not sourcematch("|"):
break
@@ -476,10 +454,10 @@ def _parse_sub(source, state, nested=True):
subpattern.append((BRANCH, (None, items)))
return subpattern
-def _parse_sub_cond(source, state, condgroup):
- item_yes = _parse(source, state)
+def _parse_sub_cond(source, state, condgroup, verbose):
+ item_yes = _parse(source, state, verbose)
if source.match("|"):
- item_no = _parse(source, state)
+ item_no = _parse(source, state, verbose)
if source.next == "|":
raise source.error("conditional backref with more than two branches")
else:
@@ -488,7 +466,7 @@ def _parse_sub_cond(source, state, condgroup):
subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no)))
return subpattern
-def _parse(source, state):
+def _parse(source, state, verbose):
# parse a simple pattern
subpattern = SubPattern(state)
@@ -498,7 +476,6 @@ def _parse(source, state):
sourcematch = source.match
_len = len
_ord = ord
- verbose = state.flags & SRE_FLAG_VERBOSE
while True:
@@ -652,6 +629,8 @@ def _parse(source, state):
group = True
name = None
condgroup = None
+ add_flags = 0
+ del_flags = 0
if sourcematch("?"):
# options
char = sourceget()
@@ -713,7 +692,7 @@ def _parse(source, state):
lookbehindgroups = state.lookbehindgroups
if lookbehindgroups is None:
state.lookbehindgroups = state.groups
- p = _parse_sub(source, state)
+ p = _parse_sub(source, state, verbose)
if dir < 0:
if lookbehindgroups is None:
state.lookbehindgroups = None
@@ -749,19 +728,23 @@ def _parse(source, state):
raise source.error("invalid group reference",
len(condname) + 1)
state.checklookbehindgroup(condgroup, source)
- elif char in FLAGS:
+ elif char in FLAGS or char == "-":
# flags
- while True:
- state.flags |= FLAGS[char]
- char = sourceget()
- if char is None:
- raise source.error("missing )")
- if char == ")":
- break
- if char not in FLAGS:
- raise source.error("unknown flag", len(char))
- verbose = state.flags & SRE_FLAG_VERBOSE
- continue
+ pos = source.pos
+ flags = _parse_flags(source, state, char)
+ if flags is None: # global flags
+ if pos != 3: # "(?x"
+ import warnings
+ warnings.warn(
+ 'Flags not at the start of the expression %s%s' % (
+ source.string[:20], # truncate long regexes
+ ' (truncated)' if len(source.string) > 20 else '',
+ ),
+ DeprecationWarning, stacklevel=7
+ )
+ continue
+ add_flags, del_flags = flags
+ group = None
else:
raise source.error("unknown extension ?" + char,
len(char) + 1)
@@ -773,15 +756,17 @@ def _parse(source, state):
except error as err:
raise source.error(err.msg, len(name) + 1) from None
if condgroup:
- p = _parse_sub_cond(source, state, condgroup)
+ p = _parse_sub_cond(source, state, condgroup, verbose)
else:
- p = _parse_sub(source, state)
+ sub_verbose = ((verbose or (add_flags & SRE_FLAG_VERBOSE)) and
+ not (del_flags & SRE_FLAG_VERBOSE))
+ p = _parse_sub(source, state, sub_verbose)
if not source.match(")"):
raise source.error("missing ), unterminated subpattern",
source.tell() - start)
if group is not None:
state.closegroup(group, p)
- subpatternappend((SUBPATTERN, (group, p)))
+ subpatternappend((SUBPATTERN, (group, add_flags, del_flags, p)))
elif this == "^":
subpatternappend((AT, AT_BEGINNING))
@@ -794,14 +779,58 @@ def _parse(source, state):
return subpattern
+def _parse_flags(source, state, char):
+ sourceget = source.get
+ add_flags = 0
+ del_flags = 0
+ if char != "-":
+ while True:
+ add_flags |= FLAGS[char]
+ char = sourceget()
+ if char is None:
+ raise source.error("missing -, : or )")
+ if char in ")-:":
+ break
+ if char not in FLAGS:
+ msg = "unknown flag" if char.isalpha() else "missing -, : or )"
+ raise source.error(msg, len(char))
+ if char == ")":
+ if ((add_flags & SRE_FLAG_VERBOSE) and
+ not (state.flags & SRE_FLAG_VERBOSE)):
+ raise Verbose
+ state.flags |= add_flags
+ return None
+ if add_flags & GLOBAL_FLAGS:
+ raise source.error("bad inline flags: cannot turn on global flag", 1)
+ if char == "-":
+ char = sourceget()
+ if char is None:
+ raise source.error("missing flag")
+ if char not in FLAGS:
+ msg = "unknown flag" if char.isalpha() else "missing flag"
+ raise source.error(msg, len(char))
+ while True:
+ del_flags |= FLAGS[char]
+ char = sourceget()
+ if char is None:
+ raise source.error("missing :")
+ if char == ":":
+ break
+ if char not in FLAGS:
+ msg = "unknown flag" if char.isalpha() else "missing :"
+ raise source.error(msg, len(char))
+ assert char == ":"
+ if del_flags & GLOBAL_FLAGS:
+ raise source.error("bad inline flags: cannot turn off global flag", 1)
+ if add_flags & del_flags:
+ raise source.error("bad inline flags: flag turned on and off", 1)
+ return add_flags, del_flags
+
def fix_flags(src, flags):
# Check and fix flags according to the type of pattern (str or bytes)
if isinstance(src, str):
if flags & SRE_FLAG_LOCALE:
- import warnings
- warnings.warn("LOCALE flag with a str pattern is deprecated. "
- "Will be an error in 3.6",
- DeprecationWarning, stacklevel=6)
+ raise ValueError("cannot use LOCALE flag with a str pattern")
if not flags & SRE_FLAG_ASCII:
flags |= SRE_FLAG_UNICODE
elif flags & SRE_FLAG_UNICODE:
@@ -810,10 +839,7 @@ def fix_flags(src, flags):
if flags & SRE_FLAG_UNICODE:
raise ValueError("cannot use UNICODE flag with a bytes pattern")
if flags & SRE_FLAG_LOCALE and flags & SRE_FLAG_ASCII:
- import warnings
- warnings.warn("ASCII and LOCALE flags are incompatible. "
- "Will be an error in 3.6",
- DeprecationWarning, stacklevel=6)
+ raise ValueError("ASCII and LOCALE flags are incompatible")
return flags
def parse(str, flags=0, pattern=None):
@@ -826,18 +852,23 @@ def parse(str, flags=0, pattern=None):
pattern.flags = flags
pattern.str = str
- p = _parse_sub(source, pattern, 0)
+ try:
+ p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, False)
+ except Verbose:
+ # the VERBOSE flag was switched on inside the pattern. to be
+ # on the safe side, we'll parse the whole thing again...
+ pattern = Pattern()
+ pattern.flags = flags | SRE_FLAG_VERBOSE
+ pattern.str = str
+ source.seek(0)
+ p = _parse_sub(source, pattern, True, False)
+
p.pattern.flags = fix_flags(str, p.pattern.flags)
if source.next is not None:
assert source.next == ")"
raise source.error("unbalanced parenthesis")
- if not (flags & SRE_FLAG_VERBOSE) and p.pattern.flags & SRE_FLAG_VERBOSE:
- # the VERBOSE flag was switched on inside the pattern. to be
- # on the safe side, we'll parse the whole thing again...
- return parse(str, p.pattern.flags)
-
if flags & SRE_FLAG_DEBUG:
p.dump()
@@ -914,9 +945,7 @@ def parse_template(source, pattern):
this = chr(ESCAPES[this][1])
except KeyError:
if c in ASCIILETTERS:
- import warnings
- warnings.warn('bad escape %s' % this,
- DeprecationWarning, stacklevel=4)
+ raise s.error('bad escape %s' % this, len(this))
lappend(this)
else:
lappend(this)
diff --git a/Lib/ssl.py b/Lib/ssl.py
index e191390..8ad4a33 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -52,6 +52,8 @@ PROTOCOL_SSLv2
PROTOCOL_SSLv3
PROTOCOL_SSLv23
PROTOCOL_TLS
+PROTOCOL_TLS_CLIENT
+PROTOCOL_TLS_SERVER
PROTOCOL_TLSv1
PROTOCOL_TLSv1_1
PROTOCOL_TLSv1_2
@@ -94,17 +96,16 @@ import re
import sys
import os
from collections import namedtuple
-from enum import Enum as _Enum, IntEnum as _IntEnum
+from enum import Enum as _Enum, IntEnum as _IntEnum, IntFlag as _IntFlag
import _ssl # if we can't import it, let the error propagate
from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
-from _ssl import _SSLContext, MemoryBIO
+from _ssl import _SSLContext, MemoryBIO, SSLSession
from _ssl import (
SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError,
SSLSyscallError, SSLEOFError,
)
-from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj
from _ssl import RAND_status, RAND_add, RAND_bytes, RAND_pseudo_bytes
try:
@@ -113,32 +114,47 @@ except ImportError:
# LibreSSL does not provide RAND_egd
pass
-def _import_symbols(prefix):
- for n in dir(_ssl):
- if n.startswith(prefix):
- globals()[n] = getattr(_ssl, n)
-
-_import_symbols('OP_')
-_import_symbols('ALERT_DESCRIPTION_')
-_import_symbols('SSL_ERROR_')
-_import_symbols('VERIFY_')
from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN
-
from _ssl import _OPENSSL_API_VERSION
+
+_IntEnum._convert(
+ '_SSLMethod', __name__,
+ lambda name: name.startswith('PROTOCOL_') and name != 'PROTOCOL_SSLv23',
+ source=_ssl)
+
+_IntFlag._convert(
+ 'Options', __name__,
+ lambda name: name.startswith('OP_'),
+ source=_ssl)
+
+_IntEnum._convert(
+ 'AlertDescription', __name__,
+ lambda name: name.startswith('ALERT_DESCRIPTION_'),
+ source=_ssl)
+
+_IntEnum._convert(
+ 'SSLErrorNumber', __name__,
+ lambda name: name.startswith('SSL_ERROR_'),
+ source=_ssl)
+
+_IntFlag._convert(
+ 'VerifyFlags', __name__,
+ lambda name: name.startswith('VERIFY_'),
+ source=_ssl)
+
_IntEnum._convert(
- '_SSLMethod', __name__,
- lambda name: name.startswith('PROTOCOL_') and name != 'PROTOCOL_SSLv23',
- source=_ssl)
+ 'VerifyMode', __name__,
+ lambda name: name.startswith('CERT_'),
+ source=_ssl)
+
PROTOCOL_SSLv23 = _SSLMethod.PROTOCOL_SSLv23 = _SSLMethod.PROTOCOL_TLS
_PROTOCOL_NAMES = {value: name for name, value in _SSLMethod.__members__.items()}
-try:
- _SSLv2_IF_EXISTS = PROTOCOL_SSLv2
-except NameError:
- _SSLv2_IF_EXISTS = None
+_SSLv2_IF_EXISTS = getattr(_SSLMethod, 'PROTOCOL_SSLv2', None)
+
if sys.platform == "win32":
from _ssl import enum_certificates, enum_crls
@@ -377,18 +393,18 @@ class SSLContext(_SSLContext):
def wrap_socket(self, sock, server_side=False,
do_handshake_on_connect=True,
suppress_ragged_eofs=True,
- server_hostname=None):
+ server_hostname=None, session=None):
return SSLSocket(sock=sock, server_side=server_side,
do_handshake_on_connect=do_handshake_on_connect,
suppress_ragged_eofs=suppress_ragged_eofs,
server_hostname=server_hostname,
- _context=self)
+ _context=self, _session=session)
def wrap_bio(self, incoming, outgoing, server_side=False,
- server_hostname=None):
+ server_hostname=None, session=None):
sslobj = self._wrap_bio(incoming, outgoing, server_side=server_side,
server_hostname=server_hostname)
- return SSLObject(sslobj)
+ return SSLObject(sslobj, session=session)
def set_npn_protocols(self, npn_protocols):
protos = bytearray()
@@ -434,6 +450,34 @@ class SSLContext(_SSLContext):
self._load_windows_store_certs(storename, purpose)
self.set_default_verify_paths()
+ @property
+ def options(self):
+ return Options(super().options)
+
+ @options.setter
+ def options(self, value):
+ super(SSLContext, SSLContext).options.__set__(self, value)
+
+ @property
+ def verify_flags(self):
+ return VerifyFlags(super().verify_flags)
+
+ @verify_flags.setter
+ def verify_flags(self, value):
+ super(SSLContext, SSLContext).verify_flags.__set__(self, value)
+
+ @property
+ def verify_mode(self):
+ value = super().verify_mode
+ try:
+ return VerifyMode(value)
+ except ValueError:
+ return value
+
+ @verify_mode.setter
+ def verify_mode(self, value):
+ super(SSLContext, SSLContext).verify_mode.__set__(self, value)
+
def create_default_context(purpose=Purpose.SERVER_AUTH, *, cafile=None,
capath=None, cadata=None):
@@ -446,32 +490,16 @@ def create_default_context(purpose=Purpose.SERVER_AUTH, *, cafile=None,
if not isinstance(purpose, _ASN1Object):
raise TypeError(purpose)
+ # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
+ # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
+ # by default.
context = SSLContext(PROTOCOL_TLS)
- # SSLv2 considered harmful.
- context.options |= OP_NO_SSLv2
-
- # SSLv3 has problematic security and is only required for really old
- # clients such as IE6 on Windows XP
- context.options |= OP_NO_SSLv3
-
- # disable compression to prevent CRIME attacks (OpenSSL 1.0+)
- context.options |= getattr(_ssl, "OP_NO_COMPRESSION", 0)
-
if purpose == Purpose.SERVER_AUTH:
# verify certs and host name in client mode
context.verify_mode = CERT_REQUIRED
context.check_hostname = True
elif purpose == Purpose.CLIENT_AUTH:
- # Prefer the server's ciphers by default so that we get stronger
- # encryption
- context.options |= getattr(_ssl, "OP_CIPHER_SERVER_PREFERENCE", 0)
-
- # Use single use keys in order to improve forward secrecy
- context.options |= getattr(_ssl, "OP_SINGLE_DH_USE", 0)
- context.options |= getattr(_ssl, "OP_SINGLE_ECDH_USE", 0)
-
- # disallow ciphers with known vulnerabilities
context.set_ciphers(_RESTRICTED_SERVER_CIPHERS)
if cafile or capath or cadata:
@@ -497,12 +525,10 @@ def _create_unverified_context(protocol=PROTOCOL_TLS, *, cert_reqs=None,
if not isinstance(purpose, _ASN1Object):
raise TypeError(purpose)
+ # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
+ # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
+ # by default.
context = SSLContext(protocol)
- # SSLv2 considered harmful.
- context.options |= OP_NO_SSLv2
- # SSLv3 has problematic security and is only required for really old
- # clients such as IE6 on Windows XP
- context.options |= OP_NO_SSLv3
if cert_reqs is not None:
context.verify_mode = cert_reqs
@@ -548,10 +574,12 @@ class SSLObject:
* The ``do_handshake_on_connect`` and ``suppress_ragged_eofs`` machinery.
"""
- def __init__(self, sslobj, owner=None):
+ def __init__(self, sslobj, owner=None, session=None):
self._sslobj = sslobj
# Note: _sslobj takes a weak reference to owner
self._sslobj.owner = owner or self
+ if session is not None:
+ self._sslobj.session = session
@property
def context(self):
@@ -563,6 +591,20 @@ class SSLObject:
self._sslobj.context = ctx
@property
+ def session(self):
+ """The SSLSession for client socket."""
+ return self._sslobj.session
+
+ @session.setter
+ def session(self, session):
+ self._sslobj.session = session
+
+ @property
+ def session_reused(self):
+ """Was the client session reused during handshake"""
+ return self._sslobj.session_reused
+
+ @property
def server_side(self):
"""Whether this is a server-side socket."""
return self._sslobj.server_side
@@ -679,7 +721,7 @@ class SSLSocket(socket):
family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None,
suppress_ragged_eofs=True, npn_protocols=None, ciphers=None,
server_hostname=None,
- _context=None):
+ _context=None, _session=None):
if _context:
self._context = _context
@@ -711,11 +753,16 @@ class SSLSocket(socket):
# mixed in.
if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
raise NotImplementedError("only stream sockets are supported")
- if server_side and server_hostname:
- raise ValueError("server_hostname can only be specified "
- "in client mode")
+ if server_side:
+ if server_hostname:
+ raise ValueError("server_hostname can only be specified "
+ "in client mode")
+ if _session is not None:
+ raise ValueError("session can only be specified in "
+ "client mode")
if self._context.check_hostname and not server_hostname:
raise ValueError("check_hostname requires server_hostname")
+ self._session = _session
self.server_side = server_side
self.server_hostname = server_hostname
self.do_handshake_on_connect = do_handshake_on_connect
@@ -751,7 +798,8 @@ class SSLSocket(socket):
try:
sslobj = self._context._wrap_socket(self, server_side,
server_hostname)
- self._sslobj = SSLObject(sslobj, owner=self)
+ self._sslobj = SSLObject(sslobj, owner=self,
+ session=self._session)
if do_handshake_on_connect:
timeout = self.gettimeout()
if timeout == 0.0:
@@ -772,6 +820,24 @@ class SSLSocket(socket):
self._context = ctx
self._sslobj.context = ctx
+ @property
+ def session(self):
+ """The SSLSession for client socket."""
+ if self._sslobj is not None:
+ return self._sslobj.session
+
+ @session.setter
+ def session(self, session):
+ self._session = session
+ if self._sslobj is not None:
+ self._sslobj.session = session
+
+ @property
+ def session_reused(self):
+ """Was the client session reused during handshake"""
+ if self._sslobj is not None:
+ return self._sslobj.session_reused
+
def dup(self):
raise NotImplemented("Can't dup() %s instances" %
self.__class__.__name__)
@@ -898,7 +964,6 @@ class SSLSocket(socket):
while (count < amount):
v = self.send(data[count:])
count += v
- return amount
else:
return socket.sendall(self, data, flags)
@@ -1005,7 +1070,8 @@ class SSLSocket(socket):
if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
sslobj = self.context._wrap_socket(self, False, self.server_hostname)
- self._sslobj = SSLObject(sslobj, owner=self)
+ self._sslobj = SSLObject(sslobj, owner=self,
+ session=self._session)
try:
if connect_ex:
rc = socket.connect_ex(self, addr)
@@ -1068,7 +1134,6 @@ def wrap_socket(sock, keyfile=None, certfile=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True,
ciphers=None):
-
return SSLSocket(sock=sock, keyfile=keyfile, certfile=certfile,
server_side=server_side, cert_reqs=cert_reqs,
ssl_version=ssl_version, ca_certs=ca_certs,
diff --git a/Lib/statistics.py b/Lib/statistics.py
index 4f5c1c1..30fe55c 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -1,20 +1,3 @@
-## Module statistics.py
-##
-## Copyright (c) 2013 Steven D'Aprano <steve+python@pearwood.info>.
-##
-## Licensed under the Apache License, Version 2.0 (the "License");
-## you may not use this file except in compliance with the License.
-## You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-
-
"""
Basic statistics module.
@@ -28,6 +11,7 @@ Calculating averages
Function Description
================== =============================================
mean Arithmetic mean (average) of data.
+harmonic_mean Harmonic mean of data.
median Median (middle value) of data.
median_low Low median of data.
median_high High median of data.
@@ -95,16 +79,18 @@ A single exception is defined: StatisticsError is a subclass of ValueError.
__all__ = [ 'StatisticsError',
'pstdev', 'pvariance', 'stdev', 'variance',
'median', 'median_low', 'median_high', 'median_grouped',
- 'mean', 'mode',
+ 'mean', 'mode', 'harmonic_mean',
]
-
import collections
+import decimal
import math
+import numbers
from fractions import Fraction
from decimal import Decimal
-from itertools import groupby
+from itertools import groupby, chain
+from bisect import bisect_left, bisect_right
@@ -134,7 +120,8 @@ def _sum(data, start=0):
Some sources of round-off error will be avoided:
- >>> _sum([1e50, 1, -1e50] * 1000) # Built-in sum returns zero.
+ # Built-in sum returns zero.
+ >>> _sum([1e50, 1, -1e50] * 1000)
(<class 'float'>, Fraction(1000, 1), 3000)
Fractions and Decimals are also supported:
@@ -223,56 +210,26 @@ def _exact_ratio(x):
# Optimise the common case of floats. We expect that the most often
# used numeric type will be builtin floats, so try to make this as
# fast as possible.
- if type(x) is float:
+ if type(x) is float or type(x) is Decimal:
return x.as_integer_ratio()
try:
# x may be an int, Fraction, or Integral ABC.
return (x.numerator, x.denominator)
except AttributeError:
try:
- # x may be a float subclass.
+ # x may be a float or Decimal subclass.
return x.as_integer_ratio()
except AttributeError:
- try:
- # x may be a Decimal.
- return _decimal_to_ratio(x)
- except AttributeError:
- # Just give up?
- pass
+ # Just give up?
+ pass
except (OverflowError, ValueError):
# float NAN or INF.
- assert not math.isfinite(x)
+ assert not _isfinite(x)
return (x, None)
msg = "can't convert type '{}' to numerator/denominator"
raise TypeError(msg.format(type(x).__name__))
-# FIXME This is faster than Fraction.from_decimal, but still too slow.
-def _decimal_to_ratio(d):
- """Convert Decimal d to exact integer ratio (numerator, denominator).
-
- >>> from decimal import Decimal
- >>> _decimal_to_ratio(Decimal("2.6"))
- (26, 10)
-
- """
- sign, digits, exp = d.as_tuple()
- if exp in ('F', 'n', 'N'): # INF, NAN, sNAN
- assert not d.is_finite()
- return (d, None)
- num = 0
- for digit in digits:
- num = num*10 + digit
- if exp < 0:
- den = 10**-exp
- else:
- num *= 10**exp
- den = 1
- if sign:
- num = -num
- return (num, den)
-
-
def _convert(value, T):
"""Convert value to given numeric type T."""
if type(value) is T:
@@ -305,6 +262,30 @@ def _counts(data):
return table
+def _find_lteq(a, x):
+ 'Locate the leftmost value exactly equal to x'
+ i = bisect_left(a, x)
+ if i != len(a) and a[i] == x:
+ return i
+ raise ValueError
+
+
+def _find_rteq(a, l, x):
+ 'Locate the rightmost value exactly equal to x'
+ i = bisect_right(a, x, lo=l)
+ if i != (len(a)+1) and a[i-1] == x:
+ return i-1
+ raise ValueError
+
+
+def _fail_neg(values, errmsg='negative value'):
+ """Iterate over values, failing if any are less than zero."""
+ for x in values:
+ if x < 0:
+ raise StatisticsError(errmsg)
+ yield x
+
+
# === Measures of central tendency (averages) ===
def mean(data):
@@ -333,6 +314,52 @@ def mean(data):
return _convert(total/n, T)
+def harmonic_mean(data):
+ """Return the harmonic mean of data.
+
+ The harmonic mean, sometimes called the subcontrary mean, is the
+ reciprocal of the arithmetic mean of the reciprocals of the data,
+ and is often appropriate when averaging quantities which are rates
+ or ratios, for example speeds. Example:
+
+ Suppose an investor purchases an equal value of shares in each of
+ three companies, with P/E (price/earning) ratios of 2.5, 3 and 10.
+ What is the average P/E ratio for the investor's portfolio?
+
+ >>> harmonic_mean([2.5, 3, 10]) # For an equal investment portfolio.
+ 3.6
+
+ Using the arithmetic mean would give an average of about 5.167, which
+ is too high.
+
+ If ``data`` is empty, or any element is less than zero,
+ ``harmonic_mean`` will raise ``StatisticsError``.
+ """
+ # For a justification for using harmonic mean for P/E ratios, see
+ # http://fixthepitch.pellucid.com/comps-analysis-the-missing-harmony-of-summary-statistics/
+ # http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2621087
+ if iter(data) is data:
+ data = list(data)
+ errmsg = 'harmonic mean does not support negative values'
+ n = len(data)
+ if n < 1:
+ raise StatisticsError('harmonic_mean requires at least one data point')
+ elif n == 1:
+ x = data[0]
+ if isinstance(x, (numbers.Real, Decimal)):
+ if x < 0:
+ raise StatisticsError(errmsg)
+ return x
+ else:
+ raise TypeError('unsupported type')
+ try:
+ T, total, count = _sum(1/x for x in _fail_neg(data, errmsg))
+ except ZeroDivisionError:
+ return 0
+ assert count == n
+ return _convert(n/total, T)
+
+
# FIXME: investigate ways to calculate medians without sorting? Quickselect?
def median(data):
"""Return the median (middle value) of numeric data.
@@ -442,9 +469,15 @@ def median_grouped(data, interval=1):
except TypeError:
# Mixed type. For now we just coerce to float.
L = float(x) - float(interval)/2
- cf = data.index(x) # Number of values below the median interval.
- # FIXME The following line could be more efficient for big lists.
- f = data.count(x) # Number of data points in the median interval.
+
+ # Uses bisection search to search for x in data with log(n) time complexity
+ # Find the position of leftmost occurrence of x in data
+ l1 = _find_lteq(data, x)
+ # Find the position of rightmost occurrence of x in data[l1...len(data)]
+ # Assuming always l1 <= l2
+ l2 = _find_rteq(data, l1, x)
+ cf = l1
+ f = l2 - l1 + 1
return L + interval*(n/2 - cf)/f
diff --git a/Lib/string.py b/Lib/string.py
index 89287c4..c902007 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -28,7 +28,7 @@ ascii_letters = ascii_lowercase + ascii_uppercase
digits = '0123456789'
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
-punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
+punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + ascii_letters + punctuation + whitespace
# Functions which aren't available as string methods.
@@ -116,10 +116,7 @@ class Template(metaclass=_TemplateMetaclass):
# Check the most common path first.
named = mo.group('named') or mo.group('braced')
if named is not None:
- val = mapping[named]
- # We use this idiom instead of str() because the latter will
- # fail if val is a Unicode containing non-ASCII characters.
- return '%s' % (val,)
+ return str(mapping[named])
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
@@ -146,9 +143,7 @@ class Template(metaclass=_TemplateMetaclass):
named = mo.group('named') or mo.group('braced')
if named is not None:
try:
- # We use this idiom instead of str() because the latter
- # will fail if val is a Unicode containing non-ASCII
- return '%s' % (mapping[named],)
+ return str(mapping[named])
except KeyError:
return mo.group()
if mo.group('escaped') is not None:
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index d8d6ab2..9df9318 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -30,7 +30,8 @@ class Popen(args, bufsize=-1, executable=None,
preexec_fn=None, close_fds=True, shell=False,
cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0,
- restore_signals=True, start_new_session=False, pass_fds=()):
+ restore_signals=True, start_new_session=False, pass_fds=(),
+ *, encoding=None, errors=None):
Arguments are:
@@ -104,20 +105,13 @@ in the child process prior to executing the command.
If env is not None, it defines the environment variables for the new
process.
-If universal_newlines is False, the file objects stdin, stdout and stderr
-are opened as binary files, and no line ending conversion is done.
+If encoding or errors are specified or universal_newlines is True, the file
+objects stdout and stderr are opened in text mode. See io.TextIOWrapper for
+the interpretation of these parameters are used.
-If universal_newlines is True, the file objects stdout and stderr are
-opened as a text file, but lines may be terminated by any of '\n',
-the Unix end-of-line convention, '\r', the old Macintosh convention or
-'\r\n', the Windows convention. All of these external representations
-are seen as '\n' by the Python program. Also, the newlines attribute
-of the file objects stdout, stdin and stderr are not updated by the
-communicate() method.
-
-In either case, the process being communicated with should start up
-expecting to receive bytes on its standard input and decode them with
-the same encoding they are sent in.
+If no encoding is specified and universal_newlines is False, the file
+objects stdin, stdout and stderr are opened as binary files, and no
+line ending conversion is done.
The startupinfo and creationflags, if given, will be passed to the
underlying CreateProcess() function. They can specify things such as
@@ -234,11 +228,8 @@ communicate(input=None)
and stderr, until end-of-file is reached. Wait for process to
terminate. The optional input argument should be data to be
sent to the child process, or None, if no data should be sent to
- the child. If the Popen instance was constructed with universal_newlines
- set to True, the input argument should be a string and will be encoded
- using the preferred system encoding (see locale.getpreferredencoding);
- if universal_newlines is False, the input argument should be a
- byte string.
+ the child. If the Popen instance was constructed in text mode, the
+ input argument should be a string. Otherwise, it should be bytes.
communicate() returns a tuple (stdout, stderr).
@@ -372,9 +363,11 @@ class SubprocessError(Exception): pass
class CalledProcessError(SubprocessError):
- """This exception is raised when a process run by check_call() or
- check_output() returns a non-zero exit status.
- The exit status will be stored in the returncode attribute;
+ """Raised when a check_call() or check_output() process returns non-zero.
+
+ The exit status will be stored in the returncode attribute, negative
+ if it represents a signal number.
+
check_output() will also store the output in the output attribute.
"""
def __init__(self, returncode, cmd, output=None, stderr=None):
@@ -384,7 +377,16 @@ class CalledProcessError(SubprocessError):
self.stderr = stderr
def __str__(self):
- return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
+ if self.returncode and self.returncode < 0:
+ try:
+ return "Command '%s' died with %r." % (
+ self.cmd, signal.Signals(-self.returncode))
+ except ValueError:
+ return "Command '%s' died with unknown signal %d." % (
+ self.cmd, -self.returncode)
+ else:
+ return "Command '%s' returned non-zero exit status %d." % (
+ self.cmd, self.returncode)
@property
def stdout(self):
@@ -471,7 +473,8 @@ if _mswindows:
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP",
"STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE",
"STD_ERROR_HANDLE", "SW_HIDE",
- "STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW"])
+ "STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW",
+ "STARTUPINFO"])
class Handle(int):
closed = False
@@ -520,6 +523,16 @@ DEVNULL = -3
# but it's here so that it can be imported when Python is compiled without
# threads.
+def _optim_args_from_interpreter_flags():
+ """Return a list of command-line arguments reproducing the current
+ optimization settings in sys.flags."""
+ args = []
+ value = sys.flags.optimize
+ if value > 0:
+ args.append('-' + 'O' * value)
+ return args
+
+
def _args_from_interpreter_flags():
"""Return a list of command-line arguments reproducing the current
settings in sys.flags and sys.warnoptions."""
@@ -527,7 +540,6 @@ def _args_from_interpreter_flags():
'debug': 'd',
# 'inspect': 'i',
# 'interactive': 'i',
- 'optimize': 'O',
'dont_write_bytecode': 'B',
'no_user_site': 's',
'no_site': 'S',
@@ -535,8 +547,9 @@ def _args_from_interpreter_flags():
'verbose': 'v',
'bytes_warning': 'b',
'quiet': 'q',
+ # -O is handled in _optim_args_from_interpreter_flags()
}
- args = []
+ args = _optim_args_from_interpreter_flags()
for flag, opt in flag_opt_map.items():
v = getattr(sys.flags, flag)
if v > 0:
@@ -786,8 +799,8 @@ def getstatusoutput(cmd):
""" Return (status, output) of executing cmd in a shell.
Execute the string 'cmd' in a shell with 'check_output' and
- return a 2-tuple (status, output). Universal newlines mode is used,
- meaning that the result with be decoded to a string.
+ return a 2-tuple (status, output). The locale encoding is used
+ to decode the output and process newlines.
A trailing newline is stripped from the output.
The exit status for the command can be interpreted
@@ -837,7 +850,7 @@ class Popen(object):
shell=False, cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0,
restore_signals=True, start_new_session=False,
- pass_fds=()):
+ pass_fds=(), *, encoding=None, errors=None):
"""Create new Popen instance."""
_cleanup()
# Held while anything is calling waitpid before returncode has been
@@ -890,6 +903,8 @@ class Popen(object):
self.pid = None
self.returncode = None
self.universal_newlines = universal_newlines
+ self.encoding = encoding
+ self.errors = errors
# Input and output objects. The general principle is like
# this:
@@ -922,22 +937,28 @@ class Popen(object):
if errread != -1:
errread = msvcrt.open_osfhandle(errread.Detach(), 0)
- if p2cwrite != -1:
- self.stdin = io.open(p2cwrite, 'wb', bufsize)
- if universal_newlines:
- self.stdin = io.TextIOWrapper(self.stdin, write_through=True,
- line_buffering=(bufsize == 1))
- if c2pread != -1:
- self.stdout = io.open(c2pread, 'rb', bufsize)
- if universal_newlines:
- self.stdout = io.TextIOWrapper(self.stdout)
- if errread != -1:
- self.stderr = io.open(errread, 'rb', bufsize)
- if universal_newlines:
- self.stderr = io.TextIOWrapper(self.stderr)
+ text_mode = encoding or errors or universal_newlines
self._closed_child_pipe_fds = False
+
try:
+ if p2cwrite != -1:
+ self.stdin = io.open(p2cwrite, 'wb', bufsize)
+ if text_mode:
+ self.stdin = io.TextIOWrapper(self.stdin, write_through=True,
+ line_buffering=(bufsize == 1),
+ encoding=encoding, errors=errors)
+ if c2pread != -1:
+ self.stdout = io.open(c2pread, 'rb', bufsize)
+ if text_mode:
+ self.stdout = io.TextIOWrapper(self.stdout,
+ encoding=encoding, errors=errors)
+ if errread != -1:
+ self.stderr = io.open(errread, 'rb', bufsize)
+ if text_mode:
+ self.stderr = io.TextIOWrapper(self.stderr,
+ encoding=encoding, errors=errors)
+
self._execute_child(args, executable, preexec_fn, close_fds,
pass_fds, cwd, env,
startupinfo, creationflags, shell,
@@ -971,9 +992,8 @@ class Popen(object):
raise
-
- def _translate_newlines(self, data, encoding):
- data = data.decode(encoding)
+ def _translate_newlines(self, data, encoding, errors):
+ data = data.decode(encoding, errors)
return data.replace("\r\n", "\n").replace("\r", "\n")
def __enter__(self):
@@ -995,6 +1015,11 @@ class Popen(object):
if not self._child_created:
# We didn't get to successfully create a child process.
return
+ if self.returncode is None:
+ # Not reading subprocess exit status creates a zombi process which
+ # is only destroyed at the parent python process exit
+ warnings.warn("subprocess %s is still running" % self.pid,
+ ResourceWarning, source=self)
# In case the child hasn't been waited on, check if it's done.
self._internal_poll(_deadstate=_maxsize)
if self.returncode is None and _active is not None:
@@ -1520,9 +1545,14 @@ class Popen(object):
if errpipe_data:
try:
- os.waitpid(self.pid, 0)
+ pid, sts = os.waitpid(self.pid, 0)
+ if pid == self.pid:
+ self._handle_exitstatus(sts)
+ else:
+ self.returncode = sys.maxsize
except ChildProcessError:
pass
+
try:
exception_name, hex_errno, err_msg = (
errpipe_data.split(b':', 2))
@@ -1748,13 +1778,15 @@ class Popen(object):
# Translate newlines, if requested.
# This also turns bytes into strings.
- if self.universal_newlines:
+ if self.encoding or self.errors or self.universal_newlines:
if stdout is not None:
stdout = self._translate_newlines(stdout,
- self.stdout.encoding)
+ self.stdout.encoding,
+ self.stdout.errors)
if stderr is not None:
stderr = self._translate_newlines(stderr,
- self.stderr.encoding)
+ self.stderr.encoding,
+ self.stderr.errors)
return (stdout, stderr)
@@ -1766,8 +1798,10 @@ class Popen(object):
if self.stdin and self._input is None:
self._input_offset = 0
self._input = input
- if self.universal_newlines and input is not None:
- self._input = self._input.encode(self.stdin.encoding)
+ if input is not None and (
+ self.encoding or self.errors or self.universal_newlines):
+ self._input = self._input.encode(self.stdin.encoding,
+ self.stdin.errors)
def send_signal(self, sig):
diff --git a/Lib/symbol.py b/Lib/symbol.py
index 7541497..d9f01e0 100755
--- a/Lib/symbol.py
+++ b/Lib/symbol.py
@@ -27,74 +27,75 @@ stmt = 269
simple_stmt = 270
small_stmt = 271
expr_stmt = 272
-testlist_star_expr = 273
-augassign = 274
-del_stmt = 275
-pass_stmt = 276
-flow_stmt = 277
-break_stmt = 278
-continue_stmt = 279
-return_stmt = 280
-yield_stmt = 281
-raise_stmt = 282
-import_stmt = 283
-import_name = 284
-import_from = 285
-import_as_name = 286
-dotted_as_name = 287
-import_as_names = 288
-dotted_as_names = 289
-dotted_name = 290
-global_stmt = 291
-nonlocal_stmt = 292
-assert_stmt = 293
-compound_stmt = 294
-async_stmt = 295
-if_stmt = 296
-while_stmt = 297
-for_stmt = 298
-try_stmt = 299
-with_stmt = 300
-with_item = 301
-except_clause = 302
-suite = 303
-test = 304
-test_nocond = 305
-lambdef = 306
-lambdef_nocond = 307
-or_test = 308
-and_test = 309
-not_test = 310
-comparison = 311
-comp_op = 312
-star_expr = 313
-expr = 314
-xor_expr = 315
-and_expr = 316
-shift_expr = 317
-arith_expr = 318
-term = 319
-factor = 320
-power = 321
-atom_expr = 322
-atom = 323
-testlist_comp = 324
-trailer = 325
-subscriptlist = 326
-subscript = 327
-sliceop = 328
-exprlist = 329
-testlist = 330
-dictorsetmaker = 331
-classdef = 332
-arglist = 333
-argument = 334
-comp_iter = 335
-comp_for = 336
-comp_if = 337
-encoding_decl = 338
-yield_expr = 339
-yield_arg = 340
+annassign = 273
+testlist_star_expr = 274
+augassign = 275
+del_stmt = 276
+pass_stmt = 277
+flow_stmt = 278
+break_stmt = 279
+continue_stmt = 280
+return_stmt = 281
+yield_stmt = 282
+raise_stmt = 283
+import_stmt = 284
+import_name = 285
+import_from = 286
+import_as_name = 287
+dotted_as_name = 288
+import_as_names = 289
+dotted_as_names = 290
+dotted_name = 291
+global_stmt = 292
+nonlocal_stmt = 293
+assert_stmt = 294
+compound_stmt = 295
+async_stmt = 296
+if_stmt = 297
+while_stmt = 298
+for_stmt = 299
+try_stmt = 300
+with_stmt = 301
+with_item = 302
+except_clause = 303
+suite = 304
+test = 305
+test_nocond = 306
+lambdef = 307
+lambdef_nocond = 308
+or_test = 309
+and_test = 310
+not_test = 311
+comparison = 312
+comp_op = 313
+star_expr = 314
+expr = 315
+xor_expr = 316
+and_expr = 317
+shift_expr = 318
+arith_expr = 319
+term = 320
+factor = 321
+power = 322
+atom_expr = 323
+atom = 324
+testlist_comp = 325
+trailer = 326
+subscriptlist = 327
+subscript = 328
+sliceop = 329
+exprlist = 330
+testlist = 331
+dictorsetmaker = 332
+classdef = 333
+arglist = 334
+argument = 335
+comp_iter = 336
+comp_for = 337
+comp_if = 338
+encoding_decl = 339
+yield_expr = 340
+yield_arg = 341
#--end constants--
sym_name = {}
diff --git a/Lib/symtable.py b/Lib/symtable.py
index 84fec4a..b0e5260 100644
--- a/Lib/symtable.py
+++ b/Lib/symtable.py
@@ -2,7 +2,7 @@
import _symtable
from _symtable import (USE, DEF_GLOBAL, DEF_LOCAL, DEF_PARAM,
- DEF_IMPORT, DEF_BOUND, SCOPE_OFF, SCOPE_MASK, FREE,
+ DEF_IMPORT, DEF_BOUND, DEF_ANNOT, SCOPE_OFF, SCOPE_MASK, FREE,
LOCAL, GLOBAL_IMPLICIT, GLOBAL_EXPLICIT, CELL)
import weakref
@@ -190,6 +190,9 @@ class Symbol(object):
def is_local(self):
return bool(self.__flags & DEF_BOUND)
+ def is_annotated(self):
+ return bool(self.__flags & DEF_ANNOT)
+
def is_free(self):
return bool(self.__scope == FREE)
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index 9c34be0..9314e71 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -86,8 +86,8 @@ _SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
# FIXME don't rely on sys.version here, its format is an implementation detail
# of CPython, use sys.version_info or sys.hexversion
_PY_VERSION = sys.version.split()[0]
-_PY_VERSION_SHORT = sys.version[:3]
-_PY_VERSION_SHORT_NO_DOT = _PY_VERSION[0] + _PY_VERSION[2]
+_PY_VERSION_SHORT = '%d.%d' % sys.version_info[:2]
+_PY_VERSION_SHORT_NO_DOT = '%d%d' % sys.version_info[:2]
_PREFIX = os.path.normpath(sys.prefix)
_BASE_PREFIX = os.path.normpath(sys.base_prefix)
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
@@ -215,7 +215,7 @@ def _parse_makefile(filename, vars=None):
# Regexes needed for parsing Makefile (and similar syntaxes,
# like old-style Setup files).
import re
- _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
+ _variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
@@ -337,8 +337,20 @@ def get_makefile_filename():
config_dir_name = 'config-%s%s' % (_PY_VERSION_SHORT, sys.abiflags)
else:
config_dir_name = 'config'
+ if hasattr(sys.implementation, '_multiarch'):
+ config_dir_name += '-%s' % sys.implementation._multiarch
return os.path.join(get_path('stdlib'), config_dir_name, 'Makefile')
+
+def _get_sysconfigdata_name():
+ return os.environ.get('_PYTHON_SYSCONFIGDATA_NAME',
+ '_sysconfigdata_{abi}_{platform}_{multiarch}'.format(
+ abi=sys.abiflags,
+ platform=sys.platform,
+ multiarch=getattr(sys.implementation, '_multiarch', ''),
+ ))
+
+
def _generate_posix_vars():
"""Generate the Python module containing build-time variables."""
import pprint
@@ -379,14 +391,14 @@ def _generate_posix_vars():
# _sysconfigdata module manually and populate it with the build vars.
# This is more than sufficient for ensuring the subsequent call to
# get_platform() succeeds.
- name = '_sysconfigdata'
+ name = _get_sysconfigdata_name()
if 'darwin' in sys.platform:
import types
module = types.ModuleType(name)
module.build_time_vars = vars
sys.modules[name] = module
- pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
+ pybuilddir = 'build/lib.%s-%s' % (get_platform(), _PY_VERSION_SHORT)
if hasattr(sys, "gettotalrefcount"):
pybuilddir += '-pydebug'
os.makedirs(pybuilddir, exist_ok=True)
@@ -405,7 +417,9 @@ def _generate_posix_vars():
def _init_posix(vars):
"""Initialize the module as appropriate for POSIX systems."""
# _sysconfigdata is generated at build time, see _generate_posix_vars()
- from _sysconfigdata import build_time_vars
+ name = _get_sysconfigdata_name()
+ _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
+ build_time_vars = _temp.build_time_vars
vars.update(build_time_vars)
def _init_non_posix(vars):
@@ -518,7 +532,7 @@ def get_config_vars(*args):
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
_CONFIG_VARS['py_version'] = _PY_VERSION
_CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
- _CONFIG_VARS['py_version_nodot'] = _PY_VERSION[0] + _PY_VERSION[2]
+ _CONFIG_VARS['py_version_nodot'] = _PY_VERSION_SHORT_NO_DOT
_CONFIG_VARS['installed_base'] = _BASE_PREFIX
_CONFIG_VARS['base'] = _PREFIX
_CONFIG_VARS['installed_platbase'] = _BASE_EXEC_PREFIX
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 721f9d7..a62ab82 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -64,7 +64,10 @@ except NameError:
pass
# from tarfile import *
-__all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
+__all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError", "ReadError",
+ "CompressionError", "StreamError", "ExtractError", "HeaderError",
+ "ENCODING", "USTAR_FORMAT", "GNU_FORMAT", "PAX_FORMAT",
+ "DEFAULT_FORMAT", "open"]
#---------------------------------------------------------
# tar constants
@@ -141,7 +144,7 @@ PAX_NUMBER_FIELDS = {
#---------------------------------------------------------
# initialization
#---------------------------------------------------------
-if os.name in ("nt", "ce"):
+if os.name == "nt":
ENCODING = "utf-8"
else:
ENCODING = sys.getfilesystemencoding()
@@ -225,21 +228,21 @@ def calc_chksums(buf):
signed_chksum = 256 + sum(struct.unpack_from("148b8x356b", buf))
return unsigned_chksum, signed_chksum
-def copyfileobj(src, dst, length=None, exception=OSError):
+def copyfileobj(src, dst, length=None, exception=OSError, bufsize=None):
"""Copy length bytes from fileobj src to fileobj dst.
If length is None, copy the entire content.
"""
+ bufsize = bufsize or 16 * 1024
if length == 0:
return
if length is None:
- shutil.copyfileobj(src, dst)
+ shutil.copyfileobj(src, dst, bufsize)
return
- BUFSIZE = 16 * 1024
- blocks, remainder = divmod(length, BUFSIZE)
+ blocks, remainder = divmod(length, bufsize)
for b in range(blocks):
- buf = src.read(BUFSIZE)
- if len(buf) < BUFSIZE:
+ buf = src.read(bufsize)
+ if len(buf) < bufsize:
raise exception("unexpected end of data")
dst.write(buf)
@@ -1400,7 +1403,8 @@ class TarFile(object):
def __init__(self, name=None, mode="r", fileobj=None, format=None,
tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
- errors="surrogateescape", pax_headers=None, debug=None, errorlevel=None):
+ errors="surrogateescape", pax_headers=None, debug=None,
+ errorlevel=None, copybufsize=None):
"""Open an (uncompressed) tar archive `name'. `mode' is either 'r' to
read from an existing archive, 'a' to append data to an existing
file or 'w' to create a new file overwriting an existing one. `mode'
@@ -1456,6 +1460,7 @@ class TarFile(object):
self.errorlevel = errorlevel
# Init datastructures.
+ self.copybufsize = copybufsize
self.closed = False
self.members = [] # list of members as TarInfo objects
self._loaded = False # flag if all members have been read
@@ -1555,7 +1560,7 @@ class TarFile(object):
saved_pos = fileobj.tell()
try:
return func(name, "r", fileobj, **kwargs)
- except (ReadError, CompressionError) as e:
+ except (ReadError, CompressionError):
if fileobj is not None:
fileobj.seek(saved_pos)
continue
@@ -1960,10 +1965,10 @@ class TarFile(object):
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
self.fileobj.write(buf)
self.offset += len(buf)
-
+ bufsize=self.copybufsize
# If there's data to follow, append it.
if fileobj is not None:
- copyfileobj(fileobj, self.fileobj, tarinfo.size)
+ copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize)
blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
if remainder > 0:
self.fileobj.write(NUL * (BLOCKSIZE - remainder))
@@ -2145,15 +2150,16 @@ class TarFile(object):
"""
source = self.fileobj
source.seek(tarinfo.offset_data)
+ bufsize = self.copybufsize
with bltn_open(targetpath, "wb") as target:
if tarinfo.sparse is not None:
for offset, size in tarinfo.sparse:
target.seek(offset)
- copyfileobj(source, target, size, ReadError)
+ copyfileobj(source, target, size, ReadError, bufsize)
target.seek(tarinfo.size)
target.truncate()
else:
- copyfileobj(source, target, tarinfo.size, ReadError)
+ copyfileobj(source, target, tarinfo.size, ReadError, bufsize)
def makeunknown(self, tarinfo, targetpath):
"""Make a file from a TarInfo object with an unknown type
@@ -2232,7 +2238,7 @@ class TarFile(object):
os.lchown(targetpath, u, g)
else:
os.chown(targetpath, u, g)
- except OSError as e:
+ except OSError:
raise ExtractError("could not change owner")
def chmod(self, tarinfo, targetpath):
@@ -2241,7 +2247,7 @@ class TarFile(object):
if hasattr(os, 'chmod'):
try:
os.chmod(targetpath, tarinfo.mode)
- except OSError as e:
+ except OSError:
raise ExtractError("could not change mode")
def utime(self, tarinfo, targetpath):
@@ -2251,7 +2257,7 @@ class TarFile(object):
return
try:
os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
- except OSError as e:
+ except OSError:
raise ExtractError("could not change modification time")
#--------------------------------------------------------------------------
@@ -2374,9 +2380,32 @@ class TarFile(object):
"""Provide an iterator object.
"""
if self._loaded:
- return iter(self.members)
- else:
- return TarIter(self)
+ yield from self.members
+ return
+
+ # Yield items using TarFile's next() method.
+ # When all members have been read, set TarFile as _loaded.
+ index = 0
+ # Fix for SF #1100429: Under rare circumstances it can
+ # happen that getmembers() is called during iteration,
+ # which will have already exhausted the next() method.
+ if self.firstmember is not None:
+ tarinfo = self.next()
+ index += 1
+ yield tarinfo
+
+ while True:
+ if index < len(self.members):
+ tarinfo = self.members[index]
+ elif not self._loaded:
+ tarinfo = self.next()
+ if not tarinfo:
+ self._loaded = True
+ return
+ else:
+ return
+ index += 1
+ yield tarinfo
def _dbg(self, level, msg):
"""Write debugging output to sys.stderr.
@@ -2397,45 +2426,6 @@ class TarFile(object):
if not self._extfileobj:
self.fileobj.close()
self.closed = True
-# class TarFile
-
-class TarIter:
- """Iterator Class.
-
- for tarinfo in TarFile(...):
- suite...
- """
-
- def __init__(self, tarfile):
- """Construct a TarIter object.
- """
- self.tarfile = tarfile
- self.index = 0
- def __iter__(self):
- """Return iterator object.
- """
- return self
- def __next__(self):
- """Return the next item using TarFile's next() method.
- When all members have been read, set TarFile as _loaded.
- """
- # Fix for SF #1100429: Under rare circumstances it can
- # happen that getmembers() is called during iteration,
- # which will cause TarIter to stop prematurely.
-
- if self.index == 0 and self.tarfile.firstmember is not None:
- tarinfo = self.tarfile.next()
- elif self.index < len(self.tarfile.members):
- tarinfo = self.tarfile.members[self.index]
- elif not self.tarfile._loaded:
- tarinfo = self.tarfile.next()
- if not tarinfo:
- self.tarfile._loaded = True
- raise StopIteration
- else:
- raise StopIteration
- self.index += 1
- return tarinfo
#--------------------
# exported functions
diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py
index 72dabc7..b0863b1 100644
--- a/Lib/telnetlib.py
+++ b/Lib/telnetlib.py
@@ -637,6 +637,12 @@ class Telnet:
raise EOFError
return (-1, None, text)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ self.close()
+
def test():
"""Test program for telnetlib.
@@ -660,11 +666,10 @@ def test():
port = int(portstr)
except ValueError:
port = socket.getservbyname(portstr, 'tcp')
- tn = Telnet()
- tn.set_debuglevel(debuglevel)
- tn.open(host, port, timeout=0.5)
- tn.interact()
- tn.close()
+ with Telnet() as tn:
+ tn.set_debuglevel(debuglevel)
+ tn.open(host, port, timeout=0.5)
+ tn.interact()
if __name__ == '__main__':
test()
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index ad687b9..6146235 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -797,7 +797,6 @@ class TemporaryDirectory(object):
_shutil.rmtree(name)
_warnings.warn(warn_message, ResourceWarning)
-
def __repr__(self):
return "<{} {!r}>".format(self.__class__.__name__, self.name)
diff --git a/Lib/test/__main__.py b/Lib/test/__main__.py
index d5fbe15..19a6b2b 100644
--- a/Lib/test/__main__.py
+++ b/Lib/test/__main__.py
@@ -1,3 +1,2 @@
-from test import regrtest
-
-regrtest.main_in_temp_cwd()
+from test.libregrtest import main
+main()
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 2becfaa..c00846c 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -1628,13 +1628,33 @@ class _TestContainers(BaseTestCase):
d = [a, b]
e = self.list(d)
self.assertEqual(
- e[:],
+ [element[:] for element in e],
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]]
)
f = self.list([a])
a.append('hello')
- self.assertEqual(f[:], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello']])
+ self.assertEqual(f[0][:], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello'])
+
+ def test_list_proxy_in_list(self):
+ a = self.list([self.list(range(3)) for _i in range(3)])
+ self.assertEqual([inner[:] for inner in a], [[0, 1, 2]] * 3)
+
+ a[0][-1] = 55
+ self.assertEqual(a[0][:], [0, 1, 55])
+ for i in range(1, 3):
+ self.assertEqual(a[i][:], [0, 1, 2])
+
+ self.assertEqual(a[1].pop(), 2)
+ self.assertEqual(len(a[1]), 2)
+ for i in range(0, 3, 2):
+ self.assertEqual(len(a[i]), 3)
+
+ del a
+
+ b = self.list()
+ b.append(b)
+ del b
def test_dict(self):
d = self.dict()
@@ -1646,6 +1666,52 @@ class _TestContainers(BaseTestCase):
self.assertEqual(sorted(d.values()), [chr(i) for i in indices])
self.assertEqual(sorted(d.items()), [(i, chr(i)) for i in indices])
+ def test_dict_proxy_nested(self):
+ pets = self.dict(ferrets=2, hamsters=4)
+ supplies = self.dict(water=10, feed=3)
+ d = self.dict(pets=pets, supplies=supplies)
+
+ self.assertEqual(supplies['water'], 10)
+ self.assertEqual(d['supplies']['water'], 10)
+
+ d['supplies']['blankets'] = 5
+ self.assertEqual(supplies['blankets'], 5)
+ self.assertEqual(d['supplies']['blankets'], 5)
+
+ d['supplies']['water'] = 7
+ self.assertEqual(supplies['water'], 7)
+ self.assertEqual(d['supplies']['water'], 7)
+
+ del pets
+ del supplies
+ self.assertEqual(d['pets']['ferrets'], 2)
+ d['supplies']['blankets'] = 11
+ self.assertEqual(d['supplies']['blankets'], 11)
+
+ pets = d['pets']
+ supplies = d['supplies']
+ supplies['water'] = 7
+ self.assertEqual(supplies['water'], 7)
+ self.assertEqual(d['supplies']['water'], 7)
+
+ d.clear()
+ self.assertEqual(len(d), 0)
+ self.assertEqual(supplies['water'], 7)
+ self.assertEqual(pets['hamsters'], 4)
+
+ l = self.list([pets, supplies])
+ l[0]['marmots'] = 1
+ self.assertEqual(pets['marmots'], 1)
+ self.assertEqual(l[0]['marmots'], 1)
+
+ del pets
+ del supplies
+ self.assertEqual(l[0]['marmots'], 1)
+
+ outer = self.list([[88, 99], l])
+ self.assertIsInstance(outer[0], list) # Not a ListProxy
+ self.assertEqual(outer[-1][-1]['feed'], 3)
+
def test_namespace(self):
n = self.Namespace()
n.name = 'Bob'
@@ -1668,6 +1734,10 @@ def sqr(x, wait=0.0):
def mul(x, y):
return x*y
+def raise_large_valuerror(wait):
+ time.sleep(wait)
+ raise ValueError("x" * 1024**2)
+
class SayWhenError(ValueError): pass
def exception_throwing_generator(total, when):
@@ -1910,6 +1980,26 @@ class _TestPool(BaseTestCase):
with self.assertRaises(RuntimeError):
p.apply(self._test_wrapped_exception)
+ def test_map_no_failfast(self):
+ # Issue #23992: the fail-fast behaviour when an exception is raised
+ # during map() would make Pool.join() deadlock, because a worker
+ # process would fill the result queue (after the result handler thread
+ # terminated, hence not draining it anymore).
+
+ t_start = time.time()
+
+ with self.assertRaises(ValueError):
+ with self.Pool(2) as p:
+ try:
+ p.map(raise_large_valuerror, [0, 1])
+ finally:
+ time.sleep(0.5)
+ p.close()
+ p.join()
+
+ # check that we indeed waited for all jobs
+ self.assertGreater(time.time() - t_start, 0.9)
+
def raising():
raise KeyError("key")
@@ -3767,7 +3857,7 @@ class TestSemaphoreTracker(unittest.TestCase):
p.stderr.close()
expected = 'semaphore_tracker: There appear to be 2 leaked semaphores'
self.assertRegex(err, expected)
- self.assertRegex(err, 'semaphore_tracker: %r: \[Errno' % name1)
+ self.assertRegex(err, r'semaphore_tracker: %r: \[Errno' % name1)
#
# Mixins
diff --git a/Lib/test/ann_module.py b/Lib/test/ann_module.py
new file mode 100644
index 0000000..9e6b87d
--- /dev/null
+++ b/Lib/test/ann_module.py
@@ -0,0 +1,53 @@
+
+
+"""
+The module for testing variable annotations.
+Empty lines above are for good reason (testing for correct line numbers)
+"""
+
+from typing import Optional
+
+__annotations__[1] = 2
+
+class C:
+
+ x = 5; y: Optional['C'] = None
+
+from typing import Tuple
+x: int = 5; y: str = x; f: Tuple[int, int]
+
+class M(type):
+
+ __annotations__['123'] = 123
+ o: type = object
+
+(pars): bool = True
+
+class D(C):
+ j: str = 'hi'; k: str= 'bye'
+
+from types import new_class
+h_class = new_class('H', (C,))
+j_class = new_class('J')
+
+class F():
+ z: int = 5
+ def __init__(self, x):
+ pass
+
+class Y(F):
+ def __init__(self):
+ super(F, self).__init__(123)
+
+class Meta(type):
+ def __new__(meta, name, bases, namespace):
+ return super().__new__(meta, name, bases, namespace)
+
+class S(metaclass = Meta):
+ x: str = 'something'
+ y: str = 'something else'
+
+def foo(x: int = 10):
+ def bar(y: List[str]):
+ x: str = 'yes'
+ bar()
diff --git a/Lib/test/ann_module2.py b/Lib/test/ann_module2.py
new file mode 100644
index 0000000..76cf5b3
--- /dev/null
+++ b/Lib/test/ann_module2.py
@@ -0,0 +1,36 @@
+"""
+Some correct syntax for variable annotation here.
+More examples are in test_grammar and test_parser.
+"""
+
+from typing import no_type_check, ClassVar
+
+i: int = 1
+j: int
+x: float = i/10
+
+def f():
+ class C: ...
+ return C()
+
+f().new_attr: object = object()
+
+class C:
+ def __init__(self, x: int) -> None:
+ self.x = x
+
+c = C(5)
+c.new_attr: int = 10
+
+__annotations__ = {}
+
+
+@no_type_check
+class NTC:
+ def meth(self, param: complex) -> None:
+ ...
+
+class CV:
+ var: ClassVar['CV']
+
+CV.var = CV()
diff --git a/Lib/test/ann_module3.py b/Lib/test/ann_module3.py
new file mode 100644
index 0000000..eccd7be
--- /dev/null
+++ b/Lib/test/ann_module3.py
@@ -0,0 +1,18 @@
+"""
+Correct syntax for variable annotation that should fail at runtime
+in a certain manner. More examples are in test_grammar and test_parser.
+"""
+
+def f_bad_ann():
+ __annotations__[1] = 2
+
+class C_OK:
+ def __init__(self, x: int) -> None:
+ self.x: no_such_name = x # This one is OK as proposed by Guido
+
+class D_bad_ann:
+ def __init__(self, x: int) -> None:
+ sfel.y: int = 0
+
+def g_bad_ann():
+ no_such_name.attr: int = 0
diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py
index 0ae2242..d3e8e9e 100644
--- a/Lib/test/audiotests.py
+++ b/Lib/test/audiotests.py
@@ -1,9 +1,8 @@
from test.support import findfile, TESTFN, unlink
-import unittest
import array
import io
import pickle
-import sys
+
class UnseekableIO(io.FileIO):
def tell(self):
diff --git a/Lib/test/autotest.py b/Lib/test/autotest.py
index 41c2088..fa85cc1 100644
--- a/Lib/test/autotest.py
+++ b/Lib/test/autotest.py
@@ -1,6 +1,5 @@
# This should be equivalent to running regrtest.py from the cmdline.
# It can be especially handy if you're in an interactive shell, e.g.,
# from test import autotest.
-
-from test import regrtest
-regrtest.main()
+from test.libregrtest import main
+main()
diff --git a/Lib/test/badsyntax_async1.py b/Lib/test/badsyntax_async1.py
deleted file mode 100644
index fb85e29..0000000
--- a/Lib/test/badsyntax_async1.py
+++ /dev/null
@@ -1,2 +0,0 @@
-async def foo(a=await something()):
- pass
diff --git a/Lib/test/badsyntax_async2.py b/Lib/test/badsyntax_async2.py
deleted file mode 100644
index fb85e29..0000000
--- a/Lib/test/badsyntax_async2.py
+++ /dev/null
@@ -1,2 +0,0 @@
-async def foo(a=await something()):
- pass
diff --git a/Lib/test/badsyntax_async3.py b/Lib/test/badsyntax_async3.py
deleted file mode 100644
index dde1bc5..0000000
--- a/Lib/test/badsyntax_async3.py
+++ /dev/null
@@ -1,2 +0,0 @@
-async def foo():
- [i async for i in els]
diff --git a/Lib/test/badsyntax_async4.py b/Lib/test/badsyntax_async4.py
deleted file mode 100644
index d033b28..0000000
--- a/Lib/test/badsyntax_async4.py
+++ /dev/null
@@ -1,2 +0,0 @@
-async def foo():
- await
diff --git a/Lib/test/badsyntax_async5.py b/Lib/test/badsyntax_async5.py
deleted file mode 100644
index 9d19af6..0000000
--- a/Lib/test/badsyntax_async5.py
+++ /dev/null
@@ -1,2 +0,0 @@
-def foo():
- await something()
diff --git a/Lib/test/badsyntax_async6.py b/Lib/test/badsyntax_async6.py
deleted file mode 100644
index cb0a23d..0000000
--- a/Lib/test/badsyntax_async6.py
+++ /dev/null
@@ -1,2 +0,0 @@
-async def foo():
- yield
diff --git a/Lib/test/badsyntax_async7.py b/Lib/test/badsyntax_async7.py
deleted file mode 100644
index 51e4bf9..0000000
--- a/Lib/test/badsyntax_async7.py
+++ /dev/null
@@ -1,2 +0,0 @@
-async def foo():
- yield from []
diff --git a/Lib/test/badsyntax_async8.py b/Lib/test/badsyntax_async8.py
deleted file mode 100644
index 3c636f9..0000000
--- a/Lib/test/badsyntax_async8.py
+++ /dev/null
@@ -1,2 +0,0 @@
-async def foo():
- await await fut
diff --git a/Lib/test/capath/0e4015b9.0 b/Lib/test/capath/0e4015b9.0
deleted file mode 100644
index b6d259b..0000000
--- a/Lib/test/capath/0e4015b9.0
+++ /dev/null
@@ -1,16 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIClTCCAf6gAwIBAgIJAKGU95wKR8pTMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV
-BAYTAlhZMRcwFQYDVQQHDA5DYXN0bGUgQW50aHJheDEjMCEGA1UECgwaUHl0aG9u
-IFNvZnR3YXJlIEZvdW5kYXRpb24xIzAhBgNVBAMMGnNlbGYtc2lnbmVkLnB5dGhv
-bnRlc3QubmV0MB4XDTE0MTEwMjE4MDkyOVoXDTI0MTAzMDE4MDkyOVowcDELMAkG
-A1UEBhMCWFkxFzAVBgNVBAcMDkNhc3RsZSBBbnRocmF4MSMwIQYDVQQKDBpQeXRo
-b24gU29mdHdhcmUgRm91bmRhdGlvbjEjMCEGA1UEAwwac2VsZi1zaWduZWQucHl0
-aG9udGVzdC5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANDXQXW9tjyZ
-Xt0Iv2tLL1+jinr4wGg36ioLDLFkMf+2Y1GL0v0BnKYG4N1OKlAU15LXGeGer8vm
-Sv/yIvmdrELvhAbbo3w4a9TMYQA4XkIVLdvu3mvNOAet+8PMJxn26dbDhG809ALv
-EHY57lQsBS3G59RZyBPVqAqmImWNJnVzAgMBAAGjNzA1MCUGA1UdEQQeMByCGnNl
-bGYtc2lnbmVkLnB5dGhvbnRlc3QubmV0MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcN
-AQEFBQADgYEAIuzAhgMouJpNdf3URCHIineyoSt6WK/9+eyUcjlKOrDoXNZaD72h
-TXMeKYoWvJyVcSLKL8ckPtDobgP2OTt0UkyAaj0n+ZHaqq1lH2yVfGUA1ILJv515
-C8BqbvVZuqm3i7ygmw3bqE/lYMgOrYtXXnqOrz6nvsE6Yc9V9rFflOM=
------END CERTIFICATE-----
diff --git a/Lib/test/capath/b1930218.0 b/Lib/test/capath/b1930218.0
new file mode 100644
index 0000000..373349c
--- /dev/null
+++ b/Lib/test/capath/b1930218.0
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDbTCCAlWgAwIBAgIJALCSZLHy2iHQMA0GCSqGSIb3DQEBBQUAME0xCzAJBgNV
+BAYTAlhZMSYwJAYDVQQKDB1QeXRob24gU29mdHdhcmUgRm91bmRhdGlvbiBDQTEW
+MBQGA1UEAwwNb3VyLWNhLXNlcnZlcjAeFw0xMzAxMDQxOTQ3MDdaFw0yMzAxMDIx
+OTQ3MDdaME0xCzAJBgNVBAYTAlhZMSYwJAYDVQQKDB1QeXRob24gU29mdHdhcmUg
+Rm91bmRhdGlvbiBDQTEWMBQGA1UEAwwNb3VyLWNhLXNlcnZlcjCCASIwDQYJKoZI
+hvcNAQEBBQADggEPADCCAQoCggEBAOfe6eMMnwC2of0rW5bSb8zgvoa5IF7sA3pV
+q+qk6flJhdJm1e3HeupWji2P50LiYiipn9Ybjuu1tJyfFKvf5pSLdh0+bSRh7Qy/
+AIphDN9cyDZzFgDNR7ptpKR0iIMjChn8Cac8SkvT5x0t5OpMVCHzJtuJNxjUArtA
+Ml+k/y0c99S77I7PXIKs5nwIbEiFYQd/JeBc4Lw0X+C5BEd1yEcLjbzWyGhfM4Ni
+0iBENbGtgRqKzbw1sFyLR9YY6ZwYl8wBPCnM6B7k5MG43ufCERiHWpM02KYl9xRx
+6+QhotIPLi7UYgA109bvXGBLTKkU4t0VWEY3Mya35y5d7ULkxU0CAwEAAaNQME4w
+HQYDVR0OBBYEFLzdYtl22hvSVGvP4GabHh57VgwLMB8GA1UdIwQYMBaAFLzdYtl2
+2hvSVGvP4GabHh57VgwLMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEB
+AH0K9cuN0129mY74Kw+668LZpidPLnsvDmTYHDVQTu78kLmNbajFxgawr/Mtvzu4
+QgfdGH1tlVRXhRhgRy/reBv56Bf9Wg2HFyisTGrmvCn09FVwKULeheqrbCMGZDB1
+Ao5TvF4BMzfMHs24pP3K5F9lO4MchvFVAqA6j9uRt0AUtOeN0u5zuuPlNC28lG9O
+JAb3X4sOp45r3l519DKaULFEM5rQBeJ4gv/b2opj66nd0b+gYa3jnookXWIO50yR
+f+/fNDY7L131hLIvxG2TlhpvMCjx2hKaZLRAMx293itTqOq+1rxOlvVE+zIYrtUf
+9mmvtk57HVjsO6lTo15YyJ4=
+-----END CERTIFICATE-----
diff --git a/Lib/test/capath/ce7b8643.0 b/Lib/test/capath/ce7b8643.0
deleted file mode 100644
index b6d259b..0000000
--- a/Lib/test/capath/ce7b8643.0
+++ /dev/null
@@ -1,16 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIClTCCAf6gAwIBAgIJAKGU95wKR8pTMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV
-BAYTAlhZMRcwFQYDVQQHDA5DYXN0bGUgQW50aHJheDEjMCEGA1UECgwaUHl0aG9u
-IFNvZnR3YXJlIEZvdW5kYXRpb24xIzAhBgNVBAMMGnNlbGYtc2lnbmVkLnB5dGhv
-bnRlc3QubmV0MB4XDTE0MTEwMjE4MDkyOVoXDTI0MTAzMDE4MDkyOVowcDELMAkG
-A1UEBhMCWFkxFzAVBgNVBAcMDkNhc3RsZSBBbnRocmF4MSMwIQYDVQQKDBpQeXRo
-b24gU29mdHdhcmUgRm91bmRhdGlvbjEjMCEGA1UEAwwac2VsZi1zaWduZWQucHl0
-aG9udGVzdC5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANDXQXW9tjyZ
-Xt0Iv2tLL1+jinr4wGg36ioLDLFkMf+2Y1GL0v0BnKYG4N1OKlAU15LXGeGer8vm
-Sv/yIvmdrELvhAbbo3w4a9TMYQA4XkIVLdvu3mvNOAet+8PMJxn26dbDhG809ALv
-EHY57lQsBS3G59RZyBPVqAqmImWNJnVzAgMBAAGjNzA1MCUGA1UdEQQeMByCGnNl
-bGYtc2lnbmVkLnB5dGhvbnRlc3QubmV0MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcN
-AQEFBQADgYEAIuzAhgMouJpNdf3URCHIineyoSt6WK/9+eyUcjlKOrDoXNZaD72h
-TXMeKYoWvJyVcSLKL8ckPtDobgP2OTt0UkyAaj0n+ZHaqq1lH2yVfGUA1ILJv515
-C8BqbvVZuqm3i7ygmw3bqE/lYMgOrYtXXnqOrz6nvsE6Yc9V9rFflOM=
------END CERTIFICATE-----
diff --git a/Lib/test/capath/ceff1710.0 b/Lib/test/capath/ceff1710.0
new file mode 100644
index 0000000..373349c
--- /dev/null
+++ b/Lib/test/capath/ceff1710.0
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDbTCCAlWgAwIBAgIJALCSZLHy2iHQMA0GCSqGSIb3DQEBBQUAME0xCzAJBgNV
+BAYTAlhZMSYwJAYDVQQKDB1QeXRob24gU29mdHdhcmUgRm91bmRhdGlvbiBDQTEW
+MBQGA1UEAwwNb3VyLWNhLXNlcnZlcjAeFw0xMzAxMDQxOTQ3MDdaFw0yMzAxMDIx
+OTQ3MDdaME0xCzAJBgNVBAYTAlhZMSYwJAYDVQQKDB1QeXRob24gU29mdHdhcmUg
+Rm91bmRhdGlvbiBDQTEWMBQGA1UEAwwNb3VyLWNhLXNlcnZlcjCCASIwDQYJKoZI
+hvcNAQEBBQADggEPADCCAQoCggEBAOfe6eMMnwC2of0rW5bSb8zgvoa5IF7sA3pV
+q+qk6flJhdJm1e3HeupWji2P50LiYiipn9Ybjuu1tJyfFKvf5pSLdh0+bSRh7Qy/
+AIphDN9cyDZzFgDNR7ptpKR0iIMjChn8Cac8SkvT5x0t5OpMVCHzJtuJNxjUArtA
+Ml+k/y0c99S77I7PXIKs5nwIbEiFYQd/JeBc4Lw0X+C5BEd1yEcLjbzWyGhfM4Ni
+0iBENbGtgRqKzbw1sFyLR9YY6ZwYl8wBPCnM6B7k5MG43ufCERiHWpM02KYl9xRx
+6+QhotIPLi7UYgA109bvXGBLTKkU4t0VWEY3Mya35y5d7ULkxU0CAwEAAaNQME4w
+HQYDVR0OBBYEFLzdYtl22hvSVGvP4GabHh57VgwLMB8GA1UdIwQYMBaAFLzdYtl2
+2hvSVGvP4GabHh57VgwLMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEB
+AH0K9cuN0129mY74Kw+668LZpidPLnsvDmTYHDVQTu78kLmNbajFxgawr/Mtvzu4
+QgfdGH1tlVRXhRhgRy/reBv56Bf9Wg2HFyisTGrmvCn09FVwKULeheqrbCMGZDB1
+Ao5TvF4BMzfMHs24pP3K5F9lO4MchvFVAqA6j9uRt0AUtOeN0u5zuuPlNC28lG9O
+JAb3X4sOp45r3l519DKaULFEM5rQBeJ4gv/b2opj66nd0b+gYa3jnookXWIO50yR
+f+/fNDY7L131hLIvxG2TlhpvMCjx2hKaZLRAMx293itTqOq+1rxOlvVE+zIYrtUf
+9mmvtk57HVjsO6lTo15YyJ4=
+-----END CERTIFICATE-----
diff --git a/Lib/test/cmath_testcases.txt b/Lib/test/cmath_testcases.txt
index 9b08653..dd7e458 100644
--- a/Lib/test/cmath_testcases.txt
+++ b/Lib/test/cmath_testcases.txt
@@ -53,6 +53,12 @@
-- MPFR homepage at http://www.mpfr.org for more information about the
-- MPFR project.
+-- A minority of the test cases were generated with the help of
+-- mpmath 0.19 at 100 bit accuracy (http://mpmath.org) to improve
+-- coverage of real functions with real-valued arguments. These are
+-- used in test.test_math.MathTests.test_testfile, as well as in
+-- test_cmath.
+
--------------------------
-- acos: Inverse cosine --
@@ -848,6 +854,18 @@ atan0302 atan 9.9999999999999999e-161 -1.0 -> 0.78539816339744828 -184.553381029
atan0303 atan -1e-165 1.0 -> -0.78539816339744828 190.30984376228875
atan0304 atan -9.9998886718268301e-321 -1.0 -> -0.78539816339744828 -368.76019403576692
+-- Additional real values (mpmath)
+atan0400 atan 1.7976931348623157e+308 0.0 -> 1.5707963267948966192 0.0
+atan0401 atan -1.7976931348623157e+308 0.0 -> -1.5707963267948966192 0.0
+atan0402 atan 1e-17 0.0 -> 1.0000000000000000715e-17 0.0
+atan0403 atan -1e-17 0.0 -> -1.0000000000000000715e-17 0.0
+atan0404 atan 0.0001 0.0 -> 0.000099999999666666673459 0.0
+atan0405 atan -0.0001 0.0 -> -0.000099999999666666673459 0.0
+atan0406 atan 0.999999999999999 0.0 -> 0.78539816339744781002 0.0
+atan0407 atan 1.000000000000001 0.0 -> 0.78539816339744886473 0.0
+atan0408 atan 14.101419947171719 0.0 -> 1.4999999999999999969 0.0
+atan0409 atan 1255.7655915007897 0.0 -> 1.5700000000000000622 0.0
+
-- special values
atan1000 atan -0.0 0.0 -> -0.0 0.0
atan1001 atan nan 0.0 -> nan 0.0
@@ -1514,6 +1532,11 @@ sqrt0131 sqrt -1.5477066694467245e-310 -0.0 -> 0.0 -1.2440685951533077e-155
sqrt0140 sqrt 1.6999999999999999e+308 -1.6999999999999999e+308 -> 1.4325088230154573e+154 -5.9336458271212207e+153
sqrt0141 sqrt -1.797e+308 -9.9999999999999999e+306 -> 3.7284476432057307e+152 -1.3410406899802901e+154
+-- Additional real values (mpmath)
+sqrt0150 sqrt 1.7976931348623157e+308 0.0 -> 1.3407807929942596355e+154 0.0
+sqrt0151 sqrt 2.2250738585072014e-308 0.0 -> 1.4916681462400413487e-154 0.0
+sqrt0152 sqrt 5e-324 0.0 -> 2.2227587494850774834e-162 0.0
+
-- special values
sqrt1000 sqrt 0.0 0.0 -> 0.0 0.0
sqrt1001 sqrt -0.0 0.0 -> 0.0 0.0
@@ -1616,6 +1639,20 @@ exp0052 exp 710.0 1.5 -> 1.5802653829857376e+307 inf overflow
exp0053 exp 710.0 1.6 -> -6.5231579995501372e+306 inf overflow
exp0054 exp 710.0 2.8 -> -inf 7.4836177417448528e+307 overflow
+-- Additional real values (mpmath)
+exp0070 exp 1e-08 0.0 -> 1.00000001000000005 0.0
+exp0071 exp 0.0003 0.0 -> 1.0003000450045003375 0.0
+exp0072 exp 0.2 0.0 -> 1.2214027581601698475 0.0
+exp0073 exp 1.0 0.0 -> 2.7182818284590452354 0.0
+exp0074 exp -1e-08 0.0 -> 0.99999999000000005 0.0
+exp0075 exp -0.0003 0.0 -> 0.99970004499550033751 0.0
+exp0076 exp -1.0 0.0 -> 0.3678794411714423216 0.0
+exp0077 exp 2.220446049250313e-16 0.0 -> 1.000000000000000222 0.0
+exp0078 exp -1.1102230246251565e-16 0.0 -> 0.99999999999999988898 0.0
+exp0079 exp 2.302585092994046 0.0 -> 10.000000000000002171 0.0
+exp0080 exp -2.302585092994046 0.0 -> 0.099999999999999978292 0.0
+exp0081 exp 709.7827 0.0 -> 1.7976699566638014654e+308 0.0
+
-- special values
exp1000 exp 0.0 0.0 -> 1.0 0.0
exp1001 exp -0.0 0.0 -> 1.0 0.0
@@ -1708,6 +1745,23 @@ cosh0023 cosh 2.218885944363501 2.0015727395883687 -> -1.94294321081968 4.129026
cosh0030 cosh 710.5 2.3519999999999999 -> -1.2967465239355998e+308 1.3076707908857333e+308
cosh0031 cosh -710.5 0.69999999999999996 -> 1.4085466381392499e+308 -1.1864024666450239e+308
+-- Additional real values (mpmath)
+cosh0050 cosh 1e-150 0.0 -> 1.0 0.0
+cosh0051 cosh 1e-18 0.0 -> 1.0 0.0
+cosh0052 cosh 1e-09 0.0 -> 1.0000000000000000005 0.0
+cosh0053 cosh 0.0003 0.0 -> 1.0000000450000003375 0.0
+cosh0054 cosh 0.2 0.0 -> 1.0200667556190758485 0.0
+cosh0055 cosh 1.0 0.0 -> 1.5430806348152437785 0.0
+cosh0056 cosh -1e-18 0.0 -> 1.0 -0.0
+cosh0057 cosh -0.0003 0.0 -> 1.0000000450000003375 -0.0
+cosh0058 cosh -1.0 0.0 -> 1.5430806348152437785 -0.0
+cosh0059 cosh 1.3169578969248168 0.0 -> 2.0000000000000001504 0.0
+cosh0060 cosh -1.3169578969248168 0.0 -> 2.0000000000000001504 -0.0
+cosh0061 cosh 17.328679513998633 0.0 -> 16777216.000000021938 0.0
+cosh0062 cosh 18.714973875118524 0.0 -> 67108864.000000043662 0.0
+cosh0063 cosh 709.7827 0.0 -> 8.9883497833190073272e+307 0.0
+cosh0064 cosh -709.7827 0.0 -> 8.9883497833190073272e+307 -0.0
+
-- special values
cosh1000 cosh 0.0 0.0 -> 1.0 0.0
cosh1001 cosh 0.0 inf -> nan 0.0 invalid ignore-imag-sign
@@ -1800,6 +1854,24 @@ sinh0023 sinh 0.043713693678420068 0.22512549887532657 -> 0.042624198673416713 0
sinh0030 sinh 710.5 -2.3999999999999999 -> -1.3579970564885919e+308 -1.24394470907798e+308
sinh0031 sinh -710.5 0.80000000000000004 -> -1.2830671601735164e+308 1.3210954193997678e+308
+-- Additional real values (mpmath)
+sinh0050 sinh 1e-100 0.0 -> 1.00000000000000002e-100 0.0
+sinh0051 sinh 5e-17 0.0 -> 4.9999999999999998955e-17 0.0
+sinh0052 sinh 1e-16 0.0 -> 9.999999999999999791e-17 0.0
+sinh0053 sinh 3.7e-08 0.0 -> 3.7000000000000008885e-8 0.0
+sinh0054 sinh 0.001 0.0 -> 0.0010000001666666750208 0.0
+sinh0055 sinh 0.2 0.0 -> 0.20133600254109399895 0.0
+sinh0056 sinh 1.0 0.0 -> 1.1752011936438014569 0.0
+sinh0057 sinh -3.7e-08 0.0 -> -3.7000000000000008885e-8 0.0
+sinh0058 sinh -0.001 0.0 -> -0.0010000001666666750208 0.0
+sinh0059 sinh -1.0 0.0 -> -1.1752011936438014569 0.0
+sinh0060 sinh 1.4436354751788103 0.0 -> 1.9999999999999999078 0.0
+sinh0061 sinh -1.4436354751788103 0.0 -> -1.9999999999999999078 0.0
+sinh0062 sinh 17.328679513998633 0.0 -> 16777215.999999992136 0.0
+sinh0063 sinh 18.714973875118524 0.0 -> 67108864.000000036211 0.0
+sinh0064 sinh 709.7827 0.0 -> 8.9883497833190073272e+307 0.0
+sinh0065 sinh -709.7827 0.0 -> -8.9883497833190073272e+307 0.0
+
-- special values
sinh1000 sinh 0.0 0.0 -> 0.0 0.0
sinh1001 sinh 0.0 inf -> 0.0 nan invalid ignore-real-sign
@@ -1897,6 +1969,24 @@ tanh0031 tanh -711 7.4000000000000004 -> -1.0 0.0
tanh0032 tanh 1000 -2.3199999999999998 -> 1.0 0.0
tanh0033 tanh -1.0000000000000001e+300 -9.6699999999999999 -> -1.0 -0.0
+-- Additional real values (mpmath)
+tanh0050 tanh 1e-100 0.0 -> 1.00000000000000002e-100 0.0
+tanh0051 tanh 5e-17 0.0 -> 4.9999999999999998955e-17 0.0
+tanh0052 tanh 1e-16 0.0 -> 9.999999999999999791e-17 0.0
+tanh0053 tanh 3.7e-08 0.0 -> 3.6999999999999983559e-8 0.0
+tanh0054 tanh 0.001 0.0 -> 0.00099999966666680002076 0.0
+tanh0055 tanh 0.2 0.0 -> 0.19737532022490401141 0.0
+tanh0056 tanh 1.0 0.0 -> 0.76159415595576488812 0.0
+tanh0057 tanh -3.7e-08 0.0 -> -3.6999999999999983559e-8 0.0
+tanh0058 tanh -0.001 0.0 -> -0.00099999966666680002076 0.0
+tanh0059 tanh -1.0 0.0 -> -0.76159415595576488812 0.0
+tanh0060 tanh 0.5493061443340549 0.0 -> 0.50000000000000003402 0.0
+tanh0061 tanh -0.5493061443340549 0.0 -> -0.50000000000000003402 0.0
+tanh0062 tanh 17.328679513998633 0.0 -> 0.99999999999999822364 0.0
+tanh0063 tanh 18.714973875118524 0.0 -> 0.99999999999999988898 0.0
+tanh0064 tanh 711 0.0 -> 1.0 0.0
+tanh0065 tanh 1.797e+308 0.0 -> 1.0 0.0
+
--special values
tanh1000 tanh 0.0 0.0 -> 0.0 0.0
tanh1001 tanh 0.0 inf -> nan nan invalid
@@ -1985,6 +2075,22 @@ cos0021 cos 4.8048375263775256 0.0062248852898515658 -> 0.092318702015846243 0.0
cos0022 cos 7.9914515433858515 0.71659966615501436 -> -0.17375439906936566 -0.77217043527294582
cos0023 cos 0.45124351152540226 1.6992693993812158 -> 2.543477948972237 -1.1528193694875477
+-- Additional real values (mpmath)
+cos0050 cos 1e-150 0.0 -> 1.0 -0.0
+cos0051 cos 1e-18 0.0 -> 1.0 -0.0
+cos0052 cos 1e-09 0.0 -> 0.9999999999999999995 -0.0
+cos0053 cos 0.0003 0.0 -> 0.9999999550000003375 -0.0
+cos0054 cos 0.2 0.0 -> 0.98006657784124162892 -0.0
+cos0055 cos 1.0 0.0 -> 0.5403023058681397174 -0.0
+cos0056 cos -1e-18 0.0 -> 1.0 0.0
+cos0057 cos -0.0003 0.0 -> 0.9999999550000003375 0.0
+cos0058 cos -1.0 0.0 -> 0.5403023058681397174 0.0
+cos0059 cos 1.0471975511965976 0.0 -> 0.50000000000000009945 -0.0
+cos0060 cos 2.5707963267948966 0.0 -> -0.84147098480789647357 -0.0
+cos0061 cos -2.5707963267948966 0.0 -> -0.84147098480789647357 0.0
+cos0062 cos 7.225663103256523 0.0 -> 0.58778525229247407559 -0.0
+cos0063 cos -8.79645943005142 0.0 -> -0.80901699437494722255 0.0
+
-- special values
cos1000 cos -0.0 0.0 -> 1.0 0.0
cos1001 cos -inf 0.0 -> nan 0.0 invalid ignore-imag-sign
@@ -2073,6 +2179,22 @@ sin0021 sin 1.4342727387492671 0.81361889790284347 -> 1.3370960060947923 0.12336
sin0022 sin 1.1518087354403725 4.8597235966150558 -> 58.919141989603041 26.237003403758852
sin0023 sin 0.00087773078406649192 34.792379211312095 -> 565548145569.38245 644329685822700.62
+-- Additional real values (mpmath)
+sin0050 sin 1e-100 0.0 -> 1.00000000000000002e-100 0.0
+sin0051 sin 3.7e-08 0.0 -> 3.6999999999999992001e-8 0.0
+sin0052 sin 0.001 0.0 -> 0.00099999983333334168748 0.0
+sin0053 sin 0.2 0.0 -> 0.19866933079506122634 0.0
+sin0054 sin 1.0 0.0 -> 0.84147098480789650665 0.0
+sin0055 sin -3.7e-08 0.0 -> -3.6999999999999992001e-8 0.0
+sin0056 sin -0.001 0.0 -> -0.00099999983333334168748 0.0
+sin0057 sin -1.0 0.0 -> -0.84147098480789650665 0.0
+sin0058 sin 0.5235987755982989 0.0 -> 0.50000000000000004642 0.0
+sin0059 sin -0.5235987755982989 0.0 -> -0.50000000000000004642 0.0
+sin0060 sin 2.6179938779914944 0.0 -> 0.49999999999999996018 -0.0
+sin0061 sin -2.6179938779914944 0.0 -> -0.49999999999999996018 -0.0
+sin0062 sin 7.225663103256523 0.0 -> 0.80901699437494673648 0.0
+sin0063 sin -8.79645943005142 0.0 -> -0.58778525229247340658 -0.0
+
-- special values
sin1000 sin -0.0 0.0 -> -0.0 0.0
sin1001 sin -inf 0.0 -> nan 0.0 invalid ignore-imag-sign
@@ -2161,6 +2283,25 @@ tan0021 tan 1.7809617968443272 1.5052381702853379 -> -0.044066222118946903 1.093
tan0022 tan 1.1615313900880577 1.7956298728647107 -> 0.041793186826390362 1.0375339546034792
tan0023 tan 0.067014779477908945 5.8517361577457097 -> 2.2088639754800034e-06 0.9999836182420061
+-- Additional real values (mpmath)
+tan0050 tan 1e-100 0.0 -> 1.00000000000000002e-100 0.0
+tan0051 tan 3.7e-08 0.0 -> 3.7000000000000017328e-8 0.0
+tan0052 tan 0.001 0.0 -> 0.0010000003333334666875 0.0
+tan0053 tan 0.2 0.0 -> 0.20271003550867249488 0.0
+tan0054 tan 1.0 0.0 -> 1.5574077246549022305 0.0
+tan0055 tan -3.7e-08 0.0 -> -3.7000000000000017328e-8 0.0
+tan0056 tan -0.001 0.0 -> -0.0010000003333334666875 0.0
+tan0057 tan -1.0 0.0 -> -1.5574077246549022305 0.0
+tan0058 tan 0.4636476090008061 0.0 -> 0.49999999999999997163 0.0
+tan0059 tan -0.4636476090008061 0.0 -> -0.49999999999999997163 0.0
+tan0060 tan 1.1071487177940904 0.0 -> 1.9999999999999995298 0.0
+tan0061 tan -1.1071487177940904 0.0 -> -1.9999999999999995298 0.0
+tan0062 tan 1.5 0.0 -> 14.101419947171719388 0.0
+tan0063 tan 1.57 0.0 -> 1255.7655915007896475 0.0
+tan0064 tan 1.5707963267948961 0.0 -> 1978937966095219.0538 0.0
+tan0065 tan 7.225663103256523 0.0 -> 1.3763819204711701522 0.0
+tan0066 tan -8.79645943005142 0.0 -> 0.7265425280053614098 0.0
+
-- special values
tan1000 tan -0.0 0.0 -> -0.0 0.0
tan1001 tan -inf 0.0 -> nan nan invalid
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 0860db8..988c6f7 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -2,14 +2,22 @@
See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
"""
+from test.support import is_resource_enabled
+
+import itertools
+import bisect
import copy
import decimal
import sys
+import os
import pickle
import random
+import struct
import unittest
+from array import array
+
from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod
from test import support
@@ -284,7 +292,8 @@ class TestTimeZone(unittest.TestCase):
with self.assertRaises(TypeError): self.EST.dst(5)
def test_tzname(self):
- self.assertEqual('UTC+00:00', timezone(ZERO).tzname(None))
+ self.assertEqual('UTC', timezone.utc.tzname(None))
+ self.assertEqual('UTC', timezone(ZERO).tzname(None))
self.assertEqual('UTC-05:00', timezone(-5 * HOUR).tzname(None))
self.assertEqual('UTC+09:30', timezone(9.5 * HOUR).tzname(None))
self.assertEqual('UTC-00:01', timezone(timedelta(minutes=-1)).tzname(None))
@@ -1558,13 +1567,32 @@ class TestDateTime(TestDate):
self.assertEqual(dt, dt2)
def test_isoformat(self):
- t = self.theclass(2, 3, 2, 4, 5, 1, 123)
- self.assertEqual(t.isoformat(), "0002-03-02T04:05:01.000123")
- self.assertEqual(t.isoformat('T'), "0002-03-02T04:05:01.000123")
- self.assertEqual(t.isoformat(' '), "0002-03-02 04:05:01.000123")
- self.assertEqual(t.isoformat('\x00'), "0002-03-02\x0004:05:01.000123")
+ t = self.theclass(1, 2, 3, 4, 5, 1, 123)
+ self.assertEqual(t.isoformat(), "0001-02-03T04:05:01.000123")
+ self.assertEqual(t.isoformat('T'), "0001-02-03T04:05:01.000123")
+ self.assertEqual(t.isoformat(' '), "0001-02-03 04:05:01.000123")
+ self.assertEqual(t.isoformat('\x00'), "0001-02-03\x0004:05:01.000123")
+ self.assertEqual(t.isoformat(timespec='hours'), "0001-02-03T04")
+ self.assertEqual(t.isoformat(timespec='minutes'), "0001-02-03T04:05")
+ self.assertEqual(t.isoformat(timespec='seconds'), "0001-02-03T04:05:01")
+ self.assertEqual(t.isoformat(timespec='milliseconds'), "0001-02-03T04:05:01.000")
+ self.assertEqual(t.isoformat(timespec='microseconds'), "0001-02-03T04:05:01.000123")
+ self.assertEqual(t.isoformat(timespec='auto'), "0001-02-03T04:05:01.000123")
+ self.assertEqual(t.isoformat(sep=' ', timespec='minutes'), "0001-02-03 04:05")
+ self.assertRaises(ValueError, t.isoformat, timespec='foo')
# str is ISO format with the separator forced to a blank.
- self.assertEqual(str(t), "0002-03-02 04:05:01.000123")
+ self.assertEqual(str(t), "0001-02-03 04:05:01.000123")
+
+ t = self.theclass(1, 2, 3, 4, 5, 1, 999500, tzinfo=timezone.utc)
+ self.assertEqual(t.isoformat(timespec='milliseconds'), "0001-02-03T04:05:01.999+00:00")
+
+ t = self.theclass(1, 2, 3, 4, 5, 1, 999500)
+ self.assertEqual(t.isoformat(timespec='milliseconds'), "0001-02-03T04:05:01.999")
+
+ t = self.theclass(1, 2, 3, 4, 5, 1)
+ self.assertEqual(t.isoformat(timespec='auto'), "0001-02-03T04:05:01")
+ self.assertEqual(t.isoformat(timespec='milliseconds'), "0001-02-03T04:05:01.000")
+ self.assertEqual(t.isoformat(timespec='microseconds'), "0001-02-03T04:05:01.000000")
t = self.theclass(2, 3, 2)
self.assertEqual(t.isoformat(), "0002-03-02T00:00:00")
@@ -1572,6 +1600,10 @@ class TestDateTime(TestDate):
self.assertEqual(t.isoformat(' '), "0002-03-02 00:00:00")
# str is ISO format with the separator forced to a blank.
self.assertEqual(str(t), "0002-03-02 00:00:00")
+ # ISO format with timezone
+ tz = FixedOffset(timedelta(seconds=16), 'XXX')
+ t = self.theclass(2, 3, 2, tzinfo=tz)
+ self.assertEqual(t.isoformat(), "0002-03-02T00:00:00+00:00:16")
def test_format(self):
dt = self.theclass(2007, 9, 10, 4, 5, 1, 123)
@@ -1691,6 +1723,14 @@ class TestDateTime(TestDate):
self.assertRaises(ValueError, self.theclass,
2000, 1, 31, 23, 59, 59,
1000000)
+ # bad fold
+ self.assertRaises(ValueError, self.theclass,
+ 2000, 1, 31, fold=-1)
+ self.assertRaises(ValueError, self.theclass,
+ 2000, 1, 31, fold=2)
+ # Positional fold:
+ self.assertRaises(TypeError, self.theclass,
+ 2000, 1, 31, 23, 59, 59, 0, None, 1)
def test_hash_equality(self):
d = self.theclass(2000, 12, 31, 23, 30, 17)
@@ -1874,16 +1914,20 @@ class TestDateTime(TestDate):
t = self.theclass(1970, 1, 1, 1, 2, 3, 4)
self.assertEqual(t.timestamp(),
18000.0 + 3600 + 2*60 + 3 + 4*1e-6)
- # Missing hour may produce platform-dependent result
- t = self.theclass(2012, 3, 11, 2, 30)
- self.assertIn(self.theclass.fromtimestamp(t.timestamp()),
- [t - timedelta(hours=1), t + timedelta(hours=1)])
+ # Missing hour
+ t0 = self.theclass(2012, 3, 11, 2, 30)
+ t1 = t0.replace(fold=1)
+ self.assertEqual(self.theclass.fromtimestamp(t1.timestamp()),
+ t0 - timedelta(hours=1))
+ self.assertEqual(self.theclass.fromtimestamp(t0.timestamp()),
+ t1 + timedelta(hours=1))
# Ambiguous hour defaults to DST
t = self.theclass(2012, 11, 4, 1, 30)
self.assertEqual(self.theclass.fromtimestamp(t.timestamp()), t)
# Timestamp may raise an overflow error on some platforms
- for t in [self.theclass(1,1,1), self.theclass(9999,12,12)]:
+ # XXX: Do we care to support the first and last year?
+ for t in [self.theclass(2,1,1), self.theclass(9998,12,12)]:
try:
s = t.timestamp()
except OverflowError:
@@ -1902,6 +1946,7 @@ class TestDateTime(TestDate):
self.assertEqual(t.timestamp(),
18000 + 3600 + 2*60 + 3 + 4*1e-6)
+ @support.run_with_tz('MSK-03') # Something east of Greenwich
def test_microsecond_rounding(self):
for fts in [self.theclass.fromtimestamp,
self.theclass.utcfromtimestamp]:
@@ -2076,11 +2121,22 @@ class TestDateTime(TestDate):
self.assertRaises(TypeError, combine) # need an arg
self.assertRaises(TypeError, combine, d) # need two args
self.assertRaises(TypeError, combine, t, d) # args reversed
- self.assertRaises(TypeError, combine, d, t, 1) # too many args
+ self.assertRaises(TypeError, combine, d, t, 1) # wrong tzinfo type
+ self.assertRaises(TypeError, combine, d, t, 1, 2) # too many args
self.assertRaises(TypeError, combine, "date", "time") # wrong types
self.assertRaises(TypeError, combine, d, "time") # wrong type
self.assertRaises(TypeError, combine, "date", t) # wrong type
+ # tzinfo= argument
+ dt = combine(d, t, timezone.utc)
+ self.assertIs(dt.tzinfo, timezone.utc)
+ dt = combine(d, t, tzinfo=timezone.utc)
+ self.assertIs(dt.tzinfo, timezone.utc)
+ t = time()
+ dt = combine(dt, t)
+ self.assertEqual(dt.date(), d)
+ self.assertEqual(dt.time(), t)
+
def test_replace(self):
cls = self.theclass
args = [1, 2, 3, 4, 5, 6, 7]
@@ -2107,6 +2163,7 @@ class TestDateTime(TestDate):
self.assertRaises(ValueError, base.replace, year=2001)
def test_astimezone(self):
+ return # The rest is no longer applicable
# Pretty boring! The TZ test is more interesting here. astimezone()
# simply can't be applied to a naive object.
dt = self.theclass.now()
@@ -2324,6 +2381,23 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
self.assertEqual(t.isoformat(), "00:00:00.100000")
self.assertEqual(t.isoformat(), str(t))
+ t = self.theclass(hour=12, minute=34, second=56, microsecond=123456)
+ self.assertEqual(t.isoformat(timespec='hours'), "12")
+ self.assertEqual(t.isoformat(timespec='minutes'), "12:34")
+ self.assertEqual(t.isoformat(timespec='seconds'), "12:34:56")
+ self.assertEqual(t.isoformat(timespec='milliseconds'), "12:34:56.123")
+ self.assertEqual(t.isoformat(timespec='microseconds'), "12:34:56.123456")
+ self.assertEqual(t.isoformat(timespec='auto'), "12:34:56.123456")
+ self.assertRaises(ValueError, t.isoformat, timespec='monkey')
+
+ t = self.theclass(hour=12, minute=34, second=56, microsecond=999500)
+ self.assertEqual(t.isoformat(timespec='milliseconds'), "12:34:56.999")
+
+ t = self.theclass(hour=12, minute=34, second=56, microsecond=0)
+ self.assertEqual(t.isoformat(timespec='milliseconds'), "12:34:56.000")
+ self.assertEqual(t.isoformat(timespec='microseconds'), "12:34:56.000000")
+ self.assertEqual(t.isoformat(timespec='auto'), "12:34:56")
+
def test_1653736(self):
# verify it doesn't accept extra keyword arguments
t = self.theclass(second=1)
@@ -2582,9 +2656,9 @@ class TZInfoBase:
self.assertRaises(ValueError, t.utcoffset)
self.assertRaises(ValueError, t.dst)
- # Not a whole number of minutes.
+ # Not a whole number of seconds.
class C7(tzinfo):
- def utcoffset(self, dt): return timedelta(seconds=61)
+ def utcoffset(self, dt): return timedelta(microseconds=61)
def dst(self, dt): return timedelta(microseconds=-81)
t = cls(1, 1, 1, tzinfo=C7())
self.assertRaises(ValueError, t.utcoffset)
@@ -3927,12 +4001,12 @@ class Oddballs(unittest.TestCase):
datetime(xx, xx, xx, xx, xx, xx, xx))
with self.assertRaisesRegex(TypeError, '^an integer is required '
- '\(got type str\)$'):
+ r'\(got type str\)$'):
datetime(10, 10, '10')
f10 = Number(10.9)
with self.assertRaisesRegex(TypeError, '^__int__ returned non-int '
- '\(type float\)$'):
+ r'\(type float\)$'):
datetime(10, 10, f10)
class Float(float):
@@ -3957,5 +4031,790 @@ class Oddballs(unittest.TestCase):
with self.assertRaises(TypeError):
datetime(10, 10, 10, 10, 10, 10, 10.)
+#############################################################################
+# Local Time Disambiguation
+
+# An experimental reimplementation of fromutc that respects the "fold" flag.
+
+class tzinfo2(tzinfo):
+
+ def fromutc(self, dt):
+ "datetime in UTC -> datetime in local time."
+
+ if not isinstance(dt, datetime):
+ raise TypeError("fromutc() requires a datetime argument")
+ if dt.tzinfo is not self:
+ raise ValueError("dt.tzinfo is not self")
+ # Returned value satisfies
+ # dt + ldt.utcoffset() = ldt
+ off0 = dt.replace(fold=0).utcoffset()
+ off1 = dt.replace(fold=1).utcoffset()
+ if off0 is None or off1 is None or dt.dst() is None:
+ raise ValueError
+ if off0 == off1:
+ ldt = dt + off0
+ off1 = ldt.utcoffset()
+ if off0 == off1:
+ return ldt
+ # Now, we discovered both possible offsets, so
+ # we can just try four possible solutions:
+ for off in [off0, off1]:
+ ldt = dt + off
+ if ldt.utcoffset() == off:
+ return ldt
+ ldt = ldt.replace(fold=1)
+ if ldt.utcoffset() == off:
+ return ldt
+
+ raise ValueError("No suitable local time found")
+
+# Reimplementing simplified US timezones to respect the "fold" flag:
+
+class USTimeZone2(tzinfo2):
+
+ def __init__(self, hours, reprname, stdname, dstname):
+ self.stdoffset = timedelta(hours=hours)
+ self.reprname = reprname
+ self.stdname = stdname
+ self.dstname = dstname
+
+ def __repr__(self):
+ return self.reprname
+
+ def tzname(self, dt):
+ if self.dst(dt):
+ return self.dstname
+ else:
+ return self.stdname
+
+ def utcoffset(self, dt):
+ return self.stdoffset + self.dst(dt)
+
+ def dst(self, dt):
+ if dt is None or dt.tzinfo is None:
+ # An exception instead may be sensible here, in one or more of
+ # the cases.
+ return ZERO
+ assert dt.tzinfo is self
+
+ # Find first Sunday in April.
+ start = first_sunday_on_or_after(DSTSTART.replace(year=dt.year))
+ assert start.weekday() == 6 and start.month == 4 and start.day <= 7
+
+ # Find last Sunday in October.
+ end = first_sunday_on_or_after(DSTEND.replace(year=dt.year))
+ assert end.weekday() == 6 and end.month == 10 and end.day >= 25
+
+ # Can't compare naive to aware objects, so strip the timezone from
+ # dt first.
+ dt = dt.replace(tzinfo=None)
+ if start + HOUR <= dt < end:
+ # DST is in effect.
+ return HOUR
+ elif end <= dt < end + HOUR:
+ # Fold (an ambiguous hour): use dt.fold to disambiguate.
+ return ZERO if dt.fold else HOUR
+ elif start <= dt < start + HOUR:
+ # Gap (a non-existent hour): reverse the fold rule.
+ return HOUR if dt.fold else ZERO
+ else:
+ # DST is off.
+ return ZERO
+
+Eastern2 = USTimeZone2(-5, "Eastern2", "EST", "EDT")
+Central2 = USTimeZone2(-6, "Central2", "CST", "CDT")
+Mountain2 = USTimeZone2(-7, "Mountain2", "MST", "MDT")
+Pacific2 = USTimeZone2(-8, "Pacific2", "PST", "PDT")
+
+# Europe_Vilnius_1941 tzinfo implementation reproduces the following
+# 1941 transition from Olson's tzdist:
+#
+# Zone NAME GMTOFF RULES FORMAT [UNTIL]
+# ZoneEurope/Vilnius 1:00 - CET 1940 Aug 3
+# 3:00 - MSK 1941 Jun 24
+# 1:00 C-Eur CE%sT 1944 Aug
+#
+# $ zdump -v Europe/Vilnius | grep 1941
+# Europe/Vilnius Mon Jun 23 20:59:59 1941 UTC = Mon Jun 23 23:59:59 1941 MSK isdst=0 gmtoff=10800
+# Europe/Vilnius Mon Jun 23 21:00:00 1941 UTC = Mon Jun 23 23:00:00 1941 CEST isdst=1 gmtoff=7200
+
+class Europe_Vilnius_1941(tzinfo):
+ def _utc_fold(self):
+ return [datetime(1941, 6, 23, 21, tzinfo=self), # Mon Jun 23 21:00:00 1941 UTC
+ datetime(1941, 6, 23, 22, tzinfo=self)] # Mon Jun 23 22:00:00 1941 UTC
+
+ def _loc_fold(self):
+ return [datetime(1941, 6, 23, 23, tzinfo=self), # Mon Jun 23 23:00:00 1941 MSK / CEST
+ datetime(1941, 6, 24, 0, tzinfo=self)] # Mon Jun 24 00:00:00 1941 CEST
+
+ def utcoffset(self, dt):
+ fold_start, fold_stop = self._loc_fold()
+ if dt < fold_start:
+ return 3 * HOUR
+ if dt < fold_stop:
+ return (2 if dt.fold else 3) * HOUR
+ # if dt >= fold_stop
+ return 2 * HOUR
+
+ def dst(self, dt):
+ fold_start, fold_stop = self._loc_fold()
+ if dt < fold_start:
+ return 0 * HOUR
+ if dt < fold_stop:
+ return (1 if dt.fold else 0) * HOUR
+ # if dt >= fold_stop
+ return 1 * HOUR
+
+ def tzname(self, dt):
+ fold_start, fold_stop = self._loc_fold()
+ if dt < fold_start:
+ return 'MSK'
+ if dt < fold_stop:
+ return ('MSK', 'CEST')[dt.fold]
+ # if dt >= fold_stop
+ return 'CEST'
+
+ def fromutc(self, dt):
+ assert dt.fold == 0
+ assert dt.tzinfo is self
+ if dt.year != 1941:
+ raise NotImplementedError
+ fold_start, fold_stop = self._utc_fold()
+ if dt < fold_start:
+ return dt + 3 * HOUR
+ if dt < fold_stop:
+ return (dt + 2 * HOUR).replace(fold=1)
+ # if dt >= fold_stop
+ return dt + 2 * HOUR
+
+
+class TestLocalTimeDisambiguation(unittest.TestCase):
+
+ def test_vilnius_1941_fromutc(self):
+ Vilnius = Europe_Vilnius_1941()
+
+ gdt = datetime(1941, 6, 23, 20, 59, 59, tzinfo=timezone.utc)
+ ldt = gdt.astimezone(Vilnius)
+ self.assertEqual(ldt.strftime("%c %Z%z"),
+ 'Mon Jun 23 23:59:59 1941 MSK+0300')
+ self.assertEqual(ldt.fold, 0)
+ self.assertFalse(ldt.dst())
+
+ gdt = datetime(1941, 6, 23, 21, tzinfo=timezone.utc)
+ ldt = gdt.astimezone(Vilnius)
+ self.assertEqual(ldt.strftime("%c %Z%z"),
+ 'Mon Jun 23 23:00:00 1941 CEST+0200')
+ self.assertEqual(ldt.fold, 1)
+ self.assertTrue(ldt.dst())
+
+ gdt = datetime(1941, 6, 23, 22, tzinfo=timezone.utc)
+ ldt = gdt.astimezone(Vilnius)
+ self.assertEqual(ldt.strftime("%c %Z%z"),
+ 'Tue Jun 24 00:00:00 1941 CEST+0200')
+ self.assertEqual(ldt.fold, 0)
+ self.assertTrue(ldt.dst())
+
+ def test_vilnius_1941_toutc(self):
+ Vilnius = Europe_Vilnius_1941()
+
+ ldt = datetime(1941, 6, 23, 22, 59, 59, tzinfo=Vilnius)
+ gdt = ldt.astimezone(timezone.utc)
+ self.assertEqual(gdt.strftime("%c %Z"),
+ 'Mon Jun 23 19:59:59 1941 UTC')
+
+ ldt = datetime(1941, 6, 23, 23, 59, 59, tzinfo=Vilnius)
+ gdt = ldt.astimezone(timezone.utc)
+ self.assertEqual(gdt.strftime("%c %Z"),
+ 'Mon Jun 23 20:59:59 1941 UTC')
+
+ ldt = datetime(1941, 6, 23, 23, 59, 59, tzinfo=Vilnius, fold=1)
+ gdt = ldt.astimezone(timezone.utc)
+ self.assertEqual(gdt.strftime("%c %Z"),
+ 'Mon Jun 23 21:59:59 1941 UTC')
+
+ ldt = datetime(1941, 6, 24, 0, tzinfo=Vilnius)
+ gdt = ldt.astimezone(timezone.utc)
+ self.assertEqual(gdt.strftime("%c %Z"),
+ 'Mon Jun 23 22:00:00 1941 UTC')
+
+
+ def test_constructors(self):
+ t = time(0, fold=1)
+ dt = datetime(1, 1, 1, fold=1)
+ self.assertEqual(t.fold, 1)
+ self.assertEqual(dt.fold, 1)
+ with self.assertRaises(TypeError):
+ time(0, 0, 0, 0, None, 0)
+
+ def test_member(self):
+ dt = datetime(1, 1, 1, fold=1)
+ t = dt.time()
+ self.assertEqual(t.fold, 1)
+ t = dt.timetz()
+ self.assertEqual(t.fold, 1)
+
+ def test_replace(self):
+ t = time(0)
+ dt = datetime(1, 1, 1)
+ self.assertEqual(t.replace(fold=1).fold, 1)
+ self.assertEqual(dt.replace(fold=1).fold, 1)
+ self.assertEqual(t.replace(fold=0).fold, 0)
+ self.assertEqual(dt.replace(fold=0).fold, 0)
+ # Check that replacement of other fields does not change "fold".
+ t = t.replace(fold=1, tzinfo=Eastern)
+ dt = dt.replace(fold=1, tzinfo=Eastern)
+ self.assertEqual(t.replace(tzinfo=None).fold, 1)
+ self.assertEqual(dt.replace(tzinfo=None).fold, 1)
+ # Check that fold is a keyword-only argument
+ with self.assertRaises(TypeError):
+ t.replace(1, 1, 1, None, 1)
+ with self.assertRaises(TypeError):
+ dt.replace(1, 1, 1, 1, 1, 1, 1, None, 1)
+
+ def test_comparison(self):
+ t = time(0)
+ dt = datetime(1, 1, 1)
+ self.assertEqual(t, t.replace(fold=1))
+ self.assertEqual(dt, dt.replace(fold=1))
+
+ def test_hash(self):
+ t = time(0)
+ dt = datetime(1, 1, 1)
+ self.assertEqual(hash(t), hash(t.replace(fold=1)))
+ self.assertEqual(hash(dt), hash(dt.replace(fold=1)))
+
+ @support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
+ def test_fromtimestamp(self):
+ s = 1414906200
+ dt0 = datetime.fromtimestamp(s)
+ dt1 = datetime.fromtimestamp(s + 3600)
+ self.assertEqual(dt0.fold, 0)
+ self.assertEqual(dt1.fold, 1)
+
+ @support.run_with_tz('Australia/Lord_Howe')
+ def test_fromtimestamp_lord_howe(self):
+ tm = _time.localtime(1.4e9)
+ if _time.strftime('%Z%z', tm) != 'LHST+1030':
+ self.skipTest('Australia/Lord_Howe timezone is not supported on this platform')
+ # $ TZ=Australia/Lord_Howe date -r 1428158700
+ # Sun Apr 5 01:45:00 LHDT 2015
+ # $ TZ=Australia/Lord_Howe date -r 1428160500
+ # Sun Apr 5 01:45:00 LHST 2015
+ s = 1428158700
+ t0 = datetime.fromtimestamp(s)
+ t1 = datetime.fromtimestamp(s + 1800)
+ self.assertEqual(t0, t1)
+ self.assertEqual(t0.fold, 0)
+ self.assertEqual(t1.fold, 1)
+
+
+ @support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
+ def test_timestamp(self):
+ dt0 = datetime(2014, 11, 2, 1, 30)
+ dt1 = dt0.replace(fold=1)
+ self.assertEqual(dt0.timestamp() + 3600,
+ dt1.timestamp())
+
+ @support.run_with_tz('Australia/Lord_Howe')
+ def test_timestamp_lord_howe(self):
+ tm = _time.localtime(1.4e9)
+ if _time.strftime('%Z%z', tm) != 'LHST+1030':
+ self.skipTest('Australia/Lord_Howe timezone is not supported on this platform')
+ t = datetime(2015, 4, 5, 1, 45)
+ s0 = t.replace(fold=0).timestamp()
+ s1 = t.replace(fold=1).timestamp()
+ self.assertEqual(s0 + 1800, s1)
+
+
+ @support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
+ def test_astimezone(self):
+ dt0 = datetime(2014, 11, 2, 1, 30)
+ dt1 = dt0.replace(fold=1)
+ # Convert both naive instances to aware.
+ adt0 = dt0.astimezone()
+ adt1 = dt1.astimezone()
+ # Check that the first instance in DST zone and the second in STD
+ self.assertEqual(adt0.tzname(), 'EDT')
+ self.assertEqual(adt1.tzname(), 'EST')
+ self.assertEqual(adt0 + HOUR, adt1)
+ # Aware instances with fixed offset tzinfo's always have fold=0
+ self.assertEqual(adt0.fold, 0)
+ self.assertEqual(adt1.fold, 0)
+
+
+ def test_pickle_fold(self):
+ t = time(fold=1)
+ dt = datetime(1, 1, 1, fold=1)
+ for pickler, unpickler, proto in pickle_choices:
+ for x in [t, dt]:
+ s = pickler.dumps(x, proto)
+ y = unpickler.loads(s)
+ self.assertEqual(x, y)
+ self.assertEqual((0 if proto < 4 else x.fold), y.fold)
+
+ def test_repr(self):
+ t = time(fold=1)
+ dt = datetime(1, 1, 1, fold=1)
+ self.assertEqual(repr(t), 'datetime.time(0, 0, fold=1)')
+ self.assertEqual(repr(dt),
+ 'datetime.datetime(1, 1, 1, 0, 0, fold=1)')
+
+ def test_dst(self):
+ # Let's first establish that things work in regular times.
+ dt_summer = datetime(2002, 10, 27, 1, tzinfo=Eastern2) - timedelta.resolution
+ dt_winter = datetime(2002, 10, 27, 2, tzinfo=Eastern2)
+ self.assertEqual(dt_summer.dst(), HOUR)
+ self.assertEqual(dt_winter.dst(), ZERO)
+ # The disambiguation flag is ignored
+ self.assertEqual(dt_summer.replace(fold=1).dst(), HOUR)
+ self.assertEqual(dt_winter.replace(fold=1).dst(), ZERO)
+
+ # Pick local time in the fold.
+ for minute in [0, 30, 59]:
+ dt = datetime(2002, 10, 27, 1, minute, tzinfo=Eastern2)
+ # With fold=0 (the default) it is in DST.
+ self.assertEqual(dt.dst(), HOUR)
+ # With fold=1 it is in STD.
+ self.assertEqual(dt.replace(fold=1).dst(), ZERO)
+
+ # Pick local time in the gap.
+ for minute in [0, 30, 59]:
+ dt = datetime(2002, 4, 7, 2, minute, tzinfo=Eastern2)
+ # With fold=0 (the default) it is in STD.
+ self.assertEqual(dt.dst(), ZERO)
+ # With fold=1 it is in DST.
+ self.assertEqual(dt.replace(fold=1).dst(), HOUR)
+
+
+ def test_utcoffset(self):
+ # Let's first establish that things work in regular times.
+ dt_summer = datetime(2002, 10, 27, 1, tzinfo=Eastern2) - timedelta.resolution
+ dt_winter = datetime(2002, 10, 27, 2, tzinfo=Eastern2)
+ self.assertEqual(dt_summer.utcoffset(), -4 * HOUR)
+ self.assertEqual(dt_winter.utcoffset(), -5 * HOUR)
+ # The disambiguation flag is ignored
+ self.assertEqual(dt_summer.replace(fold=1).utcoffset(), -4 * HOUR)
+ self.assertEqual(dt_winter.replace(fold=1).utcoffset(), -5 * HOUR)
+
+ def test_fromutc(self):
+ # Let's first establish that things work in regular times.
+ u_summer = datetime(2002, 10, 27, 6, tzinfo=Eastern2) - timedelta.resolution
+ u_winter = datetime(2002, 10, 27, 7, tzinfo=Eastern2)
+ t_summer = Eastern2.fromutc(u_summer)
+ t_winter = Eastern2.fromutc(u_winter)
+ self.assertEqual(t_summer, u_summer - 4 * HOUR)
+ self.assertEqual(t_winter, u_winter - 5 * HOUR)
+ self.assertEqual(t_summer.fold, 0)
+ self.assertEqual(t_winter.fold, 0)
+
+ # What happens in the fall-back fold?
+ u = datetime(2002, 10, 27, 5, 30, tzinfo=Eastern2)
+ t0 = Eastern2.fromutc(u)
+ u += HOUR
+ t1 = Eastern2.fromutc(u)
+ self.assertEqual(t0, t1)
+ self.assertEqual(t0.fold, 0)
+ self.assertEqual(t1.fold, 1)
+ # The tricky part is when u is in the local fold:
+ u = datetime(2002, 10, 27, 1, 30, tzinfo=Eastern2)
+ t = Eastern2.fromutc(u)
+ self.assertEqual((t.day, t.hour), (26, 21))
+ # .. or gets into the local fold after a standard time adjustment
+ u = datetime(2002, 10, 27, 6, 30, tzinfo=Eastern2)
+ t = Eastern2.fromutc(u)
+ self.assertEqual((t.day, t.hour), (27, 1))
+
+ # What happens in the spring-forward gap?
+ u = datetime(2002, 4, 7, 2, 0, tzinfo=Eastern2)
+ t = Eastern2.fromutc(u)
+ self.assertEqual((t.day, t.hour), (6, 21))
+
+ def test_mixed_compare_regular(self):
+ t = datetime(2000, 1, 1, tzinfo=Eastern2)
+ self.assertEqual(t, t.astimezone(timezone.utc))
+ t = datetime(2000, 6, 1, tzinfo=Eastern2)
+ self.assertEqual(t, t.astimezone(timezone.utc))
+
+ def test_mixed_compare_fold(self):
+ t_fold = datetime(2002, 10, 27, 1, 45, tzinfo=Eastern2)
+ t_fold_utc = t_fold.astimezone(timezone.utc)
+ self.assertNotEqual(t_fold, t_fold_utc)
+
+ def test_mixed_compare_gap(self):
+ t_gap = datetime(2002, 4, 7, 2, 45, tzinfo=Eastern2)
+ t_gap_utc = t_gap.astimezone(timezone.utc)
+ self.assertNotEqual(t_gap, t_gap_utc)
+
+ def test_hash_aware(self):
+ t = datetime(2000, 1, 1, tzinfo=Eastern2)
+ self.assertEqual(hash(t), hash(t.replace(fold=1)))
+ t_fold = datetime(2002, 10, 27, 1, 45, tzinfo=Eastern2)
+ t_gap = datetime(2002, 4, 7, 2, 45, tzinfo=Eastern2)
+ self.assertEqual(hash(t_fold), hash(t_fold.replace(fold=1)))
+ self.assertEqual(hash(t_gap), hash(t_gap.replace(fold=1)))
+
+SEC = timedelta(0, 1)
+
+def pairs(iterable):
+ a, b = itertools.tee(iterable)
+ next(b, None)
+ return zip(a, b)
+
+class ZoneInfo(tzinfo):
+ zoneroot = '/usr/share/zoneinfo'
+ def __init__(self, ut, ti):
+ """
+
+ :param ut: array
+ Array of transition point timestamps
+ :param ti: list
+ A list of (offset, isdst, abbr) tuples
+ :return: None
+ """
+ self.ut = ut
+ self.ti = ti
+ self.lt = self.invert(ut, ti)
+
+ @staticmethod
+ def invert(ut, ti):
+ lt = (array('q', ut), array('q', ut))
+ if ut:
+ offset = ti[0][0] // SEC
+ lt[0][0] += offset
+ lt[1][0] += offset
+ for i in range(1, len(ut)):
+ lt[0][i] += ti[i-1][0] // SEC
+ lt[1][i] += ti[i][0] // SEC
+ return lt
+
+ @classmethod
+ def fromfile(cls, fileobj):
+ if fileobj.read(4).decode() != "TZif":
+ raise ValueError("not a zoneinfo file")
+ fileobj.seek(32)
+ counts = array('i')
+ counts.fromfile(fileobj, 3)
+ if sys.byteorder != 'big':
+ counts.byteswap()
+
+ ut = array('i')
+ ut.fromfile(fileobj, counts[0])
+ if sys.byteorder != 'big':
+ ut.byteswap()
+
+ type_indices = array('B')
+ type_indices.fromfile(fileobj, counts[0])
+
+ ttis = []
+ for i in range(counts[1]):
+ ttis.append(struct.unpack(">lbb", fileobj.read(6)))
+
+ abbrs = fileobj.read(counts[2])
+
+ # Convert ttis
+ for i, (gmtoff, isdst, abbrind) in enumerate(ttis):
+ abbr = abbrs[abbrind:abbrs.find(0, abbrind)].decode()
+ ttis[i] = (timedelta(0, gmtoff), isdst, abbr)
+
+ ti = [None] * len(ut)
+ for i, idx in enumerate(type_indices):
+ ti[i] = ttis[idx]
+
+ self = cls(ut, ti)
+
+ return self
+
+ @classmethod
+ def fromname(cls, name):
+ path = os.path.join(cls.zoneroot, name)
+ with open(path, 'rb') as f:
+ return cls.fromfile(f)
+
+ EPOCHORDINAL = date(1970, 1, 1).toordinal()
+
+ def fromutc(self, dt):
+ """datetime in UTC -> datetime in local time."""
+
+ if not isinstance(dt, datetime):
+ raise TypeError("fromutc() requires a datetime argument")
+ if dt.tzinfo is not self:
+ raise ValueError("dt.tzinfo is not self")
+
+ timestamp = ((dt.toordinal() - self.EPOCHORDINAL) * 86400
+ + dt.hour * 3600
+ + dt.minute * 60
+ + dt.second)
+
+ if timestamp < self.ut[1]:
+ tti = self.ti[0]
+ fold = 0
+ else:
+ idx = bisect.bisect_right(self.ut, timestamp)
+ assert self.ut[idx-1] <= timestamp
+ assert idx == len(self.ut) or timestamp < self.ut[idx]
+ tti_prev, tti = self.ti[idx-2:idx]
+ # Detect fold
+ shift = tti_prev[0] - tti[0]
+ fold = (shift > timedelta(0, timestamp - self.ut[idx-1]))
+ dt += tti[0]
+ if fold:
+ return dt.replace(fold=1)
+ else:
+ return dt
+
+ def _find_ti(self, dt, i):
+ timestamp = ((dt.toordinal() - self.EPOCHORDINAL) * 86400
+ + dt.hour * 3600
+ + dt.minute * 60
+ + dt.second)
+ lt = self.lt[dt.fold]
+ idx = bisect.bisect_right(lt, timestamp)
+
+ return self.ti[max(0, idx - 1)][i]
+
+ def utcoffset(self, dt):
+ return self._find_ti(dt, 0)
+
+ def dst(self, dt):
+ isdst = self._find_ti(dt, 1)
+ # XXX: We cannot accurately determine the "save" value,
+ # so let's return 1h whenever DST is in effect. Since
+ # we don't use dst() in fromutc(), it is unlikely that
+ # it will be needed for anything more than bool(dst()).
+ return ZERO if isdst else HOUR
+
+ def tzname(self, dt):
+ return self._find_ti(dt, 2)
+
+ @classmethod
+ def zonenames(cls, zonedir=None):
+ if zonedir is None:
+ zonedir = cls.zoneroot
+ zone_tab = os.path.join(zonedir, 'zone.tab')
+ try:
+ f = open(zone_tab)
+ except OSError:
+ return
+ with f:
+ for line in f:
+ line = line.strip()
+ if line and not line.startswith('#'):
+ yield line.split()[2]
+
+ @classmethod
+ def stats(cls, start_year=1):
+ count = gap_count = fold_count = zeros_count = 0
+ min_gap = min_fold = timedelta.max
+ max_gap = max_fold = ZERO
+ min_gap_datetime = max_gap_datetime = datetime.min
+ min_gap_zone = max_gap_zone = None
+ min_fold_datetime = max_fold_datetime = datetime.min
+ min_fold_zone = max_fold_zone = None
+ stats_since = datetime(start_year, 1, 1) # Starting from 1970 eliminates a lot of noise
+ for zonename in cls.zonenames():
+ count += 1
+ tz = cls.fromname(zonename)
+ for dt, shift in tz.transitions():
+ if dt < stats_since:
+ continue
+ if shift > ZERO:
+ gap_count += 1
+ if (shift, dt) > (max_gap, max_gap_datetime):
+ max_gap = shift
+ max_gap_zone = zonename
+ max_gap_datetime = dt
+ if (shift, datetime.max - dt) < (min_gap, datetime.max - min_gap_datetime):
+ min_gap = shift
+ min_gap_zone = zonename
+ min_gap_datetime = dt
+ elif shift < ZERO:
+ fold_count += 1
+ shift = -shift
+ if (shift, dt) > (max_fold, max_fold_datetime):
+ max_fold = shift
+ max_fold_zone = zonename
+ max_fold_datetime = dt
+ if (shift, datetime.max - dt) < (min_fold, datetime.max - min_fold_datetime):
+ min_fold = shift
+ min_fold_zone = zonename
+ min_fold_datetime = dt
+ else:
+ zeros_count += 1
+ trans_counts = (gap_count, fold_count, zeros_count)
+ print("Number of zones: %5d" % count)
+ print("Number of transitions: %5d = %d (gaps) + %d (folds) + %d (zeros)" %
+ ((sum(trans_counts),) + trans_counts))
+ print("Min gap: %16s at %s in %s" % (min_gap, min_gap_datetime, min_gap_zone))
+ print("Max gap: %16s at %s in %s" % (max_gap, max_gap_datetime, max_gap_zone))
+ print("Min fold: %16s at %s in %s" % (min_fold, min_fold_datetime, min_fold_zone))
+ print("Max fold: %16s at %s in %s" % (max_fold, max_fold_datetime, max_fold_zone))
+
+
+ def transitions(self):
+ for (_, prev_ti), (t, ti) in pairs(zip(self.ut, self.ti)):
+ shift = ti[0] - prev_ti[0]
+ yield datetime.utcfromtimestamp(t), shift
+
+ def nondst_folds(self):
+ """Find all folds with the same value of isdst on both sides of the transition."""
+ for (_, prev_ti), (t, ti) in pairs(zip(self.ut, self.ti)):
+ shift = ti[0] - prev_ti[0]
+ if shift < ZERO and ti[1] == prev_ti[1]:
+ yield datetime.utcfromtimestamp(t), -shift, prev_ti[2], ti[2]
+
+ @classmethod
+ def print_all_nondst_folds(cls, same_abbr=False, start_year=1):
+ count = 0
+ for zonename in cls.zonenames():
+ tz = cls.fromname(zonename)
+ for dt, shift, prev_abbr, abbr in tz.nondst_folds():
+ if dt.year < start_year or same_abbr and prev_abbr != abbr:
+ continue
+ count += 1
+ print("%3d) %-30s %s %10s %5s -> %s" %
+ (count, zonename, dt, shift, prev_abbr, abbr))
+
+ def folds(self):
+ for t, shift in self.transitions():
+ if shift < ZERO:
+ yield t, -shift
+
+ def gaps(self):
+ for t, shift in self.transitions():
+ if shift > ZERO:
+ yield t, shift
+
+ def zeros(self):
+ for t, shift in self.transitions():
+ if not shift:
+ yield t
+
+
+class ZoneInfoTest(unittest.TestCase):
+ zonename = 'America/New_York'
+
+ def setUp(self):
+ if sys.platform == "win32":
+ self.skipTest("Skipping zoneinfo tests on Windows")
+ try:
+ self.tz = ZoneInfo.fromname(self.zonename)
+ except FileNotFoundError as err:
+ self.skipTest("Skipping %s: %s" % (self.zonename, err))
+
+ def assertEquivDatetimes(self, a, b):
+ self.assertEqual((a.replace(tzinfo=None), a.fold, id(a.tzinfo)),
+ (b.replace(tzinfo=None), b.fold, id(b.tzinfo)))
+
+ def test_folds(self):
+ tz = self.tz
+ for dt, shift in tz.folds():
+ for x in [0 * shift, 0.5 * shift, shift - timedelta.resolution]:
+ udt = dt + x
+ ldt = tz.fromutc(udt.replace(tzinfo=tz))
+ self.assertEqual(ldt.fold, 1)
+ adt = udt.replace(tzinfo=timezone.utc).astimezone(tz)
+ self.assertEquivDatetimes(adt, ldt)
+ utcoffset = ldt.utcoffset()
+ self.assertEqual(ldt.replace(tzinfo=None), udt + utcoffset)
+ # Round trip
+ self.assertEquivDatetimes(ldt.astimezone(timezone.utc),
+ udt.replace(tzinfo=timezone.utc))
+
+
+ for x in [-timedelta.resolution, shift]:
+ udt = dt + x
+ udt = udt.replace(tzinfo=tz)
+ ldt = tz.fromutc(udt)
+ self.assertEqual(ldt.fold, 0)
+
+ def test_gaps(self):
+ tz = self.tz
+ for dt, shift in tz.gaps():
+ for x in [0 * shift, 0.5 * shift, shift - timedelta.resolution]:
+ udt = dt + x
+ udt = udt.replace(tzinfo=tz)
+ ldt = tz.fromutc(udt)
+ self.assertEqual(ldt.fold, 0)
+ adt = udt.replace(tzinfo=timezone.utc).astimezone(tz)
+ self.assertEquivDatetimes(adt, ldt)
+ utcoffset = ldt.utcoffset()
+ self.assertEqual(ldt.replace(tzinfo=None), udt.replace(tzinfo=None) + utcoffset)
+ # Create a local time inside the gap
+ ldt = tz.fromutc(dt.replace(tzinfo=tz)) - shift + x
+ self.assertLess(ldt.replace(fold=1).utcoffset(),
+ ldt.replace(fold=0).utcoffset(),
+ "At %s." % ldt)
+
+ for x in [-timedelta.resolution, shift]:
+ udt = dt + x
+ ldt = tz.fromutc(udt.replace(tzinfo=tz))
+ self.assertEqual(ldt.fold, 0)
+
+ def test_system_transitions(self):
+ if ('Riyadh8' in self.zonename or
+ # From tzdata NEWS file:
+ # The files solar87, solar88, and solar89 are no longer distributed.
+ # They were a negative experiment - that is, a demonstration that
+ # tz data can represent solar time only with some difficulty and error.
+ # Their presence in the distribution caused confusion, as Riyadh
+ # civil time was generally not solar time in those years.
+ self.zonename.startswith('right/')):
+ self.skipTest("Skipping %s" % self.zonename)
+ tz = self.tz
+ TZ = os.environ.get('TZ')
+ os.environ['TZ'] = self.zonename
+ try:
+ _time.tzset()
+ for udt, shift in tz.transitions():
+ if udt.year >= 2037:
+ # System support for times around the end of 32-bit time_t
+ # and later is flaky on many systems.
+ break
+ s0 = (udt - datetime(1970, 1, 1)) // SEC
+ ss = shift // SEC # shift seconds
+ for x in [-40 * 3600, -20*3600, -1, 0,
+ ss - 1, ss + 20 * 3600, ss + 40 * 3600]:
+ s = s0 + x
+ sdt = datetime.fromtimestamp(s)
+ tzdt = datetime.fromtimestamp(s, tz).replace(tzinfo=None)
+ self.assertEquivDatetimes(sdt, tzdt)
+ s1 = sdt.timestamp()
+ self.assertEqual(s, s1)
+ if ss > 0: # gap
+ # Create local time inside the gap
+ dt = datetime.fromtimestamp(s0) - shift / 2
+ ts0 = dt.timestamp()
+ ts1 = dt.replace(fold=1).timestamp()
+ self.assertEqual(ts0, s0 + ss / 2)
+ self.assertEqual(ts1, s0 - ss / 2)
+ finally:
+ if TZ is None:
+ del os.environ['TZ']
+ else:
+ os.environ['TZ'] = TZ
+ _time.tzset()
+
+
+class ZoneInfoCompleteTest(unittest.TestSuite):
+ def __init__(self):
+ tests = []
+ if is_resource_enabled('tzdata'):
+ for name in ZoneInfo.zonenames():
+ Test = type('ZoneInfoTest[%s]' % name, (ZoneInfoTest,), {})
+ Test.zonename = name
+ for method in dir(Test):
+ if method.startswith('test_'):
+ tests.append(Test(method))
+ super().__init__(tests)
+
+# Iran had a sub-minute UTC offset before 1946.
+class IranTest(ZoneInfoTest):
+ zonename = 'Asia/Tehran'
+
+def load_tests(loader, standard_tests, pattern):
+ standard_tests.addTest(ZoneInfoCompleteTest())
+ return standard_tests
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/dtracedata/assert_usable.d b/Lib/test/dtracedata/assert_usable.d
new file mode 100644
index 0000000..0b2d4da
--- /dev/null
+++ b/Lib/test/dtracedata/assert_usable.d
@@ -0,0 +1,5 @@
+BEGIN
+{
+ printf("probe: success\n");
+ exit(0);
+}
diff --git a/Lib/test/dtracedata/assert_usable.stp b/Lib/test/dtracedata/assert_usable.stp
new file mode 100644
index 0000000..88e7e68
--- /dev/null
+++ b/Lib/test/dtracedata/assert_usable.stp
@@ -0,0 +1,5 @@
+probe begin
+{
+ println("probe: success")
+ exit ()
+}
diff --git a/Lib/test/dtracedata/call_stack.d b/Lib/test/dtracedata/call_stack.d
new file mode 100644
index 0000000..450e939
--- /dev/null
+++ b/Lib/test/dtracedata/call_stack.d
@@ -0,0 +1,31 @@
+self int indent;
+
+python$target:::function-entry
+/copyinstr(arg1) == "start"/
+{
+ self->trace = 1;
+}
+
+python$target:::function-entry
+/self->trace/
+{
+ printf("%d\t%*s:", timestamp, 15, probename);
+ printf("%*s", self->indent, "");
+ printf("%s:%s:%d\n", basename(copyinstr(arg0)), copyinstr(arg1), arg2);
+ self->indent++;
+}
+
+python$target:::function-return
+/self->trace/
+{
+ self->indent--;
+ printf("%d\t%*s:", timestamp, 15, probename);
+ printf("%*s", self->indent, "");
+ printf("%s:%s:%d\n", basename(copyinstr(arg0)), copyinstr(arg1), arg2);
+}
+
+python$target:::function-return
+/copyinstr(arg1) == "start"/
+{
+ self->trace = 0;
+}
diff --git a/Lib/test/dtracedata/call_stack.d.expected b/Lib/test/dtracedata/call_stack.d.expected
new file mode 100644
index 0000000..27849d1
--- /dev/null
+++ b/Lib/test/dtracedata/call_stack.d.expected
@@ -0,0 +1,18 @@
+ function-entry:call_stack.py:start:23
+ function-entry: call_stack.py:function_1:1
+ function-entry: call_stack.py:function_3:9
+function-return: call_stack.py:function_3:10
+function-return: call_stack.py:function_1:2
+ function-entry: call_stack.py:function_2:5
+ function-entry: call_stack.py:function_1:1
+ function-entry: call_stack.py:function_3:9
+function-return: call_stack.py:function_3:10
+function-return: call_stack.py:function_1:2
+function-return: call_stack.py:function_2:6
+ function-entry: call_stack.py:function_3:9
+function-return: call_stack.py:function_3:10
+ function-entry: call_stack.py:function_4:13
+function-return: call_stack.py:function_4:14
+ function-entry: call_stack.py:function_5:18
+function-return: call_stack.py:function_5:21
+function-return:call_stack.py:start:28
diff --git a/Lib/test/dtracedata/call_stack.py b/Lib/test/dtracedata/call_stack.py
new file mode 100644
index 0000000..ee9f3ae
--- /dev/null
+++ b/Lib/test/dtracedata/call_stack.py
@@ -0,0 +1,30 @@
+def function_1():
+ function_3(1, 2)
+
+# Check stacktrace
+def function_2():
+ function_1()
+
+# CALL_FUNCTION_VAR
+def function_3(dummy, dummy2):
+ pass
+
+# CALL_FUNCTION_KW
+def function_4(**dummy):
+ return 1
+ return 2 # unreachable
+
+# CALL_FUNCTION_VAR_KW
+def function_5(dummy, dummy2, **dummy3):
+ if False:
+ return 7
+ return 8
+
+def start():
+ function_1()
+ function_2()
+ function_3(1, 2)
+ function_4(test=42)
+ function_5(*(1, 2), **{"test": 42})
+
+start()
diff --git a/Lib/test/dtracedata/call_stack.stp b/Lib/test/dtracedata/call_stack.stp
new file mode 100644
index 0000000..54082c2
--- /dev/null
+++ b/Lib/test/dtracedata/call_stack.stp
@@ -0,0 +1,41 @@
+global tracing
+
+function basename:string(path:string)
+{
+ last_token = token = tokenize(path, "/");
+ while (token != "") {
+ last_token = token;
+ token = tokenize("", "/");
+ }
+ return last_token;
+}
+
+probe process.mark("function__entry")
+{
+ funcname = user_string($arg2);
+
+ if (funcname == "start") {
+ tracing = 1;
+ }
+}
+
+probe process.mark("function__entry"), process.mark("function__return")
+{
+ filename = user_string($arg1);
+ funcname = user_string($arg2);
+ lineno = $arg3;
+
+ if (tracing) {
+ printf("%d\t%s:%s:%s:%d\n", gettimeofday_us(), $$name,
+ basename(filename), funcname, lineno);
+ }
+}
+
+probe process.mark("function__return")
+{
+ funcname = user_string($arg2);
+
+ if (funcname == "start") {
+ tracing = 0;
+ }
+}
diff --git a/Lib/test/dtracedata/call_stack.stp.expected b/Lib/test/dtracedata/call_stack.stp.expected
new file mode 100644
index 0000000..32cf396
--- /dev/null
+++ b/Lib/test/dtracedata/call_stack.stp.expected
@@ -0,0 +1,14 @@
+function__entry:call_stack.py:start:23
+function__entry:call_stack.py:function_1:1
+function__return:call_stack.py:function_1:2
+function__entry:call_stack.py:function_2:5
+function__entry:call_stack.py:function_1:1
+function__return:call_stack.py:function_1:2
+function__return:call_stack.py:function_2:6
+function__entry:call_stack.py:function_3:9
+function__return:call_stack.py:function_3:10
+function__entry:call_stack.py:function_4:13
+function__return:call_stack.py:function_4:14
+function__entry:call_stack.py:function_5:18
+function__return:call_stack.py:function_5:21
+function__return:call_stack.py:start:28
diff --git a/Lib/test/dtracedata/gc.d b/Lib/test/dtracedata/gc.d
new file mode 100644
index 0000000..4d91487
--- /dev/null
+++ b/Lib/test/dtracedata/gc.d
@@ -0,0 +1,18 @@
+python$target:::function-entry
+/copyinstr(arg1) == "start"/
+{
+ self->trace = 1;
+}
+
+python$target:::gc-start,
+python$target:::gc-done
+/self->trace/
+{
+ printf("%d\t%s:%ld\n", timestamp, probename, arg0);
+}
+
+python$target:::function-return
+/copyinstr(arg1) == "start"/
+{
+ self->trace = 0;
+}
diff --git a/Lib/test/dtracedata/gc.d.expected b/Lib/test/dtracedata/gc.d.expected
new file mode 100644
index 0000000..8e5ac2a
--- /dev/null
+++ b/Lib/test/dtracedata/gc.d.expected
@@ -0,0 +1,8 @@
+gc-start:0
+gc-done:0
+gc-start:1
+gc-done:0
+gc-start:2
+gc-done:0
+gc-start:2
+gc-done:1
diff --git a/Lib/test/dtracedata/gc.py b/Lib/test/dtracedata/gc.py
new file mode 100644
index 0000000..144a783
--- /dev/null
+++ b/Lib/test/dtracedata/gc.py
@@ -0,0 +1,13 @@
+import gc
+
+def start():
+ gc.collect(0)
+ gc.collect(1)
+ gc.collect(2)
+ l = []
+ l.append(l)
+ del l
+ gc.collect(2)
+
+gc.collect()
+start()
diff --git a/Lib/test/dtracedata/gc.stp b/Lib/test/dtracedata/gc.stp
new file mode 100644
index 0000000..162c6d3
--- /dev/null
+++ b/Lib/test/dtracedata/gc.stp
@@ -0,0 +1,26 @@
+global tracing
+
+probe process.mark("function__entry")
+{
+ funcname = user_string($arg2);
+
+ if (funcname == "start") {
+ tracing = 1;
+ }
+}
+
+probe process.mark("gc__start"), process.mark("gc__done")
+{
+ if (tracing) {
+ printf("%d\t%s:%ld\n", gettimeofday_us(), $$name, $arg1);
+ }
+}
+
+probe process.mark("function__return")
+{
+ funcname = user_string($arg2);
+
+ if (funcname == "start") {
+ tracing = 0;
+ }
+}
diff --git a/Lib/test/dtracedata/gc.stp.expected b/Lib/test/dtracedata/gc.stp.expected
new file mode 100644
index 0000000..7e6e622
--- /dev/null
+++ b/Lib/test/dtracedata/gc.stp.expected
@@ -0,0 +1,8 @@
+gc__start:0
+gc__done:0
+gc__start:1
+gc__done:0
+gc__start:2
+gc__done:0
+gc__start:2
+gc__done:1
diff --git a/Lib/test/dtracedata/instance.py b/Lib/test/dtracedata/instance.py
new file mode 100644
index 0000000..f142137
--- /dev/null
+++ b/Lib/test/dtracedata/instance.py
@@ -0,0 +1,24 @@
+import gc
+
+class old_style_class():
+ pass
+class new_style_class(object):
+ pass
+
+a = old_style_class()
+del a
+gc.collect()
+b = new_style_class()
+del b
+gc.collect()
+
+a = old_style_class()
+del old_style_class
+gc.collect()
+b = new_style_class()
+del new_style_class
+gc.collect()
+del a
+gc.collect()
+del b
+gc.collect()
diff --git a/Lib/test/dtracedata/line.d b/Lib/test/dtracedata/line.d
new file mode 100644
index 0000000..03f22db
--- /dev/null
+++ b/Lib/test/dtracedata/line.d
@@ -0,0 +1,7 @@
+python$target:::line
+/(copyinstr(arg1)=="test_line")/
+{
+ printf("%d\t%s:%s:%s:%d\n", timestamp,
+ probename, basename(copyinstr(arg0)),
+ copyinstr(arg1), arg2);
+}
diff --git a/Lib/test/dtracedata/line.d.expected b/Lib/test/dtracedata/line.d.expected
new file mode 100644
index 0000000..9b16ce7
--- /dev/null
+++ b/Lib/test/dtracedata/line.d.expected
@@ -0,0 +1,20 @@
+line:line.py:test_line:2
+line:line.py:test_line:3
+line:line.py:test_line:4
+line:line.py:test_line:5
+line:line.py:test_line:6
+line:line.py:test_line:7
+line:line.py:test_line:8
+line:line.py:test_line:9
+line:line.py:test_line:10
+line:line.py:test_line:11
+line:line.py:test_line:4
+line:line.py:test_line:5
+line:line.py:test_line:6
+line:line.py:test_line:7
+line:line.py:test_line:8
+line:line.py:test_line:10
+line:line.py:test_line:11
+line:line.py:test_line:4
+line:line.py:test_line:12
+line:line.py:test_line:13
diff --git a/Lib/test/dtracedata/line.py b/Lib/test/dtracedata/line.py
new file mode 100644
index 0000000..0930ff3
--- /dev/null
+++ b/Lib/test/dtracedata/line.py
@@ -0,0 +1,17 @@
+def test_line():
+ a = 1
+ print('# Preamble', a)
+ for i in range(2):
+ a = i
+ b = i+2
+ c = i+3
+ if c < 4:
+ a = c
+ d = a + b +c
+ print('#', a, b, c, d)
+ a = 1
+ print('# Epilogue', a)
+
+
+if __name__ == '__main__':
+ test_line()
diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py
index e3f1aa5..9fbe04d 100644
--- a/Lib/test/eintrdata/eintr_tester.py
+++ b/Lib/test/eintrdata/eintr_tester.py
@@ -9,7 +9,7 @@ sub-second periodicity (contrarily to signal()).
"""
import contextlib
-import io
+import faulthandler
import os
import select
import signal
@@ -50,6 +50,10 @@ class EINTRBaseTest(unittest.TestCase):
signal.setitimer(signal.ITIMER_REAL, cls.signal_delay,
cls.signal_period)
+ # Issue #25277: Use faulthandler to try to debug a hang on FreeBSD
+ if hasattr(faulthandler, 'dump_traceback_later'):
+ faulthandler.dump_traceback_later(10 * 60, exit=True)
+
@classmethod
def stop_alarm(cls):
signal.setitimer(signal.ITIMER_REAL, 0, 0)
@@ -58,6 +62,8 @@ class EINTRBaseTest(unittest.TestCase):
def tearDownClass(cls):
cls.stop_alarm()
signal.signal(signal.SIGALRM, cls.orig_handler)
+ if hasattr(faulthandler, 'cancel_dump_traceback_later'):
+ faulthandler.cancel_dump_traceback_later()
def subprocess(self, *args, **kw):
cmd_args = (sys.executable, '-c') + args
@@ -77,6 +83,9 @@ class OSEINTRTest(EINTRBaseTest):
processes = [self.new_sleep_process() for _ in range(num)]
for _ in range(num):
wait_func()
+ # Call the Popen method to avoid a ResourceWarning
+ for proc in processes:
+ proc.wait()
def test_wait(self):
self._test_wait_multiple(os.wait)
@@ -88,6 +97,8 @@ class OSEINTRTest(EINTRBaseTest):
def _test_wait_single(self, wait_func):
proc = self.new_sleep_process()
wait_func(proc.pid)
+ # Call the Popen method to avoid a ResourceWarning
+ proc.wait()
def test_waitpid(self):
self._test_wait_single(lambda pid: os.waitpid(pid, 0))
diff --git a/Lib/test/exception_hierarchy.txt b/Lib/test/exception_hierarchy.txt
index 0513765..7333b2a 100644
--- a/Lib/test/exception_hierarchy.txt
+++ b/Lib/test/exception_hierarchy.txt
@@ -14,6 +14,7 @@ BaseException
+-- BufferError
+-- EOFError
+-- ImportError
+ +-- ModuleNotFoundError
+-- LookupError
| +-- IndexError
| +-- KeyError
diff --git a/Lib/test/libregrtest/__init__.py b/Lib/test/libregrtest/__init__.py
new file mode 100644
index 0000000..7ba0e6e
--- /dev/null
+++ b/Lib/test/libregrtest/__init__.py
@@ -0,0 +1,5 @@
+# We import importlib *ASAP* in order to test #15386
+import importlib
+
+from test.libregrtest.cmdline import _parse_args, RESOURCE_NAMES
+from test.libregrtest.main import main
diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py
new file mode 100644
index 0000000..891b00c
--- /dev/null
+++ b/Lib/test/libregrtest/cmdline.py
@@ -0,0 +1,347 @@
+import argparse
+import os
+import sys
+from test import support
+
+
+USAGE = """\
+python -m test [options] [test_name1 [test_name2 ...]]
+python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]]
+"""
+
+DESCRIPTION = """\
+Run Python regression tests.
+
+If no arguments or options are provided, finds all files matching
+the pattern "test_*" in the Lib/test subdirectory and runs
+them in alphabetical order (but see -M and -u, below, for exceptions).
+
+For more rigorous testing, it is useful to use the following
+command line:
+
+python -E -Wd -m test [options] [test_name1 ...]
+"""
+
+EPILOG = """\
+Additional option details:
+
+-r randomizes test execution order. You can use --randseed=int to provide an
+int seed value for the randomizer; this is useful for reproducing troublesome
+test orders.
+
+-s On the first invocation of regrtest using -s, the first test file found
+or the first test file given on the command line is run, and the name of
+the next test is recorded in a file named pynexttest. If run from the
+Python build directory, pynexttest is located in the 'build' subdirectory,
+otherwise it is located in tempfile.gettempdir(). On subsequent runs,
+the test in pynexttest is run, and the next test is written to pynexttest.
+When the last test has been run, pynexttest is deleted. In this way it
+is possible to single step through the test files. This is useful when
+doing memory analysis on the Python interpreter, which process tends to
+consume too many resources to run the full regression test non-stop.
+
+-S is used to continue running tests after an aborted run. It will
+maintain the order a standard run (ie, this assumes -r is not used).
+This is useful after the tests have prematurely stopped for some external
+reason and you want to start running from where you left off rather
+than starting from the beginning.
+
+-f reads the names of tests from the file given as f's argument, one
+or more test names per line. Whitespace is ignored. Blank lines and
+lines beginning with '#' are ignored. This is especially useful for
+whittling down failures involving interactions among tests.
+
+-L causes the leaks(1) command to be run just before exit if it exists.
+leaks(1) is available on Mac OS X and presumably on some other
+FreeBSD-derived systems.
+
+-R runs each test several times and examines sys.gettotalrefcount() to
+see if the test appears to be leaking references. The argument should
+be of the form stab:run:fname where 'stab' is the number of times the
+test is run to let gettotalrefcount settle down, 'run' is the number
+of times further it is run and 'fname' is the name of the file the
+reports are written to. These parameters all have defaults (5, 4 and
+"reflog.txt" respectively), and the minimal invocation is '-R :'.
+
+-M runs tests that require an exorbitant amount of memory. These tests
+typically try to ascertain containers keep working when containing more than
+2 billion objects, which only works on 64-bit systems. There are also some
+tests that try to exhaust the address space of the process, which only makes
+sense on 32-bit systems with at least 2Gb of memory. The passed-in memlimit,
+which is a string in the form of '2.5Gb', determines howmuch memory the
+tests will limit themselves to (but they may go slightly over.) The number
+shouldn't be more memory than the machine has (including swap memory). You
+should also keep in mind that swap memory is generally much, much slower
+than RAM, and setting memlimit to all available RAM or higher will heavily
+tax the machine. On the other hand, it is no use running these tests with a
+limit of less than 2.5Gb, and many require more than 20Gb. Tests that expect
+to use more than memlimit memory will be skipped. The big-memory tests
+generally run very, very long.
+
+-u is used to specify which special resource intensive tests to run,
+such as those requiring large file support or network connectivity.
+The argument is a comma-separated list of words indicating the
+resources to test. Currently only the following are defined:
+
+ all - Enable all special resources.
+
+ none - Disable all special resources (this is the default).
+
+ audio - Tests that use the audio device. (There are known
+ cases of broken audio drivers that can crash Python or
+ even the Linux kernel.)
+
+ curses - Tests that use curses and will modify the terminal's
+ state and output modes.
+
+ largefile - It is okay to run some test that may create huge
+ files. These tests can take a long time and may
+ consume >2GB of disk space temporarily.
+
+ network - It is okay to run tests that use external network
+ resource, e.g. testing SSL support for sockets.
+
+ decimal - Test the decimal module against a large suite that
+ verifies compliance with standards.
+
+ cpu - Used for certain CPU-heavy tests.
+
+ subprocess Run all tests for the subprocess module.
+
+ urlfetch - It is okay to download files required on testing.
+
+ gui - Run tests that require a running GUI.
+
+ tzdata - Run tests that require timezone data.
+
+To enable all resources except one, use '-uall,-<resource>'. For
+example, to run all the tests except for the gui tests, give the
+option '-uall,-gui'.
+"""
+
+
+RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network',
+ 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', 'tzdata')
+
+class _ArgParser(argparse.ArgumentParser):
+
+ def error(self, message):
+ super().error(message + "\nPass -h or --help for complete help.")
+
+
+def _create_parser():
+ # Set prog to prevent the uninformative "__main__.py" from displaying in
+ # error messages when using "python -m test ...".
+ parser = _ArgParser(prog='regrtest.py',
+ usage=USAGE,
+ description=DESCRIPTION,
+ epilog=EPILOG,
+ add_help=False,
+ formatter_class=argparse.RawDescriptionHelpFormatter)
+
+ # Arguments with this clause added to its help are described further in
+ # the epilog's "Additional option details" section.
+ more_details = ' See the section at bottom for more details.'
+
+ group = parser.add_argument_group('General options')
+ # We add help explicitly to control what argument group it renders under.
+ group.add_argument('-h', '--help', action='help',
+ help='show this help message and exit')
+ group.add_argument('--timeout', metavar='TIMEOUT', type=float,
+ help='dump the traceback and exit if a test takes '
+ 'more than TIMEOUT seconds; disabled if TIMEOUT '
+ 'is negative or equals to zero')
+ group.add_argument('--wait', action='store_true',
+ help='wait for user input, e.g., allow a debugger '
+ 'to be attached')
+ group.add_argument('--slaveargs', metavar='ARGS')
+ group.add_argument('-S', '--start', metavar='START',
+ help='the name of the test at which to start.' +
+ more_details)
+
+ group = parser.add_argument_group('Verbosity')
+ group.add_argument('-v', '--verbose', action='count',
+ help='run tests in verbose mode with output to stdout')
+ group.add_argument('-w', '--verbose2', action='store_true',
+ help='re-run failed tests in verbose mode')
+ group.add_argument('-W', '--verbose3', action='store_true',
+ help='display test output on failure')
+ group.add_argument('-q', '--quiet', action='store_true',
+ help='no output unless one or more tests fail')
+ group.add_argument('-o', '--slowest', action='store_true', dest='print_slow',
+ help='print the slowest 10 tests')
+ group.add_argument('--header', action='store_true',
+ help='print header with interpreter info')
+
+ group = parser.add_argument_group('Selecting tests')
+ group.add_argument('-r', '--randomize', action='store_true',
+ help='randomize test execution order.' + more_details)
+ group.add_argument('--randseed', metavar='SEED',
+ dest='random_seed', type=int,
+ help='pass a random seed to reproduce a previous '
+ 'random run')
+ group.add_argument('-f', '--fromfile', metavar='FILE',
+ help='read names of tests to run from a file.' +
+ more_details)
+ group.add_argument('-x', '--exclude', action='store_true',
+ help='arguments are tests to *exclude*')
+ group.add_argument('-s', '--single', action='store_true',
+ help='single step through a set of tests.' +
+ more_details)
+ group.add_argument('-m', '--match', metavar='PAT',
+ dest='match_tests',
+ help='match test cases and methods with glob pattern PAT')
+ group.add_argument('-G', '--failfast', action='store_true',
+ help='fail as soon as a test fails (only with -v or -W)')
+ group.add_argument('-u', '--use', metavar='RES1,RES2,...',
+ action='append', type=resources_list,
+ help='specify which special resource intensive tests '
+ 'to run.' + more_details)
+ group.add_argument('-M', '--memlimit', metavar='LIMIT',
+ help='run very large memory-consuming tests.' +
+ more_details)
+ group.add_argument('--testdir', metavar='DIR',
+ type=relative_filename,
+ help='execute test files in the specified directory '
+ '(instead of the Python stdlib test suite)')
+
+ group = parser.add_argument_group('Special runs')
+ group.add_argument('-l', '--findleaks', action='store_true',
+ help='if GC is available detect tests that leak memory')
+ group.add_argument('-L', '--runleaks', action='store_true',
+ help='run the leaks(1) command just before exit.' +
+ more_details)
+ group.add_argument('-R', '--huntrleaks', metavar='RUNCOUNTS',
+ type=huntrleaks,
+ help='search for reference leaks (needs debug build, '
+ 'very slow).' + more_details)
+ group.add_argument('-j', '--multiprocess', metavar='PROCESSES',
+ dest='use_mp', type=int,
+ help='run PROCESSES processes at once')
+ group.add_argument('-T', '--coverage', action='store_true',
+ dest='trace',
+ help='turn on code coverage tracing using the trace '
+ 'module')
+ group.add_argument('-D', '--coverdir', metavar='DIR',
+ type=relative_filename,
+ help='directory where coverage files are put')
+ group.add_argument('-N', '--nocoverdir',
+ action='store_const', const=None, dest='coverdir',
+ help='put coverage files alongside modules')
+ group.add_argument('-t', '--threshold', metavar='THRESHOLD',
+ type=int,
+ help='call gc.set_threshold(THRESHOLD)')
+ group.add_argument('-n', '--nowindows', action='store_true',
+ help='suppress error message boxes on Windows')
+ group.add_argument('-F', '--forever', action='store_true',
+ help='run the specified tests in a loop, until an '
+ 'error happens')
+ group.add_argument('--list-tests', action='store_true',
+ help="only write the name of tests that will be run, "
+ "don't execute them")
+ group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
+ help='enable Profile Guided Optimization training')
+
+ return parser
+
+
+def relative_filename(string):
+ # CWD is replaced with a temporary dir before calling main(), so we
+ # join it with the saved CWD so it ends up where the user expects.
+ return os.path.join(support.SAVEDCWD, string)
+
+
+def huntrleaks(string):
+ args = string.split(':')
+ if len(args) not in (2, 3):
+ raise argparse.ArgumentTypeError(
+ 'needs 2 or 3 colon-separated arguments')
+ nwarmup = int(args[0]) if args[0] else 5
+ ntracked = int(args[1]) if args[1] else 4
+ fname = args[2] if len(args) > 2 and args[2] else 'reflog.txt'
+ return nwarmup, ntracked, fname
+
+
+def resources_list(string):
+ u = [x.lower() for x in string.split(',')]
+ for r in u:
+ if r == 'all' or r == 'none':
+ continue
+ if r[0] == '-':
+ r = r[1:]
+ if r not in RESOURCE_NAMES:
+ raise argparse.ArgumentTypeError('invalid resource: ' + r)
+ return u
+
+
+def _parse_args(args, **kwargs):
+ # Defaults
+ ns = argparse.Namespace(testdir=None, verbose=0, quiet=False,
+ exclude=False, single=False, randomize=False, fromfile=None,
+ findleaks=False, use_resources=None, trace=False, coverdir='coverage',
+ runleaks=False, huntrleaks=False, verbose2=False, print_slow=False,
+ random_seed=None, use_mp=None, verbose3=False, forever=False,
+ header=False, failfast=False, match_tests=None, pgo=False)
+ for k, v in kwargs.items():
+ if not hasattr(ns, k):
+ raise TypeError('%r is an invalid keyword argument '
+ 'for this function' % k)
+ setattr(ns, k, v)
+ if ns.use_resources is None:
+ ns.use_resources = []
+
+ parser = _create_parser()
+ # Issue #14191: argparse doesn't support "intermixed" positional and
+ # optional arguments. Use parse_known_args() as workaround.
+ ns.args = parser.parse_known_args(args=args, namespace=ns)[1]
+ for arg in ns.args:
+ if arg.startswith('-'):
+ parser.error("unrecognized arguments: %s" % arg)
+ sys.exit(1)
+
+ if ns.single and ns.fromfile:
+ parser.error("-s and -f don't go together!")
+ if ns.use_mp and ns.trace:
+ parser.error("-T and -j don't go together!")
+ if ns.use_mp and ns.findleaks:
+ parser.error("-l and -j don't go together!")
+ if ns.failfast and not (ns.verbose or ns.verbose3):
+ parser.error("-G/--failfast needs either -v or -W")
+ if ns.pgo and (ns.verbose or ns.verbose2 or ns.verbose3):
+ parser.error("--pgo/-v don't go together!")
+
+ if ns.nowindows:
+ print("Warning: the --nowindows (-n) option is deprecated. "
+ "Use -vv to display assertions in stderr.", file=sys.stderr)
+
+ if ns.quiet:
+ ns.verbose = 0
+ if ns.timeout is not None:
+ if ns.timeout <= 0:
+ ns.timeout = None
+ if ns.use_mp is not None:
+ if ns.use_mp <= 0:
+ # Use all cores + extras for tests that like to sleep
+ ns.use_mp = 2 + (os.cpu_count() or 1)
+ if ns.use:
+ for a in ns.use:
+ for r in a:
+ if r == 'all':
+ ns.use_resources[:] = RESOURCE_NAMES
+ continue
+ if r == 'none':
+ del ns.use_resources[:]
+ continue
+ remove = False
+ if r[0] == '-':
+ remove = True
+ r = r[1:]
+ if remove:
+ if r in ns.use_resources:
+ ns.use_resources.remove(r)
+ elif r not in ns.use_resources:
+ ns.use_resources.append(r)
+ if ns.random_seed is not None:
+ ns.randomize = True
+
+ return ns
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
new file mode 100644
index 0000000..f0effc9
--- /dev/null
+++ b/Lib/test/libregrtest/main.py
@@ -0,0 +1,532 @@
+import datetime
+import faulthandler
+import locale
+import os
+import platform
+import random
+import re
+import sys
+import sysconfig
+import tempfile
+import textwrap
+import time
+from test.libregrtest.cmdline import _parse_args
+from test.libregrtest.runtest import (
+ findtests, runtest,
+ STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED,
+ INTERRUPTED, CHILD_ERROR,
+ PROGRESS_MIN_TIME, format_test_result)
+from test.libregrtest.setup import setup_tests
+from test import support
+try:
+ import gc
+except ImportError:
+ gc = None
+
+
+# When tests are run from the Python build directory, it is best practice
+# to keep the test files in a subfolder. This eases the cleanup of leftover
+# files using the "make distclean" command.
+if sysconfig.is_python_build():
+ TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
+else:
+ TEMPDIR = tempfile.gettempdir()
+TEMPDIR = os.path.abspath(TEMPDIR)
+
+
+def format_duration(seconds):
+ if seconds < 1.0:
+ return '%.0f ms' % (seconds * 1e3)
+ if seconds < 60.0:
+ return '%.0f sec' % seconds
+
+ minutes, seconds = divmod(seconds, 60.0)
+ return '%.0f min %.0f sec' % (minutes, seconds)
+
+
+class Regrtest:
+ """Execute a test suite.
+
+ This also parses command-line options and modifies its behavior
+ accordingly.
+
+ tests -- a list of strings containing test names (optional)
+ testdir -- the directory in which to look for tests (optional)
+
+ Users other than the Python test suite will certainly want to
+ specify testdir; if it's omitted, the directory containing the
+ Python test suite is searched for.
+
+ If the tests argument is omitted, the tests listed on the
+ command-line will be used. If that's empty, too, then all *.py
+ files beginning with test_ will be used.
+
+ The other default arguments (verbose, quiet, exclude,
+ single, randomize, findleaks, use_resources, trace, coverdir,
+ print_slow, and random_seed) allow programmers calling main()
+ directly to set the values that would normally be set by flags
+ on the command line.
+ """
+ def __init__(self):
+ # Namespace of command line options
+ self.ns = None
+
+ # tests
+ self.tests = []
+ self.selected = []
+
+ # test results
+ self.good = []
+ self.bad = []
+ self.skipped = []
+ self.resource_denieds = []
+ self.environment_changed = []
+ self.interrupted = False
+
+ # used by --slow
+ self.test_times = []
+
+ # used by --coverage, trace.Trace instance
+ self.tracer = None
+
+ # used by --findleaks, store for gc.garbage
+ self.found_garbage = []
+
+ # used to display the progress bar "[ 3/100]"
+ self.start_time = time.monotonic()
+ self.test_count = ''
+ self.test_count_width = 1
+
+ # used by --single
+ self.next_single_test = None
+ self.next_single_filename = None
+
+ def accumulate_result(self, test, result):
+ ok, test_time = result
+ if ok not in (CHILD_ERROR, INTERRUPTED):
+ self.test_times.append((test_time, test))
+ if ok == PASSED:
+ self.good.append(test)
+ elif ok == FAILED:
+ self.bad.append(test)
+ elif ok == ENV_CHANGED:
+ self.environment_changed.append(test)
+ elif ok == SKIPPED:
+ self.skipped.append(test)
+ elif ok == RESOURCE_DENIED:
+ self.skipped.append(test)
+ self.resource_denieds.append(test)
+
+ def display_progress(self, test_index, test):
+ if self.ns.quiet:
+ return
+ if self.bad and not self.ns.pgo:
+ fmt = "{time} [{test_index:{count_width}}{test_count}/{nbad}] {test_name}"
+ else:
+ fmt = "{time} [{test_index:{count_width}}{test_count}] {test_name}"
+ test_time = time.monotonic() - self.start_time
+ test_time = datetime.timedelta(seconds=int(test_time))
+ line = fmt.format(count_width=self.test_count_width,
+ test_index=test_index,
+ test_count=self.test_count,
+ nbad=len(self.bad),
+ test_name=test,
+ time=test_time)
+ print(line, flush=True)
+
+ def parse_args(self, kwargs):
+ ns = _parse_args(sys.argv[1:], **kwargs)
+
+ if ns.timeout and not hasattr(faulthandler, 'dump_traceback_later'):
+ print("Warning: The timeout option requires "
+ "faulthandler.dump_traceback_later", file=sys.stderr)
+ ns.timeout = None
+
+ if ns.threshold is not None and gc is None:
+ print('No GC available, ignore --threshold.', file=sys.stderr)
+ ns.threshold = None
+
+ if ns.findleaks:
+ if gc is not None:
+ # Uncomment the line below to report garbage that is not
+ # freeable by reference counting alone. By default only
+ # garbage that is not collectable by the GC is reported.
+ pass
+ #gc.set_debug(gc.DEBUG_SAVEALL)
+ else:
+ print('No GC available, disabling --findleaks',
+ file=sys.stderr)
+ ns.findleaks = False
+
+ # Strip .py extensions.
+ removepy(ns.args)
+
+ return ns
+
+ def find_tests(self, tests):
+ self.tests = tests
+
+ if self.ns.single:
+ self.next_single_filename = os.path.join(TEMPDIR, 'pynexttest')
+ try:
+ with open(self.next_single_filename, 'r') as fp:
+ next_test = fp.read().strip()
+ self.tests = [next_test]
+ except OSError:
+ pass
+
+ if self.ns.fromfile:
+ self.tests = []
+ # regex to match 'test_builtin' in line:
+ # '0:00:00 [ 4/400] test_builtin -- test_dict took 1 sec'
+ regex = (r'^(?:[0-9]+:[0-9]+:[0-9]+ *)?'
+ r'(?:\[[0-9/ ]+\] *)?'
+ r'(test_[a-zA-Z0-9_]+)')
+ regex = re.compile(regex)
+ with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp:
+ for line in fp:
+ line = line.strip()
+ if line.startswith('#'):
+ continue
+ match = regex.match(line)
+ if match is None:
+ continue
+ self.tests.append(match.group(1))
+
+ removepy(self.tests)
+
+ stdtests = STDTESTS[:]
+ nottests = NOTTESTS.copy()
+ if self.ns.exclude:
+ for arg in self.ns.args:
+ if arg in stdtests:
+ stdtests.remove(arg)
+ nottests.add(arg)
+ self.ns.args = []
+
+ # if testdir is set, then we are not running the python tests suite, so
+ # don't add default tests to be executed or skipped (pass empty values)
+ if self.ns.testdir:
+ alltests = findtests(self.ns.testdir, list(), set())
+ else:
+ alltests = findtests(self.ns.testdir, stdtests, nottests)
+
+ if not self.ns.fromfile:
+ self.selected = self.tests or self.ns.args or alltests
+ else:
+ self.selected = self.tests
+ if self.ns.single:
+ self.selected = self.selected[:1]
+ try:
+ pos = alltests.index(self.selected[0])
+ self.next_single_test = alltests[pos + 1]
+ except IndexError:
+ pass
+
+ # Remove all the selected tests that precede start if it's set.
+ if self.ns.start:
+ try:
+ del self.selected[:self.selected.index(self.ns.start)]
+ except ValueError:
+ print("Couldn't find starting test (%s), using all tests"
+ % self.ns.start, file=sys.stderr)
+
+ if self.ns.randomize:
+ if self.ns.random_seed is None:
+ self.ns.random_seed = random.randrange(10000000)
+ random.seed(self.ns.random_seed)
+ random.shuffle(self.selected)
+
+ def list_tests(self):
+ for name in self.selected:
+ print(name)
+
+ def rerun_failed_tests(self):
+ self.ns.verbose = True
+ self.ns.failfast = False
+ self.ns.verbose3 = False
+ self.ns.match_tests = None
+
+ print("Re-running failed tests in verbose mode")
+ for test in self.bad[:]:
+ print("Re-running test %r in verbose mode" % test, flush=True)
+ try:
+ self.ns.verbose = True
+ ok = runtest(self.ns, test)
+ except KeyboardInterrupt:
+ self.interrupted = True
+ # print a newline separate from the ^C
+ print()
+ break
+ else:
+ if ok[0] in {PASSED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED}:
+ self.bad.remove(test)
+ else:
+ if self.bad:
+ print(count(len(self.bad), 'test'), "failed again:")
+ printlist(self.bad)
+
+ def display_result(self):
+ if self.interrupted:
+ # print a newline after ^C
+ print()
+ print("Test suite interrupted by signal SIGINT.")
+ executed = set(self.good) | set(self.bad) | set(self.skipped)
+ omitted = set(self.selected) - executed
+ print(count(len(omitted), "test"), "omitted:")
+ printlist(omitted)
+
+ # If running the test suite for PGO then no one cares about
+ # results.
+ if self.ns.pgo:
+ return
+
+ if self.good and not self.ns.quiet:
+ if (not self.bad
+ and not self.skipped
+ and not self.interrupted
+ and len(self.good) > 1):
+ print("All", end=' ')
+ print(count(len(self.good), "test"), "OK.")
+
+ if self.ns.print_slow:
+ self.test_times.sort(reverse=True)
+ print()
+ print("10 slowest tests:")
+ for time, test in self.test_times[:10]:
+ print("- %s: %s" % (test, format_duration(time)))
+
+ if self.bad:
+ print()
+ print(count(len(self.bad), "test"), "failed:")
+ printlist(self.bad)
+
+ if self.environment_changed:
+ print()
+ print("{} altered the execution environment:".format(
+ count(len(self.environment_changed), "test")))
+ printlist(self.environment_changed)
+
+ if self.skipped and not self.ns.quiet:
+ print()
+ print(count(len(self.skipped), "test"), "skipped:")
+ printlist(self.skipped)
+
+ def run_tests_sequential(self):
+ if self.ns.trace:
+ import trace
+ self.tracer = trace.Trace(trace=False, count=True)
+
+ save_modules = sys.modules.keys()
+
+ print("Run tests sequentially")
+
+ previous_test = None
+ for test_index, test in enumerate(self.tests, 1):
+ start_time = time.monotonic()
+
+ text = test
+ if previous_test:
+ text = '%s -- %s' % (text, previous_test)
+ self.display_progress(test_index, text)
+
+ if self.tracer:
+ # If we're tracing code coverage, then we don't exit with status
+ # if on a false return value from main.
+ cmd = ('result = runtest(self.ns, test); '
+ 'self.accumulate_result(test, result)')
+ ns = dict(locals())
+ self.tracer.runctx(cmd, globals=globals(), locals=ns)
+ result = ns['result']
+ else:
+ try:
+ result = runtest(self.ns, test)
+ except KeyboardInterrupt:
+ self.interrupted = True
+ self.accumulate_result(test, (INTERRUPTED, None))
+ break
+ else:
+ self.accumulate_result(test, result)
+
+ previous_test = format_test_result(test, result[0])
+ test_time = time.monotonic() - start_time
+ if test_time >= PROGRESS_MIN_TIME:
+ previous_test = "%s in %s" % (previous_test, format_duration(test_time))
+ elif result[0] == PASSED:
+ # be quiet: say nothing if the test passed shortly
+ previous_test = None
+
+ if self.ns.findleaks:
+ gc.collect()
+ if gc.garbage:
+ print("Warning: test created", len(gc.garbage), end=' ')
+ print("uncollectable object(s).")
+ # move the uncollectable objects somewhere so we don't see
+ # them again
+ self.found_garbage.extend(gc.garbage)
+ del gc.garbage[:]
+
+ # Unload the newly imported modules (best effort finalization)
+ for module in sys.modules.keys():
+ if module not in save_modules and module.startswith("test."):
+ support.unload(module)
+
+ if previous_test:
+ print(previous_test)
+
+ def _test_forever(self, tests):
+ while True:
+ for test in tests:
+ yield test
+ if self.bad:
+ return
+
+ def run_tests(self):
+ # For a partial run, we do not need to clutter the output.
+ if (self.ns.verbose
+ or self.ns.header
+ or not (self.ns.pgo or self.ns.quiet or self.ns.single
+ or self.tests or self.ns.args)):
+ # Print basic platform information
+ print("==", platform.python_implementation(), *sys.version.split())
+ print("== ", platform.platform(aliased=True),
+ "%s-endian" % sys.byteorder)
+ print("== ", "hash algorithm:", sys.hash_info.algorithm,
+ "64bit" if sys.maxsize > 2**32 else "32bit")
+ print("== cwd:", os.getcwd())
+ print("== encodings: locale=%s, FS=%s"
+ % (locale.getpreferredencoding(False),
+ sys.getfilesystemencoding()))
+ print("Testing with flags:", sys.flags)
+
+ if self.ns.randomize:
+ print("Using random seed", self.ns.random_seed)
+
+ if self.ns.forever:
+ self.tests = self._test_forever(list(self.selected))
+ self.test_count = ''
+ self.test_count_width = 3
+ else:
+ self.tests = iter(self.selected)
+ self.test_count = '/{}'.format(len(self.selected))
+ self.test_count_width = len(self.test_count) - 1
+
+ if self.ns.use_mp:
+ from test.libregrtest.runtest_mp import run_tests_multiprocess
+ run_tests_multiprocess(self)
+ else:
+ self.run_tests_sequential()
+
+ def finalize(self):
+ if self.next_single_filename:
+ if self.next_single_test:
+ with open(self.next_single_filename, 'w') as fp:
+ fp.write(self.next_single_test + '\n')
+ else:
+ os.unlink(self.next_single_filename)
+
+ if self.tracer:
+ r = self.tracer.results()
+ r.write_results(show_missing=True, summary=True,
+ coverdir=self.ns.coverdir)
+
+ print()
+ duration = time.monotonic() - self.start_time
+ print("Total duration: %s" % format_duration(duration))
+
+ if self.bad:
+ result = "FAILURE"
+ elif self.interrupted:
+ result = "INTERRUPTED"
+ else:
+ result = "SUCCESS"
+ print("Tests result: %s" % result)
+
+ if self.ns.runleaks:
+ os.system("leaks %d" % os.getpid())
+
+ def main(self, tests=None, **kwargs):
+ global TEMPDIR
+
+ if sysconfig.is_python_build():
+ try:
+ os.mkdir(TEMPDIR)
+ except FileExistsError:
+ pass
+
+ # Define a writable temp dir that will be used as cwd while running
+ # the tests. The name of the dir includes the pid to allow parallel
+ # testing (see the -j option).
+ test_cwd = 'test_python_{}'.format(os.getpid())
+ test_cwd = os.path.join(TEMPDIR, test_cwd)
+
+ # Run the tests in a context manager that temporarily changes the CWD to a
+ # temporary and writable directory. If it's not possible to create or
+ # change the CWD, the original CWD will be used. The original CWD is
+ # available from support.SAVEDCWD.
+ with support.temp_cwd(test_cwd, quiet=True):
+ self._main(tests, kwargs)
+
+ def _main(self, tests, kwargs):
+ self.ns = self.parse_args(kwargs)
+
+ if self.ns.slaveargs is not None:
+ from test.libregrtest.runtest_mp import run_tests_slave
+ run_tests_slave(self.ns.slaveargs)
+
+ if self.ns.wait:
+ input("Press any key to continue...")
+
+ support.PGO = self.ns.pgo
+
+ setup_tests(self.ns)
+
+ self.find_tests(tests)
+
+ if self.ns.list_tests:
+ self.list_tests()
+ sys.exit(0)
+
+ self.run_tests()
+ self.display_result()
+
+ if self.ns.verbose2 and self.bad:
+ self.rerun_failed_tests()
+
+ self.finalize()
+ sys.exit(len(self.bad) > 0 or self.interrupted)
+
+
+def removepy(names):
+ if not names:
+ return
+ for idx, name in enumerate(names):
+ basename, ext = os.path.splitext(name)
+ if ext == '.py':
+ names[idx] = basename
+
+
+def count(n, word):
+ if n == 1:
+ return "%d %s" % (n, word)
+ else:
+ return "%d %ss" % (n, word)
+
+
+def printlist(x, width=70, indent=4):
+ """Print the elements of iterable x to stdout.
+
+ Optional arg width (default 70) is the maximum line length.
+ Optional arg indent (default 4) is the number of blanks with which to
+ begin each line.
+ """
+
+ blanks = ' ' * indent
+ # Print the sorted list: 'x' may be a '--random' list or a set()
+ print(textwrap.fill(' '.join(str(elt) for elt in sorted(x)), width,
+ initial_indent=blanks, subsequent_indent=blanks))
+
+
+def main(tests=None, **kwargs):
+ """Run the Python suite."""
+ Regrtest().main(tests=tests, **kwargs)
diff --git a/Lib/test/libregrtest/refleak.py b/Lib/test/libregrtest/refleak.py
new file mode 100644
index 0000000..59dc49f
--- /dev/null
+++ b/Lib/test/libregrtest/refleak.py
@@ -0,0 +1,202 @@
+import errno
+import os
+import re
+import sys
+import warnings
+from inspect import isabstract
+from test import support
+
+
+try:
+ MAXFD = os.sysconf("SC_OPEN_MAX")
+except Exception:
+ MAXFD = 256
+
+
+def fd_count():
+ """Count the number of open file descriptors"""
+ if sys.platform.startswith(('linux', 'freebsd')):
+ try:
+ names = os.listdir("/proc/self/fd")
+ return len(names)
+ except FileNotFoundError:
+ pass
+
+ count = 0
+ for fd in range(MAXFD):
+ try:
+ # Prefer dup() over fstat(). fstat() can require input/output
+ # whereas dup() doesn't.
+ fd2 = os.dup(fd)
+ except OSError as e:
+ if e.errno != errno.EBADF:
+ raise
+ else:
+ os.close(fd2)
+ count += 1
+ return count
+
+
+def dash_R(the_module, test, indirect_test, huntrleaks):
+ """Run a test multiple times, looking for reference leaks.
+
+ Returns:
+ False if the test didn't leak references; True if we detected refleaks.
+ """
+ # This code is hackish and inelegant, but it seems to do the job.
+ import copyreg
+ import collections.abc
+
+ if not hasattr(sys, 'gettotalrefcount'):
+ raise Exception("Tracking reference leaks requires a debug build "
+ "of Python")
+
+ # Save current values for dash_R_cleanup() to restore.
+ fs = warnings.filters[:]
+ ps = copyreg.dispatch_table.copy()
+ pic = sys.path_importer_cache.copy()
+ try:
+ import zipimport
+ except ImportError:
+ zdc = None # Run unmodified on platforms without zipimport support
+ else:
+ zdc = zipimport._zip_directory_cache.copy()
+ abcs = {}
+ for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]:
+ if not isabstract(abc):
+ continue
+ for obj in abc.__subclasses__() + [abc]:
+ abcs[obj] = obj._abc_registry.copy()
+
+ nwarmup, ntracked, fname = huntrleaks
+ fname = os.path.join(support.SAVEDCWD, fname)
+ repcount = nwarmup + ntracked
+ rc_deltas = [0] * repcount
+ alloc_deltas = [0] * repcount
+ fd_deltas = [0] * repcount
+
+ print("beginning", repcount, "repetitions", file=sys.stderr)
+ print(("1234567890"*(repcount//10 + 1))[:repcount], file=sys.stderr,
+ flush=True)
+ # initialize variables to make pyflakes quiet
+ rc_before = alloc_before = fd_before = 0
+ for i in range(repcount):
+ indirect_test()
+ alloc_after, rc_after, fd_after = dash_R_cleanup(fs, ps, pic, zdc,
+ abcs)
+ print('.', end='', flush=True)
+ if i >= nwarmup:
+ rc_deltas[i] = rc_after - rc_before
+ alloc_deltas[i] = alloc_after - alloc_before
+ fd_deltas[i] = fd_after - fd_before
+ alloc_before = alloc_after
+ rc_before = rc_after
+ fd_before = fd_after
+ print(file=sys.stderr)
+ # These checkers return False on success, True on failure
+ def check_rc_deltas(deltas):
+ return any(deltas)
+ def check_alloc_deltas(deltas):
+ # At least 1/3rd of 0s
+ if 3 * deltas.count(0) < len(deltas):
+ return True
+ # Nothing else than 1s, 0s and -1s
+ if not set(deltas) <= {1,0,-1}:
+ return True
+ return False
+ failed = False
+ for deltas, item_name, checker in [
+ (rc_deltas, 'references', check_rc_deltas),
+ (alloc_deltas, 'memory blocks', check_alloc_deltas),
+ (fd_deltas, 'file descriptors', check_rc_deltas)]:
+ if checker(deltas):
+ msg = '%s leaked %s %s, sum=%s' % (
+ test, deltas[nwarmup:], item_name, sum(deltas))
+ print(msg, file=sys.stderr, flush=True)
+ with open(fname, "a") as refrep:
+ print(msg, file=refrep)
+ refrep.flush()
+ failed = True
+ return failed
+
+
+def dash_R_cleanup(fs, ps, pic, zdc, abcs):
+ import gc, copyreg
+ import _strptime, linecache
+ import urllib.parse, urllib.request, mimetypes, doctest
+ import struct, filecmp, collections.abc
+ from distutils.dir_util import _path_created
+ from weakref import WeakSet
+
+ # Clear the warnings registry, so they can be displayed again
+ for mod in sys.modules.values():
+ if hasattr(mod, '__warningregistry__'):
+ del mod.__warningregistry__
+
+ # Restore some original values.
+ warnings.filters[:] = fs
+ copyreg.dispatch_table.clear()
+ copyreg.dispatch_table.update(ps)
+ sys.path_importer_cache.clear()
+ sys.path_importer_cache.update(pic)
+ try:
+ import zipimport
+ except ImportError:
+ pass # Run unmodified on platforms without zipimport support
+ else:
+ zipimport._zip_directory_cache.clear()
+ zipimport._zip_directory_cache.update(zdc)
+
+ # clear type cache
+ sys._clear_type_cache()
+
+ # Clear ABC registries, restoring previously saved ABC registries.
+ for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]:
+ if not isabstract(abc):
+ continue
+ for obj in abc.__subclasses__() + [abc]:
+ obj._abc_registry = abcs.get(obj, WeakSet()).copy()
+ obj._abc_cache.clear()
+ obj._abc_negative_cache.clear()
+
+ # Flush standard output, so that buffered data is sent to the OS and
+ # associated Python objects are reclaimed.
+ for stream in (sys.stdout, sys.stderr, sys.__stdout__, sys.__stderr__):
+ if stream is not None:
+ stream.flush()
+
+ # Clear assorted module caches.
+ _path_created.clear()
+ re.purge()
+ _strptime._regex_cache.clear()
+ urllib.parse.clear_cache()
+ urllib.request.urlcleanup()
+ linecache.clearcache()
+ mimetypes._default_mime_types()
+ filecmp._cache.clear()
+ struct._clearcache()
+ doctest.master = None
+ try:
+ import ctypes
+ except ImportError:
+ # Don't worry about resetting the cache if ctypes is not supported
+ pass
+ else:
+ ctypes._reset_cache()
+
+ # Collect cyclic trash and read memory statistics immediately after.
+ func1 = sys.getallocatedblocks
+ func2 = sys.gettotalrefcount
+ gc.collect()
+ return func1(), func2(), fd_count()
+
+
+def warm_caches():
+ # char cache
+ s = bytes(range(256))
+ for i in range(256):
+ s[i:i+1]
+ # unicode cache
+ [chr(i) for i in range(256)]
+ # int cache
+ list(range(-5, 257))
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
new file mode 100644
index 0000000..6282543
--- /dev/null
+++ b/Lib/test/libregrtest/runtest.py
@@ -0,0 +1,244 @@
+import faulthandler
+import importlib
+import io
+import os
+import sys
+import time
+import traceback
+import unittest
+from test import support
+from test.libregrtest.refleak import dash_R
+from test.libregrtest.save_env import saved_test_environment
+
+
+# Test result constants.
+PASSED = 1
+FAILED = 0
+ENV_CHANGED = -1
+SKIPPED = -2
+RESOURCE_DENIED = -3
+INTERRUPTED = -4
+CHILD_ERROR = -5 # error in a child process
+
+_FORMAT_TEST_RESULT = {
+ PASSED: '%s passed',
+ FAILED: '%s failed',
+ ENV_CHANGED: '%s failed (env changed)',
+ SKIPPED: '%s skipped',
+ RESOURCE_DENIED: '%s skipped (resource denied)',
+ INTERRUPTED: '%s interrupted',
+ CHILD_ERROR: '%s crashed',
+}
+
+# Minimum duration of a test to display its duration or to mention that
+# the test is running in background
+PROGRESS_MIN_TIME = 30.0 # seconds
+
+# small set of tests to determine if we have a basically functioning interpreter
+# (i.e. if any of these fail, then anything else is likely to follow)
+STDTESTS = [
+ 'test_grammar',
+ 'test_opcodes',
+ 'test_dict',
+ 'test_builtin',
+ 'test_exceptions',
+ 'test_types',
+ 'test_unittest',
+ 'test_doctest',
+ 'test_doctest2',
+ 'test_support'
+]
+
+# set of tests that we don't want to be executed when using regrtest
+NOTTESTS = set()
+
+
+def format_test_result(test_name, result):
+ fmt = _FORMAT_TEST_RESULT.get(result, "%s")
+ return fmt % test_name
+
+
+def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
+ """Return a list of all applicable test modules."""
+ testdir = findtestdir(testdir)
+ names = os.listdir(testdir)
+ tests = []
+ others = set(stdtests) | nottests
+ for name in names:
+ mod, ext = os.path.splitext(name)
+ if mod[:5] == "test_" and ext in (".py", "") and mod not in others:
+ tests.append(mod)
+ return stdtests + sorted(tests)
+
+
+def runtest(ns, test):
+ """Run a single test.
+
+ ns -- regrtest namespace of options
+ test -- the name of the test
+
+ Returns the tuple (result, test_time), where result is one of the
+ constants:
+
+ INTERRUPTED KeyboardInterrupt when run under -j
+ RESOURCE_DENIED test skipped because resource denied
+ SKIPPED test skipped for some other reason
+ ENV_CHANGED test failed because it changed the execution environment
+ FAILED test failed
+ PASSED test passed
+ """
+
+ output_on_failure = ns.verbose3
+
+ use_timeout = (ns.timeout is not None)
+ if use_timeout:
+ faulthandler.dump_traceback_later(ns.timeout, exit=True)
+ try:
+ support.match_tests = ns.match_tests
+ if ns.failfast:
+ support.failfast = True
+ if output_on_failure:
+ support.verbose = True
+
+ # Reuse the same instance to all calls to runtest(). Some
+ # tests keep a reference to sys.stdout or sys.stderr
+ # (eg. test_argparse).
+ if runtest.stringio is None:
+ stream = io.StringIO()
+ runtest.stringio = stream
+ else:
+ stream = runtest.stringio
+ stream.seek(0)
+ stream.truncate()
+
+ orig_stdout = sys.stdout
+ orig_stderr = sys.stderr
+ try:
+ sys.stdout = stream
+ sys.stderr = stream
+ result = runtest_inner(ns, test, display_failure=False)
+ if result[0] != PASSED:
+ output = stream.getvalue()
+ orig_stderr.write(output)
+ orig_stderr.flush()
+ finally:
+ sys.stdout = orig_stdout
+ sys.stderr = orig_stderr
+ else:
+ support.verbose = ns.verbose # Tell tests to be moderately quiet
+ result = runtest_inner(ns, test, display_failure=not ns.verbose)
+ return result
+ finally:
+ if use_timeout:
+ faulthandler.cancel_dump_traceback_later()
+ cleanup_test_droppings(test, ns.verbose)
+runtest.stringio = None
+
+
+def runtest_inner(ns, test, display_failure=True):
+ support.unload(test)
+
+ test_time = 0.0
+ refleak = False # True if the test leaked references.
+ try:
+ if test.startswith('test.') or ns.testdir:
+ abstest = test
+ else:
+ # Always import it from the test package
+ abstest = 'test.' + test
+ with saved_test_environment(test, ns.verbose, ns.quiet, pgo=ns.pgo) as environment:
+ start_time = time.time()
+ the_module = importlib.import_module(abstest)
+ # If the test has a test_main, that will run the appropriate
+ # tests. If not, use normal unittest test loading.
+ test_runner = getattr(the_module, "test_main", None)
+ if test_runner is None:
+ def test_runner():
+ loader = unittest.TestLoader()
+ tests = loader.loadTestsFromModule(the_module)
+ for error in loader.errors:
+ print(error, file=sys.stderr)
+ if loader.errors:
+ raise Exception("errors while loading tests")
+ support.run_unittest(tests)
+ test_runner()
+ if ns.huntrleaks:
+ refleak = dash_R(the_module, test, test_runner, ns.huntrleaks)
+ test_time = time.time() - start_time
+ except support.ResourceDenied as msg:
+ if not ns.quiet and not ns.pgo:
+ print(test, "skipped --", msg, flush=True)
+ return RESOURCE_DENIED, test_time
+ except unittest.SkipTest as msg:
+ if not ns.quiet and not ns.pgo:
+ print(test, "skipped --", msg, flush=True)
+ return SKIPPED, test_time
+ except KeyboardInterrupt:
+ raise
+ except support.TestFailed as msg:
+ if not ns.pgo:
+ if display_failure:
+ print("test", test, "failed --", msg, file=sys.stderr,
+ flush=True)
+ else:
+ print("test", test, "failed", file=sys.stderr, flush=True)
+ return FAILED, test_time
+ except:
+ msg = traceback.format_exc()
+ if not ns.pgo:
+ print("test", test, "crashed --", msg, file=sys.stderr,
+ flush=True)
+ return FAILED, test_time
+ else:
+ if refleak:
+ return FAILED, test_time
+ if environment.changed:
+ return ENV_CHANGED, test_time
+ return PASSED, test_time
+
+
+def cleanup_test_droppings(testname, verbose):
+ import shutil
+ import stat
+ import gc
+
+ # First kill any dangling references to open files etc.
+ # This can also issue some ResourceWarnings which would otherwise get
+ # triggered during the following test run, and possibly produce failures.
+ gc.collect()
+
+ # Try to clean up junk commonly left behind. While tests shouldn't leave
+ # any files or directories behind, when a test fails that can be tedious
+ # for it to arrange. The consequences can be especially nasty on Windows,
+ # since if a test leaves a file open, it cannot be deleted by name (while
+ # there's nothing we can do about that here either, we can display the
+ # name of the offending test, which is a real help).
+ for name in (support.TESTFN,
+ "db_home",
+ ):
+ if not os.path.exists(name):
+ continue
+
+ if os.path.isdir(name):
+ kind, nuker = "directory", shutil.rmtree
+ elif os.path.isfile(name):
+ kind, nuker = "file", os.unlink
+ else:
+ raise SystemError("os.path says %r exists but is neither "
+ "directory nor file" % name)
+
+ if verbose:
+ print("%r left behind %s %r" % (testname, kind, name))
+ try:
+ # if we have chmod, fix possible permissions problems
+ # that might prevent cleanup
+ if (hasattr(os, 'chmod')):
+ os.chmod(name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
+ nuker(name)
+ except Exception as msg:
+ print(("%r left behind %s %r and it couldn't be "
+ "removed: %s" % (testname, kind, name, msg)), file=sys.stderr)
+
+
+def findtestdir(path=None):
+ return path or os.path.dirname(os.path.dirname(__file__)) or os.curdir
diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py
new file mode 100644
index 0000000..9604c16
--- /dev/null
+++ b/Lib/test/libregrtest/runtest_mp.py
@@ -0,0 +1,245 @@
+import faulthandler
+import json
+import os
+import queue
+import sys
+import time
+import traceback
+import types
+from test import support
+try:
+ import threading
+except ImportError:
+ print("Multiprocess option requires thread support")
+ sys.exit(2)
+
+from test.libregrtest.runtest import (
+ runtest, INTERRUPTED, CHILD_ERROR, PROGRESS_MIN_TIME,
+ format_test_result)
+from test.libregrtest.setup import setup_tests
+
+
+# Display the running tests if nothing happened last N seconds
+PROGRESS_UPDATE = 30.0 # seconds
+
+# If interrupted, display the wait progress every N seconds
+WAIT_PROGRESS = 2.0 # seconds
+
+
+def run_test_in_subprocess(testname, ns):
+ """Run the given test in a subprocess with --slaveargs.
+
+ ns is the option Namespace parsed from command-line arguments. regrtest
+ is invoked in a subprocess with the --slaveargs argument; when the
+ subprocess exits, its return code, stdout and stderr are returned as a
+ 3-tuple.
+ """
+ from subprocess import Popen, PIPE
+
+ ns_dict = vars(ns)
+ slaveargs = (ns_dict, testname)
+ slaveargs = json.dumps(slaveargs)
+
+ cmd = [sys.executable, *support.args_from_interpreter_flags(),
+ '-X', 'faulthandler',
+ '-m', 'test.regrtest',
+ '--slaveargs', slaveargs]
+ if ns.pgo:
+ cmd += ['--pgo']
+
+ # Running the child from the same working directory as regrtest's original
+ # invocation ensures that TEMPDIR for the child is the same when
+ # sysconfig.is_python_build() is true. See issue 15300.
+ popen = Popen(cmd,
+ stdout=PIPE, stderr=PIPE,
+ universal_newlines=True,
+ close_fds=(os.name != 'nt'),
+ cwd=support.SAVEDCWD)
+ with popen:
+ stdout, stderr = popen.communicate()
+ retcode = popen.wait()
+ return retcode, stdout, stderr
+
+
+def run_tests_slave(slaveargs):
+ ns_dict, testname = json.loads(slaveargs)
+ ns = types.SimpleNamespace(**ns_dict)
+
+ setup_tests(ns)
+
+ try:
+ result = runtest(ns, testname)
+ except KeyboardInterrupt:
+ result = INTERRUPTED, ''
+ except BaseException as e:
+ traceback.print_exc()
+ result = CHILD_ERROR, str(e)
+
+ print() # Force a newline (just in case)
+ print(json.dumps(result), flush=True)
+ sys.exit(0)
+
+
+# We do not use a generator so multiple threads can call next().
+class MultiprocessIterator:
+
+ """A thread-safe iterator over tests for multiprocess mode."""
+
+ def __init__(self, tests):
+ self.interrupted = False
+ self.lock = threading.Lock()
+ self.tests = tests
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ with self.lock:
+ if self.interrupted:
+ raise StopIteration('tests interrupted')
+ return next(self.tests)
+
+
+class MultiprocessThread(threading.Thread):
+ def __init__(self, pending, output, ns):
+ super().__init__()
+ self.pending = pending
+ self.output = output
+ self.ns = ns
+ self.current_test = None
+ self.start_time = None
+
+ def _runtest(self):
+ try:
+ test = next(self.pending)
+ except StopIteration:
+ self.output.put((None, None, None, None))
+ return True
+
+ try:
+ self.start_time = time.monotonic()
+ self.current_test = test
+
+ retcode, stdout, stderr = run_test_in_subprocess(test, self.ns)
+ finally:
+ self.current_test = None
+
+ stdout, _, result = stdout.strip().rpartition("\n")
+ if retcode != 0:
+ result = (CHILD_ERROR, "Exit code %s" % retcode)
+ self.output.put((test, stdout.rstrip(), stderr.rstrip(),
+ result))
+ return True
+
+ if not result:
+ self.output.put((None, None, None, None))
+ return True
+
+ result = json.loads(result)
+ self.output.put((test, stdout.rstrip(), stderr.rstrip(),
+ result))
+ return False
+
+ def run(self):
+ try:
+ stop = False
+ while not stop:
+ stop = self._runtest()
+ except BaseException:
+ self.output.put((None, None, None, None))
+ raise
+
+
+def run_tests_multiprocess(regrtest):
+ output = queue.Queue()
+ pending = MultiprocessIterator(regrtest.tests)
+ test_timeout = regrtest.ns.timeout
+ use_timeout = (test_timeout is not None)
+
+ workers = [MultiprocessThread(pending, output, regrtest.ns)
+ for i in range(regrtest.ns.use_mp)]
+ print("Run tests in parallel using %s child processes"
+ % len(workers))
+ for worker in workers:
+ worker.start()
+
+ def get_running(workers):
+ running = []
+ for worker in workers:
+ current_test = worker.current_test
+ if not current_test:
+ continue
+ dt = time.monotonic() - worker.start_time
+ if dt >= PROGRESS_MIN_TIME:
+ running.append('%s (%.0f sec)' % (current_test, dt))
+ return running
+
+ finished = 0
+ test_index = 1
+ get_timeout = max(PROGRESS_UPDATE, PROGRESS_MIN_TIME)
+ try:
+ while finished < regrtest.ns.use_mp:
+ if use_timeout:
+ faulthandler.dump_traceback_later(test_timeout, exit=True)
+
+ try:
+ item = output.get(timeout=get_timeout)
+ except queue.Empty:
+ running = get_running(workers)
+ if running and not regrtest.ns.pgo:
+ print('running: %s' % ', '.join(running))
+ continue
+
+ test, stdout, stderr, result = item
+ if test is None:
+ finished += 1
+ continue
+ regrtest.accumulate_result(test, result)
+
+ # Display progress
+ ok, test_time = result
+ text = format_test_result(test, ok)
+ if (ok not in (CHILD_ERROR, INTERRUPTED)
+ and test_time >= PROGRESS_MIN_TIME
+ and not regrtest.ns.pgo):
+ text += ' (%.0f sec)' % test_time
+ running = get_running(workers)
+ if running and not regrtest.ns.pgo:
+ text += ' -- running: %s' % ', '.join(running)
+ regrtest.display_progress(test_index, text)
+
+ # Copy stdout and stderr from the child process
+ if stdout:
+ print(stdout, flush=True)
+ if stderr and not regrtest.ns.pgo:
+ print(stderr, file=sys.stderr, flush=True)
+
+ if result[0] == INTERRUPTED:
+ raise KeyboardInterrupt
+ if result[0] == CHILD_ERROR:
+ msg = "Child error on {}: {}".format(test, result[1])
+ raise Exception(msg)
+ test_index += 1
+ except KeyboardInterrupt:
+ regrtest.interrupted = True
+ pending.interrupted = True
+ print()
+ finally:
+ if use_timeout:
+ faulthandler.cancel_dump_traceback_later()
+
+ # If tests are interrupted, wait until tests complete
+ wait_start = time.monotonic()
+ while True:
+ running = [worker.current_test for worker in workers]
+ running = list(filter(bool, running))
+ if not running:
+ break
+
+ dt = time.monotonic() - wait_start
+ line = "Waiting for %s (%s tests)" % (', '.join(running), len(running))
+ if dt >= WAIT_PROGRESS:
+ line = "%s since %.0f sec" % (line, dt)
+ print(line)
+ for worker in workers:
+ worker.join(WAIT_PROGRESS)
diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py
new file mode 100644
index 0000000..96ad3af
--- /dev/null
+++ b/Lib/test/libregrtest/save_env.py
@@ -0,0 +1,285 @@
+import builtins
+import locale
+import logging
+import os
+import shutil
+import sys
+import sysconfig
+import warnings
+from test import support
+try:
+ import threading
+except ImportError:
+ threading = None
+try:
+ import _multiprocessing, multiprocessing.process
+except ImportError:
+ multiprocessing = None
+
+
+# Unit tests are supposed to leave the execution environment unchanged
+# once they complete. But sometimes tests have bugs, especially when
+# tests fail, and the changes to environment go on to mess up other
+# tests. This can cause issues with buildbot stability, since tests
+# are run in random order and so problems may appear to come and go.
+# There are a few things we can save and restore to mitigate this, and
+# the following context manager handles this task.
+
+class saved_test_environment:
+ """Save bits of the test environment and restore them at block exit.
+
+ with saved_test_environment(testname, verbose, quiet):
+ #stuff
+
+ Unless quiet is True, a warning is printed to stderr if any of
+ the saved items was changed by the test. The attribute 'changed'
+ is initially False, but is set to True if a change is detected.
+
+ If verbose is more than 1, the before and after state of changed
+ items is also printed.
+ """
+
+ changed = False
+
+ def __init__(self, testname, verbose=0, quiet=False, *, pgo=False):
+ self.testname = testname
+ self.verbose = verbose
+ self.quiet = quiet
+ self.pgo = pgo
+
+ # To add things to save and restore, add a name XXX to the resources list
+ # and add corresponding get_XXX/restore_XXX functions. get_XXX should
+ # return the value to be saved and compared against a second call to the
+ # get function when test execution completes. restore_XXX should accept
+ # the saved value and restore the resource using it. It will be called if
+ # and only if a change in the value is detected.
+ #
+ # Note: XXX will have any '.' replaced with '_' characters when determining
+ # the corresponding method names.
+
+ resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
+ 'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
+ 'warnings.filters', 'asyncore.socket_map',
+ 'logging._handlers', 'logging._handlerList', 'sys.gettrace',
+ 'sys.warnoptions',
+ # multiprocessing.process._cleanup() may release ref
+ # to a thread, so check processes first.
+ 'multiprocessing.process._dangling', 'threading._dangling',
+ 'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
+ 'files', 'locale', 'warnings.showwarning',
+ 'shutil_archive_formats', 'shutil_unpack_formats',
+ )
+
+ def get_sys_argv(self):
+ return id(sys.argv), sys.argv, sys.argv[:]
+ def restore_sys_argv(self, saved_argv):
+ sys.argv = saved_argv[1]
+ sys.argv[:] = saved_argv[2]
+
+ def get_cwd(self):
+ return os.getcwd()
+ def restore_cwd(self, saved_cwd):
+ os.chdir(saved_cwd)
+
+ def get_sys_stdout(self):
+ return sys.stdout
+ def restore_sys_stdout(self, saved_stdout):
+ sys.stdout = saved_stdout
+
+ def get_sys_stderr(self):
+ return sys.stderr
+ def restore_sys_stderr(self, saved_stderr):
+ sys.stderr = saved_stderr
+
+ def get_sys_stdin(self):
+ return sys.stdin
+ def restore_sys_stdin(self, saved_stdin):
+ sys.stdin = saved_stdin
+
+ def get_os_environ(self):
+ return id(os.environ), os.environ, dict(os.environ)
+ def restore_os_environ(self, saved_environ):
+ os.environ = saved_environ[1]
+ os.environ.clear()
+ os.environ.update(saved_environ[2])
+
+ def get_sys_path(self):
+ return id(sys.path), sys.path, sys.path[:]
+ def restore_sys_path(self, saved_path):
+ sys.path = saved_path[1]
+ sys.path[:] = saved_path[2]
+
+ def get_sys_path_hooks(self):
+ return id(sys.path_hooks), sys.path_hooks, sys.path_hooks[:]
+ def restore_sys_path_hooks(self, saved_hooks):
+ sys.path_hooks = saved_hooks[1]
+ sys.path_hooks[:] = saved_hooks[2]
+
+ def get_sys_gettrace(self):
+ return sys.gettrace()
+ def restore_sys_gettrace(self, trace_fxn):
+ sys.settrace(trace_fxn)
+
+ def get___import__(self):
+ return builtins.__import__
+ def restore___import__(self, import_):
+ builtins.__import__ = import_
+
+ def get_warnings_filters(self):
+ return id(warnings.filters), warnings.filters, warnings.filters[:]
+ def restore_warnings_filters(self, saved_filters):
+ warnings.filters = saved_filters[1]
+ warnings.filters[:] = saved_filters[2]
+
+ def get_asyncore_socket_map(self):
+ asyncore = sys.modules.get('asyncore')
+ # XXX Making a copy keeps objects alive until __exit__ gets called.
+ return asyncore and asyncore.socket_map.copy() or {}
+ def restore_asyncore_socket_map(self, saved_map):
+ asyncore = sys.modules.get('asyncore')
+ if asyncore is not None:
+ asyncore.close_all(ignore_all=True)
+ asyncore.socket_map.update(saved_map)
+
+ def get_shutil_archive_formats(self):
+ # we could call get_archives_formats() but that only returns the
+ # registry keys; we want to check the values too (the functions that
+ # are registered)
+ return shutil._ARCHIVE_FORMATS, shutil._ARCHIVE_FORMATS.copy()
+ def restore_shutil_archive_formats(self, saved):
+ shutil._ARCHIVE_FORMATS = saved[0]
+ shutil._ARCHIVE_FORMATS.clear()
+ shutil._ARCHIVE_FORMATS.update(saved[1])
+
+ def get_shutil_unpack_formats(self):
+ return shutil._UNPACK_FORMATS, shutil._UNPACK_FORMATS.copy()
+ def restore_shutil_unpack_formats(self, saved):
+ shutil._UNPACK_FORMATS = saved[0]
+ shutil._UNPACK_FORMATS.clear()
+ shutil._UNPACK_FORMATS.update(saved[1])
+
+ def get_logging__handlers(self):
+ # _handlers is a WeakValueDictionary
+ return id(logging._handlers), logging._handlers, logging._handlers.copy()
+ def restore_logging__handlers(self, saved_handlers):
+ # Can't easily revert the logging state
+ pass
+
+ def get_logging__handlerList(self):
+ # _handlerList is a list of weakrefs to handlers
+ return id(logging._handlerList), logging._handlerList, logging._handlerList[:]
+ def restore_logging__handlerList(self, saved_handlerList):
+ # Can't easily revert the logging state
+ pass
+
+ def get_sys_warnoptions(self):
+ return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:]
+ def restore_sys_warnoptions(self, saved_options):
+ sys.warnoptions = saved_options[1]
+ sys.warnoptions[:] = saved_options[2]
+
+ # Controlling dangling references to Thread objects can make it easier
+ # to track reference leaks.
+ def get_threading__dangling(self):
+ if not threading:
+ return None
+ # This copies the weakrefs without making any strong reference
+ return threading._dangling.copy()
+ def restore_threading__dangling(self, saved):
+ if not threading:
+ return
+ threading._dangling.clear()
+ threading._dangling.update(saved)
+
+ # Same for Process objects
+ def get_multiprocessing_process__dangling(self):
+ if not multiprocessing:
+ return None
+ # Unjoined process objects can survive after process exits
+ multiprocessing.process._cleanup()
+ # This copies the weakrefs without making any strong reference
+ return multiprocessing.process._dangling.copy()
+ def restore_multiprocessing_process__dangling(self, saved):
+ if not multiprocessing:
+ return
+ multiprocessing.process._dangling.clear()
+ multiprocessing.process._dangling.update(saved)
+
+ def get_sysconfig__CONFIG_VARS(self):
+ # make sure the dict is initialized
+ sysconfig.get_config_var('prefix')
+ return (id(sysconfig._CONFIG_VARS), sysconfig._CONFIG_VARS,
+ dict(sysconfig._CONFIG_VARS))
+ def restore_sysconfig__CONFIG_VARS(self, saved):
+ sysconfig._CONFIG_VARS = saved[1]
+ sysconfig._CONFIG_VARS.clear()
+ sysconfig._CONFIG_VARS.update(saved[2])
+
+ def get_sysconfig__INSTALL_SCHEMES(self):
+ return (id(sysconfig._INSTALL_SCHEMES), sysconfig._INSTALL_SCHEMES,
+ sysconfig._INSTALL_SCHEMES.copy())
+ def restore_sysconfig__INSTALL_SCHEMES(self, saved):
+ sysconfig._INSTALL_SCHEMES = saved[1]
+ sysconfig._INSTALL_SCHEMES.clear()
+ sysconfig._INSTALL_SCHEMES.update(saved[2])
+
+ def get_files(self):
+ return sorted(fn + ('/' if os.path.isdir(fn) else '')
+ for fn in os.listdir())
+ def restore_files(self, saved_value):
+ fn = support.TESTFN
+ if fn not in saved_value and (fn + '/') not in saved_value:
+ if os.path.isfile(fn):
+ support.unlink(fn)
+ elif os.path.isdir(fn):
+ support.rmtree(fn)
+
+ _lc = [getattr(locale, lc) for lc in dir(locale)
+ if lc.startswith('LC_')]
+ def get_locale(self):
+ pairings = []
+ for lc in self._lc:
+ try:
+ pairings.append((lc, locale.setlocale(lc, None)))
+ except (TypeError, ValueError):
+ continue
+ return pairings
+ def restore_locale(self, saved):
+ for lc, setting in saved:
+ locale.setlocale(lc, setting)
+
+ def get_warnings_showwarning(self):
+ return warnings.showwarning
+ def restore_warnings_showwarning(self, fxn):
+ warnings.showwarning = fxn
+
+ def resource_info(self):
+ for name in self.resources:
+ method_suffix = name.replace('.', '_')
+ get_name = 'get_' + method_suffix
+ restore_name = 'restore_' + method_suffix
+ yield name, getattr(self, get_name), getattr(self, restore_name)
+
+ def __enter__(self):
+ self.saved_values = dict((name, get()) for name, get, restore
+ in self.resource_info())
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ saved_values = self.saved_values
+ del self.saved_values
+ support.gc_collect() # Some resources use weak references
+ for name, get, restore in self.resource_info():
+ current = get()
+ original = saved_values.pop(name)
+ # Check for changes to the resource's value
+ if current != original:
+ self.changed = True
+ restore(original)
+ if not self.quiet and not self.pgo:
+ print(f"Warning -- {name} was modified by {self.testname}",
+ file=sys.stderr, flush=True)
+ if self.verbose > 1:
+ print(f" Before: {original}\n After: {current} ",
+ file=sys.stderr, flush=True)
+ return False
diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py
new file mode 100644
index 0000000..1d24531
--- /dev/null
+++ b/Lib/test/libregrtest/setup.py
@@ -0,0 +1,121 @@
+import atexit
+import faulthandler
+import os
+import signal
+import sys
+import unittest
+from test import support
+try:
+ import gc
+except ImportError:
+ gc = None
+
+from test.libregrtest.refleak import warm_caches
+
+
+def setup_tests(ns):
+ # Display the Python traceback on fatal errors (e.g. segfault)
+ faulthandler.enable(all_threads=True)
+
+ # Display the Python traceback on SIGALRM or SIGUSR1 signal
+ signals = []
+ if hasattr(signal, 'SIGALRM'):
+ signals.append(signal.SIGALRM)
+ if hasattr(signal, 'SIGUSR1'):
+ signals.append(signal.SIGUSR1)
+ for signum in signals:
+ faulthandler.register(signum, chain=True)
+
+ replace_stdout()
+ support.record_original_stdout(sys.stdout)
+
+ if ns.testdir:
+ # Prepend test directory to sys.path, so runtest() will be able
+ # to locate tests
+ sys.path.insert(0, os.path.abspath(ns.testdir))
+
+ # Some times __path__ and __file__ are not absolute (e.g. while running from
+ # Lib/) and, if we change the CWD to run the tests in a temporary dir, some
+ # imports might fail. This affects only the modules imported before os.chdir().
+ # These modules are searched first in sys.path[0] (so '' -- the CWD) and if
+ # they are found in the CWD their __file__ and __path__ will be relative (this
+ # happens before the chdir). All the modules imported after the chdir, are
+ # not found in the CWD, and since the other paths in sys.path[1:] are absolute
+ # (site.py absolutize them), the __file__ and __path__ will be absolute too.
+ # Therefore it is necessary to absolutize manually the __file__ and __path__ of
+ # the packages to prevent later imports to fail when the CWD is different.
+ for module in sys.modules.values():
+ if hasattr(module, '__path__'):
+ for index, path in enumerate(module.__path__):
+ module.__path__[index] = os.path.abspath(path)
+ if hasattr(module, '__file__'):
+ module.__file__ = os.path.abspath(module.__file__)
+
+ # MacOSX (a.k.a. Darwin) has a default stack size that is too small
+ # for deeply recursive regular expressions. We see this as crashes in
+ # the Python test suite when running test_re.py and test_sre.py. The
+ # fix is to set the stack limit to 2048.
+ # This approach may also be useful for other Unixy platforms that
+ # suffer from small default stack limits.
+ if sys.platform == 'darwin':
+ try:
+ import resource
+ except ImportError:
+ pass
+ else:
+ soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
+ newsoft = min(hard, max(soft, 1024*2048))
+ resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
+
+ if ns.huntrleaks:
+ unittest.BaseTestSuite._cleanup = False
+
+ # Avoid false positives due to various caches
+ # filling slowly with random data:
+ warm_caches()
+
+ if ns.memlimit is not None:
+ support.set_memlimit(ns.memlimit)
+
+ if ns.threshold is not None:
+ gc.set_threshold(ns.threshold)
+
+ try:
+ import msvcrt
+ except ImportError:
+ pass
+ else:
+ msvcrt.SetErrorMode(msvcrt.SEM_FAILCRITICALERRORS|
+ msvcrt.SEM_NOALIGNMENTFAULTEXCEPT|
+ msvcrt.SEM_NOGPFAULTERRORBOX|
+ msvcrt.SEM_NOOPENFILEERRORBOX)
+ try:
+ msvcrt.CrtSetReportMode
+ except AttributeError:
+ # release build
+ pass
+ else:
+ for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]:
+ if ns.verbose and ns.verbose >= 2:
+ msvcrt.CrtSetReportMode(m, msvcrt.CRTDBG_MODE_FILE)
+ msvcrt.CrtSetReportFile(m, msvcrt.CRTDBG_FILE_STDERR)
+ else:
+ msvcrt.CrtSetReportMode(m, 0)
+
+ support.use_resources = ns.use_resources
+
+
+def replace_stdout():
+ """Set stdout encoder error handler to backslashreplace (as stderr error
+ handler) to avoid UnicodeEncodeError when printing a traceback"""
+ stdout = sys.stdout
+ sys.stdout = open(stdout.fileno(), 'w',
+ encoding=stdout.encoding,
+ errors="backslashreplace",
+ closefd=False,
+ newline='\n')
+
+ def restore_stdout():
+ sys.stdout.close()
+ sys.stdout = stdout
+ atexit.register(restore_stdout)
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index f20fdc0..26e9368 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -266,9 +266,21 @@ class CommonTest(seq_tests.CommonTest):
self.assertEqual(a, list("spameggs"))
self.assertRaises(TypeError, a.extend, None)
-
self.assertRaises(TypeError, a.extend)
+ # overflow test. issue1621
+ class CustomIter:
+ def __iter__(self):
+ return self
+ def __next__(self):
+ raise StopIteration
+ def __length_hint__(self):
+ return sys.maxsize
+ a = self.type2test([1,2,3,4])
+ a.extend(CustomIter())
+ self.assertEqual(a, [1,2,3,4])
+
+
def test_insert(self):
a = self.type2test([0, 1, 2])
a.insert(0, -2)
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index a64aa18..a6cb3b1 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -7,6 +7,7 @@ import time
from _thread import start_new_thread, TIMEOUT_MAX
import threading
import unittest
+import weakref
from test import support
@@ -198,6 +199,17 @@ class BaseLockTests(BaseTestCase):
self.assertFalse(results[0])
self.assertTimeout(results[1], 0.5)
+ def test_weakref_exists(self):
+ lock = self.locktype()
+ ref = weakref.ref(lock)
+ self.assertIsNotNone(ref())
+
+ def test_weakref_deleted(self):
+ lock = self.locktype()
+ ref = weakref.ref(lock)
+ del lock
+ self.assertIsNone(ref())
+
class LockTests(BaseLockTests):
"""
diff --git a/Lib/test/make_ssl_certs.py b/Lib/test/make_ssl_certs.py
index a1f298d..4d9f01b 100644
--- a/Lib/test/make_ssl_certs.py
+++ b/Lib/test/make_ssl_certs.py
@@ -3,7 +3,6 @@ and friends."""
import os
import shutil
-import sys
import tempfile
from subprocess import *
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 7922b54..5c83361 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -1000,7 +1000,7 @@ class AbstractUnpickleTests(unittest.TestCase):
b'0', # POP
b'1', # POP_MARK
b'2', # DUP
- # b'(2', # PyUnpickler doesn't raise
+ b'(2',
b'R', # REDUCE
b')R',
b'a', # APPEND
@@ -1009,7 +1009,7 @@ class AbstractUnpickleTests(unittest.TestCase):
b'Nb',
b'd', # DICT
b'e', # APPENDS
- # b'(e', # PyUnpickler raises AttributeError
+ b'(e',
b'ibuiltins\nlist\n', # INST
b'l', # LIST
b'o', # OBJ
@@ -1022,7 +1022,7 @@ class AbstractUnpickleTests(unittest.TestCase):
b'NNs',
b't', # TUPLE
b'u', # SETITEMS
- # b'(u', # PyUnpickler doesn't raise
+ b'(u',
b'}(Nu',
b'\x81', # NEWOBJ
b')\x81',
@@ -1033,7 +1033,7 @@ class AbstractUnpickleTests(unittest.TestCase):
b'N\x87',
b'NN\x87',
b'\x90', # ADDITEMS
- # b'(\x90', # PyUnpickler raises AttributeError
+ b'(\x90',
b'\x91', # FROZENSET
b'\x92', # NEWOBJ_EX
b')}\x92',
@@ -1046,7 +1046,7 @@ class AbstractUnpickleTests(unittest.TestCase):
def test_bad_mark(self):
badpickles = [
- # b'N(.', # STOP
+ b'N(.', # STOP
b'N(2', # DUP
b'cbuiltins\nlist\n)(R', # REDUCE
b'cbuiltins\nlist\n()R',
@@ -1081,7 +1081,7 @@ class AbstractUnpickleTests(unittest.TestCase):
b'N(\x94', # MEMOIZE
]
for p in badpickles:
- self.check_unpickling_error(self.bad_mark_errors, p)
+ self.check_unpickling_error(self.bad_stack_errors, p)
def test_truncated_data(self):
self.check_unpickling_error(EOFError, b'')
@@ -1855,16 +1855,14 @@ class AbstractPickleTests(unittest.TestCase):
x.abc = 666
for proto in protocols:
with self.subTest(proto=proto):
- if 2 <= proto < 4:
- self.assertRaises(ValueError, self.dumps, x, proto)
- continue
s = self.dumps(x, proto)
if proto < 1:
self.assertIn(b'\nL64206', s) # LONG
elif proto < 2:
self.assertIn(b'M\xce\xfa', s) # BININT2
+ elif proto < 4:
+ self.assertIn(b'X\x04\x00\x00\x00FACE', s) # BINUNICODE
else:
- assert proto >= 4
self.assertIn(b'\x8c\x04FACE', s) # SHORT_BINUNICODE
self.assertFalse(opcode_in_pickle(pickle.NEWOBJ, s))
self.assertEqual(opcode_in_pickle(pickle.NEWOBJ_EX, s),
@@ -2583,11 +2581,6 @@ class AbstractPickleModuleTests(unittest.TestCase):
self.assertRaises(pickle.PicklingError, BadPickler().dump, 0)
self.assertRaises(pickle.UnpicklingError, BadUnpickler().load)
- def test_bad_input(self):
- # Test issue4298
- s = bytes([0x58, 0, 0, 0, 0x54])
- self.assertRaises(EOFError, pickle.loads, s)
-
class AbstractPersistentPicklerTests(unittest.TestCase):
diff --git a/Lib/test/pydoc_mod.py b/Lib/test/pydoc_mod.py
index cda1c9e..9c1fff5 100644
--- a/Lib/test/pydoc_mod.py
+++ b/Lib/test/pydoc_mod.py
@@ -12,7 +12,7 @@ class A:
pass
class B(object):
- NO_MEANING = "eggs"
+ NO_MEANING: str = "eggs"
pass
class C(object):
diff --git a/Lib/test/re_tests.py b/Lib/test/re_tests.py
index 8c158f8..a379d33 100755
--- a/Lib/test/re_tests.py
+++ b/Lib/test/re_tests.py
@@ -106,8 +106,8 @@ tests = [
('a.*b', 'acc\nccb', FAIL),
('a.{4,5}b', 'acc\nccb', FAIL),
('a.b', 'a\rb', SUCCEED, 'found', 'a\rb'),
- ('a.b(?s)', 'a\nb', SUCCEED, 'found', 'a\nb'),
- ('a.*(?s)b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'),
+ ('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'),
+ ('(?s)a.*b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'),
('(?s)a.{4,5}b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'),
('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'),
@@ -158,7 +158,7 @@ tests = [
('(abc', '-', SYNTAX_ERROR),
('a]', 'a]', SUCCEED, 'found', 'a]'),
('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'),
- ('a[\]]b', 'a]b', SUCCEED, 'found', 'a]b'),
+ ('a[\\]]b', 'a]b', SUCCEED, 'found', 'a]b'),
('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'),
('a[^bc]d', 'abd', FAIL),
('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'),
@@ -551,7 +551,7 @@ tests = [
# lookbehind: split by : but not if it is escaped by -.
('(?<!-):(.*?)(?<!-):', 'a:bc-:de:f', SUCCEED, 'g1', 'bc-:de' ),
# escaping with \ as we know it
- ('(?<!\\\):(.*?)(?<!\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ),
+ ('(?<!\\\\):(.*?)(?<!\\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ),
# terminating with ' and escaping with ? as in edifact
("(?<!\\?)'(.*?)(?<!\\?)'", "a'bc?'de'f", SUCCEED, 'g1', "bc?'de" ),
@@ -563,7 +563,7 @@ tests = [
# Check odd placement of embedded pattern modifiers
# not an error under PCRE/PRE:
- ('w(?i)', 'W', SUCCEED, 'found', 'W'),
+ ('(?i)w', 'W', SUCCEED, 'found', 'W'),
# ('w(?i)', 'W', SYNTAX_ERROR),
# Comments using the x embedded pattern modifier
@@ -627,7 +627,7 @@ xyzabc
# bug 114033: nothing to repeat
(r'(x?)?', 'x', SUCCEED, 'found', 'x'),
# bug 115040: rescan if flags are modified inside pattern
- (r' (?x)foo ', 'foo', SUCCEED, 'found', 'foo'),
+ (r'(?x) foo ', 'foo', SUCCEED, 'found', 'foo'),
# bug 115618: negative lookahead
(r'(?<!abc)(d.f)', 'abcdefdof', SUCCEED, 'found', 'dof'),
# bug 116251: character class bug
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index f870854..21b0edf 100755..100644
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -6,1608 +6,33 @@ Script to run Python regression tests.
Run this script with -h or --help for documentation.
"""
-USAGE = """\
-python -m test [options] [test_name1 [test_name2 ...]]
-python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]]
-"""
-
-DESCRIPTION = """\
-Run Python regression tests.
-
-If no arguments or options are provided, finds all files matching
-the pattern "test_*" in the Lib/test subdirectory and runs
-them in alphabetical order (but see -M and -u, below, for exceptions).
-
-For more rigorous testing, it is useful to use the following
-command line:
-
-python -E -Wd -m test [options] [test_name1 ...]
-"""
-
-EPILOG = """\
-Additional option details:
-
--r randomizes test execution order. You can use --randseed=int to provide an
-int seed value for the randomizer; this is useful for reproducing troublesome
-test orders.
-
--s On the first invocation of regrtest using -s, the first test file found
-or the first test file given on the command line is run, and the name of
-the next test is recorded in a file named pynexttest. If run from the
-Python build directory, pynexttest is located in the 'build' subdirectory,
-otherwise it is located in tempfile.gettempdir(). On subsequent runs,
-the test in pynexttest is run, and the next test is written to pynexttest.
-When the last test has been run, pynexttest is deleted. In this way it
-is possible to single step through the test files. This is useful when
-doing memory analysis on the Python interpreter, which process tends to
-consume too many resources to run the full regression test non-stop.
-
--S is used to continue running tests after an aborted run. It will
-maintain the order a standard run (ie, this assumes -r is not used).
-This is useful after the tests have prematurely stopped for some external
-reason and you want to start running from where you left off rather
-than starting from the beginning.
-
--f reads the names of tests from the file given as f's argument, one
-or more test names per line. Whitespace is ignored. Blank lines and
-lines beginning with '#' are ignored. This is especially useful for
-whittling down failures involving interactions among tests.
-
--L causes the leaks(1) command to be run just before exit if it exists.
-leaks(1) is available on Mac OS X and presumably on some other
-FreeBSD-derived systems.
-
--R runs each test several times and examines sys.gettotalrefcount() to
-see if the test appears to be leaking references. The argument should
-be of the form stab:run:fname where 'stab' is the number of times the
-test is run to let gettotalrefcount settle down, 'run' is the number
-of times further it is run and 'fname' is the name of the file the
-reports are written to. These parameters all have defaults (5, 4 and
-"reflog.txt" respectively), and the minimal invocation is '-R :'.
-
--M runs tests that require an exorbitant amount of memory. These tests
-typically try to ascertain containers keep working when containing more than
-2 billion objects, which only works on 64-bit systems. There are also some
-tests that try to exhaust the address space of the process, which only makes
-sense on 32-bit systems with at least 2Gb of memory. The passed-in memlimit,
-which is a string in the form of '2.5Gb', determines howmuch memory the
-tests will limit themselves to (but they may go slightly over.) The number
-shouldn't be more memory than the machine has (including swap memory). You
-should also keep in mind that swap memory is generally much, much slower
-than RAM, and setting memlimit to all available RAM or higher will heavily
-tax the machine. On the other hand, it is no use running these tests with a
-limit of less than 2.5Gb, and many require more than 20Gb. Tests that expect
-to use more than memlimit memory will be skipped. The big-memory tests
-generally run very, very long.
-
--u is used to specify which special resource intensive tests to run,
-such as those requiring large file support or network connectivity.
-The argument is a comma-separated list of words indicating the
-resources to test. Currently only the following are defined:
-
- all - Enable all special resources.
-
- none - Disable all special resources (this is the default).
-
- audio - Tests that use the audio device. (There are known
- cases of broken audio drivers that can crash Python or
- even the Linux kernel.)
-
- curses - Tests that use curses and will modify the terminal's
- state and output modes.
-
- largefile - It is okay to run some test that may create huge
- files. These tests can take a long time and may
- consume >2GB of disk space temporarily.
-
- network - It is okay to run tests that use external network
- resource, e.g. testing SSL support for sockets.
-
- decimal - Test the decimal module against a large suite that
- verifies compliance with standards.
-
- cpu - Used for certain CPU-heavy tests.
-
- subprocess Run all tests for the subprocess module.
-
- urlfetch - It is okay to download files required on testing.
-
- gui - Run tests that require a running GUI.
-
-To enable all resources except one, use '-uall,-<resource>'. For
-example, to run all the tests except for the gui tests, give the
-option '-uall,-gui'.
-"""
-
# We import importlib *ASAP* in order to test #15386
import importlib
-import argparse
-import builtins
-import faulthandler
-import io
-import json
-import locale
-import logging
import os
-import platform
-import random
-import re
-import shutil
-import signal
import sys
-import sysconfig
-import tempfile
-import time
-import traceback
-import unittest
-import warnings
-from inspect import isabstract
-
-try:
- import threading
-except ImportError:
- threading = None
-try:
- import _multiprocessing, multiprocessing.process
-except ImportError:
- multiprocessing = None
-
-
-# Some times __path__ and __file__ are not absolute (e.g. while running from
-# Lib/) and, if we change the CWD to run the tests in a temporary dir, some
-# imports might fail. This affects only the modules imported before os.chdir().
-# These modules are searched first in sys.path[0] (so '' -- the CWD) and if
-# they are found in the CWD their __file__ and __path__ will be relative (this
-# happens before the chdir). All the modules imported after the chdir, are
-# not found in the CWD, and since the other paths in sys.path[1:] are absolute
-# (site.py absolutize them), the __file__ and __path__ will be absolute too.
-# Therefore it is necessary to absolutize manually the __file__ and __path__ of
-# the packages to prevent later imports to fail when the CWD is different.
-for module in sys.modules.values():
- if hasattr(module, '__path__'):
- module.__path__ = [os.path.abspath(path) for path in module.__path__]
- if hasattr(module, '__file__'):
- module.__file__ = os.path.abspath(module.__file__)
-
-
-# MacOSX (a.k.a. Darwin) has a default stack size that is too small
-# for deeply recursive regular expressions. We see this as crashes in
-# the Python test suite when running test_re.py and test_sre.py. The
-# fix is to set the stack limit to 2048.
-# This approach may also be useful for other Unixy platforms that
-# suffer from small default stack limits.
-if sys.platform == 'darwin':
- try:
- import resource
- except ImportError:
- pass
- else:
- soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
- newsoft = min(hard, max(soft, 1024*2048))
- resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
-
-# Test result constants.
-PASSED = 1
-FAILED = 0
-ENV_CHANGED = -1
-SKIPPED = -2
-RESOURCE_DENIED = -3
-INTERRUPTED = -4
-CHILD_ERROR = -5 # error in a child process
-
-from test import support
-
-RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network',
- 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui')
-
-# When tests are run from the Python build directory, it is best practice
-# to keep the test files in a subfolder. This eases the cleanup of leftover
-# files using the "make distclean" command.
-if sysconfig.is_python_build():
- TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
-else:
- TEMPDIR = tempfile.gettempdir()
-TEMPDIR = os.path.abspath(TEMPDIR)
-
-class _ArgParser(argparse.ArgumentParser):
-
- def error(self, message):
- super().error(message + "\nPass -h or --help for complete help.")
-
-def _create_parser():
- # Set prog to prevent the uninformative "__main__.py" from displaying in
- # error messages when using "python -m test ...".
- parser = _ArgParser(prog='regrtest.py',
- usage=USAGE,
- description=DESCRIPTION,
- epilog=EPILOG,
- add_help=False,
- formatter_class=argparse.RawDescriptionHelpFormatter)
-
- # Arguments with this clause added to its help are described further in
- # the epilog's "Additional option details" section.
- more_details = ' See the section at bottom for more details.'
-
- group = parser.add_argument_group('General options')
- # We add help explicitly to control what argument group it renders under.
- group.add_argument('-h', '--help', action='help',
- help='show this help message and exit')
- group.add_argument('--timeout', metavar='TIMEOUT', type=float,
- help='dump the traceback and exit if a test takes '
- 'more than TIMEOUT seconds; disabled if TIMEOUT '
- 'is negative or equals to zero')
- group.add_argument('--wait', action='store_true',
- help='wait for user input, e.g., allow a debugger '
- 'to be attached')
- group.add_argument('--slaveargs', metavar='ARGS')
- group.add_argument('-S', '--start', metavar='START',
- help='the name of the test at which to start.' +
- more_details)
-
- group = parser.add_argument_group('Verbosity')
- group.add_argument('-v', '--verbose', action='count',
- help='run tests in verbose mode with output to stdout')
- group.add_argument('-w', '--verbose2', action='store_true',
- help='re-run failed tests in verbose mode')
- group.add_argument('-W', '--verbose3', action='store_true',
- help='display test output on failure')
- group.add_argument('-q', '--quiet', action='store_true',
- help='no output unless one or more tests fail')
- group.add_argument('-o', '--slow', action='store_true', dest='print_slow',
- help='print the slowest 10 tests')
- group.add_argument('--header', action='store_true',
- help='print header with interpreter info')
-
- group = parser.add_argument_group('Selecting tests')
- group.add_argument('-r', '--randomize', action='store_true',
- help='randomize test execution order.' + more_details)
- group.add_argument('--randseed', metavar='SEED',
- dest='random_seed', type=int,
- help='pass a random seed to reproduce a previous '
- 'random run')
- group.add_argument('-f', '--fromfile', metavar='FILE',
- help='read names of tests to run from a file.' +
- more_details)
- group.add_argument('-x', '--exclude', action='store_true',
- help='arguments are tests to *exclude*')
- group.add_argument('-s', '--single', action='store_true',
- help='single step through a set of tests.' +
- more_details)
- group.add_argument('-m', '--match', metavar='PAT',
- dest='match_tests',
- help='match test cases and methods with glob pattern PAT')
- group.add_argument('-G', '--failfast', action='store_true',
- help='fail as soon as a test fails (only with -v or -W)')
- group.add_argument('-u', '--use', metavar='RES1,RES2,...',
- action='append', type=resources_list,
- help='specify which special resource intensive tests '
- 'to run.' + more_details)
- group.add_argument('-M', '--memlimit', metavar='LIMIT',
- help='run very large memory-consuming tests.' +
- more_details)
- group.add_argument('--testdir', metavar='DIR',
- type=relative_filename,
- help='execute test files in the specified directory '
- '(instead of the Python stdlib test suite)')
-
- group = parser.add_argument_group('Special runs')
- group.add_argument('-l', '--findleaks', action='store_true',
- help='if GC is available detect tests that leak memory')
- group.add_argument('-L', '--runleaks', action='store_true',
- help='run the leaks(1) command just before exit.' +
- more_details)
- group.add_argument('-R', '--huntrleaks', metavar='RUNCOUNTS',
- type=huntrleaks,
- help='search for reference leaks (needs debug build, '
- 'very slow).' + more_details)
- group.add_argument('-j', '--multiprocess', metavar='PROCESSES',
- dest='use_mp', type=int,
- help='run PROCESSES processes at once')
- group.add_argument('-T', '--coverage', action='store_true',
- dest='trace',
- help='turn on code coverage tracing using the trace '
- 'module')
- group.add_argument('-D', '--coverdir', metavar='DIR',
- type=relative_filename,
- help='directory where coverage files are put')
- group.add_argument('-N', '--nocoverdir',
- action='store_const', const=None, dest='coverdir',
- help='put coverage files alongside modules')
- group.add_argument('-t', '--threshold', metavar='THRESHOLD',
- type=int,
- help='call gc.set_threshold(THRESHOLD)')
- group.add_argument('-n', '--nowindows', action='store_true',
- help='suppress error message boxes on Windows')
- group.add_argument('-F', '--forever', action='store_true',
- help='run the specified tests in a loop, until an '
- 'error happens')
- group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
- help='enable Profile Guided Optimization training')
-
- return parser
-
-def relative_filename(string):
- # CWD is replaced with a temporary dir before calling main(), so we
- # join it with the saved CWD so it ends up where the user expects.
- return os.path.join(support.SAVEDCWD, string)
-
-def huntrleaks(string):
- args = string.split(':')
- if len(args) not in (2, 3):
- raise argparse.ArgumentTypeError(
- 'needs 2 or 3 colon-separated arguments')
- nwarmup = int(args[0]) if args[0] else 5
- ntracked = int(args[1]) if args[1] else 4
- fname = args[2] if len(args) > 2 and args[2] else 'reflog.txt'
- return nwarmup, ntracked, fname
-
-def resources_list(string):
- u = [x.lower() for x in string.split(',')]
- for r in u:
- if r == 'all' or r == 'none':
- continue
- if r[0] == '-':
- r = r[1:]
- if r not in RESOURCE_NAMES:
- raise argparse.ArgumentTypeError('invalid resource: ' + r)
- return u
-
-def _parse_args(args, **kwargs):
- # Defaults
- ns = argparse.Namespace(testdir=None, verbose=0, quiet=False,
- exclude=False, single=False, randomize=False, fromfile=None,
- findleaks=False, use_resources=None, trace=False, coverdir='coverage',
- runleaks=False, huntrleaks=False, verbose2=False, print_slow=False,
- random_seed=None, use_mp=None, verbose3=False, forever=False,
- header=False, failfast=False, match_tests=None, pgo=False)
- for k, v in kwargs.items():
- if not hasattr(ns, k):
- raise TypeError('%r is an invalid keyword argument '
- 'for this function' % k)
- setattr(ns, k, v)
- if ns.use_resources is None:
- ns.use_resources = []
-
- parser = _create_parser()
- # Issue #14191: argparse doesn't support "intermixed" positional and
- # optional arguments. Use parse_known_args() as workaround.
- ns.args = parser.parse_known_args(args=args, namespace=ns)[1]
- for arg in ns.args:
- if arg.startswith('-'):
- parser.error("unrecognized arguments: %s" % arg)
- sys.exit(1)
-
- if ns.single and ns.fromfile:
- parser.error("-s and -f don't go together!")
- if ns.use_mp and ns.trace:
- parser.error("-T and -j don't go together!")
- if ns.use_mp and ns.findleaks:
- parser.error("-l and -j don't go together!")
- if ns.use_mp and ns.memlimit:
- parser.error("-M and -j don't go together!")
- if ns.failfast and not (ns.verbose or ns.verbose3):
- parser.error("-G/--failfast needs either -v or -W")
-
- if ns.quiet:
- ns.verbose = 0
- if ns.timeout is not None:
- if hasattr(faulthandler, 'dump_traceback_later'):
- if ns.timeout <= 0:
- ns.timeout = None
- else:
- print("Warning: The timeout option requires "
- "faulthandler.dump_traceback_later")
- ns.timeout = None
- if ns.use_mp is not None:
- if ns.use_mp <= 0:
- # Use all cores + extras for tests that like to sleep
- ns.use_mp = 2 + (os.cpu_count() or 1)
- if ns.use_mp == 1:
- ns.use_mp = None
- if ns.use:
- for a in ns.use:
- for r in a:
- if r == 'all':
- ns.use_resources[:] = RESOURCE_NAMES
- continue
- if r == 'none':
- del ns.use_resources[:]
- continue
- remove = False
- if r[0] == '-':
- remove = True
- r = r[1:]
- if remove:
- if r in ns.use_resources:
- ns.use_resources.remove(r)
- elif r not in ns.use_resources:
- ns.use_resources.append(r)
- if ns.random_seed is not None:
- ns.randomize = True
-
- return ns
-
-
-def run_test_in_subprocess(testname, ns):
- """Run the given test in a subprocess with --slaveargs.
-
- ns is the option Namespace parsed from command-line arguments. regrtest
- is invoked in a subprocess with the --slaveargs argument; when the
- subprocess exits, its return code, stdout and stderr are returned as a
- 3-tuple.
- """
- from subprocess import Popen, PIPE
- base_cmd = ([sys.executable] + support.args_from_interpreter_flags() +
- ['-X', 'faulthandler', '-m', 'test.regrtest'])
- # required to spawn a new process with PGO flag on/off
- if ns.pgo:
- base_cmd = base_cmd + ['--pgo']
- slaveargs = (
- (testname, ns.verbose, ns.quiet),
- dict(huntrleaks=ns.huntrleaks,
- use_resources=ns.use_resources,
- output_on_failure=ns.verbose3,
- timeout=ns.timeout, failfast=ns.failfast,
- match_tests=ns.match_tests, pgo=ns.pgo))
- # Running the child from the same working directory as regrtest's original
- # invocation ensures that TEMPDIR for the child is the same when
- # sysconfig.is_python_build() is true. See issue 15300.
- popen = Popen(base_cmd + ['--slaveargs', json.dumps(slaveargs)],
- stdout=PIPE, stderr=PIPE,
- universal_newlines=True,
- close_fds=(os.name != 'nt'),
- cwd=support.SAVEDCWD)
- stdout, stderr = popen.communicate()
- retcode = popen.wait()
- return retcode, stdout, stderr
-
-
-def main(tests=None, **kwargs):
- """Execute a test suite.
-
- This also parses command-line options and modifies its behavior
- accordingly.
-
- tests -- a list of strings containing test names (optional)
- testdir -- the directory in which to look for tests (optional)
-
- Users other than the Python test suite will certainly want to
- specify testdir; if it's omitted, the directory containing the
- Python test suite is searched for.
-
- If the tests argument is omitted, the tests listed on the
- command-line will be used. If that's empty, too, then all *.py
- files beginning with test_ will be used.
-
- The other default arguments (verbose, quiet, exclude,
- single, randomize, findleaks, use_resources, trace, coverdir,
- print_slow, and random_seed) allow programmers calling main()
- directly to set the values that would normally be set by flags
- on the command line.
- """
- # Display the Python traceback on fatal errors (e.g. segfault)
- faulthandler.enable(all_threads=True)
-
- # Display the Python traceback on SIGALRM or SIGUSR1 signal
- signals = []
- if hasattr(signal, 'SIGALRM'):
- signals.append(signal.SIGALRM)
- if hasattr(signal, 'SIGUSR1'):
- signals.append(signal.SIGUSR1)
- for signum in signals:
- faulthandler.register(signum, chain=True)
-
- replace_stdout()
-
- support.record_original_stdout(sys.stdout)
-
- ns = _parse_args(sys.argv[1:], **kwargs)
-
- if ns.huntrleaks:
- # Avoid false positives due to various caches
- # filling slowly with random data:
- warm_caches()
- if ns.memlimit is not None:
- support.set_memlimit(ns.memlimit)
- if ns.threshold is not None:
- import gc
- gc.set_threshold(ns.threshold)
- if ns.nowindows:
- print('The --nowindows (-n) option is deprecated. '
- 'Use -vv to display assertions in stderr.')
- try:
- import msvcrt
- except ImportError:
- pass
- else:
- msvcrt.SetErrorMode(msvcrt.SEM_FAILCRITICALERRORS|
- msvcrt.SEM_NOALIGNMENTFAULTEXCEPT|
- msvcrt.SEM_NOGPFAULTERRORBOX|
- msvcrt.SEM_NOOPENFILEERRORBOX)
- try:
- msvcrt.CrtSetReportMode
- except AttributeError:
- # release build
- pass
- else:
- for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]:
- if ns.verbose and ns.verbose >= 2:
- msvcrt.CrtSetReportMode(m, msvcrt.CRTDBG_MODE_FILE)
- msvcrt.CrtSetReportFile(m, msvcrt.CRTDBG_FILE_STDERR)
- else:
- msvcrt.CrtSetReportMode(m, 0)
- if ns.wait:
- input("Press any key to continue...")
-
- if ns.slaveargs is not None:
- args, kwargs = json.loads(ns.slaveargs)
- if kwargs.get('huntrleaks'):
- unittest.BaseTestSuite._cleanup = False
- try:
- result = runtest(*args, **kwargs)
- except KeyboardInterrupt:
- result = INTERRUPTED, ''
- except BaseException as e:
- traceback.print_exc()
- result = CHILD_ERROR, str(e)
- sys.stdout.flush()
- print() # Force a newline (just in case)
- print(json.dumps(result))
- sys.exit(0)
-
- good = []
- bad = []
- skipped = []
- resource_denieds = []
- environment_changed = []
- interrupted = False
-
- if ns.findleaks:
- try:
- import gc
- except ImportError:
- print('No GC available, disabling findleaks.')
- ns.findleaks = False
- else:
- # Uncomment the line below to report garbage that is not
- # freeable by reference counting alone. By default only
- # garbage that is not collectable by the GC is reported.
- #gc.set_debug(gc.DEBUG_SAVEALL)
- found_garbage = []
-
- if ns.huntrleaks:
- unittest.BaseTestSuite._cleanup = False
-
- if ns.single:
- filename = os.path.join(TEMPDIR, 'pynexttest')
- try:
- with open(filename, 'r') as fp:
- next_test = fp.read().strip()
- tests = [next_test]
- except OSError:
- pass
-
- if ns.fromfile:
- tests = []
- with open(os.path.join(support.SAVEDCWD, ns.fromfile)) as fp:
- count_pat = re.compile(r'\[\s*\d+/\s*\d+\]')
- for line in fp:
- line = count_pat.sub('', line)
- guts = line.split() # assuming no test has whitespace in its name
- if guts and not guts[0].startswith('#'):
- tests.extend(guts)
-
- # Strip .py extensions.
- removepy(ns.args)
- removepy(tests)
-
- stdtests = STDTESTS[:]
- nottests = NOTTESTS.copy()
- if ns.exclude:
- for arg in ns.args:
- if arg in stdtests:
- stdtests.remove(arg)
- nottests.add(arg)
- ns.args = []
-
- # For a partial run, we do not need to clutter the output.
- if (ns.verbose or ns.header or
- not (ns.pgo or ns.quiet or ns.single or tests or ns.args)):
- # Print basic platform information
- print("==", platform.python_implementation(), *sys.version.split())
- print("== ", platform.platform(aliased=True),
- "%s-endian" % sys.byteorder)
- print("== ", "hash algorithm:", sys.hash_info.algorithm,
- "64bit" if sys.maxsize > 2**32 else "32bit")
- print("== ", os.getcwd())
- print("Testing with flags:", sys.flags)
-
- # if testdir is set, then we are not running the python tests suite, so
- # don't add default tests to be executed or skipped (pass empty values)
- if ns.testdir:
- alltests = findtests(ns.testdir, list(), set())
- else:
- alltests = findtests(ns.testdir, stdtests, nottests)
-
- selected = tests or ns.args or alltests
- if ns.single:
- selected = selected[:1]
- try:
- next_single_test = alltests[alltests.index(selected[0])+1]
- except IndexError:
- next_single_test = None
- # Remove all the selected tests that precede start if it's set.
- if ns.start:
- try:
- del selected[:selected.index(ns.start)]
- except ValueError:
- print("Couldn't find starting test (%s), using all tests" % ns.start)
- if ns.randomize:
- if ns.random_seed is None:
- ns.random_seed = random.randrange(10000000)
- random.seed(ns.random_seed)
- print("Using random seed", ns.random_seed)
- random.shuffle(selected)
- if ns.trace:
- import trace, tempfile
- tracer = trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,
- tempfile.gettempdir()],
- trace=False, count=True)
-
- test_times = []
- support.verbose = ns.verbose # Tell tests to be moderately quiet
- support.use_resources = ns.use_resources
- save_modules = sys.modules.keys()
-
- def accumulate_result(test, result):
- ok, test_time = result
- if ok not in (CHILD_ERROR, INTERRUPTED):
- test_times.append((test_time, test))
- if ok == PASSED:
- good.append(test)
- elif ok == FAILED:
- bad.append(test)
- elif ok == ENV_CHANGED:
- environment_changed.append(test)
- elif ok == SKIPPED:
- skipped.append(test)
- elif ok == RESOURCE_DENIED:
- skipped.append(test)
- resource_denieds.append(test)
-
- if ns.forever:
- def test_forever(tests=list(selected)):
- while True:
- for test in tests:
- yield test
- if bad:
- return
- tests = test_forever()
- test_count = ''
- test_count_width = 3
- else:
- tests = iter(selected)
- test_count = '/{}'.format(len(selected))
- test_count_width = len(test_count) - 1
-
- if ns.use_mp:
- try:
- from threading import Thread
- except ImportError:
- print("Multiprocess option requires thread support")
- sys.exit(2)
- from queue import Queue
- debug_output_pat = re.compile(r"\[\d+ refs, \d+ blocks\]$")
- output = Queue()
- pending = MultiprocessTests(tests)
- def work():
- # A worker thread.
- try:
- while True:
- try:
- test = next(pending)
- except StopIteration:
- output.put((None, None, None, None))
- return
- retcode, stdout, stderr = run_test_in_subprocess(test, ns)
- # Strip last refcount output line if it exists, since it
- # comes from the shutdown of the interpreter in the subcommand.
- stderr = debug_output_pat.sub("", stderr)
- stdout, _, result = stdout.strip().rpartition("\n")
- if retcode != 0:
- result = (CHILD_ERROR, "Exit code %s" % retcode)
- output.put((test, stdout.rstrip(), stderr.rstrip(), result))
- return
- if not result:
- output.put((None, None, None, None))
- return
- result = json.loads(result)
- output.put((test, stdout.rstrip(), stderr.rstrip(), result))
- except BaseException:
- output.put((None, None, None, None))
- raise
- workers = [Thread(target=work) for i in range(ns.use_mp)]
- for worker in workers:
- worker.start()
- finished = 0
- test_index = 1
- try:
- while finished < ns.use_mp:
- test, stdout, stderr, result = output.get()
- if test is None:
- finished += 1
- continue
- accumulate_result(test, result)
- if not ns.quiet:
- if bad and not ns.pgo:
- fmt = "[{1:{0}}{2}/{3}] {4}"
- else:
- fmt = "[{1:{0}}{2}] {4}"
- print(fmt.format(
- test_count_width, test_index, test_count,
- len(bad), test))
- if stdout:
- print(stdout)
- if stderr and not ns.pgo:
- print(stderr, file=sys.stderr)
- sys.stdout.flush()
- sys.stderr.flush()
- if result[0] == INTERRUPTED:
- raise KeyboardInterrupt
- if result[0] == CHILD_ERROR:
- raise Exception("Child error on {}: {}".format(test, result[1]))
- test_index += 1
- except KeyboardInterrupt:
- interrupted = True
- pending.interrupted = True
- for worker in workers:
- worker.join()
- else:
- for test_index, test in enumerate(tests, 1):
- if not ns.quiet:
- if bad and not ns.pgo:
- fmt = "[{1:{0}}{2}/{3}] {4}"
- else:
- fmt = "[{1:{0}}{2}] {4}"
- print(fmt.format(
- test_count_width, test_index, test_count, len(bad), test))
- sys.stdout.flush()
- if ns.trace:
- # If we're tracing code coverage, then we don't exit with status
- # if on a false return value from main.
- tracer.runctx('runtest(test, ns.verbose, ns.quiet, timeout=ns.timeout)',
- globals=globals(), locals=vars())
- else:
- try:
- result = runtest(test, ns.verbose, ns.quiet,
- ns.huntrleaks,
- output_on_failure=ns.verbose3,
- timeout=ns.timeout, failfast=ns.failfast,
- match_tests=ns.match_tests, pgo=ns.pgo)
- accumulate_result(test, result)
- except KeyboardInterrupt:
- interrupted = True
- break
- if ns.findleaks:
- gc.collect()
- if gc.garbage:
- print("Warning: test created", len(gc.garbage), end=' ')
- print("uncollectable object(s).")
- # move the uncollectable objects somewhere so we don't see
- # them again
- found_garbage.extend(gc.garbage)
- del gc.garbage[:]
- # Unload the newly imported modules (best effort finalization)
- for module in sys.modules.keys():
- if module not in save_modules and module.startswith("test."):
- support.unload(module)
-
- if interrupted and not ns.pgo:
- # print a newline after ^C
- print()
- print("Test suite interrupted by signal SIGINT.")
- omitted = set(selected) - set(good) - set(bad) - set(skipped)
- print(count(len(omitted), "test"), "omitted:")
- printlist(omitted)
- if good and not ns.quiet and not ns.pgo:
- if not bad and not skipped and not interrupted and len(good) > 1:
- print("All", end=' ')
- print(count(len(good), "test"), "OK.")
- if ns.print_slow:
- test_times.sort(reverse=True)
- print("10 slowest tests:")
- for time, test in test_times[:10]:
- print("%s: %.1fs" % (test, time))
- if bad and not ns.pgo:
- print(count(len(bad), "test"), "failed:")
- printlist(bad)
- if environment_changed and not ns.pgo:
- print("{} altered the execution environment:".format(
- count(len(environment_changed), "test")))
- printlist(environment_changed)
- if skipped and not ns.quiet and not ns.pgo:
- print(count(len(skipped), "test"), "skipped:")
- printlist(skipped)
-
- if ns.verbose2 and bad:
- print("Re-running failed tests in verbose mode")
- for test in bad[:]:
- if not ns.pgo:
- print("Re-running test %r in verbose mode" % test)
- sys.stdout.flush()
- try:
- ns.verbose = True
- ok = runtest(test, True, ns.quiet, ns.huntrleaks,
- timeout=ns.timeout, pgo=ns.pgo)
- except KeyboardInterrupt:
- # print a newline separate from the ^C
- print()
- break
- else:
- if ok[0] in {PASSED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED}:
- bad.remove(test)
- else:
- if bad:
- print(count(len(bad), 'test'), "failed again:")
- printlist(bad)
-
- if ns.single:
- if next_single_test:
- with open(filename, 'w') as fp:
- fp.write(next_single_test + '\n')
- else:
- os.unlink(filename)
-
- if ns.trace:
- r = tracer.results()
- r.write_results(show_missing=True, summary=True, coverdir=ns.coverdir)
+from test.libregrtest import main
- if ns.runleaks:
- os.system("leaks %d" % os.getpid())
- sys.exit(len(bad) > 0 or interrupted)
+# Alias for backward compatibility (just in case)
+main_in_temp_cwd = main
-# small set of tests to determine if we have a basically functioning interpreter
-# (i.e. if any of these fail, then anything else is likely to follow)
-STDTESTS = [
- 'test_grammar',
- 'test_opcodes',
- 'test_dict',
- 'test_builtin',
- 'test_exceptions',
- 'test_types',
- 'test_unittest',
- 'test_doctest',
- 'test_doctest2',
- 'test_support'
-]
+def _main():
+ global __file__
-# set of tests that we don't want to be executed when using regrtest
-NOTTESTS = set()
-
-def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
- """Return a list of all applicable test modules."""
- testdir = findtestdir(testdir)
- names = os.listdir(testdir)
- tests = []
- others = set(stdtests) | nottests
- for name in names:
- mod, ext = os.path.splitext(name)
- if mod[:5] == "test_" and ext in (".py", "") and mod not in others:
- tests.append(mod)
- return stdtests + sorted(tests)
-
-# We do not use a generator so multiple threads can call next().
-class MultiprocessTests(object):
-
- """A thread-safe iterator over tests for multiprocess mode."""
-
- def __init__(self, tests):
- self.interrupted = False
- self.lock = threading.Lock()
- self.tests = tests
-
- def __iter__(self):
- return self
-
- def __next__(self):
- with self.lock:
- if self.interrupted:
- raise StopIteration('tests interrupted')
- return next(self.tests)
-
-def replace_stdout():
- """Set stdout encoder error handler to backslashreplace (as stderr error
- handler) to avoid UnicodeEncodeError when printing a traceback"""
- import atexit
-
- stdout = sys.stdout
- sys.stdout = open(stdout.fileno(), 'w',
- encoding=stdout.encoding,
- errors="backslashreplace",
- closefd=False,
- newline='\n')
-
- def restore_stdout():
- sys.stdout.close()
- sys.stdout = stdout
- atexit.register(restore_stdout)
-
-def runtest(test, verbose, quiet,
- huntrleaks=False, use_resources=None,
- output_on_failure=False, failfast=False, match_tests=None,
- timeout=None, *, pgo=False):
- """Run a single test.
-
- test -- the name of the test
- verbose -- if true, print more messages
- quiet -- if true, don't print 'skipped' messages (probably redundant)
- huntrleaks -- run multiple times to test for leaks; requires a debug
- build; a triple corresponding to -R's three arguments
- use_resources -- list of extra resources to use
- output_on_failure -- if true, display test output on failure
- timeout -- dump the traceback and exit if a test takes more than
- timeout seconds
- failfast, match_tests -- See regrtest command-line flags for these.
- pgo -- if true, do not print unnecessary info when running the test
- for Profile Guided Optimization build
-
- Returns the tuple result, test_time, where result is one of the constants:
- INTERRUPTED KeyboardInterrupt when run under -j
- RESOURCE_DENIED test skipped because resource denied
- SKIPPED test skipped for some other reason
- ENV_CHANGED test failed because it changed the execution environment
- FAILED test failed
- PASSED test passed
- """
- if use_resources is not None:
- support.use_resources = use_resources
- use_timeout = (timeout is not None)
- if use_timeout:
- faulthandler.dump_traceback_later(timeout, exit=True)
- try:
- support.match_tests = match_tests
- if failfast:
- support.failfast = True
- if output_on_failure:
- support.verbose = True
-
- # Reuse the same instance to all calls to runtest(). Some
- # tests keep a reference to sys.stdout or sys.stderr
- # (eg. test_argparse).
- if runtest.stringio is None:
- stream = io.StringIO()
- runtest.stringio = stream
- else:
- stream = runtest.stringio
- stream.seek(0)
- stream.truncate()
-
- orig_stdout = sys.stdout
- orig_stderr = sys.stderr
- try:
- sys.stdout = stream
- sys.stderr = stream
- result = runtest_inner(test, verbose, quiet, huntrleaks,
- display_failure=False, pgo=pgo)
- if result[0] != PASSED and not pgo:
- output = stream.getvalue()
- orig_stderr.write(output)
- orig_stderr.flush()
- finally:
- sys.stdout = orig_stdout
- sys.stderr = orig_stderr
- else:
- support.verbose = verbose # Tell tests to be moderately quiet
- result = runtest_inner(test, verbose, quiet, huntrleaks,
- display_failure=not verbose, pgo=pgo)
- return result
- finally:
- if use_timeout:
- faulthandler.cancel_dump_traceback_later()
- cleanup_test_droppings(test, verbose)
-runtest.stringio = None
-
-# Unit tests are supposed to leave the execution environment unchanged
-# once they complete. But sometimes tests have bugs, especially when
-# tests fail, and the changes to environment go on to mess up other
-# tests. This can cause issues with buildbot stability, since tests
-# are run in random order and so problems may appear to come and go.
-# There are a few things we can save and restore to mitigate this, and
-# the following context manager handles this task.
-
-class saved_test_environment:
- """Save bits of the test environment and restore them at block exit.
-
- with saved_test_environment(testname, verbose, quiet):
- #stuff
-
- Unless quiet is True, a warning is printed to stderr if any of
- the saved items was changed by the test. The attribute 'changed'
- is initially False, but is set to True if a change is detected.
-
- If verbose is more than 1, the before and after state of changed
- items is also printed.
- """
-
- changed = False
-
- def __init__(self, testname, verbose=0, quiet=False, *, pgo=False):
- self.testname = testname
- self.verbose = verbose
- self.quiet = quiet
- self.pgo = pgo
-
- # To add things to save and restore, add a name XXX to the resources list
- # and add corresponding get_XXX/restore_XXX functions. get_XXX should
- # return the value to be saved and compared against a second call to the
- # get function when test execution completes. restore_XXX should accept
- # the saved value and restore the resource using it. It will be called if
- # and only if a change in the value is detected.
- #
- # Note: XXX will have any '.' replaced with '_' characters when determining
- # the corresponding method names.
-
- resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
- 'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
- 'warnings.filters', 'asyncore.socket_map',
- 'logging._handlers', 'logging._handlerList', 'sys.gettrace',
- 'sys.warnoptions',
- # multiprocessing.process._cleanup() may release ref
- # to a thread, so check processes first.
- 'multiprocessing.process._dangling', 'threading._dangling',
- 'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
- 'files', 'locale', 'warnings.showwarning',
- 'shutil_archive_formats', 'shutil_unpack_formats',
- )
-
- def get_sys_argv(self):
- return id(sys.argv), sys.argv, sys.argv[:]
- def restore_sys_argv(self, saved_argv):
- sys.argv = saved_argv[1]
- sys.argv[:] = saved_argv[2]
-
- def get_cwd(self):
- return os.getcwd()
- def restore_cwd(self, saved_cwd):
- os.chdir(saved_cwd)
-
- def get_sys_stdout(self):
- return sys.stdout
- def restore_sys_stdout(self, saved_stdout):
- sys.stdout = saved_stdout
-
- def get_sys_stderr(self):
- return sys.stderr
- def restore_sys_stderr(self, saved_stderr):
- sys.stderr = saved_stderr
-
- def get_sys_stdin(self):
- return sys.stdin
- def restore_sys_stdin(self, saved_stdin):
- sys.stdin = saved_stdin
-
- def get_os_environ(self):
- return id(os.environ), os.environ, dict(os.environ)
- def restore_os_environ(self, saved_environ):
- os.environ = saved_environ[1]
- os.environ.clear()
- os.environ.update(saved_environ[2])
-
- def get_sys_path(self):
- return id(sys.path), sys.path, sys.path[:]
- def restore_sys_path(self, saved_path):
- sys.path = saved_path[1]
- sys.path[:] = saved_path[2]
-
- def get_sys_path_hooks(self):
- return id(sys.path_hooks), sys.path_hooks, sys.path_hooks[:]
- def restore_sys_path_hooks(self, saved_hooks):
- sys.path_hooks = saved_hooks[1]
- sys.path_hooks[:] = saved_hooks[2]
-
- def get_sys_gettrace(self):
- return sys.gettrace()
- def restore_sys_gettrace(self, trace_fxn):
- sys.settrace(trace_fxn)
-
- def get___import__(self):
- return builtins.__import__
- def restore___import__(self, import_):
- builtins.__import__ = import_
-
- def get_warnings_filters(self):
- return id(warnings.filters), warnings.filters, warnings.filters[:]
- def restore_warnings_filters(self, saved_filters):
- warnings.filters = saved_filters[1]
- warnings.filters[:] = saved_filters[2]
-
- def get_asyncore_socket_map(self):
- asyncore = sys.modules.get('asyncore')
- # XXX Making a copy keeps objects alive until __exit__ gets called.
- return asyncore and asyncore.socket_map.copy() or {}
- def restore_asyncore_socket_map(self, saved_map):
- asyncore = sys.modules.get('asyncore')
- if asyncore is not None:
- asyncore.close_all(ignore_all=True)
- asyncore.socket_map.update(saved_map)
-
- def get_shutil_archive_formats(self):
- # we could call get_archives_formats() but that only returns the
- # registry keys; we want to check the values too (the functions that
- # are registered)
- return shutil._ARCHIVE_FORMATS, shutil._ARCHIVE_FORMATS.copy()
- def restore_shutil_archive_formats(self, saved):
- shutil._ARCHIVE_FORMATS = saved[0]
- shutil._ARCHIVE_FORMATS.clear()
- shutil._ARCHIVE_FORMATS.update(saved[1])
-
- def get_shutil_unpack_formats(self):
- return shutil._UNPACK_FORMATS, shutil._UNPACK_FORMATS.copy()
- def restore_shutil_unpack_formats(self, saved):
- shutil._UNPACK_FORMATS = saved[0]
- shutil._UNPACK_FORMATS.clear()
- shutil._UNPACK_FORMATS.update(saved[1])
-
- def get_logging__handlers(self):
- # _handlers is a WeakValueDictionary
- return id(logging._handlers), logging._handlers, logging._handlers.copy()
- def restore_logging__handlers(self, saved_handlers):
- # Can't easily revert the logging state
- pass
-
- def get_logging__handlerList(self):
- # _handlerList is a list of weakrefs to handlers
- return id(logging._handlerList), logging._handlerList, logging._handlerList[:]
- def restore_logging__handlerList(self, saved_handlerList):
- # Can't easily revert the logging state
- pass
-
- def get_sys_warnoptions(self):
- return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:]
- def restore_sys_warnoptions(self, saved_options):
- sys.warnoptions = saved_options[1]
- sys.warnoptions[:] = saved_options[2]
-
- # Controlling dangling references to Thread objects can make it easier
- # to track reference leaks.
- def get_threading__dangling(self):
- if not threading:
- return None
- # This copies the weakrefs without making any strong reference
- return threading._dangling.copy()
- def restore_threading__dangling(self, saved):
- if not threading:
- return
- threading._dangling.clear()
- threading._dangling.update(saved)
-
- # Same for Process objects
- def get_multiprocessing_process__dangling(self):
- if not multiprocessing:
- return None
- # Unjoined process objects can survive after process exits
- multiprocessing.process._cleanup()
- # This copies the weakrefs without making any strong reference
- return multiprocessing.process._dangling.copy()
- def restore_multiprocessing_process__dangling(self, saved):
- if not multiprocessing:
- return
- multiprocessing.process._dangling.clear()
- multiprocessing.process._dangling.update(saved)
-
- def get_sysconfig__CONFIG_VARS(self):
- # make sure the dict is initialized
- sysconfig.get_config_var('prefix')
- return (id(sysconfig._CONFIG_VARS), sysconfig._CONFIG_VARS,
- dict(sysconfig._CONFIG_VARS))
- def restore_sysconfig__CONFIG_VARS(self, saved):
- sysconfig._CONFIG_VARS = saved[1]
- sysconfig._CONFIG_VARS.clear()
- sysconfig._CONFIG_VARS.update(saved[2])
-
- def get_sysconfig__INSTALL_SCHEMES(self):
- return (id(sysconfig._INSTALL_SCHEMES), sysconfig._INSTALL_SCHEMES,
- sysconfig._INSTALL_SCHEMES.copy())
- def restore_sysconfig__INSTALL_SCHEMES(self, saved):
- sysconfig._INSTALL_SCHEMES = saved[1]
- sysconfig._INSTALL_SCHEMES.clear()
- sysconfig._INSTALL_SCHEMES.update(saved[2])
-
- def get_files(self):
- return sorted(fn + ('/' if os.path.isdir(fn) else '')
- for fn in os.listdir())
- def restore_files(self, saved_value):
- fn = support.TESTFN
- if fn not in saved_value and (fn + '/') not in saved_value:
- if os.path.isfile(fn):
- support.unlink(fn)
- elif os.path.isdir(fn):
- support.rmtree(fn)
-
- _lc = [getattr(locale, lc) for lc in dir(locale)
- if lc.startswith('LC_')]
- def get_locale(self):
- pairings = []
- for lc in self._lc:
- try:
- pairings.append((lc, locale.setlocale(lc, None)))
- except (TypeError, ValueError):
- continue
- return pairings
- def restore_locale(self, saved):
- for lc, setting in saved:
- locale.setlocale(lc, setting)
-
- def get_warnings_showwarning(self):
- return warnings.showwarning
- def restore_warnings_showwarning(self, fxn):
- warnings.showwarning = fxn
-
- def resource_info(self):
- for name in self.resources:
- method_suffix = name.replace('.', '_')
- get_name = 'get_' + method_suffix
- restore_name = 'restore_' + method_suffix
- yield name, getattr(self, get_name), getattr(self, restore_name)
-
- def __enter__(self):
- self.saved_values = dict((name, get()) for name, get, restore
- in self.resource_info())
- return self
-
- def __exit__(self, exc_type, exc_val, exc_tb):
- saved_values = self.saved_values
- del self.saved_values
- support.gc_collect() # Some resources use weak references
- for name, get, restore in self.resource_info():
- current = get()
- original = saved_values.pop(name)
- # Check for changes to the resource's value
- if current != original:
- self.changed = True
- restore(original)
- if not self.quiet and not self.pgo:
- print("Warning -- {} was modified by {}".format(
- name, self.testname),
- file=sys.stderr)
- if self.verbose > 1 and not self.pgo:
- print(" Before: {}\n After: {} ".format(
- original, current),
- file=sys.stderr)
- return False
-
-
-def runtest_inner(test, verbose, quiet,
- huntrleaks=False, display_failure=True, pgo=False):
- support.unload(test)
-
- test_time = 0.0
- refleak = False # True if the test leaked references.
- try:
- if test.startswith('test.'):
- abstest = test
- else:
- # Always import it from the test package
- abstest = 'test.' + test
- with saved_test_environment(test, verbose, quiet, pgo=pgo) as environment:
- start_time = time.time()
- the_module = importlib.import_module(abstest)
- # If the test has a test_main, that will run the appropriate
- # tests. If not, use normal unittest test loading.
- test_runner = getattr(the_module, "test_main", None)
- if test_runner is None:
- def test_runner():
- loader = unittest.TestLoader()
- tests = loader.loadTestsFromModule(the_module)
- for error in loader.errors:
- print(error, file=sys.stderr)
- if loader.errors:
- raise Exception("errors while loading tests")
- support.run_unittest(tests)
- test_runner()
- if huntrleaks:
- refleak = dash_R(the_module, test, test_runner, huntrleaks)
- test_time = time.time() - start_time
- except support.ResourceDenied as msg:
- if not quiet and not pgo:
- print(test, "skipped --", msg)
- sys.stdout.flush()
- return RESOURCE_DENIED, test_time
- except unittest.SkipTest as msg:
- if not quiet and not pgo:
- print(test, "skipped --", msg)
- sys.stdout.flush()
- return SKIPPED, test_time
- except KeyboardInterrupt:
- raise
- except support.TestFailed as msg:
- if not pgo:
- if display_failure:
- print("test", test, "failed --", msg, file=sys.stderr)
- else:
- print("test", test, "failed", file=sys.stderr)
- sys.stderr.flush()
- return FAILED, test_time
- except:
- msg = traceback.format_exc()
- if not pgo:
- print("test", test, "crashed --", msg, file=sys.stderr)
- sys.stderr.flush()
- return FAILED, test_time
- else:
- if refleak:
- return FAILED, test_time
- if environment.changed:
- return ENV_CHANGED, test_time
- return PASSED, test_time
-
-def cleanup_test_droppings(testname, verbose):
- import shutil
- import stat
- import gc
-
- # First kill any dangling references to open files etc.
- # This can also issue some ResourceWarnings which would otherwise get
- # triggered during the following test run, and possibly produce failures.
- gc.collect()
-
- # Try to clean up junk commonly left behind. While tests shouldn't leave
- # any files or directories behind, when a test fails that can be tedious
- # for it to arrange. The consequences can be especially nasty on Windows,
- # since if a test leaves a file open, it cannot be deleted by name (while
- # there's nothing we can do about that here either, we can display the
- # name of the offending test, which is a real help).
- for name in (support.TESTFN,
- "db_home",
- ):
- if not os.path.exists(name):
- continue
-
- if os.path.isdir(name):
- kind, nuker = "directory", shutil.rmtree
- elif os.path.isfile(name):
- kind, nuker = "file", os.unlink
- else:
- raise SystemError("os.path says %r exists but is neither "
- "directory nor file" % name)
-
- if verbose:
- print("%r left behind %s %r" % (testname, kind, name))
- try:
- # if we have chmod, fix possible permissions problems
- # that might prevent cleanup
- if (hasattr(os, 'chmod')):
- os.chmod(name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
- nuker(name)
- except Exception as msg:
- print(("%r left behind %s %r and it couldn't be "
- "removed: %s" % (testname, kind, name, msg)), file=sys.stderr)
-
-def dash_R(the_module, test, indirect_test, huntrleaks):
- """Run a test multiple times, looking for reference leaks.
-
- Returns:
- False if the test didn't leak references; True if we detected refleaks.
- """
- # This code is hackish and inelegant, but it seems to do the job.
- import copyreg
- import collections.abc
-
- if not hasattr(sys, 'gettotalrefcount'):
- raise Exception("Tracking reference leaks requires a debug build "
- "of Python")
-
- # Save current values for dash_R_cleanup() to restore.
- fs = warnings.filters[:]
- ps = copyreg.dispatch_table.copy()
- pic = sys.path_importer_cache.copy()
- try:
- import zipimport
- except ImportError:
- zdc = None # Run unmodified on platforms without zipimport support
- else:
- zdc = zipimport._zip_directory_cache.copy()
- abcs = {}
- for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]:
- if not isabstract(abc):
- continue
- for obj in abc.__subclasses__() + [abc]:
- abcs[obj] = obj._abc_registry.copy()
-
- nwarmup, ntracked, fname = huntrleaks
- fname = os.path.join(support.SAVEDCWD, fname)
- repcount = nwarmup + ntracked
- rc_deltas = [0] * repcount
- alloc_deltas = [0] * repcount
-
- print("beginning", repcount, "repetitions", file=sys.stderr)
- print(("1234567890"*(repcount//10 + 1))[:repcount], file=sys.stderr)
- sys.stderr.flush()
- for i in range(repcount):
- indirect_test()
- alloc_after, rc_after = dash_R_cleanup(fs, ps, pic, zdc, abcs)
- sys.stderr.write('.')
- sys.stderr.flush()
- if i >= nwarmup:
- rc_deltas[i] = rc_after - rc_before
- alloc_deltas[i] = alloc_after - alloc_before
- alloc_before, rc_before = alloc_after, rc_after
- print(file=sys.stderr)
- # These checkers return False on success, True on failure
- def check_rc_deltas(deltas):
- return any(deltas)
- def check_alloc_deltas(deltas):
- # At least 1/3rd of 0s
- if 3 * deltas.count(0) < len(deltas):
- return True
- # Nothing else than 1s, 0s and -1s
- if not set(deltas) <= {1,0,-1}:
- return True
- return False
- failed = False
- for deltas, item_name, checker in [
- (rc_deltas, 'references', check_rc_deltas),
- (alloc_deltas, 'memory blocks', check_alloc_deltas)]:
- if checker(deltas):
- msg = '%s leaked %s %s, sum=%s' % (
- test, deltas[nwarmup:], item_name, sum(deltas))
- print(msg, file=sys.stderr)
- sys.stderr.flush()
- with open(fname, "a") as refrep:
- print(msg, file=refrep)
- refrep.flush()
- failed = True
- return failed
-
-def dash_R_cleanup(fs, ps, pic, zdc, abcs):
- import gc, copyreg
- import _strptime, linecache
- import urllib.parse, urllib.request, mimetypes, doctest
- import struct, filecmp, collections.abc
- from distutils.dir_util import _path_created
- from weakref import WeakSet
-
- # Clear the warnings registry, so they can be displayed again
- for mod in sys.modules.values():
- if hasattr(mod, '__warningregistry__'):
- del mod.__warningregistry__
-
- # Restore some original values.
- warnings.filters[:] = fs
- copyreg.dispatch_table.clear()
- copyreg.dispatch_table.update(ps)
- sys.path_importer_cache.clear()
- sys.path_importer_cache.update(pic)
- try:
- import zipimport
- except ImportError:
- pass # Run unmodified on platforms without zipimport support
- else:
- zipimport._zip_directory_cache.clear()
- zipimport._zip_directory_cache.update(zdc)
-
- # clear type cache
- sys._clear_type_cache()
-
- # Clear ABC registries, restoring previously saved ABC registries.
- for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]:
- if not isabstract(abc):
- continue
- for obj in abc.__subclasses__() + [abc]:
- obj._abc_registry = abcs.get(obj, WeakSet()).copy()
- obj._abc_cache.clear()
- obj._abc_negative_cache.clear()
-
- # Flush standard output, so that buffered data is sent to the OS and
- # associated Python objects are reclaimed.
- for stream in (sys.stdout, sys.stderr, sys.__stdout__, sys.__stderr__):
- if stream is not None:
- stream.flush()
-
- # Clear assorted module caches.
- _path_created.clear()
- re.purge()
- _strptime._regex_cache.clear()
- urllib.parse.clear_cache()
- urllib.request.urlcleanup()
- linecache.clearcache()
- mimetypes._default_mime_types()
- filecmp._cache.clear()
- struct._clearcache()
- doctest.master = None
- try:
- import ctypes
- except ImportError:
- # Don't worry about resetting the cache if ctypes is not supported
- pass
- else:
- ctypes._reset_cache()
-
- # Collect cyclic trash and read memory statistics immediately after.
- func1 = sys.getallocatedblocks
- func2 = sys.gettotalrefcount
- gc.collect()
- return func1(), func2()
-
-def warm_caches():
- # char cache
- s = bytes(range(256))
- for i in range(256):
- s[i:i+1]
- # unicode cache
- x = [chr(i) for i in range(256)]
- # int cache
- x = list(range(-5, 257))
-
-def findtestdir(path=None):
- return path or os.path.dirname(__file__) or os.curdir
-
-def removepy(names):
- if not names:
- return
- for idx, name in enumerate(names):
- basename, ext = os.path.splitext(name)
- if ext == '.py':
- names[idx] = basename
-
-def count(n, word):
- if n == 1:
- return "%d %s" % (n, word)
- else:
- return "%d %ss" % (n, word)
-
-def printlist(x, width=70, indent=4):
- """Print the elements of iterable x to stdout.
-
- Optional arg width (default 70) is the maximum line length.
- Optional arg indent (default 4) is the number of blanks with which to
- begin each line.
- """
-
- from textwrap import fill
- blanks = ' ' * indent
- # Print the sorted list: 'x' may be a '--random' list or a set()
- print(fill(' '.join(str(elt) for elt in sorted(x)), width,
- initial_indent=blanks, subsequent_indent=blanks))
-
-
-def main_in_temp_cwd():
- """Run main() in a temporary working directory."""
- if sysconfig.is_python_build():
- try:
- os.mkdir(TEMPDIR)
- except FileExistsError:
- pass
-
- # Define a writable temp dir that will be used as cwd while running
- # the tests. The name of the dir includes the pid to allow parallel
- # testing (see the -j option).
- test_cwd = 'test_python_{}'.format(os.getpid())
- test_cwd = os.path.join(TEMPDIR, test_cwd)
-
- # Run the tests in a context manager that temporarily changes the CWD to a
- # temporary and writable directory. If it's not possible to create or
- # change the CWD, the original CWD will be used. The original CWD is
- # available from support.SAVEDCWD.
- with support.temp_cwd(test_cwd, quiet=True):
- main()
-
-
-if __name__ == '__main__':
# Remove regrtest.py's own directory from the module search path. Despite
# the elimination of implicit relative imports, this is still needed to
# ensure that submodules of the test package do not inappropriately appear
# as top-level modules even when people (or buildbots!) invoke regrtest.py
# directly instead of using the -m switch
mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
- i = len(sys.path)
+ i = len(sys.path) - 1
while i >= 0:
- i -= 1
if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
del sys.path[i]
+ else:
+ i -= 1
# findtestdir() gets the dirname out of __file__, so we have to make it
# absolute before changing the working directory.
@@ -1618,4 +43,8 @@ if __name__ == '__main__':
# sanity check
assert __file__ == os.path.abspath(sys.argv[0])
- main_in_temp_cwd()
+ main()
+
+
+if __name__ == '__main__':
+ _main()
diff --git a/Lib/test/seq_tests.py b/Lib/test/seq_tests.py
index 72f4845..1e7a6f6 100644
--- a/Lib/test/seq_tests.py
+++ b/Lib/test/seq_tests.py
@@ -318,7 +318,6 @@ class CommonTest(unittest.TestCase):
self.assertEqual(id(s), id(s*1))
def test_bigrepeat(self):
- import sys
if sys.maxsize <= 2147483647:
x = self.type2test([0])
x *= 2**16
diff --git a/Lib/test/signalinterproctester.py b/Lib/test/signalinterproctester.py
new file mode 100644
index 0000000..d3ae170
--- /dev/null
+++ b/Lib/test/signalinterproctester.py
@@ -0,0 +1,84 @@
+import os
+import signal
+import subprocess
+import sys
+import time
+import unittest
+
+
+class SIGUSR1Exception(Exception):
+ pass
+
+
+class InterProcessSignalTests(unittest.TestCase):
+ def setUp(self):
+ self.got_signals = {'SIGHUP': 0, 'SIGUSR1': 0, 'SIGALRM': 0}
+
+ def sighup_handler(self, signum, frame):
+ self.got_signals['SIGHUP'] += 1
+
+ def sigusr1_handler(self, signum, frame):
+ self.got_signals['SIGUSR1'] += 1
+ raise SIGUSR1Exception
+
+ def wait_signal(self, child, signame, exc_class=None):
+ try:
+ if child is not None:
+ # This wait should be interrupted by exc_class
+ # (if set)
+ child.wait()
+
+ timeout = 10.0
+ deadline = time.monotonic() + timeout
+
+ while time.monotonic() < deadline:
+ if self.got_signals[signame]:
+ return
+ signal.pause()
+ except BaseException as exc:
+ if exc_class is not None and isinstance(exc, exc_class):
+ # got the expected exception
+ return
+ raise
+
+ self.fail('signal %s not received after %s seconds'
+ % (signame, timeout))
+
+ def subprocess_send_signal(self, pid, signame):
+ code = 'import os, signal; os.kill(%s, signal.%s)' % (pid, signame)
+ args = [sys.executable, '-I', '-c', code]
+ return subprocess.Popen(args)
+
+ def test_interprocess_signal(self):
+ # Install handlers. This function runs in a sub-process, so we
+ # don't worry about re-setting the default handlers.
+ signal.signal(signal.SIGHUP, self.sighup_handler)
+ signal.signal(signal.SIGUSR1, self.sigusr1_handler)
+ signal.signal(signal.SIGUSR2, signal.SIG_IGN)
+ signal.signal(signal.SIGALRM, signal.default_int_handler)
+
+ # Let the sub-processes know who to send signals to.
+ pid = str(os.getpid())
+
+ with self.subprocess_send_signal(pid, "SIGHUP") as child:
+ self.wait_signal(child, 'SIGHUP')
+ self.assertEqual(self.got_signals, {'SIGHUP': 1, 'SIGUSR1': 0,
+ 'SIGALRM': 0})
+
+ with self.subprocess_send_signal(pid, "SIGUSR1") as child:
+ self.wait_signal(child, 'SIGUSR1', SIGUSR1Exception)
+ self.assertEqual(self.got_signals, {'SIGHUP': 1, 'SIGUSR1': 1,
+ 'SIGALRM': 0})
+
+ with self.subprocess_send_signal(pid, "SIGUSR2") as child:
+ # Nothing should happen: SIGUSR2 is ignored
+ child.wait()
+
+ signal.alarm(1)
+ self.wait_signal(None, 'SIGALRM', KeyboardInterrupt)
+ self.assertEqual(self.got_signals, {'SIGHUP': 1, 'SIGUSR1': 1,
+ 'SIGALRM': 0})
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py
index 90722f7..171e5ce 100644
--- a/Lib/test/sortperf.py
+++ b/Lib/test/sortperf.py
@@ -64,7 +64,7 @@ def doit(L):
flush()
def tabulate(r):
- """Tabulate sort speed for lists of various sizes.
+ r"""Tabulate sort speed for lists of various sizes.
The sizes are 2**i for i in r (the argument, a list).
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 007f3bc..8b66f95 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -26,6 +26,7 @@ import sys
import sysconfig
import tempfile
import time
+import types
import unittest
import urllib.error
import warnings
@@ -89,8 +90,9 @@ __all__ = [
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
+ "check__all__",
# sys
- "is_jython", "check_impl_detail",
+ "is_jython", "is_android", "check_impl_detail", "unix_shell",
# network
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
# processes
@@ -103,7 +105,7 @@ __all__ = [
"check_warnings", "check_no_resource_warning", "EnvironmentVarGuard",
"run_with_locale", "swap_item",
"swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict",
- "run_with_tz",
+ "run_with_tz", "PGO",
]
class Error(Exception):
@@ -733,6 +735,13 @@ requires_lzma = unittest.skipUnless(lzma, 'requires lzma')
is_jython = sys.platform.startswith('java')
+is_android = bool(sysconfig.get_config_var('ANDROID_API_LEVEL'))
+
+if sys.platform != 'win32':
+ unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
+else:
+ unix_shell = None
+
# Filename used for testing
if os.name == 'java':
# Jython disallows @ in module names
@@ -802,7 +811,7 @@ TESTFN_ENCODING = sys.getfilesystemencoding()
# encoded by the filesystem encoding (in strict mode). It can be None if we
# cannot generate such filename.
TESTFN_UNENCODABLE = None
-if os.name in ('nt', 'ce'):
+if os.name == 'nt':
# skip win32s (0) or Windows 9x/ME (1)
if sys.getwindowsversion().platform >= 2:
# Different kinds of characters from various languages to minimize the
@@ -869,6 +878,10 @@ else:
# Save the initial cwd
SAVEDCWD = os.getcwd()
+# Set by libregrtest/main.py so we can skip tests that are not
+# useful for PGO
+PGO = False
+
@contextlib.contextmanager
def temp_dir(path=None, quiet=False):
"""Return a context manager that creates a temporary directory.
@@ -901,7 +914,7 @@ def temp_dir(path=None, quiet=False):
yield path
finally:
if dir_created:
- shutil.rmtree(path)
+ rmtree(path)
@contextlib.contextmanager
def change_cwd(path, quiet=False):
@@ -2078,6 +2091,11 @@ def args_from_interpreter_flags():
settings in sys.flags and sys.warnoptions."""
return subprocess._args_from_interpreter_flags()
+def optim_args_from_interpreter_flags():
+ """Return a list of command-line arguments reproducing the current
+ optimization settings in sys.flags."""
+ return subprocess._optim_args_from_interpreter_flags()
+
#============================================================
# Support for assertions about logging.
#============================================================
@@ -2184,7 +2202,7 @@ def can_xattr():
os.setxattr(fp.fileno(), b"user.test", b"")
# Kernels < 2.6.39 don't respect setxattr flags.
kernel_version = platform.release()
- m = re.match("2.6.(\d{1,2})", kernel_version)
+ m = re.match(r"2.6.(\d{1,2})", kernel_version)
can = m is None or int(m.group(1)) >= 39
except OSError:
can = False
@@ -2229,6 +2247,65 @@ def detect_api_mismatch(ref_api, other_api, *, ignore=()):
return missing_items
+def check__all__(test_case, module, name_of_module=None, extra=(),
+ blacklist=()):
+ """Assert that the __all__ variable of 'module' contains all public names.
+
+ The module's public names (its API) are detected automatically based on
+ whether they match the public name convention and were defined in
+ 'module'.
+
+ The 'name_of_module' argument can specify (as a string or tuple thereof)
+ what module(s) an API could be defined in in order to be detected as a
+ public API. One case for this is when 'module' imports part of its public
+ API from other modules, possibly a C backend (like 'csv' and its '_csv').
+
+ The 'extra' argument can be a set of names that wouldn't otherwise be
+ automatically detected as "public", like objects without a proper
+ '__module__' attriubute. If provided, it will be added to the
+ automatically detected ones.
+
+ The 'blacklist' argument can be a set of names that must not be treated
+ as part of the public API even though their names indicate otherwise.
+
+ Usage:
+ import bar
+ import foo
+ import unittest
+ from test import support
+
+ class MiscTestCase(unittest.TestCase):
+ def test__all__(self):
+ support.check__all__(self, foo)
+
+ class OtherTestCase(unittest.TestCase):
+ def test__all__(self):
+ extra = {'BAR_CONST', 'FOO_CONST'}
+ blacklist = {'baz'} # Undocumented name.
+ # bar imports part of its API from _bar.
+ support.check__all__(self, bar, ('bar', '_bar'),
+ extra=extra, blacklist=blacklist)
+
+ """
+
+ if name_of_module is None:
+ name_of_module = (module.__name__, )
+ elif isinstance(name_of_module, str):
+ name_of_module = (name_of_module, )
+
+ expected = set(extra)
+
+ for name in dir(module):
+ if name.startswith('_') or name in blacklist:
+ continue
+ obj = getattr(module, name)
+ if (getattr(obj, '__module__', None) in name_of_module or
+ (not hasattr(obj, '__module__') and
+ not isinstance(obj, types.ModuleType))):
+ expected.add(name)
+ test_case.assertCountEqual(module.__all__, expected)
+
+
class SuppressCrashReport:
"""Try to prevent a crash report from popping up.
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index e94d984..ae9114e 100644
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -38,6 +38,8 @@ class AllTest(unittest.TestCase):
modname, e.__class__.__name__, e))
if "__builtins__" in names:
del names["__builtins__"]
+ if '__annotations__' in names:
+ del names['__annotations__']
keys = set(names)
all_list = sys.modules[modname].__all__
all_set = set(all_list)
diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py
index 58f2f04..ab4e247 100644
--- a/Lib/test/test__locale.py
+++ b/Lib/test/test__locale.py
@@ -4,7 +4,6 @@ try:
except ImportError:
nl_langinfo = None
-import codecs
import locale
import sys
import unittest
diff --git a/Lib/test/test__osx_support.py b/Lib/test/test__osx_support.py
index ac6325a..bcba8ca 100644
--- a/Lib/test/test__osx_support.py
+++ b/Lib/test/test__osx_support.py
@@ -4,7 +4,6 @@ Test suite for _osx_support: shared OS X support functions.
import os
import platform
-import shutil
import stat
import sys
import unittest
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py
index ab51437..1bd1f89 100644
--- a/Lib/test/test_aifc.py
+++ b/Lib/test/test_aifc.py
@@ -2,7 +2,6 @@ from test.support import findfile, TESTFN, unlink
import unittest
from test import audiotests
from audioop import byteswap
-import os
import io
import sys
import struct
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 4779a13..bc83161 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -4512,6 +4512,21 @@ class TestStrings(TestCase):
string = "Namespace(bar='spam', foo=42)"
self.assertStringEqual(ns, string)
+ def test_namespace_starkwargs_notidentifier(self):
+ ns = argparse.Namespace(**{'"': 'quote'})
+ string = """Namespace(**{'"': 'quote'})"""
+ self.assertStringEqual(ns, string)
+
+ def test_namespace_kwargs_and_starkwargs_notidentifier(self):
+ ns = argparse.Namespace(a=1, **{'"': 'quote'})
+ string = """Namespace(a=1, **{'"': 'quote'})"""
+ self.assertStringEqual(ns, string)
+
+ def test_namespace_starkwargs_identifier(self):
+ ns = argparse.Namespace(**{'valid': True})
+ string = "Namespace(valid=True)"
+ self.assertStringEqual(ns, string)
+
def test_parser(self):
parser = argparse.ArgumentParser(prog='PROG')
string = (
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 2a21e74..1f8967c 100644
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -7,8 +7,6 @@ from test import support
import weakref
import pickle
import operator
-import io
-import math
import struct
import sys
import warnings
@@ -328,8 +326,19 @@ class BaseTest:
d = pickle.dumps((itorig, orig), proto)
it, a = pickle.loads(d)
a.fromlist(data2)
- self.assertEqual(type(it), type(itorig))
- self.assertEqual(list(it), data2)
+ self.assertEqual(list(it), [])
+
+ def test_exhausted_iterator(self):
+ a = array.array(self.typecode, self.example)
+ self.assertEqual(list(a), list(self.example))
+ exhit = iter(a)
+ empit = iter(a)
+ for x in exhit: # exhaust the iterator
+ next(empit) # not exhausted
+ a.append(self.outside)
+ self.assertEqual(list(exhit), [])
+ self.assertEqual(list(empit), [self.outside])
+ self.assertEqual(list(a), list(self.example) + [self.outside])
def test_insert(self):
a = array.array(self.typecode, self.example)
@@ -1080,6 +1089,12 @@ class BaseTest:
a = array.array('B', b"")
self.assertRaises(BufferError, getbuffer_with_null_view, a)
+ def test_free_after_iterating(self):
+ support.check_free_after_iterating(self, iter, array.array,
+ (self.typecode,))
+ support.check_free_after_iterating(self, reversed, array.array,
+ (self.typecode,))
+
class StringTest(BaseTest):
def test_setitem(self):
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index d3e6d35..8c62408 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1,7 +1,8 @@
+import ast
+import dis
import os
import sys
import unittest
-import ast
import weakref
from test import support
@@ -115,6 +116,8 @@ exec_tests = [
# PEP 448: Additional Unpacking Generalizations
"{**{1:2}, 2:3}",
"{*{1, 2}, 3}",
+ # Asynchronous comprehensions
+ "async def f():\n [i async for b in c]",
]
# These are compiled through "single"
@@ -238,7 +241,7 @@ class AST_Tests(unittest.TestCase):
ast_tree = compile(i, "?", kind, ast.PyCF_ONLY_AST)
self.assertEqual(to_tuple(ast_tree), o)
self._assertTrueorder(ast_tree, (0, 0))
- with self.subTest(action="compiling", input=i):
+ with self.subTest(action="compiling", input=i, kind=kind):
compile(ast_tree, "?", kind)
def test_slice(self):
@@ -547,6 +550,17 @@ class ASTHelpers_Test(unittest.TestCase):
compile(mod, 'test', 'exec')
self.assertIn("invalid integer value: None", str(cm.exception))
+ def test_level_as_none(self):
+ body = [ast.ImportFrom(module='time',
+ names=[ast.alias(name='sleep')],
+ level=None,
+ lineno=0, col_offset=0)]
+ mod = ast.Module(body)
+ code = compile(mod, 'test', 'exec')
+ ns = {}
+ exec(code, ns)
+ self.assertIn('sleep', ns)
+
class ASTValidatorTests(unittest.TestCase):
@@ -742,7 +756,7 @@ class ASTValidatorTests(unittest.TestCase):
def test_importfrom(self):
imp = ast.ImportFrom(None, [ast.alias("x", None)], -42)
- self.stmt(imp, "level less than -1")
+ self.stmt(imp, "Negative ImportFrom level")
self.stmt(ast.ImportFrom(None, [], 0), "empty names on ImportFrom")
def test_global(self):
@@ -797,21 +811,21 @@ class ASTValidatorTests(unittest.TestCase):
def _check_comprehension(self, fac):
self.expr(fac([]), "comprehension with no generators")
g = ast.comprehension(ast.Name("x", ast.Load()),
- ast.Name("x", ast.Load()), [])
+ ast.Name("x", ast.Load()), [], 0)
self.expr(fac([g]), "must have Store context")
g = ast.comprehension(ast.Name("x", ast.Store()),
- ast.Name("x", ast.Store()), [])
+ ast.Name("x", ast.Store()), [], 0)
self.expr(fac([g]), "must have Load context")
x = ast.Name("x", ast.Store())
y = ast.Name("y", ast.Load())
- g = ast.comprehension(x, y, [None])
+ g = ast.comprehension(x, y, [None], 0)
self.expr(fac([g]), "None disallowed")
- g = ast.comprehension(x, y, [ast.Name("x", ast.Store())])
+ g = ast.comprehension(x, y, [ast.Name("x", ast.Store())], 0)
self.expr(fac([g]), "must have Load context")
def _simple_comp(self, fac):
g = ast.comprehension(ast.Name("x", ast.Store()),
- ast.Name("x", ast.Load()), [])
+ ast.Name("x", ast.Load()), [], 0)
self.expr(fac(ast.Name("x", ast.Store()), [g]),
"must have Load context")
def wrap(gens):
@@ -829,7 +843,7 @@ class ASTValidatorTests(unittest.TestCase):
def test_dictcomp(self):
g = ast.comprehension(ast.Name("y", ast.Store()),
- ast.Name("p", ast.Load()), [])
+ ast.Name("p", ast.Load()), [], 0)
c = ast.DictComp(ast.Name("x", ast.Store()),
ast.Name("y", ast.Load()), [g])
self.expr(c, "must have Load context")
@@ -933,6 +947,125 @@ class ASTValidatorTests(unittest.TestCase):
compile(mod, fn, "exec")
+class ConstantTests(unittest.TestCase):
+ """Tests on the ast.Constant node type."""
+
+ def compile_constant(self, value):
+ tree = ast.parse("x = 123")
+
+ node = tree.body[0].value
+ new_node = ast.Constant(value=value)
+ ast.copy_location(new_node, node)
+ tree.body[0].value = new_node
+
+ code = compile(tree, "<string>", "exec")
+
+ ns = {}
+ exec(code, ns)
+ return ns['x']
+
+ def test_validation(self):
+ with self.assertRaises(TypeError) as cm:
+ self.compile_constant([1, 2, 3])
+ self.assertEqual(str(cm.exception),
+ "got an invalid type in Constant: list")
+
+ def test_singletons(self):
+ for const in (None, False, True, Ellipsis, b'', frozenset()):
+ with self.subTest(const=const):
+ value = self.compile_constant(const)
+ self.assertIs(value, const)
+
+ def test_values(self):
+ nested_tuple = (1,)
+ nested_frozenset = frozenset({1})
+ for level in range(3):
+ nested_tuple = (nested_tuple, 2)
+ nested_frozenset = frozenset({nested_frozenset, 2})
+ values = (123, 123.0, 123j,
+ "unicode", b'bytes',
+ tuple("tuple"), frozenset("frozenset"),
+ nested_tuple, nested_frozenset)
+ for value in values:
+ with self.subTest(value=value):
+ result = self.compile_constant(value)
+ self.assertEqual(result, value)
+
+ def test_assign_to_constant(self):
+ tree = ast.parse("x = 1")
+
+ target = tree.body[0].targets[0]
+ new_target = ast.Constant(value=1)
+ ast.copy_location(new_target, target)
+ tree.body[0].targets[0] = new_target
+
+ with self.assertRaises(ValueError) as cm:
+ compile(tree, "string", "exec")
+ self.assertEqual(str(cm.exception),
+ "expression which can't be assigned "
+ "to in Store context")
+
+ def test_get_docstring(self):
+ tree = ast.parse("'docstring'\nx = 1")
+ self.assertEqual(ast.get_docstring(tree), 'docstring')
+
+ tree.body[0].value = ast.Constant(value='constant docstring')
+ self.assertEqual(ast.get_docstring(tree), 'constant docstring')
+
+ def get_load_const(self, tree):
+ # Compile to bytecode, disassemble and get parameter of LOAD_CONST
+ # instructions
+ co = compile(tree, '<string>', 'exec')
+ consts = []
+ for instr in dis.get_instructions(co):
+ if instr.opname == 'LOAD_CONST':
+ consts.append(instr.argval)
+ return consts
+
+ @support.cpython_only
+ def test_load_const(self):
+ consts = [None,
+ True, False,
+ 124,
+ 2.0,
+ 3j,
+ "unicode",
+ b'bytes',
+ (1, 2, 3)]
+
+ code = '\n'.join(['x={!r}'.format(const) for const in consts])
+ code += '\nx = ...'
+ consts.extend((Ellipsis, None))
+
+ tree = ast.parse(code)
+ self.assertEqual(self.get_load_const(tree),
+ consts)
+
+ # Replace expression nodes with constants
+ for assign, const in zip(tree.body, consts):
+ assert isinstance(assign, ast.Assign), ast.dump(assign)
+ new_node = ast.Constant(value=const)
+ ast.copy_location(new_node, assign.value)
+ assign.value = new_node
+
+ self.assertEqual(self.get_load_const(tree),
+ consts)
+
+ def test_literal_eval(self):
+ tree = ast.parse("1 + 2")
+ binop = tree.body[0].value
+
+ new_left = ast.Constant(value=10)
+ ast.copy_location(new_left, binop.left)
+ binop.left = new_left
+
+ new_right = ast.Constant(value=20)
+ ast.copy_location(new_right, binop.right)
+ binop.right = new_right
+
+ self.assertEqual(ast.literal_eval(binop), 30)
+
+
def main():
if __name__ != '__main__':
return
@@ -940,8 +1073,9 @@ def main():
for statements, kind in ((exec_tests, "exec"), (single_tests, "single"),
(eval_tests, "eval")):
print(kind+"_results = [")
- for s in statements:
- print(repr(to_tuple(compile(s, "?", kind, 0x400)))+",")
+ for statement in statements:
+ tree = ast.parse(statement, "?", kind)
+ print("%r," % (to_tuple(tree),))
print("]")
print("main()")
raise SystemExit
@@ -979,19 +1113,20 @@ exec_results = [
('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Break', (1, 11))], [])]),
('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Continue', (1, 11))], [])]),
('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)), ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load',)), [('Pass', (1, 14))], [])]),
-('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]),
-('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]),
-('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 12), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [])]))]),
-('Module', [('Expr', (1, 0), ('GeneratorExp', (2, 4), ('Tuple', (3, 4), [('Name', (3, 4), 'Aa', ('Load',)), ('Name', (5, 7), 'Bb', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (8, 4), [('Name', (8, 4), 'Aa', ('Store',)), ('Name', (10, 4), 'Bb', ('Store',))], ('Store',)), ('Name', (10, 10), 'Cc', ('Load',)), [])]))]),
-('Module', [('Expr', (1, 0), ('DictComp', (1, 0), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Name', (1, 11), 'w', ('Store',)), ('Name', (1, 16), 'x', ('Load',)), []), ('comprehension', ('Name', (1, 22), 'm', ('Store',)), ('Name', (1, 27), 'p', ('Load',)), [('Name', (1, 32), 'g', ('Load',))])]))]),
-('Module', [('Expr', (1, 0), ('DictComp', (1, 0), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'v', ('Store',)), ('Name', (1, 13), 'w', ('Store',))], ('Store',)), ('Name', (1, 18), 'x', ('Load',)), [])]))]),
-('Module', [('Expr', (1, 0), ('SetComp', (1, 0), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 12), 'x', ('Load',)), [('Name', (1, 17), 'g', ('Load',))])]))]),
-('Module', [('Expr', (1, 0), ('SetComp', (1, 0), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Tuple', (1, 7), [('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 9), 'm', ('Store',))], ('Store',)), ('Name', (1, 14), 'x', ('Load',)), [])]))]),
+('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [], 0)]))]),
+('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [], 0)]))]),
+('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 12), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [], 0)]))]),
+('Module', [('Expr', (1, 0), ('GeneratorExp', (2, 4), ('Tuple', (3, 4), [('Name', (3, 4), 'Aa', ('Load',)), ('Name', (5, 7), 'Bb', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (8, 4), [('Name', (8, 4), 'Aa', ('Store',)), ('Name', (10, 4), 'Bb', ('Store',))], ('Store',)), ('Name', (10, 10), 'Cc', ('Load',)), [], 0)]))]),
+('Module', [('Expr', (1, 0), ('DictComp', (1, 0), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Name', (1, 11), 'w', ('Store',)), ('Name', (1, 16), 'x', ('Load',)), [], 0), ('comprehension', ('Name', (1, 22), 'm', ('Store',)), ('Name', (1, 27), 'p', ('Load',)), [('Name', (1, 32), 'g', ('Load',))], 0)]))]),
+('Module', [('Expr', (1, 0), ('DictComp', (1, 0), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'v', ('Store',)), ('Name', (1, 13), 'w', ('Store',))], ('Store',)), ('Name', (1, 18), 'x', ('Load',)), [], 0)]))]),
+('Module', [('Expr', (1, 0), ('SetComp', (1, 0), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 12), 'x', ('Load',)), [('Name', (1, 17), 'g', ('Load',))], 0)]))]),
+('Module', [('Expr', (1, 0), ('SetComp', (1, 0), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Tuple', (1, 7), [('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 9), 'm', ('Store',))], ('Store',)), ('Name', (1, 14), 'x', ('Load',)), [], 0)]))]),
('Module', [('AsyncFunctionDef', (1, 6), 'f', ('arguments', [], None, [], [], None, []), [('Expr', (2, 1), ('Await', (2, 1), ('Call', (2, 7), ('Name', (2, 7), 'something', ('Load',)), [], [])))], [], None)]),
('Module', [('AsyncFunctionDef', (1, 6), 'f', ('arguments', [], None, [], [], None, []), [('AsyncFor', (2, 7), ('Name', (2, 11), 'e', ('Store',)), ('Name', (2, 16), 'i', ('Load',)), [('Expr', (2, 19), ('Num', (2, 19), 1))], [('Expr', (3, 7), ('Num', (3, 7), 2))])], [], None)]),
('Module', [('AsyncFunctionDef', (1, 6), 'f', ('arguments', [], None, [], [], None, []), [('AsyncWith', (2, 7), [('withitem', ('Name', (2, 12), 'a', ('Load',)), ('Name', (2, 17), 'b', ('Store',)))], [('Expr', (2, 20), ('Num', (2, 20), 1))])], [], None)]),
('Module', [('Expr', (1, 0), ('Dict', (1, 0), [None, ('Num', (1, 10), 2)], [('Dict', (1, 3), [('Num', (1, 4), 1)], [('Num', (1, 6), 2)]), ('Num', (1, 12), 3)]))]),
('Module', [('Expr', (1, 0), ('Set', (1, 0), [('Starred', (1, 1), ('Set', (1, 2), [('Num', (1, 3), 1), ('Num', (1, 6), 2)]), ('Load',)), ('Num', (1, 10), 3)]))]),
+('Module', [('AsyncFunctionDef', (1, 6), 'f', ('arguments', [], None, [], [], None, []), [('Expr', (2, 1), ('ListComp', (2, 2), ('Name', (2, 2), 'i', ('Load',)), [('comprehension', ('Name', (2, 14), 'b', ('Store',)), ('Name', (2, 19), 'c', ('Load',)), [], 1)]))], [], None)]),
]
single_results = [
('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]),
@@ -1006,8 +1141,8 @@ eval_results = [
('Expression', ('Dict', (1, 0), [], [])),
('Expression', ('Set', (1, 0), [('NameConstant', (1, 1), None)])),
('Expression', ('Dict', (1, 0), [('Num', (2, 6), 1)], [('Num', (4, 10), 2)])),
-('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])),
-('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])),
+('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))], 0)])),
+('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))], 0)])),
('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])),
('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2), 1), ('Num', (1, 4), 2), ('Starred', (1, 10), ('Name', (1, 11), 'd', ('Load',)), ('Load',))], [('keyword', 'c', ('Num', (1, 8), 3)), ('keyword', None, ('Name', (1, 15), 'e', ('Load',)))])),
('Expression', ('Num', (1, 0), 10)),
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
new file mode 100644
index 0000000..c24fbea
--- /dev/null
+++ b/Lib/test/test_asyncgen.py
@@ -0,0 +1,825 @@
+import inspect
+import sys
+import types
+import unittest
+
+from unittest import mock
+
+from test.support import import_module
+asyncio = import_module("asyncio")
+
+
+class AwaitException(Exception):
+ pass
+
+
+@types.coroutine
+def awaitable(*, throw=False):
+ if throw:
+ yield ('throw',)
+ else:
+ yield ('result',)
+
+
+def run_until_complete(coro):
+ exc = False
+ while True:
+ try:
+ if exc:
+ exc = False
+ fut = coro.throw(AwaitException)
+ else:
+ fut = coro.send(None)
+ except StopIteration as ex:
+ return ex.args[0]
+
+ if fut == ('throw',):
+ exc = True
+
+
+def to_list(gen):
+ async def iterate():
+ res = []
+ async for i in gen:
+ res.append(i)
+ return res
+
+ return run_until_complete(iterate())
+
+
+class AsyncGenSyntaxTest(unittest.TestCase):
+
+ def test_async_gen_syntax_01(self):
+ code = '''async def foo():
+ await abc
+ yield from 123
+ '''
+
+ with self.assertRaisesRegex(SyntaxError, 'yield from.*inside async'):
+ exec(code, {}, {})
+
+ def test_async_gen_syntax_02(self):
+ code = '''async def foo():
+ yield from 123
+ '''
+
+ with self.assertRaisesRegex(SyntaxError, 'yield from.*inside async'):
+ exec(code, {}, {})
+
+ def test_async_gen_syntax_03(self):
+ code = '''async def foo():
+ await abc
+ yield
+ return 123
+ '''
+
+ with self.assertRaisesRegex(SyntaxError, 'return.*value.*async gen'):
+ exec(code, {}, {})
+
+ def test_async_gen_syntax_04(self):
+ code = '''async def foo():
+ yield
+ return 123
+ '''
+
+ with self.assertRaisesRegex(SyntaxError, 'return.*value.*async gen'):
+ exec(code, {}, {})
+
+ def test_async_gen_syntax_05(self):
+ code = '''async def foo():
+ if 0:
+ yield
+ return 12
+ '''
+
+ with self.assertRaisesRegex(SyntaxError, 'return.*value.*async gen'):
+ exec(code, {}, {})
+
+
+class AsyncGenTest(unittest.TestCase):
+
+ def compare_generators(self, sync_gen, async_gen):
+ def sync_iterate(g):
+ res = []
+ while True:
+ try:
+ res.append(g.__next__())
+ except StopIteration:
+ res.append('STOP')
+ break
+ except Exception as ex:
+ res.append(str(type(ex)))
+ return res
+
+ def async_iterate(g):
+ res = []
+ while True:
+ try:
+ g.__anext__().__next__()
+ except StopAsyncIteration:
+ res.append('STOP')
+ break
+ except StopIteration as ex:
+ if ex.args:
+ res.append(ex.args[0])
+ else:
+ res.append('EMPTY StopIteration')
+ break
+ except Exception as ex:
+ res.append(str(type(ex)))
+ return res
+
+ sync_gen_result = sync_iterate(sync_gen)
+ async_gen_result = async_iterate(async_gen)
+ self.assertEqual(sync_gen_result, async_gen_result)
+ return async_gen_result
+
+ def test_async_gen_iteration_01(self):
+ async def gen():
+ await awaitable()
+ a = yield 123
+ self.assertIs(a, None)
+ await awaitable()
+ yield 456
+ await awaitable()
+ yield 789
+
+ self.assertEqual(to_list(gen()), [123, 456, 789])
+
+ def test_async_gen_iteration_02(self):
+ async def gen():
+ await awaitable()
+ yield 123
+ await awaitable()
+
+ g = gen()
+ ai = g.__aiter__()
+ self.assertEqual(ai.__anext__().__next__(), ('result',))
+
+ try:
+ ai.__anext__().__next__()
+ except StopIteration as ex:
+ self.assertEqual(ex.args[0], 123)
+ else:
+ self.fail('StopIteration was not raised')
+
+ self.assertEqual(ai.__anext__().__next__(), ('result',))
+
+ try:
+ ai.__anext__().__next__()
+ except StopAsyncIteration as ex:
+ self.assertFalse(ex.args)
+ else:
+ self.fail('StopAsyncIteration was not raised')
+
+ def test_async_gen_exception_03(self):
+ async def gen():
+ await awaitable()
+ yield 123
+ await awaitable(throw=True)
+ yield 456
+
+ with self.assertRaises(AwaitException):
+ to_list(gen())
+
+ def test_async_gen_exception_04(self):
+ async def gen():
+ await awaitable()
+ yield 123
+ 1 / 0
+
+ g = gen()
+ ai = g.__aiter__()
+ self.assertEqual(ai.__anext__().__next__(), ('result',))
+
+ try:
+ ai.__anext__().__next__()
+ except StopIteration as ex:
+ self.assertEqual(ex.args[0], 123)
+ else:
+ self.fail('StopIteration was not raised')
+
+ with self.assertRaises(ZeroDivisionError):
+ ai.__anext__().__next__()
+
+ def test_async_gen_exception_05(self):
+ async def gen():
+ yield 123
+ raise StopAsyncIteration
+
+ with self.assertRaisesRegex(RuntimeError,
+ 'async generator.*StopAsyncIteration'):
+ to_list(gen())
+
+ def test_async_gen_exception_06(self):
+ async def gen():
+ yield 123
+ raise StopIteration
+
+ with self.assertRaisesRegex(RuntimeError,
+ 'async generator.*StopIteration'):
+ to_list(gen())
+
+ def test_async_gen_exception_07(self):
+ def sync_gen():
+ try:
+ yield 1
+ 1 / 0
+ finally:
+ yield 2
+ yield 3
+
+ yield 100
+
+ async def async_gen():
+ try:
+ yield 1
+ 1 / 0
+ finally:
+ yield 2
+ yield 3
+
+ yield 100
+
+ self.compare_generators(sync_gen(), async_gen())
+
+ def test_async_gen_exception_08(self):
+ def sync_gen():
+ try:
+ yield 1
+ finally:
+ yield 2
+ 1 / 0
+ yield 3
+
+ yield 100
+
+ async def async_gen():
+ try:
+ yield 1
+ await awaitable()
+ finally:
+ await awaitable()
+ yield 2
+ 1 / 0
+ yield 3
+
+ yield 100
+
+ self.compare_generators(sync_gen(), async_gen())
+
+ def test_async_gen_exception_09(self):
+ def sync_gen():
+ try:
+ yield 1
+ 1 / 0
+ finally:
+ yield 2
+ yield 3
+
+ yield 100
+
+ async def async_gen():
+ try:
+ await awaitable()
+ yield 1
+ 1 / 0
+ finally:
+ yield 2
+ await awaitable()
+ yield 3
+
+ yield 100
+
+ self.compare_generators(sync_gen(), async_gen())
+
+ def test_async_gen_exception_10(self):
+ async def gen():
+ yield 123
+ with self.assertRaisesRegex(TypeError,
+ "non-None value .* async generator"):
+ gen().__anext__().send(100)
+
+ def test_async_gen_api_01(self):
+ async def gen():
+ yield 123
+
+ g = gen()
+
+ self.assertEqual(g.__name__, 'gen')
+ g.__name__ = '123'
+ self.assertEqual(g.__name__, '123')
+
+ self.assertIn('.gen', g.__qualname__)
+ g.__qualname__ = '123'
+ self.assertEqual(g.__qualname__, '123')
+
+ self.assertIsNone(g.ag_await)
+ self.assertIsInstance(g.ag_frame, types.FrameType)
+ self.assertFalse(g.ag_running)
+ self.assertIsInstance(g.ag_code, types.CodeType)
+
+ self.assertTrue(inspect.isawaitable(g.aclose()))
+
+
+class AsyncGenAsyncioTest(unittest.TestCase):
+
+ def setUp(self):
+ self.loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(None)
+
+ def tearDown(self):
+ self.loop.close()
+ self.loop = None
+
+ async def to_list(self, gen):
+ res = []
+ async for i in gen:
+ res.append(i)
+ return res
+
+ def test_async_gen_asyncio_01(self):
+ async def gen():
+ yield 1
+ await asyncio.sleep(0.01, loop=self.loop)
+ yield 2
+ await asyncio.sleep(0.01, loop=self.loop)
+ return
+ yield 3
+
+ res = self.loop.run_until_complete(self.to_list(gen()))
+ self.assertEqual(res, [1, 2])
+
+ def test_async_gen_asyncio_02(self):
+ async def gen():
+ yield 1
+ await asyncio.sleep(0.01, loop=self.loop)
+ yield 2
+ 1 / 0
+ yield 3
+
+ with self.assertRaises(ZeroDivisionError):
+ self.loop.run_until_complete(self.to_list(gen()))
+
+ def test_async_gen_asyncio_03(self):
+ loop = self.loop
+
+ class Gen:
+ async def __aiter__(self):
+ yield 1
+ await asyncio.sleep(0.01, loop=loop)
+ yield 2
+
+ res = loop.run_until_complete(self.to_list(Gen()))
+ self.assertEqual(res, [1, 2])
+
+ def test_async_gen_asyncio_anext_04(self):
+ async def foo():
+ yield 1
+ await asyncio.sleep(0.01, loop=self.loop)
+ try:
+ yield 2
+ yield 3
+ except ZeroDivisionError:
+ yield 1000
+ await asyncio.sleep(0.01, loop=self.loop)
+ yield 4
+
+ async def run1():
+ it = foo().__aiter__()
+
+ self.assertEqual(await it.__anext__(), 1)
+ self.assertEqual(await it.__anext__(), 2)
+ self.assertEqual(await it.__anext__(), 3)
+ self.assertEqual(await it.__anext__(), 4)
+ with self.assertRaises(StopAsyncIteration):
+ await it.__anext__()
+ with self.assertRaises(StopAsyncIteration):
+ await it.__anext__()
+
+ async def run2():
+ it = foo().__aiter__()
+
+ self.assertEqual(await it.__anext__(), 1)
+ self.assertEqual(await it.__anext__(), 2)
+ try:
+ it.__anext__().throw(ZeroDivisionError)
+ except StopIteration as ex:
+ self.assertEqual(ex.args[0], 1000)
+ else:
+ self.fail('StopIteration was not raised')
+ self.assertEqual(await it.__anext__(), 4)
+ with self.assertRaises(StopAsyncIteration):
+ await it.__anext__()
+
+ self.loop.run_until_complete(run1())
+ self.loop.run_until_complete(run2())
+
+ def test_async_gen_asyncio_anext_05(self):
+ async def foo():
+ v = yield 1
+ v = yield v
+ yield v * 100
+
+ async def run():
+ it = foo().__aiter__()
+
+ try:
+ it.__anext__().send(None)
+ except StopIteration as ex:
+ self.assertEqual(ex.args[0], 1)
+ else:
+ self.fail('StopIteration was not raised')
+
+ try:
+ it.__anext__().send(10)
+ except StopIteration as ex:
+ self.assertEqual(ex.args[0], 10)
+ else:
+ self.fail('StopIteration was not raised')
+
+ try:
+ it.__anext__().send(12)
+ except StopIteration as ex:
+ self.assertEqual(ex.args[0], 1200)
+ else:
+ self.fail('StopIteration was not raised')
+
+ with self.assertRaises(StopAsyncIteration):
+ await it.__anext__()
+
+ self.loop.run_until_complete(run())
+
+ def test_async_gen_asyncio_aclose_06(self):
+ async def foo():
+ try:
+ yield 1
+ 1 / 0
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ yield 12
+
+ async def run():
+ gen = foo()
+ it = gen.__aiter__()
+ await it.__anext__()
+ await gen.aclose()
+
+ with self.assertRaisesRegex(
+ RuntimeError,
+ "async generator ignored GeneratorExit"):
+ self.loop.run_until_complete(run())
+
+ def test_async_gen_asyncio_aclose_07(self):
+ DONE = 0
+
+ async def foo():
+ nonlocal DONE
+ try:
+ yield 1
+ 1 / 0
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE += 1
+ DONE += 1000
+
+ async def run():
+ gen = foo()
+ it = gen.__aiter__()
+ await it.__anext__()
+ await gen.aclose()
+
+ self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ def test_async_gen_asyncio_aclose_08(self):
+ DONE = 0
+
+ fut = asyncio.Future(loop=self.loop)
+
+ async def foo():
+ nonlocal DONE
+ try:
+ yield 1
+ await fut
+ DONE += 1000
+ yield 2
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE += 1
+ DONE += 1000
+
+ async def run():
+ gen = foo()
+ it = gen.__aiter__()
+ self.assertEqual(await it.__anext__(), 1)
+ t = self.loop.create_task(it.__anext__())
+ await asyncio.sleep(0.01, loop=self.loop)
+ await gen.aclose()
+ return t
+
+ t = self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ # Silence ResourceWarnings
+ fut.cancel()
+ t.cancel()
+ self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
+
+ def test_async_gen_asyncio_gc_aclose_09(self):
+ DONE = 0
+
+ async def gen():
+ nonlocal DONE
+ try:
+ while True:
+ yield 1
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE = 1
+
+ async def run():
+ g = gen()
+ await g.__anext__()
+ await g.__anext__()
+ del g
+
+ await asyncio.sleep(0.1, loop=self.loop)
+
+ self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ def test_async_gen_asyncio_asend_01(self):
+ DONE = 0
+
+ # Sanity check:
+ def sgen():
+ v = yield 1
+ yield v * 2
+ sg = sgen()
+ v = sg.send(None)
+ self.assertEqual(v, 1)
+ v = sg.send(100)
+ self.assertEqual(v, 200)
+
+ async def gen():
+ nonlocal DONE
+ try:
+ await asyncio.sleep(0.01, loop=self.loop)
+ v = yield 1
+ await asyncio.sleep(0.01, loop=self.loop)
+ yield v * 2
+ await asyncio.sleep(0.01, loop=self.loop)
+ return
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE = 1
+
+ async def run():
+ g = gen()
+
+ v = await g.asend(None)
+ self.assertEqual(v, 1)
+
+ v = await g.asend(100)
+ self.assertEqual(v, 200)
+
+ with self.assertRaises(StopAsyncIteration):
+ await g.asend(None)
+
+ self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ def test_async_gen_asyncio_asend_02(self):
+ DONE = 0
+
+ async def sleep_n_crash(delay):
+ await asyncio.sleep(delay, loop=self.loop)
+ 1 / 0
+
+ async def gen():
+ nonlocal DONE
+ try:
+ await asyncio.sleep(0.01, loop=self.loop)
+ v = yield 1
+ await sleep_n_crash(0.01)
+ DONE += 1000
+ yield v * 2
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE = 1
+
+ async def run():
+ g = gen()
+
+ v = await g.asend(None)
+ self.assertEqual(v, 1)
+
+ await g.asend(100)
+
+ with self.assertRaises(ZeroDivisionError):
+ self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ def test_async_gen_asyncio_asend_03(self):
+ DONE = 0
+
+ async def sleep_n_crash(delay):
+ fut = asyncio.ensure_future(asyncio.sleep(delay, loop=self.loop),
+ loop=self.loop)
+ self.loop.call_later(delay / 2, lambda: fut.cancel())
+ return await fut
+
+ async def gen():
+ nonlocal DONE
+ try:
+ await asyncio.sleep(0.01, loop=self.loop)
+ v = yield 1
+ await sleep_n_crash(0.01)
+ DONE += 1000
+ yield v * 2
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE = 1
+
+ async def run():
+ g = gen()
+
+ v = await g.asend(None)
+ self.assertEqual(v, 1)
+
+ await g.asend(100)
+
+ with self.assertRaises(asyncio.CancelledError):
+ self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ def test_async_gen_asyncio_athrow_01(self):
+ DONE = 0
+
+ class FooEr(Exception):
+ pass
+
+ # Sanity check:
+ def sgen():
+ try:
+ v = yield 1
+ except FooEr:
+ v = 1000
+ yield v * 2
+ sg = sgen()
+ v = sg.send(None)
+ self.assertEqual(v, 1)
+ v = sg.throw(FooEr)
+ self.assertEqual(v, 2000)
+ with self.assertRaises(StopIteration):
+ sg.send(None)
+
+ async def gen():
+ nonlocal DONE
+ try:
+ await asyncio.sleep(0.01, loop=self.loop)
+ try:
+ v = yield 1
+ except FooEr:
+ v = 1000
+ await asyncio.sleep(0.01, loop=self.loop)
+ yield v * 2
+ await asyncio.sleep(0.01, loop=self.loop)
+ # return
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE = 1
+
+ async def run():
+ g = gen()
+
+ v = await g.asend(None)
+ self.assertEqual(v, 1)
+
+ v = await g.athrow(FooEr)
+ self.assertEqual(v, 2000)
+
+ with self.assertRaises(StopAsyncIteration):
+ await g.asend(None)
+
+ self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ def test_async_gen_asyncio_athrow_02(self):
+ DONE = 0
+
+ class FooEr(Exception):
+ pass
+
+ async def sleep_n_crash(delay):
+ fut = asyncio.ensure_future(asyncio.sleep(delay, loop=self.loop),
+ loop=self.loop)
+ self.loop.call_later(delay / 2, lambda: fut.cancel())
+ return await fut
+
+ async def gen():
+ nonlocal DONE
+ try:
+ await asyncio.sleep(0.01, loop=self.loop)
+ try:
+ v = yield 1
+ except FooEr:
+ await sleep_n_crash(0.01)
+ yield v * 2
+ await asyncio.sleep(0.01, loop=self.loop)
+ # return
+ finally:
+ await asyncio.sleep(0.01, loop=self.loop)
+ await asyncio.sleep(0.01, loop=self.loop)
+ DONE = 1
+
+ async def run():
+ g = gen()
+
+ v = await g.asend(None)
+ self.assertEqual(v, 1)
+
+ try:
+ await g.athrow(FooEr)
+ except asyncio.CancelledError:
+ self.assertEqual(DONE, 1)
+ raise
+ else:
+ self.fail('CancelledError was not raised')
+
+ with self.assertRaises(asyncio.CancelledError):
+ self.loop.run_until_complete(run())
+ self.assertEqual(DONE, 1)
+
+ def test_async_gen_asyncio_shutdown_01(self):
+ finalized = 0
+
+ async def waiter(timeout):
+ nonlocal finalized
+ try:
+ await asyncio.sleep(timeout, loop=self.loop)
+ yield 1
+ finally:
+ await asyncio.sleep(0, loop=self.loop)
+ finalized += 1
+
+ async def wait():
+ async for _ in waiter(1):
+ pass
+
+ t1 = self.loop.create_task(wait())
+ t2 = self.loop.create_task(wait())
+
+ self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
+
+ self.loop.run_until_complete(self.loop.shutdown_asyncgens())
+ self.assertEqual(finalized, 2)
+
+ # Silence warnings
+ t1.cancel()
+ t2.cancel()
+ self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
+
+ def test_async_gen_asyncio_shutdown_02(self):
+ logged = 0
+
+ def logger(loop, context):
+ nonlocal logged
+ self.assertIn('asyncgen', context)
+ expected = 'an error occurred during closing of asynchronous'
+ if expected in context['message']:
+ logged += 1
+
+ async def waiter(timeout):
+ try:
+ await asyncio.sleep(timeout, loop=self.loop)
+ yield 1
+ finally:
+ 1 / 0
+
+ async def wait():
+ async for _ in waiter(1):
+ pass
+
+ t = self.loop.create_task(wait())
+ self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
+
+ self.loop.set_exception_handler(logger)
+ self.loop.run_until_complete(self.loop.shutdown_asyncgens())
+
+ self.assertEqual(logged, 1)
+
+ # Silence warnings
+ t.cancel()
+ self.loop.run_until_complete(asyncio.sleep(0.1, loop=self.loop))
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py
index 3a33fc8..0eba76d 100644
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -12,7 +12,6 @@ import socket
import sys
import time
import unittest
-import warnings
import unittest.mock
try:
import threading
@@ -297,37 +296,6 @@ class TestHelperFunctions(unittest.TestCase):
self.assertEqual(asynchat.find_prefix_at_end("qwertydkjf", "\r\n"), 0)
-class TestFifo(unittest.TestCase):
- def test_basic(self):
- with self.assertWarns(DeprecationWarning) as cm:
- f = asynchat.fifo()
- self.assertEqual(str(cm.warning),
- "fifo class will be removed in Python 3.6")
- f.push(7)
- f.push(b'a')
- self.assertEqual(len(f), 2)
- self.assertEqual(f.first(), 7)
- self.assertEqual(f.pop(), (1, 7))
- self.assertEqual(len(f), 1)
- self.assertEqual(f.first(), b'a')
- self.assertEqual(f.is_empty(), False)
- self.assertEqual(f.pop(), (1, b'a'))
- self.assertEqual(len(f), 0)
- self.assertEqual(f.is_empty(), True)
- self.assertEqual(f.pop(), (0, None))
-
- def test_given_list(self):
- with self.assertWarns(DeprecationWarning) as cm:
- f = asynchat.fifo([b'x', 17, 3])
- self.assertEqual(str(cm.warning),
- "fifo class will be removed in Python 3.6")
- self.assertEqual(len(f), 3)
- self.assertEqual(f.pop(), (1, b'x'))
- self.assertEqual(f.pop(), (1, 17))
- self.assertEqual(f.pop(), (1, 3))
- self.assertEqual(f.pop(), (0, None))
-
-
class TestNotConnected(unittest.TestCase):
def test_disallow_negative_terminator(self):
# Issue #11259
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index d20eb68..6916b51 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -464,6 +464,19 @@ class FutureTests(test_utils.TestCase):
futures._set_result_unless_cancelled(fut, 2)
self.assertTrue(fut.cancelled())
+ def test_future_stop_iteration_args(self):
+ fut = asyncio.Future(loop=self.loop)
+ fut.set_result((1, 2))
+ fi = fut.__iter__()
+ result = None
+ try:
+ fi.send(None)
+ except StopIteration as ex:
+ result = ex.args[0]
+ else:
+ self.fail('StopIteration was expected')
+ self.assertEqual(result, (1, 2))
+
class FutureDoneCallbackTests(test_utils.TestCase):
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index 3857916..dbee593 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -11,6 +11,9 @@ import struct
from test import support
from io import BytesIO
+if support.PGO:
+ raise unittest.SkipTest("test is not helpful for PGO")
+
try:
import threading
except ImportError:
diff --git a/Lib/test/test_augassign.py b/Lib/test/test_augassign.py
index 5093e9d..5930d9e 100644
--- a/Lib/test/test_augassign.py
+++ b/Lib/test/test_augassign.py
@@ -83,6 +83,10 @@ class AugAssignTest(unittest.TestCase):
def __iadd__(self, val):
return aug_test3(self.val + val)
+ class aug_test4(aug_test3):
+ """Blocks inheritance, and fallback to __add__"""
+ __iadd__ = None
+
x = aug_test(1)
y = x
x += 10
@@ -106,6 +110,10 @@ class AugAssignTest(unittest.TestCase):
self.assertTrue(y is not x)
self.assertEqual(x.val, 13)
+ x = aug_test4(4)
+ with self.assertRaises(TypeError):
+ x += 10
+
def testCustomMethods2(test_self):
output = []
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_baseexception.py
index 7c98c46..27d514f 100644
--- a/Lib/test/test_pep352.py
+++ b/Lib/test/test_baseexception.py
@@ -1,6 +1,5 @@
import unittest
import builtins
-import warnings
import os
from platform import system as platform_system
diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py
index 40ac9bf..6133bbc 100644
--- a/Lib/test/test_bigmem.py
+++ b/Lib/test/test_bigmem.py
@@ -14,7 +14,6 @@ from test.support import bigmemtest, _1G, _2G, _4G
import unittest
import operator
import sys
-import functools
# These tests all use one of the bigmemtest decorators to indicate how much
# memory they use and how much memory they need to be even meaningful. The
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py
index 034245d..6b3e437 100644
--- a/Lib/test/test_binascii.py
+++ b/Lib/test/test_binascii.py
@@ -159,11 +159,25 @@ class BinASCIITest(unittest.TestCase):
# Then calculate the hexbin4 binary-to-ASCII translation
rle = binascii.rlecode_hqx(self.data)
a = binascii.b2a_hqx(self.type2test(rle))
+
b, _ = binascii.a2b_hqx(self.type2test(a))
res = binascii.rledecode_hqx(b)
-
self.assertEqual(res, self.rawdata)
+ def test_rle(self):
+ # test repetition with a repetition longer than the limit of 255
+ data = (b'a' * 100 + b'b' + b'c' * 300)
+
+ encoded = binascii.rlecode_hqx(data)
+ self.assertEqual(encoded,
+ (b'a\x90d' # 'a' * 100
+ b'b' # 'b'
+ b'c\x90\xff' # 'c' * 255
+ b'c\x90-')) # 'c' * 45
+
+ decoded = binascii.rledecode_hqx(encoded)
+ self.assertEqual(decoded, data)
+
def test_hex(self):
# test hexlification
s = b'{s\005\000\000\000worldi\002\000\000\000s\005\000\000\000helloi\001\000\000\0000'
@@ -331,6 +345,16 @@ class BinASCIITest(unittest.TestCase):
# non-ASCII string
self.assertRaises(ValueError, a2b, "\x80")
+ def test_b2a_base64_newline(self):
+ # Issue #25357: test newline parameter
+ b = self.type2test(b'hello')
+ self.assertEqual(binascii.b2a_base64(b),
+ b'aGVsbG8=\n')
+ self.assertEqual(binascii.b2a_base64(b, newline=True),
+ b'aGVsbG8=\n')
+ self.assertEqual(binascii.b2a_base64(b, newline=False),
+ b'aGVsbG8=')
+
class ArrayBinASCIITest(BinASCIITest):
def type2test(self, s):
diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py
index 9d4c85a..21f4463 100644
--- a/Lib/test/test_binhex.py
+++ b/Lib/test/test_binhex.py
@@ -4,7 +4,6 @@
Based on an original test by Roger E. Masse.
"""
import binhex
-import os
import unittest
from test import support
diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py
index e9dbddc..3ed018e 100644
--- a/Lib/test/test_binop.py
+++ b/Lib/test/test_binop.py
@@ -2,7 +2,7 @@
import unittest
from test import support
-from operator import eq, ne, lt, gt, le, ge
+from operator import eq, le, ne
from abc import ABCMeta
def gcd(a, b):
@@ -388,6 +388,54 @@ class OperationOrderTests(unittest.TestCase):
self.assertEqual(op_sequence(eq, B, V), ['B.__eq__', 'V.__eq__'])
self.assertEqual(op_sequence(le, B, V), ['B.__le__', 'V.__ge__'])
+class SupEq(object):
+ """Class that can test equality"""
+ def __eq__(self, other):
+ return True
+
+class S(SupEq):
+ """Subclass of SupEq that should fail"""
+ __eq__ = None
+
+class F(object):
+ """Independent class that should fall back"""
+
+class X(object):
+ """Independent class that should fail"""
+ __eq__ = None
+
+class SN(SupEq):
+ """Subclass of SupEq that can test equality, but not non-equality"""
+ __ne__ = None
+
+class XN:
+ """Independent class that can test equality, but not non-equality"""
+ def __eq__(self, other):
+ return True
+ __ne__ = None
+
+class FallbackBlockingTests(unittest.TestCase):
+ """Unit tests for None method blocking"""
+
+ def test_fallback_rmethod_blocking(self):
+ e, f, s, x = SupEq(), F(), S(), X()
+ self.assertEqual(e, e)
+ self.assertEqual(e, f)
+ self.assertEqual(f, e)
+ # left operand is checked first
+ self.assertEqual(e, x)
+ self.assertRaises(TypeError, eq, x, e)
+ # S is a subclass, so it's always checked first
+ self.assertRaises(TypeError, eq, e, s)
+ self.assertRaises(TypeError, eq, s, e)
+
+ def test_fallback_ne_blocking(self):
+ e, sn, xn = SupEq(), SN(), XN()
+ self.assertFalse(e != e)
+ self.assertRaises(TypeError, ne, e, sn)
+ self.assertRaises(TypeError, ne, sn, e)
+ self.assertFalse(e != xn)
+ self.assertRaises(TypeError, ne, xn, e)
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py
index d30a3b9..9f8f0e1 100644
--- a/Lib/test/test_bool.py
+++ b/Lib/test/test_bool.py
@@ -96,6 +96,13 @@ class BoolTest(unittest.TestCase):
self.assertEqual(False/1, 0)
self.assertIsNot(False/1, False)
+ self.assertEqual(True%1, 0)
+ self.assertIsNot(True%1, False)
+ self.assertEqual(True%2, 1)
+ self.assertIsNot(True%2, True)
+ self.assertEqual(False%1, 0)
+ self.assertIsNot(False%1, False)
+
for b in False, True:
for i in 0, 1, 2:
self.assertEqual(b**i, int(b)**i)
@@ -333,6 +340,17 @@ class BoolTest(unittest.TestCase):
except (Exception) as e_len:
self.assertEqual(str(e_bool), str(e_len))
+ def test_blocked(self):
+ class A:
+ __bool__ = None
+ self.assertRaises(TypeError, bool, A())
+
+ class B:
+ def __len__(self):
+ return 10
+ __bool__ = None
+ self.assertRaises(TypeError, bool, B())
+
def test_real_and_imag(self):
self.assertEqual(True.real, 1)
self.assertEqual(True.imag, 0)
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
index 2eef9fc..b83f2f1 100644
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -16,7 +16,6 @@ import unittest
from test import support
from itertools import permutations, product
from random import randrange, sample, choice
-from sysconfig import get_config_var
import warnings
import sys, array, io
from decimal import Decimal
diff --git a/Lib/test/test_bufio.py b/Lib/test/test_bufio.py
index 9931c84..fea6da4 100644
--- a/Lib/test/test_bufio.py
+++ b/Lib/test/test_bufio.py
@@ -59,7 +59,7 @@ class BufferSizeTest:
self.drive_one(b"1234567890\00\01\02\03\04\05\06")
def test_nullpat(self):
- self.drive_one(bytes(1000))
+ self.drive_one(b'\0' * 1000)
class CBufferSizeTest(BufferSizeTest, unittest.TestCase):
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 39c80b0..e0cffe1 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -81,7 +81,7 @@ test_conv_no_sign = [
('', ValueError),
(' ', ValueError),
(' \t\t ', ValueError),
- (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+ (str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
(chr(0x200), ValueError),
]
@@ -103,7 +103,7 @@ test_conv_sign = [
('', ValueError),
(' ', ValueError),
(' \t\t ', ValueError),
- (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+ (str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
(chr(0x200), ValueError),
]
@@ -1710,21 +1710,11 @@ class TestType(unittest.TestCase):
self.assertEqual(x.spam(), 'spam42')
self.assertEqual(x.to_bytes(2, 'little'), b'\x2a\x00')
- def test_type_new_keywords(self):
- class B:
- def ham(self):
- return 'ham%d' % self
- C = type.__new__(type,
- name='C',
- bases=(B, int),
- dict={'spam': lambda self: 'spam%s' % self})
- self.assertEqual(C.__name__, 'C')
- self.assertEqual(C.__qualname__, 'C')
- self.assertEqual(C.__module__, __name__)
- self.assertEqual(C.__bases__, (B, int))
- self.assertIs(C.__base__, int)
- self.assertIn('spam', C.__dict__)
- self.assertNotIn('ham', C.__dict__)
+ def test_type_nokwargs(self):
+ with self.assertRaises(TypeError):
+ type('a', (), {}, x=5)
+ with self.assertRaises(TypeError):
+ type('a', (), dict={})
def test_type_name(self):
for name in 'A', '\xc4', '\U0001f40d', 'B.A', '42', '':
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index cc312b1..2224424 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -216,7 +216,7 @@ class BaseBytesTest:
self.assertEqual(b, self.type2test(sample[:-3], "utf-8"))
def test_decode(self):
- sample = "Hello world\n\u1234\u5678\u9abc\def0\def0"
+ sample = "Hello world\n\u1234\u5678\u9abc"
for enc in ("utf-8", "utf-16"):
b = self.type2test(sample, enc)
self.assertEqual(b.decode(enc), sample)
@@ -269,6 +269,7 @@ class BaseBytesTest:
self.assertNotIn(200, b)
self.assertRaises(ValueError, lambda: 300 in b)
self.assertRaises(ValueError, lambda: -1 in b)
+ self.assertRaises(ValueError, lambda: sys.maxsize+1 in b)
self.assertRaises(TypeError, lambda: None in b)
self.assertRaises(TypeError, lambda: float(ord('a')) in b)
self.assertRaises(TypeError, lambda: "a" in b)
@@ -300,6 +301,20 @@ class BaseBytesTest:
self.assertRaises(ValueError, self.type2test.fromhex, '\x00')
self.assertRaises(ValueError, self.type2test.fromhex, '12 \x00 34')
+ for data, pos in (
+ # invalid first hexadecimal character
+ ('12 x4 56', 3),
+ # invalid second hexadecimal character
+ ('12 3x 56', 4),
+ # two invalid hexadecimal characters
+ ('12 xy 56', 3),
+ # test non-ASCII string
+ ('12 3\xff 56', 4),
+ ):
+ with self.assertRaises(ValueError) as cm:
+ self.type2test.fromhex(data)
+ self.assertIn('at position %s' % pos, str(cm.exception))
+
def test_hex(self):
self.assertRaises(TypeError, self.type2test.hex)
self.assertRaises(TypeError, self.type2test.hex, 1)
@@ -674,6 +689,37 @@ class BaseBytesTest:
test.support.check_free_after_iterating(self, iter, self.type2test)
test.support.check_free_after_iterating(self, reversed, self.type2test)
+ def test_translate(self):
+ b = self.type2test(b'hello')
+ rosetta = bytearray(range(256))
+ rosetta[ord('o')] = ord('e')
+
+ self.assertRaises(TypeError, b.translate)
+ self.assertRaises(TypeError, b.translate, None, None)
+ self.assertRaises(ValueError, b.translate, bytes(range(255)))
+
+ c = b.translate(rosetta, b'hello')
+ self.assertEqual(b, b'hello')
+ self.assertIsInstance(c, self.type2test)
+
+ c = b.translate(rosetta)
+ d = b.translate(rosetta, b'')
+ self.assertEqual(c, d)
+ self.assertEqual(c, b'helle')
+
+ c = b.translate(rosetta, b'l')
+ self.assertEqual(c, b'hee')
+ c = b.translate(None, b'e')
+ self.assertEqual(c, b'hllo')
+
+ # test delete as a keyword argument
+ c = b.translate(rosetta, delete=b'')
+ self.assertEqual(c, b'helle')
+ c = b.translate(rosetta, delete=b'l')
+ self.assertEqual(c, b'hee')
+ c = b.translate(None, delete=b'e')
+ self.assertEqual(c, b'hllo')
+
class BytesTest(BaseBytesTest, unittest.TestCase):
type2test = bytes
@@ -722,31 +768,142 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
# Test PyBytes_FromFormat()
def test_from_format(self):
- test.support.import_module('ctypes')
- from ctypes import pythonapi, py_object, c_int, c_char_p
+ ctypes = test.support.import_module('ctypes')
+ _testcapi = test.support.import_module('_testcapi')
+ from ctypes import pythonapi, py_object
+ from ctypes import (
+ c_int, c_uint,
+ c_long, c_ulong,
+ c_size_t, c_ssize_t,
+ c_char_p)
+
PyBytes_FromFormat = pythonapi.PyBytes_FromFormat
PyBytes_FromFormat.restype = py_object
+ # basic tests
self.assertEqual(PyBytes_FromFormat(b'format'),
b'format')
-
+ self.assertEqual(PyBytes_FromFormat(b'Hello %s !', b'world'),
+ b'Hello world !')
+
+ # test formatters
+ self.assertEqual(PyBytes_FromFormat(b'c=%c', c_int(0)),
+ b'c=\0')
+ self.assertEqual(PyBytes_FromFormat(b'c=%c', c_int(ord('@'))),
+ b'c=@')
+ self.assertEqual(PyBytes_FromFormat(b'c=%c', c_int(255)),
+ b'c=\xff')
+ self.assertEqual(PyBytes_FromFormat(b'd=%d ld=%ld zd=%zd',
+ c_int(1), c_long(2),
+ c_size_t(3)),
+ b'd=1 ld=2 zd=3')
+ self.assertEqual(PyBytes_FromFormat(b'd=%d ld=%ld zd=%zd',
+ c_int(-1), c_long(-2),
+ c_size_t(-3)),
+ b'd=-1 ld=-2 zd=-3')
+ self.assertEqual(PyBytes_FromFormat(b'u=%u lu=%lu zu=%zu',
+ c_uint(123), c_ulong(456),
+ c_size_t(789)),
+ b'u=123 lu=456 zu=789')
+ self.assertEqual(PyBytes_FromFormat(b'i=%i', c_int(123)),
+ b'i=123')
+ self.assertEqual(PyBytes_FromFormat(b'i=%i', c_int(-123)),
+ b'i=-123')
+ self.assertEqual(PyBytes_FromFormat(b'x=%x', c_int(0xabc)),
+ b'x=abc')
+
+ sizeof_ptr = ctypes.sizeof(c_char_p)
+
+ if os.name == 'nt':
+ # Windows (MSCRT)
+ ptr_format = '0x%0{}X'.format(2 * sizeof_ptr)
+ def ptr_formatter(ptr):
+ return (ptr_format % ptr)
+ else:
+ # UNIX (glibc)
+ def ptr_formatter(ptr):
+ return '%#x' % ptr
+
+ ptr = 0xabcdef
+ self.assertEqual(PyBytes_FromFormat(b'ptr=%p', c_char_p(ptr)),
+ ('ptr=' + ptr_formatter(ptr)).encode('ascii'))
+ self.assertEqual(PyBytes_FromFormat(b's=%s', c_char_p(b'cstr')),
+ b's=cstr')
+
+ # test minimum and maximum integer values
+ size_max = c_size_t(-1).value
+ for formatstr, ctypes_type, value, py_formatter in (
+ (b'%d', c_int, _testcapi.INT_MIN, str),
+ (b'%d', c_int, _testcapi.INT_MAX, str),
+ (b'%ld', c_long, _testcapi.LONG_MIN, str),
+ (b'%ld', c_long, _testcapi.LONG_MAX, str),
+ (b'%lu', c_ulong, _testcapi.ULONG_MAX, str),
+ (b'%zd', c_ssize_t, _testcapi.PY_SSIZE_T_MIN, str),
+ (b'%zd', c_ssize_t, _testcapi.PY_SSIZE_T_MAX, str),
+ (b'%zu', c_size_t, size_max, str),
+ (b'%p', c_char_p, size_max, ptr_formatter),
+ ):
+ self.assertEqual(PyBytes_FromFormat(formatstr, ctypes_type(value)),
+ py_formatter(value).encode('ascii')),
+
+ # width and precision (width is currently ignored)
+ self.assertEqual(PyBytes_FromFormat(b'%5s', b'a'),
+ b'a')
+ self.assertEqual(PyBytes_FromFormat(b'%.3s', b'abcdef'),
+ b'abc')
+
+ # '%%' formatter
+ self.assertEqual(PyBytes_FromFormat(b'%%'),
+ b'%')
+ self.assertEqual(PyBytes_FromFormat(b'[%%]'),
+ b'[%]')
+ self.assertEqual(PyBytes_FromFormat(b'%%%c', c_int(ord('_'))),
+ b'%_')
+ self.assertEqual(PyBytes_FromFormat(b'%%s'),
+ b'%s')
+
+ # Invalid formats and partial formatting
self.assertEqual(PyBytes_FromFormat(b'%'), b'%')
- self.assertEqual(PyBytes_FromFormat(b'%%'), b'%')
- self.assertEqual(PyBytes_FromFormat(b'%%s'), b'%s')
- self.assertEqual(PyBytes_FromFormat(b'[%%]'), b'[%]')
- self.assertEqual(PyBytes_FromFormat(b'%%%c', c_int(ord('_'))), b'%_')
+ self.assertEqual(PyBytes_FromFormat(b'x=%i y=%', c_int(2), c_int(3)),
+ b'x=2 y=%')
- self.assertEqual(PyBytes_FromFormat(b'c:%c', c_int(255)),
- b'c:\xff')
- self.assertEqual(PyBytes_FromFormat(b's:%s', c_char_p(b'cstr')),
- b's:cstr')
-
- # Issue #19969
+ # Issue #19969: %c must raise OverflowError for values
+ # not in the range [0; 255]
self.assertRaises(OverflowError,
PyBytes_FromFormat, b'%c', c_int(-1))
self.assertRaises(OverflowError,
PyBytes_FromFormat, b'%c', c_int(256))
+ def test_bytes_blocking(self):
+ class IterationBlocked(list):
+ __bytes__ = None
+ i = [0, 1, 2, 3]
+ self.assertEqual(bytes(i), b'\x00\x01\x02\x03')
+ self.assertRaises(TypeError, bytes, IterationBlocked(i))
+
+ # At least in CPython, because bytes.__new__ and the C API
+ # PyBytes_FromObject have different fallback rules, integer
+ # fallback is handled specially, so test separately.
+ class IntBlocked(int):
+ __bytes__ = None
+ self.assertEqual(bytes(3), b'\0\0\0')
+ self.assertRaises(TypeError, bytes, IntBlocked(3))
+
+ # While there is no separately-defined rule for handling bytes
+ # subclasses differently from other buffer-interface classes,
+ # an implementation may well special-case them (as CPython 2.x
+ # str did), so test them separately.
+ class BytesSubclassBlocked(bytes):
+ __bytes__ = None
+ self.assertEqual(bytes(b'ab'), b'ab')
+ self.assertRaises(TypeError, bytes, BytesSubclassBlocked(b'ab'))
+
+ class BufferBlocked(bytearray):
+ __bytes__ = None
+ ba, bb = bytearray(b'ab'), BufferBlocked(b'ab')
+ self.assertEqual(bytes(ba), b'ab')
+ self.assertRaises(TypeError, bytes, bb)
+
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
type2test = bytearray
@@ -1323,24 +1480,6 @@ class AssortedBytesTest(unittest.TestCase):
self.assertRaises(SyntaxError, eval,
'b"%s"' % chr(c))
- def test_translate(self):
- b = b'hello'
- ba = bytearray(b)
- rosetta = bytearray(range(0, 256))
- rosetta[ord('o')] = ord('e')
- c = b.translate(rosetta, b'l')
- self.assertEqual(b, b'hello')
- self.assertEqual(c, b'hee')
- c = ba.translate(rosetta, b'l')
- self.assertEqual(ba, b'hello')
- self.assertEqual(c, b'hee')
- c = b.translate(None, b'e')
- self.assertEqual(c, b'hllo')
- c = ba.translate(None, b'e')
- self.assertEqual(c, b'hllo')
- self.assertRaises(TypeError, b.translate, None, None)
- self.assertRaises(TypeError, ba.translate, None, None)
-
def test_split_bytearray(self):
self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])
@@ -1504,7 +1643,32 @@ class SubclassTest:
self.assertEqual(type(a), type(b))
self.assertEqual(type(a.y), type(b.y))
- test_fromhex = BaseBytesTest.test_fromhex
+ def test_fromhex(self):
+ b = self.type2test.fromhex('1a2B30')
+ self.assertEqual(b, b'\x1a\x2b\x30')
+ self.assertIs(type(b), self.type2test)
+
+ class B1(self.basetype):
+ def __new__(cls, value):
+ me = self.basetype.__new__(cls, value)
+ me.foo = 'bar'
+ return me
+
+ b = B1.fromhex('1a2B30')
+ self.assertEqual(b, b'\x1a\x2b\x30')
+ self.assertIs(type(b), B1)
+ self.assertEqual(b.foo, 'bar')
+
+ class B2(self.basetype):
+ def __init__(me, *args, **kwargs):
+ if self.basetype is not bytes:
+ self.basetype.__init__(me, *args, **kwargs)
+ me.foo = 'bar'
+
+ b = B2.fromhex('1a2B30')
+ self.assertEqual(b, b'\x1a\x2b\x30')
+ self.assertIs(type(b), B2)
+ self.assertEqual(b.foo, 'bar')
class ByteArraySubclass(bytearray):
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index 478921a..482242c 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -6,6 +6,7 @@ from io import BytesIO, DEFAULT_BUFFER_SIZE
import os
import pickle
import glob
+import pathlib
import random
import subprocess
import sys
@@ -560,13 +561,20 @@ class BZ2FileTest(BaseTest):
with BZ2File(str_filename, "rb") as f:
self.assertEqual(f.read(), self.DATA)
+ def testOpenPathLikeFilename(self):
+ filename = pathlib.Path(self.filename)
+ with BZ2File(filename, "wb") as f:
+ f.write(self.DATA)
+ with BZ2File(filename, "rb") as f:
+ self.assertEqual(f.read(), self.DATA)
+
def testDecompressLimited(self):
"""Decompressed data buffering should be limited"""
- bomb = bz2.compress(bytes(int(2e6)), compresslevel=9)
+ bomb = bz2.compress(b'\0' * int(2e6), compresslevel=9)
self.assertLess(len(bomb), _compression.BUFFER_SIZE)
decomp = BZ2File(BytesIO(bomb))
- self.assertEqual(bytes(1), decomp.read(1))
+ self.assertEqual(decomp.read(1), b'\0')
max_decomp = 1 + DEFAULT_BUFFER_SIZE
self.assertLessEqual(decomp._buffer.raw.tell(), max_decomp,
"Excessive amount of data was decompressed")
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py
index 5de3ce8..6c7cdd1 100644
--- a/Lib/test/test_calendar.py
+++ b/Lib/test/test_calendar.py
@@ -723,19 +723,19 @@ class CommandLineTestCase(unittest.TestCase):
def assertFailure(self, *args):
rc, stdout, stderr = assert_python_failure('-m', 'calendar', *args)
- self.assertIn(b'Usage:', stderr)
+ self.assertIn(b'usage:', stderr)
self.assertEqual(rc, 2)
def test_help(self):
stdout = self.run_ok('-h')
- self.assertIn(b'Usage:', stdout)
+ self.assertIn(b'usage:', stdout)
self.assertIn(b'calendar.py', stdout)
self.assertIn(b'--help', stdout)
def test_illegal_arguments(self):
self.assertFailure('-z')
- #self.assertFailure('spam')
- #self.assertFailure('2004', 'spam')
+ self.assertFailure('spam')
+ self.assertFailure('2004', 'spam')
self.assertFailure('-t', 'html', '2004', '1')
def test_output_current_year(self):
@@ -836,5 +836,14 @@ class CommandLineTestCase(unittest.TestCase):
b'href="custom.css" />', stdout)
+class MiscTestCase(unittest.TestCase):
+ def test__all__(self):
+ blacklist = {'mdays', 'January', 'February', 'EPOCH',
+ 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY',
+ 'SATURDAY', 'SUNDAY', 'different_locale', 'c',
+ 'prweek', 'week', 'format', 'formatstring', 'main'}
+ support.check__all__(self, calendar, blacklist=blacklist)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 1eadd22..6c3625d 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -4,8 +4,10 @@
import os
import pickle
import random
+import re
import subprocess
import sys
+import sysconfig
import textwrap
import time
import unittest
@@ -220,8 +222,8 @@ class CAPITest(unittest.TestCase):
br'result with an error set\n'
br'ValueError\n'
br'\n'
- br'During handling of the above exception, '
- br'another exception occurred:\n'
+ br'The above exception was the direct cause '
+ br'of the following exception:\n'
br'\n'
br'SystemError: <built-in '
br'function return_result_with_error> '
@@ -442,6 +444,7 @@ class EmbeddingTests(unittest.TestCase):
self.maxDiff = None
self.assertEqual(out.strip(), expected_output)
+
class SkipitemTest(unittest.TestCase):
def test_skipitem(self):
@@ -491,10 +494,10 @@ class SkipitemTest(unittest.TestCase):
_testcapi.parse_tuple_and_keywords(tuple_1, dict_b,
format.encode("ascii"), keywords)
when_not_skipped = False
- except TypeError as e:
+ except SystemError as e:
s = "argument 1 (impossible<bad format char>)"
when_not_skipped = (str(e) == s)
- except RuntimeError as e:
+ except TypeError:
when_not_skipped = False
# test the format unit when skipped
@@ -503,7 +506,7 @@ class SkipitemTest(unittest.TestCase):
_testcapi.parse_tuple_and_keywords(empty_tuple, dict_b,
optional_format.encode("ascii"), keywords)
when_skipped = False
- except RuntimeError as e:
+ except SystemError as e:
s = "impossible<bad format char>: '{}'".format(format)
when_skipped = (str(e) == s)
@@ -524,6 +527,32 @@ class SkipitemTest(unittest.TestCase):
self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords,
(), {}, b'', [42])
+ def test_positional_only(self):
+ parse = _testcapi.parse_tuple_and_keywords
+
+ parse((1, 2, 3), {}, b'OOO', ['', '', 'a'])
+ parse((1, 2), {'a': 3}, b'OOO', ['', '', 'a'])
+ with self.assertRaisesRegex(TypeError,
+ r'Function takes at least 2 positional arguments \(1 given\)'):
+ parse((1,), {'a': 3}, b'OOO', ['', '', 'a'])
+ parse((1,), {}, b'O|OO', ['', '', 'a'])
+ with self.assertRaisesRegex(TypeError,
+ r'Function takes at least 1 positional arguments \(0 given\)'):
+ parse((), {}, b'O|OO', ['', '', 'a'])
+ parse((1, 2), {'a': 3}, b'OO$O', ['', '', 'a'])
+ with self.assertRaisesRegex(TypeError,
+ r'Function takes exactly 2 positional arguments \(1 given\)'):
+ parse((1,), {'a': 3}, b'OO$O', ['', '', 'a'])
+ parse((1,), {}, b'O|O$O', ['', '', 'a'])
+ with self.assertRaisesRegex(TypeError,
+ r'Function takes at least 1 positional arguments \(0 given\)'):
+ parse((), {}, b'O|O$O', ['', '', 'a'])
+ with self.assertRaisesRegex(SystemError, r'Empty parameter name after \$'):
+ parse((1,), {}, b'O|$OO', ['', '', 'a'])
+ with self.assertRaisesRegex(SystemError, 'Empty keyword'):
+ parse((1,), {}, b'O|OO', ['', 'a', ''])
+
+
@unittest.skipUnless(threading, 'Threading required for this test.')
class TestThreadState(unittest.TestCase):
@@ -548,6 +577,7 @@ class TestThreadState(unittest.TestCase):
t.start()
t.join()
+
class Test_testcapi(unittest.TestCase):
def test__testcapi(self):
for name in dir(_testcapi):
@@ -556,5 +586,85 @@ class Test_testcapi(unittest.TestCase):
test = getattr(_testcapi, name)
test()
+
+class PyMemDebugTests(unittest.TestCase):
+ PYTHONMALLOC = 'debug'
+ # '0x04c06e0' or '04C06E0'
+ PTR_REGEX = r'(?:0x)?[0-9a-fA-F]+'
+
+ def check(self, code):
+ with support.SuppressCrashReport():
+ out = assert_python_failure('-c', code,
+ PYTHONMALLOC=self.PYTHONMALLOC)
+ stderr = out.err
+ return stderr.decode('ascii', 'replace')
+
+ def test_buffer_overflow(self):
+ out = self.check('import _testcapi; _testcapi.pymem_buffer_overflow()')
+ regex = (r"Debug memory block at address p={ptr}: API 'm'\n"
+ r" 16 bytes originally requested\n"
+ r" The [0-9] pad bytes at p-[0-9] are FORBIDDENBYTE, as expected.\n"
+ r" The [0-9] pad bytes at tail={ptr} are not all FORBIDDENBYTE \(0x[0-9a-f]{{2}}\):\n"
+ r" at tail\+0: 0x78 \*\*\* OUCH\n"
+ r" at tail\+1: 0xfb\n"
+ r" at tail\+2: 0xfb\n"
+ r" .*\n"
+ r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
+ r" Data at p: cb cb cb .*\n"
+ r"\n"
+ r"Fatal Python error: bad trailing pad byte")
+ regex = regex.format(ptr=self.PTR_REGEX)
+ regex = re.compile(regex, flags=re.DOTALL)
+ self.assertRegex(out, regex)
+
+ def test_api_misuse(self):
+ out = self.check('import _testcapi; _testcapi.pymem_api_misuse()')
+ regex = (r"Debug memory block at address p={ptr}: API 'm'\n"
+ r" 16 bytes originally requested\n"
+ r" The [0-9] pad bytes at p-[0-9] are FORBIDDENBYTE, as expected.\n"
+ r" The [0-9] pad bytes at tail={ptr} are FORBIDDENBYTE, as expected.\n"
+ r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
+ r" Data at p: cb cb cb .*\n"
+ r"\n"
+ r"Fatal Python error: bad ID: Allocated using API 'm', verified using API 'r'\n")
+ regex = regex.format(ptr=self.PTR_REGEX)
+ self.assertRegex(out, regex)
+
+ @unittest.skipUnless(threading, 'Test requires a GIL (multithreading)')
+ def check_malloc_without_gil(self, code):
+ out = self.check(code)
+ expected = ('Fatal Python error: Python memory allocator called '
+ 'without holding the GIL')
+ self.assertIn(expected, out)
+
+ def test_pymem_malloc_without_gil(self):
+ # Debug hooks must raise an error if PyMem_Malloc() is called
+ # without holding the GIL
+ code = 'import _testcapi; _testcapi.pymem_malloc_without_gil()'
+ self.check_malloc_without_gil(code)
+
+ def test_pyobject_malloc_without_gil(self):
+ # Debug hooks must raise an error if PyObject_Malloc() is called
+ # without holding the GIL
+ code = 'import _testcapi; _testcapi.pyobject_malloc_without_gil()'
+ self.check_malloc_without_gil(code)
+
+
+class PyMemMallocDebugTests(PyMemDebugTests):
+ PYTHONMALLOC = 'malloc_debug'
+
+
+@unittest.skipUnless(sysconfig.get_config_var('WITH_PYMALLOC') == 1,
+ 'need pymalloc')
+class PyMemPymallocDebugTests(PyMemDebugTests):
+ PYTHONMALLOC = 'pymalloc_debug'
+
+
+@unittest.skipUnless(Py_DEBUG, 'need Py_DEBUG')
+class PyMemDefaultTests(PyMemDebugTests):
+ # test default allocator of Python compiled in debug mode
+ PYTHONMALLOC = ''
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index ab9f6ab..6373221 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -7,6 +7,7 @@ import unittest
import warnings
from collections import namedtuple
from io import StringIO, BytesIO
+from test import support
class HackedSysModule:
# The regression test will have real values in sys.argv, which
@@ -147,7 +148,7 @@ class CgiTests(unittest.TestCase):
def test_escape(self):
# cgi.escape() is deprecated.
with warnings.catch_warnings():
- warnings.filterwarnings('ignore', 'cgi\.escape',
+ warnings.filterwarnings('ignore', r'cgi\.escape',
DeprecationWarning)
self.assertEqual("test &amp; string", cgi.escape("test & string"))
self.assertEqual("&lt;test string&gt;", cgi.escape("<test string>"))
@@ -473,6 +474,11 @@ this is the content of the fake file
cgi.parse_header('form-data; name="files"; filename="fo\\"o;bar"'),
("form-data", {"name": "files", "filename": 'fo"o;bar'}))
+ def test_all(self):
+ blacklist = {"logfile", "logfp", "initlog", "dolog", "nolog",
+ "closelog", "log", "maxlen", "valid_boundary"}
+ support.check__all__(self, cgi, blacklist=blacklist)
+
BOUNDARY = "---------------------------721837373350705526688164684"
diff --git a/Lib/test/test_charmapcodec.py b/Lib/test/test_charmapcodec.py
index 4064aef..0d4594d 100644
--- a/Lib/test/test_charmapcodec.py
+++ b/Lib/test/test_charmapcodec.py
@@ -9,7 +9,7 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
"""#"
-import test.support, unittest
+import unittest
import codecs
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py
index 1f884e5..0451fb0 100644
--- a/Lib/test/test_cmath.py
+++ b/Lib/test/test_cmath.py
@@ -4,6 +4,8 @@ import test.test_math as test_math
import unittest
import cmath, math
from cmath import phase, polar, rect, pi
+import platform
+import sys
import sysconfig
INF = float('inf')
@@ -154,6 +156,23 @@ class CMathTests(unittest.TestCase):
self.assertAlmostEqual(cmath.e, e_expected, places=9,
msg="cmath.e is {}; should be {}".format(cmath.e, e_expected))
+ def test_infinity_and_nan_constants(self):
+ self.assertEqual(cmath.inf.real, math.inf)
+ self.assertEqual(cmath.inf.imag, 0.0)
+ self.assertEqual(cmath.infj.real, 0.0)
+ self.assertEqual(cmath.infj.imag, math.inf)
+
+ self.assertTrue(math.isnan(cmath.nan.real))
+ self.assertEqual(cmath.nan.imag, 0.0)
+ self.assertEqual(cmath.nanj.real, 0.0)
+ self.assertTrue(math.isnan(cmath.nanj.imag))
+
+ # Check consistency with reprs.
+ self.assertEqual(repr(cmath.inf), "inf")
+ self.assertEqual(repr(cmath.infj), "infj")
+ self.assertEqual(repr(cmath.nan), "nan")
+ self.assertEqual(repr(cmath.nanj), "nanj")
+
def test_user_object(self):
# Test automatic calling of __complex__ and __float__ by cmath
# functions
@@ -315,6 +334,18 @@ class CMathTests(unittest.TestCase):
@requires_IEEE_754
def test_specific_values(self):
+ # Some tests need to be skipped on ancient OS X versions.
+ # See issue #27953.
+ SKIP_ON_TIGER = {'tan0064'}
+
+ osx_version = None
+ if sys.platform == 'darwin':
+ version_txt = platform.mac_ver()[0]
+ try:
+ osx_version = tuple(map(int, version_txt.split('.')))
+ except ValueError:
+ pass
+
def rect_complex(z):
"""Wrapped version of rect that accepts a complex number instead of
two float arguments."""
@@ -328,6 +359,12 @@ class CMathTests(unittest.TestCase):
for id, fn, ar, ai, er, ei, flags in parse_testfile(test_file):
arg = complex(ar, ai)
expected = complex(er, ei)
+
+ # Skip certain tests on OS X 10.4.
+ if osx_version is not None and osx_version < (10, 5):
+ if id in SKIP_ON_TIGER:
+ continue
+
if fn == 'rect':
function = rect_complex
elif fn == 'polar':
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 3d2f769..87571d3 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -348,8 +348,9 @@ class CmdLineTest(unittest.TestCase):
test.support.SuppressCrashReport().__enter__()
sys.stdout.write('x')
os.close(sys.stdout.fileno())"""
- rc, out, err = assert_python_ok('-c', code)
+ rc, out, err = assert_python_failure('-c', code)
self.assertEqual(b'', out)
+ self.assertEqual(120, rc)
self.assertRegex(err.decode('ascii', 'ignore'),
'Exception ignored in.*\nOSError: .*')
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index befe0e4..38cb2e2 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -138,9 +138,8 @@ class CmdLineTest(unittest.TestCase):
expected_argv0, expected_path0,
expected_package, expected_loader,
*cmd_line_switches):
- if not __debug__:
- cmd_line_switches += ('-' + 'O' * sys.flags.optimize,)
- run_args = cmd_line_switches + (script_name,) + tuple(example_args)
+ run_args = [*support.optim_args_from_interpreter_flags(),
+ *cmd_line_switches, script_name, *example_args]
rc, out, err = assert_python_ok(*run_args, __isolated=False)
self._check_output(script_name, rc, out + err, expected_file,
expected_argv0, expected_path0,
@@ -429,7 +428,7 @@ class CmdLineTest(unittest.TestCase):
('builtins.x', br'Error while finding module specification.*'
br'AttributeError'),
('builtins.x.y', br'Error while finding module specification.*'
- br'ImportError.*No module named.*not a package'),
+ br'ModuleNotFoundError.*No module named.*not a package'),
('os.path', br'loader.*cannot handle'),
('importlib', br'No module named.*'
br'is a package and cannot be directly executed'),
diff --git a/Lib/test/test_code_module.py b/Lib/test/test_code_module.py
index 3394b39..1a8f699 100644
--- a/Lib/test/test_code_module.py
+++ b/Lib/test/test_code_module.py
@@ -69,7 +69,7 @@ class TestInteractiveConsole(unittest.TestCase):
# with banner
self.infunc.side_effect = EOFError('Finished')
self.console.interact(banner='Foo')
- self.assertEqual(len(self.stderr.method_calls), 2)
+ self.assertEqual(len(self.stderr.method_calls), 3)
banner_call = self.stderr.method_calls[0]
self.assertEqual(banner_call, ['write', ('Foo\n',), {}])
@@ -77,8 +77,36 @@ class TestInteractiveConsole(unittest.TestCase):
self.stderr.reset_mock()
self.infunc.side_effect = EOFError('Finished')
self.console.interact(banner='')
+ self.assertEqual(len(self.stderr.method_calls), 2)
+
+ def test_exit_msg(self):
+ # default exit message
+ self.infunc.side_effect = EOFError('Finished')
+ self.console.interact(banner='')
+ self.assertEqual(len(self.stderr.method_calls), 2)
+ err_msg = self.stderr.method_calls[1]
+ expected = 'now exiting InteractiveConsole...\n'
+ self.assertEqual(err_msg, ['write', (expected,), {}])
+
+ # no exit message
+ self.stderr.reset_mock()
+ self.infunc.side_effect = EOFError('Finished')
+ self.console.interact(banner='', exitmsg='')
self.assertEqual(len(self.stderr.method_calls), 1)
+ # custom exit message
+ self.stderr.reset_mock()
+ message = (
+ 'bye! \N{GREEK SMALL LETTER ZETA}\N{CYRILLIC SMALL LETTER ZHE}'
+ )
+ self.infunc.side_effect = EOFError('Finished')
+ self.console.interact(banner='', exitmsg=message)
+ self.assertEqual(len(self.stderr.method_calls), 2)
+ err_msg = self.stderr.method_calls[1]
+ expected = message + '\n'
+ self.assertEqual(err_msg, ['write', (expected,), {}])
+
+
def test_cause_tb(self):
self.infunc.side_effect = ["raise ValueError('') from AttributeError",
EOFError('Finished')]
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index ee1e28a..6a3e993 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -4,7 +4,6 @@ import sys
import test.support
import unicodedata
import unittest
-import warnings
class PosReturn:
# this can be used for configurable callbacks
@@ -281,12 +280,12 @@ class CodecCallbackTest(unittest.TestCase):
)
self.assertEqual(
- b"\\u3042\u3xxx".decode("unicode-escape", "test.handler1"),
+ b"\\u3042\\u3xxx".decode("unicode-escape", "test.handler1"),
"\u3042[<92><117><51>]xxx"
)
self.assertEqual(
- b"\\u3042\u3xx".decode("unicode-escape", "test.handler1"),
+ b"\\u3042\\u3xx".decode("unicode-escape", "test.handler1"),
"\u3042[<92><117><51>]xx"
)
diff --git a/Lib/test/test_codecencodings_cn.py b/Lib/test/test_codecencodings_cn.py
index d0e3a15..3bdf7d0 100644
--- a/Lib/test/test_codecencodings_cn.py
+++ b/Lib/test/test_codecencodings_cn.py
@@ -3,7 +3,6 @@
# Codec encoding tests for PRC encodings.
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecencodings_hk.py b/Lib/test/test_codecencodings_hk.py
index bb9be11..c5e2f99 100644
--- a/Lib/test/test_codecencodings_hk.py
+++ b/Lib/test/test_codecencodings_hk.py
@@ -3,7 +3,6 @@
# Codec encoding tests for HongKong encodings.
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecencodings_iso2022.py b/Lib/test/test_codecencodings_iso2022.py
index 8a3ca70..00ea1c3 100644
--- a/Lib/test/test_codecencodings_iso2022.py
+++ b/Lib/test/test_codecencodings_iso2022.py
@@ -1,6 +1,5 @@
# Codec encoding tests for ISO 2022 encodings.
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecencodings_jp.py b/Lib/test/test_codecencodings_jp.py
index 44b63a0..94378d1 100644
--- a/Lib/test/test_codecencodings_jp.py
+++ b/Lib/test/test_codecencodings_jp.py
@@ -3,7 +3,6 @@
# Codec encoding tests for Japanese encodings.
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecencodings_kr.py b/Lib/test/test_codecencodings_kr.py
index b6a74fb..863d16b 100644
--- a/Lib/test/test_codecencodings_kr.py
+++ b/Lib/test/test_codecencodings_kr.py
@@ -3,7 +3,6 @@
# Codec encoding tests for ROK encodings.
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecencodings_tw.py b/Lib/test/test_codecencodings_tw.py
index 9174296..bb1d133 100644
--- a/Lib/test/test_codecencodings_tw.py
+++ b/Lib/test/test_codecencodings_tw.py
@@ -3,7 +3,6 @@
# Codec encoding tests for ROC encodings.
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecmaps_cn.py b/Lib/test/test_codecmaps_cn.py
index f1bd384..89e51c6 100644
--- a/Lib/test/test_codecmaps_cn.py
+++ b/Lib/test/test_codecmaps_cn.py
@@ -3,7 +3,6 @@
# Codec mapping tests for PRC encodings
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py
index 4c0c415..7a48d24 100644
--- a/Lib/test/test_codecmaps_hk.py
+++ b/Lib/test/test_codecmaps_hk.py
@@ -3,7 +3,6 @@
# Codec mapping tests for HongKong encodings
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecmaps_jp.py b/Lib/test/test_codecmaps_jp.py
index 5773823..fdfec80 100644
--- a/Lib/test/test_codecmaps_jp.py
+++ b/Lib/test/test_codecmaps_jp.py
@@ -3,7 +3,6 @@
# Codec mapping tests for Japanese encodings
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecmaps_kr.py b/Lib/test/test_codecmaps_kr.py
index 6cb41c8..471cd74 100644
--- a/Lib/test/test_codecmaps_kr.py
+++ b/Lib/test/test_codecmaps_kr.py
@@ -3,7 +3,6 @@
# Codec mapping tests for ROK encodings
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecmaps_tw.py b/Lib/test/test_codecmaps_tw.py
index 2ea44b5..145a97d 100644
--- a/Lib/test/test_codecmaps_tw.py
+++ b/Lib/test/test_codecmaps_tw.py
@@ -3,7 +3,6 @@
# Codec mapping tests for ROC encodings
#
-from test import support
from test import multibytecodec_support
import unittest
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 013ec64..1e63ed8 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -4,16 +4,10 @@ import io
import locale
import sys
import unittest
-import warnings
import encodings
from test import support
-if sys.platform == 'win32':
- VISTA_OR_LATER = (sys.getwindowsversion().major >= 6)
-else:
- VISTA_OR_LATER = False
-
try:
import ctypes
except ImportError:
@@ -27,6 +21,7 @@ def coding_checker(self, coder):
self.assertEqual(coder(input), (expect, len(input)))
return check
+
class Queue(object):
"""
queue: write bytes at one end, read bytes from the other end
@@ -47,6 +42,7 @@ class Queue(object):
self._buffer = self._buffer[size:]
return s
+
class MixInCheckStateHandling:
def check_state_handling_decode(self, encoding, u, s):
for i in range(len(s)+1):
@@ -80,6 +76,7 @@ class MixInCheckStateHandling:
part2 = d.encode(u[i:], True)
self.assertEqual(s, part1+part2)
+
class ReadTest(MixInCheckStateHandling):
def check_partial(self, input, partialresults):
# get a StreamReader for the encoding and feed the bytestring version
@@ -358,6 +355,12 @@ class ReadTest(MixInCheckStateHandling):
self.assertEqual("[\uDC80]".encode(self.encoding, "replace"),
"[?]".encode(self.encoding))
+ # sequential surrogate characters
+ self.assertEqual("[\uD800\uDC80]".encode(self.encoding, "ignore"),
+ "[]".encode(self.encoding))
+ self.assertEqual("[\uD800\uDC80]".encode(self.encoding, "replace"),
+ "[??]".encode(self.encoding))
+
bom = "".encode(self.encoding)
for before, after in [("\U00010fff", "A"), ("[", "]"),
("A", "\U00010fff")]:
@@ -383,6 +386,7 @@ class ReadTest(MixInCheckStateHandling):
self.assertEqual(test_sequence.decode(self.encoding, "backslashreplace"),
before + backslashreplace + after)
+
class UTF32Test(ReadTest, unittest.TestCase):
encoding = "utf-32"
if sys.byteorder == 'little':
@@ -478,6 +482,7 @@ class UTF32Test(ReadTest, unittest.TestCase):
self.assertEqual('\U00010000' * 1024,
codecs.utf_32_decode(encoded_be)[0])
+
class UTF32LETest(ReadTest, unittest.TestCase):
encoding = "utf-32-le"
ill_formed_sequence = b"\x80\xdc\x00\x00"
@@ -523,6 +528,7 @@ class UTF32LETest(ReadTest, unittest.TestCase):
self.assertEqual('\U00010000' * 1024,
codecs.utf_32_le_decode(encoded)[0])
+
class UTF32BETest(ReadTest, unittest.TestCase):
encoding = "utf-32-be"
ill_formed_sequence = b"\x00\x00\xdc\x80"
@@ -747,6 +753,7 @@ class UTF8Test(ReadTest, unittest.TestCase):
encoding = "utf-8"
ill_formed_sequence = b"\xed\xb2\x80"
ill_formed_sequence_replace = "\ufffd" * 3
+ BOM = b''
def test_partial(self):
self.check_partial(
@@ -775,27 +782,49 @@ class UTF8Test(ReadTest, unittest.TestCase):
self.check_state_handling_decode(self.encoding,
u, u.encode(self.encoding))
+ def test_decode_error(self):
+ for data, error_handler, expected in (
+ (b'[\x80\xff]', 'ignore', '[]'),
+ (b'[\x80\xff]', 'replace', '[\ufffd\ufffd]'),
+ (b'[\x80\xff]', 'surrogateescape', '[\udc80\udcff]'),
+ (b'[\x80\xff]', 'backslashreplace', '[\\x80\\xff]'),
+ ):
+ with self.subTest(data=data, error_handler=error_handler,
+ expected=expected):
+ self.assertEqual(data.decode(self.encoding, error_handler),
+ expected)
+
def test_lone_surrogates(self):
super().test_lone_surrogates()
# not sure if this is making sense for
# UTF-16 and UTF-32
- self.assertEqual("[\uDC80]".encode('utf-8', "surrogateescape"),
- b'[\x80]')
+ self.assertEqual("[\uDC80]".encode(self.encoding, "surrogateescape"),
+ self.BOM + b'[\x80]')
+
+ with self.assertRaises(UnicodeEncodeError) as cm:
+ "[\uDC80\uD800\uDFFF]".encode(self.encoding, "surrogateescape")
+ exc = cm.exception
+ self.assertEqual(exc.object[exc.start:exc.end], '\uD800\uDFFF')
def test_surrogatepass_handler(self):
- self.assertEqual("abc\ud800def".encode("utf-8", "surrogatepass"),
- b"abc\xed\xa0\x80def")
- self.assertEqual(b"abc\xed\xa0\x80def".decode("utf-8", "surrogatepass"),
+ self.assertEqual("abc\ud800def".encode(self.encoding, "surrogatepass"),
+ self.BOM + b"abc\xed\xa0\x80def")
+ self.assertEqual("\U00010fff\uD800".encode(self.encoding, "surrogatepass"),
+ self.BOM + b"\xf0\x90\xbf\xbf\xed\xa0\x80")
+ self.assertEqual("[\uD800\uDC80]".encode(self.encoding, "surrogatepass"),
+ self.BOM + b'[\xed\xa0\x80\xed\xb2\x80]')
+
+ self.assertEqual(b"abc\xed\xa0\x80def".decode(self.encoding, "surrogatepass"),
"abc\ud800def")
- self.assertEqual("\U00010fff\uD800".encode("utf-8", "surrogatepass"),
- b"\xf0\x90\xbf\xbf\xed\xa0\x80")
- self.assertEqual(b"\xf0\x90\xbf\xbf\xed\xa0\x80".decode("utf-8", "surrogatepass"),
+ self.assertEqual(b"\xf0\x90\xbf\xbf\xed\xa0\x80".decode(self.encoding, "surrogatepass"),
"\U00010fff\uD800")
+
self.assertTrue(codecs.lookup_error("surrogatepass"))
with self.assertRaises(UnicodeDecodeError):
- b"abc\xed\xa0".decode("utf-8", "surrogatepass")
+ b"abc\xed\xa0".decode(self.encoding, "surrogatepass")
with self.assertRaises(UnicodeDecodeError):
- b"abc\xed\xa0z".decode("utf-8", "surrogatepass")
+ b"abc\xed\xa0z".decode(self.encoding, "surrogatepass")
+
@unittest.skipUnless(sys.platform == 'win32',
'cp65001 is a Windows-only codec')
@@ -807,18 +836,13 @@ class CP65001Test(ReadTest, unittest.TestCase):
('abc', 'strict', b'abc'),
('\xe9\u20ac', 'strict', b'\xc3\xa9\xe2\x82\xac'),
('\U0010ffff', 'strict', b'\xf4\x8f\xbf\xbf'),
+ ('\udc80', 'strict', None),
+ ('\udc80', 'ignore', b''),
+ ('\udc80', 'replace', b'?'),
+ ('\udc80', 'backslashreplace', b'\\udc80'),
+ ('\udc80', 'namereplace', b'\\udc80'),
+ ('\udc80', 'surrogatepass', b'\xed\xb2\x80'),
]
- if VISTA_OR_LATER:
- tests.extend((
- ('\udc80', 'strict', None),
- ('\udc80', 'ignore', b''),
- ('\udc80', 'replace', b'?'),
- ('\udc80', 'backslashreplace', b'\\udc80'),
- ('\udc80', 'namereplace', b'\\udc80'),
- ('\udc80', 'surrogatepass', b'\xed\xb2\x80'),
- ))
- else:
- tests.append(('\udc80', 'strict', b'\xed\xb2\x80'))
for text, errors, expected in tests:
if expected is not None:
try:
@@ -845,17 +869,10 @@ class CP65001Test(ReadTest, unittest.TestCase):
(b'[\xff]', 'ignore', '[]'),
(b'[\xff]', 'replace', '[\ufffd]'),
(b'[\xff]', 'surrogateescape', '[\udcff]'),
+ (b'[\xed\xb2\x80]', 'strict', None),
+ (b'[\xed\xb2\x80]', 'ignore', '[]'),
+ (b'[\xed\xb2\x80]', 'replace', '[\ufffd\ufffd\ufffd]'),
]
- if VISTA_OR_LATER:
- tests.extend((
- (b'[\xed\xb2\x80]', 'strict', None),
- (b'[\xed\xb2\x80]', 'ignore', '[]'),
- (b'[\xed\xb2\x80]', 'replace', '[\ufffd\ufffd\ufffd]'),
- ))
- else:
- tests.extend((
- (b'[\xed\xb2\x80]', 'strict', '[\udc80]'),
- ))
for raw, errors, expected in tests:
if expected is not None:
try:
@@ -870,7 +887,6 @@ class CP65001Test(ReadTest, unittest.TestCase):
self.assertRaises(UnicodeDecodeError,
raw.decode, 'cp65001', errors)
- @unittest.skipUnless(VISTA_OR_LATER, 'require Windows Vista or later')
def test_lone_surrogates(self):
self.assertRaises(UnicodeEncodeError, "\ud800".encode, "cp65001")
self.assertRaises(UnicodeDecodeError, b"\xed\xa0\x80".decode, "cp65001")
@@ -887,7 +903,6 @@ class CP65001Test(ReadTest, unittest.TestCase):
self.assertEqual("[\uDC80]".encode("cp65001", "replace"),
b'[?]')
- @unittest.skipUnless(VISTA_OR_LATER, 'require Windows Vista or later')
def test_surrogatepass_handler(self):
self.assertEqual("abc\ud800def".encode("cp65001", "surrogatepass"),
b"abc\xed\xa0\x80def")
@@ -1059,6 +1074,7 @@ class ReadBufferTest(unittest.TestCase):
class UTF8SigTest(UTF8Test, unittest.TestCase):
encoding = "utf-8-sig"
+ BOM = codecs.BOM_UTF8
def test_partial(self):
self.check_partial(
@@ -1159,7 +1175,7 @@ class EscapeDecodeTest(unittest.TestCase):
check(b"[\\\n]", b"[]")
check(br'[\"]', b'["]')
check(br"[\']", b"[']")
- check(br"[\\]", br"[\]")
+ check(br"[\\]", b"[\\]")
check(br"[\a]", b"[\x07]")
check(br"[\b]", b"[\x08]")
check(br"[\t]", b"[\x09]")
@@ -1168,7 +1184,6 @@ class EscapeDecodeTest(unittest.TestCase):
check(br"[\f]", b"[\x0c]")
check(br"[\r]", b"[\x0d]")
check(br"[\7]", b"[\x07]")
- check(br"[\8]", br"[\8]")
check(br"[\78]", b"[\x078]")
check(br"[\41]", b"[!]")
check(br"[\418]", b"[!8]")
@@ -1176,12 +1191,18 @@ class EscapeDecodeTest(unittest.TestCase):
check(br"[\1010]", b"[A0]")
check(br"[\501]", b"[A]")
check(br"[\x41]", b"[A]")
- check(br"[\X41]", br"[\X41]")
check(br"[\x410]", b"[A0]")
- for b in range(256):
- if b not in b'\n"\'\\abtnvfr01234567x':
- b = bytes([b])
- check(b'\\' + b, b'\\' + b)
+ for i in range(97, 123):
+ b = bytes([i])
+ if b not in b'abfnrtvx':
+ with self.assertWarns(DeprecationWarning):
+ check(b"\\" + b, b"\\" + b)
+ with self.assertWarns(DeprecationWarning):
+ check(b"\\" + b.upper(), b"\\" + b.upper())
+ with self.assertWarns(DeprecationWarning):
+ check(br"\8", b"\\8")
+ with self.assertWarns(DeprecationWarning):
+ check(br"\9", b"\\9")
def test_errors(self):
decode = codecs.escape_decode
@@ -1194,6 +1215,7 @@ class EscapeDecodeTest(unittest.TestCase):
self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8))
self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8))
+
class RecodingTest(unittest.TestCase):
def test_recoding(self):
f = io.BytesIO()
@@ -1313,6 +1335,7 @@ for i in punycode_testcases:
if len(i)!=2:
print(repr(i))
+
class PunycodeTest(unittest.TestCase):
def test_encode(self):
for uni, puny in punycode_testcases:
@@ -1332,6 +1355,7 @@ class PunycodeTest(unittest.TestCase):
puny = puny.decode("ascii").encode("ascii")
self.assertEqual(uni, puny.decode("punycode"))
+
class UnicodeInternalTest(unittest.TestCase):
@unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t')
def test_bug1251300(self):
@@ -1586,6 +1610,7 @@ class NameprepTest(unittest.TestCase):
except Exception as e:
raise support.TestFailed("Test 3.%d: %s" % (pos+1, str(e)))
+
class IDNACodecTest(unittest.TestCase):
def test_builtin_decode(self):
self.assertEqual(str(b"python.org", "idna"), "python.org")
@@ -1672,6 +1697,7 @@ class IDNACodecTest(unittest.TestCase):
self.assertRaises(Exception,
b"python.org".decode, "idna", errors)
+
class CodecsModuleTest(unittest.TestCase):
def test_decode(self):
@@ -1780,6 +1806,7 @@ class CodecsModuleTest(unittest.TestCase):
self.assertRaises(UnicodeError,
codecs.decode, b'abc', 'undefined', errors)
+
class StreamReaderTest(unittest.TestCase):
def setUp(self):
@@ -1790,6 +1817,7 @@ class StreamReaderTest(unittest.TestCase):
f = self.reader(self.stream)
self.assertEqual(f.readlines(), ['\ud55c\n', '\uae00'])
+
class EncodedFileTest(unittest.TestCase):
def test_basic(self):
@@ -1909,6 +1937,8 @@ all_unicode_encodings = [
if hasattr(codecs, "mbcs_encode"):
all_unicode_encodings.append("mbcs")
+if hasattr(codecs, "oem_encode"):
+ all_unicode_encodings.append("oem")
# The following encoding is not tested, because it's not supposed
# to work:
@@ -1920,6 +1950,7 @@ broken_unicode_with_stateful = [
"unicode_internal"
]
+
class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
def test_basics(self):
s = "abc123" # all codecs should be able to encode these
@@ -2082,6 +2113,7 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
self.check_state_handling_decode(encoding, u, u.encode(encoding))
self.check_state_handling_encode(encoding, u, u.encode(encoding))
+
class CharmapTest(unittest.TestCase):
def test_decode_with_string_map(self):
self.assertEqual(
@@ -2332,6 +2364,7 @@ class WithStmtTest(unittest.TestCase):
info.streamwriter, 'strict') as srw:
self.assertEqual(srw.read(), "\xfc")
+
class TypesTest(unittest.TestCase):
def test_decode_unicode(self):
# Most decoders don't accept unicode input
@@ -2420,7 +2453,6 @@ class UnicodeEscapeTest(unittest.TestCase):
check(br"[\f]", "[\x0c]")
check(br"[\r]", "[\x0d]")
check(br"[\7]", "[\x07]")
- check(br"[\8]", r"[\8]")
check(br"[\78]", "[\x078]")
check(br"[\41]", "[!]")
check(br"[\418]", "[!8]")
@@ -2430,9 +2462,18 @@ class UnicodeEscapeTest(unittest.TestCase):
check(br"[\x410]", "[A0]")
check(br"\u20ac", "\u20ac")
check(br"\U0001d120", "\U0001d120")
- for b in range(256):
- if b not in b'\n"\'\\abtnvfr01234567xuUN':
- check(b'\\' + bytes([b]), '\\' + chr(b))
+ for i in range(97, 123):
+ b = bytes([i])
+ if b not in b'abfnrtuvx':
+ with self.assertWarns(DeprecationWarning):
+ check(b"\\" + b, "\\" + chr(i))
+ if b.upper() not in b'UN':
+ with self.assertWarns(DeprecationWarning):
+ check(b"\\" + b.upper(), "\\" + chr(i-32))
+ with self.assertWarns(DeprecationWarning):
+ check(br"\8", "\\8")
+ with self.assertWarns(DeprecationWarning):
+ check(br"\9", "\\9")
def test_decode_errors(self):
decode = codecs.unicode_escape_decode
@@ -2642,6 +2683,7 @@ else:
bytes_transform_encodings.append("bz2_codec")
transform_aliases["bz2_codec"] = ["bz2"]
+
class TransformCodecTest(unittest.TestCase):
def test_basics(self):
@@ -2694,8 +2736,8 @@ class TransformCodecTest(unittest.TestCase):
bad_input = "bad input type"
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
- fmt = ( "{!r} is not a text encoding; "
- "use codecs.encode\(\) to handle arbitrary codecs")
+ fmt = (r"{!r} is not a text encoding; "
+ r"use codecs.encode\(\) to handle arbitrary codecs")
msg = fmt.format(encoding)
with self.assertRaisesRegex(LookupError, msg) as failure:
bad_input.encode(encoding)
@@ -2704,7 +2746,7 @@ class TransformCodecTest(unittest.TestCase):
def test_text_to_binary_blacklists_text_transforms(self):
# Check str.encode gives a good error message for str -> str codecs
msg = (r"^'rot_13' is not a text encoding; "
- "use codecs.encode\(\) to handle arbitrary codecs")
+ r"use codecs.encode\(\) to handle arbitrary codecs")
with self.assertRaisesRegex(LookupError, msg):
"just an example message".encode("rot_13")
@@ -2716,7 +2758,7 @@ class TransformCodecTest(unittest.TestCase):
with self.subTest(encoding=encoding):
encoded_data = codecs.encode(data, encoding)
fmt = (r"{!r} is not a text encoding; "
- "use codecs.decode\(\) to handle arbitrary codecs")
+ r"use codecs.decode\(\) to handle arbitrary codecs")
msg = fmt.format(encoding)
with self.assertRaisesRegex(LookupError, msg):
encoded_data.decode(encoding)
@@ -2728,7 +2770,7 @@ class TransformCodecTest(unittest.TestCase):
for bad_input in (b"immutable", bytearray(b"mutable")):
with self.subTest(bad_input=bad_input):
msg = (r"^'rot_13' is not a text encoding; "
- "use codecs.decode\(\) to handle arbitrary codecs")
+ r"use codecs.decode\(\) to handle arbitrary codecs")
with self.assertRaisesRegex(LookupError, msg) as failure:
bad_input.decode("rot_13")
self.assertIsNone(failure.exception.__cause__)
@@ -2947,12 +2989,12 @@ class ExceptionChainingTest(unittest.TestCase):
self.assertEqual(decoded, b"not str!")
# Text model methods should complain
fmt = (r"^{!r} encoder returned 'str' instead of 'bytes'; "
- "use codecs.encode\(\) to encode to arbitrary types$")
+ r"use codecs.encode\(\) to encode to arbitrary types$")
msg = fmt.format(self.codec_name)
with self.assertRaisesRegex(TypeError, msg):
"str_input".encode(self.codec_name)
fmt = (r"^{!r} decoder returned 'bytes' instead of 'str'; "
- "use codecs.decode\(\) to decode to arbitrary types$")
+ r"use codecs.decode\(\) to decode to arbitrary types$")
msg = fmt.format(self.codec_name)
with self.assertRaisesRegex(TypeError, msg):
b"bytes input".decode(self.codec_name)
@@ -3093,11 +3135,10 @@ class CodePageTest(unittest.TestCase):
(b'\xff\xf4\x8f\xbf\xbf', 'ignore', '\U0010ffff'),
(b'\xff\xf4\x8f\xbf\xbf', 'replace', '\ufffd\U0010ffff'),
))
- if VISTA_OR_LATER:
- self.check_encode(self.CP_UTF8, (
- ('[\U0010ffff\uDC80]', 'ignore', b'[\xf4\x8f\xbf\xbf]'),
- ('[\U0010ffff\uDC80]', 'replace', b'[\xf4\x8f\xbf\xbf?]'),
- ))
+ self.check_encode(self.CP_UTF8, (
+ ('[\U0010ffff\uDC80]', 'ignore', b'[\xf4\x8f\xbf\xbf]'),
+ ('[\U0010ffff\uDC80]', 'replace', b'[\xf4\x8f\xbf\xbf?]'),
+ ))
def test_incremental(self):
decoded = codecs.code_page_decode(932, b'\x82', 'strict', False)
@@ -3118,6 +3159,96 @@ class CodePageTest(unittest.TestCase):
False)
self.assertEqual(decoded, ('abc', 3))
+ def test_mbcs_alias(self):
+ # Check that looking up our 'default' codepage will return
+ # mbcs when we don't have a more specific one available
+ import _bootlocale
+ def _get_fake_codepage(*a):
+ return 'cp123'
+ old_getpreferredencoding = _bootlocale.getpreferredencoding
+ _bootlocale.getpreferredencoding = _get_fake_codepage
+ try:
+ codec = codecs.lookup('cp123')
+ self.assertEqual(codec.name, 'mbcs')
+ finally:
+ _bootlocale.getpreferredencoding = old_getpreferredencoding
+
+
+class ASCIITest(unittest.TestCase):
+ def test_encode(self):
+ self.assertEqual('abc123'.encode('ascii'), b'abc123')
+
+ def test_encode_error(self):
+ for data, error_handler, expected in (
+ ('[\x80\xff\u20ac]', 'ignore', b'[]'),
+ ('[\x80\xff\u20ac]', 'replace', b'[???]'),
+ ('[\x80\xff\u20ac]', 'xmlcharrefreplace', b'[&#128;&#255;&#8364;]'),
+ ('[\x80\xff\u20ac\U000abcde]', 'backslashreplace',
+ b'[\\x80\\xff\\u20ac\\U000abcde]'),
+ ('[\udc80\udcff]', 'surrogateescape', b'[\x80\xff]'),
+ ):
+ with self.subTest(data=data, error_handler=error_handler,
+ expected=expected):
+ self.assertEqual(data.encode('ascii', error_handler),
+ expected)
+
+ def test_encode_surrogateescape_error(self):
+ with self.assertRaises(UnicodeEncodeError):
+ # the first character can be decoded, but not the second
+ '\udc80\xff'.encode('ascii', 'surrogateescape')
+
+ def test_decode(self):
+ self.assertEqual(b'abc'.decode('ascii'), 'abc')
+
+ def test_decode_error(self):
+ for data, error_handler, expected in (
+ (b'[\x80\xff]', 'ignore', '[]'),
+ (b'[\x80\xff]', 'replace', '[\ufffd\ufffd]'),
+ (b'[\x80\xff]', 'surrogateescape', '[\udc80\udcff]'),
+ (b'[\x80\xff]', 'backslashreplace', '[\\x80\\xff]'),
+ ):
+ with self.subTest(data=data, error_handler=error_handler,
+ expected=expected):
+ self.assertEqual(data.decode('ascii', error_handler),
+ expected)
+
+
+class Latin1Test(unittest.TestCase):
+ def test_encode(self):
+ for data, expected in (
+ ('abc', b'abc'),
+ ('\x80\xe9\xff', b'\x80\xe9\xff'),
+ ):
+ with self.subTest(data=data, expected=expected):
+ self.assertEqual(data.encode('latin1'), expected)
+
+ def test_encode_errors(self):
+ for data, error_handler, expected in (
+ ('[\u20ac\udc80]', 'ignore', b'[]'),
+ ('[\u20ac\udc80]', 'replace', b'[??]'),
+ ('[\u20ac\U000abcde]', 'backslashreplace',
+ b'[\\u20ac\\U000abcde]'),
+ ('[\u20ac\udc80]', 'xmlcharrefreplace', b'[&#8364;&#56448;]'),
+ ('[\udc80\udcff]', 'surrogateescape', b'[\x80\xff]'),
+ ):
+ with self.subTest(data=data, error_handler=error_handler,
+ expected=expected):
+ self.assertEqual(data.encode('latin1', error_handler),
+ expected)
+
+ def test_encode_surrogateescape_error(self):
+ with self.assertRaises(UnicodeEncodeError):
+ # the first character can be decoded, but not the second
+ '\udc80\u20ac'.encode('latin1', 'surrogateescape')
+
+ def test_decode(self):
+ for data, expected in (
+ (b'abc', 'abc'),
+ (b'[\x80\xff]', '[\x80\xff]'),
+ ):
+ with self.subTest(data=data, expected=expected):
+ self.assertEqual(data.decode('latin1'), expected)
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py
index 509bf5d..98da26f 100644
--- a/Lib/test/test_codeop.py
+++ b/Lib/test/test_codeop.py
@@ -282,7 +282,6 @@ class CodeopTests(unittest.TestCase):
ai("if (a == 1 and b = 2): pass")
ai("del 1")
- ai("del ()")
ai("del (1,)")
ai("del [1]")
ai("del '1'")
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 5238382..52ff256 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -20,10 +20,10 @@ from collections import UserDict, UserString, UserList
from collections import ChainMap
from collections import deque
from collections.abc import Awaitable, Coroutine, AsyncIterator, AsyncIterable
-from collections.abc import Hashable, Iterable, Iterator, Generator
-from collections.abc import Sized, Container, Callable
+from collections.abc import Hashable, Iterable, Iterator, Generator, Reversible
+from collections.abc import Sized, Container, Callable, Collection
from collections.abc import Set, MutableSet
-from collections.abc import Mapping, MutableMapping, KeysView, ItemsView
+from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView
from collections.abc import Sequence, MutableSequence
from collections.abc import ByteString
@@ -242,6 +242,10 @@ class TestNamedTuple(unittest.TestCase):
]:
self.assertEqual(namedtuple('NT', spec, rename=True)._fields, renamed)
+ def test_module_parameter(self):
+ NT = namedtuple('NT', ['x', 'y'], module=collections)
+ self.assertEqual(NT.__module__, collections)
+
def test_instance(self):
Point = namedtuple('Point', 'x y')
p = Point(11, 22)
@@ -412,6 +416,18 @@ class TestNamedTuple(unittest.TestCase):
self.assertEqual(NTColor._fields, ('red', 'green', 'blue'))
globals().pop('NTColor', None) # clean-up after this test
+ def test_keyword_only_arguments(self):
+ # See issue 25628
+ with support.captured_stdout() as template:
+ NT = namedtuple('NT', ['x', 'y'], verbose=True)
+ self.assertIn('class NT', NT._source)
+ with self.assertRaises(TypeError):
+ NT = namedtuple('NT', ['x', 'y'], True)
+
+ NT = namedtuple('NT', ['abc', 'def'], rename=True)
+ self.assertEqual(NT._fields, ('abc', '_1'))
+ with self.assertRaises(TypeError):
+ NT = namedtuple('NT', ['abc', 'def'], False, True)
def test_namedtuple_subclass_issue_24931(self):
class Point(namedtuple('_Point', ['x', 'y'])):
@@ -487,6 +503,9 @@ class ABCTestCase(unittest.TestCase):
self.assertTrue(other.right_side,'Right side not called for %s.%s'
% (type(instance), name))
+def _test_gen():
+ yield
+
class TestOneTrickPonyABCs(ABCTestCase):
def test_Awaitable(self):
@@ -674,7 +693,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
samples = [bytes(), str(),
tuple(), list(), set(), frozenset(), dict(),
dict().keys(), dict().items(), dict().values(),
- (lambda: (yield))(),
+ _test_gen(),
(x for x in []),
]
for x in samples:
@@ -688,6 +707,161 @@ class TestOneTrickPonyABCs(ABCTestCase):
self.assertFalse(issubclass(str, I))
self.validate_abstract_methods(Iterable, '__iter__')
self.validate_isinstance(Iterable, '__iter__')
+ # Check None blocking
+ class It:
+ def __iter__(self): return iter([])
+ class ItBlocked(It):
+ __iter__ = None
+ self.assertTrue(issubclass(It, Iterable))
+ self.assertTrue(isinstance(It(), Iterable))
+ self.assertFalse(issubclass(ItBlocked, Iterable))
+ self.assertFalse(isinstance(ItBlocked(), Iterable))
+
+ def test_Reversible(self):
+ # Check some non-reversibles
+ non_samples = [None, 42, 3.14, 1j, dict(), set(), frozenset()]
+ for x in non_samples:
+ self.assertNotIsInstance(x, Reversible)
+ self.assertFalse(issubclass(type(x), Reversible), repr(type(x)))
+ # Check some non-reversible iterables
+ non_reversibles = [dict().keys(), dict().items(), dict().values(),
+ Counter(), Counter().keys(), Counter().items(),
+ Counter().values(), _test_gen(),
+ (x for x in []), iter([]), reversed([])]
+ for x in non_reversibles:
+ self.assertNotIsInstance(x, Reversible)
+ self.assertFalse(issubclass(type(x), Reversible), repr(type(x)))
+ # Check some reversible iterables
+ samples = [bytes(), str(), tuple(), list(), OrderedDict(),
+ OrderedDict().keys(), OrderedDict().items(),
+ OrderedDict().values()]
+ for x in samples:
+ self.assertIsInstance(x, Reversible)
+ self.assertTrue(issubclass(type(x), Reversible), repr(type(x)))
+ # Check also Mapping, MutableMapping, and Sequence
+ self.assertTrue(issubclass(Sequence, Reversible), repr(Sequence))
+ self.assertFalse(issubclass(Mapping, Reversible), repr(Mapping))
+ self.assertFalse(issubclass(MutableMapping, Reversible), repr(MutableMapping))
+ # Check direct subclassing
+ class R(Reversible):
+ def __iter__(self):
+ return iter(list())
+ def __reversed__(self):
+ return iter(list())
+ self.assertEqual(list(reversed(R())), [])
+ self.assertFalse(issubclass(float, R))
+ self.validate_abstract_methods(Reversible, '__reversed__', '__iter__')
+ # Check reversible non-iterable (which is not Reversible)
+ class RevNoIter:
+ def __reversed__(self): return reversed([])
+ class RevPlusIter(RevNoIter):
+ def __iter__(self): return iter([])
+ self.assertFalse(issubclass(RevNoIter, Reversible))
+ self.assertFalse(isinstance(RevNoIter(), Reversible))
+ self.assertTrue(issubclass(RevPlusIter, Reversible))
+ self.assertTrue(isinstance(RevPlusIter(), Reversible))
+ # Check None blocking
+ class Rev:
+ def __iter__(self): return iter([])
+ def __reversed__(self): return reversed([])
+ class RevItBlocked(Rev):
+ __iter__ = None
+ class RevRevBlocked(Rev):
+ __reversed__ = None
+ self.assertTrue(issubclass(Rev, Reversible))
+ self.assertTrue(isinstance(Rev(), Reversible))
+ self.assertFalse(issubclass(RevItBlocked, Reversible))
+ self.assertFalse(isinstance(RevItBlocked(), Reversible))
+ self.assertFalse(issubclass(RevRevBlocked, Reversible))
+ self.assertFalse(isinstance(RevRevBlocked(), Reversible))
+
+ def test_Collection(self):
+ # Check some non-collections
+ non_collections = [None, 42, 3.14, 1j, lambda x: 2*x]
+ for x in non_collections:
+ self.assertNotIsInstance(x, Collection)
+ self.assertFalse(issubclass(type(x), Collection), repr(type(x)))
+ # Check some non-collection iterables
+ non_col_iterables = [_test_gen(), iter(b''), iter(bytearray()),
+ (x for x in []), dict().values()]
+ for x in non_col_iterables:
+ self.assertNotIsInstance(x, Collection)
+ self.assertFalse(issubclass(type(x), Collection), repr(type(x)))
+ # Check some collections
+ samples = [set(), frozenset(), dict(), bytes(), str(), tuple(),
+ list(), dict().keys(), dict().items()]
+ for x in samples:
+ self.assertIsInstance(x, Collection)
+ self.assertTrue(issubclass(type(x), Collection), repr(type(x)))
+ # Check also Mapping, MutableMapping, etc.
+ self.assertTrue(issubclass(Sequence, Collection), repr(Sequence))
+ self.assertTrue(issubclass(Mapping, Collection), repr(Mapping))
+ self.assertTrue(issubclass(MutableMapping, Collection),
+ repr(MutableMapping))
+ self.assertTrue(issubclass(Set, Collection), repr(Set))
+ self.assertTrue(issubclass(MutableSet, Collection), repr(MutableSet))
+ self.assertTrue(issubclass(Sequence, Collection), repr(MutableSet))
+ # Check direct subclassing
+ class Col(Collection):
+ def __iter__(self):
+ return iter(list())
+ def __len__(self):
+ return 0
+ def __contains__(self, item):
+ return False
+ class DerCol(Col): pass
+ self.assertEqual(list(iter(Col())), [])
+ self.assertFalse(issubclass(list, Col))
+ self.assertFalse(issubclass(set, Col))
+ self.assertFalse(issubclass(float, Col))
+ self.assertEqual(list(iter(DerCol())), [])
+ self.assertFalse(issubclass(list, DerCol))
+ self.assertFalse(issubclass(set, DerCol))
+ self.assertFalse(issubclass(float, DerCol))
+ self.validate_abstract_methods(Collection, '__len__', '__iter__',
+ '__contains__')
+ # Check sized container non-iterable (which is not Collection) etc.
+ class ColNoIter:
+ def __len__(self): return 0
+ def __contains__(self, item): return False
+ class ColNoSize:
+ def __iter__(self): return iter([])
+ def __contains__(self, item): return False
+ class ColNoCont:
+ def __iter__(self): return iter([])
+ def __len__(self): return 0
+ self.assertFalse(issubclass(ColNoIter, Collection))
+ self.assertFalse(isinstance(ColNoIter(), Collection))
+ self.assertFalse(issubclass(ColNoSize, Collection))
+ self.assertFalse(isinstance(ColNoSize(), Collection))
+ self.assertFalse(issubclass(ColNoCont, Collection))
+ self.assertFalse(isinstance(ColNoCont(), Collection))
+ # Check None blocking
+ class SizeBlock:
+ def __iter__(self): return iter([])
+ def __contains__(self): return False
+ __len__ = None
+ class IterBlock:
+ def __len__(self): return 0
+ def __contains__(self): return True
+ __iter__ = None
+ self.assertFalse(issubclass(SizeBlock, Collection))
+ self.assertFalse(isinstance(SizeBlock(), Collection))
+ self.assertFalse(issubclass(IterBlock, Collection))
+ self.assertFalse(isinstance(IterBlock(), Collection))
+ # Check None blocking in subclass
+ class ColImpl:
+ def __iter__(self):
+ return iter(list())
+ def __len__(self):
+ return 0
+ def __contains__(self, item):
+ return False
+ class NonCol(ColImpl):
+ __contains__ = None
+ self.assertFalse(issubclass(NonCol, Collection))
+ self.assertFalse(isinstance(NonCol(), Collection))
+
def test_Iterator(self):
non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()]
@@ -699,7 +873,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
iter(set()), iter(frozenset()),
iter(dict().keys()), iter(dict().items()),
iter(dict().values()),
- (lambda: (yield))(),
+ _test_gen(),
(x for x in []),
]
for x in samples:
@@ -787,7 +961,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
def test_Sized(self):
non_samples = [None, 42, 3.14, 1j,
- (lambda: (yield))(),
+ _test_gen(),
(x for x in []),
]
for x in non_samples:
@@ -805,7 +979,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
def test_Container(self):
non_samples = [None, 42, 3.14, 1j,
- (lambda: (yield))(),
+ _test_gen(),
(x for x in []),
]
for x in non_samples:
@@ -824,7 +998,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
def test_Callable(self):
non_samples = [None, 42, 3.14, 1j,
"", b"", (), [], {}, set(),
- (lambda: (yield))(),
+ _test_gen(),
(x for x in []),
]
for x in non_samples:
@@ -842,14 +1016,14 @@ class TestOneTrickPonyABCs(ABCTestCase):
self.validate_isinstance(Callable, '__call__')
def test_direct_subclassing(self):
- for B in Hashable, Iterable, Iterator, Sized, Container, Callable:
+ for B in Hashable, Iterable, Iterator, Reversible, Sized, Container, Callable:
class C(B):
pass
self.assertTrue(issubclass(C, B))
self.assertFalse(issubclass(int, C))
def test_registration(self):
- for B in Hashable, Iterable, Iterator, Sized, Container, Callable:
+ for B in Hashable, Iterable, Iterator, Reversible, Sized, Container, Callable:
class C:
__hash__ = None # Make sure it isn't hashable by default
self.assertFalse(issubclass(C, B), B.__name__)
@@ -1049,6 +1223,26 @@ class TestCollectionABCs(ABCTestCase):
self.assertFalse(ncs > cs)
self.assertTrue(ncs >= cs)
+ def test_issue26915(self):
+ # Container membership test should check identity first
+ class CustomEqualObject:
+ def __eq__(self, other):
+ return False
+ class CustomSequence(list):
+ def __contains__(self, value):
+ return Sequence.__contains__(self, value)
+
+ nan = float('nan')
+ obj = CustomEqualObject()
+ containers = [
+ CustomSequence([nan, obj]),
+ ItemsView({1: nan, 2: obj}),
+ ValuesView({1: nan, 2: obj})
+ ]
+ for container in containers:
+ for elem in container:
+ self.assertIn(elem, container)
+
def assertSameSet(self, s1, s2):
# coerce both to a real set then check equality
self.assertSetEqual(set(s1), set(s2))
@@ -1219,6 +1413,7 @@ class TestCollectionABCs(ABCTestCase):
def __iter__(self):
return iter(())
self.validate_comparison(MyMapping())
+ self.assertRaises(TypeError, reversed, MyMapping())
def test_MutableMapping(self):
for sample in [dict]:
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 824e843..409ec86 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -473,10 +473,13 @@ if 1:
self.assertEqual(d, {1: 2, 3: 4})
def test_compile_filename(self):
- for filename in ('file.py', b'file.py',
- bytearray(b'file.py'), memoryview(b'file.py')):
+ for filename in 'file.py', b'file.py':
code = compile('pass', filename, 'exec')
self.assertEqual(code.co_filename, 'file.py')
+ for filename in bytearray(b'file.py'), memoryview(b'file.py'):
+ with self.assertWarns(DeprecationWarning):
+ code = compile('pass', filename, 'exec')
+ self.assertEqual(code.co_filename, 'file.py')
self.assertRaises(TypeError, compile, 'pass', list(b'file.py'), 'exec')
@support.cpython_only
@@ -661,6 +664,16 @@ if 1:
self.assertTrue(f1(0))
self.assertTrue(f2(0.0))
+ def test_path_like_objects(self):
+ # An implicit test for PyUnicode_FSDecoder().
+ class PathLike:
+ def __init__(self, path):
+ self._path = path
+ def __fspath__(self):
+ return self._path
+
+ compile("42", PathLike("test_compile_pathlike"), "single")
+
class TestStackSize(unittest.TestCase):
# These tests check that the computed stack size for a code object
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
index 2ce8a61..2356efc 100644
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -1,6 +1,7 @@
import sys
import compileall
import importlib.util
+import test.test_importlib.util
import os
import pathlib
import py_compile
@@ -40,6 +41,11 @@ class CompileallTests(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.directory)
+ def add_bad_source_file(self):
+ self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
+ with open(self.bad_source_path, 'w') as file:
+ file.write('x (\n')
+
def data(self):
with open(self.bc_path, 'rb') as file:
data = file.read(8)
@@ -78,15 +84,47 @@ class CompileallTests(unittest.TestCase):
os.unlink(fn)
except:
pass
- compileall.compile_file(self.source_path, force=False, quiet=True)
+ self.assertTrue(compileall.compile_file(self.source_path,
+ force=False, quiet=True))
self.assertTrue(os.path.isfile(self.bc_path) and
not os.path.isfile(self.bc_path2))
os.unlink(self.bc_path)
- compileall.compile_dir(self.directory, force=False, quiet=True)
+ self.assertTrue(compileall.compile_dir(self.directory, force=False,
+ quiet=True))
self.assertTrue(os.path.isfile(self.bc_path) and
os.path.isfile(self.bc_path2))
os.unlink(self.bc_path)
os.unlink(self.bc_path2)
+ # Test against bad files
+ self.add_bad_source_file()
+ self.assertFalse(compileall.compile_file(self.bad_source_path,
+ force=False, quiet=2))
+ self.assertFalse(compileall.compile_dir(self.directory,
+ force=False, quiet=2))
+
+ def test_compile_file_pathlike(self):
+ self.assertFalse(os.path.isfile(self.bc_path))
+ # we should also test the output
+ with support.captured_stdout() as stdout:
+ self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path)))
+ self.assertRegex(stdout.getvalue(), r'Compiling ([^WindowsPath|PosixPath].*)')
+ self.assertTrue(os.path.isfile(self.bc_path))
+
+ def test_compile_file_pathlike_ddir(self):
+ self.assertFalse(os.path.isfile(self.bc_path))
+ self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path),
+ ddir=pathlib.Path('ddir_path'),
+ quiet=2))
+ self.assertTrue(os.path.isfile(self.bc_path))
+
+ def test_compile_path(self):
+ with test.test_importlib.util.import_state(path=[self.directory]):
+ self.assertTrue(compileall.compile_path(quiet=2))
+
+ with test.test_importlib.util.import_state(path=[self.directory]):
+ self.add_bad_source_file()
+ self.assertFalse(compileall.compile_path(skip_curdir=False,
+ force=True, quiet=2))
def test_no_pycache_in_non_package(self):
# Bug 8563 reported that __pycache__ directories got created by
@@ -115,6 +153,14 @@ class CompileallTests(unittest.TestCase):
optimization=opt)
self.assertTrue(os.path.isfile(cached3))
+ def test_compile_dir_pathlike(self):
+ self.assertFalse(os.path.isfile(self.bc_path))
+ with support.captured_stdout() as stdout:
+ compileall.compile_dir(pathlib.Path(self.directory))
+ line = stdout.getvalue().splitlines()[0]
+ self.assertRegex(line, r'Listing ([^WindowsPath|PosixPath].*)')
+ self.assertTrue(os.path.isfile(self.bc_path))
+
@mock.patch('compileall.ProcessPoolExecutor')
def test_compile_pool_called(self, pool_mock):
compileall.compile_dir(self.directory, quiet=True, workers=5)
@@ -197,10 +243,9 @@ class CommandLineTests(unittest.TestCase):
raise unittest.SkipTest('not all entries on sys.path are writable')
def _get_run_args(self, args):
- interp_args = ['-S']
- if sys.flags.optimize:
- interp_args.append({1 : '-O', 2 : '-OO'}[sys.flags.optimize])
- return interp_args + ['-m', 'compileall'] + list(args)
+ return [*support.optim_args_from_interpreter_flags(),
+ '-S', '-m', 'compileall',
+ *args]
def assertRunOK(self, *args, **env_vars):
rc, out, err = script_helper.assert_python_ok(
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 403ee3b..c249ca7 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -1,5 +1,7 @@
import unittest
from test import support
+from test.test_grammar import (VALID_UNDERSCORE_LITERALS,
+ INVALID_UNDERSCORE_LITERALS)
from random import random
from math import atan2, isnan, copysign
@@ -385,6 +387,18 @@ class ComplexTest(unittest.TestCase):
self.assertAlmostEqual(complex(complex1(1j)), 2j)
self.assertRaises(TypeError, complex, complex2(1j))
+ def test_underscores(self):
+ # check underscores
+ for lit in VALID_UNDERSCORE_LITERALS:
+ if not any(ch in lit for ch in 'xXoObB'):
+ self.assertEqual(complex(lit), eval(lit))
+ self.assertEqual(complex(lit), complex(lit.replace('_', '')))
+ for lit in INVALID_UNDERSCORE_LITERALS:
+ if lit in ('0_7', '09_99'): # octals are not recognized here
+ continue
+ if not any(ch in lit for ch in 'xXoObB'):
+ self.assertRaises(ValueError, complex, lit)
+
def test_hash(self):
for x in range(-30, 30):
self.assertEqual(hash(x), hash(complex(x, 0)))
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py
index 7513815..23e95b2 100644
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -154,6 +154,30 @@ class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, unittest.Tes
for t in threads:
t.join()
+ def test_thread_names_assigned(self):
+ executor = futures.ThreadPoolExecutor(
+ max_workers=5, thread_name_prefix='SpecialPool')
+ executor.map(abs, range(-5, 5))
+ threads = executor._threads
+ del executor
+
+ for t in threads:
+ self.assertRegex(t.name, r'^SpecialPool_[0-4]$')
+ t.join()
+
+ def test_thread_names_default(self):
+ executor = futures.ThreadPoolExecutor(max_workers=5)
+ executor.map(abs, range(-5, 5))
+ threads = executor._threads
+ del executor
+
+ for t in threads:
+ # We don't particularly care what the default name is, just that
+ # it has a default name implying that it is a ThreadPoolExecutor
+ # followed by what looks like a thread number.
+ self.assertRegex(t.name, r'^.*ThreadPoolExecutor.*_[0-4]$')
+ t.join()
+
class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest, unittest.TestCase):
def _prime_executor(self):
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py
index 71a8f3f..2b08198 100644
--- a/Lib/test/test_configparser.py
+++ b/Lib/test/test_configparser.py
@@ -2052,5 +2052,11 @@ class BlatantOverrideConvertersTestCase(unittest.TestCase):
self.assertEqual(cfg['two'].getlen('one'), 5)
+class MiscTestCase(unittest.TestCase):
+ def test__all__(self):
+ blacklist = {"Error"}
+ support.check__all__(self, configparser, blacklist=blacklist)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/test/test_contains.py b/Lib/test/test_contains.py
index 3c6bdef..036a1d0 100644
--- a/Lib/test/test_contains.py
+++ b/Lib/test/test_contains.py
@@ -84,6 +84,31 @@ class TestContains(unittest.TestCase):
self.assertTrue(container == constructor(values))
self.assertTrue(container == container)
+ def test_block_fallback(self):
+ # blocking fallback with __contains__ = None
+ class ByContains(object):
+ def __contains__(self, other):
+ return False
+ c = ByContains()
+ class BlockContains(ByContains):
+ """Is not a container
+
+ This class is a perfectly good iterable (as tested by
+ list(bc)), as well as inheriting from a perfectly good
+ container, but __contains__ = None prevents the usual
+ fallback to iteration in the container protocol. That
+ is, normally, 0 in bc would fall back to the equivalent
+ of any(x==0 for x in bc), but here it's blocked from
+ doing so.
+ """
+ def __iter__(self):
+ while False:
+ yield None
+ __contains__ = None
+ bc = BlockContains()
+ self.assertFalse(0 in c)
+ self.assertFalse(0 in list(bc))
+ self.assertRaises(TypeError, lambda: 0 in bc)
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 516403e..c04c804 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -12,6 +12,39 @@ except ImportError:
threading = None
+class TestAbstractContextManager(unittest.TestCase):
+
+ def test_enter(self):
+ class DefaultEnter(AbstractContextManager):
+ def __exit__(self, *args):
+ super().__exit__(*args)
+
+ manager = DefaultEnter()
+ self.assertIs(manager.__enter__(), manager)
+
+ def test_exit_is_abstract(self):
+ class MissingExit(AbstractContextManager):
+ pass
+
+ with self.assertRaises(TypeError):
+ MissingExit()
+
+ def test_structural_subclassing(self):
+ class ManagerFromScratch:
+ def __enter__(self):
+ return self
+ def __exit__(self, exc_type, exc_value, traceback):
+ return None
+
+ self.assertTrue(issubclass(ManagerFromScratch, AbstractContextManager))
+
+ class DefaultEnter(AbstractContextManager):
+ def __exit__(self, *args):
+ super().__exit__(*args)
+
+ self.assertTrue(issubclass(DefaultEnter, AbstractContextManager))
+
+
class ContextManagerTestCase(unittest.TestCase):
def test_contextmanager_plain(self):
@@ -89,7 +122,7 @@ class ContextManagerTestCase(unittest.TestCase):
def woohoo():
yield
try:
- with self.assertWarnsRegex(PendingDeprecationWarning,
+ with self.assertWarnsRegex(DeprecationWarning,
"StopIteration"):
with woohoo():
raise stop_exc
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index 0e1f670..45a6920 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -98,7 +98,7 @@ class TestCopy(unittest.TestCase):
tests = [None, ..., NotImplemented,
42, 2**100, 3.14, True, False, 1j,
"hello", "hello\u1234", f.__code__,
- b"world", bytes(range(256)), range(10),
+ b"world", bytes(range(256)), range(10), slice(1, 10, 2),
NewStyle, Classic, max, WithMetaclass]
for x in tests:
self.assertIs(copy.copy(x), x)
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index e52654c..f2839a7 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -69,55 +69,130 @@ def silence_coro_gc():
class AsyncBadSyntaxTest(unittest.TestCase):
def test_badsyntax_1(self):
- with self.assertRaisesRegex(SyntaxError, "'await' outside"):
- import test.badsyntax_async1
+ samples = [
+ """def foo():
+ await something()
+ """,
- def test_badsyntax_2(self):
- with self.assertRaisesRegex(SyntaxError, "'await' outside"):
- import test.badsyntax_async2
+ """await something()""",
- def test_badsyntax_3(self):
- with self.assertRaisesRegex(SyntaxError, 'invalid syntax'):
- import test.badsyntax_async3
+ """async def foo():
+ yield from []
+ """,
- def test_badsyntax_4(self):
- with self.assertRaisesRegex(SyntaxError, 'invalid syntax'):
- import test.badsyntax_async4
+ """async def foo():
+ await await fut
+ """,
- def test_badsyntax_5(self):
- with self.assertRaisesRegex(SyntaxError, 'invalid syntax'):
- import test.badsyntax_async5
+ """async def foo(a=await something()):
+ pass
+ """,
- def test_badsyntax_6(self):
- with self.assertRaisesRegex(
- SyntaxError, "'yield' inside async function"):
+ """async def foo(a:await something()):
+ pass
+ """,
- import test.badsyntax_async6
+ """async def foo():
+ def bar():
+ [i async for i in els]
+ """,
- def test_badsyntax_7(self):
- with self.assertRaisesRegex(
- SyntaxError, "'yield from' inside async function"):
+ """async def foo():
+ def bar():
+ [await i for i in els]
+ """,
- import test.badsyntax_async7
+ """async def foo():
+ def bar():
+ [i for i in els
+ async for b in els]
+ """,
- def test_badsyntax_8(self):
- with self.assertRaisesRegex(SyntaxError, 'invalid syntax'):
- import test.badsyntax_async8
+ """async def foo():
+ def bar():
+ [i for i in els
+ for c in b
+ async for b in els]
+ """,
- def test_badsyntax_9(self):
- ns = {}
- for comp in {'(await a for a in b)',
- '[await a for a in b]',
- '{await a for a in b}',
- '{await a: c for a in b}'}:
+ """async def foo():
+ def bar():
+ [i for i in els
+ async for b in els
+ for c in b]
+ """,
- with self.assertRaisesRegex(SyntaxError, 'await.*in comprehen'):
- exec('async def f():\n\t{}'.format(comp), ns, ns)
+ """async def foo():
+ def bar():
+ [i for i in els
+ for b in await els]
+ """,
- def test_badsyntax_10(self):
- # Tests for issue 24619
+ """async def foo():
+ def bar():
+ [i for i in els
+ for b in els
+ if await b]
+ """,
+
+ """async def foo():
+ def bar():
+ [i for i in await els]
+ """,
+
+ """async def foo():
+ def bar():
+ [i for i in els if await i]
+ """,
+
+ """def bar():
+ [i async for i in els]
+ """,
+
+ """def bar():
+ [await i for i in els]
+ """,
+
+ """def bar():
+ [i for i in els
+ async for b in els]
+ """,
+
+ """def bar():
+ [i for i in els
+ for c in b
+ async for b in els]
+ """,
+
+ """def bar():
+ [i for i in els
+ async for b in els
+ for c in b]
+ """,
+
+ """def bar():
+ [i for i in els
+ for b in await els]
+ """,
+
+ """def bar():
+ [i for i in els
+ for b in els
+ if await b]
+ """,
+
+ """def bar():
+ [i for i in await els]
+ """,
+
+ """def bar():
+ [i for i in els if await i]
+ """,
+
+ """async def foo():
+ await
+ """,
- samples = [
"""async def foo():
def bar(): pass
await = 1
@@ -283,57 +358,110 @@ class AsyncBadSyntaxTest(unittest.TestCase):
with self.subTest(code=code), self.assertRaises(SyntaxError):
compile(code, "<test>", "exec")
- def test_goodsyntax_1(self):
- # Tests for issue 24619
+ def test_badsyntax_2(self):
+ samples = [
+ """def foo():
+ await = 1
+ """,
+
+ """class Bar:
+ def async(): pass
+ """,
- def foo(await):
- async def foo(): pass
- async def foo():
+ """class Bar:
+ async = 1
+ """,
+
+ """class async:
pass
- return await + 1
- self.assertEqual(foo(10), 11)
+ """,
- def foo(await):
- async def foo(): pass
- async def foo(): pass
- return await + 2
- self.assertEqual(foo(20), 22)
+ """class await:
+ pass
+ """,
- def foo(await):
+ """import math as await""",
- async def foo(): pass
+ """def async():
+ pass""",
- async def foo(): pass
+ """def foo(*, await=1):
+ pass"""
- return await + 2
- self.assertEqual(foo(20), 22)
+ """async = 1""",
- def foo(await):
- """spam"""
- async def foo(): \
- pass
- # 123
- async def foo(): pass
- # 456
- return await + 2
- self.assertEqual(foo(20), 22)
-
- def foo(await):
- def foo(): pass
- def foo(): pass
- async def bar(): return await_
- await_ = await
- try:
- bar().send(None)
- except StopIteration as ex:
- return ex.args[0]
- self.assertEqual(foo(42), 42)
+ """print(await=1)"""
+ ]
- async def f():
- async def g(): pass
- await z
- await = 1
- self.assertTrue(inspect.iscoroutinefunction(f))
+ for code in samples:
+ with self.subTest(code=code), self.assertWarnsRegex(
+ DeprecationWarning,
+ "'await' will become reserved keywords"):
+ compile(code, "<test>", "exec")
+
+ def test_badsyntax_3(self):
+ with self.assertRaises(DeprecationWarning):
+ with warnings.catch_warnings():
+ warnings.simplefilter("error")
+ compile("async = 1", "<test>", "exec")
+
+ def test_goodsyntax_1(self):
+ # Tests for issue 24619
+
+ samples = [
+ '''def foo(await):
+ async def foo(): pass
+ async def foo():
+ pass
+ return await + 1
+ ''',
+
+ '''def foo(await):
+ async def foo(): pass
+ async def foo(): pass
+ return await + 1
+ ''',
+
+ '''def foo(await):
+
+ async def foo(): pass
+
+ async def foo(): pass
+
+ return await + 1
+ ''',
+
+ '''def foo(await):
+ """spam"""
+ async def foo(): \
+ pass
+ # 123
+ async def foo(): pass
+ # 456
+ return await + 1
+ ''',
+
+ '''def foo(await):
+ def foo(): pass
+ def foo(): pass
+ async def bar(): return await_
+ await_ = await
+ try:
+ bar().send(None)
+ except StopIteration as ex:
+ return ex.args[0] + 1
+ '''
+ ]
+
+ for code in samples:
+ with self.subTest(code=code):
+ loc = {}
+
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ exec(code, loc, loc)
+
+ self.assertEqual(loc['foo'](10), 11)
class TokenizerRegrTest(unittest.TestCase):
@@ -891,7 +1019,7 @@ class CoroutineTest(unittest.TestCase):
return await Awaitable()
with self.assertRaisesRegex(
- TypeError, "__await__\(\) returned a coroutine"):
+ TypeError, r"__await__\(\) returned a coroutine"):
run_async(foo())
@@ -1333,7 +1461,7 @@ class CoroutineTest(unittest.TestCase):
with self.assertRaisesRegex(
TypeError,
- "async for' received an invalid object.*__aiter.*\: I"):
+ r"async for' received an invalid object.*__aiter.*\: I"):
run_async(foo())
@@ -1537,6 +1665,185 @@ class CoroutineTest(unittest.TestCase):
warnings.simplefilter("error")
run_async(foo())
+ def test_comp_1(self):
+ async def f(i):
+ return i
+
+ async def run_list():
+ return [await c for c in [f(1), f(41)]]
+
+ async def run_set():
+ return {await c for c in [f(1), f(41)]}
+
+ async def run_dict1():
+ return {await c: 'a' for c in [f(1), f(41)]}
+
+ async def run_dict2():
+ return {i: await c for i, c in enumerate([f(1), f(41)])}
+
+ self.assertEqual(run_async(run_list()), ([], [1, 41]))
+ self.assertEqual(run_async(run_set()), ([], {1, 41}))
+ self.assertEqual(run_async(run_dict1()), ([], {1: 'a', 41: 'a'}))
+ self.assertEqual(run_async(run_dict2()), ([], {0: 1, 1: 41}))
+
+ def test_comp_2(self):
+ async def f(i):
+ return i
+
+ async def run_list():
+ return [s for c in [f(''), f('abc'), f(''), f(['de', 'fg'])]
+ for s in await c]
+
+ self.assertEqual(
+ run_async(run_list()),
+ ([], ['a', 'b', 'c', 'de', 'fg']))
+
+ async def run_set():
+ return {d
+ for c in [f([f([10, 30]),
+ f([20])])]
+ for s in await c
+ for d in await s}
+
+ self.assertEqual(
+ run_async(run_set()),
+ ([], {10, 20, 30}))
+
+ async def run_set2():
+ return {await s
+ for c in [f([f(10), f(20)])]
+ for s in await c}
+
+ self.assertEqual(
+ run_async(run_set2()),
+ ([], {10, 20}))
+
+ def test_comp_3(self):
+ async def f(it):
+ for i in it:
+ yield i
+
+ async def run_list():
+ return [i + 1 async for i in f([10, 20])]
+ self.assertEqual(
+ run_async(run_list()),
+ ([], [11, 21]))
+
+ async def run_set():
+ return {i + 1 async for i in f([10, 20])}
+ self.assertEqual(
+ run_async(run_set()),
+ ([], {11, 21}))
+
+ async def run_dict():
+ return {i + 1: i + 2 async for i in f([10, 20])}
+ self.assertEqual(
+ run_async(run_dict()),
+ ([], {11: 12, 21: 22}))
+
+ async def run_gen():
+ gen = (i + 1 async for i in f([10, 20]))
+ return [g + 100 async for g in gen]
+ self.assertEqual(
+ run_async(run_gen()),
+ ([], [111, 121]))
+
+ def test_comp_4(self):
+ async def f(it):
+ for i in it:
+ yield i
+
+ async def run_list():
+ return [i + 1 async for i in f([10, 20]) if i > 10]
+ self.assertEqual(
+ run_async(run_list()),
+ ([], [21]))
+
+ async def run_set():
+ return {i + 1 async for i in f([10, 20]) if i > 10}
+ self.assertEqual(
+ run_async(run_set()),
+ ([], {21}))
+
+ async def run_dict():
+ return {i + 1: i + 2 async for i in f([10, 20]) if i > 10}
+ self.assertEqual(
+ run_async(run_dict()),
+ ([], {21: 22}))
+
+ async def run_gen():
+ gen = (i + 1 async for i in f([10, 20]) if i > 10)
+ return [g + 100 async for g in gen]
+ self.assertEqual(
+ run_async(run_gen()),
+ ([], [121]))
+
+ def test_comp_5(self):
+ async def f(it):
+ for i in it:
+ yield i
+
+ async def run_list():
+ return [i + 1 for pair in ([10, 20], [30, 40]) if pair[0] > 10
+ async for i in f(pair) if i > 30]
+ self.assertEqual(
+ run_async(run_list()),
+ ([], [41]))
+
+ def test_comp_6(self):
+ async def f(it):
+ for i in it:
+ yield i
+
+ async def run_list():
+ return [i + 1 async for seq in f([(10, 20), (30,)])
+ for i in seq]
+
+ self.assertEqual(
+ run_async(run_list()),
+ ([], [11, 21, 31]))
+
+ def test_comp_7(self):
+ async def f():
+ yield 1
+ yield 2
+ raise Exception('aaa')
+
+ async def run_list():
+ return [i async for i in f()]
+
+ with self.assertRaisesRegex(Exception, 'aaa'):
+ run_async(run_list())
+
+ def test_comp_8(self):
+ async def f():
+ return [i for i in [1, 2, 3]]
+
+ self.assertEqual(
+ run_async(f()),
+ ([], [1, 2, 3]))
+
+ def test_comp_9(self):
+ async def gen():
+ yield 1
+ yield 2
+ async def f():
+ l = [i async for i in gen()]
+ return [i for i in l]
+
+ self.assertEqual(
+ run_async(f()),
+ ([], [1, 2]))
+
+ def test_comp_10(self):
+ async def f():
+ xx = {i for i in [1, 2, 3]}
+ return {x: x for x in xx}
+
+ self.assertEqual(
+ run_async(f()),
+ ([], {1: 1, 2: 2, 3: 3}))
+
def test_copy(self):
async def func(): pass
coro = func()
@@ -1667,8 +1974,8 @@ class SysSetCoroWrapperTest(unittest.TestCase):
try:
with silence_coro_gc(), self.assertRaisesRegex(
RuntimeError,
- "coroutine wrapper.*\.wrapper at 0x.*attempted to "
- "recursively wrap .* wrap .*"):
+ r"coroutine wrapper.*\.wrapper at 0x.*attempted to "
+ r"recursively wrap .* wrap .*"):
foo()
finally:
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py
index f18983f..53f8917 100644
--- a/Lib/test/test_cprofile.py
+++ b/Lib/test/test_cprofile.py
@@ -6,7 +6,7 @@ from test.support import run_unittest, TESTFN, unlink
# rip off all interesting stuff from test_profile
import cProfile
from test.test_profile import ProfileTest, regenerate_expected_output
-from test.profilee import testfunc
+
class CProfileTest(ProfileTest):
profilerclass = cProfile.Profile
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index 77c315e..03ab184 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -2,9 +2,7 @@
# csv package unit tests
import copy
-import io
import sys
-import os
import unittest
from io import StringIO
from tempfile import TemporaryFile
@@ -12,6 +10,9 @@ import csv
import gc
import pickle
from test import support
+from itertools import permutations
+from textwrap import dedent
+from collections import OrderedDict
class Test_Csv(unittest.TestCase):
"""
@@ -426,17 +427,16 @@ class TestDialectRegistry(unittest.TestCase):
self.assertRaises(TypeError, csv.reader, [], quoting = -1)
self.assertRaises(TypeError, csv.reader, [], quoting = 100)
- # See issue #22995
- ## def test_copy(self):
- ## for name in csv.list_dialects():
- ## dialect = csv.get_dialect(name)
- ## self.assertRaises(TypeError, copy.copy, dialect)
+ def test_copy(self):
+ for name in csv.list_dialects():
+ dialect = csv.get_dialect(name)
+ self.assertRaises(TypeError, copy.copy, dialect)
- ## def test_pickle(self):
- ## for name in csv.list_dialects():
- ## dialect = csv.get_dialect(name)
- ## for proto in range(pickle.HIGHEST_PROTOCOL + 1):
- ## self.assertRaises(TypeError, pickle.dumps, dialect, proto)
+ def test_pickle(self):
+ for name in csv.list_dialects():
+ dialect = csv.get_dialect(name)
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ self.assertRaises(TypeError, pickle.dumps, dialect, proto)
class TestCsvBase(unittest.TestCase):
def readerAssertEqual(self, input, expected_result):
@@ -626,6 +626,24 @@ class TestDictFields(unittest.TestCase):
self.assertNotIn("'f2'", exception)
self.assertIn("1", exception)
+ def test_typo_in_extrasaction_raises_error(self):
+ fileobj = StringIO()
+ self.assertRaises(ValueError, csv.DictWriter, fileobj, ['f1', 'f2'],
+ extrasaction="raised")
+
+ def test_write_field_not_in_field_names_raise(self):
+ fileobj = StringIO()
+ writer = csv.DictWriter(fileobj, ['f1', 'f2'], extrasaction="raise")
+ dictrow = {'f0': 0, 'f1': 1, 'f2': 2, 'f3': 3}
+ self.assertRaises(ValueError, csv.DictWriter.writerow, writer, dictrow)
+
+ def test_write_field_not_in_field_names_ignore(self):
+ fileobj = StringIO()
+ writer = csv.DictWriter(fileobj, ['f1', 'f2'], extrasaction="ignore")
+ dictrow = {'f0': 0, 'f1': 1, 'f2': 2, 'f3': 3}
+ csv.DictWriter.writerow(writer, dictrow)
+ self.assertEqual(fileobj.getvalue(), "1,2\r\n")
+
def test_read_dict_fields(self):
with TemporaryFile("w+") as fileobj:
fileobj.write("1,2,abc\r\n")
@@ -1080,7 +1098,6 @@ class TestUnicode(unittest.TestCase):
"François Pinard"]
def test_unicode_read(self):
- import io
with TemporaryFile("w+", newline='', encoding="utf-8") as fileobj:
fileobj.write(",".join(self.names) + "\r\n")
fileobj.seek(0)
@@ -1089,7 +1106,6 @@ class TestUnicode(unittest.TestCase):
def test_unicode_write(self):
- import io
with TemporaryFile("w+", newline='', encoding="utf-8") as fileobj:
writer = csv.writer(fileobj)
writer.writerow(self.names)
@@ -1097,6 +1113,63 @@ class TestUnicode(unittest.TestCase):
fileobj.seek(0)
self.assertEqual(fileobj.read(), expected)
+class KeyOrderingTest(unittest.TestCase):
+
+ def test_ordering_for_the_dict_reader_and_writer(self):
+ resultset = set()
+ for keys in permutations("abcde"):
+ with TemporaryFile('w+', newline='', encoding="utf-8") as fileobject:
+ dw = csv.DictWriter(fileobject, keys)
+ dw.writeheader()
+ fileobject.seek(0)
+ dr = csv.DictReader(fileobject)
+ kt = tuple(dr.fieldnames)
+ self.assertEqual(keys, kt)
+ resultset.add(kt)
+ # Final sanity check: were all permutations unique?
+ self.assertEqual(len(resultset), 120, "Key ordering: some key permutations not collected (expected 120)")
+
+ def test_ordered_dict_reader(self):
+ data = dedent('''\
+ FirstName,LastName
+ Eric,Idle
+ Graham,Chapman,Over1,Over2
+
+ Under1
+ John,Cleese
+ ''').splitlines()
+
+ self.assertEqual(list(csv.DictReader(data)),
+ [OrderedDict([('FirstName', 'Eric'), ('LastName', 'Idle')]),
+ OrderedDict([('FirstName', 'Graham'), ('LastName', 'Chapman'),
+ (None, ['Over1', 'Over2'])]),
+ OrderedDict([('FirstName', 'Under1'), ('LastName', None)]),
+ OrderedDict([('FirstName', 'John'), ('LastName', 'Cleese')]),
+ ])
+
+ self.assertEqual(list(csv.DictReader(data, restkey='OtherInfo')),
+ [OrderedDict([('FirstName', 'Eric'), ('LastName', 'Idle')]),
+ OrderedDict([('FirstName', 'Graham'), ('LastName', 'Chapman'),
+ ('OtherInfo', ['Over1', 'Over2'])]),
+ OrderedDict([('FirstName', 'Under1'), ('LastName', None)]),
+ OrderedDict([('FirstName', 'John'), ('LastName', 'Cleese')]),
+ ])
+
+ del data[0] # Remove the header row
+ self.assertEqual(list(csv.DictReader(data, fieldnames=['fname', 'lname'])),
+ [OrderedDict([('fname', 'Eric'), ('lname', 'Idle')]),
+ OrderedDict([('fname', 'Graham'), ('lname', 'Chapman'),
+ (None, ['Over1', 'Over2'])]),
+ OrderedDict([('fname', 'Under1'), ('lname', None)]),
+ OrderedDict([('fname', 'John'), ('lname', 'Cleese')]),
+ ])
+
+
+class MiscTestCase(unittest.TestCase):
+ def test__all__(self):
+ extra = {'__doc__', '__version__'}
+ support.check__all__(self, csv, ('csv', '_csv'), extra=extra)
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 2d4eb52..242e1bb 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -23,9 +23,16 @@ test_suffixes = ["_Pure", "_Fast"]
test_classes = []
for module, suffix in zip(test_modules, test_suffixes):
+ test_classes = []
for name, cls in module.__dict__.items():
- if not (isinstance(cls, type) and issubclass(cls, unittest.TestCase)):
+ if not isinstance(cls, type):
continue
+ if issubclass(cls, unittest.TestCase):
+ test_classes.append(cls)
+ elif issubclass(cls, unittest.TestSuite):
+ suit = cls()
+ test_classes.extend(type(test) for test in suit)
+ for cls in test_classes:
cls.__name__ = name + suffix
@classmethod
def setUpClass(cls_, module=module):
@@ -39,7 +46,6 @@ for module, suffix in zip(test_modules, test_suffixes):
sys.modules.update(cls_._save_sys_modules)
cls.setUpClass = setUpClass
cls.tearDownClass = tearDownClass
- test_classes.append(cls)
def test_main():
run_unittest(*test_classes)
diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index 623d992..f0a428d 100644
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -1,6 +1,5 @@
"""Test script for the dbm.open function based on testdumbdbm.py"""
-import os
import unittest
import glob
import test.support
diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py
index ff63c88..2d77f07 100644
--- a/Lib/test/test_dbm_dumb.py
+++ b/Lib/test/test_dbm_dumb.py
@@ -6,6 +6,7 @@ import io
import operator
import os
import unittest
+import warnings
import dbm.dumb as dumbdbm
from test import support
from functools import partial
@@ -78,6 +79,12 @@ class DumbDBMTestCase(unittest.TestCase):
self.init_db()
f = dumbdbm.open(_fname, 'r')
self.read_helper(f)
+ with self.assertWarnsRegex(DeprecationWarning,
+ 'The database is opened for reading only'):
+ f[b'g'] = b'x'
+ with self.assertWarnsRegex(DeprecationWarning,
+ 'The database is opened for reading only'):
+ del f[b'a']
f.close()
def test_dumbdbm_keys(self):
@@ -148,7 +155,7 @@ class DumbDBMTestCase(unittest.TestCase):
self.assertEqual(self._dict[key], f[key])
def init_db(self):
- f = dumbdbm.open(_fname, 'w')
+ f = dumbdbm.open(_fname, 'n')
for k in self._dict:
f[k] = self._dict[k]
f.close()
@@ -234,6 +241,24 @@ class DumbDBMTestCase(unittest.TestCase):
pass
self.assertEqual(stdout.getvalue(), '')
+ def test_warn_on_ignored_flags(self):
+ for value in ('r', 'w'):
+ _delete_files()
+ with self.assertWarnsRegex(DeprecationWarning,
+ "The database file is missing, the "
+ "semantics of the 'c' flag will "
+ "be used."):
+ f = dumbdbm.open(_fname, value)
+ f.close()
+
+ def test_invalid_flag(self):
+ for flag in ('x', 'rf', None):
+ with self.assertWarnsRegex(DeprecationWarning,
+ "Flag must be one of "
+ "'r', 'w', 'c', or 'n'"):
+ f = dumbdbm.open(_fname, flag)
+ f.close()
+
def tearDown(self):
_delete_files()
diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py
index a7808f5..304b332 100644
--- a/Lib/test/test_dbm_gnu.py
+++ b/Lib/test/test_dbm_gnu.py
@@ -2,7 +2,7 @@ from test import support
gdbm = support.import_module("dbm.gnu") #skip if not supported
import unittest
import os
-from test.support import verbose, TESTFN, unlink
+from test.support import TESTFN, unlink
filename = TESTFN
diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py
index 2291561..49f4426 100644
--- a/Lib/test/test_dbm_ndbm.py
+++ b/Lib/test/test_dbm_ndbm.py
@@ -1,8 +1,6 @@
from test import support
support.import_module("dbm.ndbm") #skip if not supported
import unittest
-import os
-import random
import dbm.ndbm
from dbm.ndbm import error
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 1aa0bf8..617a37e 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -554,6 +554,10 @@ class ExplicitConstructionTest(unittest.TestCase):
self.assertEqual(str(Decimal(' -7.89')), '-7.89')
self.assertEqual(str(Decimal(" 3.45679 ")), '3.45679')
+ # underscores
+ self.assertEqual(str(Decimal('1_3.3e4_0')), '1.33E+41')
+ self.assertEqual(str(Decimal('1_0_0_0')), '1000')
+
# unicode whitespace
for lead in ["", ' ', '\u00a0', '\u205f']:
for trail in ["", ' ', '\u00a0', '\u205f']:
@@ -578,6 +582,9 @@ class ExplicitConstructionTest(unittest.TestCase):
# embedded NUL
self.assertRaises(InvalidOperation, Decimal, "12\u00003")
+ # underscores don't prevent errors
+ self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")
+
@cpython_only
def test_from_legacy_strings(self):
import _testcapi
@@ -772,6 +779,9 @@ class ExplicitConstructionTest(unittest.TestCase):
self.assertRaises(InvalidOperation, nc.create_decimal, "xyz")
self.assertRaises(ValueError, nc.create_decimal, (1, "xyz", -25))
self.assertRaises(TypeError, nc.create_decimal, "1234", "5678")
+ # no whitespace and underscore stripping is done with this method
+ self.assertRaises(InvalidOperation, nc.create_decimal, " 1234")
+ self.assertRaises(InvalidOperation, nc.create_decimal, "12_34")
# too many NaN payload digits
nc.prec = 3
@@ -2047,6 +2057,39 @@ class UsabilityTest(unittest.TestCase):
d = Decimal( (1, (0, 2, 7, 1), 'F') )
self.assertEqual(d.as_tuple(), (1, (0,), 'F'))
+ def test_as_integer_ratio(self):
+ Decimal = self.decimal.Decimal
+
+ # exceptional cases
+ self.assertRaises(OverflowError,
+ Decimal.as_integer_ratio, Decimal('inf'))
+ self.assertRaises(OverflowError,
+ Decimal.as_integer_ratio, Decimal('-inf'))
+ self.assertRaises(ValueError,
+ Decimal.as_integer_ratio, Decimal('-nan'))
+ self.assertRaises(ValueError,
+ Decimal.as_integer_ratio, Decimal('snan123'))
+
+ for exp in range(-4, 2):
+ for coeff in range(1000):
+ for sign in '+', '-':
+ d = Decimal('%s%dE%d' % (sign, coeff, exp))
+ pq = d.as_integer_ratio()
+ p, q = pq
+
+ # check return type
+ self.assertIsInstance(pq, tuple)
+ self.assertIsInstance(p, int)
+ self.assertIsInstance(q, int)
+
+ # check normalization: q should be positive;
+ # p should be relatively prime to q.
+ self.assertGreater(q, 0)
+ self.assertEqual(math.gcd(p, q), 1)
+
+ # check that p/q actually gives the correct value
+ self.assertEqual(Decimal(p) / Decimal(q), d)
+
def test_subclassing(self):
# Different behaviours when subclassing Decimal
Decimal = self.decimal.Decimal
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 18e1df0..ce517b5 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -289,7 +289,7 @@ class TestBasic(unittest.TestCase):
else:
self.assertEqual(d.index(element, start, stop), target)
- def test_insert_bug_24913(self):
+ def test_index_bug_24913(self):
d = deque('A' * 3)
with self.assertRaises(ValueError):
i = d.index("Hello world", 0, 4)
@@ -622,20 +622,22 @@ class TestBasic(unittest.TestCase):
self.assertEqual(list(d), list(e))
def test_pickle(self):
- d = deque(range(200))
- for i in range(pickle.HIGHEST_PROTOCOL + 1):
- s = pickle.dumps(d, i)
- e = pickle.loads(s)
- self.assertNotEqual(id(d), id(e))
- self.assertEqual(list(d), list(e))
-
-## def test_pickle_recursive(self):
-## d = deque('abc')
-## d.append(d)
-## for i in range(pickle.HIGHEST_PROTOCOL + 1):
-## e = pickle.loads(pickle.dumps(d, i))
-## self.assertNotEqual(id(d), id(e))
-## self.assertEqual(id(e), id(e[-1]))
+ for d in deque(range(200)), deque(range(200), 100):
+ for i in range(pickle.HIGHEST_PROTOCOL + 1):
+ s = pickle.dumps(d, i)
+ e = pickle.loads(s)
+ self.assertNotEqual(id(e), id(d))
+ self.assertEqual(list(e), list(d))
+ self.assertEqual(e.maxlen, d.maxlen)
+
+ def test_pickle_recursive(self):
+ for d in deque('abc'), deque('abc', 3):
+ d.append(d)
+ for i in range(pickle.HIGHEST_PROTOCOL + 1):
+ e = pickle.loads(pickle.dumps(d, i))
+ self.assertNotEqual(id(e), id(d))
+ self.assertEqual(id(e[-1]), id(e))
+ self.assertEqual(e.maxlen, d.maxlen)
def test_iterator_pickle(self):
orig = deque(range(200))
@@ -696,6 +698,15 @@ class TestBasic(unittest.TestCase):
self.assertNotEqual(id(d), id(e))
self.assertEqual(list(d), list(e))
+ for i in range(5):
+ for maxlen in range(-1, 6):
+ s = [random.random() for j in range(i)]
+ d = deque(s) if maxlen == -1 else deque(s, maxlen)
+ e = d.copy()
+ self.assertEqual(d, e)
+ self.assertEqual(d.maxlen, e.maxlen)
+ self.assertTrue(all(x is y for x, y in zip(d, e)))
+
def test_copy_method(self):
mut = [10]
d = deque([mut])
@@ -845,24 +856,26 @@ class TestSubclass(unittest.TestCase):
self.assertEqual(type(d), type(e))
self.assertEqual(list(d), list(e))
-## def test_pickle(self):
-## d = Deque('abc')
-## d.append(d)
-##
-## e = pickle.loads(pickle.dumps(d))
-## self.assertNotEqual(id(d), id(e))
-## self.assertEqual(type(d), type(e))
-## dd = d.pop()
-## ee = e.pop()
-## self.assertEqual(id(e), id(ee))
-## self.assertEqual(d, e)
-##
-## d.x = d
-## e = pickle.loads(pickle.dumps(d))
-## self.assertEqual(id(e), id(e.x))
-##
-## d = DequeWithBadIter('abc')
-## self.assertRaises(TypeError, pickle.dumps, d)
+ def test_pickle_recursive(self):
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ for d in Deque('abc'), Deque('abc', 3):
+ d.append(d)
+
+ e = pickle.loads(pickle.dumps(d, proto))
+ self.assertNotEqual(id(e), id(d))
+ self.assertEqual(type(e), type(d))
+ self.assertEqual(e.maxlen, d.maxlen)
+ dd = d.pop()
+ ee = e.pop()
+ self.assertEqual(id(ee), id(e))
+ self.assertEqual(e, d)
+
+ d.x = d
+ e = pickle.loads(pickle.dumps(d, proto))
+ self.assertEqual(id(e.x), id(e))
+
+ for d in DequeWithBadIter('abc'), DequeWithBadIter('abc', 2):
+ self.assertRaises(TypeError, pickle.dumps, d, proto)
def test_weakref(self):
d = deque('gallahad')
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 418f8d2..1e08ed9 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4738,11 +4738,8 @@ class PicklingTests(unittest.TestCase):
return (args, kwargs)
obj = C3()
for proto in protocols:
- if proto >= 4:
+ if proto >= 2:
self._check_reduce(proto, obj, args, kwargs)
- elif proto >= 2:
- with self.assertRaises(ValueError):
- obj.__reduce_ex__(proto)
class C4:
def __getnewargs_ex__(self):
@@ -5061,10 +5058,6 @@ class PicklingTests(unittest.TestCase):
kwargs = getattr(cls, 'KWARGS', {})
obj = cls(*cls.ARGS, **kwargs)
proto = pickle_copier.proto
- if 2 <= proto < 4 and hasattr(cls, '__getnewargs_ex__'):
- with self.assertRaises(ValueError):
- pickle_copier.dumps(obj, proto)
- continue
objcopy = pickle_copier.copy(obj)
self._assert_is_copy(obj, objcopy)
# For test classes that supports this, make sure we didn't go
@@ -5123,12 +5116,14 @@ class SharedKeyTests(unittest.TestCase):
a, b = A(), B()
self.assertEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(b)))
self.assertLess(sys.getsizeof(vars(a)), sys.getsizeof({}))
- a.x, a.y, a.z, a.w = range(4)
+ # Initial hash table can contain at most 5 elements.
+ # Set 6 attributes to cause internal resizing.
+ a.x, a.y, a.z, a.w, a.v, a.u = range(6)
self.assertNotEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(b)))
a2 = A()
self.assertEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(a2)))
self.assertLess(sys.getsizeof(vars(a)), sys.getsizeof({}))
- b.u, b.v, b.w, b.t = range(4)
+ b.u, b.v, b.w, b.t, b.s, b.r = range(6)
self.assertLess(sys.getsizeof(vars(b)), sys.getsizeof({}))
diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py
index 506d1ab..b84d644 100644
--- a/Lib/test/test_descrtut.py
+++ b/Lib/test/test_descrtut.py
@@ -182,6 +182,7 @@ You can get the information from the list type:
'__iadd__',
'__imul__',
'__init__',
+ '__init_subclass__',
'__iter__',
'__le__',
'__len__',
diff --git a/Lib/test/test_devpoll.py b/Lib/test/test_devpoll.py
index 955618a..c133c81 100644
--- a/Lib/test/test_devpoll.py
+++ b/Lib/test/test_devpoll.py
@@ -5,9 +5,8 @@
import os
import random
import select
-import sys
import unittest
-from test.support import TESTFN, run_unittest, cpython_only
+from test.support import run_unittest, cpython_only
if not hasattr(select, 'devpoll') :
raise unittest.SkipTest('test works only on Solaris OS family')
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 6d68e76..ed66ddb 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py