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.
Files changed (316) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +323 -0
  4. Cython/Build/Dependencies.py +1306 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +463 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/SharedModule.py +76 -0
  9. Cython/Build/Tests/TestCyCache.py +194 -0
  10. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  11. Cython/Build/Tests/TestDependencies.py +133 -0
  12. Cython/Build/Tests/TestInline.py +177 -0
  13. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  14. Cython/Build/Tests/TestRecythonize.py +212 -0
  15. Cython/Build/Tests/TestStripLiterals.py +155 -0
  16. Cython/Build/Tests/__init__.py +1 -0
  17. Cython/Build/__init__.py +8 -0
  18. Cython/CodeWriter.py +811 -0
  19. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  20. Cython/Compiler/Annotate.py +326 -0
  21. Cython/Compiler/AutoDocTransforms.py +320 -0
  22. Cython/Compiler/Buffer.py +680 -0
  23. Cython/Compiler/Builtin.py +934 -0
  24. Cython/Compiler/CmdLine.py +259 -0
  25. Cython/Compiler/Code.pxd +148 -0
  26. Cython/Compiler/Code.py +3375 -0
  27. Cython/Compiler/CodeGeneration.py +33 -0
  28. Cython/Compiler/CythonScope.py +187 -0
  29. Cython/Compiler/Dataclass.py +868 -0
  30. Cython/Compiler/DebugFlags.py +24 -0
  31. Cython/Compiler/Errors.py +295 -0
  32. Cython/Compiler/ExprNodes.py +15267 -0
  33. Cython/Compiler/FlowControl.pxd +97 -0
  34. Cython/Compiler/FlowControl.py +1455 -0
  35. Cython/Compiler/FusedNode.py +1002 -0
  36. Cython/Compiler/Future.py +16 -0
  37. Cython/Compiler/Interpreter.py +57 -0
  38. Cython/Compiler/Lexicon.py +340 -0
  39. Cython/Compiler/LineTable.py +114 -0
  40. Cython/Compiler/Main.py +853 -0
  41. Cython/Compiler/MatchCaseNodes.py +259 -0
  42. Cython/Compiler/MemoryView.py +922 -0
  43. Cython/Compiler/ModuleNode.py +4024 -0
  44. Cython/Compiler/Naming.py +374 -0
  45. Cython/Compiler/Nodes.py +10826 -0
  46. Cython/Compiler/Optimize.py +5256 -0
  47. Cython/Compiler/Options.py +835 -0
  48. Cython/Compiler/ParseTreeTransforms.pxd +77 -0
  49. Cython/Compiler/ParseTreeTransforms.py +4509 -0
  50. Cython/Compiler/Parsing.pxd +9 -0
  51. Cython/Compiler/Parsing.py +4789 -0
  52. Cython/Compiler/Pipeline.py +439 -0
  53. Cython/Compiler/PyrexTypes.py +5762 -0
  54. Cython/Compiler/Pythran.py +232 -0
  55. Cython/Compiler/Scanning.pxd +40 -0
  56. Cython/Compiler/Scanning.py +577 -0
  57. Cython/Compiler/StringEncoding.py +347 -0
  58. Cython/Compiler/Symtab.py +3080 -0
  59. Cython/Compiler/Tests/TestBuffer.py +105 -0
  60. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  61. Cython/Compiler/Tests/TestCmdLine.py +586 -0
  62. Cython/Compiler/Tests/TestCode.py +86 -0
  63. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  64. Cython/Compiler/Tests/TestGrammar.py +202 -0
  65. Cython/Compiler/Tests/TestMemView.py +71 -0
  66. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  67. Cython/Compiler/Tests/TestScanning.py +134 -0
  68. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  69. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  70. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  71. Cython/Compiler/Tests/TestTreePath.py +103 -0
  72. Cython/Compiler/Tests/TestTypes.py +75 -0
  73. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  74. Cython/Compiler/Tests/TestVisitor.py +61 -0
  75. Cython/Compiler/Tests/Utils.py +36 -0
  76. Cython/Compiler/Tests/__init__.py +1 -0
  77. Cython/Compiler/TreeFragment.py +278 -0
  78. Cython/Compiler/TreePath.py +303 -0
  79. Cython/Compiler/TypeInference.py +584 -0
  80. Cython/Compiler/TypeSlots.py +1181 -0
  81. Cython/Compiler/UFuncs.py +311 -0
  82. Cython/Compiler/UtilNodes.py +389 -0
  83. Cython/Compiler/UtilityCode.py +344 -0
  84. Cython/Compiler/Version.py +8 -0
  85. Cython/Compiler/Visitor.pxd +53 -0
  86. Cython/Compiler/Visitor.py +861 -0
  87. Cython/Compiler/__init__.py +1 -0
  88. Cython/Coverage.py +448 -0
  89. Cython/Debugger/Cygdb.py +175 -0
  90. Cython/Debugger/DebugWriter.py +82 -0
  91. Cython/Debugger/Tests/TestLibCython.py +275 -0
  92. Cython/Debugger/Tests/__init__.py +1 -0
  93. Cython/Debugger/Tests/cfuncs.c +8 -0
  94. Cython/Debugger/Tests/codefile +49 -0
  95. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  96. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  97. Cython/Debugger/__init__.py +1 -0
  98. Cython/Debugger/libcython.py +1548 -0
  99. Cython/Debugger/libpython.py +2821 -0
  100. Cython/Debugging.py +20 -0
  101. Cython/Distutils/__init__.py +2 -0
  102. Cython/Distutils/build_ext.py +139 -0
  103. Cython/Distutils/extension.py +96 -0
  104. Cython/Distutils/old_build_ext.py +351 -0
  105. Cython/Includes/cpython/__init__.pxd +173 -0
  106. Cython/Includes/cpython/array.pxd +174 -0
  107. Cython/Includes/cpython/bool.pxd +37 -0
  108. Cython/Includes/cpython/buffer.pxd +112 -0
  109. Cython/Includes/cpython/bytearray.pxd +33 -0
  110. Cython/Includes/cpython/bytes.pxd +200 -0
  111. Cython/Includes/cpython/cellobject.pxd +35 -0
  112. Cython/Includes/cpython/ceval.pxd +8 -0
  113. Cython/Includes/cpython/codecs.pxd +121 -0
  114. Cython/Includes/cpython/complex.pxd +60 -0
  115. Cython/Includes/cpython/contextvars.pxd +145 -0
  116. Cython/Includes/cpython/conversion.pxd +36 -0
  117. Cython/Includes/cpython/datetime.pxd +395 -0
  118. Cython/Includes/cpython/descr.pxd +26 -0
  119. Cython/Includes/cpython/dict.pxd +187 -0
  120. Cython/Includes/cpython/exc.pxd +263 -0
  121. Cython/Includes/cpython/fileobject.pxd +57 -0
  122. Cython/Includes/cpython/float.pxd +47 -0
  123. Cython/Includes/cpython/function.pxd +65 -0
  124. Cython/Includes/cpython/genobject.pxd +25 -0
  125. Cython/Includes/cpython/getargs.pxd +12 -0
  126. Cython/Includes/cpython/instance.pxd +25 -0
  127. Cython/Includes/cpython/iterator.pxd +36 -0
  128. Cython/Includes/cpython/iterobject.pxd +24 -0
  129. Cython/Includes/cpython/list.pxd +92 -0
  130. Cython/Includes/cpython/long.pxd +149 -0
  131. Cython/Includes/cpython/longintrepr.pxd +14 -0
  132. Cython/Includes/cpython/mapping.pxd +63 -0
  133. Cython/Includes/cpython/marshal.pxd +66 -0
  134. Cython/Includes/cpython/mem.pxd +120 -0
  135. Cython/Includes/cpython/memoryview.pxd +50 -0
  136. Cython/Includes/cpython/method.pxd +49 -0
  137. Cython/Includes/cpython/module.pxd +208 -0
  138. Cython/Includes/cpython/number.pxd +258 -0
  139. Cython/Includes/cpython/object.pxd +433 -0
  140. Cython/Includes/cpython/pycapsule.pxd +143 -0
  141. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  142. Cython/Includes/cpython/pyport.pxd +8 -0
  143. Cython/Includes/cpython/pystate.pxd +95 -0
  144. Cython/Includes/cpython/pythread.pxd +53 -0
  145. Cython/Includes/cpython/ref.pxd +67 -0
  146. Cython/Includes/cpython/sequence.pxd +134 -0
  147. Cython/Includes/cpython/set.pxd +119 -0
  148. Cython/Includes/cpython/slice.pxd +70 -0
  149. Cython/Includes/cpython/time.pxd +129 -0
  150. Cython/Includes/cpython/tuple.pxd +72 -0
  151. Cython/Includes/cpython/type.pxd +53 -0
  152. Cython/Includes/cpython/unicode.pxd +639 -0
  153. Cython/Includes/cpython/version.pxd +32 -0
  154. Cython/Includes/cpython/weakref.pxd +78 -0
  155. Cython/Includes/libc/__init__.pxd +1 -0
  156. Cython/Includes/libc/complex.pxd +35 -0
  157. Cython/Includes/libc/errno.pxd +127 -0
  158. Cython/Includes/libc/float.pxd +43 -0
  159. Cython/Includes/libc/limits.pxd +28 -0
  160. Cython/Includes/libc/locale.pxd +46 -0
  161. Cython/Includes/libc/math.pxd +209 -0
  162. Cython/Includes/libc/setjmp.pxd +10 -0
  163. Cython/Includes/libc/signal.pxd +64 -0
  164. Cython/Includes/libc/stddef.pxd +9 -0
  165. Cython/Includes/libc/stdint.pxd +105 -0
  166. Cython/Includes/libc/stdio.pxd +80 -0
  167. Cython/Includes/libc/stdlib.pxd +72 -0
  168. Cython/Includes/libc/string.pxd +50 -0
  169. Cython/Includes/libc/threads.pxd +84 -0
  170. Cython/Includes/libc/time.pxd +51 -0
  171. Cython/Includes/libcpp/__init__.pxd +4 -0
  172. Cython/Includes/libcpp/algorithm.pxd +320 -0
  173. Cython/Includes/libcpp/any.pxd +16 -0
  174. Cython/Includes/libcpp/atomic.pxd +59 -0
  175. Cython/Includes/libcpp/barrier.pxd +22 -0
  176. Cython/Includes/libcpp/bit.pxd +29 -0
  177. Cython/Includes/libcpp/cast.pxd +12 -0
  178. Cython/Includes/libcpp/cmath.pxd +518 -0
  179. Cython/Includes/libcpp/complex.pxd +106 -0
  180. Cython/Includes/libcpp/deque.pxd +165 -0
  181. Cython/Includes/libcpp/exception.pxd +86 -0
  182. Cython/Includes/libcpp/execution.pxd +15 -0
  183. Cython/Includes/libcpp/forward_list.pxd +63 -0
  184. Cython/Includes/libcpp/functional.pxd +26 -0
  185. Cython/Includes/libcpp/future.pxd +103 -0
  186. Cython/Includes/libcpp/iterator.pxd +34 -0
  187. Cython/Includes/libcpp/latch.pxd +17 -0
  188. Cython/Includes/libcpp/limits.pxd +61 -0
  189. Cython/Includes/libcpp/list.pxd +117 -0
  190. Cython/Includes/libcpp/map.pxd +252 -0
  191. Cython/Includes/libcpp/memory.pxd +115 -0
  192. Cython/Includes/libcpp/mutex.pxd +130 -0
  193. Cython/Includes/libcpp/numbers.pxd +15 -0
  194. Cython/Includes/libcpp/numeric.pxd +131 -0
  195. Cython/Includes/libcpp/optional.pxd +34 -0
  196. Cython/Includes/libcpp/pair.pxd +1 -0
  197. Cython/Includes/libcpp/queue.pxd +25 -0
  198. Cython/Includes/libcpp/random.pxd +166 -0
  199. Cython/Includes/libcpp/semaphore.pxd +44 -0
  200. Cython/Includes/libcpp/set.pxd +228 -0
  201. Cython/Includes/libcpp/shared_mutex.pxd +72 -0
  202. Cython/Includes/libcpp/span.pxd +87 -0
  203. Cython/Includes/libcpp/stack.pxd +11 -0
  204. Cython/Includes/libcpp/stop_token.pxd +105 -0
  205. Cython/Includes/libcpp/string.pxd +355 -0
  206. Cython/Includes/libcpp/string_view.pxd +181 -0
  207. Cython/Includes/libcpp/typeindex.pxd +15 -0
  208. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  209. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  210. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  211. Cython/Includes/libcpp/utility.pxd +30 -0
  212. Cython/Includes/libcpp/vector.pxd +186 -0
  213. Cython/Includes/openmp.pxd +50 -0
  214. Cython/Includes/posix/__init__.pxd +1 -0
  215. Cython/Includes/posix/dlfcn.pxd +14 -0
  216. Cython/Includes/posix/fcntl.pxd +86 -0
  217. Cython/Includes/posix/ioctl.pxd +4 -0
  218. Cython/Includes/posix/mman.pxd +101 -0
  219. Cython/Includes/posix/resource.pxd +57 -0
  220. Cython/Includes/posix/select.pxd +21 -0
  221. Cython/Includes/posix/signal.pxd +73 -0
  222. Cython/Includes/posix/stat.pxd +98 -0
  223. Cython/Includes/posix/stdio.pxd +37 -0
  224. Cython/Includes/posix/stdlib.pxd +29 -0
  225. Cython/Includes/posix/strings.pxd +9 -0
  226. Cython/Includes/posix/time.pxd +71 -0
  227. Cython/Includes/posix/types.pxd +30 -0
  228. Cython/Includes/posix/uio.pxd +26 -0
  229. Cython/Includes/posix/unistd.pxd +271 -0
  230. Cython/Includes/posix/wait.pxd +38 -0
  231. Cython/Plex/Actions.pxd +24 -0
  232. Cython/Plex/Actions.py +119 -0
  233. Cython/Plex/DFA.pxd +14 -0
  234. Cython/Plex/DFA.py +164 -0
  235. Cython/Plex/Errors.py +48 -0
  236. Cython/Plex/Lexicons.py +178 -0
  237. Cython/Plex/Machines.pxd +36 -0
  238. Cython/Plex/Machines.py +238 -0
  239. Cython/Plex/Regexps.py +539 -0
  240. Cython/Plex/Scanners.pxd +47 -0
  241. Cython/Plex/Scanners.py +360 -0
  242. Cython/Plex/Transitions.pxd +14 -0
  243. Cython/Plex/Transitions.py +239 -0
  244. Cython/Plex/__init__.py +34 -0
  245. Cython/Runtime/__init__.py +1 -0
  246. Cython/Runtime/refnanny.pyx +237 -0
  247. Cython/Shadow.py +690 -0
  248. Cython/Shadow.pyi +521 -0
  249. Cython/StringIOTree.py +170 -0
  250. Cython/Tempita/__init__.py +4 -0
  251. Cython/Tempita/_looper.py +154 -0
  252. Cython/Tempita/_tempita.py +1091 -0
  253. Cython/TestUtils.py +410 -0
  254. Cython/Tests/TestCodeWriter.py +128 -0
  255. Cython/Tests/TestCythonUtils.py +202 -0
  256. Cython/Tests/TestJediTyper.py +223 -0
  257. Cython/Tests/TestShadow.py +114 -0
  258. Cython/Tests/TestStringIOTree.py +67 -0
  259. Cython/Tests/TestTestUtils.py +90 -0
  260. Cython/Tests/__init__.py +1 -0
  261. Cython/Tests/xmlrunner.py +390 -0
  262. Cython/Utility/AsyncGen.c +1002 -0
  263. Cython/Utility/Buffer.c +875 -0
  264. Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
  265. Cython/Utility/Builtins.c +776 -0
  266. Cython/Utility/CConvert.pyx +134 -0
  267. Cython/Utility/CMath.c +104 -0
  268. Cython/Utility/CommonStructures.c +118 -0
  269. Cython/Utility/Complex.c +378 -0
  270. Cython/Utility/Coroutine.c +2206 -0
  271. Cython/Utility/CpdefEnums.pyx +103 -0
  272. Cython/Utility/CppConvert.pyx +279 -0
  273. Cython/Utility/CppSupport.cpp +143 -0
  274. Cython/Utility/CythonFunction.c +1794 -0
  275. Cython/Utility/Dataclasses.c +185 -0
  276. Cython/Utility/Dataclasses.py +112 -0
  277. Cython/Utility/Embed.c +125 -0
  278. Cython/Utility/Exceptions.c +1012 -0
  279. Cython/Utility/ExtensionTypes.c +809 -0
  280. Cython/Utility/FunctionArguments.c +965 -0
  281. Cython/Utility/ImportExport.c +987 -0
  282. Cython/Utility/Lock.c +136 -0
  283. Cython/Utility/MemoryView.pxd +187 -0
  284. Cython/Utility/MemoryView.pyx +1481 -0
  285. Cython/Utility/MemoryView_C.c +1046 -0
  286. Cython/Utility/ModuleSetupCode.c +3059 -0
  287. Cython/Utility/NumpyImportArray.c +46 -0
  288. Cython/Utility/ObjectHandling.c +3342 -0
  289. Cython/Utility/Optimize.c +1589 -0
  290. Cython/Utility/Overflow.c +404 -0
  291. Cython/Utility/Printing.c +86 -0
  292. Cython/Utility/Profile.c +709 -0
  293. Cython/Utility/StringTools.c +1259 -0
  294. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  295. Cython/Utility/TestCythonScope.pyx +75 -0
  296. Cython/Utility/TestUtilityLoader.c +12 -0
  297. Cython/Utility/TypeConversion.c +1284 -0
  298. Cython/Utility/UFuncs.pyx +50 -0
  299. Cython/Utility/UFuncs_C.c +89 -0
  300. Cython/Utility/__init__.py +28 -0
  301. Cython/Utility/arrayarray.h +148 -0
  302. Cython/Utils.py +687 -0
  303. Cython/__init__.py +10 -0
  304. Cython/__init__.pyi +7 -0
  305. Cython/py.typed +0 -0
  306. cython-3.1.0.dist-info/COPYING.txt +19 -0
  307. cython-3.1.0.dist-info/LICENSE.txt +176 -0
  308. cython-3.1.0.dist-info/METADATA +636 -0
  309. cython-3.1.0.dist-info/RECORD +316 -0
  310. cython-3.1.0.dist-info/WHEEL +5 -0
  311. cython-3.1.0.dist-info/entry_points.txt +4 -0
  312. cython-3.1.0.dist-info/top_level.txt +3 -0
  313. cython.py +29 -0
  314. pyximport/__init__.py +4 -0
  315. pyximport/pyxbuild.py +160 -0
  316. 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,8 @@
1
+
2
+ cdef extern from "Python.h":
3
+
4
+ void PyEval_InitThreads()
5
+ # Initialize and acquire the global interpreter lock.
6
+
7
+ int PyEval_ThreadsInitialized()
8
+ # Returns a non-zero value if PyEval_InitThreads() has been called.
@@ -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.