oxython 0.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 (321) hide show
  1. Cython/Build/BuildExecutable.py +156 -0
  2. Cython/Build/Cache.py +198 -0
  3. Cython/Build/Cythonize.py +349 -0
  4. Cython/Build/Dependencies.py +1320 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +467 -0
  7. Cython/Build/IpythonMagic.py +559 -0
  8. Cython/Build/SharedModule.py +165 -0
  9. Cython/Build/Tests/TestCyCache.py +222 -0
  10. Cython/Build/Tests/TestCythonizeArgsParser.py +480 -0
  11. Cython/Build/Tests/TestDependencies.py +133 -0
  12. Cython/Build/Tests/TestInline.py +177 -0
  13. Cython/Build/Tests/TestIpythonMagic.py +303 -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 +11 -0
  18. Cython/CodeWriter.py +825 -0
  19. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  20. Cython/Compiler/Annotate.py +328 -0
  21. Cython/Compiler/AutoDocTransforms.py +320 -0
  22. Cython/Compiler/Buffer.py +679 -0
  23. Cython/Compiler/Builtin.py +1102 -0
  24. Cython/Compiler/CmdLine.py +373 -0
  25. Cython/Compiler/Code.pxd +154 -0
  26. Cython/Compiler/Code.py +3760 -0
  27. Cython/Compiler/CodeGeneration.py +33 -0
  28. Cython/Compiler/CythonScope.py +208 -0
  29. Cython/Compiler/Dataclass.py +890 -0
  30. Cython/Compiler/DebugFlags.py +24 -0
  31. Cython/Compiler/Errors.py +310 -0
  32. Cython/Compiler/ExprNodes.py +16319 -0
  33. Cython/Compiler/FlowControl.pxd +112 -0
  34. Cython/Compiler/FlowControl.py +1575 -0
  35. Cython/Compiler/FusedNode.py +978 -0
  36. Cython/Compiler/Future.py +16 -0
  37. Cython/Compiler/Interpreter.py +57 -0
  38. Cython/Compiler/Lexicon.py +442 -0
  39. Cython/Compiler/LineTable.py +114 -0
  40. Cython/Compiler/Main.py +879 -0
  41. Cython/Compiler/MatchCaseNodes.py +2200 -0
  42. Cython/Compiler/MemoryView.py +930 -0
  43. Cython/Compiler/ModuleNode.py +4558 -0
  44. Cython/Compiler/Naming.py +370 -0
  45. Cython/Compiler/Nodes.py +11334 -0
  46. Cython/Compiler/Optimize.py +5563 -0
  47. Cython/Compiler/Options.py +841 -0
  48. Cython/Compiler/ParseTreeTransforms.pxd +80 -0
  49. Cython/Compiler/ParseTreeTransforms.py +4808 -0
  50. Cython/Compiler/Parsing.pxd +9 -0
  51. Cython/Compiler/Parsing.py +5442 -0
  52. Cython/Compiler/Pipeline.py +439 -0
  53. Cython/Compiler/PyrexTypes.py +6588 -0
  54. Cython/Compiler/Pythran.py +232 -0
  55. Cython/Compiler/Scanning.pxd +74 -0
  56. Cython/Compiler/Scanning.py +771 -0
  57. Cython/Compiler/StringEncoding.py +354 -0
  58. Cython/Compiler/Symtab.py +3122 -0
  59. Cython/Compiler/Tests/TestBuffer.py +105 -0
  60. Cython/Compiler/Tests/TestBuiltin.py +196 -0
  61. Cython/Compiler/Tests/TestCmdLine.py +652 -0
  62. Cython/Compiler/Tests/TestCode.py +145 -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 +132 -0
  68. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  69. Cython/Compiler/Tests/TestStringEncoding.py +20 -0
  70. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  71. Cython/Compiler/Tests/TestTreePath.py +103 -0
  72. Cython/Compiler/Tests/TestTypes.py +119 -0
  73. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  74. Cython/Compiler/Tests/TestVisitor.py +119 -0
  75. Cython/Compiler/Tests/Utils.py +36 -0
  76. Cython/Compiler/Tests/__init__.py +1 -0
  77. Cython/Compiler/TreeFragment.py +279 -0
  78. Cython/Compiler/TreePath.py +303 -0
  79. Cython/Compiler/TypeInference.py +626 -0
  80. Cython/Compiler/TypeSlots.py +1330 -0
  81. Cython/Compiler/UFuncs.py +317 -0
  82. Cython/Compiler/UtilNodes.py +389 -0
  83. Cython/Compiler/UtilityCode.py +354 -0
  84. Cython/Compiler/Version.py +8 -0
  85. Cython/Compiler/Visitor.pxd +52 -0
  86. Cython/Compiler/Visitor.py +914 -0
  87. Cython/Compiler/__init__.py +1 -0
  88. Cython/Coverage.py +448 -0
  89. Cython/Debugger/Cygdb.py +214 -0
  90. Cython/Debugger/DebugWriter.py +82 -0
  91. Cython/Debugger/Tests/TestLibCython.py +280 -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 +580 -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 +143 -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 +159 -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 +268 -0
  120. Cython/Includes/cpython/exc.pxd +263 -0
  121. Cython/Includes/cpython/fileobject.pxd +57 -0
  122. Cython/Includes/cpython/float.pxd +56 -0
  123. Cython/Includes/cpython/frozendict.pxd +37 -0
  124. Cython/Includes/cpython/function.pxd +65 -0
  125. Cython/Includes/cpython/genobject.pxd +25 -0
  126. Cython/Includes/cpython/getargs.pxd +12 -0
  127. Cython/Includes/cpython/instance.pxd +25 -0
  128. Cython/Includes/cpython/iterator.pxd +36 -0
  129. Cython/Includes/cpython/iterobject.pxd +24 -0
  130. Cython/Includes/cpython/list.pxd +144 -0
  131. Cython/Includes/cpython/long.pxd +180 -0
  132. Cython/Includes/cpython/longintrepr.pxd +14 -0
  133. Cython/Includes/cpython/mapping.pxd +63 -0
  134. Cython/Includes/cpython/marshal.pxd +66 -0
  135. Cython/Includes/cpython/mem.pxd +120 -0
  136. Cython/Includes/cpython/memoryview.pxd +50 -0
  137. Cython/Includes/cpython/method.pxd +49 -0
  138. Cython/Includes/cpython/module.pxd +208 -0
  139. Cython/Includes/cpython/number.pxd +258 -0
  140. Cython/Includes/cpython/object.pxd +430 -0
  141. Cython/Includes/cpython/pycapsule.pxd +143 -0
  142. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  143. Cython/Includes/cpython/pyport.pxd +8 -0
  144. Cython/Includes/cpython/pystate.pxd +95 -0
  145. Cython/Includes/cpython/pythread.pxd +53 -0
  146. Cython/Includes/cpython/ref.pxd +141 -0
  147. Cython/Includes/cpython/sentinel.pxd +17 -0
  148. Cython/Includes/cpython/sequence.pxd +134 -0
  149. Cython/Includes/cpython/set.pxd +119 -0
  150. Cython/Includes/cpython/slice.pxd +70 -0
  151. Cython/Includes/cpython/time.pxd +129 -0
  152. Cython/Includes/cpython/tuple.pxd +72 -0
  153. Cython/Includes/cpython/type.pxd +146 -0
  154. Cython/Includes/cpython/unicode.pxd +639 -0
  155. Cython/Includes/cpython/version.pxd +32 -0
  156. Cython/Includes/cpython/weakref.pxd +78 -0
  157. Cython/Includes/libc/__init__.pxd +1 -0
  158. Cython/Includes/libc/complex.pxd +35 -0
  159. Cython/Includes/libc/errno.pxd +127 -0
  160. Cython/Includes/libc/float.pxd +43 -0
  161. Cython/Includes/libc/limits.pxd +28 -0
  162. Cython/Includes/libc/locale.pxd +46 -0
  163. Cython/Includes/libc/math.pxd +209 -0
  164. Cython/Includes/libc/setjmp.pxd +10 -0
  165. Cython/Includes/libc/signal.pxd +64 -0
  166. Cython/Includes/libc/stdbool.pxd +5 -0
  167. Cython/Includes/libc/stddef.pxd +9 -0
  168. Cython/Includes/libc/stdint.pxd +105 -0
  169. Cython/Includes/libc/stdio.pxd +80 -0
  170. Cython/Includes/libc/stdlib.pxd +72 -0
  171. Cython/Includes/libc/string.pxd +50 -0
  172. Cython/Includes/libc/threads.pxd +234 -0
  173. Cython/Includes/libc/time.pxd +52 -0
  174. Cython/Includes/libcpp/__init__.pxd +4 -0
  175. Cython/Includes/libcpp/algorithm.pxd +320 -0
  176. Cython/Includes/libcpp/any.pxd +16 -0
  177. Cython/Includes/libcpp/atomic.pxd +59 -0
  178. Cython/Includes/libcpp/barrier.pxd +22 -0
  179. Cython/Includes/libcpp/bit.pxd +29 -0
  180. Cython/Includes/libcpp/cast.pxd +12 -0
  181. Cython/Includes/libcpp/cmath.pxd +518 -0
  182. Cython/Includes/libcpp/complex.pxd +106 -0
  183. Cython/Includes/libcpp/condition_variable.pxd +322 -0
  184. Cython/Includes/libcpp/deque.pxd +165 -0
  185. Cython/Includes/libcpp/exception.pxd +216 -0
  186. Cython/Includes/libcpp/execution.pxd +15 -0
  187. Cython/Includes/libcpp/forward_list.pxd +63 -0
  188. Cython/Includes/libcpp/functional.pxd +26 -0
  189. Cython/Includes/libcpp/future.pxd +103 -0
  190. Cython/Includes/libcpp/iterator.pxd +34 -0
  191. Cython/Includes/libcpp/latch.pxd +17 -0
  192. Cython/Includes/libcpp/limits.pxd +61 -0
  193. Cython/Includes/libcpp/list.pxd +117 -0
  194. Cython/Includes/libcpp/map.pxd +252 -0
  195. Cython/Includes/libcpp/memory.pxd +115 -0
  196. Cython/Includes/libcpp/mutex.pxd +387 -0
  197. Cython/Includes/libcpp/numbers.pxd +15 -0
  198. Cython/Includes/libcpp/numeric.pxd +131 -0
  199. Cython/Includes/libcpp/optional.pxd +34 -0
  200. Cython/Includes/libcpp/pair.pxd +1 -0
  201. Cython/Includes/libcpp/queue.pxd +25 -0
  202. Cython/Includes/libcpp/random.pxd +166 -0
  203. Cython/Includes/libcpp/semaphore.pxd +43 -0
  204. Cython/Includes/libcpp/set.pxd +228 -0
  205. Cython/Includes/libcpp/shared_mutex.pxd +96 -0
  206. Cython/Includes/libcpp/span.pxd +87 -0
  207. Cython/Includes/libcpp/stack.pxd +11 -0
  208. Cython/Includes/libcpp/stop_token.pxd +117 -0
  209. Cython/Includes/libcpp/string.pxd +355 -0
  210. Cython/Includes/libcpp/string_view.pxd +183 -0
  211. Cython/Includes/libcpp/typeindex.pxd +15 -0
  212. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  213. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  214. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  215. Cython/Includes/libcpp/utility.pxd +30 -0
  216. Cython/Includes/libcpp/vector.pxd +186 -0
  217. Cython/Includes/numpy/math.pxd +150 -0
  218. Cython/Includes/openmp.pxd +50 -0
  219. Cython/Includes/posix/__init__.pxd +1 -0
  220. Cython/Includes/posix/dlfcn.pxd +14 -0
  221. Cython/Includes/posix/fcntl.pxd +86 -0
  222. Cython/Includes/posix/ioctl.pxd +4 -0
  223. Cython/Includes/posix/mman.pxd +101 -0
  224. Cython/Includes/posix/resource.pxd +57 -0
  225. Cython/Includes/posix/select.pxd +21 -0
  226. Cython/Includes/posix/signal.pxd +73 -0
  227. Cython/Includes/posix/stat.pxd +98 -0
  228. Cython/Includes/posix/stdio.pxd +37 -0
  229. Cython/Includes/posix/stdlib.pxd +29 -0
  230. Cython/Includes/posix/strings.pxd +9 -0
  231. Cython/Includes/posix/time.pxd +71 -0
  232. Cython/Includes/posix/types.pxd +30 -0
  233. Cython/Includes/posix/uio.pxd +26 -0
  234. Cython/Includes/posix/unistd.pxd +271 -0
  235. Cython/Includes/posix/wait.pxd +38 -0
  236. Cython/LZSS.py +184 -0
  237. Cython/Plex/Actions.pxd +24 -0
  238. Cython/Plex/Actions.py +119 -0
  239. Cython/Plex/DFA.pxd +14 -0
  240. Cython/Plex/DFA.py +164 -0
  241. Cython/Plex/Errors.py +48 -0
  242. Cython/Plex/Lexicons.py +178 -0
  243. Cython/Plex/Machines.pxd +36 -0
  244. Cython/Plex/Machines.py +238 -0
  245. Cython/Plex/Regexps.py +535 -0
  246. Cython/Plex/Scanners.pxd +45 -0
  247. Cython/Plex/Scanners.py +328 -0
  248. Cython/Plex/Transitions.pxd +14 -0
  249. Cython/Plex/Transitions.py +239 -0
  250. Cython/Plex/__init__.py +34 -0
  251. Cython/Runtime/__init__.py +1 -0
  252. Cython/Runtime/refnanny.pyx +237 -0
  253. Cython/Shadow.py +1172 -0
  254. Cython/StringIOTree.py +169 -0
  255. Cython/Tempita/__init__.py +4 -0
  256. Cython/Tempita/_looper.py +154 -0
  257. Cython/Tempita/_tempita.py +1087 -0
  258. Cython/TestUtils.py +472 -0
  259. Cython/Tests/TestCodeWriter.py +128 -0
  260. Cython/Tests/TestCythonUtils.py +237 -0
  261. Cython/Tests/TestJediTyper.py +223 -0
  262. Cython/Tests/TestShadow.py +125 -0
  263. Cython/Tests/TestStringIOTree.py +68 -0
  264. Cython/Tests/TestTestUtils.py +89 -0
  265. Cython/Tests/__init__.py +1 -0
  266. Cython/Tests/xmlrunner.py +390 -0
  267. Cython/Utility/AsyncGen.c +1152 -0
  268. Cython/Utility/Buffer.c +866 -0
  269. Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
  270. Cython/Utility/Builtins.c +1068 -0
  271. Cython/Utility/CConvert.pyx +153 -0
  272. Cython/Utility/CMath.c +104 -0
  273. Cython/Utility/CommonStructures.c +244 -0
  274. Cython/Utility/Complex.c +378 -0
  275. Cython/Utility/Coroutine.c +2344 -0
  276. Cython/Utility/CpdefEnums.pyx +119 -0
  277. Cython/Utility/CppConvert.pyx +284 -0
  278. Cython/Utility/CppSupport.cpp +151 -0
  279. Cython/Utility/CythonFunction.c +2143 -0
  280. Cython/Utility/Dataclasses.c +101 -0
  281. Cython/Utility/Embed.c +129 -0
  282. Cython/Utility/Exceptions.c +1331 -0
  283. Cython/Utility/Exceptions_Cy.pyx +109 -0
  284. Cython/Utility/ExtensionTypes.c +1199 -0
  285. Cython/Utility/FunctionArguments.c +1052 -0
  286. Cython/Utility/FusedFunction.pyx +44 -0
  287. Cython/Utility/ImportExport.c +972 -0
  288. Cython/Utility/MatchCase.c +985 -0
  289. Cython/Utility/MatchCase_Cy.pyx +12 -0
  290. Cython/Utility/MemoryView.pxd +108 -0
  291. Cython/Utility/MemoryView.pyx +1499 -0
  292. Cython/Utility/MemoryView_C.c +1056 -0
  293. Cython/Utility/ModuleSetupCode.c +3349 -0
  294. Cython/Utility/NumpyImportArray.c +46 -0
  295. Cython/Utility/ObjectHandling.c +3404 -0
  296. Cython/Utility/Optimize.c +2575 -0
  297. Cython/Utility/Overflow.c +378 -0
  298. Cython/Utility/Profile.c +736 -0
  299. Cython/Utility/StringTools.c +1534 -0
  300. Cython/Utility/Synchronization.c +438 -0
  301. Cython/Utility/TString.c +369 -0
  302. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  303. Cython/Utility/TestCythonScope.pyx +75 -0
  304. Cython/Utility/TestUtilityLoader.c +12 -0
  305. Cython/Utility/TypeConversion.c +1588 -0
  306. Cython/Utility/UFuncs.pyx +50 -0
  307. Cython/Utility/UFuncs_C.c +89 -0
  308. Cython/Utility/__init__.py +28 -0
  309. Cython/Utility/arrayarray.h +190 -0
  310. Cython/Utils.py +682 -0
  311. Cython/__init__.py +12 -0
  312. Cython/py.typed +0 -0
  313. cython.py +29 -0
  314. oxython-0.1.0.dist-info/METADATA +138 -0
  315. oxython-0.1.0.dist-info/RECORD +321 -0
  316. oxython-0.1.0.dist-info/WHEEL +5 -0
  317. oxython-0.1.0.dist-info/entry_points.txt +4 -0
  318. oxython-0.1.0.dist-info/top_level.txt +3 -0
  319. pyximport/__init__.py +4 -0
  320. pyximport/pyxbuild.py +160 -0
  321. pyximport/pyximport.py +482 -0
