Cython 3.1.0__py3-none-any.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 +323 -0
- Cython/Build/Dependencies.py +1306 -0
- Cython/Build/Distutils.py +1 -0
- Cython/Build/Inline.py +463 -0
- Cython/Build/IpythonMagic.py +560 -0
- Cython/Build/SharedModule.py +76 -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 +8 -0
- Cython/CodeWriter.py +811 -0
- Cython/Compiler/AnalysedTreeTransforms.py +97 -0
- Cython/Compiler/Annotate.py +326 -0
- Cython/Compiler/AutoDocTransforms.py +320 -0
- Cython/Compiler/Buffer.py +680 -0
- Cython/Compiler/Builtin.py +934 -0
- Cython/Compiler/CmdLine.py +259 -0
- Cython/Compiler/Code.pxd +148 -0
- Cython/Compiler/Code.py +3375 -0
- Cython/Compiler/CodeGeneration.py +33 -0
- Cython/Compiler/CythonScope.py +187 -0
- Cython/Compiler/Dataclass.py +868 -0
- Cython/Compiler/DebugFlags.py +24 -0
- Cython/Compiler/Errors.py +295 -0
- Cython/Compiler/ExprNodes.py +15267 -0
- Cython/Compiler/FlowControl.pxd +97 -0
- Cython/Compiler/FlowControl.py +1455 -0
- Cython/Compiler/FusedNode.py +1002 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +340 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/Main.py +853 -0
- Cython/Compiler/MatchCaseNodes.py +259 -0
- Cython/Compiler/MemoryView.py +922 -0
- Cython/Compiler/ModuleNode.py +4024 -0
- Cython/Compiler/Naming.py +374 -0
- Cython/Compiler/Nodes.py +10826 -0
- Cython/Compiler/Optimize.py +5256 -0
- Cython/Compiler/Options.py +835 -0
- Cython/Compiler/ParseTreeTransforms.pxd +77 -0
- Cython/Compiler/ParseTreeTransforms.py +4509 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +4789 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +5762 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +40 -0
- Cython/Compiler/Scanning.py +577 -0
- Cython/Compiler/StringEncoding.py +347 -0
- Cython/Compiler/Symtab.py +3080 -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 +86 -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 +33 -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 +584 -0
- Cython/Compiler/TypeSlots.py +1181 -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/__init__.py +1 -0
- Cython/Coverage.py +448 -0
- Cython/Debugger/Cygdb.py +175 -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 +174 -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 +67 -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 +84 -0
- Cython/Includes/libc/time.pxd +51 -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/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 +130 -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 +44 -0
- Cython/Includes/libcpp/set.pxd +228 -0
- Cython/Includes/libcpp/shared_mutex.pxd +72 -0
- Cython/Includes/libcpp/span.pxd +87 -0
- Cython/Includes/libcpp/stack.pxd +11 -0
- Cython/Includes/libcpp/stop_token.pxd +105 -0
- Cython/Includes/libcpp/string.pxd +355 -0
- Cython/Includes/libcpp/string_view.pxd +181 -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/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/DFA.pxd +14 -0
- Cython/Plex/DFA.py +164 -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/Regexps.py +539 -0
- Cython/Plex/Scanners.pxd +47 -0
- Cython/Plex/Scanners.py +360 -0
- Cython/Plex/Transitions.pxd +14 -0
- Cython/Plex/Transitions.py +239 -0
- Cython/Plex/__init__.py +34 -0
- Cython/Runtime/__init__.py +1 -0
- Cython/Runtime/refnanny.pyx +237 -0
- Cython/Shadow.py +690 -0
- Cython/Shadow.pyi +521 -0
- Cython/StringIOTree.py +170 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -0
- Cython/Tempita/_tempita.py +1091 -0
- Cython/TestUtils.py +410 -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 +1002 -0
- Cython/Utility/Buffer.c +875 -0
- Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
- Cython/Utility/Builtins.c +776 -0
- Cython/Utility/CConvert.pyx +134 -0
- Cython/Utility/CMath.c +104 -0
- Cython/Utility/CommonStructures.c +118 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2206 -0
- Cython/Utility/CpdefEnums.pyx +103 -0
- Cython/Utility/CppConvert.pyx +279 -0
- Cython/Utility/CppSupport.cpp +143 -0
- Cython/Utility/CythonFunction.c +1794 -0
- Cython/Utility/Dataclasses.c +185 -0
- Cython/Utility/Dataclasses.py +112 -0
- Cython/Utility/Embed.c +125 -0
- Cython/Utility/Exceptions.c +1012 -0
- Cython/Utility/ExtensionTypes.c +809 -0
- Cython/Utility/FunctionArguments.c +965 -0
- Cython/Utility/ImportExport.c +987 -0
- Cython/Utility/Lock.c +136 -0
- Cython/Utility/MemoryView.pxd +187 -0
- Cython/Utility/MemoryView.pyx +1481 -0
- Cython/Utility/MemoryView_C.c +1046 -0
- Cython/Utility/ModuleSetupCode.c +3059 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3342 -0
- Cython/Utility/Optimize.c +1589 -0
- Cython/Utility/Overflow.c +404 -0
- Cython/Utility/Printing.c +86 -0
- Cython/Utility/Profile.c +709 -0
- Cython/Utility/StringTools.c +1259 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1284 -0
- Cython/Utility/UFuncs.pyx +50 -0
- Cython/Utility/UFuncs_C.c +89 -0
- Cython/Utility/__init__.py +28 -0
- Cython/Utility/arrayarray.h +148 -0
- Cython/Utils.py +687 -0
- Cython/__init__.py +10 -0
- Cython/__init__.pyi +7 -0
- Cython/py.typed +0 -0
- cython-3.1.0.dist-info/COPYING.txt +19 -0
- cython-3.1.0.dist-info/LICENSE.txt +176 -0
- cython-3.1.0.dist-info/METADATA +636 -0
- cython-3.1.0.dist-info/RECORD +316 -0
- cython-3.1.0.dist-info/WHEEL +5 -0
- cython-3.1.0.dist-info/entry_points.txt +4 -0
- cython-3.1.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,200 @@
|
|
|
1
|
+
from .object cimport PyObject
|
|
2
|
+
|
|
3
|
+
cdef extern from "Python.h":
|
|
4
|
+
ctypedef struct va_list
|
|
5
|
+
|
|
6
|
+
############################################################################
|
|
7
|
+
# 7.3.1 String Objects
|
|
8
|
+
############################################################################
|
|
9
|
+
|
|
10
|
+
# These functions raise TypeError when expecting a string
|
|
11
|
+
# parameter and are called with a non-string parameter.
|
|
12
|
+
# PyStringObject
|
|
13
|
+
# This subtype of PyObject represents a Python bytes object.
|
|
14
|
+
# PyTypeObject PyBytes_Type
|
|
15
|
+
# This instance of PyTypeObject represents the Python bytes type;
|
|
16
|
+
# it is the same object as bytes and types.BytesType in the Python
|
|
17
|
+
# layer.
|
|
18
|
+
|
|
19
|
+
bint PyBytes_Check(object o)
|
|
20
|
+
# Return true if the object o is a string object or an instance of
|
|
21
|
+
# a subtype of the string type.
|
|
22
|
+
|
|
23
|
+
bint PyBytes_CheckExact(object o)
|
|
24
|
+
# Return true if the object o is a string object, but not an instance of a subtype of the string type.
|
|
25
|
+
|
|
26
|
+
bytes PyBytes_FromString(char *v)
|
|
27
|
+
# Return value: New reference.
|
|
28
|
+
# Return a new string object with the value v on success, and NULL
|
|
29
|
+
# on failure. The parameter v must not be NULL; it will not be
|
|
30
|
+
# checked.
|
|
31
|
+
|
|
32
|
+
bytes PyBytes_FromStringAndSize(char *v, Py_ssize_t len)
|
|
33
|
+
# Return value: New reference.
|
|
34
|
+
# Return a new string object with the value v and length len on
|
|
35
|
+
# success, and NULL on failure. If v is NULL, the contents of the
|
|
36
|
+
# string are uninitialized.
|
|
37
|
+
|
|
38
|
+
bytes PyBytes_FromFormat(char *format, ...)
|
|
39
|
+
# Return value: New reference.
|
|
40
|
+
# Take a C printf()-style format string and a variable number of
|
|
41
|
+
# arguments, calculate the size of the resulting Python string and
|
|
42
|
+
# return a string with the values formatted into it. The variable
|
|
43
|
+
# arguments must be C types and must correspond exactly to the
|
|
44
|
+
# format characters in the format string. The following format
|
|
45
|
+
# characters are allowed:
|
|
46
|
+
# Format Characters Type Comment
|
|
47
|
+
# %% n/a The literal % character.
|
|
48
|
+
# %c int A single character, represented as an C int.
|
|
49
|
+
# %d int Exactly equivalent to printf("%d").
|
|
50
|
+
# %u unsigned int Exactly equivalent to printf("%u").
|
|
51
|
+
# %ld long Exactly equivalent to printf("%ld").
|
|
52
|
+
# %lu unsigned long Exactly equivalent to printf("%lu").
|
|
53
|
+
# %zd Py_ssize_t Exactly equivalent to printf("%zd").
|
|
54
|
+
# %zu size_t Exactly equivalent to printf("%zu").
|
|
55
|
+
# %i int Exactly equivalent to printf("%i").
|
|
56
|
+
# %x int Exactly equivalent to printf("%x").
|
|
57
|
+
# %s char* A null-terminated C character array.
|
|
58
|
+
|
|
59
|
+
# %p void* The hex representation of a C pointer.
|
|
60
|
+
# Mostly equivalent to printf("%p") except that it is guaranteed to
|
|
61
|
+
# start with the literal 0x regardless of what the platform's printf
|
|
62
|
+
# yields.
|
|
63
|
+
# An unrecognized format character causes all the rest of the
|
|
64
|
+
# format string to be copied as-is to the result string, and any
|
|
65
|
+
# extra arguments discarded.
|
|
66
|
+
|
|
67
|
+
bytes PyBytes_FromFormatV(char *format, va_list vargs)
|
|
68
|
+
# Return value: New reference.
|
|
69
|
+
# Identical to PyBytes_FromFormat() except that it takes exactly two arguments.
|
|
70
|
+
|
|
71
|
+
bytes PyBytes_FromObject(object o)
|
|
72
|
+
# Return value: New reference.
|
|
73
|
+
# Return the bytes representation of object o that implements the buffer protocol.
|
|
74
|
+
|
|
75
|
+
Py_ssize_t PyBytes_Size(object string) except -1
|
|
76
|
+
# Return the length of the string in string object string.
|
|
77
|
+
|
|
78
|
+
Py_ssize_t PyBytes_GET_SIZE(object string)
|
|
79
|
+
# Macro form of PyBytes_Size() but without error checking.
|
|
80
|
+
|
|
81
|
+
char* PyBytes_AsString(object string) except NULL
|
|
82
|
+
# Return a NUL-terminated representation of the contents of
|
|
83
|
+
# string. The pointer refers to the internal buffer of string, not
|
|
84
|
+
# a copy. The data must not be modified in any way, unless the
|
|
85
|
+
# string was just created using PyBytes_FromStringAndSize(NULL,
|
|
86
|
+
# size). It must not be deallocated. If string is a Unicode
|
|
87
|
+
# object, this function computes the default encoding of string
|
|
88
|
+
# and operates on that. If string is not a string object at all,
|
|
89
|
+
# PyBytes_AsString() returns NULL and raises TypeError.
|
|
90
|
+
|
|
91
|
+
char* PyBytes_AS_STRING(object string)
|
|
92
|
+
# Macro form of PyBytes_AsString() but without error
|
|
93
|
+
# checking. Only string objects are supported; no Unicode objects
|
|
94
|
+
# should be passed.
|
|
95
|
+
|
|
96
|
+
int PyBytes_AsStringAndSize(object obj, char **buffer, Py_ssize_t *length) except -1
|
|
97
|
+
# Return a NULL-terminated representation of the contents of the
|
|
98
|
+
# object obj through the output variables buffer and length.
|
|
99
|
+
#
|
|
100
|
+
# The function accepts both string and Unicode objects as
|
|
101
|
+
# input. For Unicode objects it returns the default encoded
|
|
102
|
+
# version of the object. If length is NULL, the resulting buffer
|
|
103
|
+
# may not contain NUL characters; if it does, the function returns
|
|
104
|
+
# -1 and a TypeError is raised.
|
|
105
|
+
|
|
106
|
+
# The buffer refers to an internal string buffer of obj, not a
|
|
107
|
+
# copy. The data must not be modified in any way, unless the
|
|
108
|
+
# string was just created using PyBytes_FromStringAndSize(NULL,
|
|
109
|
+
# size). It must not be deallocated. If string is a Unicode
|
|
110
|
+
# object, this function computes the default encoding of string
|
|
111
|
+
# and operates on that. If string is not a string object at all,
|
|
112
|
+
# PyBytes_AsStringAndSize() returns -1 and raises TypeError.
|
|
113
|
+
|
|
114
|
+
void PyBytes_Concat(PyObject **string, object newpart)
|
|
115
|
+
# Create a new string object in *string containing the contents of
|
|
116
|
+
# newpart appended to string; the caller will own the new
|
|
117
|
+
# reference. The reference to the old value of string will be
|
|
118
|
+
# stolen. If the new string cannot be created, the old reference
|
|
119
|
+
# to string will still be discarded and the value of *string will
|
|
120
|
+
# be set to NULL; the appropriate exception will be set.
|
|
121
|
+
|
|
122
|
+
void PyBytes_ConcatAndDel(PyObject **string, object newpart)
|
|
123
|
+
# Create a new string object in *string containing the contents of
|
|
124
|
+
# newpart appended to string. This version decrements the
|
|
125
|
+
# reference count of newpart.
|
|
126
|
+
|
|
127
|
+
int _PyBytes_Resize(PyObject **string, Py_ssize_t newsize) except -1
|
|
128
|
+
# A way to resize a string object even though it is
|
|
129
|
+
# ``immutable''. Only use this to build up a brand new string
|
|
130
|
+
# object; don't use this if the string may already be known in
|
|
131
|
+
# other parts of the code. It is an error to call this function if
|
|
132
|
+
# the refcount on the input string object is not one. Pass the
|
|
133
|
+
# address of an existing string object as an lvalue (it may be
|
|
134
|
+
# written into), and the new size desired. On success, *string
|
|
135
|
+
# holds the resized string object and 0 is returned; the address
|
|
136
|
+
# in *string may differ from its input value. If the reallocation
|
|
137
|
+
# fails, the original string object at *string is deallocated,
|
|
138
|
+
# *string is set to NULL, a memory exception is set, and -1 is
|
|
139
|
+
# returned.
|
|
140
|
+
|
|
141
|
+
bytes PyBytes_Format(object format, object args)
|
|
142
|
+
# Return value: New reference. Return a new string object from
|
|
143
|
+
# format and args. Analogous to format % args. The args argument
|
|
144
|
+
# must be a tuple.
|
|
145
|
+
|
|
146
|
+
void PyBytes_InternInPlace(PyObject **string)
|
|
147
|
+
# Intern the argument *string in place. The argument must be the
|
|
148
|
+
# address of a pointer variable pointing to a Python string
|
|
149
|
+
# object. If there is an existing interned string that is the same
|
|
150
|
+
# as *string, it sets *string to it (decrementing the reference
|
|
151
|
+
# count of the old string object and incrementing the reference
|
|
152
|
+
# count of the interned string object), otherwise it leaves
|
|
153
|
+
# *string alone and interns it (incrementing its reference
|
|
154
|
+
# count). (Clarification: even though there is a lot of talk about
|
|
155
|
+
# reference counts, think of this function as
|
|
156
|
+
# reference-count-neutral; you own the object after the call if
|
|
157
|
+
# and only if you owned it before the call.)
|
|
158
|
+
|
|
159
|
+
bytes PyBytes_InternFromString(char *v)
|
|
160
|
+
# Return value: New reference.
|
|
161
|
+
# A combination of PyBytes_FromString() and
|
|
162
|
+
# PyBytes_InternInPlace(), returning either a new string object
|
|
163
|
+
# that has been interned, or a new (``owned'') reference to an
|
|
164
|
+
# earlier interned string object with the same value.
|
|
165
|
+
|
|
166
|
+
object PyBytes_Decode(char *s, Py_ssize_t size, char *encoding, char *errors)
|
|
167
|
+
# Return value: New reference.
|
|
168
|
+
# Create an object by decoding size bytes of the encoded buffer s
|
|
169
|
+
# using the codec registered for encoding. encoding and errors
|
|
170
|
+
# have the same meaning as the parameters of the same name in the
|
|
171
|
+
# unicode() built-in function. The codec to be used is looked up
|
|
172
|
+
# using the Python codec registry. Return NULL if an exception was
|
|
173
|
+
# raised by the codec.
|
|
174
|
+
|
|
175
|
+
object PyBytes_AsDecodedObject(object str, char *encoding, char *errors)
|
|
176
|
+
# Return value: New reference.
|
|
177
|
+
# Decode a string object by passing it to the codec registered for
|
|
178
|
+
# encoding and return the result as Python object. encoding and
|
|
179
|
+
# errors have the same meaning as the parameters of the same name
|
|
180
|
+
# in the string encode() method. The codec to be used is looked up
|
|
181
|
+
# using the Python codec registry. Return NULL if an exception was
|
|
182
|
+
# raised by the codec.
|
|
183
|
+
|
|
184
|
+
object PyBytes_Encode(char *s, Py_ssize_t size, char *encoding, char *errors)
|
|
185
|
+
# Return value: New reference.
|
|
186
|
+
# Encode the char buffer of the given size by passing it to the
|
|
187
|
+
# codec registered for encoding and return a Python
|
|
188
|
+
# object. encoding and errors have the same meaning as the
|
|
189
|
+
# parameters of the same name in the string encode() method. The
|
|
190
|
+
# codec to be used is looked up using the Python codec
|
|
191
|
+
# registry. Return NULL if an exception was raised by the codec.
|
|
192
|
+
|
|
193
|
+
object PyBytes_AsEncodedObject(object str, char *encoding, char *errors)
|
|
194
|
+
# Return value: New reference.
|
|
195
|
+
# Encode a string object using the codec registered for encoding
|
|
196
|
+
# and return the result as Python object. encoding and errors have
|
|
197
|
+
# the same meaning as the parameters of the same name in the
|
|
198
|
+
# string encode() method. The codec to be used is looked up using
|
|
199
|
+
# the Python codec registry. Return NULL if an exception was
|
|
200
|
+
# raised by the codec.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from .object cimport PyObject
|
|
2
|
+
|
|
3
|
+
cdef extern from "Python.h":
|
|
4
|
+
|
|
5
|
+
############################################################################
|
|
6
|
+
# Cell Objects
|
|
7
|
+
############################################################################
|
|
8
|
+
|
|
9
|
+
bint PyCell_Check(object ob)
|
|
10
|
+
# Return true if ob is a cell object; ob must not be NULL.
|
|
11
|
+
|
|
12
|
+
object PyCell_New(PyObject* ob)
|
|
13
|
+
# Return value: New reference.
|
|
14
|
+
# Create and return a new cell object containing the value ob. The
|
|
15
|
+
# parameter may be NULL.
|
|
16
|
+
|
|
17
|
+
object PyCell_Get(object cell)
|
|
18
|
+
# Return value: New reference.
|
|
19
|
+
# Return the contents of the cell object cell.
|
|
20
|
+
|
|
21
|
+
object PyCell_GET(object cell)
|
|
22
|
+
# Return value: Borrowed reference.
|
|
23
|
+
# Return the contents of the cell object cell, but without checking that
|
|
24
|
+
# cell is non-NULL and is a cell object.
|
|
25
|
+
|
|
26
|
+
int PyCell_Set(object cell, PyObject* value) except? -1
|
|
27
|
+
# Set the contents of the cell object cell to value. This releases the
|
|
28
|
+
# reference to any current content of the cell. value may be NULL. cell
|
|
29
|
+
# must be non-NULL; if it is not a cell object, -1 will be returned. On
|
|
30
|
+
# success, 0 will be returned.
|
|
31
|
+
|
|
32
|
+
void PyCell_SET(object cell, PyObject* value)
|
|
33
|
+
# Sets the value of the cell object cell to value. No reference counts are
|
|
34
|
+
# adjusted, and no checks are made for safety; cell must be non-NULL and
|
|
35
|
+
# must be a cell object.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
cdef extern from "Python.h":
|
|
2
|
+
|
|
3
|
+
###########################################################################
|
|
4
|
+
# Codec registry and support functions
|
|
5
|
+
###########################################################################
|
|
6
|
+
|
|
7
|
+
int PyCodec_Register(object search_function)
|
|
8
|
+
# Register a new codec search function.
|
|
9
|
+
|
|
10
|
+
# As side effect, this tries to load the encodings package, if not yet
|
|
11
|
+
# done, to make sure that it is always first in the list of search
|
|
12
|
+
# functions.
|
|
13
|
+
|
|
14
|
+
int PyCodec_KnownEncoding(const char *encoding)
|
|
15
|
+
# Return 1 or 0 depending on whether there is a registered codec for the
|
|
16
|
+
# given encoding. This function always succeeds.
|
|
17
|
+
|
|
18
|
+
object PyCodec_Encode(object o, const char *encoding, const char *errors)
|
|
19
|
+
# Return value: New reference.
|
|
20
|
+
# Generic codec based encoding API.
|
|
21
|
+
|
|
22
|
+
# o is passed through the encoder function found for the given encoding
|
|
23
|
+
# using the error handling method defined by errors. errors may be NULL
|
|
24
|
+
# to use the default method defined for the codec. Raises a LookupError
|
|
25
|
+
# if no encoder can be found.
|
|
26
|
+
|
|
27
|
+
object PyCodec_Decode(object o, const char *encoding, const char *errors)
|
|
28
|
+
# Return value: New reference.
|
|
29
|
+
# Generic codec based decoding API.
|
|
30
|
+
|
|
31
|
+
# o is passed through the decoder function found for the given encoding
|
|
32
|
+
# using the error handling method defined by errors. errors may be NULL
|
|
33
|
+
# to use the default method defined for the codec. Raises a LookupError
|
|
34
|
+
# if no encoder can be found.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Codec lookup API
|
|
38
|
+
|
|
39
|
+
# In the following functions, the encoding string is looked up converted
|
|
40
|
+
# to all lower-case characters, which makes encodings looked up through
|
|
41
|
+
# this mechanism effectively case-insensitive. If no codec is found, a
|
|
42
|
+
# KeyError is set and NULL returned.
|
|
43
|
+
|
|
44
|
+
object PyCodec_Encoder(const char *encoding)
|
|
45
|
+
# Return value: New reference.
|
|
46
|
+
# Get an encoder function for the given encoding.
|
|
47
|
+
|
|
48
|
+
object PyCodec_Decoder(const char *encoding)
|
|
49
|
+
# Return value: New reference.
|
|
50
|
+
# Get a decoder function for the given encoding.
|
|
51
|
+
|
|
52
|
+
object PyCodec_IncrementalEncoder(const char *encoding, const char *errors)
|
|
53
|
+
# Return value: New reference.
|
|
54
|
+
# Get an IncrementalEncoder object for the given encoding.
|
|
55
|
+
|
|
56
|
+
object PyCodec_IncrementalDecoder(const char *encoding, const char *errors)
|
|
57
|
+
# Return value: New reference.
|
|
58
|
+
# Get an IncrementalDecoder object for the given encoding.
|
|
59
|
+
|
|
60
|
+
object PyCodec_StreamReader(const char *encoding, object stream, const char *errors)
|
|
61
|
+
# Return value: New reference.
|
|
62
|
+
# Get a StreamReader factory function for the given encoding.
|
|
63
|
+
|
|
64
|
+
object PyCodec_StreamWriter(const char *encoding, object stream, const char *errors)
|
|
65
|
+
# Return value: New reference.
|
|
66
|
+
# Get a StreamWriter factory function for the given encoding.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# Registry API for Unicode encoding error handlers
|
|
70
|
+
|
|
71
|
+
int PyCodec_RegisterError(const char *name, object error) except? -1
|
|
72
|
+
# Register the error handling callback function error under the given
|
|
73
|
+
# name. This callback function will be called by a codec when it
|
|
74
|
+
# encounters unencodable characters/undecodable bytes and name is
|
|
75
|
+
# specified as the error parameter in the call to the encode/decode
|
|
76
|
+
# function.
|
|
77
|
+
|
|
78
|
+
# The callback gets a single argument, an instance of
|
|
79
|
+
# UnicodeEncodeError, UnicodeDecodeError or UnicodeTranslateError that
|
|
80
|
+
# holds information about the problematic sequence of characters or bytes
|
|
81
|
+
# and their offset in the original string (see Unicode Exception Objects
|
|
82
|
+
# for functions to extract this information). The callback must either
|
|
83
|
+
# raise the given exception, or return a two-item tuple containing the
|
|
84
|
+
# replacement for the problematic sequence, and an integer giving the
|
|
85
|
+
# offset in the original string at which encoding/decoding should be
|
|
86
|
+
# resumed.
|
|
87
|
+
|
|
88
|
+
# Return 0 on success, -1 on error.
|
|
89
|
+
|
|
90
|
+
object PyCodec_LookupError(const char *name)
|
|
91
|
+
# Return value: New reference.
|
|
92
|
+
# Lookup the error handling callback function registered under name. As a
|
|
93
|
+
# special case NULL can be passed, in which case the error handling
|
|
94
|
+
# callback for "strict" will be returned.
|
|
95
|
+
|
|
96
|
+
object PyCodec_StrictErrors(object exc)
|
|
97
|
+
# Return value: Always NULL.
|
|
98
|
+
# Raise exc as an exception.
|
|
99
|
+
|
|
100
|
+
object PyCodec_IgnoreErrors(object exc)
|
|
101
|
+
# Return value: New reference.
|
|
102
|
+
# Ignore the unicode error, skipping the faulty input.
|
|
103
|
+
|
|
104
|
+
object PyCodec_ReplaceErrors(object exc)
|
|
105
|
+
# Return value: New reference.
|
|
106
|
+
# Replace the unicode encode error with "?" or "U+FFFD".
|
|
107
|
+
|
|
108
|
+
object PyCodec_XMLCharRefReplaceErrors(object exc)
|
|
109
|
+
# Return value: New reference.
|
|
110
|
+
# Replace the unicode encode error with XML character references.
|
|
111
|
+
|
|
112
|
+
object PyCodec_BackslashReplaceErrors(object exc)
|
|
113
|
+
# Return value: New reference.
|
|
114
|
+
# Replace the unicode encode error with backslash escapes ("\x", "\u"
|
|
115
|
+
# and "\U").
|
|
116
|
+
|
|
117
|
+
object PyCodec_NameReplaceErrors(object exc)
|
|
118
|
+
# Return value: New reference.
|
|
119
|
+
# Replace the unicode encode error with "\N{...}" escapes.
|
|
120
|
+
|
|
121
|
+
# New in version 3.5.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
cimport cython as _cython
|
|
2
|
+
|
|
3
|
+
cdef extern from "Python.h":
|
|
4
|
+
|
|
5
|
+
ctypedef struct Py_complex:
|
|
6
|
+
double imag
|
|
7
|
+
double real
|
|
8
|
+
|
|
9
|
+
############################################################################
|
|
10
|
+
# 7.2.5.2 Complex Numbers as Python Objects
|
|
11
|
+
############################################################################
|
|
12
|
+
|
|
13
|
+
# PyComplexObject
|
|
14
|
+
# This subtype of PyObject represents a Python complex number object.
|
|
15
|
+
|
|
16
|
+
ctypedef class __builtin__.complex [object PyComplexObject]:
|
|
17
|
+
cdef Py_complex cval
|
|
18
|
+
|
|
19
|
+
# unavailable in limited API
|
|
20
|
+
@property
|
|
21
|
+
@_cython.c_compile_guard("!CYTHON_COMPILING_IN_LIMITED_API")
|
|
22
|
+
cdef inline double real(self) noexcept:
|
|
23
|
+
return self.cval.real
|
|
24
|
+
|
|
25
|
+
# unavailable in limited API
|
|
26
|
+
@property
|
|
27
|
+
@_cython.c_compile_guard("!CYTHON_COMPILING_IN_LIMITED_API")
|
|
28
|
+
cdef inline double imag(self) noexcept:
|
|
29
|
+
return self.cval.imag
|
|
30
|
+
|
|
31
|
+
# PyTypeObject PyComplex_Type
|
|
32
|
+
# This instance of PyTypeObject represents the Python complex
|
|
33
|
+
# number type. It is the same object as complex and
|
|
34
|
+
# types.ComplexType.
|
|
35
|
+
|
|
36
|
+
bint PyComplex_Check(object p)
|
|
37
|
+
# Return true if its argument is a PyComplexObject or a subtype of
|
|
38
|
+
# PyComplexObject.
|
|
39
|
+
|
|
40
|
+
bint PyComplex_CheckExact(object p)
|
|
41
|
+
# Return true if its argument is a PyComplexObject, but not a subtype of PyComplexObject.
|
|
42
|
+
|
|
43
|
+
object PyComplex_FromCComplex(Py_complex v)
|
|
44
|
+
# Return value: New reference.
|
|
45
|
+
# Create a new Python complex number object from a C Py_complex value.
|
|
46
|
+
|
|
47
|
+
object PyComplex_FromDoubles(double real, double imag)
|
|
48
|
+
# Return value: New reference.
|
|
49
|
+
# Return a new PyComplexObject object from real and imag.
|
|
50
|
+
|
|
51
|
+
double PyComplex_RealAsDouble(object op) except? -1
|
|
52
|
+
# Return the real part of op as a C double.
|
|
53
|
+
|
|
54
|
+
double PyComplex_ImagAsDouble(object op) except? -1
|
|
55
|
+
# Return the imaginary part of op as a C double.
|
|
56
|
+
|
|
57
|
+
Py_complex PyComplex_AsCComplex(object op)
|
|
58
|
+
# Return the Py_complex value of the complex number op.
|
|
59
|
+
#
|
|
60
|
+
# Returns (-1+0i) in case of an error
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
from cpython.object cimport PyObject
|
|
2
|
+
from cpython.ref cimport Py_XDECREF
|
|
3
|
+
|
|
4
|
+
cimport cython as _cython
|
|
5
|
+
|
|
6
|
+
cdef extern from *:
|
|
7
|
+
# Defining PyContextVar_Get() below to always return the default value for Py<3.7 and PyPy<7.3.6
|
|
8
|
+
# to make the inline functions sort-of work.
|
|
9
|
+
"""
|
|
10
|
+
#if (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030600) && !defined(PyContextVar_Get)
|
|
11
|
+
#define PyContextVar_Get(var, d, v) \
|
|
12
|
+
((d) ? \
|
|
13
|
+
((void)(var), Py_INCREF(d), (v)[0] = (d), 0) : \
|
|
14
|
+
((v)[0] = NULL, 0) \
|
|
15
|
+
)
|
|
16
|
+
#endif
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
cdef extern from "Python.h":
|
|
20
|
+
############################################################################
|
|
21
|
+
# Context Variables Objects
|
|
22
|
+
############################################################################
|
|
23
|
+
|
|
24
|
+
# PyContext
|
|
25
|
+
# The C structure used to represent a `contextvars.Context` object.
|
|
26
|
+
|
|
27
|
+
# PyContextVar
|
|
28
|
+
# The C structure used to represent a `contextvars.ContextVar` object.
|
|
29
|
+
|
|
30
|
+
# PyContextToken
|
|
31
|
+
# The C structure used to represent a `contextvars.Token` object.
|
|
32
|
+
|
|
33
|
+
# PyTypeObject PyContext_Type
|
|
34
|
+
# Type object representing the `contextvars.Context` type.
|
|
35
|
+
|
|
36
|
+
# PyTypeObject PyContextVar_Type
|
|
37
|
+
# Type object representing the `contextvars.ContextVar` type.
|
|
38
|
+
|
|
39
|
+
# PyTypeObject PyContextToken_Type
|
|
40
|
+
# Type object representing the `contextvars.Token` type.
|
|
41
|
+
|
|
42
|
+
bint PyContext_CheckExact(object obj)
|
|
43
|
+
# Return `true` if `obj` is of type `PyContext_Type`.
|
|
44
|
+
# `obj` must not be NULL. This function always succeeds.
|
|
45
|
+
|
|
46
|
+
bint PyContextVar_CheckExact(object obj)
|
|
47
|
+
# Return `true` if `obj` is of type `PyContextVar_Type`.
|
|
48
|
+
# `obj` must not be NULL. This function always succeeds.
|
|
49
|
+
|
|
50
|
+
bint PyContextToken_CheckExact(object obj)
|
|
51
|
+
# Return `true` if `obj` is of type `PyContextToken_Type`.
|
|
52
|
+
# `obj` must not be NULL. This function always succeeds.
|
|
53
|
+
|
|
54
|
+
object PyContext_New()
|
|
55
|
+
# Return value: New reference.
|
|
56
|
+
# Create a new empty context object.
|
|
57
|
+
# Returns NULL if an error has occurred.
|
|
58
|
+
|
|
59
|
+
object PyContext_Copy(object ctx)
|
|
60
|
+
# Return value: New reference.
|
|
61
|
+
# Create a shallow copy of the passed `ctx` context object.
|
|
62
|
+
# Returns NULL if an error has occurred.
|
|
63
|
+
|
|
64
|
+
object PyContext_CopyCurrent()
|
|
65
|
+
# Return value: New reference.
|
|
66
|
+
# Create a shallow copy of the current thread context.
|
|
67
|
+
# Returns NULL if an error has occurred.
|
|
68
|
+
|
|
69
|
+
int PyContext_Enter(object ctx) except -1
|
|
70
|
+
# Set `ctx` as the current context for the current thread.
|
|
71
|
+
# Returns 0 on success, and -1 on error.
|
|
72
|
+
|
|
73
|
+
int PyContext_Exit(object ctx) except -1
|
|
74
|
+
# Deactivate the `ctx` context and restore the previous context
|
|
75
|
+
# as the current context for the current thread.
|
|
76
|
+
# Returns 0 on success, and -1 on error.
|
|
77
|
+
|
|
78
|
+
object PyContextVar_New(const char* name, PyObject* default_value)
|
|
79
|
+
# Return value: New reference.
|
|
80
|
+
# Create a new ContextVar object. The `name` parameter is used
|
|
81
|
+
# for introspection and debug purposes. The `default_value` parameter
|
|
82
|
+
# may optionally specify the default value for the context variable.
|
|
83
|
+
# If an error has occurred, this function returns NULL.
|
|
84
|
+
|
|
85
|
+
object PyContextVar_New_with_default "PyContextVar_New" (const char* name, object default_value)
|
|
86
|
+
# A different declaration of PyContextVar_New that requires a default value
|
|
87
|
+
# to be passed on call.
|
|
88
|
+
|
|
89
|
+
int PyContextVar_Get(object var, PyObject* default_value, PyObject** value) except -1
|
|
90
|
+
# Get the value of a context variable.
|
|
91
|
+
# Returns -1 if an error has occurred during lookup, and 0 if no error
|
|
92
|
+
# occurred, whether or not a value was found.
|
|
93
|
+
#
|
|
94
|
+
# If the context variable was found, `value` will be a pointer to it.
|
|
95
|
+
# If the context variable was not found, `value` will point to:
|
|
96
|
+
#
|
|
97
|
+
# • `default_value`, if not NULL;
|
|
98
|
+
# • the default value of `var`, if not NULL;
|
|
99
|
+
# • NULL
|
|
100
|
+
int PyContextVar_Get_with_default "PyContextVar_Get" (object var, object default_value, PyObject** value) except -1
|
|
101
|
+
# A different declaration of PyContextVar_Get that requires a default value
|
|
102
|
+
# to be passed on call.
|
|
103
|
+
|
|
104
|
+
object PyContextVar_Set(object var, object value)
|
|
105
|
+
# Return value: New reference.
|
|
106
|
+
# Set the value of `var` to `value` in the current context.
|
|
107
|
+
# Returns a token object for this value change, or NULL if an error has occurred.
|
|
108
|
+
|
|
109
|
+
int PyContextVar_Reset(object var, object token) except -1
|
|
110
|
+
# Reset the state of the `var` context variable to that it was in
|
|
111
|
+
# before `PyContextVar_Set()` that returned `token` was called.
|
|
112
|
+
# This function returns 0 on success and -1 on error.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@_cython.c_compile_guard("!CYTHON_COMPILING_IN_LIMITED_API")
|
|
116
|
+
cdef inline object get_value(var, default_value=None):
|
|
117
|
+
"""Return a new reference to the value of the context variable,
|
|
118
|
+
or the default value of the context variable,
|
|
119
|
+
or None if no such value or default was found.
|
|
120
|
+
"""
|
|
121
|
+
cdef PyObject *value = NULL
|
|
122
|
+
PyContextVar_Get(var, NULL, &value)
|
|
123
|
+
if value is NULL:
|
|
124
|
+
# context variable does not have a default
|
|
125
|
+
pyvalue = default_value
|
|
126
|
+
else:
|
|
127
|
+
# value or default value of context variable
|
|
128
|
+
pyvalue = <object>value
|
|
129
|
+
Py_XDECREF(value) # PyContextVar_Get() returned an owned reference as 'PyObject*'
|
|
130
|
+
return pyvalue
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@_cython.c_compile_guard("!CYTHON_COMPILING_IN_LIMITED_API")
|
|
134
|
+
cdef inline object get_value_no_default(var, default_value=None):
|
|
135
|
+
"""Return a new reference to the value of the context variable,
|
|
136
|
+
or the provided default value if no such value was found.
|
|
137
|
+
|
|
138
|
+
Ignores the default value of the context variable, if any.
|
|
139
|
+
"""
|
|
140
|
+
cdef PyObject *value = NULL
|
|
141
|
+
PyContextVar_Get(var, <PyObject*>default_value, &value)
|
|
142
|
+
# value of context variable or 'default_value'
|
|
143
|
+
pyvalue = <object>value
|
|
144
|
+
Py_XDECREF(value) # PyContextVar_Get() returned an owned reference as 'PyObject*'
|
|
145
|
+
return pyvalue
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# From https://docs.python.org/3/c-api/conversion.html
|
|
2
|
+
|
|
3
|
+
from .object cimport PyObject
|
|
4
|
+
|
|
5
|
+
cdef extern from "Python.h":
|
|
6
|
+
ctypedef struct va_list
|
|
7
|
+
|
|
8
|
+
int PyOS_snprintf(char *str, size_t size, const char *format, ...)
|
|
9
|
+
# Output not more than size bytes to str according to the format
|
|
10
|
+
# string format and the extra arguments. See the Unix man page snprintf(2).
|
|
11
|
+
|
|
12
|
+
int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
|
|
13
|
+
# Output not more than size bytes to str according to the format
|
|
14
|
+
# string format and the variable argument list va. Unix man page vsnprintf(2).
|
|
15
|
+
|
|
16
|
+
double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception) except? -1.0
|
|
17
|
+
# Convert a string s to a double, raising a Python exception on failure. The set of
|
|
18
|
+
# accepted strings corresponds to the set of strings accepted by Python’s float()
|
|
19
|
+
# constructor, except that s must not have leading or trailing whitespace.
|
|
20
|
+
# The conversion is independent of the current locale.
|
|
21
|
+
|
|
22
|
+
enum:
|
|
23
|
+
Py_DTSF_SIGN
|
|
24
|
+
Py_DTSF_ADD_DOT_0
|
|
25
|
+
Py_DTSF_ALT
|
|
26
|
+
|
|
27
|
+
char* PyOS_double_to_string(double val, char format_code, int precision, int flags, int *ptype) except NULL
|
|
28
|
+
# Convert a double val to a string using supplied format_code, precision, and flags.
|
|
29
|
+
|
|
30
|
+
int PyOS_stricmp(const char *s1, const char *s2)
|
|
31
|
+
# Case insensitive comparison of strings. The function works almost identically
|
|
32
|
+
# to strcmp() except that it ignores the case.
|
|
33
|
+
|
|
34
|
+
int PyOS_strnicmp(const char *s1, const char *s2, Py_ssize_t size)
|
|
35
|
+
# Case insensitive comparison of strings. The function works almost identically
|
|
36
|
+
# to strncmp() except that it ignores the case.
|