[Python-checkins] r81293 - in python/branches/py3k-jit: Doc/c-api/list.rst Doc/c-api/unicode.rst Doc/distutils/sourcedist.rst Doc/howto/cporting.rst Doc/library/imp.rst Doc/library/pkgutil.rst Doc/library/runpy.rst Doc/library/ssl.rst Doc/library/sys.rst Doc/library/tarfile.rst Doc/library/wsgiref.rst Doc/library/zipimport.rst Include/unicodeobject.h Lib/distutils/command/sdist.py Lib/distutils/tests/test_sdist.py Lib/ssl.py Lib/subprocess.py Lib/tarfile.py Lib/test/capath Lib/test/list_tests.py Lib/test/test_capi.py Lib/test/test_import.py Lib/test/test_math.py Lib/test/test_os.py Lib/test/test_signal.py Lib/test/test_site.py Lib/test/test_ssl.py Lib/test/test_sys.py Lib/test/test_tarfile.py Lib/test/testtar.tar Lib/urllib/parse.py Lib/urllib/request.py Makefile.pre.in Misc/NEWS Modules/_cursesmodule.c Modules/_io/fileio.c Modules/_ssl.c Modules/_testcapimodule.c Modules/_tkinter.c Modules/grpmodule.c Modules/main.c Modules/mathmodule.c Modules/posixmodule.c Modules/pwdmodule.c Modules/spwdmodule.c Objects/object.c Objects/unicodeobject.c Parser/printgrammar.c Python/bltinmodule.c Python/graminit.c Python/import.c Python/pythonrun.c
collin.winter
python-checkins at python.org
Tue May 18 19:58:31 CEST 2010
Author: collin.winter
Date: Tue May 18 19:58:30 2010
New Revision: 81293
Log:
Merged revisions 81146,81153,81155-81156,81165,81168,81170,81181,81183,81188,81190,81192,81194,81196-81199,81201,81204,81207,81209,81211,81214-81215,81218-81219,81222,81226,81231,81233-81237,81239,81242,81246-81247,81249-81253,81257-81258,81263,81266-81267,81269-81273,81276 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r81146 | benjamin.peterson | 2010-05-13 14:16:51 -0700 (Thu, 13 May 2010) | 9 lines
Merged revisions 81145 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81145 | benjamin.peterson | 2010-05-13 16:14:10 -0500 (Thu, 13 May 2010) | 1 line
rip out mention of types.ListType #8703
........
................
r81153 | brett.cannon | 2010-05-13 17:04:56 -0700 (Thu, 13 May 2010) | 10 lines
Merged revisions 81152 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81152 | brett.cannon | 2010-05-13 16:59:41 -0700 (Thu, 13 May 2010) | 3 lines
test_site was failing under darwin for non-framework builds because a test was
assuming framework-specific site-packages directories were being used.
........
................
r81155 | brett.cannon | 2010-05-13 17:33:40 -0700 (Thu, 13 May 2010) | 22 lines
Merged revisions 81154 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81154 | brett.cannon | 2010-05-13 17:21:48 -0700 (Thu, 13 May 2010) | 15 lines
subprocess.Popen.__del__ referenced global objects, which is a no-no thanks to
interpreter shutdown semantics. Same issue goes for the methods that __del__
called. Now all the methods capture the global objects it needs as default
values to private parameters (could have stuck them on the class object itself,
but since the objects have nothing directly to do with the class that seemed
wrong).
There is no test as making one that works is hard. This patch was
verified against a consistently failing test in Mercurial's test suite, though,
so it has been tested in some regard.
Closes issue #5099. Thanks to Mary Stern for the bug report and Gabriel
Genellina for writing another patch for the same issue and attempting to write
a test.
........
................
r81156 | victor.stinner | 2010-05-13 17:59:09 -0700 (Thu, 13 May 2010) | 5 lines
Issue #4653: fix typo in flush_std_files()
Don't call sys.stderr.flush() if sys has no stderr attribute or if
sys.stderr==None.
................
r81165 | victor.stinner | 2010-05-14 07:36:18 -0700 (Fri, 14 May 2010) | 9 lines
Merged revisions 81163 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81163 | victor.stinner | 2010-05-14 16:20:07 +0200 (ven., 14 mai 2010) | 2 lines
Doc: replace PEP xxx by :pep:`xxx` to create a link on the PEP
........
................
r81168 | victor.stinner | 2010-05-14 08:58:55 -0700 (Fri, 14 May 2010) | 10 lines
Issue #8711: Document PyUnicode_DecodeFSDefault*() functions
* Add paragraph titles to c-api/unicode.rst.
* Fix PyUnicode_DecodeFSDefault*() comment: it now uses the "surrogateescape"
error handler (and not "replace")
* Remove "The function is intended to be used for paths and file names only
during bootstrapping process where the codecs are not set up." from
PyUnicode_FSConverter() comment: it is used after the bootstrapping and for
other purposes than file names
................
r81170 | victor.stinner | 2010-05-14 09:35:39 -0700 (Fri, 14 May 2010) | 6 lines
posix_listdir(), posix_readlink(): avoid temporary PyBytes object
Use directly PyUnicode_DecodeFSDefaultAndSize() instead of
PyBytes_FromStringAndSize() + PyUnicode_FromEncodedObject() if the argument is
unicode.
................
r81181 | victor.stinner | 2010-05-14 14:53:45 -0700 (Fri, 14 May 2010) | 9 lines
Merged revisions 81179 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81179 | victor.stinner | 2010-05-14 23:52:26 +0200 (ven., 14 mai 2010) | 2 lines
Fix regression introduced by r81154 (Issue #5099, subprocess destructor)
........
................
r81183 | victor.stinner | 2010-05-14 18:40:41 -0700 (Fri, 14 May 2010) | 4 lines
Fix test_capi for Windows: strip newline characters
Fix test_no_FatalError_infinite_loop() introduced by r81142 (issue #3605).
................
r81188 | stefan.krah | 2010-05-15 02:41:27 -0700 (Sat, 15 May 2010) | 10 lines
Merged revisions 81185 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81185 | stefan.krah | 2010-05-15 11:31:08 +0200 (Sat, 15 May 2010) | 4 lines
If the timeout is exceeded, count the tests as skipped instead of just
issuing a warning.
........
................
r81190 | victor.stinner | 2010-05-15 05:27:16 -0700 (Sat, 15 May 2010) | 4 lines
Issue #8610: Load file system codec at startup, and display a fatal error on
failure. Set the file system encoding to utf-8 (instead of None) if getting
the locale encoding failed, or if nl_langinfo(CODESET) function is missing.
................
r81192 | victor.stinner | 2010-05-15 06:14:32 -0700 (Sat, 15 May 2010) | 3 lines
Enable shortcuts for common encodings in PyUnicode_AsEncodedString() for any
error handler, not only the default error handler (strict)
................
r81194 | victor.stinner | 2010-05-15 09:27:27 -0700 (Sat, 15 May 2010) | 5 lines
Issue #8715: Create PyUnicode_EncodeFSDefault() function: Encode a Unicode
object to Py_FileSystemDefaultEncoding with the "surrogateescape" error
handler, return a bytes object. If Py_FileSystemDefaultEncoding is not set,
fall back to UTF-8.
................
r81196 | mark.dickinson | 2010-05-15 10:02:38 -0700 (Sat, 15 May 2010) | 13 lines
Issue #8692: Improve performance of math.factorial:
(1) use a different algorithm that roughly halves the total number of
multiplications required and results in more balanced multiplications
(2) use a lookup table for small arguments
(3) fast accumulation of products in C integer arithmetic rather than
PyLong arithmetic when possible.
Typical speedup, from unscientific testing on a 64-bit laptop, is 4.5x
to 6.5x for arguments in the range 100 - 10000.
Patch by Daniel Stutzbach; extensive reviews by Alexander Belopolsky.
................
r81197 | benjamin.peterson | 2010-05-15 10:42:02 -0700 (Sat, 15 May 2010) | 1 line
fix run-on sentence
................
r81198 | benjamin.peterson | 2010-05-15 10:43:18 -0700 (Sat, 15 May 2010) | 1 line
rephrase
................
r81199 | benjamin.peterson | 2010-05-15 10:43:57 -0700 (Sat, 15 May 2010) | 1 line
fix one more runon
................
r81201 | benjamin.peterson | 2010-05-15 10:52:12 -0700 (Sat, 15 May 2010) | 9 lines
Merged revisions 81200 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81200 | benjamin.peterson | 2010-05-15 12:48:55 -0500 (Sat, 15 May 2010) | 1 line
use TestCase skip method
........
................
r81204 | amaury.forgeotdarc | 2010-05-15 13:35:12 -0700 (Sat, 15 May 2010) | 2 lines
Remove unused variable, and fix a compilation warning on Windows.
................
r81207 | victor.stinner | 2010-05-15 14:04:43 -0700 (Sat, 15 May 2010) | 9 lines
Recorded merge of revisions 81205 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81205 | victor.stinner | 2010-05-15 23:00:59 +0200 (sam., 15 mai 2010) | 2 lines
NEWS: strip trailing spaces
........
................
r81209 | antoine.pitrou | 2010-05-15 14:34:27 -0700 (Sat, 15 May 2010) | 3 lines
Issue #8665: Fix `make pycremoval` exiting with non-zero status.
................
r81211 | amaury.forgeotdarc | 2010-05-15 14:49:45 -0700 (Sat, 15 May 2010) | 8 lines
Blocked revisions 81210 via svnmerge
........
r81210 | amaury.forgeotdarc | 2010-05-15 23:45:30 +0200 (sam., 15 mai 2010) | 2 lines
Remove unused variable, and fix a compilation warning on Windows
........
................
r81214 | brett.cannon | 2010-05-15 15:20:16 -0700 (Sat, 15 May 2010) | 2 lines
A test was not guaranteeing cleanup in the face of an exception.
................
r81215 | victor.stinner | 2010-05-15 15:23:53 -0700 (Sat, 15 May 2010) | 12 lines
Recorded merge of revisions 81213 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81213 | victor.stinner | 2010-05-16 00:19:27 +0200 (dim., 16 mai 2010) | 5 lines
reindent _cursesmodule.c
Use untabify.py + emacs (python3 mode) + manual editions for
Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS
........
................
r81218 | brett.cannon | 2010-05-15 15:51:45 -0700 (Sat, 15 May 2010) | 1 line
Fix a comment to state the right thing.
................
r81219 | brett.cannon | 2010-05-15 15:53:24 -0700 (Sat, 15 May 2010) | 4 lines
Make test_module_with_large_stack as an expected failure because of a change in
importlib that is causing it to fail. Work to fix it is being tracked in issue
8727.
................
r81222 | victor.stinner | 2010-05-15 16:00:51 -0700 (Sat, 15 May 2010) | 11 lines
Merged revisions 81220 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81220 | victor.stinner | 2010-05-16 00:55:28 +0200 (dim., 16 mai 2010) | 4 lines
Use 4-spaces for indentation (instead of tabs) in pgen outputs
Regenerate (reindent) Python/graminit.c
........
................
r81226 | victor.stinner | 2010-05-15 17:36:38 -0700 (Sat, 15 May 2010) | 11 lines
Merged revisions 81224 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81224 | victor.stinner | 2010-05-16 02:34:40 +0200 (dim., 16 mai 2010) | 4 lines
Use with open() as fo: ... instead of try: fo = open(...) finally: fo.close()
fo is not set if the open() fails.
........
................
r81231 | antoine.pitrou | 2010-05-16 07:19:41 -0700 (Sun, 16 May 2010) | 9 lines
Merged revisions 81229 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81229 | antoine.pitrou | 2010-05-16 16:16:56 +0200 (dim., 16 mai 2010) | 3 lines
Document that SSL v2 is insecure.
........
................
r81233 | antoine.pitrou | 2010-05-16 11:19:27 -0700 (Sun, 16 May 2010) | 3 lines
Issue #8550: Add first class `SSLContext` objects to the ssl module.
................
r81234 | antoine.pitrou | 2010-05-16 12:22:44 -0700 (Sun, 16 May 2010) | 3 lines
Followup on r81233: fix test_ssl with OpenSSL < 1.0.0.
................
r81235 | antoine.pitrou | 2010-05-16 12:56:32 -0700 (Sun, 16 May 2010) | 3 lines
Fix (hopefully) the remaining test_ssl buildbot failures
................
r81236 | antoine.pitrou | 2010-05-16 13:35:03 -0700 (Sun, 16 May 2010) | 3 lines
Do not fail if ssl fails to import
................
r81237 | victor.stinner | 2010-05-16 14:23:48 -0700 (Sun, 16 May 2010) | 3 lines
Issue #8477: _ssl._test_decode_cert() supports str with surrogates and bytes
for the filename
................
r81239 | victor.stinner | 2010-05-16 14:36:37 -0700 (Sun, 16 May 2010) | 2 lines
Issue #8477: ssl.RAND_egd() supports str with surrogates and bytes for the path
................
r81242 | antoine.pitrou | 2010-05-16 16:14:22 -0700 (Sun, 16 May 2010) | 10 lines
Merged revisions 81241 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81241 | antoine.pitrou | 2010-05-17 01:11:46 +0200 (lun., 17 mai 2010) | 4 lines
Clear the OpenSSL error queue each time an error is signalled.
When the error queue is not emptied, strange things can happen on the next SSL call, depending on the OpenSSL version.
........
................
r81246 | antoine.pitrou | 2010-05-16 16:46:26 -0700 (Sun, 16 May 2010) | 3 lines
"xyzzy" is not a silly enough name for some OpenSSL versions to report an error
................
r81247 | victor.stinner | 2010-05-16 17:14:53 -0700 (Sun, 16 May 2010) | 9 lines
test_os: cleanup test_internal_execvpe() and os._execvpe() mockup
* Replace os.defpath instead of os.get_exec_path() to test also
os.get_exec_path()
* Use contextlib.contextmanager, move the mockup outside the class, and
the mockup returns directly the call list object
* Use two different contexts for the two tests
* Use more revelant values and names
................
r81249 | victor.stinner | 2010-05-16 17:18:34 -0700 (Sun, 16 May 2010) | 2 lines
Oops, my patch on subprocess is not merged yet: fix my previous commit on test_os
................
r81250 | victor.stinner | 2010-05-16 18:13:37 -0700 (Sun, 16 May 2010) | 2 lines
Issue #6697: Fix a crash if code of "python -c code" contains surrogates
................
r81251 | victor.stinner | 2010-05-16 18:26:01 -0700 (Sun, 16 May 2010) | 3 lines
PyObject_Dump() encodes unicode objects to utf8 with backslashreplace (instead
of strict) error handler to escape surrogates
................
r81252 | victor.stinner | 2010-05-17 01:58:51 -0700 (Mon, 17 May 2010) | 6 lines
handle_system_exit() flushs files to warranty the output order
PyObject_Print() writes into the C object stderr, whereas PySys_WriteStderr()
writes into the Python object sys.stderr. Each object has its own buffer, so
call sys.stderr.flush() and fflush(stderr).
................
r81253 | victor.stinner | 2010-05-17 02:33:42 -0700 (Mon, 17 May 2010) | 6 lines
Fix refleak in internal_print() introduced by myself in r81251
_PyUnicode_AsDefaultEncodedString() uses a magical PyUnicode attribute to
automatically destroy PyUnicode_EncodeUTF8() result when the unicode string is
destroyed.
................
r81257 | antoine.pitrou | 2010-05-17 03:30:00 -0700 (Mon, 17 May 2010) | 3 lines
Try to fix buildbot failures with old OpenSSLs.
................
r81258 | tarek.ziade | 2010-05-17 03:38:53 -0700 (Mon, 17 May 2010) | 9 lines
Merged revisions 81255 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81255 | tarek.ziade | 2010-05-17 12:06:20 +0200 (Mon, 17 May 2010) | 1 line
Fixed #8688: Distutils now recalculates MANIFEST everytime.
........
................
r81263 | tarek.ziade | 2010-05-17 04:01:57 -0700 (Mon, 17 May 2010) | 9 lines
Merged revisions 81261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81261 | tarek.ziade | 2010-05-17 12:54:43 +0200 (Mon, 17 May 2010) | 1 line
upgraded distutils docs w.r.t. the manifest regeneration
........
................
r81266 | antoine.pitrou | 2010-05-17 07:13:10 -0700 (Mon, 17 May 2010) | 3 lines
Typo (thanks Arfrever)
................
r81267 | victor.stinner | 2010-05-17 07:36:43 -0700 (Mon, 17 May 2010) | 2 lines
Improve test_exit() error message to analyze sparc failures
................
r81269 | jeffrey.yasskin | 2010-05-17 09:59:23 -0700 (Mon, 17 May 2010) | 4 lines
Fix test_capi in !pydebug mode, where my original attempt segfaulted without
producing the expected error message. The test only tests what it's supposed
to test in pydebug mode though. Fixes issue 8726.
................
r81270 | florent.xicluna | 2010-05-17 10:24:07 -0700 (Mon, 17 May 2010) | 9 lines
Merged revision 81259 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81259 | florent.xicluna | 2010-05-17 12:39:07 +0200 (lun, 17 mai 2010) | 2 lines
Slight style cleanup.
........
................
r81271 | florent.xicluna | 2010-05-17 10:33:07 -0700 (Mon, 17 May 2010) | 11 lines
Issue #1285086: Speed up urllib.parse functions: quote, quote_from_bytes, unquote, unquote_to_bytes.
Recorded merge of revisions 81265 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81265 | florent.xicluna | 2010-05-17 15:35:09 +0200 (lun, 17 mai 2010) | 2 lines
Issue #1285086: Speed up urllib.quote and urllib.unquote for simple cases.
........
................
r81272 | florent.xicluna | 2010-05-17 11:01:22 -0700 (Mon, 17 May 2010) | 2 lines
Inadvertently removed part of the comment in r81271.
................
r81273 | lars.gustaebel | 2010-05-17 11:02:50 -0700 (Mon, 17 May 2010) | 15 lines
Issue #8633: Support for POSIX.1-2008 binary pax headers.
tarfile is now able to read and write pax headers with a
"hdrcharset=BINARY" record. This record was introduced in
POSIX.1-2008 as a method to store unencoded binary strings that
cannot be translated to UTF-8. In practice, this is just a workaround
that allows a tar implementation to store filenames that do not
comply with the current filesystem encoding and thus cannot be
decoded correctly.
Additionally, tarfile works around a bug in current versions of GNU
tar: undecodable filenames are stored as-is in a pax header without a
"hdrcharset" record being added. Technically, these headers are
invalid, but tarfile manages to read them correctly anyway.
................
r81276 | victor.stinner | 2010-05-17 12:57:40 -0700 (Mon, 17 May 2010) | 4 lines
Fix test_main_invalid_unicode() of test_sys for ASCII locale encoding
It should fix sparc 3.x and 3.1 failures.
................
Added:
python/branches/py3k-jit/Lib/test/capath/
- copied from r81276, /python/branches/py3k/Lib/test/capath/
Modified:
python/branches/py3k-jit/ (props changed)
python/branches/py3k-jit/Doc/c-api/list.rst
python/branches/py3k-jit/Doc/c-api/unicode.rst
python/branches/py3k-jit/Doc/distutils/sourcedist.rst
python/branches/py3k-jit/Doc/howto/cporting.rst
python/branches/py3k-jit/Doc/library/imp.rst
python/branches/py3k-jit/Doc/library/pkgutil.rst
python/branches/py3k-jit/Doc/library/runpy.rst
python/branches/py3k-jit/Doc/library/ssl.rst
python/branches/py3k-jit/Doc/library/sys.rst
python/branches/py3k-jit/Doc/library/tarfile.rst
python/branches/py3k-jit/Doc/library/wsgiref.rst
python/branches/py3k-jit/Doc/library/zipimport.rst
python/branches/py3k-jit/Include/unicodeobject.h
python/branches/py3k-jit/Lib/distutils/command/sdist.py
python/branches/py3k-jit/Lib/distutils/tests/test_sdist.py
python/branches/py3k-jit/Lib/ssl.py
python/branches/py3k-jit/Lib/subprocess.py
python/branches/py3k-jit/Lib/tarfile.py
python/branches/py3k-jit/Lib/test/list_tests.py
python/branches/py3k-jit/Lib/test/test_capi.py
python/branches/py3k-jit/Lib/test/test_import.py
python/branches/py3k-jit/Lib/test/test_math.py
python/branches/py3k-jit/Lib/test/test_os.py
python/branches/py3k-jit/Lib/test/test_signal.py
python/branches/py3k-jit/Lib/test/test_site.py
python/branches/py3k-jit/Lib/test/test_ssl.py
python/branches/py3k-jit/Lib/test/test_sys.py
python/branches/py3k-jit/Lib/test/test_tarfile.py
python/branches/py3k-jit/Lib/test/testtar.tar
python/branches/py3k-jit/Lib/urllib/parse.py
python/branches/py3k-jit/Lib/urllib/request.py
python/branches/py3k-jit/Makefile.pre.in
python/branches/py3k-jit/Misc/NEWS
python/branches/py3k-jit/Modules/_cursesmodule.c
python/branches/py3k-jit/Modules/_io/fileio.c
python/branches/py3k-jit/Modules/_ssl.c
python/branches/py3k-jit/Modules/_testcapimodule.c
python/branches/py3k-jit/Modules/_tkinter.c
python/branches/py3k-jit/Modules/grpmodule.c
python/branches/py3k-jit/Modules/main.c
python/branches/py3k-jit/Modules/mathmodule.c
python/branches/py3k-jit/Modules/posixmodule.c
python/branches/py3k-jit/Modules/pwdmodule.c
python/branches/py3k-jit/Modules/spwdmodule.c
python/branches/py3k-jit/Objects/object.c
python/branches/py3k-jit/Objects/unicodeobject.c
python/branches/py3k-jit/Parser/printgrammar.c
python/branches/py3k-jit/Python/bltinmodule.c
python/branches/py3k-jit/Python/graminit.c
python/branches/py3k-jit/Python/import.c
python/branches/py3k-jit/Python/pythonrun.c
Modified: python/branches/py3k-jit/Doc/c-api/list.rst
==============================================================================
--- python/branches/py3k-jit/Doc/c-api/list.rst (original)
+++ python/branches/py3k-jit/Doc/c-api/list.rst Tue May 18 19:58:30 2010
@@ -15,11 +15,8 @@
.. cvar:: PyTypeObject PyList_Type
- .. index:: single: ListType (in module types)
-
- This instance of :ctype:`PyTypeObject` represents the Python list type.
- This is the same object as ``list`` and ``types.ListType`` in the Python
- layer.
+ This instance of :ctype:`PyTypeObject` represents the Python list type. This
+ is the same object as ``list`` in the Python layer.
.. cfunction:: int PyList_Check(PyObject *p)
Modified: python/branches/py3k-jit/Doc/c-api/unicode.rst
==============================================================================
--- python/branches/py3k-jit/Doc/c-api/unicode.rst (original)
+++ python/branches/py3k-jit/Doc/c-api/unicode.rst Tue May 18 19:58:30 2010
@@ -10,11 +10,12 @@
Unicode Objects
^^^^^^^^^^^^^^^
+Unicode Type
+""""""""""""
+
These are the basic Unicode object types used for the Unicode implementation in
Python:
-.. % --- Unicode Type -------------------------------------------------------
-
.. ctype:: Py_UNICODE
@@ -89,12 +90,13 @@
Clear the free list. Return the total number of freed items.
+Unicode Character Properties
+""""""""""""""""""""""""""""
+
Unicode provides many different character properties. The most often needed ones
are available through these macros which are mapped to C functions depending on
the Python configuration.
-.. % --- Unicode character properties ---------------------------------------
-
.. cfunction:: int Py_UNICODE_ISSPACE(Py_UNICODE ch)
@@ -192,11 +194,13 @@
Return the character *ch* converted to a double. Return ``-1.0`` if this is not
possible. This macro does not raise exceptions.
+
+Plain Py_UNICODE
+""""""""""""""""
+
To create Unicode objects and access their basic sequence properties, use these
APIs:
-.. % --- Plain Py_UNICODE ---------------------------------------------------
-
.. cfunction:: PyObject* PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
@@ -364,8 +368,57 @@
Support is optimized if Python's own :ctype:`Py_UNICODE` type is identical to
the system's :ctype:`wchar_t`.
-.. % --- wchar_t support for platforms which support it ---------------------
+File System Encoding
+""""""""""""""""""""
+
+To encode and decode file names and other environment strings,
+:cdata:`Py_FileSystemEncoding` should be used as the encoding, and
+``"surrogateescape"`` should be used as the error handler (:pep:`383`). To
+encode file names during argument parsing, the ``"O&"`` converter should be
+used, passsing :func:PyUnicode_FSConverter as the conversion function:
+
+.. cfunction:: int PyUnicode_FSConverter(PyObject* obj, void* result)
+
+ Convert *obj* into *result*, using :cdata:`Py_FileSystemDefaultEncoding`,
+ and the ``"surrogateescape"`` error handler. *result* must be a
+ ``PyObject*``, return a :func:`bytes` object which must be released if it
+ is no longer used.
+
+ .. versionadded:: 3.1
+
+.. cfunction:: PyObject* PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
+
+ Decode a null-terminated string using :cdata:`Py_FileSystemDefaultEncoding`
+ and the ``"surrogateescape"`` error handler.
+
+ If :cdata:`Py_FileSystemDefaultEncoding` is not set, fall back to UTF-8.
+
+ Use :func:`PyUnicode_DecodeFSDefaultAndSize` if you know the string length.
+
+
+.. cfunction:: PyObject* PyUnicode_DecodeFSDefault(const char *s)
+
+ Decode a string using :cdata:`Py_FileSystemDefaultEncoding` and
+ the ``"surrogateescape"`` error handler.
+
+ If :cdata:`Py_FileSystemDefaultEncoding` is not set, fall back to UTF-8.
+
+
+.. cfunction:: PyObject* PyUnicode_EncodeFSDefault(PyObject *unicode)
+
+ Encode a Unicode object to :cdata:`Py_FileSystemDefaultEncoding` with the
+ ``'surrogateescape'`` error handler, and return :class:`bytes`.
+
+ If :cdata:`Py_FileSystemDefaultEncoding` is not set, fall back to UTF-8.
+
+ .. versionadded:: 3.2
+
+
+wchar_t Support
+"""""""""""""""
+
+wchar_t support for platforms which support it:
.. cfunction:: PyObject* PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size)
@@ -413,9 +466,11 @@
The codecs all use a similar interface. Only deviation from the following
generic ones are documented for simplicity.
-These are the generic codec APIs:
-.. % --- Generic Codecs -----------------------------------------------------
+Generic Codecs
+""""""""""""""
+
+These are the generic codec APIs:
.. cfunction:: PyObject* PyUnicode_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors)
@@ -444,9 +499,11 @@
using the Python codec registry. Return *NULL* if an exception was raised by
the codec.
-These are the UTF-8 codec APIs:
-.. % --- UTF-8 Codecs -------------------------------------------------------
+UTF-8 Codecs
+""""""""""""
+
+These are the UTF-8 codec APIs:
.. cfunction:: PyObject* PyUnicode_DecodeUTF8(const char *s, Py_ssize_t size, const char *errors)
@@ -476,9 +533,11 @@
object. Error handling is "strict". Return *NULL* if an exception was
raised by the codec.
-These are the UTF-32 codec APIs:
-.. % --- UTF-32 Codecs ------------------------------------------------------ */
+UTF-32 Codecs
+"""""""""""""
+
+These are the UTF-32 codec APIs:
.. cfunction:: PyObject* PyUnicode_DecodeUTF32(const char *s, Py_ssize_t size, const char *errors, int *byteorder)
@@ -543,9 +602,10 @@
Return *NULL* if an exception was raised by the codec.
-These are the UTF-16 codec APIs:
+UTF-16 Codecs
+"""""""""""""
-.. % --- UTF-16 Codecs ------------------------------------------------------ */
+These are the UTF-16 codec APIs:
.. cfunction:: PyObject* PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors, int *byteorder)
@@ -609,9 +669,11 @@
order. The string always starts with a BOM mark. Error handling is "strict".
Return *NULL* if an exception was raised by the codec.
-These are the "Unicode Escape" codec APIs:
-.. % --- Unicode-Escape Codecs ----------------------------------------------
+Unicode-Escape Codecs
+"""""""""""""""""""""
+
+These are the "Unicode Escape" codec APIs:
.. cfunction:: PyObject* PyUnicode_DecodeUnicodeEscape(const char *s, Py_ssize_t size, const char *errors)
@@ -633,9 +695,11 @@
string object. Error handling is "strict". Return *NULL* if an exception was
raised by the codec.
-These are the "Raw Unicode Escape" codec APIs:
-.. % --- Raw-Unicode-Escape Codecs ------------------------------------------
+Raw-Unicode-Escape Codecs
+"""""""""""""""""""""""""
+
+These are the "Raw Unicode Escape" codec APIs:
.. cfunction:: PyObject* PyUnicode_DecodeRawUnicodeEscape(const char *s, Py_ssize_t size, const char *errors)
@@ -657,11 +721,13 @@
Python string object. Error handling is "strict". Return *NULL* if an exception
was raised by the codec.
+
+Latin-1 Codecs
+""""""""""""""
+
These are the Latin-1 codec APIs: Latin-1 corresponds to the first 256 Unicode
ordinals and only these are accepted by the codecs during encoding.
-.. % --- Latin-1 Codecs -----------------------------------------------------
-
.. cfunction:: PyObject* PyUnicode_DecodeLatin1(const char *s, Py_ssize_t size, const char *errors)
@@ -682,11 +748,13 @@
object. Error handling is "strict". Return *NULL* if an exception was
raised by the codec.
+
+ASCII Codecs
+""""""""""""
+
These are the ASCII codec APIs. Only 7-bit ASCII data is accepted. All other
codes generate errors.
-.. % --- ASCII Codecs -------------------------------------------------------
-
.. cfunction:: PyObject* PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *errors)
@@ -707,9 +775,11 @@
object. Error handling is "strict". Return *NULL* if an exception was
raised by the codec.
-These are the mapping codec APIs:
-.. % --- Character Map Codecs -----------------------------------------------
+Character Map Codecs
+""""""""""""""""""""
+
+These are the mapping codec APIs:
This codec is special in that it can be used to implement many different codecs
(and this is in fact what was done to obtain most of the standard codecs
@@ -778,7 +848,9 @@
DBCS) is a class of encodings, not just one. The target encoding is defined by
the user settings on the machine running the codec.
-.. % --- MBCS codecs for Windows --------------------------------------------
+
+MBCS codecs for Windows
+"""""""""""""""""""""""
.. cfunction:: PyObject* PyUnicode_DecodeMBCS(const char *s, Py_ssize_t size, const char *errors)
@@ -808,20 +880,9 @@
object. Error handling is "strict". Return *NULL* if an exception was
raised by the codec.
-For decoding file names and other environment strings, :cdata:`Py_FileSystemEncoding`
-should be used as the encoding, and ``"surrogateescape"`` should be used as the error
-handler. For encoding file names during argument parsing, the ``O&`` converter should
-be used, passsing PyUnicode_FSConverter as the conversion function:
-
-.. cfunction:: int PyUnicode_FSConverter(PyObject* obj, void* result)
-
- Convert *obj* into *result*, using the file system encoding, and the ``surrogateescape``
- error handler. *result* must be a ``PyObject*``, yielding a bytes or bytearray object
- which must be released if it is no longer used.
-
- .. versionadded:: 3.1
-.. % --- Methods & Slots ----------------------------------------------------
+Methods & Slots
+"""""""""""""""
.. _unicodemethodsandslots:
Modified: python/branches/py3k-jit/Doc/distutils/sourcedist.rst
==============================================================================
--- python/branches/py3k-jit/Doc/distutils/sourcedist.rst (original)
+++ python/branches/py3k-jit/Doc/distutils/sourcedist.rst Tue May 18 19:58:30 2010
@@ -137,20 +137,12 @@
:option:`--no-defaults` and :option:`--no-prune` to disable the standard
"include" and "exclude" sets.
-Second, you might want to force the manifest to be regenerated---for example, if
-you have added or removed files or directories that match an existing pattern in
-the manifest template, you should regenerate the manifest::
-
- python setup.py sdist --force-manifest
-
-Or, you might just want to (re)generate the manifest, but not create a source
-distribution::
+Second, you might just want to (re)generate the manifest, but not create a
+source distribution::
python setup.py sdist --manifest-only
-:option:`--manifest-only` implies :option:`--force-manifest`. :option:`-o` is a
-shortcut for :option:`--manifest-only`, and :option:`-f` for
-:option:`--force-manifest`.
+:option:`-o` is a sortcut for :option:`--manifest-only`.
.. _manifest_template:
Modified: python/branches/py3k-jit/Doc/howto/cporting.rst
==============================================================================
--- python/branches/py3k-jit/Doc/howto/cporting.rst (original)
+++ python/branches/py3k-jit/Doc/howto/cporting.rst Tue May 18 19:58:30 2010
@@ -120,7 +120,7 @@
Module initialization and state
===============================
-Python 3.0 has a revamped extension module initialization system. (See PEP
+Python 3.0 has a revamped extension module initialization system. (See
:pep:`3121`.) Instead of storing module state in globals, they should be stored
in an interpreter specific structure. Creating modules that act correctly in
both 2.x and 3.0 is tricky. The following simple example demonstrates how. ::
Modified: python/branches/py3k-jit/Doc/library/imp.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/imp.rst (original)
+++ python/branches/py3k-jit/Doc/library/imp.rst Tue May 18 19:58:30 2010
@@ -211,7 +211,7 @@
.. function:: cache_from_source(path, debug_override=None)
- Return the PEP 3147 path to the byte-compiled file associated with the
+ Return the :pep:`3147` path to the byte-compiled file associated with the
source *path*. For example, if *path* is ``/foo/bar/baz.py`` the return
value would be ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2.
The ``cpython-32`` string comes from the current magic tag (see
@@ -225,15 +225,15 @@
.. function:: source_from_cache(path)
- Given the *path* to a PEP 3147 file name, return the associated source code
+ Given the *path* to a :pep:`3147` file name, return the associated source code
file path. For example, if *path* is
``/foo/bar/__pycache__/baz.cpython-32.pyc`` the returned path would be
``/foo/bar/baz.py``. *path* need not exist, however if it does not conform
- to PEP 3147 format, a ``ValueError`` is raised.
+ to :pep:`3147` format, a ``ValueError`` is raised.
.. function:: get_tag()
- Return the PEP 3147 magic tag string matching this version of Python's
+ Return the :pep:`3147` magic tag string matching this version of Python's
magic number, as returned by :func:`get_magic`.
Modified: python/branches/py3k-jit/Doc/library/pkgutil.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/pkgutil.rst (original)
+++ python/branches/py3k-jit/Doc/library/pkgutil.rst Tue May 18 19:58:30 2010
@@ -41,7 +41,7 @@
Get a resource from a package.
- This is a wrapper for the PEP 302 loader :func:`get_data` API. The package
+ This is a wrapper for the :pep:`302` loader :func:`get_data` API. The package
argument should be the name of a package, in standard module format
(foo.bar). The resource argument should be in the form of a relative
filename, using ``/`` as the path separator. The parent directory name
@@ -56,5 +56,5 @@
d = os.path.dirname(sys.modules[package].__file__)
data = open(os.path.join(d, resource), 'rb').read()
- If the package cannot be located or loaded, or it uses a PEP 302 loader
+ If the package cannot be located or loaded, or it uses a :pep:`302` loader
which does not support :func:`get_data`, then None is returned.
Modified: python/branches/py3k-jit/Doc/library/runpy.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/runpy.rst (original)
+++ python/branches/py3k-jit/Doc/library/runpy.rst Tue May 18 19:58:30 2010
@@ -18,7 +18,7 @@
Execute the code of the specified module and return the resulting module
globals dictionary. The module's code is first located using the standard
- import mechanism (refer to PEP 302 for details) and then executed in a
+ import mechanism (refer to :pep:`302` for details) and then executed in a
fresh module namespace.
If the supplied module name refers to a package rather than a normal
@@ -48,7 +48,7 @@
``__cached__`` will be set to ``None``.
- ``__loader__`` is set to the PEP 302 module loader used to retrieve the
+ ``__loader__`` is set to the :pep:`302` module loader used to retrieve the
code for the module (This loader may be a wrapper around the standard
import mechanism).
@@ -106,7 +106,7 @@
loader does not make filename information available, this variable is set
to :const:`None`. For a simple script, this will be set to ``file_path``.
- ``__loader__`` is set to the PEP 302 module loader used to retrieve the
+ ``__loader__`` is set to the :pep:`302` module loader used to retrieve the
code for the module (This loader may be a wrapper around the standard
import mechanism). For a simple script, this will be set to :const:`None`.
Modified: python/branches/py3k-jit/Doc/library/ssl.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/ssl.rst (original)
+++ python/branches/py3k-jit/Doc/library/ssl.rst Tue May 18 19:58:30 2010
@@ -36,6 +36,11 @@
connection, and a method, :meth:`cipher`, to retrieve the cipher being used for
the secure connection.
+For more sophisticated applications, the :class:`ssl.SSLContext` class
+helps manage settings and certificates, which can then be inherited
+by SSL sockets created through the :meth:`SSLContext.wrap_socket` method.
+
+
Functions, Constants, and Exceptions
------------------------------------
@@ -64,19 +69,6 @@
connection. See the discussion of :ref:`ssl-certificates` for more
information on how the certificate is stored in the ``certfile``.
- Often the private key is stored in the same file as the certificate; in this
- case, only the ``certfile`` parameter need be passed. If the private key is
- stored in a separate file, both parameters must be used. If the private key
- is stored in the ``certfile``, it should come before the first certificate in
- the certificate chain::
-
- -----BEGIN RSA PRIVATE KEY-----
- ... (private key in base64 encoding) ...
- -----END RSA PRIVATE KEY-----
- -----BEGIN CERTIFICATE-----
- ... (certificate in base64 PEM encoding) ...
- -----END CERTIFICATE-----
-
The parameter ``server_side`` is a boolean which identifies whether
server-side or client-side behavior is desired from this socket.
@@ -208,29 +200,45 @@
.. data:: CERT_NONE
- Value to pass to the ``cert_reqs`` parameter to :func:`sslobject` when no
- certificates will be required or validated from the other side of the socket
- connection.
+ Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
+ parameter to :func:`wrap_socket`. In this mode (the default), no
+ certificates will be required from the other side of the socket connection.
+ If a certificate is received from the other end, no attempt to validate it
+ is made.
+
+ See the discussion of :ref:`ssl-security` below.
.. data:: CERT_OPTIONAL
- Value to pass to the ``cert_reqs`` parameter to :func:`sslobject` when no
- certificates will be required from the other side of the socket connection,
- but if they are provided, will be validated. Note that use of this setting
- requires a valid certificate validation file also be passed as a value of the
- ``ca_certs`` parameter.
+ Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
+ parameter to :func:`wrap_socket`. In this mode no certificates will be
+ required from the other side of the socket connection; but if they
+ are provided, validation will be attempted and an :class:`SSLError`
+ will be raised on failure.
+
+ Use of this setting requires a valid set of CA certificates to
+ be passed, either to :meth:`SSLContext.load_verify_locations` or as a
+ value of the ``ca_certs`` parameter to :func:`wrap_socket`.
.. data:: CERT_REQUIRED
- Value to pass to the ``cert_reqs`` parameter to :func:`sslobject` when
- certificates will be required from the other side of the socket connection.
- Note that use of this setting requires a valid certificate validation file
- also be passed as a value of the ``ca_certs`` parameter.
+ Possible value for :attr:`SSLContext.verify_mode`, or the ``cert_reqs``
+ parameter to :func:`wrap_socket`. In this mode, certificates are
+ required from the other side of the socket connection; an :class:`SSLError`
+ will be raised if no certificate is provided, or if its validation fails.
+
+ Use of this setting requires a valid set of CA certificates to
+ be passed, either to :meth:`SSLContext.load_verify_locations` or as a
+ value of the ``ca_certs`` parameter to :func:`wrap_socket`.
.. data:: PROTOCOL_SSLv2
Selects SSL version 2 as the channel encryption protocol.
+ .. warning::
+
+ SSL version 2 is insecure. Its use is highly discouraged.
+
.. data:: PROTOCOL_SSLv23
Selects SSL version 2 or 3 as the channel encryption protocol. This is a
@@ -280,8 +288,8 @@
.. versionadded:: 3.2
-SSLSocket Objects
------------------
+SSL Sockets
+-----------
.. method:: SSLSocket.read(nbytes=1024, buffer=None)
@@ -367,6 +375,83 @@
returned socket should always be used for further communication with the
other side of the connection, rather than the original socket.
+
+SSL Contexts
+------------
+
+.. class:: SSLContext(protocol)
+
+ An object holding various data longer-lived than single SSL connections,
+ such as SSL configuration options, certificate(s) and private key(s).
+ You must pass *protocol* which must be one of the ``PROTOCOL_*`` constants
+ defined in this module. :data:`PROTOCOL_SSLv23` is recommended for
+ maximum interoperability.
+
+:class:`SSLContext` objects have the following methods and attributes:
+
+.. method:: SSLContext.load_cert_chain(certfile, keyfile=None)
+
+ Load a private key and the corresponding certificate. The *certfile*
+ string must be the path to a single file in PEM format containing the
+ certificate as well as any number of CA certificates needed to establish
+ the certificate's authenticity. The *keyfile* string, if present, must
+ point to a file containing the private key in. Otherwise the private
+ key will be taken from *certfile* as well. See the discussion of
+ :ref:`ssl-certificates` for more information on how the certificate
+ is stored in the *certfile*.
+
+ An :class:`SSLError` is raised if the private key doesn't
+ match with the certificate.
+
+.. method:: SSLContext.load_verify_locations(cafile=None, capath=None)
+
+ Load a set of "certification authority" (CA) certificates used to validate
+ other peers' certificates when :data:`verify_mode` is other than
+ :data:`CERT_NONE`. At least one of *cafile* or *capath* must be specified.
+
+ The *cafile* string, if present, is the path to a file of concatenated
+ CA certificates in PEM format. See the discussion of
+ :ref:`ssl-certificates` for more information about how to arrange the
+ certificates in this file.
+
+ The *capath* string, if present, is
+ the path to a directory containing several CA certificates in PEM format,
+ following an `OpenSSL specific layout
+ <http://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html>`_.
+
+.. method:: SSLContext.set_ciphers(ciphers)
+
+ Set the available ciphers for sockets created with this context.
+ It should be a string in the `OpenSSL cipher list format
+ <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`_.
+ If no cipher can be selected (because compile-time options or other
+ configuration forbids use of all the specified ciphers), an
+ :class:`SSLError` will be raised.
+
+ .. note::
+ when connected, the :meth:`SSLSocket.cipher` method of SSL sockets will
+ give the currently selected cipher.
+
+.. method:: SSLContext.wrap_socket(sock, server_side=False, do_handshake_on_connect=True, suppress_ragged_eofs=True)
+
+ Wrap an existing Python socket *sock* and return an :class:`SSLSocket`
+ object. The SSL socket is tied to the context, its settings and
+ certificates. The parameters *server_side*, *do_handshake_on_connect*
+ and *suppress_ragged_eofs* have the same meaning as in the top-level
+ :func:`wrap_socket` function.
+
+.. attribute:: SSLContext.protocol
+
+ The protocol version chosen when constructing the context. This attribute
+ is read-only.
+
+.. attribute:: SSLContext.verify_mode
+
+ Whether to try to verify other peers' certificates and how to behave
+ if verification fails. This attribute must be one of
+ :data:`CERT_NONE`, :data:`CERT_OPTIONAL` or :data:`CERT_REQUIRED`.
+
+
.. index:: single: certificates
.. index:: single: X509 certificate
@@ -412,6 +497,9 @@
... (certificate in base64 PEM encoding) ...
-----END CERTIFICATE-----
+Certificate chains
+^^^^^^^^^^^^^^^^^^
+
The Python files which contain certificates can contain a sequence of
certificates, sometimes called a *certificate chain*. This chain should start
with the specific certificate for the principal who "is" the client or server,
@@ -435,6 +523,9 @@
... (the root certificate for the CA's issuer)...
-----END CERTIFICATE-----
+CA certificates
+^^^^^^^^^^^^^^^
+
If you are going to require validation of the other side of the connection's
certificate, you need to provide a "CA certs" file, filled with the certificate
chains for each issuer you are willing to trust. Again, this file just contains
@@ -454,6 +545,25 @@
certificate to a root certificate. See :rfc:`4158` for more discussion of the
way in which certification chains can be built.
+Combined key and certificate
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Often the private key is stored in the same file as the certificate; in this
+case, only the ``certfile`` parameter to :meth:`SSLContext.load_cert_chain`
+and :func:`wrap_socket` needs to be passed. If the private key is stored
+with the certificate, it should come before the first certificate in
+the certificate chain::
+
+ -----BEGIN RSA PRIVATE KEY-----
+ ... (private key in base64 encoding) ...
+ -----END RSA PRIVATE KEY-----
+ -----BEGIN CERTIFICATE-----
+ ... (certificate in base64 PEM encoding) ...
+ -----END CERTIFICATE-----
+
+Self-signed certificates
+^^^^^^^^^^^^^^^^^^^^^^^^
+
If you are going to create a server that provides SSL-encrypted connection
services, you will need to acquire a certificate for that service. There are
many ways of acquiring appropriate certificates, such as buying one from a
@@ -526,8 +636,7 @@
print(pprint.pformat(ssl_sock.getpeercert()))
# Set a simple HTTP request -- use http.client in actual code.
- ssl_sock.write("""GET / HTTP/1.0\r
- Host: www.verisign.com\r\n\r\n""")
+ ssl_sock.write(b"GET / HTTP/1.0\r\nHost: www.verisign.com\r\n\r\n")
# Read a chunk of data. Will not necessarily
# read all the data returned by the server.
@@ -557,39 +666,91 @@
which is a fairly poorly-formed ``subject`` field.
+This other example first creates an SSL context, instructs it to verify
+certificates sent by peers, and feeds it a set of recognized certificate
+authorities (CA)::
+
+ >>> context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ >>> context.verify_mode = ssl.CERT_OPTIONAL
+ >>> context.load_verify_locations("/etc/ssl/certs/ca-bundle.crt")
+
+(it is assumed your operating system places a bundle of all CA certificates
+in ``/etc/ssl/certs/ca-bundle.crt``; if not, you'll get an error and have
+to adjust the location)
+
+When you use the context to connect to a server, :const:`CERT_OPTIONAL`
+validates the server certificate: it ensures that the server certificate
+was signed with one of the CA certificates, and checks the signature for
+correctness::
+
+ >>> conn = context.wrap_socket(socket.socket(socket.AF_INET))
+ >>> conn.connect(("linuxfr.org", 443))
+
+You should then fetch the certificate and check its fields for conformity.
+Here, the ``commonName`` field in the ``subject`` matches the desired HTTPS
+host ``linuxfr.org``::
+
+ >>> pprint.pprint(conn.getpeercert())
+ {'notAfter': 'Jun 26 21:41:46 2011 GMT',
+ 'subject': ((('commonName', 'linuxfr.org'),),),
+ 'subjectAltName': (('DNS', 'linuxfr.org'), ('othername', '<unsupported>'))}
+
+Now that you are assured of its authenticity, you can proceed to talk with
+the server::
+
+ >>> conn.write(b"HEAD / HTTP/1.0\r\nHost: linuxfr.org\r\n\r\n")
+ 38
+ >>> pprint.pprint(conn.read().split(b"\r\n"))
+ [b'HTTP/1.1 302 Found',
+ b'Date: Sun, 16 May 2010 13:43:28 GMT',
+ b'Server: Apache/2.2',
+ b'Location: https://linuxfr.org/pub/',
+ b'Vary: Accept-Encoding',
+ b'Connection: close',
+ b'Content-Type: text/html; charset=iso-8859-1',
+ b'',
+ b'']
+
+
+See the discussion of :ref:`ssl-security` below.
+
+
Server-side operation
^^^^^^^^^^^^^^^^^^^^^
-For server operation, typically you'd need to have a server certificate, and
-private key, each in a file. You'd open a socket, bind it to a port, call
-:meth:`listen` on it, then start waiting for clients to connect::
+For server operation, typically you'll need to have a server certificate, and
+private key, each in a file. You'll first create a context holding the key
+and the certificate, so that clients can check your authenticity. Then
+you'll open a socket, bind it to a port, call :meth:`listen` on it, and start
+waiting for clients to connect::
import socket, ssl
+ context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ context.load_cert_chain(certfile="mycertfile", keyfile="mykeyfile")
+
bindsocket = socket.socket()
bindsocket.bind(('myaddr.mydomain.com', 10023))
bindsocket.listen(5)
-When one did, you'd call :meth:`accept` on the socket to get the new socket from
-the other end, and use :func:`wrap_socket` to create a server-side SSL context
-for it::
+When a client connects, you'll call :meth:`accept` on the socket to get the
+new socket from the other end, and use the context's :meth:`SSLContext.wrap_socket`
+method to create a server-side SSL socket for the connection::
while True:
newsocket, fromaddr = bindsocket.accept()
- connstream = ssl.wrap_socket(newsocket,
- server_side=True,
- certfile="mycertfile",
- keyfile="mykeyfile",
- ssl_version=ssl.PROTOCOL_TLSv1)
- deal_with_client(connstream)
+ connstream = context.wrap_socket(newsocket, server_side=True)
+ try:
+ deal_with_client(connstream)
+ finally:
+ connstream.close()
-Then you'd read data from the ``connstream`` and do something with it till you
+Then you'll read data from the ``connstream`` and do something with it till you
are finished with the client (or the client is finished with you)::
def deal_with_client(connstream):
-
data = connstream.read()
- # null data means the client is finished with us
+ # empty data means the client is finished with us
while data:
if not do_something(connstream, data):
# we'll assume do_something returns False
@@ -597,9 +758,41 @@
break
data = connstream.read()
# finished with client
- connstream.close()
-And go back to listening for new client connections.
+And go back to listening for new client connections (of course, a real server
+would probably handle each client connection in a separate thread, or put
+the sockets in non-blocking mode and use an event loop).
+
+
+.. _ssl-security:
+
+Security considerations
+-----------------------
+
+Verifying certificates
+^^^^^^^^^^^^^^^^^^^^^^
+
+:const:`CERT_NONE` is the default. Since it does not authenticate the other
+peer, it can be insecure, especially in client mode where most of time you
+would like to ensure the authenticity of the server you're talking to.
+Therefore, when in client mode, it is highly recommended to use
+:const:`CERT_REQUIRED`. However, it is in itself not sufficient; you also
+have to check that the server certificate (obtained with
+:meth:`SSLSocket.getpeercert`) matches the desired service. The exact way
+of doing so depends on the higher-level protocol used; for example, with
+HTTPS, you'll check that the host name in the URL matches either the
+``commonName`` field in the ``subjectName``, or one of the ``DNS`` fields
+in the ``subjectAltName``.
+
+In server mode, if you want to authenticate your clients using the SSL layer
+(rather than using a higher-level authentication mechanism), you'll also have
+to specify :const:`CERT_REQUIRED` and similarly check the client certificate.
+
+ .. note::
+
+ In client mode, :const:`CERT_OPTIONAL` and :const:`CERT_REQUIRED` are
+ equivalent unless anonymous ciphers are enabled (they are disabled
+ by default).
.. seealso::
Modified: python/branches/py3k-jit/Doc/library/sys.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/sys.rst (original)
+++ python/branches/py3k-jit/Doc/library/sys.rst Tue May 18 19:58:30 2010
@@ -298,15 +298,13 @@
.. function:: getfilesystemencoding()
- Return the name of the encoding used to convert Unicode filenames into system
- file names, or ``None`` if the system default encoding is used. The result value
- depends on the operating system:
+ Return the name of the encoding used to convert Unicode filenames into
+ system file names. The result value depends on the operating system:
* On Mac OS X, the encoding is ``'utf-8'``.
* On Unix, the encoding is the user's preference according to the result of
- nl_langinfo(CODESET), or ``None`` if the ``nl_langinfo(CODESET)``
- failed.
+ nl_langinfo(CODESET), or ``'utf-8'`` if ``nl_langinfo(CODESET)`` failed.
* On Windows NT+, file names are Unicode natively, so no conversion is
performed. :func:`getfilesystemencoding` still returns ``'mbcs'``, as
@@ -316,6 +314,10 @@
* On Windows 9x, the encoding is ``'mbcs'``.
+ .. versionchanged:: 3.2
+ On Unix, use ``'utf-8'`` instead of ``None`` if ``nl_langinfo(CODESET)``
+ failed. :func:`getfilesystemencoding` result cannot be ``None``.
+
.. function:: getrefcount(object)
Modified: python/branches/py3k-jit/Doc/library/tarfile.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/tarfile.rst (original)
+++ python/branches/py3k-jit/Doc/library/tarfile.rst Tue May 18 19:58:30 2010
@@ -711,6 +711,8 @@
The default scheme is ``'surrogateescape'`` which Python also uses for its
file system calls, see :ref:`os-filenames`.
-In case of writing :const:`PAX_FORMAT` archives, *encoding* is ignored because
-non-ASCII metadata is stored using *UTF-8*. Storing surrogate characters is not
-possible and will raise a :exc:`UnicodeEncodeError`.
+In case of :const:`PAX_FORMAT` archives, *encoding* is generally not needed
+because all the metadata is stored using *UTF-8*. *encoding* is only used in
+the rare cases when binary pax headers are decoded or when strings with
+surrogate characters are stored.
+
Modified: python/branches/py3k-jit/Doc/library/wsgiref.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/wsgiref.rst (original)
+++ python/branches/py3k-jit/Doc/library/wsgiref.rst Tue May 18 19:58:30 2010
@@ -710,7 +710,7 @@
# use a function (note that you're not limited to a function, you can
# use a class for example). The first argument passed to the function
# is a dictionary containing CGI-style envrironment variables and the
- # second variable is the callable object (see PEP333)
+ # second variable is the callable object (see :pep:`333`)
def hello_world_app(environ, start_response):
status = b'200 OK' # HTTP Status
headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers
Modified: python/branches/py3k-jit/Doc/library/zipimport.rst
==============================================================================
--- python/branches/py3k-jit/Doc/library/zipimport.rst (original)
+++ python/branches/py3k-jit/Doc/library/zipimport.rst Tue May 18 19:58:30 2010
@@ -34,12 +34,12 @@
Documentation on the ZIP file format by Phil Katz, the creator of the format and
algorithms used.
- :pep:`0273` - Import Modules from Zip Archives
+ :pep:`273` - Import Modules from Zip Archives
Written by James C. Ahlstrom, who also provided an implementation. Python 2.3
follows the specification in PEP 273, but uses an implementation written by Just
van Rossum that uses the import hooks described in PEP 302.
- :pep:`0302` - New Import Hooks
+ :pep:`302` - New Import Hooks
The PEP to add the import hooks that help this module work.
Modified: python/branches/py3k-jit/Include/unicodeobject.h
==============================================================================
--- python/branches/py3k-jit/Include/unicodeobject.h (original)
+++ python/branches/py3k-jit/Include/unicodeobject.h Tue May 18 19:58:30 2010
@@ -1240,30 +1240,44 @@
/* --- File system encoding ---------------------------------------------- */
/* ParseTuple converter which converts a Unicode object into the file
- system encoding as a bytes object, using the PEP 383 error handler; bytes
- objects are output as-is. */
+ system encoding as a bytes object, using the "surrogateescape" error
+ handler; bytes objects are output as-is. */
PyAPI_FUNC(int) PyUnicode_FSConverter(PyObject*, void*);
-/* Decode a null-terminated string using Py_FileSystemDefaultEncoding.
+/* Decode a null-terminated string using Py_FileSystemDefaultEncoding
+ and the "surrogateescape" error handler.
- If the encoding is supported by one of the built-in codecs (i.e., UTF-8,
- UTF-16, UTF-32, Latin-1 or MBCS), otherwise fallback to UTF-8 and replace
- invalid characters with '?'.
+ If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8.
- The function is intended to be used for paths and file names only
- during bootstrapping process where the codecs are not set up.
+ Use PyUnicode_DecodeFSDefaultAndSize() if the string length is known.
*/
PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefault(
const char *s /* encoded string */
);
+/* Decode a string using Py_FileSystemDefaultEncoding
+ and the "surrogateescape" error handler.
+
+ If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8.
+*/
+
PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize(
const char *s, /* encoded string */
Py_ssize_t size /* size */
);
+/* Encode a Unicode object to Py_FileSystemDefaultEncoding with the
+ "surrogateescape" error handler, and return bytes.
+
+ If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8.
+*/
+
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeFSDefault(
+ PyObject *unicode
+ );
+
/* --- Methods & Slots ----------------------------------------------------
These are capable of handling Unicode objects and strings on input
Modified: python/branches/py3k-jit/Lib/distutils/command/sdist.py
==============================================================================
--- python/branches/py3k-jit/Lib/distutils/command/sdist.py (original)
+++ python/branches/py3k-jit/Lib/distutils/command/sdist.py Tue May 18 19:58:30 2010
@@ -63,7 +63,8 @@
"just regenerate the manifest and then stop "
"(implies --force-manifest)"),
('force-manifest', 'f',
- "forcibly regenerate the manifest and carry on as usual"),
+ "forcibly regenerate the manifest and carry on as usual. "
+ "Deprecated: now the manifest is always regenerated."),
('formats=', None,
"formats for source distribution (comma-separated list)"),
('keep-temp', 'k',
@@ -179,66 +180,34 @@
distribution, and put it in 'self.filelist'. This might involve
reading the manifest template (and writing the manifest), or just
reading the manifest, or just using the default file set -- it all
- depends on the user's options and the state of the filesystem.
+ depends on the user's options.
"""
- # If we have a manifest template, see if it's newer than the
- # manifest; if so, we'll regenerate the manifest.
+ # new behavior:
+ # the file list is recalculated everytime because
+ # even if MANIFEST.in or setup.py are not changed
+ # the user might have added some files in the tree that
+ # need to be included.
+ #
+ # This makes --force the default and only behavior.
template_exists = os.path.isfile(self.template)
+ if not template_exists:
+ self.warn(("manifest template '%s' does not exist " +
+ "(using default file list)") %
+ self.template)
+ self.filelist.findall()
+
+ if self.use_defaults:
+ self.add_defaults()
+
if template_exists:
- template_newer = dep_util.newer(self.template, self.manifest)
+ self.read_template()
- # The contents of the manifest file almost certainly depend on the
- # setup script as well as the manifest template -- so if the setup
- # script is newer than the manifest, we'll regenerate the manifest
- # from the template. (Well, not quite: if we already have a
- # manifest, but there's no template -- which will happen if the
- # developer elects to generate a manifest some other way -- then we
- # can't regenerate the manifest, so we don't.)
- self.debug_print("checking if %s newer than %s" %
- (self.distribution.script_name, self.manifest))
- setup_newer = dep_util.newer(self.distribution.script_name,
- self.manifest)
-
- # cases:
- # 1) no manifest, template exists: generate manifest
- # (covered by 2a: no manifest == template newer)
- # 2) manifest & template exist:
- # 2a) template or setup script newer than manifest:
- # regenerate manifest
- # 2b) manifest newer than both:
- # do nothing (unless --force or --manifest-only)
- # 3) manifest exists, no template:
- # do nothing (unless --force or --manifest-only)
- # 4) no manifest, no template: generate w/ warning ("defaults only")
-
- manifest_outofdate = (template_exists and
- (template_newer or setup_newer))
- force_regen = self.force_manifest or self.manifest_only
- manifest_exists = os.path.isfile(self.manifest)
- neither_exists = (not template_exists and not manifest_exists)
-
- # Regenerate the manifest if necessary (or if explicitly told to)
- if manifest_outofdate or neither_exists or force_regen:
- if not template_exists:
- self.warn("manifest template '%s' does not exist "
- "(using default file list)"
- % self.template)
- self.filelist.findall()
-
- if self.use_defaults:
- self.add_defaults()
- if template_exists:
- self.read_template()
- if self.prune:
- self.prune_file_list()
-
- self.filelist.sort()
- self.filelist.remove_duplicates()
- self.write_manifest()
+ if self.prune:
+ self.prune_file_list()
- # Don't regenerate the manifest, just read it in.
- else:
- self.read_manifest()
+ self.filelist.sort()
+ self.filelist.remove_duplicates()
+ self.write_manifest()
def add_defaults(self):
"""Add all the default files to self.filelist:
Modified: python/branches/py3k-jit/Lib/distutils/tests/test_sdist.py
==============================================================================
--- python/branches/py3k-jit/Lib/distutils/tests/test_sdist.py (original)
+++ python/branches/py3k-jit/Lib/distutils/tests/test_sdist.py Tue May 18 19:58:30 2010
@@ -346,6 +346,47 @@
finally:
archive.close()
+ def test_get_file_list(self):
+ # make sure MANIFEST is recalculated
+ dist, cmd = self.get_cmd()
+
+ # filling data_files by pointing files in package_data
+ dist.package_data = {'somecode': ['*.txt']}
+ self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
+ cmd.ensure_finalized()
+ cmd.run()
+
+ f = open(cmd.manifest)
+ try:
+ manifest = [line.strip() for line in f.read().split('\n')
+ if line.strip() != '']
+ finally:
+ f.close()
+
+ self.assertEquals(len(manifest), 4)
+
+ # adding a file
+ self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
+
+ # make sure build_py is reinitinialized, like a fresh run
+ build_py = dist.get_command_obj('build_py')
+ build_py.finalized = False
+ build_py.ensure_finalized()
+
+ cmd.run()
+
+ f = open(cmd.manifest)
+ try:
+ manifest2 = [line.strip() for line in f.read().split('\n')
+ if line.strip() != '']
+ finally:
+ f.close()
+
+ # do we have the new file in MANIFEST ?
+ self.assertEquals(len(manifest2), 5)
+ self.assertIn('doc2.txt', manifest2[-1])
+
+
def test_suite():
return unittest.makeSuite(SDistTestCase)
Modified: python/branches/py3k-jit/Lib/ssl.py
==============================================================================
--- python/branches/py3k-jit/Lib/ssl.py (original)
+++ python/branches/py3k-jit/Lib/ssl.py Tue May 18 19:58:30 2010
@@ -59,7 +59,7 @@
import _ssl # if we can't import it, let the error propagate
from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
-from _ssl import SSLError
+from _ssl import _SSLContext, SSLError
from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
from _ssl import (PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23,
PROTOCOL_TLSv1)
@@ -84,8 +84,29 @@
import traceback
import errno
-class SSLSocket(socket):
+class SSLContext(_SSLContext):
+ """An SSLContext holds various SSL-related configuration options and
+ data, such as certificates and possibly a private key."""
+
+ __slots__ = ('protocol',)
+
+ def __new__(cls, protocol, *args, **kwargs):
+ return _SSLContext.__new__(cls, protocol)
+
+ def __init__(self, protocol):
+ self.protocol = protocol
+
+ def wrap_socket(self, sock, server_side=False,
+ do_handshake_on_connect=True,
+ suppress_ragged_eofs=True):
+ return SSLSocket(sock=sock, server_side=server_side,
+ do_handshake_on_connect=do_handshake_on_connect,
+ suppress_ragged_eofs=suppress_ragged_eofs,
+ _context=self)
+
+
+class SSLSocket(socket):
"""This class implements a subtype of socket.socket that wraps
the underlying OS socket in an SSL context when necessary, and
provides read and write methods over that channel."""
@@ -95,8 +116,31 @@
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None,
- suppress_ragged_eofs=True, ciphers=None):
+ suppress_ragged_eofs=True, ciphers=None,
+ _context=None):
+
+ if _context:
+ self.context = _context
+ else:
+ if certfile and not keyfile:
+ keyfile = certfile
+ self.context = SSLContext(ssl_version)
+ self.context.verify_mode = cert_reqs
+ if ca_certs:
+ self.context.load_verify_locations(ca_certs)
+ if certfile:
+ self.context.load_cert_chain(certfile, keyfile)
+ if ciphers:
+ self.context.set_ciphers(ciphers)
+ self.keyfile = keyfile
+ self.certfile = certfile
+ self.cert_reqs = cert_reqs
+ self.ssl_version = ssl_version
+ self.ca_certs = ca_certs
+ self.ciphers = ciphers
+ self.do_handshake_on_connect = do_handshake_on_connect
+ self.suppress_ragged_eofs = suppress_ragged_eofs
connected = False
if sock is not None:
socket.__init__(self,
@@ -119,18 +163,12 @@
else:
socket.__init__(self, family=family, type=type, proto=proto)
- if certfile and not keyfile:
- keyfile = certfile
-
self._closed = False
self._sslobj = None
if connected:
# create the SSL object
try:
- self._sslobj = _ssl.sslwrap(self, server_side,
- keyfile, certfile,
- cert_reqs, ssl_version, ca_certs,
- ciphers)
+ self._sslobj = self.context._wrap_socket(self, server_side)
if do_handshake_on_connect:
timeout = self.gettimeout()
if timeout == 0.0:
@@ -142,15 +180,6 @@
self.close()
raise x
- self.keyfile = keyfile
- self.certfile = certfile
- self.cert_reqs = cert_reqs
- self.ssl_version = ssl_version
- self.ca_certs = ca_certs
- self.ciphers = ciphers
- self.do_handshake_on_connect = do_handshake_on_connect
- self.suppress_ragged_eofs = suppress_ragged_eofs
-
def dup(self):
raise NotImplemented("Can't dup() %s instances" %
self.__class__.__name__)
@@ -331,9 +360,7 @@
if self._sslobj:
raise ValueError("attempt to connect already-connected SSLSocket!")
socket.connect(self, addr)
- self._sslobj = _ssl.sslwrap(self, False, self.keyfile, self.certfile,
- self.cert_reqs, self.ssl_version,
- self.ca_certs, self.ciphers)
+ self._sslobj = self.context._wrap_socket(self, False)
try:
if self.do_handshake_on_connect:
self.do_handshake()
Modified: python/branches/py3k-jit/Lib/subprocess.py
==============================================================================
--- python/branches/py3k-jit/Lib/subprocess.py (original)
+++ python/branches/py3k-jit/Lib/subprocess.py Tue May 18 19:58:30 2010
@@ -356,7 +356,6 @@
if mswindows:
- from _subprocess import CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP
import threading
import msvcrt
import _subprocess
@@ -394,6 +393,7 @@
"getoutput", "check_output", "CalledProcessError"]
if mswindows:
+ from _subprocess import CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP"])
try:
MAXFD = os.sysconf("SC_OPEN_MAX")
@@ -698,12 +698,12 @@
return data.decode(encoding)
- def __del__(self, sys=sys):
+ def __del__(self, _maxsize=sys.maxsize, _active=_active):
if not self._child_created:
# We didn't get to successfully create a child process.
return
# In case the child hasn't been waited on, check if it's done.
- self._internal_poll(_deadstate=sys.maxsize)
+ self._internal_poll(_deadstate=_maxsize)
if self.returncode is None and _active is not None:
# Child is still running, keep us alive until we can wait on it.
_active.append(self)
@@ -907,13 +907,20 @@
errwrite.Close()
- def _internal_poll(self, _deadstate=None):
+ def _internal_poll(self, _deadstate=None,
+ _WaitForSingleObject=_subprocess.WaitForSingleObject,
+ _WAIT_OBJECT_0=_subprocess.WAIT_OBJECT_0,
+ _GetExitCodeProcess=_subprocess.GetExitCodeProcess):
"""Check if child process has terminated. Returns returncode
- attribute."""
+ attribute.
+
+ This method is called by __del__, so it can only refer to objects
+ in its local scope.
+
+ """
if self.returncode is None:
- if(_subprocess.WaitForSingleObject(self._handle, 0) ==
- _subprocess.WAIT_OBJECT_0):
- self.returncode = _subprocess.GetExitCodeProcess(self._handle)
+ if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
+ self.returncode = _GetExitCodeProcess(self._handle)
return self.returncode
@@ -1252,25 +1259,35 @@
raise child_exception_type(err_msg)
- def _handle_exitstatus(self, sts):
- if os.WIFSIGNALED(sts):
- self.returncode = -os.WTERMSIG(sts)
- elif os.WIFEXITED(sts):
- self.returncode = os.WEXITSTATUS(sts)
+ def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
+ _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
+ _WEXITSTATUS=os.WEXITSTATUS):
+ # This method is called (indirectly) by __del__, so it cannot
+ # refer to anything outside of its local scope."""
+ if _WIFSIGNALED(sts):
+ self.returncode = -_WTERMSIG(sts)
+ elif _WIFEXITED(sts):
+ self.returncode = _WEXITSTATUS(sts)
else:
# Should never happen
raise RuntimeError("Unknown child exit status!")
- def _internal_poll(self, _deadstate=None):
+ def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
+ _WNOHANG=os.WNOHANG, _os_error=os.error):
"""Check if child process has terminated. Returns returncode
- attribute."""
+ attribute.
+
+ This method is called by __del__, so it cannot reference anything
+ outside of the local scope (nor can any methods it calls).
+
+ """
if self.returncode is None:
try:
- pid, sts = os.waitpid(self.pid, os.WNOHANG)
+ pid, sts = _waitpid(self.pid, _WNOHANG)
if pid == self.pid:
self._handle_exitstatus(sts)
- except os.error:
+ except _os_error:
if _deadstate is not None:
self.returncode = _deadstate
return self.returncode
Modified: python/branches/py3k-jit/Lib/tarfile.py
==============================================================================
--- python/branches/py3k-jit/Lib/tarfile.py (original)
+++ python/branches/py3k-jit/Lib/tarfile.py Tue May 18 19:58:30 2010
@@ -118,6 +118,9 @@
PAX_FIELDS = ("path", "linkpath", "size", "mtime",
"uid", "gid", "uname", "gname")
+# Fields from a pax header that are affected by hdrcharset.
+PAX_NAME_FIELDS = {"path", "linkpath", "uname", "gname"}
+
# Fields in a pax header that are numbers, all other fields
# are treated as strings.
PAX_NUMBER_FIELDS = {
@@ -988,7 +991,7 @@
elif format == GNU_FORMAT:
return self.create_gnu_header(info, encoding, errors)
elif format == PAX_FORMAT:
- return self.create_pax_header(info)
+ return self.create_pax_header(info, encoding)
else:
raise ValueError("invalid format")
@@ -1019,7 +1022,7 @@
return buf + self._create_header(info, GNU_FORMAT, encoding, errors)
- def create_pax_header(self, info):
+ def create_pax_header(self, info, encoding):
"""Return the object as a ustar header block. If it cannot be
represented this way, prepend a pax extended header sequence
with supplement information.
@@ -1062,7 +1065,7 @@
# Create a pax extended header if necessary.
if pax_headers:
- buf = self._create_pax_generic_header(pax_headers, XHDTYPE)
+ buf = self._create_pax_generic_header(pax_headers, XHDTYPE, encoding)
else:
buf = b""
@@ -1072,7 +1075,7 @@
def create_pax_global_header(cls, pax_headers):
"""Return the object as a pax global header block sequence.
"""
- return cls._create_pax_generic_header(pax_headers, XGLTYPE)
+ return cls._create_pax_generic_header(pax_headers, XGLTYPE, "utf8")
def _posix_split_name(self, name):
"""Split a name longer than 100 chars into a prefix
@@ -1145,15 +1148,35 @@
cls._create_payload(name)
@classmethod
- def _create_pax_generic_header(cls, pax_headers, type):
- """Return a POSIX.1-2001 extended or global header sequence
+ def _create_pax_generic_header(cls, pax_headers, type, encoding):
+ """Return a POSIX.1-2008 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be strings.
"""
+ # Check if one of the fields contains surrogate characters and thereby
+ # forces hdrcharset=BINARY, see _proc_pax() for more information.
+ binary = False
+ for keyword, value in pax_headers.items():
+ try:
+ value.encode("utf8", "strict")
+ except UnicodeEncodeError:
+ binary = True
+ break
+
records = b""
+ if binary:
+ # Put the hdrcharset field at the beginning of the header.
+ records += b"21 hdrcharset=BINARY\n"
+
for keyword, value in pax_headers.items():
keyword = keyword.encode("utf8")
- value = value.encode("utf8")
+ if binary:
+ # Try to restore the original byte representation of `value'.
+ # Needless to say, that the encoding must match the string.
+ value = value.encode(encoding, "surrogateescape")
+ else:
+ value = value.encode("utf8")
+
l = len(keyword) + len(value) + 3 # ' ' + '=' + '\n'
n = p = 0
while True:
@@ -1354,7 +1377,7 @@
def _proc_pax(self, tarfile):
"""Process an extended or global header as described in
- POSIX.1-2001.
+ POSIX.1-2008.
"""
# Read the header information.
buf = tarfile.fileobj.read(self._block(self.size))
@@ -1367,6 +1390,24 @@
else:
pax_headers = tarfile.pax_headers.copy()
+ # Check if the pax header contains a hdrcharset field. This tells us
+ # the encoding of the path, linkpath, uname and gname fields. Normally,
+ # these fields are UTF-8 encoded but since POSIX.1-2008 tar
+ # implementations are allowed to store them as raw binary strings if
+ # the translation to UTF-8 fails.
+ match = re.search(br"\d+ hdrcharset=([^\n]+)\n", buf)
+ if match is not None:
+ pax_headers["hdrcharset"] = match.group(1).decode("utf8")
+
+ # For the time being, we don't care about anything other than "BINARY".
+ # The only other value that is currently allowed by the standard is
+ # "ISO-IR 10646 2000 UTF-8" in other words UTF-8.
+ hdrcharset = pax_headers.get("hdrcharset")
+ if hdrcharset == "BINARY":
+ encoding = tarfile.encoding
+ else:
+ encoding = "utf8"
+
# Parse pax header information. A record looks like that:
# "%d %s=%s\n" % (length, keyword, value). length is the size
# of the complete record including the length field itself and
@@ -1382,8 +1423,21 @@
length = int(length)
value = buf[match.end(2) + 1:match.start(1) + length - 1]
- keyword = keyword.decode("utf8")
- value = value.decode("utf8")
+ # Normally, we could just use "utf8" as the encoding and "strict"
+ # as the error handler, but we better not take the risk. For
+ # example, GNU tar <= 1.23 is known to store filenames it cannot
+ # translate to UTF-8 as raw strings (unfortunately without a
+ # hdrcharset=BINARY header).
+ # We first try the strict standard encoding, and if that fails we
+ # fall back on the user's encoding and error handler.
+ keyword = self._decode_pax_field(keyword, "utf8", "utf8",
+ tarfile.errors)
+ if keyword in PAX_NAME_FIELDS:
+ value = self._decode_pax_field(value, encoding, tarfile.encoding,
+ tarfile.errors)
+ else:
+ value = self._decode_pax_field(value, "utf8", "utf8",
+ tarfile.errors)
pax_headers[keyword] = value
pos += length
@@ -1431,6 +1485,14 @@
self.pax_headers = pax_headers.copy()
+ def _decode_pax_field(self, value, encoding, fallback_encoding, fallback_errors):
+ """Decode a single field from a pax record.
+ """
+ try:
+ return value.decode(encoding, "strict")
+ except UnicodeDecodeError:
+ return value.decode(fallback_encoding, fallback_errors)
+
def _block(self, count):
"""Round up a byte count by BLOCKSIZE and return it,
e.g. _block(834) => 1024.
Modified: python/branches/py3k-jit/Lib/test/list_tests.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/list_tests.py (original)
+++ python/branches/py3k-jit/Lib/test/list_tests.py Tue May 18 19:58:30 2010
@@ -66,13 +66,11 @@
d.append(d)
d.append(400)
try:
- fo = open(support.TESTFN, "w")
- fo.write(str(d))
- fo.close()
- fo = open(support.TESTFN, "r")
- self.assertEqual(fo.read(), repr(d))
+ with open(support.TESTFN, "w") as fo:
+ fo.write(str(d))
+ with open(support.TESTFN, "r") as fo:
+ self.assertEqual(fo.read(), repr(d))
finally:
- fo.close()
os.remove(support.TESTFN)
def test_set_subscript(self):
Modified: python/branches/py3k-jit/Lib/test/test_capi.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_capi.py (original)
+++ python/branches/py3k-jit/Lib/test/test_capi.py Tue May 18 19:58:30 2010
@@ -45,9 +45,9 @@
(out, err) = p.communicate()
self.assertEqual(out, b'')
# This used to cause an infinite loop.
- self.assertEqual(err,
+ self.assertEqual(err.rstrip(),
b'Fatal Python error:'
- b' PyThreadState_Get: no current thread\n')
+ b' PyThreadState_Get: no current thread')
@unittest.skipUnless(threading, 'Threading required for this test.')
Modified: python/branches/py3k-jit/Lib/test/test_import.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_import.py (original)
+++ python/branches/py3k-jit/Lib/test/test_import.py Tue May 18 19:58:30 2010
@@ -142,6 +142,7 @@
self.assertIs(orig_path, new_os.path)
self.assertIsNot(orig_getenv, new_os.getenv)
+ @unittest.expectedFailure # Issue 8727 is tracking the fix.
def test_module_with_large_stack(self, module='longlist'):
# Regression test for http://bugs.python.org/issue561858.
filename = module + '.py'
@@ -153,23 +154,23 @@
f.write('"",\n')
f.write(']')
- # Compile & remove .py file, we only need .pyc (or .pyo), but that
- # must be relocated to the PEP 3147 bytecode-only location.
- with open(filename, 'r') as f:
- py_compile.compile(filename)
+ # Compile & remove .py file; we only need .pyc (or .pyo).
+ # Bytecode must be relocated from the PEP 3147 bytecode-only location.
+ py_compile.compile(filename)
unlink(filename)
make_legacy_pyc(filename)
# Need to be able to load from current dir.
sys.path.append('')
- # This used to crash.
- exec('import ' + module)
-
- # Cleanup.
- del sys.path[-1]
- unlink(filename + 'c')
- unlink(filename + 'o')
+ try:
+ # This used to crash.
+ exec('import ' + module)
+ finally:
+ # Cleanup.
+ del sys.path[-1]
+ unlink(filename + 'c')
+ unlink(filename + 'o')
def test_failing_import_sticks(self):
source = TESTFN + ".py"
Modified: python/branches/py3k-jit/Lib/test/test_math.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_math.py (original)
+++ python/branches/py3k-jit/Lib/test/test_math.py Tue May 18 19:58:30 2010
@@ -60,6 +60,56 @@
return "error = {} ulps; permitted error = {} ulps".format(ulps_error,
ulps)
+# Here's a pure Python version of the math.factorial algorithm, for
+# documentation and comparison purposes.
+#
+# Formula:
+#
+# factorial(n) = factorial_odd_part(n) << (n - count_set_bits(n))
+#
+# where
+#
+# factorial_odd_part(n) = product_{i >= 0} product_{0 < j <= n >> i; j odd} j
+#
+# The outer product above is an infinite product, but once i >= n.bit_length,
+# (n >> i) < 1 and the corresponding term of the product is empty. So only the
+# finitely many terms for 0 <= i < n.bit_length() contribute anything.
+#
+# We iterate downwards from i == n.bit_length() - 1 to i == 0. The inner
+# product in the formula above starts at 1 for i == n.bit_length(); for each i
+# < n.bit_length() we get the inner product for i from that for i + 1 by
+# multiplying by all j in {n >> i+1 < j <= n >> i; j odd}. In Python terms,
+# this set is range((n >> i+1) + 1 | 1, (n >> i) + 1 | 1, 2).
+
+def count_set_bits(n):
+ """Number of '1' bits in binary expansion of a nonnnegative integer."""
+ return 1 + count_set_bits(n & n - 1) if n else 0
+
+def partial_product(start, stop):
+ """Product of integers in range(start, stop, 2), computed recursively.
+ start and stop should both be odd, with start <= stop.
+
+ """
+ numfactors = (stop - start) >> 1
+ if not numfactors:
+ return 1
+ elif numfactors == 1:
+ return start
+ else:
+ mid = (start + numfactors) | 1
+ return partial_product(start, mid) * partial_product(mid, stop)
+
+def py_factorial(n):
+ """Factorial of nonnegative integer n, via "Binary Split Factorial Formula"
+ described at http://www.luschny.de/math/factorial/binarysplitfact.html
+
+ """
+ inner = outer = 1
+ for i in reversed(range(n.bit_length())):
+ inner *= partial_product((n >> i + 1) + 1 | 1, (n >> i) + 1 | 1)
+ outer *= inner
+ return outer << (n - count_set_bits(n))
+
def acc_check(expected, got, rel_err=2e-15, abs_err = 5e-323):
"""Determine whether non-NaN floats a and b are equal to within a
(small) rounding error. The default values for rel_err and
@@ -365,18 +415,19 @@
self.ftest('fabs(1)', math.fabs(1), 1)
def testFactorial(self):
- def fact(n):
- result = 1
- for i in range(1, int(n)+1):
- result *= i
- return result
- values = list(range(10)) + [50, 100, 500]
- random.shuffle(values)
- for x in values:
- for cast in (int, float):
- self.assertEqual(math.factorial(cast(x)), fact(x), (x, fact(x), math.factorial(x)))
+ self.assertEqual(math.factorial(0), 1)
+ self.assertEqual(math.factorial(0.0), 1)
+ total = 1
+ for i in range(1, 1000):
+ total *= i
+ self.assertEqual(math.factorial(i), total)
+ self.assertEqual(math.factorial(float(i)), total)
+ self.assertEqual(math.factorial(i), py_factorial(i))
self.assertRaises(ValueError, math.factorial, -1)
+ self.assertRaises(ValueError, math.factorial, -1.0)
self.assertRaises(ValueError, math.factorial, math.pi)
+ self.assertRaises(OverflowError, math.factorial, sys.maxsize+1)
+ self.assertRaises(OverflowError, math.factorial, 10e100)
def testFloor(self):
self.assertRaises(TypeError, math.floor)
Modified: python/branches/py3k-jit/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_os.py (original)
+++ python/branches/py3k-jit/Lib/test/test_os.py Tue May 18 19:58:30 2010
@@ -12,6 +12,7 @@
import time
import shutil
from test import support
+import contextlib
# Detect whether we're on a Linux system that uses the (now outdated
# and unmaintained) linuxthreads threading library. There's an issue
@@ -623,6 +624,39 @@
except NotImplementedError:
pass
+ at contextlib.contextmanager
+def _execvpe_mockup(defpath=None):
+ """
+ Stubs out execv and execve functions when used as context manager.
+ Records exec calls. The mock execv and execve functions always raise an
+ exception as they would normally never return.
+ """
+ # A list of tuples containing (function name, first arg, args)
+ # of calls to execv or execve that have been made.
+ calls = []
+
+ def mock_execv(name, *args):
+ calls.append(('execv', name, args))
+ raise RuntimeError("execv called")
+
+ def mock_execve(name, *args):
+ calls.append(('execve', name, args))
+ raise OSError(errno.ENOTDIR, "execve called")
+
+ try:
+ orig_execv = os.execv
+ orig_execve = os.execve
+ orig_defpath = os.defpath
+ os.execv = mock_execv
+ os.execve = mock_execve
+ if defpath is not None:
+ os.defpath = defpath
+ yield calls
+ finally:
+ os.execv = orig_execv
+ os.execve = orig_execve
+ os.defpath = orig_defpath
+
class ExecTests(unittest.TestCase):
@unittest.skipIf(USING_LINUXTHREADS,
"avoid triggering a linuxthreads bug: see issue #4970")
@@ -633,57 +667,25 @@
def test_execvpe_with_bad_arglist(self):
self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
- class _stub_out_for_execvpe_test(object):
- """
- Stubs out execv, execve and get_exec_path functions when
- used as context manager. Records exec calls. The mock execv
- and execve functions always raise an exception as they would
- normally never return.
- """
- def __init__(self):
- # A list of tuples containing (function name, first arg, args)
- # of calls to execv or execve that have been made.
- self.calls = []
- def _mock_execv(self, name, *args):
- self.calls.append(('execv', name, args))
- raise RuntimeError("execv called")
-
- def _mock_execve(self, name, *args):
- self.calls.append(('execve', name, args))
- raise OSError(errno.ENOTDIR, "execve called")
-
- def _mock_get_exec_path(self, env=None):
- return [os.sep+'p', os.sep+'pp']
-
- def __enter__(self):
- self.orig_execv = os.execv
- self.orig_execve = os.execve
- self.orig_get_exec_path = os.get_exec_path
- os.execv = self._mock_execv
- os.execve = self._mock_execve
- os.get_exec_path = self._mock_get_exec_path
-
- def __exit__(self, type, value, tb):
- os.execv = self.orig_execv
- os.execve = self.orig_execve
- os.get_exec_path = self.orig_get_exec_path
-
@unittest.skipUnless(hasattr(os, '_execvpe'),
"No internal os._execvpe function to test.")
def test_internal_execvpe(self):
- exec_stubbed = self._stub_out_for_execvpe_test()
- with exec_stubbed:
- self.assertRaises(RuntimeError, os._execvpe, os.sep+'f', ['-a'])
- self.assertEqual([('execv', os.sep+'f', (['-a'],))],
- exec_stubbed.calls)
- exec_stubbed.calls = []
- self.assertRaises(OSError, os._execvpe, 'f', ['-a'],
- env={'spam': 'beans'})
- self.assertEqual([('execve', os.sep+'p'+os.sep+'f',
- (['-a'], {'spam': 'beans'})),
- ('execve', os.sep+'pp'+os.sep+'f',
- (['-a'], {'spam': 'beans'}))],
- exec_stubbed.calls)
+ program_path = os.sep+'absolutepath'
+ program = 'executable'
+ fullpath = os.path.join(program_path, program)
+ arguments = ['progname', 'arg1', 'arg2']
+ env = {'spam': 'beans'}
+
+ with _execvpe_mockup() as calls:
+ self.assertRaises(RuntimeError, os._execvpe, fullpath, arguments)
+ self.assertEqual(len(calls), 1)
+ self.assertEqual(calls[0], ('execv', fullpath, (arguments,)))
+
+ with _execvpe_mockup(defpath=program_path) as calls:
+ self.assertRaises(OSError, os._execvpe, program, arguments, env=env)
+ self.assertEqual(len(calls), 1)
+ self.assertEqual(calls[0], ('execve', fullpath, (arguments, env)))
+
class Win32ErrorTests(unittest.TestCase):
def test_rename(self):
Modified: python/branches/py3k-jit/Lib/test/test_signal.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_signal.py (original)
+++ python/branches/py3k-jit/Lib/test/test_signal.py Tue May 18 19:58:30 2010
@@ -431,9 +431,8 @@
if signal.getitimer(self.itimer) == (0.0, 0.0):
break # sig_vtalrm handler stopped this itimer
else: # Issue 8424
- sys.stdout.write("test_itimer_virtual: timeout: likely cause: "
- "machine too slow or load too high.\n")
- return
+ self.skipTest("timeout: likely cause: machine too slow or load too "
+ "high")
# virtual itimer should be (0.0, 0.0) now
self.assertEquals(signal.getitimer(self.itimer), (0.0, 0.0))
@@ -455,9 +454,8 @@
if signal.getitimer(self.itimer) == (0.0, 0.0):
break # sig_prof handler stopped this itimer
else: # Issue 8424
- sys.stdout.write("test_itimer_prof: timeout: likely cause: "
- "machine too slow or load too high.\n")
- return
+ self.skipTest("timeout: likely cause: machine too slow or load too "
+ "high")
# profiling itimer should be (0.0, 0.0) now
self.assertEquals(signal.getitimer(self.itimer), (0.0, 0.0))
Modified: python/branches/py3k-jit/Lib/test/test_site.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_site.py (original)
+++ python/branches/py3k-jit/Lib/test/test_site.py Tue May 18 19:58:30 2010
@@ -181,7 +181,8 @@
self.assertEquals(dirs[1], wanted)
# let's try the specific Apple location
- if sys.platform == "darwin":
+ if (sys.platform == "darwin" and
+ sysconfig.get_config_var("PYTHONFRAMEWORK")):
site.PREFIXES = ['Python.framework']
dirs = site.getsitepackages()
self.assertEqual(len(dirs), 4)
Modified: python/branches/py3k-jit/Lib/test/test_ssl.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_ssl.py (original)
+++ python/branches/py3k-jit/Lib/test/test_ssl.py Tue May 18 19:58:30 2010
@@ -10,6 +10,7 @@
import os
import errno
import pprint
+import tempfile
import urllib.parse, urllib.request
import traceback
import asyncore
@@ -23,10 +24,33 @@
import ssl
except ImportError:
skip_expected = True
+else:
+ PROTOCOLS = [
+ ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv3,
+ ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1
+ ]
HOST = support.HOST
-CERTFILE = None
-SVN_PYTHON_ORG_ROOT_CERT = None
+
+data_file = lambda name: os.path.join(os.path.dirname(__file__), name)
+fsencode = lambda name: name.encode(sys.getfilesystemencoding(), "surrogateescape")
+
+CERTFILE = data_file("keycert.pem")
+BYTES_CERTFILE = fsencode(CERTFILE)
+ONLYCERT = data_file("ssl_cert.pem")
+ONLYKEY = data_file("ssl_key.pem")
+BYTES_ONLYCERT = fsencode(ONLYCERT)
+BYTES_ONLYKEY = fsencode(ONLYKEY)
+CAPATH = data_file("capath")
+BYTES_CAPATH = fsencode(CAPATH)
+
+SVN_PYTHON_ORG_ROOT_CERT = data_file("https_svn_python_org_root.pem")
+
+EMPTYCERT = data_file("nullcert.pem")
+BADCERT = data_file("badcert.pem")
+WRONGCERT = data_file("XXXnonexisting.pem")
+BADKEY = data_file("badkey.pem")
+
def handle_error(prefix):
exc_format = ' '.join(traceback.format_exception(*sys.exc_info()))
@@ -34,7 +58,7 @@
sys.stdout.write(prefix + exc_format)
-class BasicTests(unittest.TestCase):
+class BasicSocketTests(unittest.TestCase):
def test_constants(self):
ssl.PROTOCOL_SSLv2
@@ -116,11 +140,10 @@
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_NONE, ciphers="DEFAULT")
s.connect(remote)
- # Error checking occurs when connecting, because the SSL context
- # isn't created before.
- s = ssl.wrap_socket(socket.socket(socket.AF_INET),
- cert_reqs=ssl.CERT_NONE, ciphers="^$:,;?*'dorothyx")
+ # Error checking can happen at instantiation or when connecting
with self.assertRaisesRegexp(ssl.SSLError, "No cipher can be selected"):
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_NONE, ciphers="^$:,;?*'dorothyx")
s.connect(remote)
@support.cpython_only
@@ -143,33 +166,166 @@
self.assertEqual(timeout, ss.gettimeout())
+class ContextTests(unittest.TestCase):
+
+ def test_constructor(self):
+ ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv2)
+ ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv3)
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ self.assertRaises(TypeError, ssl.SSLContext)
+ self.assertRaises(ValueError, ssl.SSLContext, -1)
+ self.assertRaises(ValueError, ssl.SSLContext, 42)
+
+ def test_protocol(self):
+ for proto in PROTOCOLS:
+ ctx = ssl.SSLContext(proto)
+ self.assertEqual(ctx.protocol, proto)
+
+ def test_ciphers(self):
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ ctx.set_ciphers("ALL")
+ ctx.set_ciphers("DEFAULT")
+ with self.assertRaisesRegexp(ssl.SSLError, "No cipher can be selected"):
+ ctx.set_ciphers("^$:,;?*'dorothyx")
+
+ def test_verify(self):
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ # Default value
+ self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
+ ctx.verify_mode = ssl.CERT_OPTIONAL
+ self.assertEqual(ctx.verify_mode, ssl.CERT_OPTIONAL)
+ ctx.verify_mode = ssl.CERT_REQUIRED
+ self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
+ ctx.verify_mode = ssl.CERT_NONE
+ self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
+ with self.assertRaises(TypeError):
+ ctx.verify_mode = None
+ with self.assertRaises(ValueError):
+ ctx.verify_mode = 42
+
+ def test_load_cert_chain(self):
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ # Combined key and cert in a single file
+ ctx.load_cert_chain(CERTFILE)
+ ctx.load_cert_chain(CERTFILE, keyfile=CERTFILE)
+ self.assertRaises(TypeError, ctx.load_cert_chain, keyfile=CERTFILE)
+ with self.assertRaisesRegexp(ssl.SSLError, "system lib"):
+ ctx.load_cert_chain(WRONGCERT)
+ with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
+ ctx.load_cert_chain(BADCERT)
+ with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
+ ctx.load_cert_chain(EMPTYCERT)
+ # Separate key and cert
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ ctx.load_cert_chain(ONLYCERT, ONLYKEY)
+ ctx.load_cert_chain(certfile=ONLYCERT, keyfile=ONLYKEY)
+ ctx.load_cert_chain(certfile=BYTES_ONLYCERT, keyfile=BYTES_ONLYKEY)
+ with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
+ ctx.load_cert_chain(ONLYCERT)
+ with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
+ ctx.load_cert_chain(ONLYKEY)
+ with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
+ ctx.load_cert_chain(certfile=ONLYKEY, keyfile=ONLYCERT)
+ # Mismatching key and cert
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ with self.assertRaisesRegexp(ssl.SSLError, "key values mismatch"):
+ ctx.load_cert_chain(CERTFILE, ONLYKEY)
+
+ def test_load_verify_locations(self):
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ ctx.load_verify_locations(CERTFILE)
+ ctx.load_verify_locations(cafile=CERTFILE, capath=None)
+ ctx.load_verify_locations(BYTES_CERTFILE)
+ ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
+ self.assertRaises(TypeError, ctx.load_verify_locations)
+ self.assertRaises(TypeError, ctx.load_verify_locations, None, None)
+ with self.assertRaisesRegexp(ssl.SSLError, "system lib"):
+ ctx.load_verify_locations(WRONGCERT)
+ with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
+ ctx.load_verify_locations(BADCERT)
+ ctx.load_verify_locations(CERTFILE, CAPATH)
+ ctx.load_verify_locations(CERTFILE, capath=BYTES_CAPATH)
+
+
class NetworkedTests(unittest.TestCase):
def test_connect(self):
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_NONE)
- s.connect(("svn.python.org", 443))
- c = s.getpeercert()
- if c:
- self.fail("Peer cert %s shouldn't be here!")
- s.close()
-
- # this should fail because we have no verification certs
- s = ssl.wrap_socket(socket.socket(socket.AF_INET),
- cert_reqs=ssl.CERT_REQUIRED)
try:
s.connect(("svn.python.org", 443))
- except ssl.SSLError:
- pass
+ self.assertEqual({}, s.getpeercert())
finally:
s.close()
+ # this should fail because we have no verification certs
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_REQUIRED)
+ self.assertRaisesRegexp(ssl.SSLError, "certificate verify failed",
+ s.connect, ("svn.python.org", 443))
+ s.close()
+
# this should succeed because we specify the root cert
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_REQUIRED,
ca_certs=SVN_PYTHON_ORG_ROOT_CERT)
try:
s.connect(("svn.python.org", 443))
+ self.assertTrue(s.getpeercert())
+ finally:
+ s.close()
+
+ def test_connect_with_context(self):
+ # Same as test_connect, but with a separately created context
+ ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ s = ctx.wrap_socket(socket.socket(socket.AF_INET))
+ s.connect(("svn.python.org", 443))
+ try:
+ self.assertEqual({}, s.getpeercert())
+ finally:
+ s.close()
+ # This should fail because we have no verification certs
+ ctx.verify_mode = ssl.CERT_REQUIRED
+ s = ctx.wrap_socket(socket.socket(socket.AF_INET))
+ self.assertRaisesRegexp(ssl.SSLError, "certificate verify failed",
+ s.connect, ("svn.python.org", 443))
+ s.close()
+ # This should succeed because we specify the root cert
+ ctx.load_verify_locations(SVN_PYTHON_ORG_ROOT_CERT)
+ s = ctx.wrap_socket(socket.socket(socket.AF_INET))
+ s.connect(("svn.python.org", 443))
+ try:
+ cert = s.getpeercert()
+ self.assertTrue(cert)
+ finally:
+ s.close()
+
+ def test_connect_capath(self):
+ # Verify server certificates using the `capath` argument
+ # NOTE: the subject hashing algorithm has been changed between
+ # OpenSSL 0.9.8n and 1.0.0, as a result the capath directory must
+ # contain both versions of each certificate (same content, different
+ # filename) for this test to be portable across OpenSSL releases.
+ ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ ctx.verify_mode = ssl.CERT_REQUIRED
+ ctx.load_verify_locations(capath=CAPATH)
+ s = ctx.wrap_socket(socket.socket(socket.AF_INET))
+ s.connect(("svn.python.org", 443))
+ try:
+ cert = s.getpeercert()
+ self.assertTrue(cert)
+ finally:
+ s.close()
+ # Same with a bytes `capath` argument
+ ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ ctx.verify_mode = ssl.CERT_REQUIRED
+ ctx.load_verify_locations(capath=BYTES_CAPATH)
+ s = ctx.wrap_socket(socket.socket(socket.AF_INET))
+ s.connect(("svn.python.org", 443))
+ try:
+ cert = s.getpeercert()
+ self.assertTrue(cert)
finally:
s.close()
@@ -1227,18 +1383,14 @@
if skip_expected:
raise unittest.SkipTest("No SSL support")
- global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT
- CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
- "keycert.pem")
- SVN_PYTHON_ORG_ROOT_CERT = os.path.join(
- os.path.dirname(__file__) or os.curdir,
- "https_svn_python_org_root.pem")
-
- if (not os.path.exists(CERTFILE) or
- not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT)):
- raise support.TestFailed("Can't read certificate files!")
+ for filename in [
+ CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, BYTES_CERTFILE,
+ ONLYCERT, ONLYKEY, BYTES_ONLYCERT, BYTES_ONLYKEY,
+ BADCERT, BADKEY, EMPTYCERT]:
+ if not os.path.exists(filename):
+ raise support.TestFailed("Can't read certificate file %r" % filename)
- tests = [BasicTests]
+ tests = [ContextTests, BasicSocketTests]
if support.is_resource_enabled('network'):
tests.append(NetworkedTests)
Modified: python/branches/py3k-jit/Lib/test/test_sys.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_sys.py (original)
+++ python/branches/py3k-jit/Lib/test/test_sys.py Tue May 18 19:58:30 2010
@@ -87,6 +87,8 @@
# Python/pythonrun.c::PyErr_PrintEx() is tricky.
def test_exit(self):
+ import subprocess
+
self.assertRaises(TypeError, sys.exit, 42, 42)
# call without argument
@@ -141,11 +143,30 @@
self.fail("no exception")
# test that the exit machinery handles SystemExits properly
- import subprocess
rc = subprocess.call([sys.executable, "-c",
"raise SystemExit(47)"])
self.assertEqual(rc, 47)
+ def check_exit_message(code, expected):
+ process = subprocess.Popen([sys.executable, "-c", code],
+ stderr=subprocess.PIPE)
+ stdout, stderr = process.communicate()
+ self.assertEqual(process.returncode, 1)
+ self.assertTrue(stderr.startswith(expected),
+ "%s doesn't start with %s" % (ascii(stderr), ascii(expected)))
+
+ # test that stderr buffer if flushed before the exit message is written
+ # into stderr
+ check_exit_message(
+ r'import sys; sys.stderr.write("unflushed,"); sys.exit("message")',
+ b"unflushed,message")
+
+ # test that the exit message is written with backslashreplace error
+ # handler to stderr
+ check_exit_message(
+ r'import sys; sys.exit("surrogates:\uDCFF")',
+ b"surrogates:\\udcff")
+
def test_getdefaultencoding(self):
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
# can't check more than the type, as the user might have changed it
@@ -450,6 +471,23 @@
self.assertRaises(TypeError, sys.intern, S("abc"))
+ def test_main_invalid_unicode(self):
+ import locale
+ non_decodable = b"\xff"
+ encoding = locale.getpreferredencoding()
+ try:
+ non_decodable.decode(encoding)
+ except UnicodeDecodeError:
+ pass
+ else:
+ self.skipTest('%r is decodable with encoding %s'
+ % (non_decodable, encoding))
+ code = b'print("' + non_decodable + b'")'
+ p = subprocess.Popen([sys.executable, "-c", code], stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ self.assertEqual(p.returncode, 1)
+ self.assert_(b"UnicodeEncodeError:" in stderr,
+ "%r not in %s" % (b"UniodeEncodeError:", ascii(stderr)))
def test_sys_flags(self):
self.assertTrue(sys.flags)
Modified: python/branches/py3k-jit/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/py3k-jit/Lib/test/test_tarfile.py (original)
+++ python/branches/py3k-jit/Lib/test/test_tarfile.py Tue May 18 19:58:30 2010
@@ -1126,11 +1126,32 @@
format = tarfile.GNU_FORMAT
+ def test_bad_pax_header(self):
+ # Test for issue #8633. GNU tar <= 1.23 creates raw binary fields
+ # without a hdrcharset=BINARY header.
+ for encoding, name in (("utf8", "pax/bad-pax-\udce4\udcf6\udcfc"),
+ ("iso8859-1", "pax/bad-pax-\xe4\xf6\xfc"),):
+ with tarfile.open(tarname, encoding=encoding, errors="surrogateescape") as tar:
+ try:
+ t = tar.getmember(name)
+ except KeyError:
+ self.fail("unable to read bad GNU tar pax header")
+
class PAXUnicodeTest(UstarUnicodeTest):
format = tarfile.PAX_FORMAT
+ def test_binary_header(self):
+ # Test a POSIX.1-2008 compatible header with a hdrcharset=BINARY field.
+ for encoding, name in (("utf8", "pax/hdrcharset-\udce4\udcf6\udcfc"),
+ ("iso8859-1", "pax/hdrcharset-\xe4\xf6\xfc"),):
+ with tarfile.open(tarname, encoding=encoding, errors="surrogateescape") as tar:
+ try:
+ t = tar.getmember(name)
+ except KeyError:
+ self.fail("unable to read POSIX.1-2008 binary header")
+
class AppendTest(unittest.TestCase):
# Test append mode (cp. patch #1652681).
Modified: python/branches/py3k-jit/Lib/test/testtar.tar
==============================================================================
Binary files. No diff available.
Modified: python/branches/py3k-jit/Lib/urllib/parse.py
==============================================================================
--- python/branches/py3k-jit/Lib/urllib/parse.py (original)
+++ python/branches/py3k-jit/Lib/urllib/parse.py Tue May 18 19:58:30 2010
@@ -41,7 +41,7 @@
uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet',
'imap', 'wais', 'file', 'mms', 'https', 'shttp',
'snews', 'prospero', 'rtsp', 'rtspu', 'rsync', '',
- 'svn', 'svn+ssh', 'sftp', 'nfs',' git', 'git+ssh']
+ 'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh']
non_hierarchical = ['gopher', 'hdl', 'mailto', 'news',
'telnet', 'wais', 'imap', 'snews', 'sip', 'sips']
uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap',
@@ -307,17 +307,20 @@
"""unquote_to_bytes('abc%20def') -> b'abc def'."""
# Note: strings are encoded as UTF-8. This is only an issue if it contains
# unescaped non-ASCII characters, which URIs should not.
+ if not string:
+ return b''
if isinstance(string, str):
string = string.encode('utf-8')
res = string.split(b'%')
- res[0] = res[0]
- for i in range(1, len(res)):
- item = res[i]
+ if len(res) == 1:
+ return string
+ string = res[0]
+ for item in res[1:]:
try:
- res[i] = bytes([int(item[:2], 16)]) + item[2:]
+ string += bytes([int(item[:2], 16)]) + item[2:]
except ValueError:
- res[i] = b'%' + item
- return b''.join(res)
+ string += b'%' + item
+ return string
def unquote(string, encoding='utf-8', errors='replace'):
"""Replace %xx escapes by their single-character equivalent. The optional
@@ -329,36 +332,39 @@
unquote('abc%20def') -> 'abc def'.
"""
- if encoding is None: encoding = 'utf-8'
- if errors is None: errors = 'replace'
- # pct_sequence: contiguous sequence of percent-encoded bytes, decoded
- # (list of single-byte bytes objects)
- pct_sequence = []
+ if not string:
+ return string
res = string.split('%')
- for i in range(1, len(res)):
- item = res[i]
+ if len(res) == 1:
+ return string
+ if encoding is None:
+ encoding = 'utf-8'
+ if errors is None:
+ errors = 'replace'
+ # pct_sequence: contiguous sequence of percent-encoded bytes, decoded
+ pct_sequence = b''
+ string = res[0]
+ for item in res[1:]:
try:
- if not item: raise ValueError
- pct_sequence.append(bytes.fromhex(item[:2]))
+ if not item:
+ raise ValueError
+ pct_sequence += bytes.fromhex(item[:2])
rest = item[2:]
+ if not rest:
+ # This segment was just a single percent-encoded character.
+ # May be part of a sequence of code units, so delay decoding.
+ # (Stored in pct_sequence).
+ continue
except ValueError:
rest = '%' + item
- if not rest:
- # This segment was just a single percent-encoded character.
- # May be part of a sequence of code units, so delay decoding.
- # (Stored in pct_sequence).
- res[i] = ''
- else:
- # Encountered non-percent-encoded characters. Flush the current
- # pct_sequence.
- res[i] = b''.join(pct_sequence).decode(encoding, errors) + rest
- pct_sequence = []
+ # Encountered non-percent-encoded characters. Flush the current
+ # pct_sequence.
+ string += pct_sequence.decode(encoding, errors) + rest
+ pct_sequence = b''
if pct_sequence:
# Flush the final pct_sequence
- # res[-1] will always be empty if pct_sequence != []
- assert not res[-1], "string=%r, res=%r" % (string, res)
- res[-1] = b''.join(pct_sequence).decode(encoding, errors)
- return ''.join(res)
+ string += pct_sequence.decode(encoding, errors)
+ return string
def parse_qs(qs, keep_blank_values=False, strict_parsing=False):
"""Parse a query given as a string argument.
@@ -439,7 +445,8 @@
b'abcdefghijklmnopqrstuvwxyz'
b'0123456789'
b'_.-')
-_safe_quoters= {}
+_ALWAYS_SAFE_BYTES = bytes(_ALWAYS_SAFE)
+_safe_quoters = {}
class Quoter(collections.defaultdict):
"""A mapping from bytes (in range(0,256)) to strings.
@@ -451,7 +458,7 @@
# of cached keys don't call Python code at all).
def __init__(self, safe):
"""safe: bytes object."""
- self.safe = _ALWAYS_SAFE.union(c for c in safe if c < 128)
+ self.safe = _ALWAYS_SAFE.union(safe)
def __repr__(self):
# Without this, will just display as a defaultdict
@@ -459,7 +466,7 @@
def __missing__(self, b):
# Handle a cache miss. Store quoted string in cache and return.
- res = b in self.safe and chr(b) or ('%%%02X' % b)
+ res = chr(b) if b in self.safe else '%{:02X}'.format(b)
self[b] = res
return res
@@ -493,6 +500,8 @@
errors='strict' (unsupported characters raise a UnicodeEncodeError).
"""
if isinstance(string, str):
+ if not string:
+ return string
if encoding is None:
encoding = 'utf-8'
if errors is None:
@@ -527,18 +536,22 @@
not perform string-to-bytes encoding. It always returns an ASCII string.
quote_from_bytes(b'abc def\xab') -> 'abc%20def%AB'
"""
+ if not isinstance(bs, (bytes, bytearray)):
+ raise TypeError("quote_from_bytes() expected bytes")
+ if not bs:
+ return ''
if isinstance(safe, str):
# Normalize 'safe' by converting to bytes and removing non-ASCII chars
safe = safe.encode('ascii', 'ignore')
- cachekey = bytes(safe) # In case it was a bytearray
- if not (isinstance(bs, bytes) or isinstance(bs, bytearray)):
- raise TypeError("quote_from_bytes() expected a bytes")
+ else:
+ safe = bytes([c for c in safe if c < 128])
+ if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe):
+ return bs.decode()
try:
- quoter = _safe_quoters[cachekey]
+ quoter = _safe_quoters[safe]
except KeyError:
- quoter = Quoter(safe)
- _safe_quoters[cachekey] = quoter
- return ''.join([quoter[char] for char in bs])
+ _safe_quoters[safe] = quoter = Quoter(safe).__getitem__
+ return ''.join([quoter(char) for char in bs])
def urlencode(query, doseq=False):
"""Encode a sequence of two-element tuples or dictionary into a URL query string.
Modified: python/branches/py3k-jit/Lib/urllib/request.py
==============================================================================
--- python/branches/py3k-jit/Lib/urllib/request.py (original)
+++ python/branches/py3k-jit/Lib/urllib/request.py Tue May 18 19:58:30 2010
@@ -1965,7 +1965,7 @@
else:
return self.open(newurl, data)
- def get_user_passwd(self, host, realm, clear_cache = 0):
+ def get_user_passwd(self, host, realm, clear_cache=0):
key = realm + '@' + host.lower()
if key in self.auth_cache:
if clear_cache:
Modified: python/branches/py3k-jit/Makefile.pre.in
==============================================================================
--- python/branches/py3k-jit/Makefile.pre.in (original)
+++ python/branches/py3k-jit/Makefile.pre.in Tue May 18 19:58:30 2010
@@ -1233,7 +1233,7 @@
# files, which clobber removes as well
pycremoval:
-find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
- -find $(srcdir) -name '__pycache__' -exec rmdir {} ';'
+ -find $(srcdir) -name '__pycache__' -exec rmdir {} '+'
rmtestturds:
-rm -f *BAD *GOOD *SKIPPED
Modified: python/branches/py3k-jit/Misc/NEWS
==============================================================================
--- python/branches/py3k-jit/Misc/NEWS (original)
+++ python/branches/py3k-jit/Misc/NEWS Tue May 18 19:58:30 2010
@@ -12,6 +12,21 @@
Core and Builtins
-----------------
+- PyObject_Dump() encodes unicode objects to utf8 with backslashreplace
+ (instead of strict) error handler to escape surrogates
+
+- Issue #8715: Create PyUnicode_EncodeFSDefault() function: Encode a Unicode
+ object to Py_FileSystemDefaultEncoding with the "surrogateescape" error
+ handler, and return bytes. If Py_FileSystemDefaultEncoding is not set, fall
+ back to UTF-8.
+
+- Enable shortcuts for common encodings in PyUnicode_AsEncodedString() for any
+ error handler, not only the default error handler (strict)
+
+- Issue #8610: Load file system codec at startup, and display a fatal error on
+ failure. Set the file system encoding to utf-8 (instead of None) if getting
+ the locale encoding failed, or if nl_langinfo(CODESET) function is missing.
+
- PyFile_FromFd() uses PyUnicode_DecodeFSDefault() instead of
PyUnicode_FromString() to support surrogates in the filename and use the
right encoding
@@ -351,6 +366,19 @@
Library
-------
+- Issue #8633: tarfile is now able to read and write archives with "raw" binary
+ pax headers as described in POSIX.1-2008.
+
+- Issue #1285086: Speed up urllib.parse functions: quote, quote_from_bytes,
+ unquote, unquote_to_bytes.
+
+- Issue #8688: Distutils now recalculates MANIFEST everytime.
+
+- Issue #8477: ssl.RAND_egd() and ssl._test_decode_cert() support str with
+ surrogates and bytes for the filename
+
+- Issue #8550: Add first class ``SSLContext`` objects to the ssl module.
+
- Issue #8681: Make the zlib module's error messages more informative when
the zlib itself doesn't give any detailed explanation.
@@ -377,9 +405,9 @@
- Issue #8573: asyncore _strerror() function might throw ValueError.
-- Issue #8483: asyncore.dispatcher's __getattr__ method produced confusing
- error messages when accessing undefined class attributes because of the cheap
- inheritance with the underlying socket object.
+- Issue #8483: asyncore.dispatcher's __getattr__ method produced confusing
+ error messages when accessing undefined class attributes because of the cheap
+ inheritance with the underlying socket object.
The cheap inheritance has been deprecated.
- Issue #4265: shutil.copyfile() was leaking file descriptors when disk fills.
@@ -476,7 +504,7 @@
- Issue #6547: Added the ignore_dangling_symlinks option to shutil.copytree.
-- Issue #1540112: Now allowing the choice of a copy function in
+- Issue #1540112: Now allowing the choice of a copy function in
shutil.copytree.
- Issue #4814: timeout parameter is now applied also for connections resulting
@@ -791,7 +819,7 @@
Initial patch by Brian Curtin.
- Issue #7556: Make sure Distutils' msvc9compile reads and writes the
- MSVC XML Manifest file in text mode so string patterns can be used
+ MSVC XML Manifest file in text mode so string patterns can be used
in regular expressions.
- Issue #7552: Removed line feed in the base64 Authorization header in
@@ -822,13 +850,13 @@
- Issue #6986: Fix crash in the JSON C accelerator when called with the
wrong parameter types. Patch by Victor Stinner.
-- Issue #7457: added a read_pkg_file method to
+- Issue #7457: added a read_pkg_file method to
distutils.dist.DistributionMetadata.
- logging: Added optional `secure` parameter to SMTPHandler, to enable use of
TLS with authentication credentials.
-- Issue #1923: Fixed the removal of meaningful spaces when PKG-INFO is
+- Issue #1923: Fixed the removal of meaningful spaces when PKG-INFO is
generated in Distutils. Patch by Stephen Emslie.
- Issue #4120: Drop reference to CRT from manifest when building extensions with
@@ -866,7 +894,7 @@
- Issue #6123: tarfile now opens empty archives correctly and consistently
raises ReadError on empty files.
-- Issue #7354: distutils.tests.test_msvc9compiler - dragfullwindows can
+- Issue #7354: distutils.tests.test_msvc9compiler - dragfullwindows can
be 2.
- Issue #5037: Proxy the __bytes__ special method instead to __bytes__ instead
@@ -904,12 +932,12 @@
- Issue #7893: ``unittest.TextTestResult`` is made public and a ``resultclass``
argument added to the TextTestRunner constructor allowing a different result
class to be used without having to subclass.
-
+
- Issue 7588: ``unittest.TextTestResult.getDescription`` now includes the test
name in failure reports even if the test has a docstring.
- Issue #3001: Add a C implementation of recursive locks which is used by
- default when instantiating a `threading.RLock` object. This makes
+ default when instantiating a `threading.RLock` object. This makes
recursive locks as fast as regular non-recursive locks (previously,
they were slower by 10x to 15x).
@@ -1120,6 +1148,12 @@
Extension Modules
-----------------
+- Issue #8692: Optimize math.factorial: replace the previous naive
+ algorithm with an improved 'binary-split' algorithm that uses fewer
+ multiplications and allows many of the multiplications to be
+ performed using plain C integer arithmetic instead of PyLong
+ arithmetic. Also uses a lookup table for small arguments.
+
- Issue #8674: Fixed a number of incorrect or undefined-behaviour-inducing
overflow checks in the audioop module.
@@ -1349,7 +1383,7 @@
- Issue #7498: test_multiprocessing now uses test.support.find_unused_port
instead of a hardcoded port number in test_rapid_restart.
-- Issue #7431: use TESTFN in test_linecache instead of trying to create a
+- Issue #7431: use TESTFN in test_linecache instead of trying to create a
file in the Lib/test directory, which might be read-only for the
user running the tests.
@@ -2233,7 +2267,7 @@
- Issue #7071: byte-compilation in Distutils is now done with respect to
sys.dont_write_bytecode.
-- Issue #7066: archive_util.make_archive now restores the cwd if an error is
+- Issue #7066: archive_util.make_archive now restores the cwd if an error is
raised. Initial patch by Ezio Melotti.
- Issue #6516: Added owner/group support when creating tar archives in
Modified: python/branches/py3k-jit/Modules/_cursesmodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/_cursesmodule.c (original)
+++ python/branches/py3k-jit/Modules/_cursesmodule.c Tue May 18 19:58:30 2010
@@ -33,66 +33,66 @@
/*
-A number of SysV or ncurses functions don't have wrappers yet; if you
-need a given function, add it and send a patch. See
-http://www.python.org/dev/patches/ for instructions on how to submit
-patches to Python.
-
-Here's a list of currently unsupported functions:
-
- addchnstr addchstr color_set define_key
- del_curterm delscreen dupwin inchnstr inchstr innstr keyok
- mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
- mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
- mvwinchnstr mvwinchstr mvwinnstr newterm
- restartterm ripoffline scr_dump
- scr_init scr_restore scr_set scrl set_curterm set_term setterm
- tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
- vidattr vidputs waddchnstr waddchstr
- wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
-
-Low-priority:
- slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
- slk_attron slk_attrset slk_clear slk_color slk_init slk_label
- slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
-
-Menu extension (ncurses and probably SYSV):
- current_item free_item free_menu item_count item_description
- item_index item_init item_name item_opts item_opts_off
- item_opts_on item_term item_userptr item_value item_visible
- menu_back menu_driver menu_fore menu_format menu_grey
- menu_init menu_items menu_mark menu_opts menu_opts_off
- menu_opts_on menu_pad menu_pattern menu_request_by_name
- menu_request_name menu_spacing menu_sub menu_term menu_userptr
- menu_win new_item new_menu pos_menu_cursor post_menu
- scale_menu set_current_item set_item_init set_item_opts
- set_item_term set_item_userptr set_item_value set_menu_back
- set_menu_fore set_menu_format set_menu_grey set_menu_init
- set_menu_items set_menu_mark set_menu_opts set_menu_pad
- set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
- set_menu_userptr set_menu_win set_top_row top_row unpost_menu
-
-Form extension (ncurses and probably SYSV):
- current_field data_ahead data_behind dup_field
- dynamic_fieldinfo field_arg field_back field_buffer
- field_count field_fore field_index field_info field_init
- field_just field_opts field_opts_off field_opts_on field_pad
- field_status field_term field_type field_userptr form_driver
- form_fields form_init form_opts form_opts_off form_opts_on
- form_page form_request_by_name form_request_name form_sub
- form_term form_userptr form_win free_field free_form
- link_field link_fieldtype move_field new_field new_form
- new_page pos_form_cursor post_form scale_form
- set_current_field set_field_back set_field_buffer
- set_field_fore set_field_init set_field_just set_field_opts
- set_field_pad set_field_status set_field_term set_field_type
- set_field_userptr set_fieldtype_arg set_fieldtype_choice
- set_form_fields set_form_init set_form_opts set_form_page
- set_form_sub set_form_term set_form_userptr set_form_win
- set_max_field set_new_page unpost_form
+ A number of SysV or ncurses functions don't have wrappers yet; if you
+ need a given function, add it and send a patch. See
+ http://www.python.org/dev/patches/ for instructions on how to submit
+ patches to Python.
+
+ Here's a list of currently unsupported functions:
+
+ addchnstr addchstr color_set define_key
+ del_curterm delscreen dupwin inchnstr inchstr innstr keyok
+ mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
+ mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
+ mvwinchnstr mvwinchstr mvwinnstr newterm
+ restartterm ripoffline scr_dump
+ scr_init scr_restore scr_set scrl set_curterm set_term setterm
+ tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
+ vidattr vidputs waddchnstr waddchstr
+ wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
+
+ Low-priority:
+ slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
+ slk_attron slk_attrset slk_clear slk_color slk_init slk_label
+ slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
+
+ Menu extension (ncurses and probably SYSV):
+ current_item free_item free_menu item_count item_description
+ item_index item_init item_name item_opts item_opts_off
+ item_opts_on item_term item_userptr item_value item_visible
+ menu_back menu_driver menu_fore menu_format menu_grey
+ menu_init menu_items menu_mark menu_opts menu_opts_off
+ menu_opts_on menu_pad menu_pattern menu_request_by_name
+ menu_request_name menu_spacing menu_sub menu_term menu_userptr
+ menu_win new_item new_menu pos_menu_cursor post_menu
+ scale_menu set_current_item set_item_init set_item_opts
+ set_item_term set_item_userptr set_item_value set_menu_back
+ set_menu_fore set_menu_format set_menu_grey set_menu_init
+ set_menu_items set_menu_mark set_menu_opts set_menu_pad
+ set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
+ set_menu_userptr set_menu_win set_top_row top_row unpost_menu
+
+ Form extension (ncurses and probably SYSV):
+ current_field data_ahead data_behind dup_field
+ dynamic_fieldinfo field_arg field_back field_buffer
+ field_count field_fore field_index field_info field_init
+ field_just field_opts field_opts_off field_opts_on field_pad
+ field_status field_term field_type field_userptr form_driver
+ form_fields form_init form_opts form_opts_off form_opts_on
+ form_page form_request_by_name form_request_name form_sub
+ form_term form_userptr form_win free_field free_form
+ link_field link_fieldtype move_field new_field new_form
+ new_page pos_form_cursor post_form scale_form
+ set_current_field set_field_back set_field_buffer
+ set_field_fore set_field_init set_field_just set_field_opts
+ set_field_pad set_field_status set_field_term set_field_type
+ set_field_userptr set_fieldtype_arg set_fieldtype_choice
+ set_form_fields set_form_init set_form_opts set_form_page
+ set_form_sub set_form_term set_form_userptr set_form_win
+ set_max_field set_new_page unpost_form
- */
+*/
/* Release Number */
@@ -116,9 +116,9 @@
#define CURSES_MODULE
#include "py_curses.h"
-/* These prototypes are in <term.h>, but including this header
- #defines many common symbols (such as "lines") which breaks the
- curses module in other ways. So the code will just specify
+/* These prototypes are in <term.h>, but including this header
+ #defines many common symbols (such as "lines") which breaks the
+ curses module in other ways. So the code will just specify
explicit prototypes here. */
extern int setupterm(char *,int,int *);
#ifdef __sgi
@@ -148,23 +148,23 @@
static int initialisedcolors = FALSE;
/* Utility Macros */
-#define PyCursesSetupTermCalled \
- if (initialised_setupterm != TRUE) { \
- PyErr_SetString(PyCursesError, \
- "must call (at least) setupterm() first"); \
- return 0; }
-
-#define PyCursesInitialised \
- if (initialised != TRUE) { \
- PyErr_SetString(PyCursesError, \
- "must call initscr() first"); \
- return 0; }
-
-#define PyCursesInitialisedColor \
- if (initialisedcolors != TRUE) { \
- PyErr_SetString(PyCursesError, \
- "must call start_color() first"); \
- return 0; }
+#define PyCursesSetupTermCalled \
+ if (initialised_setupterm != TRUE) { \
+ PyErr_SetString(PyCursesError, \
+ "must call (at least) setupterm() first"); \
+ return 0; }
+
+#define PyCursesInitialised \
+ if (initialised != TRUE) { \
+ PyErr_SetString(PyCursesError, \
+ "must call initscr() first"); \
+ return 0; }
+
+#define PyCursesInitialisedColor \
+ if (initialisedcolors != TRUE) { \
+ PyErr_SetString(PyCursesError, \
+ "must call start_color() first"); \
+ return 0; }
#ifndef MIN
#define MIN(x,y) ((x) < (y) ? (x) : (y))
@@ -173,51 +173,51 @@
/* Utility Functions */
/*
- * Check the return code from a curses function and return None
+ * Check the return code from a curses function and return None
* or raise an exception as appropriate. These are exported using the
- * capsule API.
+ * capsule API.
*/
static PyObject *
PyCursesCheckERR(int code, char *fname)
{
- if (code != ERR) {
- Py_INCREF(Py_None);
- return Py_None;
- } else {
- if (fname == NULL) {
- PyErr_SetString(PyCursesError, catchall_ERR);
+ if (code != ERR) {
+ Py_INCREF(Py_None);
+ return Py_None;
} else {
- PyErr_Format(PyCursesError, "%s() returned ERR", fname);
+ if (fname == NULL) {
+ PyErr_SetString(PyCursesError, catchall_ERR);
+ } else {
+ PyErr_Format(PyCursesError, "%s() returned ERR", fname);
+ }
+ return NULL;
}
- return NULL;
- }
}
-static int
+static int
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
{
- if (PyLong_CheckExact(obj)) {
- int overflow;
- /* XXX should the truncation by the cast also be reported
- as an error? */
- *ch = (chtype) PyLong_AsLongAndOverflow(obj, &overflow);
- if (overflow)
- return 0;
- } else if(PyBytes_Check(obj)
- && (PyBytes_Size(obj) == 1)) {
- *ch = (chtype) *PyBytes_AsString(obj);
- } else if (PyUnicode_Check(obj) && PyUnicode_GetSize(obj) == 1) {
- *ch = (chtype) *PyUnicode_AS_UNICODE(obj);
- } else {
- return 0;
- }
- return 1;
+ if (PyLong_CheckExact(obj)) {
+ int overflow;
+ /* XXX should the truncation by the cast also be reported
+ as an error? */
+ *ch = (chtype) PyLong_AsLongAndOverflow(obj, &overflow);
+ if (overflow)
+ return 0;
+ } else if(PyBytes_Check(obj)
+ && (PyBytes_Size(obj) == 1)) {
+ *ch = (chtype) *PyBytes_AsString(obj);
+ } else if (PyUnicode_Check(obj) && PyUnicode_GetSize(obj) == 1) {
+ *ch = (chtype) *PyUnicode_AS_UNICODE(obj);
+ } else {
+ return 0;
+ }
+ return 1;
}
/* Function versions of the 3 functions for testing whether curses has been
initialised or not. */
-
+
static int func_PyCursesSetupTermCalled(void)
{
PyCursesSetupTermCalled;
@@ -250,56 +250,56 @@
TYPE - parameter Type
ERGSTR - format string for construction of the return value
PARSESTR - format string for argument parsing
- */
+*/
-#define Window_NoArgNoReturnFunction(X) \
-static PyObject *PyCursesWindow_ ## X \
-(PyCursesWindowObject *self, PyObject *args) \
-{ return PyCursesCheckERR(X(self->win), # X); }
-
-#define Window_NoArgTrueFalseFunction(X) \
-static PyObject * PyCursesWindow_ ## X \
-(PyCursesWindowObject *self) \
-{ \
- if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
- else { Py_INCREF(Py_True); return Py_True; } }
-
-#define Window_NoArgNoReturnVoidFunction(X) \
-static PyObject * PyCursesWindow_ ## X \
-(PyCursesWindowObject *self) \
-{ \
- X(self->win); Py_INCREF(Py_None); return Py_None; }
-
-#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
-static PyObject * PyCursesWindow_ ## X \
-(PyCursesWindowObject *self) \
-{ \
- TYPE arg1, arg2; \
- X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
-
-#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
-static PyObject * PyCursesWindow_ ## X \
-(PyCursesWindowObject *self, PyObject *args) \
-{ \
- TYPE arg1; \
- if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
- X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
-
-#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
-static PyObject * PyCursesWindow_ ## X \
-(PyCursesWindowObject *self, PyObject *args) \
-{ \
- TYPE arg1; \
- if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
- return PyCursesCheckERR(X(self->win, arg1), # X); }
-
-#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
-static PyObject * PyCursesWindow_ ## X \
-(PyCursesWindowObject *self, PyObject *args) \
-{ \
- TYPE arg1, arg2; \
- if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
- return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
+#define Window_NoArgNoReturnFunction(X) \
+ static PyObject *PyCursesWindow_ ## X \
+ (PyCursesWindowObject *self, PyObject *args) \
+ { return PyCursesCheckERR(X(self->win), # X); }
+
+#define Window_NoArgTrueFalseFunction(X) \
+ static PyObject * PyCursesWindow_ ## X \
+ (PyCursesWindowObject *self) \
+ { \
+ if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
+ else { Py_INCREF(Py_True); return Py_True; } }
+
+#define Window_NoArgNoReturnVoidFunction(X) \
+ static PyObject * PyCursesWindow_ ## X \
+ (PyCursesWindowObject *self) \
+ { \
+ X(self->win); Py_INCREF(Py_None); return Py_None; }
+
+#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
+ static PyObject * PyCursesWindow_ ## X \
+ (PyCursesWindowObject *self) \
+ { \
+ TYPE arg1, arg2; \
+ X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
+
+#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
+ static PyObject * PyCursesWindow_ ## X \
+ (PyCursesWindowObject *self, PyObject *args) \
+ { \
+ TYPE arg1; \
+ if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
+ X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
+
+#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
+ static PyObject * PyCursesWindow_ ## X \
+ (PyCursesWindowObject *self, PyObject *args) \
+ { \
+ TYPE arg1; \
+ if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
+ return PyCursesCheckERR(X(self->win, arg1), # X); }
+
+#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
+ static PyObject * PyCursesWindow_ ## X \
+ (PyCursesWindowObject *self, PyObject *args) \
+ { \
+ TYPE arg1, arg2; \
+ if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
+ return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
/* ------------- WINDOW routines --------------- */
@@ -360,19 +360,19 @@
static PyObject *
PyCursesWindow_New(WINDOW *win)
{
- PyCursesWindowObject *wo;
+ PyCursesWindowObject *wo;
- wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
- if (wo == NULL) return NULL;
- wo->win = win;
- return (PyObject *)wo;
+ wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
+ if (wo == NULL) return NULL;
+ wo->win = win;
+ return (PyObject *)wo;
}
static void
PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
{
- if (wo->win != stdscr) delwin(wo->win);
- PyObject_DEL(wo);
+ if (wo->win != stdscr) delwin(wo->win);
+ PyObject_DEL(wo);
}
/* Addch, Addstr, Addnstr */
@@ -380,287 +380,287 @@
static PyObject *
PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
{
- int rtn, x, y, use_xy = FALSE;
- PyObject *temp;
- chtype ch = 0;
- attr_t attr = A_NORMAL;
- long lattr;
-
- switch (PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
- return NULL;
- break;
- case 2:
- if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
- return NULL;
- attr = lattr;
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
- return NULL;
- use_xy = TRUE;
- break;
- case 4:
- if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr",
- &y, &x, &temp, &lattr))
- return NULL;
- attr = lattr;
- use_xy = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
- return NULL;
- }
-
- if (!PyCurses_ConvertToChtype(temp, &ch)) {
- PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
- return NULL;
- }
-
- if (use_xy == TRUE)
- rtn = mvwaddch(self->win,y,x, ch | attr);
- else {
- rtn = waddch(self->win, ch | attr);
- }
- return PyCursesCheckERR(rtn, "addch");
+ int rtn, x, y, use_xy = FALSE;
+ PyObject *temp;
+ chtype ch = 0;
+ attr_t attr = A_NORMAL;
+ long lattr;
+
+ switch (PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
+ return NULL;
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
+ return NULL;
+ use_xy = TRUE;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr",
+ &y, &x, &temp, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
+ return NULL;
+ }
+
+ if (!PyCurses_ConvertToChtype(temp, &ch)) {
+ PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
+ return NULL;
+ }
+
+ if (use_xy == TRUE)
+ rtn = mvwaddch(self->win,y,x, ch | attr);
+ else {
+ rtn = waddch(self->win, ch | attr);
+ }
+ return PyCursesCheckERR(rtn, "addch");
}
static PyObject *
PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
{
- int rtn;
- int x, y;
- char *str;
- attr_t attr = A_NORMAL , attr_old = A_NORMAL;
- long lattr;
- int use_xy = FALSE, use_attr = FALSE;
-
- switch (PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args,"s;str", &str))
- return NULL;
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
- return NULL;
- attr = lattr;
- use_attr = TRUE;
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str))
- return NULL;
- use_xy = TRUE;
- break;
- case 4:
- if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &lattr))
- return NULL;
- attr = lattr;
- use_xy = use_attr = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
- return NULL;
- }
-
- if (use_attr == TRUE) {
- attr_old = getattrs(self->win);
- (void)wattrset(self->win,attr);
- }
- if (use_xy == TRUE)
- rtn = mvwaddstr(self->win,y,x,str);
- else
- rtn = waddstr(self->win,str);
- if (use_attr == TRUE)
- (void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, "addstr");
+ int rtn;
+ int x, y;
+ char *str;
+ attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+ long lattr;
+ int use_xy = FALSE, use_attr = FALSE;
+
+ switch (PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args,"s;str", &str))
+ return NULL;
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
+ return NULL;
+ attr = lattr;
+ use_attr = TRUE;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str))
+ return NULL;
+ use_xy = TRUE;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = use_attr = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
+ return NULL;
+ }
+
+ if (use_attr == TRUE) {
+ attr_old = getattrs(self->win);
+ (void)wattrset(self->win,attr);
+ }
+ if (use_xy == TRUE)
+ rtn = mvwaddstr(self->win,y,x,str);
+ else
+ rtn = waddstr(self->win,str);
+ if (use_attr == TRUE)
+ (void)wattrset(self->win,attr_old);
+ return PyCursesCheckERR(rtn, "addstr");
}
static PyObject *
PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
{
- int rtn, x, y, n;
- char *str;
- attr_t attr = A_NORMAL , attr_old = A_NORMAL;
- long lattr;
- int use_xy = FALSE, use_attr = FALSE;
-
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
- return NULL;
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
- return NULL;
- attr = lattr;
- use_attr = TRUE;
- break;
- case 4:
- if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
- return NULL;
- use_xy = TRUE;
- break;
- case 5:
- if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
- return NULL;
- attr = lattr;
- use_xy = use_attr = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
- return NULL;
- }
-
- if (use_attr == TRUE) {
- attr_old = getattrs(self->win);
- (void)wattrset(self->win,attr);
- }
- if (use_xy == TRUE)
- rtn = mvwaddnstr(self->win,y,x,str,n);
- else
- rtn = waddnstr(self->win,str,n);
- if (use_attr == TRUE)
- (void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, "addnstr");
+ int rtn, x, y, n;
+ char *str;
+ attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+ long lattr;
+ int use_xy = FALSE, use_attr = FALSE;
+
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
+ return NULL;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ use_attr = TRUE;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
+ return NULL;
+ use_xy = TRUE;
+ break;
+ case 5:
+ if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = use_attr = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
+ return NULL;
+ }
+
+ if (use_attr == TRUE) {
+ attr_old = getattrs(self->win);
+ (void)wattrset(self->win,attr);
+ }
+ if (use_xy == TRUE)
+ rtn = mvwaddnstr(self->win,y,x,str,n);
+ else
+ rtn = waddnstr(self->win,str,n);
+ if (use_attr == TRUE)
+ (void)wattrset(self->win,attr_old);
+ return PyCursesCheckERR(rtn, "addnstr");
}
static PyObject *
PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
{
- PyObject *temp;
- chtype bkgd;
- attr_t attr = A_NORMAL;
- long lattr;
+ PyObject *temp;
+ chtype bkgd;
+ attr_t attr = A_NORMAL;
+ long lattr;
- switch (PyTuple_Size(args)) {
+ switch (PyTuple_Size(args)) {
case 1:
- if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
- return NULL;
- break;
+ if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
+ return NULL;
+ break;
case 2:
- if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
- return NULL;
- attr = lattr;
- break;
+ if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
default:
- PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
- return NULL;
- }
+ PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
+ return NULL;
+ }
- if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
- PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
- return NULL;
- }
+ if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
+ PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
+ return NULL;
+ }
- return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
+ return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
}
static PyObject *
PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args)
{
- long lattr;
- if (!PyArg_ParseTuple(args,"l;attr", &lattr))
- return NULL;
- return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff");
+ long lattr;
+ if (!PyArg_ParseTuple(args,"l;attr", &lattr))
+ return NULL;
+ return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff");
}
static PyObject *
PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args)
{
- long lattr;
- if (!PyArg_ParseTuple(args,"l;attr", &lattr))
- return NULL;
- return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron");
+ long lattr;
+ if (!PyArg_ParseTuple(args,"l;attr", &lattr))
+ return NULL;
+ return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron");
}
static PyObject *
PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args)
{
- long lattr;
- if (!PyArg_ParseTuple(args,"l;attr", &lattr))
- return NULL;
- return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset");
+ long lattr;
+ if (!PyArg_ParseTuple(args,"l;attr", &lattr))
+ return NULL;
+ return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset");
}
static PyObject *
PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
{
- PyObject *temp;
- chtype bkgd;
- attr_t attr = A_NORMAL;
- long lattr;
+ PyObject *temp;
+ chtype bkgd;
+ attr_t attr = A_NORMAL;
+ long lattr;
- switch (PyTuple_Size(args)) {
+ switch (PyTuple_Size(args)) {
case 1:
- if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
- return NULL;
- break;
+ if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
+ return NULL;
+ break;
case 2:
- if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
- return NULL;
- attr = lattr;
- break;
+ if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
default:
- PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
- return NULL;
- }
+ PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
+ return NULL;
+ }
- if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
- PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
- return NULL;
- }
+ if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
+ PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
+ return NULL;
+ }
- wbkgdset(self->win, bkgd | attr);
- return PyCursesCheckERR(0, "bkgdset");
+ wbkgdset(self->win, bkgd | attr);
+ return PyCursesCheckERR(0, "bkgdset");
}
static PyObject *
PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
{
- PyObject *temp[8];
- chtype ch[8];
- int i;
-
- /* Clear the array of parameters */
- for(i=0; i<8; i++) {
- temp[i] = NULL;
- ch[i] = 0;
- }
-
- if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
- &temp[0], &temp[1], &temp[2], &temp[3],
- &temp[4], &temp[5], &temp[6], &temp[7]))
- return NULL;
-
- for(i=0; i<8; i++) {
- if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
- PyErr_Format(PyExc_TypeError,
- "argument %i must be a ch or an int", i+1);
- return NULL;
- }
- }
-
- wborder(self->win,
- ch[0], ch[1], ch[2], ch[3],
- ch[4], ch[5], ch[6], ch[7]);
- Py_INCREF(Py_None);
- return Py_None;
+ PyObject *temp[8];
+ chtype ch[8];
+ int i;
+
+ /* Clear the array of parameters */
+ for(i=0; i<8; i++) {
+ temp[i] = NULL;
+ ch[i] = 0;
+ }
+
+ if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
+ &temp[0], &temp[1], &temp[2], &temp[3],
+ &temp[4], &temp[5], &temp[6], &temp[7]))
+ return NULL;
+
+ for(i=0; i<8; i++) {
+ if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
+ PyErr_Format(PyExc_TypeError,
+ "argument %i must be a ch or an int", i+1);
+ return NULL;
+ }
+ }
+
+ wborder(self->win,
+ ch[0], ch[1], ch[2], ch[3],
+ ch[4], ch[5], ch[6], ch[7]);
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyObject *
PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
{
- chtype ch1=0,ch2=0;
- switch(PyTuple_Size(args)){
- case 0: break;
- default:
- if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
- return NULL;
- }
- box(self->win,ch1,ch2);
- Py_INCREF(Py_None);
- return Py_None;
+ chtype ch1=0,ch2=0;
+ switch(PyTuple_Size(args)){
+ case 0: break;
+ default:
+ if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
+ return NULL;
+ }
+ box(self->win,ch1,ch2);
+ Py_INCREF(Py_None);
+ return Py_None;
}
#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
@@ -668,10 +668,10 @@
#else
int py_mvwdelch(WINDOW *w, int y, int x)
{
- mvwdelch(w,y,x);
- /* On HP/UX, mvwdelch already returns. On other systems,
- we may well run into this return statement. */
- return 0;
+ mvwdelch(w,y,x);
+ /* On HP/UX, mvwdelch already returns. On other systems,
+ we may well run into this return statement. */
+ return 0;
}
#endif
@@ -680,603 +680,603 @@
static PyObject *
PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args)
{
- int rtn;
- int x, y;
- int num = -1;
- short color;
- attr_t attr = A_NORMAL;
- long lattr;
- int use_xy = FALSE;
+ int rtn;
+ int x, y;
+ int num = -1;
+ short color;
+ attr_t attr = A_NORMAL;
+ long lattr;
+ int use_xy = FALSE;
- switch (PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args,"l;attr", &lattr))
- return NULL;
- attr = lattr;
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
- return NULL;
- attr = lattr;
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
- return NULL;
- attr = lattr;
- use_xy = TRUE;
- break;
- case 4:
- if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
- return NULL;
- attr = lattr;
- use_xy = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
- return NULL;
- }
-
- color = (short)((attr >> 8) & 0xff);
- attr = attr - (color << 8);
-
- if (use_xy == TRUE) {
- rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
- touchline(self->win,y,1);
- } else {
- getyx(self->win,y,x);
- rtn = wchgat(self->win,num,attr,color,NULL);
- touchline(self->win,y,1);
- }
- return PyCursesCheckERR(rtn, "chgat");
+ switch (PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args,"l;attr", &lattr))
+ return NULL;
+ attr = lattr;
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = TRUE;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
+ return NULL;
+ }
+
+ color = (short)((attr >> 8) & 0xff);
+ attr = attr - (color << 8);
+
+ if (use_xy == TRUE) {
+ rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
+ touchline(self->win,y,1);
+ } else {
+ getyx(self->win,y,x);
+ rtn = wchgat(self->win,num,attr,color,NULL);
+ touchline(self->win,y,1);
+ }
+ return PyCursesCheckERR(rtn, "chgat");
}
static PyObject *
PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
{
- int rtn;
- int x, y;
+ int rtn;
+ int x, y;
- switch (PyTuple_Size(args)) {
- case 0:
- rtn = wdelch(self->win);
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
- return NULL;
- rtn = py_mvwdelch(self->win,y,x);
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
- return NULL;
- }
- return PyCursesCheckERR(rtn, "[mv]wdelch");
+ switch (PyTuple_Size(args)) {
+ case 0:
+ rtn = wdelch(self->win);
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
+ return NULL;
+ rtn = py_mvwdelch(self->win,y,x);
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
+ return NULL;
+ }
+ return PyCursesCheckERR(rtn, "[mv]wdelch");
}
static PyObject *
PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
{
- WINDOW *win;
- int nlines, ncols, begin_y, begin_x;
+ WINDOW *win;
+ int nlines, ncols, begin_y, begin_x;
- nlines = 0;
- ncols = 0;
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
- return NULL;
- break;
- case 4:
- if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
- &nlines,&ncols,&begin_y,&begin_x))
- return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
- return NULL;
- }
-
- win = derwin(self->win,nlines,ncols,begin_y,begin_x);
-
- if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
- return NULL;
- }
+ nlines = 0;
+ ncols = 0;
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
+ return NULL;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
+ &nlines,&ncols,&begin_y,&begin_x))
+ return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
+ return NULL;
+ }
- return (PyObject *)PyCursesWindow_New(win);
+ win = derwin(self->win,nlines,ncols,begin_y,begin_x);
+
+ if (win == NULL) {
+ PyErr_SetString(PyCursesError, catchall_NULL);
+ return NULL;
+ }
+
+ return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
{
- PyObject *temp;
- chtype ch;
- attr_t attr = A_NORMAL;
- long lattr;
-
- switch (PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
- return NULL;
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
- return NULL;
- attr = lattr;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
-
-
- return NULL;
- }
-
- if (!PyCurses_ConvertToChtype(temp, &ch)) {
- PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
- return NULL;
- }
-
+ PyObject *temp;
+ chtype ch;
+ attr_t attr = A_NORMAL;
+ long lattr;
+
+ switch (PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
+ return NULL;
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
+
+
+ return NULL;
+ }
+
+ if (!PyCurses_ConvertToChtype(temp, &ch)) {
+ PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
+ return NULL;
+ }
+
#ifdef WINDOW_HAS_FLAGS
- if (self->win->_flags & _ISPAD)
- return PyCursesCheckERR(pechochar(self->win, ch | attr),
- "echochar");
- else
+ if (self->win->_flags & _ISPAD)
+ return PyCursesCheckERR(pechochar(self->win, ch | attr),
+ "echochar");
+ else
#endif
- return PyCursesCheckERR(wechochar(self->win, ch | attr),
- "echochar");
+ return PyCursesCheckERR(wechochar(self->win, ch | attr),
+ "echochar");
}
#ifdef NCURSES_MOUSE_VERSION
static PyObject *
PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
{
- int x, y;
- if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
- return NULL;
+ int x, y;
+ if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
+ return NULL;
- return PyLong_FromLong( wenclose(self->win,y,x) );
+ return PyLong_FromLong( wenclose(self->win,y,x) );
}
#endif
static PyObject *
PyCursesWindow_GetBkgd(PyCursesWindowObject *self)
{
- return PyLong_FromLong((long) getbkgd(self->win));
+ return PyLong_FromLong((long) getbkgd(self->win));
}
static PyObject *
PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
{
- int x, y;
- int rtn;
+ int x, y;
+ int rtn;
- switch (PyTuple_Size(args)) {
- case 0:
- Py_BEGIN_ALLOW_THREADS
- rtn = wgetch(self->win);
- Py_END_ALLOW_THREADS
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- rtn = mvwgetch(self->win,y,x);
- Py_END_ALLOW_THREADS
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
- return NULL;
- }
- return PyLong_FromLong((long)rtn);
+ switch (PyTuple_Size(args)) {
+ case 0:
+ Py_BEGIN_ALLOW_THREADS
+ rtn = wgetch(self->win);
+ Py_END_ALLOW_THREADS
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ rtn = mvwgetch(self->win,y,x);
+ Py_END_ALLOW_THREADS
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
+ return NULL;
+ }
+ return PyLong_FromLong((long)rtn);
}
static PyObject *
PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
{
- int x, y;
- int rtn;
+ int x, y;
+ int rtn;
- switch (PyTuple_Size(args)) {
- case 0:
- Py_BEGIN_ALLOW_THREADS
- rtn = wgetch(self->win);
- Py_END_ALLOW_THREADS
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- rtn = mvwgetch(self->win,y,x);
- Py_END_ALLOW_THREADS
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
- return NULL;
- }
- if (rtn == ERR) {
- /* getch() returns ERR in nodelay mode */
- PyErr_SetString(PyCursesError, "no input");
- return NULL;
- } else if (rtn<=255) {
- return Py_BuildValue("C", rtn);
- } else {
- const char *knp;
+ switch (PyTuple_Size(args)) {
+ case 0:
+ Py_BEGIN_ALLOW_THREADS
+ rtn = wgetch(self->win);
+ Py_END_ALLOW_THREADS
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ rtn = mvwgetch(self->win,y,x);
+ Py_END_ALLOW_THREADS
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
+ return NULL;
+ }
+ if (rtn == ERR) {
+ /* getch() returns ERR in nodelay mode */
+ PyErr_SetString(PyCursesError, "no input");
+ return NULL;
+ } else if (rtn<=255) {
+ return Py_BuildValue("C", rtn);
+ } else {
+ const char *knp;
#if defined(__NetBSD__)
- knp = unctrl(rtn);
+ knp = unctrl(rtn);
#else
- knp = keyname(rtn);
+ knp = keyname(rtn);
#endif
- return PyUnicode_FromString((knp == NULL) ? "" : knp);
- }
+ return PyUnicode_FromString((knp == NULL) ? "" : knp);
+ }
}
static PyObject *
PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
{
- int x, y, n;
- char rtn[1024]; /* This should be big enough.. I hope */
- int rtn2;
-
- switch (PyTuple_Size(args)) {
- case 0:
- Py_BEGIN_ALLOW_THREADS
- rtn2 = wgetnstr(self->win,rtn, 1023);
- Py_END_ALLOW_THREADS
- break;
- case 1:
- if (!PyArg_ParseTuple(args,"i;n", &n))
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
- Py_END_ALLOW_THREADS
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
- return NULL;
- Py_BEGIN_ALLOW_THREADS
+ int x, y, n;
+ char rtn[1024]; /* This should be big enough.. I hope */
+ int rtn2;
+
+ switch (PyTuple_Size(args)) {
+ case 0:
+ Py_BEGIN_ALLOW_THREADS
+ rtn2 = wgetnstr(self->win,rtn, 1023);
+ Py_END_ALLOW_THREADS
+ break;
+ case 1:
+ if (!PyArg_ParseTuple(args,"i;n", &n))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
+ Py_END_ALLOW_THREADS
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
#ifdef STRICT_SYSV_CURSES
- rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
+ rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
#else
- rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
+ rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
#endif
- Py_END_ALLOW_THREADS
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
- return NULL;
+ Py_END_ALLOW_THREADS
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
+ return NULL;
#ifdef STRICT_SYSV_CURSES
- Py_BEGIN_ALLOW_THREADS
- rtn2 = wmove(self->win,y,x)==ERR ? ERR :
- wgetnstr(self->win, rtn, MIN(n, 1023));
- Py_END_ALLOW_THREADS
+ Py_BEGIN_ALLOW_THREADS
+ rtn2 = wmove(self->win,y,x)==ERR ? ERR :
+ wgetnstr(self->win, rtn, MIN(n, 1023));
+ Py_END_ALLOW_THREADS
#else
- Py_BEGIN_ALLOW_THREADS
- rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
- Py_END_ALLOW_THREADS
-#endif
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
- return NULL;
- }
- if (rtn2 == ERR)
- rtn[0] = 0;
- return PyBytes_FromString(rtn);
+ Py_BEGIN_ALLOW_THREADS
+ rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
+ Py_END_ALLOW_THREADS
+#endif
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
+ return NULL;
+ }
+ if (rtn2 == ERR)
+ rtn[0] = 0;
+ return PyBytes_FromString(rtn);
}
static PyObject *
PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
{
- PyObject *temp;
- chtype ch;
- int n, x, y, code = OK;
- attr_t attr = A_NORMAL;
- long lattr;
-
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
- return NULL;
- break;
- case 3:
- if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
- return NULL;
- attr = lattr;
- break;
- case 4:
- if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
- return NULL;
- code = wmove(self->win, y, x);
- break;
- case 5:
- if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
- &y, &x, &temp, &n, &lattr))
- return NULL;
- attr = lattr;
- code = wmove(self->win, y, x);
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
- return NULL;
- }
+ PyObject *temp;
+ chtype ch;
+ int n, x, y, code = OK;
+ attr_t attr = A_NORMAL;
+ long lattr;
- if (code != ERR) {
- if (!PyCurses_ConvertToChtype(temp, &ch)) {
- PyErr_SetString(PyExc_TypeError,
- "argument 1 or 3 must be a ch or an int");
- return NULL;
- }
- return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
- } else
- return PyCursesCheckERR(code, "wmove");
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
+ return NULL;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
+ return NULL;
+ code = wmove(self->win, y, x);
+ break;
+ case 5:
+ if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
+ &y, &x, &temp, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ code = wmove(self->win, y, x);
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
+ return NULL;
+ }
+
+ if (code != ERR) {
+ if (!PyCurses_ConvertToChtype(temp, &ch)) {
+ PyErr_SetString(PyExc_TypeError,
+ "argument 1 or 3 must be a ch or an int");
+ return NULL;
+ }
+ return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
+ } else
+ return PyCursesCheckERR(code, "wmove");
}
static PyObject *
PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
{
- int rtn, x, y, use_xy = FALSE;
- PyObject *temp;
- chtype ch = 0;
- attr_t attr = A_NORMAL;
- long lattr;
-
- switch (PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
- return NULL;
- break;
- case 2:
- if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
- return NULL;
- attr = lattr;
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
- return NULL;
- use_xy = TRUE;
- break;
- case 4:
- if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr))
- return NULL;
- attr = lattr;
- use_xy = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
- return NULL;
- }
-
- if (!PyCurses_ConvertToChtype(temp, &ch)) {
- PyErr_SetString(PyExc_TypeError,
- "argument 1 or 3 must be a ch or an int");
- return NULL;
- }
-
- if (use_xy == TRUE)
- rtn = mvwinsch(self->win,y,x, ch | attr);
- else {
- rtn = winsch(self->win, ch | attr);
- }
- return PyCursesCheckERR(rtn, "insch");
+ int rtn, x, y, use_xy = FALSE;
+ PyObject *temp;
+ chtype ch = 0;
+ attr_t attr = A_NORMAL;
+ long lattr;
+
+ switch (PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
+ return NULL;
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
+ return NULL;
+ use_xy = TRUE;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
+ return NULL;
+ }
+
+ if (!PyCurses_ConvertToChtype(temp, &ch)) {
+ PyErr_SetString(PyExc_TypeError,
+ "argument 1 or 3 must be a ch or an int");
+ return NULL;
+ }
+
+ if (use_xy == TRUE)
+ rtn = mvwinsch(self->win,y,x, ch | attr);
+ else {
+ rtn = winsch(self->win, ch | attr);
+ }
+ return PyCursesCheckERR(rtn, "insch");
}
static PyObject *
PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
{
- int x, y, rtn;
+ int x, y, rtn;
- switch (PyTuple_Size(args)) {
- case 0:
- rtn = winch(self->win);
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
- return NULL;
- rtn = mvwinch(self->win,y,x);
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
- return NULL;
- }
- return PyLong_FromLong((long) rtn);
+ switch (PyTuple_Size(args)) {
+ case 0:
+ rtn = winch(self->win);
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
+ return NULL;
+ rtn = mvwinch(self->win,y,x);
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
+ return NULL;
+ }
+ return PyLong_FromLong((long) rtn);
}
static PyObject *
PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
{
- int x, y, n;
- char rtn[1024]; /* This should be big enough.. I hope */
- int rtn2;
-
- switch (PyTuple_Size(args)) {
- case 0:
- rtn2 = winnstr(self->win,rtn, 1023);
- break;
- case 1:
- if (!PyArg_ParseTuple(args,"i;n", &n))
- return NULL;
- rtn2 = winnstr(self->win,rtn,MIN(n,1023));
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
- return NULL;
- rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
- break;
- case 3:
- if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
- return NULL;
- rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
- return NULL;
- }
- if (rtn2 == ERR)
- rtn[0] = 0;
- return PyBytes_FromString(rtn);
+ int x, y, n;
+ char rtn[1024]; /* This should be big enough.. I hope */
+ int rtn2;
+
+ switch (PyTuple_Size(args)) {
+ case 0:
+ rtn2 = winnstr(self->win,rtn, 1023);
+ break;
+ case 1:
+ if (!PyArg_ParseTuple(args,"i;n", &n))
+ return NULL;
+ rtn2 = winnstr(self->win,rtn,MIN(n,1023));
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
+ return NULL;
+ rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
+ return NULL;
+ rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
+ return NULL;
+ }
+ if (rtn2 == ERR)
+ rtn[0] = 0;
+ return PyBytes_FromString(rtn);
}
static PyObject *
PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
{
- int rtn;
- int x, y;
- char *str;
- attr_t attr = A_NORMAL , attr_old = A_NORMAL;
- long lattr;
- int use_xy = FALSE, use_attr = FALSE;
-
- switch (PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args,"s;str", &str))
- return NULL;
- break;
- case 2:
- if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
- return NULL;
- attr = lattr;
- use_attr = TRUE;
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str))
- return NULL;
- use_xy = TRUE;
- break;
- case 4:
- if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &lattr))
- return NULL;
- attr = lattr;
- use_xy = use_attr = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
- return NULL;
- }
-
- if (use_attr == TRUE) {
- attr_old = getattrs(self->win);
- (void)wattrset(self->win,attr);
- }
- if (use_xy == TRUE)
- rtn = mvwinsstr(self->win,y,x,str);
- else
- rtn = winsstr(self->win,str);
- if (use_attr == TRUE)
- (void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, "insstr");
+ int rtn;
+ int x, y;
+ char *str;
+ attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+ long lattr;
+ int use_xy = FALSE, use_attr = FALSE;
+
+ switch (PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args,"s;str", &str))
+ return NULL;
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
+ return NULL;
+ attr = lattr;
+ use_attr = TRUE;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str))
+ return NULL;
+ use_xy = TRUE;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = use_attr = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
+ return NULL;
+ }
+
+ if (use_attr == TRUE) {
+ attr_old = getattrs(self->win);
+ (void)wattrset(self->win,attr);
+ }
+ if (use_xy == TRUE)
+ rtn = mvwinsstr(self->win,y,x,str);
+ else
+ rtn = winsstr(self->win,str);
+ if (use_attr == TRUE)
+ (void)wattrset(self->win,attr_old);
+ return PyCursesCheckERR(rtn, "insstr");
}
static PyObject *
PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
{
- int rtn, x, y, n;
- char *str;
- attr_t attr = A_NORMAL , attr_old = A_NORMAL;
- long lattr;
- int use_xy = FALSE, use_attr = FALSE;
-
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
- return NULL;
- break;
- case 3:
- if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
- return NULL;
- attr = lattr;
- use_attr = TRUE;
- break;
- case 4:
- if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
- return NULL;
- use_xy = TRUE;
- break;
- case 5:
- if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
- return NULL;
- attr = lattr;
- use_xy = use_attr = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
- return NULL;
- }
-
- if (use_attr == TRUE) {
- attr_old = getattrs(self->win);
- (void)wattrset(self->win,attr);
- }
- if (use_xy == TRUE)
- rtn = mvwinsnstr(self->win,y,x,str,n);
- else
- rtn = winsnstr(self->win,str,n);
- if (use_attr == TRUE)
- (void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, "insnstr");
+ int rtn, x, y, n;
+ char *str;
+ attr_t attr = A_NORMAL , attr_old = A_NORMAL;
+ long lattr;
+ int use_xy = FALSE, use_attr = FALSE;
+
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
+ return NULL;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ use_attr = TRUE;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
+ return NULL;
+ use_xy = TRUE;
+ break;
+ case 5:
+ if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ use_xy = use_attr = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
+ return NULL;
+ }
+
+ if (use_attr == TRUE) {
+ attr_old = getattrs(self->win);
+ (void)wattrset(self->win,attr);
+ }
+ if (use_xy == TRUE)
+ rtn = mvwinsnstr(self->win,y,x,str,n);
+ else
+ rtn = winsnstr(self->win,str,n);
+ if (use_attr == TRUE)
+ (void)wattrset(self->win,attr_old);
+ return PyCursesCheckERR(rtn, "insnstr");
}
static PyObject *
PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
{
- int line, erg;
- if (!PyArg_ParseTuple(args,"i;line", &line))
- return NULL;
- erg = is_linetouched(self->win, line);
- if (erg == ERR) {
- PyErr_SetString(PyExc_TypeError,
- "is_linetouched: line number outside of boundaries");
- return NULL;
- } else
- if (erg == FALSE) {
- Py_INCREF(Py_False);
- return Py_False;
- } else {
- Py_INCREF(Py_True);
- return Py_True;
- }
+ int line, erg;
+ if (!PyArg_ParseTuple(args,"i;line", &line))
+ return NULL;
+ erg = is_linetouched(self->win, line);
+ if (erg == ERR) {
+ PyErr_SetString(PyExc_TypeError,
+ "is_linetouched: line number outside of boundaries");
+ return NULL;
+ } else
+ if (erg == FALSE) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ } else {
+ Py_INCREF(Py_True);
+ return Py_True;
+ }
}
static PyObject *
PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
{
- int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
- int rtn;
+ int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
+ int rtn;
#ifndef WINDOW_HAS_FLAGS
- if (0)
+ if (0)
#else
- if (self->win->_flags & _ISPAD)
+ if (self->win->_flags & _ISPAD)
#endif
- {
- switch(PyTuple_Size(args)) {
- case 6:
- if (!PyArg_ParseTuple(args,
- "iiiiii;" \
- "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
- &pminrow, &pmincol, &sminrow,
- &smincol, &smaxrow, &smaxcol))
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- rtn = pnoutrefresh(self->win,
- pminrow, pmincol, sminrow,
- smincol, smaxrow, smaxcol);
- Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "pnoutrefresh");
- default:
- PyErr_SetString(PyCursesError,
- "noutrefresh() called for a pad "
- "requires 6 arguments");
- return NULL;
- }
- } else {
- if (!PyArg_ParseTuple(args, ":noutrefresh"))
- return NULL;
-
- Py_BEGIN_ALLOW_THREADS
- rtn = wnoutrefresh(self->win);
- Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "wnoutrefresh");
- }
+ {
+ switch(PyTuple_Size(args)) {
+ case 6:
+ if (!PyArg_ParseTuple(args,
+ "iiiiii;" \
+ "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
+ &pminrow, &pmincol, &sminrow,
+ &smincol, &smaxrow, &smaxcol))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ rtn = pnoutrefresh(self->win,
+ pminrow, pmincol, sminrow,
+ smincol, smaxrow, smaxcol);
+ Py_END_ALLOW_THREADS
+ return PyCursesCheckERR(rtn, "pnoutrefresh");
+ default:
+ PyErr_SetString(PyCursesError,
+ "noutrefresh() called for a pad "
+ "requires 6 arguments");
+ return NULL;
+ }
+ } else {
+ if (!PyArg_ParseTuple(args, ":noutrefresh"))
+ return NULL;
+
+ Py_BEGIN_ALLOW_THREADS
+ rtn = wnoutrefresh(self->win);
+ Py_END_ALLOW_THREADS
+ return PyCursesCheckERR(rtn, "wnoutrefresh");
+ }
}
static PyObject *
@@ -1286,34 +1286,34 @@
int use_copywin = FALSE;
int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
int rtn;
-
+
switch (PyTuple_Size(args)) {
case 1:
- if (!PyArg_ParseTuple(args, "O!;window object",
- &PyCursesWindow_Type, &temp))
- return NULL;
- break;
+ if (!PyArg_ParseTuple(args, "O!;window object",
+ &PyCursesWindow_Type, &temp))
+ return NULL;
+ break;
case 7:
- if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
- &PyCursesWindow_Type, &temp, &sminrow, &smincol,
- &dminrow, &dmincol, &dmaxrow, &dmaxcol))
- return NULL;
- use_copywin = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError,
- "overlay requires one or seven arguments");
- return NULL;
+ if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
+ &PyCursesWindow_Type, &temp, &sminrow, &smincol,
+ &dminrow, &dmincol, &dmaxrow, &dmaxcol))
+ return NULL;
+ use_copywin = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError,
+ "overlay requires one or seven arguments");
+ return NULL;
}
if (use_copywin == TRUE) {
- rtn = copywin(self->win, temp->win, sminrow, smincol,
- dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
- return PyCursesCheckERR(rtn, "copywin");
+ rtn = copywin(self->win, temp->win, sminrow, smincol,
+ dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
+ return PyCursesCheckERR(rtn, "copywin");
}
else {
- rtn = overlay(self->win, temp->win);
- return PyCursesCheckERR(rtn, "overlay");
+ rtn = overlay(self->win, temp->win);
+ return PyCursesCheckERR(rtn, "overlay");
}
}
@@ -1324,377 +1324,377 @@
int use_copywin = FALSE;
int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
int rtn;
-
+
switch (PyTuple_Size(args)) {
case 1:
- if (!PyArg_ParseTuple(args, "O!;window object",
- &PyCursesWindow_Type, &temp))
- return NULL;
- break;
+ if (!PyArg_ParseTuple(args, "O!;window object",
+ &PyCursesWindow_Type, &temp))
+ return NULL;
+ break;
case 7:
- if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
- &PyCursesWindow_Type, &temp, &sminrow, &smincol,
- &dminrow, &dmincol, &dmaxrow, &dmaxcol))
- return NULL;
- use_copywin = TRUE;
- break;
- default:
- PyErr_SetString(PyExc_TypeError,
- "overwrite requires one or seven arguments");
- return NULL;
+ if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
+ &PyCursesWindow_Type, &temp, &sminrow, &smincol,
+ &dminrow, &dmincol, &dmaxrow, &dmaxcol))
+ return NULL;
+ use_copywin = TRUE;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError,
+ "overwrite requires one or seven arguments");
+ return NULL;
}
if (use_copywin == TRUE) {
- rtn = copywin(self->win, temp->win, sminrow, smincol,
- dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
+ rtn = copywin(self->win, temp->win, sminrow, smincol,
+ dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
return PyCursesCheckERR(rtn, "copywin");
}
else {
- rtn = overwrite(self->win, temp->win);
- return PyCursesCheckERR(rtn, "overwrite");
+ rtn = overwrite(self->win, temp->win);
+ return PyCursesCheckERR(rtn, "overwrite");
}
}
static PyObject *
PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream)
{
- /* We have to simulate this by writing to a temporary FILE*,
- then reading back, then writing to the argument stream. */
- char fn[100];
- int fd;
- FILE *fp;
- PyObject *res;
-
- strcpy(fn, "/tmp/py.curses.putwin.XXXXXX");
- fd = mkstemp(fn);
- if (fd < 0)
- return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
- fp = fdopen(fd, "wb+");
- if (fp == NULL) {
- close(fd);
- remove(fn);
- return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
- }
- res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
- if (res == NULL) {
+ /* We have to simulate this by writing to a temporary FILE*,
+ then reading back, then writing to the argument stream. */
+ char fn[100];
+ int fd;
+ FILE *fp;
+ PyObject *res;
+
+ strcpy(fn, "/tmp/py.curses.putwin.XXXXXX");
+ fd = mkstemp(fn);
+ if (fd < 0)
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+ fp = fdopen(fd, "wb+");
+ if (fp == NULL) {
+ close(fd);
+ remove(fn);
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+ }
+ res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
+ if (res == NULL) {
+ fclose(fp);
+ remove(fn);
+ return res;
+ }
+ fseek(fp, 0, 0);
+ while (1) {
+ char buf[BUFSIZ];
+ Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);
+ if (n <= 0)
+ break;
+ Py_DECREF(res);
+ res = PyObject_CallMethod(stream, "write", "y#", buf, n);
+ if (res == NULL)
+ break;
+ }
fclose(fp);
remove(fn);
return res;
- }
- fseek(fp, 0, 0);
- while (1) {
- char buf[BUFSIZ];
- Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);
- if (n <= 0)
- break;
- Py_DECREF(res);
- res = PyObject_CallMethod(stream, "write", "y#", buf, n);
- if (res == NULL)
- break;
- }
- fclose(fp);
- remove(fn);
- return res;
}
static PyObject *
PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
{
- int beg, num;
- if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num))
- return NULL;
- return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
+ int beg, num;
+ if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num))
+ return NULL;
+ return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
}
static PyObject *
PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
{
- int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
- int rtn;
-
+ int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
+ int rtn;
+
#ifndef WINDOW_HAS_FLAGS
- if (0)
+ if (0)
#else
- if (self->win->_flags & _ISPAD)
+ if (self->win->_flags & _ISPAD)
#endif
- {
- switch(PyTuple_Size(args)) {
- case 6:
- if (!PyArg_ParseTuple(args,
- "iiiiii;" \
- "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
- &pminrow, &pmincol, &sminrow,
- &smincol, &smaxrow, &smaxcol))
- return NULL;
-
- Py_BEGIN_ALLOW_THREADS
- rtn = prefresh(self->win,
- pminrow, pmincol, sminrow,
- smincol, smaxrow, smaxcol);
- Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "prefresh");
- default:
- PyErr_SetString(PyCursesError,
- "refresh() for a pad requires 6 arguments");
- return NULL;
- }
- } else {
- if (!PyArg_ParseTuple(args, ":refresh"))
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- rtn = wrefresh(self->win);
- Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "prefresh");
- }
+ {
+ switch(PyTuple_Size(args)) {
+ case 6:
+ if (!PyArg_ParseTuple(args,
+ "iiiiii;" \
+ "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
+ &pminrow, &pmincol, &sminrow,
+ &smincol, &smaxrow, &smaxcol))
+ return NULL;
+
+ Py_BEGIN_ALLOW_THREADS
+ rtn = prefresh(self->win,
+ pminrow, pmincol, sminrow,
+ smincol, smaxrow, smaxcol);
+ Py_END_ALLOW_THREADS
+ return PyCursesCheckERR(rtn, "prefresh");
+ default:
+ PyErr_SetString(PyCursesError,
+ "refresh() for a pad requires 6 arguments");
+ return NULL;
+ }
+ } else {
+ if (!PyArg_ParseTuple(args, ":refresh"))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ rtn = wrefresh(self->win);
+ Py_END_ALLOW_THREADS
+ return PyCursesCheckERR(rtn, "prefresh");
+ }
}
static PyObject *
PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
{
- int x, y;
- if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
- return NULL;
- return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
+ int x, y;
+ if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
+ return NULL;
+ return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
}
static PyObject *
PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
{
- WINDOW *win;
- int nlines, ncols, begin_y, begin_x;
+ WINDOW *win;
+ int nlines, ncols, begin_y, begin_x;
- nlines = 0;
- ncols = 0;
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
- return NULL;
- break;
- case 4:
- if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
- &nlines,&ncols,&begin_y,&begin_x))
- return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
- return NULL;
- }
+ nlines = 0;
+ ncols = 0;
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
+ return NULL;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
+ &nlines,&ncols,&begin_y,&begin_x))
+ return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
+ return NULL;
+ }
- /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
+ /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
#ifdef WINDOW_HAS_FLAGS
- if (self->win->_flags & _ISPAD)
- win = subpad(self->win, nlines, ncols, begin_y, begin_x);
- else
-#endif
- win = subwin(self->win, nlines, ncols, begin_y, begin_x);
-
- if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
- return NULL;
- }
-
- return (PyObject *)PyCursesWindow_New(win);
+ if (self->win->_flags & _ISPAD)
+ win = subpad(self->win, nlines, ncols, begin_y, begin_x);
+ else
+#endif
+ win = subwin(self->win, nlines, ncols, begin_y, begin_x);
+
+ if (win == NULL) {
+ PyErr_SetString(PyCursesError, catchall_NULL);
+ return NULL;
+ }
+
+ return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
{
- int nlines;
- switch(PyTuple_Size(args)) {
- case 0:
- return PyCursesCheckERR(scroll(self->win), "scroll");
- case 1:
- if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
- return NULL;
- return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
- default:
- PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
- return NULL;
- }
+ int nlines;
+ switch(PyTuple_Size(args)) {
+ case 0:
+ return PyCursesCheckERR(scroll(self->win), "scroll");
+ case 1:
+ if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
+ return NULL;
+ return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
+ default:
+ PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
+ return NULL;
+ }
}
static PyObject *
PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
{
- int st, cnt, val;
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
- return NULL;
- return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
- case 3:
- if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
- return NULL;
- return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
- default:
- PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
- return NULL;
- }
+ int st, cnt, val;
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
+ return NULL;
+ return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
+ case 3:
+ if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
+ return NULL;
+ return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
+ default:
+ PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
+ return NULL;
+ }
}
static PyObject *
PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
{
- PyObject *temp;
- chtype ch;
- int n, x, y, code = OK;
- attr_t attr = A_NORMAL;
- long lattr;
-
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
- return NULL;
- break;
- case 3:
- if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
- return NULL;
- attr = lattr;
- break;
- case 4:
- if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
- return NULL;
- code = wmove(self->win, y, x);
- break;
- case 5:
- if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
- &y, &x, &temp, &n, &lattr))
- return NULL;
- attr = lattr;
- code = wmove(self->win, y, x);
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
- return NULL;
- }
+ PyObject *temp;
+ chtype ch;
+ int n, x, y, code = OK;
+ attr_t attr = A_NORMAL;
+ long lattr;
- if (code != ERR) {
- if (!PyCurses_ConvertToChtype(temp, &ch)) {
- PyErr_SetString(PyExc_TypeError,
- "argument 1 or 3 must be a ch or an int");
- return NULL;
- }
- return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
- } else
- return PyCursesCheckERR(code, "wmove");
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
+ return NULL;
+ break;
+ case 3:
+ if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
+ return NULL;
+ code = wmove(self->win, y, x);
+ break;
+ case 5:
+ if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
+ &y, &x, &temp, &n, &lattr))
+ return NULL;
+ attr = lattr;
+ code = wmove(self->win, y, x);
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
+ return NULL;
+ }
+
+ if (code != ERR) {
+ if (!PyCurses_ConvertToChtype(temp, &ch)) {
+ PyErr_SetString(PyExc_TypeError,
+ "argument 1 or 3 must be a ch or an int");
+ return NULL;
+ }
+ return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
+ } else
+ return PyCursesCheckERR(code, "wmove");
}
static PyMethodDef PyCursesWindow_Methods[] = {
- {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
- {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
- {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
- {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS},
- {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS},
- {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS},
- {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
- {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
- {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
- {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
- {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
- {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
- {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
- {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
- {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
- {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
- {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
- {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
- {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
- {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
+ {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
+ {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
+ {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
+ {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS},
+ {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS},
+ {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS},
+ {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
+ {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
+ {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
+ {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
+ {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
+ {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
+ {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
+ {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
+ {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
+ {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
+ {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
+ {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
+ {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
+ {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
#ifdef NCURSES_MOUSE_VERSION
- {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
+ {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
#endif
- {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
- {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
- {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
- {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
- {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
- {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
- {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
- {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
- {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
- {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
- {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
- {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
- {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
- {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
- {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
- {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
- {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
- {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
- {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
- {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
- {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
- {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
- {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
- {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
- {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
- {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
- {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
- {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
- {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
- {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
- /* Backward compatibility alias -- remove in Python 2.3 */
- {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
- {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
- {"overwrite", (PyCFunction)PyCursesWindow_Overwrite,
- METH_VARARGS},
- {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O},
- {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS},
- {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
- {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
+ {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
+ {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
+ {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
+ {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
+ {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
+ {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
+ {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
+ {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
+ {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
+ {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
+ {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
+ {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
+ {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
+ {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
+ {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
+ {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
+ {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
+ {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
+ {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
+ {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
+ {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
+ {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
+ {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
+ {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
+ {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
+ {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
+ {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
+ {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
+ {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
+ {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
+ /* Backward compatibility alias -- remove in Python 2.3 */
+ {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
+ {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
+ {"overwrite", (PyCFunction)PyCursesWindow_Overwrite,
+ METH_VARARGS},
+ {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O},
+ {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS},
+ {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
+ {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
#ifndef STRICT_SYSV_CURSES
- {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
+ {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
#endif
- {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
- {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
- {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
- {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
- {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
- {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
- {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
- {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
- {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
- {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
- {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
- {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
- {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
- {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
- {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
- {NULL, NULL} /* sentinel */
+ {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
+ {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
+ {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
+ {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
+ {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
+ {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
+ {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
+ {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
+ {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
+ {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
+ {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
+ {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
+ {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
+ {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
+ {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
+ {NULL, NULL} /* sentinel */
};
/* -------------------------------------------------------*/
PyTypeObject PyCursesWindow_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "_curses.curses window", /*tp_name*/
- sizeof(PyCursesWindowObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)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*/
- PyCursesWindow_Methods, /*tp_methods*/
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "_curses.curses window", /*tp_name*/
+ sizeof(PyCursesWindowObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)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*/
+ PyCursesWindow_Methods, /*tp_methods*/
};
/*********************************************************************
@@ -1738,452 +1738,452 @@
static PyObject *
PyCurses_filter(PyObject *self)
{
- /* not checking for PyCursesInitialised here since filter() must
- be called before initscr() */
- filter();
- Py_INCREF(Py_None);
- return Py_None;
+ /* not checking for PyCursesInitialised here since filter() must
+ be called before initscr() */
+ filter();
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyObject *
PyCurses_Color_Content(PyObject *self, PyObject *args)
{
- short color,r,g,b;
+ short color,r,g,b;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesInitialised;
+ PyCursesInitialisedColor;
- if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
+ if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
- if (color_content(color, &r, &g, &b) != ERR)
- return Py_BuildValue("(iii)", r, g, b);
- else {
- PyErr_SetString(PyCursesError,
- "Argument 1 was out of range. Check value of COLORS.");
- return NULL;
- }
+ if (color_content(color, &r, &g, &b) != ERR)
+ return Py_BuildValue("(iii)", r, g, b);
+ else {
+ PyErr_SetString(PyCursesError,
+ "Argument 1 was out of range. Check value of COLORS.");
+ return NULL;
+ }
}
static PyObject *
PyCurses_color_pair(PyObject *self, PyObject *args)
{
- int n;
+ int n;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesInitialised;
+ PyCursesInitialisedColor;
- if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
- return PyLong_FromLong((long) (n << 8));
+ if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
+ return PyLong_FromLong((long) (n << 8));
}
static PyObject *
PyCurses_Curs_Set(PyObject *self, PyObject *args)
{
- int vis,erg;
+ int vis,erg;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
+ if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
- erg = curs_set(vis);
- if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
+ erg = curs_set(vis);
+ if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
- return PyLong_FromLong((long) erg);
+ return PyLong_FromLong((long) erg);
}
static PyObject *
PyCurses_Delay_Output(PyObject *self, PyObject *args)
{
- int ms;
+ int ms;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
+ if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
- return PyCursesCheckERR(delay_output(ms), "delay_output");
+ return PyCursesCheckERR(delay_output(ms), "delay_output");
}
static PyObject *
PyCurses_EraseChar(PyObject *self)
{
- char ch;
+ char ch;
- PyCursesInitialised;
+ PyCursesInitialised;
- ch = erasechar();
+ ch = erasechar();
- return PyBytes_FromStringAndSize(&ch, 1);
+ return PyBytes_FromStringAndSize(&ch, 1);
}
static PyObject *
PyCurses_getsyx(PyObject *self)
{
- int x = 0;
- int y = 0;
+ int x = 0;
+ int y = 0;
- PyCursesInitialised;
+ PyCursesInitialised;
- getsyx(y, x);
+ getsyx(y, x);
- return Py_BuildValue("(ii)", y, x);
+ return Py_BuildValue("(ii)", y, x);
}
#ifdef NCURSES_MOUSE_VERSION
static PyObject *
PyCurses_GetMouse(PyObject *self)
{
- int rtn;
- MEVENT event;
+ int rtn;
+ MEVENT event;
- PyCursesInitialised;
+ PyCursesInitialised;
- rtn = getmouse( &event );
- if (rtn == ERR) {
- PyErr_SetString(PyCursesError, "getmouse() returned ERR");
- return NULL;
- }
- return Py_BuildValue("(hiiil)",
- (short)event.id,
- event.x, event.y, event.z,
- (long) event.bstate);
+ rtn = getmouse( &event );
+ if (rtn == ERR) {
+ PyErr_SetString(PyCursesError, "getmouse() returned ERR");
+ return NULL;
+ }
+ return Py_BuildValue("(hiiil)",
+ (short)event.id,
+ event.x, event.y, event.z,
+ (long) event.bstate);
}
static PyObject *
PyCurses_UngetMouse(PyObject *self, PyObject *args)
{
- MEVENT event;
+ MEVENT event;
- PyCursesInitialised;
- if (!PyArg_ParseTuple(args, "hiiil",
- &event.id,
- &event.x, &event.y, &event.z,
- (int *) &event.bstate))
- return NULL;
+ PyCursesInitialised;
+ if (!PyArg_ParseTuple(args, "hiiil",
+ &event.id,
+ &event.x, &event.y, &event.z,
+ (int *) &event.bstate))
+ return NULL;
- return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
+ return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
}
#endif
static PyObject *
PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
{
- char fn[100];
- int fd;
- FILE *fp;
- PyObject *data;
- size_t datalen;
- WINDOW *win;
-
- PyCursesInitialised;
-
- strcpy(fn, "/tmp/py.curses.getwin.XXXXXX");
- fd = mkstemp(fn);
- if (fd < 0)
- return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
- fp = fdopen(fd, "wb+");
- if (fp == NULL) {
- close(fd);
- remove(fn);
- return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
- }
- data = PyObject_CallMethod(stream, "read", "");
- if (data == NULL) {
- fclose(fp);
- remove(fn);
- return NULL;
- }
- if (!PyBytes_Check(data)) {
- PyErr_Format(PyExc_TypeError,
- "f.read() returned %.100s instead of bytes",
- data->ob_type->tp_name);
- Py_DECREF(data);
- fclose(fp);
- remove(fn);
- return NULL;
- }
- datalen = PyBytes_GET_SIZE(data);
- if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
+ char fn[100];
+ int fd;
+ FILE *fp;
+ PyObject *data;
+ size_t datalen;
+ WINDOW *win;
+
+ PyCursesInitialised;
+
+ strcpy(fn, "/tmp/py.curses.getwin.XXXXXX");
+ fd = mkstemp(fn);
+ if (fd < 0)
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+ fp = fdopen(fd, "wb+");
+ if (fp == NULL) {
+ close(fd);
+ remove(fn);
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+ }
+ data = PyObject_CallMethod(stream, "read", "");
+ if (data == NULL) {
+ fclose(fp);
+ remove(fn);
+ return NULL;
+ }
+ if (!PyBytes_Check(data)) {
+ PyErr_Format(PyExc_TypeError,
+ "f.read() returned %.100s instead of bytes",
+ data->ob_type->tp_name);
+ Py_DECREF(data);
+ fclose(fp);
+ remove(fn);
+ return NULL;
+ }
+ datalen = PyBytes_GET_SIZE(data);
+ if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
+ Py_DECREF(data);
+ fclose(fp);
+ remove(fn);
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+ }
Py_DECREF(data);
+ fseek(fp, 0, 0);
+ win = getwin(fp);
fclose(fp);
remove(fn);
- return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
- }
- Py_DECREF(data);
- fseek(fp, 0, 0);
- win = getwin(fp);
- fclose(fp);
- remove(fn);
- if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
- return NULL;
- }
- return PyCursesWindow_New(win);
+ if (win == NULL) {
+ PyErr_SetString(PyCursesError, catchall_NULL);
+ return NULL;
+ }
+ return PyCursesWindow_New(win);
}
static PyObject *
PyCurses_HalfDelay(PyObject *self, PyObject *args)
{
- unsigned char tenths;
+ unsigned char tenths;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
+ if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
- return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
+ return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
}
#ifndef STRICT_SYSV_CURSES
- /* No has_key! */
+/* No has_key! */
static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
{
- int ch;
+ int ch;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
+ if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
- if (has_key(ch) == FALSE) {
- Py_INCREF(Py_False);
- return Py_False;
- }
- Py_INCREF(Py_True);
- return Py_True;
+ if (has_key(ch) == FALSE) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ Py_INCREF(Py_True);
+ return Py_True;
}
#endif /* STRICT_SYSV_CURSES */
static PyObject *
PyCurses_Init_Color(PyObject *self, PyObject *args)
{
- short color, r, g, b;
+ short color, r, g, b;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesInitialised;
+ PyCursesInitialisedColor;
- switch(PyTuple_Size(args)) {
- case 4:
- if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
- return NULL;
- }
+ switch(PyTuple_Size(args)) {
+ case 4:
+ if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
+ return NULL;
+ }
- return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
+ return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
}
static PyObject *
PyCurses_Init_Pair(PyObject *self, PyObject *args)
{
- short pair, f, b;
+ short pair, f, b;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesInitialised;
+ PyCursesInitialisedColor;
- if (PyTuple_Size(args) != 3) {
- PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
- return NULL;
- }
+ if (PyTuple_Size(args) != 3) {
+ PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
+ return NULL;
+ }
- if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
+ if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
- return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
+ return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
}
static PyObject *ModDict;
-static PyObject *
+static PyObject *
PyCurses_InitScr(PyObject *self)
{
- WINDOW *win;
+ WINDOW *win;
- if (initialised == TRUE) {
- wrefresh(stdscr);
- return (PyObject *)PyCursesWindow_New(stdscr);
- }
+ if (initialised == TRUE) {
+ wrefresh(stdscr);
+ return (PyObject *)PyCursesWindow_New(stdscr);
+ }
- win = initscr();
+ win = initscr();
- if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
- return NULL;
- }
+ if (win == NULL) {
+ PyErr_SetString(PyCursesError, catchall_NULL);
+ return NULL;
+ }
- initialised = initialised_setupterm = TRUE;
+ initialised = initialised_setupterm = TRUE;
/* This was moved from initcurses() because it core dumped on SGI,
where they're not defined until you've called initscr() */
-#define SetDictInt(string,ch) \
- do { \
- PyObject *o = PyLong_FromLong((long) (ch)); \
- if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
- Py_DECREF(o); \
- } \
+#define SetDictInt(string,ch) \
+ do { \
+ PyObject *o = PyLong_FromLong((long) (ch)); \
+ if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
+ Py_DECREF(o); \
+ } \
} while (0)
- /* Here are some graphic symbols you can use */
- SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
- SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
- SetDictInt("ACS_URCORNER", (ACS_URCORNER));
- SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
- SetDictInt("ACS_LTEE", (ACS_LTEE));
- SetDictInt("ACS_RTEE", (ACS_RTEE));
- SetDictInt("ACS_BTEE", (ACS_BTEE));
- SetDictInt("ACS_TTEE", (ACS_TTEE));
- SetDictInt("ACS_HLINE", (ACS_HLINE));
- SetDictInt("ACS_VLINE", (ACS_VLINE));
- SetDictInt("ACS_PLUS", (ACS_PLUS));
+ /* Here are some graphic symbols you can use */
+ SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
+ SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
+ SetDictInt("ACS_URCORNER", (ACS_URCORNER));
+ SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
+ SetDictInt("ACS_LTEE", (ACS_LTEE));
+ SetDictInt("ACS_RTEE", (ACS_RTEE));
+ SetDictInt("ACS_BTEE", (ACS_BTEE));
+ SetDictInt("ACS_TTEE", (ACS_TTEE));
+ SetDictInt("ACS_HLINE", (ACS_HLINE));
+ SetDictInt("ACS_VLINE", (ACS_VLINE));
+ SetDictInt("ACS_PLUS", (ACS_PLUS));
#if !defined(__hpux) || defined(HAVE_NCURSES_H)
- /* On HP/UX 11, these are of type cchar_t, which is not an
- integral type. If this is a problem on more platforms, a
- configure test should be added to determine whether ACS_S1
- is of integral type. */
- SetDictInt("ACS_S1", (ACS_S1));
- SetDictInt("ACS_S9", (ACS_S9));
- SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
- SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
- SetDictInt("ACS_DEGREE", (ACS_DEGREE));
- SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
- SetDictInt("ACS_BULLET", (ACS_BULLET));
- SetDictInt("ACS_LARROW", (ACS_LARROW));
- SetDictInt("ACS_RARROW", (ACS_RARROW));
- SetDictInt("ACS_DARROW", (ACS_DARROW));
- SetDictInt("ACS_UARROW", (ACS_UARROW));
- SetDictInt("ACS_BOARD", (ACS_BOARD));
- SetDictInt("ACS_LANTERN", (ACS_LANTERN));
- SetDictInt("ACS_BLOCK", (ACS_BLOCK));
-#endif
- SetDictInt("ACS_BSSB", (ACS_ULCORNER));
- SetDictInt("ACS_SSBB", (ACS_LLCORNER));
- SetDictInt("ACS_BBSS", (ACS_URCORNER));
- SetDictInt("ACS_SBBS", (ACS_LRCORNER));
- SetDictInt("ACS_SBSS", (ACS_RTEE));
- SetDictInt("ACS_SSSB", (ACS_LTEE));
- SetDictInt("ACS_SSBS", (ACS_BTEE));
- SetDictInt("ACS_BSSS", (ACS_TTEE));
- SetDictInt("ACS_BSBS", (ACS_HLINE));
- SetDictInt("ACS_SBSB", (ACS_VLINE));
- SetDictInt("ACS_SSSS", (ACS_PLUS));
+ /* On HP/UX 11, these are of type cchar_t, which is not an
+ integral type. If this is a problem on more platforms, a
+ configure test should be added to determine whether ACS_S1
+ is of integral type. */
+ SetDictInt("ACS_S1", (ACS_S1));
+ SetDictInt("ACS_S9", (ACS_S9));
+ SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
+ SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
+ SetDictInt("ACS_DEGREE", (ACS_DEGREE));
+ SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
+ SetDictInt("ACS_BULLET", (ACS_BULLET));
+ SetDictInt("ACS_LARROW", (ACS_LARROW));
+ SetDictInt("ACS_RARROW", (ACS_RARROW));
+ SetDictInt("ACS_DARROW", (ACS_DARROW));
+ SetDictInt("ACS_UARROW", (ACS_UARROW));
+ SetDictInt("ACS_BOARD", (ACS_BOARD));
+ SetDictInt("ACS_LANTERN", (ACS_LANTERN));
+ SetDictInt("ACS_BLOCK", (ACS_BLOCK));
+#endif
+ SetDictInt("ACS_BSSB", (ACS_ULCORNER));
+ SetDictInt("ACS_SSBB", (ACS_LLCORNER));
+ SetDictInt("ACS_BBSS", (ACS_URCORNER));
+ SetDictInt("ACS_SBBS", (ACS_LRCORNER));
+ SetDictInt("ACS_SBSS", (ACS_RTEE));
+ SetDictInt("ACS_SSSB", (ACS_LTEE));
+ SetDictInt("ACS_SSBS", (ACS_BTEE));
+ SetDictInt("ACS_BSSS", (ACS_TTEE));
+ SetDictInt("ACS_BSBS", (ACS_HLINE));
+ SetDictInt("ACS_SBSB", (ACS_VLINE));
+ SetDictInt("ACS_SSSS", (ACS_PLUS));
- /* The following are never available with strict SYSV curses */
+ /* The following are never available with strict SYSV curses */
#ifdef ACS_S3
- SetDictInt("ACS_S3", (ACS_S3));
+ SetDictInt("ACS_S3", (ACS_S3));
#endif
#ifdef ACS_S7
- SetDictInt("ACS_S7", (ACS_S7));
+ SetDictInt("ACS_S7", (ACS_S7));
#endif
#ifdef ACS_LEQUAL
- SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
+ SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
#endif
#ifdef ACS_GEQUAL
- SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
+ SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
#endif
#ifdef ACS_PI
- SetDictInt("ACS_PI", (ACS_PI));
+ SetDictInt("ACS_PI", (ACS_PI));
#endif
#ifdef ACS_NEQUAL
- SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
+ SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
#endif
#ifdef ACS_STERLING
- SetDictInt("ACS_STERLING", (ACS_STERLING));
+ SetDictInt("ACS_STERLING", (ACS_STERLING));
#endif
- SetDictInt("LINES", LINES);
- SetDictInt("COLS", COLS);
+ SetDictInt("LINES", LINES);
+ SetDictInt("COLS", COLS);
- return (PyObject *)PyCursesWindow_New(win);
+ return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
{
- int fd = -1;
- int err;
- char* termstr = NULL;
-
- static char *kwlist[] = {"term", "fd", NULL};
-
- if (!PyArg_ParseTupleAndKeywords(
- args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) {
- return NULL;
- }
-
- if (fd == -1) {
- PyObject* sys_stdout;
-
- sys_stdout = PySys_GetObject("stdout");
-
- if (sys_stdout == NULL || sys_stdout == Py_None) {
- PyErr_SetString(
- PyCursesError,
- "lost sys.stdout");
- return NULL;
- }
-
- fd = PyObject_AsFileDescriptor(sys_stdout);
-
- if (fd == -1) {
- return NULL;
- }
- }
-
- if (setupterm(termstr,fd,&err) == ERR) {
- char* s = "setupterm: unknown error";
-
- if (err == 0) {
- s = "setupterm: could not find terminal";
- } else if (err == -1) {
- s = "setupterm: could not find terminfo database";
- }
-
- PyErr_SetString(PyCursesError,s);
- return NULL;
- }
+ int fd = -1;
+ int err;
+ char* termstr = NULL;
- initialised_setupterm = TRUE;
+ static char *kwlist[] = {"term", "fd", NULL};
- Py_INCREF(Py_None);
- return Py_None;
+ if (!PyArg_ParseTupleAndKeywords(
+ args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) {
+ return NULL;
+ }
+
+ if (fd == -1) {
+ PyObject* sys_stdout;
+
+ sys_stdout = PySys_GetObject("stdout");
+
+ if (sys_stdout == NULL || sys_stdout == Py_None) {
+ PyErr_SetString(
+ PyCursesError,
+ "lost sys.stdout");
+ return NULL;
+ }
+
+ fd = PyObject_AsFileDescriptor(sys_stdout);
+
+ if (fd == -1) {
+ return NULL;
+ }
+ }
+
+ if (setupterm(termstr,fd,&err) == ERR) {
+ char* s = "setupterm: unknown error";
+
+ if (err == 0) {
+ s = "setupterm: could not find terminal";
+ } else if (err == -1) {
+ s = "setupterm: could not find terminfo database";
+ }
+
+ PyErr_SetString(PyCursesError,s);
+ return NULL;
+ }
+
+ initialised_setupterm = TRUE;
+
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyObject *
PyCurses_IntrFlush(PyObject *self, PyObject *args)
{
- int ch;
+ int ch;
- PyCursesInitialised;
+ PyCursesInitialised;
- switch(PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
- return NULL;
- }
+ switch(PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
+ return NULL;
+ }
- return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
+ return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
}
#ifdef HAVE_CURSES_IS_TERM_RESIZED
static PyObject *
PyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
{
- int lines;
- int columns;
- int result;
-
- PyCursesInitialised;
-
- if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
- return NULL;
- result = is_term_resized(lines, columns);
- if (result == TRUE) {
- Py_INCREF(Py_True);
- return Py_True;
- } else {
- Py_INCREF(Py_False);
- return Py_False;
- }
+ int lines;
+ int columns;
+ int result;
+
+ PyCursesInitialised;
+
+ if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
+ return NULL;
+ result = is_term_resized(lines, columns);
+ if (result == TRUE) {
+ Py_INCREF(Py_True);
+ return Py_True;
+ } else {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
}
#endif /* HAVE_CURSES_IS_TERM_RESIZED */
@@ -2191,75 +2191,75 @@
static PyObject *
PyCurses_KeyName(PyObject *self, PyObject *args)
{
- const char *knp;
- int ch;
+ const char *knp;
+ int ch;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
+ if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
- if (ch < 0) {
- PyErr_SetString(PyExc_ValueError, "invalid key number");
- return NULL;
- }
- knp = keyname(ch);
+ if (ch < 0) {
+ PyErr_SetString(PyExc_ValueError, "invalid key number");
+ return NULL;
+ }
+ knp = keyname(ch);
- return PyBytes_FromString((knp == NULL) ? "" : (char *)knp);
+ return PyBytes_FromString((knp == NULL) ? "" : (char *)knp);
}
#endif
-static PyObject *
-PyCurses_KillChar(PyObject *self)
-{
- char ch;
+static PyObject *
+PyCurses_KillChar(PyObject *self)
+{
+ char ch;
- ch = killchar();
+ ch = killchar();
- return PyBytes_FromStringAndSize(&ch, 1);
-}
+ return PyBytes_FromStringAndSize(&ch, 1);
+}
static PyObject *
PyCurses_Meta(PyObject *self, PyObject *args)
{
- int ch;
+ int ch;
- PyCursesInitialised;
+ PyCursesInitialised;
- switch(PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
- return NULL;
- }
+ switch(PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
+ return NULL;
+ }
- return PyCursesCheckERR(meta(stdscr, ch), "meta");
+ return PyCursesCheckERR(meta(stdscr, ch), "meta");
}
#ifdef NCURSES_MOUSE_VERSION
static PyObject *
PyCurses_MouseInterval(PyObject *self, PyObject *args)
{
- int interval;
- PyCursesInitialised;
+ int interval;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"i;interval",&interval))
- return NULL;
- return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
+ if (!PyArg_ParseTuple(args,"i;interval",&interval))
+ return NULL;
+ return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
}
static PyObject *
PyCurses_MouseMask(PyObject *self, PyObject *args)
{
- int newmask;
- mmask_t oldmask, availmask;
+ int newmask;
+ mmask_t oldmask, availmask;
- PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
- return NULL;
- availmask = mousemask(newmask, &oldmask);
- return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
+ PyCursesInitialised;
+ if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
+ return NULL;
+ availmask = mousemask(newmask, &oldmask);
+ return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
}
#endif
@@ -2278,133 +2278,133 @@
static PyObject *
PyCurses_NewPad(PyObject *self, PyObject *args)
{
- WINDOW *win;
- int nlines, ncols;
+ WINDOW *win;
+ int nlines, ncols;
+
+ PyCursesInitialised;
- PyCursesInitialised;
+ if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
- if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
+ win = newpad(nlines, ncols);
- win = newpad(nlines, ncols);
-
- if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
- return NULL;
- }
+ if (win == NULL) {
+ PyErr_SetString(PyCursesError, catchall_NULL);
+ return NULL;
+ }
- return (PyObject *)PyCursesWindow_New(win);
+ return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCurses_NewWindow(PyObject *self, PyObject *args)
{
- WINDOW *win;
- int nlines, ncols, begin_y=0, begin_x=0;
+ WINDOW *win;
+ int nlines, ncols, begin_y=0, begin_x=0;
- PyCursesInitialised;
+ PyCursesInitialised;
- switch (PyTuple_Size(args)) {
- case 2:
- if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
- return NULL;
- break;
- case 4:
- if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
- &nlines,&ncols,&begin_y,&begin_x))
- return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
- return NULL;
- }
-
- win = newwin(nlines,ncols,begin_y,begin_x);
- if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
- return NULL;
- }
+ switch (PyTuple_Size(args)) {
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
+ return NULL;
+ break;
+ case 4:
+ if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
+ &nlines,&ncols,&begin_y,&begin_x))
+ return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
+ return NULL;
+ }
+
+ win = newwin(nlines,ncols,begin_y,begin_x);
+ if (win == NULL) {
+ PyErr_SetString(PyCursesError, catchall_NULL);
+ return NULL;
+ }
- return (PyObject *)PyCursesWindow_New(win);
+ return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCurses_Pair_Content(PyObject *self, PyObject *args)
{
- short pair,f,b;
+ short pair,f,b;
+
+ PyCursesInitialised;
+ PyCursesInitialisedColor;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ switch(PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
+ return NULL;
+ }
- switch(PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
- return NULL;
- }
-
- if (pair_content(pair, &f, &b)==ERR) {
- PyErr_SetString(PyCursesError,
- "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
- return NULL;
- }
+ if (pair_content(pair, &f, &b)==ERR) {
+ PyErr_SetString(PyCursesError,
+ "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
+ return NULL;
+ }
- return Py_BuildValue("(ii)", f, b);
+ return Py_BuildValue("(ii)", f, b);
}
static PyObject *
PyCurses_pair_number(PyObject *self, PyObject *args)
{
- int n;
+ int n;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesInitialised;
+ PyCursesInitialisedColor;
- switch(PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError,
- "pair_number requires 1 argument");
- return NULL;
- }
+ switch(PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError,
+ "pair_number requires 1 argument");
+ return NULL;
+ }
- return PyLong_FromLong((long) ((n & A_COLOR) >> 8));
+ return PyLong_FromLong((long) ((n & A_COLOR) >> 8));
}
static PyObject *
PyCurses_Putp(PyObject *self, PyObject *args)
{
- char *str;
+ char *str;
- if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
- return PyCursesCheckERR(putp(str), "putp");
+ if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
+ return PyCursesCheckERR(putp(str), "putp");
}
static PyObject *
PyCurses_QiFlush(PyObject *self, PyObject *args)
{
- int flag = 0;
+ int flag = 0;
- PyCursesInitialised;
+ PyCursesInitialised;
- switch(PyTuple_Size(args)) {
- case 0:
- qiflush();
- Py_INCREF(Py_None);
- return Py_None;
- case 1:
- if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
- if (flag) qiflush();
- else noqiflush();
- Py_INCREF(Py_None);
- return Py_None;
- default:
- PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
- return NULL;
- }
+ switch(PyTuple_Size(args)) {
+ case 0:
+ qiflush();
+ Py_INCREF(Py_None);
+ return Py_None;
+ case 1:
+ if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
+ if (flag) qiflush();
+ else noqiflush();
+ Py_INCREF(Py_None);
+ return Py_None;
+ default:
+ PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
+ return NULL;
+ }
}
/* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
@@ -2413,46 +2413,46 @@
static int
update_lines_cols(void)
{
- PyObject *o;
- PyObject *m = PyImport_ImportModuleNoBlock("curses");
+ PyObject *o;
+ PyObject *m = PyImport_ImportModuleNoBlock("curses");
- if (!m)
- return 0;
+ if (!m)
+ return 0;
- o = PyLong_FromLong(LINES);
- if (!o) {
- Py_DECREF(m);
- return 0;
- }
- if (PyObject_SetAttrString(m, "LINES", o)) {
- Py_DECREF(m);
- Py_DECREF(o);
- return 0;
- }
- if (PyDict_SetItemString(ModDict, "LINES", o)) {
- Py_DECREF(m);
+ o = PyLong_FromLong(LINES);
+ if (!o) {
+ Py_DECREF(m);
+ return 0;
+ }
+ if (PyObject_SetAttrString(m, "LINES", o)) {
+ Py_DECREF(m);
+ Py_DECREF(o);
+ return 0;
+ }
+ if (PyDict_SetItemString(ModDict, "LINES", o)) {
+ Py_DECREF(m);
+ Py_DECREF(o);
+ return 0;
+ }
Py_DECREF(o);
- return 0;
- }
- Py_DECREF(o);
- o = PyLong_FromLong(COLS);
- if (!o) {
- Py_DECREF(m);
- return 0;
- }
- if (PyObject_SetAttrString(m, "COLS", o)) {
- Py_DECREF(m);
+ o = PyLong_FromLong(COLS);
+ if (!o) {
+ Py_DECREF(m);
+ return 0;
+ }
+ if (PyObject_SetAttrString(m, "COLS", o)) {
+ Py_DECREF(m);
+ Py_DECREF(o);
+ return 0;
+ }
+ if (PyDict_SetItemString(ModDict, "COLS", o)) {
+ Py_DECREF(m);
+ Py_DECREF(o);
+ return 0;
+ }
Py_DECREF(o);
- return 0;
- }
- if (PyDict_SetItemString(ModDict, "COLS", o)) {
Py_DECREF(m);
- Py_DECREF(o);
- return 0;
- }
- Py_DECREF(o);
- Py_DECREF(m);
- return 1;
+ return 1;
}
#endif
@@ -2460,21 +2460,21 @@
static PyObject *
PyCurses_ResizeTerm(PyObject *self, PyObject *args)
{
- int lines;
- int columns;
- PyObject *result;
-
- PyCursesInitialised;
-
- if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
- return NULL;
-
- result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
- if (!result)
- return NULL;
- if (!update_lines_cols())
- return NULL;
- return result;
+ int lines;
+ int columns;
+ PyObject *result;
+
+ PyCursesInitialised;
+
+ if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
+ return NULL;
+
+ result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
+ if (!result)
+ return NULL;
+ if (!update_lines_cols())
+ return NULL;
+ return result;
}
#endif
@@ -2483,496 +2483,496 @@
static PyObject *
PyCurses_Resize_Term(PyObject *self, PyObject *args)
{
- int lines;
- int columns;
+ int lines;
+ int columns;
- PyObject *result;
+ PyObject *result;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
- return NULL;
-
- result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
- if (!result)
- return NULL;
- if (!update_lines_cols())
- return NULL;
- return result;
+ if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
+ return NULL;
+
+ result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
+ if (!result)
+ return NULL;
+ if (!update_lines_cols())
+ return NULL;
+ return result;
}
#endif /* HAVE_CURSES_RESIZE_TERM */
static PyObject *
PyCurses_setsyx(PyObject *self, PyObject *args)
{
- int y,x;
+ int y,x;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (PyTuple_Size(args)!=2) {
- PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
- return NULL;
- }
+ if (PyTuple_Size(args)!=2) {
+ PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
+ return NULL;
+ }
- if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
+ if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
- setsyx(y,x);
+ setsyx(y,x);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyObject *
PyCurses_Start_Color(PyObject *self)
{
- int code;
- PyObject *c, *cp;
+ int code;
+ PyObject *c, *cp;
- PyCursesInitialised;
+ PyCursesInitialised;
- code = start_color();
- if (code != ERR) {
- initialisedcolors = TRUE;
- c = PyLong_FromLong((long) COLORS);
- PyDict_SetItemString(ModDict, "COLORS", c);
- Py_DECREF(c);
- cp = PyLong_FromLong((long) COLOR_PAIRS);
- PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
- Py_DECREF(cp);
- Py_INCREF(Py_None);
- return Py_None;
- } else {
- PyErr_SetString(PyCursesError, "start_color() returned ERR");
- return NULL;
- }
+ code = start_color();
+ if (code != ERR) {
+ initialisedcolors = TRUE;
+ c = PyLong_FromLong((long) COLORS);
+ PyDict_SetItemString(ModDict, "COLORS", c);
+ Py_DECREF(c);
+ cp = PyLong_FromLong((long) COLOR_PAIRS);
+ PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
+ Py_DECREF(cp);
+ Py_INCREF(Py_None);
+ return Py_None;
+ } else {
+ PyErr_SetString(PyCursesError, "start_color() returned ERR");
+ return NULL;
+ }
}
static PyObject *
PyCurses_tigetflag(PyObject *self, PyObject *args)
{
- char *capname;
+ char *capname;
- PyCursesSetupTermCalled;
-
- if (!PyArg_ParseTuple(args, "s", &capname))
- return NULL;
+ PyCursesSetupTermCalled;
- return PyLong_FromLong( (long) tigetflag( capname ) );
+ if (!PyArg_ParseTuple(args, "s", &capname))
+ return NULL;
+
+ return PyLong_FromLong( (long) tigetflag( capname ) );
}
static PyObject *
PyCurses_tigetnum(PyObject *self, PyObject *args)
{
- char *capname;
+ char *capname;
- PyCursesSetupTermCalled;
-
- if (!PyArg_ParseTuple(args, "s", &capname))
- return NULL;
+ PyCursesSetupTermCalled;
- return PyLong_FromLong( (long) tigetnum( capname ) );
+ if (!PyArg_ParseTuple(args, "s", &capname))
+ return NULL;
+
+ return PyLong_FromLong( (long) tigetnum( capname ) );
}
static PyObject *
PyCurses_tigetstr(PyObject *self, PyObject *args)
{
- char *capname;
+ char *capname;
+
+ PyCursesSetupTermCalled;
- PyCursesSetupTermCalled;
-
- if (!PyArg_ParseTuple(args, "s", &capname))
- return NULL;
-
- capname = tigetstr( capname );
- if (capname == 0 || capname == (char*) -1) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return PyBytes_FromString( capname );
+ if (!PyArg_ParseTuple(args, "s", &capname))
+ return NULL;
+
+ capname = tigetstr( capname );
+ if (capname == 0 || capname == (char*) -1) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyBytes_FromString( capname );
}
static PyObject *
PyCurses_tparm(PyObject *self, PyObject *args)
{
- char* fmt;
- char* result = NULL;
- int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
-
- PyCursesSetupTermCalled;
-
- if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
- &fmt, &i1, &i2, &i3, &i4,
- &i5, &i6, &i7, &i8, &i9)) {
- return NULL;
- }
-
- result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
- if (!result) {
- PyErr_SetString(PyCursesError, "tparm() returned NULL");
- return NULL;
- }
+ char* fmt;
+ char* result = NULL;
+ int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
+
+ PyCursesSetupTermCalled;
+
+ if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
+ &fmt, &i1, &i2, &i3, &i4,
+ &i5, &i6, &i7, &i8, &i9)) {
+ return NULL;
+ }
- return PyBytes_FromString(result);
+ result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
+ if (!result) {
+ PyErr_SetString(PyCursesError, "tparm() returned NULL");
+ return NULL;
+ }
+
+ return PyBytes_FromString(result);
}
static PyObject *
PyCurses_TypeAhead(PyObject *self, PyObject *args)
{
- int fd;
+ int fd;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
+ if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
- return PyCursesCheckERR(typeahead( fd ), "typeahead");
+ return PyCursesCheckERR(typeahead( fd ), "typeahead");
}
static PyObject *
PyCurses_UnCtrl(PyObject *self, PyObject *args)
{
- PyObject *temp;
- chtype ch;
+ PyObject *temp;
+ chtype ch;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
+ if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
- if (!PyCurses_ConvertToChtype(temp, &ch)) {
- PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
- return NULL;
- }
+ if (!PyCurses_ConvertToChtype(temp, &ch)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
+ return NULL;
+ }
- return PyBytes_FromString(unctrl(ch));
+ return PyBytes_FromString(unctrl(ch));
}
static PyObject *
PyCurses_UngetCh(PyObject *self, PyObject *args)
{
- PyObject *temp;
- chtype ch;
+ PyObject *temp;
+ chtype ch;
- PyCursesInitialised;
+ PyCursesInitialised;
- if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
+ if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
- if (!PyCurses_ConvertToChtype(temp, &ch)) {
- PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
- return NULL;
- }
+ if (!PyCurses_ConvertToChtype(temp, &ch)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
+ return NULL;
+ }
- return PyCursesCheckERR(ungetch(ch), "ungetch");
+ return PyCursesCheckERR(ungetch(ch), "ungetch");
}
static PyObject *
PyCurses_Use_Env(PyObject *self, PyObject *args)
{
- int flag;
+ int flag;
- switch(PyTuple_Size(args)) {
- case 1:
- if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
- return NULL;
- break;
- default:
- PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
- return NULL;
- }
- use_env(flag);
- Py_INCREF(Py_None);
- return Py_None;
+ switch(PyTuple_Size(args)) {
+ case 1:
+ if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
+ return NULL;
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
+ return NULL;
+ }
+ use_env(flag);
+ Py_INCREF(Py_None);
+ return Py_None;
}
#ifndef STRICT_SYSV_CURSES
static PyObject *
PyCurses_Use_Default_Colors(PyObject *self)
{
- int code;
+ int code;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesInitialised;
+ PyCursesInitialisedColor;
- code = use_default_colors();
- if (code != ERR) {
- Py_INCREF(Py_None);
- return Py_None;
- } else {
- PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
- return NULL;
- }
+ code = use_default_colors();
+ if (code != ERR) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ } else {
+ PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
+ return NULL;
+ }
}
#endif /* STRICT_SYSV_CURSES */
/* List of functions defined in the module */
static PyMethodDef PyCurses_methods[] = {
- {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS},
- {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS},
- {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
- {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS},
- {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
- {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS},
- {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
- {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
- {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
- {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
- {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS},
- {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS},
- {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS},
- {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
- {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS},
- {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS},
- {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS},
+ {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS},
+ {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS},
+ {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
+ {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS},
+ {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
+ {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS},
+ {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
+ {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
+ {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
+ {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
+ {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS},
+ {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS},
+ {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS},
+ {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
+ {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS},
+ {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS},
+ {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS},
#ifdef NCURSES_MOUSE_VERSION
- {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
- {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
+ {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
+ {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
#endif
- {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS},
- {"getwin", (PyCFunction)PyCurses_GetWin, METH_O},
- {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS},
- {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS},
- {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS},
+ {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS},
+ {"getwin", (PyCFunction)PyCurses_GetWin, METH_O},
+ {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS},
+ {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS},
+ {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS},
#ifndef STRICT_SYSV_CURSES
- {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS},
+ {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS},
#endif
- {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
- {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
- {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
- {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS},
- {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
- {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS},
+ {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
+ {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
+ {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
+ {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS},
+ {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
+ {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS},
#ifdef HAVE_CURSES_IS_TERM_RESIZED
- {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
+ {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
#endif
#if !defined(__NetBSD__)
- {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS},
+ {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS},
#endif
- {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS},
- {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS},
- {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS},
+ {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS},
+ {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS},
+ {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS},
#ifdef NCURSES_MOUSE_VERSION
- {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
- {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
+ {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
+ {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
#endif
- {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS},
- {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS},
- {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
- {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS},
- {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
- {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS},
- {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS},
- {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
- {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS},
- {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
- {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS},
- {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS},
- {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
- {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS},
- {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
- {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
- {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS},
+ {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS},
+ {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS},
+ {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
+ {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS},
+ {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
+ {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS},
+ {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS},
+ {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
+ {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS},
+ {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
+ {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS},
+ {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS},
+ {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
+ {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS},
+ {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
+ {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
+ {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS},
#ifdef HAVE_CURSES_RESIZETERM
- {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
+ {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
#endif
#ifdef HAVE_CURSES_RESIZE_TERM
- {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
+ {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
#endif
- {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS},
- {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS},
- {"setupterm", (PyCFunction)PyCurses_setupterm,
- METH_VARARGS|METH_KEYWORDS},
- {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
- {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS},
- {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS},
- {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
- {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
- {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
- {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
- {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
- {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
- {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
- {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
+ {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS},
+ {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS},
+ {"setupterm", (PyCFunction)PyCurses_setupterm,
+ METH_VARARGS|METH_KEYWORDS},
+ {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
+ {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS},
+ {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS},
+ {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
+ {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
+ {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
+ {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
+ {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
+ {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
+ {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
+ {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
#ifndef STRICT_SYSV_CURSES
- {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
+ {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
#endif
- {NULL, NULL} /* sentinel */
+ {NULL, NULL} /* sentinel */
};
/* Initialization function for the module */
static struct PyModuleDef _cursesmodule = {
- PyModuleDef_HEAD_INIT,
- "_curses",
- NULL,
- -1,
- PyCurses_methods,
- NULL,
- NULL,
- NULL,
- NULL
+ PyModuleDef_HEAD_INIT,
+ "_curses",
+ NULL,
+ -1,
+ PyCurses_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
PyMODINIT_FUNC
PyInit__curses(void)
{
- PyObject *m, *d, *v, *c_api_object;
- static void *PyCurses_API[PyCurses_API_pointers];
+ PyObject *m, *d, *v, *c_api_object;
+ static void *PyCurses_API[PyCurses_API_pointers];
+
+ /* Initialize object type */
+ if (PyType_Ready(&PyCursesWindow_Type) < 0)
+ return NULL;
+
+ /* Initialize the C API pointer array */
+ PyCurses_API[0] = (void *)&PyCursesWindow_Type;
+ PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
+ PyCurses_API[2] = (void *)func_PyCursesInitialised;
+ PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
+
+ /* Create the module and add the functions */
+ m = PyModule_Create(&_cursesmodule);
+ if (m == NULL)
+ return NULL;
- /* Initialize object type */
- if (PyType_Ready(&PyCursesWindow_Type) < 0)
- return NULL;
-
- /* Initialize the C API pointer array */
- PyCurses_API[0] = (void *)&PyCursesWindow_Type;
- PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
- PyCurses_API[2] = (void *)func_PyCursesInitialised;
- PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
-
- /* Create the module and add the functions */
- m = PyModule_Create(&_cursesmodule);
- if (m == NULL)
- return NULL;
-
- /* Add some symbolic constants to the module */
- d = PyModule_GetDict(m);
- if (d == NULL)
- return NULL;
- ModDict = d; /* For PyCurses_InitScr to use later */
-
- /* Add a capsule for the C API */
- c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL);
- PyDict_SetItemString(d, "_C_API", c_api_object);
- Py_DECREF(c_api_object);
-
- /* For exception curses.error */
- PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
- PyDict_SetItemString(d, "error", PyCursesError);
-
- /* Make the version available */
- v = PyBytes_FromString(PyCursesVersion);
- PyDict_SetItemString(d, "version", v);
- PyDict_SetItemString(d, "__version__", v);
- Py_DECREF(v);
-
- SetDictInt("ERR", ERR);
- SetDictInt("OK", OK);
-
- /* Here are some attributes you can add to chars to print */
-
- SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
- SetDictInt("A_NORMAL", A_NORMAL);
- SetDictInt("A_STANDOUT", A_STANDOUT);
- SetDictInt("A_UNDERLINE", A_UNDERLINE);
- SetDictInt("A_REVERSE", A_REVERSE);
- SetDictInt("A_BLINK", A_BLINK);
- SetDictInt("A_DIM", A_DIM);
- SetDictInt("A_BOLD", A_BOLD);
- SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
+ /* Add some symbolic constants to the module */
+ d = PyModule_GetDict(m);
+ if (d == NULL)
+ return NULL;
+ ModDict = d; /* For PyCurses_InitScr to use later */
+
+ /* Add a capsule for the C API */
+ c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL);
+ PyDict_SetItemString(d, "_C_API", c_api_object);
+ Py_DECREF(c_api_object);
+
+ /* For exception curses.error */
+ PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
+ PyDict_SetItemString(d, "error", PyCursesError);
+
+ /* Make the version available */
+ v = PyBytes_FromString(PyCursesVersion);
+ PyDict_SetItemString(d, "version", v);
+ PyDict_SetItemString(d, "__version__", v);
+ Py_DECREF(v);
+
+ SetDictInt("ERR", ERR);
+ SetDictInt("OK", OK);
+
+ /* Here are some attributes you can add to chars to print */
+
+ SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
+ SetDictInt("A_NORMAL", A_NORMAL);
+ SetDictInt("A_STANDOUT", A_STANDOUT);
+ SetDictInt("A_UNDERLINE", A_UNDERLINE);
+ SetDictInt("A_REVERSE", A_REVERSE);
+ SetDictInt("A_BLINK", A_BLINK);
+ SetDictInt("A_DIM", A_DIM);
+ SetDictInt("A_BOLD", A_BOLD);
+ SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
#if !defined(__NetBSD__)
- SetDictInt("A_INVIS", A_INVIS);
+ SetDictInt("A_INVIS", A_INVIS);
#endif
- SetDictInt("A_PROTECT", A_PROTECT);
- SetDictInt("A_CHARTEXT", A_CHARTEXT);
- SetDictInt("A_COLOR", A_COLOR);
+ SetDictInt("A_PROTECT", A_PROTECT);
+ SetDictInt("A_CHARTEXT", A_CHARTEXT);
+ SetDictInt("A_COLOR", A_COLOR);
- /* The following are never available with strict SYSV curses */
+ /* The following are never available with strict SYSV curses */
#ifdef A_HORIZONTAL
- SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
+ SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
#endif
#ifdef A_LEFT
- SetDictInt("A_LEFT", A_LEFT);
+ SetDictInt("A_LEFT", A_LEFT);
#endif
#ifdef A_LOW
- SetDictInt("A_LOW", A_LOW);
+ SetDictInt("A_LOW", A_LOW);
#endif
#ifdef A_RIGHT
- SetDictInt("A_RIGHT", A_RIGHT);
+ SetDictInt("A_RIGHT", A_RIGHT);
#endif
#ifdef A_TOP
- SetDictInt("A_TOP", A_TOP);
+ SetDictInt("A_TOP", A_TOP);
#endif
#ifdef A_VERTICAL
- SetDictInt("A_VERTICAL", A_VERTICAL);
+ SetDictInt("A_VERTICAL", A_VERTICAL);
#endif
- SetDictInt("COLOR_BLACK", COLOR_BLACK);
- SetDictInt("COLOR_RED", COLOR_RED);
- SetDictInt("COLOR_GREEN", COLOR_GREEN);
- SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
- SetDictInt("COLOR_BLUE", COLOR_BLUE);
- SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
- SetDictInt("COLOR_CYAN", COLOR_CYAN);
- SetDictInt("COLOR_WHITE", COLOR_WHITE);
+ SetDictInt("COLOR_BLACK", COLOR_BLACK);
+ SetDictInt("COLOR_RED", COLOR_RED);
+ SetDictInt("COLOR_GREEN", COLOR_GREEN);
+ SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
+ SetDictInt("COLOR_BLUE", COLOR_BLUE);
+ SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
+ SetDictInt("COLOR_CYAN", COLOR_CYAN);
+ SetDictInt("COLOR_WHITE", COLOR_WHITE);
#ifdef NCURSES_MOUSE_VERSION
- /* Mouse-related constants */
- SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
- SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
- SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
- SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
- SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
-
- SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
- SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
- SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
- SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
- SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
-
- SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
- SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
- SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
- SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
- SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
-
- SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
- SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
- SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
- SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
- SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
-
- SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
- SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
- SetDictInt("BUTTON_ALT", BUTTON_ALT);
-
- SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
- SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
-#endif
- /* Now set everything up for KEY_ variables */
- {
- int key;
- char *key_n;
- char *key_n2;
+ /* Mouse-related constants */
+ SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
+ SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
+ SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
+ SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
+ SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
+
+ SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
+ SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
+ SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
+ SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
+ SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
+
+ SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
+ SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
+ SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
+ SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
+ SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
+
+ SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
+ SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
+ SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
+ SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
+ SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
+
+ SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
+ SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
+ SetDictInt("BUTTON_ALT", BUTTON_ALT);
+
+ SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
+ SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
+#endif
+ /* Now set everything up for KEY_ variables */
+ {
+ int key;
+ char *key_n;
+ char *key_n2;
#if !defined(__NetBSD__)
- for (key=KEY_MIN;key < KEY_MAX; key++) {
- key_n = (char *)keyname(key);
- if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
- continue;
- if (strncmp(key_n,"KEY_F(",6)==0) {
- char *p1, *p2;
- key_n2 = malloc(strlen(key_n)+1);
- if (!key_n2) {
- PyErr_NoMemory();
- break;
- }
- p1 = key_n;
- p2 = key_n2;
- while (*p1) {
- if (*p1 != '(' && *p1 != ')') {
- *p2 = *p1;
- p2++;
- }
- p1++;
- }
- *p2 = (char)0;
- } else
- key_n2 = key_n;
- SetDictInt(key_n2,key);
- if (key_n2 != key_n)
- free(key_n2);
- }
-#endif
- SetDictInt("KEY_MIN", KEY_MIN);
- SetDictInt("KEY_MAX", KEY_MAX);
- }
- return m;
+ for (key=KEY_MIN;key < KEY_MAX; key++) {
+ key_n = (char *)keyname(key);
+ if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
+ continue;
+ if (strncmp(key_n,"KEY_F(",6)==0) {
+ char *p1, *p2;
+ key_n2 = malloc(strlen(key_n)+1);
+ if (!key_n2) {
+ PyErr_NoMemory();
+ break;
+ }
+ p1 = key_n;
+ p2 = key_n2;
+ while (*p1) {
+ if (*p1 != '(' && *p1 != ')') {
+ *p2 = *p1;
+ p2++;
+ }
+ p1++;
+ }
+ *p2 = (char)0;
+ } else
+ key_n2 = key_n;
+ SetDictInt(key_n2,key);
+ if (key_n2 != key_n)
+ free(key_n2);
+ }
+#endif
+ SetDictInt("KEY_MIN", KEY_MIN);
+ SetDictInt("KEY_MAX", KEY_MAX);
+ }
+ return m;
}
Modified: python/branches/py3k-jit/Modules/_io/fileio.c
==============================================================================
--- python/branches/py3k-jit/Modules/_io/fileio.c (original)
+++ python/branches/py3k-jit/Modules/_io/fileio.c Tue May 18 19:58:30 2010
@@ -247,8 +247,7 @@
if (u == NULL)
return -1;
- stringobj = PyUnicode_AsEncodedString(
- u, Py_FileSystemDefaultEncoding, "surrogateescape");
+ stringobj = PyUnicode_EncodeFSDefault(u);
Py_DECREF(u);
if (stringobj == NULL)
return -1;
Modified: python/branches/py3k-jit/Modules/_ssl.c
==============================================================================
--- python/branches/py3k-jit/Modules/_ssl.c (original)
+++ python/branches/py3k-jit/Modules/_ssl.c Tue May 18 19:58:30 2010
@@ -115,23 +115,29 @@
typedef struct {
PyObject_HEAD
- PyObject *Socket; /* weakref to socket on which we're layered */
- SSL_CTX* ctx;
- SSL* ssl;
- X509* peer_cert;
- int shutdown_seen_zero;
-
-} PySSLObject;
-
-static PyTypeObject PySSL_Type;
-static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args);
-static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args);
+ SSL_CTX *ctx;
+} PySSLContext;
+
+typedef struct {
+ PyObject_HEAD
+ PyObject *Socket; /* weakref to socket on which we're layered */
+ SSL *ssl;
+ X509 *peer_cert;
+ int shutdown_seen_zero;
+} PySSLSocket;
+
+static PyTypeObject PySSLContext_Type;
+static PyTypeObject PySSLSocket_Type;
+
+static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args);
+static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args);
static int check_socket_and_wait_for_timeout(PySocketSockObject *s,
int writing);
-static PyObject *PySSL_peercert(PySSLObject *self, PyObject *args);
-static PyObject *PySSL_cipher(PySSLObject *self);
+static PyObject *PySSL_peercert(PySSLSocket *self, PyObject *args);
+static PyObject *PySSL_cipher(PySSLSocket *self);
-#define PySSLObject_Check(v) (Py_TYPE(v) == &PySSL_Type)
+#define PySSLContext_Check(v) (Py_TYPE(v) == &PySSLContext_Type)
+#define PySSLSocket_Check(v) (Py_TYPE(v) == &PySSLSocket_Type)
typedef enum {
SOCKET_IS_NONBLOCKING,
@@ -154,7 +160,7 @@
*/
static PyObject *
-PySSL_SetError(PySSLObject *obj, int ret, char *filename, int lineno)
+PySSL_SetError(PySSLSocket *obj, int ret, char *filename, int lineno)
{
PyObject *v;
char buf[2048];
@@ -199,6 +205,7 @@
errstr = "EOF occurred in violation of protocol";
} else if (ret == -1) {
/* underlying BIO reported an I/O error */
+ ERR_clear_error();
return s->errorhandler();
} else { /* possible? */
p = PY_SSL_ERROR_SYSCALL;
@@ -231,6 +238,7 @@
errstr = ERR_error_string(ERR_peek_last_error(), NULL);
}
PyOS_snprintf(buf, sizeof(buf), "_ssl.c:%d: %s", lineno, errstr);
+ ERR_clear_error();
v = Py_BuildValue("(is)", p, buf);
if (v != NULL) {
PyErr_SetObject(PySSLErrorObject, v);
@@ -250,6 +258,7 @@
errstr = ERR_error_string(errcode, NULL);
}
PyOS_snprintf(buf, sizeof(buf), "_ssl.c:%d: %s", lineno, errstr);
+ ERR_clear_error();
v = Py_BuildValue("(is)", errcode, buf);
if (v != NULL) {
PyErr_SetObject(PySSLErrorObject, v);
@@ -258,126 +267,28 @@
return NULL;
}
-static PySSLObject *
-newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file,
- enum py_ssl_server_or_client socket_type,
- enum py_ssl_cert_requirements certreq,
- enum py_ssl_version proto_version,
- char *cacerts_file, char *ciphers)
+static PySSLSocket *
+newPySSLSocket(SSL_CTX *ctx, PySocketSockObject *sock,
+ enum py_ssl_server_or_client socket_type)
{
- PySSLObject *self;
- char *errstr = NULL;
- int ret;
- int verification_mode;
+ PySSLSocket *self;
- self = PyObject_New(PySSLObject, &PySSL_Type); /* Create new object */
+ self = PyObject_New(PySSLSocket, &PySSLSocket_Type);
if (self == NULL)
return NULL;
+
self->peer_cert = NULL;
self->ssl = NULL;
- self->ctx = NULL;
self->Socket = NULL;
/* Make sure the SSL error state is initialized */
(void) ERR_get_state();
ERR_clear_error();
- if ((key_file && !cert_file) || (!key_file && cert_file)) {
- errstr = ERRSTR("Both the key & certificate files "
- "must be specified");
- goto fail;
- }
-
- if ((socket_type == PY_SSL_SERVER) &&
- ((key_file == NULL) || (cert_file == NULL))) {
- errstr = ERRSTR("Both the key & certificate files "
- "must be specified for server-side operation");
- goto fail;
- }
-
- PySSL_BEGIN_ALLOW_THREADS
- if (proto_version == PY_SSL_VERSION_TLS1)
- self->ctx = SSL_CTX_new(TLSv1_method()); /* Set up context */
- else if (proto_version == PY_SSL_VERSION_SSL3)
- self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
- else if (proto_version == PY_SSL_VERSION_SSL2)
- self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
- else if (proto_version == PY_SSL_VERSION_SSL23)
- self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */
- PySSL_END_ALLOW_THREADS
-
- if (self->ctx == NULL) {
- errstr = ERRSTR("Invalid SSL protocol variant specified.");
- goto fail;
- }
-
- if (ciphers != NULL) {
- ret = SSL_CTX_set_cipher_list(self->ctx, ciphers);
- if (ret == 0) {
- errstr = ERRSTR("No cipher can be selected.");
- goto fail;
- }
- }
-
- if (certreq != PY_SSL_CERT_NONE) {
- if (cacerts_file == NULL) {
- errstr = ERRSTR("No root certificates specified for "
- "verification of other-side certificates.");
- goto fail;
- } else {
- PySSL_BEGIN_ALLOW_THREADS
- ret = SSL_CTX_load_verify_locations(self->ctx,
- cacerts_file,
- NULL);
- PySSL_END_ALLOW_THREADS
- if (ret != 1) {
- _setSSLError(NULL, 0, __FILE__, __LINE__);
- goto fail;
- }
- }
- }
- if (key_file) {
- PySSL_BEGIN_ALLOW_THREADS
- ret = SSL_CTX_use_PrivateKey_file(self->ctx, key_file,
- SSL_FILETYPE_PEM);
- PySSL_END_ALLOW_THREADS
- if (ret != 1) {
- _setSSLError(NULL, ret, __FILE__, __LINE__);
- goto fail;
- }
-
- PySSL_BEGIN_ALLOW_THREADS
- ret = SSL_CTX_use_certificate_chain_file(self->ctx,
- cert_file);
- PySSL_END_ALLOW_THREADS
- if (ret != 1) {
- /*
- fprintf(stderr, "ret is %d, errcode is %lu, %lu, with file \"%s\"\n",
- ret, ERR_peek_error(), ERR_peek_last_error(), cert_file);
- */
- if (ERR_peek_last_error() != 0) {
- _setSSLError(NULL, ret, __FILE__, __LINE__);
- goto fail;
- }
- }
- }
-
- /* ssl compatibility */
- SSL_CTX_set_options(self->ctx, SSL_OP_ALL);
-
- verification_mode = SSL_VERIFY_NONE;
- if (certreq == PY_SSL_CERT_OPTIONAL)
- verification_mode = SSL_VERIFY_PEER;
- else if (certreq == PY_SSL_CERT_REQUIRED)
- verification_mode = (SSL_VERIFY_PEER |
- SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
- SSL_CTX_set_verify(self->ctx, verification_mode,
- NULL); /* set verify lvl */
-
PySSL_BEGIN_ALLOW_THREADS
- self->ssl = SSL_new(self->ctx); /* New ssl struct */
+ self->ssl = SSL_new(ctx);
PySSL_END_ALLOW_THREADS
- SSL_set_fd(self->ssl, Sock->sock_fd); /* Set the socket for SSL */
+ SSL_set_fd(self->ssl, sock->sock_fd);
#ifdef SSL_MODE_AUTO_RETRY
SSL_set_mode(self->ssl, SSL_MODE_AUTO_RETRY);
#endif
@@ -385,8 +296,7 @@
/* If the socket is in non-blocking mode or timeout mode, set the BIO
* to non-blocking mode (blocking is the default)
*/
- if (Sock->sock_timeout >= 0.0) {
- /* Set both the read and write BIO's to non-blocking mode */
+ if (sock->sock_timeout >= 0.0) {
BIO_set_nbio(SSL_get_rbio(self->ssl), 1);
BIO_set_nbio(SSL_get_wbio(self->ssl), 1);
}
@@ -398,57 +308,13 @@
SSL_set_accept_state(self->ssl);
PySSL_END_ALLOW_THREADS
- self->Socket = PyWeakref_NewRef((PyObject *) Sock, Py_None);
+ self->Socket = PyWeakref_NewRef((PyObject *) sock, NULL);
return self;
- fail:
- if (errstr)
- PyErr_SetString(PySSLErrorObject, errstr);
- Py_DECREF(self);
- return NULL;
}
-static PyObject *
-PySSL_sslwrap(PyObject *self, PyObject *args)
-{
- PySocketSockObject *Sock;
- int server_side = 0;
- int verification_mode = PY_SSL_CERT_NONE;
- int protocol = PY_SSL_VERSION_SSL23;
- char *key_file = NULL;
- char *cert_file = NULL;
- char *cacerts_file = NULL;
- char *ciphers = NULL;
-
- if (!PyArg_ParseTuple(args, "O!i|zziizz:sslwrap",
- PySocketModule.Sock_Type,
- &Sock,
- &server_side,
- &key_file, &cert_file,
- &verification_mode, &protocol,
- &cacerts_file, &ciphers))
- return NULL;
-
- /*
- fprintf(stderr,
- "server_side is %d, keyfile %p, certfile %p, verify_mode %d, "
- "protocol %d, certs %p\n",
- server_side, key_file, cert_file, verification_mode,
- protocol, cacerts_file);
- */
-
- return (PyObject *) newPySSLObject(Sock, key_file, cert_file,
- server_side, verification_mode,
- protocol, cacerts_file,
- ciphers);
-}
-
-PyDoc_STRVAR(ssl_doc,
-"sslwrap(socket, server_side, [keyfile, certfile, certs_mode, protocol,\n"
-" cacertsfile, ciphers]) -> sslobject");
-
/* SSL object methods */
-static PyObject *PySSL_SSLdo_handshake(PySSLObject *self)
+static PyObject *PySSL_SSLdo_handshake(PySSLSocket *self)
{
int ret;
int err;
@@ -948,13 +814,13 @@
PySSL_test_decode_certificate (PyObject *mod, PyObject *args) {
PyObject *retval = NULL;
- char *filename = NULL;
+ PyObject *filename;
X509 *x=NULL;
BIO *cert;
int verbose = 1;
- if (!PyArg_ParseTuple(args, "s|i:test_decode_certificate",
- &filename, &verbose))
+ if (!PyArg_ParseTuple(args, "O&|i:test_decode_certificate",
+ PyUnicode_FSConverter, &filename, &verbose))
return NULL;
if ((cert=BIO_new(BIO_s_file())) == NULL) {
@@ -963,7 +829,7 @@
goto fail0;
}
- if (BIO_read_filename(cert,filename) <= 0) {
+ if (BIO_read_filename(cert, PyBytes_AsString(filename)) <= 0) {
PyErr_SetString(PySSLErrorObject,
"Can't open file");
goto fail0;
@@ -979,14 +845,14 @@
retval = _decode_certificate(x, verbose);
fail0:
-
+ Py_DECREF(filename);
if (cert != NULL) BIO_free(cert);
return retval;
}
static PyObject *
-PySSL_peercert(PySSLObject *self, PyObject *args)
+PySSL_peercert(PySSLSocket *self, PyObject *args)
{
PyObject *retval = NULL;
int len;
@@ -1017,8 +883,7 @@
return retval;
} else {
-
- verification = SSL_CTX_get_verify_mode(self->ctx);
+ verification = SSL_CTX_get_verify_mode(SSL_get_SSL_CTX(self->ssl));
if ((verification & SSL_VERIFY_PEER) == 0)
return PyDict_New();
else
@@ -1038,7 +903,7 @@
peer certificate, or None if no certificate was provided. This will\n\
return the certificate even if it wasn't validated.");
-static PyObject *PySSL_cipher (PySSLObject *self) {
+static PyObject *PySSL_cipher (PySSLSocket *self) {
PyObject *retval, *v;
SSL_CIPHER *current;
@@ -1084,14 +949,12 @@
return NULL;
}
-static void PySSL_dealloc(PySSLObject *self)
+static void PySSL_dealloc(PySSLSocket *self)
{
if (self->peer_cert) /* Possible not to have one? */
X509_free (self->peer_cert);
if (self->ssl)
SSL_free(self->ssl);
- if (self->ctx)
- SSL_CTX_free(self->ctx);
Py_XDECREF(self->Socket);
PyObject_Del(self);
}
@@ -1166,7 +1029,7 @@
return rc == 0 ? SOCKET_HAS_TIMED_OUT : SOCKET_OPERATION_OK;
}
-static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
+static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
{
Py_buffer buf;
int len;
@@ -1250,7 +1113,7 @@
Writes the string s into the SSL object. Returns the number\n\
of bytes written.");
-static PyObject *PySSL_SSLpending(PySSLObject *self)
+static PyObject *PySSL_SSLpending(PySSLSocket *self)
{
int count = 0;
@@ -1269,7 +1132,7 @@
Returns the number of already decrypted bytes available for read,\n\
pending on the connection.\n");
-static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
+static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
{
PyObject *dest = NULL;
Py_buffer buf;
@@ -1392,7 +1255,7 @@
\n\
Read up to len bytes from the SSL socket.");
-static PyObject *PySSL_SSLshutdown(PySSLObject *self)
+static PyObject *PySSL_SSLshutdown(PySSLSocket *self)
{
int err, ssl_err, sockstate, nonblocking;
int zeros = 0;
@@ -1497,10 +1360,10 @@
{NULL, NULL}
};
-static PyTypeObject PySSL_Type = {
+static PyTypeObject PySSLSocket_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "ssl.SSLContext", /*tp_name*/
- sizeof(PySSLObject), /*tp_basicsize*/
+ "_ssl._SSLSocket", /*tp_name*/
+ sizeof(PySSLSocket), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)PySSL_dealloc, /*tp_dealloc*/
@@ -1529,6 +1392,310 @@
PySSLMethods, /*tp_methods*/
};
+
+/*
+ * _SSLContext objects
+ */
+
+static PyObject *
+context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ char *kwlist[] = {"protocol", NULL};
+ PySSLContext *self;
+ int proto_version = PY_SSL_VERSION_SSL23;
+ SSL_CTX *ctx = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwds, "i:_SSLContext", kwlist,
+ &proto_version))
+ return NULL;
+
+ PySSL_BEGIN_ALLOW_THREADS
+ if (proto_version == PY_SSL_VERSION_TLS1)
+ ctx = SSL_CTX_new(TLSv1_method());
+ else if (proto_version == PY_SSL_VERSION_SSL3)
+ ctx = SSL_CTX_new(SSLv3_method());
+ else if (proto_version == PY_SSL_VERSION_SSL2)
+ ctx = SSL_CTX_new(SSLv2_method());
+ else if (proto_version == PY_SSL_VERSION_SSL23)
+ ctx = SSL_CTX_new(SSLv23_method());
+ else
+ proto_version = -1;
+ PySSL_END_ALLOW_THREADS
+
+ if (proto_version == -1) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid protocol version");
+ return NULL;
+ }
+ if (ctx == NULL) {
+ PyErr_SetString(PySSLErrorObject,
+ "failed to allocate SSL context");
+ return NULL;
+ }
+
+ assert(type != NULL && type->tp_alloc != NULL);
+ self = (PySSLContext *) type->tp_alloc(type, 0);
+ if (self == NULL) {
+ SSL_CTX_free(ctx);
+ return NULL;
+ }
+ self->ctx = ctx;
+ /* Defaults */
+ SSL_CTX_set_verify(self->ctx, SSL_VERIFY_NONE, NULL);
+ SSL_CTX_set_options(self->ctx, SSL_OP_ALL);
+
+ return (PyObject *)self;
+}
+
+static void
+context_dealloc(PySSLContext *self)
+{
+ SSL_CTX_free(self->ctx);
+ Py_TYPE(self)->tp_free(self);
+}
+
+static PyObject *
+set_ciphers(PySSLContext *self, PyObject *args)
+{
+ int ret;
+ const char *cipherlist;
+
+ if (!PyArg_ParseTuple(args, "s:set_ciphers", &cipherlist))
+ return NULL;
+ ret = SSL_CTX_set_cipher_list(self->ctx, cipherlist);
+ if (ret == 0) {
+ /* Clearing the error queue is necessary on some OpenSSL versions,
+ otherwise the error will be reported again when another SSL call
+ is done. */
+ ERR_clear_error();
+ PyErr_SetString(PySSLErrorObject,
+ "No cipher can be selected.");
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+get_verify_mode(PySSLContext *self, void *c)
+{
+ switch (SSL_CTX_get_verify_mode(self->ctx)) {
+ case SSL_VERIFY_NONE:
+ return PyLong_FromLong(PY_SSL_CERT_NONE);
+ case SSL_VERIFY_PEER:
+ return PyLong_FromLong(PY_SSL_CERT_OPTIONAL);
+ case SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT:
+ return PyLong_FromLong(PY_SSL_CERT_REQUIRED);
+ }
+ PyErr_SetString(PySSLErrorObject,
+ "invalid return value from SSL_CTX_get_verify_mode");
+ return NULL;
+}
+
+static int
+set_verify_mode(PySSLContext *self, PyObject *arg, void *c)
+{
+ int n, mode;
+ if (!PyArg_Parse(arg, "i", &n))
+ return -1;
+ if (n == PY_SSL_CERT_NONE)
+ mode = SSL_VERIFY_NONE;
+ else if (n == PY_SSL_CERT_OPTIONAL)
+ mode = SSL_VERIFY_PEER;
+ else if (n == PY_SSL_CERT_REQUIRED)
+ mode = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid value for verify_mode");
+ return -1;
+ }
+ SSL_CTX_set_verify(self->ctx, mode, NULL);
+ return 0;
+}
+
+static PyObject *
+load_cert_chain(PySSLContext *self, PyObject *args, PyObject *kwds)
+{
+ char *kwlist[] = {"certfile", "keyfile", NULL};
+ PyObject *certfile, *keyfile = NULL;
+ PyObject *certfile_bytes = NULL, *keyfile_bytes = NULL;
+ int r;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds,
+ "O|O:load_cert_chain", kwlist,
+ &certfile, &keyfile))
+ return NULL;
+ if (keyfile == Py_None)
+ keyfile = NULL;
+ if (!PyUnicode_FSConverter(certfile, &certfile_bytes)) {
+ PyErr_SetString(PyExc_TypeError,
+ "certfile should be a valid filesystem path");
+ return NULL;
+ }
+ if (keyfile && !PyUnicode_FSConverter(keyfile, &keyfile_bytes)) {
+ PyErr_SetString(PyExc_TypeError,
+ "keyfile should be a valid filesystem path");
+ goto error;
+ }
+ PySSL_BEGIN_ALLOW_THREADS
+ r = SSL_CTX_use_certificate_chain_file(self->ctx,
+ PyBytes_AS_STRING(certfile_bytes));
+ PySSL_END_ALLOW_THREADS
+ if (r != 1) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ goto error;
+ }
+ PySSL_BEGIN_ALLOW_THREADS
+ r = SSL_CTX_use_RSAPrivateKey_file(self->ctx,
+ PyBytes_AS_STRING(keyfile ? keyfile_bytes : certfile_bytes),
+ SSL_FILETYPE_PEM);
+ PySSL_END_ALLOW_THREADS
+ Py_XDECREF(keyfile_bytes);
+ Py_XDECREF(certfile_bytes);
+ if (r != 1) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ return NULL;
+ }
+ PySSL_BEGIN_ALLOW_THREADS
+ r = SSL_CTX_check_private_key(self->ctx);
+ PySSL_END_ALLOW_THREADS
+ if (r != 1) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ return NULL;
+ }
+ Py_RETURN_NONE;
+
+error:
+ Py_XDECREF(keyfile_bytes);
+ Py_XDECREF(certfile_bytes);
+ return NULL;
+}
+
+static PyObject *
+load_verify_locations(PySSLContext *self, PyObject *args, PyObject *kwds)
+{
+ char *kwlist[] = {"cafile", "capath", NULL};
+ PyObject *cafile = NULL, *capath = NULL;
+ PyObject *cafile_bytes = NULL, *capath_bytes = NULL;
+ const char *cafile_buf = NULL, *capath_buf = NULL;
+ int r;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds,
+ "|OO:load_verify_locations", kwlist,
+ &cafile, &capath))
+ return NULL;
+ if (cafile == Py_None)
+ cafile = NULL;
+ if (capath == Py_None)
+ capath = NULL;
+ if (cafile == NULL && capath == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "cafile and capath cannot be both omitted");
+ return NULL;
+ }
+ if (cafile && !PyUnicode_FSConverter(cafile, &cafile_bytes)) {
+ PyErr_SetString(PyExc_TypeError,
+ "cafile should be a valid filesystem path");
+ return NULL;
+ }
+ if (capath && !PyUnicode_FSConverter(capath, &capath_bytes)) {
+ Py_DECREF(cafile_bytes);
+ PyErr_SetString(PyExc_TypeError,
+ "capath should be a valid filesystem path");
+ return NULL;
+ }
+ if (cafile)
+ cafile_buf = PyBytes_AS_STRING(cafile_bytes);
+ if (capath)
+ capath_buf = PyBytes_AS_STRING(capath_bytes);
+ PySSL_BEGIN_ALLOW_THREADS
+ r = SSL_CTX_load_verify_locations(self->ctx, cafile_buf, capath_buf);
+ PySSL_END_ALLOW_THREADS
+ Py_XDECREF(cafile_bytes);
+ Py_XDECREF(capath_bytes);
+ if (r != 1) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+context_wrap_socket(PySSLContext *self, PyObject *args, PyObject *kwds)
+{
+ char *kwlist[] = {"sock", "server_side", NULL};
+ PySocketSockObject *sock;
+ int server_side = 0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!i:_wrap_socket", kwlist,
+ PySocketModule.Sock_Type,
+ &sock, &server_side))
+ return NULL;
+
+ return (PyObject *) newPySSLSocket(self->ctx, sock, server_side);
+}
+
+static PyGetSetDef context_getsetlist[] = {
+ {"verify_mode", (getter) get_verify_mode,
+ (setter) set_verify_mode, NULL},
+ {NULL}, /* sentinel */
+};
+
+static struct PyMethodDef context_methods[] = {
+ {"_wrap_socket", (PyCFunction) context_wrap_socket,
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {"set_ciphers", (PyCFunction) set_ciphers,
+ METH_VARARGS, NULL},
+ {"load_cert_chain", (PyCFunction) load_cert_chain,
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {"load_verify_locations", (PyCFunction) load_verify_locations,
+ METH_VARARGS | METH_KEYWORDS, NULL},
+ {NULL, NULL} /* sentinel */
+};
+
+static PyTypeObject PySSLContext_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "_ssl._SSLContext", /*tp_name*/
+ sizeof(PySSLContext), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ (destructor)context_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 | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ context_methods, /*tp_methods*/
+ 0, /*tp_members*/
+ context_getsetlist, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ context_new, /*tp_new*/
+};
+
+
+
#ifdef HAVE_OPENSSL_RAND
/* helper routines for seeding the SSL PRNG */
@@ -1566,15 +1733,17 @@
using the ssl() function.");
static PyObject *
-PySSL_RAND_egd(PyObject *self, PyObject *arg)
+PySSL_RAND_egd(PyObject *self, PyObject *args)
{
+ PyObject *path;
int bytes;
- if (!PyUnicode_Check(arg))
- return PyErr_Format(PyExc_TypeError,
- "RAND_egd() expected string, found %s",
- Py_TYPE(arg)->tp_name);
- bytes = RAND_egd(_PyUnicode_AsString(arg));
+ if (!PyArg_ParseTuple(args, "O&|i:RAND_egd",
+ PyUnicode_FSConverter, &path))
+ return NULL;
+
+ bytes = RAND_egd(PyBytes_AsString(path));
+ Py_DECREF(path);
if (bytes == -1) {
PyErr_SetString(PySSLErrorObject,
"EGD connection failed or EGD did not return "
@@ -1598,14 +1767,12 @@
/* List of functions exported by this module. */
static PyMethodDef PySSL_methods[] = {
- {"sslwrap", PySSL_sslwrap,
- METH_VARARGS, ssl_doc},
{"_test_decode_cert", PySSL_test_decode_certificate,
METH_VARARGS},
#ifdef HAVE_OPENSSL_RAND
{"RAND_add", PySSL_RAND_add, METH_VARARGS,
PySSL_RAND_add_doc},
- {"RAND_egd", PySSL_RAND_egd, METH_O,
+ {"RAND_egd", PySSL_RAND_egd, METH_VARARGS,
PySSL_RAND_egd_doc},
{"RAND_status", (PyCFunction)PySSL_RAND_status, METH_NOARGS,
PySSL_RAND_status_doc},
@@ -1708,7 +1875,9 @@
unsigned int major, minor, fix, patch, status;
PySocketModule_APIObject *socket_api;
- if (PyType_Ready(&PySSL_Type) < 0)
+ if (PyType_Ready(&PySSLContext_Type) < 0)
+ return NULL;
+ if (PyType_Ready(&PySSLSocket_Type) < 0)
return NULL;
m = PyModule_Create(&_sslmodule);
@@ -1741,8 +1910,11 @@
return NULL;
if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0)
return NULL;
- if (PyDict_SetItemString(d, "SSLType",
- (PyObject *)&PySSL_Type) != 0)
+ if (PyDict_SetItemString(d, "_SSLContext",
+ (PyObject *)&PySSLContext_Type) != 0)
+ return NULL;
+ if (PyDict_SetItemString(d, "_SSLSocket",
+ (PyObject *)&PySSLSocket_Type) != 0)
return NULL;
PyModule_AddIntConstant(m, "SSL_ERROR_ZERO_RETURN",
PY_SSL_ERROR_ZERO_RETURN);
Modified: python/branches/py3k-jit/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/_testcapimodule.c (original)
+++ python/branches/py3k-jit/Modules/_testcapimodule.c Tue May 18 19:58:30 2010
@@ -1551,7 +1551,11 @@
crash_no_current_thread(PyObject *self)
{
Py_BEGIN_ALLOW_THREADS
- PyErr_SetString(PyExc_SystemError, "bork bork bork");
+ /* Using PyThreadState_Get() directly allows the test to pass in
+ !pydebug mode. However, the test only actually tests anything
+ in pydebug mode, since that's where the infinite loop was in
+ the first place. */
+ PyThreadState_Get();
Py_END_ALLOW_THREADS
return NULL;
}
Modified: python/branches/py3k-jit/Modules/_tkinter.c
==============================================================================
--- python/branches/py3k-jit/Modules/_tkinter.c (original)
+++ python/branches/py3k-jit/Modules/_tkinter.c Tue May 18 19:58:30 2010
@@ -3147,9 +3147,7 @@
it also helps Tcl find its encodings. */
uexe = PyUnicode_FromWideChar(Py_GetProgramName(), -1);
if (uexe) {
- cexe = PyUnicode_AsEncodedString(uexe,
- Py_FileSystemDefaultEncoding,
- NULL);
+ cexe = PyUnicode_EncodeFSDefault(uexe);
if (cexe)
Tcl_FindExecutable(PyBytes_AsString(cexe));
Py_XDECREF(cexe);
Modified: python/branches/py3k-jit/Modules/grpmodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/grpmodule.c (original)
+++ python/branches/py3k-jit/Modules/grpmodule.c Tue May 18 19:58:30 2010
@@ -111,8 +111,7 @@
if (!PyArg_ParseTuple(args, "U:getgrnam", &arg))
return NULL;
- if ((bytes = PyUnicode_AsEncodedString(arg, Py_FileSystemDefaultEncoding,
- "surrogateescape")) == NULL)
+ if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
return NULL;
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
goto out;
Modified: python/branches/py3k-jit/Modules/main.c
==============================================================================
--- python/branches/py3k-jit/Modules/main.c (original)
+++ python/branches/py3k-jit/Modules/main.c Tue May 18 19:58:30 2010
@@ -563,18 +563,22 @@
}
if (command) {
+ char *commandStr;
PyObject *commandObj = PyUnicode_FromWideChar(
command, wcslen(command));
free(command);
- if (commandObj != NULL) {
- sts = PyRun_SimpleStringFlags(
- _PyUnicode_AsString(commandObj), &cf) != 0;
+ if (commandObj != NULL)
+ commandStr = _PyUnicode_AsString(commandObj);
+ else
+ commandStr = NULL;
+ if (commandStr != NULL) {
+ sts = PyRun_SimpleStringFlags(commandStr, &cf) != 0;
+ Py_DECREF(commandObj);
}
else {
PyErr_Print();
sts = 1;
}
- Py_DECREF(commandObj);
} else if (module) {
sts = RunModule(module, 1);
}
Modified: python/branches/py3k-jit/Modules/mathmodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/mathmodule.c (original)
+++ python/branches/py3k-jit/Modules/mathmodule.c Tue May 18 19:58:30 2010
@@ -1129,18 +1129,239 @@
Return an accurate floating point sum of values in the iterable.\n\
Assumes IEEE-754 floating point arithmetic.");
+/* Return the smallest integer k such that n < 2**k, or 0 if n == 0.
+ * Equivalent to floor(lg(x))+1. Also equivalent to: bitwidth_of_type -
+ * count_leading_zero_bits(x)
+ */
+
+/* XXX: This routine does more or less the same thing as
+ * bits_in_digit() in Objects/longobject.c. Someday it would be nice to
+ * consolidate them. On BSD, there's a library function called fls()
+ * that we could use, and GCC provides __builtin_clz().
+ */
+
+static unsigned long
+bit_length(unsigned long n)
+{
+ unsigned long len = 0;
+ while (n != 0) {
+ ++len;
+ n >>= 1;
+ }
+ return len;
+}
+
+static unsigned long
+count_set_bits(unsigned long n)
+{
+ unsigned long count = 0;
+ while (n != 0) {
+ ++count;
+ n &= n - 1; /* clear least significant bit */
+ }
+ return count;
+}
+
+/* Divide-and-conquer factorial algorithm
+ *
+ * Based on the formula and psuedo-code provided at:
+ * http://www.luschny.de/math/factorial/binarysplitfact.html
+ *
+ * Faster algorithms exist, but they're more complicated and depend on
+ * a fast prime factoriazation algorithm.
+ *
+ * Notes on the algorithm
+ * ----------------------
+ *
+ * factorial(n) is written in the form 2**k * m, with m odd. k and m are
+ * computed separately, and then combined using a left shift.
+ *
+ * The function factorial_odd_part computes the odd part m (i.e., the greatest
+ * odd divisor) of factorial(n), using the formula:
+ *
+ * factorial_odd_part(n) =
+ *
+ * product_{i >= 0} product_{0 < j <= n / 2**i, j odd} j
+ *
+ * Example: factorial_odd_part(20) =
+ *
+ * (1) *
+ * (1) *
+ * (1 * 3 * 5) *
+ * (1 * 3 * 5 * 7 * 9)
+ * (1 * 3 * 5 * 7 * 9 * 11 * 13 * 15 * 17 * 19)
+ *
+ * Here i goes from large to small: the first term corresponds to i=4 (any
+ * larger i gives an empty product), and the last term corresponds to i=0.
+ * Each term can be computed from the last by multiplying by the extra odd
+ * numbers required: e.g., to get from the penultimate term to the last one,
+ * we multiply by (11 * 13 * 15 * 17 * 19).
+ *
+ * To see a hint of why this formula works, here are the same numbers as above
+ * but with the even parts (i.e., the appropriate powers of 2) included. For
+ * each subterm in the product for i, we multiply that subterm by 2**i:
+ *
+ * factorial(20) =
+ *
+ * (16) *
+ * (8) *
+ * (4 * 12 * 20) *
+ * (2 * 6 * 10 * 14 * 18) *
+ * (1 * 3 * 5 * 7 * 9 * 11 * 13 * 15 * 17 * 19)
+ *
+ * The factorial_partial_product function computes the product of all odd j in
+ * range(start, stop) for given start and stop. It's used to compute the
+ * partial products like (11 * 13 * 15 * 17 * 19) in the example above. It
+ * operates recursively, repeatedly splitting the range into two roughly equal
+ * pieces until the subranges are small enough to be computed using only C
+ * integer arithmetic.
+ *
+ * The two-valuation k (i.e., the exponent of the largest power of 2 dividing
+ * the factorial) is computed independently in the main math_factorial
+ * function. By standard results, its value is:
+ *
+ * two_valuation = n//2 + n//4 + n//8 + ....
+ *
+ * It can be shown (e.g., by complete induction on n) that two_valuation is
+ * equal to n - count_set_bits(n), where count_set_bits(n) gives the number of
+ * '1'-bits in the binary expansion of n.
+ */
+
+/* factorial_partial_product: Compute product(range(start, stop, 2)) using
+ * divide and conquer. Assumes start and stop are odd and stop > start.
+ * max_bits must be >= bit_length(stop - 2). */
+
+static PyObject *
+factorial_partial_product(unsigned long start, unsigned long stop,
+ unsigned long max_bits)
+{
+ unsigned long midpoint, num_operands;
+ PyObject *left = NULL, *right = NULL, *result = NULL;
+
+ /* If the return value will fit an unsigned long, then we can
+ * multiply in a tight, fast loop where each multiply is O(1).
+ * Compute an upper bound on the number of bits required to store
+ * the answer.
+ *
+ * Storing some integer z requires floor(lg(z))+1 bits, which is
+ * conveniently the value returned by bit_length(z). The
+ * product x*y will require at most
+ * bit_length(x) + bit_length(y) bits to store, based
+ * on the idea that lg product = lg x + lg y.
+ *
+ * We know that stop - 2 is the largest number to be multiplied. From
+ * there, we have: bit_length(answer) <= num_operands *
+ * bit_length(stop - 2)
+ */
+
+ num_operands = (stop - start) / 2;
+ /* The "num_operands <= 8 * SIZEOF_LONG" check guards against the
+ * unlikely case of an overflow in num_operands * max_bits. */
+ if (num_operands <= 8 * SIZEOF_LONG &&
+ num_operands * max_bits <= 8 * SIZEOF_LONG) {
+ unsigned long j, total;
+ for (total = start, j = start + 2; j < stop; j += 2)
+ total *= j;
+ return PyLong_FromUnsignedLong(total);
+ }
+
+ /* find midpoint of range(start, stop), rounded up to next odd number. */
+ midpoint = (start + num_operands) | 1;
+ left = factorial_partial_product(start, midpoint,
+ bit_length(midpoint - 2));
+ if (left == NULL)
+ goto error;
+ right = factorial_partial_product(midpoint, stop, max_bits);
+ if (right == NULL)
+ goto error;
+ result = PyNumber_Multiply(left, right);
+
+ error:
+ Py_XDECREF(left);
+ Py_XDECREF(right);
+ return result;
+}
+
+/* factorial_odd_part: compute the odd part of factorial(n). */
+
+static PyObject *
+factorial_odd_part(unsigned long n)
+{
+ long i;
+ unsigned long v, lower, upper;
+ PyObject *partial, *tmp, *inner, *outer;
+
+ inner = PyLong_FromLong(1);
+ if (inner == NULL)
+ return NULL;
+ outer = inner;
+ Py_INCREF(outer);
+
+ upper = 3;
+ for (i = bit_length(n) - 2; i >= 0; i--) {
+ v = n >> i;
+ if (v <= 2)
+ continue;
+ lower = upper;
+ /* (v + 1) | 1 = least odd integer strictly larger than n / 2**i */
+ upper = (v + 1) | 1;
+ /* Here inner is the product of all odd integers j in the range (0,
+ n/2**(i+1)]. The factorial_partial_product call below gives the
+ product of all odd integers j in the range (n/2**(i+1), n/2**i]. */
+ partial = factorial_partial_product(lower, upper, bit_length(upper-2));
+ /* inner *= partial */
+ if (partial == NULL)
+ goto error;
+ tmp = PyNumber_Multiply(inner, partial);
+ Py_DECREF(partial);
+ if (tmp == NULL)
+ goto error;
+ Py_DECREF(inner);
+ inner = tmp;
+ /* Now inner is the product of all odd integers j in the range (0,
+ n/2**i], giving the inner product in the formula above. */
+
+ /* outer *= inner; */
+ tmp = PyNumber_Multiply(outer, inner);
+ if (tmp == NULL)
+ goto error;
+ Py_DECREF(outer);
+ outer = tmp;
+ }
+
+ goto done;
+
+ error:
+ Py_DECREF(outer);
+ done:
+ Py_DECREF(inner);
+ return outer;
+}
+
+/* Lookup table for small factorial values */
+
+static const unsigned long SmallFactorials[] = {
+ 1, 1, 2, 6, 24, 120, 720, 5040, 40320,
+ 362880, 3628800, 39916800, 479001600,
+#if SIZEOF_LONG >= 8
+ 6227020800, 87178291200, 1307674368000,
+ 20922789888000, 355687428096000, 6402373705728000,
+ 121645100408832000, 2432902008176640000
+#endif
+};
+
static PyObject *
math_factorial(PyObject *self, PyObject *arg)
{
- long i, x;
- PyObject *result, *iobj, *newresult;
+ long x;
+ PyObject *result, *odd_part, *two_valuation;
if (PyFloat_Check(arg)) {
PyObject *lx;
double dx = PyFloat_AS_DOUBLE((PyFloatObject *)arg);
if (!(Py_IS_FINITE(dx) && dx == floor(dx))) {
PyErr_SetString(PyExc_ValueError,
- "factorial() only accepts integral values");
+ "factorial() only accepts integral values");
return NULL;
}
lx = PyLong_FromDouble(dx);
@@ -1156,29 +1377,28 @@
return NULL;
if (x < 0) {
PyErr_SetString(PyExc_ValueError,
- "factorial() not defined for negative values");
+ "factorial() not defined for negative values");
return NULL;
}
- result = (PyObject *)PyLong_FromLong(1);
- if (result == NULL)
+ /* use lookup table if x is small */
+ if (x < (long)(sizeof(SmallFactorials)/sizeof(SmallFactorials[0])))
+ return PyLong_FromUnsignedLong(SmallFactorials[x]);
+
+ /* else express in the form odd_part * 2**two_valuation, and compute as
+ odd_part << two_valuation. */
+ odd_part = factorial_odd_part(x);
+ if (odd_part == NULL)
+ return NULL;
+ two_valuation = PyLong_FromLong(x - count_set_bits(x));
+ if (two_valuation == NULL) {
+ Py_DECREF(odd_part);
return NULL;
- for (i=1 ; i<=x ; i++) {
- iobj = (PyObject *)PyLong_FromLong(i);
- if (iobj == NULL)
- goto error;
- newresult = PyNumber_Multiply(result, iobj);
- Py_DECREF(iobj);
- if (newresult == NULL)
- goto error;
- Py_DECREF(result);
- result = newresult;
}
+ result = PyNumber_Lshift(odd_part, two_valuation);
+ Py_DECREF(two_valuation);
+ Py_DECREF(odd_part);
return result;
-
-error:
- Py_DECREF(result);
- return NULL;
}
PyDoc_STRVAR(math_factorial_doc,
Modified: python/branches/py3k-jit/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/posixmodule.c (original)
+++ python/branches/py3k-jit/Modules/posixmodule.c Tue May 18 19:58:30 2010
@@ -2364,33 +2364,17 @@
(NAMLEN(ep) == 1 ||
(ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
continue;
- v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
+ if (arg_is_unicode)
+ v = PyUnicode_DecodeFSDefaultAndSize(ep->d_name, NAMLEN(ep));
+ else
+ v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
if (v == NULL) {
- Py_DECREF(d);
- d = NULL;
+ Py_CLEAR(d);
break;
}
- if (arg_is_unicode) {
- PyObject *w;
-
- w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "surrogateescape");
- Py_DECREF(v);
- if (w != NULL)
- v = w;
- else {
- /* Encoding failed to decode ASCII bytes.
- Raise exception. */
- Py_DECREF(d);
- d = NULL;
- break;
- }
- }
if (PyList_Append(d, v) != 0) {
Py_DECREF(v);
- Py_DECREF(d);
- d = NULL;
+ Py_CLEAR(d);
break;
}
Py_DECREF(v);
@@ -4078,7 +4062,7 @@
static PyObject *
win32_kill(PyObject *self, PyObject *args)
{
- PyObject *result, handle_obj;
+ PyObject *result;
DWORD pid, sig, err;
HANDLE handle;
@@ -4605,22 +4589,10 @@
return posix_error_with_allocated_filename(opath);
Py_DECREF(opath);
- v = PyBytes_FromStringAndSize(buf, n);
- if (arg_is_unicode) {
- PyObject *w;
-
- w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "surrogateescape");
- if (w != NULL) {
- Py_DECREF(v);
- v = w;
- }
- else {
- v = NULL;
- }
- }
- return v;
+ if (arg_is_unicode)
+ return PyUnicode_DecodeFSDefaultAndSize(buf, n);
+ else
+ return PyBytes_FromStringAndSize(buf, n);
}
#endif /* HAVE_READLINK */
Modified: python/branches/py3k-jit/Modules/pwdmodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/pwdmodule.c (original)
+++ python/branches/py3k-jit/Modules/pwdmodule.c Tue May 18 19:58:30 2010
@@ -132,9 +132,7 @@
if (!PyArg_ParseTuple(args, "U:getpwnam", &arg))
return NULL;
- if ((bytes = PyUnicode_AsEncodedString(arg,
- Py_FileSystemDefaultEncoding,
- "surrogateescape")) == NULL)
+ if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
return NULL;
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
goto out;
Modified: python/branches/py3k-jit/Modules/spwdmodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/spwdmodule.c (original)
+++ python/branches/py3k-jit/Modules/spwdmodule.c Tue May 18 19:58:30 2010
@@ -118,9 +118,7 @@
if (!PyArg_ParseTuple(args, "U:getspnam", &arg))
return NULL;
- if ((bytes = PyUnicode_AsEncodedString(arg,
- Py_FileSystemDefaultEncoding,
- "surrogateescape")) == NULL)
+ if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
return NULL;
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
goto out;
Modified: python/branches/py3k-jit/Objects/object.c
==============================================================================
--- python/branches/py3k-jit/Objects/object.c (original)
+++ python/branches/py3k-jit/Objects/object.c Tue May 18 19:58:30 2010
@@ -303,12 +303,15 @@
}
else if (PyUnicode_Check(s)) {
PyObject *t;
- t = _PyUnicode_AsDefaultEncodedString(s, NULL);
+ t = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(s),
+ PyUnicode_GET_SIZE(s),
+ "backslashreplace");
if (t == NULL)
ret = 0;
else {
fwrite(PyBytes_AS_STRING(t), 1,
PyBytes_GET_SIZE(t), fp);
+ Py_DECREF(t);
}
}
else {
Modified: python/branches/py3k-jit/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-jit/Objects/unicodeobject.c (original)
+++ python/branches/py3k-jit/Objects/unicodeobject.c Tue May 18 19:58:30 2010
@@ -1461,6 +1461,18 @@
return NULL;
}
+PyObject *PyUnicode_EncodeFSDefault(PyObject *unicode)
+{
+ if (Py_FileSystemDefaultEncoding)
+ return PyUnicode_AsEncodedString(unicode,
+ Py_FileSystemDefaultEncoding,
+ "surrogateescape");
+ else
+ return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
+ PyUnicode_GET_SIZE(unicode),
+ "surrogateescape");
+}
+
PyObject *PyUnicode_AsEncodedString(PyObject *unicode,
const char *encoding,
const char *errors)
@@ -1476,31 +1488,39 @@
encoding = PyUnicode_GetDefaultEncoding();
/* Shortcuts for common default encodings */
- if (errors == NULL) {
- if (strcmp(encoding, "utf-8") == 0)
- return PyUnicode_AsUTF8String(unicode);
- else if (strcmp(encoding, "latin-1") == 0)
- return PyUnicode_AsLatin1String(unicode);
+ if (strcmp(encoding, "utf-8") == 0)
+ return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
+ PyUnicode_GET_SIZE(unicode),
+ errors);
+ else if (strcmp(encoding, "latin-1") == 0)
+ return PyUnicode_EncodeLatin1(PyUnicode_AS_UNICODE(unicode),
+ PyUnicode_GET_SIZE(unicode),
+ errors);
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
- else if (strcmp(encoding, "mbcs") == 0)
- return PyUnicode_AsMBCSString(unicode);
-#endif
- else if (strcmp(encoding, "ascii") == 0)
- return PyUnicode_AsASCIIString(unicode);
- /* During bootstrap, we may need to find the encodings
- package, to load the file system encoding, and require the
- file system encoding in order to load the encodings
- package.
-
- Break out of this dependency by assuming that the path to
- the encodings module is ASCII-only. XXX could try wcstombs
- instead, if the file system encoding is the locale's
- encoding. */
- else if (Py_FileSystemDefaultEncoding &&
- strcmp(encoding, Py_FileSystemDefaultEncoding) == 0 &&
- !PyThreadState_GET()->interp->codecs_initialized)
- return PyUnicode_AsASCIIString(unicode);
- }
+ else if (strcmp(encoding, "mbcs") == 0)
+ return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode),
+ PyUnicode_GET_SIZE(unicode),
+ errors);
+#endif
+ else if (strcmp(encoding, "ascii") == 0)
+ return PyUnicode_EncodeASCII(PyUnicode_AS_UNICODE(unicode),
+ PyUnicode_GET_SIZE(unicode),
+ errors);
+ /* During bootstrap, we may need to find the encodings
+ package, to load the file system encoding, and require the
+ file system encoding in order to load the encodings
+ package.
+
+ Break out of this dependency by assuming that the path to
+ the encodings module is ASCII-only. XXX could try wcstombs
+ instead, if the file system encoding is the locale's
+ encoding. */
+ else if (Py_FileSystemDefaultEncoding &&
+ strcmp(encoding, Py_FileSystemDefaultEncoding) == 0 &&
+ !PyThreadState_GET()->interp->codecs_initialized)
+ return PyUnicode_EncodeASCII(PyUnicode_AS_UNICODE(unicode),
+ PyUnicode_GET_SIZE(unicode),
+ errors);
/* Encode via the codec registry */
v = PyCodec_Encode(unicode, encoding, errors);
@@ -1638,9 +1658,7 @@
arg = PyUnicode_FromObject(arg);
if (!arg)
return 0;
- output = PyUnicode_AsEncodedObject(arg,
- Py_FileSystemDefaultEncoding,
- "surrogateescape");
+ output = PyUnicode_EncodeFSDefault(arg);
Py_DECREF(arg);
if (!output)
return 0;
Modified: python/branches/py3k-jit/Parser/printgrammar.c
==============================================================================
--- python/branches/py3k-jit/Parser/printgrammar.c (original)
+++ python/branches/py3k-jit/Parser/printgrammar.c Tue May 18 19:58:30 2010
@@ -20,10 +20,10 @@
printdfas(g, fp);
printlabels(g, fp);
fprintf(fp, "grammar _PyParser_Grammar = {\n");
- fprintf(fp, "\t%d,\n", g->g_ndfas);
- fprintf(fp, "\tdfas,\n");
- fprintf(fp, "\t{%d, labels},\n", g->g_ll.ll_nlabels);
- fprintf(fp, "\t%d\n", g->g_start);
+ fprintf(fp, " %d,\n", g->g_ndfas);
+ fprintf(fp, " dfas,\n");
+ fprintf(fp, " {%d, labels},\n", g->g_ll.ll_nlabels);
+ fprintf(fp, " %d\n", g->g_start);
fprintf(fp, "};\n");
}
@@ -53,7 +53,7 @@
i, j, s->s_narcs);
a = s->s_arc;
for (k = 0; k < s->s_narcs; k++, a++)
- fprintf(fp, "\t{%d, %d},\n", a->a_lbl, a->a_arrow);
+ fprintf(fp, " {%d, %d},\n", a->a_lbl, a->a_arrow);
fprintf(fp, "};\n");
}
}
@@ -72,7 +72,7 @@
i, d->d_nstates);
s = d->d_state;
for (j = 0; j < d->d_nstates; j++, s++)
- fprintf(fp, "\t{%d, arcs_%d_%d},\n",
+ fprintf(fp, " {%d, arcs_%d_%d},\n",
s->s_narcs, i, j);
fprintf(fp, "};\n");
}
@@ -88,9 +88,9 @@
fprintf(fp, "static dfa dfas[%d] = {\n", g->g_ndfas);
d = g->g_dfa;
for (i = 0; i < g->g_ndfas; i++, d++) {
- fprintf(fp, "\t{%d, \"%s\", %d, %d, states_%d,\n",
+ fprintf(fp, " {%d, \"%s\", %d, %d, states_%d,\n",
d->d_type, d->d_name, d->d_initial, d->d_nstates, i);
- fprintf(fp, "\t \"");
+ fprintf(fp, " \"");
for (j = 0; j < NBYTES(g->g_ll.ll_nlabels); j++)
fprintf(fp, "\\%03o", d->d_first[j] & 0xff);
fprintf(fp, "\"},\n");
@@ -108,9 +108,9 @@
l = g->g_ll.ll_label;
for (i = g->g_ll.ll_nlabels; --i >= 0; l++) {
if (l->lb_str == NULL)
- fprintf(fp, "\t{%d, 0},\n", l->lb_type);
+ fprintf(fp, " {%d, 0},\n", l->lb_type);
else
- fprintf(fp, "\t{%d, \"%s\"},\n",
+ fprintf(fp, " {%d, \"%s\"},\n",
l->lb_type, l->lb_str);
}
fprintf(fp, "};\n");
Modified: python/branches/py3k-jit/Python/bltinmodule.c
==============================================================================
--- python/branches/py3k-jit/Python/bltinmodule.c (original)
+++ python/branches/py3k-jit/Python/bltinmodule.c Tue May 18 19:58:30 2010
@@ -9,6 +9,10 @@
#include <ctype.h>
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h> /* CODESET */
+#endif
+
/* The default encoding used by the platform file system APIs
Can remain NULL for all platforms that don't have such a concept
@@ -21,9 +25,12 @@
#elif defined(__APPLE__)
const char *Py_FileSystemDefaultEncoding = "utf-8";
int Py_HasFileSystemDefaultEncoding = 1;
-#else
-const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
+#elif defined(HAVE_LANGINFO_H) && defined(CODESET)
+const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */
int Py_HasFileSystemDefaultEncoding = 0;
+#else
+const char *Py_FileSystemDefaultEncoding = "utf-8";
+int Py_HasFileSystemDefaultEncoding = 1;
#endif
int
Modified: python/branches/py3k-jit/Python/graminit.c
==============================================================================
--- python/branches/py3k-jit/Python/graminit.c (original)
+++ python/branches/py3k-jit/Python/graminit.c Tue May 18 19:58:30 2010
@@ -4,2077 +4,2077 @@
#include "grammar.h"
PyAPI_DATA(grammar) _PyParser_Grammar;
static arc arcs_0_0[3] = {
- {2, 1},
- {3, 1},
- {4, 2},
+ {2, 1},
+ {3, 1},
+ {4, 2},
};
static arc arcs_0_1[1] = {
- {0, 1},
+ {0, 1},
};
static arc arcs_0_2[1] = {
- {2, 1},
+ {2, 1},
};
static state states_0[3] = {
- {3, arcs_0_0},
- {1, arcs_0_1},
- {1, arcs_0_2},
+ {3, arcs_0_0},
+ {1, arcs_0_1},
+ {1, arcs_0_2},
};
static arc arcs_1_0[3] = {
- {2, 0},
- {6, 0},
- {7, 1},
+ {2, 0},
+ {6, 0},
+ {7, 1},
};
static arc arcs_1_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_1[2] = {
- {3, arcs_1_0},
- {1, arcs_1_1},
+ {3, arcs_1_0},
+ {1, arcs_1_1},
};
static arc arcs_2_0[1] = {
- {9, 1},
+ {9, 1},
};
static arc arcs_2_1[2] = {
- {2, 1},
- {7, 2},
+ {2, 1},
+ {7, 2},
};
static arc arcs_2_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_2[3] = {
- {1, arcs_2_0},
- {2, arcs_2_1},
- {1, arcs_2_2},
+ {1, arcs_2_0},
+ {2, arcs_2_1},
+ {1, arcs_2_2},
};
static arc arcs_3_0[1] = {
- {11, 1},
+ {11, 1},
};
static arc arcs_3_1[1] = {
- {12, 2},
+ {12, 2},
};
static arc arcs_3_2[2] = {
- {13, 3},
- {2, 4},
+ {13, 3},
+ {2, 4},
};
static arc arcs_3_3[2] = {
- {14, 5},
- {15, 6},
+ {14, 5},
+ {15, 6},
};
static arc arcs_3_4[1] = {
- {0, 4},
+ {0, 4},
};
static arc arcs_3_5[1] = {
- {15, 6},
+ {15, 6},
};
static arc arcs_3_6[1] = {
- {2, 4},
+ {2, 4},
};
static state states_3[7] = {
- {1, arcs_3_0},
- {1, arcs_3_1},
- {2, arcs_3_2},
- {2, arcs_3_3},
- {1, arcs_3_4},
- {1, arcs_3_5},
- {1, arcs_3_6},
+ {1, arcs_3_0},
+ {1, arcs_3_1},
+ {2, arcs_3_2},
+ {2, arcs_3_3},
+ {1, arcs_3_4},
+ {1, arcs_3_5},
+ {1, arcs_3_6},
};
static arc arcs_4_0[1] = {
- {10, 1},
+ {10, 1},
};
static arc arcs_4_1[2] = {
- {10, 1},
- {0, 1},
+ {10, 1},
+ {0, 1},
};
static state states_4[2] = {
- {1, arcs_4_0},
- {2, arcs_4_1},
+ {1, arcs_4_0},
+ {2, arcs_4_1},
};
static arc arcs_5_0[1] = {
- {16, 1},
+ {16, 1},
};
static arc arcs_5_1[2] = {
- {18, 2},
- {19, 2},
+ {18, 2},
+ {19, 2},
};
static arc arcs_5_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_5[3] = {
- {1, arcs_5_0},
- {2, arcs_5_1},
- {1, arcs_5_2},
+ {1, arcs_5_0},
+ {2, arcs_5_1},
+ {1, arcs_5_2},
};
static arc arcs_6_0[1] = {
- {20, 1},
+ {20, 1},
};
static arc arcs_6_1[1] = {
- {21, 2},
+ {21, 2},
};
static arc arcs_6_2[1] = {
- {22, 3},
+ {22, 3},
};
static arc arcs_6_3[2] = {
- {23, 4},
- {25, 5},
+ {23, 4},
+ {25, 5},
};
static arc arcs_6_4[1] = {
- {24, 6},
+ {24, 6},
};
static arc arcs_6_5[1] = {
- {26, 7},
+ {26, 7},
};
static arc arcs_6_6[1] = {
- {25, 5},
+ {25, 5},
};
static arc arcs_6_7[1] = {
- {0, 7},
+ {0, 7},
};
static state states_6[8] = {
- {1, arcs_6_0},
- {1, arcs_6_1},
- {1, arcs_6_2},
- {2, arcs_6_3},
- {1, arcs_6_4},
- {1, arcs_6_5},
- {1, arcs_6_6},
- {1, arcs_6_7},
+ {1, arcs_6_0},
+ {1, arcs_6_1},
+ {1, arcs_6_2},
+ {2, arcs_6_3},
+ {1, arcs_6_4},
+ {1, arcs_6_5},
+ {1, arcs_6_6},
+ {1, arcs_6_7},
};
static arc arcs_7_0[1] = {
- {13, 1},
+ {13, 1},
};
static arc arcs_7_1[2] = {
- {27, 2},
- {15, 3},
+ {27, 2},
+ {15, 3},
};
static arc arcs_7_2[1] = {
- {15, 3},
+ {15, 3},
};
static arc arcs_7_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_7[4] = {
- {1, arcs_7_0},
- {2, arcs_7_1},
- {1, arcs_7_2},
- {1, arcs_7_3},
+ {1, arcs_7_0},
+ {2, arcs_7_1},
+ {1, arcs_7_2},
+ {1, arcs_7_3},
};
static arc arcs_8_0[3] = {
- {28, 1},
- {31, 2},
- {32, 3},
+ {28, 1},
+ {31, 2},
+ {32, 3},
};
static arc arcs_8_1[3] = {
- {29, 4},
- {30, 5},
- {0, 1},
+ {29, 4},
+ {30, 5},
+ {0, 1},
};
static arc arcs_8_2[3] = {
- {28, 6},
- {30, 7},
- {0, 2},
+ {28, 6},
+ {30, 7},
+ {0, 2},
};
static arc arcs_8_3[1] = {
- {28, 8},
+ {28, 8},
};
static arc arcs_8_4[1] = {
- {24, 9},
+ {24, 9},
};
static arc arcs_8_5[4] = {
- {28, 1},
- {31, 2},
- {32, 3},
- {0, 5},
+ {28, 1},
+ {31, 2},
+ {32, 3},
+ {0, 5},
};
static arc arcs_8_6[2] = {
- {30, 7},
- {0, 6},
+ {30, 7},
+ {0, 6},
};
static arc arcs_8_7[2] = {
- {28, 10},
- {32, 3},
+ {28, 10},
+ {32, 3},
};
static arc arcs_8_8[1] = {
- {0, 8},
+ {0, 8},
};
static arc arcs_8_9[2] = {
- {30, 5},
- {0, 9},
+ {30, 5},
+ {0, 9},
};
static arc arcs_8_10[3] = {
- {30, 7},
- {29, 11},
- {0, 10},
+ {30, 7},
+ {29, 11},
+ {0, 10},
};
static arc arcs_8_11[1] = {
- {24, 6},
+ {24, 6},
};
static state states_8[12] = {
- {3, arcs_8_0},
- {3, arcs_8_1},
- {3, arcs_8_2},
- {1, arcs_8_3},
- {1, arcs_8_4},
- {4, arcs_8_5},
- {2, arcs_8_6},
- {2, arcs_8_7},
- {1, arcs_8_8},
- {2, arcs_8_9},
- {3, arcs_8_10},
- {1, arcs_8_11},
+ {3, arcs_8_0},
+ {3, arcs_8_1},
+ {3, arcs_8_2},
+ {1, arcs_8_3},
+ {1, arcs_8_4},
+ {4, arcs_8_5},
+ {2, arcs_8_6},
+ {2, arcs_8_7},
+ {1, arcs_8_8},
+ {2, arcs_8_9},
+ {3, arcs_8_10},
+ {1, arcs_8_11},
};
static arc arcs_9_0[1] = {
- {21, 1},
+ {21, 1},
};
static arc arcs_9_1[2] = {
- {25, 2},
- {0, 1},
+ {25, 2},
+ {0, 1},
};
static arc arcs_9_2[1] = {
- {24, 3},
+ {24, 3},
};
static arc arcs_9_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_9[4] = {
- {1, arcs_9_0},
- {2, arcs_9_1},
- {1, arcs_9_2},
- {1, arcs_9_3},
+ {1, arcs_9_0},
+ {2, arcs_9_1},
+ {1, arcs_9_2},
+ {1, arcs_9_3},
};
static arc arcs_10_0[3] = {
- {34, 1},
- {31, 2},
- {32, 3},
+ {34, 1},
+ {31, 2},
+ {32, 3},
};
static arc arcs_10_1[3] = {
- {29, 4},
- {30, 5},
- {0, 1},
+ {29, 4},
+ {30, 5},
+ {0, 1},
};
static arc arcs_10_2[3] = {
- {34, 6},
- {30, 7},
- {0, 2},
+ {34, 6},
+ {30, 7},
+ {0, 2},
};
static arc arcs_10_3[1] = {
- {34, 8},
+ {34, 8},
};
static arc arcs_10_4[1] = {
- {24, 9},
+ {24, 9},
};
static arc arcs_10_5[4] = {
- {34, 1},
- {31, 2},
- {32, 3},
- {0, 5},
+ {34, 1},
+ {31, 2},
+ {32, 3},
+ {0, 5},
};
static arc arcs_10_6[2] = {
- {30, 7},
- {0, 6},
+ {30, 7},
+ {0, 6},
};
static arc arcs_10_7[2] = {
- {34, 10},
- {32, 3},
+ {34, 10},
+ {32, 3},
};
static arc arcs_10_8[1] = {
- {0, 8},
+ {0, 8},
};
static arc arcs_10_9[2] = {
- {30, 5},
- {0, 9},
+ {30, 5},
+ {0, 9},
};
static arc arcs_10_10[3] = {
- {30, 7},
- {29, 11},
- {0, 10},
+ {30, 7},
+ {29, 11},
+ {0, 10},
};
static arc arcs_10_11[1] = {
- {24, 6},
+ {24, 6},
};
static state states_10[12] = {
- {3, arcs_10_0},
- {3, arcs_10_1},
- {3, arcs_10_2},
- {1, arcs_10_3},
- {1, arcs_10_4},
- {4, arcs_10_5},
- {2, arcs_10_6},
- {2, arcs_10_7},
- {1, arcs_10_8},
- {2, arcs_10_9},
- {3, arcs_10_10},
- {1, arcs_10_11},
+ {3, arcs_10_0},
+ {3, arcs_10_1},
+ {3, arcs_10_2},
+ {1, arcs_10_3},
+ {1, arcs_10_4},
+ {4, arcs_10_5},
+ {2, arcs_10_6},
+ {2, arcs_10_7},
+ {1, arcs_10_8},
+ {2, arcs_10_9},
+ {3, arcs_10_10},
+ {1, arcs_10_11},
};
static arc arcs_11_0[1] = {
- {21, 1},
+ {21, 1},
};
static arc arcs_11_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_11[2] = {
- {1, arcs_11_0},
- {1, arcs_11_1},
+ {1, arcs_11_0},
+ {1, arcs_11_1},
};
static arc arcs_12_0[2] = {
- {3, 1},
- {4, 1},
+ {3, 1},
+ {4, 1},
};
static arc arcs_12_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_12[2] = {
- {2, arcs_12_0},
- {1, arcs_12_1},
+ {2, arcs_12_0},
+ {1, arcs_12_1},
};
static arc arcs_13_0[1] = {
- {35, 1},
+ {35, 1},
};
static arc arcs_13_1[2] = {
- {36, 2},
- {2, 3},
+ {36, 2},
+ {2, 3},
};
static arc arcs_13_2[2] = {
- {35, 1},
- {2, 3},
+ {35, 1},
+ {2, 3},
};
static arc arcs_13_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_13[4] = {
- {1, arcs_13_0},
- {2, arcs_13_1},
- {2, arcs_13_2},
- {1, arcs_13_3},
+ {1, arcs_13_0},
+ {2, arcs_13_1},
+ {2, arcs_13_2},
+ {1, arcs_13_3},
};
static arc arcs_14_0[8] = {
- {37, 1},
- {38, 1},
- {39, 1},
- {40, 1},
- {41, 1},
- {42, 1},
- {43, 1},
- {44, 1},
+ {37, 1},
+ {38, 1},
+ {39, 1},
+ {40, 1},
+ {41, 1},
+ {42, 1},
+ {43, 1},
+ {44, 1},
};
static arc arcs_14_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_14[2] = {
- {8, arcs_14_0},
- {1, arcs_14_1},
+ {8, arcs_14_0},
+ {1, arcs_14_1},
};
static arc arcs_15_0[1] = {
- {45, 1},
+ {45, 1},
};
static arc arcs_15_1[3] = {
- {46, 2},
- {29, 3},
- {0, 1},
+ {46, 2},
+ {29, 3},
+ {0, 1},
};
static arc arcs_15_2[2] = {
- {47, 4},
- {9, 4},
+ {47, 4},
+ {9, 4},
};
static arc arcs_15_3[2] = {
- {47, 5},
- {45, 5},
+ {47, 5},
+ {45, 5},
};
static arc arcs_15_4[1] = {
- {0, 4},
+ {0, 4},
};
static arc arcs_15_5[2] = {
- {29, 3},
- {0, 5},
+ {29, 3},
+ {0, 5},
};
static state states_15[6] = {
- {1, arcs_15_0},
- {3, arcs_15_1},
- {2, arcs_15_2},
- {2, arcs_15_3},
- {1, arcs_15_4},
- {2, arcs_15_5},
+ {1, arcs_15_0},
+ {3, arcs_15_1},
+ {2, arcs_15_2},
+ {2, arcs_15_3},
+ {1, arcs_15_4},
+ {2, arcs_15_5},
};
static arc arcs_16_0[2] = {
- {24, 1},
- {48, 1},
+ {24, 1},
+ {48, 1},
};
static arc arcs_16_1[2] = {
- {30, 2},
- {0, 1},
+ {30, 2},
+ {0, 1},
};
static arc arcs_16_2[3] = {
- {24, 1},
- {48, 1},
- {0, 2},
+ {24, 1},
+ {48, 1},
+ {0, 2},
};
static state states_16[3] = {
- {2, arcs_16_0},
- {2, arcs_16_1},
- {3, arcs_16_2},
+ {2, arcs_16_0},
+ {2, arcs_16_1},
+ {3, arcs_16_2},
};
static arc arcs_17_0[12] = {
- {49, 1},
- {50, 1},
- {51, 1},
- {52, 1},
- {53, 1},
- {54, 1},
- {55, 1},
- {56, 1},
- {57, 1},
- {58, 1},
- {59, 1},
- {60, 1},
+ {49, 1},
+ {50, 1},
+ {51, 1},
+ {52, 1},
+ {53, 1},
+ {54, 1},
+ {55, 1},
+ {56, 1},
+ {57, 1},
+ {58, 1},
+ {59, 1},
+ {60, 1},
};
static arc arcs_17_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_17[2] = {
- {12, arcs_17_0},
- {1, arcs_17_1},
+ {12, arcs_17_0},
+ {1, arcs_17_1},
};
static arc arcs_18_0[1] = {
- {61, 1},
+ {61, 1},
};
static arc arcs_18_1[1] = {
- {62, 2},
+ {62, 2},
};
static arc arcs_18_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_18[3] = {
- {1, arcs_18_0},
- {1, arcs_18_1},
- {1, arcs_18_2},
+ {1, arcs_18_0},
+ {1, arcs_18_1},
+ {1, arcs_18_2},
};
static arc arcs_19_0[1] = {
- {63, 1},
+ {63, 1},
};
static arc arcs_19_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_19[2] = {
- {1, arcs_19_0},
- {1, arcs_19_1},
+ {1, arcs_19_0},
+ {1, arcs_19_1},
};
static arc arcs_20_0[5] = {
- {64, 1},
- {65, 1},
- {66, 1},
- {67, 1},
- {68, 1},
+ {64, 1},
+ {65, 1},
+ {66, 1},
+ {67, 1},
+ {68, 1},
};
static arc arcs_20_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_20[2] = {
- {5, arcs_20_0},
- {1, arcs_20_1},
+ {5, arcs_20_0},
+ {1, arcs_20_1},
};
static arc arcs_21_0[1] = {
- {69, 1},
+ {69, 1},
};
static arc arcs_21_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_21[2] = {
- {1, arcs_21_0},
- {1, arcs_21_1},
+ {1, arcs_21_0},
+ {1, arcs_21_1},
};
static arc arcs_22_0[1] = {
- {70, 1},
+ {70, 1},
};
static arc arcs_22_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_22[2] = {
- {1, arcs_22_0},
- {1, arcs_22_1},
+ {1, arcs_22_0},
+ {1, arcs_22_1},
};
static arc arcs_23_0[1] = {
- {71, 1},
+ {71, 1},
};
static arc arcs_23_1[2] = {
- {9, 2},
- {0, 1},
+ {9, 2},
+ {0, 1},
};
static arc arcs_23_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_23[3] = {
- {1, arcs_23_0},
- {2, arcs_23_1},
- {1, arcs_23_2},
+ {1, arcs_23_0},
+ {2, arcs_23_1},
+ {1, arcs_23_2},
};
static arc arcs_24_0[1] = {
- {47, 1},
+ {47, 1},
};
static arc arcs_24_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_24[2] = {
- {1, arcs_24_0},
- {1, arcs_24_1},
+ {1, arcs_24_0},
+ {1, arcs_24_1},
};
static arc arcs_25_0[1] = {
- {72, 1},
+ {72, 1},
};
static arc arcs_25_1[2] = {
- {24, 2},
- {0, 1},
+ {24, 2},
+ {0, 1},
};
static arc arcs_25_2[2] = {
- {73, 3},
- {0, 2},
+ {73, 3},
+ {0, 2},
};
static arc arcs_25_3[1] = {
- {24, 4},
+ {24, 4},
};
static arc arcs_25_4[1] = {
- {0, 4},
+ {0, 4},
};
static state states_25[5] = {
- {1, arcs_25_0},
- {2, arcs_25_1},
- {2, arcs_25_2},
- {1, arcs_25_3},
- {1, arcs_25_4},
+ {1, arcs_25_0},
+ {2, arcs_25_1},
+ {2, arcs_25_2},
+ {1, arcs_25_3},
+ {1, arcs_25_4},
};
static arc arcs_26_0[2] = {
- {74, 1},
- {75, 1},
+ {74, 1},
+ {75, 1},
};
static arc arcs_26_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_26[2] = {
- {2, arcs_26_0},
- {1, arcs_26_1},
+ {2, arcs_26_0},
+ {1, arcs_26_1},
};
static arc arcs_27_0[1] = {
- {76, 1},
+ {76, 1},
};
static arc arcs_27_1[1] = {
- {77, 2},
+ {77, 2},
};
static arc arcs_27_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_27[3] = {
- {1, arcs_27_0},
- {1, arcs_27_1},
- {1, arcs_27_2},
+ {1, arcs_27_0},
+ {1, arcs_27_1},
+ {1, arcs_27_2},
};
static arc arcs_28_0[1] = {
- {73, 1},
+ {73, 1},
};
static arc arcs_28_1[3] = {
- {78, 2},
- {79, 2},
- {12, 3},
+ {78, 2},
+ {79, 2},
+ {12, 3},
};
static arc arcs_28_2[4] = {
- {78, 2},
- {79, 2},
- {12, 3},
- {76, 4},
+ {78, 2},
+ {79, 2},
+ {12, 3},
+ {76, 4},
};
static arc arcs_28_3[1] = {
- {76, 4},
+ {76, 4},
};
static arc arcs_28_4[3] = {
- {31, 5},
- {13, 6},
- {80, 5},
+ {31, 5},
+ {13, 6},
+ {80, 5},
};
static arc arcs_28_5[1] = {
- {0, 5},
+ {0, 5},
};
static arc arcs_28_6[1] = {
- {80, 7},
+ {80, 7},
};
static arc arcs_28_7[1] = {
- {15, 5},
+ {15, 5},
};
static state states_28[8] = {
- {1, arcs_28_0},
- {3, arcs_28_1},
- {4, arcs_28_2},
- {1, arcs_28_3},
- {3, arcs_28_4},
- {1, arcs_28_5},
- {1, arcs_28_6},
- {1, arcs_28_7},
+ {1, arcs_28_0},
+ {3, arcs_28_1},
+ {4, arcs_28_2},
+ {1, arcs_28_3},
+ {3, arcs_28_4},
+ {1, arcs_28_5},
+ {1, arcs_28_6},
+ {1, arcs_28_7},
};
static arc arcs_29_0[1] = {
- {21, 1},
+ {21, 1},
};
static arc arcs_29_1[2] = {
- {82, 2},
- {0, 1},
+ {82, 2},
+ {0, 1},
};
static arc arcs_29_2[1] = {
- {21, 3},
+ {21, 3},
};
static arc arcs_29_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_29[4] = {
- {1, arcs_29_0},
- {2, arcs_29_1},
- {1, arcs_29_2},
- {1, arcs_29_3},
+ {1, arcs_29_0},
+ {2, arcs_29_1},
+ {1, arcs_29_2},
+ {1, arcs_29_3},
};
static arc arcs_30_0[1] = {
- {12, 1},
+ {12, 1},
};
static arc arcs_30_1[2] = {
- {82, 2},
- {0, 1},
+ {82, 2},
+ {0, 1},
};
static arc arcs_30_2[1] = {
- {21, 3},
+ {21, 3},
};
static arc arcs_30_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_30[4] = {
- {1, arcs_30_0},
- {2, arcs_30_1},
- {1, arcs_30_2},
- {1, arcs_30_3},
+ {1, arcs_30_0},
+ {2, arcs_30_1},
+ {1, arcs_30_2},
+ {1, arcs_30_3},
};
static arc arcs_31_0[1] = {
- {81, 1},
+ {81, 1},
};
static arc arcs_31_1[2] = {
- {30, 2},
- {0, 1},
+ {30, 2},
+ {0, 1},
};
static arc arcs_31_2[2] = {
- {81, 1},
- {0, 2},
+ {81, 1},
+ {0, 2},
};
static state states_31[3] = {
- {1, arcs_31_0},
- {2, arcs_31_1},
- {2, arcs_31_2},
+ {1, arcs_31_0},
+ {2, arcs_31_1},
+ {2, arcs_31_2},
};
static arc arcs_32_0[1] = {
- {83, 1},
+ {83, 1},
};
static arc arcs_32_1[2] = {
- {30, 0},
- {0, 1},
+ {30, 0},
+ {0, 1},
};
static state states_32[2] = {
- {1, arcs_32_0},
- {2, arcs_32_1},
+ {1, arcs_32_0},
+ {2, arcs_32_1},
};
static arc arcs_33_0[1] = {
- {21, 1},
+ {21, 1},
};
static arc arcs_33_1[2] = {
- {78, 0},
- {0, 1},
+ {78, 0},
+ {0, 1},
};
static state states_33[2] = {
- {1, arcs_33_0},
- {2, arcs_33_1},
+ {1, arcs_33_0},
+ {2, arcs_33_1},
};
static arc arcs_34_0[1] = {
- {84, 1},
+ {84, 1},
};
static arc arcs_34_1[1] = {
- {21, 2},
+ {21, 2},
};
static arc arcs_34_2[2] = {
- {30, 1},
- {0, 2},
+ {30, 1},
+ {0, 2},
};
static state states_34[3] = {
- {1, arcs_34_0},
- {1, arcs_34_1},
- {2, arcs_34_2},
+ {1, arcs_34_0},
+ {1, arcs_34_1},
+ {2, arcs_34_2},
};
static arc arcs_35_0[1] = {
- {85, 1},
+ {85, 1},
};
static arc arcs_35_1[1] = {
- {21, 2},
+ {21, 2},
};
static arc arcs_35_2[2] = {
- {30, 1},
- {0, 2},
+ {30, 1},
+ {0, 2},
};
static state states_35[3] = {
- {1, arcs_35_0},
- {1, arcs_35_1},
- {2, arcs_35_2},
+ {1, arcs_35_0},
+ {1, arcs_35_1},
+ {2, arcs_35_2},
};
static arc arcs_36_0[1] = {
- {86, 1},
+ {86, 1},
};
static arc arcs_36_1[1] = {
- {24, 2},
+ {24, 2},
};
static arc arcs_36_2[2] = {
- {30, 3},
- {0, 2},
+ {30, 3},
+ {0, 2},
};
static arc arcs_36_3[1] = {
- {24, 4},
+ {24, 4},
};
static arc arcs_36_4[1] = {
- {0, 4},
+ {0, 4},
};
static state states_36[5] = {
- {1, arcs_36_0},
- {1, arcs_36_1},
- {2, arcs_36_2},
- {1, arcs_36_3},
- {1, arcs_36_4},
+ {1, arcs_36_0},
+ {1, arcs_36_1},
+ {2, arcs_36_2},
+ {1, arcs_36_3},
+ {1, arcs_36_4},
};
static arc arcs_37_0[8] = {
- {87, 1},
- {88, 1},
- {89, 1},
- {90, 1},
- {91, 1},
- {19, 1},
- {18, 1},
- {17, 1},
+ {87, 1},
+ {88, 1},
+ {89, 1},
+ {90, 1},
+ {91, 1},
+ {19, 1},
+ {18, 1},
+ {17, 1},
};
static arc arcs_37_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_37[2] = {
- {8, arcs_37_0},
- {1, arcs_37_1},
+ {8, arcs_37_0},
+ {1, arcs_37_1},
};
static arc arcs_38_0[1] = {
- {92, 1},
+ {92, 1},
};
static arc arcs_38_1[1] = {
- {24, 2},
+ {24, 2},
};
static arc arcs_38_2[1] = {
- {25, 3},
+ {25, 3},
};
static arc arcs_38_3[1] = {
- {26, 4},
+ {26, 4},
};
static arc arcs_38_4[3] = {
- {93, 1},
- {94, 5},
- {0, 4},
+ {93, 1},
+ {94, 5},
+ {0, 4},
};
static arc arcs_38_5[1] = {
- {25, 6},
+ {25, 6},
};
static arc arcs_38_6[1] = {
- {26, 7},
+ {26, 7},
};
static arc arcs_38_7[1] = {
- {0, 7},
+ {0, 7},
};
static state states_38[8] = {
- {1, arcs_38_0},
- {1, arcs_38_1},
- {1, arcs_38_2},
- {1, arcs_38_3},
- {3, arcs_38_4},
- {1, arcs_38_5},
- {1, arcs_38_6},
- {1, arcs_38_7},
+ {1, arcs_38_0},
+ {1, arcs_38_1},
+ {1, arcs_38_2},
+ {1, arcs_38_3},
+ {3, arcs_38_4},
+ {1, arcs_38_5},
+ {1, arcs_38_6},
+ {1, arcs_38_7},
};
static arc arcs_39_0[1] = {
- {95, 1},
+ {95, 1},
};
static arc arcs_39_1[1] = {
- {24, 2},
+ {24, 2},
};
static arc arcs_39_2[1] = {
- {25, 3},
+ {25, 3},
};
static arc arcs_39_3[1] = {
- {26, 4},
+ {26, 4},
};
static arc arcs_39_4[2] = {
- {94, 5},
- {0, 4},
+ {94, 5},
+ {0, 4},
};
static arc arcs_39_5[1] = {
- {25, 6},
+ {25, 6},
};
static arc arcs_39_6[1] = {
- {26, 7},
+ {26, 7},
};
static arc arcs_39_7[1] = {
- {0, 7},
+ {0, 7},
};
static state states_39[8] = {
- {1, arcs_39_0},
- {1, arcs_39_1},
- {1, arcs_39_2},
- {1, arcs_39_3},
- {2, arcs_39_4},
- {1, arcs_39_5},
- {1, arcs_39_6},
- {1, arcs_39_7},
+ {1, arcs_39_0},
+ {1, arcs_39_1},
+ {1, arcs_39_2},
+ {1, arcs_39_3},
+ {2, arcs_39_4},
+ {1, arcs_39_5},
+ {1, arcs_39_6},
+ {1, arcs_39_7},
};
static arc arcs_40_0[1] = {
- {96, 1},
+ {96, 1},
};
static arc arcs_40_1[1] = {
- {62, 2},
+ {62, 2},
};
static arc arcs_40_2[1] = {
- {97, 3},
+ {97, 3},
};
static arc arcs_40_3[1] = {
- {9, 4},
+ {9, 4},
};
static arc arcs_40_4[1] = {
- {25, 5},
+ {25, 5},
};
static arc arcs_40_5[1] = {
- {26, 6},
+ {26, 6},
};
static arc arcs_40_6[2] = {
- {94, 7},
- {0, 6},
+ {94, 7},
+ {0, 6},
};
static arc arcs_40_7[1] = {
- {25, 8},
+ {25, 8},
};
static arc arcs_40_8[1] = {
- {26, 9},
+ {26, 9},
};
static arc arcs_40_9[1] = {
- {0, 9},
+ {0, 9},
};
static state states_40[10] = {
- {1, arcs_40_0},
- {1, arcs_40_1},
- {1, arcs_40_2},
- {1, arcs_40_3},
- {1, arcs_40_4},
- {1, arcs_40_5},
- {2, arcs_40_6},
- {1, arcs_40_7},
- {1, arcs_40_8},
- {1, arcs_40_9},
+ {1, arcs_40_0},
+ {1, arcs_40_1},
+ {1, arcs_40_2},
+ {1, arcs_40_3},
+ {1, arcs_40_4},
+ {1, arcs_40_5},
+ {2, arcs_40_6},
+ {1, arcs_40_7},
+ {1, arcs_40_8},
+ {1, arcs_40_9},
};
static arc arcs_41_0[1] = {
- {98, 1},
+ {98, 1},
};
static arc arcs_41_1[1] = {
- {25, 2},
+ {25, 2},
};
static arc arcs_41_2[1] = {
- {26, 3},
+ {26, 3},
};
static arc arcs_41_3[2] = {
- {99, 4},
- {100, 5},
+ {99, 4},
+ {100, 5},
};
static arc arcs_41_4[1] = {
- {25, 6},
+ {25, 6},
};
static arc arcs_41_5[1] = {
- {25, 7},
+ {25, 7},
};
static arc arcs_41_6[1] = {
- {26, 8},
+ {26, 8},
};
static arc arcs_41_7[1] = {
- {26, 9},
+ {26, 9},
};
static arc arcs_41_8[4] = {
- {99, 4},
- {94, 10},
- {100, 5},
- {0, 8},
+ {99, 4},
+ {94, 10},
+ {100, 5},
+ {0, 8},
};
static arc arcs_41_9[1] = {
- {0, 9},
+ {0, 9},
};
static arc arcs_41_10[1] = {
- {25, 11},
+ {25, 11},
};
static arc arcs_41_11[1] = {
- {26, 12},
+ {26, 12},
};
static arc arcs_41_12[2] = {
- {100, 5},
- {0, 12},
+ {100, 5},
+ {0, 12},
};
static state states_41[13] = {
- {1, arcs_41_0},
- {1, arcs_41_1},
- {1, arcs_41_2},
- {2, arcs_41_3},
- {1, arcs_41_4},
- {1, arcs_41_5},
- {1, arcs_41_6},
- {1, arcs_41_7},
- {4, arcs_41_8},
- {1, arcs_41_9},
- {1, arcs_41_10},
- {1, arcs_41_11},
- {2, arcs_41_12},
+ {1, arcs_41_0},
+ {1, arcs_41_1},
+ {1, arcs_41_2},
+ {2, arcs_41_3},
+ {1, arcs_41_4},
+ {1, arcs_41_5},
+ {1, arcs_41_6},
+ {1, arcs_41_7},
+ {4, arcs_41_8},
+ {1, arcs_41_9},
+ {1, arcs_41_10},
+ {1, arcs_41_11},
+ {2, arcs_41_12},
};
static arc arcs_42_0[1] = {
- {101, 1},
+ {101, 1},
};
static arc arcs_42_1[1] = {
- {102, 2},
+ {102, 2},
};
static arc arcs_42_2[2] = {
- {30, 1},
- {25, 3},
+ {30, 1},
+ {25, 3},
};
static arc arcs_42_3[1] = {
- {26, 4},
+ {26, 4},
};
static arc arcs_42_4[1] = {
- {0, 4},
+ {0, 4},
};
static state states_42[5] = {
- {1, arcs_42_0},
- {1, arcs_42_1},
- {2, arcs_42_2},
- {1, arcs_42_3},
- {1, arcs_42_4},
+ {1, arcs_42_0},
+ {1, arcs_42_1},
+ {2, arcs_42_2},
+ {1, arcs_42_3},
+ {1, arcs_42_4},
};
static arc arcs_43_0[1] = {
- {24, 1},
+ {24, 1},
};
static arc arcs_43_1[2] = {
- {82, 2},
- {0, 1},
+ {82, 2},
+ {0, 1},
};
static arc arcs_43_2[1] = {
- {103, 3},
+ {103, 3},
};
static arc arcs_43_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_43[4] = {
- {1, arcs_43_0},
- {2, arcs_43_1},
- {1, arcs_43_2},
- {1, arcs_43_3},
+ {1, arcs_43_0},
+ {2, arcs_43_1},
+ {1, arcs_43_2},
+ {1, arcs_43_3},
};
static arc arcs_44_0[1] = {
- {104, 1},
+ {104, 1},
};
static arc arcs_44_1[2] = {
- {24, 2},
- {0, 1},
+ {24, 2},
+ {0, 1},
};
static arc arcs_44_2[2] = {
- {82, 3},
- {0, 2},
+ {82, 3},
+ {0, 2},
};
static arc arcs_44_3[1] = {
- {21, 4},
+ {21, 4},
};
static arc arcs_44_4[1] = {
- {0, 4},
+ {0, 4},
};
static state states_44[5] = {
- {1, arcs_44_0},
- {2, arcs_44_1},
- {2, arcs_44_2},
- {1, arcs_44_3},
- {1, arcs_44_4},
+ {1, arcs_44_0},
+ {2, arcs_44_1},
+ {2, arcs_44_2},
+ {1, arcs_44_3},
+ {1, arcs_44_4},
};
static arc arcs_45_0[2] = {
- {3, 1},
- {2, 2},
+ {3, 1},
+ {2, 2},
};
static arc arcs_45_1[1] = {
- {0, 1},
+ {0, 1},
};
static arc arcs_45_2[1] = {
- {105, 3},
+ {105, 3},
};
static arc arcs_45_3[1] = {
- {6, 4},
+ {6, 4},
};
static arc arcs_45_4[2] = {
- {6, 4},
- {106, 1},
+ {6, 4},
+ {106, 1},
};
static state states_45[5] = {
- {2, arcs_45_0},
- {1, arcs_45_1},
- {1, arcs_45_2},
- {1, arcs_45_3},
- {2, arcs_45_4},
+ {2, arcs_45_0},
+ {1, arcs_45_1},
+ {1, arcs_45_2},
+ {1, arcs_45_3},
+ {2, arcs_45_4},
};
static arc arcs_46_0[2] = {
- {107, 1},
- {108, 2},
+ {107, 1},
+ {108, 2},
};
static arc arcs_46_1[2] = {
- {92, 3},
- {0, 1},
+ {92, 3},
+ {0, 1},
};
static arc arcs_46_2[1] = {
- {0, 2},
+ {0, 2},
};
static arc arcs_46_3[1] = {
- {107, 4},
+ {107, 4},
};
static arc arcs_46_4[1] = {
- {94, 5},
+ {94, 5},
};
static arc arcs_46_5[1] = {
- {24, 2},
+ {24, 2},
};
static state states_46[6] = {
- {2, arcs_46_0},
- {2, arcs_46_1},
- {1, arcs_46_2},
- {1, arcs_46_3},
- {1, arcs_46_4},
- {1, arcs_46_5},
+ {2, arcs_46_0},
+ {2, arcs_46_1},
+ {1, arcs_46_2},
+ {1, arcs_46_3},
+ {1, arcs_46_4},
+ {1, arcs_46_5},
};
static arc arcs_47_0[2] = {
- {107, 1},
- {110, 1},
+ {107, 1},
+ {110, 1},
};
static arc arcs_47_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_47[2] = {
- {2, arcs_47_0},
- {1, arcs_47_1},
+ {2, arcs_47_0},
+ {1, arcs_47_1},
};
static arc arcs_48_0[1] = {
- {111, 1},
+ {111, 1},
};
static arc arcs_48_1[2] = {
- {33, 2},
- {25, 3},
+ {33, 2},
+ {25, 3},
};
static arc arcs_48_2[1] = {
- {25, 3},
+ {25, 3},
};
static arc arcs_48_3[1] = {
- {24, 4},
+ {24, 4},
};
static arc arcs_48_4[1] = {
- {0, 4},
+ {0, 4},
};
static state states_48[5] = {
- {1, arcs_48_0},
- {2, arcs_48_1},
- {1, arcs_48_2},
- {1, arcs_48_3},
- {1, arcs_48_4},
+ {1, arcs_48_0},
+ {2, arcs_48_1},
+ {1, arcs_48_2},
+ {1, arcs_48_3},
+ {1, arcs_48_4},
};
static arc arcs_49_0[1] = {
- {111, 1},
+ {111, 1},
};
static arc arcs_49_1[2] = {
- {33, 2},
- {25, 3},
+ {33, 2},
+ {25, 3},
};
static arc arcs_49_2[1] = {
- {25, 3},
+ {25, 3},
};
static arc arcs_49_3[1] = {
- {109, 4},
+ {109, 4},
};
static arc arcs_49_4[1] = {
- {0, 4},
+ {0, 4},
};
static state states_49[5] = {
- {1, arcs_49_0},
- {2, arcs_49_1},
- {1, arcs_49_2},
- {1, arcs_49_3},
- {1, arcs_49_4},
+ {1, arcs_49_0},
+ {2, arcs_49_1},
+ {1, arcs_49_2},
+ {1, arcs_49_3},
+ {1, arcs_49_4},
};
static arc arcs_50_0[1] = {
- {112, 1},
+ {112, 1},
};
static arc arcs_50_1[2] = {
- {113, 0},
- {0, 1},
+ {113, 0},
+ {0, 1},
};
static state states_50[2] = {
- {1, arcs_50_0},
- {2, arcs_50_1},
+ {1, arcs_50_0},
+ {2, arcs_50_1},
};
static arc arcs_51_0[1] = {
- {114, 1},
+ {114, 1},
};
static arc arcs_51_1[2] = {
- {115, 0},
- {0, 1},
+ {115, 0},
+ {0, 1},
};
static state states_51[2] = {
- {1, arcs_51_0},
- {2, arcs_51_1},
+ {1, arcs_51_0},
+ {2, arcs_51_1},
};
static arc arcs_52_0[2] = {
- {116, 1},
- {117, 2},
+ {116, 1},
+ {117, 2},
};
static arc arcs_52_1[1] = {
- {114, 2},
+ {114, 2},
};
static arc arcs_52_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_52[3] = {
- {2, arcs_52_0},
- {1, arcs_52_1},
- {1, arcs_52_2},
+ {2, arcs_52_0},
+ {1, arcs_52_1},
+ {1, arcs_52_2},
};
static arc arcs_53_0[1] = {
- {103, 1},
+ {103, 1},
};
static arc arcs_53_1[2] = {
- {118, 0},
- {0, 1},
+ {118, 0},
+ {0, 1},
};
static state states_53[2] = {
- {1, arcs_53_0},
- {2, arcs_53_1},
+ {1, arcs_53_0},
+ {2, arcs_53_1},
};
static arc arcs_54_0[10] = {
- {119, 1},
- {120, 1},
- {121, 1},
- {122, 1},
- {123, 1},
- {124, 1},
- {125, 1},
- {97, 1},
- {116, 2},
- {126, 3},
+ {119, 1},
+ {120, 1},
+ {121, 1},
+ {122, 1},
+ {123, 1},
+ {124, 1},
+ {125, 1},
+ {97, 1},
+ {116, 2},
+ {126, 3},
};
static arc arcs_54_1[1] = {
- {0, 1},
+ {0, 1},
};
static arc arcs_54_2[1] = {
- {97, 1},
+ {97, 1},
};
static arc arcs_54_3[2] = {
- {116, 1},
- {0, 3},
+ {116, 1},
+ {0, 3},
};
static state states_54[4] = {
- {10, arcs_54_0},
- {1, arcs_54_1},
- {1, arcs_54_2},
- {2, arcs_54_3},
+ {10, arcs_54_0},
+ {1, arcs_54_1},
+ {1, arcs_54_2},
+ {2, arcs_54_3},
};
static arc arcs_55_0[1] = {
- {31, 1},
+ {31, 1},
};
static arc arcs_55_1[1] = {
- {103, 2},
+ {103, 2},
};
static arc arcs_55_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_55[3] = {
- {1, arcs_55_0},
- {1, arcs_55_1},
- {1, arcs_55_2},
+ {1, arcs_55_0},
+ {1, arcs_55_1},
+ {1, arcs_55_2},
};
static arc arcs_56_0[1] = {
- {127, 1},
+ {127, 1},
};
static arc arcs_56_1[2] = {
- {128, 0},
- {0, 1},
+ {128, 0},
+ {0, 1},
};
static state states_56[2] = {
- {1, arcs_56_0},
- {2, arcs_56_1},
+ {1, arcs_56_0},
+ {2, arcs_56_1},
};
static arc arcs_57_0[1] = {
- {129, 1},
+ {129, 1},
};
static arc arcs_57_1[2] = {
- {130, 0},
- {0, 1},
+ {130, 0},
+ {0, 1},
};
static state states_57[2] = {
- {1, arcs_57_0},
- {2, arcs_57_1},
+ {1, arcs_57_0},
+ {2, arcs_57_1},
};
static arc arcs_58_0[1] = {
- {131, 1},
+ {131, 1},
};
static arc arcs_58_1[2] = {
- {132, 0},
- {0, 1},
+ {132, 0},
+ {0, 1},
};
static state states_58[2] = {
- {1, arcs_58_0},
- {2, arcs_58_1},
+ {1, arcs_58_0},
+ {2, arcs_58_1},
};
static arc arcs_59_0[1] = {
- {133, 1},
+ {133, 1},
};
static arc arcs_59_1[3] = {
- {134, 0},
- {135, 0},
- {0, 1},
+ {134, 0},
+ {135, 0},
+ {0, 1},
};
static state states_59[2] = {
- {1, arcs_59_0},
- {3, arcs_59_1},
+ {1, arcs_59_0},
+ {3, arcs_59_1},
};
static arc arcs_60_0[1] = {
- {136, 1},
+ {136, 1},
};
static arc arcs_60_1[3] = {
- {137, 0},
- {138, 0},
- {0, 1},
+ {137, 0},
+ {138, 0},
+ {0, 1},
};
static state states_60[2] = {
- {1, arcs_60_0},
- {3, arcs_60_1},
+ {1, arcs_60_0},
+ {3, arcs_60_1},
};
static arc arcs_61_0[1] = {
- {139, 1},
+ {139, 1},
};
static arc arcs_61_1[5] = {
- {31, 0},
- {140, 0},
- {141, 0},
- {142, 0},
- {0, 1},
+ {31, 0},
+ {140, 0},
+ {141, 0},
+ {142, 0},
+ {0, 1},
};
static state states_61[2] = {
- {1, arcs_61_0},
- {5, arcs_61_1},
+ {1, arcs_61_0},
+ {5, arcs_61_1},
};
static arc arcs_62_0[4] = {
- {137, 1},
- {138, 1},
- {143, 1},
- {144, 2},
+ {137, 1},
+ {138, 1},
+ {143, 1},
+ {144, 2},
};
static arc arcs_62_1[1] = {
- {139, 2},
+ {139, 2},
};
static arc arcs_62_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_62[3] = {
- {4, arcs_62_0},
- {1, arcs_62_1},
- {1, arcs_62_2},
+ {4, arcs_62_0},
+ {1, arcs_62_1},
+ {1, arcs_62_2},
};
static arc arcs_63_0[1] = {
- {145, 1},
+ {145, 1},
};
static arc arcs_63_1[3] = {
- {146, 1},
- {32, 2},
- {0, 1},
+ {146, 1},
+ {32, 2},
+ {0, 1},
};
static arc arcs_63_2[1] = {
- {139, 3},
+ {139, 3},
};
static arc arcs_63_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_63[4] = {
- {1, arcs_63_0},
- {3, arcs_63_1},
- {1, arcs_63_2},
- {1, arcs_63_3},
+ {1, arcs_63_0},
+ {3, arcs_63_1},
+ {1, arcs_63_2},
+ {1, arcs_63_3},
};
static arc arcs_64_0[10] = {
- {13, 1},
- {148, 2},
- {150, 3},
- {21, 4},
- {153, 4},
- {154, 5},
- {79, 4},
- {155, 4},
- {156, 4},
- {157, 4},
+ {13, 1},
+ {148, 2},
+ {150, 3},
+ {21, 4},
+ {153, 4},
+ {154, 5},
+ {79, 4},
+ {155, 4},
+ {156, 4},
+ {157, 4},
};
static arc arcs_64_1[3] = {
- {47, 6},
- {147, 6},
- {15, 4},
+ {47, 6},
+ {147, 6},
+ {15, 4},
};
static arc arcs_64_2[2] = {
- {147, 7},
- {149, 4},
+ {147, 7},
+ {149, 4},
};
static arc arcs_64_3[2] = {
- {151, 8},
- {152, 4},
+ {151, 8},
+ {152, 4},
};
static arc arcs_64_4[1] = {
- {0, 4},
+ {0, 4},
};
static arc arcs_64_5[2] = {
- {154, 5},
- {0, 5},
+ {154, 5},
+ {0, 5},
};
static arc arcs_64_6[1] = {
- {15, 4},
+ {15, 4},
};
static arc arcs_64_7[1] = {
- {149, 4},
+ {149, 4},
};
static arc arcs_64_8[1] = {
- {152, 4},
+ {152, 4},
};
static state states_64[9] = {
- {10, arcs_64_0},
- {3, arcs_64_1},
- {2, arcs_64_2},
- {2, arcs_64_3},
- {1, arcs_64_4},
- {2, arcs_64_5},
- {1, arcs_64_6},
- {1, arcs_64_7},
- {1, arcs_64_8},
+ {10, arcs_64_0},
+ {3, arcs_64_1},
+ {2, arcs_64_2},
+ {2, arcs_64_3},
+ {1, arcs_64_4},
+ {2, arcs_64_5},
+ {1, arcs_64_6},
+ {1, arcs_64_7},
+ {1, arcs_64_8},
};
static arc arcs_65_0[2] = {
- {24, 1},
- {48, 1},
+ {24, 1},
+ {48, 1},
};
static arc arcs_65_1[3] = {
- {158, 2},
- {30, 3},
- {0, 1},
+ {158, 2},
+ {30, 3},
+ {0, 1},
};
static arc arcs_65_2[1] = {
- {0, 2},
+ {0, 2},
};
static arc arcs_65_3[3] = {
- {24, 4},
- {48, 4},
- {0, 3},
+ {24, 4},
+ {48, 4},
+ {0, 3},
};
static arc arcs_65_4[2] = {
- {30, 3},
- {0, 4},
+ {30, 3},
+ {0, 4},
};
static state states_65[5] = {
- {2, arcs_65_0},
- {3, arcs_65_1},
- {1, arcs_65_2},
- {3, arcs_65_3},
- {2, arcs_65_4},
+ {2, arcs_65_0},
+ {3, arcs_65_1},
+ {1, arcs_65_2},
+ {3, arcs_65_3},
+ {2, arcs_65_4},
};
static arc arcs_66_0[3] = {
- {13, 1},
- {148, 2},
- {78, 3},
+ {13, 1},
+ {148, 2},
+ {78, 3},
};
static arc arcs_66_1[2] = {
- {14, 4},
- {15, 5},
+ {14, 4},
+ {15, 5},
};
static arc arcs_66_2[1] = {
- {159, 6},
+ {159, 6},
};
static arc arcs_66_3[1] = {
- {21, 5},
+ {21, 5},
};
static arc arcs_66_4[1] = {
- {15, 5},
+ {15, 5},
};
static arc arcs_66_5[1] = {
- {0, 5},
+ {0, 5},
};
static arc arcs_66_6[1] = {
- {149, 5},
+ {149, 5},
};
static state states_66[7] = {
- {3, arcs_66_0},
- {2, arcs_66_1},
- {1, arcs_66_2},
- {1, arcs_66_3},
- {1, arcs_66_4},
- {1, arcs_66_5},
- {1, arcs_66_6},
+ {3, arcs_66_0},
+ {2, arcs_66_1},
+ {1, arcs_66_2},
+ {1, arcs_66_3},
+ {1, arcs_66_4},
+ {1, arcs_66_5},
+ {1, arcs_66_6},
};
static arc arcs_67_0[1] = {
- {160, 1},
+ {160, 1},
};
static arc arcs_67_1[2] = {
- {30, 2},
- {0, 1},
+ {30, 2},
+ {0, 1},
};
static arc arcs_67_2[2] = {
- {160, 1},
- {0, 2},
+ {160, 1},
+ {0, 2},
};
static state states_67[3] = {
- {1, arcs_67_0},
- {2, arcs_67_1},
- {2, arcs_67_2},
+ {1, arcs_67_0},
+ {2, arcs_67_1},
+ {2, arcs_67_2},
};
static arc arcs_68_0[2] = {
- {24, 1},
- {25, 2},
+ {24, 1},
+ {25, 2},
};
static arc arcs_68_1[2] = {
- {25, 2},
- {0, 1},
+ {25, 2},
+ {0, 1},
};
static arc arcs_68_2[3] = {
- {24, 3},
- {161, 4},
- {0, 2},
+ {24, 3},
+ {161, 4},
+ {0, 2},
};
static arc arcs_68_3[2] = {
- {161, 4},
- {0, 3},
+ {161, 4},
+ {0, 3},
};
static arc arcs_68_4[1] = {
- {0, 4},
+ {0, 4},
};
static state states_68[5] = {
- {2, arcs_68_0},
- {2, arcs_68_1},
- {3, arcs_68_2},
- {2, arcs_68_3},
- {1, arcs_68_4},
+ {2, arcs_68_0},
+ {2, arcs_68_1},
+ {3, arcs_68_2},
+ {2, arcs_68_3},
+ {1, arcs_68_4},
};
static arc arcs_69_0[1] = {
- {25, 1},
+ {25, 1},
};
static arc arcs_69_1[2] = {
- {24, 2},
- {0, 1},
+ {24, 2},
+ {0, 1},
};
static arc arcs_69_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_69[3] = {
- {1, arcs_69_0},
- {2, arcs_69_1},
- {1, arcs_69_2},
+ {1, arcs_69_0},
+ {2, arcs_69_1},
+ {1, arcs_69_2},
};
static arc arcs_70_0[2] = {
- {103, 1},
- {48, 1},
+ {103, 1},
+ {48, 1},
};
static arc arcs_70_1[2] = {
- {30, 2},
- {0, 1},
+ {30, 2},
+ {0, 1},
};
static arc arcs_70_2[3] = {
- {103, 1},
- {48, 1},
- {0, 2},
+ {103, 1},
+ {48, 1},
+ {0, 2},
};
static state states_70[3] = {
- {2, arcs_70_0},
- {2, arcs_70_1},
- {3, arcs_70_2},
+ {2, arcs_70_0},
+ {2, arcs_70_1},
+ {3, arcs_70_2},
};
static arc arcs_71_0[1] = {
- {24, 1},
+ {24, 1},
};
static arc arcs_71_1[2] = {
- {30, 2},
- {0, 1},
+ {30, 2},
+ {0, 1},
};
static arc arcs_71_2[2] = {
- {24, 1},
- {0, 2},
+ {24, 1},
+ {0, 2},
};
static state states_71[3] = {
- {1, arcs_71_0},
- {2, arcs_71_1},
- {2, arcs_71_2},
+ {1, arcs_71_0},
+ {2, arcs_71_1},
+ {2, arcs_71_2},
};
static arc arcs_72_0[1] = {
- {24, 1},
+ {24, 1},
};
static arc arcs_72_1[4] = {
- {25, 2},
- {158, 3},
- {30, 4},
- {0, 1},
+ {25, 2},
+ {158, 3},
+ {30, 4},
+ {0, 1},
};
static arc arcs_72_2[1] = {
- {24, 5},
+ {24, 5},
};
static arc arcs_72_3[1] = {
- {0, 3},
+ {0, 3},
};
static arc arcs_72_4[2] = {
- {24, 6},
- {0, 4},
+ {24, 6},
+ {0, 4},
};
static arc arcs_72_5[3] = {
- {158, 3},
- {30, 7},
- {0, 5},
+ {158, 3},
+ {30, 7},
+ {0, 5},
};
static arc arcs_72_6[2] = {
- {30, 4},
- {0, 6},
+ {30, 4},
+ {0, 6},
};
static arc arcs_72_7[2] = {
- {24, 8},
- {0, 7},
+ {24, 8},
+ {0, 7},
};
static arc arcs_72_8[1] = {
- {25, 9},
+ {25, 9},
};
static arc arcs_72_9[1] = {
- {24, 10},
+ {24, 10},
};
static arc arcs_72_10[2] = {
- {30, 7},
- {0, 10},
+ {30, 7},
+ {0, 10},
};
static state states_72[11] = {
- {1, arcs_72_0},
- {4, arcs_72_1},
- {1, arcs_72_2},
- {1, arcs_72_3},
- {2, arcs_72_4},
- {3, arcs_72_5},
- {2, arcs_72_6},
- {2, arcs_72_7},
- {1, arcs_72_8},
- {1, arcs_72_9},
- {2, arcs_72_10},
+ {1, arcs_72_0},
+ {4, arcs_72_1},
+ {1, arcs_72_2},
+ {1, arcs_72_3},
+ {2, arcs_72_4},
+ {3, arcs_72_5},
+ {2, arcs_72_6},
+ {2, arcs_72_7},
+ {1, arcs_72_8},
+ {1, arcs_72_9},
+ {2, arcs_72_10},
};
static arc arcs_73_0[1] = {
- {162, 1},
+ {162, 1},
};
static arc arcs_73_1[1] = {
- {21, 2},
+ {21, 2},
};
static arc arcs_73_2[2] = {
- {13, 3},
- {25, 4},
+ {13, 3},
+ {25, 4},
};
static arc arcs_73_3[2] = {
- {14, 5},
- {15, 6},
+ {14, 5},
+ {15, 6},
};
static arc arcs_73_4[1] = {
- {26, 7},
+ {26, 7},
};
static arc arcs_73_5[1] = {
- {15, 6},
+ {15, 6},
};
static arc arcs_73_6[1] = {
- {25, 4},
+ {25, 4},
};
static arc arcs_73_7[1] = {
- {0, 7},
+ {0, 7},
};
static state states_73[8] = {
- {1, arcs_73_0},
- {1, arcs_73_1},
- {2, arcs_73_2},
- {2, arcs_73_3},
- {1, arcs_73_4},
- {1, arcs_73_5},
- {1, arcs_73_6},
- {1, arcs_73_7},
+ {1, arcs_73_0},
+ {1, arcs_73_1},
+ {2, arcs_73_2},
+ {2, arcs_73_3},
+ {1, arcs_73_4},
+ {1, arcs_73_5},
+ {1, arcs_73_6},
+ {1, arcs_73_7},
};
static arc arcs_74_0[3] = {
- {163, 1},
- {31, 2},
- {32, 3},
+ {163, 1},
+ {31, 2},
+ {32, 3},
};
static arc arcs_74_1[2] = {
- {30, 4},
- {0, 1},
+ {30, 4},
+ {0, 1},
};
static arc arcs_74_2[1] = {
- {24, 5},
+ {24, 5},
};
static arc arcs_74_3[1] = {
- {24, 6},
+ {24, 6},
};
static arc arcs_74_4[4] = {
- {163, 1},
- {31, 2},
- {32, 3},
- {0, 4},
+ {163, 1},
+ {31, 2},
+ {32, 3},
+ {0, 4},
};
static arc arcs_74_5[2] = {
- {30, 7},
- {0, 5},
+ {30, 7},
+ {0, 5},
};
static arc arcs_74_6[1] = {
- {0, 6},
+ {0, 6},
};
static arc arcs_74_7[2] = {
- {163, 5},
- {32, 3},
+ {163, 5},
+ {32, 3},
};
static state states_74[8] = {
- {3, arcs_74_0},
- {2, arcs_74_1},
- {1, arcs_74_2},
- {1, arcs_74_3},
- {4, arcs_74_4},
- {2, arcs_74_5},
- {1, arcs_74_6},
- {2, arcs_74_7},
+ {3, arcs_74_0},
+ {2, arcs_74_1},
+ {1, arcs_74_2},
+ {1, arcs_74_3},
+ {4, arcs_74_4},
+ {2, arcs_74_5},
+ {1, arcs_74_6},
+ {2, arcs_74_7},
};
static arc arcs_75_0[1] = {
- {24, 1},
+ {24, 1},
};
static arc arcs_75_1[3] = {
- {158, 2},
- {29, 3},
- {0, 1},
+ {158, 2},
+ {29, 3},
+ {0, 1},
};
static arc arcs_75_2[1] = {
- {0, 2},
+ {0, 2},
};
static arc arcs_75_3[1] = {
- {24, 2},
+ {24, 2},
};
static state states_75[4] = {
- {1, arcs_75_0},
- {3, arcs_75_1},
- {1, arcs_75_2},
- {1, arcs_75_3},
+ {1, arcs_75_0},
+ {3, arcs_75_1},
+ {1, arcs_75_2},
+ {1, arcs_75_3},
};
static arc arcs_76_0[2] = {
- {158, 1},
- {165, 1},
+ {158, 1},
+ {165, 1},
};
static arc arcs_76_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_76[2] = {
- {2, arcs_76_0},
- {1, arcs_76_1},
+ {2, arcs_76_0},
+ {1, arcs_76_1},
};
static arc arcs_77_0[1] = {
- {96, 1},
+ {96, 1},
};
static arc arcs_77_1[1] = {
- {62, 2},
+ {62, 2},
};
static arc arcs_77_2[1] = {
- {97, 3},
+ {97, 3},
};
static arc arcs_77_3[1] = {
- {107, 4},
+ {107, 4},
};
static arc arcs_77_4[2] = {
- {164, 5},
- {0, 4},
+ {164, 5},
+ {0, 4},
};
static arc arcs_77_5[1] = {
- {0, 5},
+ {0, 5},
};
static state states_77[6] = {
- {1, arcs_77_0},
- {1, arcs_77_1},
- {1, arcs_77_2},
- {1, arcs_77_3},
- {2, arcs_77_4},
- {1, arcs_77_5},
+ {1, arcs_77_0},
+ {1, arcs_77_1},
+ {1, arcs_77_2},
+ {1, arcs_77_3},
+ {2, arcs_77_4},
+ {1, arcs_77_5},
};
static arc arcs_78_0[1] = {
- {92, 1},
+ {92, 1},
};
static arc arcs_78_1[1] = {
- {109, 2},
+ {109, 2},
};
static arc arcs_78_2[2] = {
- {164, 3},
- {0, 2},
+ {164, 3},
+ {0, 2},
};
static arc arcs_78_3[1] = {
- {0, 3},
+ {0, 3},
};
static state states_78[4] = {
- {1, arcs_78_0},
- {1, arcs_78_1},
- {2, arcs_78_2},
- {1, arcs_78_3},
+ {1, arcs_78_0},
+ {1, arcs_78_1},
+ {2, arcs_78_2},
+ {1, arcs_78_3},
};
static arc arcs_79_0[1] = {
- {21, 1},
+ {21, 1},
};
static arc arcs_79_1[1] = {
- {0, 1},
+ {0, 1},
};
static state states_79[2] = {
- {1, arcs_79_0},
- {1, arcs_79_1},
+ {1, arcs_79_0},
+ {1, arcs_79_1},
};
static arc arcs_80_0[1] = {
- {167, 1},
+ {167, 1},
};
static arc arcs_80_1[2] = {
- {9, 2},
- {0, 1},
+ {9, 2},
+ {0, 1},
};
static arc arcs_80_2[1] = {
- {0, 2},
+ {0, 2},
};
static state states_80[3] = {
- {1, arcs_80_0},
- {2, arcs_80_1},
- {1, arcs_80_2},
+ {1, arcs_80_0},
+ {2, arcs_80_1},
+ {1, arcs_80_2},
};
static dfa dfas[81] = {
- {256, "single_input", 0, 3, states_0,
- "\004\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
- {257, "file_input", 0, 2, states_1,
- "\204\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
- {258, "eval_input", 0, 3, states_2,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {259, "decorator", 0, 7, states_3,
- "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {260, "decorators", 0, 2, states_4,
- "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {261, "decorated", 0, 3, states_5,
- "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {262, "funcdef", 0, 8, states_6,
- "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {263, "parameters", 0, 4, states_7,
- "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {264, "typedargslist", 0, 12, states_8,
- "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {265, "tfpdef", 0, 4, states_9,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {266, "varargslist", 0, 12, states_10,
- "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {267, "vfpdef", 0, 2, states_11,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {268, "stmt", 0, 2, states_12,
- "\000\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
- {269, "simple_stmt", 0, 4, states_13,
- "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
- {270, "small_stmt", 0, 2, states_14,
- "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
- {271, "expr_stmt", 0, 6, states_15,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {272, "testlist_star_expr", 0, 3, states_16,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {273, "augassign", 0, 2, states_17,
- "\000\000\000\000\000\000\376\037\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {274, "del_stmt", 0, 3, states_18,
- "\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {275, "pass_stmt", 0, 2, states_19,
- "\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {276, "flow_stmt", 0, 2, states_20,
- "\000\000\000\000\000\000\000\000\340\001\000\000\000\000\000\000\000\000\000\000\200"},
- {277, "break_stmt", 0, 2, states_21,
- "\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000"},
- {278, "continue_stmt", 0, 2, states_22,
- "\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000"},
- {279, "return_stmt", 0, 3, states_23,
- "\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000"},
- {280, "yield_stmt", 0, 2, states_24,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
- {281, "raise_stmt", 0, 5, states_25,
- "\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000"},
- {282, "import_stmt", 0, 2, states_26,
- "\000\000\000\000\000\000\000\000\000\022\000\000\000\000\000\000\000\000\000\000\000"},
- {283, "import_name", 0, 3, states_27,
- "\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000"},
- {284, "import_from", 0, 8, states_28,
- "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000"},
- {285, "import_as_name", 0, 4, states_29,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {286, "dotted_as_name", 0, 4, states_30,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {287, "import_as_names", 0, 3, states_31,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {288, "dotted_as_names", 0, 2, states_32,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {289, "dotted_name", 0, 2, states_33,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {290, "global_stmt", 0, 3, states_34,
- "\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},
- {291, "nonlocal_stmt", 0, 3, states_35,
- "\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000"},
- {292, "assert_stmt", 0, 5, states_36,
- "\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"},
- {293, "compound_stmt", 0, 2, states_37,
- "\000\010\020\000\000\000\000\000\000\000\000\220\045\000\000\000\000\000\000\000\004"},
- {294, "if_stmt", 0, 8, states_38,
- "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
- {295, "while_stmt", 0, 8, states_39,
- "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000"},
- {296, "for_stmt", 0, 10, states_40,
- "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
- {297, "try_stmt", 0, 13, states_41,
- "\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000"},
- {298, "with_stmt", 0, 5, states_42,
- "\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},
- {299, "with_item", 0, 4, states_43,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {300, "except_clause", 0, 5, states_44,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000"},
- {301, "suite", 0, 5, states_45,
- "\004\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
- {302, "test", 0, 6, states_46,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {303, "test_nocond", 0, 2, states_47,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {304, "lambdef", 0, 5, states_48,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
- {305, "lambdef_nocond", 0, 5, states_49,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
- {306, "or_test", 0, 2, states_50,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
- {307, "and_test", 0, 2, states_51,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
- {308, "not_test", 0, 3, states_52,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
- {309, "comparison", 0, 2, states_53,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {310, "comp_op", 0, 4, states_54,
- "\000\000\000\000\000\000\000\000\000\000\000\000\002\000\220\177\000\000\000\000\000"},
- {311, "star_expr", 0, 3, states_55,
- "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {312, "expr", 0, 2, states_56,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {313, "xor_expr", 0, 2, states_57,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {314, "and_expr", 0, 2, states_58,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {315, "shift_expr", 0, 2, states_59,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {316, "arith_expr", 0, 2, states_60,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {317, "term", 0, 2, states_61,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {318, "factor", 0, 3, states_62,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {319, "power", 0, 4, states_63,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
- {320, "atom", 0, 9, states_64,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
- {321, "testlist_comp", 0, 5, states_65,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {322, "trailer", 0, 7, states_66,
- "\000\040\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\020\000\000"},
- {323, "subscriptlist", 0, 3, states_67,
- "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {324, "subscript", 0, 5, states_68,
- "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {325, "sliceop", 0, 3, states_69,
- "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {326, "exprlist", 0, 3, states_70,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {327, "testlist", 0, 3, states_71,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {328, "dictorsetmaker", 0, 11, states_72,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {329, "classdef", 0, 8, states_73,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004"},
- {330, "arglist", 0, 8, states_74,
- "\000\040\040\200\001\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {331, "argument", 0, 4, states_75,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {332, "comp_iter", 0, 2, states_76,
- "\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000"},
- {333, "comp_for", 0, 6, states_77,
- "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
- {334, "comp_if", 0, 4, states_78,
- "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
- {335, "encoding_decl", 0, 2, states_79,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {336, "yield_expr", 0, 3, states_80,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
+ {256, "single_input", 0, 3, states_0,
+ "\004\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
+ {257, "file_input", 0, 2, states_1,
+ "\204\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
+ {258, "eval_input", 0, 3, states_2,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {259, "decorator", 0, 7, states_3,
+ "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {260, "decorators", 0, 2, states_4,
+ "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {261, "decorated", 0, 3, states_5,
+ "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {262, "funcdef", 0, 8, states_6,
+ "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {263, "parameters", 0, 4, states_7,
+ "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {264, "typedargslist", 0, 12, states_8,
+ "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {265, "tfpdef", 0, 4, states_9,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {266, "varargslist", 0, 12, states_10,
+ "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {267, "vfpdef", 0, 2, states_11,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {268, "stmt", 0, 2, states_12,
+ "\000\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
+ {269, "simple_stmt", 0, 4, states_13,
+ "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
+ {270, "small_stmt", 0, 2, states_14,
+ "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
+ {271, "expr_stmt", 0, 6, states_15,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {272, "testlist_star_expr", 0, 3, states_16,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {273, "augassign", 0, 2, states_17,
+ "\000\000\000\000\000\000\376\037\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {274, "del_stmt", 0, 3, states_18,
+ "\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {275, "pass_stmt", 0, 2, states_19,
+ "\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {276, "flow_stmt", 0, 2, states_20,
+ "\000\000\000\000\000\000\000\000\340\001\000\000\000\000\000\000\000\000\000\000\200"},
+ {277, "break_stmt", 0, 2, states_21,
+ "\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {278, "continue_stmt", 0, 2, states_22,
+ "\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {279, "return_stmt", 0, 3, states_23,
+ "\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {280, "yield_stmt", 0, 2, states_24,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
+ {281, "raise_stmt", 0, 5, states_25,
+ "\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000"},
+ {282, "import_stmt", 0, 2, states_26,
+ "\000\000\000\000\000\000\000\000\000\022\000\000\000\000\000\000\000\000\000\000\000"},
+ {283, "import_name", 0, 3, states_27,
+ "\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000"},
+ {284, "import_from", 0, 8, states_28,
+ "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000"},
+ {285, "import_as_name", 0, 4, states_29,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {286, "dotted_as_name", 0, 4, states_30,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {287, "import_as_names", 0, 3, states_31,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {288, "dotted_as_names", 0, 2, states_32,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {289, "dotted_name", 0, 2, states_33,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {290, "global_stmt", 0, 3, states_34,
+ "\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},
+ {291, "nonlocal_stmt", 0, 3, states_35,
+ "\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000"},
+ {292, "assert_stmt", 0, 5, states_36,
+ "\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"},
+ {293, "compound_stmt", 0, 2, states_37,
+ "\000\010\020\000\000\000\000\000\000\000\000\220\045\000\000\000\000\000\000\000\004"},
+ {294, "if_stmt", 0, 8, states_38,
+ "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
+ {295, "while_stmt", 0, 8, states_39,
+ "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000"},
+ {296, "for_stmt", 0, 10, states_40,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
+ {297, "try_stmt", 0, 13, states_41,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000"},
+ {298, "with_stmt", 0, 5, states_42,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},
+ {299, "with_item", 0, 4, states_43,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {300, "except_clause", 0, 5, states_44,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000"},
+ {301, "suite", 0, 5, states_45,
+ "\004\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
+ {302, "test", 0, 6, states_46,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {303, "test_nocond", 0, 2, states_47,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {304, "lambdef", 0, 5, states_48,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
+ {305, "lambdef_nocond", 0, 5, states_49,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
+ {306, "or_test", 0, 2, states_50,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
+ {307, "and_test", 0, 2, states_51,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
+ {308, "not_test", 0, 3, states_52,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
+ {309, "comparison", 0, 2, states_53,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {310, "comp_op", 0, 4, states_54,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\002\000\220\177\000\000\000\000\000"},
+ {311, "star_expr", 0, 3, states_55,
+ "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {312, "expr", 0, 2, states_56,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {313, "xor_expr", 0, 2, states_57,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {314, "and_expr", 0, 2, states_58,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {315, "shift_expr", 0, 2, states_59,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {316, "arith_expr", 0, 2, states_60,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {317, "term", 0, 2, states_61,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {318, "factor", 0, 3, states_62,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {319, "power", 0, 4, states_63,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
+ {320, "atom", 0, 9, states_64,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
+ {321, "testlist_comp", 0, 5, states_65,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {322, "trailer", 0, 7, states_66,
+ "\000\040\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\020\000\000"},
+ {323, "subscriptlist", 0, 3, states_67,
+ "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {324, "subscript", 0, 5, states_68,
+ "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {325, "sliceop", 0, 3, states_69,
+ "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {326, "exprlist", 0, 3, states_70,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
+ {327, "testlist", 0, 3, states_71,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {328, "dictorsetmaker", 0, 11, states_72,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {329, "classdef", 0, 8, states_73,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004"},
+ {330, "arglist", 0, 8, states_74,
+ "\000\040\040\200\001\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {331, "argument", 0, 4, states_75,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
+ {332, "comp_iter", 0, 2, states_76,
+ "\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000"},
+ {333, "comp_for", 0, 6, states_77,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
+ {334, "comp_if", 0, 4, states_78,
+ "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
+ {335, "encoding_decl", 0, 2, states_79,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {336, "yield_expr", 0, 3, states_80,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
};
static label labels[168] = {
- {0, "EMPTY"},
- {256, 0},
- {4, 0},
- {269, 0},
- {293, 0},
- {257, 0},
- {268, 0},
- {0, 0},
- {258, 0},
- {327, 0},
- {259, 0},
- {50, 0},
- {289, 0},
- {7, 0},
- {330, 0},
- {8, 0},
- {260, 0},
- {261, 0},
- {329, 0},
- {262, 0},
- {1, "def"},
- {1, 0},
- {263, 0},
- {51, 0},
- {302, 0},
- {11, 0},
- {301, 0},
- {264, 0},
- {265, 0},
- {22, 0},
- {12, 0},
- {16, 0},
- {36, 0},
- {266, 0},
- {267, 0},
- {270, 0},
- {13, 0},
- {271, 0},
- {274, 0},
- {275, 0},
- {276, 0},
- {282, 0},
- {290, 0},
- {291, 0},
- {292, 0},
- {272, 0},
- {273, 0},
- {336, 0},
- {311, 0},
- {37, 0},
- {38, 0},
- {39, 0},
- {40, 0},
- {41, 0},
- {42, 0},
- {43, 0},
- {44, 0},
- {45, 0},
- {46, 0},
- {47, 0},
- {49, 0},
- {1, "del"},
- {326, 0},
- {1, "pass"},
- {277, 0},
- {278, 0},
- {279, 0},
- {281, 0},
- {280, 0},
- {1, "break"},
- {1, "continue"},
- {1, "return"},
- {1, "raise"},
- {1, "from"},
- {283, 0},
- {284, 0},
- {1, "import"},
- {288, 0},
- {23, 0},
- {52, 0},
- {287, 0},
- {285, 0},
- {1, "as"},
- {286, 0},
- {1, "global"},
- {1, "nonlocal"},
- {1, "assert"},
- {294, 0},
- {295, 0},
- {296, 0},
- {297, 0},
- {298, 0},
- {1, "if"},
- {1, "elif"},
- {1, "else"},
- {1, "while"},
- {1, "for"},
- {1, "in"},
- {1, "try"},
- {300, 0},
- {1, "finally"},
- {1, "with"},
- {299, 0},
- {312, 0},
- {1, "except"},
- {5, 0},
- {6, 0},
- {306, 0},
- {304, 0},
- {303, 0},
- {305, 0},
- {1, "lambda"},
- {307, 0},
- {1, "or"},
- {308, 0},
- {1, "and"},
- {1, "not"},
- {309, 0},
- {310, 0},
- {20, 0},
- {21, 0},
- {28, 0},
- {31, 0},
- {30, 0},
- {29, 0},
- {29, 0},
- {1, "is"},
- {313, 0},
- {18, 0},
- {314, 0},
- {33, 0},
- {315, 0},
- {19, 0},
- {316, 0},
- {34, 0},
- {35, 0},
- {317, 0},
- {14, 0},
- {15, 0},
- {318, 0},
- {17, 0},
- {24, 0},
- {48, 0},
- {32, 0},
- {319, 0},
- {320, 0},
- {322, 0},
- {321, 0},
- {9, 0},
- {10, 0},
- {26, 0},
- {328, 0},
- {27, 0},
- {2, 0},
- {3, 0},
- {1, "None"},
- {1, "True"},
- {1, "False"},
- {333, 0},
- {323, 0},
- {324, 0},
- {325, 0},
- {1, "class"},
- {331, 0},
- {332, 0},
- {334, 0},
- {335, 0},
- {1, "yield"},
+ {0, "EMPTY"},
+ {256, 0},
+ {4, 0},
+ {269, 0},
+ {293, 0},
+ {257, 0},
+ {268, 0},
+ {0, 0},
+ {258, 0},
+ {327, 0},
+ {259, 0},
+ {50, 0},
+ {289, 0},
+ {7, 0},
+ {330, 0},
+ {8, 0},
+ {260, 0},
+ {261, 0},
+ {329, 0},
+ {262, 0},
+ {1, "def"},
+ {1, 0},
+ {263, 0},
+ {51, 0},
+ {302, 0},
+ {11, 0},
+ {301, 0},
+ {264, 0},
+ {265, 0},
+ {22, 0},
+ {12, 0},
+ {16, 0},
+ {36, 0},
+ {266, 0},
+ {267, 0},
+ {270, 0},
+ {13, 0},
+ {271, 0},
+ {274, 0},
+ {275, 0},
+ {276, 0},
+ {282, 0},
+ {290, 0},
+ {291, 0},
+ {292, 0},
+ {272, 0},
+ {273, 0},
+ {336, 0},
+ {311, 0},
+ {37, 0},
+ {38, 0},
+ {39, 0},
+ {40, 0},
+ {41, 0},
+ {42, 0},
+ {43, 0},
+ {44, 0},
+ {45, 0},
+ {46, 0},
+ {47, 0},
+ {49, 0},
+ {1, "del"},
+ {326, 0},
+ {1, "pass"},
+ {277, 0},
+ {278, 0},
+ {279, 0},
+ {281, 0},
+ {280, 0},
+ {1, "break"},
+ {1, "continue"},
+ {1, "return"},
+ {1, "raise"},
+ {1, "from"},
+ {283, 0},
+ {284, 0},
+ {1, "import"},
+ {288, 0},
+ {23, 0},
+ {52, 0},
+ {287, 0},
+ {285, 0},
+ {1, "as"},
+ {286, 0},
+ {1, "global"},
+ {1, "nonlocal"},
+ {1, "assert"},
+ {294, 0},
+ {295, 0},
+ {296, 0},
+ {297, 0},
+ {298, 0},
+ {1, "if"},
+ {1, "elif"},
+ {1, "else"},
+ {1, "while"},
+ {1, "for"},
+ {1, "in"},
+ {1, "try"},
+ {300, 0},
+ {1, "finally"},
+ {1, "with"},
+ {299, 0},
+ {312, 0},
+ {1, "except"},
+ {5, 0},
+ {6, 0},
+ {306, 0},
+ {304, 0},
+ {303, 0},
+ {305, 0},
+ {1, "lambda"},
+ {307, 0},
+ {1, "or"},
+ {308, 0},
+ {1, "and"},
+ {1, "not"},
+ {309, 0},
+ {310, 0},
+ {20, 0},
+ {21, 0},
+ {28, 0},
+ {31, 0},
+ {30, 0},
+ {29, 0},
+ {29, 0},
+ {1, "is"},
+ {313, 0},
+ {18, 0},
+ {314, 0},
+ {33, 0},
+ {315, 0},
+ {19, 0},
+ {316, 0},
+ {34, 0},
+ {35, 0},
+ {317, 0},
+ {14, 0},
+ {15, 0},
+ {318, 0},
+ {17, 0},
+ {24, 0},
+ {48, 0},
+ {32, 0},
+ {319, 0},
+ {320, 0},
+ {322, 0},
+ {321, 0},
+ {9, 0},
+ {10, 0},
+ {26, 0},
+ {328, 0},
+ {27, 0},
+ {2, 0},
+ {3, 0},
+ {1, "None"},
+ {1, "True"},
+ {1, "False"},
+ {333, 0},
+ {323, 0},
+ {324, 0},
+ {325, 0},
+ {1, "class"},
+ {331, 0},
+ {332, 0},
+ {334, 0},
+ {335, 0},
+ {1, "yield"},
};
grammar _PyParser_Grammar = {
- 81,
- dfas,
- {168, labels},
- 256
+ 81,
+ dfas,
+ {168, labels},
+ 256
};
Modified: python/branches/py3k-jit/Python/import.c
==============================================================================
--- python/branches/py3k-jit/Python/import.c (original)
+++ python/branches/py3k-jit/Python/import.c Tue May 18 19:58:30 2010
@@ -1633,8 +1633,7 @@
if (!v)
return NULL;
if (PyUnicode_Check(v)) {
- v = PyUnicode_AsEncodedString(v,
- Py_FileSystemDefaultEncoding, NULL);
+ v = PyUnicode_EncodeFSDefault(v);
if (v == NULL)
return NULL;
}
@@ -2752,14 +2751,7 @@
char *subname;
PyObject *submod;
char *p;
- if (!Py_FileSystemDefaultEncoding) {
- item8 = PyUnicode_EncodeASCII(PyUnicode_AsUnicode(item),
- PyUnicode_GetSize(item),
- NULL);
- } else {
- item8 = PyUnicode_AsEncodedString(item,
- Py_FileSystemDefaultEncoding, NULL);
- }
+ item8 = PyUnicode_EncodeFSDefault(item);
if (!item8) {
PyErr_SetString(PyExc_ValueError, "Cannot encode path item");
return 0;
Modified: python/branches/py3k-jit/Python/pythonrun.c
==============================================================================
--- python/branches/py3k-jit/Python/pythonrun.c (original)
+++ python/branches/py3k-jit/Python/pythonrun.c Tue May 18 19:58:30 2010
@@ -57,6 +57,7 @@
/* Forward */
static void initmain(void);
+static void initfsencoding(void);
static void initsite(void);
static int initstdio(void);
static void flush_io(void);
@@ -159,7 +160,6 @@
error:
Py_XDECREF(codec);
- PyErr_Clear();
return NULL;
}
#endif
@@ -171,9 +171,6 @@
PyThreadState *tstate;
PyObject *bimod, *sysmod, *pstderr;
char *p;
-#if defined(HAVE_LANGINFO_H) && defined(CODESET)
- char *codeset;
-#endif
extern void _Py_ReadyTypes(void);
if (initialized)
@@ -264,21 +261,7 @@
_PyImportHooks_Init();
-#if defined(HAVE_LANGINFO_H) && defined(CODESET)
- /* On Unix, set the file system encoding according to the
- user's preference, if the CODESET names a well-known
- Python codec, and Py_FileSystemDefaultEncoding isn't
- initialized by other means. Also set the encoding of
- stdin and stdout if these are terminals. */
-
- codeset = get_codeset();
- if (codeset) {
- if (!Py_FileSystemDefaultEncoding)
- Py_FileSystemDefaultEncoding = codeset;
- else
- free(codeset);
- }
-#endif
+ initfsencoding();
if (install_sigs)
initsigs(); /* Signal handling stuff, including initintr() */
@@ -334,7 +317,7 @@
Py_DECREF(tmp);
}
- if (ferr != NULL || ferr != Py_None) {
+ if (ferr != NULL && ferr != Py_None) {
tmp = PyObject_CallMethod(ferr, "flush", "");
if (tmp == NULL)
PyErr_Clear();
@@ -497,7 +480,7 @@
_PyUnicode_Fini();
/* reset file system default encoding */
- if (!Py_HasFileSystemDefaultEncoding) {
+ if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
free((char*)Py_FileSystemDefaultEncoding);
Py_FileSystemDefaultEncoding = NULL;
}
@@ -708,6 +691,45 @@
}
}
+static void
+initfsencoding(void)
+{
+ PyObject *codec;
+#if defined(HAVE_LANGINFO_H) && defined(CODESET)
+ char *codeset;
+
+ /* On Unix, set the file system encoding according to the
+ user's preference, if the CODESET names a well-known
+ Python codec, and Py_FileSystemDefaultEncoding isn't
+ initialized by other means. Also set the encoding of
+ stdin and stdout if these are terminals. */
+ codeset = get_codeset();
+ if (codeset != NULL) {
+ Py_FileSystemDefaultEncoding = codeset;
+ Py_HasFileSystemDefaultEncoding = 0;
+ return;
+ }
+
+ PyErr_Clear();
+ fprintf(stderr,
+ "Unable to get the locale encoding: "
+ "fallback to utf-8\n");
+ Py_FileSystemDefaultEncoding = "utf-8";
+ Py_HasFileSystemDefaultEncoding = 1;
+#endif
+
+ /* the encoding is mbcs, utf-8 or ascii */
+ codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding);
+ if (!codec) {
+ /* Such error can only occurs in critical situations: no more
+ * memory, import a module of the standard library failed,
+ * etc. */
+ Py_FatalError("Py_Initialize: unable to load the file system codec");
+ } else {
+ Py_DECREF(codec);
+ }
+}
+
/* Import the site module (not into __main__ though) */
static void
@@ -1346,7 +1368,11 @@
if (PyLong_Check(value))
exitcode = (int)PyLong_AsLong(value);
else {
+ PyObject *sys_stderr = PySys_GetObject("stderr");
+ if (sys_stderr != NULL)
+ PyObject_CallMethod(sys_stderr, "flush", NULL);
PyObject_Print(value, stderr, Py_PRINT_RAW);
+ fflush(stderr);
PySys_WriteStderr("\n");
exitcode = 1;
}
More information about the Python-checkins
mailing list