Cython/Utils.py ADDED
@@ -0,0 +1,682 @@
1
+ # uses @functools.wraps()
2
+ # cython: binding=True
3
+
4
+ """
5
+ Cython -- Things that don't belong anywhere else in particular
6
+ """
7
+
8
+
9
+ import cython
10
+
11
+ cython.declare(
12
+ os=object, sys=object, re=object, io=object, glob=object, shutil=object, tempfile=object,
13
+ update_wrapper=object, partial=object, wraps=object, cython_version=object,
14
+ _cache_function=object, _function_caches=list, _parse_file_version=object, _match_file_encoding=object,
15
+ _match_non_comment_line=object
16
+ )
17
+
18
+ import os
19
+ import sys
20
+ import re
21
+ import io
22
+ import glob
23
+ import shutil
24
+ import tempfile
25
+ from functools import wraps
26
+
27
+
28
+ from . import __version__ as cython_version
29
+
30
+ PACKAGE_FILES = ("__init__.py", "__init__.pyc", "__init__.pyx", "__init__.pxd", "__init__.oxy", "__init__.oxd")
31
+
32
+ _build_cache_name = "__{}_cache".format
33
+ _CACHE_NAME_PATTERN = re.compile(r"^__(.+)_cache$")
34
+
35
+ modification_time = os.path.getmtime
36
+
37
+ GENERATED_BY_MARKER = "/* Generated by Cython %s */" % cython_version
38
+ GENERATED_BY_MARKER_BYTES = GENERATED_BY_MARKER.encode('us-ascii')
39
+
40
+
41
+ class _TryFinallyGeneratorContextManager:
42
+ """
43
+ Fast, bare minimum @contextmanager, only for try-finally, not for exception handling.
44
+ """
45
+ def __init__(self, gen):
46
+ self._gen = gen
47
+
48
+ def __enter__(self):
49
+ return next(self._gen)
50
+
51
+ def __exit__(self, exc_type, exc_val, exc_tb):
52
+ try:
53
+ next(self._gen)
54
+ except (StopIteration, GeneratorExit):
55
+ pass
56
+
57
+
58
+ def try_finally_contextmanager(gen_func):
59
+ @wraps(gen_func)
60
+ def make_gen(*args, **kwargs):
61
+ return _TryFinallyGeneratorContextManager(gen_func(*args, **kwargs))
62
+ return make_gen
63
+
64
+
65
+ try:
66
+ from functools import cache as _cache_function
67
+ except ImportError:
68
+ from functools import lru_cache
69
+ _cache_function = lru_cache(maxsize=None)
70
+
71
+
72
+ _function_caches = []
73
+
74
+
75
+ def clear_function_caches():
76
+ for cache in _function_caches:
77
+ cache.cache_clear()
78
+
79
+
80
+ def cached_function(f):
81
+ cf = _cache_function(f)
82
+ _function_caches.append(cf)
83
+ cf.uncached = f # needed by coverage plugin
84
+ return cf
85
+
86
+
87
+
88
+ def _find_cache_attributes(obj):
89
+ """The function iterates over the attributes of the object and,
90
+ if it finds the name of the cache, it returns it and the corresponding method name.
91
+ The method may not be present in the object.
92
+ """
93
+ for attr_name in dir(obj):
94
+ match = _CACHE_NAME_PATTERN.match(attr_name)
95
+ if match is not None:
96
+ yield attr_name, match.group(1)
97
+
98
+
99
+ def clear_method_caches(obj):
100
+ """Removes every cache found in the object,
101
+ if a corresponding method exists for that cache.
102
+ """
103
+ for cache_name, method_name in _find_cache_attributes(obj):
104
+ if hasattr(obj, method_name):
105
+ delattr(obj, cache_name)
106
+ # if there is no corresponding method, then we assume
107
+ # that this attribute was not created by our cached method
108
+
109
+
110
+ def cached_method(f):
111
+ cache_name = _build_cache_name(f.__name__)
112
+
113
+ def wrapper(self, *args):
114
+ cache = getattr(self, cache_name, None)
115
+ if cache is None:
116
+ cache = {}
117
+ setattr(self, cache_name, cache)
118
+ if args in cache:
119
+ return cache[args]
120
+ res = cache[args] = f(self, *args)
121
+ return res
122
+
123
+ return wrapper
124
+
125
+
126
+ def replace_suffix(path, newsuf):
127
+ base, _ = os.path.splitext(path)
128
+ return base + newsuf
129
+
130
+
131
+ def open_new_file(path):
132
+ if os.path.exists(path):
133
+ # Make sure to create a new file here so we can
134
+ # safely hard link the output files.
135
+ os.unlink(path)
136
+
137
+ # We only write pure ASCII code strings, but need to write file paths in position comments.
138
+ # Those are encoded in UTF-8 so that tools can parse them out again.
139
+ return open(path, "w", encoding="UTF-8")
140
+
141
+
142
+ def castrate_file(path, st):
143
+ # Remove junk contents from an output file after a
144
+ # failed compilation.
145
+ # Also sets access and modification times back to
146
+ # those specified by st (a stat struct).
147
+ if not is_cython_generated_file(path, allow_failed=True, if_not_found=False):
148
+ return
149
+
150
+ try:
151
+ f = open_new_file(path)
152
+ except OSError:
153
+ pass
154
+ else:
155
+ f.write(
156
+ "#error Do not use this file, it is the result of a failed Cython compilation.\n")
157
+ f.close()
158
+ if st:
159
+ os.utime(path, (st.st_atime, st.st_mtime-1))
160
+
161
+
162
+ def is_cython_generated_file(path, allow_failed=False, if_not_found=True):
163
+ failure_marker = b"#error Do not use this file, it is the result of a failed Cython compilation."
164
+ file_content = None
165
+ if os.path.exists(path):
166
+ try:
167
+ with open(path, "rb") as f:
168
+ file_content = f.read(len(failure_marker))
169
+ except OSError:
170
+ pass # Probably just doesn't exist any more
171
+
172
+ if file_content is None:
173
+ # file does not exist (yet)
174
+ return if_not_found
175
+
176
+ return (
177
+ # Cython C file?
178
+ file_content.startswith(b"/* Generated by Cython ") or
179
+ # Cython output file after previous failures?
180
+ (allow_failed and file_content == failure_marker) or
181
+ # Let's allow overwriting empty files as well. They might have resulted from previous failures.
182
+ not file_content
183
+ )
184
+
185
+
186
+ def file_generated_by_this_cython(path):
187
+ file_content = b''
188
+ if os.path.exists(path):
189
+ try:
190
+ with open(path, "rb") as f:
191
+ file_content = f.read(len(GENERATED_BY_MARKER_BYTES))
192
+ except OSError:
193
+ pass # Probably just doesn't exist any more
194
+ return file_content and file_content.startswith(GENERATED_BY_MARKER_BYTES)
195
+
196
+
197
+ def file_newer_than(path, time):
198
+ ftime = modification_time(path)
199
+ return ftime > time
200
+
201
+
202
+ def copy_file_to_dir_if_newer(sourcefile, destdir):
203
+ """
204
+ Copy file sourcefile to directory destdir (creating it if needed),
205
+ preserving metadata. If the destination file exists and is not
206
+ older than the source file, the copying is skipped.
207
+ """
208
+ destfile = os.path.join(destdir, os.path.basename(sourcefile))
209
+ try:
210
+ desttime = modification_time(destfile)
211
+ except OSError:
212
+ # New file does not exist, destdir may or may not exist
213
+ os.makedirs(destdir, exist_ok=True)
214
+ else:
215
+ # New file already exists
216
+ if not file_newer_than(sourcefile, desttime):
217
+ return
218
+ shutil.copy2(sourcefile, destfile)
219
+
220
+
221
+ @cached_function
222
+ def find_root_package_dir(file_path):
223
+ dir = os.path.dirname(file_path)
224
+ if file_path == dir:
225
+ return dir
226
+ elif is_package_dir(dir):
227
+ return find_root_package_dir(dir)
228
+ else:
229
+ return dir
230
+
231
+
232
+ @cached_function
233
+ def check_package_dir(dir_path, package_names):
234
+ namespace = True
235
+ for dirname in package_names:
236
+ dir_path = os.path.join(dir_path, dirname)
237
+ has_init = contains_init(dir_path)
238
+ if has_init:
239
+ namespace = False
240
+ return dir_path, namespace
241
+
242
+
243
+ @cached_function
244
+ def contains_init(dir_path):
245
+ for filename in PACKAGE_FILES:
246
+ path = os.path.join(dir_path, filename)
247
+ if path_exists(path):
248
+ return 1
249
+
250
+
251
+ def is_package_dir(dir_path):
252
+ if contains_init(dir_path):
253
+ return 1
254
+
255
+
256
+ @cached_function
257
+ def path_exists(path):
258
+ # try on the filesystem first
259
+ if os.path.exists(path):
260
+ return True
261
+ # figure out if a PEP 302 loader is around
262
+ try:
263
+ loader = __loader__
264
+ # XXX the code below assumes a 'zipimport.zipimporter' instance
265
+ # XXX should be easy to generalize, but too lazy right now to write it
266
+ archive_path = getattr(loader, 'archive', None)
267
+ if archive_path:
268
+ normpath = os.path.normpath(path)
269
+ if normpath.startswith(archive_path):
270
+ arcname = normpath[len(archive_path)+1:]
271
+ try:
272
+ loader.get_data(arcname)
273
+ return True
274
+ except OSError:
275
+ return False
276
+ except NameError:
277
+ pass
278
+ return False
279
+
280
+
281
+ _parse_file_version = re.compile(r".*[.]cython-([0-9]+)[.][^./\\]+$").findall
282
+
283
+
284
+ @cached_function
285
+ def find_versioned_file(directory, filename, suffix,
286
+ _current_version=int(re.sub(r"^([0-9]+)[.]([0-9]+).*", r"\1\2", cython_version))):
287
+ """
288
+ Search a directory for versioned pxd files, e.g. "lib.cython-30.pxd" for a Cython 3.0+ version.
289
+
290
+ @param directory: the directory to search
291
+ @param filename: the filename without suffix
292
+ @param suffix: the filename extension including the dot, e.g. ".pxd"
293
+ @return: the file path if found, or None
294
+ """
295
+ assert not suffix or suffix[:1] == '.'
296
+ path_prefix = os.path.join(directory, filename)
297
+
298
+ matching_files = glob.glob(glob.escape(path_prefix) + ".cython-*" + suffix)
299
+ path = path_prefix + suffix
300
+ if not os.path.exists(path):
301
+ path = None
302
+ best_match = (-1, path) # last resort, if we do not have versioned .pxd files
303
+
304
+ for path in matching_files:
305
+ versions = _parse_file_version(path)
306
+ if versions:
307
+ int_version = int(versions[0])
308
+ # Let's assume no duplicates.
309
+ if best_match[0] < int_version <= _current_version:
310
+ best_match = (int_version, path)
311
+ return best_match[1]
312
+
313
+
314
+ # file name encodings
315
+
316
+ def decode_filename(filename):
317
+ if isinstance(filename, bytes):
318
+ try:
319
+ filename_encoding = sys.getfilesystemencoding()
320
+ if filename_encoding is None:
321
+ filename_encoding = sys.getdefaultencoding()
322
+ filename = filename.decode(filename_encoding)
323
+ except UnicodeDecodeError:
324
+ pass
325
+ return filename
326
+
327
+
328
+ # support for source file encoding detection
329
+
330
+ _match_non_comment_line = re.compile(br"\s*[^\s#]").match
331
+ _match_file_encoding = re.compile(br"(\w*coding)[:=]\s*([-\w.]+)").search
332
+
333
+
334
+ def detect_opened_file_encoding(f, default='UTF-8'):
335
+ # PEPs 263 and 3120
336
+ # Most of the time the first two lines fall in the first couple of hundred chars,
337
+ # and this bulk read/split is much faster.
338
+ lines = ()
339
+ start = b''
340
+ while len(lines) < 3:
341
+ data = f.read(500)
342
+ start += data
343
+ lines = start.split(b"\n")
344
+ if not data:
345
+ break
346
+
347
+ for line in lines[:2]:
348
+ m = _match_non_comment_line(line)
349
+ if m:
350
+ return default
351
+ m = _match_file_encoding(line)
352
+ if not m:
353
+ continue
354
+ if m.group(1) == b'c_string_encoding':
355
+ from .Compiler.Errors import warning
356
+ warning(
357
+ None,
358
+ "c_string_encoding in the first two lines of a file is interpreted as a directive "
359
+ "in Cython and a source file-encoding in Python", 2)
360
+ continue
361
+ return m.group(2).decode('iso8859-1')
362
+ return default
363
+
364
+
365
+ def skip_bom(f):
366
+ """
367
+ Read past a BOM at the beginning of a source file.
368
+ This could be added to the scanner, but it's *substantially* easier
369
+ to keep it at this level.
370
+ """
371
+ if f.read(1) != '\uFEFF':
372
+ f.seek(0)
373
+
374
+
375
+ def open_source_file(source_filename, encoding=None, error_handling=None):
376
+ stream = None
377
+ try:
378
+ if encoding is None:
379
+ # Most of the time the encoding is not specified, so try hard to open the file only once.
380
+ f = open(source_filename, 'rb')
381
+ encoding = detect_opened_file_encoding(f)
382
+ f.seek(0)
383
+ stream = io.TextIOWrapper(f, encoding=encoding, errors=error_handling)
384
+ else:
385
+ stream = open(source_filename, encoding=encoding, errors=error_handling)
386
+
387
+ except OSError:
388
+ if os.path.exists(source_filename):
389
+ raise # File is there, but something went wrong reading from it.
390
+ # Allow source files to be in zip files etc.
391
+ try:
392
+ loader = __loader__
393
+ if source_filename.startswith(loader.archive):
394
+ stream = open_source_from_loader(
395
+ loader, source_filename,
396
+ encoding, error_handling)
397
+ except (NameError, AttributeError):
398
+ pass
399
+
400
+ if stream is None:
401
+ raise FileNotFoundError(source_filename)
402
+ skip_bom(stream)
403
+ return stream
404
+
405
+
406
+ def open_source_from_loader(loader,
407
+ source_filename,
408
+ encoding=None, error_handling=None):
409
+ nrmpath = os.path.normpath(source_filename)
410
+ arcname = nrmpath[len(loader.archive)+1:]
411
+ data = loader.get_data(arcname)
412
+ return io.TextIOWrapper(io.BytesIO(data),
413
+ encoding=encoding,
414
+ errors=error_handling)
415
+
416
+
417
+ def str_to_number(value):
418
+ # note: this expects a string as input that was accepted by the
419
+ # parser already, with an optional "-" sign in front
420
+ is_neg = False
421
+ if value[:1] == '-':
422
+ is_neg = True
423
+ value = value[1:]
424
+ if len(value) < 2:
425
+ value = int(value, 0)
426
+ elif value[0] == '0':
427
+ literal_type = value[1] # 0'o' - 0'b' - 0'x'
428
+ if literal_type in 'xX':
429
+ # hex notation ('0x1AF')
430
+ value = strip_py2_long_suffix(value)
431
+ value = int(value[2:], 16)
432
+ elif literal_type in 'oO':
433
+ # Py3 octal notation ('0o136')
434
+ value = int(value[2:], 8)
435
+ elif literal_type in 'bB':
436
+ # Py3 binary notation ('0b101')
437
+ value = int(value[2:], 2)
438
+ else:
439
+ # Py2 octal notation ('0136')
440
+ value = int(value, 8)
441
+ else:
442
+ value = int(value, 0)
443
+ return -value if is_neg else value
444
+
445
+
446
+ def strip_py2_long_suffix(value_str):
447
+ """
448
+ Python 2 likes to append 'L' to stringified numbers
449
+ which in then can't process when converting them to numbers.
450
+ """
451
+ if value_str[-1] in 'lL':
452
+ return value_str[:-1]
453
+ return value_str
454
+
455
+
456
+ def long_literal(value):
457
+ if isinstance(value, str):
458
+ value = str_to_number(value)
459
+ return not -2**31 <= value < 2**31
460
+
461
+
462
+ @try_finally_contextmanager
463
+ def captured_fd(stream=2, encoding=None):
464
+ orig_stream = os.dup(stream) # keep copy of original stream
465
+ try:
466
+ with tempfile.TemporaryFile(mode="a+b") as temp_file:
467
+ def read_output(_output=[b'']):
468
+ if not temp_file.closed:
469
+ temp_file.seek(0)
470
+ _output[0] = temp_file.read()
471
+ return _output[0]
472
+
473
+ os.dup2(temp_file.fileno(), stream) # replace stream by copy of pipe
474
+ def get_output():
475
+ result = read_output()
476
+ return result.decode(encoding) if encoding else result
477
+
478
+ yield get_output
479
+ # note: @contextlib.contextmanager requires try-finally here
480
+ os.dup2(orig_stream, stream) # restore original stream
481
+ read_output() # keep the output in case it's used after closing the context manager
482
+ finally:
483
+ os.close(orig_stream)
484
+
485
+
486
+ def get_encoding_candidates():
487
+ candidates = [sys.getdefaultencoding()]
488
+ for stream in (sys.stdout, sys.stdin, sys.__stdout__, sys.__stdin__):
489
+ encoding = getattr(stream, 'encoding', None)
490
+ # encoding might be None (e.g. somebody redirects stdout):
491
+ if encoding is not None and encoding not in candidates:
492
+ candidates.append(encoding)
493
+ return candidates
494
+
495
+
496
+ def prepare_captured(captured):
497
+ captured_bytes = captured.strip()
498
+ if not captured_bytes:
499
+ return None
500
+ for encoding in get_encoding_candidates():
501
+ try:
502
+ return captured_bytes.decode(encoding)
503
+ except UnicodeDecodeError:
504
+ pass
505
+ # last resort: print at least the readable ascii parts correctly.
506
+ return captured_bytes.decode('latin-1')
507
+
508
+
509
+ def print_captured(captured, output, header_line=None):
510
+ captured = prepare_captured(captured)
511
+ if captured:
512
+ if header_line:
513
+ output.write(header_line)
514
+ output.write(captured)
515
+
516
+
517
+ def print_bytes(s, header_text=None, end=b'\n', file=sys.stdout, flush=True):
518
+ if header_text:
519
+ file.write(header_text) # note: text! => file.write() instead of out.write()
520
+ file.flush()
521
+ out = file.buffer
522
+ out.write(s)
523
+ if end:
524
+ out.write(end)
525
+ if flush:
526
+ out.flush()
527
+
528
+
529
+ class OrderedSet:
530
+ def __init__(self, elements=()):
531
+ self._list = []
532
+ self._set = set()
533
+ self.update(elements)
534
+
535
+ def __iter__(self):
536
+ return iter(self._list)
537
+
538
+ def update(self, elements):
539
+ for e in elements:
540
+ self.add(e)
541
+
542
+ def add(self, e):
543
+ if e not in self._set:
544
+ self._list.append(e)
545
+ self._set.add(e)
546
+
547
+ def __bool__(self):
548
+ return bool(self._set)
549
+
550
+ __nonzero__ = __bool__
551
+
552
+
553
+ def set_dedup(it):
554
+ """Deduplicate the items in an iterable using a set.
555
+ """
556
+ seen = set()
557
+ for item in it:
558
+ if item not in seen:
559
+ seen.add(item)
560
+ yield item
561
+
562
+
563
+ # Class decorator that adds a metaclass and recreates the class with it.
564
+ # Copied from 'six'.
565
+ def add_metaclass(metaclass):
566
+ """Class decorator for creating a class with a metaclass."""
567
+ def wrapper(cls):
568
+ orig_vars = cls.__dict__.copy()
569
+ slots = orig_vars.get('__slots__')
570
+ if slots is not None:
571
+ if isinstance(slots, str):
572
+ slots = [slots]
573
+ for slots_var in slots:
574
+ orig_vars.pop(slots_var)
575
+ orig_vars.pop('__dict__', None)
576
+ orig_vars.pop('__weakref__', None)
577
+ return metaclass(cls.__name__, cls.__bases__, orig_vars)
578
+ return wrapper
579
+
580
+
581
+ def raise_error_if_module_name_forbidden(full_module_name):
582
+ # it is bad idea to call the pyx-file cython.pyx, so fail early
583
+ if full_module_name == 'cython' or full_module_name.startswith('cython.'):
584
+ raise ValueError('cython is a special module, cannot be used as a module name')
585
+
586
+
587
+ def build_hex_version(version_string):
588
+ """
589
+ Parse and translate public version identifier like '4.3a1' into the readable hex representation '0x040300A1' (like PY_VERSION_HEX).
590
+
591
+ SEE: https://peps.python.org/pep-0440/#public-version-identifiers
592
+ """
593
+ # Parse '4.12a1' into [4, 12, 0, 0xA01]
594
+ # And ignore .dev, .pre and .post segments
595
+ digits = []
596
+ release_status = 0xF0
597
+ for segment in re.split(r'(\D+)', version_string):
598
+ if segment in ('a', 'b', 'rc'):
599
+ release_status = {'a': 0xA0, 'b': 0xB0, 'rc': 0xC0}[segment]
600
+ digits = (digits + [0, 0])[:3] # 1.2a1 -> 1.2.0a1
601
+ elif segment in ('.dev', '.pre', '.post'):
602
+ break # break since those are the last segments
603
+ elif segment != '.':
604
+ digits.append(int(segment))
605
+
606
+ digits = (digits + [0] * 3)[:4]
607
+ digits[3] += release_status
608
+
609
+ # Then, build a single hex value, two hex digits per version part.
610
+ hexversion = 0
611
+ for digit in digits:
612
+ hexversion = (hexversion << 8) + digit
613
+
614
+ return '0x%08X' % hexversion
615
+
616
+
617
+ def write_depfile(target, source, dependencies):
618
+ src_base_dir = os.path.dirname(source)
619
+ cwd = os.getcwd()
620
+ if not src_base_dir.endswith(os.sep):
621
+ src_base_dir += os.sep
622
+ # paths below the base_dir are relative, otherwise absolute
623
+ paths = []
624
+ for fname in dependencies:
625
+ try:
626
+ newpath = os.path.relpath(fname, cwd)
627
+ except ValueError:
628
+ # if they are on different Windows drives, absolute is fine
629
+ newpath = os.path.abspath(fname)
630
+
631
+ # Escape spaces
632
+ newpath = newpath.replace(" ", "\\ ")
633
+ paths.append(newpath)
634
+
635
+ depline = os.path.relpath(target, cwd) + ": \\\n "
636
+ depline += " \\\n ".join(paths) + "\n"
637
+
638
+ with open(target+'.dep', 'w') as outfile:
639
+ outfile.write(depline)
640
+
641
+
642
+ def print_version():
643
+ print("Cython version %s" % cython_version)
644
+ # For legacy reasons, we also write the version to stderr.
645
+ # New tools should expect it in stdout, but existing ones still pipe from stderr, or from both.
646
+ if sys.stderr.isatty() or sys.stdout == sys.stderr:
647
+ return
648
+ if os.fstat(1) == os.fstat(2):
649
+ # This is somewhat unsafe since sys.stdout/err might not really be linked to streams 1/2.
650
+ # However, in most *relevant* cases, where Cython is run as an external tool, they are linked.
651
+ return
652
+ sys.stderr.write("Cython version %s\n" % cython_version)
653
+
654
+
655
+ def normalise_float_repr(float_str):
656
+ """
657
+ Generate a 'normalised', simple digits string representation of a float value
658
+ to allow string comparisons. Examples: '.123', '123.456', '123.'
659
+ """
660
+ str_value = float_str.lower().lstrip('0')
661
+
662
+ exp = 0
663
+ if 'E' in str_value or 'e' in str_value:
664
+ str_value, exp = str_value.split('E' if 'E' in str_value else 'e', 1)
665
+ exp = int(exp)
666
+
667
+ if '.' in str_value:
668
+ num_int_digits = str_value.index('.')
669
+ str_value = str_value[:num_int_digits] + str_value[num_int_digits + 1:]
670
+ else:
671
+ num_int_digits = len(str_value)
672
+ exp += num_int_digits
673
+
674
+ result = (
675
+ str_value[:exp]
676
+ + '0' * (exp - len(str_value))
677
+ + '.'
678
+ + '0' * -exp
679
+ + str_value[exp:]
680
+ ).rstrip('0')
681
+
682
+ return result if result != '.' else '.0'
Cython/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ from typing import Any
2
+
3
+ from .Shadow import __version__
4
+
5
+ # Void cython.* directives (for case insensitive operating systems).
6
+ from .Shadow import *
7
+
8
+
9
+ def load_ipython_extension(ip: Any) -> None:
10
+ """Load the extension in IPython."""
11
+ from .Build.IpythonMagic import CythonMagics # pylint: disable=cyclic-import
12
+ ip.register_magics(CythonMagics)
Cython/py.typed ADDED
File without changes