Cython 3.2.0__cp39-abi3-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Cython/Build/BuildExecutable.py +169 -0
- Cython/Build/Cache.py +199 -0
- Cython/Build/Cythonize.py +350 -0
- Cython/Build/Dependencies.py +1314 -0
- Cython/Build/Distutils.py +1 -0
- Cython/Build/Inline.py +463 -0
- Cython/Build/IpythonMagic.py +560 -0
- Cython/Build/SharedModule.py +94 -0
- Cython/Build/Tests/TestCyCache.py +194 -0
- Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
- Cython/Build/Tests/TestDependencies.py +133 -0
- Cython/Build/Tests/TestInline.py +177 -0
- Cython/Build/Tests/TestIpythonMagic.py +287 -0
- Cython/Build/Tests/TestRecythonize.py +212 -0
- Cython/Build/Tests/TestStripLiterals.py +155 -0
- Cython/Build/Tests/__init__.py +1 -0
- Cython/Build/__init__.py +11 -0
- Cython/CodeWriter.py +815 -0
- Cython/Compiler/AnalysedTreeTransforms.py +97 -0
- Cython/Compiler/Annotate.py +328 -0
- Cython/Compiler/AutoDocTransforms.py +320 -0
- Cython/Compiler/Buffer.py +680 -0
- Cython/Compiler/Builtin.py +984 -0
- Cython/Compiler/CmdLine.py +263 -0
- Cython/Compiler/Code.pxd +149 -0
- Cython/Compiler/Code.py +3746 -0
- Cython/Compiler/Code.pyd +0 -0
- Cython/Compiler/CodeGeneration.py +33 -0
- Cython/Compiler/CythonScope.py +191 -0
- Cython/Compiler/Dataclass.py +864 -0
- Cython/Compiler/DebugFlags.py +24 -0
- Cython/Compiler/Errors.py +297 -0
- Cython/Compiler/ExprNodes.py +15562 -0
- Cython/Compiler/FlowControl.pxd +97 -0
- Cython/Compiler/FlowControl.py +1451 -0
- Cython/Compiler/FlowControl.pyd +0 -0
- Cython/Compiler/FusedNode.py +971 -0
- Cython/Compiler/FusedNode.pyd +0 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +421 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/LineTable.pyd +0 -0
- Cython/Compiler/Main.py +857 -0
- Cython/Compiler/MatchCaseNodes.py +259 -0
- Cython/Compiler/MemoryView.py +905 -0
- Cython/Compiler/ModuleNode.py +4235 -0
- Cython/Compiler/Naming.py +363 -0
- Cython/Compiler/Nodes.py +10831 -0
- Cython/Compiler/Optimize.py +5288 -0
- Cython/Compiler/Options.py +843 -0
- Cython/Compiler/ParseTreeTransforms.pxd +78 -0
- Cython/Compiler/ParseTreeTransforms.py +4638 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +4775 -0
- Cython/Compiler/Parsing.pyd +0 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +5870 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +48 -0
- Cython/Compiler/Scanning.py +701 -0
- Cython/Compiler/Scanning.pyd +0 -0
- Cython/Compiler/StringEncoding.py +298 -0
- Cython/Compiler/Symtab.py +3073 -0
- Cython/Compiler/Tests/TestBuffer.py +105 -0
- Cython/Compiler/Tests/TestBuiltin.py +72 -0
- Cython/Compiler/Tests/TestCmdLine.py +586 -0
- Cython/Compiler/Tests/TestCode.py +144 -0
- Cython/Compiler/Tests/TestFlowControl.py +65 -0
- Cython/Compiler/Tests/TestGrammar.py +202 -0
- Cython/Compiler/Tests/TestMemView.py +71 -0
- Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
- Cython/Compiler/Tests/TestScanning.py +134 -0
- Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
- Cython/Compiler/Tests/TestStringEncoding.py +21 -0
- Cython/Compiler/Tests/TestTreeFragment.py +63 -0
- Cython/Compiler/Tests/TestTreePath.py +103 -0
- Cython/Compiler/Tests/TestTypes.py +75 -0
- Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
- Cython/Compiler/Tests/TestVisitor.py +61 -0
- Cython/Compiler/Tests/Utils.py +36 -0
- Cython/Compiler/Tests/__init__.py +1 -0
- Cython/Compiler/TreeFragment.py +278 -0
- Cython/Compiler/TreePath.py +303 -0
- Cython/Compiler/TypeInference.py +591 -0
- Cython/Compiler/TypeSlots.py +1174 -0
- Cython/Compiler/UFuncs.py +311 -0
- Cython/Compiler/UtilNodes.py +389 -0
- Cython/Compiler/UtilityCode.py +344 -0
- Cython/Compiler/Version.py +8 -0
- Cython/Compiler/Visitor.pxd +53 -0
- Cython/Compiler/Visitor.py +861 -0
- Cython/Compiler/Visitor.pyd +0 -0
- Cython/Compiler/__init__.py +1 -0
- Cython/Coverage.py +448 -0
- Cython/Debugger/Cygdb.py +177 -0
- Cython/Debugger/DebugWriter.py +82 -0
- Cython/Debugger/Tests/TestLibCython.py +275 -0
- Cython/Debugger/Tests/__init__.py +1 -0
- Cython/Debugger/Tests/cfuncs.c +8 -0
- Cython/Debugger/Tests/codefile +49 -0
- Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
- Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
- Cython/Debugger/__init__.py +1 -0
- Cython/Debugger/libcython.py +1548 -0
- Cython/Debugger/libpython.py +2821 -0
- Cython/Debugging.py +20 -0
- Cython/Distutils/__init__.py +2 -0
- Cython/Distutils/build_ext.py +139 -0
- Cython/Distutils/extension.py +96 -0
- Cython/Distutils/old_build_ext.py +351 -0
- Cython/Includes/cpython/__init__.pxd +173 -0
- Cython/Includes/cpython/array.pxd +178 -0
- Cython/Includes/cpython/bool.pxd +37 -0
- Cython/Includes/cpython/buffer.pxd +112 -0
- Cython/Includes/cpython/bytearray.pxd +33 -0
- Cython/Includes/cpython/bytes.pxd +200 -0
- Cython/Includes/cpython/cellobject.pxd +35 -0
- Cython/Includes/cpython/ceval.pxd +8 -0
- Cython/Includes/cpython/codecs.pxd +121 -0
- Cython/Includes/cpython/complex.pxd +60 -0
- Cython/Includes/cpython/contextvars.pxd +145 -0
- Cython/Includes/cpython/conversion.pxd +36 -0
- Cython/Includes/cpython/datetime.pxd +395 -0
- Cython/Includes/cpython/descr.pxd +26 -0
- Cython/Includes/cpython/dict.pxd +187 -0
- Cython/Includes/cpython/exc.pxd +263 -0
- Cython/Includes/cpython/fileobject.pxd +57 -0
- Cython/Includes/cpython/float.pxd +47 -0
- Cython/Includes/cpython/function.pxd +65 -0
- Cython/Includes/cpython/genobject.pxd +25 -0
- Cython/Includes/cpython/getargs.pxd +12 -0
- Cython/Includes/cpython/instance.pxd +25 -0
- Cython/Includes/cpython/iterator.pxd +36 -0
- Cython/Includes/cpython/iterobject.pxd +24 -0
- Cython/Includes/cpython/list.pxd +92 -0
- Cython/Includes/cpython/long.pxd +149 -0
- Cython/Includes/cpython/longintrepr.pxd +14 -0
- Cython/Includes/cpython/mapping.pxd +63 -0
- Cython/Includes/cpython/marshal.pxd +66 -0
- Cython/Includes/cpython/mem.pxd +120 -0
- Cython/Includes/cpython/memoryview.pxd +50 -0
- Cython/Includes/cpython/method.pxd +49 -0
- Cython/Includes/cpython/module.pxd +208 -0
- Cython/Includes/cpython/number.pxd +258 -0
- Cython/Includes/cpython/object.pxd +433 -0
- Cython/Includes/cpython/pycapsule.pxd +143 -0
- Cython/Includes/cpython/pylifecycle.pxd +68 -0
- Cython/Includes/cpython/pyport.pxd +8 -0
- Cython/Includes/cpython/pystate.pxd +95 -0
- Cython/Includes/cpython/pythread.pxd +53 -0
- Cython/Includes/cpython/ref.pxd +141 -0
- Cython/Includes/cpython/sequence.pxd +134 -0
- Cython/Includes/cpython/set.pxd +119 -0
- Cython/Includes/cpython/slice.pxd +70 -0
- Cython/Includes/cpython/time.pxd +129 -0
- Cython/Includes/cpython/tuple.pxd +72 -0
- Cython/Includes/cpython/type.pxd +53 -0
- Cython/Includes/cpython/unicode.pxd +639 -0
- Cython/Includes/cpython/version.pxd +32 -0
- Cython/Includes/cpython/weakref.pxd +78 -0
- Cython/Includes/libc/__init__.pxd +1 -0
- Cython/Includes/libc/complex.pxd +35 -0
- Cython/Includes/libc/errno.pxd +127 -0
- Cython/Includes/libc/float.pxd +43 -0
- Cython/Includes/libc/limits.pxd +28 -0
- Cython/Includes/libc/locale.pxd +46 -0
- Cython/Includes/libc/math.pxd +209 -0
- Cython/Includes/libc/setjmp.pxd +10 -0
- Cython/Includes/libc/signal.pxd +64 -0
- Cython/Includes/libc/stddef.pxd +9 -0
- Cython/Includes/libc/stdint.pxd +105 -0
- Cython/Includes/libc/stdio.pxd +80 -0
- Cython/Includes/libc/stdlib.pxd +72 -0
- Cython/Includes/libc/string.pxd +50 -0
- Cython/Includes/libc/threads.pxd +234 -0
- Cython/Includes/libc/time.pxd +52 -0
- Cython/Includes/libcpp/__init__.pxd +4 -0
- Cython/Includes/libcpp/algorithm.pxd +320 -0
- Cython/Includes/libcpp/any.pxd +16 -0
- Cython/Includes/libcpp/atomic.pxd +59 -0
- Cython/Includes/libcpp/barrier.pxd +22 -0
- Cython/Includes/libcpp/bit.pxd +29 -0
- Cython/Includes/libcpp/cast.pxd +12 -0
- Cython/Includes/libcpp/cmath.pxd +518 -0
- Cython/Includes/libcpp/complex.pxd +106 -0
- Cython/Includes/libcpp/condition_variable.pxd +322 -0
- Cython/Includes/libcpp/deque.pxd +165 -0
- Cython/Includes/libcpp/exception.pxd +86 -0
- Cython/Includes/libcpp/execution.pxd +15 -0
- Cython/Includes/libcpp/forward_list.pxd +63 -0
- Cython/Includes/libcpp/functional.pxd +26 -0
- Cython/Includes/libcpp/future.pxd +103 -0
- Cython/Includes/libcpp/iterator.pxd +34 -0
- Cython/Includes/libcpp/latch.pxd +17 -0
- Cython/Includes/libcpp/limits.pxd +61 -0
- Cython/Includes/libcpp/list.pxd +117 -0
- Cython/Includes/libcpp/map.pxd +252 -0
- Cython/Includes/libcpp/memory.pxd +115 -0
- Cython/Includes/libcpp/mutex.pxd +387 -0
- Cython/Includes/libcpp/numbers.pxd +15 -0
- Cython/Includes/libcpp/numeric.pxd +131 -0
- Cython/Includes/libcpp/optional.pxd +34 -0
- Cython/Includes/libcpp/pair.pxd +1 -0
- Cython/Includes/libcpp/queue.pxd +25 -0
- Cython/Includes/libcpp/random.pxd +166 -0
- Cython/Includes/libcpp/semaphore.pxd +43 -0
- Cython/Includes/libcpp/set.pxd +228 -0
- Cython/Includes/libcpp/shared_mutex.pxd +96 -0
- Cython/Includes/libcpp/span.pxd +87 -0
- Cython/Includes/libcpp/stack.pxd +11 -0
- Cython/Includes/libcpp/stop_token.pxd +117 -0
- Cython/Includes/libcpp/string.pxd +355 -0
- Cython/Includes/libcpp/string_view.pxd +183 -0
- Cython/Includes/libcpp/typeindex.pxd +15 -0
- Cython/Includes/libcpp/typeinfo.pxd +10 -0
- Cython/Includes/libcpp/unordered_map.pxd +193 -0
- Cython/Includes/libcpp/unordered_set.pxd +152 -0
- Cython/Includes/libcpp/utility.pxd +30 -0
- Cython/Includes/libcpp/vector.pxd +186 -0
- Cython/Includes/numpy/math.pxd +150 -0
- Cython/Includes/openmp.pxd +50 -0
- Cython/Includes/posix/__init__.pxd +1 -0
- Cython/Includes/posix/dlfcn.pxd +14 -0
- Cython/Includes/posix/fcntl.pxd +86 -0
- Cython/Includes/posix/ioctl.pxd +4 -0
- Cython/Includes/posix/mman.pxd +101 -0
- Cython/Includes/posix/resource.pxd +57 -0
- Cython/Includes/posix/select.pxd +21 -0
- Cython/Includes/posix/signal.pxd +73 -0
- Cython/Includes/posix/stat.pxd +98 -0
- Cython/Includes/posix/stdio.pxd +37 -0
- Cython/Includes/posix/stdlib.pxd +29 -0
- Cython/Includes/posix/strings.pxd +9 -0
- Cython/Includes/posix/time.pxd +71 -0
- Cython/Includes/posix/types.pxd +30 -0
- Cython/Includes/posix/uio.pxd +26 -0
- Cython/Includes/posix/unistd.pxd +271 -0
- Cython/Includes/posix/wait.pxd +38 -0
- Cython/Plex/Actions.pxd +24 -0
- Cython/Plex/Actions.py +119 -0
- Cython/Plex/Actions.pyd +0 -0
- Cython/Plex/DFA.pxd +14 -0
- Cython/Plex/DFA.py +164 -0
- Cython/Plex/DFA.pyd +0 -0
- Cython/Plex/Errors.py +48 -0
- Cython/Plex/Lexicons.py +178 -0
- Cython/Plex/Machines.pxd +36 -0
- Cython/Plex/Machines.py +238 -0
- Cython/Plex/Machines.pyd +0 -0
- Cython/Plex/Regexps.py +535 -0
- Cython/Plex/Scanners.pxd +45 -0
- Cython/Plex/Scanners.py +328 -0
- Cython/Plex/Scanners.pyd +0 -0
- Cython/Plex/Transitions.pxd +14 -0
- Cython/Plex/Transitions.py +239 -0
- Cython/Plex/Transitions.pyd +0 -0
- Cython/Plex/__init__.py +34 -0
- Cython/Runtime/__init__.py +1 -0
- Cython/Runtime/refnanny.pyd +0 -0
- Cython/Runtime/refnanny.pyx +237 -0
- Cython/Shadow.py +690 -0
- Cython/Shadow.pyi +521 -0
- Cython/StringIOTree.py +170 -0
- Cython/StringIOTree.pyd +0 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -0
- Cython/Tempita/_tempita.py +1091 -0
- Cython/Tempita/_tempita.pyd +0 -0
- Cython/TestUtils.py +422 -0
- Cython/Tests/TestCodeWriter.py +128 -0
- Cython/Tests/TestCythonUtils.py +202 -0
- Cython/Tests/TestJediTyper.py +223 -0
- Cython/Tests/TestShadow.py +114 -0
- Cython/Tests/TestStringIOTree.py +67 -0
- Cython/Tests/TestTestUtils.py +90 -0
- Cython/Tests/__init__.py +1 -0
- Cython/Tests/xmlrunner.py +390 -0
- Cython/Utility/AsyncGen.c +1031 -0
- Cython/Utility/Buffer.c +865 -0
- Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
- Cython/Utility/Builtins.c +810 -0
- Cython/Utility/CConvert.pyx +134 -0
- Cython/Utility/CMath.c +104 -0
- Cython/Utility/CommonStructures.c +226 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2300 -0
- Cython/Utility/CpdefEnums.pyx +103 -0
- Cython/Utility/CppConvert.pyx +282 -0
- Cython/Utility/CppSupport.cpp +151 -0
- Cython/Utility/CythonFunction.c +1832 -0
- Cython/Utility/Dataclasses.c +101 -0
- Cython/Utility/Embed.c +121 -0
- Cython/Utility/Exceptions.c +1016 -0
- Cython/Utility/ExtensionTypes.c +996 -0
- Cython/Utility/FunctionArguments.c +1043 -0
- Cython/Utility/FusedFunction.pyx +44 -0
- Cython/Utility/ImportExport.c +907 -0
- Cython/Utility/MemoryView.pxd +188 -0
- Cython/Utility/MemoryView.pyx +1482 -0
- Cython/Utility/MemoryView_C.c +927 -0
- Cython/Utility/ModuleSetupCode.c +3203 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3273 -0
- Cython/Utility/Optimize.c +1603 -0
- Cython/Utility/Overflow.c +384 -0
- Cython/Utility/Printing.c +86 -0
- Cython/Utility/Profile.c +732 -0
- Cython/Utility/StringTools.c +1379 -0
- Cython/Utility/Synchronization.c +399 -0
- Cython/Utility/TString.c +356 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1385 -0
- Cython/Utility/UFuncs.pyx +50 -0
- Cython/Utility/UFuncs_C.c +89 -0
- Cython/Utility/__init__.py +28 -0
- Cython/Utility/arrayarray.h +167 -0
- Cython/Utils.py +687 -0
- Cython/Utils.pyd +0 -0
- Cython/__init__.py +10 -0
- Cython/__init__.pyi +7 -0
- Cython/py.typed +0 -0
- cython-3.2.0.dist-info/METADATA +85 -0
- cython-3.2.0.dist-info/RECORD +333 -0
- cython-3.2.0.dist-info/WHEEL +5 -0
- cython-3.2.0.dist-info/entry_points.txt +4 -0
- cython-3.2.0.dist-info/top_level.txt +3 -0
- cython.py +29 -0
- pyximport/__init__.py +4 -0
- pyximport/pyxbuild.py +160 -0
- pyximport/pyximport.py +482 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
from .object cimport PyObject
|
|
2
|
+
|
|
3
|
+
cdef extern from "Python.h":
|
|
4
|
+
|
|
5
|
+
#####################################################################
|
|
6
|
+
# 3. Exception Handling
|
|
7
|
+
#####################################################################
|
|
8
|
+
|
|
9
|
+
# The functions described in this chapter will let you handle and
|
|
10
|
+
# raise Python exceptions. It is important to understand some of
|
|
11
|
+
# the basics of Python exception handling. It works somewhat like
|
|
12
|
+
# the Unix errno variable: there is a global indicator (per
|
|
13
|
+
# thread) of the last error that occurred. Most functions don't
|
|
14
|
+
# clear this on success, but will set it to indicate the cause of
|
|
15
|
+
# the error on failure. Most functions also return an error
|
|
16
|
+
# indicator, usually NULL if they are supposed to return a
|
|
17
|
+
# pointer, or -1 if they return an integer (exception: the
|
|
18
|
+
# PyArg_*() functions return 1 for success and 0 for failure).
|
|
19
|
+
|
|
20
|
+
# When a function must fail because some function it called
|
|
21
|
+
# failed, it generally doesn't set the error indicator; the
|
|
22
|
+
# function it called already set it. It is responsible for either
|
|
23
|
+
# handling the error and clearing the exception or returning after
|
|
24
|
+
# cleaning up any resources it holds (such as object references or
|
|
25
|
+
# memory allocations); it should not continue normally if it is
|
|
26
|
+
# not prepared to handle the error. If returning due to an error,
|
|
27
|
+
# it is important to indicate to the caller that an error has been
|
|
28
|
+
# set. If the error is not handled or carefully propagated,
|
|
29
|
+
# additional calls into the Python/C API may not behave as
|
|
30
|
+
# intended and may fail in mysterious ways.
|
|
31
|
+
|
|
32
|
+
# The error indicator consists of three Python objects
|
|
33
|
+
# corresponding to the Python variables sys.exc_type,
|
|
34
|
+
# sys.exc_value and sys.exc_traceback. API functions exist to
|
|
35
|
+
# interact with the error indicator in various ways. There is a
|
|
36
|
+
# separate error indicator for each thread.
|
|
37
|
+
|
|
38
|
+
void PyErr_Print()
|
|
39
|
+
# Print a standard traceback to sys.stderr and clear the error
|
|
40
|
+
# indicator. Call this function only when the error indicator is
|
|
41
|
+
# set. (Otherwise it will cause a fatal error!)
|
|
42
|
+
|
|
43
|
+
PyObject* PyErr_Occurred()
|
|
44
|
+
# Return value: Borrowed reference.
|
|
45
|
+
# Test whether the error indicator is set. If set, return the
|
|
46
|
+
# exception type (the first argument to the last call to one of
|
|
47
|
+
# the PyErr_Set*() functions or to PyErr_Restore()). If not set,
|
|
48
|
+
# return NULL. You do not own a reference to the return value, so
|
|
49
|
+
# you do not need to Py_DECREF() it. Note: Do not compare the
|
|
50
|
+
# return value to a specific exception; use
|
|
51
|
+
# PyErr_ExceptionMatches() instead, shown below. (The comparison
|
|
52
|
+
# could easily fail since the exception may be an instance instead
|
|
53
|
+
# of a class, in the case of a class exception, or it may be a
|
|
54
|
+
# subclass of the expected exception.)
|
|
55
|
+
|
|
56
|
+
bint PyErr_ExceptionMatches(object exc)
|
|
57
|
+
# Equivalent to "PyErr_GivenExceptionMatches(PyErr_Occurred(),
|
|
58
|
+
# exc)". This should only be called when an exception is actually
|
|
59
|
+
# set; a memory access violation will occur if no exception has
|
|
60
|
+
# been raised.
|
|
61
|
+
|
|
62
|
+
bint PyErr_GivenExceptionMatches(object given, object exc)
|
|
63
|
+
# Return true if the given exception matches the exception in
|
|
64
|
+
# exc. If exc is a class object, this also returns true when given
|
|
65
|
+
# is an instance of a subclass. If exc is a tuple, all exceptions
|
|
66
|
+
# in the tuple (and recursively in subtuples) are searched for a
|
|
67
|
+
# match. If given is NULL, a memory access violation will occur.
|
|
68
|
+
|
|
69
|
+
void PyErr_NormalizeException(PyObject** exc, PyObject** val, PyObject** tb)
|
|
70
|
+
# Under certain circumstances, the values returned by
|
|
71
|
+
# PyErr_Fetch() below can be ``unnormalized'', meaning that *exc
|
|
72
|
+
# is a class object but *val is not an instance of the same
|
|
73
|
+
# class. This function can be used to instantiate the class in
|
|
74
|
+
# that case. If the values are already normalized, nothing
|
|
75
|
+
# happens. The delayed normalization is implemented to improve
|
|
76
|
+
# performance.
|
|
77
|
+
|
|
78
|
+
void PyErr_Clear()
|
|
79
|
+
# Clear the error indicator. If the error indicator is not set, there is no effect.
|
|
80
|
+
|
|
81
|
+
void PyErr_Fetch(PyObject** ptype, PyObject** pvalue, PyObject** ptraceback)
|
|
82
|
+
# Retrieve the error indicator into three variables whose
|
|
83
|
+
# addresses are passed. If the error indicator is not set, set all
|
|
84
|
+
# three variables to NULL. If it is set, it will be cleared and
|
|
85
|
+
# you own a reference to each object retrieved. The value and
|
|
86
|
+
# traceback object may be NULL even when the type object is
|
|
87
|
+
# not. Note: This function is normally only used by code that
|
|
88
|
+
# needs to handle exceptions or by code that needs to save and
|
|
89
|
+
# restore the error indicator temporarily.
|
|
90
|
+
|
|
91
|
+
PyObject* PyErr_GetHandledException()
|
|
92
|
+
void PyErr_SetHandledException(PyObject* exc)
|
|
93
|
+
PyObject* PyErr_GetRaisedException()
|
|
94
|
+
void PyErr_SetRaisedException(PyObject* exc)
|
|
95
|
+
|
|
96
|
+
void PyErr_Restore(PyObject* type, PyObject* value, PyObject* traceback)
|
|
97
|
+
# Set the error indicator from the three objects. If the error
|
|
98
|
+
# indicator is already set, it is cleared first. If the objects
|
|
99
|
+
# are NULL, the error indicator is cleared. Do not pass a NULL
|
|
100
|
+
# type and non-NULL value or traceback. The exception type should
|
|
101
|
+
# be a class. Do not pass an invalid exception type or
|
|
102
|
+
# value. (Violating these rules will cause subtle problems later.)
|
|
103
|
+
# This call takes away a reference to each object: you must own a
|
|
104
|
+
# reference to each object before the call and after the call you
|
|
105
|
+
# no longer own these references. (If you don't understand this,
|
|
106
|
+
# don't use this function. I warned you.) Note: This function is
|
|
107
|
+
# normally only used by code that needs to save and restore the
|
|
108
|
+
# error indicator temporarily; use PyErr_Fetch() to save the
|
|
109
|
+
# current exception state.
|
|
110
|
+
|
|
111
|
+
void PyErr_SetString(object type, char *message)
|
|
112
|
+
# This is the most common way to set the error indicator. The
|
|
113
|
+
# first argument specifies the exception type; it is normally one
|
|
114
|
+
# of the standard exceptions, e.g. PyExc_RuntimeError. You need
|
|
115
|
+
# not increment its reference count. The second argument is an
|
|
116
|
+
# error message; it is converted to a string object.
|
|
117
|
+
|
|
118
|
+
void PyErr_SetObject(object type, object value)
|
|
119
|
+
# This function is similar to PyErr_SetString() but lets you
|
|
120
|
+
# specify an arbitrary Python object for the ``value'' of the
|
|
121
|
+
# exception.
|
|
122
|
+
|
|
123
|
+
PyObject* PyErr_Format(object exception, char *format, ...) except NULL
|
|
124
|
+
# Return value: Always NULL.
|
|
125
|
+
# This function sets the error indicator and returns
|
|
126
|
+
# NULL. exception should be a Python exception (class, not an
|
|
127
|
+
# instance). format should be a string, containing format codes,
|
|
128
|
+
# similar to printf(). The width.precision before a format code is
|
|
129
|
+
# parsed, but the width part is ignored.
|
|
130
|
+
|
|
131
|
+
void PyErr_SetNone(object type)
|
|
132
|
+
# This is a shorthand for "PyErr_SetObject(type, Py_None)".
|
|
133
|
+
|
|
134
|
+
int PyErr_BadArgument() except 0
|
|
135
|
+
|
|
136
|
+
# This is a shorthand for "PyErr_SetString(PyExc_TypeError,
|
|
137
|
+
# message)", where message indicates that a built-in operation was
|
|
138
|
+
# invoked with an illegal argument. It is mostly for internal use.
|
|
139
|
+
|
|
140
|
+
PyObject* PyErr_NoMemory() except NULL
|
|
141
|
+
# Return value: Always NULL.
|
|
142
|
+
# This is a shorthand for "PyErr_SetNone(PyExc_MemoryError)"; it
|
|
143
|
+
# returns NULL so an object allocation function can write "return
|
|
144
|
+
# PyErr_NoMemory();" when it runs out of memory.
|
|
145
|
+
|
|
146
|
+
PyObject* PyErr_SetFromErrno(object type) except NULL
|
|
147
|
+
# Return value: Always NULL.
|
|
148
|
+
# This is a convenience function to raise an exception when a C
|
|
149
|
+
# library function has returned an error and set the C variable
|
|
150
|
+
# errno. It constructs a tuple object whose first item is the
|
|
151
|
+
# integer errno value and whose second item is the corresponding
|
|
152
|
+
# error message (gotten from strerror()), and then calls
|
|
153
|
+
# "PyErr_SetObject(type, object)". On Unix, when the errno value
|
|
154
|
+
# is EINTR, indicating an interrupted system call, this calls
|
|
155
|
+
# PyErr_CheckSignals(), and if that set the error indicator,
|
|
156
|
+
# leaves it set to that. The function always returns NULL, so a
|
|
157
|
+
# wrapper function around a system call can write "return
|
|
158
|
+
# PyErr_SetFromErrno(type);" when the system call returns an
|
|
159
|
+
# error.
|
|
160
|
+
|
|
161
|
+
PyObject* PyErr_SetFromErrnoWithFilenameObject(object type, object filenameObject) except NULL
|
|
162
|
+
# Similar to PyErr_SetFromErrno(), with the additional behavior
|
|
163
|
+
# that if filenameObject is not NULL, it is passed to the
|
|
164
|
+
# constructor of type as a third parameter.
|
|
165
|
+
# In the case of OSError exception, this is used to define
|
|
166
|
+
# the filename attribute of the exception instance.
|
|
167
|
+
|
|
168
|
+
PyObject* PyErr_SetFromErrnoWithFilename(object type, char *filename) except NULL
|
|
169
|
+
# Return value: Always NULL. Similar to PyErr_SetFromErrno(),
|
|
170
|
+
# with the additional behavior that if filename is not NULL, it is
|
|
171
|
+
# passed to the constructor of type as a third parameter. In the
|
|
172
|
+
# case of exceptions such as IOError and OSError, this is used to
|
|
173
|
+
# define the filename attribute of the exception instance.
|
|
174
|
+
|
|
175
|
+
PyObject* PyErr_SetFromWindowsErr(int ierr) except NULL
|
|
176
|
+
# Return value: Always NULL. This is a convenience function to
|
|
177
|
+
# raise WindowsError. If called with ierr of 0, the error code
|
|
178
|
+
# returned by a call to GetLastError() is used instead. It calls
|
|
179
|
+
# the Win32 function FormatMessage() to retrieve the Windows
|
|
180
|
+
# description of error code given by ierr or GetLastError(), then
|
|
181
|
+
# it constructs a tuple object whose first item is the ierr value
|
|
182
|
+
# and whose second item is the corresponding error message (gotten
|
|
183
|
+
# from FormatMessage()), and then calls
|
|
184
|
+
# "PyErr_SetObject(PyExc_WindowsError, object)". This function
|
|
185
|
+
# always returns NULL. Availability: Windows.
|
|
186
|
+
|
|
187
|
+
PyObject* PyErr_SetExcFromWindowsErr(object type, int ierr) except NULL
|
|
188
|
+
# Return value: Always NULL. Similar to
|
|
189
|
+
# PyErr_SetFromWindowsErr(), with an additional parameter
|
|
190
|
+
# specifying the exception type to be raised. Availability:
|
|
191
|
+
# Windows. New in version 2.3.
|
|
192
|
+
|
|
193
|
+
PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, char *filename) except NULL
|
|
194
|
+
# Return value: Always NULL. Similar to
|
|
195
|
+
# PyErr_SetFromWindowsErr(), with the additional behavior that if
|
|
196
|
+
# filename is not NULL, it is passed to the constructor of
|
|
197
|
+
# WindowsError as a third parameter. Availability: Windows.
|
|
198
|
+
|
|
199
|
+
PyObject* PyErr_SetExcFromWindowsErrWithFilename(object type, int ierr, char *filename) except NULL
|
|
200
|
+
# Return value: Always NULL.
|
|
201
|
+
# Similar to PyErr_SetFromWindowsErrWithFilename(), with an
|
|
202
|
+
# additional parameter specifying the exception type to be
|
|
203
|
+
# raised. Availability: Windows.
|
|
204
|
+
|
|
205
|
+
void PyErr_BadInternalCall()
|
|
206
|
+
# This is a shorthand for "PyErr_SetString(PyExc_TypeError,
|
|
207
|
+
# message)", where message indicates that an internal operation
|
|
208
|
+
# (e.g. a Python/C API function) was invoked with an illegal
|
|
209
|
+
# argument. It is mostly for internal use.
|
|
210
|
+
|
|
211
|
+
int PyErr_WarnEx(object category, char *message, int stacklevel) except -1
|
|
212
|
+
# Issue a warning message. The category argument is a warning
|
|
213
|
+
# category (see below) or NULL; the message argument is a message
|
|
214
|
+
# string. stacklevel is a positive number giving a number of stack
|
|
215
|
+
# frames; the warning will be issued from the currently executing
|
|
216
|
+
# line of code in that stack frame. A stacklevel of 1 is the
|
|
217
|
+
# function calling PyErr_WarnEx(), 2 is the function above that,
|
|
218
|
+
# and so forth.
|
|
219
|
+
|
|
220
|
+
int PyErr_WarnExplicit(object category, char *message, char *filename, int lineno, char *module, object registry) except -1
|
|
221
|
+
# Issue a warning message with explicit control over all warning
|
|
222
|
+
# attributes. This is a straightforward wrapper around the Python
|
|
223
|
+
# function warnings.warn_explicit(), see there for more
|
|
224
|
+
# information. The module and registry arguments may be set to
|
|
225
|
+
# NULL to get the default effect described there.
|
|
226
|
+
|
|
227
|
+
int PyErr_CheckSignals() except -1
|
|
228
|
+
# This function interacts with Python's signal handling. It checks
|
|
229
|
+
# whether a signal has been sent to the processes and if so,
|
|
230
|
+
# invokes the corresponding signal handler. If the signal module
|
|
231
|
+
# is supported, this can invoke a signal handler written in
|
|
232
|
+
# Python. In all cases, the default effect for SIGINT is to raise
|
|
233
|
+
# the KeyboardInterrupt exception. If an exception is raised the
|
|
234
|
+
# error indicator is set and the function returns 1; otherwise the
|
|
235
|
+
# function returns 0. The error indicator may or may not be
|
|
236
|
+
# cleared if it was previously set.
|
|
237
|
+
|
|
238
|
+
void PyErr_SetInterrupt() nogil
|
|
239
|
+
# This function simulates the effect of a SIGINT signal arriving
|
|
240
|
+
# -- the next time PyErr_CheckSignals() is called,
|
|
241
|
+
# KeyboardInterrupt will be raised. It may be called without
|
|
242
|
+
# holding the interpreter lock.
|
|
243
|
+
|
|
244
|
+
int PyErr_SetInterruptEx(int signum)
|
|
245
|
+
|
|
246
|
+
object PyErr_NewException(char *name, object base, object dict)
|
|
247
|
+
# Return value: New reference.
|
|
248
|
+
# This utility function creates and returns a new exception
|
|
249
|
+
# object. The name argument must be the name of the new exception,
|
|
250
|
+
# a C string of the form module.class. The base and dict arguments
|
|
251
|
+
# are normally NULL. This creates a class object derived from
|
|
252
|
+
# Exception (accessible in C as PyExc_Exception).
|
|
253
|
+
|
|
254
|
+
void PyErr_WriteUnraisable(object obj)
|
|
255
|
+
# This utility function prints a warning message to sys.stderr
|
|
256
|
+
# when an exception has been set but it is impossible for the
|
|
257
|
+
# interpreter to actually raise the exception. It is used, for
|
|
258
|
+
# example, when an exception occurs in an __del__() method.
|
|
259
|
+
#
|
|
260
|
+
# The function is called with a single argument obj that
|
|
261
|
+
# identifies the context in which the unraisable exception
|
|
262
|
+
# occurred. The repr of obj will be printed in the warning
|
|
263
|
+
# message.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""
|
|
2
|
+
From https://docs.python.org/3.9/c-api/file.html
|
|
3
|
+
|
|
4
|
+
These APIs are a minimal emulation of the Python 2 C API for built-in file objects,
|
|
5
|
+
which used to rely on the buffered I/O (FILE*) support from the C standard library.
|
|
6
|
+
In Python 3, files and streams use the new io module, which defines several layers
|
|
7
|
+
over the low-level unbuffered I/O of the operating system. The functions described
|
|
8
|
+
below are convenience C wrappers over these new APIs, and meant mostly for internal
|
|
9
|
+
error reporting in the interpreter;
|
|
10
|
+
|
|
11
|
+
third-party code is advised to access the io APIs instead.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
cdef extern from "Python.h":
|
|
15
|
+
|
|
16
|
+
###########################################################################
|
|
17
|
+
# File Objects
|
|
18
|
+
###########################################################################
|
|
19
|
+
|
|
20
|
+
object PyFile_FromFd(int fd, const char *name, const char *mode, int buffering,
|
|
21
|
+
const char *encoding, const char *errors, const char *newline, int closefd)
|
|
22
|
+
# Return value: New reference.
|
|
23
|
+
# Create a Python file object from the file descriptor of an already
|
|
24
|
+
# opened file fd. The arguments name, encoding, errors and newline can be
|
|
25
|
+
# NULL to use the defaults; buffering can be -1 to use the default. name
|
|
26
|
+
# is ignored and kept for backward compatibility. Return NULL on failure.
|
|
27
|
+
# For a more comprehensive description of the arguments, please refer to
|
|
28
|
+
# the io.open() function documentation.
|
|
29
|
+
|
|
30
|
+
# Warning: Since Python streams have their own buffering layer, mixing
|
|
31
|
+
# them with OS-level file descriptors can produce various issues (such as
|
|
32
|
+
# unexpected ordering of data).
|
|
33
|
+
|
|
34
|
+
# Changed in version 3.2: Ignore name attribute.
|
|
35
|
+
|
|
36
|
+
object PyFile_GetLine(object p, int n)
|
|
37
|
+
# Return value: New reference.
|
|
38
|
+
# Equivalent to p.readline([n]), this function reads one line from the
|
|
39
|
+
# object p. p may be a file object or any object with a readline()
|
|
40
|
+
# method. If n is 0, exactly one line is read, regardless of the length of
|
|
41
|
+
# the line. If n is greater than 0, no more than n bytes will be read from
|
|
42
|
+
# the file; a partial line can be returned. In both cases, an empty string
|
|
43
|
+
# is returned if the end of the file is reached immediately. If n is less
|
|
44
|
+
# than 0, however, one line is read regardless of length, but EOFError is
|
|
45
|
+
# raised if the end of the file is reached immediately.
|
|
46
|
+
|
|
47
|
+
int PyFile_WriteObject(object obj, object p, int flags) except? -1
|
|
48
|
+
# Write object obj to file object p. The only supported flag for flags
|
|
49
|
+
# is Py_PRINT_RAW; if given, the str() of the object is written instead of
|
|
50
|
+
# the repr(). Return 0 on success or -1 on failure; the appropriate
|
|
51
|
+
# exception will be set.
|
|
52
|
+
|
|
53
|
+
int PyFile_WriteString(const char *s, object p) except? -1
|
|
54
|
+
# Write string s to file object p. Return 0 on success or -1 on failure;
|
|
55
|
+
# the appropriate exception will be set.
|
|
56
|
+
|
|
57
|
+
enum: Py_PRINT_RAW
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
cdef extern from *:
|
|
2
|
+
"""
|
|
3
|
+
#if PY_MAJOR_VERSION >= 3
|
|
4
|
+
#define __Pyx_PyFloat_FromString(obj) PyFloat_FromString(obj)
|
|
5
|
+
#else
|
|
6
|
+
#define __Pyx_PyFloat_FromString(obj) PyFloat_FromString(obj, NULL)
|
|
7
|
+
#endif
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
cdef extern from "Python.h":
|
|
11
|
+
############################################################################
|
|
12
|
+
# 7.2.3
|
|
13
|
+
############################################################################
|
|
14
|
+
# PyFloatObject
|
|
15
|
+
#
|
|
16
|
+
# This subtype of PyObject represents a Python floating point object.
|
|
17
|
+
|
|
18
|
+
# PyTypeObject PyFloat_Type
|
|
19
|
+
#
|
|
20
|
+
# This instance of PyTypeObject represents the Python floating
|
|
21
|
+
# point type. This is the same object as float and
|
|
22
|
+
# types.FloatType.
|
|
23
|
+
|
|
24
|
+
bint PyFloat_Check(object p)
|
|
25
|
+
# Return true if its argument is a PyFloatObject or a subtype of
|
|
26
|
+
# PyFloatObject.
|
|
27
|
+
|
|
28
|
+
bint PyFloat_CheckExact(object p)
|
|
29
|
+
# Return true if its argument is a PyFloatObject, but not a
|
|
30
|
+
# subtype of PyFloatObject.
|
|
31
|
+
|
|
32
|
+
object PyFloat_FromString "__Pyx_PyFloat_FromString" (object str)
|
|
33
|
+
# Return value: New reference.
|
|
34
|
+
# Create a PyFloatObject object based on the string value in str,
|
|
35
|
+
# or NULL on failure. The pend argument is ignored. It remains
|
|
36
|
+
# only for backward compatibility.
|
|
37
|
+
|
|
38
|
+
object PyFloat_FromDouble(double v)
|
|
39
|
+
# Return value: New reference.
|
|
40
|
+
# Create a PyFloatObject object from v, or NULL on failure.
|
|
41
|
+
|
|
42
|
+
double PyFloat_AsDouble(object pyfloat) except? -1
|
|
43
|
+
# Return a C double representation of the contents of pyfloat.
|
|
44
|
+
|
|
45
|
+
double PyFloat_AS_DOUBLE(object pyfloat)
|
|
46
|
+
# Return a C double representation of the contents of pyfloat, but
|
|
47
|
+
# without error checking.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from .object cimport PyObject
|
|
2
|
+
|
|
3
|
+
cdef extern from "Python.h":
|
|
4
|
+
|
|
5
|
+
############################################################################
|
|
6
|
+
# 7.5.3 Function Objects
|
|
7
|
+
############################################################################
|
|
8
|
+
# There are a few functions specific to Python functions.
|
|
9
|
+
|
|
10
|
+
# PyFunctionObject
|
|
11
|
+
#
|
|
12
|
+
# The C structure used for functions.
|
|
13
|
+
|
|
14
|
+
# PyTypeObject PyFunction_Type
|
|
15
|
+
#
|
|
16
|
+
# This is an instance of PyTypeObject and represents the Python
|
|
17
|
+
# function type. It is exposed to Python programmers as
|
|
18
|
+
# types.FunctionType.
|
|
19
|
+
|
|
20
|
+
bint PyFunction_Check(object o)
|
|
21
|
+
# Return true if o is a function object (has type
|
|
22
|
+
# PyFunction_Type). The parameter must not be NULL.
|
|
23
|
+
|
|
24
|
+
object PyFunction_New(object code, object globals)
|
|
25
|
+
# Return value: New reference.
|
|
26
|
+
# Return a new function object associated with the code object
|
|
27
|
+
# code. globals must be a dictionary with the global variables
|
|
28
|
+
# accessible to the function.
|
|
29
|
+
# The function's docstring, name and __module__ are retrieved from
|
|
30
|
+
# the code object, the argument defaults and closure are set to
|
|
31
|
+
# NULL.
|
|
32
|
+
|
|
33
|
+
PyObject* PyFunction_GetCode(object op) except? NULL
|
|
34
|
+
# Return value: Borrowed reference.
|
|
35
|
+
# Return the code object associated with the function object op.
|
|
36
|
+
|
|
37
|
+
PyObject* PyFunction_GetGlobals(object op) except? NULL
|
|
38
|
+
# Return value: Borrowed reference.
|
|
39
|
+
# Return the globals dictionary associated with the function object op.
|
|
40
|
+
|
|
41
|
+
PyObject* PyFunction_GetModule(object op) except? NULL
|
|
42
|
+
# Return value: Borrowed reference.
|
|
43
|
+
# Return the __module__ attribute of the function object op. This
|
|
44
|
+
# is normally a string containing the module name, but can be set
|
|
45
|
+
# to any other object by Python code.
|
|
46
|
+
|
|
47
|
+
PyObject* PyFunction_GetDefaults(object op) except? NULL
|
|
48
|
+
# Return value: Borrowed reference.
|
|
49
|
+
# Return the argument default values of the function object
|
|
50
|
+
# op. This can be a tuple of arguments or NULL.
|
|
51
|
+
|
|
52
|
+
int PyFunction_SetDefaults(object op, object defaults) except -1
|
|
53
|
+
# Set the argument default values for the function object
|
|
54
|
+
# op. defaults must be Py_None or a tuple.
|
|
55
|
+
# Raises SystemError and returns -1 on failure.
|
|
56
|
+
|
|
57
|
+
PyObject* PyFunction_GetClosure(object op) except? NULL
|
|
58
|
+
# Return value: Borrowed reference.
|
|
59
|
+
# Return the closure associated with the function object op. This
|
|
60
|
+
# can be NULL or a tuple of cell objects.
|
|
61
|
+
|
|
62
|
+
int PyFunction_SetClosure(object op, object closure) except -1
|
|
63
|
+
# Set the closure associated with the function object op. closure
|
|
64
|
+
# must be Py_None or a tuple of cell objects.
|
|
65
|
+
# Raises SystemError and returns -1 on failure.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from .pystate cimport PyFrameObject
|
|
2
|
+
|
|
3
|
+
cdef extern from "Python.h":
|
|
4
|
+
|
|
5
|
+
###########################################################################
|
|
6
|
+
# Generator Objects
|
|
7
|
+
###########################################################################
|
|
8
|
+
|
|
9
|
+
bint PyGen_Check(object ob)
|
|
10
|
+
# Return true if ob is a generator object; ob must not be NULL.
|
|
11
|
+
|
|
12
|
+
bint PyGen_CheckExact(object ob)
|
|
13
|
+
# Return true if ob's type is PyGen_Type; ob must not be NULL.
|
|
14
|
+
|
|
15
|
+
object PyGen_New(PyFrameObject *frame)
|
|
16
|
+
# Return value: New reference.
|
|
17
|
+
# Create and return a new generator object based on the frame object. A
|
|
18
|
+
# reference to frame is stolen by this function. The argument must not be
|
|
19
|
+
# NULL.
|
|
20
|
+
|
|
21
|
+
object PyGen_NewWithQualName(PyFrameObject *frame, object name, object qualname)
|
|
22
|
+
# Return value: New reference.
|
|
23
|
+
# Create and return a new generator object based on the frame object, with
|
|
24
|
+
# __name__ and __qualname__ set to name and qualname. A reference to frame
|
|
25
|
+
# is stolen by this function. The frame argument must not be NULL.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
cdef extern from "Python.h":
|
|
3
|
+
#####################################################################
|
|
4
|
+
# 5.5 Parsing arguments and building values
|
|
5
|
+
#####################################################################
|
|
6
|
+
ctypedef struct va_list
|
|
7
|
+
int PyArg_ParseTuple(object args, char *format, ...) except 0
|
|
8
|
+
int PyArg_VaParse(object args, char *format, va_list vargs) except 0
|
|
9
|
+
int PyArg_ParseTupleAndKeywords(object args, object kw, char *format, char *keywords[], ...) except 0
|
|
10
|
+
int PyArg_VaParseTupleAndKeywords(object args, object kw, char *format, char *keywords[], va_list vargs) except 0
|
|
11
|
+
int PyArg_Parse(object args, char *format, ...) except 0
|
|
12
|
+
int PyArg_UnpackTuple(object args, char *name, Py_ssize_t min, Py_ssize_t max, ...) except 0
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
cdef extern from "Python.h":
|
|
2
|
+
|
|
3
|
+
############################################################################
|
|
4
|
+
# 7.5.2 Instance Objects
|
|
5
|
+
############################################################################
|
|
6
|
+
|
|
7
|
+
# PyTypeObject PyInstance_Type
|
|
8
|
+
#
|
|
9
|
+
# Type object for class instances.
|
|
10
|
+
|
|
11
|
+
int PyInstance_Check(object obj)
|
|
12
|
+
# Return true if obj is an instance.
|
|
13
|
+
|
|
14
|
+
object PyInstance_New(object cls, object arg, object kw)
|
|
15
|
+
# Return value: New reference.
|
|
16
|
+
# Create a new instance of a specific class. The parameters arg
|
|
17
|
+
# and kw are used as the positional and keyword parameters to the
|
|
18
|
+
# object's constructor.
|
|
19
|
+
|
|
20
|
+
object PyInstance_NewRaw(object cls, object dict)
|
|
21
|
+
# Return value: New reference.
|
|
22
|
+
# Create a new instance of a specific class without calling its
|
|
23
|
+
# constructor. class is the class of new object. The dict
|
|
24
|
+
# parameter will be used as the object's __dict__; if NULL, a new
|
|
25
|
+
# dictionary will be created for the instance.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
cdef extern from "Python.h":
|
|
2
|
+
|
|
3
|
+
############################################################################
|
|
4
|
+
# 6.5 Iterator Protocol
|
|
5
|
+
############################################################################
|
|
6
|
+
bint PyIter_Check(object o)
|
|
7
|
+
# Return true if the object o supports the iterator protocol.
|
|
8
|
+
|
|
9
|
+
object PyIter_Next(object o)
|
|
10
|
+
# Return value: New reference.
|
|
11
|
+
# Return the next value from the iteration o. If the object is an
|
|
12
|
+
# iterator, this retrieves the next value from the iteration, and
|
|
13
|
+
# returns NULL with no exception set if there are no remaining
|
|
14
|
+
# items. If the object is not an iterator, TypeError is raised, or
|
|
15
|
+
# if there is an error in retrieving the item, returns NULL and
|
|
16
|
+
# passes along the exception.
|
|
17
|
+
|
|
18
|
+
# To write a loop which iterates over an iterator, the C code should look something like this:
|
|
19
|
+
# PyObject *iterator = PyObject_GetIter(obj);
|
|
20
|
+
# PyObject *item;
|
|
21
|
+
# if (iterator == NULL) {
|
|
22
|
+
# /* propagate error */
|
|
23
|
+
# }
|
|
24
|
+
# while (item = PyIter_Next(iterator)) {
|
|
25
|
+
# /* do something with item */
|
|
26
|
+
# ...
|
|
27
|
+
# /* release reference when done */
|
|
28
|
+
# Py_DECREF(item);
|
|
29
|
+
# }
|
|
30
|
+
# Py_DECREF(iterator);
|
|
31
|
+
# if (PyErr_Occurred()) {
|
|
32
|
+
# /* propagate error */
|
|
33
|
+
# }
|
|
34
|
+
# else {
|
|
35
|
+
# /* continue doing useful work */
|
|
36
|
+
# }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
cdef extern from "Python.h":
|
|
2
|
+
|
|
3
|
+
###########################################################################
|
|
4
|
+
# Iterator Objects
|
|
5
|
+
###########################################################################
|
|
6
|
+
|
|
7
|
+
bint PySeqIter_Check(object op)
|
|
8
|
+
# Return true if the type of op is PySeqIter_Type.
|
|
9
|
+
|
|
10
|
+
object PySeqIter_New(object seq)
|
|
11
|
+
# Return value: New reference.
|
|
12
|
+
# Return an iterator that works with a general sequence object, seq. The
|
|
13
|
+
# iteration ends when the sequence raises IndexError for the subscripting
|
|
14
|
+
# operation.
|
|
15
|
+
|
|
16
|
+
bint PyCallIter_Check(object op)
|
|
17
|
+
# Return true if the type of op is PyCallIter_Type.
|
|
18
|
+
|
|
19
|
+
object PyCallIter_New(object callable, object sentinel)
|
|
20
|
+
# Return value: New reference.
|
|
21
|
+
# Return a new iterator. The first parameter, callable, can be any Python
|
|
22
|
+
# callable object that can be called with no parameters; each call to it
|
|
23
|
+
# should return the next item in the iteration. When callable returns a
|
|
24
|
+
# value equal to sentinel, the iteration will be terminated.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from .object cimport PyObject
|
|
2
|
+
|
|
3
|
+
cdef extern from "Python.h":
|
|
4
|
+
|
|
5
|
+
############################################################################
|
|
6
|
+
# Lists
|
|
7
|
+
############################################################################
|
|
8
|
+
list PyList_New(Py_ssize_t len)
|
|
9
|
+
# Return a new list of length len on success, or NULL on failure.
|
|
10
|
+
#
|
|
11
|
+
# Note: If length is greater than zero, the returned list object's
|
|
12
|
+
# items are set to NULL. Thus you cannot use abstract API
|
|
13
|
+
# functions such as PySequence_SetItem() or expose the object to
|
|
14
|
+
# Python code before setting all items to a real object with
|
|
15
|
+
# PyList_SetItem().
|
|
16
|
+
|
|
17
|
+
bint PyList_Check(object p)
|
|
18
|
+
# Return true if p is a list object or an instance of a subtype of
|
|
19
|
+
# the list type.
|
|
20
|
+
|
|
21
|
+
bint PyList_CheckExact(object p)
|
|
22
|
+
# Return true if p is a list object, but not an instance of a
|
|
23
|
+
# subtype of the list type.
|
|
24
|
+
|
|
25
|
+
Py_ssize_t PyList_Size(object list) except -1
|
|
26
|
+
# Return the length of the list object in list; this is equivalent
|
|
27
|
+
# to "len(list)" on a list object.
|
|
28
|
+
|
|
29
|
+
Py_ssize_t PyList_GET_SIZE(object list)
|
|
30
|
+
# Macro form of PyList_Size() without error checking.
|
|
31
|
+
|
|
32
|
+
PyObject* PyList_GetItem(object list, Py_ssize_t index) except NULL
|
|
33
|
+
# Return value: Borrowed reference.
|
|
34
|
+
# Return the object at position pos in the list pointed to by
|
|
35
|
+
# p. The position must be positive, indexing from the end of the
|
|
36
|
+
# list is not supported. If pos is out of bounds, return NULL and
|
|
37
|
+
# set an IndexError exception.
|
|
38
|
+
|
|
39
|
+
PyObject* PyList_GET_ITEM(object list, Py_ssize_t i)
|
|
40
|
+
# Return value: Borrowed reference.
|
|
41
|
+
# Macro form of PyList_GetItem() without error checking.
|
|
42
|
+
|
|
43
|
+
int PyList_SetItem(object list, Py_ssize_t index, object item) except -1
|
|
44
|
+
# Set the item at index index in list to item. Return 0 on success
|
|
45
|
+
# or -1 on failure.
|
|
46
|
+
#
|
|
47
|
+
# WARNING: This function _steals_ a reference to item and discards a
|
|
48
|
+
# reference to an item already in the list at the affected position.
|
|
49
|
+
|
|
50
|
+
void PyList_SET_ITEM(object list, Py_ssize_t i, object o)
|
|
51
|
+
# Macro form of PyList_SetItem() without error checking. This is
|
|
52
|
+
# normally only used to fill in new lists where there is no
|
|
53
|
+
# previous content.
|
|
54
|
+
#
|
|
55
|
+
# WARNING: This function _steals_ a reference to item, and, unlike
|
|
56
|
+
# PyList_SetItem(), does not discard a reference to any item that
|
|
57
|
+
# it being replaced; any reference in list at position i will be *leaked*.
|
|
58
|
+
|
|
59
|
+
int PyList_Insert(object list, Py_ssize_t index, object item) except -1
|
|
60
|
+
# Insert the item item into list list in front of index
|
|
61
|
+
# index. Return 0 if successful; return -1 and set an exception if
|
|
62
|
+
# unsuccessful. Analogous to list.insert(index, item).
|
|
63
|
+
|
|
64
|
+
int PyList_Append(object list, object item) except -1
|
|
65
|
+
# Append the object item at the end of list list. Return 0 if
|
|
66
|
+
# successful; return -1 and set an exception if
|
|
67
|
+
# unsuccessful. Analogous to list.append(item).
|
|
68
|
+
|
|
69
|
+
list PyList_GetSlice(object list, Py_ssize_t low, Py_ssize_t high)
|
|
70
|
+
# Return value: New reference.
|
|
71
|
+
# Return a list of the objects in list containing the objects
|
|
72
|
+
# between low and high. Return NULL and set an exception if
|
|
73
|
+
# unsuccessful. Analogous to list[low:high].
|
|
74
|
+
|
|
75
|
+
int PyList_SetSlice(object list, Py_ssize_t low, Py_ssize_t high, object itemlist) except -1
|
|
76
|
+
# Set the slice of list between low and high to the contents of
|
|
77
|
+
# itemlist. Analogous to list[low:high] = itemlist. The itemlist
|
|
78
|
+
# may be NULL, indicating the assignment of an empty list (slice
|
|
79
|
+
# deletion). Return 0 on success, -1 on failure.
|
|
80
|
+
|
|
81
|
+
int PyList_Sort(object list) except -1
|
|
82
|
+
# Sort the items of list in place. Return 0 on success, -1 on
|
|
83
|
+
# failure. This is equivalent to "list.sort()".
|
|
84
|
+
|
|
85
|
+
int PyList_Reverse(object list) except -1
|
|
86
|
+
# Reverse the items of list in place. Return 0 on success, -1 on
|
|
87
|
+
# failure. This is the equivalent of "list.reverse()".
|
|
88
|
+
|
|
89
|
+
tuple PyList_AsTuple(object list)
|
|
90
|
+
# Return value: New reference.
|
|
91
|
+
# Return a new tuple object containing the contents of list;
|
|
92
|
+
# equivalent to "tuple(list)".
|