From python-checkins at python.org Wed Jan 1 02:52:09 2014 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 1 Jan 2014 02:52:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzIwMDU1?= =?utf-8?q?=3A_Fix_test=5Fshutil_under_Windows_with_symlink_privileges_hel?= =?utf-8?q?d=2E?= Message-ID: <3dvFk11T2Cz7Ll5@mail.python.org> http://hg.python.org/cpython/rev/0f888589dbcd changeset: 88239:0f888589dbcd branch: 3.3 parent: 88237:9c88280245e0 user: Antoine Pitrou date: Wed Jan 01 02:50:45 2014 +0100 summary: Issue #20055: Fix test_shutil under Windows with symlink privileges held. Patch by Vajrasky Kok. files: Lib/test/test_shutil.py | 32 +++++++++++++++++----------- Misc/NEWS | 3 ++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -287,18 +287,20 @@ self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode) shutil.copymode(src, dst) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) - # follow src link - os.chmod(dst, stat.S_IRWXO) - shutil.copymode(src_link, dst) - self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) - # follow dst link - os.chmod(dst, stat.S_IRWXO) - shutil.copymode(src, dst_link) - self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) - # follow both links - os.chmod(dst, stat.S_IRWXO) - shutil.copymode(src_link, dst) - self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) + # On Windows, os.chmod does not follow symlinks (issue #15411) + if os.name != 'nt': + # follow src link + os.chmod(dst, stat.S_IRWXO) + shutil.copymode(src_link, dst) + self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) + # follow dst link + os.chmod(dst, stat.S_IRWXO) + shutil.copymode(src, dst_link) + self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) + # follow both links + os.chmod(dst, stat.S_IRWXO) + shutil.copymode(src_link, dst_link) + self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) @unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod') @support.skip_unless_symlink @@ -1543,7 +1545,11 @@ dst_link = os.path.join(self.dst_dir, 'quux') shutil.move(dst, dst_link) self.assertTrue(os.path.islink(dst_link)) - self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link)) + # On Windows, os.path.realpath does not follow symlinks (issue #9949) + if os.name == 'nt': + self.assertEqual(os.path.realpath(src), os.readlink(dst_link)) + else: + self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link)) @support.skip_unless_symlink @mock_rename diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -197,6 +197,9 @@ Tests ----- +- Issue #20055: Fix test_shutil under Windows with symlink privileges held. + Patch by Vajrasky Kok. + - Issue #19938: Re-enabled test_bug_1333982 in test_dis, which had been disabled since 3.0 due to the changes in listcomp handling. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Jan 1 02:52:11 2014 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 1 Jan 2014 02:52:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2320055=3A_Fix_test=5Fshutil_under_Windows_with_s?= =?utf-8?q?ymlink_privileges_held=2E?= Message-ID: <3dvFk31J1tz7Lpw@mail.python.org> http://hg.python.org/cpython/rev/6fd3d473e1c2 changeset: 88240:6fd3d473e1c2 parent: 88238:b5f85b093252 parent: 88239:0f888589dbcd user: Antoine Pitrou date: Wed Jan 01 02:51:58 2014 +0100 summary: Issue #20055: Fix test_shutil under Windows with symlink privileges held. Patch by Vajrasky Kok. files: Lib/test/test_shutil.py | 32 +++++++++++++++++----------- Misc/NEWS | 3 ++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -288,18 +288,20 @@ self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode) shutil.copymode(src, dst) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) - # follow src link - os.chmod(dst, stat.S_IRWXO) - shutil.copymode(src_link, dst) - self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) - # follow dst link - os.chmod(dst, stat.S_IRWXO) - shutil.copymode(src, dst_link) - self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) - # follow both links - os.chmod(dst, stat.S_IRWXO) - shutil.copymode(src_link, dst) - self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) + # On Windows, os.chmod does not follow symlinks (issue #15411) + if os.name != 'nt': + # follow src link + os.chmod(dst, stat.S_IRWXO) + shutil.copymode(src_link, dst) + self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) + # follow dst link + os.chmod(dst, stat.S_IRWXO) + shutil.copymode(src, dst_link) + self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) + # follow both links + os.chmod(dst, stat.S_IRWXO) + shutil.copymode(src_link, dst_link) + self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) @unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod') @support.skip_unless_symlink @@ -1554,7 +1556,11 @@ dst_link = os.path.join(self.dst_dir, 'quux') shutil.move(dst, dst_link) self.assertTrue(os.path.islink(dst_link)) - self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link)) + # On Windows, os.path.realpath does not follow symlinks (issue #9949) + if os.name == 'nt': + self.assertEqual(os.path.realpath(src), os.readlink(dst_link)) + else: + self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link)) @support.skip_unless_symlink @mock_rename diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -267,6 +267,9 @@ Tests ----- +- Issue #20055: Fix test_shutil under Windows with symlink privileges held. + Patch by Vajrasky Kok. + - Issue #20070: Don't run test_urllib2net when network resources are not enabled. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Jan 1 05:02:54 2014 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 1 Jan 2014 05:02:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_update_copyrig?= =?utf-8?q?ht_year?= Message-ID: <3dvJct4vCGz7LjS@mail.python.org> http://hg.python.org/cpython/rev/8c276f37ba42 changeset: 88241:8c276f37ba42 branch: 3.3 parent: 88239:0f888589dbcd user: Benjamin Peterson date: Tue Dec 31 22:02:22 2013 -0600 summary: update copyright year files: Doc/README.txt | 2 +- Doc/copyright.rst | 2 +- Doc/license.rst | 2 +- LICENSE | 2 +- PC/python_nt.rc | 2 +- Python/getcopyright.c | 2 +- README | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/README.txt b/Doc/README.txt --- a/Doc/README.txt +++ b/Doc/README.txt @@ -135,7 +135,7 @@ as long as you don't change or remove the copyright notice: ---------------------------------------------------------------------- -Copyright (c) 2000-2013 Python Software Foundation. +Copyright (c) 2000-2014 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. diff --git a/Doc/copyright.rst b/Doc/copyright.rst --- a/Doc/copyright.rst +++ b/Doc/copyright.rst @@ -4,7 +4,7 @@ Python and this documentation is: -Copyright ?? 2001-2013 Python Software Foundation. All rights reserved. +Copyright ?? 2001-2014 Python Software Foundation. All rights reserved. Copyright ?? 2000 BeOpen.com. All rights reserved. diff --git a/Doc/license.rst b/Doc/license.rst --- a/Doc/license.rst +++ b/Doc/license.rst @@ -84,7 +84,7 @@ analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python |release| alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of - copyright, i.e., "Copyright ?? 2001-2013 Python Software Foundation; All Rights + copyright, i.e., "Copyright ?? 2001-2014 Python Software Foundation; All Rights Reserved" are retained in Python |release| alone or in any derivative version prepared by Licensee. diff --git a/LICENSE b/LICENSE --- a/LICENSE +++ b/LICENSE @@ -74,7 +74,7 @@ distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -2011, 2012, 2013 Python Software Foundation; All Rights Reserved" are retained +2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are retained in Python alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on diff --git a/PC/python_nt.rc b/PC/python_nt.rc --- a/PC/python_nt.rc +++ b/PC/python_nt.rc @@ -61,7 +61,7 @@ VALUE "FileDescription", "Python Core\0" VALUE "FileVersion", PYTHON_VERSION VALUE "InternalName", "Python DLL\0" - VALUE "LegalCopyright", "Copyright ? 2001-2013 Python Software Foundation. Copyright ? 2000 BeOpen.com. Copyright ? 1995-2001 CNRI. Copyright ? 1991-1995 SMC.\0" + VALUE "LegalCopyright", "Copyright ? 2001-2014 Python Software Foundation. Copyright ? 2000 BeOpen.com. Copyright ? 1995-2001 CNRI. Copyright ? 1991-1995 SMC.\0" VALUE "OriginalFilename", PYTHON_DLL_NAME "\0" VALUE "ProductName", "Python\0" VALUE "ProductVersion", PYTHON_VERSION diff --git a/Python/getcopyright.c b/Python/getcopyright.c --- a/Python/getcopyright.c +++ b/Python/getcopyright.c @@ -4,7 +4,7 @@ static const char cprt[] = "\ -Copyright (c) 2001-2013 Python Software Foundation.\n\ +Copyright (c) 2001-2014 Python Software Foundation.\n\ All Rights Reserved.\n\ \n\ Copyright (c) 2000 BeOpen.com.\n\ diff --git a/README b/README --- a/README +++ b/README @@ -2,7 +2,7 @@ ============================ Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Python Software Foundation. All rights reserved. +2012, 2013, 2014 Python Software Foundation. All rights reserved. Python 3.x is a new version of the language, which is incompatible with the 2.x line of releases. The language is mostly the same, but many details, especially @@ -175,7 +175,7 @@ --------------------------------- Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Python Software Foundation. All rights reserved. +2012, 2013, 2014 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. All rights reserved. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Jan 1 05:02:56 2014 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 1 Jan 2014 05:02:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4z?= Message-ID: <3dvJcw12T9z7Lkg@mail.python.org> http://hg.python.org/cpython/rev/14133d998493 changeset: 88242:14133d998493 parent: 88240:6fd3d473e1c2 parent: 88241:8c276f37ba42 user: Benjamin Peterson date: Tue Dec 31 22:02:41 2013 -0600 summary: merge 3.3 files: Doc/README.txt | 2 +- Doc/copyright.rst | 2 +- Doc/license.rst | 2 +- LICENSE | 2 +- PC/python_nt.rc | 2 +- Python/getcopyright.c | 2 +- README | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/README.txt b/Doc/README.txt --- a/Doc/README.txt +++ b/Doc/README.txt @@ -136,7 +136,7 @@ as long as you don't change or remove the copyright notice: ---------------------------------------------------------------------- -Copyright (c) 2000-2013 Python Software Foundation. +Copyright (c) 2000-2014 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. diff --git a/Doc/copyright.rst b/Doc/copyright.rst --- a/Doc/copyright.rst +++ b/Doc/copyright.rst @@ -4,7 +4,7 @@ Python and this documentation is: -Copyright ?? 2001-2013 Python Software Foundation. All rights reserved. +Copyright ?? 2001-2014 Python Software Foundation. All rights reserved. Copyright ?? 2000 BeOpen.com. All rights reserved. diff --git a/Doc/license.rst b/Doc/license.rst --- a/Doc/license.rst +++ b/Doc/license.rst @@ -84,7 +84,7 @@ analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python |release| alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of - copyright, i.e., "Copyright ?? 2001-2013 Python Software Foundation; All Rights + copyright, i.e., "Copyright ?? 2001-2014 Python Software Foundation; All Rights Reserved" are retained in Python |release| alone or in any derivative version prepared by Licensee. diff --git a/LICENSE b/LICENSE --- a/LICENSE +++ b/LICENSE @@ -74,7 +74,7 @@ distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -2011, 2012, 2013 Python Software Foundation; All Rights Reserved" are retained +2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are retained in Python alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on diff --git a/PC/python_nt.rc b/PC/python_nt.rc --- a/PC/python_nt.rc +++ b/PC/python_nt.rc @@ -61,7 +61,7 @@ VALUE "FileDescription", "Python Core\0" VALUE "FileVersion", PYTHON_VERSION VALUE "InternalName", "Python DLL\0" - VALUE "LegalCopyright", "Copyright ? 2001-2013 Python Software Foundation. Copyright ? 2000 BeOpen.com. Copyright ? 1995-2001 CNRI. Copyright ? 1991-1995 SMC.\0" + VALUE "LegalCopyright", "Copyright ? 2001-2014 Python Software Foundation. Copyright ? 2000 BeOpen.com. Copyright ? 1995-2001 CNRI. Copyright ? 1991-1995 SMC.\0" VALUE "OriginalFilename", PYTHON_DLL_NAME "\0" VALUE "ProductName", "Python\0" VALUE "ProductVersion", PYTHON_VERSION diff --git a/Python/getcopyright.c b/Python/getcopyright.c --- a/Python/getcopyright.c +++ b/Python/getcopyright.c @@ -4,7 +4,7 @@ static const char cprt[] = "\ -Copyright (c) 2001-2013 Python Software Foundation.\n\ +Copyright (c) 2001-2014 Python Software Foundation.\n\ All Rights Reserved.\n\ \n\ Copyright (c) 2000 BeOpen.com.\n\ diff --git a/README b/README --- a/README +++ b/README @@ -2,7 +2,7 @@ =================================== Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Python Software Foundation. All rights reserved. +2012, 2013, 2014 Python Software Foundation. All rights reserved. Python 3.x is a new version of the language, which is incompatible with the 2.x line of releases. The language is mostly the same, but many details, especially @@ -175,7 +175,7 @@ --------------------------------- Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Python Software Foundation. All rights reserved. +2012, 2013, 2014 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. All rights reserved. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Jan 1 05:05:18 2014 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 1 Jan 2014 05:05:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_update_copyrig?= =?utf-8?q?ht_year?= Message-ID: <3dvJgf3MFdz7LjW@mail.python.org> http://hg.python.org/cpython/rev/72f323e8988b changeset: 88243:72f323e8988b branch: 2.7 parent: 88215:990d7647ea51 user: Benjamin Peterson date: Tue Dec 31 22:02:22 2013 -0600 summary: update copyright year files: Doc/README.txt | 2 +- Doc/copyright.rst | 2 +- Doc/license.rst | 2 +- LICENSE | 2 +- PC/python_nt.rc | 2 +- Python/getcopyright.c | 2 +- README | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/README.txt b/Doc/README.txt --- a/Doc/README.txt +++ b/Doc/README.txt @@ -127,7 +127,7 @@ as long as you don't change or remove the copyright notice: ---------------------------------------------------------------------- -Copyright (c) 2000-2013 Python Software Foundation. +Copyright (c) 2000-2014 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. diff --git a/Doc/copyright.rst b/Doc/copyright.rst --- a/Doc/copyright.rst +++ b/Doc/copyright.rst @@ -4,7 +4,7 @@ Python and this documentation is: -Copyright ?? 2001-2013 Python Software Foundation. All rights reserved. +Copyright ?? 2001-2014 Python Software Foundation. All rights reserved. Copyright ?? 2000 BeOpen.com. All rights reserved. diff --git a/Doc/license.rst b/Doc/license.rst --- a/Doc/license.rst +++ b/Doc/license.rst @@ -84,7 +84,7 @@ analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python |release| alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of - copyright, i.e., "Copyright ?? 2001-2013 Python Software Foundation; All Rights + copyright, i.e., "Copyright ?? 2001-2014 Python Software Foundation; All Rights Reserved" are retained in Python |release| alone or in any derivative version prepared by Licensee. diff --git a/LICENSE b/LICENSE --- a/LICENSE +++ b/LICENSE @@ -74,7 +74,7 @@ distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -2011, 2012, 2013 Python Software Foundation; All Rights Reserved" are retained +2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are retained in Python alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on diff --git a/PC/python_nt.rc b/PC/python_nt.rc --- a/PC/python_nt.rc +++ b/PC/python_nt.rc @@ -61,7 +61,7 @@ VALUE "FileDescription", "Python Core\0" VALUE "FileVersion", PYTHON_VERSION VALUE "InternalName", "Python DLL\0" - VALUE "LegalCopyright", "Copyright ? 2001-2008 Python Software Foundation. Copyright ? 2000 BeOpen.com. Copyright ? 1995-2001 CNRI. Copyright ? 1991-1995 SMC.\0" + VALUE "LegalCopyright", "Copyright ? 2001-2014 Python Software Foundation. Copyright ? 2000 BeOpen.com. Copyright ? 1995-2001 CNRI. Copyright ? 1991-1995 SMC.\0" VALUE "OriginalFilename", PYTHON_DLL_NAME "\0" VALUE "ProductName", "Python\0" VALUE "ProductVersion", PYTHON_VERSION diff --git a/Python/getcopyright.c b/Python/getcopyright.c --- a/Python/getcopyright.c +++ b/Python/getcopyright.c @@ -4,7 +4,7 @@ static char cprt[] = "\ -Copyright (c) 2001-2013 Python Software Foundation.\n\ +Copyright (c) 2001-2014 Python Software Foundation.\n\ All Rights Reserved.\n\ \n\ Copyright (c) 2000 BeOpen.com.\n\ diff --git a/README b/README --- a/README +++ b/README @@ -2,7 +2,7 @@ ============================ Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Python Software Foundation. All rights reserved. +2012, 2013, 2014 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. All rights reserved. -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Jan 1 09:46:11 2014 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 01 Jan 2014 09:46:11 +0100 Subject: [Python-checkins] Daily reference leaks (6fd3d473e1c2): sum=0 Message-ID: results for 6fd3d473e1c2 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog_CdVl_', '-x'] From python-checkins at python.org Wed Jan 1 22:06:29 2014 From: python-checkins at python.org (ned.deily) Date: Wed, 1 Jan 2014 22:06:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Update_copyrig?= =?utf-8?q?ht_dates_in_Mac_plists=2E?= Message-ID: <3dvlKx6cKjz7LjW@mail.python.org> http://hg.python.org/cpython/rev/aeb70f2f6f38 changeset: 88244:aeb70f2f6f38 branch: 2.7 user: Ned Deily date: Wed Jan 01 13:03:24 2014 -0800 summary: Update copyright dates in Mac plists. files: Mac/IDLE/Info.plist.in | 2 +- Mac/PythonLauncher/Info.plist.in | 2 +- Mac/Resources/app/Info.plist.in | 6 +++--- Mac/Resources/framework/Info.plist.in | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Mac/IDLE/Info.plist.in b/Mac/IDLE/Info.plist.in --- a/Mac/IDLE/Info.plist.in +++ b/Mac/IDLE/Info.plist.in @@ -36,7 +36,7 @@ CFBundleExecutable IDLE CFBundleGetInfoString - %VERSION%, ? 2001-2013 Python Software Foundation + %VERSION%, ? 2001-2014 Python Software Foundation CFBundleIconFile IDLE.icns CFBundleIdentifier diff --git a/Mac/PythonLauncher/Info.plist.in b/Mac/PythonLauncher/Info.plist.in --- a/Mac/PythonLauncher/Info.plist.in +++ b/Mac/PythonLauncher/Info.plist.in @@ -40,7 +40,7 @@ CFBundleExecutable PythonLauncher CFBundleGetInfoString - %VERSION%, ? 2001-2013 Python Software Foundation + %VERSION%, ? 2001-2014 Python Software Foundation CFBundleIconFile PythonLauncher.icns CFBundleIdentifier diff --git a/Mac/Resources/app/Info.plist.in b/Mac/Resources/app/Info.plist.in --- a/Mac/Resources/app/Info.plist.in +++ b/Mac/Resources/app/Info.plist.in @@ -20,7 +20,7 @@ CFBundleExecutable Python CFBundleGetInfoString - %version%, (c) 2004-2013 Python Software Foundation. + %version%, (c) 2004-2014 Python Software Foundation. CFBundleHelpBookFolder Documentation @@ -37,7 +37,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleLongVersionString - %version%, (c) 2004-2013 Python Software Foundation. + %version%, (c) 2004-2014 Python Software Foundation. CFBundleName Python CFBundlePackageType @@ -55,7 +55,7 @@ NSAppleScriptEnabled NSHumanReadableCopyright - (c) 2013 Python Software Foundation. + (c) 2014 Python Software Foundation. NSHighResolutionCapable diff --git a/Mac/Resources/framework/Info.plist.in b/Mac/Resources/framework/Info.plist.in --- a/Mac/Resources/framework/Info.plist.in +++ b/Mac/Resources/framework/Info.plist.in @@ -17,9 +17,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - %VERSION%, (c) 2004-2013 Python Software Foundation. + %VERSION%, (c) 2004-2014 Python Software Foundation. CFBundleLongVersionString - %VERSION%, (c) 2004-2013 Python Software Foundation. + %VERSION%, (c) 2004-2014 Python Software Foundation. CFBundleSignature ???? CFBundleVersion -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Jan 1 22:06:31 2014 From: python-checkins at python.org (ned.deily) Date: Wed, 1 Jan 2014 22:06:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Update_copyrig?= =?utf-8?q?ht_dates_in_Mac_plists=2E?= Message-ID: <3dvlKz10Y3z7LjW@mail.python.org> http://hg.python.org/cpython/rev/6a1a1cf5a01b changeset: 88245:6a1a1cf5a01b branch: 3.3 parent: 88241:8c276f37ba42 user: Ned Deily date: Wed Jan 01 13:05:03 2014 -0800 summary: Update copyright dates in Mac plists. files: Mac/IDLE/IDLE.app/Contents/Info.plist | 2 +- Mac/PythonLauncher/Info.plist.in | 2 +- Mac/Resources/app/Info.plist.in | 6 +++--- Mac/Resources/framework/Info.plist.in | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Mac/IDLE/IDLE.app/Contents/Info.plist b/Mac/IDLE/IDLE.app/Contents/Info.plist --- a/Mac/IDLE/IDLE.app/Contents/Info.plist +++ b/Mac/IDLE/IDLE.app/Contents/Info.plist @@ -36,7 +36,7 @@ CFBundleExecutable IDLE CFBundleGetInfoString - %version%, ? 2001-2013 Python Software Foundation + %version%, ? 2001-2014 Python Software Foundation CFBundleIconFile IDLE.icns CFBundleIdentifier diff --git a/Mac/PythonLauncher/Info.plist.in b/Mac/PythonLauncher/Info.plist.in --- a/Mac/PythonLauncher/Info.plist.in +++ b/Mac/PythonLauncher/Info.plist.in @@ -40,7 +40,7 @@ CFBundleExecutable PythonLauncher CFBundleGetInfoString - %VERSION%, ? 2001-2013 Python Software Foundation + %VERSION%, ? 2001-2014 Python Software Foundation CFBundleIconFile PythonLauncher.icns CFBundleIdentifier diff --git a/Mac/Resources/app/Info.plist.in b/Mac/Resources/app/Info.plist.in --- a/Mac/Resources/app/Info.plist.in +++ b/Mac/Resources/app/Info.plist.in @@ -20,7 +20,7 @@ CFBundleExecutable Python CFBundleGetInfoString - %version%, (c) 2004-2013 Python Software Foundation. + %version%, (c) 2004-2014 Python Software Foundation. CFBundleHelpBookFolder Documentation @@ -37,7 +37,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleLongVersionString - %version%, (c) 2004-2013 Python Software Foundation. + %version%, (c) 2004-2014 Python Software Foundation. CFBundleName Python CFBundlePackageType @@ -55,7 +55,7 @@ NSAppleScriptEnabled NSHumanReadableCopyright - (c) 2013 Python Software Foundation. + (c) 2014 Python Software Foundation. NSHighResolutionCapable diff --git a/Mac/Resources/framework/Info.plist.in b/Mac/Resources/framework/Info.plist.in --- a/Mac/Resources/framework/Info.plist.in +++ b/Mac/Resources/framework/Info.plist.in @@ -17,9 +17,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - %VERSION%, (c) 2004-2013 Python Software Foundation. + %VERSION%, (c) 2004-2014 Python Software Foundation. CFBundleLongVersionString - %VERSION%, (c) 2004-2013 Python Software Foundation. + %VERSION%, (c) 2004-2014 Python Software Foundation. CFBundleSignature ???? CFBundleVersion -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Jan 1 22:06:32 2014 From: python-checkins at python.org (ned.deily) Date: Wed, 1 Jan 2014 22:06:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Update_copyright_dates_in_Mac_plists=2E?= Message-ID: <3dvlL02TM6z7Lm0@mail.python.org> http://hg.python.org/cpython/rev/37582f4d90b5 changeset: 88246:37582f4d90b5 parent: 88242:14133d998493 parent: 88245:6a1a1cf5a01b user: Ned Deily date: Wed Jan 01 13:06:02 2014 -0800 summary: Update copyright dates in Mac plists. files: Mac/IDLE/IDLE.app/Contents/Info.plist | 2 +- Mac/PythonLauncher/Info.plist.in | 2 +- Mac/Resources/app/Info.plist.in | 6 +++--- Mac/Resources/framework/Info.plist.in | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Mac/IDLE/IDLE.app/Contents/Info.plist b/Mac/IDLE/IDLE.app/Contents/Info.plist --- a/Mac/IDLE/IDLE.app/Contents/Info.plist +++ b/Mac/IDLE/IDLE.app/Contents/Info.plist @@ -36,7 +36,7 @@ CFBundleExecutable IDLE CFBundleGetInfoString - %version%, ? 2001-2013 Python Software Foundation + %version%, ? 2001-2014 Python Software Foundation CFBundleIconFile IDLE.icns CFBundleIdentifier diff --git a/Mac/PythonLauncher/Info.plist.in b/Mac/PythonLauncher/Info.plist.in --- a/Mac/PythonLauncher/Info.plist.in +++ b/Mac/PythonLauncher/Info.plist.in @@ -40,7 +40,7 @@ CFBundleExecutable PythonLauncher CFBundleGetInfoString - %VERSION%, ? 2001-2013 Python Software Foundation + %VERSION%, ? 2001-2014 Python Software Foundation CFBundleIconFile PythonLauncher.icns CFBundleIdentifier diff --git a/Mac/Resources/app/Info.plist.in b/Mac/Resources/app/Info.plist.in --- a/Mac/Resources/app/Info.plist.in +++ b/Mac/Resources/app/Info.plist.in @@ -20,7 +20,7 @@ CFBundleExecutable Python CFBundleGetInfoString - %version%, (c) 2004-2013 Python Software Foundation. + %version%, (c) 2004-2014 Python Software Foundation. CFBundleHelpBookFolder Documentation @@ -37,7 +37,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleLongVersionString - %version%, (c) 2004-2013 Python Software Foundation. + %version%, (c) 2004-2014 Python Software Foundation. CFBundleName Python CFBundlePackageType @@ -55,7 +55,7 @@ NSAppleScriptEnabled NSHumanReadableCopyright - (c) 2013 Python Software Foundation. + (c) 2014 Python Software Foundation. NSHighResolutionCapable diff --git a/Mac/Resources/framework/Info.plist.in b/Mac/Resources/framework/Info.plist.in --- a/Mac/Resources/framework/Info.plist.in +++ b/Mac/Resources/framework/Info.plist.in @@ -17,9 +17,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - %VERSION%, (c) 2004-2013 Python Software Foundation. + %VERSION%, (c) 2004-2014 Python Software Foundation. CFBundleLongVersionString - %VERSION%, (c) 2004-2013 Python Software Foundation. + %VERSION%, (c) 2004-2014 Python Software Foundation. CFBundleSignature ???? CFBundleVersion -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Thu Jan 2 09:45:17 2014 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 02 Jan 2014 09:45:17 +0100 Subject: [Python-checkins] Daily reference leaks (37582f4d90b5): sum=-4 Message-ID: results for 37582f4d90b5 on branch "default" -------------------------------------------- test_site leaked [0, -2, 0] references, sum=-2 test_site leaked [0, -2, 0] memory blocks, sum=-2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/refloghG1XVq', '-x'] From python-checkins at python.org Thu Jan 2 11:51:33 2014 From: python-checkins at python.org (victor.stinner) Date: Thu, 2 Jan 2014 11:51:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogcGFyc2VyOiBmaXgg?= =?utf-8?q?usage_of_Py=5FBuildValue=28=29_to_build_a_parser_error?= Message-ID: <3dw5dx45k8z7LjT@mail.python.org> http://hg.python.org/cpython/rev/91cb83f895cf changeset: 88247:91cb83f895cf branch: 3.3 parent: 88245:6a1a1cf5a01b user: Victor Stinner date: Thu Jan 02 11:49:27 2014 +0100 summary: parser: fix usage of Py_BuildValue() to build a parser error Fix typo: "os" format => "Os" files: Modules/parsermodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -748,7 +748,7 @@ } } if (!ok) { - PyObject *err = Py_BuildValue("os", elem, + PyObject *err = Py_BuildValue("Os", elem, "Illegal node construct."); PyErr_SetObject(parser_error, err); Py_XDECREF(err); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 11:51:34 2014 From: python-checkins at python.org (victor.stinner) Date: Thu, 2 Jan 2014 11:51:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=28Merge_3=2E3=29_parser=3A_fix_usage_of_Py=5FBuildValue?= =?utf-8?q?=28=29_to_build_a_parser_error?= Message-ID: <3dw5dy60v2z7Ljc@mail.python.org> http://hg.python.org/cpython/rev/cd952e92c180 changeset: 88248:cd952e92c180 parent: 88246:37582f4d90b5 parent: 88247:91cb83f895cf user: Victor Stinner date: Thu Jan 02 11:50:10 2014 +0100 summary: (Merge 3.3) parser: fix usage of Py_BuildValue() to build a parser error Fix typo: "os" format => "Os" files: Modules/parsermodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -785,7 +785,7 @@ } } if (!ok) { - PyObject *err = Py_BuildValue("os", elem, + PyObject *err = Py_BuildValue("Os", elem, "Illegal node construct."); PyErr_SetObject(parser_error, err); Py_XDECREF(err); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 12:54:03 2014 From: python-checkins at python.org (victor.stinner) Date: Thu, 2 Jan 2014 12:54:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_threading=2ERLock=2E=5Facq?= =?utf-8?q?uire=5Frestore=28=29_now_raises_a_TypeError_instead_of_a?= Message-ID: <3dw7235gCHz7LjR@mail.python.org> http://hg.python.org/cpython/rev/9a61be172c23 changeset: 88249:9a61be172c23 user: Victor Stinner date: Thu Jan 02 12:47:24 2014 +0100 summary: threading.RLock._acquire_restore() now raises a TypeError instead of a SystemError when it is not called with 2 arguments files: Modules/_threadmodule.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -379,13 +379,13 @@ to be available for other threads."); static PyObject * -rlock_acquire_restore(rlockobject *self, PyObject *arg) +rlock_acquire_restore(rlockobject *self, PyObject *args) { long owner; unsigned long count; int r = 1; - if (!PyArg_ParseTuple(arg, "kl:_acquire_restore", &count, &owner)) + if (!PyArg_ParseTuple(args, "(kl):_acquire_restore", &count, &owner)) return NULL; if (!PyThread_acquire_lock(self->rlock_lock, 0)) { @@ -488,7 +488,7 @@ {"_is_owned", (PyCFunction)rlock_is_owned, METH_NOARGS, rlock_is_owned_doc}, {"_acquire_restore", (PyCFunction)rlock_acquire_restore, - METH_O, rlock_acquire_restore_doc}, + METH_VARARGS, rlock_acquire_restore_doc}, {"_release_save", (PyCFunction)rlock_release_save, METH_NOARGS, rlock_release_save_doc}, {"__enter__", (PyCFunction)rlock_acquire, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 12:54:05 2014 From: python-checkins at python.org (victor.stinner) Date: Thu, 2 Jan 2014 12:54:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE4ODI5?= =?utf-8?q?=3A_Add_tests_for_the_csv_module_for_invalid_characters_=28deli?= =?utf-8?q?miter=2C?= Message-ID: <3dw7250HV0z7LjT@mail.python.org> http://hg.python.org/cpython/rev/0daf7f02c97f changeset: 88250:0daf7f02c97f branch: 3.3 parent: 88247:91cb83f895cf user: Victor Stinner date: Thu Jan 02 12:53:13 2014 +0100 summary: Issue #18829: Add tests for the csv module for invalid characters (delimiter, escapechar, quotechar) files: Lib/test/test_csv.py | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -828,6 +828,19 @@ self.assertEqual(str(cm.exception), '"lineterminator" must be a string') + def test_invalid_chars(self): + def create_invalid(field_name, value): + class mydialect(csv.Dialect): + pass + setattr(mydialect, field_name, value) + d = mydialect() + + for field_name in ("delimiter", "escapechar", "quotechar"): + self.assertRaises(csv.Error, create_invalid, field_name, "") + self.assertRaises(csv.Error, create_invalid, field_name, "abc") + self.assertRaises(csv.Error, create_invalid, field_name, b'x') + self.assertRaises(csv.Error, create_invalid, field_name, 5) + class TestSniffer(unittest.TestCase): sample1 = """\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 12:54:06 2014 From: python-checkins at python.org (victor.stinner) Date: Thu, 2 Jan 2014 12:54:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=28Merge_3=2E3=29_Issue_=2318829=3A_Add_tests_for_the_cs?= =?utf-8?q?v_module_for_invalid_characters?= Message-ID: <3dw7261yf7z7LjZ@mail.python.org> http://hg.python.org/cpython/rev/ccb52323039f changeset: 88251:ccb52323039f parent: 88249:9a61be172c23 parent: 88250:0daf7f02c97f user: Victor Stinner date: Thu Jan 02 12:53:50 2014 +0100 summary: (Merge 3.3) Issue #18829: Add tests for the csv module for invalid characters (delimiter, escapechar, quotechar) files: Lib/test/test_csv.py | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -837,6 +837,20 @@ self.assertEqual(str(cm.exception), '"lineterminator" must be a string') + def test_invalid_chars(self): + def create_invalid(field_name, value): + class mydialect(csv.Dialect): + pass + setattr(mydialect, field_name, value) + d = mydialect() + + for field_name in ("delimiter", "escapechar", "quotechar"): + with self.subTest(field_name=field_name): + self.assertRaises(csv.Error, create_invalid, field_name, "") + self.assertRaises(csv.Error, create_invalid, field_name, "abc") + self.assertRaises(csv.Error, create_invalid, field_name, b'x') + self.assertRaises(csv.Error, create_invalid, field_name, 5) + class TestSniffer(unittest.TestCase): sample1 = """\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 14:12:58 2014 From: python-checkins at python.org (martin.v.loewis) Date: Thu, 2 Jan 2014 14:12:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319728=3A_Enable_p?= =?utf-8?q?ip_installation_by_default_on_Windows=2E?= Message-ID: <3dw8n61wFZz7LjS@mail.python.org> http://hg.python.org/cpython/rev/4c7b3e7fd4ca changeset: 88252:4c7b3e7fd4ca user: Martin v. L?wis date: Thu Jan 02 14:12:30 2014 +0100 summary: Issue #19728: Enable pip installation by default on Windows. files: Misc/NEWS | 2 ++ Tools/msi/msi.py | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -303,6 +303,8 @@ Build ----- +- Issue #19728: Enable pip installation by default on Windows. + - Issue #16136: Remove VMS support - Issue #18215: Add script Tools/ssl/test_multiple_versions.py to compile and diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -422,7 +422,7 @@ compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py2_|lib2to3\\tests|venv\\scripts" "[TARGETDIR]Lib"' lib2to3args = r'-c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"' updatepipargs = r'-m ensurepip -U' - removepipargs = r'-m ensurepip -r' # does not yet work + removepipargs = r'-m ensurepip._uninstall' # See "CustomAction Table" add_data(db, "CustomAction", [ # msidbCustomActionTypeFirstSequence + msidbCustomActionTypeTextData + msidbCustomActionTypeProperty @@ -441,7 +441,7 @@ ("CompileGrammar", 18, "python.exe", lib2to3args), # msidbCustomActionTypeInScript (1024); run during actual installation ("UpdatePip", 18+1024, "python.exe", updatepipargs), - #("RemovePip", 18, "python.exe", removepipargs), + ("RemovePip", 18, "python.exe", removepipargs), ]) # UI Sequences, see "InstallUISequence Table", "Using a Sequence Table" @@ -480,10 +480,10 @@ ("UpdateEditIDLE", None, 1050), # run command if install state of pip changes to INSTALLSTATE_LOCAL # run after InstallFiles - ("UpdatePip", "&pip=3", 4001), + ("UpdatePip", "&pip_feature=3", 4001), # remove pip when state changes to INSTALLSTATE_ABSENT # run before RemoveFiles - #("RemovePip", "&pip=2", 3499), + ("RemovePip", "&pip_feature=2", 3499), ("CompilePyc", "COMPILEALL", 6800), ("CompilePyo", "COMPILEALL", 6801), ("CompileGrammar", "COMPILEALL", 6802), @@ -862,7 +862,7 @@ # Features that have no advertisement trigger (e.g. the test suite) # must not support advertisement global default_feature, tcltk, htmlfiles, tools, testsuite - global ext_feature, private_crt, prepend_path, update_pip + global ext_feature, private_crt, prepend_path, pip_feature default_feature = Feature(db, "DefaultFeature", "Python", "Python Interpreter and Libraries", 1, directory = "TARGETDIR") @@ -886,10 +886,10 @@ parent = default_feature, attributes=2) # pip installation isn't enabled by default until a clean uninstall procedure # becomes possible - update_pip = Feature(db, "pip", "pip", + pip_feature = Feature(db, "pip_feature", "pip", "Install (or upgrade from an earlier version) pip, " "a tool for installing and managing Python packages.", 11, - parent = default_feature, attributes=2|8, level=2) + parent = default_feature, attributes=2|8) testsuite = Feature(db, "Testsuite", "Test suite", "Python test suite (Lib/test/)", 13, parent = default_feature, attributes=2|8) @@ -1206,6 +1206,8 @@ "Documentation"), ("REGISTRY.path", msilib.gen_uuid(), "TARGETDIR", registry_component, None, None), + ("REGISTRY.ensurepip", msilib.gen_uuid(), "TARGETDIR", registry_component, "EnsurePipRun", + None), ("REGISTRY.def", msilib.gen_uuid(), "TARGETDIR", registry_component, None, None)] + tcldata) # See "FeatureComponents Table". @@ -1223,6 +1225,7 @@ [(default_feature.id, "REGISTRY"), (htmlfiles.id, "REGISTRY.doc"), (prepend_path.id, "REGISTRY.path"), + (pip_feature.id, "REGISTRY.ensurepip"), (ext_feature.id, "REGISTRY.def")] + tcldata ) @@ -1309,7 +1312,9 @@ "", r"[TARGETDIR]Python.exe", "REGISTRY.def"), ("DisplayIcon", -1, r"Software\Microsoft\Windows\CurrentVersion\Uninstall\%s" % product_code, - "DisplayIcon", "[TARGETDIR]python.exe", "REGISTRY") + "DisplayIcon", "[TARGETDIR]python.exe", "REGISTRY"), + # Fake registry entry to allow installer to track whether ensurepip has been run + ("EnsurePipRun", -1, prefix+r"\EnsurePipRun", "", "#1", "REGISTRY.ensurepip"), ]) # Shortcuts, see "Shortcut Table" add_data(db, "Directory", -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 15:33:47 2014 From: python-checkins at python.org (donald.stufft) Date: Thu, 2 Jan 2014 15:33:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Update_pip_to_the_released?= =?utf-8?q?_1=2E5?= Message-ID: <3dwBZM54QRz7LjN@mail.python.org> http://hg.python.org/cpython/rev/70fd3383bd31 changeset: 88253:70fd3383bd31 user: Donald Stufft date: Thu Jan 02 09:33:35 2014 -0500 summary: Update pip to the released 1.5 files: Lib/ensurepip/__init__.py | 10 +----- Lib/ensurepip/_bundled/pip-1.5-py2.py3-none-any.whl | Bin Lib/ensurepip/_bundled/pip-1.5rc4-py2.py3-none-any.whl | Bin Lib/test/test_ensurepip.py | 16 +++++----- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -4,15 +4,13 @@ import sys import tempfile -# TODO: Remove the --pre flag when a pip 1.5 final copy is available - __all__ = ["version", "bootstrap"] _SETUPTOOLS_VERSION = "2.0.2" -_PIP_VERSION = "1.5rc4" +_PIP_VERSION = "1.5" # pip currently requires ssl support, so we try to provide a nicer # error message when that is missing (http://bugs.python.org/issue19744) @@ -102,11 +100,7 @@ additional_paths.append(os.path.join(tmpdir, wheel_name)) # Construct the arguments to be passed to the pip command - args = [ - "install", "--no-index", "--find-links", tmpdir, - # Temporary until pip 1.5 is final - "--pre", - ] + args = ["install", "--no-index", "--find-links", tmpdir] if root: args += ["--root", root] if upgrade: diff --git a/Lib/ensurepip/_bundled/pip-1.5-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-1.5-py2.py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..dd7ca2e634424d8f443cf82f7b92393410219748 GIT binary patch [stripped] diff --git a/Lib/ensurepip/_bundled/pip-1.5rc4-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-1.5rc4-py2.py3-none-any.whl deleted file mode 100644 index 2a16332814c690b3fc6f040fc79709dfed2e5095..0000000000000000000000000000000000000000 GIT binary patch [stripped] diff --git a/Lib/test/test_ensurepip.py b/Lib/test/test_ensurepip.py --- a/Lib/test/test_ensurepip.py +++ b/Lib/test/test_ensurepip.py @@ -52,7 +52,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "setuptools", "pip", + unittest.mock.ANY, "setuptools", "pip", ], unittest.mock.ANY, ) @@ -67,7 +67,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "--root", "/foo/bar/", + unittest.mock.ANY, "--root", "/foo/bar/", "setuptools", "pip", ], unittest.mock.ANY, @@ -80,7 +80,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "--user", "setuptools", "pip", + unittest.mock.ANY, "--user", "setuptools", "pip", ], unittest.mock.ANY, ) @@ -92,7 +92,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "--upgrade", "setuptools", "pip", + unittest.mock.ANY, "--upgrade", "setuptools", "pip", ], unittest.mock.ANY, ) @@ -104,7 +104,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "-v", "setuptools", "pip", + unittest.mock.ANY, "-v", "setuptools", "pip", ], unittest.mock.ANY, ) @@ -116,7 +116,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "-vv", "setuptools", "pip", + unittest.mock.ANY, "-vv", "setuptools", "pip", ], unittest.mock.ANY, ) @@ -128,7 +128,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "-vvv", "setuptools", "pip", + unittest.mock.ANY, "-vvv", "setuptools", "pip", ], unittest.mock.ANY, ) @@ -286,7 +286,7 @@ self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", - unittest.mock.ANY, "--pre", "setuptools", "pip", + unittest.mock.ANY, "setuptools", "pip", ], unittest.mock.ANY, ) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 16:43:31 2014 From: python-checkins at python.org (zach.ware) Date: Thu, 2 Jan 2014 16:43:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzIwMTAx?= =?utf-8?q?=3A_Allow_test=5Fmonotonic_to_pass_on_Windows_machines_on_which?= Message-ID: <3dwD6q4mRYz7LjS@mail.python.org> http://hg.python.org/cpython/rev/82df66a091da changeset: 88254:82df66a091da branch: 3.3 parent: 88250:0daf7f02c97f user: Zachary Ware date: Thu Jan 02 09:41:10 2014 -0600 summary: Issue #20101: Allow test_monotonic to pass on Windows machines on which time.get_clock_info('monotonic').resolution == 0.015600099999999999 This is just a workaround pending a real resolution to #20101. files: Lib/test/test_time.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -376,7 +376,8 @@ t2 = time.monotonic() dt = t2 - t1 self.assertGreater(t2, t1) - self.assertTrue(0.5 <= dt <= 1.0, dt) + # Issue #20101: On some Windows machines, dt may be slightly low + self.assertTrue(0.45 <= dt <= 1.0, dt) info = time.get_clock_info('monotonic') self.assertTrue(info.monotonic) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 16:43:32 2014 From: python-checkins at python.org (zach.ware) Date: Thu, 2 Jan 2014 16:43:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2320101=3A_Merge_with_3=2E3?= Message-ID: <3dwD6r6Lbfz7LjS@mail.python.org> http://hg.python.org/cpython/rev/e2a1400b7db9 changeset: 88255:e2a1400b7db9 parent: 88253:70fd3383bd31 parent: 88254:82df66a091da user: Zachary Ware date: Thu Jan 02 09:43:09 2014 -0600 summary: Issue #20101: Merge with 3.3 files: Lib/test/test_time.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -384,7 +384,8 @@ t2 = time.monotonic() dt = t2 - t1 self.assertGreater(t2, t1) - self.assertTrue(0.5 <= dt <= 1.0, dt) + # Issue #20101: On some Windows machines, dt may be slightly low + self.assertTrue(0.45 <= dt <= 1.0, dt) # monotonic() is a monotonic but non adjustable clock info = time.get_clock_info('monotonic') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 19:27:06 2014 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 2 Jan 2014 19:27:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_remove_bracket?= =?utf-8?q?s?= Message-ID: <3dwHlZ0KZQz7Ljy@mail.python.org> http://hg.python.org/cpython/rev/8083b8870686 changeset: 88256:8083b8870686 branch: 3.3 parent: 88254:82df66a091da user: Benjamin Peterson date: Thu Jan 02 12:22:30 2014 -0600 summary: remove brackets files: Doc/library/inspect.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -752,7 +752,7 @@ metatype is in use, cls will be the first element of the tuple. -.. function:: getcallargs(func[, *args][, **kwds]) +.. function:: getcallargs(func, *args, **kwds) Bind the *args* and *kwds* to the argument names of the Python function or method *func*, as if it was called with them. For bound methods, bind also the -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 19:27:07 2014 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 2 Jan 2014 19:27:07 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_avoid_paramete?= =?utf-8?q?r_name_clash_=28closes_=2320108=29?= Message-ID: <3dwHlb1qtGz7Ljw@mail.python.org> http://hg.python.org/cpython/rev/b0d472e3ff42 changeset: 88257:b0d472e3ff42 branch: 3.3 user: Benjamin Peterson date: Thu Jan 02 12:24:08 2014 -0600 summary: avoid parameter name clash (closes #20108) files: Lib/inspect.py | 4 +++- Misc/NEWS | 2 ++ 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -985,12 +985,14 @@ (f_name, sig, "s" if plural else "", given, kwonly_sig, "was" if given == 1 and not kwonly_given else "were")) -def getcallargs(func, *positional, **named): +def getcallargs(*func_and_positional, **named): """Get the mapping of arguments to values. A dict is returned, with keys the function argument names (including the names of the * and ** arguments, if any), and values the respective bound values from 'positional' and 'named'.""" + func = func_and_positional[0] + positional = func_and_positional[1:] spec = getfullargspec(func) args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = spec f_name = func.__name__ diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,8 @@ Library ------- +- Issue #20108: Avoid parameter name clash in inspect.getcallargs(). + - Issue #12692: Backport the fix for ResourceWarning in test_urllib2net. This also helps in closing the socket when Connection Close header is not sent. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 19:27:08 2014 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 2 Jan 2014 19:27:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_merge_3=2E3_=28closes_=2320108=29?= Message-ID: <3dwHlc3TqFz7LkT@mail.python.org> http://hg.python.org/cpython/rev/c265675cd8e2 changeset: 88258:c265675cd8e2 parent: 88255:e2a1400b7db9 parent: 88257:b0d472e3ff42 user: Benjamin Peterson date: Thu Jan 02 12:26:50 2014 -0600 summary: merge 3.3 (closes #20108) files: Doc/library/inspect.rst | 2 +- Lib/inspect.py | 4 +++- Misc/NEWS | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -753,7 +753,7 @@ metatype is in use, cls will be the first element of the tuple. -.. function:: getcallargs(func[, *args][, **kwds]) +.. function:: getcallargs(func, *args, **kwds) Bind the *args* and *kwds* to the argument names of the Python function or method *func*, as if it was called with them. For bound methods, bind also the diff --git a/Lib/inspect.py b/Lib/inspect.py --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1087,12 +1087,14 @@ (f_name, sig, "s" if plural else "", given, kwonly_sig, "was" if given == 1 and not kwonly_given else "were")) -def getcallargs(func, *positional, **named): +def getcallargs(*func_and_positional, **named): """Get the mapping of arguments to values. A dict is returned, with keys the function argument names (including the names of the * and ** arguments, if any), and values the respective bound values from 'positional' and 'named'.""" + func = func_and_positional[0] + positional = func_and_positional[1:] spec = getfullargspec(func) args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = spec f_name = func.__name__ diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -46,6 +46,8 @@ - Fix breakage in TestSuite.countTestCases() introduced by issue #11798. +- Issue #20108: Avoid parameter name clash in inspect.getcallargs(). + - Issue #19918: Fix PurePath.relative_to() under Windows. - Issue #19422: Explicitly disallow non-SOCK_STREAM sockets in the ssl -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 19:44:51 2014 From: python-checkins at python.org (r.david.murray) Date: Thu, 2 Jan 2014 19:44:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogIzE3MjgyOiBEb2N1?= =?utf-8?q?ment_unittest=2Emain_defaultTest_argument=2E?= Message-ID: <3dwJ833cc5z7Ljh@mail.python.org> http://hg.python.org/cpython/rev/045e7a587f3c changeset: 88259:045e7a587f3c branch: 3.3 parent: 88257:b0d472e3ff42 user: R David Murray date: Thu Jan 02 13:37:26 2014 -0500 summary: #17282: Document unittest.main defaultTest argument. files: Doc/library/unittest.rst | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1801,6 +1801,10 @@ if __name__ == '__main__': unittest.main(verbosity=2) + The *defaultTest* argument is the name of the test to run if no test names + are specified via *argv*. If not specified or ``None`` and no test names are + provided via *argv*, all tests found in *module* are run. + The *argv* argument can be a list of options passed to the program, with the first element being the program name. If not specified or ``None``, the values of :data:`sys.argv` are used. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 19:44:52 2014 From: python-checkins at python.org (r.david.murray) Date: Thu, 2 Jan 2014 19:44:52 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE3MjgyOiBEb2N1?= =?utf-8?q?ment_unittest=2Emain_defaultTest_argument=2E?= Message-ID: <3dwJ845Y8rz7Ljk@mail.python.org> http://hg.python.org/cpython/rev/69b5f6924553 changeset: 88260:69b5f6924553 branch: 2.7 parent: 88244:aeb70f2f6f38 user: R David Murray date: Thu Jan 02 13:38:02 2014 -0500 summary: #17282: Document unittest.main defaultTest argument. files: Doc/library/unittest.rst | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1808,6 +1808,10 @@ if __name__ == '__main__': unittest.main(verbosity=2) + The *defaultTest* argument is the name of the test to run if no test names + are specified via *argv*. If not specified or ``None`` and no test names are + provided via *argv*, all tests found in *module* are run. + The *argv* argument can be a list of options passed to the program, with the first element being the program name. If not specified or ``None``, the values of :data:`sys.argv` are used. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 19:44:54 2014 From: python-checkins at python.org (r.david.murray) Date: Thu, 2 Jan 2014 19:44:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_and_update_=2317282=3A_Document_unittest=2Emain_de?= =?utf-8?q?faultTest_argument=2E?= Message-ID: <3dwJ860G3Tz7LkF@mail.python.org> http://hg.python.org/cpython/rev/1bbf8c263d3c changeset: 88261:1bbf8c263d3c parent: 88258:c265675cd8e2 parent: 88259:045e7a587f3c user: R David Murray date: Thu Jan 02 13:43:02 2014 -0500 summary: Merge and update #17282: Document unittest.main defaultTest argument. In 3.4 defaultTest can also be a list (see issue 15132). files: Doc/library/unittest.rst | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1966,6 +1966,11 @@ if __name__ == '__main__': unittest.main(verbosity=2) + The *defaultTest* argument is either the name of a single test or an + iterable of test names to run if no test names are specified via *argv*. If + not specified or ``None`` and no test names are provided via *argv*, all + tests found in *module* are run. + The *argv* argument can be a list of options passed to the program, with the first element being the program name. If not specified or ``None``, the values of :data:`sys.argv` are used. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 19:44:55 2014 From: python-checkins at python.org (r.david.murray) Date: Thu, 2 Jan 2014 19:44:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_sqlite3_uri_pa?= =?utf-8?q?rm=2C_unittest=2Emain_defaultTest=2C_ftplib=2ENetrc_deprecation?= Message-ID: <3dwJ871h9Hz7Lk3@mail.python.org> http://hg.python.org/cpython/rev/04af288c004c changeset: 88262:04af288c004c user: R David Murray date: Thu Jan 02 13:44:18 2014 -0500 summary: whatsnew: sqlite3 uri parm, unittest.main defaultTest, ftplib.Netrc deprecation files: Doc/whatsnew/3.4.rst | 17 +++++++++++++++++ Misc/NEWS | 2 +- 2 files changed, 18 insertions(+), 1 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -915,6 +915,15 @@ during debugging, instead of integer "magic numbers". +sqlite3 +------- + +A new boolean parameter, *uri*, to the :func:`~sqlite3.connect` function can +be used to indicate that the *database* parameter is a ``uri`` (see +the `SQLite URI documentation `_). +(Contributed by poq in :issue:`13773`.) + + ssl --- @@ -998,6 +1007,10 @@ :meth:`~unittest.TestCase.subTest` context manager. (Contributed by Antoine Pitrou in :issue:`16997`.) +:func:`unittest.main` now also accepts an iterable of test names for +*defaultTest*, where previously it only accepted a single test name as a +string. (Contributed by Jyrki Pulliainen in :issue:`15132`.) + venv ---- @@ -1246,6 +1259,10 @@ * MD5 as default digestmod for :mod:`hmac` is deprecated. Python 3.6 will require an explicit digest name or constructor as *digestmod* argument. +* The internal ``Netrc`` class in the :mod:`ftplib` module has been documented + as deprecated in its docstring for quite some time. It now emits a + :exc:`DeprecationWarning` and will be removed completely in Python 3.5. + Deprecated Functions and Types in the C API ------------------------------------------- diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2439,7 +2439,7 @@ - Issue #4591: Uid and gid values larger than 2**31 are supported now. -- Issue #17141: random.vonmisesvariate() no more hangs for large kappas. +- Issue #17141: random.vonmisesvariate() no longer hangs for large kappas. - Issue #17149: Fix random.vonmisesvariate to always return results in [0, 2*math.pi]. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 23:48:39 2014 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 2 Jan 2014 23:48:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_correct_word_f?= =?utf-8?q?or_=5F=5Fannotations=5F=5F_doc_=28closes_=2320110=29?= Message-ID: <3dwPYM3tZ2z7LjY@mail.python.org> http://hg.python.org/cpython/rev/203ca77ea819 changeset: 88263:203ca77ea819 branch: 3.3 parent: 88259:045e7a587f3c user: Benjamin Peterson date: Thu Jan 02 16:47:50 2014 -0600 summary: correct word for __annotations__ doc (closes #20110) Patch from Claudiu Popa. files: Doc/reference/datamodel.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -495,7 +495,7 @@ | :attr:`__annotations__` | A dict containing annotations | Writable | | | of parameters. The keys of | | | | the dict are the parameter | | - | | names, or ``'return'`` for | | + | | names, and ``'return'`` for | | | | the return annotation, if | | | | provided. | | +-------------------------+-------------------------------+-----------+ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Jan 2 23:48:40 2014 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 2 Jan 2014 23:48:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4zICgjMjAxMTAp?= Message-ID: <3dwPYN5T9Vz7LjY@mail.python.org> http://hg.python.org/cpython/rev/3e75f649e93b changeset: 88264:3e75f649e93b parent: 88262:04af288c004c parent: 88263:203ca77ea819 user: Benjamin Peterson date: Thu Jan 02 16:48:24 2014 -0600 summary: merge 3.3 (#20110) files: Doc/reference/datamodel.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -495,7 +495,7 @@ | :attr:`__annotations__` | A dict containing annotations | Writable | | | of parameters. The keys of | | | | the dict are the parameter | | - | | names, or ``'return'`` for | | + | | names, and ``'return'`` for | | | | the return annotation, if | | | | provided. | | +-------------------------+-------------------------------+-----------+ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 00:07:37 2014 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 3 Jan 2014 00:07:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2320111=3A_pathlib?= =?utf-8?q?=2EPath=2Ewith=5Fsuffix=28=29_now_sanity_checks_the_given_suffi?= =?utf-8?q?x=2E?= Message-ID: <3dwPzF5BNsz7Ljh@mail.python.org> http://hg.python.org/cpython/rev/ef2b2ddd27c8 changeset: 88265:ef2b2ddd27c8 user: Antoine Pitrou date: Fri Jan 03 00:07:17 2014 +0100 summary: Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix. files: Lib/pathlib.py | 6 ++++++ Lib/test/test_pathlib.py | 20 ++++++++++++++++++++ Misc/NEWS | 2 ++ 3 files changed, 28 insertions(+), 0 deletions(-) diff --git a/Lib/pathlib.py b/Lib/pathlib.py --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -755,6 +755,12 @@ def with_suffix(self, suffix): """Return a new path with the file suffix changed (or added, if none).""" # XXX if suffix is None, should the current suffix be removed? + drv, root, parts = self._flavour.parse_parts((suffix,)) + if drv or root or len(parts) != 1: + raise ValueError("Invalid suffix %r" % (suffix)) + suffix = parts[0] + if not suffix.startswith('.'): + raise ValueError("Invalid suffix %r" % (suffix)) name = self.name if not name: raise ValueError("%r has an empty name" % (self,)) diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -528,9 +528,16 @@ self.assertEqual(P('/a/b').with_suffix('.gz'), P('/a/b.gz')) self.assertEqual(P('a/b.py').with_suffix('.gz'), P('a/b.gz')) self.assertEqual(P('/a/b.py').with_suffix('.gz'), P('/a/b.gz')) + # Path doesn't have a "filename" component self.assertRaises(ValueError, P('').with_suffix, '.gz') self.assertRaises(ValueError, P('.').with_suffix, '.gz') self.assertRaises(ValueError, P('/').with_suffix, '.gz') + # Invalid suffix + self.assertRaises(ValueError, P('a/b').with_suffix, 'gz') + self.assertRaises(ValueError, P('a/b').with_suffix, '/') + self.assertRaises(ValueError, P('a/b').with_suffix, '/.gz') + self.assertRaises(ValueError, P('a/b').with_suffix, 'c/d') + self.assertRaises(ValueError, P('a/b').with_suffix, '.c/.d') def test_relative_to_common(self): P = self.cls @@ -920,10 +927,23 @@ self.assertEqual(P('c:/a/b').with_suffix('.gz'), P('c:/a/b.gz')) self.assertEqual(P('c:a/b.py').with_suffix('.gz'), P('c:a/b.gz')) self.assertEqual(P('c:/a/b.py').with_suffix('.gz'), P('c:/a/b.gz')) + # Path doesn't have a "filename" component self.assertRaises(ValueError, P('').with_suffix, '.gz') self.assertRaises(ValueError, P('.').with_suffix, '.gz') self.assertRaises(ValueError, P('/').with_suffix, '.gz') self.assertRaises(ValueError, P('//My/Share').with_suffix, '.gz') + # Invalid suffix + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '/') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '\\') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c:') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '/.gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '\\.gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c:.gz') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c/d') + self.assertRaises(ValueError, P('c:a/b').with_suffix, 'c\\d') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '.c/d') + self.assertRaises(ValueError, P('c:a/b').with_suffix, '.c\\d') def test_relative_to(self): P = self.cls diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -44,6 +44,8 @@ Library ------- +- Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix. + - Fix breakage in TestSuite.countTestCases() introduced by issue #11798. - Issue #20108: Avoid parameter name clash in inspect.getcallargs(). -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 03:27:02 2014 From: python-checkins at python.org (victor.stinner) Date: Fri, 3 Jan 2014 03:27:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_asyncio=3A_make_PY34_symbo?= =?utf-8?q?l_private_=28rename_it_to_=5FPY34=29?= Message-ID: <3dwVPL5V0Yz7LjN@mail.python.org> http://hg.python.org/cpython/rev/584870f6d3d1 changeset: 88266:584870f6d3d1 user: Victor Stinner date: Thu Jan 02 18:41:34 2014 +0100 summary: asyncio: make PY34 symbol private (rename it to _PY34) files: Lib/asyncio/transports.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/asyncio/transports.py b/Lib/asyncio/transports.py --- a/Lib/asyncio/transports.py +++ b/Lib/asyncio/transports.py @@ -2,7 +2,7 @@ import sys -PY34 = sys.version_info >= (3, 4) +_PY34 = sys.version_info >= (3, 4) __all__ = ['BaseTransport', 'ReadTransport', 'WriteTransport', 'Transport', 'DatagramTransport', 'SubprocessTransport', @@ -94,7 +94,7 @@ The default implementation concatenates the arguments and calls write() on the result. """ - if not PY34: + if not _PY34: # In Python 3.3, bytes.join() doesn't handle memoryview. list_of_data = ( bytes(data) if isinstance(data, memoryview) else data -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 03:27:04 2014 From: python-checkins at python.org (victor.stinner) Date: Fri, 3 Jan 2014 03:27:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_audioop=3A_adpcm2lin=28=29?= =?utf-8?q?_and_lin2adpcm=28=29_now_raises_a_TypeError_instead_of_a?= Message-ID: <3dwVPN0Trkz7LjN@mail.python.org> http://hg.python.org/cpython/rev/dee33603a5fa changeset: 88267:dee33603a5fa user: Victor Stinner date: Fri Jan 03 03:26:47 2014 +0100 summary: audioop: adpcm2lin() and lin2adpcm() now raises a TypeError instead of a SystemError if the state type is invalid. files: Lib/test/test_audioop.py | 5 +++++ Modules/audioop.c | 6 ++++++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py --- a/Lib/test/test_audioop.py +++ b/Lib/test/test_audioop.py @@ -269,6 +269,11 @@ self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None), (b'\0' * 5, (0, 0))) + def test_invalid_adpcm_state(self): + # state must be a tuple or None, not an integer + self.assertRaises(TypeError, audioop.adpcm2lin, b'\0', 1, 555) + self.assertRaises(TypeError, audioop.lin2adpcm, b'\0', 1, 555) + def test_lin2alaw(self): self.assertEqual(audioop.lin2alaw(datas[1], 1), b'\xd5\x87\xa4\x24\xaa\x2a\x5a') diff --git a/Modules/audioop.c b/Modules/audioop.c --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -1525,6 +1525,9 @@ /* First time, it seems. Set defaults */ valpred = 0; index = 0; + } else if (!PyTuple_Check(state)) { + PyErr_SetString(PyExc_TypeError, "state must be a tuple or None"); + goto exit; } else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) goto exit; @@ -1631,6 +1634,9 @@ /* First time, it seems. Set defaults */ valpred = 0; index = 0; + } else if (!PyTuple_Check(state)) { + PyErr_SetString(PyExc_TypeError, "state must be a tuple or None"); + goto exit; } else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) goto exit; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 05:20:49 2014 From: python-checkins at python.org (daniel.holth) Date: Fri, 3 Jan 2014 05:20:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2318585=3A_speed_zi?= =?utf-8?q?pfile_import_by_only_generating_zipfile=2E=5FZipDecryptor_on?= Message-ID: <3dwXwd2kkbz7Lk4@mail.python.org> http://hg.python.org/cpython/rev/536a2cf5f1d2 changeset: 88268:536a2cf5f1d2 user: Daniel Holth date: Thu Jan 02 23:17:21 2014 -0500 summary: Issue #18585: speed zipfile import by only generating zipfile._ZipDecryptor on demand files: Lib/zipfile.py | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Lib/zipfile.py b/Lib/zipfile.py --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -475,13 +475,15 @@ crc = ((crc >> 1) & 0x7FFFFFFF) table[i] = crc return table - crctable = _GenerateCRCTable() + crctable = None def _crc32(self, ch, crc): """Compute the CRC32 primitive on one byte.""" return ((crc >> 8) & 0xffffff) ^ self.crctable[(crc ^ ch) & 0xff] def __init__(self, pwd): + if _ZipDecrypter.crctable is None: + _ZipDecrypter.crctable = _ZipDecrypter._GenerateCRCTable() self.key0 = 305419896 self.key1 = 591751049 self.key2 = 878082192 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 06:31:31 2014 From: python-checkins at python.org (eric.snow) Date: Fri, 3 Jan 2014 06:31:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2320097=3A_Fix_bad_?= =?utf-8?q?use_of_=22self=22_in_importlib=27s_WindowsRegistryFinder=2E?= Message-ID: <3dwZVC02V2z7LkF@mail.python.org> http://hg.python.org/cpython/rev/7dbb4c6cd30e changeset: 88269:7dbb4c6cd30e user: Eric Snow date: Thu Jan 02 22:25:00 2014 -0700 summary: Issue #20097: Fix bad use of "self" in importlib's WindowsRegistryFinder. files: Lib/importlib/_bootstrap.py | 2 +- Lib/test/test_importlib/test_windows.py | 29 + Misc/NEWS | 2 + Python/importlib.h | 3726 +++++----- 4 files changed, 1895 insertions(+), 1864 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1406,7 +1406,7 @@ @classmethod def find_module(cls, fullname, path=None): """Find module named in the registry.""" - spec = self.find_spec(fullname, path) + spec = cls.find_spec(fullname, path) if spec is not None: return spec.loader else: diff --git a/Lib/test/test_importlib/test_windows.py b/Lib/test/test_importlib/test_windows.py new file mode 100644 --- /dev/null +++ b/Lib/test/test_importlib/test_windows.py @@ -0,0 +1,29 @@ +from . import util +frozen_machinery, source_machinery = util.import_importlib('importlib.machinery') + +import sys +import unittest + + + at unittest.skipUnless(sys.platform.startswith('win'), 'requires Windows') +class WindowsRegistryFinderTests: + + # XXX Need a test that finds the spec via the registry. + + def test_find_spec_missing(self): + spec = self.machinery.WindowsRegistryFinder.find_spec('spam') + self.assertIs(spec, None) + + def test_find_module_missing(self): + loader = self.machinery.WindowsRegistryFinder.find_module('spam') + self.assertIs(loader, None) + + +class Frozen_WindowsRegistryFinderTests(WindowsRegistryFinderTests, + unittest.TestCase): + machinery = frozen_machinery + + +class Source_WindowsRegistryFinderTests(WindowsRegistryFinderTests, + unittest.TestCase): + machinery = source_machinery diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -36,6 +36,8 @@ - Issue #19736: Add module-level statvfs constants defined for GNU/glibc based systems. +- Issue #20097: Fix bad use of "self" in importlib's WindowsRegistryFinder. + - Issue #19729: In str.format(), fix recursive expansion in format spec. - Issue #19638: Fix possible crash / undefined behaviour from huge (more than 2 diff --git a/Python/importlib.h b/Python/importlib.h --- a/Python/importlib.h +++ b/Python/importlib.h [stripped] -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Fri Jan 3 09:49:44 2014 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 03 Jan 2014 09:49:44 +0100 Subject: [Python-checkins] Daily reference leaks (dee33603a5fa): sum=3 Message-ID: results for dee33603a5fa on branch "default" -------------------------------------------- test_audioop leaked [1, 1, 1] references, sum=3 test_site leaked [-2, 2, 0] references, sum=0 test_site leaked [-2, 2, 0] memory blocks, sum=0 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogrwKKjc', '-x'] From root at python.org Fri Jan 3 11:05:27 2014 From: root at python.org (Cron Daemon) Date: Fri, 03 Jan 2014 11:05:27 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From python-checkins at python.org Fri Jan 3 12:27:27 2014 From: python-checkins at python.org (victor.stinner) Date: Fri, 3 Jan 2014 12:27:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2318294=3A_Fix_uint?= =?utf-8?q?=5Fconverter=28=29_in_zlibmodule=2Ec=2C_fix_the_=22=3E_UINT=5FM?= =?utf-8?q?AX=22_check?= Message-ID: <3dwkNv1GJ5z7LkC@mail.python.org> http://hg.python.org/cpython/rev/0cca6c5513d2 changeset: 88270:0cca6c5513d2 user: Victor Stinner date: Fri Jan 03 12:26:12 2014 +0100 summary: Issue #18294: Fix uint_converter() in zlibmodule.c, fix the "> UINT_MAX" check files: Modules/zlibmodule.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -329,11 +329,6 @@ uval = PyLong_AsUnsignedLong(obj); if (uval == (unsigned long)-1 && PyErr_Occurred()) return 0; - if (uval > UINT_MAX) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large for C unsigned int"); - return 0; - } } else { if (val < 0) { @@ -344,6 +339,12 @@ uval = (unsigned long)val; } + if (uval > UINT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "Python int too large for C unsigned int"); + return 0; + } + *(unsigned int *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned int); return 1; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 13:01:01 2014 From: python-checkins at python.org (victor.stinner) Date: Fri, 3 Jan 2014 13:01:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_add_unicode=5Fchar=28=29_i?= =?utf-8?q?n_unicodeobject=2Ec_to_factorize_code?= Message-ID: <3dwl7d4x8cz7Ljs@mail.python.org> http://hg.python.org/cpython/rev/d453c95def31 changeset: 88271:d453c95def31 user: Victor Stinner date: Fri Jan 03 12:53:47 2014 +0100 summary: add unicode_char() in unicodeobject.c to factorize code files: Objects/unicodeobject.c | 86 ++++++++++------------------ 1 files changed, 31 insertions(+), 55 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1749,7 +1749,6 @@ } } - static PyObject* get_latin1_char(unsigned char ch) { @@ -1766,6 +1765,31 @@ return unicode; } +static PyObject* +unicode_char(Py_UCS4 ch) +{ + PyObject *unicode; + + assert(ch <= MAX_UNICODE); + + unicode = PyUnicode_New(1, ch); + if (unicode == NULL) + return NULL; + switch (PyUnicode_KIND(unicode)) { + case PyUnicode_1BYTE_KIND: + PyUnicode_1BYTE_DATA(unicode)[0] = (Py_UCS1)ch; + break; + case PyUnicode_2BYTE_KIND: + PyUnicode_2BYTE_DATA(unicode)[0] = (Py_UCS2)ch; + break; + default: + assert(PyUnicode_KIND(unicode) == PyUnicode_4BYTE_KIND); + PyUnicode_4BYTE_DATA(unicode)[0] = ch; + } + assert(_PyUnicode_CheckConsistency(unicode, 1)); + return unicode; +} + PyObject * PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) { @@ -1964,22 +1988,8 @@ if (size == 0) _Py_RETURN_UNICODE_EMPTY(); assert(size > 0); - if (size == 1) { - Py_UCS4 ch = u[0]; - int kind; - void *data; - if (ch < 256) - return get_latin1_char((unsigned char)ch); - - res = PyUnicode_New(1, ch); - if (res == NULL) - return NULL; - kind = PyUnicode_KIND(res); - data = PyUnicode_DATA(res); - PyUnicode_WRITE(kind, data, 0, ch); - assert(_PyUnicode_CheckConsistency(res, 1)); - return res; - } + if (size == 1) + return unicode_char(u[0]); max_char = ucs2lib_find_max_char(u, u + size); res = PyUnicode_New(size, max_char); @@ -2004,22 +2014,8 @@ if (size == 0) _Py_RETURN_UNICODE_EMPTY(); assert(size > 0); - if (size == 1) { - Py_UCS4 ch = u[0]; - int kind; - void *data; - if (ch < 256) - return get_latin1_char((unsigned char)ch); - - res = PyUnicode_New(1, ch); - if (res == NULL) - return NULL; - kind = PyUnicode_KIND(res); - data = PyUnicode_DATA(res); - PyUnicode_WRITE(kind, data, 0, ch); - assert(_PyUnicode_CheckConsistency(res, 1)); - return res; - } + if (size == 1) + return unicode_char(u[0]); max_char = ucs4lib_find_max_char(u, u + size); res = PyUnicode_New(size, max_char); @@ -2887,17 +2883,7 @@ return NULL; } - if ((Py_UCS4)ordinal < 256) - return get_latin1_char((unsigned char)ordinal); - - v = PyUnicode_New(1, ordinal); - if (v == NULL) - return NULL; - kind = PyUnicode_KIND(v); - data = PyUnicode_DATA(v); - PyUnicode_WRITE(kind, data, 0, ordinal); - assert(_PyUnicode_CheckConsistency(v, 1)); - return v; + return unicode_char((Py_UCS4)ordinal); } PyObject * @@ -11354,17 +11340,7 @@ kind = PyUnicode_KIND(self); data = PyUnicode_DATA(self); ch = PyUnicode_READ(kind, data, index); - if (ch < 256) - return get_latin1_char(ch); - - res = PyUnicode_New(1, ch); - if (res == NULL) - return NULL; - kind = PyUnicode_KIND(res); - data = PyUnicode_DATA(res); - PyUnicode_WRITE(kind, data, 0, ch); - assert(_PyUnicode_CheckConsistency(res, 1)); - return res; + return unicode_char(ch); } /* Believe it or not, this produces the same value for ASCII strings -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 13:16:31 2014 From: python-checkins at python.org (victor.stinner) Date: Fri, 3 Jan 2014 13:16:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_unicode=5Fchar=28=29_uses_?= =?utf-8?q?get=5Flatin1=5Fchar=28=29_to_get_latin1_singleton_characters?= Message-ID: <3dwlTW2y2cz7Ljs@mail.python.org> http://hg.python.org/cpython/rev/fb8802277613 changeset: 88272:fb8802277613 user: Victor Stinner date: Fri Jan 03 13:16:00 2014 +0100 summary: unicode_char() uses get_latin1_char() to get latin1 singleton characters files: Objects/unicodeobject.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1772,6 +1772,9 @@ assert(ch <= MAX_UNICODE); + if (ch < 256) + return get_latin1_char(ch); + unicode = PyUnicode_New(1, ch); if (unicode == NULL) return NULL; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 14:11:02 2014 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 3 Jan 2014 14:11:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_*_Issue_=2316113=3A_Remove?= =?utf-8?q?_sha3_module_again=2E?= Message-ID: <3dwmhQ5pZlz7LjV@mail.python.org> http://hg.python.org/cpython/rev/52350d325b41 changeset: 88273:52350d325b41 user: Martin v. L?wis date: Fri Jan 03 14:05:06 2014 +0100 summary: * Issue #16113: Remove sha3 module again. Patch by Christian Heimes, with modifications. files: Doc/library/hashlib.rst | 6 +- Doc/license.rst | 19 - Doc/whatsnew/3.4.rst | 8 - Lib/hashlib.py | 10 +- Lib/test/test_hashlib.py | 112 +- Makefile.pre.in | 1 - Misc/NEWS | 2 + Modules/_sha3/cleanup.py | 49 - Modules/_sha3/keccak/KeccakF-1600-32-rvk.macros | 555 ---- Modules/_sha3/keccak/KeccakF-1600-32-s1.macros | 1187 ---------- Modules/_sha3/keccak/KeccakF-1600-32-s2.macros | 1187 ---------- Modules/_sha3/keccak/KeccakF-1600-32.macros | 26 - Modules/_sha3/keccak/KeccakF-1600-64.macros | 728 ------ Modules/_sha3/keccak/KeccakF-1600-int-set.h | 6 - Modules/_sha3/keccak/KeccakF-1600-interface.h | 46 - Modules/_sha3/keccak/KeccakF-1600-opt32-settings.h | 6 - Modules/_sha3/keccak/KeccakF-1600-opt32.c | 524 ---- Modules/_sha3/keccak/KeccakF-1600-opt64-settings.h | 9 - Modules/_sha3/keccak/KeccakF-1600-opt64.c | 510 ---- Modules/_sha3/keccak/KeccakF-1600-simd128.macros | 651 ----- Modules/_sha3/keccak/KeccakF-1600-simd64.macros | 517 ---- Modules/_sha3/keccak/KeccakF-1600-unrolling.macros | 124 - Modules/_sha3/keccak/KeccakF-1600-xop.macros | 573 ---- Modules/_sha3/keccak/KeccakNISTInterface.c | 83 - Modules/_sha3/keccak/KeccakNISTInterface.h | 72 - Modules/_sha3/keccak/KeccakSponge.c | 266 -- Modules/_sha3/keccak/KeccakSponge.h | 76 - Modules/_sha3/keccak/brg_endian.h | 142 - Modules/_sha3/keccak/crypto_hash.h | 0 Modules/_sha3/sha3module.c | 593 ---- PC/VS9.0/_sha3.vcproj | 513 ---- PC/VS9.0/pcbuild.sln | 2 - PCbuild/_sha3.vcxproj | 218 - PCbuild/_sha3.vcxproj.filters | 13 - PCbuild/pcbuild.sln | 4 - PCbuild/readme.txt | 1 - Tools/msi/msi.py | 1 - setup.py | 9 - 38 files changed, 5 insertions(+), 8844 deletions(-) diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -60,13 +60,9 @@ Constructors for hash algorithms that are always present in this module are :func:`md5`, :func:`sha1`, :func:`sha224`, :func:`sha256`, :func:`sha384`, -:func:`sha512`, :func:`sha3_224`, :func:`sha3_256`, :func:`sha3_384`, and -:func:`sha3_512`. Additional algorithms may also be available depending upon +and :func:`sha512`. Additional algorithms may also be available depending upon the OpenSSL library that Python uses on your platform. - .. versionchanged:: 3.4 - Added sha3 family of hash algorithms. - For example, to obtain the digest of the byte string ``b'Nobody inspects the spammish repetition'``:: diff --git a/Doc/license.rst b/Doc/license.rst --- a/Doc/license.rst +++ b/Doc/license.rst @@ -590,25 +590,6 @@ SUCH DAMAGE. -SHA-3 ------ - -The module :mod:`_sha3` and :mod:`hashlib` are using the reference -implementation of Keccak. The files at :file:`Modules/_sha3/keccak/` contain -the following note:: - - The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, - Micha?l Peeters and Gilles Van Assche. For more information, feedback or - questions, please refer to our website: http://keccak.noekeon.org/ - - Implementation by the designers, - hereby denoted as "the implementer". - - To the extent possible under law, the implementer has waived all copyright - and related or neighboring rights to the source code in this file. - http://creativecommons.org/publicdomain/zero/1.0/ - - SipHash24 --------- diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -123,8 +123,6 @@ * :ref:`Single-dispatch generic functions ` in :mod:`functools` (:pep:`443`). * New :mod:`pickle` :ref:`protocol 4 ` (:pep:`3154`). -* :ref:`SHA-3 (Keccak) support ` for :mod:`hashlib` - (:issue:`16113`). * :ref:`TLSv1.1 and TLSv1.2 support ` for :mod:`ssl` (:issue:`16692`). * :mod:`multiprocessing` now has :ref:`an option to avoid using os.fork @@ -667,12 +665,6 @@ New :func:`hashlib.pbkdf2_hmac` function. (Contributed by Christian Heimes in :issue:`18582`) -.. _whatsnew-sha3: - -New :ref:`hash algorithms ` ``sha3_224()``, ``sha3_256()``, -``sha3_384()``, and ``sha3_512()``. (Contributed by Christian Heimes in -:issue:`16113`.) - html ---- diff --git a/Lib/hashlib.py b/Lib/hashlib.py --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -54,8 +54,7 @@ # 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', - 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512') +__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') algorithms_guaranteed = set(__always_supported) algorithms_available = set(__always_supported) @@ -86,13 +85,6 @@ import _sha512 cache['SHA384'] = cache['sha384'] = _sha512.sha384 cache['SHA512'] = cache['sha512'] = _sha512.sha512 - elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', - 'SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512'}: - import _sha3 - cache['SHA3_224'] = cache['sha3_224'] = _sha3.sha3_224 - cache['SHA3_256'] = cache['sha3_256'] = _sha3.sha3_256 - cache['SHA3_384'] = cache['sha3_384'] = _sha3.sha3_384 - cache['SHA3_512'] = cache['sha3_512'] = _sha3.sha3_512 except ImportError: pass # no extension module, this hash is unsupported. diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -38,10 +38,7 @@ class HashLibTestCase(unittest.TestCase): supported_hash_names = ( 'md5', 'MD5', 'sha1', 'SHA1', 'sha224', 'SHA224', 'sha256', 'SHA256', - 'sha384', 'SHA384', 'sha512', 'SHA512', - 'sha3_224', 'sha3_256', 'sha3_384', - 'sha3_512', 'SHA3_224', 'SHA3_256', - 'SHA3_384', 'SHA3_512' ) + 'sha384', 'SHA384', 'sha512', 'SHA512') # Issue #14693: fallback modules are always compiled under POSIX _warn_on_extension_import = os.name == 'posix' or COMPILED_WITH_PYDEBUG @@ -102,12 +99,6 @@ if _sha512: add_builtin_constructor('sha384') add_builtin_constructor('sha512') - _sha3 = self._conditional_import_module('_sha3') - if _sha3: - add_builtin_constructor('sha3_224') - add_builtin_constructor('sha3_256') - add_builtin_constructor('sha3_384') - add_builtin_constructor('sha3_512') super(HashLibTestCase, self).__init__(*args, **kwargs) @@ -234,10 +225,6 @@ self.check_no_unicode('sha256') self.check_no_unicode('sha384') self.check_no_unicode('sha512') - self.check_no_unicode('sha3_224') - self.check_no_unicode('sha3_256') - self.check_no_unicode('sha3_384') - self.check_no_unicode('sha3_512') def check_blocksize_name(self, name, block_size=0, digest_size=0): constructors = self.constructors_to_test[name] @@ -257,10 +244,6 @@ self.check_blocksize_name('sha256', 64, 32) self.check_blocksize_name('sha384', 128, 48) self.check_blocksize_name('sha512', 128, 64) - self.check_blocksize_name('sha3_224', NotImplemented, 28) - self.check_blocksize_name('sha3_256', NotImplemented, 32) - self.check_blocksize_name('sha3_384', NotImplemented, 48) - self.check_blocksize_name('sha3_512', NotImplemented, 64) def test_case_md5_0(self): self.check('md5', b'', 'd41d8cd98f00b204e9800998ecf8427e') @@ -396,27 +379,6 @@ "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"+ "de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b") - # SHA-3 family - def test_case_sha3_224_0(self): - self.check('sha3_224', b"", - "F71837502BA8E10837BDD8D365ADB85591895602FC552B48B7390ABD") - - def test_case_sha3_224_1(self): - self.check('sha3_224', bytes.fromhex("CC"), - "A9CAB59EB40A10B246290F2D6086E32E3689FAF1D26B470C899F2802") - - def test_case_sha3_224_2(self): - self.check('sha3_224', bytes.fromhex("41FB"), - "615BA367AFDC35AAC397BC7EB5D58D106A734B24986D5D978FEFD62C") - - def test_case_sha3_224_3(self): - self.check('sha3_224', bytes.fromhex( - "433C5303131624C0021D868A30825475E8D0BD3052A022180398F4CA4423B9"+ - "8214B6BEAAC21C8807A2C33F8C93BD42B092CC1B06CEDF3224D5ED1EC29784"+ - "444F22E08A55AA58542B524B02CD3D5D5F6907AFE71C5D7462224A3F9D9E53"+ - "E7E0846DCBB4CE"), - "62B10F1B6236EBC2DA72957742A8D4E48E213B5F8934604BFD4D2C3A") - @bigmemtest(size=_4G + 5, memuse=1) def test_case_sha3_224_huge(self, size): if size == _4G + 5: @@ -426,78 +388,6 @@ except OverflowError: pass # 32-bit arch - - def test_case_sha3_256_0(self): - self.check('sha3_256', b"", - "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470") - - def test_case_sha3_256_1(self): - self.check('sha3_256', bytes.fromhex("CC"), - "EEAD6DBFC7340A56CAEDC044696A168870549A6A7F6F56961E84A54BD9970B8A") - - def test_case_sha3_256_2(self): - self.check('sha3_256', bytes.fromhex("41FB"), - "A8EACEDA4D47B3281A795AD9E1EA2122B407BAF9AABCB9E18B5717B7873537D2") - - def test_case_sha3_256_3(self): - self.check('sha3_256', bytes.fromhex( - "433C5303131624C0021D868A30825475E8D0BD3052A022180398F4CA4423B9"+ - "8214B6BEAAC21C8807A2C33F8C93BD42B092CC1B06CEDF3224D5ED1EC29784"+ - "444F22E08A55AA58542B524B02CD3D5D5F6907AFE71C5D7462224A3F9D9E53"+ - "E7E0846DCBB4CE"), - "CE87A5173BFFD92399221658F801D45C294D9006EE9F3F9D419C8D427748DC41") - - - def test_case_sha3_384_0(self): - self.check('sha3_384', b"", - "2C23146A63A29ACF99E73B88F8C24EAA7DC60AA771780CCC006AFBFA8FE2479B"+ - "2DD2B21362337441AC12B515911957FF") - - def test_case_sha3_384_1(self): - self.check('sha3_384', bytes.fromhex("CC"), - "1B84E62A46E5A201861754AF5DC95C4A1A69CAF4A796AE405680161E29572641"+ - "F5FA1E8641D7958336EE7B11C58F73E9") - - def test_case_sha3_384_2(self): - self.check('sha3_384', bytes.fromhex("41FB"), - "495CCE2714CD72C8C53C3363D22C58B55960FE26BE0BF3BBC7A3316DD563AD1D"+ - "B8410E75EEFEA655E39D4670EC0B1792") - - def test_case_sha3_384_3(self): - self.check('sha3_384', bytes.fromhex( - "433C5303131624C0021D868A30825475E8D0BD3052A022180398F4CA4423B9"+ - "8214B6BEAAC21C8807A2C33F8C93BD42B092CC1B06CEDF3224D5ED1EC29784"+ - "444F22E08A55AA58542B524B02CD3D5D5F6907AFE71C5D7462224A3F9D9E53"+ - "E7E0846DCBB4CE"), - "135114508DD63E279E709C26F7817C0482766CDE49132E3EDF2EEDD8996F4E35"+ - "96D184100B384868249F1D8B8FDAA2C9") - - - def test_case_sha3_512_0(self): - self.check('sha3_512', b"", - "0EAB42DE4C3CEB9235FC91ACFFE746B29C29A8C366B7C60E4E67C466F36A4304"+ - "C00FA9CAF9D87976BA469BCBE06713B435F091EF2769FB160CDAB33D3670680E") - - def test_case_sha3_512_1(self): - self.check('sha3_512', bytes.fromhex("CC"), - "8630C13CBD066EA74BBE7FE468FEC1DEE10EDC1254FB4C1B7C5FD69B646E4416"+ - "0B8CE01D05A0908CA790DFB080F4B513BC3B6225ECE7A810371441A5AC666EB9") - - def test_case_sha3_512_2(self): - self.check('sha3_512', bytes.fromhex("41FB"), - "551DA6236F8B96FCE9F97F1190E901324F0B45E06DBBB5CDB8355D6ED1DC34B3"+ - "F0EAE7DCB68622FF232FA3CECE0D4616CDEB3931F93803662A28DF1CD535B731") - - def test_case_sha3_512_3(self): - self.check('sha3_512', bytes.fromhex( - "433C5303131624C0021D868A30825475E8D0BD3052A022180398F4CA4423B9"+ - "8214B6BEAAC21C8807A2C33F8C93BD42B092CC1B06CEDF3224D5ED1EC29784"+ - "444F22E08A55AA58542B524B02CD3D5D5F6907AFE71C5D7462224A3F9D9E53"+ - "E7E0846DCBB4CE"), - "527D28E341E6B14F4684ADB4B824C496C6482E51149565D3D17226828884306B"+ - "51D6148A72622C2B75F5D3510B799D8BDC03EAEDE453676A6EC8FE03A1AD0EAB") - - def test_gil(self): # Check things work fine with an input larger than the size required # for multithreaded operation (which is hardwired to 2048). diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -501,7 +501,6 @@ : # remove 3rd party modules and system headers @lcov --remove $(COVERAGE_INFO) \ '*/Modules/_ctypes/libffi*/*' \ - '*/Modules/_sha3/keccak/*' \ '*/Modules/_decimal/libmpdec/*' \ '*/Modules/expat/*' \ '*/Modules/zlib/*' \ diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -46,6 +46,8 @@ Library ------- +- Issue #16113: Remove sha3 module again. + - Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix. - Fix breakage in TestSuite.countTestCases() introduced by issue #11798. diff --git a/Modules/_sha3/cleanup.py b/Modules/_sha3/cleanup.py deleted file mode 100755 --- a/Modules/_sha3/cleanup.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Christian Heimes (christian at python.org) -# Licensed to PSF under a Contributor Agreement. -# -# cleanup Keccak sources - -import os -import re - -CPP1 = re.compile("^//(.*)") -CPP2 = re.compile("\ //(.*)") - -STATICS = ("void ", "int ", "HashReturn ", "const UINT64 ", "UINT16 ") - -HERE = os.path.dirname(os.path.abspath(__file__)) -KECCAK = os.path.join(HERE, "keccak") - -def getfiles(): - for name in os.listdir(KECCAK): - name = os.path.join(KECCAK, name) - if os.path.isfile(name): - yield name - -def cleanup(f): - buf = [] - for line in f: - # mark all functions and global data as static - if line.startswith(STATICS): - buf.append("static " + line) - continue - # remove UINT64 typedef, we have our own - if line.startswith("typedef unsigned long long int"): - buf.append("/* %s */\n" % line.strip()) - continue - # remove #include "brg_endian.h" - if "brg_endian.h" in line: - buf.append("/* %s */\n" % line.strip()) - continue - # transform C++ comments into ANSI C comments - line = CPP1.sub(r"/* \1 */", line) - line = CPP2.sub(r" /* \1 */", line) - buf.append(line) - return "".join(buf) - -for name in getfiles(): - with open(name) as f: - res = cleanup(f) - with open(name, "w") as f: - f.write(res) diff --git a/Modules/_sha3/keccak/KeccakF-1600-32-rvk.macros b/Modules/_sha3/keccak/KeccakF-1600-32-rvk.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-32-rvk.macros +++ /dev/null @@ -1,555 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by Ronny Van Keer, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -static const UINT32 KeccakF1600RoundConstants_int2[2*24] = -{ - 0x00000001UL, 0x00000000UL, - 0x00000000UL, 0x00000089UL, - 0x00000000UL, 0x8000008bUL, - 0x00000000UL, 0x80008080UL, - 0x00000001UL, 0x0000008bUL, - 0x00000001UL, 0x00008000UL, - 0x00000001UL, 0x80008088UL, - 0x00000001UL, 0x80000082UL, - 0x00000000UL, 0x0000000bUL, - 0x00000000UL, 0x0000000aUL, - 0x00000001UL, 0x00008082UL, - 0x00000000UL, 0x00008003UL, - 0x00000001UL, 0x0000808bUL, - 0x00000001UL, 0x8000000bUL, - 0x00000001UL, 0x8000008aUL, - 0x00000001UL, 0x80000081UL, - 0x00000000UL, 0x80000081UL, - 0x00000000UL, 0x80000008UL, - 0x00000000UL, 0x00000083UL, - 0x00000000UL, 0x80008003UL, - 0x00000001UL, 0x80008088UL, - 0x00000000UL, 0x80000088UL, - 0x00000001UL, 0x00008000UL, - 0x00000000UL, 0x80008082UL -}; - -#undef rounds - -#define rounds \ -{ \ - UINT32 Da0, De0, Di0, Do0, Du0; \ - UINT32 Da1, De1, Di1, Do1, Du1; \ - UINT32 Ba, Be, Bi, Bo, Bu; \ - UINT32 Aba0, Abe0, Abi0, Abo0, Abu0; \ - UINT32 Aba1, Abe1, Abi1, Abo1, Abu1; \ - UINT32 Aga0, Age0, Agi0, Ago0, Agu0; \ - UINT32 Aga1, Age1, Agi1, Ago1, Agu1; \ - UINT32 Aka0, Ake0, Aki0, Ako0, Aku0; \ - UINT32 Aka1, Ake1, Aki1, Ako1, Aku1; \ - UINT32 Ama0, Ame0, Ami0, Amo0, Amu0; \ - UINT32 Ama1, Ame1, Ami1, Amo1, Amu1; \ - UINT32 Asa0, Ase0, Asi0, Aso0, Asu0; \ - UINT32 Asa1, Ase1, Asi1, Aso1, Asu1; \ - UINT32 Cw, Cx, Cy, Cz; \ - UINT32 Eba0, Ebe0, Ebi0, Ebo0, Ebu0; \ - UINT32 Eba1, Ebe1, Ebi1, Ebo1, Ebu1; \ - UINT32 Ega0, Ege0, Egi0, Ego0, Egu0; \ - UINT32 Ega1, Ege1, Egi1, Ego1, Egu1; \ - UINT32 Eka0, Eke0, Eki0, Eko0, Eku0; \ - UINT32 Eka1, Eke1, Eki1, Eko1, Eku1; \ - UINT32 Ema0, Eme0, Emi0, Emo0, Emu0; \ - UINT32 Ema1, Eme1, Emi1, Emo1, Emu1; \ - UINT32 Esa0, Ese0, Esi0, Eso0, Esu0; \ - UINT32 Esa1, Ese1, Esi1, Eso1, Esu1; \ - const UINT32 * pRoundConstants = KeccakF1600RoundConstants_int2; \ - UINT32 i; \ -\ - copyFromState(A, state) \ -\ - for( i = 12; i != 0; --i ) { \ - Cx = Abu0^Agu0^Aku0^Amu0^Asu0; \ - Du1 = Abe1^Age1^Ake1^Ame1^Ase1; \ - Da0 = Cx^ROL32(Du1, 1); \ - Cz = Abu1^Agu1^Aku1^Amu1^Asu1; \ - Du0 = Abe0^Age0^Ake0^Ame0^Ase0; \ - Da1 = Cz^Du0; \ -\ - Cw = Abi0^Agi0^Aki0^Ami0^Asi0; \ - Do0 = Cw^ROL32(Cz, 1); \ - Cy = Abi1^Agi1^Aki1^Ami1^Asi1; \ - Do1 = Cy^Cx; \ -\ - Cx = Aba0^Aga0^Aka0^Ama0^Asa0; \ - De0 = Cx^ROL32(Cy, 1); \ - Cz = Aba1^Aga1^Aka1^Ama1^Asa1; \ - De1 = Cz^Cw; \ -\ - Cy = Abo1^Ago1^Ako1^Amo1^Aso1; \ - Di0 = Du0^ROL32(Cy, 1); \ - Cw = Abo0^Ago0^Ako0^Amo0^Aso0; \ - Di1 = Du1^Cw; \ -\ - Du0 = Cw^ROL32(Cz, 1); \ - Du1 = Cy^Cx; \ -\ - Aba0 ^= Da0; \ - Ba = Aba0; \ - Age0 ^= De0; \ - Be = ROL32(Age0, 22); \ - Aki1 ^= Di1; \ - Bi = ROL32(Aki1, 22); \ - Amo1 ^= Do1; \ - Bo = ROL32(Amo1, 11); \ - Asu0 ^= Du0; \ - Bu = ROL32(Asu0, 7); \ - Eba0 = Ba ^((~Be)& Bi ) ^ *(pRoundConstants++); \ - Ebe0 = Be ^((~Bi)& Bo ); \ - Ebi0 = Bi ^((~Bo)& Bu ); \ - Ebo0 = Bo ^((~Bu)& Ba ); \ - Ebu0 = Bu ^((~Ba)& Be ); \ -\ - Abo0 ^= Do0; \ - Ba = ROL32(Abo0, 14); \ - Agu0 ^= Du0; \ - Be = ROL32(Agu0, 10); \ - Aka1 ^= Da1; \ - Bi = ROL32(Aka1, 2); \ - Ame1 ^= De1; \ - Bo = ROL32(Ame1, 23); \ - Asi1 ^= Di1; \ - Bu = ROL32(Asi1, 31); \ - Ega0 = Ba ^((~Be)& Bi ); \ - Ege0 = Be ^((~Bi)& Bo ); \ - Egi0 = Bi ^((~Bo)& Bu ); \ - Ego0 = Bo ^((~Bu)& Ba ); \ - Egu0 = Bu ^((~Ba)& Be ); \ -\ - Abe1 ^= De1; \ - Ba = ROL32(Abe1, 1); \ - Agi0 ^= Di0; \ - Be = ROL32(Agi0, 3); \ - Ako1 ^= Do1; \ - Bi = ROL32(Ako1, 13); \ - Amu0 ^= Du0; \ - Bo = ROL32(Amu0, 4); \ - Asa0 ^= Da0; \ - Bu = ROL32(Asa0, 9); \ - Eka0 = Ba ^((~Be)& Bi ); \ - Eke0 = Be ^((~Bi)& Bo ); \ - Eki0 = Bi ^((~Bo)& Bu ); \ - Eko0 = Bo ^((~Bu)& Ba ); \ - Eku0 = Bu ^((~Ba)& Be ); \ -\ - Abu1 ^= Du1; \ - Ba = ROL32(Abu1, 14); \ - Aga0 ^= Da0; \ - Be = ROL32(Aga0, 18); \ - Ake0 ^= De0; \ - Bi = ROL32(Ake0, 5); \ - Ami1 ^= Di1; \ - Bo = ROL32(Ami1, 8); \ - Aso0 ^= Do0; \ - Bu = ROL32(Aso0, 28); \ - Ema0 = Ba ^((~Be)& Bi ); \ - Eme0 = Be ^((~Bi)& Bo ); \ - Emi0 = Bi ^((~Bo)& Bu ); \ - Emo0 = Bo ^((~Bu)& Ba ); \ - Emu0 = Bu ^((~Ba)& Be ); \ -\ - Abi0 ^= Di0; \ - Ba = ROL32(Abi0, 31); \ - Ago1 ^= Do1; \ - Be = ROL32(Ago1, 28); \ - Aku1 ^= Du1; \ - Bi = ROL32(Aku1, 20); \ - Ama1 ^= Da1; \ - Bo = ROL32(Ama1, 21); \ - Ase0 ^= De0; \ - Bu = ROL32(Ase0, 1); \ - Esa0 = Ba ^((~Be)& Bi ); \ - Ese0 = Be ^((~Bi)& Bo ); \ - Esi0 = Bi ^((~Bo)& Bu ); \ - Eso0 = Bo ^((~Bu)& Ba ); \ - Esu0 = Bu ^((~Ba)& Be ); \ -\ - Aba1 ^= Da1; \ - Ba = Aba1; \ - Age1 ^= De1; \ - Be = ROL32(Age1, 22); \ - Aki0 ^= Di0; \ - Bi = ROL32(Aki0, 21); \ - Amo0 ^= Do0; \ - Bo = ROL32(Amo0, 10); \ - Asu1 ^= Du1; \ - Bu = ROL32(Asu1, 7); \ - Eba1 = Ba ^((~Be)& Bi ); \ - Eba1 ^= *(pRoundConstants++); \ - Ebe1 = Be ^((~Bi)& Bo ); \ - Ebi1 = Bi ^((~Bo)& Bu ); \ - Ebo1 = Bo ^((~Bu)& Ba ); \ - Ebu1 = Bu ^((~Ba)& Be ); \ -\ - Abo1 ^= Do1; \ - Ba = ROL32(Abo1, 14); \ - Agu1 ^= Du1; \ - Be = ROL32(Agu1, 10); \ - Aka0 ^= Da0; \ - Bi = ROL32(Aka0, 1); \ - Ame0 ^= De0; \ - Bo = ROL32(Ame0, 22); \ - Asi0 ^= Di0; \ - Bu = ROL32(Asi0, 30); \ - Ega1 = Ba ^((~Be)& Bi ); \ - Ege1 = Be ^((~Bi)& Bo ); \ - Egi1 = Bi ^((~Bo)& Bu ); \ - Ego1 = Bo ^((~Bu)& Ba ); \ - Egu1 = Bu ^((~Ba)& Be ); \ -\ - Abe0 ^= De0; \ - Ba = Abe0; \ - Agi1 ^= Di1; \ - Be = ROL32(Agi1, 3); \ - Ako0 ^= Do0; \ - Bi = ROL32(Ako0, 12); \ - Amu1 ^= Du1; \ - Bo = ROL32(Amu1, 4); \ - Asa1 ^= Da1; \ - Bu = ROL32(Asa1, 9); \ - Eka1 = Ba ^((~Be)& Bi ); \ - Eke1 = Be ^((~Bi)& Bo ); \ - Eki1 = Bi ^((~Bo)& Bu ); \ - Eko1 = Bo ^((~Bu)& Ba ); \ - Eku1 = Bu ^((~Ba)& Be ); \ -\ - Abu0 ^= Du0; \ - Ba = ROL32(Abu0, 13); \ - Aga1 ^= Da1; \ - Be = ROL32(Aga1, 18); \ - Ake1 ^= De1; \ - Bi = ROL32(Ake1, 5); \ - Ami0 ^= Di0; \ - Bo = ROL32(Ami0, 7); \ - Aso1 ^= Do1; \ - Bu = ROL32(Aso1, 28); \ - Ema1 = Ba ^((~Be)& Bi ); \ - Eme1 = Be ^((~Bi)& Bo ); \ - Emi1 = Bi ^((~Bo)& Bu ); \ - Emo1 = Bo ^((~Bu)& Ba ); \ - Emu1 = Bu ^((~Ba)& Be ); \ -\ - Abi1 ^= Di1; \ - Ba = ROL32(Abi1, 31); \ - Ago0 ^= Do0; \ - Be = ROL32(Ago0, 27); \ - Aku0 ^= Du0; \ - Bi = ROL32(Aku0, 19); \ - Ama0 ^= Da0; \ - Bo = ROL32(Ama0, 20); \ - Ase1 ^= De1; \ - Bu = ROL32(Ase1, 1); \ - Esa1 = Ba ^((~Be)& Bi ); \ - Ese1 = Be ^((~Bi)& Bo ); \ - Esi1 = Bi ^((~Bo)& Bu ); \ - Eso1 = Bo ^((~Bu)& Ba ); \ - Esu1 = Bu ^((~Ba)& Be ); \ -\ - Cx = Ebu0^Egu0^Eku0^Emu0^Esu0; \ - Du1 = Ebe1^Ege1^Eke1^Eme1^Ese1; \ - Da0 = Cx^ROL32(Du1, 1); \ - Cz = Ebu1^Egu1^Eku1^Emu1^Esu1; \ - Du0 = Ebe0^Ege0^Eke0^Eme0^Ese0; \ - Da1 = Cz^Du0; \ -\ - Cw = Ebi0^Egi0^Eki0^Emi0^Esi0; \ - Do0 = Cw^ROL32(Cz, 1); \ - Cy = Ebi1^Egi1^Eki1^Emi1^Esi1; \ - Do1 = Cy^Cx; \ -\ - Cx = Eba0^Ega0^Eka0^Ema0^Esa0; \ - De0 = Cx^ROL32(Cy, 1); \ - Cz = Eba1^Ega1^Eka1^Ema1^Esa1; \ - De1 = Cz^Cw; \ -\ - Cy = Ebo1^Ego1^Eko1^Emo1^Eso1; \ - Di0 = Du0^ROL32(Cy, 1); \ - Cw = Ebo0^Ego0^Eko0^Emo0^Eso0; \ - Di1 = Du1^Cw; \ -\ - Du0 = Cw^ROL32(Cz, 1); \ - Du1 = Cy^Cx; \ -\ - Eba0 ^= Da0; \ - Ba = Eba0; \ - Ege0 ^= De0; \ - Be = ROL32(Ege0, 22); \ - Eki1 ^= Di1; \ - Bi = ROL32(Eki1, 22); \ - Emo1 ^= Do1; \ - Bo = ROL32(Emo1, 11); \ - Esu0 ^= Du0; \ - Bu = ROL32(Esu0, 7); \ - Aba0 = Ba ^((~Be)& Bi ); \ - Aba0 ^= *(pRoundConstants++); \ - Abe0 = Be ^((~Bi)& Bo ); \ - Abi0 = Bi ^((~Bo)& Bu ); \ - Abo0 = Bo ^((~Bu)& Ba ); \ - Abu0 = Bu ^((~Ba)& Be ); \ -\ - Ebo0 ^= Do0; \ - Ba = ROL32(Ebo0, 14); \ - Egu0 ^= Du0; \ - Be = ROL32(Egu0, 10); \ - Eka1 ^= Da1; \ - Bi = ROL32(Eka1, 2); \ - Eme1 ^= De1; \ - Bo = ROL32(Eme1, 23); \ - Esi1 ^= Di1; \ - Bu = ROL32(Esi1, 31); \ - Aga0 = Ba ^((~Be)& Bi ); \ - Age0 = Be ^((~Bi)& Bo ); \ - Agi0 = Bi ^((~Bo)& Bu ); \ - Ago0 = Bo ^((~Bu)& Ba ); \ - Agu0 = Bu ^((~Ba)& Be ); \ -\ - Ebe1 ^= De1; \ - Ba = ROL32(Ebe1, 1); \ - Egi0 ^= Di0; \ - Be = ROL32(Egi0, 3); \ - Eko1 ^= Do1; \ - Bi = ROL32(Eko1, 13); \ - Emu0 ^= Du0; \ - Bo = ROL32(Emu0, 4); \ - Esa0 ^= Da0; \ - Bu = ROL32(Esa0, 9); \ - Aka0 = Ba ^((~Be)& Bi ); \ - Ake0 = Be ^((~Bi)& Bo ); \ - Aki0 = Bi ^((~Bo)& Bu ); \ - Ako0 = Bo ^((~Bu)& Ba ); \ - Aku0 = Bu ^((~Ba)& Be ); \ -\ - Ebu1 ^= Du1; \ - Ba = ROL32(Ebu1, 14); \ - Ega0 ^= Da0; \ - Be = ROL32(Ega0, 18); \ - Eke0 ^= De0; \ - Bi = ROL32(Eke0, 5); \ - Emi1 ^= Di1; \ - Bo = ROL32(Emi1, 8); \ - Eso0 ^= Do0; \ - Bu = ROL32(Eso0, 28); \ - Ama0 = Ba ^((~Be)& Bi ); \ - Ame0 = Be ^((~Bi)& Bo ); \ - Ami0 = Bi ^((~Bo)& Bu ); \ - Amo0 = Bo ^((~Bu)& Ba ); \ - Amu0 = Bu ^((~Ba)& Be ); \ -\ - Ebi0 ^= Di0; \ - Ba = ROL32(Ebi0, 31); \ - Ego1 ^= Do1; \ - Be = ROL32(Ego1, 28); \ - Eku1 ^= Du1; \ - Bi = ROL32(Eku1, 20); \ - Ema1 ^= Da1; \ - Bo = ROL32(Ema1, 21); \ - Ese0 ^= De0; \ - Bu = ROL32(Ese0, 1); \ - Asa0 = Ba ^((~Be)& Bi ); \ - Ase0 = Be ^((~Bi)& Bo ); \ - Asi0 = Bi ^((~Bo)& Bu ); \ - Aso0 = Bo ^((~Bu)& Ba ); \ - Asu0 = Bu ^((~Ba)& Be ); \ -\ - Eba1 ^= Da1; \ - Ba = Eba1; \ - Ege1 ^= De1; \ - Be = ROL32(Ege1, 22); \ - Eki0 ^= Di0; \ - Bi = ROL32(Eki0, 21); \ - Emo0 ^= Do0; \ - Bo = ROL32(Emo0, 10); \ - Esu1 ^= Du1; \ - Bu = ROL32(Esu1, 7); \ - Aba1 = Ba ^((~Be)& Bi ); \ - Aba1 ^= *(pRoundConstants++); \ - Abe1 = Be ^((~Bi)& Bo ); \ - Abi1 = Bi ^((~Bo)& Bu ); \ - Abo1 = Bo ^((~Bu)& Ba ); \ - Abu1 = Bu ^((~Ba)& Be ); \ -\ - Ebo1 ^= Do1; \ - Ba = ROL32(Ebo1, 14); \ - Egu1 ^= Du1; \ - Be = ROL32(Egu1, 10); \ - Eka0 ^= Da0; \ - Bi = ROL32(Eka0, 1); \ - Eme0 ^= De0; \ - Bo = ROL32(Eme0, 22); \ - Esi0 ^= Di0; \ - Bu = ROL32(Esi0, 30); \ - Aga1 = Ba ^((~Be)& Bi ); \ - Age1 = Be ^((~Bi)& Bo ); \ - Agi1 = Bi ^((~Bo)& Bu ); \ - Ago1 = Bo ^((~Bu)& Ba ); \ - Agu1 = Bu ^((~Ba)& Be ); \ -\ - Ebe0 ^= De0; \ - Ba = Ebe0; \ - Egi1 ^= Di1; \ - Be = ROL32(Egi1, 3); \ - Eko0 ^= Do0; \ - Bi = ROL32(Eko0, 12); \ - Emu1 ^= Du1; \ - Bo = ROL32(Emu1, 4); \ - Esa1 ^= Da1; \ - Bu = ROL32(Esa1, 9); \ - Aka1 = Ba ^((~Be)& Bi ); \ - Ake1 = Be ^((~Bi)& Bo ); \ - Aki1 = Bi ^((~Bo)& Bu ); \ - Ako1 = Bo ^((~Bu)& Ba ); \ - Aku1 = Bu ^((~Ba)& Be ); \ -\ - Ebu0 ^= Du0; \ - Ba = ROL32(Ebu0, 13); \ - Ega1 ^= Da1; \ - Be = ROL32(Ega1, 18); \ - Eke1 ^= De1; \ - Bi = ROL32(Eke1, 5); \ - Emi0 ^= Di0; \ - Bo = ROL32(Emi0, 7); \ - Eso1 ^= Do1; \ - Bu = ROL32(Eso1, 28); \ - Ama1 = Ba ^((~Be)& Bi ); \ - Ame1 = Be ^((~Bi)& Bo ); \ - Ami1 = Bi ^((~Bo)& Bu ); \ - Amo1 = Bo ^((~Bu)& Ba ); \ - Amu1 = Bu ^((~Ba)& Be ); \ -\ - Ebi1 ^= Di1; \ - Ba = ROL32(Ebi1, 31); \ - Ego0 ^= Do0; \ - Be = ROL32(Ego0, 27); \ - Eku0 ^= Du0; \ - Bi = ROL32(Eku0, 19); \ - Ema0 ^= Da0; \ - Bo = ROL32(Ema0, 20); \ - Ese1 ^= De1; \ - Bu = ROL32(Ese1, 1); \ - Asa1 = Ba ^((~Be)& Bi ); \ - Ase1 = Be ^((~Bi)& Bo ); \ - Asi1 = Bi ^((~Bo)& Bu ); \ - Aso1 = Bo ^((~Bu)& Ba ); \ - Asu1 = Bu ^((~Ba)& Be ); \ - } \ - copyToState(state, A) \ -} - -#define copyFromState(X, state) \ - X##ba0 = state[ 0]; \ - X##ba1 = state[ 1]; \ - X##be0 = state[ 2]; \ - X##be1 = state[ 3]; \ - X##bi0 = state[ 4]; \ - X##bi1 = state[ 5]; \ - X##bo0 = state[ 6]; \ - X##bo1 = state[ 7]; \ - X##bu0 = state[ 8]; \ - X##bu1 = state[ 9]; \ - X##ga0 = state[10]; \ - X##ga1 = state[11]; \ - X##ge0 = state[12]; \ - X##ge1 = state[13]; \ - X##gi0 = state[14]; \ - X##gi1 = state[15]; \ - X##go0 = state[16]; \ - X##go1 = state[17]; \ - X##gu0 = state[18]; \ - X##gu1 = state[19]; \ - X##ka0 = state[20]; \ - X##ka1 = state[21]; \ - X##ke0 = state[22]; \ - X##ke1 = state[23]; \ - X##ki0 = state[24]; \ - X##ki1 = state[25]; \ - X##ko0 = state[26]; \ - X##ko1 = state[27]; \ - X##ku0 = state[28]; \ - X##ku1 = state[29]; \ - X##ma0 = state[30]; \ - X##ma1 = state[31]; \ - X##me0 = state[32]; \ - X##me1 = state[33]; \ - X##mi0 = state[34]; \ - X##mi1 = state[35]; \ - X##mo0 = state[36]; \ - X##mo1 = state[37]; \ - X##mu0 = state[38]; \ - X##mu1 = state[39]; \ - X##sa0 = state[40]; \ - X##sa1 = state[41]; \ - X##se0 = state[42]; \ - X##se1 = state[43]; \ - X##si0 = state[44]; \ - X##si1 = state[45]; \ - X##so0 = state[46]; \ - X##so1 = state[47]; \ - X##su0 = state[48]; \ - X##su1 = state[49]; \ - -#define copyToState(state, X) \ - state[ 0] = X##ba0; \ - state[ 1] = X##ba1; \ - state[ 2] = X##be0; \ - state[ 3] = X##be1; \ - state[ 4] = X##bi0; \ - state[ 5] = X##bi1; \ - state[ 6] = X##bo0; \ - state[ 7] = X##bo1; \ - state[ 8] = X##bu0; \ - state[ 9] = X##bu1; \ - state[10] = X##ga0; \ - state[11] = X##ga1; \ - state[12] = X##ge0; \ - state[13] = X##ge1; \ - state[14] = X##gi0; \ - state[15] = X##gi1; \ - state[16] = X##go0; \ - state[17] = X##go1; \ - state[18] = X##gu0; \ - state[19] = X##gu1; \ - state[20] = X##ka0; \ - state[21] = X##ka1; \ - state[22] = X##ke0; \ - state[23] = X##ke1; \ - state[24] = X##ki0; \ - state[25] = X##ki1; \ - state[26] = X##ko0; \ - state[27] = X##ko1; \ - state[28] = X##ku0; \ - state[29] = X##ku1; \ - state[30] = X##ma0; \ - state[31] = X##ma1; \ - state[32] = X##me0; \ - state[33] = X##me1; \ - state[34] = X##mi0; \ - state[35] = X##mi1; \ - state[36] = X##mo0; \ - state[37] = X##mo1; \ - state[38] = X##mu0; \ - state[39] = X##mu1; \ - state[40] = X##sa0; \ - state[41] = X##sa1; \ - state[42] = X##se0; \ - state[43] = X##se1; \ - state[44] = X##si0; \ - state[45] = X##si1; \ - state[46] = X##so0; \ - state[47] = X##so1; \ - state[48] = X##su0; \ - state[49] = X##su1; \ - diff --git a/Modules/_sha3/keccak/KeccakF-1600-32-s1.macros b/Modules/_sha3/keccak/KeccakF-1600-32-s1.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-32-s1.macros +++ /dev/null @@ -1,1187 +0,0 @@ -/* -Code automatically generated by KeccakTools! - -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define declareABCDE \ - UINT32 Aba0, Abe0, Abi0, Abo0, Abu0; \ - UINT32 Aba1, Abe1, Abi1, Abo1, Abu1; \ - UINT32 Aga0, Age0, Agi0, Ago0, Agu0; \ - UINT32 Aga1, Age1, Agi1, Ago1, Agu1; \ - UINT32 Aka0, Ake0, Aki0, Ako0, Aku0; \ - UINT32 Aka1, Ake1, Aki1, Ako1, Aku1; \ - UINT32 Ama0, Ame0, Ami0, Amo0, Amu0; \ - UINT32 Ama1, Ame1, Ami1, Amo1, Amu1; \ - UINT32 Asa0, Ase0, Asi0, Aso0, Asu0; \ - UINT32 Asa1, Ase1, Asi1, Aso1, Asu1; \ - UINT32 Bba0, Bbe0, Bbi0, Bbo0, Bbu0; \ - UINT32 Bba1, Bbe1, Bbi1, Bbo1, Bbu1; \ - UINT32 Bga0, Bge0, Bgi0, Bgo0, Bgu0; \ - UINT32 Bga1, Bge1, Bgi1, Bgo1, Bgu1; \ - UINT32 Bka0, Bke0, Bki0, Bko0, Bku0; \ - UINT32 Bka1, Bke1, Bki1, Bko1, Bku1; \ - UINT32 Bma0, Bme0, Bmi0, Bmo0, Bmu0; \ - UINT32 Bma1, Bme1, Bmi1, Bmo1, Bmu1; \ - UINT32 Bsa0, Bse0, Bsi0, Bso0, Bsu0; \ - UINT32 Bsa1, Bse1, Bsi1, Bso1, Bsu1; \ - UINT32 Ca0, Ce0, Ci0, Co0, Cu0; \ - UINT32 Ca1, Ce1, Ci1, Co1, Cu1; \ - UINT32 Da0, De0, Di0, Do0, Du0; \ - UINT32 Da1, De1, Di1, Do1, Du1; \ - UINT32 Eba0, Ebe0, Ebi0, Ebo0, Ebu0; \ - UINT32 Eba1, Ebe1, Ebi1, Ebo1, Ebu1; \ - UINT32 Ega0, Ege0, Egi0, Ego0, Egu0; \ - UINT32 Ega1, Ege1, Egi1, Ego1, Egu1; \ - UINT32 Eka0, Eke0, Eki0, Eko0, Eku0; \ - UINT32 Eka1, Eke1, Eki1, Eko1, Eku1; \ - UINT32 Ema0, Eme0, Emi0, Emo0, Emu0; \ - UINT32 Ema1, Eme1, Emi1, Emo1, Emu1; \ - UINT32 Esa0, Ese0, Esi0, Eso0, Esu0; \ - UINT32 Esa1, Ese1, Esi1, Eso1, Esu1; \ - -#define prepareTheta \ - Ca0 = Aba0^Aga0^Aka0^Ama0^Asa0; \ - Ca1 = Aba1^Aga1^Aka1^Ama1^Asa1; \ - Ce0 = Abe0^Age0^Ake0^Ame0^Ase0; \ - Ce1 = Abe1^Age1^Ake1^Ame1^Ase1; \ - Ci0 = Abi0^Agi0^Aki0^Ami0^Asi0; \ - Ci1 = Abi1^Agi1^Aki1^Ami1^Asi1; \ - Co0 = Abo0^Ago0^Ako0^Amo0^Aso0; \ - Co1 = Abo1^Ago1^Ako1^Amo1^Aso1; \ - Cu0 = Abu0^Agu0^Aku0^Amu0^Asu0; \ - Cu1 = Abu1^Agu1^Aku1^Amu1^Asu1; \ - -#ifdef UseBebigokimisa -/* --- Code for round, with prepare-theta (lane complementing pattern 'bebigokimisa') */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##ba0 = Bba0 ^( Bbe0 | Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - Ca0 = E##ba0; \ - E##be0 = Bbe0 ^((~Bbi0)| Bbo0 ); \ - Ce0 = E##be0; \ - E##bi0 = Bbi0 ^( Bbo0 & Bbu0 ); \ - Ci0 = E##bi0; \ - E##bo0 = Bbo0 ^( Bbu0 | Bba0 ); \ - Co0 = E##bo0; \ - E##bu0 = Bbu0 ^( Bba0 & Bbe0 ); \ - Cu0 = E##bu0; \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##ba1 = Bba1 ^( Bbe1 | Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - Ca1 = E##ba1; \ - E##be1 = Bbe1 ^((~Bbi1)| Bbo1 ); \ - Ce1 = E##be1; \ - E##bi1 = Bbi1 ^( Bbo1 & Bbu1 ); \ - Ci1 = E##bi1; \ - E##bo1 = Bbo1 ^( Bbu1 | Bba1 ); \ - Co1 = E##bo1; \ - E##bu1 = Bbu1 ^( Bba1 & Bbe1 ); \ - Cu1 = E##bu1; \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##ga0 = Bga0 ^( Bge0 | Bgi0 ); \ - Ca0 ^= E##ga0; \ - E##ge0 = Bge0 ^( Bgi0 & Bgo0 ); \ - Ce0 ^= E##ge0; \ - E##gi0 = Bgi0 ^( Bgo0 |(~Bgu0)); \ - Ci0 ^= E##gi0; \ - E##go0 = Bgo0 ^( Bgu0 | Bga0 ); \ - Co0 ^= E##go0; \ - E##gu0 = Bgu0 ^( Bga0 & Bge0 ); \ - Cu0 ^= E##gu0; \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##ga1 = Bga1 ^( Bge1 | Bgi1 ); \ - Ca1 ^= E##ga1; \ - E##ge1 = Bge1 ^( Bgi1 & Bgo1 ); \ - Ce1 ^= E##ge1; \ - E##gi1 = Bgi1 ^( Bgo1 |(~Bgu1)); \ - Ci1 ^= E##gi1; \ - E##go1 = Bgo1 ^( Bgu1 | Bga1 ); \ - Co1 ^= E##go1; \ - E##gu1 = Bgu1 ^( Bga1 & Bge1 ); \ - Cu1 ^= E##gu1; \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ka0 = Bka0 ^( Bke0 | Bki0 ); \ - Ca0 ^= E##ka0; \ - E##ke0 = Bke0 ^( Bki0 & Bko0 ); \ - Ce0 ^= E##ke0; \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - Ci0 ^= E##ki0; \ - E##ko0 = (~Bko0)^( Bku0 | Bka0 ); \ - Co0 ^= E##ko0; \ - E##ku0 = Bku0 ^( Bka0 & Bke0 ); \ - Cu0 ^= E##ku0; \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ka1 = Bka1 ^( Bke1 | Bki1 ); \ - Ca1 ^= E##ka1; \ - E##ke1 = Bke1 ^( Bki1 & Bko1 ); \ - Ce1 ^= E##ke1; \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - Ci1 ^= E##ki1; \ - E##ko1 = (~Bko1)^( Bku1 | Bka1 ); \ - Co1 ^= E##ko1; \ - E##ku1 = Bku1 ^( Bka1 & Bke1 ); \ - Cu1 ^= E##ku1; \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##ma0 = Bma0 ^( Bme0 & Bmi0 ); \ - Ca0 ^= E##ma0; \ - E##me0 = Bme0 ^( Bmi0 | Bmo0 ); \ - Ce0 ^= E##me0; \ - E##mi0 = Bmi0 ^((~Bmo0)| Bmu0 ); \ - Ci0 ^= E##mi0; \ - E##mo0 = (~Bmo0)^( Bmu0 & Bma0 ); \ - Co0 ^= E##mo0; \ - E##mu0 = Bmu0 ^( Bma0 | Bme0 ); \ - Cu0 ^= E##mu0; \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##ma1 = Bma1 ^( Bme1 & Bmi1 ); \ - Ca1 ^= E##ma1; \ - E##me1 = Bme1 ^( Bmi1 | Bmo1 ); \ - Ce1 ^= E##me1; \ - E##mi1 = Bmi1 ^((~Bmo1)| Bmu1 ); \ - Ci1 ^= E##mi1; \ - E##mo1 = (~Bmo1)^( Bmu1 & Bma1 ); \ - Co1 ^= E##mo1; \ - E##mu1 = Bmu1 ^( Bma1 | Bme1 ); \ - Cu1 ^= E##mu1; \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - Ca0 ^= E##sa0; \ - E##se0 = (~Bse0)^( Bsi0 | Bso0 ); \ - Ce0 ^= E##se0; \ - E##si0 = Bsi0 ^( Bso0 & Bsu0 ); \ - Ci0 ^= E##si0; \ - E##so0 = Bso0 ^( Bsu0 | Bsa0 ); \ - Co0 ^= E##so0; \ - E##su0 = Bsu0 ^( Bsa0 & Bse0 ); \ - Cu0 ^= E##su0; \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - Ca1 ^= E##sa1; \ - E##se1 = (~Bse1)^( Bsi1 | Bso1 ); \ - Ce1 ^= E##se1; \ - E##si1 = Bsi1 ^( Bso1 & Bsu1 ); \ - Ci1 ^= E##si1; \ - E##so1 = Bso1 ^( Bsu1 | Bsa1 ); \ - Co1 ^= E##so1; \ - E##su1 = Bsu1 ^( Bsa1 & Bse1 ); \ - Cu1 ^= E##su1; \ -\ - -/* --- Code for round (lane complementing pattern 'bebigokimisa') */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIota(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##ba0 = Bba0 ^( Bbe0 | Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - E##be0 = Bbe0 ^((~Bbi0)| Bbo0 ); \ - E##bi0 = Bbi0 ^( Bbo0 & Bbu0 ); \ - E##bo0 = Bbo0 ^( Bbu0 | Bba0 ); \ - E##bu0 = Bbu0 ^( Bba0 & Bbe0 ); \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##ba1 = Bba1 ^( Bbe1 | Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - E##be1 = Bbe1 ^((~Bbi1)| Bbo1 ); \ - E##bi1 = Bbi1 ^( Bbo1 & Bbu1 ); \ - E##bo1 = Bbo1 ^( Bbu1 | Bba1 ); \ - E##bu1 = Bbu1 ^( Bba1 & Bbe1 ); \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##ga0 = Bga0 ^( Bge0 | Bgi0 ); \ - E##ge0 = Bge0 ^( Bgi0 & Bgo0 ); \ - E##gi0 = Bgi0 ^( Bgo0 |(~Bgu0)); \ - E##go0 = Bgo0 ^( Bgu0 | Bga0 ); \ - E##gu0 = Bgu0 ^( Bga0 & Bge0 ); \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##ga1 = Bga1 ^( Bge1 | Bgi1 ); \ - E##ge1 = Bge1 ^( Bgi1 & Bgo1 ); \ - E##gi1 = Bgi1 ^( Bgo1 |(~Bgu1)); \ - E##go1 = Bgo1 ^( Bgu1 | Bga1 ); \ - E##gu1 = Bgu1 ^( Bga1 & Bge1 ); \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ka0 = Bka0 ^( Bke0 | Bki0 ); \ - E##ke0 = Bke0 ^( Bki0 & Bko0 ); \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - E##ko0 = (~Bko0)^( Bku0 | Bka0 ); \ - E##ku0 = Bku0 ^( Bka0 & Bke0 ); \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ka1 = Bka1 ^( Bke1 | Bki1 ); \ - E##ke1 = Bke1 ^( Bki1 & Bko1 ); \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - E##ko1 = (~Bko1)^( Bku1 | Bka1 ); \ - E##ku1 = Bku1 ^( Bka1 & Bke1 ); \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##ma0 = Bma0 ^( Bme0 & Bmi0 ); \ - E##me0 = Bme0 ^( Bmi0 | Bmo0 ); \ - E##mi0 = Bmi0 ^((~Bmo0)| Bmu0 ); \ - E##mo0 = (~Bmo0)^( Bmu0 & Bma0 ); \ - E##mu0 = Bmu0 ^( Bma0 | Bme0 ); \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##ma1 = Bma1 ^( Bme1 & Bmi1 ); \ - E##me1 = Bme1 ^( Bmi1 | Bmo1 ); \ - E##mi1 = Bmi1 ^((~Bmo1)| Bmu1 ); \ - E##mo1 = (~Bmo1)^( Bmu1 & Bma1 ); \ - E##mu1 = Bmu1 ^( Bma1 | Bme1 ); \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - E##se0 = (~Bse0)^( Bsi0 | Bso0 ); \ - E##si0 = Bsi0 ^( Bso0 & Bsu0 ); \ - E##so0 = Bso0 ^( Bsu0 | Bsa0 ); \ - E##su0 = Bsu0 ^( Bsa0 & Bse0 ); \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - E##se1 = (~Bse1)^( Bsi1 | Bso1 ); \ - E##si1 = Bsi1 ^( Bso1 & Bsu1 ); \ - E##so1 = Bso1 ^( Bsu1 | Bsa1 ); \ - E##su1 = Bsu1 ^( Bsa1 & Bse1 ); \ -\ - -#else /* UseBebigokimisa */ -/* --- Code for round, with prepare-theta */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##ba0 = Bba0 ^((~Bbe0)& Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - Ca0 = E##ba0; \ - E##be0 = Bbe0 ^((~Bbi0)& Bbo0 ); \ - Ce0 = E##be0; \ - E##bi0 = Bbi0 ^((~Bbo0)& Bbu0 ); \ - Ci0 = E##bi0; \ - E##bo0 = Bbo0 ^((~Bbu0)& Bba0 ); \ - Co0 = E##bo0; \ - E##bu0 = Bbu0 ^((~Bba0)& Bbe0 ); \ - Cu0 = E##bu0; \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##ba1 = Bba1 ^((~Bbe1)& Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - Ca1 = E##ba1; \ - E##be1 = Bbe1 ^((~Bbi1)& Bbo1 ); \ - Ce1 = E##be1; \ - E##bi1 = Bbi1 ^((~Bbo1)& Bbu1 ); \ - Ci1 = E##bi1; \ - E##bo1 = Bbo1 ^((~Bbu1)& Bba1 ); \ - Co1 = E##bo1; \ - E##bu1 = Bbu1 ^((~Bba1)& Bbe1 ); \ - Cu1 = E##bu1; \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##ga0 = Bga0 ^((~Bge0)& Bgi0 ); \ - Ca0 ^= E##ga0; \ - E##ge0 = Bge0 ^((~Bgi0)& Bgo0 ); \ - Ce0 ^= E##ge0; \ - E##gi0 = Bgi0 ^((~Bgo0)& Bgu0 ); \ - Ci0 ^= E##gi0; \ - E##go0 = Bgo0 ^((~Bgu0)& Bga0 ); \ - Co0 ^= E##go0; \ - E##gu0 = Bgu0 ^((~Bga0)& Bge0 ); \ - Cu0 ^= E##gu0; \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##ga1 = Bga1 ^((~Bge1)& Bgi1 ); \ - Ca1 ^= E##ga1; \ - E##ge1 = Bge1 ^((~Bgi1)& Bgo1 ); \ - Ce1 ^= E##ge1; \ - E##gi1 = Bgi1 ^((~Bgo1)& Bgu1 ); \ - Ci1 ^= E##gi1; \ - E##go1 = Bgo1 ^((~Bgu1)& Bga1 ); \ - Co1 ^= E##go1; \ - E##gu1 = Bgu1 ^((~Bga1)& Bge1 ); \ - Cu1 ^= E##gu1; \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ka0 = Bka0 ^((~Bke0)& Bki0 ); \ - Ca0 ^= E##ka0; \ - E##ke0 = Bke0 ^((~Bki0)& Bko0 ); \ - Ce0 ^= E##ke0; \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - Ci0 ^= E##ki0; \ - E##ko0 = Bko0 ^((~Bku0)& Bka0 ); \ - Co0 ^= E##ko0; \ - E##ku0 = Bku0 ^((~Bka0)& Bke0 ); \ - Cu0 ^= E##ku0; \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ka1 = Bka1 ^((~Bke1)& Bki1 ); \ - Ca1 ^= E##ka1; \ - E##ke1 = Bke1 ^((~Bki1)& Bko1 ); \ - Ce1 ^= E##ke1; \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - Ci1 ^= E##ki1; \ - E##ko1 = Bko1 ^((~Bku1)& Bka1 ); \ - Co1 ^= E##ko1; \ - E##ku1 = Bku1 ^((~Bka1)& Bke1 ); \ - Cu1 ^= E##ku1; \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##ma0 = Bma0 ^((~Bme0)& Bmi0 ); \ - Ca0 ^= E##ma0; \ - E##me0 = Bme0 ^((~Bmi0)& Bmo0 ); \ - Ce0 ^= E##me0; \ - E##mi0 = Bmi0 ^((~Bmo0)& Bmu0 ); \ - Ci0 ^= E##mi0; \ - E##mo0 = Bmo0 ^((~Bmu0)& Bma0 ); \ - Co0 ^= E##mo0; \ - E##mu0 = Bmu0 ^((~Bma0)& Bme0 ); \ - Cu0 ^= E##mu0; \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##ma1 = Bma1 ^((~Bme1)& Bmi1 ); \ - Ca1 ^= E##ma1; \ - E##me1 = Bme1 ^((~Bmi1)& Bmo1 ); \ - Ce1 ^= E##me1; \ - E##mi1 = Bmi1 ^((~Bmo1)& Bmu1 ); \ - Ci1 ^= E##mi1; \ - E##mo1 = Bmo1 ^((~Bmu1)& Bma1 ); \ - Co1 ^= E##mo1; \ - E##mu1 = Bmu1 ^((~Bma1)& Bme1 ); \ - Cu1 ^= E##mu1; \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - Ca0 ^= E##sa0; \ - E##se0 = Bse0 ^((~Bsi0)& Bso0 ); \ - Ce0 ^= E##se0; \ - E##si0 = Bsi0 ^((~Bso0)& Bsu0 ); \ - Ci0 ^= E##si0; \ - E##so0 = Bso0 ^((~Bsu0)& Bsa0 ); \ - Co0 ^= E##so0; \ - E##su0 = Bsu0 ^((~Bsa0)& Bse0 ); \ - Cu0 ^= E##su0; \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - Ca1 ^= E##sa1; \ - E##se1 = Bse1 ^((~Bsi1)& Bso1 ); \ - Ce1 ^= E##se1; \ - E##si1 = Bsi1 ^((~Bso1)& Bsu1 ); \ - Ci1 ^= E##si1; \ - E##so1 = Bso1 ^((~Bsu1)& Bsa1 ); \ - Co1 ^= E##so1; \ - E##su1 = Bsu1 ^((~Bsa1)& Bse1 ); \ - Cu1 ^= E##su1; \ -\ - -/* --- Code for round */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIota(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##ba0 = Bba0 ^((~Bbe0)& Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - E##be0 = Bbe0 ^((~Bbi0)& Bbo0 ); \ - E##bi0 = Bbi0 ^((~Bbo0)& Bbu0 ); \ - E##bo0 = Bbo0 ^((~Bbu0)& Bba0 ); \ - E##bu0 = Bbu0 ^((~Bba0)& Bbe0 ); \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##ba1 = Bba1 ^((~Bbe1)& Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - E##be1 = Bbe1 ^((~Bbi1)& Bbo1 ); \ - E##bi1 = Bbi1 ^((~Bbo1)& Bbu1 ); \ - E##bo1 = Bbo1 ^((~Bbu1)& Bba1 ); \ - E##bu1 = Bbu1 ^((~Bba1)& Bbe1 ); \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##ga0 = Bga0 ^((~Bge0)& Bgi0 ); \ - E##ge0 = Bge0 ^((~Bgi0)& Bgo0 ); \ - E##gi0 = Bgi0 ^((~Bgo0)& Bgu0 ); \ - E##go0 = Bgo0 ^((~Bgu0)& Bga0 ); \ - E##gu0 = Bgu0 ^((~Bga0)& Bge0 ); \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##ga1 = Bga1 ^((~Bge1)& Bgi1 ); \ - E##ge1 = Bge1 ^((~Bgi1)& Bgo1 ); \ - E##gi1 = Bgi1 ^((~Bgo1)& Bgu1 ); \ - E##go1 = Bgo1 ^((~Bgu1)& Bga1 ); \ - E##gu1 = Bgu1 ^((~Bga1)& Bge1 ); \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ka0 = Bka0 ^((~Bke0)& Bki0 ); \ - E##ke0 = Bke0 ^((~Bki0)& Bko0 ); \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - E##ko0 = Bko0 ^((~Bku0)& Bka0 ); \ - E##ku0 = Bku0 ^((~Bka0)& Bke0 ); \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ka1 = Bka1 ^((~Bke1)& Bki1 ); \ - E##ke1 = Bke1 ^((~Bki1)& Bko1 ); \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - E##ko1 = Bko1 ^((~Bku1)& Bka1 ); \ - E##ku1 = Bku1 ^((~Bka1)& Bke1 ); \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##ma0 = Bma0 ^((~Bme0)& Bmi0 ); \ - E##me0 = Bme0 ^((~Bmi0)& Bmo0 ); \ - E##mi0 = Bmi0 ^((~Bmo0)& Bmu0 ); \ - E##mo0 = Bmo0 ^((~Bmu0)& Bma0 ); \ - E##mu0 = Bmu0 ^((~Bma0)& Bme0 ); \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##ma1 = Bma1 ^((~Bme1)& Bmi1 ); \ - E##me1 = Bme1 ^((~Bmi1)& Bmo1 ); \ - E##mi1 = Bmi1 ^((~Bmo1)& Bmu1 ); \ - E##mo1 = Bmo1 ^((~Bmu1)& Bma1 ); \ - E##mu1 = Bmu1 ^((~Bma1)& Bme1 ); \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - E##se0 = Bse0 ^((~Bsi0)& Bso0 ); \ - E##si0 = Bsi0 ^((~Bso0)& Bsu0 ); \ - E##so0 = Bso0 ^((~Bsu0)& Bsa0 ); \ - E##su0 = Bsu0 ^((~Bsa0)& Bse0 ); \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - E##se1 = Bse1 ^((~Bsi1)& Bso1 ); \ - E##si1 = Bsi1 ^((~Bso1)& Bsu1 ); \ - E##so1 = Bso1 ^((~Bsu1)& Bsa1 ); \ - E##su1 = Bsu1 ^((~Bsa1)& Bse1 ); \ -\ - -#endif /* UseBebigokimisa */ - -const UINT32 KeccakF1600RoundConstants_int2_0[24] = { - 0x00000001UL, - 0x00000000UL, - 0x00000000UL, - 0x00000000UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000000UL, - 0x00000000UL, - 0x00000001UL, - 0x00000000UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000000UL, - 0x00000000UL, - 0x00000000UL, - 0x00000000UL, - 0x00000001UL, - 0x00000000UL, - 0x00000001UL, - 0x00000000UL }; - -const UINT32 KeccakF1600RoundConstants_int2_1[24] = { - 0x00000000UL, - 0x00000089UL, - 0x8000008bUL, - 0x80008080UL, - 0x0000008bUL, - 0x00008000UL, - 0x80008088UL, - 0x80000082UL, - 0x0000000bUL, - 0x0000000aUL, - 0x00008082UL, - 0x00008003UL, - 0x0000808bUL, - 0x8000000bUL, - 0x8000008aUL, - 0x80000081UL, - 0x80000081UL, - 0x80000008UL, - 0x00000083UL, - 0x80008003UL, - 0x80008088UL, - 0x80000088UL, - 0x00008000UL, - 0x80008082UL }; - -#define copyFromStateAndXor1024bits(X, state, input) \ - X##ba0 = state[ 0]^input[ 0]; \ - X##ba1 = state[ 1]^input[ 1]; \ - X##be0 = state[ 2]^input[ 2]; \ - X##be1 = state[ 3]^input[ 3]; \ - X##bi0 = state[ 4]^input[ 4]; \ - X##bi1 = state[ 5]^input[ 5]; \ - X##bo0 = state[ 6]^input[ 6]; \ - X##bo1 = state[ 7]^input[ 7]; \ - X##bu0 = state[ 8]^input[ 8]; \ - X##bu1 = state[ 9]^input[ 9]; \ - X##ga0 = state[10]^input[10]; \ - X##ga1 = state[11]^input[11]; \ - X##ge0 = state[12]^input[12]; \ - X##ge1 = state[13]^input[13]; \ - X##gi0 = state[14]^input[14]; \ - X##gi1 = state[15]^input[15]; \ - X##go0 = state[16]^input[16]; \ - X##go1 = state[17]^input[17]; \ - X##gu0 = state[18]^input[18]; \ - X##gu1 = state[19]^input[19]; \ - X##ka0 = state[20]^input[20]; \ - X##ka1 = state[21]^input[21]; \ - X##ke0 = state[22]^input[22]; \ - X##ke1 = state[23]^input[23]; \ - X##ki0 = state[24]^input[24]; \ - X##ki1 = state[25]^input[25]; \ - X##ko0 = state[26]^input[26]; \ - X##ko1 = state[27]^input[27]; \ - X##ku0 = state[28]^input[28]; \ - X##ku1 = state[29]^input[29]; \ - X##ma0 = state[30]^input[30]; \ - X##ma1 = state[31]^input[31]; \ - X##me0 = state[32]; \ - X##me1 = state[33]; \ - X##mi0 = state[34]; \ - X##mi1 = state[35]; \ - X##mo0 = state[36]; \ - X##mo1 = state[37]; \ - X##mu0 = state[38]; \ - X##mu1 = state[39]; \ - X##sa0 = state[40]; \ - X##sa1 = state[41]; \ - X##se0 = state[42]; \ - X##se1 = state[43]; \ - X##si0 = state[44]; \ - X##si1 = state[45]; \ - X##so0 = state[46]; \ - X##so1 = state[47]; \ - X##su0 = state[48]; \ - X##su1 = state[49]; \ - -#define copyFromStateAndXor1088bits(X, state, input) \ - X##ba0 = state[ 0]^input[ 0]; \ - X##ba1 = state[ 1]^input[ 1]; \ - X##be0 = state[ 2]^input[ 2]; \ - X##be1 = state[ 3]^input[ 3]; \ - X##bi0 = state[ 4]^input[ 4]; \ - X##bi1 = state[ 5]^input[ 5]; \ - X##bo0 = state[ 6]^input[ 6]; \ - X##bo1 = state[ 7]^input[ 7]; \ - X##bu0 = state[ 8]^input[ 8]; \ - X##bu1 = state[ 9]^input[ 9]; \ - X##ga0 = state[10]^input[10]; \ - X##ga1 = state[11]^input[11]; \ - X##ge0 = state[12]^input[12]; \ - X##ge1 = state[13]^input[13]; \ - X##gi0 = state[14]^input[14]; \ - X##gi1 = state[15]^input[15]; \ - X##go0 = state[16]^input[16]; \ - X##go1 = state[17]^input[17]; \ - X##gu0 = state[18]^input[18]; \ - X##gu1 = state[19]^input[19]; \ - X##ka0 = state[20]^input[20]; \ - X##ka1 = state[21]^input[21]; \ - X##ke0 = state[22]^input[22]; \ - X##ke1 = state[23]^input[23]; \ - X##ki0 = state[24]^input[24]; \ - X##ki1 = state[25]^input[25]; \ - X##ko0 = state[26]^input[26]; \ - X##ko1 = state[27]^input[27]; \ - X##ku0 = state[28]^input[28]; \ - X##ku1 = state[29]^input[29]; \ - X##ma0 = state[30]^input[30]; \ - X##ma1 = state[31]^input[31]; \ - X##me0 = state[32]^input[32]; \ - X##me1 = state[33]^input[33]; \ - X##mi0 = state[34]; \ - X##mi1 = state[35]; \ - X##mo0 = state[36]; \ - X##mo1 = state[37]; \ - X##mu0 = state[38]; \ - X##mu1 = state[39]; \ - X##sa0 = state[40]; \ - X##sa1 = state[41]; \ - X##se0 = state[42]; \ - X##se1 = state[43]; \ - X##si0 = state[44]; \ - X##si1 = state[45]; \ - X##so0 = state[46]; \ - X##so1 = state[47]; \ - X##su0 = state[48]; \ - X##su1 = state[49]; \ - -#define copyFromState(X, state) \ - X##ba0 = state[ 0]; \ - X##ba1 = state[ 1]; \ - X##be0 = state[ 2]; \ - X##be1 = state[ 3]; \ - X##bi0 = state[ 4]; \ - X##bi1 = state[ 5]; \ - X##bo0 = state[ 6]; \ - X##bo1 = state[ 7]; \ - X##bu0 = state[ 8]; \ - X##bu1 = state[ 9]; \ - X##ga0 = state[10]; \ - X##ga1 = state[11]; \ - X##ge0 = state[12]; \ - X##ge1 = state[13]; \ - X##gi0 = state[14]; \ - X##gi1 = state[15]; \ - X##go0 = state[16]; \ - X##go1 = state[17]; \ - X##gu0 = state[18]; \ - X##gu1 = state[19]; \ - X##ka0 = state[20]; \ - X##ka1 = state[21]; \ - X##ke0 = state[22]; \ - X##ke1 = state[23]; \ - X##ki0 = state[24]; \ - X##ki1 = state[25]; \ - X##ko0 = state[26]; \ - X##ko1 = state[27]; \ - X##ku0 = state[28]; \ - X##ku1 = state[29]; \ - X##ma0 = state[30]; \ - X##ma1 = state[31]; \ - X##me0 = state[32]; \ - X##me1 = state[33]; \ - X##mi0 = state[34]; \ - X##mi1 = state[35]; \ - X##mo0 = state[36]; \ - X##mo1 = state[37]; \ - X##mu0 = state[38]; \ - X##mu1 = state[39]; \ - X##sa0 = state[40]; \ - X##sa1 = state[41]; \ - X##se0 = state[42]; \ - X##se1 = state[43]; \ - X##si0 = state[44]; \ - X##si1 = state[45]; \ - X##so0 = state[46]; \ - X##so1 = state[47]; \ - X##su0 = state[48]; \ - X##su1 = state[49]; \ - -#define copyToState(state, X) \ - state[ 0] = X##ba0; \ - state[ 1] = X##ba1; \ - state[ 2] = X##be0; \ - state[ 3] = X##be1; \ - state[ 4] = X##bi0; \ - state[ 5] = X##bi1; \ - state[ 6] = X##bo0; \ - state[ 7] = X##bo1; \ - state[ 8] = X##bu0; \ - state[ 9] = X##bu1; \ - state[10] = X##ga0; \ - state[11] = X##ga1; \ - state[12] = X##ge0; \ - state[13] = X##ge1; \ - state[14] = X##gi0; \ - state[15] = X##gi1; \ - state[16] = X##go0; \ - state[17] = X##go1; \ - state[18] = X##gu0; \ - state[19] = X##gu1; \ - state[20] = X##ka0; \ - state[21] = X##ka1; \ - state[22] = X##ke0; \ - state[23] = X##ke1; \ - state[24] = X##ki0; \ - state[25] = X##ki1; \ - state[26] = X##ko0; \ - state[27] = X##ko1; \ - state[28] = X##ku0; \ - state[29] = X##ku1; \ - state[30] = X##ma0; \ - state[31] = X##ma1; \ - state[32] = X##me0; \ - state[33] = X##me1; \ - state[34] = X##mi0; \ - state[35] = X##mi1; \ - state[36] = X##mo0; \ - state[37] = X##mo1; \ - state[38] = X##mu0; \ - state[39] = X##mu1; \ - state[40] = X##sa0; \ - state[41] = X##sa1; \ - state[42] = X##se0; \ - state[43] = X##se1; \ - state[44] = X##si0; \ - state[45] = X##si1; \ - state[46] = X##so0; \ - state[47] = X##so1; \ - state[48] = X##su0; \ - state[49] = X##su1; \ - -#define copyStateVariables(X, Y) \ - X##ba0 = Y##ba0; \ - X##ba1 = Y##ba1; \ - X##be0 = Y##be0; \ - X##be1 = Y##be1; \ - X##bi0 = Y##bi0; \ - X##bi1 = Y##bi1; \ - X##bo0 = Y##bo0; \ - X##bo1 = Y##bo1; \ - X##bu0 = Y##bu0; \ - X##bu1 = Y##bu1; \ - X##ga0 = Y##ga0; \ - X##ga1 = Y##ga1; \ - X##ge0 = Y##ge0; \ - X##ge1 = Y##ge1; \ - X##gi0 = Y##gi0; \ - X##gi1 = Y##gi1; \ - X##go0 = Y##go0; \ - X##go1 = Y##go1; \ - X##gu0 = Y##gu0; \ - X##gu1 = Y##gu1; \ - X##ka0 = Y##ka0; \ - X##ka1 = Y##ka1; \ - X##ke0 = Y##ke0; \ - X##ke1 = Y##ke1; \ - X##ki0 = Y##ki0; \ - X##ki1 = Y##ki1; \ - X##ko0 = Y##ko0; \ - X##ko1 = Y##ko1; \ - X##ku0 = Y##ku0; \ - X##ku1 = Y##ku1; \ - X##ma0 = Y##ma0; \ - X##ma1 = Y##ma1; \ - X##me0 = Y##me0; \ - X##me1 = Y##me1; \ - X##mi0 = Y##mi0; \ - X##mi1 = Y##mi1; \ - X##mo0 = Y##mo0; \ - X##mo1 = Y##mo1; \ - X##mu0 = Y##mu0; \ - X##mu1 = Y##mu1; \ - X##sa0 = Y##sa0; \ - X##sa1 = Y##sa1; \ - X##se0 = Y##se0; \ - X##se1 = Y##se1; \ - X##si0 = Y##si0; \ - X##si1 = Y##si1; \ - X##so0 = Y##so0; \ - X##so1 = Y##so1; \ - X##su0 = Y##su0; \ - X##su1 = Y##su1; \ - diff --git a/Modules/_sha3/keccak/KeccakF-1600-32-s2.macros b/Modules/_sha3/keccak/KeccakF-1600-32-s2.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-32-s2.macros +++ /dev/null @@ -1,1187 +0,0 @@ -/* -Code automatically generated by KeccakTools! - -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define declareABCDE \ - UINT32 Aba0, Abe0, Abi0, Abo0, Abu0; \ - UINT32 Aba1, Abe1, Abi1, Abo1, Abu1; \ - UINT32 Aga0, Age0, Agi0, Ago0, Agu0; \ - UINT32 Aga1, Age1, Agi1, Ago1, Agu1; \ - UINT32 Aka0, Ake0, Aki0, Ako0, Aku0; \ - UINT32 Aka1, Ake1, Aki1, Ako1, Aku1; \ - UINT32 Ama0, Ame0, Ami0, Amo0, Amu0; \ - UINT32 Ama1, Ame1, Ami1, Amo1, Amu1; \ - UINT32 Asa0, Ase0, Asi0, Aso0, Asu0; \ - UINT32 Asa1, Ase1, Asi1, Aso1, Asu1; \ - UINT32 Bba0, Bbe0, Bbi0, Bbo0, Bbu0; \ - UINT32 Bba1, Bbe1, Bbi1, Bbo1, Bbu1; \ - UINT32 Bga0, Bge0, Bgi0, Bgo0, Bgu0; \ - UINT32 Bga1, Bge1, Bgi1, Bgo1, Bgu1; \ - UINT32 Bka0, Bke0, Bki0, Bko0, Bku0; \ - UINT32 Bka1, Bke1, Bki1, Bko1, Bku1; \ - UINT32 Bma0, Bme0, Bmi0, Bmo0, Bmu0; \ - UINT32 Bma1, Bme1, Bmi1, Bmo1, Bmu1; \ - UINT32 Bsa0, Bse0, Bsi0, Bso0, Bsu0; \ - UINT32 Bsa1, Bse1, Bsi1, Bso1, Bsu1; \ - UINT32 Ca0, Ce0, Ci0, Co0, Cu0; \ - UINT32 Ca1, Ce1, Ci1, Co1, Cu1; \ - UINT32 Da0, De0, Di0, Do0, Du0; \ - UINT32 Da1, De1, Di1, Do1, Du1; \ - UINT32 Eba0, Ebe0, Ebi0, Ebo0, Ebu0; \ - UINT32 Eba1, Ebe1, Ebi1, Ebo1, Ebu1; \ - UINT32 Ega0, Ege0, Egi0, Ego0, Egu0; \ - UINT32 Ega1, Ege1, Egi1, Ego1, Egu1; \ - UINT32 Eka0, Eke0, Eki0, Eko0, Eku0; \ - UINT32 Eka1, Eke1, Eki1, Eko1, Eku1; \ - UINT32 Ema0, Eme0, Emi0, Emo0, Emu0; \ - UINT32 Ema1, Eme1, Emi1, Emo1, Emu1; \ - UINT32 Esa0, Ese0, Esi0, Eso0, Esu0; \ - UINT32 Esa1, Ese1, Esi1, Eso1, Esu1; \ - -#define prepareTheta \ - Ca0 = Aba0^Aga0^Aka0^Ama0^Asa0; \ - Ca1 = Aba1^Aga1^Aka1^Ama1^Asa1; \ - Ce0 = Abe0^Age0^Ake0^Ame0^Ase0; \ - Ce1 = Abe1^Age1^Ake1^Ame1^Ase1; \ - Ci0 = Abi0^Agi0^Aki0^Ami0^Asi0; \ - Ci1 = Abi1^Agi1^Aki1^Ami1^Asi1; \ - Co0 = Abo0^Ago0^Ako0^Amo0^Aso0; \ - Co1 = Abo1^Ago1^Ako1^Amo1^Aso1; \ - Cu0 = Abu0^Agu0^Aku0^Amu0^Asu0; \ - Cu1 = Abu1^Agu1^Aku1^Amu1^Asu1; \ - -#ifdef UseBebigokimisa -/* --- Code for round, with prepare-theta (lane complementing pattern 'bebigokimisa') */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - E##ba0 = Bba0 ^( Bbe0 | Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - Ca0 = E##ba0; \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - E##be0 = Bbe0 ^((~Bbi0)| Bbo0 ); \ - Ce0 = E##be0; \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##bi0 = Bbi0 ^( Bbo0 & Bbu0 ); \ - Ci0 = E##bi0; \ - E##bo0 = Bbo0 ^( Bbu0 | Bba0 ); \ - Co0 = E##bo0; \ - E##bu0 = Bbu0 ^( Bba0 & Bbe0 ); \ - Cu0 = E##bu0; \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - E##ba1 = Bba1 ^( Bbe1 | Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - Ca1 = E##ba1; \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - E##be1 = Bbe1 ^((~Bbi1)| Bbo1 ); \ - Ce1 = E##be1; \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##bi1 = Bbi1 ^( Bbo1 & Bbu1 ); \ - Ci1 = E##bi1; \ - E##bo1 = Bbo1 ^( Bbu1 | Bba1 ); \ - Co1 = E##bo1; \ - E##bu1 = Bbu1 ^( Bba1 & Bbe1 ); \ - Cu1 = E##bu1; \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - E##ga0 = Bga0 ^( Bge0 | Bgi0 ); \ - Ca0 ^= E##ga0; \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - E##ge0 = Bge0 ^( Bgi0 & Bgo0 ); \ - Ce0 ^= E##ge0; \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##gi0 = Bgi0 ^( Bgo0 |(~Bgu0)); \ - Ci0 ^= E##gi0; \ - E##go0 = Bgo0 ^( Bgu0 | Bga0 ); \ - Co0 ^= E##go0; \ - E##gu0 = Bgu0 ^( Bga0 & Bge0 ); \ - Cu0 ^= E##gu0; \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - E##ga1 = Bga1 ^( Bge1 | Bgi1 ); \ - Ca1 ^= E##ga1; \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - E##ge1 = Bge1 ^( Bgi1 & Bgo1 ); \ - Ce1 ^= E##ge1; \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##gi1 = Bgi1 ^( Bgo1 |(~Bgu1)); \ - Ci1 ^= E##gi1; \ - E##go1 = Bgo1 ^( Bgu1 | Bga1 ); \ - Co1 ^= E##go1; \ - E##gu1 = Bgu1 ^( Bga1 & Bge1 ); \ - Cu1 ^= E##gu1; \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - E##ka0 = Bka0 ^( Bke0 | Bki0 ); \ - Ca0 ^= E##ka0; \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - E##ke0 = Bke0 ^( Bki0 & Bko0 ); \ - Ce0 ^= E##ke0; \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - Ci0 ^= E##ki0; \ - E##ko0 = (~Bko0)^( Bku0 | Bka0 ); \ - Co0 ^= E##ko0; \ - E##ku0 = Bku0 ^( Bka0 & Bke0 ); \ - Cu0 ^= E##ku0; \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - E##ka1 = Bka1 ^( Bke1 | Bki1 ); \ - Ca1 ^= E##ka1; \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - E##ke1 = Bke1 ^( Bki1 & Bko1 ); \ - Ce1 ^= E##ke1; \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - Ci1 ^= E##ki1; \ - E##ko1 = (~Bko1)^( Bku1 | Bka1 ); \ - Co1 ^= E##ko1; \ - E##ku1 = Bku1 ^( Bka1 & Bke1 ); \ - Cu1 ^= E##ku1; \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - E##ma0 = Bma0 ^( Bme0 & Bmi0 ); \ - Ca0 ^= E##ma0; \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - E##me0 = Bme0 ^( Bmi0 | Bmo0 ); \ - Ce0 ^= E##me0; \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##mi0 = Bmi0 ^((~Bmo0)| Bmu0 ); \ - Ci0 ^= E##mi0; \ - E##mo0 = (~Bmo0)^( Bmu0 & Bma0 ); \ - Co0 ^= E##mo0; \ - E##mu0 = Bmu0 ^( Bma0 | Bme0 ); \ - Cu0 ^= E##mu0; \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - E##ma1 = Bma1 ^( Bme1 & Bmi1 ); \ - Ca1 ^= E##ma1; \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - E##me1 = Bme1 ^( Bmi1 | Bmo1 ); \ - Ce1 ^= E##me1; \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##mi1 = Bmi1 ^((~Bmo1)| Bmu1 ); \ - Ci1 ^= E##mi1; \ - E##mo1 = (~Bmo1)^( Bmu1 & Bma1 ); \ - Co1 ^= E##mo1; \ - E##mu1 = Bmu1 ^( Bma1 | Bme1 ); \ - Cu1 ^= E##mu1; \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - Ca0 ^= E##sa0; \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - E##se0 = (~Bse0)^( Bsi0 | Bso0 ); \ - Ce0 ^= E##se0; \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##si0 = Bsi0 ^( Bso0 & Bsu0 ); \ - Ci0 ^= E##si0; \ - E##so0 = Bso0 ^( Bsu0 | Bsa0 ); \ - Co0 ^= E##so0; \ - E##su0 = Bsu0 ^( Bsa0 & Bse0 ); \ - Cu0 ^= E##su0; \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - Ca1 ^= E##sa1; \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - E##se1 = (~Bse1)^( Bsi1 | Bso1 ); \ - Ce1 ^= E##se1; \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##si1 = Bsi1 ^( Bso1 & Bsu1 ); \ - Ci1 ^= E##si1; \ - E##so1 = Bso1 ^( Bsu1 | Bsa1 ); \ - Co1 ^= E##so1; \ - E##su1 = Bsu1 ^( Bsa1 & Bse1 ); \ - Cu1 ^= E##su1; \ -\ - -/* --- Code for round (lane complementing pattern 'bebigokimisa') */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIota(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - E##ba0 = Bba0 ^( Bbe0 | Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - E##be0 = Bbe0 ^((~Bbi0)| Bbo0 ); \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##bi0 = Bbi0 ^( Bbo0 & Bbu0 ); \ - E##bo0 = Bbo0 ^( Bbu0 | Bba0 ); \ - E##bu0 = Bbu0 ^( Bba0 & Bbe0 ); \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - E##ba1 = Bba1 ^( Bbe1 | Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - E##be1 = Bbe1 ^((~Bbi1)| Bbo1 ); \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##bi1 = Bbi1 ^( Bbo1 & Bbu1 ); \ - E##bo1 = Bbo1 ^( Bbu1 | Bba1 ); \ - E##bu1 = Bbu1 ^( Bba1 & Bbe1 ); \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - E##ga0 = Bga0 ^( Bge0 | Bgi0 ); \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - E##ge0 = Bge0 ^( Bgi0 & Bgo0 ); \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##gi0 = Bgi0 ^( Bgo0 |(~Bgu0)); \ - E##go0 = Bgo0 ^( Bgu0 | Bga0 ); \ - E##gu0 = Bgu0 ^( Bga0 & Bge0 ); \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - E##ga1 = Bga1 ^( Bge1 | Bgi1 ); \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - E##ge1 = Bge1 ^( Bgi1 & Bgo1 ); \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##gi1 = Bgi1 ^( Bgo1 |(~Bgu1)); \ - E##go1 = Bgo1 ^( Bgu1 | Bga1 ); \ - E##gu1 = Bgu1 ^( Bga1 & Bge1 ); \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - E##ka0 = Bka0 ^( Bke0 | Bki0 ); \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - E##ke0 = Bke0 ^( Bki0 & Bko0 ); \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - E##ko0 = (~Bko0)^( Bku0 | Bka0 ); \ - E##ku0 = Bku0 ^( Bka0 & Bke0 ); \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - E##ka1 = Bka1 ^( Bke1 | Bki1 ); \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - E##ke1 = Bke1 ^( Bki1 & Bko1 ); \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - E##ko1 = (~Bko1)^( Bku1 | Bka1 ); \ - E##ku1 = Bku1 ^( Bka1 & Bke1 ); \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - E##ma0 = Bma0 ^( Bme0 & Bmi0 ); \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - E##me0 = Bme0 ^( Bmi0 | Bmo0 ); \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##mi0 = Bmi0 ^((~Bmo0)| Bmu0 ); \ - E##mo0 = (~Bmo0)^( Bmu0 & Bma0 ); \ - E##mu0 = Bmu0 ^( Bma0 | Bme0 ); \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - E##ma1 = Bma1 ^( Bme1 & Bmi1 ); \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - E##me1 = Bme1 ^( Bmi1 | Bmo1 ); \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##mi1 = Bmi1 ^((~Bmo1)| Bmu1 ); \ - E##mo1 = (~Bmo1)^( Bmu1 & Bma1 ); \ - E##mu1 = Bmu1 ^( Bma1 | Bme1 ); \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - E##se0 = (~Bse0)^( Bsi0 | Bso0 ); \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##si0 = Bsi0 ^( Bso0 & Bsu0 ); \ - E##so0 = Bso0 ^( Bsu0 | Bsa0 ); \ - E##su0 = Bsu0 ^( Bsa0 & Bse0 ); \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - E##se1 = (~Bse1)^( Bsi1 | Bso1 ); \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##si1 = Bsi1 ^( Bso1 & Bsu1 ); \ - E##so1 = Bso1 ^( Bsu1 | Bsa1 ); \ - E##su1 = Bsu1 ^( Bsa1 & Bse1 ); \ -\ - -#else /* UseBebigokimisa */ -/* --- Code for round, with prepare-theta */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - E##ba0 = Bba0 ^((~Bbe0)& Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - Ca0 = E##ba0; \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - E##be0 = Bbe0 ^((~Bbi0)& Bbo0 ); \ - Ce0 = E##be0; \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##bi0 = Bbi0 ^((~Bbo0)& Bbu0 ); \ - Ci0 = E##bi0; \ - E##bo0 = Bbo0 ^((~Bbu0)& Bba0 ); \ - Co0 = E##bo0; \ - E##bu0 = Bbu0 ^((~Bba0)& Bbe0 ); \ - Cu0 = E##bu0; \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - E##ba1 = Bba1 ^((~Bbe1)& Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - Ca1 = E##ba1; \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - E##be1 = Bbe1 ^((~Bbi1)& Bbo1 ); \ - Ce1 = E##be1; \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##bi1 = Bbi1 ^((~Bbo1)& Bbu1 ); \ - Ci1 = E##bi1; \ - E##bo1 = Bbo1 ^((~Bbu1)& Bba1 ); \ - Co1 = E##bo1; \ - E##bu1 = Bbu1 ^((~Bba1)& Bbe1 ); \ - Cu1 = E##bu1; \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - E##ga0 = Bga0 ^((~Bge0)& Bgi0 ); \ - Ca0 ^= E##ga0; \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - E##ge0 = Bge0 ^((~Bgi0)& Bgo0 ); \ - Ce0 ^= E##ge0; \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##gi0 = Bgi0 ^((~Bgo0)& Bgu0 ); \ - Ci0 ^= E##gi0; \ - E##go0 = Bgo0 ^((~Bgu0)& Bga0 ); \ - Co0 ^= E##go0; \ - E##gu0 = Bgu0 ^((~Bga0)& Bge0 ); \ - Cu0 ^= E##gu0; \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - E##ga1 = Bga1 ^((~Bge1)& Bgi1 ); \ - Ca1 ^= E##ga1; \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - E##ge1 = Bge1 ^((~Bgi1)& Bgo1 ); \ - Ce1 ^= E##ge1; \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##gi1 = Bgi1 ^((~Bgo1)& Bgu1 ); \ - Ci1 ^= E##gi1; \ - E##go1 = Bgo1 ^((~Bgu1)& Bga1 ); \ - Co1 ^= E##go1; \ - E##gu1 = Bgu1 ^((~Bga1)& Bge1 ); \ - Cu1 ^= E##gu1; \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - E##ka0 = Bka0 ^((~Bke0)& Bki0 ); \ - Ca0 ^= E##ka0; \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - E##ke0 = Bke0 ^((~Bki0)& Bko0 ); \ - Ce0 ^= E##ke0; \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - Ci0 ^= E##ki0; \ - E##ko0 = Bko0 ^((~Bku0)& Bka0 ); \ - Co0 ^= E##ko0; \ - E##ku0 = Bku0 ^((~Bka0)& Bke0 ); \ - Cu0 ^= E##ku0; \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - E##ka1 = Bka1 ^((~Bke1)& Bki1 ); \ - Ca1 ^= E##ka1; \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - E##ke1 = Bke1 ^((~Bki1)& Bko1 ); \ - Ce1 ^= E##ke1; \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - Ci1 ^= E##ki1; \ - E##ko1 = Bko1 ^((~Bku1)& Bka1 ); \ - Co1 ^= E##ko1; \ - E##ku1 = Bku1 ^((~Bka1)& Bke1 ); \ - Cu1 ^= E##ku1; \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - E##ma0 = Bma0 ^((~Bme0)& Bmi0 ); \ - Ca0 ^= E##ma0; \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - E##me0 = Bme0 ^((~Bmi0)& Bmo0 ); \ - Ce0 ^= E##me0; \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##mi0 = Bmi0 ^((~Bmo0)& Bmu0 ); \ - Ci0 ^= E##mi0; \ - E##mo0 = Bmo0 ^((~Bmu0)& Bma0 ); \ - Co0 ^= E##mo0; \ - E##mu0 = Bmu0 ^((~Bma0)& Bme0 ); \ - Cu0 ^= E##mu0; \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - E##ma1 = Bma1 ^((~Bme1)& Bmi1 ); \ - Ca1 ^= E##ma1; \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - E##me1 = Bme1 ^((~Bmi1)& Bmo1 ); \ - Ce1 ^= E##me1; \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##mi1 = Bmi1 ^((~Bmo1)& Bmu1 ); \ - Ci1 ^= E##mi1; \ - E##mo1 = Bmo1 ^((~Bmu1)& Bma1 ); \ - Co1 ^= E##mo1; \ - E##mu1 = Bmu1 ^((~Bma1)& Bme1 ); \ - Cu1 ^= E##mu1; \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - Ca0 ^= E##sa0; \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - E##se0 = Bse0 ^((~Bsi0)& Bso0 ); \ - Ce0 ^= E##se0; \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##si0 = Bsi0 ^((~Bso0)& Bsu0 ); \ - Ci0 ^= E##si0; \ - E##so0 = Bso0 ^((~Bsu0)& Bsa0 ); \ - Co0 ^= E##so0; \ - E##su0 = Bsu0 ^((~Bsa0)& Bse0 ); \ - Cu0 ^= E##su0; \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - Ca1 ^= E##sa1; \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - E##se1 = Bse1 ^((~Bsi1)& Bso1 ); \ - Ce1 ^= E##se1; \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##si1 = Bsi1 ^((~Bso1)& Bsu1 ); \ - Ci1 ^= E##si1; \ - E##so1 = Bso1 ^((~Bsu1)& Bsa1 ); \ - Co1 ^= E##so1; \ - E##su1 = Bsu1 ^((~Bsa1)& Bse1 ); \ - Cu1 ^= E##su1; \ -\ - -/* --- Code for round */ -/* --- using factor 2 interleaving, 64-bit lanes mapped to 32-bit words */ -#define thetaRhoPiChiIota(i, A, E) \ - Da0 = Cu0^ROL32(Ce1, 1); \ - Da1 = Cu1^Ce0; \ - De0 = Ca0^ROL32(Ci1, 1); \ - De1 = Ca1^Ci0; \ - Di0 = Ce0^ROL32(Co1, 1); \ - Di1 = Ce1^Co0; \ - Do0 = Ci0^ROL32(Cu1, 1); \ - Do1 = Ci1^Cu0; \ - Du0 = Co0^ROL32(Ca1, 1); \ - Du1 = Co1^Ca0; \ -\ - A##ba0 ^= Da0; \ - Bba0 = A##ba0; \ - A##ge0 ^= De0; \ - Bbe0 = ROL32(A##ge0, 22); \ - A##ki1 ^= Di1; \ - Bbi0 = ROL32(A##ki1, 22); \ - E##ba0 = Bba0 ^((~Bbe0)& Bbi0 ); \ - E##ba0 ^= KeccakF1600RoundConstants_int2_0[i]; \ - A##mo1 ^= Do1; \ - Bbo0 = ROL32(A##mo1, 11); \ - E##be0 = Bbe0 ^((~Bbi0)& Bbo0 ); \ - A##su0 ^= Du0; \ - Bbu0 = ROL32(A##su0, 7); \ - E##bi0 = Bbi0 ^((~Bbo0)& Bbu0 ); \ - E##bo0 = Bbo0 ^((~Bbu0)& Bba0 ); \ - E##bu0 = Bbu0 ^((~Bba0)& Bbe0 ); \ -\ - A##ba1 ^= Da1; \ - Bba1 = A##ba1; \ - A##ge1 ^= De1; \ - Bbe1 = ROL32(A##ge1, 22); \ - A##ki0 ^= Di0; \ - Bbi1 = ROL32(A##ki0, 21); \ - E##ba1 = Bba1 ^((~Bbe1)& Bbi1 ); \ - E##ba1 ^= KeccakF1600RoundConstants_int2_1[i]; \ - A##mo0 ^= Do0; \ - Bbo1 = ROL32(A##mo0, 10); \ - E##be1 = Bbe1 ^((~Bbi1)& Bbo1 ); \ - A##su1 ^= Du1; \ - Bbu1 = ROL32(A##su1, 7); \ - E##bi1 = Bbi1 ^((~Bbo1)& Bbu1 ); \ - E##bo1 = Bbo1 ^((~Bbu1)& Bba1 ); \ - E##bu1 = Bbu1 ^((~Bba1)& Bbe1 ); \ -\ - A##bo0 ^= Do0; \ - Bga0 = ROL32(A##bo0, 14); \ - A##gu0 ^= Du0; \ - Bge0 = ROL32(A##gu0, 10); \ - A##ka1 ^= Da1; \ - Bgi0 = ROL32(A##ka1, 2); \ - E##ga0 = Bga0 ^((~Bge0)& Bgi0 ); \ - A##me1 ^= De1; \ - Bgo0 = ROL32(A##me1, 23); \ - E##ge0 = Bge0 ^((~Bgi0)& Bgo0 ); \ - A##si1 ^= Di1; \ - Bgu0 = ROL32(A##si1, 31); \ - E##gi0 = Bgi0 ^((~Bgo0)& Bgu0 ); \ - E##go0 = Bgo0 ^((~Bgu0)& Bga0 ); \ - E##gu0 = Bgu0 ^((~Bga0)& Bge0 ); \ -\ - A##bo1 ^= Do1; \ - Bga1 = ROL32(A##bo1, 14); \ - A##gu1 ^= Du1; \ - Bge1 = ROL32(A##gu1, 10); \ - A##ka0 ^= Da0; \ - Bgi1 = ROL32(A##ka0, 1); \ - E##ga1 = Bga1 ^((~Bge1)& Bgi1 ); \ - A##me0 ^= De0; \ - Bgo1 = ROL32(A##me0, 22); \ - E##ge1 = Bge1 ^((~Bgi1)& Bgo1 ); \ - A##si0 ^= Di0; \ - Bgu1 = ROL32(A##si0, 30); \ - E##gi1 = Bgi1 ^((~Bgo1)& Bgu1 ); \ - E##go1 = Bgo1 ^((~Bgu1)& Bga1 ); \ - E##gu1 = Bgu1 ^((~Bga1)& Bge1 ); \ -\ - A##be1 ^= De1; \ - Bka0 = ROL32(A##be1, 1); \ - A##gi0 ^= Di0; \ - Bke0 = ROL32(A##gi0, 3); \ - A##ko1 ^= Do1; \ - Bki0 = ROL32(A##ko1, 13); \ - E##ka0 = Bka0 ^((~Bke0)& Bki0 ); \ - A##mu0 ^= Du0; \ - Bko0 = ROL32(A##mu0, 4); \ - E##ke0 = Bke0 ^((~Bki0)& Bko0 ); \ - A##sa0 ^= Da0; \ - Bku0 = ROL32(A##sa0, 9); \ - E##ki0 = Bki0 ^((~Bko0)& Bku0 ); \ - E##ko0 = Bko0 ^((~Bku0)& Bka0 ); \ - E##ku0 = Bku0 ^((~Bka0)& Bke0 ); \ -\ - A##be0 ^= De0; \ - Bka1 = A##be0; \ - A##gi1 ^= Di1; \ - Bke1 = ROL32(A##gi1, 3); \ - A##ko0 ^= Do0; \ - Bki1 = ROL32(A##ko0, 12); \ - E##ka1 = Bka1 ^((~Bke1)& Bki1 ); \ - A##mu1 ^= Du1; \ - Bko1 = ROL32(A##mu1, 4); \ - E##ke1 = Bke1 ^((~Bki1)& Bko1 ); \ - A##sa1 ^= Da1; \ - Bku1 = ROL32(A##sa1, 9); \ - E##ki1 = Bki1 ^((~Bko1)& Bku1 ); \ - E##ko1 = Bko1 ^((~Bku1)& Bka1 ); \ - E##ku1 = Bku1 ^((~Bka1)& Bke1 ); \ -\ - A##bu1 ^= Du1; \ - Bma0 = ROL32(A##bu1, 14); \ - A##ga0 ^= Da0; \ - Bme0 = ROL32(A##ga0, 18); \ - A##ke0 ^= De0; \ - Bmi0 = ROL32(A##ke0, 5); \ - E##ma0 = Bma0 ^((~Bme0)& Bmi0 ); \ - A##mi1 ^= Di1; \ - Bmo0 = ROL32(A##mi1, 8); \ - E##me0 = Bme0 ^((~Bmi0)& Bmo0 ); \ - A##so0 ^= Do0; \ - Bmu0 = ROL32(A##so0, 28); \ - E##mi0 = Bmi0 ^((~Bmo0)& Bmu0 ); \ - E##mo0 = Bmo0 ^((~Bmu0)& Bma0 ); \ - E##mu0 = Bmu0 ^((~Bma0)& Bme0 ); \ -\ - A##bu0 ^= Du0; \ - Bma1 = ROL32(A##bu0, 13); \ - A##ga1 ^= Da1; \ - Bme1 = ROL32(A##ga1, 18); \ - A##ke1 ^= De1; \ - Bmi1 = ROL32(A##ke1, 5); \ - E##ma1 = Bma1 ^((~Bme1)& Bmi1 ); \ - A##mi0 ^= Di0; \ - Bmo1 = ROL32(A##mi0, 7); \ - E##me1 = Bme1 ^((~Bmi1)& Bmo1 ); \ - A##so1 ^= Do1; \ - Bmu1 = ROL32(A##so1, 28); \ - E##mi1 = Bmi1 ^((~Bmo1)& Bmu1 ); \ - E##mo1 = Bmo1 ^((~Bmu1)& Bma1 ); \ - E##mu1 = Bmu1 ^((~Bma1)& Bme1 ); \ -\ - A##bi0 ^= Di0; \ - Bsa0 = ROL32(A##bi0, 31); \ - A##go1 ^= Do1; \ - Bse0 = ROL32(A##go1, 28); \ - A##ku1 ^= Du1; \ - Bsi0 = ROL32(A##ku1, 20); \ - E##sa0 = Bsa0 ^((~Bse0)& Bsi0 ); \ - A##ma1 ^= Da1; \ - Bso0 = ROL32(A##ma1, 21); \ - E##se0 = Bse0 ^((~Bsi0)& Bso0 ); \ - A##se0 ^= De0; \ - Bsu0 = ROL32(A##se0, 1); \ - E##si0 = Bsi0 ^((~Bso0)& Bsu0 ); \ - E##so0 = Bso0 ^((~Bsu0)& Bsa0 ); \ - E##su0 = Bsu0 ^((~Bsa0)& Bse0 ); \ -\ - A##bi1 ^= Di1; \ - Bsa1 = ROL32(A##bi1, 31); \ - A##go0 ^= Do0; \ - Bse1 = ROL32(A##go0, 27); \ - A##ku0 ^= Du0; \ - Bsi1 = ROL32(A##ku0, 19); \ - E##sa1 = Bsa1 ^((~Bse1)& Bsi1 ); \ - A##ma0 ^= Da0; \ - Bso1 = ROL32(A##ma0, 20); \ - E##se1 = Bse1 ^((~Bsi1)& Bso1 ); \ - A##se1 ^= De1; \ - Bsu1 = ROL32(A##se1, 1); \ - E##si1 = Bsi1 ^((~Bso1)& Bsu1 ); \ - E##so1 = Bso1 ^((~Bsu1)& Bsa1 ); \ - E##su1 = Bsu1 ^((~Bsa1)& Bse1 ); \ -\ - -#endif /* UseBebigokimisa */ - -const UINT32 KeccakF1600RoundConstants_int2_0[24] = { - 0x00000001UL, - 0x00000000UL, - 0x00000000UL, - 0x00000000UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000000UL, - 0x00000000UL, - 0x00000001UL, - 0x00000000UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000001UL, - 0x00000000UL, - 0x00000000UL, - 0x00000000UL, - 0x00000000UL, - 0x00000001UL, - 0x00000000UL, - 0x00000001UL, - 0x00000000UL }; - -const UINT32 KeccakF1600RoundConstants_int2_1[24] = { - 0x00000000UL, - 0x00000089UL, - 0x8000008bUL, - 0x80008080UL, - 0x0000008bUL, - 0x00008000UL, - 0x80008088UL, - 0x80000082UL, - 0x0000000bUL, - 0x0000000aUL, - 0x00008082UL, - 0x00008003UL, - 0x0000808bUL, - 0x8000000bUL, - 0x8000008aUL, - 0x80000081UL, - 0x80000081UL, - 0x80000008UL, - 0x00000083UL, - 0x80008003UL, - 0x80008088UL, - 0x80000088UL, - 0x00008000UL, - 0x80008082UL }; - -#define copyFromStateAndXor1024bits(X, state, input) \ - X##ba0 = state[ 0]^input[ 0]; \ - X##ba1 = state[ 1]^input[ 1]; \ - X##be0 = state[ 2]^input[ 2]; \ - X##be1 = state[ 3]^input[ 3]; \ - X##bi0 = state[ 4]^input[ 4]; \ - X##bi1 = state[ 5]^input[ 5]; \ - X##bo0 = state[ 6]^input[ 6]; \ - X##bo1 = state[ 7]^input[ 7]; \ - X##bu0 = state[ 8]^input[ 8]; \ - X##bu1 = state[ 9]^input[ 9]; \ - X##ga0 = state[10]^input[10]; \ - X##ga1 = state[11]^input[11]; \ - X##ge0 = state[12]^input[12]; \ - X##ge1 = state[13]^input[13]; \ - X##gi0 = state[14]^input[14]; \ - X##gi1 = state[15]^input[15]; \ - X##go0 = state[16]^input[16]; \ - X##go1 = state[17]^input[17]; \ - X##gu0 = state[18]^input[18]; \ - X##gu1 = state[19]^input[19]; \ - X##ka0 = state[20]^input[20]; \ - X##ka1 = state[21]^input[21]; \ - X##ke0 = state[22]^input[22]; \ - X##ke1 = state[23]^input[23]; \ - X##ki0 = state[24]^input[24]; \ - X##ki1 = state[25]^input[25]; \ - X##ko0 = state[26]^input[26]; \ - X##ko1 = state[27]^input[27]; \ - X##ku0 = state[28]^input[28]; \ - X##ku1 = state[29]^input[29]; \ - X##ma0 = state[30]^input[30]; \ - X##ma1 = state[31]^input[31]; \ - X##me0 = state[32]; \ - X##me1 = state[33]; \ - X##mi0 = state[34]; \ - X##mi1 = state[35]; \ - X##mo0 = state[36]; \ - X##mo1 = state[37]; \ - X##mu0 = state[38]; \ - X##mu1 = state[39]; \ - X##sa0 = state[40]; \ - X##sa1 = state[41]; \ - X##se0 = state[42]; \ - X##se1 = state[43]; \ - X##si0 = state[44]; \ - X##si1 = state[45]; \ - X##so0 = state[46]; \ - X##so1 = state[47]; \ - X##su0 = state[48]; \ - X##su1 = state[49]; \ - -#define copyFromStateAndXor1088bits(X, state, input) \ - X##ba0 = state[ 0]^input[ 0]; \ - X##ba1 = state[ 1]^input[ 1]; \ - X##be0 = state[ 2]^input[ 2]; \ - X##be1 = state[ 3]^input[ 3]; \ - X##bi0 = state[ 4]^input[ 4]; \ - X##bi1 = state[ 5]^input[ 5]; \ - X##bo0 = state[ 6]^input[ 6]; \ - X##bo1 = state[ 7]^input[ 7]; \ - X##bu0 = state[ 8]^input[ 8]; \ - X##bu1 = state[ 9]^input[ 9]; \ - X##ga0 = state[10]^input[10]; \ - X##ga1 = state[11]^input[11]; \ - X##ge0 = state[12]^input[12]; \ - X##ge1 = state[13]^input[13]; \ - X##gi0 = state[14]^input[14]; \ - X##gi1 = state[15]^input[15]; \ - X##go0 = state[16]^input[16]; \ - X##go1 = state[17]^input[17]; \ - X##gu0 = state[18]^input[18]; \ - X##gu1 = state[19]^input[19]; \ - X##ka0 = state[20]^input[20]; \ - X##ka1 = state[21]^input[21]; \ - X##ke0 = state[22]^input[22]; \ - X##ke1 = state[23]^input[23]; \ - X##ki0 = state[24]^input[24]; \ - X##ki1 = state[25]^input[25]; \ - X##ko0 = state[26]^input[26]; \ - X##ko1 = state[27]^input[27]; \ - X##ku0 = state[28]^input[28]; \ - X##ku1 = state[29]^input[29]; \ - X##ma0 = state[30]^input[30]; \ - X##ma1 = state[31]^input[31]; \ - X##me0 = state[32]^input[32]; \ - X##me1 = state[33]^input[33]; \ - X##mi0 = state[34]; \ - X##mi1 = state[35]; \ - X##mo0 = state[36]; \ - X##mo1 = state[37]; \ - X##mu0 = state[38]; \ - X##mu1 = state[39]; \ - X##sa0 = state[40]; \ - X##sa1 = state[41]; \ - X##se0 = state[42]; \ - X##se1 = state[43]; \ - X##si0 = state[44]; \ - X##si1 = state[45]; \ - X##so0 = state[46]; \ - X##so1 = state[47]; \ - X##su0 = state[48]; \ - X##su1 = state[49]; \ - -#define copyFromState(X, state) \ - X##ba0 = state[ 0]; \ - X##ba1 = state[ 1]; \ - X##be0 = state[ 2]; \ - X##be1 = state[ 3]; \ - X##bi0 = state[ 4]; \ - X##bi1 = state[ 5]; \ - X##bo0 = state[ 6]; \ - X##bo1 = state[ 7]; \ - X##bu0 = state[ 8]; \ - X##bu1 = state[ 9]; \ - X##ga0 = state[10]; \ - X##ga1 = state[11]; \ - X##ge0 = state[12]; \ - X##ge1 = state[13]; \ - X##gi0 = state[14]; \ - X##gi1 = state[15]; \ - X##go0 = state[16]; \ - X##go1 = state[17]; \ - X##gu0 = state[18]; \ - X##gu1 = state[19]; \ - X##ka0 = state[20]; \ - X##ka1 = state[21]; \ - X##ke0 = state[22]; \ - X##ke1 = state[23]; \ - X##ki0 = state[24]; \ - X##ki1 = state[25]; \ - X##ko0 = state[26]; \ - X##ko1 = state[27]; \ - X##ku0 = state[28]; \ - X##ku1 = state[29]; \ - X##ma0 = state[30]; \ - X##ma1 = state[31]; \ - X##me0 = state[32]; \ - X##me1 = state[33]; \ - X##mi0 = state[34]; \ - X##mi1 = state[35]; \ - X##mo0 = state[36]; \ - X##mo1 = state[37]; \ - X##mu0 = state[38]; \ - X##mu1 = state[39]; \ - X##sa0 = state[40]; \ - X##sa1 = state[41]; \ - X##se0 = state[42]; \ - X##se1 = state[43]; \ - X##si0 = state[44]; \ - X##si1 = state[45]; \ - X##so0 = state[46]; \ - X##so1 = state[47]; \ - X##su0 = state[48]; \ - X##su1 = state[49]; \ - -#define copyToState(state, X) \ - state[ 0] = X##ba0; \ - state[ 1] = X##ba1; \ - state[ 2] = X##be0; \ - state[ 3] = X##be1; \ - state[ 4] = X##bi0; \ - state[ 5] = X##bi1; \ - state[ 6] = X##bo0; \ - state[ 7] = X##bo1; \ - state[ 8] = X##bu0; \ - state[ 9] = X##bu1; \ - state[10] = X##ga0; \ - state[11] = X##ga1; \ - state[12] = X##ge0; \ - state[13] = X##ge1; \ - state[14] = X##gi0; \ - state[15] = X##gi1; \ - state[16] = X##go0; \ - state[17] = X##go1; \ - state[18] = X##gu0; \ - state[19] = X##gu1; \ - state[20] = X##ka0; \ - state[21] = X##ka1; \ - state[22] = X##ke0; \ - state[23] = X##ke1; \ - state[24] = X##ki0; \ - state[25] = X##ki1; \ - state[26] = X##ko0; \ - state[27] = X##ko1; \ - state[28] = X##ku0; \ - state[29] = X##ku1; \ - state[30] = X##ma0; \ - state[31] = X##ma1; \ - state[32] = X##me0; \ - state[33] = X##me1; \ - state[34] = X##mi0; \ - state[35] = X##mi1; \ - state[36] = X##mo0; \ - state[37] = X##mo1; \ - state[38] = X##mu0; \ - state[39] = X##mu1; \ - state[40] = X##sa0; \ - state[41] = X##sa1; \ - state[42] = X##se0; \ - state[43] = X##se1; \ - state[44] = X##si0; \ - state[45] = X##si1; \ - state[46] = X##so0; \ - state[47] = X##so1; \ - state[48] = X##su0; \ - state[49] = X##su1; \ - -#define copyStateVariables(X, Y) \ - X##ba0 = Y##ba0; \ - X##ba1 = Y##ba1; \ - X##be0 = Y##be0; \ - X##be1 = Y##be1; \ - X##bi0 = Y##bi0; \ - X##bi1 = Y##bi1; \ - X##bo0 = Y##bo0; \ - X##bo1 = Y##bo1; \ - X##bu0 = Y##bu0; \ - X##bu1 = Y##bu1; \ - X##ga0 = Y##ga0; \ - X##ga1 = Y##ga1; \ - X##ge0 = Y##ge0; \ - X##ge1 = Y##ge1; \ - X##gi0 = Y##gi0; \ - X##gi1 = Y##gi1; \ - X##go0 = Y##go0; \ - X##go1 = Y##go1; \ - X##gu0 = Y##gu0; \ - X##gu1 = Y##gu1; \ - X##ka0 = Y##ka0; \ - X##ka1 = Y##ka1; \ - X##ke0 = Y##ke0; \ - X##ke1 = Y##ke1; \ - X##ki0 = Y##ki0; \ - X##ki1 = Y##ki1; \ - X##ko0 = Y##ko0; \ - X##ko1 = Y##ko1; \ - X##ku0 = Y##ku0; \ - X##ku1 = Y##ku1; \ - X##ma0 = Y##ma0; \ - X##ma1 = Y##ma1; \ - X##me0 = Y##me0; \ - X##me1 = Y##me1; \ - X##mi0 = Y##mi0; \ - X##mi1 = Y##mi1; \ - X##mo0 = Y##mo0; \ - X##mo1 = Y##mo1; \ - X##mu0 = Y##mu0; \ - X##mu1 = Y##mu1; \ - X##sa0 = Y##sa0; \ - X##sa1 = Y##sa1; \ - X##se0 = Y##se0; \ - X##se1 = Y##se1; \ - X##si0 = Y##si0; \ - X##si1 = Y##si1; \ - X##so0 = Y##so0; \ - X##so1 = Y##so1; \ - X##su0 = Y##su0; \ - X##su1 = Y##su1; \ - diff --git a/Modules/_sha3/keccak/KeccakF-1600-32.macros b/Modules/_sha3/keccak/KeccakF-1600-32.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-32.macros +++ /dev/null @@ -1,26 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifdef UseSchedule - #if (UseSchedule == 1) - #include "KeccakF-1600-32-s1.macros" - #elif (UseSchedule == 2) - #include "KeccakF-1600-32-s2.macros" - #elif (UseSchedule == 3) - #include "KeccakF-1600-32-rvk.macros" - #else - #error "This schedule is not supported." - #endif -#else - #include "KeccakF-1600-32-s1.macros" -#endif diff --git a/Modules/_sha3/keccak/KeccakF-1600-64.macros b/Modules/_sha3/keccak/KeccakF-1600-64.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-64.macros +++ /dev/null @@ -1,728 +0,0 @@ -/* -Code automatically generated by KeccakTools! - -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define declareABCDE \ - UINT64 Aba, Abe, Abi, Abo, Abu; \ - UINT64 Aga, Age, Agi, Ago, Agu; \ - UINT64 Aka, Ake, Aki, Ako, Aku; \ - UINT64 Ama, Ame, Ami, Amo, Amu; \ - UINT64 Asa, Ase, Asi, Aso, Asu; \ - UINT64 Bba, Bbe, Bbi, Bbo, Bbu; \ - UINT64 Bga, Bge, Bgi, Bgo, Bgu; \ - UINT64 Bka, Bke, Bki, Bko, Bku; \ - UINT64 Bma, Bme, Bmi, Bmo, Bmu; \ - UINT64 Bsa, Bse, Bsi, Bso, Bsu; \ - UINT64 Ca, Ce, Ci, Co, Cu; \ - UINT64 Da, De, Di, Do, Du; \ - UINT64 Eba, Ebe, Ebi, Ebo, Ebu; \ - UINT64 Ega, Ege, Egi, Ego, Egu; \ - UINT64 Eka, Eke, Eki, Eko, Eku; \ - UINT64 Ema, Eme, Emi, Emo, Emu; \ - UINT64 Esa, Ese, Esi, Eso, Esu; \ - -#define prepareTheta \ - Ca = Aba^Aga^Aka^Ama^Asa; \ - Ce = Abe^Age^Ake^Ame^Ase; \ - Ci = Abi^Agi^Aki^Ami^Asi; \ - Co = Abo^Ago^Ako^Amo^Aso; \ - Cu = Abu^Agu^Aku^Amu^Asu; \ - -#ifdef UseBebigokimisa -/* --- Code for round, with prepare-theta (lane complementing pattern 'bebigokimisa') */ -/* --- 64-bit lanes mapped to 64-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^( Bbe | Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - Ca = E##ba; \ - E##be = Bbe ^((~Bbi)| Bbo ); \ - Ce = E##be; \ - E##bi = Bbi ^( Bbo & Bbu ); \ - Ci = E##bi; \ - E##bo = Bbo ^( Bbu | Bba ); \ - Co = E##bo; \ - E##bu = Bbu ^( Bba & Bbe ); \ - Cu = E##bu; \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^( Bge | Bgi ); \ - Ca ^= E##ga; \ - E##ge = Bge ^( Bgi & Bgo ); \ - Ce ^= E##ge; \ - E##gi = Bgi ^( Bgo |(~Bgu)); \ - Ci ^= E##gi; \ - E##go = Bgo ^( Bgu | Bga ); \ - Co ^= E##go; \ - E##gu = Bgu ^( Bga & Bge ); \ - Cu ^= E##gu; \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^( Bke | Bki ); \ - Ca ^= E##ka; \ - E##ke = Bke ^( Bki & Bko ); \ - Ce ^= E##ke; \ - E##ki = Bki ^((~Bko)& Bku ); \ - Ci ^= E##ki; \ - E##ko = (~Bko)^( Bku | Bka ); \ - Co ^= E##ko; \ - E##ku = Bku ^( Bka & Bke ); \ - Cu ^= E##ku; \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^( Bme & Bmi ); \ - Ca ^= E##ma; \ - E##me = Bme ^( Bmi | Bmo ); \ - Ce ^= E##me; \ - E##mi = Bmi ^((~Bmo)| Bmu ); \ - Ci ^= E##mi; \ - E##mo = (~Bmo)^( Bmu & Bma ); \ - Co ^= E##mo; \ - E##mu = Bmu ^( Bma | Bme ); \ - Cu ^= E##mu; \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - Ca ^= E##sa; \ - E##se = (~Bse)^( Bsi | Bso ); \ - Ce ^= E##se; \ - E##si = Bsi ^( Bso & Bsu ); \ - Ci ^= E##si; \ - E##so = Bso ^( Bsu | Bsa ); \ - Co ^= E##so; \ - E##su = Bsu ^( Bsa & Bse ); \ - Cu ^= E##su; \ -\ - -/* --- Code for round (lane complementing pattern 'bebigokimisa') */ -/* --- 64-bit lanes mapped to 64-bit words */ -#define thetaRhoPiChiIota(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^( Bbe | Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - E##be = Bbe ^((~Bbi)| Bbo ); \ - E##bi = Bbi ^( Bbo & Bbu ); \ - E##bo = Bbo ^( Bbu | Bba ); \ - E##bu = Bbu ^( Bba & Bbe ); \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^( Bge | Bgi ); \ - E##ge = Bge ^( Bgi & Bgo ); \ - E##gi = Bgi ^( Bgo |(~Bgu)); \ - E##go = Bgo ^( Bgu | Bga ); \ - E##gu = Bgu ^( Bga & Bge ); \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^( Bke | Bki ); \ - E##ke = Bke ^( Bki & Bko ); \ - E##ki = Bki ^((~Bko)& Bku ); \ - E##ko = (~Bko)^( Bku | Bka ); \ - E##ku = Bku ^( Bka & Bke ); \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^( Bme & Bmi ); \ - E##me = Bme ^( Bmi | Bmo ); \ - E##mi = Bmi ^((~Bmo)| Bmu ); \ - E##mo = (~Bmo)^( Bmu & Bma ); \ - E##mu = Bmu ^( Bma | Bme ); \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - E##se = (~Bse)^( Bsi | Bso ); \ - E##si = Bsi ^( Bso & Bsu ); \ - E##so = Bso ^( Bsu | Bsa ); \ - E##su = Bsu ^( Bsa & Bse ); \ -\ - -#else /* UseBebigokimisa */ -/* --- Code for round, with prepare-theta */ -/* --- 64-bit lanes mapped to 64-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^((~Bbe)& Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - Ca = E##ba; \ - E##be = Bbe ^((~Bbi)& Bbo ); \ - Ce = E##be; \ - E##bi = Bbi ^((~Bbo)& Bbu ); \ - Ci = E##bi; \ - E##bo = Bbo ^((~Bbu)& Bba ); \ - Co = E##bo; \ - E##bu = Bbu ^((~Bba)& Bbe ); \ - Cu = E##bu; \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^((~Bge)& Bgi ); \ - Ca ^= E##ga; \ - E##ge = Bge ^((~Bgi)& Bgo ); \ - Ce ^= E##ge; \ - E##gi = Bgi ^((~Bgo)& Bgu ); \ - Ci ^= E##gi; \ - E##go = Bgo ^((~Bgu)& Bga ); \ - Co ^= E##go; \ - E##gu = Bgu ^((~Bga)& Bge ); \ - Cu ^= E##gu; \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^((~Bke)& Bki ); \ - Ca ^= E##ka; \ - E##ke = Bke ^((~Bki)& Bko ); \ - Ce ^= E##ke; \ - E##ki = Bki ^((~Bko)& Bku ); \ - Ci ^= E##ki; \ - E##ko = Bko ^((~Bku)& Bka ); \ - Co ^= E##ko; \ - E##ku = Bku ^((~Bka)& Bke ); \ - Cu ^= E##ku; \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^((~Bme)& Bmi ); \ - Ca ^= E##ma; \ - E##me = Bme ^((~Bmi)& Bmo ); \ - Ce ^= E##me; \ - E##mi = Bmi ^((~Bmo)& Bmu ); \ - Ci ^= E##mi; \ - E##mo = Bmo ^((~Bmu)& Bma ); \ - Co ^= E##mo; \ - E##mu = Bmu ^((~Bma)& Bme ); \ - Cu ^= E##mu; \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - Ca ^= E##sa; \ - E##se = Bse ^((~Bsi)& Bso ); \ - Ce ^= E##se; \ - E##si = Bsi ^((~Bso)& Bsu ); \ - Ci ^= E##si; \ - E##so = Bso ^((~Bsu)& Bsa ); \ - Co ^= E##so; \ - E##su = Bsu ^((~Bsa)& Bse ); \ - Cu ^= E##su; \ -\ - -/* --- Code for round */ -/* --- 64-bit lanes mapped to 64-bit words */ -#define thetaRhoPiChiIota(i, A, E) \ - Da = Cu^ROL64(Ce, 1); \ - De = Ca^ROL64(Ci, 1); \ - Di = Ce^ROL64(Co, 1); \ - Do = Ci^ROL64(Cu, 1); \ - Du = Co^ROL64(Ca, 1); \ -\ - A##ba ^= Da; \ - Bba = A##ba; \ - A##ge ^= De; \ - Bbe = ROL64(A##ge, 44); \ - A##ki ^= Di; \ - Bbi = ROL64(A##ki, 43); \ - A##mo ^= Do; \ - Bbo = ROL64(A##mo, 21); \ - A##su ^= Du; \ - Bbu = ROL64(A##su, 14); \ - E##ba = Bba ^((~Bbe)& Bbi ); \ - E##ba ^= KeccakF1600RoundConstants[i]; \ - E##be = Bbe ^((~Bbi)& Bbo ); \ - E##bi = Bbi ^((~Bbo)& Bbu ); \ - E##bo = Bbo ^((~Bbu)& Bba ); \ - E##bu = Bbu ^((~Bba)& Bbe ); \ -\ - A##bo ^= Do; \ - Bga = ROL64(A##bo, 28); \ - A##gu ^= Du; \ - Bge = ROL64(A##gu, 20); \ - A##ka ^= Da; \ - Bgi = ROL64(A##ka, 3); \ - A##me ^= De; \ - Bgo = ROL64(A##me, 45); \ - A##si ^= Di; \ - Bgu = ROL64(A##si, 61); \ - E##ga = Bga ^((~Bge)& Bgi ); \ - E##ge = Bge ^((~Bgi)& Bgo ); \ - E##gi = Bgi ^((~Bgo)& Bgu ); \ - E##go = Bgo ^((~Bgu)& Bga ); \ - E##gu = Bgu ^((~Bga)& Bge ); \ -\ - A##be ^= De; \ - Bka = ROL64(A##be, 1); \ - A##gi ^= Di; \ - Bke = ROL64(A##gi, 6); \ - A##ko ^= Do; \ - Bki = ROL64(A##ko, 25); \ - A##mu ^= Du; \ - Bko = ROL64(A##mu, 8); \ - A##sa ^= Da; \ - Bku = ROL64(A##sa, 18); \ - E##ka = Bka ^((~Bke)& Bki ); \ - E##ke = Bke ^((~Bki)& Bko ); \ - E##ki = Bki ^((~Bko)& Bku ); \ - E##ko = Bko ^((~Bku)& Bka ); \ - E##ku = Bku ^((~Bka)& Bke ); \ -\ - A##bu ^= Du; \ - Bma = ROL64(A##bu, 27); \ - A##ga ^= Da; \ - Bme = ROL64(A##ga, 36); \ - A##ke ^= De; \ - Bmi = ROL64(A##ke, 10); \ - A##mi ^= Di; \ - Bmo = ROL64(A##mi, 15); \ - A##so ^= Do; \ - Bmu = ROL64(A##so, 56); \ - E##ma = Bma ^((~Bme)& Bmi ); \ - E##me = Bme ^((~Bmi)& Bmo ); \ - E##mi = Bmi ^((~Bmo)& Bmu ); \ - E##mo = Bmo ^((~Bmu)& Bma ); \ - E##mu = Bmu ^((~Bma)& Bme ); \ -\ - A##bi ^= Di; \ - Bsa = ROL64(A##bi, 62); \ - A##go ^= Do; \ - Bse = ROL64(A##go, 55); \ - A##ku ^= Du; \ - Bsi = ROL64(A##ku, 39); \ - A##ma ^= Da; \ - Bso = ROL64(A##ma, 41); \ - A##se ^= De; \ - Bsu = ROL64(A##se, 2); \ - E##sa = Bsa ^((~Bse)& Bsi ); \ - E##se = Bse ^((~Bsi)& Bso ); \ - E##si = Bsi ^((~Bso)& Bsu ); \ - E##so = Bso ^((~Bsu)& Bsa ); \ - E##su = Bsu ^((~Bsa)& Bse ); \ -\ - -#endif /* UseBebigokimisa */ - -static const UINT64 KeccakF1600RoundConstants[24] = { - 0x0000000000000001ULL, - 0x0000000000008082ULL, - 0x800000000000808aULL, - 0x8000000080008000ULL, - 0x000000000000808bULL, - 0x0000000080000001ULL, - 0x8000000080008081ULL, - 0x8000000000008009ULL, - 0x000000000000008aULL, - 0x0000000000000088ULL, - 0x0000000080008009ULL, - 0x000000008000000aULL, - 0x000000008000808bULL, - 0x800000000000008bULL, - 0x8000000000008089ULL, - 0x8000000000008003ULL, - 0x8000000000008002ULL, - 0x8000000000000080ULL, - 0x000000000000800aULL, - 0x800000008000000aULL, - 0x8000000080008081ULL, - 0x8000000000008080ULL, - 0x0000000080000001ULL, - 0x8000000080008008ULL }; - -#define copyFromStateAndXor576bits(X, state, input) \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]; \ - X##ka = state[10]; \ - X##ke = state[11]; \ - X##ki = state[12]; \ - X##ko = state[13]; \ - X##ku = state[14]; \ - X##ma = state[15]; \ - X##me = state[16]; \ - X##mi = state[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyFromStateAndXor832bits(X, state, input) \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - X##ka = state[10]^input[10]; \ - X##ke = state[11]^input[11]; \ - X##ki = state[12]^input[12]; \ - X##ko = state[13]; \ - X##ku = state[14]; \ - X##ma = state[15]; \ - X##me = state[16]; \ - X##mi = state[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyFromStateAndXor1024bits(X, state, input) \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - X##ka = state[10]^input[10]; \ - X##ke = state[11]^input[11]; \ - X##ki = state[12]^input[12]; \ - X##ko = state[13]^input[13]; \ - X##ku = state[14]^input[14]; \ - X##ma = state[15]^input[15]; \ - X##me = state[16]; \ - X##mi = state[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyFromStateAndXor1088bits(X, state, input) \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - X##ka = state[10]^input[10]; \ - X##ke = state[11]^input[11]; \ - X##ki = state[12]^input[12]; \ - X##ko = state[13]^input[13]; \ - X##ku = state[14]^input[14]; \ - X##ma = state[15]^input[15]; \ - X##me = state[16]^input[16]; \ - X##mi = state[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyFromStateAndXor1152bits(X, state, input) \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - X##ka = state[10]^input[10]; \ - X##ke = state[11]^input[11]; \ - X##ki = state[12]^input[12]; \ - X##ko = state[13]^input[13]; \ - X##ku = state[14]^input[14]; \ - X##ma = state[15]^input[15]; \ - X##me = state[16]^input[16]; \ - X##mi = state[17]^input[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyFromStateAndXor1344bits(X, state, input) \ - X##ba = state[ 0]^input[ 0]; \ - X##be = state[ 1]^input[ 1]; \ - X##bi = state[ 2]^input[ 2]; \ - X##bo = state[ 3]^input[ 3]; \ - X##bu = state[ 4]^input[ 4]; \ - X##ga = state[ 5]^input[ 5]; \ - X##ge = state[ 6]^input[ 6]; \ - X##gi = state[ 7]^input[ 7]; \ - X##go = state[ 8]^input[ 8]; \ - X##gu = state[ 9]^input[ 9]; \ - X##ka = state[10]^input[10]; \ - X##ke = state[11]^input[11]; \ - X##ki = state[12]^input[12]; \ - X##ko = state[13]^input[13]; \ - X##ku = state[14]^input[14]; \ - X##ma = state[15]^input[15]; \ - X##me = state[16]^input[16]; \ - X##mi = state[17]^input[17]; \ - X##mo = state[18]^input[18]; \ - X##mu = state[19]^input[19]; \ - X##sa = state[20]^input[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyFromState(X, state) \ - X##ba = state[ 0]; \ - X##be = state[ 1]; \ - X##bi = state[ 2]; \ - X##bo = state[ 3]; \ - X##bu = state[ 4]; \ - X##ga = state[ 5]; \ - X##ge = state[ 6]; \ - X##gi = state[ 7]; \ - X##go = state[ 8]; \ - X##gu = state[ 9]; \ - X##ka = state[10]; \ - X##ke = state[11]; \ - X##ki = state[12]; \ - X##ko = state[13]; \ - X##ku = state[14]; \ - X##ma = state[15]; \ - X##me = state[16]; \ - X##mi = state[17]; \ - X##mo = state[18]; \ - X##mu = state[19]; \ - X##sa = state[20]; \ - X##se = state[21]; \ - X##si = state[22]; \ - X##so = state[23]; \ - X##su = state[24]; \ - -#define copyToState(state, X) \ - state[ 0] = X##ba; \ - state[ 1] = X##be; \ - state[ 2] = X##bi; \ - state[ 3] = X##bo; \ - state[ 4] = X##bu; \ - state[ 5] = X##ga; \ - state[ 6] = X##ge; \ - state[ 7] = X##gi; \ - state[ 8] = X##go; \ - state[ 9] = X##gu; \ - state[10] = X##ka; \ - state[11] = X##ke; \ - state[12] = X##ki; \ - state[13] = X##ko; \ - state[14] = X##ku; \ - state[15] = X##ma; \ - state[16] = X##me; \ - state[17] = X##mi; \ - state[18] = X##mo; \ - state[19] = X##mu; \ - state[20] = X##sa; \ - state[21] = X##se; \ - state[22] = X##si; \ - state[23] = X##so; \ - state[24] = X##su; \ - -#define copyStateVariables(X, Y) \ - X##ba = Y##ba; \ - X##be = Y##be; \ - X##bi = Y##bi; \ - X##bo = Y##bo; \ - X##bu = Y##bu; \ - X##ga = Y##ga; \ - X##ge = Y##ge; \ - X##gi = Y##gi; \ - X##go = Y##go; \ - X##gu = Y##gu; \ - X##ka = Y##ka; \ - X##ke = Y##ke; \ - X##ki = Y##ki; \ - X##ko = Y##ko; \ - X##ku = Y##ku; \ - X##ma = Y##ma; \ - X##me = Y##me; \ - X##mi = Y##mi; \ - X##mo = Y##mo; \ - X##mu = Y##mu; \ - X##sa = Y##sa; \ - X##se = Y##se; \ - X##si = Y##si; \ - X##so = Y##so; \ - X##su = Y##su; \ - diff --git a/Modules/_sha3/keccak/KeccakF-1600-int-set.h b/Modules/_sha3/keccak/KeccakF-1600-int-set.h deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-int-set.h +++ /dev/null @@ -1,6 +0,0 @@ -#define ProvideFast576 -#define ProvideFast832 -#define ProvideFast1024 -#define ProvideFast1088 -#define ProvideFast1152 -#define ProvideFast1344 diff --git a/Modules/_sha3/keccak/KeccakF-1600-interface.h b/Modules/_sha3/keccak/KeccakF-1600-interface.h deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-interface.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _KeccakPermutationInterface_h_ -#define _KeccakPermutationInterface_h_ - -#include "KeccakF-1600-int-set.h" - -static void KeccakInitialize( void ); -static void KeccakInitializeState(unsigned char *state); -static void KeccakPermutation(unsigned char *state); -#ifdef ProvideFast576 -static void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data); -#endif -#ifdef ProvideFast832 -static void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data); -#endif -#ifdef ProvideFast1024 -static void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data); -#endif -#ifdef ProvideFast1088 -static void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data); -#endif -#ifdef ProvideFast1152 -static void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data); -#endif -#ifdef ProvideFast1344 -static void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data); -#endif -static void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount); -#ifdef ProvideFast1024 -static void KeccakExtract1024bits(const unsigned char *state, unsigned char *data); -#endif -static void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount); - -#endif diff --git a/Modules/_sha3/keccak/KeccakF-1600-opt32-settings.h b/Modules/_sha3/keccak/KeccakF-1600-opt32-settings.h deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-opt32-settings.h +++ /dev/null @@ -1,6 +0,0 @@ -/* -#define Unrolling 2 -#define UseBebigokimisa -#define UseInterleaveTables -#define UseSchedule 3 -*/ diff --git a/Modules/_sha3/keccak/KeccakF-1600-opt32.c b/Modules/_sha3/keccak/KeccakF-1600-opt32.c deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-opt32.c +++ /dev/null @@ -1,524 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include -/* #include "brg_endian.h" */ -#include "KeccakF-1600-opt32-settings.h" -#include "KeccakF-1600-interface.h" - -typedef unsigned char UINT8; -typedef unsigned short UINT16; -typedef unsigned int UINT32; -/* typedef unsigned long long int UINT64; */ - -#ifdef UseInterleaveTables -static int interleaveTablesBuilt = 0; -static UINT16 interleaveTable[65536]; -static UINT16 deinterleaveTable[65536]; - -static void buildInterleaveTables() -{ - UINT32 i, j; - UINT16 x; - - if (!interleaveTablesBuilt) { - for(i=0; i<65536; i++) { - x = 0; - for(j=0; j<16; j++) { - if (i & (1 << j)) - x |= (1 << (j/2 + 8*(j%2))); - } - interleaveTable[i] = x; - deinterleaveTable[x] = (UINT16)i; - } - interleaveTablesBuilt = 1; - } -} - -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - -#define xor2bytesIntoInterleavedWords(even, odd, source, j) \ - i##j = interleaveTable[((const UINT16*)source)[j]]; \ - ((UINT8*)even)[j] ^= i##j & 0xFF; \ - ((UINT8*)odd)[j] ^= i##j >> 8; - -#define setInterleavedWordsInto2bytes(dest, even, odd, j) \ - d##j = deinterleaveTable[((even >> (j*8)) & 0xFF) ^ (((odd >> (j*8)) & 0xFF) << 8)]; \ - ((UINT16*)dest)[j] = d##j; - -#else /* (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN) */ - -#define xor2bytesIntoInterleavedWords(even, odd, source, j) \ - i##j = interleaveTable[source[2*j] ^ ((UINT16)source[2*j+1] << 8)]; \ - *even ^= (i##j & 0xFF) << (j*8); \ - *odd ^= ((i##j >> 8) & 0xFF) << (j*8); - -#define setInterleavedWordsInto2bytes(dest, even, odd, j) \ - d##j = deinterleaveTable[((even >> (j*8)) & 0xFF) ^ (((odd >> (j*8)) & 0xFF) << 8)]; \ - dest[2*j] = d##j & 0xFF; \ - dest[2*j+1] = d##j >> 8; - -#endif /* Endianness */ - -static void xor8bytesIntoInterleavedWords(UINT32 *even, UINT32 *odd, const UINT8* source) -{ - UINT16 i0, i1, i2, i3; - - xor2bytesIntoInterleavedWords(even, odd, source, 0) - xor2bytesIntoInterleavedWords(even, odd, source, 1) - xor2bytesIntoInterleavedWords(even, odd, source, 2) - xor2bytesIntoInterleavedWords(even, odd, source, 3) -} - -#define xorLanesIntoState(laneCount, state, input) \ - { \ - int i; \ - for(i=0; i<(laneCount); i++) \ - xor8bytesIntoInterleavedWords(state+i*2, state+i*2+1, input+i*8); \ - } - -static void setInterleavedWordsInto8bytes(UINT8* dest, UINT32 even, UINT32 odd) -{ - UINT16 d0, d1, d2, d3; - - setInterleavedWordsInto2bytes(dest, even, odd, 0) - setInterleavedWordsInto2bytes(dest, even, odd, 1) - setInterleavedWordsInto2bytes(dest, even, odd, 2) - setInterleavedWordsInto2bytes(dest, even, odd, 3) -} - -#define extractLanes(laneCount, state, data) \ - { \ - int i; \ - for(i=0; i<(laneCount); i++) \ - setInterleavedWordsInto8bytes(data+i*8, ((UINT32*)state)[i*2], ((UINT32*)state)[i*2+1]); \ - } - -#else /* No interleaving tables */ - -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - -/* Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002 */ -#define xorInterleavedLE(rateInLanes, state, input) \ - { \ - const UINT32 * pI = (const UINT32 *)input; \ - UINT32 * pS = state; \ - UINT32 t, x0, x1; \ - int i; \ - for (i = (rateInLanes)-1; i >= 0; --i) \ - { \ - x0 = *(pI++); \ - t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1); \ - t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2); \ - t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4); \ - t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8); \ - x1 = *(pI++); \ - t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1); \ - t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2); \ - t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4); \ - t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8); \ - *(pS++) ^= (UINT16)x0 | (x1 << 16); \ - *(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000); \ - } \ - } - -#define xorLanesIntoState(laneCount, state, input) \ - xorInterleavedLE(laneCount, state, input) - -#else /* (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN) */ - -/* Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002 */ -UINT64 toInterleaving(UINT64 x) -{ - UINT64 t; - - t = (x ^ (x >> 1)) & 0x2222222222222222ULL; x = x ^ t ^ (t << 1); - t = (x ^ (x >> 2)) & 0x0C0C0C0C0C0C0C0CULL; x = x ^ t ^ (t << 2); - t = (x ^ (x >> 4)) & 0x00F000F000F000F0ULL; x = x ^ t ^ (t << 4); - t = (x ^ (x >> 8)) & 0x0000FF000000FF00ULL; x = x ^ t ^ (t << 8); - t = (x ^ (x >> 16)) & 0x00000000FFFF0000ULL; x = x ^ t ^ (t << 16); - - return x; -} - -static void xor8bytesIntoInterleavedWords(UINT32* evenAndOdd, const UINT8* source) -{ - /* This can be optimized */ - UINT64 sourceWord = - (UINT64)source[0] - ^ (((UINT64)source[1]) << 8) - ^ (((UINT64)source[2]) << 16) - ^ (((UINT64)source[3]) << 24) - ^ (((UINT64)source[4]) << 32) - ^ (((UINT64)source[5]) << 40) - ^ (((UINT64)source[6]) << 48) - ^ (((UINT64)source[7]) << 56); - UINT64 evenAndOddWord = toInterleaving(sourceWord); - evenAndOdd[0] ^= (UINT32)evenAndOddWord; - evenAndOdd[1] ^= (UINT32)(evenAndOddWord >> 32); -} - -#define xorLanesIntoState(laneCount, state, input) \ - { \ - int i; \ - for(i=0; i<(laneCount); i++) \ - xor8bytesIntoInterleavedWords(state+i*2, input+i*8); \ - } - -#endif /* Endianness */ - -/* Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002 */ -UINT64 fromInterleaving(UINT64 x) -{ - UINT64 t; - - t = (x ^ (x >> 16)) & 0x00000000FFFF0000ULL; x = x ^ t ^ (t << 16); - t = (x ^ (x >> 8)) & 0x0000FF000000FF00ULL; x = x ^ t ^ (t << 8); - t = (x ^ (x >> 4)) & 0x00F000F000F000F0ULL; x = x ^ t ^ (t << 4); - t = (x ^ (x >> 2)) & 0x0C0C0C0C0C0C0C0CULL; x = x ^ t ^ (t << 2); - t = (x ^ (x >> 1)) & 0x2222222222222222ULL; x = x ^ t ^ (t << 1); - - return x; -} - -static void setInterleavedWordsInto8bytes(UINT8* dest, UINT32* evenAndOdd) -{ -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - ((UINT64*)dest)[0] = fromInterleaving(*(UINT64*)evenAndOdd); -#else /* (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN) */ - /* This can be optimized */ - UINT64 evenAndOddWord = (UINT64)evenAndOdd[0] ^ ((UINT64)evenAndOdd[1] << 32); - UINT64 destWord = fromInterleaving(evenAndOddWord); - dest[0] = destWord & 0xFF; - dest[1] = (destWord >> 8) & 0xFF; - dest[2] = (destWord >> 16) & 0xFF; - dest[3] = (destWord >> 24) & 0xFF; - dest[4] = (destWord >> 32) & 0xFF; - dest[5] = (destWord >> 40) & 0xFF; - dest[6] = (destWord >> 48) & 0xFF; - dest[7] = (destWord >> 56) & 0xFF; -#endif /* Endianness */ -} - -#define extractLanes(laneCount, state, data) \ - { \ - unsigned int i; \ - for(i=0; i<(laneCount); i++) \ - setInterleavedWordsInto8bytes(data+i*8, (UINT32*)state+i*2); \ - } - -#endif /* With or without interleaving tables */ - -#if defined(_MSC_VER) -#define ROL32(a, offset) _rotl(a, offset) -#elif (defined (__arm__) && defined(__ARMCC_VERSION)) -#define ROL32(a, offset) __ror(a, 32-(offset)) -#else -#define ROL32(a, offset) ((((UINT32)a) << (offset)) ^ (((UINT32)a) >> (32-(offset)))) -#endif - -#include "KeccakF-1600-unrolling.macros" -#include "KeccakF-1600-32.macros" - -#if (UseSchedule == 3) - -#ifdef UseBebigokimisa -#error "No lane complementing with schedule 3." -#endif - -#if (Unrolling != 2) -#error "Only unrolling 2 is supported by schedule 3." -#endif - -static void KeccakPermutationOnWords(UINT32 *state) -{ - rounds -} - -static void KeccakPermutationOnWordsAfterXoring(UINT32 *state, const UINT8 *input, unsigned int laneCount) -{ - xorLanesIntoState(laneCount, state, input) - rounds -} - -#ifdef ProvideFast576 -static void KeccakPermutationOnWordsAfterXoring576bits(UINT32 *state, const UINT8 *input) -{ - xorLanesIntoState(9, state, input) - rounds -} -#endif - -#ifdef ProvideFast832 -static void KeccakPermutationOnWordsAfterXoring832bits(UINT32 *state, const UINT8 *input) -{ - xorLanesIntoState(13, state, input) - rounds -} -#endif - -#ifdef ProvideFast1024 -static void KeccakPermutationOnWordsAfterXoring1024bits(UINT32 *state, const UINT8 *input) -{ - xorLanesIntoState(16, state, input) - rounds -} -#endif - -#ifdef ProvideFast1088 -static void KeccakPermutationOnWordsAfterXoring1088bits(UINT32 *state, const UINT8 *input) -{ - xorLanesIntoState(17, state, input) - rounds -} -#endif - -#ifdef ProvideFast1152 -static void KeccakPermutationOnWordsAfterXoring1152bits(UINT32 *state, const UINT8 *input) -{ - xorLanesIntoState(18, state, input) - rounds -} -#endif - -#ifdef ProvideFast1344 -static void KeccakPermutationOnWordsAfterXoring1344bits(UINT32 *state, const UINT8 *input) -{ - xorLanesIntoState(21, state, input) - rounds -} -#endif - -#else /* (Schedule != 3) */ - -static void KeccakPermutationOnWords(UINT32 *state) -{ - declareABCDE -#if (Unrolling != 24) - unsigned int i; -#endif - - copyFromState(A, state) - rounds -} - -static void KeccakPermutationOnWordsAfterXoring(UINT32 *state, const UINT8 *input, unsigned int laneCount) -{ - declareABCDE - unsigned int i; - - xorLanesIntoState(laneCount, state, input) - copyFromState(A, state) - rounds -} - -#ifdef ProvideFast576 -static void KeccakPermutationOnWordsAfterXoring576bits(UINT32 *state, const UINT8 *input) -{ - declareABCDE - unsigned int i; - - xorLanesIntoState(9, state, input) - copyFromState(A, state) - rounds -} -#endif - -#ifdef ProvideFast832 -static void KeccakPermutationOnWordsAfterXoring832bits(UINT32 *state, const UINT8 *input) -{ - declareABCDE - unsigned int i; - - xorLanesIntoState(13, state, input) - copyFromState(A, state) - rounds -} -#endif - -#ifdef ProvideFast1024 -static void KeccakPermutationOnWordsAfterXoring1024bits(UINT32 *state, const UINT8 *input) -{ - declareABCDE - unsigned int i; - - xorLanesIntoState(16, state, input) - copyFromState(A, state) - rounds -} -#endif - -#ifdef ProvideFast1088 -static void KeccakPermutationOnWordsAfterXoring1088bits(UINT32 *state, const UINT8 *input) -{ - declareABCDE - unsigned int i; - - xorLanesIntoState(17, state, input) - copyFromState(A, state) - rounds -} -#endif - -#ifdef ProvideFast1152 -static void KeccakPermutationOnWordsAfterXoring1152bits(UINT32 *state, const UINT8 *input) -{ - declareABCDE - unsigned int i; - - xorLanesIntoState(18, state, input) - copyFromState(A, state) - rounds -} -#endif - -#ifdef ProvideFast1344 -static void KeccakPermutationOnWordsAfterXoring1344bits(UINT32 *state, const UINT8 *input) -{ - declareABCDE - unsigned int i; - - xorLanesIntoState(21, state, input) - copyFromState(A, state) - rounds -} -#endif - -#endif - -static void KeccakInitialize() -{ -#ifdef UseInterleaveTables - buildInterleaveTables(); -#endif -} - -static void KeccakInitializeState(unsigned char *state) -{ - memset(state, 0, 200); -#ifdef UseBebigokimisa - ((UINT32*)state)[ 2] = ~(UINT32)0; - ((UINT32*)state)[ 3] = ~(UINT32)0; - ((UINT32*)state)[ 4] = ~(UINT32)0; - ((UINT32*)state)[ 5] = ~(UINT32)0; - ((UINT32*)state)[16] = ~(UINT32)0; - ((UINT32*)state)[17] = ~(UINT32)0; - ((UINT32*)state)[24] = ~(UINT32)0; - ((UINT32*)state)[25] = ~(UINT32)0; - ((UINT32*)state)[34] = ~(UINT32)0; - ((UINT32*)state)[35] = ~(UINT32)0; - ((UINT32*)state)[40] = ~(UINT32)0; - ((UINT32*)state)[41] = ~(UINT32)0; -#endif -} - -static void KeccakPermutation(unsigned char *state) -{ - /* We assume the state is always stored as interleaved 32-bit words */ - KeccakPermutationOnWords((UINT32*)state); -} - -#ifdef ProvideFast576 -static void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data) -{ - KeccakPermutationOnWordsAfterXoring576bits((UINT32*)state, data); -} -#endif - -#ifdef ProvideFast832 -static void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data) -{ - KeccakPermutationOnWordsAfterXoring832bits((UINT32*)state, data); -} -#endif - -#ifdef ProvideFast1024 -static void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data) -{ - KeccakPermutationOnWordsAfterXoring1024bits((UINT32*)state, data); -} -#endif - -#ifdef ProvideFast1088 -static void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data) -{ - KeccakPermutationOnWordsAfterXoring1088bits((UINT32*)state, data); -} -#endif - -#ifdef ProvideFast1152 -static void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data) -{ - KeccakPermutationOnWordsAfterXoring1152bits((UINT32*)state, data); -} -#endif - -#ifdef ProvideFast1344 -static void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data) -{ - KeccakPermutationOnWordsAfterXoring1344bits((UINT32*)state, data); -} -#endif - -static void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount) -{ - KeccakPermutationOnWordsAfterXoring((UINT32*)state, data, laneCount); -} - -#ifdef ProvideFast1024 -static void KeccakExtract1024bits(const unsigned char *state, unsigned char *data) -{ - extractLanes(16, state, data) -#ifdef UseBebigokimisa - ((UINT32*)data)[ 2] = ~((UINT32*)data)[ 2]; - ((UINT32*)data)[ 3] = ~((UINT32*)data)[ 3]; - ((UINT32*)data)[ 4] = ~((UINT32*)data)[ 4]; - ((UINT32*)data)[ 5] = ~((UINT32*)data)[ 5]; - ((UINT32*)data)[16] = ~((UINT32*)data)[16]; - ((UINT32*)data)[17] = ~((UINT32*)data)[17]; - ((UINT32*)data)[24] = ~((UINT32*)data)[24]; - ((UINT32*)data)[25] = ~((UINT32*)data)[25]; -#endif -} -#endif - -static void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount) -{ - extractLanes(laneCount, state, data) -#ifdef UseBebigokimisa - if (laneCount > 1) { - ((UINT32*)data)[ 2] = ~((UINT32*)data)[ 2]; - ((UINT32*)data)[ 3] = ~((UINT32*)data)[ 3]; - if (laneCount > 2) { - ((UINT32*)data)[ 4] = ~((UINT32*)data)[ 4]; - ((UINT32*)data)[ 5] = ~((UINT32*)data)[ 5]; - if (laneCount > 8) { - ((UINT32*)data)[16] = ~((UINT32*)data)[16]; - ((UINT32*)data)[17] = ~((UINT32*)data)[17]; - if (laneCount > 12) { - ((UINT32*)data)[24] = ~((UINT32*)data)[24]; - ((UINT32*)data)[25] = ~((UINT32*)data)[25]; - if (laneCount > 17) { - ((UINT32*)data)[34] = ~((UINT32*)data)[34]; - ((UINT32*)data)[35] = ~((UINT32*)data)[35]; - if (laneCount > 20) { - ((UINT32*)data)[40] = ~((UINT32*)data)[40]; - ((UINT32*)data)[41] = ~((UINT32*)data)[41]; - } - } - } - } - } - } -#endif -} diff --git a/Modules/_sha3/keccak/KeccakF-1600-opt64-settings.h b/Modules/_sha3/keccak/KeccakF-1600-opt64-settings.h deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-opt64-settings.h +++ /dev/null @@ -1,9 +0,0 @@ -/* -#define Unrolling 24 -#define UseBebigokimisa -#define UseSSE -#define UseOnlySIMD64 -#define UseMMX -#define UseSHLD -#define UseXOP -*/ diff --git a/Modules/_sha3/keccak/KeccakF-1600-opt64.c b/Modules/_sha3/keccak/KeccakF-1600-opt64.c deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-opt64.c +++ /dev/null @@ -1,510 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include -/* #include "brg_endian.h" */ -#include "KeccakF-1600-opt64-settings.h" -#include "KeccakF-1600-interface.h" - -typedef unsigned char UINT8; -/* typedef unsigned long long int UINT64; */ - -#if defined(__GNUC__) -#define ALIGN __attribute__ ((aligned(32))) -#elif defined(_MSC_VER) -#define ALIGN __declspec(align(32)) -#else -#define ALIGN -#endif - -#if defined(UseSSE) - #include - typedef __m128i V64; - typedef __m128i V128; - typedef union { - V128 v128; - UINT64 v64[2]; - } V6464; - - #define ANDnu64(a, b) _mm_andnot_si128(a, b) - #define LOAD64(a) _mm_loadl_epi64((const V64 *)&(a)) - #define CONST64(a) _mm_loadl_epi64((const V64 *)&(a)) - #define ROL64(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o))) - #define STORE64(a, b) _mm_storel_epi64((V64 *)&(a), b) - #define XOR64(a, b) _mm_xor_si128(a, b) - #define XOReq64(a, b) a = _mm_xor_si128(a, b) - #define SHUFFLEBYTES128(a, b) _mm_shuffle_epi8(a, b) - - #define ANDnu128(a, b) _mm_andnot_si128(a, b) - #define LOAD6464(a, b) _mm_set_epi64((__m64)(a), (__m64)(b)) - #define CONST128(a) _mm_load_si128((const V128 *)&(a)) - #define LOAD128(a) _mm_load_si128((const V128 *)&(a)) - #define LOAD128u(a) _mm_loadu_si128((const V128 *)&(a)) - #define ROL64in128(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o))) - #define STORE128(a, b) _mm_store_si128((V128 *)&(a), b) - #define XOR128(a, b) _mm_xor_si128(a, b) - #define XOReq128(a, b) a = _mm_xor_si128(a, b) - #define GET64LOLO(a, b) _mm_unpacklo_epi64(a, b) - #define GET64HIHI(a, b) _mm_unpackhi_epi64(a, b) - #define COPY64HI2LO(a) _mm_shuffle_epi32(a, 0xEE) - #define COPY64LO2HI(a) _mm_shuffle_epi32(a, 0x44) - #define ZERO128() _mm_setzero_si128() - - #ifdef UseOnlySIMD64 - #include "KeccakF-1600-simd64.macros" - #else -ALIGN const UINT64 rho8_56[2] = {0x0605040302010007, 0x080F0E0D0C0B0A09}; - #include "KeccakF-1600-simd128.macros" - #endif - - #ifdef UseBebigokimisa - #error "UseBebigokimisa cannot be used in combination with UseSSE" - #endif -#elif defined(UseXOP) - #include - typedef __m128i V64; - typedef __m128i V128; - - #define LOAD64(a) _mm_loadl_epi64((const V64 *)&(a)) - #define CONST64(a) _mm_loadl_epi64((const V64 *)&(a)) - #define STORE64(a, b) _mm_storel_epi64((V64 *)&(a), b) - #define XOR64(a, b) _mm_xor_si128(a, b) - #define XOReq64(a, b) a = _mm_xor_si128(a, b) - - #define ANDnu128(a, b) _mm_andnot_si128(a, b) - #define LOAD6464(a, b) _mm_set_epi64((__m64)(a), (__m64)(b)) - #define CONST128(a) _mm_load_si128((const V128 *)&(a)) - #define LOAD128(a) _mm_load_si128((const V128 *)&(a)) - #define LOAD128u(a) _mm_loadu_si128((const V128 *)&(a)) - #define STORE128(a, b) _mm_store_si128((V128 *)&(a), b) - #define XOR128(a, b) _mm_xor_si128(a, b) - #define XOReq128(a, b) a = _mm_xor_si128(a, b) - #define ZERO128() _mm_setzero_si128() - - #define SWAP64(a) _mm_shuffle_epi32(a, 0x4E) - #define GET64LOLO(a, b) _mm_unpacklo_epi64(a, b) - #define GET64HIHI(a, b) _mm_unpackhi_epi64(a, b) - #define GET64LOHI(a, b) ((__m128i)_mm_blend_pd((__m128d)a, (__m128d)b, 2)) - #define GET64HILO(a, b) SWAP64(GET64LOHI(b, a)) - #define COPY64HI2LO(a) _mm_shuffle_epi32(a, 0xEE) - #define COPY64LO2HI(a) _mm_shuffle_epi32(a, 0x44) - - #define ROL6464same(a, o) _mm_roti_epi64(a, o) - #define ROL6464(a, r1, r2) _mm_rot_epi64(a, CONST128( rot_##r1##_##r2 )) -ALIGN const UINT64 rot_0_20[2] = { 0, 20}; -ALIGN const UINT64 rot_44_3[2] = {44, 3}; -ALIGN const UINT64 rot_43_45[2] = {43, 45}; -ALIGN const UINT64 rot_21_61[2] = {21, 61}; -ALIGN const UINT64 rot_14_28[2] = {14, 28}; -ALIGN const UINT64 rot_1_36[2] = { 1, 36}; -ALIGN const UINT64 rot_6_10[2] = { 6, 10}; -ALIGN const UINT64 rot_25_15[2] = {25, 15}; -ALIGN const UINT64 rot_8_56[2] = { 8, 56}; -ALIGN const UINT64 rot_18_27[2] = {18, 27}; -ALIGN const UINT64 rot_62_55[2] = {62, 55}; -ALIGN const UINT64 rot_39_41[2] = {39, 41}; - -#if defined(UseSimulatedXOP) - /* For debugging purposes, when XOP is not available */ - #undef ROL6464 - #undef ROL6464same - #define ROL6464same(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o))) - V128 ROL6464(V128 a, int r0, int r1) - { - V128 a0 = ROL64(a, r0); - V128 a1 = COPY64HI2LO(ROL64(a, r1)); - return GET64LOLO(a0, a1); - } -#endif - - #include "KeccakF-1600-xop.macros" - - #ifdef UseBebigokimisa - #error "UseBebigokimisa cannot be used in combination with UseXOP" - #endif -#elif defined(UseMMX) - #include - typedef __m64 V64; - #define ANDnu64(a, b) _mm_andnot_si64(a, b) - - #if (defined(_MSC_VER) || defined (__INTEL_COMPILER)) - #define LOAD64(a) *(V64*)&(a) - #define CONST64(a) *(V64*)&(a) - #define STORE64(a, b) *(V64*)&(a) = b - #else - #define LOAD64(a) (V64)a - #define CONST64(a) (V64)a - #define STORE64(a, b) a = (UINT64)b - #endif - #define ROL64(a, o) _mm_or_si64(_mm_slli_si64(a, o), _mm_srli_si64(a, 64-(o))) - #define XOR64(a, b) _mm_xor_si64(a, b) - #define XOReq64(a, b) a = _mm_xor_si64(a, b) - - #include "KeccakF-1600-simd64.macros" - - #ifdef UseBebigokimisa - #error "UseBebigokimisa cannot be used in combination with UseMMX" - #endif -#else - #if defined(_MSC_VER) - #define ROL64(a, offset) _rotl64(a, offset) - #elif defined(UseSHLD) - #define ROL64(x,N) ({ \ - register UINT64 __out; \ - register UINT64 __in = x; \ - __asm__ ("shld %2,%0,%0" : "=r"(__out) : "0"(__in), "i"(N)); \ - __out; \ - }) - #else - #define ROL64(a, offset) ((((UINT64)a) << offset) ^ (((UINT64)a) >> (64-offset))) - #endif - - #include "KeccakF-1600-64.macros" -#endif - -#include "KeccakF-1600-unrolling.macros" - -static void KeccakPermutationOnWords(UINT64 *state) -{ - declareABCDE -#if (Unrolling != 24) - unsigned int i; -#endif - - copyFromState(A, state) - rounds -#if defined(UseMMX) - _mm_empty(); -#endif -} - -static void KeccakPermutationOnWordsAfterXoring(UINT64 *state, const UINT64 *input, unsigned int laneCount) -{ - declareABCDE -#if (Unrolling != 24) - unsigned int i; -#endif - unsigned int j; - - for(j=0; j> (8*i)) & 0xFF; -} -#endif - - -#ifdef ProvideFast1024 -static void KeccakExtract1024bits(const unsigned char *state, unsigned char *data) -{ -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - memcpy(data, state, 128); -#else - unsigned int i; - - for(i=0; i<16; i++) - fromWordToBytes(data+(i*8), ((const UINT64*)state)[i]); -#endif -#ifdef UseBebigokimisa - ((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1]; - ((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2]; - ((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8]; - ((UINT64*)data)[12] = ~((UINT64*)data)[12]; -#endif -} -#endif - -static void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount) -{ -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) - memcpy(data, state, laneCount*8); -#else - unsigned int i; - - for(i=0; i 1) { - ((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1]; - if (laneCount > 2) { - ((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2]; - if (laneCount > 8) { - ((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8]; - if (laneCount > 12) { - ((UINT64*)data)[12] = ~((UINT64*)data)[12]; - if (laneCount > 17) { - ((UINT64*)data)[17] = ~((UINT64*)data)[17]; - if (laneCount > 20) { - ((UINT64*)data)[20] = ~((UINT64*)data)[20]; - } - } - } - } - } - } -#endif -} diff --git a/Modules/_sha3/keccak/KeccakF-1600-simd128.macros b/Modules/_sha3/keccak/KeccakF-1600-simd128.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-simd128.macros +++ /dev/null @@ -1,651 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define declareABCDE \ - V6464 Abage, Abegi, Abigo, Abogu, Abuga; \ - V6464 Akame, Akemi, Akimo, Akomu, Akuma; \ - V6464 Abae, Abio, Agae, Agio, Akae, Akio, Amae, Amio, Asae, Asio; \ - V64 Aba, Abe, Abi, Abo, Abu; \ - V64 Aga, Age, Agi, Ago, Agu; \ - V64 Aka, Ake, Aki, Ako, Aku; \ - V64 Ama, Ame, Ami, Amo, Amu; \ - V64 Asa, Ase, Asi, Aso, Asu; \ - V128 Bbage, Bbegi, Bbigo, Bbogu, Bbuga; \ - V128 Bkame, Bkemi, Bkimo, Bkomu, Bkuma; \ - V64 Bba, Bbe, Bbi, Bbo, Bbu; \ - V64 Bga, Bge, Bgi, Bgo, Bgu; \ - V64 Bka, Bke, Bki, Bko, Bku; \ - V64 Bma, Bme, Bmi, Bmo, Bmu; \ - V64 Bsa, Bse, Bsi, Bso, Bsu; \ - V128 Cae, Cei, Cio, Cou, Cua, Dei, Dou; \ - V64 Ca, Ce, Ci, Co, Cu; \ - V64 Da, De, Di, Do, Du; \ - V6464 Ebage, Ebegi, Ebigo, Ebogu, Ebuga; \ - V6464 Ekame, Ekemi, Ekimo, Ekomu, Ekuma; \ - V64 Eba, Ebe, Ebi, Ebo, Ebu; \ - V64 Ega, Ege, Egi, Ego, Egu; \ - V64 Eka, Eke, Eki, Eko, Eku; \ - V64 Ema, Eme, Emi, Emo, Emu; \ - V64 Esa, Ese, Esi, Eso, Esu; \ - V128 Zero; - -#define prepareTheta - -#define computeD \ - Cua = GET64LOLO(Cu, Cae); \ - Dei = XOR128(Cae, ROL64in128(Cio, 1)); \ - Dou = XOR128(Cio, ROL64in128(Cua, 1)); \ - Da = XOR64(Cu, ROL64in128(COPY64HI2LO(Cae), 1)); \ - De = Dei; \ - Di = COPY64HI2LO(Dei); \ - Do = Dou; \ - Du = COPY64HI2LO(Dou); - -/* --- Theta Rho Pi Chi Iota Prepare-theta */ -/* --- 64-bit lanes mapped to 64-bit and 128-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - computeD \ - \ - A##ba = LOAD64(A##bage.v64[0]); \ - XOReq64(A##ba, Da); \ - Bba = A##ba; \ - XOReq64(A##gu, Du); \ - Bge = ROL64(A##gu, 20); \ - Bbage = GET64LOLO(Bba, Bge); \ - A##ge = LOAD64(A##bage.v64[1]); \ - XOReq64(A##ge, De); \ - Bbe = ROL64(A##ge, 44); \ - A##ka = LOAD64(A##kame.v64[0]); \ - XOReq64(A##ka, Da); \ - Bgi = ROL64(A##ka, 3); \ - Bbegi = GET64LOLO(Bbe, Bgi); \ - XOReq64(A##ki, Di); \ - Bbi = ROL64(A##ki, 43); \ - A##me = LOAD64(A##kame.v64[1]); \ - XOReq64(A##me, De); \ - Bgo = ROL64(A##me, 45); \ - Bbigo = GET64LOLO(Bbi, Bgo); \ - E##bage.v128 = XOR128(Bbage, ANDnu128(Bbegi, Bbigo)); \ - XOReq128(E##bage.v128, CONST64(KeccakF1600RoundConstants[i])); \ - Cae = E##bage.v128; \ - XOReq64(A##mo, Do); \ - Bbo = ROL64(A##mo, 21); \ - XOReq64(A##si, Di); \ - Bgu = ROL64(A##si, 61); \ - Bbogu = GET64LOLO(Bbo, Bgu); \ - E##begi.v128 = XOR128(Bbegi, ANDnu128(Bbigo, Bbogu)); \ - Cei = E##begi.v128; \ - XOReq64(A##su, Du); \ - Bbu = ROL64(A##su, 14); \ - XOReq64(A##bo, Do); \ - Bga = ROL64(A##bo, 28); \ - Bbuga = GET64LOLO(Bbu, Bga); \ - E##bigo.v128 = XOR128(Bbigo, ANDnu128(Bbogu, Bbuga)); \ - E##bi = E##bigo.v128; \ - E##go = GET64HIHI(E##bigo.v128, E##bigo.v128); \ - Cio = E##bigo.v128; \ - E##bogu.v128 = XOR128(Bbogu, ANDnu128(Bbuga, Bbage)); \ - E##bo = E##bogu.v128; \ - E##gu = GET64HIHI(E##bogu.v128, E##bogu.v128); \ - Cou = E##bogu.v128; \ - E##buga.v128 = XOR128(Bbuga, ANDnu128(Bbage, Bbegi)); \ - E##bu = E##buga.v128; \ - E##ga = GET64HIHI(E##buga.v128, E##buga.v128); \ - Cua = E##buga.v128; \ -\ - A##be = LOAD64(A##begi.v64[0]); \ - XOReq64(A##be, De); \ - Bka = ROL64(A##be, 1); \ - XOReq64(A##ga, Da); \ - Bme = ROL64(A##ga, 36); \ - Bkame = GET64LOLO(Bka, Bme); \ - A##gi = LOAD64(A##begi.v64[1]); \ - XOReq64(A##gi, Di); \ - Bke = ROL64(A##gi, 6); \ - A##ke = LOAD64(A##kemi.v64[0]); \ - XOReq64(A##ke, De); \ - Bmi = ROL64(A##ke, 10); \ - Bkemi = GET64LOLO(Bke, Bmi); \ - XOReq64(A##ko, Do); \ - Bki = ROL64(A##ko, 25); \ - A##mi = LOAD64(A##kemi.v64[1]); \ - XOReq64(A##mi, Di); \ - Bmo = ROL64(A##mi, 15); \ - Bkimo = GET64LOLO(Bki, Bmo); \ - E##kame.v128 = XOR128(Bkame, ANDnu128(Bkemi, Bkimo)); \ - XOReq128(Cae, E##kame.v128); \ - Bkomu = GET64LOLO(XOR64(A##mu, Du), XOR64(A##so, Do)); \ - Bkomu = SHUFFLEBYTES128(Bkomu, CONST128(rho8_56)); \ - E##kemi.v128 = XOR128(Bkemi, ANDnu128(Bkimo, Bkomu)); \ - XOReq128(Cei, E##kemi.v128); \ - XOReq64(A##sa, Da); \ - Bku = ROL64(A##sa, 18); \ - XOReq64(A##bu, Du); \ - Bma = ROL64(A##bu, 27); \ - Bkuma = GET64LOLO(Bku, Bma); \ - E##kimo.v128 = XOR128(Bkimo, ANDnu128(Bkomu, Bkuma)); \ - E##ki = E##kimo.v128; \ - E##mo = GET64HIHI(E##kimo.v128, E##kimo.v128); \ - XOReq128(Cio, E##kimo.v128); \ - E##komu.v128 = XOR128(Bkomu, ANDnu128(Bkuma, Bkame)); \ - E##ko = E##komu.v128; \ - E##mu = GET64HIHI(E##komu.v128, E##komu.v128); \ - XOReq128(Cou, E##komu.v128); \ - E##kuma.v128 = XOR128(Bkuma, ANDnu128(Bkame, Bkemi)); \ - E##ku = E##kuma.v128; \ - E##ma = GET64HIHI(E##kuma.v128, E##kuma.v128); \ - XOReq128(Cua, E##kuma.v128); \ -\ - XOReq64(A##bi, Di); \ - Bsa = ROL64(A##bi, 62); \ - XOReq64(A##go, Do); \ - Bse = ROL64(A##go, 55); \ - XOReq64(A##ku, Du); \ - Bsi = ROL64(A##ku, 39); \ - E##sa = XOR64(Bsa, ANDnu64(Bse, Bsi)); \ - Ca = E##sa; \ - XOReq64(A##ma, Da); \ - Bso = ROL64(A##ma, 41); \ - E##se = XOR64(Bse, ANDnu64(Bsi, Bso)); \ - Ce = E##se; \ - XOReq128(Cae, GET64LOLO(Ca, Ce)); \ - XOReq64(A##se, De); \ - Bsu = ROL64(A##se, 2); \ - E##si = XOR64(Bsi, ANDnu64(Bso, Bsu)); \ - Ci = E##si; \ - E##so = XOR64(Bso, ANDnu64(Bsu, Bsa)); \ - Co = E##so; \ - XOReq128(Cio, GET64LOLO(Ci, Co)); \ - E##su = XOR64(Bsu, ANDnu64(Bsa, Bse)); \ - Cu = E##su; \ -\ - Zero = ZERO128(); \ - XOReq128(Cae, GET64HIHI(Cua, Zero)); \ - XOReq128(Cae, GET64LOLO(Zero, Cei)); \ - XOReq128(Cio, GET64HIHI(Cei, Zero)); \ - XOReq128(Cio, GET64LOLO(Zero, Cou)); \ - XOReq128(Cua, GET64HIHI(Cou, Zero)); \ - XOReq64(Cu, Cua); \ - -/* --- Theta Rho Pi Chi Iota */ -/* --- 64-bit lanes mapped to 64-bit and 128-bit words */ -#define thetaRhoPiChiIota(i, A, E) thetaRhoPiChiIotaPrepareTheta(i, A, E) - -static const UINT64 KeccakF1600RoundConstants[24] = { - 0x0000000000000001ULL, - 0x0000000000008082ULL, - 0x800000000000808aULL, - 0x8000000080008000ULL, - 0x000000000000808bULL, - 0x0000000080000001ULL, - 0x8000000080008081ULL, - 0x8000000000008009ULL, - 0x000000000000008aULL, - 0x0000000000000088ULL, - 0x0000000080008009ULL, - 0x000000008000000aULL, - 0x000000008000808bULL, - 0x800000000000008bULL, - 0x8000000000008089ULL, - 0x8000000000008003ULL, - 0x8000000000008002ULL, - 0x8000000000000080ULL, - 0x000000000000800aULL, - 0x800000008000000aULL, - 0x8000000080008081ULL, - 0x8000000000008080ULL, - 0x0000000080000001ULL, - 0x8000000080008008ULL }; - -#define copyFromStateAndXor576bits(X, state, input) \ - X##bae.v128 = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae.v128; \ - X##be = GET64HIHI(X##bae.v128, X##bae.v128); \ - Cae = X##bae.v128; \ - X##bio.v128 = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio.v128; \ - X##bo = GET64HIHI(X##bio.v128, X##bio.v128); \ - Cio = X##bio.v128; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cu = X##bu; \ - X##gae.v128 = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae.v128; \ - X##ge = GET64HIHI(X##gae.v128, X##gae.v128); \ - X##bage.v128 = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae.v128); \ - X##gio.v128 = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio.v128; \ - X##begi.v128 = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio.v128, X##gio.v128); \ - XOReq128(Cio, X##gio.v128); \ - X##gu = LOAD64(state[ 9]); \ - XOReq64(Cu, X##gu); \ - X##kae.v128 = LOAD128(state[10]); \ - X##ka = X##kae.v128; \ - X##ke = GET64HIHI(X##kae.v128, X##kae.v128); \ - XOReq128(Cae, X##kae.v128); \ - X##kio.v128 = LOAD128(state[12]); \ - X##ki = X##kio.v128; \ - X##ko = GET64HIHI(X##kio.v128, X##kio.v128); \ - XOReq128(Cio, X##kio.v128); \ - X##ku = LOAD64(state[14]); \ - XOReq64(Cu, X##ku); \ - X##mae.v128 = LOAD128u(state[15]); \ - X##ma = X##mae.v128; \ - X##me = GET64HIHI(X##mae.v128, X##mae.v128); \ - X##kame.v128 = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, X##mae.v128); \ - X##mio.v128 = LOAD128u(state[17]); \ - X##mi = X##mio.v128; \ - X##kemi.v128 = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio.v128, X##mio.v128); \ - XOReq128(Cio, X##mio.v128); \ - X##mu = LOAD64(state[19]); \ - XOReq64(Cu, X##mu); \ - X##sae.v128 = LOAD128(state[20]); \ - X##sa = X##sae.v128; \ - X##se = GET64HIHI(X##sae.v128, X##sae.v128); \ - XOReq128(Cae, X##sae.v128); \ - X##sio.v128 = LOAD128(state[22]); \ - X##si = X##sio.v128; \ - X##so = GET64HIHI(X##sio.v128, X##sio.v128); \ - XOReq128(Cio, X##sio.v128); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cu, X##su); \ - -#define copyFromStateAndXor832bits(X, state, input) \ - X##bae.v128 = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae.v128; \ - X##be = GET64HIHI(X##bae.v128, X##bae.v128); \ - Cae = X##bae.v128; \ - X##bio.v128 = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio.v128; \ - X##bo = GET64HIHI(X##bio.v128, X##bio.v128); \ - Cio = X##bio.v128; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cu = X##bu; \ - X##gae.v128 = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae.v128; \ - X##ge = GET64HIHI(X##gae.v128, X##gae.v128); \ - X##bage.v128 = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae.v128); \ - X##gio.v128 = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio.v128; \ - X##begi.v128 = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio.v128, X##gio.v128); \ - XOReq128(Cio, X##gio.v128); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - XOReq64(Cu, X##gu); \ - X##kae.v128 = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae.v128; \ - X##ke = GET64HIHI(X##kae.v128, X##kae.v128); \ - XOReq128(Cae, X##kae.v128); \ - X##kio.v128 = XOR128(LOAD128(state[12]), LOAD64(input[12])); \ - X##ki = X##kio.v128; \ - X##ko = GET64HIHI(X##kio.v128, X##kio.v128); \ - XOReq128(Cio, X##kio.v128); \ - X##ku = LOAD64(state[14]); \ - XOReq64(Cu, X##ku); \ - X##mae.v128 = LOAD128u(state[15]); \ - X##ma = X##mae.v128; \ - X##me = GET64HIHI(X##mae.v128, X##mae.v128); \ - X##kame.v128 = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, X##mae.v128); \ - X##mio.v128 = LOAD128u(state[17]); \ - X##mi = X##mio.v128; \ - X##kemi.v128 = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio.v128, X##mio.v128); \ - XOReq128(Cio, X##mio.v128); \ - X##mu = LOAD64(state[19]); \ - XOReq64(Cu, X##mu); \ - X##sae.v128 = LOAD128(state[20]); \ - X##sa = X##sae.v128; \ - X##se = GET64HIHI(X##sae.v128, X##sae.v128); \ - XOReq128(Cae, X##sae.v128); \ - X##sio.v128 = LOAD128(state[22]); \ - X##si = X##sio.v128; \ - X##so = GET64HIHI(X##sio.v128, X##sio.v128); \ - XOReq128(Cio, X##sio.v128); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cu, X##su); \ - -#define copyFromStateAndXor1024bits(X, state, input) \ - X##bae.v128 = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae.v128; \ - X##be = GET64HIHI(X##bae.v128, X##bae.v128); \ - Cae = X##bae.v128; \ - X##bio.v128 = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio.v128; \ - X##bo = GET64HIHI(X##bio.v128, X##bio.v128); \ - Cio = X##bio.v128; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cu = X##bu; \ - X##gae.v128 = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae.v128; \ - X##ge = GET64HIHI(X##gae.v128, X##gae.v128); \ - X##bage.v128 = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae.v128); \ - X##gio.v128 = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio.v128; \ - X##begi.v128 = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio.v128, X##gio.v128); \ - XOReq128(Cio, X##gio.v128); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - XOReq64(Cu, X##gu); \ - X##kae.v128 = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae.v128; \ - X##ke = GET64HIHI(X##kae.v128, X##kae.v128); \ - XOReq128(Cae, X##kae.v128); \ - X##kio.v128 = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio.v128; \ - X##ko = GET64HIHI(X##kio.v128, X##kio.v128); \ - XOReq128(Cio, X##kio.v128); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - XOReq64(Cu, X##ku); \ - X##mae.v128 = XOR128(LOAD128u(state[15]), LOAD64(input[15])); \ - X##ma = X##mae.v128; \ - X##me = GET64HIHI(X##mae.v128, X##mae.v128); \ - X##kame.v128 = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, X##mae.v128); \ - X##mio.v128 = LOAD128u(state[17]); \ - X##mi = X##mio.v128; \ - X##kemi.v128 = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio.v128, X##mio.v128); \ - XOReq128(Cio, X##mio.v128); \ - X##mu = LOAD64(state[19]); \ - XOReq64(Cu, X##mu); \ - X##sae.v128 = LOAD128(state[20]); \ - X##sa = X##sae.v128; \ - X##se = GET64HIHI(X##sae.v128, X##sae.v128); \ - XOReq128(Cae, X##sae.v128); \ - X##sio.v128 = LOAD128(state[22]); \ - X##si = X##sio.v128; \ - X##so = GET64HIHI(X##sio.v128, X##sio.v128); \ - XOReq128(Cio, X##sio.v128); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cu, X##su); \ - -#define copyFromStateAndXor1088bits(X, state, input) \ - X##bae.v128 = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae.v128; \ - X##be = GET64HIHI(X##bae.v128, X##bae.v128); \ - Cae = X##bae.v128; \ - X##bio.v128 = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio.v128; \ - X##bo = GET64HIHI(X##bio.v128, X##bio.v128); \ - Cio = X##bio.v128; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cu = X##bu; \ - X##gae.v128 = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae.v128; \ - X##ge = GET64HIHI(X##gae.v128, X##gae.v128); \ - X##bage.v128 = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae.v128); \ - X##gio.v128 = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio.v128; \ - X##begi.v128 = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio.v128, X##gio.v128); \ - XOReq128(Cio, X##gio.v128); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - XOReq64(Cu, X##gu); \ - X##kae.v128 = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae.v128; \ - X##ke = GET64HIHI(X##kae.v128, X##kae.v128); \ - XOReq128(Cae, X##kae.v128); \ - X##kio.v128 = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio.v128; \ - X##ko = GET64HIHI(X##kio.v128, X##kio.v128); \ - XOReq128(Cio, X##kio.v128); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - XOReq64(Cu, X##ku); \ - X##mae.v128 = XOR128(LOAD128u(state[15]), LOAD128u(input[15])); \ - X##ma = X##mae.v128; \ - X##me = GET64HIHI(X##mae.v128, X##mae.v128); \ - X##kame.v128 = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, X##mae.v128); \ - X##mio.v128 = LOAD128u(state[17]); \ - X##mi = X##mio.v128; \ - X##kemi.v128 = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio.v128, X##mio.v128); \ - XOReq128(Cio, X##mio.v128); \ - X##mu = LOAD64(state[19]); \ - XOReq64(Cu, X##mu); \ - X##sae.v128 = LOAD128(state[20]); \ - X##sa = X##sae.v128; \ - X##se = GET64HIHI(X##sae.v128, X##sae.v128); \ - XOReq128(Cae, X##sae.v128); \ - X##sio.v128 = LOAD128(state[22]); \ - X##si = X##sio.v128; \ - X##so = GET64HIHI(X##sio.v128, X##sio.v128); \ - XOReq128(Cio, X##sio.v128); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cu, X##su); \ - -#define copyFromStateAndXor1152bits(X, state, input) \ - X##bae.v128 = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae.v128; \ - X##be = GET64HIHI(X##bae.v128, X##bae.v128); \ - Cae = X##bae.v128; \ - X##bio.v128 = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio.v128; \ - X##bo = GET64HIHI(X##bio.v128, X##bio.v128); \ - Cio = X##bio.v128; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cu = X##bu; \ - X##gae.v128 = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae.v128; \ - X##ge = GET64HIHI(X##gae.v128, X##gae.v128); \ - X##bage.v128 = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae.v128); \ - X##gio.v128 = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio.v128; \ - X##begi.v128 = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio.v128, X##gio.v128); \ - XOReq128(Cio, X##gio.v128); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - XOReq64(Cu, X##gu); \ - X##kae.v128 = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae.v128; \ - X##ke = GET64HIHI(X##kae.v128, X##kae.v128); \ - XOReq128(Cae, X##kae.v128); \ - X##kio.v128 = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio.v128; \ - X##ko = GET64HIHI(X##kio.v128, X##kio.v128); \ - XOReq128(Cio, X##kio.v128); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - XOReq64(Cu, X##ku); \ - X##mae.v128 = XOR128(LOAD128u(state[15]), LOAD128u(input[15])); \ - X##ma = X##mae.v128; \ - X##me = GET64HIHI(X##mae.v128, X##mae.v128); \ - X##kame.v128 = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, X##mae.v128); \ - X##mio.v128 = XOR128(LOAD128u(state[17]), LOAD64(input[17])); \ - X##mi = X##mio.v128; \ - X##kemi.v128 = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio.v128, X##mio.v128); \ - XOReq128(Cio, X##mio.v128); \ - X##mu = LOAD64(state[19]); \ - XOReq64(Cu, X##mu); \ - X##sae.v128 = LOAD128(state[20]); \ - X##sa = X##sae.v128; \ - X##se = GET64HIHI(X##sae.v128, X##sae.v128); \ - XOReq128(Cae, X##sae.v128); \ - X##sio.v128 = LOAD128(state[22]); \ - X##si = X##sio.v128; \ - X##so = GET64HIHI(X##sio.v128, X##sio.v128); \ - XOReq128(Cio, X##sio.v128); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cu, X##su); \ - -#define copyFromStateAndXor1344bits(X, state, input) \ - X##bae.v128 = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae.v128; \ - X##be = GET64HIHI(X##bae.v128, X##bae.v128); \ - Cae = X##bae.v128; \ - X##bio.v128 = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio.v128; \ - X##bo = GET64HIHI(X##bio.v128, X##bio.v128); \ - Cio = X##bio.v128; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cu = X##bu; \ - X##gae.v128 = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae.v128; \ - X##ge = GET64HIHI(X##gae.v128, X##gae.v128); \ - X##bage.v128 = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae.v128); \ - X##gio.v128 = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio.v128; \ - X##begi.v128 = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio.v128, X##gio.v128); \ - XOReq128(Cio, X##gio.v128); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - XOReq64(Cu, X##gu); \ - X##kae.v128 = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae.v128; \ - X##ke = GET64HIHI(X##kae.v128, X##kae.v128); \ - XOReq128(Cae, X##kae.v128); \ - X##kio.v128 = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio.v128; \ - X##ko = GET64HIHI(X##kio.v128, X##kio.v128); \ - XOReq128(Cio, X##kio.v128); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - XOReq64(Cu, X##ku); \ - X##mae.v128 = XOR128(LOAD128u(state[15]), LOAD128u(input[15])); \ - X##ma = X##mae.v128; \ - X##me = GET64HIHI(X##mae.v128, X##mae.v128); \ - X##kame.v128 = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, X##mae.v128); \ - X##mio.v128 = XOR128(LOAD128u(state[17]), LOAD128u(input[17])); \ - X##mi = X##mio.v128; \ - X##kemi.v128 = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio.v128, X##mio.v128); \ - XOReq128(Cio, X##mio.v128); \ - X##mu = XOR64(LOAD64(state[19]), LOAD64(input[19])); \ - XOReq64(Cu, X##mu); \ - X##sae.v128 = XOR128(LOAD128(state[20]), LOAD64(input[20])); \ - X##sa = X##sae.v128; \ - X##se = GET64HIHI(X##sae.v128, X##sae.v128); \ - XOReq128(Cae, X##sae.v128); \ - X##sio.v128 = LOAD128(state[22]); \ - X##si = X##sio.v128; \ - X##so = GET64HIHI(X##sio.v128, X##sio.v128); \ - XOReq128(Cio, X##sio.v128); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cu, X##su); \ - -#define copyFromState(X, state) \ - X##bae.v128 = LOAD128(state[ 0]); \ - X##ba = X##bae.v128; \ - X##be = GET64HIHI(X##bae.v128, X##bae.v128); \ - Cae = X##bae.v128; \ - X##bio.v128 = LOAD128(state[ 2]); \ - X##bi = X##bio.v128; \ - X##bo = GET64HIHI(X##bio.v128, X##bio.v128); \ - Cio = X##bio.v128; \ - X##bu = LOAD64(state[ 4]); \ - Cu = X##bu; \ - X##gae.v128 = LOAD128u(state[ 5]); \ - X##ga = X##gae.v128; \ - X##ge = GET64HIHI(X##gae.v128, X##gae.v128); \ - X##bage.v128 = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae.v128); \ - X##gio.v128 = LOAD128u(state[ 7]); \ - X##gi = X##gio.v128; \ - X##begi.v128 = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio.v128, X##gio.v128); \ - XOReq128(Cio, X##gio.v128); \ - X##gu = LOAD64(state[ 9]); \ - XOReq64(Cu, X##gu); \ - X##kae.v128 = LOAD128(state[10]); \ - X##ka = X##kae.v128; \ - X##ke = GET64HIHI(X##kae.v128, X##kae.v128); \ - XOReq128(Cae, X##kae.v128); \ - X##kio.v128 = LOAD128(state[12]); \ - X##ki = X##kio.v128; \ - X##ko = GET64HIHI(X##kio.v128, X##kio.v128); \ - XOReq128(Cio, X##kio.v128); \ - X##ku = LOAD64(state[14]); \ - XOReq64(Cu, X##ku); \ - X##mae.v128 = LOAD128u(state[15]); \ - X##ma = X##mae.v128; \ - X##me = GET64HIHI(X##mae.v128, X##mae.v128); \ - X##kame.v128 = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, X##mae.v128); \ - X##mio.v128 = LOAD128u(state[17]); \ - X##mi = X##mio.v128; \ - X##kemi.v128 = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio.v128, X##mio.v128); \ - XOReq128(Cio, X##mio.v128); \ - X##mu = LOAD64(state[19]); \ - XOReq64(Cu, X##mu); \ - X##sae.v128 = LOAD128(state[20]); \ - X##sa = X##sae.v128; \ - X##se = GET64HIHI(X##sae.v128, X##sae.v128); \ - XOReq128(Cae, X##sae.v128); \ - X##sio.v128 = LOAD128(state[22]); \ - X##si = X##sio.v128; \ - X##so = GET64HIHI(X##sio.v128, X##sio.v128); \ - XOReq128(Cio, X##sio.v128); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cu, X##su); \ - -#define copyToState(state, X) \ - state[ 0] = A##bage.v64[0]; \ - state[ 1] = A##begi.v64[0]; \ - STORE64(state[ 2], X##bi); \ - STORE64(state[ 3], X##bo); \ - STORE64(state[ 4], X##bu); \ - STORE64(state[ 5], X##ga); \ - state[ 6] = A##bage.v64[1]; \ - state[ 7] = A##begi.v64[1]; \ - STORE64(state[ 8], X##go); \ - STORE64(state[ 9], X##gu); \ - state[10] = X##kame.v64[0]; \ - state[11] = X##kemi.v64[0]; \ - STORE64(state[12], X##ki); \ - STORE64(state[13], X##ko); \ - STORE64(state[14], X##ku); \ - STORE64(state[15], X##ma); \ - state[16] = X##kame.v64[1]; \ - state[17] = X##kemi.v64[1]; \ - STORE64(state[18], X##mo); \ - STORE64(state[19], X##mu); \ - STORE64(state[20], X##sa); \ - STORE64(state[21], X##se); \ - STORE64(state[22], X##si); \ - STORE64(state[23], X##so); \ - STORE64(state[24], X##su); \ - -#define copyStateVariables(X, Y) \ - X##bage = Y##bage; \ - X##begi = Y##begi; \ - X##bi = Y##bi; \ - X##bo = Y##bo; \ - X##bu = Y##bu; \ - X##ga = Y##ga; \ - X##go = Y##go; \ - X##gu = Y##gu; \ - X##kame = Y##kame; \ - X##kemi = Y##kemi; \ - X##ki = Y##ki; \ - X##ko = Y##ko; \ - X##ku = Y##ku; \ - X##ma = Y##ma; \ - X##mo = Y##mo; \ - X##mu = Y##mu; \ - X##sa = Y##sa; \ - X##se = Y##se; \ - X##si = Y##si; \ - X##so = Y##so; \ - X##su = Y##su; \ - diff --git a/Modules/_sha3/keccak/KeccakF-1600-simd64.macros b/Modules/_sha3/keccak/KeccakF-1600-simd64.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-simd64.macros +++ /dev/null @@ -1,517 +0,0 @@ -/* -Code automatically generated by KeccakTools! - -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define declareABCDE \ - V64 Aba, Abe, Abi, Abo, Abu; \ - V64 Aga, Age, Agi, Ago, Agu; \ - V64 Aka, Ake, Aki, Ako, Aku; \ - V64 Ama, Ame, Ami, Amo, Amu; \ - V64 Asa, Ase, Asi, Aso, Asu; \ - V64 Bba, Bbe, Bbi, Bbo, Bbu; \ - V64 Bga, Bge, Bgi, Bgo, Bgu; \ - V64 Bka, Bke, Bki, Bko, Bku; \ - V64 Bma, Bme, Bmi, Bmo, Bmu; \ - V64 Bsa, Bse, Bsi, Bso, Bsu; \ - V64 Ca, Ce, Ci, Co, Cu; \ - V64 Da, De, Di, Do, Du; \ - V64 Eba, Ebe, Ebi, Ebo, Ebu; \ - V64 Ega, Ege, Egi, Ego, Egu; \ - V64 Eka, Eke, Eki, Eko, Eku; \ - V64 Ema, Eme, Emi, Emo, Emu; \ - V64 Esa, Ese, Esi, Eso, Esu; \ - -#define prepareTheta \ - Ca = XOR64(Aba, XOR64(Aga, XOR64(Aka, XOR64(Ama, Asa)))); \ - Ce = XOR64(Abe, XOR64(Age, XOR64(Ake, XOR64(Ame, Ase)))); \ - Ci = XOR64(Abi, XOR64(Agi, XOR64(Aki, XOR64(Ami, Asi)))); \ - Co = XOR64(Abo, XOR64(Ago, XOR64(Ako, XOR64(Amo, Aso)))); \ - Cu = XOR64(Abu, XOR64(Agu, XOR64(Aku, XOR64(Amu, Asu)))); \ - -/* --- Code for round, with prepare-theta */ -/* --- 64-bit lanes mapped to 64-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - Da = XOR64(Cu, ROL64(Ce, 1)); \ - De = XOR64(Ca, ROL64(Ci, 1)); \ - Di = XOR64(Ce, ROL64(Co, 1)); \ - Do = XOR64(Ci, ROL64(Cu, 1)); \ - Du = XOR64(Co, ROL64(Ca, 1)); \ -\ - XOReq64(A##ba, Da); \ - Bba = A##ba; \ - XOReq64(A##ge, De); \ - Bbe = ROL64(A##ge, 44); \ - XOReq64(A##ki, Di); \ - Bbi = ROL64(A##ki, 43); \ - E##ba = XOR64(Bba, ANDnu64(Bbe, Bbi)); \ - XOReq64(E##ba, CONST64(KeccakF1600RoundConstants[i])); \ - Ca = E##ba; \ - XOReq64(A##mo, Do); \ - Bbo = ROL64(A##mo, 21); \ - E##be = XOR64(Bbe, ANDnu64(Bbi, Bbo)); \ - Ce = E##be; \ - XOReq64(A##su, Du); \ - Bbu = ROL64(A##su, 14); \ - E##bi = XOR64(Bbi, ANDnu64(Bbo, Bbu)); \ - Ci = E##bi; \ - E##bo = XOR64(Bbo, ANDnu64(Bbu, Bba)); \ - Co = E##bo; \ - E##bu = XOR64(Bbu, ANDnu64(Bba, Bbe)); \ - Cu = E##bu; \ -\ - XOReq64(A##bo, Do); \ - Bga = ROL64(A##bo, 28); \ - XOReq64(A##gu, Du); \ - Bge = ROL64(A##gu, 20); \ - XOReq64(A##ka, Da); \ - Bgi = ROL64(A##ka, 3); \ - E##ga = XOR64(Bga, ANDnu64(Bge, Bgi)); \ - XOReq64(Ca, E##ga); \ - XOReq64(A##me, De); \ - Bgo = ROL64(A##me, 45); \ - E##ge = XOR64(Bge, ANDnu64(Bgi, Bgo)); \ - XOReq64(Ce, E##ge); \ - XOReq64(A##si, Di); \ - Bgu = ROL64(A##si, 61); \ - E##gi = XOR64(Bgi, ANDnu64(Bgo, Bgu)); \ - XOReq64(Ci, E##gi); \ - E##go = XOR64(Bgo, ANDnu64(Bgu, Bga)); \ - XOReq64(Co, E##go); \ - E##gu = XOR64(Bgu, ANDnu64(Bga, Bge)); \ - XOReq64(Cu, E##gu); \ -\ - XOReq64(A##be, De); \ - Bka = ROL64(A##be, 1); \ - XOReq64(A##gi, Di); \ - Bke = ROL64(A##gi, 6); \ - XOReq64(A##ko, Do); \ - Bki = ROL64(A##ko, 25); \ - E##ka = XOR64(Bka, ANDnu64(Bke, Bki)); \ - XOReq64(Ca, E##ka); \ - XOReq64(A##mu, Du); \ - Bko = ROL64(A##mu, 8); \ - E##ke = XOR64(Bke, ANDnu64(Bki, Bko)); \ - XOReq64(Ce, E##ke); \ - XOReq64(A##sa, Da); \ - Bku = ROL64(A##sa, 18); \ - E##ki = XOR64(Bki, ANDnu64(Bko, Bku)); \ - XOReq64(Ci, E##ki); \ - E##ko = XOR64(Bko, ANDnu64(Bku, Bka)); \ - XOReq64(Co, E##ko); \ - E##ku = XOR64(Bku, ANDnu64(Bka, Bke)); \ - XOReq64(Cu, E##ku); \ -\ - XOReq64(A##bu, Du); \ - Bma = ROL64(A##bu, 27); \ - XOReq64(A##ga, Da); \ - Bme = ROL64(A##ga, 36); \ - XOReq64(A##ke, De); \ - Bmi = ROL64(A##ke, 10); \ - E##ma = XOR64(Bma, ANDnu64(Bme, Bmi)); \ - XOReq64(Ca, E##ma); \ - XOReq64(A##mi, Di); \ - Bmo = ROL64(A##mi, 15); \ - E##me = XOR64(Bme, ANDnu64(Bmi, Bmo)); \ - XOReq64(Ce, E##me); \ - XOReq64(A##so, Do); \ - Bmu = ROL64(A##so, 56); \ - E##mi = XOR64(Bmi, ANDnu64(Bmo, Bmu)); \ - XOReq64(Ci, E##mi); \ - E##mo = XOR64(Bmo, ANDnu64(Bmu, Bma)); \ - XOReq64(Co, E##mo); \ - E##mu = XOR64(Bmu, ANDnu64(Bma, Bme)); \ - XOReq64(Cu, E##mu); \ -\ - XOReq64(A##bi, Di); \ - Bsa = ROL64(A##bi, 62); \ - XOReq64(A##go, Do); \ - Bse = ROL64(A##go, 55); \ - XOReq64(A##ku, Du); \ - Bsi = ROL64(A##ku, 39); \ - E##sa = XOR64(Bsa, ANDnu64(Bse, Bsi)); \ - XOReq64(Ca, E##sa); \ - XOReq64(A##ma, Da); \ - Bso = ROL64(A##ma, 41); \ - E##se = XOR64(Bse, ANDnu64(Bsi, Bso)); \ - XOReq64(Ce, E##se); \ - XOReq64(A##se, De); \ - Bsu = ROL64(A##se, 2); \ - E##si = XOR64(Bsi, ANDnu64(Bso, Bsu)); \ - XOReq64(Ci, E##si); \ - E##so = XOR64(Bso, ANDnu64(Bsu, Bsa)); \ - XOReq64(Co, E##so); \ - E##su = XOR64(Bsu, ANDnu64(Bsa, Bse)); \ - XOReq64(Cu, E##su); \ -\ - -/* --- Code for round */ -/* --- 64-bit lanes mapped to 64-bit words */ -#define thetaRhoPiChiIota(i, A, E) \ - Da = XOR64(Cu, ROL64(Ce, 1)); \ - De = XOR64(Ca, ROL64(Ci, 1)); \ - Di = XOR64(Ce, ROL64(Co, 1)); \ - Do = XOR64(Ci, ROL64(Cu, 1)); \ - Du = XOR64(Co, ROL64(Ca, 1)); \ -\ - XOReq64(A##ba, Da); \ - Bba = A##ba; \ - XOReq64(A##ge, De); \ - Bbe = ROL64(A##ge, 44); \ - XOReq64(A##ki, Di); \ - Bbi = ROL64(A##ki, 43); \ - E##ba = XOR64(Bba, ANDnu64(Bbe, Bbi)); \ - XOReq64(E##ba, CONST64(KeccakF1600RoundConstants[i])); \ - XOReq64(A##mo, Do); \ - Bbo = ROL64(A##mo, 21); \ - E##be = XOR64(Bbe, ANDnu64(Bbi, Bbo)); \ - XOReq64(A##su, Du); \ - Bbu = ROL64(A##su, 14); \ - E##bi = XOR64(Bbi, ANDnu64(Bbo, Bbu)); \ - E##bo = XOR64(Bbo, ANDnu64(Bbu, Bba)); \ - E##bu = XOR64(Bbu, ANDnu64(Bba, Bbe)); \ -\ - XOReq64(A##bo, Do); \ - Bga = ROL64(A##bo, 28); \ - XOReq64(A##gu, Du); \ - Bge = ROL64(A##gu, 20); \ - XOReq64(A##ka, Da); \ - Bgi = ROL64(A##ka, 3); \ - E##ga = XOR64(Bga, ANDnu64(Bge, Bgi)); \ - XOReq64(A##me, De); \ - Bgo = ROL64(A##me, 45); \ - E##ge = XOR64(Bge, ANDnu64(Bgi, Bgo)); \ - XOReq64(A##si, Di); \ - Bgu = ROL64(A##si, 61); \ - E##gi = XOR64(Bgi, ANDnu64(Bgo, Bgu)); \ - E##go = XOR64(Bgo, ANDnu64(Bgu, Bga)); \ - E##gu = XOR64(Bgu, ANDnu64(Bga, Bge)); \ -\ - XOReq64(A##be, De); \ - Bka = ROL64(A##be, 1); \ - XOReq64(A##gi, Di); \ - Bke = ROL64(A##gi, 6); \ - XOReq64(A##ko, Do); \ - Bki = ROL64(A##ko, 25); \ - E##ka = XOR64(Bka, ANDnu64(Bke, Bki)); \ - XOReq64(A##mu, Du); \ - Bko = ROL64(A##mu, 8); \ - E##ke = XOR64(Bke, ANDnu64(Bki, Bko)); \ - XOReq64(A##sa, Da); \ - Bku = ROL64(A##sa, 18); \ - E##ki = XOR64(Bki, ANDnu64(Bko, Bku)); \ - E##ko = XOR64(Bko, ANDnu64(Bku, Bka)); \ - E##ku = XOR64(Bku, ANDnu64(Bka, Bke)); \ -\ - XOReq64(A##bu, Du); \ - Bma = ROL64(A##bu, 27); \ - XOReq64(A##ga, Da); \ - Bme = ROL64(A##ga, 36); \ - XOReq64(A##ke, De); \ - Bmi = ROL64(A##ke, 10); \ - E##ma = XOR64(Bma, ANDnu64(Bme, Bmi)); \ - XOReq64(A##mi, Di); \ - Bmo = ROL64(A##mi, 15); \ - E##me = XOR64(Bme, ANDnu64(Bmi, Bmo)); \ - XOReq64(A##so, Do); \ - Bmu = ROL64(A##so, 56); \ - E##mi = XOR64(Bmi, ANDnu64(Bmo, Bmu)); \ - E##mo = XOR64(Bmo, ANDnu64(Bmu, Bma)); \ - E##mu = XOR64(Bmu, ANDnu64(Bma, Bme)); \ -\ - XOReq64(A##bi, Di); \ - Bsa = ROL64(A##bi, 62); \ - XOReq64(A##go, Do); \ - Bse = ROL64(A##go, 55); \ - XOReq64(A##ku, Du); \ - Bsi = ROL64(A##ku, 39); \ - E##sa = XOR64(Bsa, ANDnu64(Bse, Bsi)); \ - XOReq64(A##ma, Da); \ - Bso = ROL64(A##ma, 41); \ - E##se = XOR64(Bse, ANDnu64(Bsi, Bso)); \ - XOReq64(A##se, De); \ - Bsu = ROL64(A##se, 2); \ - E##si = XOR64(Bsi, ANDnu64(Bso, Bsu)); \ - E##so = XOR64(Bso, ANDnu64(Bsu, Bsa)); \ - E##su = XOR64(Bsu, ANDnu64(Bsa, Bse)); \ -\ - -static const UINT64 KeccakF1600RoundConstants[24] = { - 0x0000000000000001ULL, - 0x0000000000008082ULL, - 0x800000000000808aULL, - 0x8000000080008000ULL, - 0x000000000000808bULL, - 0x0000000080000001ULL, - 0x8000000080008081ULL, - 0x8000000000008009ULL, - 0x000000000000008aULL, - 0x0000000000000088ULL, - 0x0000000080008009ULL, - 0x000000008000000aULL, - 0x000000008000808bULL, - 0x800000000000008bULL, - 0x8000000000008089ULL, - 0x8000000000008003ULL, - 0x8000000000008002ULL, - 0x8000000000000080ULL, - 0x000000000000800aULL, - 0x800000008000000aULL, - 0x8000000080008081ULL, - 0x8000000000008080ULL, - 0x0000000080000001ULL, - 0x8000000080008008ULL }; - -#define copyFromStateAndXor576bits(X, state, input) \ - X##ba = XOR64(LOAD64(state[ 0]), LOAD64(input[ 0])); \ - X##be = XOR64(LOAD64(state[ 1]), LOAD64(input[ 1])); \ - X##bi = XOR64(LOAD64(state[ 2]), LOAD64(input[ 2])); \ - X##bo = XOR64(LOAD64(state[ 3]), LOAD64(input[ 3])); \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - X##ga = XOR64(LOAD64(state[ 5]), LOAD64(input[ 5])); \ - X##ge = XOR64(LOAD64(state[ 6]), LOAD64(input[ 6])); \ - X##gi = XOR64(LOAD64(state[ 7]), LOAD64(input[ 7])); \ - X##go = XOR64(LOAD64(state[ 8]), LOAD64(input[ 8])); \ - X##gu = LOAD64(state[ 9]); \ - X##ka = LOAD64(state[10]); \ - X##ke = LOAD64(state[11]); \ - X##ki = LOAD64(state[12]); \ - X##ko = LOAD64(state[13]); \ - X##ku = LOAD64(state[14]); \ - X##ma = LOAD64(state[15]); \ - X##me = LOAD64(state[16]); \ - X##mi = LOAD64(state[17]); \ - X##mo = LOAD64(state[18]); \ - X##mu = LOAD64(state[19]); \ - X##sa = LOAD64(state[20]); \ - X##se = LOAD64(state[21]); \ - X##si = LOAD64(state[22]); \ - X##so = LOAD64(state[23]); \ - X##su = LOAD64(state[24]); \ - -#define copyFromStateAndXor832bits(X, state, input) \ - X##ba = XOR64(LOAD64(state[ 0]), LOAD64(input[ 0])); \ - X##be = XOR64(LOAD64(state[ 1]), LOAD64(input[ 1])); \ - X##bi = XOR64(LOAD64(state[ 2]), LOAD64(input[ 2])); \ - X##bo = XOR64(LOAD64(state[ 3]), LOAD64(input[ 3])); \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - X##ga = XOR64(LOAD64(state[ 5]), LOAD64(input[ 5])); \ - X##ge = XOR64(LOAD64(state[ 6]), LOAD64(input[ 6])); \ - X##gi = XOR64(LOAD64(state[ 7]), LOAD64(input[ 7])); \ - X##go = XOR64(LOAD64(state[ 8]), LOAD64(input[ 8])); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##ka = XOR64(LOAD64(state[10]), LOAD64(input[10])); \ - X##ke = XOR64(LOAD64(state[11]), LOAD64(input[11])); \ - X##ki = XOR64(LOAD64(state[12]), LOAD64(input[12])); \ - X##ko = LOAD64(state[13]); \ - X##ku = LOAD64(state[14]); \ - X##ma = LOAD64(state[15]); \ - X##me = LOAD64(state[16]); \ - X##mi = LOAD64(state[17]); \ - X##mo = LOAD64(state[18]); \ - X##mu = LOAD64(state[19]); \ - X##sa = LOAD64(state[20]); \ - X##se = LOAD64(state[21]); \ - X##si = LOAD64(state[22]); \ - X##so = LOAD64(state[23]); \ - X##su = LOAD64(state[24]); \ - -#define copyFromStateAndXor1024bits(X, state, input) \ - X##ba = XOR64(LOAD64(state[ 0]), LOAD64(input[ 0])); \ - X##be = XOR64(LOAD64(state[ 1]), LOAD64(input[ 1])); \ - X##bi = XOR64(LOAD64(state[ 2]), LOAD64(input[ 2])); \ - X##bo = XOR64(LOAD64(state[ 3]), LOAD64(input[ 3])); \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - X##ga = XOR64(LOAD64(state[ 5]), LOAD64(input[ 5])); \ - X##ge = XOR64(LOAD64(state[ 6]), LOAD64(input[ 6])); \ - X##gi = XOR64(LOAD64(state[ 7]), LOAD64(input[ 7])); \ - X##go = XOR64(LOAD64(state[ 8]), LOAD64(input[ 8])); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##ka = XOR64(LOAD64(state[10]), LOAD64(input[10])); \ - X##ke = XOR64(LOAD64(state[11]), LOAD64(input[11])); \ - X##ki = XOR64(LOAD64(state[12]), LOAD64(input[12])); \ - X##ko = XOR64(LOAD64(state[13]), LOAD64(input[13])); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - X##ma = XOR64(LOAD64(state[15]), LOAD64(input[15])); \ - X##me = LOAD64(state[16]); \ - X##mi = LOAD64(state[17]); \ - X##mo = LOAD64(state[18]); \ - X##mu = LOAD64(state[19]); \ - X##sa = LOAD64(state[20]); \ - X##se = LOAD64(state[21]); \ - X##si = LOAD64(state[22]); \ - X##so = LOAD64(state[23]); \ - X##su = LOAD64(state[24]); \ - -#define copyFromStateAndXor1088bits(X, state, input) \ - X##ba = XOR64(LOAD64(state[ 0]), LOAD64(input[ 0])); \ - X##be = XOR64(LOAD64(state[ 1]), LOAD64(input[ 1])); \ - X##bi = XOR64(LOAD64(state[ 2]), LOAD64(input[ 2])); \ - X##bo = XOR64(LOAD64(state[ 3]), LOAD64(input[ 3])); \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - X##ga = XOR64(LOAD64(state[ 5]), LOAD64(input[ 5])); \ - X##ge = XOR64(LOAD64(state[ 6]), LOAD64(input[ 6])); \ - X##gi = XOR64(LOAD64(state[ 7]), LOAD64(input[ 7])); \ - X##go = XOR64(LOAD64(state[ 8]), LOAD64(input[ 8])); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##ka = XOR64(LOAD64(state[10]), LOAD64(input[10])); \ - X##ke = XOR64(LOAD64(state[11]), LOAD64(input[11])); \ - X##ki = XOR64(LOAD64(state[12]), LOAD64(input[12])); \ - X##ko = XOR64(LOAD64(state[13]), LOAD64(input[13])); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - X##ma = XOR64(LOAD64(state[15]), LOAD64(input[15])); \ - X##me = XOR64(LOAD64(state[16]), LOAD64(input[16])); \ - X##mi = LOAD64(state[17]); \ - X##mo = LOAD64(state[18]); \ - X##mu = LOAD64(state[19]); \ - X##sa = LOAD64(state[20]); \ - X##se = LOAD64(state[21]); \ - X##si = LOAD64(state[22]); \ - X##so = LOAD64(state[23]); \ - X##su = LOAD64(state[24]); \ - -#define copyFromStateAndXor1152bits(X, state, input) \ - X##ba = XOR64(LOAD64(state[ 0]), LOAD64(input[ 0])); \ - X##be = XOR64(LOAD64(state[ 1]), LOAD64(input[ 1])); \ - X##bi = XOR64(LOAD64(state[ 2]), LOAD64(input[ 2])); \ - X##bo = XOR64(LOAD64(state[ 3]), LOAD64(input[ 3])); \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - X##ga = XOR64(LOAD64(state[ 5]), LOAD64(input[ 5])); \ - X##ge = XOR64(LOAD64(state[ 6]), LOAD64(input[ 6])); \ - X##gi = XOR64(LOAD64(state[ 7]), LOAD64(input[ 7])); \ - X##go = XOR64(LOAD64(state[ 8]), LOAD64(input[ 8])); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##ka = XOR64(LOAD64(state[10]), LOAD64(input[10])); \ - X##ke = XOR64(LOAD64(state[11]), LOAD64(input[11])); \ - X##ki = XOR64(LOAD64(state[12]), LOAD64(input[12])); \ - X##ko = XOR64(LOAD64(state[13]), LOAD64(input[13])); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - X##ma = XOR64(LOAD64(state[15]), LOAD64(input[15])); \ - X##me = XOR64(LOAD64(state[16]), LOAD64(input[16])); \ - X##mi = XOR64(LOAD64(state[17]), LOAD64(input[17])); \ - X##mo = LOAD64(state[18]); \ - X##mu = LOAD64(state[19]); \ - X##sa = LOAD64(state[20]); \ - X##se = LOAD64(state[21]); \ - X##si = LOAD64(state[22]); \ - X##so = LOAD64(state[23]); \ - X##su = LOAD64(state[24]); \ - -#define copyFromStateAndXor1344bits(X, state, input) \ - X##ba = XOR64(LOAD64(state[ 0]), LOAD64(input[ 0])); \ - X##be = XOR64(LOAD64(state[ 1]), LOAD64(input[ 1])); \ - X##bi = XOR64(LOAD64(state[ 2]), LOAD64(input[ 2])); \ - X##bo = XOR64(LOAD64(state[ 3]), LOAD64(input[ 3])); \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - X##ga = XOR64(LOAD64(state[ 5]), LOAD64(input[ 5])); \ - X##ge = XOR64(LOAD64(state[ 6]), LOAD64(input[ 6])); \ - X##gi = XOR64(LOAD64(state[ 7]), LOAD64(input[ 7])); \ - X##go = XOR64(LOAD64(state[ 8]), LOAD64(input[ 8])); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##ka = XOR64(LOAD64(state[10]), LOAD64(input[10])); \ - X##ke = XOR64(LOAD64(state[11]), LOAD64(input[11])); \ - X##ki = XOR64(LOAD64(state[12]), LOAD64(input[12])); \ - X##ko = XOR64(LOAD64(state[13]), LOAD64(input[13])); \ - X##ku = XOR64(LOAD64(state[14]), LOAD64(input[14])); \ - X##ma = XOR64(LOAD64(state[15]), LOAD64(input[15])); \ - X##me = XOR64(LOAD64(state[16]), LOAD64(input[16])); \ - X##mi = XOR64(LOAD64(state[17]), LOAD64(input[17])); \ - X##mo = XOR64(LOAD64(state[18]), LOAD64(input[18])); \ - X##mu = XOR64(LOAD64(state[19]), LOAD64(input[19])); \ - X##sa = XOR64(LOAD64(state[20]), LOAD64(input[20])); \ - X##se = LOAD64(state[21]); \ - X##si = LOAD64(state[22]); \ - X##so = LOAD64(state[23]); \ - X##su = LOAD64(state[24]); \ - -#define copyFromState(X, state) \ - X##ba = LOAD64(state[ 0]); \ - X##be = LOAD64(state[ 1]); \ - X##bi = LOAD64(state[ 2]); \ - X##bo = LOAD64(state[ 3]); \ - X##bu = LOAD64(state[ 4]); \ - X##ga = LOAD64(state[ 5]); \ - X##ge = LOAD64(state[ 6]); \ - X##gi = LOAD64(state[ 7]); \ - X##go = LOAD64(state[ 8]); \ - X##gu = LOAD64(state[ 9]); \ - X##ka = LOAD64(state[10]); \ - X##ke = LOAD64(state[11]); \ - X##ki = LOAD64(state[12]); \ - X##ko = LOAD64(state[13]); \ - X##ku = LOAD64(state[14]); \ - X##ma = LOAD64(state[15]); \ - X##me = LOAD64(state[16]); \ - X##mi = LOAD64(state[17]); \ - X##mo = LOAD64(state[18]); \ - X##mu = LOAD64(state[19]); \ - X##sa = LOAD64(state[20]); \ - X##se = LOAD64(state[21]); \ - X##si = LOAD64(state[22]); \ - X##so = LOAD64(state[23]); \ - X##su = LOAD64(state[24]); \ - -#define copyToState(state, X) \ - STORE64(state[ 0], X##ba); \ - STORE64(state[ 1], X##be); \ - STORE64(state[ 2], X##bi); \ - STORE64(state[ 3], X##bo); \ - STORE64(state[ 4], X##bu); \ - STORE64(state[ 5], X##ga); \ - STORE64(state[ 6], X##ge); \ - STORE64(state[ 7], X##gi); \ - STORE64(state[ 8], X##go); \ - STORE64(state[ 9], X##gu); \ - STORE64(state[10], X##ka); \ - STORE64(state[11], X##ke); \ - STORE64(state[12], X##ki); \ - STORE64(state[13], X##ko); \ - STORE64(state[14], X##ku); \ - STORE64(state[15], X##ma); \ - STORE64(state[16], X##me); \ - STORE64(state[17], X##mi); \ - STORE64(state[18], X##mo); \ - STORE64(state[19], X##mu); \ - STORE64(state[20], X##sa); \ - STORE64(state[21], X##se); \ - STORE64(state[22], X##si); \ - STORE64(state[23], X##so); \ - STORE64(state[24], X##su); \ - -#define copyStateVariables(X, Y) \ - X##ba = Y##ba; \ - X##be = Y##be; \ - X##bi = Y##bi; \ - X##bo = Y##bo; \ - X##bu = Y##bu; \ - X##ga = Y##ga; \ - X##ge = Y##ge; \ - X##gi = Y##gi; \ - X##go = Y##go; \ - X##gu = Y##gu; \ - X##ka = Y##ka; \ - X##ke = Y##ke; \ - X##ki = Y##ki; \ - X##ko = Y##ko; \ - X##ku = Y##ku; \ - X##ma = Y##ma; \ - X##me = Y##me; \ - X##mi = Y##mi; \ - X##mo = Y##mo; \ - X##mu = Y##mu; \ - X##sa = Y##sa; \ - X##se = Y##se; \ - X##si = Y##si; \ - X##so = Y##so; \ - X##su = Y##su; \ - diff --git a/Modules/_sha3/keccak/KeccakF-1600-unrolling.macros b/Modules/_sha3/keccak/KeccakF-1600-unrolling.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-unrolling.macros +++ /dev/null @@ -1,124 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#if (Unrolling == 24) -#define rounds \ - prepareTheta \ - thetaRhoPiChiIotaPrepareTheta( 0, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 1, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 2, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 3, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 4, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 5, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 6, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 7, E, A) \ - thetaRhoPiChiIotaPrepareTheta( 8, A, E) \ - thetaRhoPiChiIotaPrepareTheta( 9, E, A) \ - thetaRhoPiChiIotaPrepareTheta(10, A, E) \ - thetaRhoPiChiIotaPrepareTheta(11, E, A) \ - thetaRhoPiChiIotaPrepareTheta(12, A, E) \ - thetaRhoPiChiIotaPrepareTheta(13, E, A) \ - thetaRhoPiChiIotaPrepareTheta(14, A, E) \ - thetaRhoPiChiIotaPrepareTheta(15, E, A) \ - thetaRhoPiChiIotaPrepareTheta(16, A, E) \ - thetaRhoPiChiIotaPrepareTheta(17, E, A) \ - thetaRhoPiChiIotaPrepareTheta(18, A, E) \ - thetaRhoPiChiIotaPrepareTheta(19, E, A) \ - thetaRhoPiChiIotaPrepareTheta(20, A, E) \ - thetaRhoPiChiIotaPrepareTheta(21, E, A) \ - thetaRhoPiChiIotaPrepareTheta(22, A, E) \ - thetaRhoPiChiIota(23, E, A) \ - copyToState(state, A) -#elif (Unrolling == 12) -#define rounds \ - prepareTheta \ - for(i=0; i<24; i+=12) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 3, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 4, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 5, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 6, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 7, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+ 8, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+ 9, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+10, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+11, E, A) \ - } \ - copyToState(state, A) -#elif (Unrolling == 8) -#define rounds \ - prepareTheta \ - for(i=0; i<24; i+=8) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+6, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+7, E, A) \ - } \ - copyToState(state, A) -#elif (Unrolling == 6) -#define rounds \ - prepareTheta \ - for(i=0; i<24; i+=6) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \ - } \ - copyToState(state, A) -#elif (Unrolling == 4) -#define rounds \ - prepareTheta \ - for(i=0; i<24; i+=4) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ - } \ - copyToState(state, A) -#elif (Unrolling == 3) -#define rounds \ - prepareTheta \ - for(i=0; i<24; i+=3) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ - copyStateVariables(A, E) \ - } \ - copyToState(state, A) -#elif (Unrolling == 2) -#define rounds \ - prepareTheta \ - for(i=0; i<24; i+=2) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ - } \ - copyToState(state, A) -#elif (Unrolling == 1) -#define rounds \ - prepareTheta \ - for(i=0; i<24; i++) { \ - thetaRhoPiChiIotaPrepareTheta(i , A, E) \ - copyStateVariables(A, E) \ - } \ - copyToState(state, A) -#else -#error "Unrolling is not correctly specified!" -#endif diff --git a/Modules/_sha3/keccak/KeccakF-1600-xop.macros b/Modules/_sha3/keccak/KeccakF-1600-xop.macros deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakF-1600-xop.macros +++ /dev/null @@ -1,573 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#define declareABCDE \ - V128 Abage, Abegi, Abigo, Abogu, Abuga; \ - V128 Akame, Akemi, Akimo, Akomu, Akuma; \ - V128 Abae, Abio, Agae, Agio, Akae, Akio, Amae, Amio; \ - V64 Aba, Abe, Abi, Abo, Abu; \ - V64 Aga, Age, Agi, Ago, Agu; \ - V64 Aka, Ake, Aki, Ako, Aku; \ - V64 Ama, Ame, Ami, Amo, Amu; \ - V128 Asase, Asiso; \ - V64 Asu; \ - V128 Bbage, Bbegi, Bbigo, Bbogu, Bbuga; \ - V128 Bkame, Bkemi, Bkimo, Bkomu, Bkuma; \ - V128 Bsase, Bsesi, Bsiso, Bsosu, Bsusa; \ - V128 Cae, Cei, Cio, Cou, Cua; \ - V128 Dau, Dea, Die, Doi, Duo; \ - V128 Dua, Dae, Dei, Dio, Dou; \ - V128 Ebage, Ebegi, Ebigo, Ebogu, Ebuga; \ - V128 Ekame, Ekemi, Ekimo, Ekomu, Ekuma; \ - V128 Esase, Esiso; \ - V64 Esu; \ - V128 Zero; - -#define prepareTheta - -#define computeD \ - Cua = GET64LOLO(Cua, Cae); \ - Dei = XOR128(Cae, ROL6464same(Cio, 1)); \ - Dou = XOR128(Cio, ROL6464same(Cua, 1)); \ - Cei = GET64HILO(Cae, Cio); \ - Dae = XOR128(Cua, ROL6464same(Cei, 1)); \ - Dau = GET64LOHI(Dae, Dou); \ - Dea = SWAP64(Dae); \ - Die = SWAP64(Dei); \ - Doi = GET64LOLO(Dou, Die); \ - Duo = SWAP64(Dou); - -/* --- Theta Rho Pi Chi Iota Prepare-theta */ -/* --- 64-bit lanes mapped to 64-bit and 128-bit words */ -#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \ - computeD \ - \ - Bbage = XOR128(GET64LOHI(A##bage, A##bogu), Dau); \ - Bbage = ROL6464(Bbage, 0, 20); \ - Bbegi = XOR128(GET64HILO(A##bage, A##kame), Dea); \ - Bbegi = ROL6464(Bbegi, 44, 3); \ - Bbigo = XOR128(GET64LOHI(A##kimo, A##kame), Die); \ - Bbigo = ROL6464(Bbigo, 43, 45); \ - E##bage = XOR128(Bbage, ANDnu128(Bbegi, Bbigo)); \ - XOReq128(E##bage, CONST64(KeccakF1600RoundConstants[i])); \ - Cae = E##bage; \ - Bbogu = XOR128(GET64HILO(A##kimo, A##siso), Doi); \ - Bbogu = ROL6464(Bbogu, 21, 61); \ - E##begi = XOR128(Bbegi, ANDnu128(Bbigo, Bbogu)); \ - Cei = E##begi; \ - Bbuga = XOR128(GET64LOLO(A##su, A##bogu), Duo); \ - Bbuga = ROL6464(Bbuga, 14, 28); \ - E##bigo = XOR128(Bbigo, ANDnu128(Bbogu, Bbuga)); \ - Cio = E##bigo; \ - E##bogu = XOR128(Bbogu, ANDnu128(Bbuga, Bbage)); \ - Cou = E##bogu; \ - E##buga = XOR128(Bbuga, ANDnu128(Bbage, Bbegi)); \ - Cua = E##buga; \ -\ - Bkame = XOR128(GET64LOHI(A##begi, A##buga), Dea); \ - Bkame = ROL6464(Bkame, 1, 36); \ - Bkemi = XOR128(GET64HILO(A##begi, A##kemi), Die); \ - Bkemi = ROL6464(Bkemi, 6, 10); \ - Bkimo = XOR128(GET64LOHI(A##komu, A##kemi), Doi); \ - Bkimo = ROL6464(Bkimo, 25, 15); \ - E##kame = XOR128(Bkame, ANDnu128(Bkemi, Bkimo)); \ - XOReq128(Cae, E##kame); \ - Bkomu = XOR128(GET64HIHI(A##komu, A##siso), Duo); \ - Bkomu = ROL6464(Bkomu, 8, 56); \ - E##kemi = XOR128(Bkemi, ANDnu128(Bkimo, Bkomu)); \ - XOReq128(Cei, E##kemi); \ - Bkuma = XOR128(GET64LOLO(A##sase, A##buga), Dau); \ - Bkuma = ROL6464(Bkuma, 18, 27); \ - E##kimo = XOR128(Bkimo, ANDnu128(Bkomu, Bkuma)); \ - XOReq128(Cio, E##kimo); \ - E##komu = XOR128(Bkomu, ANDnu128(Bkuma, Bkame)); \ - XOReq128(Cou, E##komu); \ - E##kuma = XOR128(Bkuma, ANDnu128(Bkame, Bkemi)); \ - XOReq128(Cua, E##kuma); \ -\ - Bsase = XOR128(A##bigo, SWAP64(Doi)); \ - Bsase = ROL6464(Bsase, 62, 55); \ - Bsiso = XOR128(A##kuma, SWAP64(Dau)); \ - Bsiso = ROL6464(Bsiso, 39, 41); \ - Bsusa = XOR64(COPY64HI2LO(A##sase), Dei); \ - Bsusa = ROL6464same(Bsusa, 2); \ - Bsusa = GET64LOLO(Bsusa, Bsase); \ - Bsesi = GET64HILO(Bsase, Bsiso); \ - Bsosu = GET64HILO(Bsiso, Bsusa); \ - E##sase = XOR128(Bsase, ANDnu128(Bsesi, Bsiso)); \ - XOReq128(Cae, E##sase); \ - E##siso = XOR128(Bsiso, ANDnu128(Bsosu, Bsusa)); \ - XOReq128(Cio, E##siso); \ - E##su = GET64LOLO(XOR128(Bsusa, ANDnu128(Bsase, Bsesi)), Zero); \ - XOReq128(Cua, E##su); \ -\ - Zero = ZERO128(); \ - XOReq128(Cae, GET64HIHI(Cua, Zero)); \ - XOReq128(Cae, GET64LOLO(Zero, Cei)); \ - XOReq128(Cio, GET64HIHI(Cei, Zero)); \ - XOReq128(Cio, GET64LOLO(Zero, Cou)); \ - XOReq128(Cua, GET64HIHI(Cou, Zero)); \ - -/* --- Theta Rho Pi Chi Iota */ -/* --- 64-bit lanes mapped to 64-bit and 128-bit words */ -#define thetaRhoPiChiIota(i, A, E) thetaRhoPiChiIotaPrepareTheta(i, A, E) - -static const UINT64 KeccakF1600RoundConstants[24] = { - 0x0000000000000001ULL, - 0x0000000000008082ULL, - 0x800000000000808aULL, - 0x8000000080008000ULL, - 0x000000000000808bULL, - 0x0000000080000001ULL, - 0x8000000080008081ULL, - 0x8000000000008009ULL, - 0x000000000000008aULL, - 0x0000000000000088ULL, - 0x0000000080008009ULL, - 0x000000008000000aULL, - 0x000000008000808bULL, - 0x800000000000008bULL, - 0x8000000000008089ULL, - 0x8000000000008003ULL, - 0x8000000000008002ULL, - 0x8000000000000080ULL, - 0x000000000000800aULL, - 0x800000008000000aULL, - 0x8000000080008081ULL, - 0x8000000000008080ULL, - 0x0000000080000001ULL, - 0x8000000080008008ULL }; - -#define copyFromStateAndXor576bits(X, state, input) \ - X##bae = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae; \ - X##be = GET64HIHI(X##bae, X##bae); \ - Cae = X##bae; \ - X##bio = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio; \ - X##bo = GET64HIHI(X##bio, X##bio); \ - Cio = X##bio; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cua = X##bu; \ - X##gae = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae; \ - X##buga = GET64LOLO(X##bu, X##ga); \ - X##ge = GET64HIHI(X##gae, X##gae); \ - X##bage = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae); \ - X##gio = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio; \ - X##begi = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio, X##gio); \ - X##bigo = GET64LOLO(X##bi, X##go); \ - XOReq128(Cio, X##gio); \ - X##gu = LOAD64(state[ 9]); \ - X##bogu = GET64LOLO(X##bo, X##gu); \ - XOReq64(Cua, X##gu); \ - X##kae = LOAD128(state[10]); \ - X##ka = X##kae; \ - X##ke = GET64HIHI(X##kae, X##kae); \ - XOReq128(Cae, X##kae); \ - X##kio = LOAD128(state[12]); \ - X##ki = X##kio; \ - X##ko = GET64HIHI(X##kio, X##kio); \ - XOReq128(Cio, X##kio); \ - X##kuma = LOAD128(state[14]); \ - XOReq64(Cua, X##kuma); \ - X##me = LOAD64(state[16]); \ - X##kame = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, GET64HIHI(X##kuma, X##kame)); \ - X##mio = LOAD128u(state[17]); \ - X##mi = X##mio; \ - X##kemi = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio, X##mio); \ - X##kimo = GET64LOLO(X##ki, X##mo); \ - XOReq128(Cio, X##mio); \ - X##mu = LOAD64(state[19]); \ - X##komu = GET64LOLO(X##ko, X##mu); \ - XOReq64(Cua, X##mu); \ - X##sase = LOAD128(state[20]); \ - XOReq128(Cae, X##sase); \ - X##siso = LOAD128(state[22]); \ - XOReq128(Cio, X##siso); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cua, X##su); \ - -#define copyFromStateAndXor832bits(X, state, input) \ - X##bae = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae; \ - X##be = GET64HIHI(X##bae, X##bae); \ - Cae = X##bae; \ - X##bio = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio; \ - X##bo = GET64HIHI(X##bio, X##bio); \ - Cio = X##bio; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cua = X##bu; \ - X##gae = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae; \ - X##buga = GET64LOLO(X##bu, X##ga); \ - X##ge = GET64HIHI(X##gae, X##gae); \ - X##bage = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae); \ - X##gio = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio; \ - X##begi = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio, X##gio); \ - X##bigo = GET64LOLO(X##bi, X##go); \ - XOReq128(Cio, X##gio); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##bogu = GET64LOLO(X##bo, X##gu); \ - XOReq64(Cua, X##gu); \ - X##kae = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae; \ - X##ke = GET64HIHI(X##kae, X##kae); \ - XOReq128(Cae, X##kae); \ - X##kio = XOR128(LOAD128(state[12]), LOAD64(input[12])); \ - X##ki = X##kio; \ - X##ko = GET64HIHI(X##kio, X##kio); \ - XOReq128(Cio, X##kio); \ - X##kuma = LOAD128(state[14]); \ - XOReq64(Cua, X##kuma); \ - X##me = LOAD64(state[16]); \ - X##kame = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, GET64HIHI(X##kuma, X##kame)); \ - X##mio = LOAD128u(state[17]); \ - X##mi = X##mio; \ - X##kemi = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio, X##mio); \ - X##kimo = GET64LOLO(X##ki, X##mo); \ - XOReq128(Cio, X##mio); \ - X##mu = LOAD64(state[19]); \ - X##komu = GET64LOLO(X##ko, X##mu); \ - XOReq64(Cua, X##mu); \ - X##sase = LOAD128(state[20]); \ - XOReq128(Cae, X##sase); \ - X##siso = LOAD128(state[22]); \ - XOReq128(Cio, X##siso); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cua, X##su); \ - -#define copyFromStateAndXor1024bits(X, state, input) \ - X##bae = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae; \ - X##be = GET64HIHI(X##bae, X##bae); \ - Cae = X##bae; \ - X##bio = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio; \ - X##bo = GET64HIHI(X##bio, X##bio); \ - Cio = X##bio; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cua = X##bu; \ - X##gae = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae; \ - X##buga = GET64LOLO(X##bu, X##ga); \ - X##ge = GET64HIHI(X##gae, X##gae); \ - X##bage = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae); \ - X##gio = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio; \ - X##begi = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio, X##gio); \ - X##bigo = GET64LOLO(X##bi, X##go); \ - XOReq128(Cio, X##gio); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##bogu = GET64LOLO(X##bo, X##gu); \ - XOReq64(Cua, X##gu); \ - X##kae = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae; \ - X##ke = GET64HIHI(X##kae, X##kae); \ - XOReq128(Cae, X##kae); \ - X##kio = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio; \ - X##ko = GET64HIHI(X##kio, X##kio); \ - XOReq128(Cio, X##kio); \ - X##kuma = XOR128(LOAD128(state[14]), LOAD128(input[14])); \ - XOReq64(Cua, X##kuma); \ - X##me = LOAD64(state[16]); \ - X##kame = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, GET64HIHI(X##kuma, X##kame)); \ - X##mio = LOAD128u(state[17]); \ - X##mi = X##mio; \ - X##kemi = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio, X##mio); \ - X##kimo = GET64LOLO(X##ki, X##mo); \ - XOReq128(Cio, X##mio); \ - X##mu = LOAD64(state[19]); \ - X##komu = GET64LOLO(X##ko, X##mu); \ - XOReq64(Cua, X##mu); \ - X##sase = LOAD128(state[20]); \ - XOReq128(Cae, X##sase); \ - X##siso = LOAD128(state[22]); \ - XOReq128(Cio, X##siso); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cua, X##su); \ - -#define copyFromStateAndXor1088bits(X, state, input) \ - X##bae = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae; \ - X##be = GET64HIHI(X##bae, X##bae); \ - Cae = X##bae; \ - X##bio = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio; \ - X##bo = GET64HIHI(X##bio, X##bio); \ - Cio = X##bio; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cua = X##bu; \ - X##gae = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae; \ - X##buga = GET64LOLO(X##bu, X##ga); \ - X##ge = GET64HIHI(X##gae, X##gae); \ - X##bage = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae); \ - X##gio = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio; \ - X##begi = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio, X##gio); \ - X##bigo = GET64LOLO(X##bi, X##go); \ - XOReq128(Cio, X##gio); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##bogu = GET64LOLO(X##bo, X##gu); \ - XOReq64(Cua, X##gu); \ - X##kae = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae; \ - X##ke = GET64HIHI(X##kae, X##kae); \ - XOReq128(Cae, X##kae); \ - X##kio = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio; \ - X##ko = GET64HIHI(X##kio, X##kio); \ - XOReq128(Cio, X##kio); \ - X##kuma = XOR128(LOAD128(state[14]), LOAD128(input[14])); \ - XOReq64(Cua, X##kuma); \ - X##me = XOR64(LOAD64(state[16]), LOAD64(input[16])); \ - X##kame = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, GET64HIHI(X##kuma, X##kame)); \ - X##mio = LOAD128u(state[17]); \ - X##mi = X##mio; \ - X##kemi = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio, X##mio); \ - X##kimo = GET64LOLO(X##ki, X##mo); \ - XOReq128(Cio, X##mio); \ - X##mu = LOAD64(state[19]); \ - X##komu = GET64LOLO(X##ko, X##mu); \ - XOReq64(Cua, X##mu); \ - X##sase = LOAD128(state[20]); \ - XOReq128(Cae, X##sase); \ - X##siso = LOAD128(state[22]); \ - XOReq128(Cio, X##siso); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cua, X##su); \ - -#define copyFromStateAndXor1152bits(X, state, input) \ - X##bae = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae; \ - X##be = GET64HIHI(X##bae, X##bae); \ - Cae = X##bae; \ - X##bio = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio; \ - X##bo = GET64HIHI(X##bio, X##bio); \ - Cio = X##bio; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cua = X##bu; \ - X##gae = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae; \ - X##buga = GET64LOLO(X##bu, X##ga); \ - X##ge = GET64HIHI(X##gae, X##gae); \ - X##bage = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae); \ - X##gio = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio; \ - X##begi = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio, X##gio); \ - X##bigo = GET64LOLO(X##bi, X##go); \ - XOReq128(Cio, X##gio); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##bogu = GET64LOLO(X##bo, X##gu); \ - XOReq64(Cua, X##gu); \ - X##kae = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae; \ - X##ke = GET64HIHI(X##kae, X##kae); \ - XOReq128(Cae, X##kae); \ - X##kio = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio; \ - X##ko = GET64HIHI(X##kio, X##kio); \ - XOReq128(Cio, X##kio); \ - X##kuma = XOR128(LOAD128(state[14]), LOAD128(input[14])); \ - XOReq64(Cua, X##kuma); \ - X##me = XOR64(LOAD64(state[16]), LOAD64(input[16])); \ - X##kame = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, GET64HIHI(X##kuma, X##kame)); \ - X##mio = XOR128(LOAD128u(state[17]), LOAD64(input[17])); \ - X##mi = X##mio; \ - X##kemi = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio, X##mio); \ - X##kimo = GET64LOLO(X##ki, X##mo); \ - XOReq128(Cio, X##mio); \ - X##mu = LOAD64(state[19]); \ - X##komu = GET64LOLO(X##ko, X##mu); \ - XOReq64(Cua, X##mu); \ - X##sase = LOAD128(state[20]); \ - XOReq128(Cae, X##sase); \ - X##siso = LOAD128(state[22]); \ - XOReq128(Cio, X##siso); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cua, X##su); \ - -#define copyFromStateAndXor1344bits(X, state, input) \ - X##bae = XOR128(LOAD128(state[ 0]), LOAD128u(input[ 0])); \ - X##ba = X##bae; \ - X##be = GET64HIHI(X##bae, X##bae); \ - Cae = X##bae; \ - X##bio = XOR128(LOAD128(state[ 2]), LOAD128u(input[ 2])); \ - X##bi = X##bio; \ - X##bo = GET64HIHI(X##bio, X##bio); \ - Cio = X##bio; \ - X##bu = XOR64(LOAD64(state[ 4]), LOAD64(input[ 4])); \ - Cua = X##bu; \ - X##gae = XOR128(LOAD128u(state[ 5]), LOAD128u(input[ 5])); \ - X##ga = X##gae; \ - X##buga = GET64LOLO(X##bu, X##ga); \ - X##ge = GET64HIHI(X##gae, X##gae); \ - X##bage = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae); \ - X##gio = XOR128(LOAD128u(state[ 7]), LOAD128u(input[ 7])); \ - X##gi = X##gio; \ - X##begi = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio, X##gio); \ - X##bigo = GET64LOLO(X##bi, X##go); \ - XOReq128(Cio, X##gio); \ - X##gu = XOR64(LOAD64(state[ 9]), LOAD64(input[ 9])); \ - X##bogu = GET64LOLO(X##bo, X##gu); \ - XOReq64(Cua, X##gu); \ - X##kae = XOR128(LOAD128(state[10]), LOAD128u(input[10])); \ - X##ka = X##kae; \ - X##ke = GET64HIHI(X##kae, X##kae); \ - XOReq128(Cae, X##kae); \ - X##kio = XOR128(LOAD128(state[12]), LOAD128u(input[12])); \ - X##ki = X##kio; \ - X##ko = GET64HIHI(X##kio, X##kio); \ - XOReq128(Cio, X##kio); \ - X##kuma = XOR128(LOAD128(state[14]), LOAD128(input[14])); \ - XOReq64(Cua, X##kuma); \ - X##me = XOR64(LOAD64(state[16]), LOAD64(input[16])); \ - X##kame = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, GET64HIHI(X##kuma, X##kame)); \ - X##mio = XOR128(LOAD128u(state[17]), LOAD128u(input[17])); \ - X##mi = X##mio; \ - X##kemi = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio, X##mio); \ - X##kimo = GET64LOLO(X##ki, X##mo); \ - XOReq128(Cio, X##mio); \ - X##mu = XOR64(LOAD64(state[19]), LOAD64(input[19])); \ - X##komu = GET64LOLO(X##ko, X##mu); \ - XOReq64(Cua, X##mu); \ - X##sase = XOR128(LOAD128(state[20]), LOAD64(input[20])); \ - XOReq128(Cae, X##sase); \ - X##siso = LOAD128(state[22]); \ - XOReq128(Cio, X##siso); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cua, X##su); \ - -#define copyFromState(X, state) \ - X##bae = LOAD128(state[ 0]); \ - X##ba = X##bae; \ - X##be = GET64HIHI(X##bae, X##bae); \ - Cae = X##bae; \ - X##bio = LOAD128(state[ 2]); \ - X##bi = X##bio; \ - X##bo = GET64HIHI(X##bio, X##bio); \ - Cio = X##bio; \ - X##bu = LOAD64(state[ 4]); \ - Cua = X##bu; \ - X##gae = LOAD128u(state[ 5]); \ - X##ga = X##gae; \ - X##buga = GET64LOLO(X##bu, X##ga); \ - X##ge = GET64HIHI(X##gae, X##gae); \ - X##bage = GET64LOLO(X##ba, X##ge); \ - XOReq128(Cae, X##gae); \ - X##gio = LOAD128u(state[ 7]); \ - X##gi = X##gio; \ - X##begi = GET64LOLO(X##be, X##gi); \ - X##go = GET64HIHI(X##gio, X##gio); \ - X##bigo = GET64LOLO(X##bi, X##go); \ - XOReq128(Cio, X##gio); \ - X##gu = LOAD64(state[ 9]); \ - X##bogu = GET64LOLO(X##bo, X##gu); \ - XOReq64(Cua, X##gu); \ - X##kae = LOAD128(state[10]); \ - X##ka = X##kae; \ - X##ke = GET64HIHI(X##kae, X##kae); \ - XOReq128(Cae, X##kae); \ - X##kio = LOAD128(state[12]); \ - X##ki = X##kio; \ - X##ko = GET64HIHI(X##kio, X##kio); \ - XOReq128(Cio, X##kio); \ - X##kuma = LOAD128(state[14]); \ - XOReq64(Cua, X##kuma); \ - X##me = LOAD64(state[16]); \ - X##kame = GET64LOLO(X##ka, X##me); \ - XOReq128(Cae, GET64HIHI(X##kuma, X##kame)); \ - X##mio = LOAD128u(state[17]); \ - X##mi = X##mio; \ - X##kemi = GET64LOLO(X##ke, X##mi); \ - X##mo = GET64HIHI(X##mio, X##mio); \ - X##kimo = GET64LOLO(X##ki, X##mo); \ - XOReq128(Cio, X##mio); \ - X##mu = LOAD64(state[19]); \ - X##komu = GET64LOLO(X##ko, X##mu); \ - XOReq64(Cua, X##mu); \ - X##sase = LOAD128(state[20]); \ - XOReq128(Cae, X##sase); \ - X##siso = LOAD128(state[22]); \ - XOReq128(Cio, X##siso); \ - X##su = LOAD64(state[24]); \ - XOReq64(Cua, X##su); \ - -#define copyToState(state, X) \ - STORE64(state[ 0], X##bage); \ - STORE64(state[ 1], X##begi); \ - STORE64(state[ 2], X##bigo); \ - STORE64(state[ 3], X##bogu); \ - STORE128(state[ 4], X##buga); \ - STORE64(state[ 6], COPY64HI2LO(X##bage)); \ - STORE64(state[ 7], COPY64HI2LO(X##begi)); \ - STORE64(state[ 8], COPY64HI2LO(X##bigo)); \ - STORE64(state[ 9], COPY64HI2LO(X##bogu)); \ - STORE64(state[10], X##kame); \ - STORE64(state[11], X##kemi); \ - STORE64(state[12], X##kimo); \ - STORE64(state[13], X##komu); \ - STORE128(state[14], X##kuma); \ - STORE64(state[16], COPY64HI2LO(X##kame)); \ - STORE64(state[17], COPY64HI2LO(X##kemi)); \ - STORE64(state[18], COPY64HI2LO(X##kimo)); \ - STORE64(state[19], COPY64HI2LO(X##komu)); \ - STORE128(state[20], X##sase); \ - STORE128(state[22], X##siso); \ - STORE64(state[24], X##su); \ - -#define copyStateVariables(X, Y) \ - X##bage = Y##bage; \ - X##begi = Y##begi; \ - X##bigo = Y##bigo; \ - X##bogu = Y##bogu; \ - X##buga = Y##buga; \ - X##kame = Y##kame; \ - X##kemi = Y##kemi; \ - X##kimo = Y##kimo; \ - X##komu = Y##komu; \ - X##kuma = Y##kuma; \ - X##sase = Y##sase; \ - X##siso = Y##siso; \ - X##su = Y##su; \ - diff --git a/Modules/_sha3/keccak/KeccakNISTInterface.c b/Modules/_sha3/keccak/KeccakNISTInterface.c deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakNISTInterface.c +++ /dev/null @@ -1,83 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include -#include "KeccakNISTInterface.h" -#include "KeccakF-1600-interface.h" - -static HashReturn Init(hashState *state, int hashbitlen) -{ - switch(hashbitlen) { - case 0: /* Default parameters, arbitrary length output */ - InitSponge((spongeState*)state, 1024, 576); - break; - case 224: - InitSponge((spongeState*)state, 1152, 448); - break; - case 256: - InitSponge((spongeState*)state, 1088, 512); - break; - case 384: - InitSponge((spongeState*)state, 832, 768); - break; - case 512: - InitSponge((spongeState*)state, 576, 1024); - break; - default: - return BAD_HASHLEN; - } - state->fixedOutputLength = hashbitlen; - return SUCCESS; -} - -static HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen) -{ - if ((databitlen % 8) == 0) - return Absorb((spongeState*)state, data, databitlen); - else { - HashReturn ret = Absorb((spongeState*)state, data, databitlen - (databitlen % 8)); - if (ret == SUCCESS) { - unsigned char lastByte; - /* Align the last partial byte to the least significant bits */ - lastByte = data[databitlen/8] >> (8 - (databitlen % 8)); - return Absorb((spongeState*)state, &lastByte, databitlen % 8); - } - else - return ret; - } -} - -static HashReturn Final(hashState *state, BitSequence *hashval) -{ - return Squeeze(state, hashval, state->fixedOutputLength); -} - -/* -static HashReturn Hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval) -{ - hashState state; - HashReturn result; - - if ((hashbitlen != 224) && (hashbitlen != 256) && (hashbitlen != 384) && (hashbitlen != 512)) - return BAD_HASHLEN; * Only the four fixed output lengths available through this API * - result = Init(&state, hashbitlen); - if (result != SUCCESS) - return result; - result = Update(&state, data, databitlen); - if (result != SUCCESS) - return result; - result = Final(&state, hashval); - return result; -} -*/ - diff --git a/Modules/_sha3/keccak/KeccakNISTInterface.h b/Modules/_sha3/keccak/KeccakNISTInterface.h deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakNISTInterface.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _KeccakNISTInterface_h_ -#define _KeccakNISTInterface_h_ - -#include "KeccakSponge.h" - -typedef unsigned char BitSequence; -typedef unsigned long long DataLength; -typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn; - -typedef spongeState hashState; - -/** - * Function to initialize the state of the Keccak[r, c] sponge function. - * The rate r and capacity c values are determined from @a hashbitlen. - * @param state Pointer to the state of the sponge function to be initialized. - * @param hashbitlen The desired number of output bits, - * or 0 for Keccak[] with default parameters - * and arbitrarily-long output. - * @pre The value of hashbitlen must be one of 0, 224, 256, 384 and 512. - * @return SUCCESS if successful, BAD_HASHLEN if the value of hashbitlen is incorrect. - */ -static HashReturn Init(hashState *state, int hashbitlen); -/** - * Function to give input data for the sponge function to absorb. - * @param state Pointer to the state of the sponge function initialized by Init(). - * @param data Pointer to the input data. - * When @a databitLen is not a multiple of 8, the last bits of data must be - * in the most significant bits of the last byte. - * @param databitLen The number of input bits provided in the input data. - * @pre In the previous call to Absorb(), databitLen was a multiple of 8. - * @return SUCCESS if successful, FAIL otherwise. - */ -static HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen); -/** - * Function to squeeze output data from the sponge function. - * If @a hashbitlen was not 0 in the call to Init(), the number of output bits is equal to @a hashbitlen. - * If @a hashbitlen was 0 in the call to Init(), the output bits must be extracted using the Squeeze() function. - * @param state Pointer to the state of the sponge function initialized by Init(). - * @param hashval Pointer to the buffer where to store the output data. - * @return SUCCESS if successful, FAIL otherwise. - */ -static HashReturn Final(hashState *state, BitSequence *hashval); -/** - * Function to compute a hash using the Keccak[r, c] sponge function. - * The rate r and capacity c values are determined from @a hashbitlen. - * @param hashbitlen The desired number of output bits. - * @param data Pointer to the input data. - * When @a databitLen is not a multiple of 8, the last bits of data must be - * in the most significant bits of the last byte. - * @param databitLen The number of input bits provided in the input data. - * @param hashval Pointer to the buffer where to store the output data. - * @pre The value of hashbitlen must be one of 224, 256, 384 and 512. - * @return SUCCESS if successful, BAD_HASHLEN if the value of hashbitlen is incorrect. - */ -/* -static HashReturn Hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval); -*/ - -#endif diff --git a/Modules/_sha3/keccak/KeccakSponge.c b/Modules/_sha3/keccak/KeccakSponge.c deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakSponge.c +++ /dev/null @@ -1,266 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include -#include "KeccakSponge.h" -#include "KeccakF-1600-interface.h" -#ifdef KeccakReference -#include "displayIntermediateValues.h" -#endif - -static int InitSponge(spongeState *state, unsigned int rate, unsigned int capacity) -{ - if (rate+capacity != 1600) - return 1; - if ((rate <= 0) || (rate >= 1600) || ((rate % 64) != 0)) - return 1; - KeccakInitialize(); - state->rate = rate; - state->capacity = capacity; - state->fixedOutputLength = 0; - KeccakInitializeState(state->state); - memset(state->dataQueue, 0, KeccakMaximumRateInBytes); - state->bitsInQueue = 0; - state->squeezing = 0; - state->bitsAvailableForSqueezing = 0; - - return 0; -} - -static void AbsorbQueue(spongeState *state) -{ - /* state->bitsInQueue is assumed to be equal to state->rate */ - #ifdef KeccakReference - displayBytes(1, "Block to be absorbed", state->dataQueue, state->rate/8); - #endif -#ifdef ProvideFast576 - if (state->rate == 576) - KeccakAbsorb576bits(state->state, state->dataQueue); - else -#endif -#ifdef ProvideFast832 - if (state->rate == 832) - KeccakAbsorb832bits(state->state, state->dataQueue); - else -#endif -#ifdef ProvideFast1024 - if (state->rate == 1024) - KeccakAbsorb1024bits(state->state, state->dataQueue); - else -#endif -#ifdef ProvideFast1088 - if (state->rate == 1088) - KeccakAbsorb1088bits(state->state, state->dataQueue); - else -#endif -#ifdef ProvideFast1152 - if (state->rate == 1152) - KeccakAbsorb1152bits(state->state, state->dataQueue); - else -#endif -#ifdef ProvideFast1344 - if (state->rate == 1344) - KeccakAbsorb1344bits(state->state, state->dataQueue); - else -#endif - KeccakAbsorb(state->state, state->dataQueue, state->rate/64); - state->bitsInQueue = 0; -} - -static int Absorb(spongeState *state, const unsigned char *data, unsigned long long databitlen) -{ - unsigned long long i, j, wholeBlocks; - unsigned int partialBlock, partialByte; - const unsigned char *curData; - - if ((state->bitsInQueue % 8) != 0) - return 1; /* Only the last call may contain a partial byte */ - if (state->squeezing) - return 1; /* Too late for additional input */ - - i = 0; - while(i < databitlen) { - if ((state->bitsInQueue == 0) && (databitlen >= state->rate) && (i <= (databitlen-state->rate))) { - wholeBlocks = (databitlen-i)/state->rate; - curData = data+i/8; -#ifdef ProvideFast576 - if (state->rate == 576) { - for(j=0; jrate/8); - #endif - KeccakAbsorb576bits(state->state, curData); - } - } - else -#endif -#ifdef ProvideFast832 - if (state->rate == 832) { - for(j=0; jrate/8); - #endif - KeccakAbsorb832bits(state->state, curData); - } - } - else -#endif -#ifdef ProvideFast1024 - if (state->rate == 1024) { - for(j=0; jrate/8); - #endif - KeccakAbsorb1024bits(state->state, curData); - } - } - else -#endif -#ifdef ProvideFast1088 - if (state->rate == 1088) { - for(j=0; jrate/8); - #endif - KeccakAbsorb1088bits(state->state, curData); - } - } - else -#endif -#ifdef ProvideFast1152 - if (state->rate == 1152) { - for(j=0; jrate/8); - #endif - KeccakAbsorb1152bits(state->state, curData); - } - } - else -#endif -#ifdef ProvideFast1344 - if (state->rate == 1344) { - for(j=0; jrate/8); - #endif - KeccakAbsorb1344bits(state->state, curData); - } - } - else -#endif - { - for(j=0; jrate/8) { - #ifdef KeccakReference - displayBytes(1, "Block to be absorbed", curData, state->rate/8); - #endif - KeccakAbsorb(state->state, curData, state->rate/64); - } - } - i += wholeBlocks*state->rate; - } - else { - partialBlock = (unsigned int)(databitlen - i); - if (partialBlock+state->bitsInQueue > state->rate) - partialBlock = state->rate-state->bitsInQueue; - partialByte = partialBlock % 8; - partialBlock -= partialByte; - memcpy(state->dataQueue+state->bitsInQueue/8, data+i/8, partialBlock/8); - state->bitsInQueue += partialBlock; - i += partialBlock; - if (state->bitsInQueue == state->rate) - AbsorbQueue(state); - if (partialByte > 0) { - unsigned char mask = (1 << partialByte)-1; - state->dataQueue[state->bitsInQueue/8] = data[i/8] & mask; - state->bitsInQueue += partialByte; - i += partialByte; - } - } - } - return 0; -} - -static void PadAndSwitchToSqueezingPhase(spongeState *state) -{ - /* Note: the bits are numbered from 0=LSB to 7=MSB */ - if (state->bitsInQueue + 1 == state->rate) { - state->dataQueue[state->bitsInQueue/8 ] |= 1 << (state->bitsInQueue % 8); - AbsorbQueue(state); - memset(state->dataQueue, 0, state->rate/8); - } - else { - memset(state->dataQueue + (state->bitsInQueue+7)/8, 0, state->rate/8 - (state->bitsInQueue+7)/8); - state->dataQueue[state->bitsInQueue/8 ] |= 1 << (state->bitsInQueue % 8); - } - state->dataQueue[(state->rate-1)/8] |= 1 << ((state->rate-1) % 8); - AbsorbQueue(state); - - #ifdef KeccakReference - displayText(1, "--- Switching to squeezing phase ---"); - #endif -#ifdef ProvideFast1024 - if (state->rate == 1024) { - KeccakExtract1024bits(state->state, state->dataQueue); - state->bitsAvailableForSqueezing = 1024; - } - else -#endif - { - KeccakExtract(state->state, state->dataQueue, state->rate/64); - state->bitsAvailableForSqueezing = state->rate; - } - #ifdef KeccakReference - displayBytes(1, "Block available for squeezing", state->dataQueue, state->bitsAvailableForSqueezing/8); - #endif - state->squeezing = 1; -} - -static int Squeeze(spongeState *state, unsigned char *output, unsigned long long outputLength) -{ - unsigned long long i; - unsigned int partialBlock; - - if (!state->squeezing) - PadAndSwitchToSqueezingPhase(state); - if ((outputLength % 8) != 0) - return 1; /* Only multiple of 8 bits are allowed, truncation can be done at user level */ - - i = 0; - while(i < outputLength) { - if (state->bitsAvailableForSqueezing == 0) { - KeccakPermutation(state->state); -#ifdef ProvideFast1024 - if (state->rate == 1024) { - KeccakExtract1024bits(state->state, state->dataQueue); - state->bitsAvailableForSqueezing = 1024; - } - else -#endif - { - KeccakExtract(state->state, state->dataQueue, state->rate/64); - state->bitsAvailableForSqueezing = state->rate; - } - #ifdef KeccakReference - displayBytes(1, "Block available for squeezing", state->dataQueue, state->bitsAvailableForSqueezing/8); - #endif - } - partialBlock = state->bitsAvailableForSqueezing; - if ((unsigned long long)partialBlock > outputLength - i) - partialBlock = (unsigned int)(outputLength - i); - memcpy(output+i/8, state->dataQueue+(state->rate-state->bitsAvailableForSqueezing)/8, partialBlock/8); - state->bitsAvailableForSqueezing -= partialBlock; - i += partialBlock; - } - return 0; -} diff --git a/Modules/_sha3/keccak/KeccakSponge.h b/Modules/_sha3/keccak/KeccakSponge.h deleted file mode 100644 --- a/Modules/_sha3/keccak/KeccakSponge.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, -Micha?l Peeters and Gilles Van Assche. For more information, feedback or -questions, please refer to our website: http://keccak.noekeon.org/ - -Implementation by the designers, -hereby denoted as "the implementer". - -To the extent possible under law, the implementer has waived all copyright -and related or neighboring rights to the source code in this file. -http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#ifndef _KeccakSponge_h_ -#define _KeccakSponge_h_ - -#define KeccakPermutationSize 1600 -#define KeccakPermutationSizeInBytes (KeccakPermutationSize/8) -#define KeccakMaximumRate 1536 -#define KeccakMaximumRateInBytes (KeccakMaximumRate/8) - -#if defined(__GNUC__) -#define ALIGN __attribute__ ((aligned(32))) -#elif defined(_MSC_VER) -#define ALIGN __declspec(align(32)) -#else -#define ALIGN -#endif - -ALIGN typedef struct spongeStateStruct { - ALIGN unsigned char state[KeccakPermutationSizeInBytes]; - ALIGN unsigned char dataQueue[KeccakMaximumRateInBytes]; - unsigned int rate; - unsigned int capacity; - unsigned int bitsInQueue; - unsigned int fixedOutputLength; - int squeezing; - unsigned int bitsAvailableForSqueezing; -} spongeState; - -/** - * Function to initialize the state of the Keccak[r, c] sponge function. - * The sponge function is set to the absorbing phase. - * @param state Pointer to the state of the sponge function to be initialized. - * @param rate The value of the rate r. - * @param capacity The value of the capacity c. - * @pre One must have r+c=1600 and the rate a multiple of 64 bits in this implementation. - * @return Zero if successful, 1 otherwise. - */ -static int InitSponge(spongeState *state, unsigned int rate, unsigned int capacity); -/** - * Function to give input data for the sponge function to absorb. - * @param state Pointer to the state of the sponge function initialized by InitSponge(). - * @param data Pointer to the input data. - * When @a databitLen is not a multiple of 8, the last bits of data must be - * in the least significant bits of the last byte. - * @param databitLen The number of input bits provided in the input data. - * @pre In the previous call to Absorb(), databitLen was a multiple of 8. - * @pre The sponge function must be in the absorbing phase, - * i.e., Squeeze() must not have been called before. - * @return Zero if successful, 1 otherwise. - */ -static int Absorb(spongeState *state, const unsigned char *data, unsigned long long databitlen); -/** - * Function to squeeze output data from the sponge function. - * If the sponge function was in the absorbing phase, this function - * switches it to the squeezing phase. - * @param state Pointer to the state of the sponge function initialized by InitSponge(). - * @param output Pointer to the buffer where to store the output data. - * @param outputLength The number of output bits desired. - * It must be a multiple of 8. - * @return Zero if successful, 1 otherwise. - */ -static int Squeeze(spongeState *state, unsigned char *output, unsigned long long outputLength); - -#endif diff --git a/Modules/_sha3/keccak/brg_endian.h b/Modules/_sha3/keccak/brg_endian.h deleted file mode 100755 --- a/Modules/_sha3/keccak/brg_endian.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - --------------------------------------------------------------------------- - Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved. - - LICENSE TERMS - - The redistribution and use of this software (with or without changes) - is allowed without the payment of fees or royalties provided that: - - 1. source code distributions include the above copyright notice, this - list of conditions and the following disclaimer; - - 2. binary distributions include the above copyright notice, this list - of conditions and the following disclaimer in their documentation; - - 3. the name of the copyright holder is not used to endorse products - built using this software without specific written permission. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and/or fitness for purpose. - --------------------------------------------------------------------------- - Issue Date: 20/12/2007 - Changes for ARM 9/9/2010 -*/ - -#ifndef _BRG_ENDIAN_H -#define _BRG_ENDIAN_H - -#define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ -#define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ - -#if 0 -/* Include files where endian defines and byteswap functions may reside */ -#if defined( __sun ) -# include -#elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) -# include -#elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ - defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) -# include -#elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) -# if !defined( __MINGW32__ ) && !defined( _AIX ) -# include -# if !defined( __BEOS__ ) -# include -# endif -# endif -#endif -#endif - -/* Now attempt to set the define for platform byte order using any */ -/* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ -/* seem to encompass most endian symbol definitions */ - -#if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) -# if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -# elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -# endif -#elif defined( BIG_ENDIAN ) -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -#elif defined( LITTLE_ENDIAN ) -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -#endif - -#if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) -# if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -# elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -# endif -#elif defined( _BIG_ENDIAN ) -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -#elif defined( _LITTLE_ENDIAN ) -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -#endif - -#if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) -# if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -# elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -# endif -#elif defined( __BIG_ENDIAN ) -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -#elif defined( __LITTLE_ENDIAN ) -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -#endif - -#if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) -# if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -# elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -# endif -#elif defined( __BIG_ENDIAN__ ) -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -#elif defined( __LITTLE_ENDIAN__ ) -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -#endif - -/* if the platform byte order could not be determined, then try to */ -/* set this define using common machine defines */ -#if !defined(PLATFORM_BYTE_ORDER) - -#if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ - defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ - defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ - defined( vax ) || defined( vms ) || defined( VMS ) || \ - defined( __VMS ) || defined( _M_X64 ) -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN - -#elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ - defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ - defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ - defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ - defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ - defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ - defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN - -#elif defined(__arm__) -# ifdef __BIG_ENDIAN -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -# else -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -# endif -#elif 1 /* **** EDIT HERE IF NECESSARY **** */ -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -#elif 0 /* **** EDIT HERE IF NECESSARY **** */ -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -#else -# error Please edit lines 132 or 134 in brg_endian.h to set the platform byte order -#endif - -#endif - -#endif diff --git a/Modules/_sha3/keccak/crypto_hash.h b/Modules/_sha3/keccak/crypto_hash.h deleted file mode 100644 diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c deleted file mode 100644 --- a/Modules/_sha3/sha3module.c +++ /dev/null @@ -1,593 +0,0 @@ -/* SHA3 module - * - * This module provides an interface to the SHA3 algorithm - * - * See below for information about the original code this module was - * based upon. Additional work performed by: - * - * Andrew Kuchling (amk at amk.ca) - * Greg Stein (gstein at lyra.org) - * Trevor Perrin (trevp at trevp.net) - * Gregory P. Smith (greg at krypto.org) - * - * Copyright (C) 2012 Christian Heimes (christian at python.org) - * Licensed to PSF under a Contributor Agreement. - * - */ - -#include "Python.h" -#include "../hashlib.h" - -/* ************************************************************************** - * SHA-3 (Keccak) - * - * The code is based on KeccakReferenceAndOptimized-3.2.zip from 29 May 2012. - * - * The reference implementation is altered in this points: - * - C++ comments are converted to ANSI C comments. - * - All functions and globals are declared static. - * - The typedef for UINT64 is commented out. - * - KeccakF-1600-opt[32|64]-settings.h are commented out - * - Some unused functions are commented out to silence compiler warnings. - * - * In order to avoid name clashes with other software I have to declare all - * Keccak functions and global data as static. The C code is directly - * included into this file in order to access the static functions. - * - * Keccak can be tuned with several paramenters. I try to explain all options - * as far as I understand them. The reference implementation also contains - * assembler code for ARM platforms (NEON instructions). - * - * Common - * ====== - * - * Options: - * UseBebigokimisa, Unrolling - * - * - Unrolling: loop unrolling (24, 12, 8, 6, 4, 3, 2, 1) - * - UseBebigokimisa: lane complementing - * - * 64bit platforms - * =============== - * - * Additional options: - * UseSSE, UseOnlySIMD64, UseMMX, UseXOP, UseSHLD - * - * Optimized instructions (disabled by default): - * - UseSSE: use Stream SIMD extensions - * o UseOnlySIMD64: limit to 64bit instructions, otherwise 128bit - * o w/o UseOnlySIMD64: requires compiler agument -mssse3 or -mtune - * - UseMMX: use 64bit MMX instructions - * - UseXOP: use AMD's eXtended Operations (128bit SSE extension) - * - * Other: - * - Unrolling: default 24 - * - UseBebigokimisa: default 1 - * - * When neither UseSSE, UseMMX nor UseXOP is configured, ROL64 (rotate left - * 64) is implemented as: - * - Windows: _rotl64() - * - UseSHLD: use shld (shift left) asm optimization - * - otherwise: shift and xor - * - * UseBebigokimisa can't be used in combination with UseSSE, UseMMX or - * UseXOP. UseOnlySIMD64 has no effect unless UseSSE is specified. - * - * Tests have shown that UseSSE + UseOnlySIMD64 is about three to four - * times SLOWER than UseBebigokimisa. UseSSE and UseMMX are about two times - * slower. (tested by CH and AP) - * - * 32bit platforms - * =============== - * - * Additional options: - * UseInterleaveTables, UseSchedule - * - * - Unrolling: default 2 - * - UseBebigokimisa: default n/a - * - UseSchedule: ???, (1, 2, 3; default 3) - * - UseInterleaveTables: use two 64k lookup tables for (de)interleaving - * default: n/a - * - * schedules: - * - 3: no UseBebigokimisa, Unrolling must be 2 - * - 2 + 1: ??? - * - * *************************************************************************/ - -#ifdef __sparc - /* opt64 uses un-aligned memory access that causes a BUS error with msg - * 'invalid address alignment' on SPARC. */ - #define KeccakOpt 32 -#elif SIZEOF_VOID_P == 8 && defined(PY_UINT64_T) - /* opt64 works only for 64bit platforms with unsigned int64 */ - #define KeccakOpt 64 -#else - /* opt32 is used for the remaining 32 and 64bit platforms */ - #define KeccakOpt 32 -#endif - -#if KeccakOpt == 64 && defined(PY_UINT64_T) - /* 64bit platforms with unsigned int64 */ - #define Unrolling 24 - #define UseBebigokimisa - typedef PY_UINT64_T UINT64; -#elif KeccakOpt == 32 && defined(PY_UINT64_T) - /* 32bit platforms with unsigned int64 */ - #define Unrolling 2 - #define UseSchedule 3 - typedef PY_UINT64_T UINT64; -#else - /* 32 or 64bit platforms without unsigned int64 */ - #define Unrolling 2 - #define UseSchedule 3 - #define UseInterleaveTables -#endif - -/* replacement for brg_endian.h */ -#define IS_BIG_ENDIAN 4321 -#define IS_LITTLE_ENDIAN 1234 -#if PY_BIG_ENDIAN -# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN -#else -# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN -#endif - -/* inline all Keccak dependencies */ -#include "keccak/KeccakNISTInterface.h" -#include "keccak/KeccakNISTInterface.c" -#include "keccak/KeccakSponge.c" -#if KeccakOpt == 64 - #include "keccak/KeccakF-1600-opt64.c" -#elif KeccakOpt == 32 - #include "keccak/KeccakF-1600-opt32.c" -#endif - -/* #define SHA3_BLOCKSIZE 200 // 1600 bits */ -#define SHA3_MAX_DIGESTSIZE 64 /* 512 bits */ -#define SHA3_state hashState -#define SHA3_init Init -#define SHA3_process Update -#define SHA3_done Final -#define SHA3_copystate(dest, src) memcpy(&(dest), &(src), sizeof(SHA3_state)) -#define SHA3_clearstate(state) memset(&(state), 0, sizeof(SHA3_state)) - -/* The structure for storing SHA3 info */ - -typedef struct { - PyObject_HEAD - int hashbitlen; - SHA3_state hash_state; -#ifdef WITH_THREAD - PyThread_type_lock lock; -#endif - -} SHA3object; - -static PyTypeObject SHA3type; - - -static SHA3object * -newSHA3object(int hashbitlen) -{ - SHA3object *newobj; - - /* check hashbitlen */ - switch(hashbitlen) { - /* supported hash length */ - case 224: - break; - case 256: - break; - case 384: - break; - case 512: - break; - case 0: - /* arbitrarily-long output isn't supported by this module */ - default: - /* everything else is an error */ - PyErr_SetString(PyExc_ValueError, - "hashbitlen must be one of 224, 256, 384 or 512."); - return NULL; - } - newobj = (SHA3object *)PyObject_New(SHA3object, &SHA3type); - if (newobj == NULL) { - return NULL; - } - newobj->hashbitlen = hashbitlen; -#ifdef WITH_THREAD - newobj->lock = NULL; -#endif - return newobj; -} - - -/* Internal methods for a hash object */ - -static void -SHA3_dealloc(SHA3object *self) -{ - SHA3_clearstate(self->hash_state); -#ifdef WITH_THREAD - if (self->lock) { - PyThread_free_lock(self->lock); - } -#endif - PyObject_Del(self); -} - - -/* External methods for a hash object */ - -PyDoc_STRVAR(SHA3_copy__doc__, "Return a copy of the hash object."); - -static PyObject * -SHA3_copy(SHA3object *self, PyObject *unused) -{ - SHA3object *newobj; - - if ((newobj = newSHA3object(self->hashbitlen)) == NULL) { - return NULL; - } - ENTER_HASHLIB(self); - SHA3_copystate(newobj->hash_state, self->hash_state); - LEAVE_HASHLIB(self); - return (PyObject *)newobj; -} - - -PyDoc_STRVAR(SHA3_digest__doc__, -"Return the digest value as a string of binary data."); - -static PyObject * -SHA3_digest(SHA3object *self, PyObject *unused) -{ - unsigned char digest[SHA3_MAX_DIGESTSIZE]; - SHA3_state temp; - HashReturn res; - - ENTER_HASHLIB(self); - SHA3_copystate(temp, self->hash_state); - LEAVE_HASHLIB(self); - res = SHA3_done(&temp, digest); - SHA3_clearstate(temp); - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Final()"); - return NULL; - } - return PyBytes_FromStringAndSize((const char *)digest, - self->hashbitlen / 8); -} - - -PyDoc_STRVAR(SHA3_hexdigest__doc__, -"Return the digest value as a string of hexadecimal digits."); - -static PyObject * -SHA3_hexdigest(SHA3object *self, PyObject *unused) -{ - unsigned char digest[SHA3_MAX_DIGESTSIZE]; - SHA3_state temp; - HashReturn res; - PyObject *retval; - Py_UCS1 *hex_digest; - int digestlen, i, j; - - /* Get the raw (binary) digest value */ - ENTER_HASHLIB(self); - SHA3_copystate(temp, self->hash_state); - LEAVE_HASHLIB(self); - res = SHA3_done(&temp, digest); - SHA3_clearstate(temp); - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, "internal error in SHA3 Final()"); - return NULL; - } - - /* Create a new string */ - digestlen = self->hashbitlen / 8; - retval = PyUnicode_New(digestlen * 2, 127); - if (!retval) - return NULL; - hex_digest = PyUnicode_1BYTE_DATA(retval); - - /* Make hex version of the digest */ - for(i=j=0; i < digestlen; i++) { - unsigned char c; - c = (digest[i] >> 4) & 0xf; - hex_digest[j++] = Py_hexdigits[c]; - c = (digest[i] & 0xf); - hex_digest[j++] = Py_hexdigits[c]; - } -#ifdef Py_DEBUG - assert(_PyUnicode_CheckConsistency(retval, 1)); -#endif - return retval; -} - -PyDoc_STRVAR(SHA3_update__doc__, -"Update this hash object's state with the provided string."); - -static PyObject * -SHA3_update(SHA3object *self, PyObject *args) -{ - PyObject *obj; - Py_buffer buf; - HashReturn res; - - if (!PyArg_ParseTuple(args, "O:update", &obj)) - return NULL; - - GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); - - /* add new data, the function takes the length in bits not bytes */ -#ifdef WITH_THREAD - if (self->lock == NULL && buf.len >= HASHLIB_GIL_MINSIZE) { - self->lock = PyThread_allocate_lock(); - } - /* Once a lock exists all code paths must be synchronized. We have to - * release the GIL even for small buffers as acquiring the lock may take - * an unlimited amount of time when another thread updates this object - * with lots of data. */ - if (self->lock) { - Py_BEGIN_ALLOW_THREADS - PyThread_acquire_lock(self->lock, 1); - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); - PyThread_release_lock(self->lock); - Py_END_ALLOW_THREADS - } - else { - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); - } -#else - res = SHA3_process(&self->hash_state, buf.buf, buf.len * 8); -#endif - LEAVE_HASHLIB(self); - - if (res != SUCCESS) { - PyBuffer_Release(&buf); - PyErr_SetString(PyExc_RuntimeError, - "internal error in SHA3 Update()"); - return NULL; - } - - PyBuffer_Release(&buf); - Py_INCREF(Py_None); - return Py_None; -} - -static PyMethodDef SHA3_methods[] = { - {"copy", (PyCFunction)SHA3_copy, METH_NOARGS, - SHA3_copy__doc__}, - {"digest", (PyCFunction)SHA3_digest, METH_NOARGS, - SHA3_digest__doc__}, - {"hexdigest", (PyCFunction)SHA3_hexdigest, METH_NOARGS, - SHA3_hexdigest__doc__}, - {"update", (PyCFunction)SHA3_update, METH_VARARGS, - SHA3_update__doc__}, - {NULL, NULL} /* sentinel */ -}; - -static PyObject * -SHA3_get_block_size(SHA3object *self, void *closure) -{ - /* HMAC-SHA3 hasn't been specified yet and no official test vectors are - * available. Thus block_size returns NotImplemented to prevent people - * from using SHA3 with the hmac module. - */ - Py_RETURN_NOTIMPLEMENTED; -} - -static PyObject * -SHA3_get_name(SHA3object *self, void *closure) -{ - return PyUnicode_FromFormat("sha3_%i", self->hashbitlen); -} - -static PyObject * -SHA3_get_digest_size(SHA3object *self, void *closure) -{ - return PyLong_FromLong(self->hashbitlen / 8); -} - - -static PyGetSetDef SHA3_getseters[] = { - {"block_size", (getter)SHA3_get_block_size, NULL, NULL, NULL}, - {"name", (getter)SHA3_get_name, NULL, NULL, NULL}, - {"digest_size", (getter)SHA3_get_digest_size, NULL, NULL, NULL}, - {NULL} /* Sentinel */ -}; - -static PyTypeObject SHA3type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_sha3.SHA3", /* tp_name */ - sizeof(SHA3object), /* tp_size */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)SHA3_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - SHA3_methods, /* tp_methods */ - NULL, /* tp_members */ - SHA3_getseters, /* tp_getset */ -}; - - -/* constructor helper */ -static PyObject * -SHA3_factory(PyObject *args, PyObject *kwdict, const char *fmt, - int hashbitlen) -{ - SHA3object *newobj = NULL; - static char *kwlist[] = {"string", NULL}; - PyObject *data_obj = NULL; - Py_buffer buf; - HashReturn res; - - if (!PyArg_ParseTupleAndKeywords(args, kwdict, fmt, kwlist, - &data_obj)) { - return NULL; - } - - if (data_obj) - GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); - - if ((newobj = newSHA3object(hashbitlen)) == NULL) { - goto error; - } - - if (SHA3_init(&newobj->hash_state, hashbitlen) != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, - "internal error in SHA3 Update()"); - goto error; - } - - if (data_obj) { -#ifdef WITH_THREAD - if (buf.len >= HASHLIB_GIL_MINSIZE) { - /* invariant: New objects can't be accessed by other code yet, - * thus it's safe to release the GIL without locking the object. - */ - Py_BEGIN_ALLOW_THREADS - res = SHA3_process(&newobj->hash_state, buf.buf, buf.len * 8); - Py_END_ALLOW_THREADS - } - else { - res = SHA3_process(&newobj->hash_state, buf.buf, buf.len * 8); - } -#else - res = SHA3_process(&newobj->hash_state, buf.buf, buf.len * 8); -#endif - if (res != SUCCESS) { - PyErr_SetString(PyExc_RuntimeError, - "internal error in SHA3 Update()"); - goto error; - } - PyBuffer_Release(&buf); - } - - return (PyObject *)newobj; - - error: - if (newobj) { - SHA3_dealloc(newobj); - } - if (data_obj) { - PyBuffer_Release(&buf); - } - return NULL; - -} - -PyDoc_STRVAR(sha3_224__doc__, -"sha3_224([string]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 28 bytes."); - -static PyObject * -sha3_224(PyObject *self, PyObject *args, PyObject *kwdict) -{ - return SHA3_factory(args, kwdict, "|O:sha3_224", 224); -} - - -PyDoc_STRVAR(sha3_256__doc__, -"sha3_256([string]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 32 bytes."); - -static PyObject * -sha3_256(PyObject *self, PyObject *args, PyObject *kwdict) -{ - return SHA3_factory(args, kwdict, "|O:sha3_256", 256); -} - -PyDoc_STRVAR(sha3_384__doc__, -"sha3_384([string]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 48 bytes."); - -static PyObject * -sha3_384(PyObject *self, PyObject *args, PyObject *kwdict) -{ - return SHA3_factory(args, kwdict, "|O:sha3_384", 384); -} - -PyDoc_STRVAR(sha3_512__doc__, -"sha3_512([string]) -> SHA3 object\n\ -\n\ -Return a new SHA3 hash object with a hashbit length of 64 bytes."); - -static PyObject * -sha3_512(PyObject *self, PyObject *args, PyObject *kwdict) -{ - return SHA3_factory(args, kwdict, "|O:sha3_512", 512); -} - - -/* List of functions exported by this module */ -static struct PyMethodDef SHA3_functions[] = { - {"sha3_224", (PyCFunction)sha3_224, METH_VARARGS|METH_KEYWORDS, - sha3_224__doc__}, - {"sha3_256", (PyCFunction)sha3_256, METH_VARARGS|METH_KEYWORDS, - sha3_256__doc__}, - {"sha3_384", (PyCFunction)sha3_384, METH_VARARGS|METH_KEYWORDS, - sha3_384__doc__}, - {"sha3_512", (PyCFunction)sha3_512, METH_VARARGS|METH_KEYWORDS, - sha3_512__doc__}, - {NULL, NULL} /* Sentinel */ -}; - - -/* Initialize this module. */ -static struct PyModuleDef _SHA3module = { - PyModuleDef_HEAD_INIT, - "_sha3", - NULL, - -1, - SHA3_functions, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__sha3(void) -{ - PyObject *m; - - Py_TYPE(&SHA3type) = &PyType_Type; - if (PyType_Ready(&SHA3type) < 0) { - return NULL; - } - - m = PyModule_Create(&_SHA3module); - if (m == NULL) - return NULL; - - Py_INCREF((PyObject *)&SHA3type); - PyModule_AddObject(m, "SHA3Type", (PyObject *)&SHA3type); - return m; -} diff --git a/PC/VS9.0/_sha3.vcproj b/PC/VS9.0/_sha3.vcproj deleted file mode 100644 --- a/PC/VS9.0/_sha3.vcproj +++ /dev/null @@ -1,513 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PC/VS9.0/pcbuild.sln b/PC/VS9.0/pcbuild.sln --- a/PC/VS9.0/pcbuild.sln +++ b/PC/VS9.0/pcbuild.sln @@ -152,8 +152,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_sha3", "_sha3.vcproj", "{04F37400-883C-42D7-AE28-6CF9953BF975}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 diff --git a/PCbuild/_sha3.vcxproj b/PCbuild/_sha3.vcxproj deleted file mode 100644 --- a/PCbuild/_sha3.vcxproj +++ /dev/null @@ -1,218 +0,0 @@ -? - - - - Debug - Win32 - - - Debug - x64 - - - PGInstrument - Win32 - - - PGInstrument - x64 - - - PGUpdate - Win32 - - - PGUpdate - x64 - - - Release - Win32 - - - Release - x64 - - - - {254A0C05-6696-4B08-8CB2-EF7D533AEE01} - _sha3 - Win32Proj - - - - DynamicLibrary - NotSet - true - - - DynamicLibrary - NotSet - true - - - DynamicLibrary - NotSet - true - - - DynamicLibrary - NotSet - - - DynamicLibrary - NotSet - true - - - DynamicLibrary - NotSet - true - - - DynamicLibrary - NotSet - true - - - DynamicLibrary - NotSet - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - %(AdditionalDependencies) - - - - - X64 - - - %(AdditionalDependencies) - - - - - %(AdditionalDependencies) - - - - - X64 - - - %(AdditionalDependencies) - - - - - %(AdditionalDependencies) - - - - - X64 - - - %(AdditionalDependencies) - MachineX64 - - - - - %(AdditionalDependencies) - - - - - X64 - - - %(AdditionalDependencies) - MachineX64 - - - - - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - false - - - - - - - - - \ No newline at end of file diff --git a/PCbuild/_sha3.vcxproj.filters b/PCbuild/_sha3.vcxproj.filters deleted file mode 100644 --- a/PCbuild/_sha3.vcxproj.filters +++ /dev/null @@ -1,13 +0,0 @@ -? - - - - {f1f1fd19-4f85-4a56-be41-af14f0bc2a9c} - - - - - Source Files - - - \ No newline at end of file diff --git a/PCbuild/pcbuild.sln b/PCbuild/pcbuild.sln --- a/PCbuild/pcbuild.sln +++ b/PCbuild/pcbuild.sln @@ -74,10 +74,6 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_freeze_importlib", "_freeze_importlib.vcxproj", "{19C0C13F-47CA-4432-AFF3-799A296A4DDC}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_sha3", "_sha3.vcxproj", "{254A0C05-6696-4B08-8CB2-EF7D533AEE01}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_overlapped", "_overlapped.vcxproj", "{EB6E69DD-04BF-4543-9B92-49FAABCEAC2E}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testembed", "_testembed.vcxproj", "{6DAC66D9-E703-4624-BE03-49112AB5AA62}" EndProject Global diff --git a/PCbuild/readme.txt b/PCbuild/readme.txt --- a/PCbuild/readme.txt +++ b/PCbuild/readme.txt @@ -140,7 +140,6 @@ _msi _multiprocessing _overlapped -_sha3 _socket _testcapi _testbuffer diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -100,7 +100,6 @@ '_lzma.pyd', '_decimal.pyd', '_testbuffer.pyd', - '_sha3.pyd', '_testimportmultiple.pyd', '_overlapped.pyd', ] diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -827,15 +827,6 @@ exts.append( Extension('_sha1', ['sha1module.c'], depends=['hashlib.h']) ) - # SHA-3 (Keccak) module - sha3_depends = ['hashlib.h'] - keccak = os.path.join(os.getcwd(), srcdir, 'Modules', '_sha3', - 'keccak') - for pattern in ('*.c', '*.h', '*.macros'): - sha3_depends.extend(glob(os.path.join(keccak, pattern))) - exts.append(Extension("_sha3", ["_sha3/sha3module.c"], - depends=sha3_depends)) - # Modules that provide persistent dictionary-like semantics. You will # probably want to arrange for at least one of them to be available on # your machine, though none are defined by default because of library -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 15:53:42 2014 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 3 Jan 2014 15:53:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Revert_accidental_deletion?= =?utf-8?q?_of_=5Foverlapped=2E?= Message-ID: <3dwpyt4r87z7Ljw@mail.python.org> http://hg.python.org/cpython/rev/8a3718f31188 changeset: 88274:8a3718f31188 user: Martin v. L?wis date: Fri Jan 03 15:53:20 2014 +0100 summary: Revert accidental deletion of _overlapped. files: PCbuild/pcbuild.sln | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/PCbuild/pcbuild.sln b/PCbuild/pcbuild.sln --- a/PCbuild/pcbuild.sln +++ b/PCbuild/pcbuild.sln @@ -74,6 +74,8 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_freeze_importlib", "_freeze_importlib.vcxproj", "{19C0C13F-47CA-4432-AFF3-799A296A4DDC}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_overlapped", "_overlapped.vcxproj", "{EB6E69DD-04BF-4543-9B92-49FAABCEAC2E}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testembed", "_testembed.vcxproj", "{6DAC66D9-E703-4624-BE03-49112AB5AA62}" EndProject Global -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 17:40:10 2014 From: python-checkins at python.org (victor.stinner) Date: Fri, 3 Jan 2014 17:40:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_now_unused_variable?= =?utf-8?q?s?= Message-ID: <3dwsKk6ZWGz7Ljf@mail.python.org> http://hg.python.org/cpython/rev/85006a6136bf changeset: 88275:85006a6136bf user: Victor Stinner date: Fri Jan 03 17:39:40 2014 +0100 summary: Remove now unused variables files: Objects/unicodeobject.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2876,10 +2876,6 @@ PyObject * PyUnicode_FromOrdinal(int ordinal) { - PyObject *v; - void *data; - int kind; - if (ordinal < 0 || ordinal > MAX_UNICODE) { PyErr_SetString(PyExc_ValueError, "chr() arg not in range(0x110000)"); @@ -11330,7 +11326,6 @@ void *data; enum PyUnicode_Kind kind; Py_UCS4 ch; - PyObject *res; if (!PyUnicode_Check(self) || PyUnicode_READY(self) == -1) { PyErr_BadArgument(); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 17:42:29 2014 From: python-checkins at python.org (victor.stinner) Date: Fri, 3 Jan 2014 17:42:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_deadcode_=28HASH_ma?= =?utf-8?q?cro_is_no_more_defined=29?= Message-ID: <3dwsNP4wg1z7LjR@mail.python.org> http://hg.python.org/cpython/rev/14a2324e82e4 changeset: 88276:14a2324e82e4 user: Victor Stinner date: Fri Jan 03 17:42:18 2014 +0100 summary: Remove deadcode (HASH macro is no more defined) files: Objects/unicodeobject.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11370,7 +11370,6 @@ _PyUnicode_HASH(self) = x; return x; } -#undef HASH PyDoc_STRVAR(index__doc__, "S.index(sub[, start[, end]]) -> int\n\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 19:04:58 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 19:04:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_http=2Eserver_?= =?utf-8?q?send=5Ferror_explain_parameter=2E?= Message-ID: <3dwvCZ6zMHzQnV@mail.python.org> http://hg.python.org/cpython/rev/8ade807624a5 changeset: 88277:8ade807624a5 user: R David Murray date: Fri Jan 03 13:03:00 2014 -0500 summary: whatsnew: http.server send_error explain parameter. Also rewrote the send_error description for clarity and correct English. files: Doc/library/http.server.rst | 15 +++++++++------ Doc/whatsnew/3.4.rst | 12 ++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst --- a/Doc/library/http.server.rst +++ b/Doc/library/http.server.rst @@ -116,7 +116,7 @@ HTTP error code value. *message* should be a string containing a (detailed) error message of what occurred, and *explain* should be an explanation of the error code number. Default *message* and *explain* - values can found in the *responses* class variable. + values can found in the :attr:`responses` class variable. .. attribute:: error_content_type @@ -173,11 +173,14 @@ .. method:: send_error(code, message=None, explain=None) Sends and logs a complete error reply to the client. The numeric *code* - specifies the HTTP error code, with *message* as optional, more specific - text, usually referring to short message response. The *explain* - argument can be used to send a detailed information about the error in - response content body. A complete set of headers is sent, followed by - text composed using the :attr:`error_message_format` class variable. + specifies the HTTP error code, with *message* as an optional, short, human + readable description of the error. The *explain* argument can be used to + provide more detailed information about the error; it will be formatted + using the :attr:`error_message_format` class variable and emitted, after + a complete set of headers, as the response body. The :attr:`responses` + class variable holds the default values for *message* and *explain* that + will be used if no value is provided; for unknown codes the default value + for both is the string ``???``. .. versionchanged:: 3.4 The error response includes a Content-Length header. diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -684,6 +684,18 @@ (Contributed by Ezio Melotti in :issue:`15114`) +http +---- + +:meth:`~http.server.BaseHTTPRequestHandler.send_error` now accepts an +optional additional *exaplain* parameter which can be used to provide an +extended error description, overriding the hardcoded default if there is one. +This extended error description will be formatted using the +:attr:`~http.server.HTTP.error_message_format` attribute and sent as the body +of the error response. (Contributed by Karl Cow in :issue:`12921`.) + + + importlib --------- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 19:05:00 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 19:05:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_unittest_impor?= =?utf-8?q?t_time_SkipTest_reported_as_skip_not_error=2E?= Message-ID: <3dwvCc1gyczQnV@mail.python.org> http://hg.python.org/cpython/rev/22235c8e0a33 changeset: 88278:22235c8e0a33 user: R David Murray date: Fri Jan 03 13:03:36 2014 -0500 summary: whatsnew: unittest import time SkipTest reported as skip not error. files: Doc/library/unittest.rst | 5 +++-- Doc/whatsnew/3.4.rst | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -559,8 +559,9 @@ Usually you can use :meth:`TestCase.skipTest` or one of the skipping decorators instead of raising this directly. -Skipped tests will not have :meth:`setUp` or :meth:`tearDown` run around them. -Skipped classes will not have :meth:`setUpClass` or :meth:`tearDownClass` run. +Skipped tests will not have :meth:`~TestCase.setUp` or :meth:`~TestCase.tearDown` run around them. +Skipped classes will not have :meth:`~TestCase.setUpClass` or :meth:`~TestCase.tearDownClass` run. +Skipped modules will not have :func:`setUpModule` or :func:`tearDownModule` run. .. _subtests: diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1015,6 +1015,10 @@ *defaultTest*, where previously it only accepted a single test name as a string. (Contributed by Jyrki Pulliainen in :issue:`15132`.) +If :class:`~unittest.SkipTest` is raised during test discovery (that is, at the +module level in the test file), it is now reported as a skip instead of an +error. (Contributed by Zach Ware in :issue:`16935`.) + venv ---- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 19:05:01 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 19:05:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_deprecation_of?= =?utf-8?q?_HTTPConnection=27s_strict_parameter=2E?= Message-ID: <3dwvCd39HQz7LlG@mail.python.org> http://hg.python.org/cpython/rev/5ff4f2be7d8a changeset: 88279:5ff4f2be7d8a user: R David Murray date: Fri Jan 03 13:04:25 2014 -0500 summary: whatsnew: deprecation of HTTPConnection's strict parameter. files: Doc/library/http.client.rst | 12 ++++++------ Doc/whatsnew/3.4.rst | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst --- a/Doc/library/http.client.rst +++ b/Doc/library/http.client.rst @@ -52,8 +52,8 @@ *source_address* was added. .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9-style "Simple Responses" are - not supported. + The *strict* parameter was removed. HTTP 0.9-style "Simple Responses" are + not longer supported. .. class:: HTTPSConnection(host, port=None, key_file=None, \ @@ -90,8 +90,8 @@ if :data:`ssl.HAS_SNI` is true). .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9-style "Simple Responses" are - not supported anymore. + The *strict* parameter was removed. HTTP 0.9-style "Simple Responses" are + no longer supported. .. class:: HTTPResponse(sock, debuglevel=0, method=None, url=None) @@ -100,8 +100,8 @@ instantiated directly by user. .. versionchanged:: 3.4 - The *strict* parameter is removed. HTTP 0.9 style "Simple Responses" are - not supported anymore. + The *strict* parameter was removed. HTTP 0.9 style "Simple Responses" are + no longer supported. The following exceptions are raised as appropriate: diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1303,7 +1303,7 @@ * The unmaintained ``Misc/TextMate`` and ``Misc/vim`` directories have been removed (see the `devguide `_ - for what to use instead). + for suggestions on what to use instead). * The ``SO`` makefile macro is removed (it was replaced by the ``SHLIB_SUFFIX`` and ``EXT_SUFFIX`` macros) (:issue:`16754`). @@ -1314,6 +1314,9 @@ * ``PyLoader`` and ``PyPycLoader`` have been removed from :mod:`importlib`. (Contributed by Taras Lyapun in :issue:`15641`.) +* The *strict* argument to :class:`~http.client.HTTPConnection` has been + removed. HTTP 0.9-style "Simple Responses" are no longer supported. + Porting to Python 3.4 ===================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 20:00:28 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 20:00:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_closes_16039?= =?utf-8?q?=3A_CVE-2013-1752=3A_limit_line_length_in_imaplib_readline_call?= =?utf-8?q?s=2E?= Message-ID: <3dwwRc4B3Kz7Ljg@mail.python.org> http://hg.python.org/cpython/rev/dd906f4ab923 changeset: 88280:dd906f4ab923 branch: 2.7 parent: 88260:69b5f6924553 user: R David Murray date: Fri Jan 03 13:59:22 2014 -0500 summary: closes 16039: CVE-2013-1752: limit line length in imaplib readline calls. files: Lib/imaplib.py | 14 +++++++++++++- Lib/test/test_imaplib.py | 10 ++++++++++ Misc/NEWS | 3 +++ 3 files changed, 26 insertions(+), 1 deletions(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -35,6 +35,15 @@ IMAP4_SSL_PORT = 993 AllowedVersions = ('IMAP4REV1', 'IMAP4') # Most recent first +# Maximal line length when calling readline(). This is to prevent +# reading arbitrary length lines. RFC 3501 and 2060 (IMAP 4rev1) +# don't specify a line length. RFC 2683 however suggests limiting client +# command lines to 1000 octets and server command lines to 8000 octets. +# We have selected 10000 for some extra margin and since that is supposedly +# also what UW and Panda IMAP does. +_MAXLINE = 10000 + + # Commands Commands = { @@ -237,7 +246,10 @@ def readline(self): """Read line from remote.""" - return self.file.readline() + line = self.file.readline(_MAXLINE + 1) + if len(line) > _MAXLINE: + raise self.error("got more than %d bytes" % _MAXLINE) + return line def send(self, data): diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -165,6 +165,16 @@ self.imap_class, *server.server_address) + def test_linetoolong(self): + class TooLongHandler(SimpleIMAPHandler): + def handle(self): + # Send a very long response line + self.wfile.write('* OK ' + imaplib._MAXLINE*'x' + '\r\n') + + with self.reaped_server(TooLongHandler) as server: + self.assertRaises(imaplib.IMAP4.error, + self.imap_class, *server.server_address) + class ThreadedNetworkedTests(BaseThreadedNetworkedTests): server_class = SocketServer.TCPServer diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,9 @@ Library ------- +- Issue #16039: CVE-2013-1752: Change use of readline in imaplib module to + limit line length. Patch by Emil Lind. + - Issue #19422: Explicitly disallow non-SOCK_STREAM sockets in the ssl module, rather than silently let them emit clear text data. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 20:14:08 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 20:14:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_porting_note_f?= =?utf-8?q?or_HTTP=5BS=5DConnection_strict_parameter_removal=2E?= Message-ID: <3dwwlN2kqwz7Ljw@mail.python.org> http://hg.python.org/cpython/rev/f9bb9c11363a changeset: 88281:f9bb9c11363a parent: 88279:5ff4f2be7d8a user: R David Murray date: Fri Jan 03 14:06:01 2014 -0500 summary: whatsnew: porting note for HTTP[S]Connection strict parameter removal. It was discussed in issue #17460 whether or not to make the remaining arguments keyword only so that things would fail noisily if someone was still using positional parameters, but no decision was made and we are now well past the Beta API change deadline. files: Doc/whatsnew/3.4.rst | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1314,8 +1314,9 @@ * ``PyLoader`` and ``PyPycLoader`` have been removed from :mod:`importlib`. (Contributed by Taras Lyapun in :issue:`15641`.) -* The *strict* argument to :class:`~http.client.HTTPConnection` has been - removed. HTTP 0.9-style "Simple Responses" are no longer supported. +* The *strict* argument to :class:`~http.client.HTTPConnection` and + :class:`~http.client.HTTPSConnection` has been removed. HTTP 0.9-style + "Simple Responses" are no longer supported. Porting to Python 3.4 @@ -1383,6 +1384,12 @@ ``-m`` with the interpreter (this does not influence when the path to a file is specified on the command-line). +* The removal of the *strict* argument to :class:`~http.client.HTTPConnection` + and :class:`~http.client.HTTPSConnection` changes the meaning of the + remaining arguments if you are specifying them positionally rather than by + keyword. If you've been paying attention to deprecation warnings your code + should already be specifying any additional arguments via keywords. + Changes in the C API -------------------- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 21:37:15 2014 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 3 Jan 2014 21:37:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319526=3A_Exclude_?= =?utf-8?q?all_new_API_from_the_stable_ABI=2E?= Message-ID: <3dwybH4bS2z7Lk1@mail.python.org> http://hg.python.org/cpython/rev/15bad3abfac9 changeset: 88282:15bad3abfac9 user: Martin v. L?wis date: Fri Jan 03 21:36:49 2014 +0100 summary: Issue #19526: Exclude all new API from the stable ABI. files: Include/abstract.h | 2 +- Include/codecs.h | 2 +- Include/dictobject.h | 2 ++ Include/fileutils.h | 4 ++++ Include/object.h | 2 ++ Include/pyerrors.h | 6 ++++++ Include/pyhash.h | 2 ++ Include/pymem.h | 4 ++++ Include/pystate.h | 2 ++ Include/pythonrun.h | 2 ++ Include/sysmodule.h | 2 ++ Include/unicodeobject.h | 2 ++ Include/warnings.h | 4 ++++ Misc/NEWS | 3 +++ 14 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Include/abstract.h b/Include/abstract.h --- a/Include/abstract.h +++ b/Include/abstract.h @@ -409,8 +409,8 @@ #ifndef Py_LIMITED_API PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o); + PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t); #endif -PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t); /* Guess the size of object o using len(o) or o.__length_hint__(). diff --git a/Include/codecs.h b/Include/codecs.h --- a/Include/codecs.h +++ b/Include/codecs.h @@ -94,7 +94,7 @@ const char *errors ); -#ifndef PY_LIMITED_API +#ifndef Py_LIMITED_API /* Text codec specific encoding and decoding API. Checks the encoding against a list of codecs which do not diff --git a/Include/dictobject.h b/Include/dictobject.h --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -53,8 +53,10 @@ PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); 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 PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); diff --git a/Include/fileutils.h b/Include/fileutils.h --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -27,9 +27,11 @@ struct stat *statbuf); #endif +#ifndef Py_LIMITED_API PyAPI_FUNC(int) _Py_open( const char *pathname, int flags); +#endif PyAPI_FUNC(FILE *) _Py_wfopen( const wchar_t *path, @@ -61,12 +63,14 @@ 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, int *atomic_flag_works); PyAPI_FUNC(int) _Py_dup(int fd); +#endif #ifdef __cplusplus } diff --git a/Include/object.h b/Include/object.h --- a/Include/object.h +++ b/Include/object.h @@ -533,8 +533,10 @@ PyAPI_FUNC(int) PyCallable_Check(PyObject *); PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *); +#ifndef Py_LIMITED_API PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *); PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *); +#endif /* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes dict as the last parameter. */ diff --git a/Include/pyerrors.h b/Include/pyerrors.h --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -75,7 +75,9 @@ PyAPI_FUNC(void) PyErr_SetNone(PyObject *); PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *); +#ifndef Py_LIMITED_API PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); +#endif PyAPI_FUNC(void) PyErr_SetString( PyObject *exception, const char *string /* decoded from utf-8 */ @@ -321,16 +323,20 @@ const char *filename, /* decoded from the filesystem encoding */ int lineno, int col_offset); +#ifndef Py_LIMITED_API PyAPI_FUNC(void) PyErr_SyntaxLocationObject( PyObject *filename, int lineno, int col_offset); +#endif PyAPI_FUNC(PyObject *) PyErr_ProgramText( const char *filename, /* decoded from the filesystem encoding */ int lineno); +#ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( PyObject *filename, int lineno); +#endif /* The following functions are used to create and modify unicode exceptions from C */ diff --git a/Include/pyhash.h b/Include/pyhash.h --- a/Include/pyhash.h +++ b/Include/pyhash.h @@ -50,6 +50,7 @@ * (*) The siphash member may not be available on 32 bit platforms without * an unsigned int64 data type. */ +#ifndef Py_LIMITED_API typedef union { /* ensure 24 bytes */ unsigned char uc[24]; @@ -76,6 +77,7 @@ } expat; } _Py_HashSecret_t; PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret; +#endif #ifdef Py_DEBUG PyAPI_DATA(int) _Py_HashSecret_Initialized; diff --git a/Include/pymem.h b/Include/pymem.h --- a/Include/pymem.h +++ b/Include/pymem.h @@ -11,9 +11,11 @@ extern "C" { #endif +#ifndef Py_LIMITED_API PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size); PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size); PyAPI_FUNC(void) PyMem_RawFree(void *ptr); +#endif /* BEWARE: @@ -58,8 +60,10 @@ PyAPI_FUNC(void *) PyMem_Realloc(void *ptr, size_t new_size); PyAPI_FUNC(void) PyMem_Free(void *ptr); +#ifndef Py_LIMITED_API PyAPI_FUNC(char *) _PyMem_RawStrdup(const char *str); PyAPI_FUNC(char *) _PyMem_Strdup(const char *str); +#endif /* Macros. */ diff --git a/Include/pystate.h b/Include/pystate.h --- a/Include/pystate.h +++ b/Include/pystate.h @@ -236,7 +236,9 @@ /* Helper/diagnostic function - return 1 if the current thread * currently holds the GIL, 0 otherwise */ +#ifndef Py_LIMITED_API PyAPI_FUNC(int) PyGILState_Check(void); +#endif #endif /* #ifdef WITH_THREAD */ diff --git a/Include/pythonrun.h b/Include/pythonrun.h --- a/Include/pythonrun.h +++ b/Include/pythonrun.h @@ -155,10 +155,12 @@ const char *str, const char *filename, /* decoded from the filesystem encoding */ int start); +#ifndef Py_LIMITED_API PyAPI_FUNC(struct symtable *) Py_SymtableStringObject( const char *str, PyObject *filename, int start); +#endif PyAPI_FUNC(void) PyErr_Print(void); PyAPI_FUNC(void) PyErr_PrintEx(int); diff --git a/Include/sysmodule.h b/Include/sysmodule.h --- a/Include/sysmodule.h +++ b/Include/sysmodule.h @@ -8,7 +8,9 @@ #endif PyAPI_FUNC(PyObject *) PySys_GetObject(const char *); +#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 *); diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -2004,10 +2004,12 @@ PyObject *right /* Right string */ ); +#ifndef Py_LIMITED_API PyAPI_FUNC(int) _PyUnicode_CompareWithId( PyObject *left, /* Left string */ _Py_Identifier *right /* Right identifier */ ); +#endif PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString( PyObject *left, diff --git a/Include/warnings.h b/Include/warnings.h --- a/Include/warnings.h +++ b/Include/warnings.h @@ -17,6 +17,7 @@ Py_ssize_t stack_level, const char *format, /* ASCII-encoded string */ ...); +#ifndef Py_LIMITED_API PyAPI_FUNC(int) PyErr_WarnExplicitObject( PyObject *category, PyObject *message, @@ -24,6 +25,7 @@ int lineno, PyObject *module, PyObject *registry); +#endif PyAPI_FUNC(int) PyErr_WarnExplicit( PyObject *category, const char *message, /* UTF-8 encoded string */ @@ -32,11 +34,13 @@ const char *module, /* UTF-8 encoded string */ PyObject *registry); +#ifndef Py_LIMITED_API PyAPI_FUNC(int) PyErr_WarnExplicitFormat(PyObject *category, const char *filename, int lineno, const char *module, PyObject *registry, const char *format, ...); +#endif /* DEPRECATED: Use PyErr_WarnEx() instead. */ #ifndef Py_LIMITED_API diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #19526: Exclude all new API from the stable ABI. Exceptions can be + made if a need is demonstrated. + - Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if "%c" argument is not in range [0; 255]. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 21:53:50 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 21:53:50 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_unittest_disco?= =?utf-8?q?very_sorting=2C_urlllib_Request_getter/setter_removals=2E?= Message-ID: <3dwyyQ5SwBz7Lk1@mail.python.org> http://hg.python.org/cpython/rev/4799400c09aa changeset: 88283:4799400c09aa user: R David Murray date: Fri Jan 03 15:46:24 2014 -0500 summary: whatsnew: unittest discovery sorting, urlllib Request getter/setter removals. files: Doc/whatsnew/3.4.rst | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1019,6 +1019,10 @@ module level in the test file), it is now reported as a skip instead of an error. (Contributed by Zach Ware in :issue:`16935`.) +:meth:`~unittest.TestLoader.discover` now sorts the discovered files to provide +consistent test ordering. (Contributed by Martin Melin and Jeff Ramnani in +:issue:`16709`.) + venv ---- @@ -1318,6 +1322,11 @@ :class:`~http.client.HTTPSConnection` has been removed. HTTP 0.9-style "Simple Responses" are no longer supported. +* The deprecated :mod:`urllib.request.Request` getter and setter methods + ``add_data``, ``has_data``, ``get_data``, ``get_type``, ``get_host``, + ``get_selector``, ``set_proxy``, ``get_origin_req_host``, and + ``is_unverifiable`` have been removed (use direct attribute access instead). + Porting to Python 3.4 ===================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 21:53:52 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 21:53:52 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_make_bullet_li?= =?utf-8?q?st_presentation_style_consistent=2E?= Message-ID: <3dwyyS0Gsyz7Lk1@mail.python.org> http://hg.python.org/cpython/rev/ae69ebd41807 changeset: 88284:ae69ebd41807 user: R David Murray date: Fri Jan 03 15:52:22 2014 -0500 summary: whatsnew: make bullet list presentation style consistent. files: Doc/whatsnew/3.4.rst | 39 ++++++++++++++++++------------- 1 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1213,24 +1213,20 @@ probe now checks a series of consecutive, adjacent key/hash pairs before continuing to make random probes through the hash table. This exploits cache locality to make collision resolution less expensive. - The collision resolution scheme can be described as a hybrid of linear probing and open addressing. The number of additional linear probes defaults to nine. This can be changed at compile-time by defining LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off - linear probing entirely. - - (Contributed by Raymond Hettinger in :issue:`18771`.) + linear probing entirely. (Contributed by Raymond Hettinger in + :issue:`18771`.) * The interpreter starts about 30% faster. A couple of measures lead to the speedup. The interpreter loads fewer modules on startup, e.g. the :mod:`re`, :mod:`collections` and :mod:`locale` modules and their dependencies are no longer imported by default. The marshal module has been improved to load - compiled Python code faster. - - (Contributed by Antoine Pitrou, Christian Heimes and Victor Stinner in - :issue:`19219`, :issue:`19218`, :issue:`19209`, :issue:`19205` and - :issue:`9548`) + compiled Python code faster. (Contributed by Antoine Pitrou, Christian + Heimes and Victor Stinner in :issue:`19219`, :issue:`19218`, :issue:`19209`, + :issue:`19205` and :issue:`9548`) * :class:`bz2.BZ2File` is now as fast or faster than the Python2 version for most cases. :class:`lzma.LZMAFile` has also been optimized. (Contributed by @@ -1292,18 +1288,27 @@ exists, is deprecated (:issue:`19375`). + Removed ======= + +Operating Systems No Longer Supported +------------------------------------- + +Support for the following operating systems has been removed from the source +and build tools: + +* OS/2 (:issue:`16135`). +* Windows 2000 (changeset e52df05b496a). +* VMS (:issue:`16136`). + + +API and Feature Removals +------------------------ + The following obsolete and previously deprecated APIs and features have been -removed in Python 3.4: - -* Support for the following operating systems has been removed from the source - and build tools: - - * OS/2 (:issue:`16135`). - * Windows 2000 (changeset e52df05b496a). - * VMS (:issue:`16136`). +removed: * The unmaintained ``Misc/TextMate`` and ``Misc/vim`` directories have been removed (see the `devguide `_ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 23:27:33 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 23:27:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_consistently_u?= =?utf-8?q?se_3_blanks_between_major_sections=2E_2_for_minor=2E?= Message-ID: <3dx12Y0hR4z7Llh@mail.python.org> http://hg.python.org/cpython/rev/48bd7ec44bbc changeset: 88285:48bd7ec44bbc user: R David Murray date: Fri Jan 03 16:15:45 2014 -0500 summary: whatsnew: consistently use 3 blanks between major sections. 2 for minor. files: Doc/whatsnew/3.4.rst | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -78,6 +78,7 @@ :pep:`429` -- Python 3.4 Release Schedule + Summary -- Release Highlights ============================= @@ -149,6 +150,7 @@ porting issues. + New Expected Features for Python Implementations ================================================ @@ -341,6 +343,7 @@ :issue:`12892`. + New Modules =========== @@ -469,6 +472,7 @@ PEP written and implemented by Victor Stinner + Improved Modules ================ @@ -486,7 +490,6 @@ (Contributed by Bruno Dupuis in :issue:`16049`.) - aifc ---- @@ -1078,6 +1081,7 @@ (Contributed by Christian Tismer in :issue:`19274`.) + CPython Implementation Changes ============================== @@ -1176,6 +1180,7 @@ interpreter is not available (for example, in cross compilation scenarios). + Other Improvements ================== @@ -1204,6 +1209,7 @@ :issue:`13390`). + Significant Optimizations ========================= @@ -1236,6 +1242,7 @@ common use case). (Contributed by Serhiy Storchaka in :issue:`16674`). + Deprecated ========== @@ -1333,6 +1340,7 @@ ``is_unverifiable`` have been removed (use direct attribute access instead). + Porting to Python 3.4 ===================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Jan 3 23:27:34 2014 From: python-checkins at python.org (r.david.murray) Date: Fri, 3 Jan 2014 23:27:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2MDM5LyMyMDEx?= =?utf-8?q?8=3A_temporarily_skip_failing_imaplib_SSL_test=2E?= Message-ID: <3dx12Z2P2zz7Llh@mail.python.org> http://hg.python.org/cpython/rev/d7ae948d9eee changeset: 88286:d7ae948d9eee branch: 2.7 parent: 88280:dd906f4ab923 user: R David Murray date: Fri Jan 03 17:26:21 2014 -0500 summary: #16039/#20118: temporarily skip failing imaplib SSL test. The fix the test is testing prevents a DOS attack, and the failure mode will also prevent the DOS attack, so for now skip the test. Either the test or the code does need fixing, however. files: Lib/test/test_imaplib.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -187,6 +187,9 @@ server_class = SecureTCPServer imap_class = IMAP4_SSL + def test_linetoolong(self): + raise unittest.SkipTest("test is not reliable on 2.7; see issue 20118") + class RemoteIMAPTest(unittest.TestCase): host = 'cyrus.andrew.cmu.edu' -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sat Jan 4 09:45:07 2014 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 04 Jan 2014 09:45:07 +0100 Subject: [Python-checkins] Daily reference leaks (48bd7ec44bbc): sum=3 Message-ID: results for 48bd7ec44bbc on branch "default" -------------------------------------------- test_audioop leaked [1, 1, 1] references, sum=3 test_site leaked [0, 2, -2] references, sum=0 test_site leaked [0, 2, -2] memory blocks, sum=0 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogMqNuQa', '-x'] From python-checkins at python.org Sat Jan 4 10:06:42 2014 From: python-checkins at python.org (martin.v.loewis) Date: Sat, 4 Jan 2014 10:06:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE3NDMy?= =?utf-8?q?=3A_Drop_UCS2_from_names_of_Unicode_functions_in_python3=2Edef?= =?utf-8?q?=2E?= Message-ID: <3dxHD2452qz7Ljk@mail.python.org> http://hg.python.org/cpython/rev/ea0aa3e32ab5 changeset: 88287:ea0aa3e32ab5 branch: 3.3 parent: 88263:203ca77ea819 user: Martin v. L?wis date: Sat Jan 04 10:01:42 2014 +0100 summary: Issue #17432: Drop UCS2 from names of Unicode functions in python3.def. files: Misc/NEWS | 2 + PC/python3.def | 124 ++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 62 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #17432: Drop UCS2 from names of Unicode functions in python3.def. + - Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if "%c" argument is not in range [0; 255]. diff --git a/PC/python3.def b/PC/python3.def --- a/PC/python3.def +++ b/PC/python3.def @@ -547,68 +547,68 @@ PyUnicodeTranslateError_SetEnd=python33.PyUnicodeTranslateError_SetEnd PyUnicodeTranslateError_SetReason=python33.PyUnicodeTranslateError_SetReason PyUnicodeTranslateError_SetStart=python33.PyUnicodeTranslateError_SetStart - PyUnicode_Append=python33.PyUnicodeUCS2_Append - PyUnicode_AppendAndDel=python33.PyUnicodeUCS2_AppendAndDel - PyUnicode_AsASCIIString=python33.PyUnicodeUCS2_AsASCIIString - PyUnicode_AsCharmapString=python33.PyUnicodeUCS2_AsCharmapString - PyUnicode_AsDecodedObject=python33.PyUnicodeUCS2_AsDecodedObject - PyUnicode_AsDecodedUnicode=python33.PyUnicodeUCS2_AsDecodedUnicode - PyUnicode_AsEncodedObject=python33.PyUnicodeUCS2_AsEncodedObject - PyUnicode_AsEncodedString=python33.PyUnicodeUCS2_AsEncodedString - PyUnicode_AsEncodedUnicode=python33.PyUnicodeUCS2_AsEncodedUnicode - PyUnicode_AsLatin1String=python33.PyUnicodeUCS2_AsLatin1String - PyUnicode_AsRawUnicodeEscapeString=python33.PyUnicodeUCS2_AsRawUnicodeEscapeString - PyUnicode_AsUTF16String=python33.PyUnicodeUCS2_AsUTF16String - PyUnicode_AsUTF32String=python33.PyUnicodeUCS2_AsUTF32String - PyUnicode_AsUTF8String=python33.PyUnicodeUCS2_AsUTF8String - PyUnicode_AsUnicodeEscapeString=python33.PyUnicodeUCS2_AsUnicodeEscapeString - PyUnicode_AsWideChar=python33.PyUnicodeUCS2_AsWideChar - PyUnicode_ClearFreelist=python33.PyUnicodeUCS2_ClearFreelist - PyUnicode_Compare=python33.PyUnicodeUCS2_Compare - PyUnicode_Concat=python33.PyUnicodeUCS2_Concat - PyUnicode_Contains=python33.PyUnicodeUCS2_Contains - PyUnicode_Count=python33.PyUnicodeUCS2_Count - PyUnicode_Decode=python33.PyUnicodeUCS2_Decode - PyUnicode_DecodeASCII=python33.PyUnicodeUCS2_DecodeASCII - PyUnicode_DecodeCharmap=python33.PyUnicodeUCS2_DecodeCharmap - PyUnicode_DecodeFSDefault=python33.PyUnicodeUCS2_DecodeFSDefault - PyUnicode_DecodeFSDefaultAndSize=python33.PyUnicodeUCS2_DecodeFSDefaultAndSize - PyUnicode_DecodeLatin1=python33.PyUnicodeUCS2_DecodeLatin1 - PyUnicode_DecodeRawUnicodeEscape=python33.PyUnicodeUCS2_DecodeRawUnicodeEscape - PyUnicode_DecodeUTF16=python33.PyUnicodeUCS2_DecodeUTF16 - PyUnicode_DecodeUTF16Stateful=python33.PyUnicodeUCS2_DecodeUTF16Stateful - PyUnicode_DecodeUTF32=python33.PyUnicodeUCS2_DecodeUTF32 - PyUnicode_DecodeUTF32Stateful=python33.PyUnicodeUCS2_DecodeUTF32Stateful - PyUnicode_DecodeUTF8=python33.PyUnicodeUCS2_DecodeUTF8 - PyUnicode_DecodeUTF8Stateful=python33.PyUnicodeUCS2_DecodeUTF8Stateful - PyUnicode_DecodeUnicodeEscape=python33.PyUnicodeUCS2_DecodeUnicodeEscape - PyUnicode_FSConverter=python33.PyUnicodeUCS2_FSConverter - PyUnicode_FSDecoder=python33.PyUnicodeUCS2_FSDecoder - PyUnicode_Find=python33.PyUnicodeUCS2_Find - PyUnicode_Format=python33.PyUnicodeUCS2_Format - PyUnicode_FromEncodedObject=python33.PyUnicodeUCS2_FromEncodedObject - PyUnicode_FromFormat=python33.PyUnicodeUCS2_FromFormat - PyUnicode_FromFormatV=python33.PyUnicodeUCS2_FromFormatV - PyUnicode_FromObject=python33.PyUnicodeUCS2_FromObject - PyUnicode_FromOrdinal=python33.PyUnicodeUCS2_FromOrdinal - PyUnicode_FromString=python33.PyUnicodeUCS2_FromString - PyUnicode_FromStringAndSize=python33.PyUnicodeUCS2_FromStringAndSize - PyUnicode_FromWideChar=python33.PyUnicodeUCS2_FromWideChar - PyUnicode_GetDefaultEncoding=python33.PyUnicodeUCS2_GetDefaultEncoding - PyUnicode_GetSize=python33.PyUnicodeUCS2_GetSize - PyUnicode_IsIdentifier=python33.PyUnicodeUCS2_IsIdentifier - PyUnicode_Join=python33.PyUnicodeUCS2_Join - PyUnicode_Partition=python33.PyUnicodeUCS2_Partition - PyUnicode_RPartition=python33.PyUnicodeUCS2_RPartition - PyUnicode_RSplit=python33.PyUnicodeUCS2_RSplit - PyUnicode_Replace=python33.PyUnicodeUCS2_Replace - PyUnicode_Resize=python33.PyUnicodeUCS2_Resize - PyUnicode_RichCompare=python33.PyUnicodeUCS2_RichCompare - PyUnicode_SetDefaultEncoding=python33.PyUnicodeUCS2_SetDefaultEncoding - PyUnicode_Split=python33.PyUnicodeUCS2_Split - PyUnicode_Splitlines=python33.PyUnicodeUCS2_Splitlines - PyUnicode_Tailmatch=python33.PyUnicodeUCS2_Tailmatch - PyUnicode_Translate=python33.PyUnicodeUCS2_Translate + PyUnicode_Append=python33.PyUnicode_Append + PyUnicode_AppendAndDel=python33.PyUnicode_AppendAndDel + PyUnicode_AsASCIIString=python33.PyUnicode_AsASCIIString + PyUnicode_AsCharmapString=python33.PyUnicode_AsCharmapString + PyUnicode_AsDecodedObject=python33.PyUnicode_AsDecodedObject + PyUnicode_AsDecodedUnicode=python33.PyUnicode_AsDecodedUnicode + PyUnicode_AsEncodedObject=python33.PyUnicode_AsEncodedObject + PyUnicode_AsEncodedString=python33.PyUnicode_AsEncodedString + PyUnicode_AsEncodedUnicode=python33.PyUnicode_AsEncodedUnicode + PyUnicode_AsLatin1String=python33.PyUnicode_AsLatin1String + PyUnicode_AsRawUnicodeEscapeString=python33.PyUnicode_AsRawUnicodeEscapeString + PyUnicode_AsUTF16String=python33.PyUnicode_AsUTF16String + PyUnicode_AsUTF32String=python33.PyUnicode_AsUTF32String + PyUnicode_AsUTF8String=python33.PyUnicode_AsUTF8String + PyUnicode_AsUnicodeEscapeString=python33.PyUnicode_AsUnicodeEscapeString + PyUnicode_AsWideChar=python33.PyUnicode_AsWideChar + PyUnicode_ClearFreelist=python33.PyUnicode_ClearFreelist + PyUnicode_Compare=python33.PyUnicode_Compare + PyUnicode_Concat=python33.PyUnicode_Concat + PyUnicode_Contains=python33.PyUnicode_Contains + PyUnicode_Count=python33.PyUnicode_Count + PyUnicode_Decode=python33.PyUnicode_Decode + PyUnicode_DecodeASCII=python33.PyUnicode_DecodeASCII + PyUnicode_DecodeCharmap=python33.PyUnicode_DecodeCharmap + PyUnicode_DecodeFSDefault=python33.PyUnicode_DecodeFSDefault + PyUnicode_DecodeFSDefaultAndSize=python33.PyUnicode_DecodeFSDefaultAndSize + PyUnicode_DecodeLatin1=python33.PyUnicode_DecodeLatin1 + PyUnicode_DecodeRawUnicodeEscape=python33.PyUnicode_DecodeRawUnicodeEscape + PyUnicode_DecodeUTF16=python33.PyUnicode_DecodeUTF16 + PyUnicode_DecodeUTF16Stateful=python33.PyUnicode_DecodeUTF16Stateful + PyUnicode_DecodeUTF32=python33.PyUnicode_DecodeUTF32 + PyUnicode_DecodeUTF32Stateful=python33.PyUnicode_DecodeUTF32Stateful + PyUnicode_DecodeUTF8=python33.PyUnicode_DecodeUTF8 + PyUnicode_DecodeUTF8Stateful=python33.PyUnicode_DecodeUTF8Stateful + PyUnicode_DecodeUnicodeEscape=python33.PyUnicode_DecodeUnicodeEscape + PyUnicode_FSConverter=python33.PyUnicode_FSConverter + PyUnicode_FSDecoder=python33.PyUnicode_FSDecoder + PyUnicode_Find=python33.PyUnicode_Find + PyUnicode_Format=python33.PyUnicode_Format + PyUnicode_FromEncodedObject=python33.PyUnicode_FromEncodedObject + PyUnicode_FromFormat=python33.PyUnicode_FromFormat + PyUnicode_FromFormatV=python33.PyUnicode_FromFormatV + PyUnicode_FromObject=python33.PyUnicode_FromObject + PyUnicode_FromOrdinal=python33.PyUnicode_FromOrdinal + PyUnicode_FromString=python33.PyUnicode_FromString + PyUnicode_FromStringAndSize=python33.PyUnicode_FromStringAndSize + PyUnicode_FromWideChar=python33.PyUnicode_FromWideChar + PyUnicode_GetDefaultEncoding=python33.PyUnicode_GetDefaultEncoding + PyUnicode_GetSize=python33.PyUnicode_GetSize + PyUnicode_IsIdentifier=python33.PyUnicode_IsIdentifier + PyUnicode_Join=python33.PyUnicode_Join + PyUnicode_Partition=python33.PyUnicode_Partition + PyUnicode_RPartition=python33.PyUnicode_RPartition + PyUnicode_RSplit=python33.PyUnicode_RSplit + PyUnicode_Replace=python33.PyUnicode_Replace + PyUnicode_Resize=python33.PyUnicode_Resize + PyUnicode_RichCompare=python33.PyUnicode_RichCompare + PyUnicode_SetDefaultEncoding=python33.PyUnicode_SetDefaultEncoding + PyUnicode_Split=python33.PyUnicode_Split + PyUnicode_Splitlines=python33.PyUnicode_Splitlines + PyUnicode_Tailmatch=python33.PyUnicode_Tailmatch + PyUnicode_Translate=python33.PyUnicode_Translate PyUnicode_BuildEncodingMap=python33.PyUnicode_BuildEncodingMap PyUnicode_CompareWithASCIIString=python33.PyUnicode_CompareWithASCIIString PyUnicode_DecodeUTF7=python33.PyUnicode_DecodeUTF7 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 10:06:43 2014 From: python-checkins at python.org (martin.v.loewis) Date: Sat, 4 Jan 2014 10:06:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E3=3A_Issue_=2317432=3A_Drop_UCS2_from_nam?= =?utf-8?q?es_of_Unicode_functions_in?= Message-ID: <3dxHD36rk9z7Lkf@mail.python.org> http://hg.python.org/cpython/rev/0ea09c824d9b changeset: 88288:0ea09c824d9b parent: 88285:48bd7ec44bbc parent: 88287:ea0aa3e32ab5 user: Martin v. L?wis date: Sat Jan 04 10:06:28 2014 +0100 summary: Merge with 3.3: Issue #17432: Drop UCS2 from names of Unicode functions in python3.def. files: Misc/NEWS | 2 + PC/python3.def | 124 ++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 62 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #17432: Drop UCS2 from names of Unicode functions in python3.def. + - Issue #19526: Exclude all new API from the stable ABI. Exceptions can be made if a need is demonstrated. diff --git a/PC/python3.def b/PC/python3.def --- a/PC/python3.def +++ b/PC/python3.def @@ -548,68 +548,68 @@ PyUnicodeTranslateError_SetEnd=python34.PyUnicodeTranslateError_SetEnd PyUnicodeTranslateError_SetReason=python34.PyUnicodeTranslateError_SetReason PyUnicodeTranslateError_SetStart=python34.PyUnicodeTranslateError_SetStart - PyUnicode_Append=python34.PyUnicodeUCS2_Append - PyUnicode_AppendAndDel=python34.PyUnicodeUCS2_AppendAndDel - PyUnicode_AsASCIIString=python34.PyUnicodeUCS2_AsASCIIString - PyUnicode_AsCharmapString=python34.PyUnicodeUCS2_AsCharmapString - PyUnicode_AsDecodedObject=python34.PyUnicodeUCS2_AsDecodedObject - PyUnicode_AsDecodedUnicode=python34.PyUnicodeUCS2_AsDecodedUnicode - PyUnicode_AsEncodedObject=python34.PyUnicodeUCS2_AsEncodedObject - PyUnicode_AsEncodedString=python34.PyUnicodeUCS2_AsEncodedString - PyUnicode_AsEncodedUnicode=python34.PyUnicodeUCS2_AsEncodedUnicode - PyUnicode_AsLatin1String=python34.PyUnicodeUCS2_AsLatin1String - PyUnicode_AsRawUnicodeEscapeString=python34.PyUnicodeUCS2_AsRawUnicodeEscapeString - PyUnicode_AsUTF16String=python34.PyUnicodeUCS2_AsUTF16String - PyUnicode_AsUTF32String=python34.PyUnicodeUCS2_AsUTF32String - PyUnicode_AsUTF8String=python34.PyUnicodeUCS2_AsUTF8String - PyUnicode_AsUnicodeEscapeString=python34.PyUnicodeUCS2_AsUnicodeEscapeString - PyUnicode_AsWideChar=python34.PyUnicodeUCS2_AsWideChar - PyUnicode_ClearFreelist=python34.PyUnicodeUCS2_ClearFreelist - PyUnicode_Compare=python34.PyUnicodeUCS2_Compare - PyUnicode_Concat=python34.PyUnicodeUCS2_Concat - PyUnicode_Contains=python34.PyUnicodeUCS2_Contains - PyUnicode_Count=python34.PyUnicodeUCS2_Count - PyUnicode_Decode=python34.PyUnicodeUCS2_Decode - PyUnicode_DecodeASCII=python34.PyUnicodeUCS2_DecodeASCII - PyUnicode_DecodeCharmap=python34.PyUnicodeUCS2_DecodeCharmap - PyUnicode_DecodeFSDefault=python34.PyUnicodeUCS2_DecodeFSDefault - PyUnicode_DecodeFSDefaultAndSize=python34.PyUnicodeUCS2_DecodeFSDefaultAndSize - PyUnicode_DecodeLatin1=python34.PyUnicodeUCS2_DecodeLatin1 - PyUnicode_DecodeRawUnicodeEscape=python34.PyUnicodeUCS2_DecodeRawUnicodeEscape - PyUnicode_DecodeUTF16=python34.PyUnicodeUCS2_DecodeUTF16 - PyUnicode_DecodeUTF16Stateful=python34.PyUnicodeUCS2_DecodeUTF16Stateful - PyUnicode_DecodeUTF32=python34.PyUnicodeUCS2_DecodeUTF32 - PyUnicode_DecodeUTF32Stateful=python34.PyUnicodeUCS2_DecodeUTF32Stateful - PyUnicode_DecodeUTF8=python34.PyUnicodeUCS2_DecodeUTF8 - PyUnicode_DecodeUTF8Stateful=python34.PyUnicodeUCS2_DecodeUTF8Stateful - PyUnicode_DecodeUnicodeEscape=python34.PyUnicodeUCS2_DecodeUnicodeEscape - PyUnicode_FSConverter=python34.PyUnicodeUCS2_FSConverter - PyUnicode_FSDecoder=python34.PyUnicodeUCS2_FSDecoder - PyUnicode_Find=python34.PyUnicodeUCS2_Find - PyUnicode_Format=python34.PyUnicodeUCS2_Format - PyUnicode_FromEncodedObject=python34.PyUnicodeUCS2_FromEncodedObject - PyUnicode_FromFormat=python34.PyUnicodeUCS2_FromFormat - PyUnicode_FromFormatV=python34.PyUnicodeUCS2_FromFormatV - PyUnicode_FromObject=python34.PyUnicodeUCS2_FromObject - PyUnicode_FromOrdinal=python34.PyUnicodeUCS2_FromOrdinal - PyUnicode_FromString=python34.PyUnicodeUCS2_FromString - PyUnicode_FromStringAndSize=python34.PyUnicodeUCS2_FromStringAndSize - PyUnicode_FromWideChar=python34.PyUnicodeUCS2_FromWideChar - PyUnicode_GetDefaultEncoding=python34.PyUnicodeUCS2_GetDefaultEncoding - PyUnicode_GetSize=python34.PyUnicodeUCS2_GetSize - PyUnicode_IsIdentifier=python34.PyUnicodeUCS2_IsIdentifier - PyUnicode_Join=python34.PyUnicodeUCS2_Join - PyUnicode_Partition=python34.PyUnicodeUCS2_Partition - PyUnicode_RPartition=python34.PyUnicodeUCS2_RPartition - PyUnicode_RSplit=python34.PyUnicodeUCS2_RSplit - PyUnicode_Replace=python34.PyUnicodeUCS2_Replace - PyUnicode_Resize=python34.PyUnicodeUCS2_Resize - PyUnicode_RichCompare=python34.PyUnicodeUCS2_RichCompare - PyUnicode_SetDefaultEncoding=python34.PyUnicodeUCS2_SetDefaultEncoding - PyUnicode_Split=python34.PyUnicodeUCS2_Split - PyUnicode_Splitlines=python34.PyUnicodeUCS2_Splitlines - PyUnicode_Tailmatch=python34.PyUnicodeUCS2_Tailmatch - PyUnicode_Translate=python34.PyUnicodeUCS2_Translate + PyUnicode_Append=python34.PyUnicode_Append + PyUnicode_AppendAndDel=python34.PyUnicode_AppendAndDel + PyUnicode_AsASCIIString=python34.PyUnicode_AsASCIIString + PyUnicode_AsCharmapString=python34.PyUnicode_AsCharmapString + PyUnicode_AsDecodedObject=python34.PyUnicode_AsDecodedObject + PyUnicode_AsDecodedUnicode=python34.PyUnicode_AsDecodedUnicode + PyUnicode_AsEncodedObject=python34.PyUnicode_AsEncodedObject + PyUnicode_AsEncodedString=python34.PyUnicode_AsEncodedString + PyUnicode_AsEncodedUnicode=python34.PyUnicode_AsEncodedUnicode + PyUnicode_AsLatin1String=python34.PyUnicode_AsLatin1String + PyUnicode_AsRawUnicodeEscapeString=python34.PyUnicode_AsRawUnicodeEscapeString + PyUnicode_AsUTF16String=python34.PyUnicode_AsUTF16String + PyUnicode_AsUTF32String=python34.PyUnicode_AsUTF32String + PyUnicode_AsUTF8String=python34.PyUnicode_AsUTF8String + PyUnicode_AsUnicodeEscapeString=python34.PyUnicode_AsUnicodeEscapeString + PyUnicode_AsWideChar=python34.PyUnicode_AsWideChar + PyUnicode_ClearFreelist=python34.PyUnicode_ClearFreelist + PyUnicode_Compare=python34.PyUnicode_Compare + PyUnicode_Concat=python34.PyUnicode_Concat + PyUnicode_Contains=python34.PyUnicode_Contains + PyUnicode_Count=python34.PyUnicode_Count + PyUnicode_Decode=python34.PyUnicode_Decode + PyUnicode_DecodeASCII=python34.PyUnicode_DecodeASCII + PyUnicode_DecodeCharmap=python34.PyUnicode_DecodeCharmap + PyUnicode_DecodeFSDefault=python34.PyUnicode_DecodeFSDefault + PyUnicode_DecodeFSDefaultAndSize=python34.PyUnicode_DecodeFSDefaultAndSize + PyUnicode_DecodeLatin1=python34.PyUnicode_DecodeLatin1 + PyUnicode_DecodeRawUnicodeEscape=python34.PyUnicode_DecodeRawUnicodeEscape + PyUnicode_DecodeUTF16=python34.PyUnicode_DecodeUTF16 + PyUnicode_DecodeUTF16Stateful=python34.PyUnicode_DecodeUTF16Stateful + PyUnicode_DecodeUTF32=python34.PyUnicode_DecodeUTF32 + PyUnicode_DecodeUTF32Stateful=python34.PyUnicode_DecodeUTF32Stateful + PyUnicode_DecodeUTF8=python34.PyUnicode_DecodeUTF8 + PyUnicode_DecodeUTF8Stateful=python34.PyUnicode_DecodeUTF8Stateful + PyUnicode_DecodeUnicodeEscape=python34.PyUnicode_DecodeUnicodeEscape + PyUnicode_FSConverter=python34.PyUnicode_FSConverter + PyUnicode_FSDecoder=python34.PyUnicode_FSDecoder + PyUnicode_Find=python34.PyUnicode_Find + PyUnicode_Format=python34.PyUnicode_Format + PyUnicode_FromEncodedObject=python34.PyUnicode_FromEncodedObject + PyUnicode_FromFormat=python34.PyUnicode_FromFormat + PyUnicode_FromFormatV=python34.PyUnicode_FromFormatV + PyUnicode_FromObject=python34.PyUnicode_FromObject + PyUnicode_FromOrdinal=python34.PyUnicode_FromOrdinal + PyUnicode_FromString=python34.PyUnicode_FromString + PyUnicode_FromStringAndSize=python34.PyUnicode_FromStringAndSize + PyUnicode_FromWideChar=python34.PyUnicode_FromWideChar + PyUnicode_GetDefaultEncoding=python34.PyUnicode_GetDefaultEncoding + PyUnicode_GetSize=python34.PyUnicode_GetSize + PyUnicode_IsIdentifier=python34.PyUnicode_IsIdentifier + PyUnicode_Join=python34.PyUnicode_Join + PyUnicode_Partition=python34.PyUnicode_Partition + PyUnicode_RPartition=python34.PyUnicode_RPartition + PyUnicode_RSplit=python34.PyUnicode_RSplit + PyUnicode_Replace=python34.PyUnicode_Replace + PyUnicode_Resize=python34.PyUnicode_Resize + PyUnicode_RichCompare=python34.PyUnicode_RichCompare + PyUnicode_SetDefaultEncoding=python34.PyUnicode_SetDefaultEncoding + PyUnicode_Split=python34.PyUnicode_Split + PyUnicode_Splitlines=python34.PyUnicode_Splitlines + PyUnicode_Tailmatch=python34.PyUnicode_Tailmatch + PyUnicode_Translate=python34.PyUnicode_Translate PyUnicode_BuildEncodingMap=python34.PyUnicode_BuildEncodingMap PyUnicode_CompareWithASCIIString=python34.PyUnicode_CompareWithASCIIString PyUnicode_DecodeUTF7=python34.PyUnicode_DecodeUTF7 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 11:21:30 2014 From: python-checkins at python.org (martin.v.loewis) Date: Sat, 4 Jan 2014 11:21:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Regenerate_pyt?= =?utf-8?q?hon34stub=2Edef=2E?= Message-ID: <3dxJtL1jy4z7LlX@mail.python.org> http://hg.python.org/cpython/rev/1819fee1c20f changeset: 88289:1819fee1c20f branch: 3.3 parent: 88287:ea0aa3e32ab5 user: Martin v. L?wis date: Sat Jan 04 11:20:45 2014 +0100 summary: Regenerate python34stub.def. files: PC/python33stub.def | 124 ++++++++++++++++---------------- 1 files changed, 62 insertions(+), 62 deletions(-) diff --git a/PC/python33stub.def b/PC/python33stub.def --- a/PC/python33stub.def +++ b/PC/python33stub.def @@ -546,68 +546,68 @@ PyUnicodeTranslateError_SetEnd PyUnicodeTranslateError_SetReason PyUnicodeTranslateError_SetStart -PyUnicodeUCS2_Append -PyUnicodeUCS2_AppendAndDel -PyUnicodeUCS2_AsASCIIString -PyUnicodeUCS2_AsCharmapString -PyUnicodeUCS2_AsDecodedObject -PyUnicodeUCS2_AsDecodedUnicode -PyUnicodeUCS2_AsEncodedObject -PyUnicodeUCS2_AsEncodedString -PyUnicodeUCS2_AsEncodedUnicode -PyUnicodeUCS2_AsLatin1String -PyUnicodeUCS2_AsRawUnicodeEscapeString -PyUnicodeUCS2_AsUTF16String -PyUnicodeUCS2_AsUTF32String -PyUnicodeUCS2_AsUTF8String -PyUnicodeUCS2_AsUnicodeEscapeString -PyUnicodeUCS2_AsWideChar -PyUnicodeUCS2_ClearFreelist -PyUnicodeUCS2_Compare -PyUnicodeUCS2_Concat -PyUnicodeUCS2_Contains -PyUnicodeUCS2_Count -PyUnicodeUCS2_Decode -PyUnicodeUCS2_DecodeASCII -PyUnicodeUCS2_DecodeCharmap -PyUnicodeUCS2_DecodeFSDefault -PyUnicodeUCS2_DecodeFSDefaultAndSize -PyUnicodeUCS2_DecodeLatin1 -PyUnicodeUCS2_DecodeRawUnicodeEscape -PyUnicodeUCS2_DecodeUTF16 -PyUnicodeUCS2_DecodeUTF16Stateful -PyUnicodeUCS2_DecodeUTF32 -PyUnicodeUCS2_DecodeUTF32Stateful -PyUnicodeUCS2_DecodeUTF8 -PyUnicodeUCS2_DecodeUTF8Stateful -PyUnicodeUCS2_DecodeUnicodeEscape -PyUnicodeUCS2_FSConverter -PyUnicodeUCS2_FSDecoder -PyUnicodeUCS2_Find -PyUnicodeUCS2_Format -PyUnicodeUCS2_FromEncodedObject -PyUnicodeUCS2_FromFormat -PyUnicodeUCS2_FromFormatV -PyUnicodeUCS2_FromObject -PyUnicodeUCS2_FromOrdinal -PyUnicodeUCS2_FromString -PyUnicodeUCS2_FromStringAndSize -PyUnicodeUCS2_FromWideChar -PyUnicodeUCS2_GetDefaultEncoding -PyUnicodeUCS2_GetSize -PyUnicodeUCS2_IsIdentifier -PyUnicodeUCS2_Join -PyUnicodeUCS2_Partition -PyUnicodeUCS2_RPartition -PyUnicodeUCS2_RSplit -PyUnicodeUCS2_Replace -PyUnicodeUCS2_Resize -PyUnicodeUCS2_RichCompare -PyUnicodeUCS2_SetDefaultEncoding -PyUnicodeUCS2_Split -PyUnicodeUCS2_Splitlines -PyUnicodeUCS2_Tailmatch -PyUnicodeUCS2_Translate +PyUnicode_Append +PyUnicode_AppendAndDel +PyUnicode_AsASCIIString +PyUnicode_AsCharmapString +PyUnicode_AsDecodedObject +PyUnicode_AsDecodedUnicode +PyUnicode_AsEncodedObject +PyUnicode_AsEncodedString +PyUnicode_AsEncodedUnicode +PyUnicode_AsLatin1String +PyUnicode_AsRawUnicodeEscapeString +PyUnicode_AsUTF16String +PyUnicode_AsUTF32String +PyUnicode_AsUTF8String +PyUnicode_AsUnicodeEscapeString +PyUnicode_AsWideChar +PyUnicode_ClearFreelist +PyUnicode_Compare +PyUnicode_Concat +PyUnicode_Contains +PyUnicode_Count +PyUnicode_Decode +PyUnicode_DecodeASCII +PyUnicode_DecodeCharmap +PyUnicode_DecodeFSDefault +PyUnicode_DecodeFSDefaultAndSize +PyUnicode_DecodeLatin1 +PyUnicode_DecodeRawUnicodeEscape +PyUnicode_DecodeUTF16 +PyUnicode_DecodeUTF16Stateful +PyUnicode_DecodeUTF32 +PyUnicode_DecodeUTF32Stateful +PyUnicode_DecodeUTF8 +PyUnicode_DecodeUTF8Stateful +PyUnicode_DecodeUnicodeEscape +PyUnicode_FSConverter +PyUnicode_FSDecoder +PyUnicode_Find +PyUnicode_Format +PyUnicode_FromEncodedObject +PyUnicode_FromFormat +PyUnicode_FromFormatV +PyUnicode_FromObject +PyUnicode_FromOrdinal +PyUnicode_FromString +PyUnicode_FromStringAndSize +PyUnicode_FromWideChar +PyUnicode_GetDefaultEncoding +PyUnicode_GetSize +PyUnicode_IsIdentifier +PyUnicode_Join +PyUnicode_Partition +PyUnicode_RPartition +PyUnicode_RSplit +PyUnicode_Replace +PyUnicode_Resize +PyUnicode_RichCompare +PyUnicode_SetDefaultEncoding +PyUnicode_Split +PyUnicode_Splitlines +PyUnicode_Tailmatch +PyUnicode_Translate PyUnicode_BuildEncodingMap PyUnicode_CompareWithASCIIString PyUnicode_DecodeUTF7 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 11:21:31 2014 From: python-checkins at python.org (martin.v.loewis) Date: Sat, 4 Jan 2014 11:21:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4z?= Message-ID: <3dxJtM4Ygsz7Lkx@mail.python.org> http://hg.python.org/cpython/rev/7ce112a25402 changeset: 88290:7ce112a25402 parent: 88288:0ea09c824d9b parent: 88289:1819fee1c20f user: Martin v. L?wis date: Sat Jan 04 11:21:15 2014 +0100 summary: Merge 3.3 files: PC/python34stub.def | 124 ++++++++++++++++---------------- 1 files changed, 62 insertions(+), 62 deletions(-) diff --git a/PC/python34stub.def b/PC/python34stub.def --- a/PC/python34stub.def +++ b/PC/python34stub.def @@ -547,68 +547,68 @@ PyUnicodeTranslateError_SetEnd PyUnicodeTranslateError_SetReason PyUnicodeTranslateError_SetStart -PyUnicodeUCS2_Append -PyUnicodeUCS2_AppendAndDel -PyUnicodeUCS2_AsASCIIString -PyUnicodeUCS2_AsCharmapString -PyUnicodeUCS2_AsDecodedObject -PyUnicodeUCS2_AsDecodedUnicode -PyUnicodeUCS2_AsEncodedObject -PyUnicodeUCS2_AsEncodedString -PyUnicodeUCS2_AsEncodedUnicode -PyUnicodeUCS2_AsLatin1String -PyUnicodeUCS2_AsRawUnicodeEscapeString -PyUnicodeUCS2_AsUTF16String -PyUnicodeUCS2_AsUTF32String -PyUnicodeUCS2_AsUTF8String -PyUnicodeUCS2_AsUnicodeEscapeString -PyUnicodeUCS2_AsWideChar -PyUnicodeUCS2_ClearFreelist -PyUnicodeUCS2_Compare -PyUnicodeUCS2_Concat -PyUnicodeUCS2_Contains -PyUnicodeUCS2_Count -PyUnicodeUCS2_Decode -PyUnicodeUCS2_DecodeASCII -PyUnicodeUCS2_DecodeCharmap -PyUnicodeUCS2_DecodeFSDefault -PyUnicodeUCS2_DecodeFSDefaultAndSize -PyUnicodeUCS2_DecodeLatin1 -PyUnicodeUCS2_DecodeRawUnicodeEscape -PyUnicodeUCS2_DecodeUTF16 -PyUnicodeUCS2_DecodeUTF16Stateful -PyUnicodeUCS2_DecodeUTF32 -PyUnicodeUCS2_DecodeUTF32Stateful -PyUnicodeUCS2_DecodeUTF8 -PyUnicodeUCS2_DecodeUTF8Stateful -PyUnicodeUCS2_DecodeUnicodeEscape -PyUnicodeUCS2_FSConverter -PyUnicodeUCS2_FSDecoder -PyUnicodeUCS2_Find -PyUnicodeUCS2_Format -PyUnicodeUCS2_FromEncodedObject -PyUnicodeUCS2_FromFormat -PyUnicodeUCS2_FromFormatV -PyUnicodeUCS2_FromObject -PyUnicodeUCS2_FromOrdinal -PyUnicodeUCS2_FromString -PyUnicodeUCS2_FromStringAndSize -PyUnicodeUCS2_FromWideChar -PyUnicodeUCS2_GetDefaultEncoding -PyUnicodeUCS2_GetSize -PyUnicodeUCS2_IsIdentifier -PyUnicodeUCS2_Join -PyUnicodeUCS2_Partition -PyUnicodeUCS2_RPartition -PyUnicodeUCS2_RSplit -PyUnicodeUCS2_Replace -PyUnicodeUCS2_Resize -PyUnicodeUCS2_RichCompare -PyUnicodeUCS2_SetDefaultEncoding -PyUnicodeUCS2_Split -PyUnicodeUCS2_Splitlines -PyUnicodeUCS2_Tailmatch -PyUnicodeUCS2_Translate +PyUnicode_Append +PyUnicode_AppendAndDel +PyUnicode_AsASCIIString +PyUnicode_AsCharmapString +PyUnicode_AsDecodedObject +PyUnicode_AsDecodedUnicode +PyUnicode_AsEncodedObject +PyUnicode_AsEncodedString +PyUnicode_AsEncodedUnicode +PyUnicode_AsLatin1String +PyUnicode_AsRawUnicodeEscapeString +PyUnicode_AsUTF16String +PyUnicode_AsUTF32String +PyUnicode_AsUTF8String +PyUnicode_AsUnicodeEscapeString +PyUnicode_AsWideChar +PyUnicode_ClearFreelist +PyUnicode_Compare +PyUnicode_Concat +PyUnicode_Contains +PyUnicode_Count +PyUnicode_Decode +PyUnicode_DecodeASCII +PyUnicode_DecodeCharmap +PyUnicode_DecodeFSDefault +PyUnicode_DecodeFSDefaultAndSize +PyUnicode_DecodeLatin1 +PyUnicode_DecodeRawUnicodeEscape +PyUnicode_DecodeUTF16 +PyUnicode_DecodeUTF16Stateful +PyUnicode_DecodeUTF32 +PyUnicode_DecodeUTF32Stateful +PyUnicode_DecodeUTF8 +PyUnicode_DecodeUTF8Stateful +PyUnicode_DecodeUnicodeEscape +PyUnicode_FSConverter +PyUnicode_FSDecoder +PyUnicode_Find +PyUnicode_Format +PyUnicode_FromEncodedObject +PyUnicode_FromFormat +PyUnicode_FromFormatV +PyUnicode_FromObject +PyUnicode_FromOrdinal +PyUnicode_FromString +PyUnicode_FromStringAndSize +PyUnicode_FromWideChar +PyUnicode_GetDefaultEncoding +PyUnicode_GetSize +PyUnicode_IsIdentifier +PyUnicode_Join +PyUnicode_Partition +PyUnicode_RPartition +PyUnicode_RSplit +PyUnicode_Replace +PyUnicode_Resize +PyUnicode_RichCompare +PyUnicode_SetDefaultEncoding +PyUnicode_Split +PyUnicode_Splitlines +PyUnicode_Tailmatch +PyUnicode_Translate PyUnicode_BuildEncodingMap PyUnicode_CompareWithASCIIString PyUnicode_DecodeUTF7 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 11:26:04 2014 From: python-checkins at python.org (martin.v.loewis) Date: Sat, 4 Jan 2014 11:26:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Drop_reference_to_pythonco?= =?utf-8?q?re=2C_to_avoid_linking_python34=2Edll?= Message-ID: <3dxJzc406Wz7LjZ@mail.python.org> http://hg.python.org/cpython/rev/e36018357fd1 changeset: 88291:e36018357fd1 user: Martin v. L?wis date: Sat Jan 04 11:25:35 2014 +0100 summary: Drop reference to pythoncore, to avoid linking python34.dll files: PCbuild/xxlimited.vcxproj | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-) diff --git a/PCbuild/xxlimited.vcxproj b/PCbuild/xxlimited.vcxproj --- a/PCbuild/xxlimited.vcxproj +++ b/PCbuild/xxlimited.vcxproj @@ -183,11 +183,6 @@ - - - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - - -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 13:07:39 2014 From: python-checkins at python.org (stefan.krah) Date: Sat, 4 Jan 2014 13:07:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Whitespace=2E?= Message-ID: <3dxMDq0pljz7LjZ@mail.python.org> http://hg.python.org/cpython/rev/28337a8fb502 changeset: 88292:28337a8fb502 branch: 3.3 parent: 88289:1819fee1c20f user: Stefan Krah date: Sat Jan 04 13:03:48 2014 +0100 summary: Whitespace. files: Modules/_decimal/libmpdec/mpdecimal.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -406,7 +406,7 @@ mpd_ssize_t mpd_to_eng_size(char **res, const mpd_t *dec, int fmt); int mpd_validate_lconv(mpd_spec_t *spec); int mpd_parse_fmt_str(mpd_spec_t *spec, const char *fmt, int caps); -char * mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, const mpd_context_t *ctx, uint32_t *status); +char *mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, const mpd_context_t *ctx, uint32_t *status); char *mpd_qformat(const mpd_t *dec, const char *fmt, const mpd_context_t *ctx, uint32_t *status); #define MPD_NUM_FLAGS 15 @@ -465,7 +465,7 @@ int mpd_qcheck_nans(mpd_t *nanresult, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status); void mpd_qfinalize(mpd_t *result, const mpd_context_t *ctx, uint32_t *status); -const char * mpd_class(const mpd_t *a, const mpd_context_t *ctx); +const char *mpd_class(const mpd_t *a, const mpd_context_t *ctx); int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status); mpd_t *mpd_qncopy(const mpd_t *a); @@ -579,7 +579,7 @@ /* Signalling functions */ /******************************************************************************/ -char * mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx); +char *mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx); void mpd_import_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx); void mpd_import_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx); size_t mpd_export_u16(uint16_t **rdata, size_t rlen, uint32_t base, const mpd_t *src, mpd_context_t *ctx); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 13:07:40 2014 From: python-checkins at python.org (stefan.krah) Date: Sat, 4 Jan 2014 13:07:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgZnJvbSAzLjMu?= Message-ID: <3dxMDr2fKfz7LjZ@mail.python.org> http://hg.python.org/cpython/rev/1f02dc050855 changeset: 88293:1f02dc050855 parent: 88291:e36018357fd1 parent: 88292:28337a8fb502 user: Stefan Krah date: Sat Jan 04 13:06:59 2014 +0100 summary: Merge from 3.3. files: Modules/_decimal/libmpdec/mpdecimal.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -406,7 +406,7 @@ mpd_ssize_t mpd_to_eng_size(char **res, const mpd_t *dec, int fmt); int mpd_validate_lconv(mpd_spec_t *spec); int mpd_parse_fmt_str(mpd_spec_t *spec, const char *fmt, int caps); -char * mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, const mpd_context_t *ctx, uint32_t *status); +char *mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, const mpd_context_t *ctx, uint32_t *status); char *mpd_qformat(const mpd_t *dec, const char *fmt, const mpd_context_t *ctx, uint32_t *status); #define MPD_NUM_FLAGS 15 @@ -465,7 +465,7 @@ int mpd_qcheck_nans(mpd_t *nanresult, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status); void mpd_qfinalize(mpd_t *result, const mpd_context_t *ctx, uint32_t *status); -const char * mpd_class(const mpd_t *a, const mpd_context_t *ctx); +const char *mpd_class(const mpd_t *a, const mpd_context_t *ctx); int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status); mpd_t *mpd_qncopy(const mpd_t *a); @@ -579,7 +579,7 @@ /* Signalling functions */ /******************************************************************************/ -char * mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx); +char *mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx); void mpd_import_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx); void mpd_import_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx); size_t mpd_export_u16(uint16_t **rdata, size_t rlen, uint32_t base, const mpd_t *src, mpd_context_t *ctx); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 18:26:01 2014 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 4 Jan 2014 18:26:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315027=3A_Rewrite_?= =?utf-8?q?the_UTF-32_encoder=2E__It_is_now_1=2E6x_to_3=2E5x_faster=2E?= Message-ID: <3dxVJ90mFrz7Ljs@mail.python.org> http://hg.python.org/cpython/rev/b72c5573c5e7 changeset: 88294:b72c5573c5e7 user: Serhiy Storchaka date: Sat Jan 04 19:25:37 2014 +0200 summary: Issue #15027: Rewrite the UTF-32 encoder. It is now 1.6x to 3.5x faster. files: Doc/whatsnew/3.4.rst | 4 +- Misc/NEWS | 2 + Objects/stringlib/codecs.h | 87 +++++++++++++++++++ Objects/unicodeobject.c | 110 ++++++++++-------------- 4 files changed, 137 insertions(+), 66 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1213,7 +1213,9 @@ Significant Optimizations ========================= -* The UTF-32 decoder is now 3x to 4x faster. +* The UTF-32 decoder is now 3x to 4x faster. The UTF-32 encoder is now 1.6x + to 3.5x faster. (Contributed by Serhiy Storchaka in :issue:`14625` and + :issue:`15027`.) * The cost of hash collisions for sets is now reduced. Each hash table probe now checks a series of consecutive, adjacent key/hash pairs before diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #15027: Rewrite the UTF-32 encoder. It is now 1.6x to 3.5x faster. + - Issue #17432: Drop UCS2 from names of Unicode functions in python3.def. - Issue #19526: Exclude all new API from the stable ABI. Exceptions can be diff --git a/Objects/stringlib/codecs.h b/Objects/stringlib/codecs.h --- a/Objects/stringlib/codecs.h +++ b/Objects/stringlib/codecs.h @@ -718,6 +718,93 @@ return len - (end - in + 1); #endif } + +#if STRINGLIB_SIZEOF_CHAR == 1 +# define SWAB4(CH, tmp) ((CH) << 24) /* high bytes are zero */ +#elif STRINGLIB_SIZEOF_CHAR == 2 +# define SWAB4(CH, tmp) (tmp = (CH), \ + ((tmp & 0x00FFu) << 24) + ((tmp & 0xFF00u) << 8)) + /* high bytes are zero */ +#else +# define SWAB4(CH, tmp) (tmp = (CH), \ + tmp = ((tmp & 0x00FF00FFu) << 8) + ((tmp >> 8) & 0x00FF00FFu), \ + ((tmp & 0x0000FFFFu) << 16) + ((tmp >> 16) & 0x0000FFFFu)) +#endif +Py_LOCAL_INLINE(Py_ssize_t) +STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in, + Py_ssize_t len, + PY_UINT32_T **outptr, + int native_ordering) +{ + PY_UINT32_T *out = *outptr; + const STRINGLIB_CHAR *end = in + len; + if (native_ordering) { + const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4); + while (in < unrolled_end) { +#if STRINGLIB_SIZEOF_CHAR > 1 + /* check if any character is a surrogate character */ + if (((in[0] ^ 0xd800) & + (in[1] ^ 0xd800) & + (in[2] ^ 0xd800) & + (in[3] ^ 0xd800) & 0xf800) == 0) + break; +#endif + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[2]; + out[3] = in[3]; + in += 4; out += 4; + } + while (in < end) { + Py_UCS4 ch; + ch = *in++; +#if STRINGLIB_SIZEOF_CHAR > 1 + if (Py_UNICODE_IS_SURROGATE(ch)) { + /* reject surrogate characters (U+DC800-U+DFFF) */ + goto fail; + } +#endif + *out++ = ch; + } + } else { + const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4); + while (in < unrolled_end) { +#if STRINGLIB_SIZEOF_CHAR > 1 + Py_UCS4 ch1, ch2, ch3, ch4; + /* check if any character is a surrogate character */ + if (((in[0] ^ 0xd800) & + (in[1] ^ 0xd800) & + (in[2] ^ 0xd800) & + (in[3] ^ 0xd800) & 0xf800) == 0) + break; +#endif + out[0] = SWAB4(in[0], ch1); + out[1] = SWAB4(in[1], ch2); + out[2] = SWAB4(in[2], ch3); + out[3] = SWAB4(in[3], ch4); + in += 4; out += 4; + } + while (in < end) { + Py_UCS4 ch = *in++; +#if STRINGLIB_SIZEOF_CHAR > 1 + if (Py_UNICODE_IS_SURROGATE(ch)) { + /* reject surrogate characters (U+DC800-U+DFFF) */ + goto fail; + } +#endif + *out++ = SWAB4(ch, ch); + } + } + *outptr = out; + return len; +#if STRINGLIB_SIZEOF_CHAR > 1 + fail: + *outptr = out; + return len - (end - in + 1); +#endif +} +#undef SWAB4 + #endif #endif /* STRINGLIB_IS_UNICODE */ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -5085,32 +5085,22 @@ const char *errors, int byteorder) { - int kind; - void *data; + enum PyUnicode_Kind kind; + const void *data; Py_ssize_t len; PyObject *v; - unsigned char *p; - Py_ssize_t nsize, i; - /* Offsets from p for storing byte pairs in the right order. */ + PY_UINT32_T *out; #if PY_LITTLE_ENDIAN - int iorder[] = {0, 1, 2, 3}; + int native_ordering = byteorder <= 0; #else - int iorder[] = {3, 2, 1, 0}; + int native_ordering = byteorder >= 0; #endif const char *encoding; + Py_ssize_t nsize, pos; PyObject *errorHandler = NULL; PyObject *exc = NULL; PyObject *rep = NULL; -#define STORECHAR(CH) \ - do { \ - p[iorder[3]] = ((CH) >> 24) & 0xff; \ - p[iorder[2]] = ((CH) >> 16) & 0xff; \ - p[iorder[1]] = ((CH) >> 8) & 0xff; \ - p[iorder[0]] = (CH) & 0xff; \ - p += 4; \ - } while(0) - if (!PyUnicode_Check(str)) { PyErr_BadArgument(); return NULL; @@ -5121,59 +5111,53 @@ data = PyUnicode_DATA(str); len = PyUnicode_GET_LENGTH(str); + if (len > PY_SSIZE_T_MAX / 4 - (byteorder == 0)) + return PyErr_NoMemory(); nsize = len + (byteorder == 0); - if (nsize > PY_SSIZE_T_MAX / 4) - return PyErr_NoMemory(); v = PyBytes_FromStringAndSize(NULL, nsize * 4); if (v == NULL) return NULL; - p = (unsigned char *)PyBytes_AS_STRING(v); + /* output buffer is 4-bytes aligned */ + assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 4)); + out = (PY_UINT32_T *)PyBytes_AS_STRING(v); if (byteorder == 0) - STORECHAR(0xFEFF); + *out++ = 0xFEFF; if (len == 0) - return v; - - if (byteorder == -1) { - /* force LE */ - iorder[0] = 0; - iorder[1] = 1; - iorder[2] = 2; - iorder[3] = 3; + goto done; + + if (byteorder == -1) encoding = "utf-32-le"; - } - else if (byteorder == 1) { - /* force BE */ - iorder[0] = 3; - iorder[1] = 2; - iorder[2] = 1; - iorder[3] = 0; + else if (byteorder == 1) encoding = "utf-32-be"; - } else encoding = "utf-32"; if (kind == PyUnicode_1BYTE_KIND) { - for (i = 0; i < len; i++) - STORECHAR(PyUnicode_READ(kind, data, i)); - return v; - } - - for (i = 0; i < len;) { + ucs1lib_utf32_encode((const Py_UCS1 *)data, len, &out, native_ordering); + goto done; + } + + pos = 0; + while (pos < len) { Py_ssize_t repsize, moreunits; - Py_UCS4 ch = PyUnicode_READ(kind, data, i); - i++; - assert(ch <= MAX_UNICODE); - if (!Py_UNICODE_IS_SURROGATE(ch)) { - STORECHAR(ch); - continue; - } + + if (kind == PyUnicode_2BYTE_KIND) { + pos += ucs2lib_utf32_encode((const Py_UCS2 *)data + pos, len - pos, + &out, native_ordering); + } + else { + assert(kind == PyUnicode_4BYTE_KIND); + pos += ucs4lib_utf32_encode((const Py_UCS4 *)data + pos, len - pos, + &out, native_ordering); + } + if (pos == len) + break; rep = unicode_encode_call_errorhandler( errors, &errorHandler, encoding, "surrogates not allowed", - str, &exc, i-1, i, &i); - + str, &exc, pos, pos + 1, &pos); if (!rep) goto error; @@ -5181,7 +5165,7 @@ repsize = PyBytes_GET_SIZE(rep); if (repsize & 3) { raise_encode_exception(&exc, encoding, - str, i - 1, i, + str, pos - 1, pos, "surrogates not allowed"); goto error; } @@ -5194,7 +5178,7 @@ moreunits = repsize = PyUnicode_GET_LENGTH(rep); if (!PyUnicode_IS_ASCII(rep)) { raise_encode_exception(&exc, encoding, - str, i - 1, i, + str, pos - 1, pos, "surrogates not allowed"); goto error; } @@ -5202,7 +5186,7 @@ /* four bytes are reserved for each surrogate */ if (moreunits > 1) { - Py_ssize_t outpos = p - (unsigned char*) PyBytes_AS_STRING(v); + Py_ssize_t outpos = out - (PY_UINT32_T*) PyBytes_AS_STRING(v); Py_ssize_t morebytes = 4 * (moreunits - 1); if (PyBytes_GET_SIZE(v) > PY_SSIZE_T_MAX - morebytes) { /* integer overflow */ @@ -5211,20 +5195,16 @@ } if (_PyBytes_Resize(&v, PyBytes_GET_SIZE(v) + morebytes) < 0) goto error; - p = (unsigned char*) PyBytes_AS_STRING(v) + outpos; + out = (PY_UINT32_T*) PyBytes_AS_STRING(v) + outpos; } if (PyBytes_Check(rep)) { - Py_MEMCPY(p, PyBytes_AS_STRING(rep), repsize); - p += repsize; + Py_MEMCPY(out, PyBytes_AS_STRING(rep), repsize); + out += moreunits; } else /* rep is unicode */ { - const Py_UCS1 *repdata; assert(PyUnicode_KIND(rep) == PyUnicode_1BYTE_KIND); - repdata = PyUnicode_1BYTE_DATA(rep); - while (repsize--) { - Py_UCS4 ch = *repdata++; - STORECHAR(ch); - } + ucs1lib_utf32_encode(PyUnicode_1BYTE_DATA(rep), repsize, + &out, native_ordering); } Py_CLEAR(rep); @@ -5233,11 +5213,12 @@ /* Cut back to size actually needed. This is necessary for, for example, encoding of a string containing isolated surrogates and the 'ignore' handler is used. */ - nsize = p - (unsigned char*) PyBytes_AS_STRING(v); + nsize = (unsigned char*) out - (unsigned char*) PyBytes_AS_STRING(v); if (nsize != PyBytes_GET_SIZE(v)) _PyBytes_Resize(&v, nsize); Py_XDECREF(errorHandler); Py_XDECREF(exc); + done: return v; error: Py_XDECREF(rep); @@ -5245,7 +5226,6 @@ Py_XDECREF(exc); Py_XDECREF(v); return NULL; -#undef STORECHAR } PyObject * -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 20:09:30 2014 From: python-checkins at python.org (larry.hastings) Date: Sat, 4 Jan 2014 20:09:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319976=3A_Argument?= =?utf-8?q?_Clinic_METH=5FNOARGS_functions_now_always?= Message-ID: <3dxXbZ30w6z7Ljs@mail.python.org> http://hg.python.org/cpython/rev/c4ababa110a2 changeset: 88295:c4ababa110a2 user: Larry Hastings date: Sat Jan 04 11:09:09 2014 -0800 summary: Issue #19976: Argument Clinic METH_NOARGS functions now always take two parameters. files: Include/pymacro.h | 6 + Misc/NEWS | 5 + Modules/_pickle.c | 140 +++++++++++++++++++++++++--- Modules/zlibmodule.c | 17 +++- Tools/clinic/clinic.py | 13 +-- 5 files changed, 150 insertions(+), 31 deletions(-) diff --git a/Include/pymacro.h b/Include/pymacro.h --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -69,4 +69,10 @@ /* 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))) +#ifdef __GNUC__ +#define Py_UNUSED(name) _unused_ ## name __attribute__((unused)) +#else +#define Py_UNUSED(name) _unused_ ## name +#endif + #endif /* Py_PYMACRO_H */ diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -342,6 +342,11 @@ - Issue #19795: Improved markup of True/False constants. +Tools/Demos +----------- + +- Issue #19976: Argument Clinic METH_NOARGS functions now always + take two parameters. What's New in Python 3.4.0 Beta 1? ================================== diff --git a/Modules/_pickle.c b/Modules/_pickle.c --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -3901,8 +3901,21 @@ {"clear_memo", (PyCFunction)_pickle_Pickler_clear_memo, METH_NOARGS, _pickle_Pickler_clear_memo__doc__}, static PyObject * -_pickle_Pickler_clear_memo(PicklerObject *self) -/*[clinic checksum: 9c32be7e7a17ff82a81aae409d0d4f469033a5b2]*/ +_pickle_Pickler_clear_memo_impl(PicklerObject *self); + +static PyObject * +_pickle_Pickler_clear_memo(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_Pickler_clear_memo_impl((PicklerObject *)self); + + return return_value; +} + +static PyObject * +_pickle_Pickler_clear_memo_impl(PicklerObject *self) +/*[clinic checksum: 0574593b102fffb8e781d7bb9b536ceffc525ac1]*/ { if (self->memo) PyMemoTable_Clear(self->memo); @@ -4176,8 +4189,21 @@ {"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__}, static PyObject * -_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self) -/*[clinic checksum: 507f13938721992e175a3e58b5ad02620045a1cc]*/ +_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self); + +static PyObject * +_pickle_PicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_PicklerMemoProxy_clear_impl((PicklerMemoProxyObject *)self); + + return return_value; +} + +static PyObject * +_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self) +/*[clinic checksum: c6ca252530ccb3ea2f4b33507b51b183f23b24c7]*/ { if (self->pickler->memo) PyMemoTable_Clear(self->pickler->memo); @@ -4200,8 +4226,21 @@ {"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__}, static PyObject * -_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self) -/*[clinic checksum: 73a5117ab354290ebdbe07bd0bf7232d0936a69d]*/ +_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self); + +static PyObject * +_pickle_PicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_PicklerMemoProxy_copy_impl((PicklerMemoProxyObject *)self); + + return return_value; +} + +static PyObject * +_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self) +/*[clinic checksum: 808c4d5a37359ed5fb2efe81dbe5ff480719f470]*/ { Py_ssize_t i; PyMemoTable *memo; @@ -4254,11 +4293,24 @@ {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__}, static PyObject * -_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self) -/*[clinic checksum: 40f0bf7a9b161e77130674f0481bda0a0184dcce]*/ +_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self); + +static PyObject * +_pickle_PicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_PicklerMemoProxy___reduce___impl((PicklerMemoProxyObject *)self); + + return return_value; +} + +static PyObject * +_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self) +/*[clinic checksum: 2293152bdf53951a012d430767b608f5fb4213b5]*/ { PyObject *reduce_value, *dict_args; - PyObject *contents = _pickle_PicklerMemoProxy_copy(self); + PyObject *contents = _pickle_PicklerMemoProxy_copy_impl(self); if (contents == NULL) return NULL; @@ -6288,8 +6340,21 @@ {"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__}, static PyObject * -_pickle_Unpickler_load(PyObject *self) -/*[clinic checksum: c2ae1263f0dd000f34ccf0fe59d7c544464babc4]*/ +_pickle_Unpickler_load_impl(PyObject *self); + +static PyObject * +_pickle_Unpickler_load(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_Unpickler_load_impl(self); + + return return_value; +} + +static PyObject * +_pickle_Unpickler_load_impl(PyObject *self) +/*[clinic checksum: 55f35fcaf034817e75c355ec50b7878577355899]*/ { UnpicklerObject *unpickler = (UnpicklerObject*)self; @@ -6688,8 +6753,21 @@ {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__}, static PyObject * -_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self) -/*[clinic checksum: 46fecf4e33c0c873124f845edf6cc3a2e9864bd5]*/ +_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self); + +static PyObject * +_pickle_UnpicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_UnpicklerMemoProxy_clear_impl((UnpicklerMemoProxyObject *)self); + + return return_value; +} + +static PyObject * +_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self) +/*[clinic checksum: e0f99c26d48444a3f58f598bec3190c66595fce7]*/ { _Unpickler_MemoCleanup(self->unpickler); self->unpickler->memo = _Unpickler_NewMemo(self->unpickler->memo_size); @@ -6714,8 +6792,21 @@ {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__}, static PyObject * -_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self) -/*[clinic checksum: f8856c4e8a33540886dfbb245f286af3008fa0ad]*/ +_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self); + +static PyObject * +_pickle_UnpicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_UnpicklerMemoProxy_copy_impl((UnpicklerMemoProxyObject *)self); + + return return_value; +} + +static PyObject * +_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self) +/*[clinic checksum: 8c0ab91c0b694ea71a1774650898a760d1ab4765]*/ { Py_ssize_t i; PyObject *new_memo = PyDict_New(); @@ -6761,12 +6852,25 @@ {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__}, static PyObject * -_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self) -/*[clinic checksum: ab5516a77659144e1191c7dd70a0c6c7455660bc]*/ +_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self); + +static PyObject * +_pickle_UnpicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = _pickle_UnpicklerMemoProxy___reduce___impl((UnpicklerMemoProxyObject *)self); + + return return_value; +} + +static PyObject * +_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self) +/*[clinic checksum: 4ee76a65511291f0de2e9e63db395d2e5d6d8df6]*/ { PyObject *reduce_value; PyObject *constructor_args; - PyObject *contents = _pickle_UnpicklerMemoProxy_copy(self); + PyObject *contents = _pickle_UnpicklerMemoProxy_copy_impl(self); if (contents == NULL) return NULL; diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -1045,8 +1045,21 @@ {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__}, static PyObject * -zlib_Compress_copy(compobject *self) -/*[clinic checksum: 0b37c07f8f27deb7d4769951fbecf600a1006ef8]*/ +zlib_Compress_copy_impl(compobject *self); + +static PyObject * +zlib_Compress_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = zlib_Compress_copy_impl((compobject *)self); + + return return_value; +} + +static PyObject * +zlib_Compress_copy_impl(compobject *self) +/*[clinic checksum: 2f454ee15be3bc53cfb4e845c3f891f68be4c8e4]*/ { compobject *retval = NULL; int err; diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -400,19 +400,13 @@ {{"{name}", (PyCFunction){c_basename}, {methoddef_flags}, {c_basename}__doc__}}, """.replace('{methoddef_flags}', flags) - def meth_noargs_pyobject_template(self, methoddef_flags=""): - return self.template_base("METH_NOARGS", methoddef_flags) + """ -static PyObject * -{c_basename}({impl_parameters}) -""" - def meth_noargs_template(self, methoddef_flags=""): return self.template_base("METH_NOARGS", methoddef_flags) + """ static {impl_return_type} {impl_prototype}; static PyObject * -{c_basename}({self_type}{self_name}) +{c_basename}({self_type}{self_name}, PyObject *Py_UNUSED(ignored)) {{ PyObject *return_value = NULL; {declarations} @@ -713,10 +707,7 @@ f.return_converter.type == 'PyObject *') if not parameters: - if default_return_converter: - template = self.meth_noargs_pyobject_template(f.methoddef_flags) - else: - template = self.meth_noargs_template(f.methoddef_flags) + template = self.meth_noargs_template(f.methoddef_flags) elif (len(parameters) == 1 and parameters[0].kind == inspect.Parameter.POSITIONAL_ONLY and not converters[0].is_optional() and -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 21:45:13 2014 From: python-checkins at python.org (larry.hastings) Date: Sat, 4 Jan 2014 21:45:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319659=3A_Added_do?= =?utf-8?q?cumentation_for_Argument_Clinic=2E?= Message-ID: <3dxZk10Zt0z7Lmp@mail.python.org> http://hg.python.org/cpython/rev/e2280bf5c263 changeset: 88296:e2280bf5c263 user: Larry Hastings date: Sat Jan 04 12:44:57 2014 -0800 summary: Issue #19659: Added documentation for Argument Clinic. files: Doc/howto/clinic.rst | 900 +++++++++++++++++++++++++++++ Doc/howto/index.rst | 1 + Misc/NEWS | 2 + Modules/zlibmodule.c | 7 +- Tools/clinic/clinic.py | 56 +- 5 files changed, 955 insertions(+), 11 deletions(-) diff --git a/Doc/howto/clinic.rst b/Doc/howto/clinic.rst new file mode 100644 --- /dev/null +++ b/Doc/howto/clinic.rst @@ -0,0 +1,900 @@ +====================== +Argument Clinic How-To +====================== + +:author: Larry Hastings + + +.. topic:: Abstract + + Argument Clinic is a preprocessor for CPython C files. + Its purpose is to automate all the boilerplate involved + with writing argument parsing code for "builtins". + This document shows you how to convert your first C + function to work with Argument Clinic, and then introduces + some advanced topics on Argument Clinic usage. + + Argument Clinic is currently considered an internal + tool for the CPython code tree. Its use is not supported + for files outside the CPython code tree, and no guarantees + are made regarding backwards compatibility for future + versions. In other words: if you maintain an external C + extension for CPython, you're welcome to experiment with + Argument Clinic in your own code. But the version of Argument + Clinic that ships with CPython 3.5 *could* be totally + incompatible and break all your code. + +======================== +Basic Concepts And Usage +======================== + +Argument Clinic ships with CPython. You can find it in ``Tools/clinic/clinic.py``. +If you run that script, specifying a C file as an argument:: + + % python3 Tools/clinic/clinic.py foo.c + +Argument Clinic will scan over the file looking for lines that +look exactly like this:: + + /*[clinic] + +When it finds one, it reads everything up to a line that looks +like this:: + + [clinic]*/ + +Everything in between these two lines is input for Argument Clinic. +All of these lines, including the beginning and ending comment +lines, are collectively called an Argument Clinic "input block", +or "block" for short. + +When Argument Clinic parses one of these blocks, it +generates output. This output is rewritten into the C file +immediately after the block, followed by a comment containing a checksum. +The resulting Argument Clinic block looks like this:: + + /*[clinic] + ... clinic input goes here ... + [clinic]*/ + ... clinic output goes here ... + /*[clinic checksum:...]*/ + +If you run Argument Clinic on the same file a second time, Argument Clinic +will discard the old output and write out the new output with a fresh checksum +line. However, if the input hasn't changed, the output won't change either. + +You should never modify the output portion of an Argument Clinic block. Instead, +change the input until it produces the output you want. (That's the purpose of the +checksum--to detect and warn you in case someone accidentally modifies the output.) + +For the sake of clarity, here's the terminology we'll use with Argument Clinic: + +* The first line of the comment (``/*[clinic]``) is the *start line*. +* The last line of the initial comment (``[clinic]*/``) is the *end line*. +* The last line (``/*[clinic checksum:...]*/``) is the *checksum line*. +* In between the start line and the end line is the *input*. +* In between the end line and the checksum line is the *output*. +* All the text collectively, from the start line to the checksum line inclusively, + is the *block*. (A block that hasn't been successfully processed by Argument + Clinic yet doesn't have output or a checksum line, but it's still considered + a block.) + + +============================== +Converting Your First Function +============================== + +The best way to get a sense of how Argument Clinic works is to +convert a function to work with it. Let's dive in! + +0. Make sure you're working with a freshly updated trunk. + +1. Find a Python builtin that calls either ``PyArg_ParseTuple()`` + or ``PyArg_ParseTupleAndKeywords()``, and hasn't been converted yet. + For my example I'm using ``pickle.Pickler.dump()``. + +2. If the call to the ``PyArg_Parse`` function uses any of the + following format units:: + + O& + O! + es + es# + et + et# + + or if it has multiple calls to ``PyArg_ParseTuple()``, + you should choose a different function. Argument Clinic *does* + support all of these scenarios. But these are advanced + topics--let's do something simpler for your first function. + +3. Add the following boilerplate above the function, creating our block:: + + /*[clinic] + [clinic]*/ + +4. Cut the docstring and paste it in between the ``[clinic]`` lines, + removing all the junk that makes it a properly quoted C string. + When you're done you should have just the text, based at the left + margin, with no line wider than 80 characters. + (Argument Clinic will preserve indents inside the docstring.) + + Sample:: + + /*[clinic] + Write a pickled representation of obj to the open file. + [clinic]*/ + +5. If your docstring doesn't have a "summary" line, Argument Clinic will + complain. So let's make sure it has one. The "summary" line should + be a paragraph consisting of a single 80-column line + at the beginning of the docstring. + + (Our docstring consists solely of the summary line, so the sample + code doesn't have to change for this step.) + +6. Above the docstring, enter the name of the function, followed + by a blank line. This should be the Python name of the function, + and should be the full dotted path + to the function--it should start with the name of the module, + include any sub-modules, and if the function is a method on + a class it should include the class name too. + + Sample:: + + /*[clinic] + pickle.Pickler.dump + + Write a pickled representation of obj to the open file. + [clinic]*/ + +7. If this is the first time that module or class has been used with Argument + Clinic in this C file, + you must declare the module and/or class. Proper Argument Clinic hygiene + prefers declaring these in a separate block somewhere near the + top of the C file, in the same way that include files and statics go at + the top. (In our sample code we'll just show the two blocks next to + each other.) + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + Write a pickled representation of obj to the open file. + [clinic]*/ + + +8. Declare each of the parameters to the function. Each parameter + should get its own line. All the parameter lines should be + indented from the function name and the docstring. + + The general form of these parameter lines is as follows:: + + name_of_parameter: converter + + If the parameter has a default value, add that after the + converter:: + + name_of_parameter: converter = default_value + + Add a blank line below the parameters. + + What's a "converter"? It establishes both the type + of the variable used in C, and the method to convert the Python + value into a C value at runtime. + For now you're going to use what's called a "legacy converter"--a + convenience syntax intended to make porting old code into Argument + Clinic easier. + + For each parameter, copy the "format unit" for that + parameter from the ``PyArg_Parse()`` format argument and + specify *that* as its converter, as a quoted + string. ("format unit" is the formal name for the one-to-three + character substring of the ``format`` parameter that tells + the argument parsing function what the type of the variable + is and how to convert it.) + + For multicharacter format units like ``z#``, use the + entire two-or-three character string. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + + Write a pickled representation of obj to the open file. + [clinic]*/ + +9. If your function has ``|`` in the format string, meaning some + parameters have default values, you can ignore it. Argument + Clinic infers which parameters are optional based on whether + or not they have default values. + + If your function has ``$`` in the format string, meaning it + takes keyword-only arguments, specify ``*`` on a line by + itself before the first keyword-only argument, indented the + same as the parameter lines. + + (``pickle.Pickler.dump`` has neither, so our sample is unchanged.) + + +10. If the existing C function uses ``PyArg_ParseTuple()`` + (instead of ``PyArg_ParseTupleAndKeywords()``), then all its + arguments are positional-only. + + To mark all parameters as positional-only in Argument Clinic, + add a ``/`` on a line by itself after the last parameter, + indented the same as the parameter lines. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + +11. It's helpful to write a per-parameter docstring, indented + another level past the parameter declaration. But per-parameter + docstrings are optional; you can skip this step if you prefer. + + Here's how per-parameter docstrings work. The first line + of the per-parameter docstring must be indented further than the + parameter definition. This left margin establishes the left margin + for the whole per-parameter docstring; all the text you write will + be outdented by this amount. You can write as much as you like, + across multiple lines if you wish. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + +12. Save and close the file, then run ``Tools/clinic/clinic.py`` on it. + With luck everything worked and your block now has output! Reopen + the file in your text editor to see:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + /*[clinic checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + + PyDoc_STRVAR(pickle_Pickler_dump__doc__, + "Write a pickled representation of obj to the open file.\n" + "\n" + ... + static PyObject * + pickle_Pickler_dump_impl(PyObject *self, PyObject *obj) + /*[clinic checksum: 3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/ + +13. Double-check that the argument-parsing code Argument Clinic generated + looks basically the same as the existing code. + + First, ensure both places use the same argument-parsing function. + The existing code must call either + ``PyArg_ParseTuple()`` or ``PyArg_ParseTupleAndKeywords()``; + ensure that the code generated by Argument Clinic calls the + same function. + + Second, the format string passed in to ``PyArg_ParseTuple()`` or + ``PyArg_ParseTupleAndKeywords()`` should be *exactly* the same + as the hand-written one in the existing function. + + Well, there's one way that Argument Clinic's output is permitted + to be different. Argument Clinic always generates a format string + ending with ``:`` followed by the name of the function. If the + format string originally ended with ``;`` (to specify usage help), + this is harmless--don't worry about this difference. + + Apart from that, if either of these things differ in *any way*, + fix your input to Argument Clinic and rerun ``Tools/clinic/clinic.py`` + until they are the same. + + +14. Notice that the last line of its output is the declaration + of your "impl" function. This is where the builtin's implementation goes. + Delete the existing prototype of the function you're modifying, but leave + the opening curly brace. Now delete its argument parsing code and the + declarations of all the variables it dumps the arguments into. + Notice how the Python arguments are now arguments to this impl function; + if the implementation used different names for these variables, fix it. + The result should be a function that handles just the implementation + of the Python function without any argument-parsing code. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + /*[clinic checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + + PyDoc_STRVAR(pickle_Pickler_dump__doc__, + "Write a pickled representation of obj to the open file.\n" + "\n" + ... + static PyObject * + pickle_Pickler_dump_impl(PyObject *self, PyObject *obj) + /*[clinic checksum: 3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/ + { + /* Check whether the Pickler was initialized correctly (issue3664). + Developers often forget to call __init__() in their subclasses, which + would trigger a segfault without this check. */ + if (self->write == NULL) { + PyErr_Format(PicklingError, + "Pickler.__init__() was not called by %s.__init__()", + Py_TYPE(self)->tp_name); + return NULL; + } + + if (_Pickler_ClearBuffer(self) < 0) + return NULL; + + ... + +15. Compile and run the relevant portions of the regression-test suite. + This change should not introduce any new compile-time warnings or errors, + and there should be no externally-visible change to Python's behavior. + + Well, except for one difference: ``inspect.signature()`` run on your function + should now provide a valid signature! + + Congratulations, you've ported your first function to work with Argument Clinic! + +=============== +Advanced Topics +=============== + + +Renaming the C functions generated by Argument Clinic +----------------------------------------------------- + +Argument Clinic automatically names the functions it generates for you. +Occasionally this may cause a problem, if the generated name collides with +the name of an existing C function. There's an easy solution: you can explicitly +specify the base name to use for the C functions. Just add the keyword ``"as"`` +to your function declaration line, followed by the function name you wish to use. +Argument Clinic will use the function name you use for the base (generated) function, +and then add ``"_impl"`` to the end for the name of the impl function. + +For example, if we wanted to rename the C function names generated for +``pickle.Pickler.dump``, it'd look like this:: + + /*[clinic] + pickle.Pickler.dump as pickler_dumper + + ... + +The base function would now be named ``pickler_dumper()``, +and the impl function would be named ``pickler_dumper_impl()``. + + +Optional Groups +--------------- + +Some legacy functions have a tricky approach to parsing their arguments: +they count the number of positional arguments, then use a ``switch`` statement +to call one of several different ``PyArg_ParseTuple()`` calls depending on +how many positional arguments there are. (These functions cannot accept +keyword-only arguments.) This approach was used to simulate optional +arguments back before ``PyArg_ParseTupleAndKeywords()`` was created. + +Functions using this approach can often be converted to +use ``PyArg_ParseTupleAndKeywords()``, optional arguments, and default values. +But it's not always possible, because some of these legacy functions have +behaviors ``PyArg_ParseTupleAndKeywords()`` can't directly support. +The most obvious example is the builtin function ``range()``, which has +an optional argument on the *left* side of its required argument! +Another example is ``curses.window.addch()``, which has a group of two +arguments that must always be specified together. (The arguments are +called ``x`` and ``y``; if you call the function passing in ``x``, +you must also pass in ``y``--and if you don't pass in ``x`` you may not +pass in ``y`` either.) + +For the sake of backwards compatibility, Argument Clinic supports this +alternate approach to parsing, using what are called *optional groups*. +Optional groups are groups of arguments that can only be specified together. +They can be to the left or the right of the required arguments. They +can *only* be used with positional-only parameters. + +To specify an optional group, add a ``[`` on a line by itself before +the parameters you wish to be +in a group together, and a ``]`` on a line by itself after the +parameters. As an example, here's how ``curses.window.addch`` +uses optional groups to make the first two parameters and the last +parameter optional:: + + /*[clinic] + + curses.window.addch + + [ + x: int + X-coordinate. + y: int + Y-coordinate. + ] + + ch: object + Character to add. + + [ + attr: long + Attributes for the character. + ] + / + + ... + + +Notes: + +* For every optional group, one additional parameter will be passed into the + impl function representing the group. The parameter will be an int, and it will + be named ``group_{direction}_{number}``, + where ``{direction}`` is either ``right`` or ``left`` depending on whether the group + is before or after the required parameters, and ``{number}`` is a monotonically + increasing number (starting at 1) indicating how far away the group is from + the required parameters. When the impl is called, this parameter will be set + to zero if this group was unused, and set to non-zero if this group was used. + (By used or unused, I mean whether or not the parameters received arguments + in this invocation.) + +* If there are no required arguments, the optional groups will behave + as if they are to the right of the required arguments. + +* In the case of ambiguity, the argument parsing code + favors parameters on the left (before the required parameters). + +* Optional groups are *only* intended for legacy code. Please do not + use optional groups for new code. + + +Using real Argument Clinic converters, instead of "legacy converters" +--------------------------------------------------------------------- + +To save time, and to minimize how much you need to learn +to achieve your first port to Argument Clinic, the walkthrough above tells +you to use the "legacy converters". "Legacy converters" are a convenience, +designed explicitly to make porting existing code to Argument Clinic +easier. And to be clear, their use is entirely acceptable when porting +code for Python 3.4. + +However, in the long term we probably want all our blocks to +use Argument Clinic's real syntax for converters. Why? A couple +reasons: + +* The proper converters are far easier to read and clearer in their intent. +* There are some format units that are unsupported as "legacy converters", + because they require arguments, and the legacy converter syntax doesn't + support specifying arguments. +* In the future we may have a new argument parsing library that isn't + restricted to what ``PyArg_ParseTuple()`` supports. + +So if you want +to go that extra effort, you should consider using normal +converters instead of the legacy converters. + +In a nutshell, the syntax for Argument Clinic (non-legacy) converters +looks like a Python function call. However, if there are no explicit +arguments to the function (all functions take their default values), +you may omit the parentheses. Thus ``bool`` and ``bool()`` are exactly +the same. All parameters to Argument Clinic converters are keyword-only. + +All Argument Clinic converters accept the following arguments: + +``doc_default`` + If the parameter takes a default value, normally this value is also + provided in the ``inspect.Signature`` metadata, and displayed in the + docstring. ``doc_default`` lets you override the value used in these + two places: pass in a string representing the Python value you wish + to use in these two contexts. + +``required`` + If a parameter takes a default value, Argument Clinic infers that the + parameter is optional. However, you may want a parameter to take a + default value in C, but not behave in Python as if the parameter is + optional. Passing in ``required=True`` to a converter tells Argument + Clinic that this parameter is not optional, even if it has a default + value. + +``annotation`` + The annotation value for this parameter. Not currently supported, + because PEP 8 mandates that the Python library may not use + annotations. + +Below is a table showing the mapping of legacy converters into real +Argument Clinic converters. On the left is the legacy converter, +on the right is the text you'd replace it with. + +========= ================================================================================= +``'B'`` ``byte(bitwise=True)`` +``'b'`` ``byte`` +``'c'`` ``char`` +``'C'`` ``int(types='str')`` +``'d'`` ``double`` +``'D'`` ``Py_complex`` +``'es#'`` ``str(encoding='name_of_encoding', length=True, zeroes=True)`` +``'es'`` ``str(encoding='name_of_encoding')`` +``'et#'`` ``str(encoding='name_of_encoding', types='bytes bytearray str', length=True)`` +``'et'`` ``str(encoding='name_of_encoding', types='bytes bytearray str')`` +``'f'`` ``float`` +``'h'`` ``short`` +``'H'`` ``unsigned_short`` +``'i'`` ``int`` +``'I'`` ``unsigned_int`` +``'K'`` ``unsigned_PY_LONG_LONG`` +``'L'`` ``PY_LONG_LONG`` +``'n'`` ``Py_ssize_t`` +``'O!'`` ``object(type='name_of_Python_type')`` +``'O&'`` ``object(converter='name_of_c_function')`` +``'O'`` ``object`` +``'p'`` ``bool`` +``'s#'`` ``str(length=True)`` +``'S'`` ``PyBytesObject`` +``'s'`` ``str`` +``'s*'`` ``Py_buffer(types='str bytes bytearray buffer')`` +``'u#'`` ``Py_UNICODE(length=True)`` +``'u'`` ``Py_UNICODE`` +``'U'`` ``unicode`` +``'w*'`` ``Py_buffer(types='bytearray rwbuffer')`` +``'y#'`` ``str(type='bytes', length=True)`` +``'Y'`` ``PyByteArrayObject`` +``'y'`` ``str(type='bytes')`` +``'y*'`` ``Py_buffer`` +``'Z#'`` ``Py_UNICODE(nullable=True, length=True)`` +``'z#'`` ``str(nullable=True, length=True)`` +``'Z'`` ``Py_UNICODE(nullable=True)`` +``'z'`` ``str(nullable=True)`` +``'z*'`` ``Py_buffer(types='str bytes bytearray buffer', nullable=True)`` +========= ================================================================================= + +As an example, here's our sample ``pickle.Pickler.dump`` using the proper +converter:: + + /*[clinic] + pickle.Pickler.dump + + obj: object + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + +Argument Clinic will show you all the converters it has +available. For each converter it'll show you all the parameters +it accepts, along with the default value for each parameter. +Just run ``Tools/clinic/clinic.py --converters`` to see the full list. + + +Advanced converters +------------------- + +Remeber those format units you skipped for your first +time because they were advanced? Here's how to handle those too. + +The trick is, all those format units take arguments--either +conversion functions, or types, or strings specifying an encoding. +(But "legacy converters" don't support arguments. That's why we +skipped them for your first function.) The argument you specified +to the format unit is now an argument to the converter; this +argument is either ``converter`` (for ``O&``), ``type`` (for ``O!``), +or ``encoding`` (for all the format units that start with ``e``). + +Note that ``object()`` must explicitly support each Python type you specify +for the ``type`` argument. Currently it only supports ``str``. It should be +easy to add more, just edit ``Tools/clinic/clinic.py``, search for ``O!`` in +the text, and add more entries to the dict mapping types to strings just above it. + +Note also that this approach takes away some possible flexibility for the format +units starting with ``e``. It used to be possible to decide at runtime what +encoding string to pass in to ``PyArg_ParseTuple()``. But now this string must +be hard-coded at compile-time. This limitation is deliberate; it made supporting +this format unit much easier, and may allow for future compile-time optimizations. +This restriction does not seem unreasonable; CPython itself always passes in static +hard-coded strings when using format units starting with ``e``. + + +Using a return converter +------------------------ + +By default the impl function Argument Clinic generates for you returns ``PyObject *``. +But your C function often computes some C type, then converts it into the ``PyObject *`` +at the last moment. Argument Clinic handles converting your inputs from Python types +into native C types--why not have it convert your return value from a native C type +into a Python type too? + +That's what a "return converter" does. It changes your impl function to return +some C type, then adds code to the generated (non-impl) function to handle converting +that value into the appropriate ``PyObject *``. + +The syntax for return converters is similar to that of parameter converters. +You specify the return converter like it was a return annotation on the +function itself. Return converters behave much the same as parameter converters; +they take arguments, the arguments are all keyword-only, and if you're not changing +any of the default arguments you can omit the parentheses. + +(If you use both ``"as"`` *and* a return converter for your function, +the ``"as"`` should come before the return converter.) + +There's one additional complication when using return converters: how do you +indicate an error has occured? Normally, a function returns a valid (non-``NULL``) +pointer for success, and ``NULL`` for failure. But if you use an integer return converter, +all integers are valid. How can Argument Clinic detect an error? Its solution: each return +converter implicitly looks for a special value that indicates an error. If you return +that value, and an error has been set (``PyErr_Occurred()`` returns a true +value), then the generated code will propogate the error. Otherwise it will +encode the value you return like normal. + +Currently Argument Clinic supports only a few return converters:: + + int + long + Py_ssize_t + DecodeFSDefault + +None of these take parameters. For the first three, return -1 to indicate +error. For ``DecodeFSDefault``, the return type is ``char *``; return a NULL +pointer to indicate an error. + +Calling Python code +------------------- + +The rest of the advanced topics require you to write Python code +which lives inside your C file and modifies Argument Clinic at +runtime. This is simple; you simply define a Python block. + +A Python block uses different delimiter lines than an Argument +Clinic function block. It looks like this:: + + /*[python] + # python code goes here + [python]*/ + +All the code inside the Python block is executed at the +time it's parsed. All text written to stdout inside the block +is redirected into the "output" after the block. + +As an example, here's a Python block that adds a static integer +variable to the C code:: + + /*[python] + print('static int __ignored_unused_variable__ = 0;') + [python]*/ + static int __ignored_unused_variable__ = 0; + /*[python checksum:...]*/ + + +Using a "self converter" +------------------------ + +Argument Clinic automatically adds a "self" parameter for you +using a default converter. However, you can override +Argument Clinic's converter and specify one yourself. +Just add your own ``self`` parameter as the first parameter in a +block, and ensure that its converter is an instance of +``self_converter`` or a subclass thereof. + +What's the point? This lets you automatically cast ``self`` +from ``PyObject *`` to a custom type. + +How do you specify the custom type you want to cast ``self`` to? +If you only have one or two functions with the same type for ``self``, +you can directly use Argument Clinic's existing ``self`` converter, +passing in the type you want to use as the ``type`` parameter:: + + /*[clinic] + + _pickle.Pickler.dump + + self: self(type="PicklerObject *") + obj: object + / + + Write a pickled representation of the given object to the open file. + [clinic]*/ + +On the other hand, if you have a lot of functions that will use the same +type for ``self``, it's best to create your own converter, subclassing +``self_converter`` but overwriting the ``type`` member:: + + /*[clinic] + class PicklerObject_converter(self_converter): + type = "PicklerObject *" + [clinic]*/ + + /*[clinic] + + _pickle.Pickler.dump + + self: PicklerObject + obj: object + / + + Write a pickled representation of the given object to the open file. + [clinic]*/ + + + +Writing a custom converter +-------------------------- + +As we hinted at in the previous section... you can write your own converters! +A converter is simply a Python class that inherits from ``CConverter``. +The main purpose of a custom converter is if you have a parameter using +the ``O&`` format unit--parsing this parameter means calling +a ``PyArg_ParseTuple()`` "converter function". + +Your converter class should be named ``*something*_converter``. +If the name follows this convention, then your converter class +will be automatically registered with Argument Clinic; its name +will be the name of your class with the ``_converter`` suffix +stripped off. (This is done automatically for you with a metaclass.) + +You shouldn't subclass ``CConverter.__init__``. Instead, you should +write a ``converter_init()`` function. ``converter_init()`` +always accepts a ``self`` parameter; after that, all additional +parameters *must* be keyword-only. Any arguments passed in to +the converter in Argument Clinic will be passed along to your +``converter_init()``. + +There are some additional members of ``CConverter`` you may wish +to specify in your subclass. Here's the current list: + +``type`` + The C type to use for this variable. + ``type`` should be a Python string specifying the type, e.g. ``int``. + If this is a pointer type, the type string should end with ``' *'``. + +``default`` + The Python default value for this parameter, as a Python value. + Or the magic value ``unspecified`` if there is no default. + +``doc_default`` + ``default`` as it should appear in the documentation, + as a string. + Or ``None`` if there is no default. + This string, when run through ``eval()``, should produce + a Python value. + +``py_default`` + ``default`` as it should appear in Python code, + as a string. + Or ``None`` if there is no default. + +``c_default`` + ``default`` as it should appear in C code, + as a string. + Or ``None`` if there is no default. + +``c_ignored_default`` + The default value used to initialize the C variable when + there is no default, but not specifying a default may + result in an "uninitialized variable" warning. This is + easily happen when using option groups--although + properly-written code won't actually use the variable, + the variable does get passed in to the _impl, and the + C compiler will complain about the "use" of the uninitialized + value. This value should be a string. + +``converter`` + The name of the C converter function, as a string. + +``impl_by_reference`` + A boolean value. If true, + Argument Clinic will add a ``&`` in front of the name of + the variable when passing it into the impl function. + +``parse_by_reference`` + A boolean value. If true, + Argument Clinic will add a ``&`` in front of the name of + the variable when passing it into ``PyArg_ParseTuple()``. + + +Here's the simplest example of a custom converter, from ``Modules/zlibmodule.c``:: + + /*[python] + + class uint_converter(CConverter): + type = 'unsigned int' + converter = 'uint_converter' + + [python]*/ + /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + +This block adds a ``uint`` converter to Argument Clinic. Parameters +declared as ``uint`` will be declared as type ``unsigned int``, and will +be parsed by calling the ``uint_converter`` converter function in C. +``uint`` variables automatically support default values. + +More sophisticated custom converters can insert custom C code to +handle initialization and cleanup. +You can see more examples of custom converters in the CPython +source tree; grep the C files for the string ``CConverter``. + +Writing a custom return converter +--------------------------------- + +Writing a custom return converter is much like writing +a custom converter. Except it's much simpler, because return +converters are themselves much simpler. + +Return converters must subclass ``CReturnConverter``. +There are no examples yet of custom return converters, +because they are not widely used yet. If you wish to +write your own return converter, please read ``Tools/clinic/clinic.py``, +specifically the implementation of ``CReturnConverter`` and +all its subclasses. + + +Using Argument Clinic in Python files +------------------------------------- + +It's actually possible to use Argument Clinic to preprocess Python files. +There's no point to using Argument Clinic blocks, of course, as the output +wouldn't make any sense to the Python interpreter. But using Argument Clinic +to run Python blocks lets you use Python as a Python preprocessor! + +Since Python comments are different from C comments, Argument Clinic +blocks embedded in Python files look slightly different. They look like this:: + + #/*[python] + #print("def foo(): pass") + #[python]*/ + def foo(): pass + #/*[python checksum:...]*/ diff --git a/Doc/howto/index.rst b/Doc/howto/index.rst --- a/Doc/howto/index.rst +++ b/Doc/howto/index.rst @@ -28,4 +28,5 @@ webservers.rst argparse.rst ipaddress.rst + clinic.rst diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -345,6 +345,8 @@ Tools/Demos ----------- +- Issue #19659: Added documentation for Argument Clinic. + - Issue #19976: Argument Clinic METH_NOARGS functions now always take two parameters. diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -312,9 +312,6 @@ type = 'unsigned int' converter = 'uint_converter' -class compobject_converter(self_converter): - type = "compobject *" - [python]*/ /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ @@ -750,7 +747,7 @@ zlib.Decompress.decompress - self: compobject + self: self(type="compobject *") data: Py_buffer The binary data to decompress. @@ -1032,7 +1029,7 @@ /*[clinic] zlib.Compress.copy - self: compobject + self: self(type="compobject *") Return a copy of the compression object. [clinic]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1296,11 +1296,13 @@ must be keyword-only. """ + # The C type to use for this variable. + # 'type' should be a Python string specifying the type, e.g. "int". + # If this is a pointer type, the type string should end with ' *'. type = None - format_unit = 'O&' # The Python default value for this parameter, as a Python value. - # Or "unspecified" if there is no default. + # Or the magic value "unspecified" if there is no default. default = unspecified # "default" as it should appear in the documentation, as a string. @@ -1330,9 +1332,32 @@ # (If this is not None, format_unit must be 'O&'.) converter = None + # Should Argument Clinic add a '&' before the name of + # the variable when passing it into the _impl function? + impl_by_reference = False + + # Should Argument Clinic add a '&' before the name of + # the variable when passing it into PyArg_ParseTuple (AndKeywords)? + parse_by_reference = True + + ############################################################# + ############################################################# + ## You shouldn't need to read anything below this point to ## + ## write your own converter functions. ## + ############################################################# + ############################################################# + + # The "format unit" to specify for this variable when + # parsing arguments using PyArg_ParseTuple (AndKeywords). + # Custom converters should always use the default value of 'O&'. + format_unit = 'O&' + + # What encoding do we want for this variable? Only used + # by format units starting with 'e'. encoding = None - impl_by_reference = False - parse_by_reference = True + + # Do we want an adjacent '_length' variable for this variable? + # Only used by format units ending with '#'. length = False def __init__(self, name, function, default=unspecified, *, doc_default=None, required=False, annotation=unspecified, **kwargs): @@ -1751,7 +1776,7 @@ this is the default converter used for "self". """ type = "PyObject *" - def converter_init(self): + def converter_init(self, *, type=None): f = self.function if f.kind == CALLABLE: if f.cls: @@ -1766,6 +1791,9 @@ self.name = "cls" self.type = "PyTypeObject *" + if type: + self.type = type + def render(self, parameter, data): fail("render() should never be called on self_converter instances") @@ -1787,7 +1815,13 @@ class CReturnConverter(metaclass=CReturnConverterAutoRegister): + # The C type to use for this variable. + # 'type' should be a Python string specifying the type, e.g. "int". + # If this is a pointer type, the type string should end with ' *'. type = 'PyObject *' + + # The Python default value for this parameter, as a Python value. + # Or the magic value "unspecified" if there is no default. default = None def __init__(self, *, doc_default=None, **kwargs): @@ -1826,6 +1860,16 @@ add_c_return_converter(CReturnConverter, 'object') +class NoneType_return_converter(CReturnConverter): + def render(self, function, data): + self.declare(data) + data.return_conversion.append(''' +if (_return_value != Py_None) + goto exit; +return_value = Py_None; +Py_INCREF(Py_None); +'''.strip()) + class int_return_converter(CReturnConverter): type = 'int' @@ -2680,7 +2724,7 @@ # print(" ", short_name + "".join(parameters)) print() - print("All converters also accept (doc_default=None, required=False).") + print("All converters also accept (doc_default=None, required=False, annotation=None).") print("All return converters also accept (doc_default=None).") sys.exit(0) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 21:51:12 2014 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 4 Jan 2014 21:51:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Reverted_changeset_b72c557?= =?utf-8?b?M2M1ZTcgKGlzc3VlICMxNTAyNyku?= Message-ID: <3dxZrw3vC4z7LjS@mail.python.org> http://hg.python.org/cpython/rev/1e345924f7ea changeset: 88297:1e345924f7ea parent: 88295:c4ababa110a2 user: Serhiy Storchaka date: Sat Jan 04 22:44:01 2014 +0200 summary: Reverted changeset b72c5573c5e7 (issue #15027). files: Doc/whatsnew/3.4.rst | 4 +- Misc/NEWS | 2 - Objects/stringlib/codecs.h | 87 ------------------- Objects/unicodeobject.c | 110 ++++++++++++++---------- 4 files changed, 66 insertions(+), 137 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1213,9 +1213,7 @@ Significant Optimizations ========================= -* The UTF-32 decoder is now 3x to 4x faster. The UTF-32 encoder is now 1.6x - to 3.5x faster. (Contributed by Serhiy Storchaka in :issue:`14625` and - :issue:`15027`.) +* The UTF-32 decoder is now 3x to 4x faster. * The cost of hash collisions for sets is now reduced. Each hash table probe now checks a series of consecutive, adjacent key/hash pairs before diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,8 +10,6 @@ Core and Builtins ----------------- -- Issue #15027: Rewrite the UTF-32 encoder. It is now 1.6x to 3.5x faster. - - Issue #17432: Drop UCS2 from names of Unicode functions in python3.def. - Issue #19526: Exclude all new API from the stable ABI. Exceptions can be diff --git a/Objects/stringlib/codecs.h b/Objects/stringlib/codecs.h --- a/Objects/stringlib/codecs.h +++ b/Objects/stringlib/codecs.h @@ -718,93 +718,6 @@ return len - (end - in + 1); #endif } - -#if STRINGLIB_SIZEOF_CHAR == 1 -# define SWAB4(CH, tmp) ((CH) << 24) /* high bytes are zero */ -#elif STRINGLIB_SIZEOF_CHAR == 2 -# define SWAB4(CH, tmp) (tmp = (CH), \ - ((tmp & 0x00FFu) << 24) + ((tmp & 0xFF00u) << 8)) - /* high bytes are zero */ -#else -# define SWAB4(CH, tmp) (tmp = (CH), \ - tmp = ((tmp & 0x00FF00FFu) << 8) + ((tmp >> 8) & 0x00FF00FFu), \ - ((tmp & 0x0000FFFFu) << 16) + ((tmp >> 16) & 0x0000FFFFu)) -#endif -Py_LOCAL_INLINE(Py_ssize_t) -STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in, - Py_ssize_t len, - PY_UINT32_T **outptr, - int native_ordering) -{ - PY_UINT32_T *out = *outptr; - const STRINGLIB_CHAR *end = in + len; - if (native_ordering) { - const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4); - while (in < unrolled_end) { -#if STRINGLIB_SIZEOF_CHAR > 1 - /* check if any character is a surrogate character */ - if (((in[0] ^ 0xd800) & - (in[1] ^ 0xd800) & - (in[2] ^ 0xd800) & - (in[3] ^ 0xd800) & 0xf800) == 0) - break; -#endif - out[0] = in[0]; - out[1] = in[1]; - out[2] = in[2]; - out[3] = in[3]; - in += 4; out += 4; - } - while (in < end) { - Py_UCS4 ch; - ch = *in++; -#if STRINGLIB_SIZEOF_CHAR > 1 - if (Py_UNICODE_IS_SURROGATE(ch)) { - /* reject surrogate characters (U+DC800-U+DFFF) */ - goto fail; - } -#endif - *out++ = ch; - } - } else { - const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4); - while (in < unrolled_end) { -#if STRINGLIB_SIZEOF_CHAR > 1 - Py_UCS4 ch1, ch2, ch3, ch4; - /* check if any character is a surrogate character */ - if (((in[0] ^ 0xd800) & - (in[1] ^ 0xd800) & - (in[2] ^ 0xd800) & - (in[3] ^ 0xd800) & 0xf800) == 0) - break; -#endif - out[0] = SWAB4(in[0], ch1); - out[1] = SWAB4(in[1], ch2); - out[2] = SWAB4(in[2], ch3); - out[3] = SWAB4(in[3], ch4); - in += 4; out += 4; - } - while (in < end) { - Py_UCS4 ch = *in++; -#if STRINGLIB_SIZEOF_CHAR > 1 - if (Py_UNICODE_IS_SURROGATE(ch)) { - /* reject surrogate characters (U+DC800-U+DFFF) */ - goto fail; - } -#endif - *out++ = SWAB4(ch, ch); - } - } - *outptr = out; - return len; -#if STRINGLIB_SIZEOF_CHAR > 1 - fail: - *outptr = out; - return len - (end - in + 1); -#endif -} -#undef SWAB4 - #endif #endif /* STRINGLIB_IS_UNICODE */ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -5085,22 +5085,32 @@ const char *errors, int byteorder) { - enum PyUnicode_Kind kind; - const void *data; + int kind; + void *data; Py_ssize_t len; PyObject *v; - PY_UINT32_T *out; + unsigned char *p; + Py_ssize_t nsize, i; + /* Offsets from p for storing byte pairs in the right order. */ #if PY_LITTLE_ENDIAN - int native_ordering = byteorder <= 0; + int iorder[] = {0, 1, 2, 3}; #else - int native_ordering = byteorder >= 0; + int iorder[] = {3, 2, 1, 0}; #endif const char *encoding; - Py_ssize_t nsize, pos; PyObject *errorHandler = NULL; PyObject *exc = NULL; PyObject *rep = NULL; +#define STORECHAR(CH) \ + do { \ + p[iorder[3]] = ((CH) >> 24) & 0xff; \ + p[iorder[2]] = ((CH) >> 16) & 0xff; \ + p[iorder[1]] = ((CH) >> 8) & 0xff; \ + p[iorder[0]] = (CH) & 0xff; \ + p += 4; \ + } while(0) + if (!PyUnicode_Check(str)) { PyErr_BadArgument(); return NULL; @@ -5111,53 +5121,59 @@ data = PyUnicode_DATA(str); len = PyUnicode_GET_LENGTH(str); - if (len > PY_SSIZE_T_MAX / 4 - (byteorder == 0)) + nsize = len + (byteorder == 0); + if (nsize > PY_SSIZE_T_MAX / 4) return PyErr_NoMemory(); - nsize = len + (byteorder == 0); v = PyBytes_FromStringAndSize(NULL, nsize * 4); if (v == NULL) return NULL; - /* output buffer is 4-bytes aligned */ - assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 4)); - out = (PY_UINT32_T *)PyBytes_AS_STRING(v); + p = (unsigned char *)PyBytes_AS_STRING(v); if (byteorder == 0) - *out++ = 0xFEFF; + STORECHAR(0xFEFF); if (len == 0) - goto done; - - if (byteorder == -1) + return v; + + if (byteorder == -1) { + /* force LE */ + iorder[0] = 0; + iorder[1] = 1; + iorder[2] = 2; + iorder[3] = 3; encoding = "utf-32-le"; - else if (byteorder == 1) + } + else if (byteorder == 1) { + /* force BE */ + iorder[0] = 3; + iorder[1] = 2; + iorder[2] = 1; + iorder[3] = 0; encoding = "utf-32-be"; + } else encoding = "utf-32"; if (kind == PyUnicode_1BYTE_KIND) { - ucs1lib_utf32_encode((const Py_UCS1 *)data, len, &out, native_ordering); - goto done; - } - - pos = 0; - while (pos < len) { + for (i = 0; i < len; i++) + STORECHAR(PyUnicode_READ(kind, data, i)); + return v; + } + + for (i = 0; i < len;) { Py_ssize_t repsize, moreunits; - - if (kind == PyUnicode_2BYTE_KIND) { - pos += ucs2lib_utf32_encode((const Py_UCS2 *)data + pos, len - pos, - &out, native_ordering); - } - else { - assert(kind == PyUnicode_4BYTE_KIND); - pos += ucs4lib_utf32_encode((const Py_UCS4 *)data + pos, len - pos, - &out, native_ordering); - } - if (pos == len) - break; + Py_UCS4 ch = PyUnicode_READ(kind, data, i); + i++; + assert(ch <= MAX_UNICODE); + if (!Py_UNICODE_IS_SURROGATE(ch)) { + STORECHAR(ch); + continue; + } rep = unicode_encode_call_errorhandler( errors, &errorHandler, encoding, "surrogates not allowed", - str, &exc, pos, pos + 1, &pos); + str, &exc, i-1, i, &i); + if (!rep) goto error; @@ -5165,7 +5181,7 @@ repsize = PyBytes_GET_SIZE(rep); if (repsize & 3) { raise_encode_exception(&exc, encoding, - str, pos - 1, pos, + str, i - 1, i, "surrogates not allowed"); goto error; } @@ -5178,7 +5194,7 @@ moreunits = repsize = PyUnicode_GET_LENGTH(rep); if (!PyUnicode_IS_ASCII(rep)) { raise_encode_exception(&exc, encoding, - str, pos - 1, pos, + str, i - 1, i, "surrogates not allowed"); goto error; } @@ -5186,7 +5202,7 @@ /* four bytes are reserved for each surrogate */ if (moreunits > 1) { - Py_ssize_t outpos = out - (PY_UINT32_T*) PyBytes_AS_STRING(v); + Py_ssize_t outpos = p - (unsigned char*) PyBytes_AS_STRING(v); Py_ssize_t morebytes = 4 * (moreunits - 1); if (PyBytes_GET_SIZE(v) > PY_SSIZE_T_MAX - morebytes) { /* integer overflow */ @@ -5195,16 +5211,20 @@ } if (_PyBytes_Resize(&v, PyBytes_GET_SIZE(v) + morebytes) < 0) goto error; - out = (PY_UINT32_T*) PyBytes_AS_STRING(v) + outpos; + p = (unsigned char*) PyBytes_AS_STRING(v) + outpos; } if (PyBytes_Check(rep)) { - Py_MEMCPY(out, PyBytes_AS_STRING(rep), repsize); - out += moreunits; + Py_MEMCPY(p, PyBytes_AS_STRING(rep), repsize); + p += repsize; } else /* rep is unicode */ { + const Py_UCS1 *repdata; assert(PyUnicode_KIND(rep) == PyUnicode_1BYTE_KIND); - ucs1lib_utf32_encode(PyUnicode_1BYTE_DATA(rep), repsize, - &out, native_ordering); + repdata = PyUnicode_1BYTE_DATA(rep); + while (repsize--) { + Py_UCS4 ch = *repdata++; + STORECHAR(ch); + } } Py_CLEAR(rep); @@ -5213,12 +5233,11 @@ /* Cut back to size actually needed. This is necessary for, for example, encoding of a string containing isolated surrogates and the 'ignore' handler is used. */ - nsize = (unsigned char*) out - (unsigned char*) PyBytes_AS_STRING(v); + nsize = p - (unsigned char*) PyBytes_AS_STRING(v); if (nsize != PyBytes_GET_SIZE(v)) _PyBytes_Resize(&v, nsize); Py_XDECREF(errorHandler); Py_XDECREF(exc); - done: return v; error: Py_XDECREF(rep); @@ -5226,6 +5245,7 @@ Py_XDECREF(exc); Py_XDECREF(v); return NULL; +#undef STORECHAR } PyObject * -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 21:51:14 2014 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 4 Jan 2014 21:51:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge_heads?= Message-ID: <3dxZry1Y1wz7LmR@mail.python.org> http://hg.python.org/cpython/rev/0a306e5ce5aa changeset: 88298:0a306e5ce5aa parent: 88297:1e345924f7ea parent: 88296:e2280bf5c263 user: Serhiy Storchaka date: Sat Jan 04 22:49:40 2014 +0200 summary: Merge heads files: Doc/howto/clinic.rst | 900 +++++++++++++++++++++++++++++ Doc/howto/index.rst | 1 + Misc/NEWS | 2 + Modules/zlibmodule.c | 7 +- Tools/clinic/clinic.py | 56 +- 5 files changed, 955 insertions(+), 11 deletions(-) diff --git a/Doc/howto/clinic.rst b/Doc/howto/clinic.rst new file mode 100644 --- /dev/null +++ b/Doc/howto/clinic.rst @@ -0,0 +1,900 @@ +====================== +Argument Clinic How-To +====================== + +:author: Larry Hastings + + +.. topic:: Abstract + + Argument Clinic is a preprocessor for CPython C files. + Its purpose is to automate all the boilerplate involved + with writing argument parsing code for "builtins". + This document shows you how to convert your first C + function to work with Argument Clinic, and then introduces + some advanced topics on Argument Clinic usage. + + Argument Clinic is currently considered an internal + tool for the CPython code tree. Its use is not supported + for files outside the CPython code tree, and no guarantees + are made regarding backwards compatibility for future + versions. In other words: if you maintain an external C + extension for CPython, you're welcome to experiment with + Argument Clinic in your own code. But the version of Argument + Clinic that ships with CPython 3.5 *could* be totally + incompatible and break all your code. + +======================== +Basic Concepts And Usage +======================== + +Argument Clinic ships with CPython. You can find it in ``Tools/clinic/clinic.py``. +If you run that script, specifying a C file as an argument:: + + % python3 Tools/clinic/clinic.py foo.c + +Argument Clinic will scan over the file looking for lines that +look exactly like this:: + + /*[clinic] + +When it finds one, it reads everything up to a line that looks +like this:: + + [clinic]*/ + +Everything in between these two lines is input for Argument Clinic. +All of these lines, including the beginning and ending comment +lines, are collectively called an Argument Clinic "input block", +or "block" for short. + +When Argument Clinic parses one of these blocks, it +generates output. This output is rewritten into the C file +immediately after the block, followed by a comment containing a checksum. +The resulting Argument Clinic block looks like this:: + + /*[clinic] + ... clinic input goes here ... + [clinic]*/ + ... clinic output goes here ... + /*[clinic checksum:...]*/ + +If you run Argument Clinic on the same file a second time, Argument Clinic +will discard the old output and write out the new output with a fresh checksum +line. However, if the input hasn't changed, the output won't change either. + +You should never modify the output portion of an Argument Clinic block. Instead, +change the input until it produces the output you want. (That's the purpose of the +checksum--to detect and warn you in case someone accidentally modifies the output.) + +For the sake of clarity, here's the terminology we'll use with Argument Clinic: + +* The first line of the comment (``/*[clinic]``) is the *start line*. +* The last line of the initial comment (``[clinic]*/``) is the *end line*. +* The last line (``/*[clinic checksum:...]*/``) is the *checksum line*. +* In between the start line and the end line is the *input*. +* In between the end line and the checksum line is the *output*. +* All the text collectively, from the start line to the checksum line inclusively, + is the *block*. (A block that hasn't been successfully processed by Argument + Clinic yet doesn't have output or a checksum line, but it's still considered + a block.) + + +============================== +Converting Your First Function +============================== + +The best way to get a sense of how Argument Clinic works is to +convert a function to work with it. Let's dive in! + +0. Make sure you're working with a freshly updated trunk. + +1. Find a Python builtin that calls either ``PyArg_ParseTuple()`` + or ``PyArg_ParseTupleAndKeywords()``, and hasn't been converted yet. + For my example I'm using ``pickle.Pickler.dump()``. + +2. If the call to the ``PyArg_Parse`` function uses any of the + following format units:: + + O& + O! + es + es# + et + et# + + or if it has multiple calls to ``PyArg_ParseTuple()``, + you should choose a different function. Argument Clinic *does* + support all of these scenarios. But these are advanced + topics--let's do something simpler for your first function. + +3. Add the following boilerplate above the function, creating our block:: + + /*[clinic] + [clinic]*/ + +4. Cut the docstring and paste it in between the ``[clinic]`` lines, + removing all the junk that makes it a properly quoted C string. + When you're done you should have just the text, based at the left + margin, with no line wider than 80 characters. + (Argument Clinic will preserve indents inside the docstring.) + + Sample:: + + /*[clinic] + Write a pickled representation of obj to the open file. + [clinic]*/ + +5. If your docstring doesn't have a "summary" line, Argument Clinic will + complain. So let's make sure it has one. The "summary" line should + be a paragraph consisting of a single 80-column line + at the beginning of the docstring. + + (Our docstring consists solely of the summary line, so the sample + code doesn't have to change for this step.) + +6. Above the docstring, enter the name of the function, followed + by a blank line. This should be the Python name of the function, + and should be the full dotted path + to the function--it should start with the name of the module, + include any sub-modules, and if the function is a method on + a class it should include the class name too. + + Sample:: + + /*[clinic] + pickle.Pickler.dump + + Write a pickled representation of obj to the open file. + [clinic]*/ + +7. If this is the first time that module or class has been used with Argument + Clinic in this C file, + you must declare the module and/or class. Proper Argument Clinic hygiene + prefers declaring these in a separate block somewhere near the + top of the C file, in the same way that include files and statics go at + the top. (In our sample code we'll just show the two blocks next to + each other.) + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + Write a pickled representation of obj to the open file. + [clinic]*/ + + +8. Declare each of the parameters to the function. Each parameter + should get its own line. All the parameter lines should be + indented from the function name and the docstring. + + The general form of these parameter lines is as follows:: + + name_of_parameter: converter + + If the parameter has a default value, add that after the + converter:: + + name_of_parameter: converter = default_value + + Add a blank line below the parameters. + + What's a "converter"? It establishes both the type + of the variable used in C, and the method to convert the Python + value into a C value at runtime. + For now you're going to use what's called a "legacy converter"--a + convenience syntax intended to make porting old code into Argument + Clinic easier. + + For each parameter, copy the "format unit" for that + parameter from the ``PyArg_Parse()`` format argument and + specify *that* as its converter, as a quoted + string. ("format unit" is the formal name for the one-to-three + character substring of the ``format`` parameter that tells + the argument parsing function what the type of the variable + is and how to convert it.) + + For multicharacter format units like ``z#``, use the + entire two-or-three character string. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + + Write a pickled representation of obj to the open file. + [clinic]*/ + +9. If your function has ``|`` in the format string, meaning some + parameters have default values, you can ignore it. Argument + Clinic infers which parameters are optional based on whether + or not they have default values. + + If your function has ``$`` in the format string, meaning it + takes keyword-only arguments, specify ``*`` on a line by + itself before the first keyword-only argument, indented the + same as the parameter lines. + + (``pickle.Pickler.dump`` has neither, so our sample is unchanged.) + + +10. If the existing C function uses ``PyArg_ParseTuple()`` + (instead of ``PyArg_ParseTupleAndKeywords()``), then all its + arguments are positional-only. + + To mark all parameters as positional-only in Argument Clinic, + add a ``/`` on a line by itself after the last parameter, + indented the same as the parameter lines. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + +11. It's helpful to write a per-parameter docstring, indented + another level past the parameter declaration. But per-parameter + docstrings are optional; you can skip this step if you prefer. + + Here's how per-parameter docstrings work. The first line + of the per-parameter docstring must be indented further than the + parameter definition. This left margin establishes the left margin + for the whole per-parameter docstring; all the text you write will + be outdented by this amount. You can write as much as you like, + across multiple lines if you wish. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + +12. Save and close the file, then run ``Tools/clinic/clinic.py`` on it. + With luck everything worked and your block now has output! Reopen + the file in your text editor to see:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + /*[clinic checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + + PyDoc_STRVAR(pickle_Pickler_dump__doc__, + "Write a pickled representation of obj to the open file.\n" + "\n" + ... + static PyObject * + pickle_Pickler_dump_impl(PyObject *self, PyObject *obj) + /*[clinic checksum: 3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/ + +13. Double-check that the argument-parsing code Argument Clinic generated + looks basically the same as the existing code. + + First, ensure both places use the same argument-parsing function. + The existing code must call either + ``PyArg_ParseTuple()`` or ``PyArg_ParseTupleAndKeywords()``; + ensure that the code generated by Argument Clinic calls the + same function. + + Second, the format string passed in to ``PyArg_ParseTuple()`` or + ``PyArg_ParseTupleAndKeywords()`` should be *exactly* the same + as the hand-written one in the existing function. + + Well, there's one way that Argument Clinic's output is permitted + to be different. Argument Clinic always generates a format string + ending with ``:`` followed by the name of the function. If the + format string originally ended with ``;`` (to specify usage help), + this is harmless--don't worry about this difference. + + Apart from that, if either of these things differ in *any way*, + fix your input to Argument Clinic and rerun ``Tools/clinic/clinic.py`` + until they are the same. + + +14. Notice that the last line of its output is the declaration + of your "impl" function. This is where the builtin's implementation goes. + Delete the existing prototype of the function you're modifying, but leave + the opening curly brace. Now delete its argument parsing code and the + declarations of all the variables it dumps the arguments into. + Notice how the Python arguments are now arguments to this impl function; + if the implementation used different names for these variables, fix it. + The result should be a function that handles just the implementation + of the Python function without any argument-parsing code. + + Sample:: + + /*[clinic] + module pickle + class pickle.Pickler + [clinic]*/ + /*[clinic checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + + /*[clinic] + pickle.Pickler.dump + + obj: 'O' + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + + PyDoc_STRVAR(pickle_Pickler_dump__doc__, + "Write a pickled representation of obj to the open file.\n" + "\n" + ... + static PyObject * + pickle_Pickler_dump_impl(PyObject *self, PyObject *obj) + /*[clinic checksum: 3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/ + { + /* Check whether the Pickler was initialized correctly (issue3664). + Developers often forget to call __init__() in their subclasses, which + would trigger a segfault without this check. */ + if (self->write == NULL) { + PyErr_Format(PicklingError, + "Pickler.__init__() was not called by %s.__init__()", + Py_TYPE(self)->tp_name); + return NULL; + } + + if (_Pickler_ClearBuffer(self) < 0) + return NULL; + + ... + +15. Compile and run the relevant portions of the regression-test suite. + This change should not introduce any new compile-time warnings or errors, + and there should be no externally-visible change to Python's behavior. + + Well, except for one difference: ``inspect.signature()`` run on your function + should now provide a valid signature! + + Congratulations, you've ported your first function to work with Argument Clinic! + +=============== +Advanced Topics +=============== + + +Renaming the C functions generated by Argument Clinic +----------------------------------------------------- + +Argument Clinic automatically names the functions it generates for you. +Occasionally this may cause a problem, if the generated name collides with +the name of an existing C function. There's an easy solution: you can explicitly +specify the base name to use for the C functions. Just add the keyword ``"as"`` +to your function declaration line, followed by the function name you wish to use. +Argument Clinic will use the function name you use for the base (generated) function, +and then add ``"_impl"`` to the end for the name of the impl function. + +For example, if we wanted to rename the C function names generated for +``pickle.Pickler.dump``, it'd look like this:: + + /*[clinic] + pickle.Pickler.dump as pickler_dumper + + ... + +The base function would now be named ``pickler_dumper()``, +and the impl function would be named ``pickler_dumper_impl()``. + + +Optional Groups +--------------- + +Some legacy functions have a tricky approach to parsing their arguments: +they count the number of positional arguments, then use a ``switch`` statement +to call one of several different ``PyArg_ParseTuple()`` calls depending on +how many positional arguments there are. (These functions cannot accept +keyword-only arguments.) This approach was used to simulate optional +arguments back before ``PyArg_ParseTupleAndKeywords()`` was created. + +Functions using this approach can often be converted to +use ``PyArg_ParseTupleAndKeywords()``, optional arguments, and default values. +But it's not always possible, because some of these legacy functions have +behaviors ``PyArg_ParseTupleAndKeywords()`` can't directly support. +The most obvious example is the builtin function ``range()``, which has +an optional argument on the *left* side of its required argument! +Another example is ``curses.window.addch()``, which has a group of two +arguments that must always be specified together. (The arguments are +called ``x`` and ``y``; if you call the function passing in ``x``, +you must also pass in ``y``--and if you don't pass in ``x`` you may not +pass in ``y`` either.) + +For the sake of backwards compatibility, Argument Clinic supports this +alternate approach to parsing, using what are called *optional groups*. +Optional groups are groups of arguments that can only be specified together. +They can be to the left or the right of the required arguments. They +can *only* be used with positional-only parameters. + +To specify an optional group, add a ``[`` on a line by itself before +the parameters you wish to be +in a group together, and a ``]`` on a line by itself after the +parameters. As an example, here's how ``curses.window.addch`` +uses optional groups to make the first two parameters and the last +parameter optional:: + + /*[clinic] + + curses.window.addch + + [ + x: int + X-coordinate. + y: int + Y-coordinate. + ] + + ch: object + Character to add. + + [ + attr: long + Attributes for the character. + ] + / + + ... + + +Notes: + +* For every optional group, one additional parameter will be passed into the + impl function representing the group. The parameter will be an int, and it will + be named ``group_{direction}_{number}``, + where ``{direction}`` is either ``right`` or ``left`` depending on whether the group + is before or after the required parameters, and ``{number}`` is a monotonically + increasing number (starting at 1) indicating how far away the group is from + the required parameters. When the impl is called, this parameter will be set + to zero if this group was unused, and set to non-zero if this group was used. + (By used or unused, I mean whether or not the parameters received arguments + in this invocation.) + +* If there are no required arguments, the optional groups will behave + as if they are to the right of the required arguments. + +* In the case of ambiguity, the argument parsing code + favors parameters on the left (before the required parameters). + +* Optional groups are *only* intended for legacy code. Please do not + use optional groups for new code. + + +Using real Argument Clinic converters, instead of "legacy converters" +--------------------------------------------------------------------- + +To save time, and to minimize how much you need to learn +to achieve your first port to Argument Clinic, the walkthrough above tells +you to use the "legacy converters". "Legacy converters" are a convenience, +designed explicitly to make porting existing code to Argument Clinic +easier. And to be clear, their use is entirely acceptable when porting +code for Python 3.4. + +However, in the long term we probably want all our blocks to +use Argument Clinic's real syntax for converters. Why? A couple +reasons: + +* The proper converters are far easier to read and clearer in their intent. +* There are some format units that are unsupported as "legacy converters", + because they require arguments, and the legacy converter syntax doesn't + support specifying arguments. +* In the future we may have a new argument parsing library that isn't + restricted to what ``PyArg_ParseTuple()`` supports. + +So if you want +to go that extra effort, you should consider using normal +converters instead of the legacy converters. + +In a nutshell, the syntax for Argument Clinic (non-legacy) converters +looks like a Python function call. However, if there are no explicit +arguments to the function (all functions take their default values), +you may omit the parentheses. Thus ``bool`` and ``bool()`` are exactly +the same. All parameters to Argument Clinic converters are keyword-only. + +All Argument Clinic converters accept the following arguments: + +``doc_default`` + If the parameter takes a default value, normally this value is also + provided in the ``inspect.Signature`` metadata, and displayed in the + docstring. ``doc_default`` lets you override the value used in these + two places: pass in a string representing the Python value you wish + to use in these two contexts. + +``required`` + If a parameter takes a default value, Argument Clinic infers that the + parameter is optional. However, you may want a parameter to take a + default value in C, but not behave in Python as if the parameter is + optional. Passing in ``required=True`` to a converter tells Argument + Clinic that this parameter is not optional, even if it has a default + value. + +``annotation`` + The annotation value for this parameter. Not currently supported, + because PEP 8 mandates that the Python library may not use + annotations. + +Below is a table showing the mapping of legacy converters into real +Argument Clinic converters. On the left is the legacy converter, +on the right is the text you'd replace it with. + +========= ================================================================================= +``'B'`` ``byte(bitwise=True)`` +``'b'`` ``byte`` +``'c'`` ``char`` +``'C'`` ``int(types='str')`` +``'d'`` ``double`` +``'D'`` ``Py_complex`` +``'es#'`` ``str(encoding='name_of_encoding', length=True, zeroes=True)`` +``'es'`` ``str(encoding='name_of_encoding')`` +``'et#'`` ``str(encoding='name_of_encoding', types='bytes bytearray str', length=True)`` +``'et'`` ``str(encoding='name_of_encoding', types='bytes bytearray str')`` +``'f'`` ``float`` +``'h'`` ``short`` +``'H'`` ``unsigned_short`` +``'i'`` ``int`` +``'I'`` ``unsigned_int`` +``'K'`` ``unsigned_PY_LONG_LONG`` +``'L'`` ``PY_LONG_LONG`` +``'n'`` ``Py_ssize_t`` +``'O!'`` ``object(type='name_of_Python_type')`` +``'O&'`` ``object(converter='name_of_c_function')`` +``'O'`` ``object`` +``'p'`` ``bool`` +``'s#'`` ``str(length=True)`` +``'S'`` ``PyBytesObject`` +``'s'`` ``str`` +``'s*'`` ``Py_buffer(types='str bytes bytearray buffer')`` +``'u#'`` ``Py_UNICODE(length=True)`` +``'u'`` ``Py_UNICODE`` +``'U'`` ``unicode`` +``'w*'`` ``Py_buffer(types='bytearray rwbuffer')`` +``'y#'`` ``str(type='bytes', length=True)`` +``'Y'`` ``PyByteArrayObject`` +``'y'`` ``str(type='bytes')`` +``'y*'`` ``Py_buffer`` +``'Z#'`` ``Py_UNICODE(nullable=True, length=True)`` +``'z#'`` ``str(nullable=True, length=True)`` +``'Z'`` ``Py_UNICODE(nullable=True)`` +``'z'`` ``str(nullable=True)`` +``'z*'`` ``Py_buffer(types='str bytes bytearray buffer', nullable=True)`` +========= ================================================================================= + +As an example, here's our sample ``pickle.Pickler.dump`` using the proper +converter:: + + /*[clinic] + pickle.Pickler.dump + + obj: object + The object to be pickled. + / + + Write a pickled representation of obj to the open file. + [clinic]*/ + +Argument Clinic will show you all the converters it has +available. For each converter it'll show you all the parameters +it accepts, along with the default value for each parameter. +Just run ``Tools/clinic/clinic.py --converters`` to see the full list. + + +Advanced converters +------------------- + +Remeber those format units you skipped for your first +time because they were advanced? Here's how to handle those too. + +The trick is, all those format units take arguments--either +conversion functions, or types, or strings specifying an encoding. +(But "legacy converters" don't support arguments. That's why we +skipped them for your first function.) The argument you specified +to the format unit is now an argument to the converter; this +argument is either ``converter`` (for ``O&``), ``type`` (for ``O!``), +or ``encoding`` (for all the format units that start with ``e``). + +Note that ``object()`` must explicitly support each Python type you specify +for the ``type`` argument. Currently it only supports ``str``. It should be +easy to add more, just edit ``Tools/clinic/clinic.py``, search for ``O!`` in +the text, and add more entries to the dict mapping types to strings just above it. + +Note also that this approach takes away some possible flexibility for the format +units starting with ``e``. It used to be possible to decide at runtime what +encoding string to pass in to ``PyArg_ParseTuple()``. But now this string must +be hard-coded at compile-time. This limitation is deliberate; it made supporting +this format unit much easier, and may allow for future compile-time optimizations. +This restriction does not seem unreasonable; CPython itself always passes in static +hard-coded strings when using format units starting with ``e``. + + +Using a return converter +------------------------ + +By default the impl function Argument Clinic generates for you returns ``PyObject *``. +But your C function often computes some C type, then converts it into the ``PyObject *`` +at the last moment. Argument Clinic handles converting your inputs from Python types +into native C types--why not have it convert your return value from a native C type +into a Python type too? + +That's what a "return converter" does. It changes your impl function to return +some C type, then adds code to the generated (non-impl) function to handle converting +that value into the appropriate ``PyObject *``. + +The syntax for return converters is similar to that of parameter converters. +You specify the return converter like it was a return annotation on the +function itself. Return converters behave much the same as parameter converters; +they take arguments, the arguments are all keyword-only, and if you're not changing +any of the default arguments you can omit the parentheses. + +(If you use both ``"as"`` *and* a return converter for your function, +the ``"as"`` should come before the return converter.) + +There's one additional complication when using return converters: how do you +indicate an error has occured? Normally, a function returns a valid (non-``NULL``) +pointer for success, and ``NULL`` for failure. But if you use an integer return converter, +all integers are valid. How can Argument Clinic detect an error? Its solution: each return +converter implicitly looks for a special value that indicates an error. If you return +that value, and an error has been set (``PyErr_Occurred()`` returns a true +value), then the generated code will propogate the error. Otherwise it will +encode the value you return like normal. + +Currently Argument Clinic supports only a few return converters:: + + int + long + Py_ssize_t + DecodeFSDefault + +None of these take parameters. For the first three, return -1 to indicate +error. For ``DecodeFSDefault``, the return type is ``char *``; return a NULL +pointer to indicate an error. + +Calling Python code +------------------- + +The rest of the advanced topics require you to write Python code +which lives inside your C file and modifies Argument Clinic at +runtime. This is simple; you simply define a Python block. + +A Python block uses different delimiter lines than an Argument +Clinic function block. It looks like this:: + + /*[python] + # python code goes here + [python]*/ + +All the code inside the Python block is executed at the +time it's parsed. All text written to stdout inside the block +is redirected into the "output" after the block. + +As an example, here's a Python block that adds a static integer +variable to the C code:: + + /*[python] + print('static int __ignored_unused_variable__ = 0;') + [python]*/ + static int __ignored_unused_variable__ = 0; + /*[python checksum:...]*/ + + +Using a "self converter" +------------------------ + +Argument Clinic automatically adds a "self" parameter for you +using a default converter. However, you can override +Argument Clinic's converter and specify one yourself. +Just add your own ``self`` parameter as the first parameter in a +block, and ensure that its converter is an instance of +``self_converter`` or a subclass thereof. + +What's the point? This lets you automatically cast ``self`` +from ``PyObject *`` to a custom type. + +How do you specify the custom type you want to cast ``self`` to? +If you only have one or two functions with the same type for ``self``, +you can directly use Argument Clinic's existing ``self`` converter, +passing in the type you want to use as the ``type`` parameter:: + + /*[clinic] + + _pickle.Pickler.dump + + self: self(type="PicklerObject *") + obj: object + / + + Write a pickled representation of the given object to the open file. + [clinic]*/ + +On the other hand, if you have a lot of functions that will use the same +type for ``self``, it's best to create your own converter, subclassing +``self_converter`` but overwriting the ``type`` member:: + + /*[clinic] + class PicklerObject_converter(self_converter): + type = "PicklerObject *" + [clinic]*/ + + /*[clinic] + + _pickle.Pickler.dump + + self: PicklerObject + obj: object + / + + Write a pickled representation of the given object to the open file. + [clinic]*/ + + + +Writing a custom converter +-------------------------- + +As we hinted at in the previous section... you can write your own converters! +A converter is simply a Python class that inherits from ``CConverter``. +The main purpose of a custom converter is if you have a parameter using +the ``O&`` format unit--parsing this parameter means calling +a ``PyArg_ParseTuple()`` "converter function". + +Your converter class should be named ``*something*_converter``. +If the name follows this convention, then your converter class +will be automatically registered with Argument Clinic; its name +will be the name of your class with the ``_converter`` suffix +stripped off. (This is done automatically for you with a metaclass.) + +You shouldn't subclass ``CConverter.__init__``. Instead, you should +write a ``converter_init()`` function. ``converter_init()`` +always accepts a ``self`` parameter; after that, all additional +parameters *must* be keyword-only. Any arguments passed in to +the converter in Argument Clinic will be passed along to your +``converter_init()``. + +There are some additional members of ``CConverter`` you may wish +to specify in your subclass. Here's the current list: + +``type`` + The C type to use for this variable. + ``type`` should be a Python string specifying the type, e.g. ``int``. + If this is a pointer type, the type string should end with ``' *'``. + +``default`` + The Python default value for this parameter, as a Python value. + Or the magic value ``unspecified`` if there is no default. + +``doc_default`` + ``default`` as it should appear in the documentation, + as a string. + Or ``None`` if there is no default. + This string, when run through ``eval()``, should produce + a Python value. + +``py_default`` + ``default`` as it should appear in Python code, + as a string. + Or ``None`` if there is no default. + +``c_default`` + ``default`` as it should appear in C code, + as a string. + Or ``None`` if there is no default. + +``c_ignored_default`` + The default value used to initialize the C variable when + there is no default, but not specifying a default may + result in an "uninitialized variable" warning. This is + easily happen when using option groups--although + properly-written code won't actually use the variable, + the variable does get passed in to the _impl, and the + C compiler will complain about the "use" of the uninitialized + value. This value should be a string. + +``converter`` + The name of the C converter function, as a string. + +``impl_by_reference`` + A boolean value. If true, + Argument Clinic will add a ``&`` in front of the name of + the variable when passing it into the impl function. + +``parse_by_reference`` + A boolean value. If true, + Argument Clinic will add a ``&`` in front of the name of + the variable when passing it into ``PyArg_ParseTuple()``. + + +Here's the simplest example of a custom converter, from ``Modules/zlibmodule.c``:: + + /*[python] + + class uint_converter(CConverter): + type = 'unsigned int' + converter = 'uint_converter' + + [python]*/ + /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + +This block adds a ``uint`` converter to Argument Clinic. Parameters +declared as ``uint`` will be declared as type ``unsigned int``, and will +be parsed by calling the ``uint_converter`` converter function in C. +``uint`` variables automatically support default values. + +More sophisticated custom converters can insert custom C code to +handle initialization and cleanup. +You can see more examples of custom converters in the CPython +source tree; grep the C files for the string ``CConverter``. + +Writing a custom return converter +--------------------------------- + +Writing a custom return converter is much like writing +a custom converter. Except it's much simpler, because return +converters are themselves much simpler. + +Return converters must subclass ``CReturnConverter``. +There are no examples yet of custom return converters, +because they are not widely used yet. If you wish to +write your own return converter, please read ``Tools/clinic/clinic.py``, +specifically the implementation of ``CReturnConverter`` and +all its subclasses. + + +Using Argument Clinic in Python files +------------------------------------- + +It's actually possible to use Argument Clinic to preprocess Python files. +There's no point to using Argument Clinic blocks, of course, as the output +wouldn't make any sense to the Python interpreter. But using Argument Clinic +to run Python blocks lets you use Python as a Python preprocessor! + +Since Python comments are different from C comments, Argument Clinic +blocks embedded in Python files look slightly different. They look like this:: + + #/*[python] + #print("def foo(): pass") + #[python]*/ + def foo(): pass + #/*[python checksum:...]*/ diff --git a/Doc/howto/index.rst b/Doc/howto/index.rst --- a/Doc/howto/index.rst +++ b/Doc/howto/index.rst @@ -28,4 +28,5 @@ webservers.rst argparse.rst ipaddress.rst + clinic.rst diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -343,6 +343,8 @@ Tools/Demos ----------- +- Issue #19659: Added documentation for Argument Clinic. + - Issue #19976: Argument Clinic METH_NOARGS functions now always take two parameters. diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -312,9 +312,6 @@ type = 'unsigned int' converter = 'uint_converter' -class compobject_converter(self_converter): - type = "compobject *" - [python]*/ /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ @@ -750,7 +747,7 @@ zlib.Decompress.decompress - self: compobject + self: self(type="compobject *") data: Py_buffer The binary data to decompress. @@ -1032,7 +1029,7 @@ /*[clinic] zlib.Compress.copy - self: compobject + self: self(type="compobject *") Return a copy of the compression object. [clinic]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1296,11 +1296,13 @@ must be keyword-only. """ + # The C type to use for this variable. + # 'type' should be a Python string specifying the type, e.g. "int". + # If this is a pointer type, the type string should end with ' *'. type = None - format_unit = 'O&' # The Python default value for this parameter, as a Python value. - # Or "unspecified" if there is no default. + # Or the magic value "unspecified" if there is no default. default = unspecified # "default" as it should appear in the documentation, as a string. @@ -1330,9 +1332,32 @@ # (If this is not None, format_unit must be 'O&'.) converter = None + # Should Argument Clinic add a '&' before the name of + # the variable when passing it into the _impl function? + impl_by_reference = False + + # Should Argument Clinic add a '&' before the name of + # the variable when passing it into PyArg_ParseTuple (AndKeywords)? + parse_by_reference = True + + ############################################################# + ############################################################# + ## You shouldn't need to read anything below this point to ## + ## write your own converter functions. ## + ############################################################# + ############################################################# + + # The "format unit" to specify for this variable when + # parsing arguments using PyArg_ParseTuple (AndKeywords). + # Custom converters should always use the default value of 'O&'. + format_unit = 'O&' + + # What encoding do we want for this variable? Only used + # by format units starting with 'e'. encoding = None - impl_by_reference = False - parse_by_reference = True + + # Do we want an adjacent '_length' variable for this variable? + # Only used by format units ending with '#'. length = False def __init__(self, name, function, default=unspecified, *, doc_default=None, required=False, annotation=unspecified, **kwargs): @@ -1751,7 +1776,7 @@ this is the default converter used for "self". """ type = "PyObject *" - def converter_init(self): + def converter_init(self, *, type=None): f = self.function if f.kind == CALLABLE: if f.cls: @@ -1766,6 +1791,9 @@ self.name = "cls" self.type = "PyTypeObject *" + if type: + self.type = type + def render(self, parameter, data): fail("render() should never be called on self_converter instances") @@ -1787,7 +1815,13 @@ class CReturnConverter(metaclass=CReturnConverterAutoRegister): + # The C type to use for this variable. + # 'type' should be a Python string specifying the type, e.g. "int". + # If this is a pointer type, the type string should end with ' *'. type = 'PyObject *' + + # The Python default value for this parameter, as a Python value. + # Or the magic value "unspecified" if there is no default. default = None def __init__(self, *, doc_default=None, **kwargs): @@ -1826,6 +1860,16 @@ add_c_return_converter(CReturnConverter, 'object') +class NoneType_return_converter(CReturnConverter): + def render(self, function, data): + self.declare(data) + data.return_conversion.append(''' +if (_return_value != Py_None) + goto exit; +return_value = Py_None; +Py_INCREF(Py_None); +'''.strip()) + class int_return_converter(CReturnConverter): type = 'int' @@ -2680,7 +2724,7 @@ # print(" ", short_name + "".join(parameters)) print() - print("All converters also accept (doc_default=None, required=False).") + print("All converters also accept (doc_default=None, required=False, annotation=None).") print("All return converters also accept (doc_default=None).") sys.exit(0) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 23:13:51 2014 From: python-checkins at python.org (eric.snow) Date: Sat, 4 Jan 2014 23:13:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319927=3A_Add_=5F?= =?utf-8?q?=5Feq=5F=5F_to_path-based_loaders_in_importlib=2E?= Message-ID: <3dxchH3dVxz7LmP@mail.python.org> http://hg.python.org/cpython/rev/a72a0e4dad20 changeset: 88299:a72a0e4dad20 user: Eric Snow date: Sat Jan 04 15:06:49 2014 -0700 summary: Issue #19927: Add __eq__ to path-based loaders in importlib. files: Lib/importlib/_bootstrap.py | 14 + Lib/test/test_importlib/extension/test_loader.py | 9 + Lib/test/test_importlib/source/test_file_loader.py | 13 + Lib/test/test_importlib/test_api.py | 3 +- Misc/NEWS | 2 + Python/importlib.h | 1278 +++++---- 6 files changed, 698 insertions(+), 621 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1559,6 +1559,13 @@ self.name = fullname self.path = path + def __eq__(self, other): + return (self.__class__ == other.__class__ and + self.__dict__ == other.__dict__) + + def __hash__(self): + return hash(self.name) ^ hash(self.path) + @_check_name def load_module(self, fullname): """Load a module from a file.""" @@ -1653,6 +1660,13 @@ self.name = name self.path = path + def __eq__(self, other): + return (self.__class__ == other.__class__ and + self.__dict__ == other.__dict__) + + def __hash__(self): + return hash(self.name) ^ hash(self.path) + @_check_name def load_module(self, fullname): """Load an extension module.""" diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py --- a/Lib/test/test_importlib/extension/test_loader.py +++ b/Lib/test/test_importlib/extension/test_loader.py @@ -28,6 +28,15 @@ with self.assertRaises(ImportError): self.load_module('XXX') + def test_equality(self): + other = self.machinery.ExtensionFileLoader(ext_util.NAME, + ext_util.FILEPATH) + self.assertEqual(self.loader, other) + + def test_inequality(self): + other = self.machinery.ExtensionFileLoader('_' + ext_util.NAME, + ext_util.FILEPATH) + self.assertNotEqual(self.loader, other) def test_module(self): with util.uncache(ext_util.NAME): diff --git a/Lib/test/test_importlib/source/test_file_loader.py b/Lib/test/test_importlib/source/test_file_loader.py --- a/Lib/test/test_importlib/source/test_file_loader.py +++ b/Lib/test/test_importlib/source/test_file_loader.py @@ -27,6 +27,11 @@ """ + def setUp(self): + self.name = 'spam' + self.filepath = os.path.join('ham', self.name + '.py') + self.loader = self.machinery.SourceFileLoader(self.name, self.filepath) + def test_load_module_API(self): class Tester(self.abc.FileLoader): def get_source(self, _): return 'attr = 42' @@ -53,6 +58,14 @@ with self.assertRaises(ImportError): loader.get_filename(name + 'XXX') + def test_equality(self): + other = self.machinery.SourceFileLoader(self.name, self.filepath) + self.assertEqual(self.loader, other) + + def test_inequality(self): + other = self.machinery.SourceFileLoader('_' + self.name, self.filepath) + self.assertNotEqual(self.loader, other) + # [basic] def test_module(self): with source_util.create_modules('_temp') as mapping: diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -288,8 +288,7 @@ self.assertNotIn(name, sorted(sys.modules)) # Ensure successive calls behave the same. spec_again = self.init.find_spec(fullname, [pkg_dir]) - # XXX Once #19927 is resolved, uncomment this line. - #self.assertEqual(spec_again, spec) + self.assertEqual(spec_again, spec) def test_find_submodule_missing_path(self): name = 'spam' diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -203,6 +203,8 @@ no exception detail exists (no colon following the exception's name, or a colon does follow but no text follows the colon). +- Issue #19927: Add __eq__ to path-based loaders in importlib. + - Issue #19827: On UNIX, setblocking() and settimeout() methods of socket.socket can now avoid a second syscall if the ioctl() function can be used, or if the non-blocking flag of the socket is unchanged. diff --git a/Python/importlib.h b/Python/importlib.h --- a/Python/importlib.h +++ b/Python/importlib.h [stripped] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 23:13:52 2014 From: python-checkins at python.org (eric.snow) Date: Sat, 4 Jan 2014 23:13:52 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319713=3A_Move_awa?= =?utf-8?q?y_from_using_find=5Fmodule/load=5Fmodule=2E?= Message-ID: <3dxchJ5XcSz7LmX@mail.python.org> http://hg.python.org/cpython/rev/a18c1a4cf30a changeset: 88300:a18c1a4cf30a user: Eric Snow date: Sat Jan 04 15:09:28 2014 -0700 summary: Issue #19713: Move away from using find_module/load_module. files: Lib/test/test_tools.py | 9 +++++---- Misc/NEWS | 2 ++ setup.py | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_tools.py b/Lib/test/test_tools.py --- a/Lib/test/test_tools.py +++ b/Lib/test/test_tools.py @@ -6,6 +6,7 @@ import os import sys +import importlib._bootstrap import importlib.machinery import unittest from unittest import mock @@ -405,8 +406,8 @@ @classmethod def setUpClass(self): path = os.path.join(scriptsdir, 'pdeps.py') - loader = importlib.machinery.SourceFileLoader('pdeps', path) - self.pdeps = loader.load_module() + spec = importlib.util.spec_from_file_location('pdeps', path) + self.pdeps = importlib._bootstrap._SpecMethods(spec).load() @classmethod def tearDownClass(self): @@ -430,8 +431,8 @@ def setUp(self): path = os.path.join(scriptsdir, 'gprof2html.py') - loader = importlib.machinery.SourceFileLoader('gprof2html', path) - self.gprof = loader.load_module() + spec = importlib.util.spec_from_file_location('gprof2html', path) + self.gprof = importlib._bootstrap._SpecMethods(spec).load() oldargv = sys.argv def fixup(): sys.argv = oldargv diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -255,6 +255,8 @@ - Issue #6477: Added support for pickling the types of built-in singletons (i.e., Ellipsis, NotImplemented, None). +- Issue #19713: Move away from using find_module/load_module. + - Issue #19851: Fixed a regression in reloading sub-modules. - ssl.create_default_context() sets OP_NO_COMPRESSION to prevent CRIME. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -3,6 +3,8 @@ import sys, os, importlib.machinery, re, optparse from glob import glob +import importlib._bootstrap +import importlib.util import sysconfig from distutils import log @@ -327,8 +329,10 @@ return loader = importlib.machinery.ExtensionFileLoader(ext.name, ext_filename) + spec = importlib.util.spec_from_file_location(ext.name, ext_filename, + loader=loader) try: - loader.load_module() + importlib._bootstrap._SpecMethods(spec).load() except ImportError as why: self.failed.append(ext.name) self.announce('*** WARNING: renaming "%s" since importing it' -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Jan 4 23:13:54 2014 From: python-checkins at python.org (eric.snow) Date: Sat, 4 Jan 2014 23:13:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319708=3A_Update_p?= =?utf-8?q?kgutil_to_use_the_new_importer_APIs=2E?= Message-ID: <3dxchL1VN3z7Lmr@mail.python.org> http://hg.python.org/cpython/rev/acebe574ab08 changeset: 88301:acebe574ab08 user: Eric Snow date: Sat Jan 04 15:09:53 2014 -0700 summary: Issue #19708: Update pkgutil to use the new importer APIs. files: Lib/pkgutil.py | 20 ++++++++++++++++++-- Lib/test/test_pkgutil.py | 25 ++++++++++++------------- Misc/NEWS | 2 ++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -16,6 +16,21 @@ 'ImpImporter', 'ImpLoader', 'read_code', 'extend_path', ] + +def _get_spec(finder, name): + """Return the finder-specific module spec.""" + # Works with legacy finders. + try: + find_spec = finder.find_spec + except AttributeError: + loader = finder.find_module(name) + if loader is None: + return None + return importlib.util.spec_from_loader(name, loader) + else: + return find_spec(name) + + def read_code(stream): # This helper is needed in order for the PEP 302 emulation to # correctly handle compiled files @@ -326,9 +341,10 @@ self.source = self._get_delegate().get_source() return self.source - def _get_delegate(self): - return ImpImporter(self.filename).find_module('__init__') + finder = ImpImporter(self.filename) + spec = _get_spec(finder, '__init__') + return spec.loader def get_filename(self, fullname=None): fullname = self._fix_name(fullname) diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py --- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -2,6 +2,7 @@ import unittest import sys import importlib +from importlib.util import spec_from_file_location import pkgutil import os import os.path @@ -103,23 +104,20 @@ class PkgutilPEP302Tests(unittest.TestCase): class MyTestLoader(object): - def load_module(self, fullname): - # Create an empty module - mod = sys.modules.setdefault(fullname, types.ModuleType(fullname)) - mod.__file__ = "<%s>" % self.__class__.__name__ - mod.__loader__ = self - # Make it a package - mod.__path__ = [] + def exec_module(self, mod): # Count how many times the module is reloaded - mod.__dict__['loads'] = mod.__dict__.get('loads',0) + 1 - return mod + mod.__dict__['loads'] = mod.__dict__.get('loads', 0) + 1 def get_data(self, path): return "Hello, world!" class MyTestImporter(object): - def find_module(self, fullname, path=None): - return PkgutilPEP302Tests.MyTestLoader() + def find_spec(self, fullname, path=None, target=None): + loader = PkgutilPEP302Tests.MyTestLoader() + return spec_from_file_location(fullname, + '<%s>' % loader.__class__.__name__, + loader=loader, + submodule_search_locations=[]) def setUp(self): sys.meta_path.insert(0, self.MyTestImporter()) @@ -210,7 +208,8 @@ importers = list(iter_importers(fullname)) expected_importer = get_importer(pathitem) for finder in importers: - loader = finder.find_module(fullname) + spec = pkgutil._get_spec(finder, fullname) + loader = spec.loader try: loader = loader.loader except AttributeError: @@ -221,7 +220,7 @@ self.assertEqual(finder, expected_importer) self.assertIsInstance(loader, importlib.machinery.SourceFileLoader) - self.assertIsNone(finder.find_module(pkgname)) + self.assertIsNone(pkgutil._get_spec(finder, pkgname)) with self.assertRaises(ImportError): list(iter_importers('invalid.module')) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -257,6 +257,8 @@ - Issue #19713: Move away from using find_module/load_module. +- Issue #19708: Update pkgutil to use the new importer APIs. + - Issue #19851: Fixed a regression in reloading sub-modules. - ssl.create_default_context() sets OP_NO_COMPRESSION to prevent CRIME. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 00:29:40 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 00:29:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_Mock_mock=5Fop?= =?utf-8?q?en_readline=28s=29=3B_expand_description_of_subtests_feature=2E?= Message-ID: <3dxfMm3Qrxz7LnN@mail.python.org> http://hg.python.org/cpython/rev/28f7e08a6a87 changeset: 88302:28f7e08a6a87 user: R David Murray date: Fri Jan 03 23:31:54 2014 -0500 summary: whatsnew: Mock mock_open readline(s); expand description of subtests feature. files: Doc/whatsnew/3.4.rst | 26 ++++++++++++++++++++++---- 1 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -759,6 +759,9 @@ or name, instead of only by position. (Contributed by Antoine Pitrou in :issue:`17015`.) +:func:`~mock.mock_open` objects now have ``readline`` and ``readlines`` +methods. (Contributed by Toshio Kuratomi in :issue:`17467`.) + multiprocessing --------------- @@ -1010,11 +1013,26 @@ unittest -------- -Support for easy dynamically-generated subtests using the -:meth:`~unittest.TestCase.subTest` context manager. -(Contributed by Antoine Pitrou in :issue:`16997`.) +The :class:`~unittest.TestCase` class has a new method, +:meth:`~unittest.TestCase.subTest`, that produces a context manager whose +:keyword:`with` block becomes a "sub-test". This context manager allows a test +method to dynamically generate subtests by, say, calling the ``subTest`` +context manager inside a loop. A single test method can thereby produce an +indefinite number of separately-identified and separately-counted tests, all of +which will run even if one or more of them fail. For example:: -:func:`unittest.main` now also accepts an iterable of test names for + class NumbersTest(unittest.TestCase): + def test_even(self): + for i in range(6): + with self.subTest(i=1): + self.assertEqual(i % 2, 0) + +will result in six subtests, each identified in the unittest verbose output +with a label consisting of the variable name ``i`` and a particular value for +that variable (``i=0``, ``i=1``, etc). See :ref:`subtests` for the full +version of this example. (Contributed by Antoine Pitrou in :issue:`16997`.) + +:func:`unittest.main` now accepts an iterable of test names for *defaultTest*, where previously it only accepted a single test name as a string. (Contributed by Jyrki Pulliainen in :issue:`15132`.) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 00:29:41 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 00:29:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_ppring_string_?= =?utf-8?q?wrapping=2C_string_pickling_optimization=2E?= Message-ID: <3dxfMn5Kfgz7LnJ@mail.python.org> http://hg.python.org/cpython/rev/d0c710d34927 changeset: 88303:d0c710d34927 user: R David Murray date: Sat Jan 04 17:11:23 2014 -0500 summary: whatsnew: ppring string wrapping, string pickling optimization. Also clarify some NEWS entries. files: Doc/whatsnew/3.4.rst | 7 +++++++ Misc/NEWS | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -847,6 +847,9 @@ The :mod:`pprint` module now supports *compact* mode for formatting long sequences (:issue:`19132`). +Long strings are now wrapped using Python's normal line continuation +syntax (Contributed by Antoine Pitrou in :issue:`17150`.) + pty --- @@ -1259,6 +1262,10 @@ * :func:`random.getrandbits` is 20%-40% faster for small integers (the most common use case). (Contributed by Serhiy Storchaka in :issue:`16674`). +* By taking advantage of the new storage format for strings, pickling of + strings is now significantly faster. (Contributed by Victor Stinner and + Antoine Pitrou in :issue:`15596`.) + Deprecated diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2282,7 +2282,7 @@ - Issue #15596: Faster pickling of unicode strings. -- Issue #17572: Avoid chained exceptions while passing bad directives to +- Issue #17572: Avoid chained exceptions when passing bad directives to time.strptime(). Initial patch by Claudiu Popa. - Issue #17435: threading.Timer's __init__ method no longer uses mutable @@ -2291,7 +2291,7 @@ - Issue #17526: fix an IndexError raised while passing code without filename to inspect.findsource(). Initial patch by Tyler Doyle. -- Issue #17540: Added style to formatter configuration by dict. +- Issue #17540: Added style parameter to logging formatter configuration by dict. - Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele Orr?. @@ -2312,10 +2312,10 @@ - Issue #17521: Corrected non-enabling of logger following two calls to fileConfig(). -- Issue #17508: Corrected MemoryHandler configuration in dictConfig() where - the target handler wasn't configured first. - -- Issue #17209: curses.window.get_wch() now handles correctly KeyboardInterrupt +- Issue #17508: Corrected logging MemoryHandler configuration in dictConfig() + where the target handler wasn't configured first. + +- Issue #17209: curses.window.get_wch() now correctly handles KeyboardInterrupt (CTRL+c). - Issue #5713: smtplib now handles 421 (closing connection) error codes when -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 00:29:43 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 00:29:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_from_=5F=5Ffut?= =?utf-8?q?ure=5F=5F_string_exception=2C_attribute_UTF-32_decoder_speedup?= =?utf-8?q?=2E?= Message-ID: <3dxfMq05SBz7Lmw@mail.python.org> http://hg.python.org/cpython/rev/87decd548a56 changeset: 88304:87decd548a56 user: R David Murray date: Sat Jan 04 18:07:20 2014 -0500 summary: whatsnew: from __future__ string exception, attribute UTF-32 decoder speedup. And more news entry clarifications. files: Doc/whatsnew/3.4.rst | 9 ++++++++- Misc/NEWS | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1234,7 +1234,8 @@ Significant Optimizations ========================= -* The UTF-32 decoder is now 3x to 4x faster. +* The UTF-32 decoder is now 3x to 4x faster. (Contributed by Serhiy Storchaka + in :issue:`14625`.) * The cost of hash collisions for sets is now reduced. Each hash table probe now checks a series of consecutive, adjacent key/hash pairs before @@ -1437,6 +1438,12 @@ keyword. If you've been paying attention to deprecation warnings your code should already be specifying any additional arguments via keywords. +* Strings between ``from __future__ import ...`` statements now *always* raise + a :exc:`SyntaxError`. Previously if there was no leading docstring, an + interstitial string would sometimes be ignored. This brings CPython into + compliance with the language spec; Jython and PyPy already were. + (:issue:`17434`). + Changes in the C API -------------------- diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2243,10 +2243,10 @@ calls. - Issue #17566: Make importlib.abc.Loader.module_repr() optional instead of an - abstractmethod and raising NotImplementedError so as to be ignored by default. - -- Issue #17678: Remove the use of deprecated method in http/cookiejar.py. - Changing the usage of get_origin_req_host() to origin_req_host. + abstractmethod; now it raises NotImplementedError so as to be ignored by default. + +- Issue #17678: Remove the use of deprecated method in http/cookiejar.py by + changing the call to get_origin_req_host() to origin_req_host. - Issue #17666: Fix reading gzip files with an extra field. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 02:33:03 2014 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 5 Jan 2014 02:33:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_fix_release_date?= Message-ID: <3dxj6713q6z7LkS@mail.python.org> http://hg.python.org/peps/rev/3143c88f23ce changeset: 5335:3143c88f23ce user: Benjamin Peterson date: Sat Jan 04 19:32:54 2014 -0600 summary: fix release date files: pep-0373.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0373.txt b/pep-0373.txt --- a/pep-0373.txt +++ b/pep-0373.txt @@ -71,7 +71,7 @@ - 2.7.4 2013-04-06 - 2.7.5 2013-05-12 - 2.7.6rc1 2013-10-26 -- 2.7.6 2012-11-10 +- 2.7.6 2013-11-10 Possible features for 2.7 -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sun Jan 5 03:18:29 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 03:18:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_logging_TimedR?= =?utf-8?q?otatingFileHandler_atTime_parameter=2E?= Message-ID: <3dxk6Y17sDz7Ljm@mail.python.org> http://hg.python.org/cpython/rev/1eb10bbebe79 changeset: 88305:1eb10bbebe79 user: R David Murray date: Sat Jan 04 18:55:01 2014 -0500 summary: whatsnew: logging TimedRotatingFileHandler atTime parameter. files: Doc/whatsnew/3.4.rst | 8 ++++++++ Misc/NEWS | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -730,6 +730,14 @@ :issue:`19030`) +logging +------- + +The :class:`~logging.handlers.TimedRotatingFileHandler` has a new *atTime* +parameter that can be used to specify the time of day when rollover should +happen. (Contributed by Ronald Oussoren in :issue:`9556`.) + + .. _whatsnew-marshal-3: marshal diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2226,8 +2226,8 @@ - Issue #16658: add missing return to HTTPConnection.send() Patch by Jeff Knupp. -- Issue #9556: Allowed specifying a time-of-day for a TimedRotatingFileHandler - to rotate. +- Issue #9556: the logging package now allows specifying a time-of-day for a + TimedRotatingFileHandler to rotate. - Issue #14971: unittest test discovery no longer gets confused when a function has a different __name__ than its name in the TestCase class dictionary. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 03:18:30 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 03:18:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_removal_of_TYP?= =?utf-8?q?E=5FINT64_from_marshal=2E?= Message-ID: <3dxk6Z2zz1z7Lms@mail.python.org> http://hg.python.org/cpython/rev/6d72617cae64 changeset: 88306:6d72617cae64 user: R David Murray date: Sat Jan 04 21:17:52 2014 -0500 summary: whatsnew: removal of TYPE_INT64 from marshal. Also update news entry for SMTPException; when I changed it from IOError to OSError I forgot to update the news item. files: Doc/whatsnew/3.4.rst | 3 +++ Misc/NEWS | 2 +- 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1373,6 +1373,9 @@ ``get_selector``, ``set_proxy``, ``get_origin_req_host``, and ``is_unverifiable`` have been removed (use direct attribute access instead). +* Support for loading the deprecated ``TYPE_INT64`` has been removed from + :mod:`marshal`. (Contributed by Dan Riti in :issue:`15480`.) + Porting to Python 3.4 diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2218,7 +2218,7 @@ - Issue #15480: Remove the deprecated and unused TYPE_INT64 code from marshal. Initial patch by Daniel Riti. -- Issue #2118: SMTPException is now a subclass of IOError. +- Issue #2118: SMTPException is now a subclass of OSError. - Issue #17016: Get rid of possible pointer wraparounds and integer overflows in the re module. Patch by Nickolai Zeldovich. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 04:58:40 2014 From: python-checkins at python.org (eric.snow) Date: Sun, 5 Jan 2014 04:58:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_20123=3A_Fix_pydoc?= =?utf-8?b?LnN5bm9wc2lzKCkgZm9yICJiaW5hcnkiIG1vZHVsZXMu?= Message-ID: <3dxmL81pS9z7Lp4@mail.python.org> http://hg.python.org/cpython/rev/d6c3fb8d5f84 changeset: 88307:d6c3fb8d5f84 user: Eric Snow date: Sat Jan 04 20:38:11 2014 -0700 summary: Issue 20123: Fix pydoc.synopsis() for "binary" modules. Also add missing tests to test_pydoc. files: Lib/pydoc.py | 46 +++++++++++++------------- Lib/test/test_pydoc.py | 52 ++++++++++++++++++++++++++++++ Misc/NEWS | 2 + 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -225,34 +225,34 @@ mtime = os.stat(filename).st_mtime lastupdate, result = cache.get(filename, (None, None)) if lastupdate is None or lastupdate < mtime: - try: - file = tokenize.open(filename) - except OSError: - # module can't be opened, so skip it - return None - binary_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:] - binary_suffixes += importlib.machinery.EXTENSION_SUFFIXES[:] - if any(filename.endswith(x) for x in binary_suffixes): - # binary modules have to be imported - file.close() - if any(filename.endswith(x) for x in - importlib.machinery.BYTECODE_SUFFIXES): - loader = importlib.machinery.SourcelessFileLoader('__temp__', - filename) - else: - loader = importlib.machinery.ExtensionFileLoader('__temp__', - filename) + # Look for binary suffixes first, falling back to source. + if filename.endswith(tuple(importlib.machinery.BYTECODE_SUFFIXES)): + loader_cls = importlib.machinery.SourcelessFileLoader + elif filename.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)): + loader_cls = importlib.machinery.ExtensionFileLoader + else: + loader_cls = None + # Now handle the choice. + if loader_cls is None: + # Must be a source file. + try: + file = tokenize.open(filename) + except OSError: + # module can't be opened, so skip it + return None + # text modules can be directly examined + with file: + result = source_synopsis(file) + else: + # Must be a binary module, which has to be imported. + loader = loader_cls('__temp__', filename) try: module = loader.load_module('__temp__') except: return None + del sys.modules['__temp__'] result = (module.__doc__ or '').splitlines()[0] - del sys.modules['__temp__'] - else: - # text modules can be directly examined - result = source_synopsis(file) - file.close() - + # Cache the result. cache[filename] = (mtime, result) return result diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -487,6 +487,13 @@ synopsis = pydoc.synopsis(TESTFN, {}) self.assertEqual(synopsis, 'line 1: h\xe9') + def test_synopsis_sourceless(self): + expected = os.__doc__.splitlines()[0] + filename = os.__cached__ + synopsis = pydoc.synopsis(filename) + + self.assertEqual(synopsis, expected) + def test_splitdoc_with_description(self): example_string = "I Am A Doc\n\n\nHere is my description" self.assertEqual(pydoc.splitdoc(example_string), @@ -600,6 +607,50 @@ self.assertEqual(out.getvalue(), '') self.assertEqual(err.getvalue(), '') + def test_modules(self): + # See Helper.listmodules(). + num_header_lines = 2 + num_module_lines_min = 5 # Playing it safe. + num_footer_lines = 3 + expected = num_header_lines + num_module_lines_min + num_footer_lines + + output = StringIO() + helper = pydoc.Helper(output=output) + helper('modules') + result = output.getvalue().strip() + num_lines = len(result.splitlines()) + + self.assertGreaterEqual(num_lines, expected) + + def test_modules_search(self): + # See Helper.listmodules(). + expected = 'pydoc - ' + + output = StringIO() + helper = pydoc.Helper(output=output) + with captured_stdout() as help_io: + helper('modules pydoc') + result = help_io.getvalue() + + self.assertIn(expected, result) + + def test_modules_search_builtin(self): + expected = 'gc - ' + + output = StringIO() + helper = pydoc.Helper(output=output) + with captured_stdout() as help_io: + helper('modules garbage') + result = help_io.getvalue() + + self.assertTrue(result.startswith(expected)) + + def test_importfile(self): + loaded_pydoc = pydoc.importfile(pydoc.__file__) + + self.assertEqual(loaded_pydoc.__name__, 'pydoc') + self.assertEqual(loaded_pydoc.__file__, pydoc.__file__) + class TestDescriptions(unittest.TestCase): @@ -827,6 +878,7 @@ print_diffs(expected_text, result) self.fail("outputs are not equal, see diff above") + @reap_threads def test_main(): try: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -221,6 +221,8 @@ - Issue #19782: imaplib now supports SSLContext.check_hostname and server name indication for TLS/SSL connections. +- Issue 20123: Fix pydoc.synopsis() for "binary" modules. + - Issue #19834: Support unpickling of exceptions pickled by Python 2. - Issue #19781: ftplib now supports SSLContext.check_hostname and server name -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 05:54:24 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 05:54:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_XMLPullParser?= =?utf-8?q?=2C_plus_some_doc_updates=2E?= Message-ID: <3dxnZS1P8vz7Lmc@mail.python.org> http://hg.python.org/cpython/rev/069f88f4935f changeset: 88308:069f88f4935f user: R David Murray date: Sat Jan 04 23:52:50 2014 -0500 summary: whatsnew: XMLPullParser, plus some doc updates. I was confused by the text saying that read_events "iterated", since it actually returns an iterator (that's what a generator does) that the caller must then iterate. So I tidied up the language. I'm not sure what the sentence "Events provided in a previous call to read_events() will not be yielded again." is trying to convey, so I didn't try to fix that. Also fixed a couple more news items. files: Doc/library/xml.etree.elementtree.rst | 23 +++++++++----- Doc/whatsnew/3.4.rst | 7 ++- Lib/xml/etree/ElementTree.py | 2 +- Misc/NEWS | 12 +++--- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -105,12 +105,15 @@ >>> root[0][1].text '2008' + +.. _elementtree-pull-parsing: + Pull API for non-blocking parsing ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Most parsing functions provided by this module require to read the whole -document at once before returning any result. It is possible to use a -:class:`XMLParser` and feed data into it incrementally, but it's a push API that +Most parsing functions provided by this module require the whole document +to be read at once before returning any result. It is possible to use an +:class:`XMLParser` and feed data into it incrementally, but it is a push API that calls methods on a callback target, which is too low-level and inconvenient for most needs. Sometimes what the user really wants is to be able to parse XML incrementally, without blocking operations, while enjoying the convenience of @@ -119,7 +122,7 @@ The most powerful tool for doing this is :class:`XMLPullParser`. It does not require a blocking read to obtain the XML data, and is instead fed with data incrementally with :meth:`XMLPullParser.feed` calls. To get the parsed XML -elements, call :meth:`XMLPullParser.read_events`. Here's an example:: +elements, call :meth:`XMLPullParser.read_events`. Here is an example:: >>> parser = ET.XMLPullParser(['start', 'end']) >>> parser.feed('sometext') @@ -1038,15 +1041,17 @@ .. method:: read_events() - Iterate over the events which have been encountered in the data fed to the - parser. This method yields ``(event, elem)`` pairs, where *event* is a + Return an iterator over the events which have been encountered in the + data fed to the + parser. The iterator yields ``(event, elem)`` pairs, where *event* is a string representing the type of event (e.g. ``"end"``) and *elem* is the encountered :class:`Element` object. Events provided in a previous call to :meth:`read_events` will not be - yielded again. As events are consumed from the internal queue only as - they are retrieved from the iterator, multiple readers calling - :meth:`read_events` in parallel will have unpredictable results. + yielded again. Events are consumed from the internal queue only when + they are retrieved from the iterator, so multiple readers iterating in + parallel over iterators obtained from :meth:`read_events` will have + unpredictable results. .. note:: diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1088,9 +1088,10 @@ xml.etree --------- -Add an event-driven parser for non-blocking applications, -:class:`~xml.etree.ElementTree.XMLPullParser`. -(Contributed by Antoine Pitrou in :issue:`17741`.) +A new parser, :class:`~xml.etree.ElementTree.XMLPullParser`, allows a +non-blocking applications to parse XML documents. An example can be +seen at :ref:`elementtree-pull-parsing`. (Contributed by Antoine +Pitrou in :issue:`17741`.) The :mod:`xml.etree.ElementTree` :func:`~xml.etree.ElementTree.tostring` and :func:`~xml.etree.ElementTree.tostringlist` functions, and the diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1251,7 +1251,7 @@ self._close_and_return_root() def read_events(self): - """Iterate over currently available (event, elem) pairs. + """Return an iterator over currently available (event, elem) pairs. Events are consumed from the internal event queue as they are retrieved from the iterator. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2193,14 +2193,14 @@ - Issue #17555: Fix ForkAwareThreadLock so that size of after fork registry does not grow exponentially with generation of process. -- Issue #17707: multiprocessing.Queue's get() method does not block for short - timeouts. - -- Isuse #17720: Fix the Python implementation of pickle.Unpickler to correctly +- Issue #17707: fix regression in multiprocessing.Queue's get() method where + it did not block for short timeouts. + +- Issue #17720: Fix the Python implementation of pickle.Unpickler to correctly process the APPENDS opcode when it is used on non-list objects. -- Issue #17012: shutil.which() no longer fallbacks to the PATH environment - variable if empty path argument is specified. Patch by Serhiy Storchaka. +- Issue #17012: shutil.which() no longer falls back to the PATH environment + variable if an empty path argument is specified. Patch by Serhiy Storchaka. - Issue #17710: Fix pickle raising a SystemError on bogus input. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 06:05:38 2014 From: python-checkins at python.org (eric.snow) Date: Sun, 5 Jan 2014 06:05:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_20123=3A_try_using_a?= =?utf-8?q?_different_builtin_module_in_a_pydoc_test=2E?= Message-ID: <3dxnqQ0dBBz7Lmc@mail.python.org> http://hg.python.org/cpython/rev/ff3be21338d5 changeset: 88309:ff3be21338d5 user: Eric Snow date: Sat Jan 04 21:56:07 2014 -0700 summary: Issue 20123: try using a different builtin module in a pydoc test. The test is failing on one of the stable FreeBSD buildbots. It seems unlikely that the gc module would not be available, so switching to _imp may not fix the problem. files: Lib/test/test_pydoc.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -635,12 +635,12 @@ self.assertIn(expected, result) def test_modules_search_builtin(self): - expected = 'gc - ' + expected = '_imp - ' output = StringIO() helper = pydoc.Helper(output=output) with captured_stdout() as help_io: - helper('modules garbage') + helper('modules low-level') result = help_io.getvalue() self.assertTrue(result.startswith(expected)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 06:30:32 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 06:30:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_news_entry_to_use_upda?= =?utf-8?q?ted_name_for_XMLPullParser=2E?= Message-ID: <3dxpN85g7JzPVW@mail.python.org> http://hg.python.org/cpython/rev/2d876843b52c changeset: 88310:2d876843b52c user: R David Murray date: Sun Jan 05 00:30:03 2014 -0500 summary: Fix news entry to use updated name for XMLPullParser. files: Misc/NEWS | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2187,8 +2187,8 @@ - Issue #11182: remove the unused and undocumented pydoc.Scanner class. Patch by Martin Morrison. -- Issue #17741: Add ElementTree.IncrementalParser, an event-driven parser - for non-blocking applications. +- Issue #17741: Add ElementTree.XMLPullParser, an event-driven parser for + non-blocking applications. - Issue #17555: Fix ForkAwareThreadLock so that size of after fork registry does not grow exponentially with generation of process. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 07:06:11 2014 From: python-checkins at python.org (eric.snow) Date: Sun, 5 Jan 2014 07:06:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_20123=3A_Disable_a_p?= =?utf-8?q?roblematic_test=2E?= Message-ID: <3dxq9H4zTCz7Lmb@mail.python.org> http://hg.python.org/cpython/rev/efcf163d04f5 changeset: 88311:efcf163d04f5 user: Eric Snow date: Sat Jan 04 23:04:27 2014 -0700 summary: Issue 20123: Disable a problematic test. files: Lib/test/test_pydoc.py | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -634,13 +634,14 @@ self.assertIn(expected, result) + @unittest.skip('some buildbots are not cooperating (#20123)') def test_modules_search_builtin(self): - expected = '_imp - ' + expected = 'gc - ' output = StringIO() helper = pydoc.Helper(output=output) with captured_stdout() as help_io: - helper('modules low-level') + helper('modules garbage') result = help_io.getvalue() self.assertTrue(result.startswith(expected)) -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sun Jan 5 09:46:13 2014 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 05 Jan 2014 09:46:13 +0100 Subject: [Python-checkins] Daily reference leaks (6d72617cae64): sum=11 Message-ID: results for 6d72617cae64 on branch "default" -------------------------------------------- test_asyncio leaked [0, 0, 4] memory blocks, sum=4 test_audioop leaked [1, 1, 1] references, sum=3 test_site leaked [0, 0, 2] references, sum=2 test_site leaked [0, 0, 2] memory blocks, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/refloggDBTf7', '-x'] From python-checkins at python.org Sun Jan 5 11:50:58 2014 From: python-checkins at python.org (larry.hastings) Date: Sun, 5 Jan 2014 11:50:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Argument_Clinic=3A_fixed_t?= =?utf-8?q?est_suite=2C_improved_howto=2E?= Message-ID: <3dxxTt3yjyz7Ljd@mail.python.org> http://hg.python.org/cpython/rev/172a6bfdd91b changeset: 88312:172a6bfdd91b user: Larry Hastings date: Sun Jan 05 02:50:45 2014 -0800 summary: Argument Clinic: fixed test suite, improved howto. files: Doc/howto/clinic.rst | 241 +++++++++++++++-------- Tools/clinic/clinic.py | 9 +- Tools/clinic/clinic_test.py | 24 +- 3 files changed, 173 insertions(+), 101 deletions(-) diff --git a/Doc/howto/clinic.rst b/Doc/howto/clinic.rst --- a/Doc/howto/clinic.rst +++ b/Doc/howto/clinic.rst @@ -14,21 +14,20 @@ function to work with Argument Clinic, and then introduces some advanced topics on Argument Clinic usage. - Argument Clinic is currently considered an internal - tool for the CPython code tree. Its use is not supported - for files outside the CPython code tree, and no guarantees - are made regarding backwards compatibility for future - versions. In other words: if you maintain an external C - extension for CPython, you're welcome to experiment with - Argument Clinic in your own code. But the version of Argument - Clinic that ships with CPython 3.5 *could* be totally - incompatible and break all your code. + Currently Argument Clinic is considered internal-only + for CPython. Its use is not supported for files outside + CPython, and no guarantees are made regarding backwards + compatibility for future versions. In other words: if you + maintain an external C extension for CPython, you're welcome + to experiment with Argument Clinic in your own code. But the + version of Argument Clinic that ships with CPython 3.5 *could* + be totally incompatible and break all your code. ======================== Basic Concepts And Usage ======================== -Argument Clinic ships with CPython. You can find it in ``Tools/clinic/clinic.py``. +Argument Clinic ships with CPython; you'll find it in ``Tools/clinic/clinic.py``. If you run that script, specifying a C file as an argument:: % python3 Tools/clinic/clinic.py foo.c @@ -45,13 +44,12 @@ Everything in between these two lines is input for Argument Clinic. All of these lines, including the beginning and ending comment -lines, are collectively called an Argument Clinic "input block", -or "block" for short. +lines, are collectively called an Argument Clinic "block". When Argument Clinic parses one of these blocks, it generates output. This output is rewritten into the C file immediately after the block, followed by a comment containing a checksum. -The resulting Argument Clinic block looks like this:: +The Argument Clinic block now looks like this:: /*[clinic] ... clinic input goes here ... @@ -65,7 +63,8 @@ You should never modify the output portion of an Argument Clinic block. Instead, change the input until it produces the output you want. (That's the purpose of the -checksum--to detect and warn you in case someone accidentally modifies the output.) +checksum--to detect if someone changed the output, as these edits would be lost +the next time Argument Clinic writes out fresh output.) For the sake of clarity, here's the terminology we'll use with Argument Clinic: @@ -87,10 +86,12 @@ The best way to get a sense of how Argument Clinic works is to convert a function to work with it. Let's dive in! -0. Make sure you're working with a freshly updated trunk. +0. Make sure you're working with a freshly updated checkout + of the CPython trunk. -1. Find a Python builtin that calls either ``PyArg_ParseTuple()`` - or ``PyArg_ParseTupleAndKeywords()``, and hasn't been converted yet. +1. Find a Python builtin that calls either :c:func:`PyArg_ParseTuple` + or :c:func:`PyArg_ParseTupleAndKeywords`, and hasn't been converted + to work with Argument Clinic yet. For my example I'm using ``pickle.Pickler.dump()``. 2. If the call to the ``PyArg_Parse`` function uses any of the @@ -103,7 +104,7 @@ et et# - or if it has multiple calls to ``PyArg_ParseTuple()``, + or if it has multiple calls to :c:func:`PyArg_ParseTuple`, you should choose a different function. Argument Clinic *does* support all of these scenarios. But these are advanced topics--let's do something simpler for your first function. @@ -130,7 +131,7 @@ be a paragraph consisting of a single 80-column line at the beginning of the docstring. - (Our docstring consists solely of the summary line, so the sample + (Our example docstring consists solely of a summary line, so the sample code doesn't have to change for this step.) 6. Above the docstring, enter the name of the function, followed @@ -198,7 +199,8 @@ string. ("format unit" is the formal name for the one-to-three character substring of the ``format`` parameter that tells the argument parsing function what the type of the variable - is and how to convert it.) + is and how to convert it. For more on format units please + see :ref:`arg-parsing`.) For multicharacter format units like ``z#``, use the entire two-or-three character string. @@ -231,14 +233,18 @@ (``pickle.Pickler.dump`` has neither, so our sample is unchanged.) -10. If the existing C function uses ``PyArg_ParseTuple()`` - (instead of ``PyArg_ParseTupleAndKeywords()``), then all its +10. If the existing C function calls :c:func:`PyArg_ParseTuple` + (as opposed to :c:func:`PyArg_ParseTupleAndKeywords`), then all its arguments are positional-only. To mark all parameters as positional-only in Argument Clinic, add a ``/`` on a line by itself after the last parameter, indented the same as the parameter lines. + Currently this is all-or-nothing; either all parameters are + positional-only, or none of them are. (In the future Argument + Clinic may relax this restriction.) + Sample:: /*[clinic] @@ -255,16 +261,16 @@ Write a pickled representation of obj to the open file. [clinic]*/ -11. It's helpful to write a per-parameter docstring, indented - another level past the parameter declaration. But per-parameter - docstrings are optional; you can skip this step if you prefer. +11. It's helpful to write a per-parameter docstring for each parameter. + But per-parameter docstrings are optional; you can skip this step + if you prefer. - Here's how per-parameter docstrings work. The first line + Here's how to add a per-parameter docstring. The first line of the per-parameter docstring must be indented further than the - parameter definition. This left margin establishes the left margin - for the whole per-parameter docstring; all the text you write will - be outdented by this amount. You can write as much as you like, - across multiple lines if you wish. + parameter definition. The left margin of this first line establishes + the left margin for the whole per-parameter docstring; all the text + you write will be outdented by this amount. You can write as much + text as you like, across multiple lines if you wish. Sample:: @@ -311,28 +317,47 @@ pickle_Pickler_dump_impl(PyObject *self, PyObject *obj) /*[clinic checksum: 3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/ + Obviously, if Argument Clinic didn't produce any output, it's because + it found an error in your input. Keep fixing your errors and retrying + until Argument Clinic processes your file without complaint. + 13. Double-check that the argument-parsing code Argument Clinic generated looks basically the same as the existing code. First, ensure both places use the same argument-parsing function. The existing code must call either - ``PyArg_ParseTuple()`` or ``PyArg_ParseTupleAndKeywords()``; + :c:func:`PyArg_ParseTuple` or :c:func:`PyArg_ParseTupleAndKeywords`; ensure that the code generated by Argument Clinic calls the - same function. + *exact* same function. - Second, the format string passed in to ``PyArg_ParseTuple()`` or - ``PyArg_ParseTupleAndKeywords()`` should be *exactly* the same - as the hand-written one in the existing function. + Second, the format string passed in to :c:func:`PyArg_ParseTuple` or + :c:func:`PyArg_ParseTupleAndKeywords` should be *exactly* the same + as the hand-written one in the existing function, up to the colon + or semi-colon. - Well, there's one way that Argument Clinic's output is permitted - to be different. Argument Clinic always generates a format string - ending with ``:`` followed by the name of the function. If the - format string originally ended with ``;`` (to specify usage help), - this is harmless--don't worry about this difference. + (Argument Clinic always generates its format strings + with a ``:`` followed by the name of the function. If the + existing code's format string ends with ``;``, to provide + usage help, this change is harmless--don't worry about it.) - Apart from that, if either of these things differ in *any way*, - fix your input to Argument Clinic and rerun ``Tools/clinic/clinic.py`` - until they are the same. + Third, for parameters whose format units require two arguments + (like a length variable, or an encoding string, or a pointer + to a conversion function), ensure that the second argument is + *exactly* the same between the two invocations. + + Fourth, inside the output portion of the block you'll find a preprocessor + macro defining the appropriate static :c:type:`PyMethodDef` structure for + this builtin:: + + #define _PICKLE_PICKLER_DUMP_METHODDEF \ + {"dump", (PyCFunction)_pickle_Pickler_dump, METH_O, _pickle_Pickler_dump__doc__}, + + This static structure should be *exactly* the same as the existing static + :c:type:`PyMethodDef` structure for this builtin. + + If any of these items differ in *any way*, + adjust your Argument Clinic function specification and rerun + ``Tools/clinic/clinic.py`` until they *are* the same. 14. Notice that the last line of its output is the declaration @@ -342,8 +367,19 @@ declarations of all the variables it dumps the arguments into. Notice how the Python arguments are now arguments to this impl function; if the implementation used different names for these variables, fix it. - The result should be a function that handles just the implementation - of the Python function without any argument-parsing code. + + Let's reiterate, just because it's kind of weird. Your code should now + look like this:: + + static return_type + your_function_impl(...) + /*[clinic checksum: ...]*/ + { + ... + + Argument Clinic generated the checksum line and the function prototype just + above it. You should write the opening (and closing) curly braces for the + function, and the implementation inside. Sample:: @@ -386,7 +422,27 @@ ... -15. Compile and run the relevant portions of the regression-test suite. +15. Remember the macro with the :c:type:`PyMethodDef` structure for this + function? Find the existing :c:type:`PyMethodDef` structure for this + function and replace it with a reference to the macro. (If the builtin + is at module scope, this will probably be very near the end of the file; + if the builtin is a class method, this will probably be below but relatively + near to the implementation.) + + Note that the body of the macro contains a trailing comma. So when you + replace the existing static :c:type:`PyMethodDef` structure with the macro, + *don't* add a comma to the end. + + Sample:: + + static struct PyMethodDef Pickler_methods[] = { + _PICKLE_PICKLER_DUMP_METHODDEF + _PICKLE_PICKLER_CLEAR_MEMO_METHODDEF + {NULL, NULL} /* sentinel */ + }; + + +16. Compile, then run the relevant portions of the regression-test suite. This change should not introduce any new compile-time warnings or errors, and there should be no externally-visible change to Python's behavior. @@ -405,11 +461,11 @@ Argument Clinic automatically names the functions it generates for you. Occasionally this may cause a problem, if the generated name collides with -the name of an existing C function. There's an easy solution: you can explicitly -specify the base name to use for the C functions. Just add the keyword ``"as"`` +the name of an existing C function. There's an easy solution: override the names +used for the C functions. Just add the keyword ``"as"`` to your function declaration line, followed by the function name you wish to use. -Argument Clinic will use the function name you use for the base (generated) function, -and then add ``"_impl"`` to the end for the name of the impl function. +Argument Clinic will use that function name for the base (generated) function, +then add ``"_impl"`` to the end and use that for the name of the impl function. For example, if we wanted to rename the C function names generated for ``pickle.Pickler.dump``, it'd look like this:: @@ -420,7 +476,7 @@ ... The base function would now be named ``pickler_dumper()``, -and the impl function would be named ``pickler_dumper_impl()``. +and the impl function would now be named ``pickler_dumper_impl()``. Optional Groups @@ -428,15 +484,15 @@ Some legacy functions have a tricky approach to parsing their arguments: they count the number of positional arguments, then use a ``switch`` statement -to call one of several different ``PyArg_ParseTuple()`` calls depending on +to call one of several different :c:func:`PyArg_ParseTuple` calls depending on how many positional arguments there are. (These functions cannot accept keyword-only arguments.) This approach was used to simulate optional -arguments back before ``PyArg_ParseTupleAndKeywords()`` was created. +arguments back before :c:func:`PyArg_ParseTupleAndKeywords` was created. -Functions using this approach can often be converted to -use ``PyArg_ParseTupleAndKeywords()``, optional arguments, and default values. -But it's not always possible, because some of these legacy functions have -behaviors ``PyArg_ParseTupleAndKeywords()`` can't directly support. +While functions using this approach can often be converted to +use :c:func:`PyArg_ParseTupleAndKeywords`, optional arguments, and default values, +it's not always possible. Some of these legacy functions have +behaviors :c:func:`PyArg_ParseTupleAndKeywords` doesn't directly support. The most obvious example is the builtin function ``range()``, which has an optional argument on the *left* side of its required argument! Another example is ``curses.window.addch()``, which has a group of two @@ -445,16 +501,17 @@ you must also pass in ``y``--and if you don't pass in ``x`` you may not pass in ``y`` either.) -For the sake of backwards compatibility, Argument Clinic supports this -alternate approach to parsing, using what are called *optional groups*. -Optional groups are groups of arguments that can only be specified together. +In any case, the goal of Argument Clinic is to support argument parsing +for all existing CPython builtins without changing their semantics. +Therefore Argument Clinic supports +this alternate approach to parsing, using what are called *optional groups*. +Optional groups are groups of arguments that must all be passed in together. They can be to the left or the right of the required arguments. They can *only* be used with positional-only parameters. To specify an optional group, add a ``[`` on a line by itself before -the parameters you wish to be -in a group together, and a ``]`` on a line by itself after the -parameters. As an example, here's how ``curses.window.addch`` +the parameters you wish to group together, and a ``]`` on a line by itself +after these parameters. As an example, here's how ``curses.window.addch`` uses optional groups to make the first two parameters and the last parameter optional:: @@ -484,8 +541,8 @@ Notes: * For every optional group, one additional parameter will be passed into the - impl function representing the group. The parameter will be an int, and it will - be named ``group_{direction}_{number}``, + impl function representing the group. The parameter will be an int named + ``group_{direction}_{number}``, where ``{direction}`` is either ``right`` or ``left`` depending on whether the group is before or after the required parameters, and ``{number}`` is a monotonically increasing number (starting at 1) indicating how far away the group is from @@ -495,11 +552,13 @@ in this invocation.) * If there are no required arguments, the optional groups will behave - as if they are to the right of the required arguments. + as if they're to the right of the required arguments. * In the case of ambiguity, the argument parsing code favors parameters on the left (before the required parameters). +* Optional groups can only contain positional-only parameters. + * Optional groups are *only* intended for legacy code. Please do not use optional groups for new code. @@ -509,7 +568,7 @@ To save time, and to minimize how much you need to learn to achieve your first port to Argument Clinic, the walkthrough above tells -you to use the "legacy converters". "Legacy converters" are a convenience, +you to use "legacy converters". "Legacy converters" are a convenience, designed explicitly to make porting existing code to Argument Clinic easier. And to be clear, their use is entirely acceptable when porting code for Python 3.4. @@ -523,18 +582,19 @@ because they require arguments, and the legacy converter syntax doesn't support specifying arguments. * In the future we may have a new argument parsing library that isn't - restricted to what ``PyArg_ParseTuple()`` supports. + restricted to what :c:func:`PyArg_ParseTuple` supports; this flexibility + won't be available to parameters using legacy converters. -So if you want -to go that extra effort, you should consider using normal -converters instead of the legacy converters. +Therefore, if you don't mind a little extra effort, you should consider +using normal converters instead of legacy converters. In a nutshell, the syntax for Argument Clinic (non-legacy) converters looks like a Python function call. However, if there are no explicit arguments to the function (all functions take their default values), you may omit the parentheses. Thus ``bool`` and ``bool()`` are exactly -the same. All parameters to Argument Clinic converters are keyword-only. +the same converters. +All arguments to Argument Clinic converters are keyword-only. All Argument Clinic converters accept the following arguments: ``doc_default`` @@ -643,11 +703,11 @@ Note also that this approach takes away some possible flexibility for the format units starting with ``e``. It used to be possible to decide at runtime what -encoding string to pass in to ``PyArg_ParseTuple()``. But now this string must +encoding string to pass in to :c:func:`PyArg_ParseTuple`. But now this string must be hard-coded at compile-time. This limitation is deliberate; it made supporting this format unit much easier, and may allow for future compile-time optimizations. This restriction does not seem unreasonable; CPython itself always passes in static -hard-coded strings when using format units starting with ``e``. +hard-coded encoding strings for parameters whose format units start with ``e``. Using a return converter @@ -692,12 +752,17 @@ error. For ``DecodeFSDefault``, the return type is ``char *``; return a NULL pointer to indicate an error. +To see all the return converters Argument Clinic supports, along with +their parameters (if any), +just run ``Tools/clinic/clinic.py --converters`` for the full list. + + Calling Python code ------------------- The rest of the advanced topics require you to write Python code -which lives inside your C file and modifies Argument Clinic at -runtime. This is simple; you simply define a Python block. +which lives inside your C file and modifies Argument Clinic's +runtime state. This is simple: you simply define a Python block. A Python block uses different delimiter lines than an Argument Clinic function block. It looks like this:: @@ -778,13 +843,13 @@ A converter is simply a Python class that inherits from ``CConverter``. The main purpose of a custom converter is if you have a parameter using the ``O&`` format unit--parsing this parameter means calling -a ``PyArg_ParseTuple()`` "converter function". +a :c:func:`PyArg_ParseTuple` "converter function". Your converter class should be named ``*something*_converter``. If the name follows this convention, then your converter class will be automatically registered with Argument Clinic; its name will be the name of your class with the ``_converter`` suffix -stripped off. (This is done automatically for you with a metaclass.) +stripped off. (This is accomplished with a metaclass.) You shouldn't subclass ``CConverter.__init__``. Instead, you should write a ``converter_init()`` function. ``converter_init()`` @@ -825,12 +890,13 @@ ``c_ignored_default`` The default value used to initialize the C variable when there is no default, but not specifying a default may - result in an "uninitialized variable" warning. This is + result in an "uninitialized variable" warning. This can easily happen when using option groups--although - properly-written code won't actually use the variable, - the variable does get passed in to the _impl, and the - C compiler will complain about the "use" of the uninitialized - value. This value should be a string. + properly-written code will never actually use this value, + the variable does get passed in to the impl, and the + C compiler will complain about the "use" of the + uninitialized value. This value should always be a + non-empty string. ``converter`` The name of the C converter function, as a string. @@ -843,7 +909,7 @@ ``parse_by_reference`` A boolean value. If true, Argument Clinic will add a ``&`` in front of the name of - the variable when passing it into ``PyArg_ParseTuple()``. + the variable when passing it into :c:func:`PyArg_ParseTuple`. Here's the simplest example of a custom converter, from ``Modules/zlibmodule.c``:: @@ -857,9 +923,10 @@ [python]*/ /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ -This block adds a ``uint`` converter to Argument Clinic. Parameters +This block adds a converter to Argument Clinic named ``uint``. Parameters declared as ``uint`` will be declared as type ``unsigned int``, and will -be parsed by calling the ``uint_converter`` converter function in C. +be parsed by the ``'O&'`` format unit, which will call the ``uint_converter`` +converter function. ``uint`` variables automatically support default values. More sophisticated custom converters can insert custom C code to @@ -871,7 +938,7 @@ --------------------------------- Writing a custom return converter is much like writing -a custom converter. Except it's much simpler, because return +a custom converter. Except it's somewhat simpler, because return converters are themselves much simpler. Return converters must subclass ``CReturnConverter``. diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -997,7 +997,8 @@ # "languages" maps the name of the language ("C", "Python"). # "extensions" maps the file extension ("c", "py"). languages = { 'C': CLanguage, 'Python': PythonLanguage } -extensions = { 'c': CLanguage, 'h': CLanguage, 'py': PythonLanguage } +extensions = { name: CLanguage for name in "c cc cpp cxx h hh hpp hxx".split() } +extensions['py'] = PythonLanguage # maps strings to callables. @@ -2430,9 +2431,6 @@ # the final stanza of the DSL is the docstring. def state_function_docstring(self, line): - if not self.function.self_converter: - self.function.self_converter = self_converter("self", self.function) - if self.group: fail("Function " + self.function.name + " has a ] without a matching [.") @@ -2604,6 +2602,9 @@ if not self.function: return + if not self.function.self_converter: + self.function.self_converter = self_converter("self", self.function) + if self.keyword_only: values = self.function.parameters.values() if not values: diff --git a/Tools/clinic/clinic_test.py b/Tools/clinic/clinic_test.py --- a/Tools/clinic/clinic_test.py +++ b/Tools/clinic/clinic_test.py @@ -296,9 +296,9 @@ Perform a stat system call on the given path.""") self.assertEqual(""" +stat(path) Perform a stat system call on the given path. -os.stat(path) path Path to be examined """.strip(), function.docstring) @@ -316,9 +316,9 @@ Okay, we're done here. """) self.assertEqual(""" +bar(x, y) This is the documentation for foo. -foo.bar(x, y) x Documentation for x. @@ -356,7 +356,7 @@ def test_left_group(self): function = self.parse_function(""" module curses -curses.window.addch +curses.addch [ y: int Y-coordinate. @@ -380,7 +380,9 @@ self.assertEqual(p.group, group) self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY) self.assertEqual(function.docstring.strip(), """ -curses.window.addch([y, x,] ch, [attr]) +addch([y, x,] ch, [attr]) + + y Y-coordinate. x @@ -394,7 +396,7 @@ def test_nested_groups(self): function = self.parse_function(""" module curses -curses.window.imaginary +curses.imaginary [ [ y1: int @@ -439,7 +441,9 @@ self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY) self.assertEqual(function.docstring.strip(), """ -curses.window.imaginary([[y1, y2,] x1, x2,] ch, [attr1, attr2, attr3, [attr4, attr5, attr6]]) +imaginary([[y1, y2,] x1, x2,] ch, [attr1, attr2, attr3, [attr4, attr5, attr6]]) + + y1 Y-coordinate. y2 @@ -557,7 +561,7 @@ Docstring """) - self.assertEqual("Docstring\n\nfoo.bar()", function.docstring) + self.assertEqual("bar()\nDocstring", function.docstring) self.assertEqual(0, len(function.parameters)) def test_illegal_module_line(self): @@ -652,9 +656,9 @@ Not at column 0! """) self.assertEqual(""" +bar(x, *, y) Not at column 0! -foo.bar(x, *, y) x Nested docstring here, goeth. """.strip(), function.docstring) @@ -666,7 +670,7 @@ path: str This/used to break Clinic! """) - self.assertEqual("This/used to break Clinic!\n\nos.stat(path)", function.docstring) + self.assertEqual("stat(path)\nThis/used to break Clinic!", function.docstring) def test_directive(self): c = FakeClinic() @@ -692,7 +696,7 @@ def parse_function(self, text): block = self.parse(text) s = block.signatures - assert len(s) == 2 + self.assertEqual(len(s), 2) assert isinstance(s[0], clinic.Module) assert isinstance(s[1], clinic.Function) return s[1] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 15:50:40 2014 From: python-checkins at python.org (ethan.furman) Date: Sun, 5 Jan 2014 15:50:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbjogSXNzdWUxOTk5NTogJW8sICV4?= =?utf-8?q?=2C_=25X_now_only_accept_ints?= Message-ID: <3dy2pS1Bh2z7Lpy@mail.python.org> http://hg.python.org/cpython/rev/2f81f0e331f6 changeset: 88313:2f81f0e331f6 user: Ethan Furman date: Sun Jan 05 06:50:30 2014 -0800 summary: Issue19995: %o, %x, %X now only accept ints files: Doc/reference/datamodel.rst | 14 +++++++-- Lib/tarfile.py | 2 +- Lib/test/test_format.py | 5 --- Lib/test/test_unicode.py | 29 ++++++++++++++++++++ Misc/NEWS | 4 ++ Objects/unicodeobject.c | 35 +++++++++++++++++++----- 6 files changed, 72 insertions(+), 17 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -2080,9 +2080,17 @@ .. method:: object.__index__(self) - Called to implement :func:`operator.index`. Also called whenever Python needs - an integer object (such as in slicing, or in the built-in :func:`bin`, - :func:`hex` and :func:`oct` functions). Must return an integer. + Called to implement :func:`operator.index`, and whenever Python needs to + losslessly convert the numeric object to an integer object (such as in + slicing, or in the built-in :func:`bin`, :func:`hex` and :func:`oct` + functions). Presence of this method indicates that the numeric object is + an integer type. Must return an integer. + + .. note:: + + When :meth:`__index__` is defined, :meth:`__int__` should also be defined, + and both shuld return the same value, in order to have a coherent integer + type class. .. _context-managers: diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -196,7 +196,7 @@ # A 0o200 byte indicates a positive number, a 0o377 byte a negative # number. if 0 <= n < 8 ** (digits - 1): - s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL + s = bytes("%0*o" % (digits - 1, int(n)), "ascii") + NUL elif format == GNU_FORMAT and -256 ** (digits - 1) <= n < 256 ** (digits - 1): if n >= 0: s = bytearray([0o200]) diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -142,7 +142,6 @@ testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345") # same, except no 0 flag testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345") - testformat("%x", float(big), "123456_______________", 6) big = 0o12345670123456701234567012345670 # 32 octal digits testformat("%o", big, "12345670123456701234567012345670") testformat("%o", -big, "-12345670123456701234567012345670") @@ -182,7 +181,6 @@ testformat("%034.33o", big, "0012345670123456701234567012345670") # base marker shouldn't change that testformat("%0#34.33o", big, "0o012345670123456701234567012345670") - testformat("%o", float(big), "123456__________________________", 6) # Some small ints, in both Python int and flavors). testformat("%d", 42, "42") testformat("%d", -42, "-42") @@ -193,7 +191,6 @@ testformat("%#x", 1, "0x1") testformat("%#X", 1, "0X1") testformat("%#X", 1, "0X1") - testformat("%#x", 1.0, "0x1") testformat("%#o", 1, "0o1") testformat("%#o", 1, "0o1") testformat("%#o", 0, "0o0") @@ -210,12 +207,10 @@ testformat("%x", -0x42, "-42") testformat("%x", 0x42, "42") testformat("%x", -0x42, "-42") - testformat("%x", float(0x42), "42") testformat("%o", 0o42, "42") testformat("%o", -0o42, "-42") testformat("%o", 0o42, "42") testformat("%o", -0o42, "-42") - testformat("%o", float(0o42), "42") testformat("%r", "\u0378", "'\\u0378'") # non printable testformat("%a", "\u0378", "'\\u0378'") # non printable testformat("%r", "\u0374", "'\u0374'") # printable diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1126,6 +1126,35 @@ self.assertEqual('%.1s' % "a\xe9\u20ac", 'a') self.assertEqual('%.2s' % "a\xe9\u20ac", 'a\xe9') + #issue 19995 + class PsuedoInt: + def __init__(self, value): + self.value = int(value) + def __int__(self): + return self.value + def __index__(self): + return self.value + class PsuedoFloat: + def __init__(self, value): + self.value = float(value) + def __int__(self): + return int(self.value) + pi = PsuedoFloat(3.1415) + letter_m = PsuedoInt(109) + self.assertEquals('%x' % 42, '2a') + self.assertEquals('%X' % 15, 'F') + self.assertEquals('%o' % 9, '11') + self.assertEquals('%c' % 109, 'm') + self.assertEquals('%x' % letter_m, '6d') + self.assertEquals('%X' % letter_m, '6D') + self.assertEquals('%o' % letter_m, '155') + self.assertEquals('%c' % letter_m, 'm') + self.assertRaises(TypeError, '%x'.__mod__, pi) + self.assertRaises(TypeError, '%x'.__mod__, 3.14) + self.assertRaises(TypeError, '%X'.__mod__, 2.11) + self.assertRaises(TypeError, '%o'.__mod__, 1.79) + self.assertRaises(TypeError, '%c'.__mod__, pi) + def test_formatting_with_enum(self): # issue18780 import enum diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -18,6 +18,10 @@ - Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if "%c" argument is not in range [0; 255]. +- Issue #19995: %c, %o, %x, and %X now raise TypeError on non-integer input; + reworded docs to clarify that an integer type should define both __int__ + and __index__. + - Issue #19787: PyThread_set_key_value() now always set the value. In Python 3.3, the function did nothing if the key already exists (if the current value is a non-NULL pointer). diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13988,7 +13988,7 @@ return result; } -/* Format an integer. +/* Format an integer or a float as an integer. * Return 1 if the number has been formatted into the writer, * 0 if the number has been formatted into *p_output * -1 and raise an exception on error */ @@ -14005,11 +14005,19 @@ goto wrongtype; if (!PyLong_Check(v)) { - iobj = PyNumber_Long(v); - if (iobj == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - goto wrongtype; - return -1; + if (type == 'o' || type == 'x' || type == 'X') { + iobj = PyNumber_Index(v); + if (iobj == NULL) { + return -1; + } + } + else { + iobj = PyNumber_Long(v); + if (iobj == NULL ) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + goto wrongtype; + return -1; + } } assert(PyLong_Check(iobj)); } @@ -14079,8 +14087,18 @@ goto onError; } else { + PyObject *iobj; + long x; + /* make sure number is a type of integer */ + if (!PyLong_Check(v)) { + iobj = PyNumber_Index(v); + if (iobj == NULL) { + goto onError; + } + v = iobj; + Py_DECREF(iobj); + } /* Integer input truncated to a character */ - long x; x = PyLong_AsLong(v); if (x == -1 && PyErr_Occurred()) goto onError; @@ -14282,7 +14300,8 @@ /* Format one argument. Supported conversion specifiers: - "s", "r", "a": any type - - "i", "d", "u", "o", "x", "X": int + - "i", "d", "u": int or float + - "o", "x", "X": int - "e", "E", "f", "F", "g", "G": float - "c": int or str (1 character) -- Repository URL: http://hg.python.org/cpython From root at python.org Sun Jan 5 16:55:23 2014 From: root at python.org (Cron Daemon) Date: Sun, 05 Jan 2014 16:55:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sun Jan 5 17:00:24 2014 From: root at python.org (Cron Daemon) Date: Sun, 05 Jan 2014 17:00:24 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From python-checkins at python.org Sun Jan 5 21:00:37 2014 From: python-checkins at python.org (raymond.hettinger) Date: Sun, 5 Jan 2014 21:00:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_comments_to_frozenset?= =?utf-8?b?X2hhc2goKS4=?= Message-ID: <3dy9h56lFnz7LqG@mail.python.org> http://hg.python.org/cpython/rev/247f12fecf2b changeset: 88314:247f12fecf2b user: Raymond Hettinger date: Sun Jan 05 12:00:31 2014 -0800 summary: Add comments to frozenset_hash(). Also, provide a minor hint to the compiler on how to group the xors. files: Objects/setobject.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -738,6 +738,17 @@ static Py_hash_t frozenset_hash(PyObject *self) { + /* Most of the constants in this hash algorithm are randomly choosen + large primes with "interesting bit patterns" and that passed + tests for good collision statistics on a variety of problematic + datasets such as: + + ps = [] + for r in range(21): + ps += itertools.combinations(range(20), r) + num_distinct_hashes = len({hash(frozenset(s)) for s in ps}) + + */ PySetObject *so = (PySetObject *)self; Py_uhash_t h, hash = 1927868237UL; setentry *entry; @@ -754,8 +765,10 @@ hashes so that many distinct combinations collapse to only a handful of distinct hash values. */ h = entry->hash; - hash ^= (h ^ (h << 16) ^ 89869747UL) * 3644798167UL; + hash ^= ((h ^ 89869747UL) ^ (h << 16)) * 3644798167UL; } + /* Make the final result spread-out in a different pattern + than the algorithem for tuples or other python objects. */ hash = hash * 69069U + 907133923UL; if (hash == -1) hash = 590923713UL; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 21:39:41 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 21:39:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzEwNjU5ODY6IE1h?= =?utf-8?q?ke_pydoc_handle_unicode_strings=2E?= Message-ID: <3dyBY915mFz7LjP@mail.python.org> http://hg.python.org/cpython/rev/bf077fc97fdd changeset: 88315:bf077fc97fdd branch: 2.7 parent: 88286:d7ae948d9eee user: R David Murray date: Sun Jan 05 12:35:59 2014 -0500 summary: #1065986: Make pydoc handle unicode strings. Patch by Akira Kitada. files: Lib/pydoc.py | 58 ++++++++++++++---- Lib/test/test_pydoc.py | 91 ++++++++++++++++++++++++++++++ Misc/NEWS | 2 + 3 files changed, 137 insertions(+), 14 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -81,6 +81,7 @@ def getdoc(object): """Get the doc string or comments for an object.""" result = inspect.getdoc(object) or inspect.getcomments(object) + result = _encode(result) return result and re.sub('^ *\n', '', rstrip(result)) or '' def splitdoc(doc): @@ -182,6 +183,34 @@ return name, kind, cls, value return map(fixup, inspect.classify_class_attrs(object)) +# ----------------------------------------------------- Unicode support helpers + +try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one that nothing will match, and make + # the _encode function that do nothing. + class _unicode(object): + pass + _encoding = 'ascii' + def _encode(text, encoding='ascii'): + return text +else: + import locale + _encoding = locale.getpreferredencoding() + + def _encode(text, encoding=None): + if isinstance(text, unicode): + return text.encode(encoding or _encoding, 'xmlcharrefreplace') + else: + return text + +def _binstr(obj): + # Ensure that we have an encoded (binary) string representation of obj, + # even if it is a unicode string. + return obj.encode(_encoding) if isinstance(obj, _unicode) else str(obj) + # ----------------------------------------------------- module manipulation def ispackage(path): @@ -424,12 +453,13 @@ def page(self, title, contents): """Format an HTML page.""" - return ''' + return _encode(''' Python: %s + %s -''' % (title, contents) +''' % (title, contents), 'ascii') def heading(self, title, fgcol, bgcol, extras=''): """Format a page heading.""" @@ -606,12 +636,12 @@ filelink = '(built-in)' info = [] if hasattr(object, '__version__'): - version = str(object.__version__) + version = _binstr(object.__version__) if version[:11] == '$' + 'Revision: ' and version[-1:] == '$': version = strip(version[11:-1]) info.append('version %s' % self.escape(version)) if hasattr(object, '__date__'): - info.append(self.escape(str(object.__date__))) + info.append(self.escape(_binstr(object.__date__))) if info: head = head + ' (%s)' % join(info, ', ') docloc = self.getdocloc(object) @@ -694,11 +724,11 @@ result = result + self.bigsection( 'Data', '#ffffff', '#55aa55', join(contents, '
\n')) if hasattr(object, '__author__'): - contents = self.markup(str(object.__author__), self.preformat) + contents = self.markup(_binstr(object.__author__), self.preformat) result = result + self.bigsection( 'Author', '#ffffff', '#7799ee', contents) if hasattr(object, '__credits__'): - contents = self.markup(str(object.__credits__), self.preformat) + contents = self.markup(_binstr(object.__credits__), self.preformat) result = result + self.bigsection( 'Credits', '#ffffff', '#7799ee', contents) @@ -1116,16 +1146,16 @@ result = result + self.section('DATA', join(contents, '\n')) if hasattr(object, '__version__'): - version = str(object.__version__) + version = _binstr(object.__version__) if version[:11] == '$' + 'Revision: ' and version[-1:] == '$': version = strip(version[11:-1]) result = result + self.section('VERSION', version) if hasattr(object, '__date__'): - result = result + self.section('DATE', str(object.__date__)) + result = result + self.section('DATE', _binstr(object.__date__)) if hasattr(object, '__author__'): - result = result + self.section('AUTHOR', str(object.__author__)) + result = result + self.section('AUTHOR', _binstr(object.__author__)) if hasattr(object, '__credits__'): - result = result + self.section('CREDITS', str(object.__credits__)) + result = result + self.section('CREDITS', _binstr(object.__credits__)) return result def docclass(self, object, name=None, mod=None, *ignored): @@ -1375,7 +1405,7 @@ """Page through text by feeding it to another program.""" pipe = os.popen(cmd, 'w') try: - pipe.write(text) + pipe.write(_encode(text)) pipe.close() except IOError: pass # Ignore broken pipes caused by quitting the pager program. @@ -1385,7 +1415,7 @@ import tempfile filename = tempfile.mktemp() file = open(filename, 'w') - file.write(text) + file.write(_encode(text)) file.close() try: os.system(cmd + ' "' + filename + '"') @@ -1394,7 +1424,7 @@ def ttypager(text): """Page through text on a text terminal.""" - lines = split(plain(text), '\n') + lines = plain(_encode(plain(text), getattr(sys.stdout, 'encoding', _encoding))).split('\n') try: import tty fd = sys.stdin.fileno() @@ -1432,7 +1462,7 @@ def plainpager(text): """Simply print unformatted text. This is the ultimate fallback.""" - sys.stdout.write(plain(text)) + sys.stdout.write(_encode(plain(text), getattr(sys.stdout, 'encoding', _encoding))) def describe(thing): """Produce a short description of the given thing.""" diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -10,6 +10,7 @@ import pkgutil import unittest import xml.etree +import types import test.test_support from collections import namedtuple from test.script_helper import assert_python_ok @@ -428,6 +429,95 @@ self.assertIn('_asdict', helptext) + at unittest.skipUnless(test.test_support.have_unicode, + "test requires unicode support") +class TestUnicode(unittest.TestCase): + + def setUp(self): + # Better not to use unicode escapes in literals, lest the + # parser choke on it if Python has been built without + # unicode support. + self.Q = types.ModuleType( + 'Q', 'Rational numbers: \xe2\x84\x9a'.decode('utf8')) + self.Q.__version__ = '\xe2\x84\x9a'.decode('utf8') + self.Q.__date__ = '\xe2\x84\x9a'.decode('utf8') + self.Q.__author__ = '\xe2\x84\x9a'.decode('utf8') + self.Q.__credits__ = '\xe2\x84\x9a'.decode('utf8') + + self.assertIsInstance(self.Q.__doc__, unicode) + + def test_render_doc(self): + # render_doc is robust against unicode in docstrings + doc = pydoc.render_doc(self.Q) + self.assertIsInstance(doc, str) + + def test_encode(self): + # _encode is robust against characters out the specified encoding + self.assertEqual(pydoc._encode(self.Q.__doc__, 'ascii'), 'Rational numbers: ℚ') + + def test_pipepager(self): + # pipepager does not choke on unicode + doc = pydoc.render_doc(self.Q) + + saved, os.popen = os.popen, open + try: + with test.test_support.temp_cwd(): + pydoc.pipepager(doc, 'pipe') + self.assertEqual(open('pipe').read(), pydoc._encode(doc)) + finally: + os.popen = saved + + def test_tempfilepager(self): + # tempfilepager does not choke on unicode + doc = pydoc.render_doc(self.Q) + + output = {} + def mock_system(cmd): + import ast + output['content'] = open(ast.literal_eval(cmd.strip())).read() + saved, os.system = os.system, mock_system + try: + pydoc.tempfilepager(doc, '') + self.assertEqual(output['content'], pydoc._encode(doc)) + finally: + os.system = saved + + def test_plainpager(self): + # plainpager does not choke on unicode + doc = pydoc.render_doc(self.Q) + + # Note: captured_stdout is too permissive when it comes to + # unicode, and using it here would make the test always + # pass. + with test.test_support.temp_cwd(): + with open('output', 'w') as f: + saved, sys.stdout = sys.stdout, f + try: + pydoc.plainpager(doc) + finally: + sys.stdout = saved + self.assertIn('Rational numbers:', open('output').read()) + + def test_ttypager(self): + # ttypager does not choke on unicode + doc = pydoc.render_doc(self.Q) + # Test ttypager + with test.test_support.temp_cwd(), test.test_support.captured_stdin(): + with open('output', 'w') as f: + saved, sys.stdout = sys.stdout, f + try: + pydoc.ttypager(doc) + finally: + sys.stdout = saved + self.assertIn('Rational numbers:', open('output').read()) + + def test_htmlpage(self): + # html.page does not choke on unicode + with test.test_support.temp_cwd(): + with captured_stdout() as output: + pydoc.writedoc(self.Q) + self.assertEqual(output.getvalue(), 'wrote Q.html\n') + class TestHelper(unittest.TestCase): def test_keywords(self): self.assertEqual(sorted(pydoc.Helper.keywords), @@ -456,6 +546,7 @@ test.test_support.run_unittest(PydocDocTest, PydocImportTest, TestDescriptions, + TestUnicode, TestHelper) finally: reap_children() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,8 @@ Library ------- +- Issue #1065986: pydoc can now handle unicode strings. + - Issue #16039: CVE-2013-1752: Change use of readline in imaplib module to limit line length. Patch by Emil Lind. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Jan 5 23:14:27 2014 From: python-checkins at python.org (r.david.murray) Date: Sun, 5 Jan 2014 23:14:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzEwNjU5ODY6IGFk?= =?utf-8?q?d_missing_error_handler_in_pydoc_unicode_fix=2E?= Message-ID: <3dyDfW5wYtz7Lr2@mail.python.org> http://hg.python.org/cpython/rev/e57660acc6d4 changeset: 88316:e57660acc6d4 branch: 2.7 user: R David Murray date: Sun Jan 05 17:14:08 2014 -0500 summary: #1065986: add missing error handler in pydoc unicode fix. files: Lib/pydoc.py | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -209,7 +209,9 @@ def _binstr(obj): # Ensure that we have an encoded (binary) string representation of obj, # even if it is a unicode string. - return obj.encode(_encoding) if isinstance(obj, _unicode) else str(obj) + if isinstance(obj, _unicode): + return obj.encode(_encoding, 'xmlcharrefreplace') + return str(obj) # ----------------------------------------------------- module manipulation -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Jan 6 09:47:25 2014 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 06 Jan 2014 09:47:25 +0100 Subject: [Python-checkins] Daily reference leaks (247f12fecf2b): sum=3 Message-ID: results for 247f12fecf2b on branch "default" -------------------------------------------- test_audioop leaked [1, 1, 1] references, sum=3 test_site leaked [2, -2, 0] references, sum=0 test_site leaked [2, -2, 0] memory blocks, sum=0 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogU8DXuf', '-x'] From python-checkins at python.org Mon Jan 6 11:53:12 2014 From: python-checkins at python.org (victor.stinner) Date: Mon, 6 Jan 2014 11:53:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Rename_pep-0466/_to_pep-0446/?= Message-ID: <3dyYV04lk1z7Ljw@mail.python.org> http://hg.python.org/peps/rev/caedc2aa99b6 changeset: 5336:caedc2aa99b6 user: Victor Stinner date: Mon Jan 06 11:53:05 2014 +0100 summary: Rename pep-0466/ to pep-0446/ files: pep-0466/test_cloexec.py | 0 1 files changed, 0 insertions(+), 0 deletions(-) diff --git a/pep-0466/test_cloexec.py b/pep-0446/test_cloexec.py rename from pep-0466/test_cloexec.py rename to pep-0446/test_cloexec.py -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Mon Jan 6 14:19:10 2014 From: python-checkins at python.org (victor.stinner) Date: Mon, 6 Jan 2014 14:19:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Create_PEP_460_=22Add_bytes_?= =?utf-8?q?=25_args_and_bytes=2Eformat=28args=29_to_Python_3=2E5=22?= Message-ID: <3dyckQ324Hz7LjN@mail.python.org> http://hg.python.org/peps/rev/7a92360bbdff changeset: 5337:7a92360bbdff user: Victor Stinner date: Mon Jan 06 14:01:09 2014 +0100 summary: Create PEP 460 "Add bytes % args and bytes.format(args) to Python 3.5" files: pep-0460.txt | 175 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) diff --git a/pep-0460.txt b/pep-0460.txt new file mode 100644 --- /dev/null +++ b/pep-0460.txt @@ -0,0 +1,175 @@ +PEP: 460 +Title: Add bytes % args and bytes.format(args) to Python 3.5 +Version: $Revision$ +Last-Modified: $Date$ +Author: Victor Stinner +Status: Draft +Type: Standards Track +Content-Type: text/x-rst +Created: 6-Jan-2014 +Python-Version: 3.5 + + +Abstract +======== + +Add ``bytes % args`` operator and ``bytes.format(args)`` method to +Python 3.5. + + +Rationale +========= + +``bytes % args`` and ``bytes.format(args)`` have been removed in Python +2. This operator and this method are requested by Mercurial and Twisted +developers to ease porting their project on Python 3. + +Python 3 suggests to format text first and then encode to bytes. In +some cases, it does not make sense because arguments are bytes strings. +Typical usage is a network protocol which is binary, since data are +send to and received from sockets. For example, SMTP, SIP, HTTP, IMAP, +POP, FTP are ASCII commands interspersed with binary data. + +Using multiple ``bytes + bytes`` instructions is inefficient because it +requires temporary buffers and copies which are slow and waste memory. +Python 3.3 optimizes ``str2 += str2`` but not ``bytes2 += bytes1``. + +``bytes % args`` and ``bytes.format(args)`` were asked since 2008, even +before the first release of Python 3.0 (see issue #3982). + +``struct.pack()`` is incomplete. For example, a number cannot be +formatted as decimal and it does not support padding bytes string. + +Mercurial 2.8 still supports Python 2.4. + + +Needed and excluded features +============================ + +Needed features + +* Bytes strings: bytes, bytearray and memoryview types +* Format integer numbers as decimal +* Padding with spaces and null bytes +* "%s" should use the buffer protocol, not str() + +The feature set is minimal to keep the implementation as simple as +possible to limit the cost of the implementation. ``str % args`` and +``str.format(args)`` are already complex and difficult to maintain, the +code is heavily optimized. + +Excluded features: + +* no implicit conversion from Unicode to bytes (ex: encode to ASCII or + to Latin1) +* Locale support (``{!n}`` format for numbers). Locales are related to + text and usually to an encoding. +* ``repr()``, ``ascii()``: ``%r``, ``{!r}``, ``%a`` and ``{!a}`` + formats. ``repr()`` and ``ascii()`` are used to debug, the output is + displayed a terminal or a graphical widget. They are more related to + text. +* Attribute access: ``{obj.attr}`` +* Indexing: ``{dict[key]}`` +* Features of struct.pack(). For example, format a number as 32 bit unsigned + integer in network endian. The ``struct.pack()`` can be used to prepare + arguments, the implementation should be kept simple. +* Features of int.to_bytes(). +* Features of ctypes. +* New format protocol like a new ``__bformat__()`` method. Since the +* list of + supported types is short, there is no need to add a new protocol. + Other types must be explicitly casted. +* Alternate format for integer. For example, ``'{|#x}'.format(0x123)`` + to get ``0x123``. It is more related to debug, and the prefix can be + easily be written in the format string (ex: ``0x%x``). +* Relation with format() and the __format__() protocol. bytes.format() + and str.format() are unrelated. + +Unknown: + +* Format integer to hexadecimal? ``%x`` and ``%X`` +* Format integer to octal? ``%o`` +* Format integer to binary? ``{!b}`` +* Alignment? +* Truncating? Truncate or raise an error? +* format keywords? ``b'{arg}'.format(arg=5)`` +* ``str % dict`` ? ``b'%(arg)s' % {'arg': 5)`` +* Floating point number? +* ``%i``, ``%u`` and ``%d`` formats for integer numbers? +* Signed number? ``%+i`` and ``%-i`` + + +bytes % args +============ + +Formatters: + +* ``"%c"``: one byte +* ``"%s"``: integer or bytes strings +* ``"%20s"`` pads to 20 bytes with spaces (``b' '``) +* ``"%020s"`` pads to 20 bytes with zeros (``b'0'``) +* ``"%\020s"`` pads to 20 bytes with null bytes (``b'\0'``) + + +bytes.format(args) +================== + +Formatters: + +* ``"{!c}"``: one byte +* ``"{!s}"``: integer or bytes strings +* ``"{!.20s}"`` pads to 20 bytes with spaces (``b' '``) +* ``"{!.020s}"`` pads to 20 bytes with zeros (``b'0'``) +* ``"{!\020s}"`` pads to 20 bytes with null bytes (``b'\0'``) + + +Examples +======== + +* ``b'a%sc%s' % (b'b', 4)`` gives ``b'abc4'`` +* ``b'a{}c{}'.format(b'b', 4)`` gives ``b'abc4'`` +* ``b'%c'`` % 88`` gives ``b'X``' +* ``b'%%'`` gives ``b'%'`` + + +Criticisms +========== + +* The development cost and maintenance cost. +* In 3.3 encoding to ascii or latin1 is as fast as memcpy +* Developers must work around the lack of bytes%args and + bytes.format(args) anyway to support Python 3.0-3.4 +* bytes.join() is consistently faster than format to join bytes strings. +* Formatting functions can be implemented in a third party module + + +References +========== + +* `Issue #3982: support .format for bytes + `_ +* `Mercurial project + `_ +* `Twisted project + `_ +* `Documentation of Python 2 formatting (str % args) + `_ +* `Documentation of Python 2 formatting (str.format) + `_ + +Copyright +========= + +This document has been placed in the public domain. + + + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + coding: utf-8 + End: + -- Repository URL: http://hg.python.org/peps From ncoghlan at gmail.com Mon Jan 6 16:22:21 2014 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 7 Jan 2014 01:22:21 +1000 Subject: [Python-checkins] cpython: whatsnew: XMLPullParser, plus some doc updates. In-Reply-To: <3dxnZS1P8vz7Lmc@mail.python.org> References: <3dxnZS1P8vz7Lmc@mail.python.org> Message-ID: On 5 Jan 2014 12:54, "r.david.murray" wrote: > > http://hg.python.org/cpython/rev/069f88f4935f > changeset: 88308:069f88f4935f > user: R David Murray > date: Sat Jan 04 23:52:50 2014 -0500 > summary: > whatsnew: XMLPullParser, plus some doc updates. > > I was confused by the text saying that read_events "iterated", since it > actually returns an iterator (that's what a generator does) that the > caller must then iterate. So I tidied up the language. I'm not sure > what the sentence "Events provided in a previous call to read_events() > will not be yielded again." is trying to convey, so I didn't try to fix that. It's a mutating API - once the events have been retrieved, that's it, they're gone from the internal state. Suggestions for wording improvements welcome :) Cheers, Nick. > > Also fixed a couple more news items. > > files: > Doc/library/xml.etree.elementtree.rst | 23 +++++++++----- > Doc/whatsnew/3.4.rst | 7 ++- > Lib/xml/etree/ElementTree.py | 2 +- > Misc/NEWS | 12 +++--- > 4 files changed, 25 insertions(+), 19 deletions(-) > > > diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst > --- a/Doc/library/xml.etree.elementtree.rst > +++ b/Doc/library/xml.etree.elementtree.rst > @@ -105,12 +105,15 @@ > >>> root[0][1].text > '2008' > > + > +.. _elementtree-pull-parsing: > + > Pull API for non-blocking parsing > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > -Most parsing functions provided by this module require to read the whole > -document at once before returning any result. It is possible to use a > -:class:`XMLParser` and feed data into it incrementally, but it's a push API that > +Most parsing functions provided by this module require the whole document > +to be read at once before returning any result. It is possible to use an > +:class:`XMLParser` and feed data into it incrementally, but it is a push API that > calls methods on a callback target, which is too low-level and inconvenient for > most needs. Sometimes what the user really wants is to be able to parse XML > incrementally, without blocking operations, while enjoying the convenience of > @@ -119,7 +122,7 @@ > The most powerful tool for doing this is :class:`XMLPullParser`. It does not > require a blocking read to obtain the XML data, and is instead fed with data > incrementally with :meth:`XMLPullParser.feed` calls. To get the parsed XML > -elements, call :meth:`XMLPullParser.read_events`. Here's an example:: > +elements, call :meth:`XMLPullParser.read_events`. Here is an example:: > > >>> parser = ET.XMLPullParser(['start', 'end']) > >>> parser.feed('sometext') > @@ -1038,15 +1041,17 @@ > > .. method:: read_events() > > - Iterate over the events which have been encountered in the data fed to the > - parser. This method yields ``(event, elem)`` pairs, where *event* is a > + Return an iterator over the events which have been encountered in the > + data fed to the > + parser. The iterator yields ``(event, elem)`` pairs, where *event* is a > string representing the type of event (e.g. ``"end"``) and *elem* is the > encountered :class:`Element` object. > > Events provided in a previous call to :meth:`read_events` will not be > - yielded again. As events are consumed from the internal queue only as > - they are retrieved from the iterator, multiple readers calling > - :meth:`read_events` in parallel will have unpredictable results. > + yielded again. Events are consumed from the internal queue only when > + they are retrieved from the iterator, so multiple readers iterating in > + parallel over iterators obtained from :meth:`read_events` will have > + unpredictable results. > > .. note:: > > diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst > --- a/Doc/whatsnew/3.4.rst > +++ b/Doc/whatsnew/3.4.rst > @@ -1088,9 +1088,10 @@ > xml.etree > --------- > > -Add an event-driven parser for non-blocking applications, > -:class:`~xml.etree.ElementTree.XMLPullParser`. > -(Contributed by Antoine Pitrou in :issue:`17741`.) > +A new parser, :class:`~xml.etree.ElementTree.XMLPullParser`, allows a > +non-blocking applications to parse XML documents. An example can be > +seen at :ref:`elementtree-pull-parsing`. (Contributed by Antoine > +Pitrou in :issue:`17741`.) > > The :mod:`xml.etree.ElementTree` :func:`~xml.etree.ElementTree.tostring` and > :func:`~xml.etree.ElementTree.tostringlist` functions, and the > diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py > --- a/Lib/xml/etree/ElementTree.py > +++ b/Lib/xml/etree/ElementTree.py > @@ -1251,7 +1251,7 @@ > self._close_and_return_root() > > def read_events(self): > - """Iterate over currently available (event, elem) pairs. > + """Return an iterator over currently available (event, elem) pairs. > > Events are consumed from the internal event queue as they are > retrieved from the iterator. > diff --git a/Misc/NEWS b/Misc/NEWS > --- a/Misc/NEWS > +++ b/Misc/NEWS > @@ -2193,14 +2193,14 @@ > - Issue #17555: Fix ForkAwareThreadLock so that size of after fork > registry does not grow exponentially with generation of process. > > -- Issue #17707: multiprocessing.Queue's get() method does not block for short > - timeouts. > - > -- Isuse #17720: Fix the Python implementation of pickle.Unpickler to correctly > +- Issue #17707: fix regression in multiprocessing.Queue's get() method where > + it did not block for short timeouts. > + > +- Issue #17720: Fix the Python implementation of pickle.Unpickler to correctly > process the APPENDS opcode when it is used on non-list objects. > > -- Issue #17012: shutil.which() no longer fallbacks to the PATH environment > - variable if empty path argument is specified. Patch by Serhiy Storchaka. > +- Issue #17012: shutil.which() no longer falls back to the PATH environment > + variable if an empty path argument is specified. Patch by Serhiy Storchaka. > > - Issue #17710: Fix pickle raising a SystemError on bogus input. > > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > https://mail.python.org/mailman/listinfo/python-checkins > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Mon Jan 6 16:24:48 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 16:24:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Regenerated_pydoc/topics?= =?utf-8?q?=2Epy=2C_and_fix_a_=22suspicious=22_doc_error=2E?= Message-ID: <3dygWN1B3HzT0F@mail.python.org> http://hg.python.org/cpython/rev/f2a958c80485 changeset: 88317:f2a958c80485 parent: 88312:172a6bfdd91b user: Larry Hastings date: Sun Jan 05 04:35:56 2014 -0800 summary: Regenerated pydoc/topics.py, and fix a "suspicious" doc error. files: Doc/reference/import.rst | 2 +- Lib/pydoc_data/topics.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -440,7 +440,7 @@ For compatibility with existing loaders, the import machinery will use the ``load_module()`` method of loaders if it exists and the loader does - not also implement ``exec_module(). However, ``load_module()`` has been + not also implement ``exec_module()``. However, ``load_module()`` has been deprecated and loaders should implement ``exec_module()`` instead. The ``load_module()`` method must implement all the boilerplate loading diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py --- a/Lib/pydoc_data/topics.py +++ b/Lib/pydoc_data/topics.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -# Autogenerated by Sphinx on Sun Nov 24 06:50:34 2013 +# Autogenerated by Sphinx on Sun Jan 5 04:33:19 2014 topics = {'assert': '\nThe ``assert`` statement\n************************\n\nAssert statements are a convenient way to insert debugging assertions\ninto a program:\n\n assert_stmt ::= "assert" expression ["," expression]\n\nThe simple form, ``assert expression``, is equivalent to\n\n if __debug__:\n if not expression: raise AssertionError\n\nThe extended form, ``assert expression1, expression2``, is equivalent\nto\n\n if __debug__:\n if not expression1: raise AssertionError(expression2)\n\nThese equivalences assume that ``__debug__`` and ``AssertionError``\nrefer to the built-in variables with those names. In the current\nimplementation, the built-in variable ``__debug__`` is ``True`` under\nnormal circumstances, ``False`` when optimization is requested\n(command line option -O). The current code generator emits no code\nfor an assert statement when optimization is requested at compile\ntime. Note that it is unnecessary to include the source code for the\nexpression that failed in the error message; it will be displayed as\npart of the stack trace.\n\nAssignments to ``__debug__`` are illegal. The value for the built-in\nvariable is determined when the interpreter starts.\n', 'assignment': '\nAssignment statements\n*********************\n\nAssignment statements are used to (re)bind names to values and to\nmodify attributes or items of mutable objects:\n\n assignment_stmt ::= (target_list "=")+ (expression_list | yield_expression)\n target_list ::= target ("," target)* [","]\n target ::= identifier\n | "(" target_list ")"\n | "[" target_list "]"\n | attributeref\n | subscription\n | slicing\n | "*" target\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn assignment statement evaluates the expression list (remember that\nthis can be a single expression or a comma-separated list, the latter\nyielding a tuple) and assigns the single resulting object to each of\nthe target lists, from left to right.\n\nAssignment is defined recursively depending on the form of the target\n(list). When a target is part of a mutable object (an attribute\nreference, subscription or slicing), the mutable object must\nultimately perform the assignment and decide about its validity, and\nmay raise an exception if the assignment is unacceptable. The rules\nobserved by various types and the exceptions raised are given with the\ndefinition of the object types (see section *The standard type\nhierarchy*).\n\nAssignment of an object to a target list, optionally enclosed in\nparentheses or square brackets, is recursively defined as follows.\n\n* If the target list is a single target: The object is assigned to\n that target.\n\n* If the target list is a comma-separated list of targets: The object\n must be an iterable with the same number of items as there are\n targets in the target list, and the items are assigned, from left to\n right, to the corresponding targets.\n\n * If the target list contains one target prefixed with an asterisk,\n called a "starred" target: The object must be a sequence with at\n least as many items as there are targets in the target list, minus\n one. The first items of the sequence are assigned, from left to\n right, to the targets before the starred target. The final items\n of the sequence are assigned to the targets after the starred\n target. A list of the remaining items in the sequence is then\n assigned to the starred target (the list can be empty).\n\n * Else: The object must be a sequence with the same number of items\n as there are targets in the target list, and the items are\n assigned, from left to right, to the corresponding targets.\n\nAssignment of an object to a single target is recursively defined as\nfollows.\n\n* If the target is an identifier (name):\n\n * If the name does not occur in a ``global`` or ``nonlocal``\n statement in the current code block: the name is bound to the\n object in the current local namespace.\n\n * Otherwise: the name is bound to the object in the global namespace\n or the outer namespace determined by ``nonlocal``, respectively.\n\n The name is rebound if it was already bound. This may cause the\n reference count for the object previously bound to the name to reach\n zero, causing the object to be deallocated and its destructor (if it\n has one) to be called.\n\n* If the target is a target list enclosed in parentheses or in square\n brackets: The object must be an iterable with the same number of\n items as there are targets in the target list, and its items are\n assigned, from left to right, to the corresponding targets.\n\n* If the target is an attribute reference: The primary expression in\n the reference is evaluated. It should yield an object with\n assignable attributes; if this is not the case, ``TypeError`` is\n raised. That object is then asked to assign the assigned object to\n the given attribute; if it cannot perform the assignment, it raises\n an exception (usually but not necessarily ``AttributeError``).\n\n Note: If the object is a class instance and the attribute reference\n occurs on both sides of the assignment operator, the RHS expression,\n ``a.x`` can access either an instance attribute or (if no instance\n attribute exists) a class attribute. The LHS target ``a.x`` is\n always set as an instance attribute, creating it if necessary.\n Thus, the two occurrences of ``a.x`` do not necessarily refer to the\n same attribute: if the RHS expression refers to a class attribute,\n the LHS creates a new instance attribute as the target of the\n assignment:\n\n class Cls:\n x = 3 # class variable\n inst = Cls()\n inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x as 3\n\n This description does not necessarily apply to descriptor\n attributes, such as properties created with ``property()``.\n\n* If the target is a subscription: The primary expression in the\n reference is evaluated. It should yield either a mutable sequence\n object (such as a list) or a mapping object (such as a dictionary).\n Next, the subscript expression is evaluated.\n\n If the primary is a mutable sequence object (such as a list), the\n subscript must yield an integer. If it is negative, the sequence\'s\n length is added to it. The resulting value must be a nonnegative\n integer less than the sequence\'s length, and the sequence is asked\n to assign the assigned object to its item with that index. If the\n index is out of range, ``IndexError`` is raised (assignment to a\n subscripted sequence cannot add new items to a list).\n\n If the primary is a mapping object (such as a dictionary), the\n subscript must have a type compatible with the mapping\'s key type,\n and the mapping is then asked to create a key/datum pair which maps\n the subscript to the assigned object. This can either replace an\n existing key/value pair with the same key value, or insert a new\n key/value pair (if no key with the same value existed).\n\n For user-defined objects, the ``__setitem__()`` method is called\n with appropriate arguments.\n\n* If the target is a slicing: The primary expression in the reference\n is evaluated. It should yield a mutable sequence object (such as a\n list). The assigned object should be a sequence object of the same\n type. Next, the lower and upper bound expressions are evaluated,\n insofar they are present; defaults are zero and the sequence\'s\n length. The bounds should evaluate to integers. If either bound is\n negative, the sequence\'s length is added to it. The resulting\n bounds are clipped to lie between zero and the sequence\'s length,\n inclusive. Finally, the sequence object is asked to replace the\n slice with the items of the assigned sequence. The length of the\n slice may be different from the length of the assigned sequence,\n thus changing the length of the target sequence, if the object\n allows it.\n\n**CPython implementation detail:** In the current implementation, the\nsyntax for targets is taken to be the same as for expressions, and\ninvalid syntax is rejected during the code generation phase, causing\nless detailed error messages.\n\nWARNING: Although the definition of assignment implies that overlaps\nbetween the left-hand side and the right-hand side are \'safe\' (for\nexample ``a, b = b, a`` swaps two variables), overlaps *within* the\ncollection of assigned-to variables are not safe! For instance, the\nfollowing program prints ``[0, 2]``:\n\n x = [0, 1]\n i = 0\n i, x[i] = 1, 2\n print(x)\n\nSee also:\n\n **PEP 3132** - Extended Iterable Unpacking\n The specification for the ``*target`` feature.\n\n\nAugmented assignment statements\n===============================\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like ``x += 1`` can be rewritten as\n``x = x + 1`` to achieve a similar, but not exactly equal effect. In\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n', 'atom-identifiers': '\nIdentifiers (Names)\n*******************\n\nAn identifier occurring as an atom is a name. See section\n*Identifiers and keywords* for lexical definition and section *Naming\nand binding* for documentation of naming and binding.\n\nWhen the name is bound to an object, evaluation of the atom yields\nthat object. When a name is not bound, an attempt to evaluate it\nraises a ``NameError`` exception.\n\n**Private name mangling:** When an identifier that textually occurs in\na class definition begins with two or more underscore characters and\ndoes not end in two or more underscores, it is considered a *private\nname* of that class. Private names are transformed to a longer form\nbefore code is generated for them. The transformation inserts the\nclass name, with leading underscores removed and a single underscore\ninserted, in front of the name. For example, the identifier\n``__spam`` occurring in a class named ``Ham`` will be transformed to\n``_Ham__spam``. This transformation is independent of the syntactical\ncontext in which the identifier is used. If the transformed name is\nextremely long (longer than 255 characters), implementation defined\ntruncation may happen. If the class name consists only of underscores,\nno transformation is done.\n', 'atom-literals': "\nLiterals\n********\n\nPython supports string and bytes literals and various numeric\nliterals:\n\n literal ::= stringliteral | bytesliteral\n | integer | floatnumber | imagnumber\n\nEvaluation of a literal yields an object of the given type (string,\nbytes, integer, floating point number, complex number) with the given\nvalue. The value may be approximated in the case of floating point\nand imaginary (complex) literals. See section *Literals* for details.\n\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': '\nCustomizing attribute access\n****************************\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n========================\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n====================\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n=========\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n--------------------------\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n', + 'attribute-access': '\nCustomizing attribute access\n****************************\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n========================\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n====================\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n=========\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n--------------------------\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``bytes`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n', 'attribute-references': '\nAttribute references\n********************\n\nAn attribute reference is a primary followed by a period and a name:\n\n attributeref ::= primary "." identifier\n\nThe primary must evaluate to an object of a type that supports\nattribute references, which most objects do. This object is then\nasked to produce the attribute whose name is the identifier (which can\nbe customized by overriding the ``__getattr__()`` method). If this\nattribute is not available, the exception ``AttributeError`` is\nraised. Otherwise, the type and value of the object produced is\ndetermined by the object. Multiple evaluations of the same attribute\nreference may yield different objects.\n', 'augassign': '\nAugmented assignment statements\n*******************************\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like ``x += 1`` can be rewritten as\n``x = x + 1`` to achieve a similar, but not exactly equal effect. In\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n', 'binary': '\nBinary arithmetic operations\n****************************\n\nThe binary arithmetic operations have the conventional priority\nlevels. Note that some of these operations also apply to certain non-\nnumeric types. Apart from the power operator, there are only two\nlevels, one for multiplicative operators and one for additive\noperators:\n\n m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr\n | m_expr "%" u_expr\n a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n\nThe ``*`` (multiplication) operator yields the product of its\narguments. The arguments must either both be numbers, or one argument\nmust be an integer and the other must be a sequence. In the former\ncase, the numbers are converted to a common type and then multiplied\ntogether. In the latter case, sequence repetition is performed; a\nnegative repetition factor yields an empty sequence.\n\nThe ``/`` (division) and ``//`` (floor division) operators yield the\nquotient of their arguments. The numeric arguments are first\nconverted to a common type. 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\n``4*0.7 + 0.34``.) The modulo operator always yields a result with\nthe same sign as its second operand (or zero); the absolute value of\nthe result is strictly smaller than the absolute value of the second\noperand [1].\n\nThe floor division and modulo operators are connected by the following\nidentity: ``x == (x//y)*y + (x%y)``. Floor division and modulo are\nalso connected with the built-in function ``divmod()``: ``divmod(x, y)\n== (x//y, x%y)``. [2].\n\nIn addition to performing the modulo operation on numbers, the ``%``\noperator is also overloaded by string objects to perform old-style\nstring formatting (also known as interpolation). The syntax for\nstring formatting is described in the Python Library Reference,\nsection *printf-style String Formatting*.\n\nThe floor division operator, the modulo operator, and the ``divmod()``\nfunction are not defined for complex numbers. Instead, convert to a\nfloating point number using the ``abs()`` function if appropriate.\n\nThe ``+`` (addition) operator yields the sum of its arguments. The\narguments must either both be numbers or both sequences of the same\ntype. In the former case, the numbers are converted to a common type\nand then added together. In the latter case, the sequences are\nconcatenated.\n\nThe ``-`` (subtraction) operator yields the difference of its\narguments. The numeric arguments are first converted to a common\ntype.\n', @@ -60,13 +60,13 @@ 'shifting': '\nShifting operations\n*******************\n\nThe shifting operations have lower priority than the arithmetic\noperations:\n\n shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr\n\nThese operators accept integers as arguments. They shift the first\nargument to the left or right by the number of bits given by the\nsecond argument.\n\nA right shift by *n* bits is defined as floor division by\n``pow(2,n)``. A left shift by *n* bits is defined as multiplication\nwith ``pow(2,n)``.\n\nNote: In the current implementation, the right-hand operand is required to\n be at most ``sys.maxsize``. If the right-hand operand is larger\n than ``sys.maxsize`` an ``OverflowError`` exception is raised.\n', 'slicings': '\nSlicings\n********\n\nA slicing selects a range of items in a sequence object (e.g., a\nstring, tuple or list). Slicings may be used as expressions or as\ntargets in assignment or ``del`` statements. The syntax for a\nslicing:\n\n slicing ::= primary "[" slice_list "]"\n slice_list ::= slice_item ("," slice_item)* [","]\n slice_item ::= expression | proper_slice\n proper_slice ::= [lower_bound] ":" [upper_bound] [ ":" [stride] ]\n lower_bound ::= expression\n upper_bound ::= expression\n stride ::= expression\n\nThere is ambiguity in the formal syntax here: anything that looks like\nan expression list also looks like a slice list, so any subscription\ncan be interpreted as a slicing. Rather than further complicating the\nsyntax, this is disambiguated by defining that in this case the\ninterpretation as a subscription takes priority over the\ninterpretation as a slicing (this is the case if the slice list\ncontains no proper slice).\n\nThe semantics for a slicing are as follows. The primary must evaluate\nto a mapping object, and it is indexed (using the same\n``__getitem__()`` method as normal subscription) with a key that is\nconstructed from the slice list, as follows. If the slice list\ncontains at least one comma, the key is a tuple containing the\nconversion of the slice items; otherwise, the conversion of the lone\nslice item is the key. The conversion of a slice item that is an\nexpression is that expression. The conversion of a proper slice is a\nslice object (see section *The standard type hierarchy*) whose\n``start``, ``stop`` and ``step`` attributes are the values of the\nexpressions given as lower bound, upper bound and stride,\nrespectively, substituting ``None`` for missing expressions.\n', 'specialattrs': '\nSpecial Attributes\n******************\n\nThe implementation adds a few special read-only attributes to several\nobject types, where they are relevant. Some of these are not reported\nby the ``dir()`` built-in function.\n\nobject.__dict__\n\n A dictionary or other mapping object used to store an object\'s\n (writable) attributes.\n\ninstance.__class__\n\n The class to which a class instance belongs.\n\nclass.__bases__\n\n The tuple of base classes of a class object.\n\nclass.__name__\n\n The name of the class or type.\n\nclass.__qualname__\n\n The *qualified name* of the class or type.\n\n New in version 3.3.\n\nclass.__mro__\n\n This attribute is a tuple of classes that are considered when\n looking for base classes during method resolution.\n\nclass.mro()\n\n This method can be overridden by a metaclass to customize the\n method resolution order for its instances. It is called at class\n instantiation, and its result is stored in ``__mro__``.\n\nclass.__subclasses__()\n\n Each class keeps a list of weak references to its immediate\n subclasses. This method returns a list of all those references\n still alive. Example:\n\n >>> int.__subclasses__()\n []\n\n-[ Footnotes ]-\n\n[1] Additional information on these special methods may be found in\n the Python Reference Manual (*Basic customization*).\n\n[2] As a consequence, the list ``[1, 2]`` is considered equal to\n ``[1.0, 2.0]``, and similarly for tuples.\n\n[3] They must have since the parser can\'t tell the type of the\n operands.\n\n[4] Cased characters are those with general category property being\n one of "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt"\n (Letter, titlecase).\n\n[5] To format only a tuple you should therefore provide a singleton\n tuple whose only element is the tuple to be formatted.\n', - 'specialnames': '\nSpecial method names\n********************\n\nA class can implement certain operations that are invoked by special\nsyntax (such as arithmetic operations or subscripting and slicing) by\ndefining methods with special names. This is Python\'s approach to\n*operator overloading*, allowing classes to define their own behavior\nwith respect to language operators. For instance, if a class defines\na method named ``__getitem__()``, and ``x`` is an instance of this\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``TypeError``).\n\nWhen implementing a class that emulates any built-in type, it is\nimportant that the emulation only be implemented to the degree that it\nmakes sense for the object being modelled. For example, some\nsequences may work well with retrieval of individual elements, but\nextracting a slice may not make sense. (One example of this is the\n``NodeList`` interface in the W3C\'s Document Object Model.)\n\n\nBasic customization\n===================\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected and cleaned up when the cyclic garbage collector is\n enabled (it\'s on by default). Refer to the documentation for the\n ``gc`` module for more information about this topic.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by ``str(object)`` and the built-in functions ``format()``\n and ``print()`` to compute the "informal" or nicely printable\n string representation of an object. The return value must be a\n *string* 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\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n Note: ``hash()`` truncates the value returned from an object\'s custom\n ``__hash__()`` method to the size of a ``Py_ssize_t``. This is\n typically 8 bytes on 64-bit builds and 4 bytes on 32-bit builds.\n If an object\'s ``__hash__()`` must interoperate on builds of\n different bit sizes, be sure to check the width on all supported\n builds. An easy way to do this is with ``python -c "import sys;\n 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\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n A class that overrides ``__eq__()`` and does not define\n ``__hash__()`` will have its ``__hash__()`` implicitly set to\n ``None``. When the ``__hash__()`` method of a class is ``None``,\n instances of the class will raise an appropriate ``TypeError`` when\n a program attempts to retrieve their hash value, and will also be\n correctly identified as unhashable when checking ``isinstance(obj,\n collections.Hashable``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``.\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\n as hashable by an ``isinstance(obj, collections.Hashable)`` call.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n\n\nCustomizing attribute access\n============================\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n--------------------\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n---------\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\n\nThe following methods are used to override the default behavior of the\n``isinstance()`` and ``issubclass()`` built-in functions.\n\nIn particular, the metaclass ``abc.ABCMeta`` implements these methods\nin order to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n ``isinstance(instance, class)``.\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n ``issubclass(subclass, class)``.\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also:\n\n **PEP 3119** - Introducing Abstract Base Classes\n Includes the specification for customizing ``isinstance()`` and\n ``issubclass()`` behavior through ``__instancecheck__()`` and\n ``__subclasscheck__()``, with motivation for this functionality\n in the context of adding Abstract Base Classes (see the ``abc``\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, ``x(arg1, arg2, ...)`` is a shorthand for\n ``x.__call__(arg1, arg2, ...)``.\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which ``0 <= k < N``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function ``len()``. Should return\n the length of the object, an integer ``>=`` 0. Also, an object\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\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. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n should be raised.\n\n Note: ``for`` loops expect that an ``IndexError`` will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the ``__getitem__()`` method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the ``__getitem__()``\n method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method ``keys()``.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the ``reversed()`` built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the ``__reversed__()`` method is not provided, the\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\n\nThe membership test operators (``in`` and ``not in``) are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define ``__contains__()``, the membership\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__truediv__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return ``NotImplemented``.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\n ``**=``, ``<<=``, ``>>=``, ``&=``, ``^=``, ``|=``). These methods\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n considered, as with the evaluation of ``x + y``.\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations (``-``, ``+``,\n ``abs()`` and ``~``).\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: object of type \'C\' has no len()\n\nThe rationale behind this behaviour lies with a number of special\nmethods such as ``__hash__()`` and ``__repr__()`` that are implemented\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen invoked on the type object itself:\n\n >>> 1 .__hash__() == hash(1)\n True\n >>> int.__hash__() == hash(int)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe ``__getattribute__()`` method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print("Metaclass getattribute invoked")\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object, metaclass=Meta):\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print("Class getattribute invoked")\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the ``__getattribute__()`` machinery in this fashion\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n handled incorrectly.\n\n[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', - 'string-methods': '\nString Methods\n**************\n\nStrings implement all of the *common* sequence operations, along with\nthe additional methods described below.\n\nStrings also support two styles of string formatting, one providing a\nlarge degree of flexibility and customization (see ``str.format()``,\n*Format String Syntax* and *String Formatting*) and the other based on\nC ``printf`` style formatting that handles a narrower range of types\nand is slightly harder to use correctly, but is often faster for the\ncases it can handle (*printf-style String Formatting*).\n\nThe *Text Processing Services* section of the standard library covers\na number of other modules that provide various text related utilities\n(including regular expression support in the ``re`` module).\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs(tabsize=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\n result until the current column is equal to the next tab position.\n (The tab character itself is not copied.) If the character is a\n newline (``\\n``) or return (``\\r``), it is copied and the current\n column is reset to zero. Any other character is copied unchanged\n and the 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, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\n Use ``keyword.iskeyword()`` to test for reserved identifiers such\n as ``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 a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the *universal newlines* approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n\', \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n ... lambda mo: mo.group(0)[0].upper() +\n ... mo.group(0)[1:].lower(),\n ... s)\n ...\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', + 'specialnames': '\nSpecial method names\n********************\n\nA class can implement certain operations that are invoked by special\nsyntax (such as arithmetic operations or subscripting and slicing) by\ndefining methods with special names. This is Python\'s approach to\n*operator overloading*, allowing classes to define their own behavior\nwith respect to language operators. For instance, if a class defines\na method named ``__getitem__()``, and ``x`` is an instance of this\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``TypeError``).\n\nWhen implementing a class that emulates any built-in type, it is\nimportant that the emulation only be implemented to the degree that it\nmakes sense for the object being modelled. For example, some\nsequences may work well with retrieval of individual elements, but\nextracting a slice may not make sense. (One example of this is the\n``NodeList`` interface in the W3C\'s Document Object Model.)\n\n\nBasic customization\n===================\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected and cleaned up when the cyclic garbage collector is\n enabled (it\'s on by default). Refer to the documentation for the\n ``gc`` module for more information about this topic.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by ``str(object)`` and the built-in functions ``format()``\n and ``print()`` to compute the "informal" or nicely printable\n string representation of an object. The return value must be a\n *string* 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\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n Note: ``hash()`` truncates the value returned from an object\'s custom\n ``__hash__()`` method to the size of a ``Py_ssize_t``. This is\n typically 8 bytes on 64-bit builds and 4 bytes on 32-bit builds.\n If an object\'s ``__hash__()`` must interoperate on builds of\n different bit sizes, be sure to check the width on all supported\n builds. An easy way to do this is with ``python -c "import sys;\n 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\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n A class that overrides ``__eq__()`` and does not define\n ``__hash__()`` will have its ``__hash__()`` implicitly set to\n ``None``. When the ``__hash__()`` method of a class is ``None``,\n instances of the class will raise an appropriate ``TypeError`` when\n a program attempts to retrieve their hash value, and will also be\n correctly identified as unhashable when checking ``isinstance(obj,\n collections.Hashable``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``.\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\n as hashable by an ``isinstance(obj, collections.Hashable)`` call.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n\n\nCustomizing attribute access\n============================\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n--------------------\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n---------\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``bytes`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\n\nThe following methods are used to override the default behavior of the\n``isinstance()`` and ``issubclass()`` built-in functions.\n\nIn particular, the metaclass ``abc.ABCMeta`` implements these methods\nin order to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n ``isinstance(instance, class)``.\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n ``issubclass(subclass, class)``.\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also:\n\n **PEP 3119** - Introducing Abstract Base Classes\n Includes the specification for customizing ``isinstance()`` and\n ``issubclass()`` behavior through ``__instancecheck__()`` and\n ``__subclasscheck__()``, with motivation for this functionality\n in the context of adding Abstract Base Classes (see the ``abc``\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, ``x(arg1, arg2, ...)`` is a shorthand for\n ``x.__call__(arg1, arg2, ...)``.\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which ``0 <= k < N``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function ``len()``. Should return\n the length of the object, an integer ``>=`` 0. Also, an object\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\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. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n should be raised.\n\n Note: ``for`` loops expect that an ``IndexError`` will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the ``__getitem__()`` method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the ``__getitem__()``\n method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method ``keys()``.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the ``reversed()`` built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the ``__reversed__()`` method is not provided, the\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\n\nThe membership test operators (``in`` and ``not in``) are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define ``__contains__()``, the membership\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__truediv__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return ``NotImplemented``.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\n ``**=``, ``<<=``, ``>>=``, ``&=``, ``^=``, ``|=``). These methods\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n considered, as with the evaluation of ``x + y``.\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations (``-``, ``+``,\n ``abs()`` and ``~``).\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: object of type \'C\' has no len()\n\nThe rationale behind this behaviour lies with a number of special\nmethods such as ``__hash__()`` and ``__repr__()`` that are implemented\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen invoked on the type object itself:\n\n >>> 1 .__hash__() == hash(1)\n True\n >>> int.__hash__() == hash(int)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe ``__getattribute__()`` method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print("Metaclass getattribute invoked")\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object, metaclass=Meta):\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print("Class getattribute invoked")\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the ``__getattribute__()`` machinery in this fashion\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n handled incorrectly.\n\n[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', + 'string-methods': '\nString Methods\n**************\n\nStrings implement all of the *common* sequence operations, along with\nthe additional methods described below.\n\nStrings also support two styles of string formatting, one providing a\nlarge degree of flexibility and customization (see ``str.format()``,\n*Format String Syntax* and *String Formatting*) and the other based on\nC ``printf`` style formatting that handles a narrower range of types\nand is slightly harder to use correctly, but is often faster for the\ncases it can handle (*printf-style String Formatting*).\n\nThe *Text Processing Services* section of the standard library covers\na number of other modules that provide various text related utilities\n(including regular expression support in the ``re`` module).\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs(tabsize=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\n result until the current column is equal to the next tab position.\n (The tab character itself is not copied.) If the character is a\n newline (``\\n``) or return (``\\r``), it is copied and the current\n column is reset to zero. Any other character is copied unchanged\n and the 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, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict``. This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\n Use ``keyword.iskeyword()`` to test for reserved identifiers such\n as ``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 a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the *universal newlines* approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n\', \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n ... lambda mo: mo.group(0)[0].upper() +\n ... mo.group(0)[1:].lower(),\n ... s)\n ...\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', 'strings': '\nString and Bytes literals\n*************************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "R" | "U"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'" | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | stringescapeseq\n longstringitem ::= longstringchar | stringescapeseq\n shortstringchar ::= \n longstringchar ::= \n stringescapeseq ::= "\\" \n\n bytesliteral ::= bytesprefix(shortbytes | longbytes)\n bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"\n shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' shortbytesitem* \'"\'\n longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' longbytesitem* \'"""\'\n shortbytesitem ::= shortbyteschar | bytesescapeseq\n longbytesitem ::= longbyteschar | bytesescapeseq\n shortbyteschar ::= \n longbyteschar ::= \n bytesescapeseq ::= "\\" \n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the ``stringprefix`` or\n``bytesprefix`` and the rest of the literal. The source character set\nis defined by the encoding declaration; it is UTF-8 if no encoding\ndeclaration is given in the source file; see section *Encoding\ndeclarations*.\n\nIn plain English: Both types of literals can be enclosed in matching\nsingle quotes (``\'``) or double quotes (``"``). They can also be\nenclosed in matching groups of three single or double quotes (these\nare generally referred to as *triple-quoted strings*). The backslash\n(``\\``) character is used to escape characters that otherwise have a\nspecial meaning, such as newline, backslash itself, or the quote\ncharacter.\n\nBytes literals are always prefixed with ``\'b\'`` or ``\'B\'``; they\nproduce an instance of the ``bytes`` type instead of the ``str`` type.\nThey may only contain ASCII characters; bytes with a numeric value of\n128 or greater must be expressed with escapes.\n\nAs of Python 3.3 it is possible again to prefix unicode strings with a\n``u`` prefix to simplify maintenance of dual 2.x and 3.x codebases.\n\nBoth string and bytes literals may optionally be prefixed with a\nletter ``\'r\'`` or ``\'R\'``; such strings are called *raw strings* and\ntreat backslashes as literal characters. As a result, in string\nliterals, ``\'\\U\'`` and ``\'\\u\'`` escapes in raw strings are not treated\nspecially. Given that Python 2.x\'s raw unicode literals behave\ndifferently than Python 3.x\'s the ``\'ur\'`` syntax is not supported.\n\n New in version 3.3: The ``\'rb\'`` prefix of raw bytes literals has\n been added as a synonym of ``\'br\'``.\n\n New in version 3.3: Support for the unicode legacy literal\n (``u\'value\'``) was reintroduced to simplify the maintenance of dual\n Python 2.x and 3.x codebases. See **PEP 414** for more information.\n\nIn triple-quoted strings, unescaped newlines and quotes are allowed\n(and are retained), except that three unescaped quotes in a row\nterminate the string. (A "quote" is the character used to open the\nstring, i.e. either ``\'`` or ``"``.)\n\nUnless an ``\'r\'`` or ``\'R\'`` prefix is present, escape sequences in\nstrings are interpreted according to rules similar to those used by\nStandard C. The recognized escape sequences are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\newline`` | Backslash and newline ignored | |\n+-------------------+-----------------------------------+---------+\n| ``\\\\`` | Backslash (``\\``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\\'`` | Single quote (``\'``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\"`` | Double quote (``"``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\a`` | ASCII Bell (BEL) | |\n+-------------------+-----------------------------------+---------+\n| ``\\b`` | ASCII Backspace (BS) | |\n+-------------------+-----------------------------------+---------+\n| ``\\f`` | ASCII Formfeed (FF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\n`` | ASCII Linefeed (LF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\r`` | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| ``\\t`` | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| ``\\v`` | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| ``\\ooo`` | Character with octal value *ooo* | (1,3) |\n+-------------------+-----------------------------------+---------+\n| ``\\xhh`` | Character with hex value *hh* | (2,3) |\n+-------------------+-----------------------------------+---------+\n\nEscape sequences only recognized in string literals are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\N{name}`` | Character named *name* in the | (4) |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (5) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (6) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, exactly two hex digits are required.\n\n3. In a bytes literal, hexadecimal and octal escapes denote the byte\n with the given value. In a string literal, these escapes denote a\n Unicode character with the given value.\n\n4. Changed in version 3.3: Support for name aliases [1] has been\n added.\n\n5. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Exactly four hex digits are\n required.\n\n6. Any Unicode character can be encoded this way. Exactly eight hex\n digits are required.\n\nUnlike Standard C, all unrecognized escape sequences are left in the\nstring unchanged, i.e., *the backslash is left in the string*. (This\nbehavior is useful when debugging: if an escape sequence is mistyped,\nthe resulting output is more easily recognized as broken.) It is also\nimportant to note that the escape sequences only recognized in string\nliterals fall into the category of unrecognized escapes for bytes\nliterals.\n\nEven in a raw string, string quotes can be escaped with a backslash,\nbut the backslash remains in the string; for example, ``r"\\""`` is a\nvalid string literal consisting of two characters: a backslash and a\ndouble quote; ``r"\\"`` is not a valid string literal (even a raw\nstring cannot end in an odd number of backslashes). Specifically, *a\nraw string cannot end in a single backslash* (since the backslash\nwould escape the following quote character). Note also that a single\nbackslash followed by a newline is interpreted as those two characters\nas part of the string, *not* as a line continuation.\n', 'subscriptions': '\nSubscriptions\n*************\n\nA subscription selects an item of a sequence (string, tuple or list)\nor mapping (dictionary) object:\n\n subscription ::= primary "[" expression_list "]"\n\nThe primary must evaluate to an object that supports subscription,\ne.g. a list or dictionary. User-defined objects can support\nsubscription by defining a ``__getitem__()`` method.\n\nFor built-in objects, there are two types of objects that support\nsubscription:\n\nIf the primary is a mapping, the expression list must evaluate to an\nobject whose value is one of the keys of the mapping, and the\nsubscription selects the value in the mapping that corresponds to that\nkey. (The expression list is a tuple except if it has exactly one\nitem.)\n\nIf the primary is a sequence, the expression (list) must evaluate to\nan integer or a slice (as discussed in the following section).\n\nThe formal syntax makes no special provision for negative indices in\nsequences; however, built-in sequences all provide a ``__getitem__()``\nmethod that interprets negative indices by adding the length of the\nsequence to the index (so that ``x[-1]`` selects the last item of\n``x``). The resulting value must be a nonnegative integer less than\nthe number of items in the sequence, and the subscription selects the\nitem whose index is that value (counting from zero). Since the support\nfor negative indices and slicing occurs in the object\'s\n``__getitem__()`` method, subclasses overriding this method will need\nto explicitly add that support.\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n', 'truth': "\nTruth Value Testing\n*******************\n\nAny object can be tested for truth value, for use in an ``if`` or\n``while`` condition or as operand of the Boolean operations below. The\nfollowing values are considered false:\n\n* ``None``\n\n* ``False``\n\n* zero of any numeric type, for example, ``0``, ``0.0``, ``0j``.\n\n* any empty sequence, for example, ``''``, ``()``, ``[]``.\n\n* any empty mapping, for example, ``{}``.\n\n* instances of user-defined classes, if the class defines a\n ``__bool__()`` or ``__len__()`` method, when that method returns the\n integer zero or ``bool`` value ``False``. [1]\n\nAll other values are considered true --- so objects of many types are\nalways true.\n\nOperations and built-in functions that have a Boolean result always\nreturn ``0`` or ``False`` for false and ``1`` or ``True`` for true,\nunless otherwise stated. (Important exception: the Boolean operations\n``or`` and ``and`` always return one of their operands.)\n", 'try': '\nThe ``try`` statement\n*********************\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception it is re-raised at the end of\nthe ``finally`` clause. If the ``finally`` clause raises another\nexception, the saved exception is set as the context of the new\nexception. If the ``finally`` clause executes a ``return`` or\n``break`` statement, the saved exception is discarded:\n\n def f():\n try:\n 1/0\n finally:\n return 42\n\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the ``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', - 'types': '\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.), although such additions\nwill often be provided via the standard library instead.\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name ``None``.\n It is used to signify the absence of a value in many situations,\n e.g., it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n ``NotImplemented``. Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the literal ``...`` or the\n built-in name ``Ellipsis``. Its truth value is true.\n\n``numbers.Number``\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n ``numbers.Integral``\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are two types of integers:\n\n Integers (``int``)\n\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, and Boolean values behave like the values 0 and 1,\n respectively, in almost all contexts, the exception being\n that when converted to a string, the strings ``"False"`` or\n ``"True"`` are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers.\n\n ``numbers.Real`` (``float``)\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these is\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n ``numbers.Complex`` (``complex``)\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number ``z`` can be retrieved through the read-only\n attributes ``z.real`` and ``z.imag``.\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function ``len()`` returns the number of\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is selected by ``a[i]``.\n\n Sequences also support slicing: ``a[i:j]`` selects all items with\n index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: ``a[i:j:k]`` selects all items of *a* with index *x*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'``) and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and ``del`` (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in ``bytearray()`` constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module ``array`` provides an additional example of\n a mutable sequence type, as does the ``collections`` module.\n\nSet types\n These represent unordered, finite sets of unique, immutable\n objects. As such, they cannot be indexed by any subscript. However,\n they can be iterated over, and the built-in function ``len()``\n returns the number of items in a set. Common uses for sets are fast\n membership testing, removing duplicates from a sequence, and\n computing mathematical operations such as intersection, union,\n difference, and symmetric difference.\n\n For set elements, the same immutability rules apply as for\n dictionary keys. Note that numeric types obey the normal rules for\n numeric comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``), only one of them can be contained in a set.\n\n There are currently two intrinsic set types:\n\n Sets\n These represent a mutable set. They are created by the built-in\n ``set()`` constructor and can be modified afterwards by several\n methods, such as ``add()``.\n\n Frozen sets\n These represent an immutable set. They are created by the\n built-in ``frozenset()`` constructor. As a frozenset is\n immutable and *hashable*, it can be used again as an element of\n another set, or as a dictionary key.\n\nMappings\n These represent finite sets of objects indexed by arbitrary index\n sets. The subscript notation ``a[k]`` selects the item indexed by\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``len()`` returns the number of items in a mapping.\n\n There is currently a single intrinsic mapping type:\n\n Dictionaries\n These represent finite sets of objects indexed by nearly\n arbitrary values. The only types of values not acceptable as\n keys are values containing lists or dictionaries or other\n mutable types that are compared by value rather than by object\n identity, the reason being that the efficient implementation of\n dictionaries requires a key\'s hash value to remain constant.\n Numeric types used for keys obey the normal rules for numeric\n comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``) then they can be used interchangeably to index the same\n dictionary entry.\n\n Dictionaries are mutable; they can be created by the ``{...}``\n notation (see section *Dictionary displays*).\n\n The extension modules ``dbm.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\n\nCallable types\n These are the types to which the function call operation (see\n section *Calls*) can be applied:\n\n User-defined functions\n A user-defined function object is created by a function\n definition (see section *Function definitions*). It should be\n called with an argument list containing the same number of items\n as the function\'s formal parameter list.\n\n Special attributes:\n\n +---------------------------+---------------------------------+-------------+\n | Attribute | Meaning | |\n +===========================+=================================+=============+\n | ``__doc__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\n +---------------------------+---------------------------------+-------------+\n | ``__module__`` | The name of the module the | Writable |\n | | function was defined in, or | |\n | | ``None`` if unavailable. | |\n +---------------------------+---------------------------------+-------------+\n | ``__defaults__`` | A tuple containing default | Writable |\n | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | that holds the function\'s | |\n | | global variables --- the global | |\n | | namespace of the module in | |\n | | which the function was defined. | |\n +---------------------------+---------------------------------+-------------+\n | ``__dict__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | or ``\'return\'`` for the return | |\n | | annotation, if provided. | |\n +---------------------------+---------------------------------+-------------+\n | ``__kwdefaults__`` | A dict containing defaults for | Writable |\n | | keyword-only parameters. | |\n +---------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\n\n Function objects also support getting and setting arbitrary\n attributes, which can be used, for example, to attach metadata\n to functions. Regular attribute dot-notation is used to get and\n set such attributes. *Note that the current implementation only\n supports function attributes on user-defined functions. Function\n attributes on built-in functions may be supported in the\n future.*\n\n Additional information about a function\'s definition can be\n retrieved from its code object; see the description of internal\n types below.\n\n Instance methods\n An instance method object combines a class, a class instance and\n any callable object (normally a user-defined function).\n\n Special read-only attributes: ``__self__`` is the class instance\n object, ``__func__`` is the function object; ``__doc__`` is the\n method\'s documentation (same as ``__func__.__doc__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\n\n Methods also support accessing (but not setting) the arbitrary\n function attributes on the underlying function object.\n\n User-defined method objects may be created when getting an\n attribute of a class (perhaps via an instance of that class), if\n that attribute is a user-defined function object or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__func__``\n attribute is the original function object.\n\n When a user-defined method object is created by retrieving\n another method object from a class or instance, the behaviour is\n the same as for a function object, except that the ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n of the class.\n\n Generator functions\n A function or method which uses the ``yield`` statement (see\n section *The yield statement*) is called a *generator function*.\n Such a function, when called, always returns an iterator object\n which can be used to execute the body of the function: calling\n the iterator\'s ``iterator.__next__()`` method will cause the\n function to execute until it provides a value using the\n ``yield`` statement. When the function executes a ``return``\n statement or falls off the end, a ``StopIteration`` exception is\n raised and the iterator will have reached the end of the set of\n values to be returned.\n\n Built-in functions\n A built-in function object is a wrapper around a C function.\n Examples of built-in functions are ``len()`` and ``math.sin()``\n (``math`` is a standard built-in module). The number and type of\n the arguments are determined by the C function. Special read-\n only attributes: ``__doc__`` is the function\'s documentation\n string, or ``None`` if unavailable; ``__name__`` is the\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined in or ``None`` if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n ``alist.append()``, assuming *alist* is a list object. In this\n case, the special read-only attribute ``__self__`` is set to the\n object denoted by *alist*.\n\n Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the ``import``\n statement (see ``import``), or by calling functions such as\n ``importlib.import_module()`` and built-in ``__import__()``. A\n module object has a namespace implemented by a dictionary object\n (this is the dictionary referenced by the ``__globals__`` attribute\n of functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., ``m.x`` is\n equivalent to ``m.__dict__["x"]``. A module object does not contain\n the code object used to initialize the module (since it isn\'t\n needed once the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., ``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.\n\n Special read-only attribute: ``__dict__`` is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: ``__name__`` is the module\'s\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute may be missing for certain types of modules,\n such as C modules that are statically linked into the interpreter;\n for extension modules loaded dynamically from a shared library, it\n is the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\n\n Class attribute assignments update the class\'s dictionary, never\n the dictionary of a base class.\n\n A class object can be called (see above) to yield a class instance\n (see below).\n\n Special attributes: ``__name__`` is the class name; ``__module__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n undefined.\n\nClass instances\n A class instance is created by calling a class object (see above).\n A class instance has a namespace implemented as a dictionary which\n is the first place in which attribute references are searched.\n When an attribute is not found there, and the instance\'s class has\n an attribute by that name, the search continues with the class\n attributes. If a class attribute is found that is a user-defined\n function object, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n lookup.\n\n Attribute assignments and deletions update the instance\'s\n dictionary, never a class\'s dictionary. If the class has a\n ``__setattr__()`` or ``__delattr__()`` method, this is called\n instead of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n *Special method names*.\n\n Special attributes: ``__dict__`` is the attribute dictionary;\n ``__class__`` is the instance\'s class.\n\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: ``co_name`` gives the function\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n the filename from which the code was compiled;\n ``co_firstlineno`` is the first line number of the function;\n ``co_lnotab`` is a string encoding the mapping from bytecode\n offsets to line numbers (for details see the source code of the\n interpreter); ``co_stacksize`` is the required stack size\n (including local variables); ``co_flags`` is an integer encoding\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of Python.\n\n Other bits in ``co_flags`` are reserved for internal use.\n\n If a code object represents a function, the first item in\n ``co_consts`` is the documentation string of the function, or\n ``None`` if undefined.\n\n Frame objects\n Frame objects represent execution frames. They may occur in\n traceback objects (see below).\n\n Special read-only attributes: ``f_back`` is to the previous\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string of the code object).\n\n Special writable attributes: ``f_trace``, if not ``None``, is a\n function called at the start of each source code line (this is\n used by the debugger); ``f_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n by writing to f_lineno.\n\n 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\n 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\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n ``staticmethod()`` constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in ``classmethod()`` constructor.\n', + 'types': '\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.), although such additions\nwill often be provided via the standard library instead.\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name ``None``.\n It is used to signify the absence of a value in many situations,\n e.g., it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n ``NotImplemented``. Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the literal ``...`` or the\n built-in name ``Ellipsis``. Its truth value is true.\n\n``numbers.Number``\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n ``numbers.Integral``\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are two types of integers:\n\n Integers (``int``)\n\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans (``bool``)\n These represent the truth values False and True. The two\n objects representing the values ``False`` and ``True`` are\n the only Boolean objects. The Boolean type is a subtype of\n the integer type, and Boolean values behave like the values 0\n and 1, respectively, in almost all contexts, the exception\n being that when converted to a string, the strings\n ``"False"`` or ``"True"`` are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers.\n\n ``numbers.Real`` (``float``)\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these is\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n ``numbers.Complex`` (``complex``)\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number ``z`` can be retrieved through the read-only\n attributes ``z.real`` and ``z.imag``.\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function ``len()`` returns the number of\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is selected by ``a[i]``.\n\n Sequences also support slicing: ``a[i:j]`` selects all items with\n index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: ``a[i:j:k]`` selects all items of *a* with index *x*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'``) and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and ``del`` (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in ``bytearray()`` constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module ``array`` provides an additional example of\n a mutable sequence type, as does the ``collections`` module.\n\nSet types\n These represent unordered, finite sets of unique, immutable\n objects. As such, they cannot be indexed by any subscript. However,\n they can be iterated over, and the built-in function ``len()``\n returns the number of items in a set. Common uses for sets are fast\n membership testing, removing duplicates from a sequence, and\n computing mathematical operations such as intersection, union,\n difference, and symmetric difference.\n\n For set elements, the same immutability rules apply as for\n dictionary keys. Note that numeric types obey the normal rules for\n numeric comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``), only one of them can be contained in a set.\n\n There are currently two intrinsic set types:\n\n Sets\n These represent a mutable set. They are created by the built-in\n ``set()`` constructor and can be modified afterwards by several\n methods, such as ``add()``.\n\n Frozen sets\n These represent an immutable set. They are created by the\n built-in ``frozenset()`` constructor. As a frozenset is\n immutable and *hashable*, it can be used again as an element of\n another set, or as a dictionary key.\n\nMappings\n These represent finite sets of objects indexed by arbitrary index\n sets. The subscript notation ``a[k]`` selects the item indexed by\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``len()`` returns the number of items in a mapping.\n\n There is currently a single intrinsic mapping type:\n\n Dictionaries\n These represent finite sets of objects indexed by nearly\n arbitrary values. The only types of values not acceptable as\n keys are values containing lists or dictionaries or other\n mutable types that are compared by value rather than by object\n identity, the reason being that the efficient implementation of\n dictionaries requires a key\'s hash value to remain constant.\n Numeric types used for keys obey the normal rules for numeric\n comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``) then they can be used interchangeably to index the same\n dictionary entry.\n\n Dictionaries are mutable; they can be created by the ``{...}``\n notation (see section *Dictionary displays*).\n\n The extension modules ``dbm.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\n\nCallable types\n These are the types to which the function call operation (see\n section *Calls*) can be applied:\n\n User-defined functions\n A user-defined function object is created by a function\n definition (see section *Function definitions*). It should be\n called with an argument list containing the same number of items\n as the function\'s formal parameter list.\n\n Special attributes:\n\n +---------------------------+---------------------------------+-------------+\n | Attribute | Meaning | |\n +===========================+=================================+=============+\n | ``__doc__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\n +---------------------------+---------------------------------+-------------+\n | ``__module__`` | The name of the module the | Writable |\n | | function was defined in, or | |\n | | ``None`` if unavailable. | |\n +---------------------------+---------------------------------+-------------+\n | ``__defaults__`` | A tuple containing default | Writable |\n | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | that holds the function\'s | |\n | | global variables --- the global | |\n | | namespace of the module in | |\n | | which the function was defined. | |\n +---------------------------+---------------------------------+-------------+\n | ``__dict__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | 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__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\n\n Methods also support accessing (but not setting) the arbitrary\n function attributes on the underlying function object.\n\n User-defined method objects may be created when getting an\n attribute of a class (perhaps via an instance of that class), if\n that attribute is a user-defined function object or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__func__``\n attribute is the original function object.\n\n When a user-defined method object is created by retrieving\n another method object from a class or instance, the behaviour is\n the same as for a function object, except that the ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n of the class.\n\n Generator functions\n A function or method which uses the ``yield`` statement (see\n section *The yield statement*) is called a *generator function*.\n Such a function, when called, always returns an iterator object\n which can be used to execute the body of the function: calling\n the iterator\'s ``iterator.__next__()`` method will cause the\n function to execute until it provides a value using the\n ``yield`` statement. When the function executes a ``return``\n statement or falls off the end, a ``StopIteration`` exception is\n raised and the iterator will have reached the end of the set of\n values to be returned.\n\n Built-in functions\n A built-in function object is a wrapper around a C function.\n Examples of built-in functions are ``len()`` and ``math.sin()``\n (``math`` is a standard built-in module). The number and type of\n the arguments are determined by the C function. Special read-\n only attributes: ``__doc__`` is the function\'s documentation\n string, or ``None`` if unavailable; ``__name__`` is the\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined in or ``None`` if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n ``alist.append()``, assuming *alist* is a list object. In this\n case, the special read-only attribute ``__self__`` is set to the\n object denoted by *alist*.\n\n Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the ``import``\n statement (see ``import``), or by calling functions such as\n ``importlib.import_module()`` and built-in ``__import__()``. A\n module object has a namespace implemented by a dictionary object\n (this is the dictionary referenced by the ``__globals__`` attribute\n of functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., ``m.x`` is\n equivalent to ``m.__dict__["x"]``. A module object does not contain\n the code object used to initialize the module (since it isn\'t\n needed once the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., ``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.\n\n Special read-only attribute: ``__dict__`` is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: ``__name__`` is the module\'s\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute may be missing for certain types of modules,\n such as C modules that are statically linked into the interpreter;\n for extension modules loaded dynamically from a shared library, it\n is the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\n\n Class attribute assignments update the class\'s dictionary, never\n the dictionary of a base class.\n\n A class object can be called (see above) to yield a class instance\n (see below).\n\n Special attributes: ``__name__`` is the class name; ``__module__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n undefined.\n\nClass instances\n A class instance is created by calling a class object (see above).\n A class instance has a namespace implemented as a dictionary which\n is the first place in which attribute references are searched.\n When an attribute is not found there, and the instance\'s class has\n an attribute by that name, the search continues with the class\n attributes. If a class attribute is found that is a user-defined\n function object, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n lookup.\n\n Attribute assignments and deletions update the instance\'s\n dictionary, never a class\'s dictionary. If the class has a\n ``__setattr__()`` or ``__delattr__()`` method, this is called\n instead of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n *Special method names*.\n\n Special attributes: ``__dict__`` is the attribute dictionary;\n ``__class__`` is the instance\'s class.\n\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: ``co_name`` gives the function\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n the filename from which the code was compiled;\n ``co_firstlineno`` is the first line number of the function;\n ``co_lnotab`` is a string encoding the mapping from bytecode\n offsets to line numbers (for details see the source code of the\n interpreter); ``co_stacksize`` is the required stack size\n (including local variables); ``co_flags`` is an integer encoding\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of Python.\n\n Other bits in ``co_flags`` are reserved for internal use.\n\n If a code object represents a function, the first item in\n ``co_consts`` is the documentation string of the function, or\n ``None`` if undefined.\n\n Frame objects\n Frame objects represent execution frames. They may occur in\n traceback objects (see below).\n\n Special read-only attributes: ``f_back`` is to the previous\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string of the code object).\n\n Special writable attributes: ``f_trace``, if not ``None``, is a\n function called at the start of each source code line (this is\n used by the debugger); ``f_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n by writing to f_lineno.\n\n 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\n 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\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n ``staticmethod()`` constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in ``classmethod()`` constructor.\n', 'typesfunctions': '\nFunctions\n*********\n\nFunction objects are created by function definitions. The only\noperation on a function object is to call it: ``func(argument-list)``.\n\nThere are really two flavors of function objects: built-in functions\nand user-defined functions. Both support the same operation (to call\nthe function), but the implementation is different, hence the\ndifferent object types.\n\nSee *Function definitions* for more information.\n', 'typesmapping': '\nMapping Types --- ``dict``\n**************************\n\nA *mapping* object maps *hashable* values to arbitrary objects.\nMappings are mutable objects. There is currently only one standard\nmapping type, the *dictionary*. (For other containers see the built-\nin ``list``, ``set``, and ``tuple`` classes, and the ``collections``\nmodule.)\n\nA dictionary\'s keys are *almost* arbitrary values. Values that are\nnot *hashable*, that is, values containing lists, dictionaries or\nother mutable types (that are compared by value rather than by object\nidentity) may not be used as keys. Numeric types used for keys obey\nthe normal rules for numeric comparison: if two numbers compare equal\n(such as ``1`` and ``1.0``) then they can be used interchangeably to\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict(**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 *iterator*\n object. Each item in the iterable must itself be an iterator 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__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\n\n d[key] = value\n\n Set ``d[key]`` to *value*.\n\n del d[key]\n\n Remove ``d[key]`` from *d*. Raises a ``KeyError`` if *key* is\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n classmethod fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n ``fromkeys()`` is a class method that returns a new dictionary.\n *value* defaults to ``None``.\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to ``None``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a ``KeyError`` is raised.\n\n popitem()\n\n Remove and return an arbitrary ``(key, value)`` pair from the\n dictionary.\n\n ``popitem()`` is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling ``popitem()`` raises a ``KeyError``.\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to ``None``.\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return ``None``.\n\n ``update()`` accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: ``d.update(red=1,\n blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` are *view objects*. They provide a dynamic view on\nthe dictionary\'s entries, which means that when the dictionary\nchanges, the view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of ``(key, value)``) in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of ``(value, key)`` pairs\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n d.items()]``.\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a ``RuntimeError`` or fail to iterate over all entries.\n\nx in dictview\n\n Return ``True`` if *x* is in the underlying dictionary\'s keys,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that ``(key, value)`` pairs are unique\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.abc.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', 'typesmethods': '\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as ``append()`` on\nlists) and class instance methods. Built-in methods are described\nwith the types that support them.\n\nIf you access a method (a function defined in a class namespace)\nthrough an instance, you get a special object: a *bound method* (also\ncalled *instance method*) object. When called, it will add the\n``self`` argument to the argument list. Bound methods have two\nspecial read-only attributes: ``m.__self__`` is the object on which\nthe method operates, and ``m.__func__`` is the function implementing\nthe method. Calling ``m(arg-1, arg-2, ..., arg-n)`` is completely\nequivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,\narg-n)``.\n\nLike function objects, bound method objects support getting arbitrary\nattributes. However, since method attributes are actually stored on\nthe underlying function object (``meth.__func__``), setting method\nattributes on bound methods is disallowed. Attempting to set an\nattribute on a method results in an ``AttributeError`` being raised.\nIn order to set a method attribute, you need to explicitly set it on\nthe 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 "", line 1, in \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', -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 16:24:49 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 16:24:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Bump_version_number_for_3?= =?utf-8?b?LjQuMGIyLg==?= Message-ID: <3dygWP2tLyzT0F@mail.python.org> http://hg.python.org/cpython/rev/ba32913eb13e changeset: 88318:ba32913eb13e tag: v3.4.0b2 user: Larry Hastings date: Sun Jan 05 04:40:25 2014 -0800 summary: Bump version number for 3.4.0b2. files: Include/patchlevel.h | 4 ++-- Lib/distutils/__init__.py | 2 +- Lib/idlelib/idlever.py | 2 +- Misc/RPM/python-3.4.spec | 2 +- README | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Include/patchlevel.h b/Include/patchlevel.h --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -20,10 +20,10 @@ #define PY_MINOR_VERSION 4 #define PY_MICRO_VERSION 0 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_BETA -#define PY_RELEASE_SERIAL 1 +#define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.4.0b1" +#define PY_VERSION "3.4.0b2" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Lib/distutils/__init__.py b/Lib/distutils/__init__.py --- a/Lib/distutils/__init__.py +++ b/Lib/distutils/__init__.py @@ -13,5 +13,5 @@ # Updated automatically by the Python release process. # #--start constants-- -__version__ = "3.4.0b1" +__version__ = "3.4.0b2" #--end constants-- diff --git a/Lib/idlelib/idlever.py b/Lib/idlelib/idlever.py --- a/Lib/idlelib/idlever.py +++ b/Lib/idlelib/idlever.py @@ -1,1 +1,1 @@ -IDLE_VERSION = "3.4.0b1" +IDLE_VERSION = "3.4.0b2" diff --git a/Misc/RPM/python-3.4.spec b/Misc/RPM/python-3.4.spec --- a/Misc/RPM/python-3.4.spec +++ b/Misc/RPM/python-3.4.spec @@ -39,7 +39,7 @@ %define name python #--start constants-- -%define version 3.4.0b1 +%define version 3.4.0b2 %define libvers 3.4 #--end constants-- %define release 1pydotorg diff --git a/README b/README --- a/README +++ b/README @@ -1,4 +1,4 @@ -This is Python version 3.4.0 beta 1 +This is Python version 3.4.0 beta 2 =================================== Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 16:24:50 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 16:24:50 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Added_tag_v3=2E4=2E0b2_for?= =?utf-8?q?_changeset_ba32913eb13e?= Message-ID: <3dygWQ4Cg6z7LjX@mail.python.org> http://hg.python.org/cpython/rev/9dac16369df8 changeset: 88319:9dac16369df8 user: Larry Hastings date: Sun Jan 05 04:43:31 2014 -0800 summary: Added tag v3.4.0b2 for changeset ba32913eb13e files: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -123,3 +123,4 @@ dd9cdf90a5073510877e9dd5112f8e6cf20d5e89 v3.4.0a3 e245b0d7209bb6d0e19316e1e2af1aa9c2139104 v3.4.0a4 3405dc9a6afaa0a06dd1f6f182ec5c998dce6f5f v3.4.0b1 +ba32913eb13ec545a46dd0ce18035b6c416f0d78 v3.4.0b2 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 16:24:51 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 16:24:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Post-release_engineering?= =?utf-8?q?=3B_updated_NEWS_and_version_string=2E?= Message-ID: <3dygWR6VDwz7Lk0@mail.python.org> http://hg.python.org/cpython/rev/d26ff99508cb changeset: 88320:d26ff99508cb user: Larry Hastings date: Mon Jan 06 07:17:47 2014 -0800 summary: Post-release engineering; updated NEWS and version string. files: Include/patchlevel.h | 2 +- Misc/NEWS | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/Include/patchlevel.h b/Include/patchlevel.h --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.4.0b2" +#define PY_VERSION "3.4.0b2+" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2,6 +2,18 @@ Python News +++++++++++ +What's New in Python 3.4.0 Release Candidate 1? +=============================================== + +Release date: 2014-01-19 + +Core and Builtins +----------------- + +Library +------- + + What's New in Python 3.4.0 Beta 2? ================================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 16:24:53 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 16:24:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E4=2E0b2_release_revisions_back_into_mainline?= =?utf-8?q?=2E?= Message-ID: <3dygWT3Hvsz7Ljk@mail.python.org> http://hg.python.org/cpython/rev/44c4ba63631d changeset: 88321:44c4ba63631d parent: 88320:d26ff99508cb parent: 88314:247f12fecf2b user: Larry Hastings date: Mon Jan 06 07:24:19 2014 -0800 summary: Merge 3.4.0b2 release revisions back into mainline. files: Doc/reference/datamodel.rst | 14 +++++++-- Lib/tarfile.py | 2 +- Lib/test/test_format.py | 5 --- Lib/test/test_unicode.py | 29 ++++++++++++++++++++ Misc/NEWS | 4 ++ Objects/setobject.c | 15 ++++++++++- Objects/unicodeobject.c | 35 +++++++++++++++++++----- 7 files changed, 86 insertions(+), 18 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -2080,9 +2080,17 @@ .. method:: object.__index__(self) - Called to implement :func:`operator.index`. Also called whenever Python needs - an integer object (such as in slicing, or in the built-in :func:`bin`, - :func:`hex` and :func:`oct` functions). Must return an integer. + Called to implement :func:`operator.index`, and whenever Python needs to + losslessly convert the numeric object to an integer object (such as in + slicing, or in the built-in :func:`bin`, :func:`hex` and :func:`oct` + functions). Presence of this method indicates that the numeric object is + an integer type. Must return an integer. + + .. note:: + + When :meth:`__index__` is defined, :meth:`__int__` should also be defined, + and both shuld return the same value, in order to have a coherent integer + type class. .. _context-managers: diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -196,7 +196,7 @@ # A 0o200 byte indicates a positive number, a 0o377 byte a negative # number. if 0 <= n < 8 ** (digits - 1): - s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL + s = bytes("%0*o" % (digits - 1, int(n)), "ascii") + NUL elif format == GNU_FORMAT and -256 ** (digits - 1) <= n < 256 ** (digits - 1): if n >= 0: s = bytearray([0o200]) diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -142,7 +142,6 @@ testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345") # same, except no 0 flag testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345") - testformat("%x", float(big), "123456_______________", 6) big = 0o12345670123456701234567012345670 # 32 octal digits testformat("%o", big, "12345670123456701234567012345670") testformat("%o", -big, "-12345670123456701234567012345670") @@ -182,7 +181,6 @@ testformat("%034.33o", big, "0012345670123456701234567012345670") # base marker shouldn't change that testformat("%0#34.33o", big, "0o012345670123456701234567012345670") - testformat("%o", float(big), "123456__________________________", 6) # Some small ints, in both Python int and flavors). testformat("%d", 42, "42") testformat("%d", -42, "-42") @@ -193,7 +191,6 @@ testformat("%#x", 1, "0x1") testformat("%#X", 1, "0X1") testformat("%#X", 1, "0X1") - testformat("%#x", 1.0, "0x1") testformat("%#o", 1, "0o1") testformat("%#o", 1, "0o1") testformat("%#o", 0, "0o0") @@ -210,12 +207,10 @@ testformat("%x", -0x42, "-42") testformat("%x", 0x42, "42") testformat("%x", -0x42, "-42") - testformat("%x", float(0x42), "42") testformat("%o", 0o42, "42") testformat("%o", -0o42, "-42") testformat("%o", 0o42, "42") testformat("%o", -0o42, "-42") - testformat("%o", float(0o42), "42") testformat("%r", "\u0378", "'\\u0378'") # non printable testformat("%a", "\u0378", "'\\u0378'") # non printable testformat("%r", "\u0374", "'\u0374'") # printable diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1126,6 +1126,35 @@ self.assertEqual('%.1s' % "a\xe9\u20ac", 'a') self.assertEqual('%.2s' % "a\xe9\u20ac", 'a\xe9') + #issue 19995 + class PsuedoInt: + def __init__(self, value): + self.value = int(value) + def __int__(self): + return self.value + def __index__(self): + return self.value + class PsuedoFloat: + def __init__(self, value): + self.value = float(value) + def __int__(self): + return int(self.value) + pi = PsuedoFloat(3.1415) + letter_m = PsuedoInt(109) + self.assertEquals('%x' % 42, '2a') + self.assertEquals('%X' % 15, 'F') + self.assertEquals('%o' % 9, '11') + self.assertEquals('%c' % 109, 'm') + self.assertEquals('%x' % letter_m, '6d') + self.assertEquals('%X' % letter_m, '6D') + self.assertEquals('%o' % letter_m, '155') + self.assertEquals('%c' % letter_m, 'm') + self.assertRaises(TypeError, '%x'.__mod__, pi) + self.assertRaises(TypeError, '%x'.__mod__, 3.14) + self.assertRaises(TypeError, '%X'.__mod__, 2.11) + self.assertRaises(TypeError, '%o'.__mod__, 1.79) + self.assertRaises(TypeError, '%c'.__mod__, pi) + def test_formatting_with_enum(self): # issue18780 import enum diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,10 @@ - Issue #19969: PyBytes_FromFormatV() now raises an OverflowError if "%c" argument is not in range [0; 255]. +- Issue #19995: %c, %o, %x, and %X now raise TypeError on non-integer input; + reworded docs to clarify that an integer type should define both __int__ + and __index__. + - Issue #19787: PyThread_set_key_value() now always set the value. In Python 3.3, the function did nothing if the key already exists (if the current value is a non-NULL pointer). diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -738,6 +738,17 @@ static Py_hash_t frozenset_hash(PyObject *self) { + /* Most of the constants in this hash algorithm are randomly choosen + large primes with "interesting bit patterns" and that passed + tests for good collision statistics on a variety of problematic + datasets such as: + + ps = [] + for r in range(21): + ps += itertools.combinations(range(20), r) + num_distinct_hashes = len({hash(frozenset(s)) for s in ps}) + + */ PySetObject *so = (PySetObject *)self; Py_uhash_t h, hash = 1927868237UL; setentry *entry; @@ -754,8 +765,10 @@ hashes so that many distinct combinations collapse to only a handful of distinct hash values. */ h = entry->hash; - hash ^= (h ^ (h << 16) ^ 89869747UL) * 3644798167UL; + hash ^= ((h ^ 89869747UL) ^ (h << 16)) * 3644798167UL; } + /* Make the final result spread-out in a different pattern + than the algorithem for tuples or other python objects. */ hash = hash * 69069U + 907133923UL; if (hash == -1) hash = 590923713UL; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13988,7 +13988,7 @@ return result; } -/* Format an integer. +/* Format an integer or a float as an integer. * Return 1 if the number has been formatted into the writer, * 0 if the number has been formatted into *p_output * -1 and raise an exception on error */ @@ -14005,11 +14005,19 @@ goto wrongtype; if (!PyLong_Check(v)) { - iobj = PyNumber_Long(v); - if (iobj == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - goto wrongtype; - return -1; + if (type == 'o' || type == 'x' || type == 'X') { + iobj = PyNumber_Index(v); + if (iobj == NULL) { + return -1; + } + } + else { + iobj = PyNumber_Long(v); + if (iobj == NULL ) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + goto wrongtype; + return -1; + } } assert(PyLong_Check(iobj)); } @@ -14079,8 +14087,18 @@ goto onError; } else { + PyObject *iobj; + long x; + /* make sure number is a type of integer */ + if (!PyLong_Check(v)) { + iobj = PyNumber_Index(v); + if (iobj == NULL) { + goto onError; + } + v = iobj; + Py_DECREF(iobj); + } /* Integer input truncated to a character */ - long x; x = PyLong_AsLong(v); if (x == -1 && PyErr_Occurred()) goto onError; @@ -14282,7 +14300,8 @@ /* Format one argument. Supported conversion specifiers: - "s", "r", "a": any type - - "i", "d", "u", "o", "x", "X": int + - "i", "d", "u": int or float + - "o", "x", "X": int - "e", "E", "f", "F", "g", "G": float - "c": int or str (1 character) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 16:27:24 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 16:27:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Updated_3=2E4_release_schedul?= =?utf-8?q?e_PEP=2C_moving_completed_beta_2_release?= Message-ID: <3dygZN5g7lz7LjN@mail.python.org> http://hg.python.org/peps/rev/acf6cf65a8a7 changeset: 5338:acf6cf65a8a7 user: Larry Hastings date: Mon Jan 06 07:27:11 2014 -0800 summary: Updated 3.4 release schedule PEP, moving completed beta 2 release from "future" to "released". files: pep-0429.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0429.txt b/pep-0429.txt --- a/pep-0429.txt +++ b/pep-0429.txt @@ -41,12 +41,12 @@ - 3.4.0 alpha 3: September 29, 2013 - 3.4.0 alpha 4: October 20, 2013 - 3.4.0 beta 1: November 24, 2013 +- 3.4.0 beta 2: January 5, 2014 (Beta 1 is also "feature freeze"--no new features beyond this point.) The anticipated schedule for future releases: -- 3.4.0 beta 2: January 5, 2014 - 3.4.0 candidate 1: January 19, 2014 - 3.4.0 candidate 2: February 2, 2014 - 3.4.0 final: February 23, 2014 -- Repository URL: http://hg.python.org/peps From rdmurray at bitdance.com Mon Jan 6 17:22:08 2014 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 06 Jan 2014 11:22:08 -0500 Subject: [Python-checkins] [Python-Dev] cpython: whatsnew: XMLPullParser, plus some doc updates. In-Reply-To: References: <3dxnZS1P8vz7Lmc@mail.python.org> Message-ID: <20140106162208.CFC842500AA@webabinitio.net> On Tue, 07 Jan 2014 01:22:21 +1000, Nick Coghlan wrote: > On 5 Jan 2014 12:54, "r.david.murray" wrote: > > > > http://hg.python.org/cpython/rev/069f88f4935f > > changeset: 88308:069f88f4935f > > user: R David Murray > > date: Sat Jan 04 23:52:50 2014 -0500 > > summary: > > whatsnew: XMLPullParser, plus some doc updates. > > > > I was confused by the text saying that read_events "iterated", since it > > actually returns an iterator (that's what a generator does) that the > > caller must then iterate. So I tidied up the language. I'm not sure > > what the sentence "Events provided in a previous call to read_events() > > will not be yielded again." is trying to convey, so I didn't try to fix > that. > > It's a mutating API - once the events have been retrieved, that's it, > they're gone from the internal state. Suggestions for wording improvements > welcome :) Well, my guess as to what it meant was roughly: "An Event will be yielded exactly once regardless of how many read_events iterators are processed." Looking at the code, though, I'm not sure that's actually true. The code does not appear to be thread-safe. Of course, it isn't intended to be used in a threaded context, but the docs don't quite make that explicit. I imagine that's the intent of the statement about "parallel" reading, but it doesn't actually say that the code is not thread safe. It reads more as if it is warning that the order of retrieval would be unpredictable. --David From python-checkins at python.org Mon Jan 6 18:51:44 2014 From: python-checkins at python.org (gregory.p.smith) Date: Mon, 6 Jan 2014 18:51:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fixes_issue190?= =?utf-8?q?81=3A_When_a_zipimport_=2Ezip_file_in_sys=2Epath_being_imported?= Message-ID: <3dykmw2lyhzRCV@mail.python.org> http://hg.python.org/cpython/rev/8dbf8edb7128 changeset: 88322:8dbf8edb7128 branch: 2.7 parent: 88316:e57660acc6d4 user: Gregory P. Smith date: Mon Jan 06 09:46:46 2014 -0800 summary: Fixes issue19081: When a zipimport .zip file in sys.path being imported from is modified during the lifetime of the Python process after zipimport has already opened and cached the zip's table of contents it now fstat's the file after opening it upon every attempt to access anything within and will re-read the table of contents if the .zip file inode, size or mtime have changed. It would've been nicer to hold any .zip file used by zipimport open for the duration of the process but that would be more invasive and add an additional open file descriptor to all zipimport using processes. It also would likely not fix the problem on Windows due to different filesystem semantics. files: Lib/test/test_zipimport.py | 103 +++++++- Modules/zipimport.c | 294 ++++++++++++++++++++---- 2 files changed, 324 insertions(+), 73 deletions(-) diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -1,3 +1,4 @@ +import io import sys import os import marshal @@ -55,6 +56,27 @@ TEMP_ZIP = os.path.abspath("junk95142" + os.extsep + "zip") +def _write_zip_package(zipname, files, + data_to_prepend=b"", compression=ZIP_STORED): + z = ZipFile(zipname, "w") + try: + for name, (mtime, data) in files.items(): + zinfo = ZipInfo(name, time.localtime(mtime)) + zinfo.compress_type = compression + z.writestr(zinfo, data) + finally: + z.close() + + if data_to_prepend: + # Prepend data to the start of the zipfile + with open(zipname, "rb") as f: + zip_data = f.read() + + with open(zipname, "wb") as f: + f.write(data_to_prepend) + f.write(zip_data) + + class UncompressedZipImportTestCase(ImportHooksBaseTestCase): compression = ZIP_STORED @@ -67,26 +89,9 @@ ImportHooksBaseTestCase.setUp(self) def doTest(self, expected_ext, files, *modules, **kw): - z = ZipFile(TEMP_ZIP, "w") + _write_zip_package(TEMP_ZIP, files, data_to_prepend=kw.get("stuff"), + compression=self.compression) try: - for name, (mtime, data) in files.items(): - zinfo = ZipInfo(name, time.localtime(mtime)) - zinfo.compress_type = self.compression - z.writestr(zinfo, data) - z.close() - - stuff = kw.get("stuff", None) - if stuff is not None: - # Prepend 'stuff' to the start of the zipfile - f = open(TEMP_ZIP, "rb") - data = f.read() - f.close() - - f = open(TEMP_ZIP, "wb") - f.write(stuff) - f.write(data) - f.close() - sys.path.insert(0, TEMP_ZIP) mod = __import__(".".join(modules), globals(), locals(), @@ -101,7 +106,6 @@ self.assertEqual(file, os.path.join(TEMP_ZIP, *modules) + expected_ext) finally: - z.close() os.remove(TEMP_ZIP) def testAFakeZlib(self): @@ -387,6 +391,64 @@ compression = ZIP_DEFLATED +class ZipFileModifiedAfterImportTestCase(ImportHooksBaseTestCase): + def setUp(self): + zipimport._zip_directory_cache.clear() + zipimport._zip_stat_cache.clear() + ImportHooksBaseTestCase.setUp(self) + + def tearDown(self): + ImportHooksBaseTestCase.tearDown(self) + if os.path.exists(TEMP_ZIP): + os.remove(TEMP_ZIP) + + def testZipFileChangesAfterFirstImport(self): + """Alter the zip file after caching its index and try an import.""" + packdir = TESTPACK + os.sep + files = {packdir + "__init__" + pyc_ext: (NOW, test_pyc), + packdir + TESTMOD + ".py": (NOW, "test_value = 38\n"), + "ziptest_a.py": (NOW, "test_value = 23\n"), + "ziptest_b.py": (NOW, "test_value = 42\n"), + "ziptest_c.py": (NOW, "test_value = 1337\n")} + zipfile_path = TEMP_ZIP + _write_zip_package(zipfile_path, files) + self.assertTrue(os.path.exists(zipfile_path)) + sys.path.insert(0, zipfile_path) + + # Import something out of the zipfile and confirm it is correct. + testmod = __import__(TESTPACK + "." + TESTMOD, + globals(), locals(), ["__dummy__"]) + self.assertEqual(testmod.test_value, 38) + # Import something else out of the zipfile and confirm it is correct. + ziptest_b = __import__("ziptest_b", globals(), locals(), ["test_value"]) + self.assertEqual(ziptest_b.test_value, 42) + + # Truncate and fill the zip file with non-zip garbage. + with io.open(zipfile_path, "rb") as orig_zip_file: + orig_zip_file_contents = orig_zip_file.read() + with io.open(zipfile_path, "wb") as byebye_valid_zip_file: + byebye_valid_zip_file.write(b"Tear down this wall!\n"*1987) + # Now that the zipfile has been replaced, import something else from it + # which should fail as the file contents are now garbage. + with self.assertRaises(ImportError): + ziptest_a = __import__("ziptest_a", globals(), locals(), + ["test_value"]) + + # Now lets make it a valid zipfile that has some garbage at the start. + # This alters all of the offsets within the file + with io.open(zipfile_path, "wb") as new_zip_file: + new_zip_file.write(b"X"*1991) # The year Python was created. + new_zip_file.write(orig_zip_file_contents) + + # Now that the zip file has been "restored" to a valid but different + # zipfile the zipimporter should *successfully* re-read the new zip + # file's end of file central index and be able to import from it again. + ziptest_a = __import__("ziptest_a", globals(), locals(), ["test_value"]) + self.assertEqual(ziptest_a.test_value, 23) + ziptest_c = __import__("ziptest_c", globals(), locals(), ["test_value"]) + self.assertEqual(ziptest_c.test_value, 1337) + + class BadFileZipImportTestCase(unittest.TestCase): def assertZipFailure(self, filename): self.assertRaises(zipimport.ZipImportError, @@ -464,6 +526,7 @@ UncompressedZipImportTestCase, CompressedZipImportTestCase, BadFileZipImportTestCase, + ZipFileModifiedAfterImportTestCase, ) finally: test_support.unlink(TESTMOD) diff --git a/Modules/zipimport.c b/Modules/zipimport.c --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -42,10 +42,16 @@ static PyObject *ZipImportError; static PyObject *zip_directory_cache = NULL; +static PyObject *zip_stat_cache = NULL; +/* posix.fstat or nt.fstat function. Used due to posixmodule.c's + * superior fstat implementation over libc's on Windows. */ +static PyObject *fstat_function = NULL; /* posix.fstat() or nt.fstat() */ /* forward decls */ -static PyObject *read_directory(char *archive); -static PyObject *get_data(char *archive, PyObject *toc_entry); +static FILE *fopen_rb_and_stat(char *path, PyObject **py_stat_p); +static FILE *safely_reopen_archive(ZipImporter *self, char **archive_p); +static PyObject *read_directory(FILE *fp, char *archive); +static PyObject *get_data(FILE *fp, char *archive, PyObject *toc_entry); static PyObject *get_module_code(ZipImporter *self, char *fullname, int *p_ispackage, char **p_modpath); @@ -126,12 +132,38 @@ PyObject *files; files = PyDict_GetItemString(zip_directory_cache, path); if (files == NULL) { - files = read_directory(buf); - if (files == NULL) + PyObject *zip_stat = NULL; + FILE *fp = fopen_rb_and_stat(buf, &zip_stat); + if (fp == NULL) { + PyErr_Format(ZipImportError, "can't open Zip file: " + "'%.200s'", buf); + Py_XDECREF(zip_stat); return -1; + } + + if (Py_VerboseFlag) + PySys_WriteStderr("# zipimport: %s not cached, " + "reading TOC.\n", path); + + files = read_directory(fp, buf); + fclose(fp); + if (files == NULL) { + Py_XDECREF(zip_stat); + return -1; + } if (PyDict_SetItemString(zip_directory_cache, path, - files) != 0) + files) != 0) { + Py_DECREF(files); + Py_XDECREF(zip_stat); return -1; + } + if (zip_stat && PyDict_SetItemString(zip_stat_cache, path, + zip_stat) != 0) { + Py_DECREF(files); + Py_DECREF(zip_stat); + return -1; + } + Py_XDECREF(zip_stat); } else Py_INCREF(files); @@ -419,11 +451,12 @@ zipimporter_get_data(PyObject *obj, PyObject *args) { ZipImporter *self = (ZipImporter *)obj; - char *path; + char *path, *archive; + FILE *fp; #ifdef ALTSEP char *p, buf[MAXPATHLEN + 1]; #endif - PyObject *toc_entry; + PyObject *toc_entry, *data; Py_ssize_t len; if (!PyArg_ParseTuple(args, "s:zipimporter.get_data", &path)) @@ -448,12 +481,19 @@ path = path + len + 1; } + fp = safely_reopen_archive(self, &archive); + if (fp == NULL) + return NULL; + toc_entry = PyDict_GetItemString(self->files, path); if (toc_entry == NULL) { PyErr_SetFromErrnoWithFilename(PyExc_IOError, path); + fclose(fp); return NULL; } - return get_data(PyString_AsString(self->archive), toc_entry); + data = get_data(fp, archive, toc_entry); + fclose(fp); + return data; } static PyObject * @@ -473,7 +513,8 @@ { ZipImporter *self = (ZipImporter *)obj; PyObject *toc_entry; - char *fullname, *subname, path[MAXPATHLEN+1]; + FILE *fp; + char *fullname, *subname, path[MAXPATHLEN+1], *archive; int len; enum zi_module_info mi; @@ -501,13 +542,20 @@ else strcpy(path + len, ".py"); + fp = safely_reopen_archive(self, &archive); + if (fp == NULL) + return NULL; + toc_entry = PyDict_GetItemString(self->files, path); - if (toc_entry != NULL) - return get_data(PyString_AsString(self->archive), toc_entry); + if (toc_entry != NULL) { + PyObject *data = get_data(fp, archive, toc_entry); + fclose(fp); + return data; + } + fclose(fp); /* we have the module, but no source */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(doc_find_module, @@ -662,7 +710,139 @@ } /* - read_directory(archive) -> files dict (new reference) + fopen_rb_and_stat(path, &py_stat) -> FILE * + + Opens path in "rb" mode and populates the Python py_stat stat_result + with information about the opened file. *py_stat may not be changed + if there is no fstat_function or if fstat_function fails. + + Returns NULL and does nothing to *py_stat if the open failed. +*/ +static FILE * +fopen_rb_and_stat(char *path, PyObject **py_stat_p) +{ + FILE *fp; + assert(py_stat_p != NULL); + assert(*py_stat_p == NULL); + + fp = fopen(path, "rb"); + if (fp == NULL) { + return NULL; + } + + if (fstat_function) { + PyObject *stat_result = PyObject_CallFunction(fstat_function, + "i", fileno(fp)); + if (stat_result == NULL) { + PyErr_Clear(); /* We can function without it. */ + } else { + *py_stat_p = stat_result; + } + } + + return fp; +} + +/* Return 1 if objects a and b fail a Py_EQ test for an attr. */ +static int +compare_obj_attr_strings(PyObject *obj_a, PyObject *obj_b, char *attr_name) +{ + int problem = 0; + PyObject *attr_a = PyObject_GetAttrString(obj_a, attr_name); + PyObject *attr_b = PyObject_GetAttrString(obj_b, attr_name); + if (attr_a == NULL || attr_b == NULL) + problem = 1; + else + problem = (PyObject_RichCompareBool(attr_a, attr_b, Py_EQ) != 1); + Py_XDECREF(attr_a); + Py_XDECREF(attr_b); + return problem; +} + +/* + * Returns an open FILE * on success and sets *archive_p to point to + * a read only C string representation of the archive name (as a + * convenience for use in error messages). + * + * Returns NULL on error with the Python error context set. + */ +static FILE * +safely_reopen_archive(ZipImporter *self, char **archive_p) +{ + FILE *fp; + PyObject *stat_now = NULL; + char *archive; + + assert(archive_p != NULL); + *archive_p = PyString_AsString(self->archive); + if (*archive_p == NULL) + return NULL; + archive = *archive_p; + + fp = fopen_rb_and_stat(archive, &stat_now); + if (!fp) { + PyErr_Format(PyExc_IOError, + "zipimport: can not open file %s", archive); + Py_XDECREF(stat_now); + return NULL; + } + + if (stat_now != NULL) { + int problem = 0; + PyObject *files; + PyObject *prev_stat = PyDict_GetItemString(zip_stat_cache, archive); + /* Test stat_now vs the old cached stat on some key attributes. */ + if (prev_stat != NULL) { + problem = compare_obj_attr_strings(prev_stat, stat_now, + "st_ino"); + problem |= compare_obj_attr_strings(prev_stat, stat_now, + "st_size"); + problem |= compare_obj_attr_strings(prev_stat, stat_now, + "st_mtime"); + } else { + if (Py_VerboseFlag) + PySys_WriteStderr("# zipimport: no stat data for %s!\n", + archive); + problem = 1; + } + + if (problem) { + if (Py_VerboseFlag) + PySys_WriteStderr("# zipimport: %s modified since last" + " import, rereading TOC.\n", archive); + files = read_directory(fp, archive); + if (files == NULL) { + Py_DECREF(stat_now); + fclose(fp); + return NULL; + } + if (PyDict_SetItem(zip_directory_cache, self->archive, + files) != 0) { + Py_DECREF(files); + Py_DECREF(stat_now); + fclose(fp); + return NULL; + } + if (stat_now && PyDict_SetItem(zip_stat_cache, self->archive, + stat_now) != 0) { + Py_DECREF(files); + Py_DECREF(stat_now); + fclose(fp); + return NULL; + } + Py_XDECREF(self->files); /* free the old value. */ + self->files = files; + } else { + /* No problem, discard the new stat data. */ + Py_DECREF(stat_now); + } + } /* stat succeeded */ + + return fp; +} + +/* + read_directory(fp, archive) -> files dict (new reference) Given a path to a Zip archive, build a dict, mapping file names (local to the archive, using SEP as a separator) to toc entries. @@ -683,10 +863,9 @@ data_size and file_offset are 0. */ static PyObject * -read_directory(char *archive) +read_directory(FILE *fp, char *archive) { PyObject *files = NULL; - FILE *fp; long compress, crc, data_size, file_size, file_offset, date, time; long header_offset, name_size, header_size, header_position; long i, l, count; @@ -696,6 +875,7 @@ char *p, endof_central_dir[22]; long arc_offset; /* offset from beginning of file to start of zip-archive */ + assert(fp != NULL); if (strlen(archive) > MAXPATHLEN) { PyErr_SetString(PyExc_OverflowError, "Zip path name is too long"); @@ -703,28 +883,18 @@ } strcpy(path, archive); - fp = fopen(archive, "rb"); - if (fp == NULL) { - PyErr_Format(ZipImportError, "can't open Zip file: " - "'%.200s'", archive); - return NULL; - } - if (fseek(fp, -22, SEEK_END) == -1) { - fclose(fp); PyErr_Format(ZipImportError, "can't read Zip file: %s", archive); return NULL; } header_position = ftell(fp); if (fread(endof_central_dir, 1, 22, fp) != 22) { - fclose(fp); PyErr_Format(ZipImportError, "can't read Zip file: " "'%.200s'", archive); return NULL; } if (get_long((unsigned char *)endof_central_dir) != 0x06054B50) { /* Bad: End of Central Dir signature */ - fclose(fp); PyErr_Format(ZipImportError, "not a Zip file: " "'%.200s'", archive); return NULL; @@ -793,18 +963,15 @@ goto error; count++; } - fclose(fp); if (Py_VerboseFlag) PySys_WriteStderr("# zipimport: found %ld names in %s\n", count, archive); return files; fseek_error: - fclose(fp); Py_XDECREF(files); PyErr_Format(ZipImportError, "can't read Zip file: %s", archive); return NULL; error: - fclose(fp); Py_XDECREF(files); return NULL; } @@ -841,14 +1008,13 @@ return decompress; } -/* Given a path to a Zip file and a toc_entry, return the (uncompressed) +/* Given a FILE* to a Zip file and a toc_entry, return the (uncompressed) data as a new reference. */ static PyObject * -get_data(char *archive, PyObject *toc_entry) +get_data(FILE *fp, char *archive, PyObject *toc_entry) { PyObject *raw_data, *data = NULL, *decompress; char *buf; - FILE *fp; int err; Py_ssize_t bytes_read = 0; long l; @@ -862,16 +1028,8 @@ return NULL; } - fp = fopen(archive, "rb"); - if (!fp) { - PyErr_Format(PyExc_IOError, - "zipimport: can not open file %s", archive); - return NULL; - } - /* Check to make sure the local file header is correct */ if (fseek(fp, file_offset, 0) == -1) { - fclose(fp); PyErr_Format(ZipImportError, "can't read Zip file: %s", archive); return NULL; } @@ -882,11 +1040,9 @@ PyErr_Format(ZipImportError, "bad local file header in %s", archive); - fclose(fp); return NULL; } if (fseek(fp, file_offset + 26, 0) == -1) { - fclose(fp); PyErr_Format(ZipImportError, "can't read Zip file: %s", archive); return NULL; } @@ -898,7 +1054,6 @@ raw_data = PyString_FromStringAndSize((char *)NULL, compress == 0 ? data_size : data_size + 1); if (raw_data == NULL) { - fclose(fp); return NULL; } buf = PyString_AsString(raw_data); @@ -907,11 +1062,9 @@ if (err == 0) { bytes_read = fread(buf, 1, data_size, fp); } else { - fclose(fp); PyErr_Format(ZipImportError, "can't read Zip file: %s", archive); return NULL; } - fclose(fp); if (err || bytes_read != data_size) { PyErr_SetString(PyExc_IOError, "zipimport: can't read data"); @@ -1107,17 +1260,13 @@ /* Return the code object for the module named by 'fullname' from the Zip archive as a new reference. */ static PyObject * -get_code_from_data(ZipImporter *self, int ispackage, int isbytecode, - time_t mtime, PyObject *toc_entry) +get_code_from_data(char *archive, FILE *fp, int ispackage, + int isbytecode, time_t mtime, PyObject *toc_entry) { PyObject *data, *code; char *modpath; - char *archive = PyString_AsString(self->archive); - if (archive == NULL) - return NULL; - - data = get_data(archive, toc_entry); + data = get_data(fp, archive, toc_entry); if (data == NULL) return NULL; @@ -1152,12 +1301,19 @@ for (zso = zip_searchorder; *zso->suffix; zso++) { PyObject *code = NULL; + FILE *fp; + char *archive; strcpy(path + len, zso->suffix); if (Py_VerboseFlag > 1) PySys_WriteStderr("# trying %s%c%s\n", PyString_AsString(self->archive), SEP, path); + + fp = safely_reopen_archive(self, &archive); + if (fp == NULL) + return NULL; + toc_entry = PyDict_GetItemString(self->files, path); if (toc_entry != NULL) { time_t mtime = 0; @@ -1168,9 +1324,10 @@ mtime = get_mtime_of_source(self, path); if (p_ispackage != NULL) *p_ispackage = ispackage; - code = get_code_from_data(self, ispackage, + code = get_code_from_data(archive, fp, ispackage, isbytecode, mtime, toc_entry); + fclose(fp); if (code == Py_None) { /* bad magic number or non-matching mtime in byte code, try next */ @@ -1182,6 +1339,7 @@ PyTuple_GetItem(toc_entry, 0)); return code; } + fclose(fp); } PyErr_Format(ZipImportError, "can't find module '%.200s'", fullname); return NULL; @@ -1199,6 +1357,8 @@ subclass of ImportError, so it can be caught as ImportError, too.\n\ - _zip_directory_cache: a dict, mapping archive paths to zip directory\n\ info dicts, as used in zipimporter._files.\n\ +- _zip_stat_cache: a dict, mapping archive paths to stat_result\n\ + info for the .zip the last time anything was imported from it.\n\ \n\ It is usually not needed to use the zipimport module explicitly; it is\n\ used by the builtin import mechanism for sys.path items that are paths\n\ @@ -1247,6 +1407,7 @@ (PyObject *)&ZipImporter_Type) < 0) return; + Py_XDECREF(zip_directory_cache); /* Avoid embedded interpreter leaks. */ zip_directory_cache = PyDict_New(); if (zip_directory_cache == NULL) return; @@ -1254,4 +1415,31 @@ if (PyModule_AddObject(mod, "_zip_directory_cache", zip_directory_cache) < 0) return; + + Py_XDECREF(zip_stat_cache); /* Avoid embedded interpreter leaks. */ + zip_stat_cache = PyDict_New(); + if (zip_stat_cache == NULL) + return; + Py_INCREF(zip_stat_cache); + if (PyModule_AddObject(mod, "_zip_stat_cache", zip_stat_cache) < 0) + return; + + { + /* We cannot import "os" here as that is a .py/.pyc file that could + * live within a zipped up standard library. Import the posix or nt + * builtin that provides the fstat() function we want instead. */ + PyObject *os_like_module; + Py_XDECREF(fstat_function); /* Avoid embedded interpreter leaks. */ + os_like_module = PyImport_ImportModule("posix"); + if (os_like_module == NULL) { + os_like_module = PyImport_ImportModule("nt"); + } + if (os_like_module != NULL) { + fstat_function = PyObject_GetAttrString(os_like_module, "fstat"); + Py_DECREF(os_like_module); + } + if (fstat_function == NULL) { + PyErr_Clear(); /* non-fatal, we'll go on without it. */ + } + } } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 18:51:45 2014 From: python-checkins at python.org (gregory.p.smith) Date: Mon, 6 Jan 2014 18:51:45 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_news_entry_for?= =?utf-8?q?_issue19081_fix=2E?= Message-ID: <3dykmx55pKzSXf@mail.python.org> http://hg.python.org/cpython/rev/90a99059aa36 changeset: 88323:90a99059aa36 branch: 2.7 user: Gregory P. Smith date: Mon Jan 06 09:50:19 2014 -0800 summary: news entry for issue19081 fix. files: Misc/NEWS | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,11 @@ Core and Builtins ----------------- +- Issue #19081: When a zipimport .zip file in sys.path being imported from + is modified during the lifetime of the Python process after zipimport has + already cached the zip's table of contents we detect this and recover + rather than read bad data from the .zip (causing odd import errors). + - Raise a better error when non-unicode codecs are used for a file's coding cookie. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 18:51:47 2014 From: python-checkins at python.org (gregory.p.smith) Date: Mon, 6 Jan 2014 18:51:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_normalize_whit?= =?utf-8?q?espace_from_prior_issue19081_fix_commit=2E?= Message-ID: <3dykmz09lLz7Ljd@mail.python.org> http://hg.python.org/cpython/rev/cbeb22969da1 changeset: 88324:cbeb22969da1 branch: 2.7 user: Gregory P. Smith date: Mon Jan 06 09:51:32 2014 -0800 summary: normalize whitespace from prior issue19081 fix commit. files: Lib/test/test_zipimport.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -70,11 +70,11 @@ if data_to_prepend: # Prepend data to the start of the zipfile with open(zipname, "rb") as f: - zip_data = f.read() + zip_data = f.read() with open(zipname, "wb") as f: - f.write(data_to_prepend) - f.write(zip_data) + f.write(data_to_prepend) + f.write(zip_data) class UncompressedZipImportTestCase(ImportHooksBaseTestCase): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 19:34:33 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 19:34:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2320142=3A_Py=5Fbuf?= =?utf-8?q?fer_variables_generated_by_Argument_Clinic_are_now?= Message-ID: <3dylkK5FhYzSfC@mail.python.org> http://hg.python.org/cpython/rev/16ff19d1d367 changeset: 88325:16ff19d1d367 parent: 88321:44c4ba63631d user: Larry Hastings date: Mon Jan 06 10:34:00 2014 -0800 summary: Issue #20142: Py_buffer variables generated by Argument Clinic are now initialized with a default value. files: Misc/NEWS | 5 +++++ Modules/zlibmodule.c | 8 ++++---- Tools/clinic/clinic.py | 10 +++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,11 @@ Library ------- +Tools/Demos +----------- + +- Issue #20142: Py_buffer variables generated by Argument Clinic are now + initialized with a default value. What's New in Python 3.4.0 Beta 2? ================================== diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -198,7 +198,7 @@ zlib_compress(PyModuleDef *module, PyObject *args) { PyObject *return_value = NULL; - Py_buffer bytes; + Py_buffer bytes = {NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL}; int group_right_1 = 0; int level = 0; @@ -227,7 +227,7 @@ static PyObject * zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level) -/*[clinic checksum: f490708eff84be652b5ebe7fe622ab73ac12c888]*/ +/*[clinic checksum: 9f055a396620bc1a8a13d74c3496249528b32b0d]*/ { PyObject *ReturnVal = NULL; Byte *input, *output = NULL; @@ -789,7 +789,7 @@ zlib_Decompress_decompress(PyObject *self, PyObject *args) { PyObject *return_value = NULL; - Py_buffer data; + Py_buffer data = {NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL}; unsigned int max_length = 0; if (!PyArg_ParseTuple(args, @@ -808,7 +808,7 @@ static PyObject * zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length) -/*[clinic checksum: 3599698948f5a712f5a8309491671cc2ce969d2c]*/ +/*[clinic checksum: 5b1e4f9f1ef8eca55fff78356f9df0c81232ed3b]*/ { int err; unsigned int old_length, length = DEFAULTALLOC; diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1488,7 +1488,12 @@ declaration.append('\nPy_ssize_clean_t ') declaration.append(self.length_name()) declaration.append(';') - return "".join(declaration) + s = "".join(declaration) + # double up curly-braces, this string will be used + # as part of a format_map() template later + s = s.replace("{", "{{") + s = s.replace("}", "}}") + return s def initialize(self): """ @@ -1742,6 +1747,9 @@ c_ignored_default = "{NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL}" def converter_init(self, *, types='bytes bytearray buffer', nullable=False): + if self.default != unspecified: + fail("There is no legal default value for Py_buffer ") + self.c_default = self.c_ignored_default types = set(types.strip().split()) bytes_type = set(('bytes',)) bytearray_type = set(('bytearray',)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 20:10:57 2014 From: python-checkins at python.org (larry.hastings) Date: Mon, 6 Jan 2014 20:10:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2320143=3A_The_line?= =?utf-8?q?_numbers_reported_in_Argument_Clinic_errors_are?= Message-ID: <3dymXK6716z7Ljy@mail.python.org> http://hg.python.org/cpython/rev/9c8d31d69044 changeset: 88326:9c8d31d69044 user: Larry Hastings date: Mon Jan 06 11:10:08 2014 -0800 summary: Issue #20143: The line numbers reported in Argument Clinic errors are now more accurate. files: Misc/NEWS | 3 +++ Tools/clinic/clinic.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Tools/Demos ----------- +- Issue #20143: The line numbers reported in Argument Clinic errors are + now more accurate. + - Issue #20142: Py_buffer variables generated by Argument Clinic are now initialized with a default value. diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -943,8 +943,9 @@ fail("Checksum mismatch!\nExpected: {}\nComputed: {}".format(checksum, computed)) else: # put back output - self.input.extend(reversed(output.splitlines(keepends=True))) - self.line_number -= len(output) + output_lines = output.splitlines(keepends=True) + self.line_number -= len(output_lines) + self.input.extend(reversed(output_lines)) output = None return Block(input_output(), dsl_name, output=output) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 22:32:54 2014 From: python-checkins at python.org (r.david.murray) Date: Mon, 6 Jan 2014 22:32:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_pydoc=2EScanne?= =?utf-8?q?r_removal=2C_check=5Foutput_input_parm=2C_operator=2Epy=2E?= Message-ID: <3dyqh63Js2z7LjN@mail.python.org> http://hg.python.org/cpython/rev/0473c770b523 changeset: 88327:0473c770b523 user: R David Murray date: Sun Jan 05 20:52:06 2014 -0500 summary: whatsnew: pydoc.Scanner removal, check_output input parm, operator.py. Also fleshed out the entry on struct.iter_unpack. files: Doc/whatsnew/3.4.rst | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -794,6 +794,14 @@ processes. (Contributed by Nick Coghlan in :issue:`19946`) +operator +-------- + +There is now a pure-python version of the :mod:`operator` module available for +reference and for use by alternate implementations of Python. (Contributed by +Zachary Ware in :issue:`16694`.) + + os -- @@ -981,8 +989,19 @@ struct ------ -Streaming struct unpacking using :func:`struct.iter_unpack`. -(Contributed by Antoine Pitrou in :issue:`17804`.) +:mod:`struct` now supports the streamed unpacking of a buffer containing +repeated instances of a given format of data. Both a module level +:mod:`~struct.iter_unpack` function and a :meth:`struct.Struct.iter_unpack` +method on compiled formats have been added. (Contributed by Antoine Pitrou in +:issue:`17804`.) + + +subprocess +---------- + +:func:`~subprocess.check_output` now accepts an *input* argument that can +be used to provide the contents of ``stdin`` for the command that is run. +(Contributed by Zack Weinberg in :issue:`16624`.) sunau @@ -1378,6 +1397,13 @@ :mod:`marshal`. (Contributed by Dan Riti in :issue:`15480`.) +Code Cleanups +------------- + +* The unused and undocumented internal ``Scanner`` class has been removed from + the :mod:`pydoc` module. + + Porting to Python 3.4 ===================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Jan 6 22:32:55 2014 From: python-checkins at python.org (r.david.murray) Date: Mon, 6 Jan 2014 22:32:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_whatsnew=3A_ssl_getpeercer?= =?utf-8?q?t/do=5Fhandshake_raise_OSError=2C_weakref_=5F=5Fcallback=5F=5F?= =?utf-8?q?=2E?= Message-ID: <3dyqh762hDz7Ljs@mail.python.org> http://hg.python.org/cpython/rev/2798ebe65fb1 changeset: 88328:2798ebe65fb1 user: R David Murray date: Mon Jan 06 16:32:05 2014 -0500 summary: whatsnew: ssl getpeercert/do_handshake raise OSError, weakref __callback__. Also add a missing word to gc entry, and delete a now-obsolete doc note in the weakref __callback__ docs. (Opened an issue for rewriting the section that compares finalizers and __del__ method.) files: Doc/library/weakref.rst | 11 +---------- Doc/whatsnew/3.4.rst | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -123,15 +123,6 @@ weakref. If there is no callback or if the referent of the weakref is no longer alive then this attribute will have value ``None``. - .. note:: - - Like :meth:`__del__` methods, weak reference callbacks can be - called during interpreter shutdown when module globals have been - overwritten with :const:`None`. This can make writing robust - weak reference callbacks a challenge. Callbacks registered - using :class:`finalize` do not have to worry about this issue - because they will not be run after module teardown has begun. - .. versionchanged:: 3.4 Added the :attr:`__callback__` attribute. @@ -247,7 +238,7 @@ .. class:: finalize(obj, func, *args, **kwargs) Return a callable finalizer object which will be called when *obj* - is garbage collected. Unlike an ordinary weak reference, a finalizer is + is garbage collected. Unlike an ordinary weak reference, a finalizer will always survive until the reference object is collected, greatly simplifying lifecycle management. diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -657,9 +657,9 @@ gc -- -New :func:`~gc.get_stats` returns a list of three per-generation dictionaries -containing the collections statistics since interpreter startup. (Contributed -by Antoine Pitrou in :issue:`16351`.) +New function :func:`~gc.get_stats` returns a list of three per-generation +dictionaries containing the collections statistics since interpreter startup. +(Contributed by Antoine Pitrou in :issue:`16351`.) hashlib @@ -1103,6 +1103,10 @@ carefully manage the lifecycle of the weak reference itself. (Contributed by Richard Oudkerk in :issue:`15528`) +The callback, if any, associated with a :class:`~weakref.ref` is now +exposed via the :attr:`~weakref.ref.__callback__` attribute. (Contributed +by Mark Dickinson in :issue:`17643`.) + xml.etree --------- @@ -1482,6 +1486,12 @@ compliance with the language spec; Jython and PyPy already were. (:issue:`17434`). +* :meth:`ssl.SSLSocket.getpeercert` and :meth:`ssl.SSLSocket.do_handshake` + now raise an :exc:`OSError` with ``ENOTCONN`` when the ``SSLSocket`` is not + connected, instead of the previous behavior of raising an + :exc:`AttributError`. In addition, :meth:`~ssl.SSLSocket.getpeercert` + will raise a :exc:`ValueError` if the handshake has not yet been done. + Changes in the C API -------------------- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Jan 7 01:09:30 2014 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 7 Jan 2014 01:09:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_asyncio=3A_Fix_deadlock_in?= =?utf-8?q?_readexactly=28=29=2E_Fixes_issue_=2320154=2E?= Message-ID: <3dyv8p2xvLz7LjN@mail.python.org> http://hg.python.org/cpython/rev/54d32e01bbfd changeset: 88329:54d32e01bbfd user: Guido van Rossum date: Mon Jan 06 16:09:18 2014 -0800 summary: asyncio: Fix deadlock in readexactly(). Fixes issue #20154. files: Lib/asyncio/streams.py | 29 +++++++++++++++++++---------- Misc/NEWS | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -220,6 +220,7 @@ if loop is None: loop = events.get_event_loop() self._loop = loop + # TODO: Use a bytearray for a buffer, like the transport. self._buffer = collections.deque() # Deque of bytes objects. self._byte_count = 0 # Bytes in buffer. self._eof = False # Whether we're done. @@ -384,15 +385,23 @@ if self._exception is not None: raise self._exception - if n <= 0: - return b'' + # There used to be "optimized" code here. It created its own + # Future and waited until self._buffer had at least the n + # bytes, then called read(n). Unfortunately, this could pause + # the transport if the argument was larger than the pause + # limit (which is twice self._limit). So now we just read() + # into a local buffer. - while self._byte_count < n and not self._eof: - assert not self._waiter - self._waiter = futures.Future(loop=self._loop) - try: - yield from self._waiter - finally: - self._waiter = None + blocks = [] + while n > 0: + block = yield from self.read(n) + if not block: + break + blocks.append(block) + n -= len(block) - return (yield from self.read(n)) + # TODO: Raise EOFError if we break before n == 0? (That would + # be a change in specification, but I've always had to add an + # explicit size check to the caller.) + + return b''.join(blocks) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -75,6 +75,8 @@ Library ------- +- Issue #20154: Deadlock in asyncio.StreamReader.readexactly(). + - Issue #16113: Remove sha3 module again. - Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Jan 7 04:51:08 2014 From: python-checkins at python.org (eric.snow) Date: Tue, 7 Jan 2014 04:51:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_dead_PEP_451_code?= =?utf-8?q?=2E?= Message-ID: <3dz04X3Xfxz7LkJ@mail.python.org> http://hg.python.org/cpython/rev/2b50ac02a5a8 changeset: 88330:2b50ac02a5a8 user: Eric Snow date: Mon Jan 06 20:38:16 2014 -0700 summary: Remove dead PEP 451 code. files: Lib/importlib/_bootstrap.py | 10 ---------- Lib/test/test_importlib/test_spec.py | 12 ------------ 2 files changed, 0 insertions(+), 22 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1183,15 +1183,6 @@ pass return module - # XXX If we don't end up using this for pythonrun.c/runpy, we should - # get rid of it. - def _load_existing(self, module): - """Exec the spec'ed module into an existing module's namespace.""" - # For use by runpy. - with _installed_safely(module): - loaded = self.exec(module) - return loaded - def _load_unlocked(self): # A helper for direct use by the import system. if self.spec.loader is not None: @@ -1389,7 +1380,6 @@ @classmethod def find_spec(cls, fullname, path=None, target=None): - # XXX untested! Need a Windows person to write tests (otherwise mock out appropriately) filepath = cls._search_registry(fullname) if filepath is None: return None diff --git a/Lib/test/test_importlib/test_spec.py b/Lib/test/test_importlib/test_spec.py --- a/Lib/test/test_importlib/test_spec.py +++ b/Lib/test/test_importlib/test_spec.py @@ -437,18 +437,6 @@ loaded = self.bootstrap._SpecMethods(self.spec).load() self.assertNotIn(self.spec.name, sys.modules) - def test_load_existing(self): - existing = type(sys)('ham') - existing.count = 5 - self.spec.loader = NewLoader() - with CleanImport(self.name): - sys.modules[self.name] = existing - assert self.spec.name == self.name - loaded = self.bootstrap._SpecMethods(self.spec).load() - - self.assertEqual(loaded.eggs, 1) - self.assertFalse(hasattr(loaded, 'ham')) - def test_load_legacy(self): self.spec.loader = LegacyLoader() with CleanImport(self.spec.name): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Jan 7 04:51:09 2014 From: python-checkins at python.org (eric.snow) Date: Tue, 7 Jan 2014 04:51:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2319703=3A_Update_p?= =?utf-8?q?ydoc_to_use_the_new_importer_APIs=2E?= Message-ID: <3dz04Y5Zwvz7Lkl@mail.python.org> http://hg.python.org/cpython/rev/f67ccb4490ea changeset: 88331:f67ccb4490ea user: Eric Snow date: Mon Jan 06 20:42:59 2014 -0700 summary: Issue #19703: Update pydoc to use the new importer APIs. files: Lib/pydoc.py | 17 +++++++++++++---- Lib/test/test_pydoc.py | 2 ++ Misc/NEWS | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -246,8 +246,12 @@ else: # Must be a binary module, which has to be imported. loader = loader_cls('__temp__', filename) + # XXX We probably don't need to pass in the loader here. + spec = importlib.util.spec_from_file_location('__temp__', filename, + loader=loader) + _spec = importlib._bootstrap._SpecMethods(spec) try: - module = loader.load_module('__temp__') + module = _spec.load() except: return None del sys.modules['__temp__'] @@ -277,8 +281,11 @@ loader = importlib._bootstrap.SourcelessFileLoader(name, path) else: loader = importlib._bootstrap.SourceFileLoader(name, path) + # XXX We probably don't need to pass in the loader here. + spec = importlib.util.spec_from_file_location(name, path, loader=loader) + _spec = importlib._bootstrap._SpecMethods(spec) try: - return loader.load_module(name) + return _spec.load() except: raise ErrorDuringImport(path, sys.exc_info()) @@ -2008,10 +2015,11 @@ callback(None, modname, '') else: try: - loader = importer.find_module(modname) + spec = pkgutil._get_spec(importer, modname) except SyntaxError: # raised by tests for bad coding cookies or BOM continue + loader = spec.loader if hasattr(loader, 'get_source'): try: source = loader.get_source(modname) @@ -2025,8 +2033,9 @@ else: path = None else: + _spec = importlib._bootstrap._SpecMethods(spec) try: - module = loader.load_module(modname) + module = _spec.load() except ImportError: if onerror: onerror(modname) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -649,8 +649,10 @@ def test_importfile(self): loaded_pydoc = pydoc.importfile(pydoc.__file__) + self.assertIsNot(loaded_pydoc, pydoc) self.assertEqual(loaded_pydoc.__name__, 'pydoc') self.assertEqual(loaded_pydoc.__file__, pydoc.__file__) + self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__) class TestDescriptions(unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -287,6 +287,8 @@ - Issue #19708: Update pkgutil to use the new importer APIs. +- Issue #19703: Update pydoc to use the new importer APIs. + - Issue #19851: Fixed a regression in reloading sub-modules. - ssl.create_default_context() sets OP_NO_COMPRESSION to prevent CRIME. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Jan 7 04:51:11 2014 From: python-checkins at python.org (eric.snow) Date: Tue, 7 Jan 2014 04:51:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_more_usage_of_APIs_?= =?utf-8?q?deprecated_by_PEP_451=2E?= Message-ID: <3dz04b0Pp3z7Lkt@mail.python.org> http://hg.python.org/cpython/rev/bfcbe41e892d changeset: 88332:bfcbe41e892d user: Eric Snow date: Mon Jan 06 20:42:59 2014 -0700 summary: Remove more usage of APIs deprecated by PEP 451. files: Lib/idlelib/EditorWindow.py | 8 ++++---- Lib/pkgutil.py | 13 +++++++------ Lib/pyclbr.py | 9 +++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -659,20 +659,20 @@ return # XXX Ought to insert current file's directory in front of path try: - loader = importlib.find_loader(name) + spec = importlib.find_spec(name) except (ValueError, ImportError) as msg: tkMessageBox.showerror("Import error", str(msg), parent=self.text) return - if loader is None: + if spec is None: tkMessageBox.showerror("Import error", "module not found", parent=self.text) return - if not isinstance(loader, importlib.abc.SourceLoader): + if not isinstance(spec.loader, importlib.abc.SourceLoader): tkMessageBox.showerror("Import error", "not a source-based module", parent=self.text) return try: - file_path = loader.get_filename(name) + file_path = spec.loader.get_filename(name) except AttributeError: tkMessageBox.showerror("Import error", "loader does not support get_filename", diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -554,13 +554,14 @@ finder = get_importer(dir) if finder is not None: + portions = [] + if hasattr(finder, 'find_spec'): + spec = finder.find_spec(final_name) + if spec is not None: + portions = spec.submodule_search_locations or [] # Is this finder PEP 420 compliant? - if hasattr(finder, 'find_loader'): - loader, portions = finder.find_loader(final_name) - else: - # No, no need to call it - loader = None - portions = [] + elif hasattr(finder, 'find_loader'): + _, portions = finder.find_loader(final_name) for portion in portions: # XXX This may still add duplicate entries to path on diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py --- a/Lib/pyclbr.py +++ b/Lib/pyclbr.py @@ -140,13 +140,14 @@ search_path = path else: search_path = path + sys.path - loader = importlib.find_loader(fullmodule, search_path) - fname = loader.get_filename(fullmodule) + # XXX This will change once issue19944 lands. + spec = importlib.find_spec(fullmodule, search_path) + fname = spec.loader.get_filename(fullmodule) _modules[fullmodule] = dict - if loader.is_package(fullmodule): + if spec.loader.is_package(fullmodule): dict['__path__'] = [os.path.dirname(fname)] try: - source = loader.get_source(fullmodule) + source = spec.loader.get_source(fullmodule) if source is None: return dict except (AttributeError, ImportError): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Jan 7 04:51:12 2014 From: python-checkins at python.org (eric.snow) Date: Tue, 7 Jan 2014 04:51:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_19713=3A_Add_PEP_451?= =?utf-8?q?-related_deprecations=2E?= Message-ID: <3dz04c5S29z7Lkr@mail.python.org> http://hg.python.org/cpython/rev/37caaf21f827 changeset: 88333:37caaf21f827 user: Eric Snow date: Mon Jan 06 20:49:04 2014 -0700 summary: Issue 19713: Add PEP 451-related deprecations. files: Lib/importlib/__init__.py | 6 +- Lib/importlib/_bootstrap.py | 124 +- Lib/importlib/abc.py | 13 +- Lib/importlib/util.py | 20 +- Lib/test/test_importlib/extension/test_finder.py | 5 +- Lib/test/test_importlib/frozen/test_loader.py | 42 +- Lib/test/test_importlib/source/test_file_loader.py | 54 +- Lib/test/test_importlib/source/test_finder.py | 49 +- Lib/test/test_importlib/source/test_source_encoding.py | 21 +- Lib/test/test_importlib/test_abc.py | 13 +- Lib/test/test_importlib/test_api.py | 27 +- Lib/test/test_importlib/test_spec.py | 2 +- Lib/test/test_importlib/test_util.py | 26 +- Misc/NEWS | 3 +- Python/importlib.h | 7978 +++++---- 15 files changed, 4342 insertions(+), 4041 deletions(-) diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -12,6 +12,7 @@ import _imp # Just the builtin component, NOT the full Python module import sys import types +import warnings try: import _frozen_importlib as _bootstrap @@ -77,13 +78,16 @@ return spec -# XXX Deprecate... def find_loader(name, path=None): """Return the loader for the specified module. This is a backward-compatible wrapper around find_spec(). + This function is deprecated in favor of importlib.find_spec(). + """ + warnings.warn('Use importlib.find_spec() instead.', DeprecationWarning, + stacklevel=2) try: loader = sys.modules[name].__loader__ if loader is None: diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -564,7 +564,11 @@ def _find_module_shim(self, fullname): """Try to find a loader for the specified module by delegating to - self.find_loader().""" + self.find_loader(). + + This method is deprecated in favor of finder.find_spec(). + + """ # Call find_loader(). If it returns a string (indicating this # is a namespace package portion), generate a warning and # return None. @@ -576,8 +580,11 @@ def _load_module_shim(self, fullname): - """Load the specified module into sys.modules and return it.""" - # XXX Deprecation Warning here... + """Load the specified module into sys.modules and return it. + + This method is deprecated. Use loader.exec_module instead. + + """ spec = spec_from_loader(fullname, self) methods = _SpecMethods(spec) if fullname in sys.modules: @@ -683,7 +690,9 @@ # The implementation of ModuleType__repr__(). loader = getattr(module, '__loader__', None) if hasattr(loader, 'module_repr'): - # XXX Deprecation Warning here... + # As soon as BuiltinImporter, FrozenImporter, and NamespaceLoader + # drop their implementations for module_repr. we can add a + # deprecation warning here. try: return loader.module_repr(module) except Exception: @@ -1149,17 +1158,27 @@ return module self.init_module_attrs(module, _override=True) if not hasattr(self.spec.loader, 'exec_module'): - # XXX DeprecationWarning goes here... + # (issue19713) Once BuiltinImporter and ExtensionFileLoader + # have exec_module() implemented, we can add a deprecation + # warning here. self.spec.loader.load_module(name) else: self._exec(module) return sys.modules[name] def _load_backward_compatible(self): - # XXX DeprecationWarning goes here... + # (issue19713) Once BuiltinImporter and ExtensionFileLoader + # have exec_module() implemented, we can add a deprecation + # warning here. spec = self.spec # The module must be in sys.modules! - spec.loader.load_module(spec.name) + try: + _warnings + except NameError: + # We must be importing builtins in setup(). + spec.loader.load_module(spec.name) + else: + spec.loader.load_module(spec.name) module = sys.modules[spec.name] if getattr(module, '__loader__', None) is None: try: @@ -1233,7 +1252,11 @@ @staticmethod def module_repr(module): - # XXX deprecate + """Return repr for the module. + + The method is deprecated. The import machinery does the job itself. + + """ return ''.format(module.__name__) @classmethod @@ -1251,6 +1274,8 @@ If 'path' is ever specified then the search is considered a failure. + This method is deprecated. Use find_spec() instead. + """ spec = cls.find_spec(fullname, path) return spec.loader if spec is not None else None @@ -1259,6 +1284,8 @@ @_requires_builtin def load_module(cls, fullname): """Load a built-in module.""" + # Once an exec_module() implementation is added we can also + # add a deprecation warning here. with _ManageReload(fullname): module = _call_with_frames_removed(_imp.init_builtin, fullname) module.__loader__ = cls @@ -1281,7 +1308,6 @@ @_requires_builtin def is_package(cls, fullname): """Return False as built-in modules are never packages.""" - # XXX DeprecationWarning here... return False @@ -1296,7 +1322,11 @@ @staticmethod def module_repr(m): - # XXX deprecate + """Return repr for the module. + + The method is deprecated. The import machinery does the job itself. + + """ return ''.format(m.__name__) @classmethod @@ -1308,7 +1338,11 @@ @classmethod def find_module(cls, fullname, path=None): - """Find a frozen module.""" + """Find a frozen module. + + This method is deprecated. Use find_spec() instead. + + """ return cls if _imp.is_frozen(fullname) else None @staticmethod @@ -1322,7 +1356,11 @@ @classmethod def load_module(cls, fullname): - """Load a frozen module.""" + """Load a frozen module. + + This method is deprecated. Use exec_module() instead. + + """ return _load_module_shim(cls, fullname) @classmethod @@ -1395,7 +1433,11 @@ @classmethod def find_module(cls, fullname, path=None): - """Find module named in the registry.""" + """Find module named in the registry. + + This method is deprecated. Use exec_module() instead. + + """ spec = cls.find_spec(fullname, path) if spec is not None: return spec.loader @@ -1408,7 +1450,6 @@ """Base class of common code needed by both SourceLoader and SourcelessFileLoader.""" - # XXX deprecate? def is_package(self, fullname): """Concrete implementation of InspectLoader.is_package by checking if the path returned by get_filename has a filename of '__init__.py'.""" @@ -1558,9 +1599,12 @@ @_check_name def load_module(self, fullname): - """Load a module from a file.""" + """Load a module from a file. + + This method is deprecated. Use exec_module() instead. + + """ # The only reason for this method is for the name check. - # Issue #14857: Avoid the zero-argument form of super so the implementation # of that form can be updated without breaking the frozen module return super(FileLoader, self).load_module(fullname) @@ -1660,6 +1704,8 @@ @_check_name def load_module(self, fullname): """Load an extension module.""" + # Once an exec_module() implementation is added we can also + # add a deprecation warning here. with _ManageReload(fullname): module = _call_with_frames_removed(_imp.load_dynamic, fullname, self.path) @@ -1754,9 +1800,13 @@ def __init__(self, name, path, path_finder): self._path = _NamespacePath(name, path, path_finder) - # XXX Deprecate @classmethod def module_repr(cls, module): + """Return repr for the module. + + The method is deprecated. The import machinery does the job itself. + + """ return ''.format(module.__name__) def is_package(self, fullname): @@ -1768,9 +1818,16 @@ def get_code(self, fullname): return compile('', '', 'exec', dont_inherit=True) - # XXX Deprecate + def exec_module(self, module): + pass + def load_module(self, fullname): - """Load a namespace module.""" + """Load a namespace module. + + This method is deprecated. Use exec_module() instead. + + """ + # The import system never calls this method. _verbose_message('namespace module loaded with path {!r}', self._path) return _load_module_shim(self, fullname) @@ -1825,6 +1882,8 @@ @classmethod def _legacy_get_spec(cls, fullname, finder): + # This would be a good place for a DeprecationWarning if + # we ended up going that route. if hasattr(finder, 'find_loader'): loader, portions = finder.find_loader(fullname) else: @@ -1893,8 +1952,11 @@ @classmethod def find_module(cls, fullname, path=None): """find the module on sys.path or 'path' based on sys.path_hooks and - sys.path_importer_cache.""" - # XXX Deprecation warning here. + sys.path_importer_cache. + + This method is deprecated. Use find_spec() instead. + + """ spec = cls.find_spec(fullname, path) if spec is None: return None @@ -1932,7 +1994,11 @@ def find_loader(self, fullname): """Try to find a loader for the specified module, or the namespace - package portions. Returns (loader, list-of-portions).""" + package portions. Returns (loader, list-of-portions). + + This method is deprecated. Use find_spec() instead. + + """ spec = self.find_spec(fullname) if spec is None: return None, [] @@ -2065,6 +2131,15 @@ return '{}.{}'.format(base, name) if name else base +def _find_spec_legacy(finder, name, path): + # This would be a good place for a DeprecationWarning if + # we ended up going that route. + loader = finder.find_module(name, path) + if loader is None: + return None + return spec_from_loader(name, loader) + + def _find_spec(name, path, target=None): """Find a module's loader.""" if not sys.meta_path: @@ -2078,10 +2153,9 @@ try: find_spec = finder.find_spec except AttributeError: - loader = finder.find_module(name, path) - if loader is None: + spec = _find_spec_legacy(finder, name, path) + if spec is None: continue - spec = spec_from_loader(name, loader) else: spec = find_spec(name, path, target) if spec is not None: diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -43,13 +43,14 @@ # We don't define find_spec() here since that would break # hasattr checks we do to support backward compatibility. - # XXX Deprecate def find_module(self, fullname, path): """Return a loader for the module. If no module is found, return None. The fullname is a str and the path is a list of strings or None. + This method is deprecated in favor of finder.find_spec(). + """ return None @@ -69,7 +70,6 @@ # We don't define find_spec() here since that would break # hasattr checks we do to support backward compatibility. - # XXX Deprecate. def find_loader(self, fullname): """Return (loader, namespace portion) for the path entry. @@ -81,10 +81,11 @@ The portion will be discarded if another path entry finder locates the module as a normal module or package. + This method is deprecated in favor of finder.find_spec(). + """ return None, [] - # XXX Deprecate. find_module = _bootstrap._find_module_shim def invalidate_caches(self): @@ -115,7 +116,6 @@ # We don't define exec_module() here since that would break # hasattr checks we do to support backward compatibility. - # XXX Deprecate. def load_module(self, fullname): """Return the loaded module. @@ -124,16 +124,19 @@ ImportError is raised on failure. + This method is deprecated in favor of loader.exec_module(). + """ raise ImportError - # XXX Deprecate. def module_repr(self, module): """Return a module's repr. Used by the module type when the method does not raise NotImplementedError. + This method is deprecated. + """ # The exception will cause ModuleType.__repr__ to ignore this method. raise NotImplementedError diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -55,11 +55,16 @@ module.__initializing__ = False -# XXX deprecate def set_package(fxn): - """Set __package__ on the returned module.""" + """Set __package__ on the returned module. + + This function is deprecated. + + """ @functools.wraps(fxn) def set_package_wrapper(*args, **kwargs): + warnings.warn('The import system now takes care of this automatically.', + DeprecationWarning, stacklevel=2) module = fxn(*args, **kwargs) if getattr(module, '__package__', None) is None: module.__package__ = module.__name__ @@ -69,11 +74,16 @@ return set_package_wrapper -# XXX deprecate def set_loader(fxn): - """Set __loader__ on the returned module.""" + """Set __loader__ on the returned module. + + This function is deprecated. + + """ @functools.wraps(fxn) def set_loader_wrapper(self, *args, **kwargs): + warnings.warn('The import system now takes care of this automatically.', + DeprecationWarning, stacklevel=2) module = fxn(self, *args, **kwargs) if getattr(module, '__loader__', None) is None: module.__loader__ = self @@ -100,7 +110,7 @@ """ warnings.warn('The import system now takes care of this automatically.', - PendingDeprecationWarning, stacklevel=2) + DeprecationWarning, stacklevel=2) @functools.wraps(fxn) def module_for_loader_wrapper(self, fullname, *args, **kwargs): with _module_to_load(fullname) as module: diff --git a/Lib/test/test_importlib/extension/test_finder.py b/Lib/test/test_importlib/extension/test_finder.py --- a/Lib/test/test_importlib/extension/test_finder.py +++ b/Lib/test/test_importlib/extension/test_finder.py @@ -5,6 +5,7 @@ machinery = test_util.import_importlib('importlib.machinery') import unittest +import warnings # XXX find_spec tests @@ -16,7 +17,9 @@ importer = self.machinery.FileFinder(util.PATH, (self.machinery.ExtensionFileLoader, self.machinery.EXTENSION_SUFFIXES)) - return importer.find_module(fullname) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + return importer.find_module(fullname) def test_module(self): self.assertTrue(self.find_module(util.NAME)) diff --git a/Lib/test/test_importlib/frozen/test_loader.py b/Lib/test/test_importlib/frozen/test_loader.py --- a/Lib/test