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.
- Cython/Build/BuildExecutable.py +156 -0
- Cython/Build/Cache.py +198 -0
- Cython/Build/Cythonize.py +349 -0
- Cython/Build/Dependencies.py +1320 -0
- Cython/Build/Distutils.py +1 -0
- Cython/Build/Inline.py +467 -0
- Cython/Build/IpythonMagic.py +559 -0
- Cython/Build/SharedModule.py +165 -0
- Cython/Build/Tests/TestCyCache.py +222 -0
- Cython/Build/Tests/TestCythonizeArgsParser.py +480 -0
- Cython/Build/Tests/TestDependencies.py +133 -0
- Cython/Build/Tests/TestInline.py +177 -0
- Cython/Build/Tests/TestIpythonMagic.py +303 -0
- Cython/Build/Tests/TestRecythonize.py +212 -0
- Cython/Build/Tests/TestStripLiterals.py +155 -0
- Cython/Build/Tests/__init__.py +1 -0
- Cython/Build/__init__.py +11 -0
- Cython/CodeWriter.py +825 -0
- Cython/Compiler/AnalysedTreeTransforms.py +97 -0
- Cython/Compiler/Annotate.py +328 -0
- Cython/Compiler/AutoDocTransforms.py +320 -0
- Cython/Compiler/Buffer.py +679 -0
- Cython/Compiler/Builtin.py +1102 -0
- Cython/Compiler/CmdLine.py +373 -0
- Cython/Compiler/Code.pxd +154 -0
- Cython/Compiler/Code.py +3760 -0
- Cython/Compiler/CodeGeneration.py +33 -0
- Cython/Compiler/CythonScope.py +208 -0
- Cython/Compiler/Dataclass.py +890 -0
- Cython/Compiler/DebugFlags.py +24 -0
- Cython/Compiler/Errors.py +310 -0
- Cython/Compiler/ExprNodes.py +16319 -0
- Cython/Compiler/FlowControl.pxd +112 -0
- Cython/Compiler/FlowControl.py +1575 -0
- Cython/Compiler/FusedNode.py +978 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +442 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/Main.py +879 -0
- Cython/Compiler/MatchCaseNodes.py +2200 -0
- Cython/Compiler/MemoryView.py +930 -0
- Cython/Compiler/ModuleNode.py +4558 -0
- Cython/Compiler/Naming.py +370 -0
- Cython/Compiler/Nodes.py +11334 -0
- Cython/Compiler/Optimize.py +5563 -0
- Cython/Compiler/Options.py +841 -0
- Cython/Compiler/ParseTreeTransforms.pxd +80 -0
- Cython/Compiler/ParseTreeTransforms.py +4808 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +5442 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +6588 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +74 -0
- Cython/Compiler/Scanning.py +771 -0
- Cython/Compiler/StringEncoding.py +354 -0
- Cython/Compiler/Symtab.py +3122 -0
- Cython/Compiler/Tests/TestBuffer.py +105 -0
- Cython/Compiler/Tests/TestBuiltin.py +196 -0
- Cython/Compiler/Tests/TestCmdLine.py +652 -0
- Cython/Compiler/Tests/TestCode.py +145 -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 +132 -0
- Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
- Cython/Compiler/Tests/TestStringEncoding.py +20 -0
- Cython/Compiler/Tests/TestTreeFragment.py +63 -0
- Cython/Compiler/Tests/TestTreePath.py +103 -0
- Cython/Compiler/Tests/TestTypes.py +119 -0
- Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
- Cython/Compiler/Tests/TestVisitor.py +119 -0
- Cython/Compiler/Tests/Utils.py +36 -0
- Cython/Compiler/Tests/__init__.py +1 -0
- Cython/Compiler/TreeFragment.py +279 -0
- Cython/Compiler/TreePath.py +303 -0
- Cython/Compiler/TypeInference.py +626 -0
- Cython/Compiler/TypeSlots.py +1330 -0
- Cython/Compiler/UFuncs.py +317 -0
- Cython/Compiler/UtilNodes.py +389 -0
- Cython/Compiler/UtilityCode.py +354 -0
- Cython/Compiler/Version.py +8 -0
- Cython/Compiler/Visitor.pxd +52 -0
- Cython/Compiler/Visitor.py +914 -0
- Cython/Compiler/__init__.py +1 -0
- Cython/Coverage.py +448 -0
- Cython/Debugger/Cygdb.py +214 -0
- Cython/Debugger/DebugWriter.py +82 -0
- Cython/Debugger/Tests/TestLibCython.py +280 -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 +580 -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 +143 -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 +159 -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 +268 -0
- Cython/Includes/cpython/exc.pxd +263 -0
- Cython/Includes/cpython/fileobject.pxd +57 -0
- Cython/Includes/cpython/float.pxd +56 -0
- Cython/Includes/cpython/frozendict.pxd +37 -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 +144 -0
- Cython/Includes/cpython/long.pxd +180 -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 +430 -0
- Cython/Includes/cpython/pycapsule.pxd +143 -0
- Cython/Includes/cpython/pylifecycle.pxd +68 -0
- Cython/Includes/cpython/pyport.pxd +8 -0
- Cython/Includes/cpython/pystate.pxd +95 -0
- Cython/Includes/cpython/pythread.pxd +53 -0
- Cython/Includes/cpython/ref.pxd +141 -0
- Cython/Includes/cpython/sentinel.pxd +17 -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 +146 -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/stdbool.pxd +5 -0
- Cython/Includes/libc/stddef.pxd +9 -0
- Cython/Includes/libc/stdint.pxd +105 -0
- Cython/Includes/libc/stdio.pxd +80 -0
- Cython/Includes/libc/stdlib.pxd +72 -0
- Cython/Includes/libc/string.pxd +50 -0
- Cython/Includes/libc/threads.pxd +234 -0
- Cython/Includes/libc/time.pxd +52 -0
- Cython/Includes/libcpp/__init__.pxd +4 -0
- Cython/Includes/libcpp/algorithm.pxd +320 -0
- Cython/Includes/libcpp/any.pxd +16 -0
- Cython/Includes/libcpp/atomic.pxd +59 -0
- Cython/Includes/libcpp/barrier.pxd +22 -0
- Cython/Includes/libcpp/bit.pxd +29 -0
- Cython/Includes/libcpp/cast.pxd +12 -0
- Cython/Includes/libcpp/cmath.pxd +518 -0
- Cython/Includes/libcpp/complex.pxd +106 -0
- Cython/Includes/libcpp/condition_variable.pxd +322 -0
- Cython/Includes/libcpp/deque.pxd +165 -0
- Cython/Includes/libcpp/exception.pxd +216 -0
- Cython/Includes/libcpp/execution.pxd +15 -0
- Cython/Includes/libcpp/forward_list.pxd +63 -0
- Cython/Includes/libcpp/functional.pxd +26 -0
- Cython/Includes/libcpp/future.pxd +103 -0
- Cython/Includes/libcpp/iterator.pxd +34 -0
- Cython/Includes/libcpp/latch.pxd +17 -0
- Cython/Includes/libcpp/limits.pxd +61 -0
- Cython/Includes/libcpp/list.pxd +117 -0
- Cython/Includes/libcpp/map.pxd +252 -0
- Cython/Includes/libcpp/memory.pxd +115 -0
- Cython/Includes/libcpp/mutex.pxd +387 -0
- Cython/Includes/libcpp/numbers.pxd +15 -0
- Cython/Includes/libcpp/numeric.pxd +131 -0
- Cython/Includes/libcpp/optional.pxd +34 -0
- Cython/Includes/libcpp/pair.pxd +1 -0
- Cython/Includes/libcpp/queue.pxd +25 -0
- Cython/Includes/libcpp/random.pxd +166 -0
- Cython/Includes/libcpp/semaphore.pxd +43 -0
- Cython/Includes/libcpp/set.pxd +228 -0
- Cython/Includes/libcpp/shared_mutex.pxd +96 -0
- Cython/Includes/libcpp/span.pxd +87 -0
- Cython/Includes/libcpp/stack.pxd +11 -0
- Cython/Includes/libcpp/stop_token.pxd +117 -0
- Cython/Includes/libcpp/string.pxd +355 -0
- Cython/Includes/libcpp/string_view.pxd +183 -0
- Cython/Includes/libcpp/typeindex.pxd +15 -0
- Cython/Includes/libcpp/typeinfo.pxd +10 -0
- Cython/Includes/libcpp/unordered_map.pxd +193 -0
- Cython/Includes/libcpp/unordered_set.pxd +152 -0
- Cython/Includes/libcpp/utility.pxd +30 -0
- Cython/Includes/libcpp/vector.pxd +186 -0
- Cython/Includes/numpy/math.pxd +150 -0
- Cython/Includes/openmp.pxd +50 -0
- Cython/Includes/posix/__init__.pxd +1 -0
- Cython/Includes/posix/dlfcn.pxd +14 -0
- Cython/Includes/posix/fcntl.pxd +86 -0
- Cython/Includes/posix/ioctl.pxd +4 -0
- Cython/Includes/posix/mman.pxd +101 -0
- Cython/Includes/posix/resource.pxd +57 -0
- Cython/Includes/posix/select.pxd +21 -0
- Cython/Includes/posix/signal.pxd +73 -0
- Cython/Includes/posix/stat.pxd +98 -0
- Cython/Includes/posix/stdio.pxd +37 -0
- Cython/Includes/posix/stdlib.pxd +29 -0
- Cython/Includes/posix/strings.pxd +9 -0
- Cython/Includes/posix/time.pxd +71 -0
- Cython/Includes/posix/types.pxd +30 -0
- Cython/Includes/posix/uio.pxd +26 -0
- Cython/Includes/posix/unistd.pxd +271 -0
- Cython/Includes/posix/wait.pxd +38 -0
- Cython/LZSS.py +184 -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 +535 -0
- Cython/Plex/Scanners.pxd +45 -0
- Cython/Plex/Scanners.py +328 -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 +1172 -0
- Cython/StringIOTree.py +169 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -0
- Cython/Tempita/_tempita.py +1087 -0
- Cython/TestUtils.py +472 -0
- Cython/Tests/TestCodeWriter.py +128 -0
- Cython/Tests/TestCythonUtils.py +237 -0
- Cython/Tests/TestJediTyper.py +223 -0
- Cython/Tests/TestShadow.py +125 -0
- Cython/Tests/TestStringIOTree.py +68 -0
- Cython/Tests/TestTestUtils.py +89 -0
- Cython/Tests/__init__.py +1 -0
- Cython/Tests/xmlrunner.py +390 -0
- Cython/Utility/AsyncGen.c +1152 -0
- Cython/Utility/Buffer.c +866 -0
- Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
- Cython/Utility/Builtins.c +1068 -0
- Cython/Utility/CConvert.pyx +153 -0
- Cython/Utility/CMath.c +104 -0
- Cython/Utility/CommonStructures.c +244 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2344 -0
- Cython/Utility/CpdefEnums.pyx +119 -0
- Cython/Utility/CppConvert.pyx +284 -0
- Cython/Utility/CppSupport.cpp +151 -0
- Cython/Utility/CythonFunction.c +2143 -0
- Cython/Utility/Dataclasses.c +101 -0
- Cython/Utility/Embed.c +129 -0
- Cython/Utility/Exceptions.c +1331 -0
- Cython/Utility/Exceptions_Cy.pyx +109 -0
- Cython/Utility/ExtensionTypes.c +1199 -0
- Cython/Utility/FunctionArguments.c +1052 -0
- Cython/Utility/FusedFunction.pyx +44 -0
- Cython/Utility/ImportExport.c +972 -0
- Cython/Utility/MatchCase.c +985 -0
- Cython/Utility/MatchCase_Cy.pyx +12 -0
- Cython/Utility/MemoryView.pxd +108 -0
- Cython/Utility/MemoryView.pyx +1499 -0
- Cython/Utility/MemoryView_C.c +1056 -0
- Cython/Utility/ModuleSetupCode.c +3349 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3404 -0
- Cython/Utility/Optimize.c +2575 -0
- Cython/Utility/Overflow.c +378 -0
- Cython/Utility/Profile.c +736 -0
- Cython/Utility/StringTools.c +1534 -0
- Cython/Utility/Synchronization.c +438 -0
- Cython/Utility/TString.c +369 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1588 -0
- Cython/Utility/UFuncs.pyx +50 -0
- Cython/Utility/UFuncs_C.c +89 -0
- Cython/Utility/__init__.py +28 -0
- Cython/Utility/arrayarray.h +190 -0
- Cython/Utils.py +682 -0
- Cython/__init__.py +12 -0
- Cython/py.typed +0 -0
- cython.py +29 -0
- oxython-0.1.0.dist-info/METADATA +138 -0
- oxython-0.1.0.dist-info/RECORD +321 -0
- oxython-0.1.0.dist-info/WHEEL +5 -0
- oxython-0.1.0.dist-info/entry_points.txt +4 -0
- oxython-0.1.0.dist-info/top_level.txt +3 -0
- pyximport/__init__.py +4 -0
- pyximport/pyxbuild.py +160 -0
- pyximport/pyximport.py +482 -0
Cython/Utility/TString.c
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
//////////////////////////// InitializeTemplateLib.module_state_decls /////////////////////
|
|
2
|
+
//@requires: Synchronization.c::Atomics
|
|
3
|
+
|
|
4
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
5
|
+
__pyx_atomic_ptr_type __pyx_templatelib_Template;
|
|
6
|
+
__pyx_atomic_ptr_type __pyx_templatelib_Interpolation;
|
|
7
|
+
#else
|
|
8
|
+
// If freethreading but not atomics then this is unguarded
|
|
9
|
+
PyObject *__pyx_templatelib_Template;
|
|
10
|
+
PyObject *__pyx_templatelib_Interpolation;
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
//////////////////////////// InitializeTemplateLib.module_state_traverse ////////////////////////////
|
|
14
|
+
|
|
15
|
+
Py_VISIT((PyObject*)traverse_module_state->__pyx_templatelib_Template);
|
|
16
|
+
Py_VISIT((PyObject*)traverse_module_state->__pyx_templatelib_Interpolation);
|
|
17
|
+
|
|
18
|
+
//////////////////////////// InitializeTemplateLib.module_state_clear ////////////////////////////
|
|
19
|
+
|
|
20
|
+
Py_XDECREF((PyObject*)clear_module_state->__pyx_templatelib_Template);
|
|
21
|
+
clear_module_state->__pyx_templatelib_Template = 0;
|
|
22
|
+
Py_XDECREF((PyObject*)clear_module_state->__pyx_templatelib_Interpolation);
|
|
23
|
+
clear_module_state->__pyx_templatelib_Interpolation = 0;
|
|
24
|
+
|
|
25
|
+
//////////////////////////// InitializeTemplateLib.proto ///////////////////////////
|
|
26
|
+
|
|
27
|
+
// Returns Template if template, else Interpolation
|
|
28
|
+
static PyObject* __Pyx__GetObjectFromTemplateLib(int is_template); /* proto */
|
|
29
|
+
|
|
30
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && !CYTHON_ATOMICS
|
|
31
|
+
static PyObject* __Pyx_GetObjectFromTemplateLib(int is_template); /* proto */
|
|
32
|
+
#else
|
|
33
|
+
#define __Pyx_GetObjectFromTemplateLib __Pyx__GetObjectFromTemplateLib
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
//////////////////////////// InitializeTemplateLib ///////////////////////////
|
|
38
|
+
//@requires: Exceptions.c::IgnoreException
|
|
39
|
+
|
|
40
|
+
#if __PYX_LIMITED_VERSION_HEX < 0x030E0000
|
|
41
|
+
static PyObject *__Pyx_TemplateLibFallback(void) {
|
|
42
|
+
if (!__Pyx_IgnoreException(PyExc_Exception)) {
|
|
43
|
+
return NULL; // BaseException
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The assumption here is that Interpolation and Template are fairly simple classes
|
|
47
|
+
// and the cost of compiling them with Cython (for all Python versions) is probably
|
|
48
|
+
// higher than the cost of using a plain-Python fallback.
|
|
49
|
+
const char code_str[] = CSTRING("""
|
|
50
|
+
class Interpolation:
|
|
51
|
+
__module__ = 'string.templatelib'
|
|
52
|
+
__slots__ = __match_args__ = ('value', 'expression', 'conversion', 'format_spec')
|
|
53
|
+
def __setattr__(self, attr, value):
|
|
54
|
+
raise AttributeError('Interpolation is immutable')
|
|
55
|
+
def __new__(cls, value, expression='', conversion=None, format_spec=''):
|
|
56
|
+
obj = super().__new__(cls)
|
|
57
|
+
super().__setattr__(obj, 'value', value)
|
|
58
|
+
super().__setattr__(obj, 'expression', expression)
|
|
59
|
+
super().__setattr__(obj, 'conversion', conversion)
|
|
60
|
+
super().__setattr__(obj, 'format_spec', format_spec)
|
|
61
|
+
return obj
|
|
62
|
+
def __repr__(self):
|
|
63
|
+
return f'Interpolation({self.value!r}, {self.expression!r}, {self.conversion!r}, {self.format_spec!r})'
|
|
64
|
+
def __reduce__(self):
|
|
65
|
+
# This probably won't work unless a t-string has already been created from Cython
|
|
66
|
+
return (type(self), (self.value, self.expression, self.conversion, self.format_spec))
|
|
67
|
+
def __init_subclass__(cls, **kwds):
|
|
68
|
+
raise TypeError('Interpolation is not an acceptable base type')
|
|
69
|
+
class Template:
|
|
70
|
+
__module__ = 'string.templatelib'
|
|
71
|
+
__slots__ = ('strings', 'interpolations')
|
|
72
|
+
def __setattr__(self, attr, value):
|
|
73
|
+
raise AttributeError('Template is immutable')
|
|
74
|
+
def __new__(cls, *args, strings=None, interpolations=None):
|
|
75
|
+
if strings is None and interpolations is None:
|
|
76
|
+
strings = []
|
|
77
|
+
interpolations = []
|
|
78
|
+
last_string = ''
|
|
79
|
+
for arg in args:
|
|
80
|
+
if isinstance(arg, str):
|
|
81
|
+
last_string += arg
|
|
82
|
+
elif isinstance(arg, Interpolation):
|
|
83
|
+
strings.append(last_string)
|
|
84
|
+
last_string = ''
|
|
85
|
+
interpolations.append(arg)
|
|
86
|
+
else:
|
|
87
|
+
raise TypeError('Unexpected argument to Template')
|
|
88
|
+
strings.append(last_string)
|
|
89
|
+
else:
|
|
90
|
+
if args:
|
|
91
|
+
raise ValueError("'strings' or 'interpolations' should not be passed with positional arguments")
|
|
92
|
+
if strings is None: strings = ()
|
|
93
|
+
if interpolations is None: interpolations = ()
|
|
94
|
+
obj = super().__new__(cls)
|
|
95
|
+
super().__setattr__(obj, 'strings', tuple(strings))
|
|
96
|
+
super().__setattr__(obj, 'interpolations', tuple(interpolations))
|
|
97
|
+
return obj
|
|
98
|
+
def __repr__(self):
|
|
99
|
+
return f'Template(strings={self.strings!r}, interpolations={self.interpolations!r})'
|
|
100
|
+
def __reduce__(self):
|
|
101
|
+
# This probably won't work unless a t-string has already been created from Cython.
|
|
102
|
+
# It also doesn't quite match how CPython pickles them.
|
|
103
|
+
values = tuple(iter(self))
|
|
104
|
+
return (type(self), values)
|
|
105
|
+
def __iter__(self):
|
|
106
|
+
for n in range(len(self.interpolations)):
|
|
107
|
+
if (s := self.strings[n]):
|
|
108
|
+
yield s
|
|
109
|
+
yield self.interpolations[n]
|
|
110
|
+
if (s := self.strings[-1]):
|
|
111
|
+
yield s
|
|
112
|
+
def __add__(self, other):
|
|
113
|
+
if not (isinstance(self, Template) and isinstance(other, Template)):
|
|
114
|
+
raise TypeError('can only concatenate Template to Template')
|
|
115
|
+
interpolations = self.interpolations + other.interpolations
|
|
116
|
+
middle_string = self.strings[-1] + other.strings[0]
|
|
117
|
+
strings = self.strings[:-1] + (middle_string,) + other.strings[1:]
|
|
118
|
+
return Template(strings=strings, interpolations=interpolations)
|
|
119
|
+
@property
|
|
120
|
+
def values(self):
|
|
121
|
+
return tuple(i.value for i in self.interpolations)
|
|
122
|
+
def __init_subclass__(cls, **kwds):
|
|
123
|
+
raise TypeError('Template is not an acceptable base type')
|
|
124
|
+
""");
|
|
125
|
+
|
|
126
|
+
PyObject *code=NULL, *eval_result=NULL, *module=NULL, *module_dict=NULL;
|
|
127
|
+
PyObject *dict = PyDict_New();
|
|
128
|
+
if (unlikely(!dict)) return NULL;
|
|
129
|
+
#if __PYX_LIMITED_VERSION_HEX < 0x030A0000
|
|
130
|
+
{
|
|
131
|
+
PyObject *builtins = PyEval_GetBuiltins();
|
|
132
|
+
if (unlikely(!builtins)) goto end;
|
|
133
|
+
if (unlikely(PyDict_SetItemString(dict, "__builtins__", builtins) < 0)) goto end;
|
|
134
|
+
}
|
|
135
|
+
#endif
|
|
136
|
+
|
|
137
|
+
code = Py_CompileString(code_str, "<cython string.templatelib fallback>", Py_file_input);
|
|
138
|
+
if (unlikely(!code)) goto end;
|
|
139
|
+
eval_result = PyEval_EvalCode(code, dict, NULL);
|
|
140
|
+
Py_DECREF(code);
|
|
141
|
+
if (unlikely(!eval_result)) goto end;
|
|
142
|
+
Py_DECREF(eval_result);
|
|
143
|
+
|
|
144
|
+
module = __Pyx_PyImport_AddModuleRef("string.templatelib");
|
|
145
|
+
if (!module) goto end;
|
|
146
|
+
module_dict = PyModule_GetDict(module);
|
|
147
|
+
if (!module_dict) goto bad;
|
|
148
|
+
if (unlikely(PyDict_Merge(module_dict, dict, 0) < 0)) goto bad;
|
|
149
|
+
|
|
150
|
+
end:
|
|
151
|
+
Py_XDECREF(dict);
|
|
152
|
+
return module;
|
|
153
|
+
bad:
|
|
154
|
+
Py_CLEAR(module);
|
|
155
|
+
goto end;
|
|
156
|
+
}
|
|
157
|
+
#endif
|
|
158
|
+
|
|
159
|
+
static int __Pyx_InitializeTemplateLib(void) {
|
|
160
|
+
// Even in earlier versions of Python, still try the import. We're happy
|
|
161
|
+
// to use what's there if someone's patched it with something compatible.
|
|
162
|
+
PyObject *templatelib = PyImport_ImportModule("string.templatelib");
|
|
163
|
+
if (!templatelib) {
|
|
164
|
+
#if __PYX_LIMITED_VERSION_HEX < 0x030E0000
|
|
165
|
+
templatelib = __Pyx_TemplateLibFallback();
|
|
166
|
+
if (!templatelib)
|
|
167
|
+
#endif
|
|
168
|
+
return -1;
|
|
169
|
+
}
|
|
170
|
+
PyObject *template_=NULL, *interpolation=NULL;
|
|
171
|
+
int result = -1;
|
|
172
|
+
template_ = PyObject_GetAttrString(templatelib, "Template");
|
|
173
|
+
if (unlikely(!template_)) goto end;
|
|
174
|
+
interpolation = PyObject_GetAttrString(templatelib, "Interpolation");
|
|
175
|
+
if (unlikely(!interpolation)) goto end;
|
|
176
|
+
|
|
177
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
178
|
+
{
|
|
179
|
+
__pyx_nonatomic_ptr_type expected = 0;
|
|
180
|
+
if (!__pyx_atomic_pointer_cmp_exchange(&CGLOBAL(__pyx_templatelib_Template), &expected, (__pyx_nonatomic_ptr_type)template_)) {
|
|
181
|
+
// Already written - that's fine.
|
|
182
|
+
Py_DECREF(template_);
|
|
183
|
+
}
|
|
184
|
+
expected = 0;
|
|
185
|
+
if (!__pyx_atomic_pointer_cmp_exchange(&CGLOBAL(__pyx_templatelib_Interpolation), &expected, (__pyx_nonatomic_ptr_type)interpolation)) {
|
|
186
|
+
// Already written - that's fine.
|
|
187
|
+
Py_DECREF(interpolation);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
#else
|
|
191
|
+
if (unlikely(CGLOBAL(__pyx_templatelib_Template))) {
|
|
192
|
+
Py_DECREF(template_);
|
|
193
|
+
} else {
|
|
194
|
+
CGLOBAL(__pyx_templatelib_Template) = template_;
|
|
195
|
+
}
|
|
196
|
+
if (unlikely(CGLOBAL(__pyx_templatelib_Interpolation))) {
|
|
197
|
+
Py_DECREF(interpolation);
|
|
198
|
+
} else {
|
|
199
|
+
CGLOBAL(__pyx_templatelib_Interpolation) = interpolation;
|
|
200
|
+
}
|
|
201
|
+
#endif
|
|
202
|
+
result = 0;
|
|
203
|
+
|
|
204
|
+
end:
|
|
205
|
+
Py_DECREF(templatelib);
|
|
206
|
+
Py_XDECREF(template_);
|
|
207
|
+
Py_XDECREF(interpolation);
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static PyObject* __Pyx__GetObjectFromTemplateLib(int is_template) {
|
|
212
|
+
PyObject *lookup;
|
|
213
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
214
|
+
__pyx_atomic_ptr_type* ptr;
|
|
215
|
+
#else
|
|
216
|
+
PyObject **ptr;
|
|
217
|
+
#endif
|
|
218
|
+
ptr = is_template ? &CGLOBAL(__pyx_templatelib_Template) : &CGLOBAL(__pyx_templatelib_Interpolation);
|
|
219
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
220
|
+
lookup = (PyObject*)__pyx_atomic_pointer_load_relaxed(ptr);
|
|
221
|
+
#else
|
|
222
|
+
lookup = *ptr;
|
|
223
|
+
#endif
|
|
224
|
+
if (unlikely(!lookup)) {
|
|
225
|
+
if (unlikely(__Pyx_InitializeTemplateLib()) < 0) return NULL;
|
|
226
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
227
|
+
lookup = (PyObject*)__pyx_atomic_pointer_load_acquire(ptr);
|
|
228
|
+
#else
|
|
229
|
+
lookup = *ptr;
|
|
230
|
+
#endif
|
|
231
|
+
}
|
|
232
|
+
Py_XINCREF(lookup);
|
|
233
|
+
return lookup;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && !CYTHON_ATOMICS
|
|
237
|
+
static PyObject* __Pyx_GetObjectFromTemplateLib(int is_template) {
|
|
238
|
+
static PyMutex mutex = {0};
|
|
239
|
+
PyMutex_Lock(&mutex);
|
|
240
|
+
PyObject *result = __Pyx__GetObjectFromTemplateLib(is_template);
|
|
241
|
+
PyMutex_Unlock(&mutex);
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
#endif
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
//////////////////////////// MakeTemplateLibInterpolation.proto //////////////////////
|
|
250
|
+
|
|
251
|
+
static PyObject* __Pyx_MakeTemplateLibInterpolation(PyObject *value, PyObject *expression, PyObject *conversion_char, PyObject *format_spec); /* proto */
|
|
252
|
+
|
|
253
|
+
//////////////////////////// MakeTemplateLibInterpolation ////////////////////////
|
|
254
|
+
//@requires: InitializeTemplateLib
|
|
255
|
+
//@requires: ObjectHandling.c::PyObjectFastCall
|
|
256
|
+
|
|
257
|
+
static PyObject* __Pyx_MakeTemplateLibInterpolation(PyObject *value, PyObject *expression, PyObject *conversion_char, PyObject *format_spec) {
|
|
258
|
+
PyObject *tp = __Pyx_GetObjectFromTemplateLib(0);
|
|
259
|
+
if (unlikely(!tp)) return NULL;
|
|
260
|
+
PyObject *args[] = {value, expression, conversion_char, format_spec};
|
|
261
|
+
|
|
262
|
+
PyObject *result = __Pyx_PyObject_FastCallDict(tp, args, 4, NULL);
|
|
263
|
+
Py_DECREF(tp);
|
|
264
|
+
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
//////////////////////////// MakeTemplateLibTemplate.proto //////////////////////
|
|
269
|
+
|
|
270
|
+
static PyObject* __Pyx_MakeTemplateLibTemplate(PyObject *strings, PyObject *interpolations); /* proto */
|
|
271
|
+
|
|
272
|
+
//////////////////////////// MakeTemplateLibTemplate ////////////////////////
|
|
273
|
+
//@requires: InitializeTemplateLib
|
|
274
|
+
|
|
275
|
+
#if PY_VERSION_HEX >= 0x030E0000 && CYTHON_COMPILING_IN_CPYTHON
|
|
276
|
+
#ifndef Py_BUILD_CORE
|
|
277
|
+
#define Py_BUILD_CORE
|
|
278
|
+
#endif
|
|
279
|
+
#include "internal/pycore_template.h"
|
|
280
|
+
|
|
281
|
+
static PyObject* __Pyx_MakeTemplateLibTemplate(PyObject *strings, PyObject *interpolations) {
|
|
282
|
+
(void)&__Pyx_GetObjectFromTemplateLib;
|
|
283
|
+
return _PyTemplate_Build(strings, interpolations);
|
|
284
|
+
}
|
|
285
|
+
#else
|
|
286
|
+
|
|
287
|
+
static PyObject* __Pyx_MakeTemplateLibTemplate(PyObject *strings, PyObject *interpolations) {
|
|
288
|
+
PyObject *tp = __Pyx_GetObjectFromTemplateLib(1);
|
|
289
|
+
PyObject *result = NULL, *zipped_tuple = NULL;
|
|
290
|
+
Py_ssize_t zipped_index = 0;
|
|
291
|
+
if (unlikely(!tp)) return NULL;
|
|
292
|
+
|
|
293
|
+
#if __PYX_LIMITED_VERSION_HEX < 0x030E0000
|
|
294
|
+
if (__Pyx_get_runtime_version() < 0x030E0000) {
|
|
295
|
+
// There's a high chance (but not certain) that we're using our internal
|
|
296
|
+
// fallback version of template. In this case we can try to use a better
|
|
297
|
+
// constructor.
|
|
298
|
+
PyObject *kwds = NULL;
|
|
299
|
+
{
|
|
300
|
+
#if CYTHON_VECTORCALL
|
|
301
|
+
PyObject *args[] = { strings, interpolations };
|
|
302
|
+
kwds = PyTuple_Pack(2, PYIDENT("strings"), PYIDENT("interpolations"));
|
|
303
|
+
if (unlikely(!kwds)) goto failed_shortcut;
|
|
304
|
+
result = PyObject_Vectorcall(tp, args, 0, kwds);
|
|
305
|
+
#else
|
|
306
|
+
kwds = PyDict_New();
|
|
307
|
+
if (unlikely(!kwds)) goto failed_shortcut;
|
|
308
|
+
if (unlikely(PyDict_SetItem(kwds, PYIDENT("strings"), strings) < 0)) goto failed_shortcut;
|
|
309
|
+
if (unlikely(PyDict_SetItem(kwds, PYIDENT("interpolations"), interpolations) < 0)) goto failed_shortcut;
|
|
310
|
+
result = PyObject_Call(tp, EMPTY(tuple), kwds);
|
|
311
|
+
#endif
|
|
312
|
+
}
|
|
313
|
+
if (result) {
|
|
314
|
+
Py_DECREF(kwds);
|
|
315
|
+
Py_DECREF(tp);
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
failed_shortcut:
|
|
320
|
+
Py_XDECREF(kwds);
|
|
321
|
+
if (!__Pyx_IgnoreException(PyExc_Exception)) {
|
|
322
|
+
return NULL; // BaseException
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
#endif
|
|
326
|
+
|
|
327
|
+
// Slightly frustratingly, we have to go to the trouble of zipping together
|
|
328
|
+
// the strings and the interpolations. And then internally the Template does
|
|
329
|
+
// the exact opposite.
|
|
330
|
+
Py_ssize_t strings_len, interpolations_len;
|
|
331
|
+
strings_len = __Pyx_PyTuple_GET_SIZE(strings);
|
|
332
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
333
|
+
if (unlikely(strings_len < 0)) goto end;
|
|
334
|
+
#endif
|
|
335
|
+
interpolations_len = __Pyx_PyTuple_GET_SIZE(interpolations);
|
|
336
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
337
|
+
if (unlikely(interpolations_len < 0)) goto end;
|
|
338
|
+
#endif
|
|
339
|
+
zipped_tuple = PyTuple_New(strings_len + interpolations_len);
|
|
340
|
+
if (!zipped_tuple) goto end;
|
|
341
|
+
for (Py_ssize_t i=0; (i<interpolations_len || i<strings_len); ++i) {
|
|
342
|
+
if (i < strings_len) {
|
|
343
|
+
PyObject *s = __Pyx_PyTuple_GET_ITEM(strings, i);
|
|
344
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
345
|
+
if (unlikely(!s)) goto end;
|
|
346
|
+
#endif
|
|
347
|
+
Py_INCREF(s);
|
|
348
|
+
if (unlikely(__Pyx_PyTuple_SET_ITEM(zipped_tuple, zipped_index, s) < 0)) goto end;
|
|
349
|
+
++zipped_index;
|
|
350
|
+
}
|
|
351
|
+
if (i < interpolations_len) {
|
|
352
|
+
PyObject *interpolation = __Pyx_PyTuple_GET_ITEM(interpolations, i);
|
|
353
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
354
|
+
if (unlikely(!interpolation)) goto end;
|
|
355
|
+
#endif
|
|
356
|
+
Py_INCREF(interpolation);
|
|
357
|
+
if (unlikely(__Pyx_PyTuple_SET_ITEM(zipped_tuple, zipped_index, interpolation) < 0)) goto end;
|
|
358
|
+
++zipped_index;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
result = PyObject_CallObject(tp, zipped_tuple);
|
|
363
|
+
|
|
364
|
+
end:
|
|
365
|
+
Py_XDECREF(zipped_tuple);
|
|
366
|
+
Py_DECREF(tp);
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
#endif
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
########## TestClass ##########
|
|
2
|
+
# These utilities are for testing purposes
|
|
3
|
+
|
|
4
|
+
# The "cythonscope" test calls METH_O functions with their (self, arg) signature.
|
|
5
|
+
# cython: always_allow_keywords=False
|
|
6
|
+
|
|
7
|
+
from __future__ import print_function
|
|
8
|
+
|
|
9
|
+
cdef extern from *:
|
|
10
|
+
cdef object __pyx_test_dep(object)
|
|
11
|
+
ctypedef struct PyObject
|
|
12
|
+
|
|
13
|
+
@cname('__pyx_TestClass')
|
|
14
|
+
cdef class TestClass(object):
|
|
15
|
+
cdef public int value
|
|
16
|
+
|
|
17
|
+
def __init__(self, int value):
|
|
18
|
+
self.value = value
|
|
19
|
+
|
|
20
|
+
def __str__(self):
|
|
21
|
+
return f'TestClass({self.value})'
|
|
22
|
+
|
|
23
|
+
cdef cdef_method(self, int value):
|
|
24
|
+
print('Hello from cdef_method', value)
|
|
25
|
+
|
|
26
|
+
cpdef cpdef_method(self, int value):
|
|
27
|
+
print('Hello from cpdef_method', value)
|
|
28
|
+
|
|
29
|
+
def def_method(self, int value):
|
|
30
|
+
print('Hello from def_method', value)
|
|
31
|
+
|
|
32
|
+
@cname('cdef_cname')
|
|
33
|
+
cdef cdef_cname_method(self, int value):
|
|
34
|
+
print("Hello from cdef_cname_method", value)
|
|
35
|
+
|
|
36
|
+
@cname('cpdef_cname')
|
|
37
|
+
cpdef cpdef_cname_method(self, int value):
|
|
38
|
+
print("Hello from cpdef_cname_method", value)
|
|
39
|
+
|
|
40
|
+
@cname('def_cname')
|
|
41
|
+
def def_cname_method(self, int value):
|
|
42
|
+
print("Hello from def_cname_method", value)
|
|
43
|
+
|
|
44
|
+
# For now cdef variables are outside the module scope,
|
|
45
|
+
# so we can create a global cname that is easily accessible
|
|
46
|
+
cdef PyObject* __pyx_TestClass_type = <PyObject*>TestClass
|
|
47
|
+
|
|
48
|
+
@cname('__pyx_test_call_other_cy_util')
|
|
49
|
+
cdef test_call(obj):
|
|
50
|
+
print('test_call')
|
|
51
|
+
__pyx_test_dep(obj)
|
|
52
|
+
|
|
53
|
+
@cname('__pyx_TestClass_New')
|
|
54
|
+
cdef _testclass_new(int value):
|
|
55
|
+
return TestClass(value)
|
|
56
|
+
|
|
57
|
+
########### TestDep ##########
|
|
58
|
+
|
|
59
|
+
from __future__ import print_function
|
|
60
|
+
|
|
61
|
+
@cname('__pyx_test_dep')
|
|
62
|
+
cdef test_dep(obj):
|
|
63
|
+
print('test_dep', obj)
|
|
64
|
+
|
|
65
|
+
########## TestScope ##########
|
|
66
|
+
|
|
67
|
+
@cname('__pyx_testscope')
|
|
68
|
+
cdef object _testscope(int value):
|
|
69
|
+
return f"hello from cython scope, value={value}"
|
|
70
|
+
|
|
71
|
+
########## View.TestScope ##########
|
|
72
|
+
|
|
73
|
+
@cname('__pyx_view_testscope')
|
|
74
|
+
cdef object _testscope(int value):
|
|
75
|
+
return f"hello from cython.view scope, value={value}"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
////////// TestUtilityLoader.proto //////////
|
|
2
|
+
test {{loader}} prototype
|
|
3
|
+
|
|
4
|
+
////////// TestUtilityLoader //////////
|
|
5
|
+
//@requires: OtherUtility
|
|
6
|
+
test {{loader}} impl
|
|
7
|
+
|
|
8
|
+
////////// OtherUtility.proto //////////
|
|
9
|
+
req {{loader}} proto
|
|
10
|
+
|
|
11
|
+
////////// OtherUtility //////////
|
|
12
|
+
req {{loader}} impl
|