Cython 3.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Cython/Build/BuildExecutable.py +169 -0
- Cython/Build/Cache.py +199 -0
- Cython/Build/Cythonize.py +323 -0
- Cython/Build/Dependencies.py +1306 -0
- Cython/Build/Distutils.py +1 -0
- Cython/Build/Inline.py +463 -0
- Cython/Build/IpythonMagic.py +560 -0
- Cython/Build/SharedModule.py +76 -0
- Cython/Build/Tests/TestCyCache.py +194 -0
- Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
- Cython/Build/Tests/TestDependencies.py +133 -0
- Cython/Build/Tests/TestInline.py +177 -0
- Cython/Build/Tests/TestIpythonMagic.py +287 -0
- Cython/Build/Tests/TestRecythonize.py +212 -0
- Cython/Build/Tests/TestStripLiterals.py +155 -0
- Cython/Build/Tests/__init__.py +1 -0
- Cython/Build/__init__.py +8 -0
- Cython/CodeWriter.py +811 -0
- Cython/Compiler/AnalysedTreeTransforms.py +97 -0
- Cython/Compiler/Annotate.py +326 -0
- Cython/Compiler/AutoDocTransforms.py +320 -0
- Cython/Compiler/Buffer.py +680 -0
- Cython/Compiler/Builtin.py +934 -0
- Cython/Compiler/CmdLine.py +259 -0
- Cython/Compiler/Code.pxd +148 -0
- Cython/Compiler/Code.py +3375 -0
- Cython/Compiler/CodeGeneration.py +33 -0
- Cython/Compiler/CythonScope.py +187 -0
- Cython/Compiler/Dataclass.py +868 -0
- Cython/Compiler/DebugFlags.py +24 -0
- Cython/Compiler/Errors.py +295 -0
- Cython/Compiler/ExprNodes.py +15267 -0
- Cython/Compiler/FlowControl.pxd +97 -0
- Cython/Compiler/FlowControl.py +1455 -0
- Cython/Compiler/FusedNode.py +1002 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +340 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/Main.py +853 -0
- Cython/Compiler/MatchCaseNodes.py +259 -0
- Cython/Compiler/MemoryView.py +922 -0
- Cython/Compiler/ModuleNode.py +4024 -0
- Cython/Compiler/Naming.py +374 -0
- Cython/Compiler/Nodes.py +10826 -0
- Cython/Compiler/Optimize.py +5256 -0
- Cython/Compiler/Options.py +835 -0
- Cython/Compiler/ParseTreeTransforms.pxd +77 -0
- Cython/Compiler/ParseTreeTransforms.py +4509 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +4789 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +5762 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +40 -0
- Cython/Compiler/Scanning.py +577 -0
- Cython/Compiler/StringEncoding.py +347 -0
- Cython/Compiler/Symtab.py +3080 -0
- Cython/Compiler/Tests/TestBuffer.py +105 -0
- Cython/Compiler/Tests/TestBuiltin.py +72 -0
- Cython/Compiler/Tests/TestCmdLine.py +586 -0
- Cython/Compiler/Tests/TestCode.py +86 -0
- Cython/Compiler/Tests/TestFlowControl.py +65 -0
- Cython/Compiler/Tests/TestGrammar.py +202 -0
- Cython/Compiler/Tests/TestMemView.py +71 -0
- Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
- Cython/Compiler/Tests/TestScanning.py +134 -0
- Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
- Cython/Compiler/Tests/TestStringEncoding.py +33 -0
- Cython/Compiler/Tests/TestTreeFragment.py +63 -0
- Cython/Compiler/Tests/TestTreePath.py +103 -0
- Cython/Compiler/Tests/TestTypes.py +75 -0
- Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
- Cython/Compiler/Tests/TestVisitor.py +61 -0
- Cython/Compiler/Tests/Utils.py +36 -0
- Cython/Compiler/Tests/__init__.py +1 -0
- Cython/Compiler/TreeFragment.py +278 -0
- Cython/Compiler/TreePath.py +303 -0
- Cython/Compiler/TypeInference.py +584 -0
- Cython/Compiler/TypeSlots.py +1181 -0
- Cython/Compiler/UFuncs.py +311 -0
- Cython/Compiler/UtilNodes.py +389 -0
- Cython/Compiler/UtilityCode.py +344 -0
- Cython/Compiler/Version.py +8 -0
- Cython/Compiler/Visitor.pxd +53 -0
- Cython/Compiler/Visitor.py +861 -0
- Cython/Compiler/__init__.py +1 -0
- Cython/Coverage.py +448 -0
- Cython/Debugger/Cygdb.py +175 -0
- Cython/Debugger/DebugWriter.py +82 -0
- Cython/Debugger/Tests/TestLibCython.py +275 -0
- Cython/Debugger/Tests/__init__.py +1 -0
- Cython/Debugger/Tests/cfuncs.c +8 -0
- Cython/Debugger/Tests/codefile +49 -0
- Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
- Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
- Cython/Debugger/__init__.py +1 -0
- Cython/Debugger/libcython.py +1548 -0
- Cython/Debugger/libpython.py +2821 -0
- Cython/Debugging.py +20 -0
- Cython/Distutils/__init__.py +2 -0
- Cython/Distutils/build_ext.py +139 -0
- Cython/Distutils/extension.py +96 -0
- Cython/Distutils/old_build_ext.py +351 -0
- Cython/Includes/cpython/__init__.pxd +173 -0
- Cython/Includes/cpython/array.pxd +174 -0
- Cython/Includes/cpython/bool.pxd +37 -0
- Cython/Includes/cpython/buffer.pxd +112 -0
- Cython/Includes/cpython/bytearray.pxd +33 -0
- Cython/Includes/cpython/bytes.pxd +200 -0
- Cython/Includes/cpython/cellobject.pxd +35 -0
- Cython/Includes/cpython/ceval.pxd +8 -0
- Cython/Includes/cpython/codecs.pxd +121 -0
- Cython/Includes/cpython/complex.pxd +60 -0
- Cython/Includes/cpython/contextvars.pxd +145 -0
- Cython/Includes/cpython/conversion.pxd +36 -0
- Cython/Includes/cpython/datetime.pxd +395 -0
- Cython/Includes/cpython/descr.pxd +26 -0
- Cython/Includes/cpython/dict.pxd +187 -0
- Cython/Includes/cpython/exc.pxd +263 -0
- Cython/Includes/cpython/fileobject.pxd +57 -0
- Cython/Includes/cpython/float.pxd +47 -0
- Cython/Includes/cpython/function.pxd +65 -0
- Cython/Includes/cpython/genobject.pxd +25 -0
- Cython/Includes/cpython/getargs.pxd +12 -0
- Cython/Includes/cpython/instance.pxd +25 -0
- Cython/Includes/cpython/iterator.pxd +36 -0
- Cython/Includes/cpython/iterobject.pxd +24 -0
- Cython/Includes/cpython/list.pxd +92 -0
- Cython/Includes/cpython/long.pxd +149 -0
- Cython/Includes/cpython/longintrepr.pxd +14 -0
- Cython/Includes/cpython/mapping.pxd +63 -0
- Cython/Includes/cpython/marshal.pxd +66 -0
- Cython/Includes/cpython/mem.pxd +120 -0
- Cython/Includes/cpython/memoryview.pxd +50 -0
- Cython/Includes/cpython/method.pxd +49 -0
- Cython/Includes/cpython/module.pxd +208 -0
- Cython/Includes/cpython/number.pxd +258 -0
- Cython/Includes/cpython/object.pxd +433 -0
- Cython/Includes/cpython/pycapsule.pxd +143 -0
- Cython/Includes/cpython/pylifecycle.pxd +68 -0
- Cython/Includes/cpython/pyport.pxd +8 -0
- Cython/Includes/cpython/pystate.pxd +95 -0
- Cython/Includes/cpython/pythread.pxd +53 -0
- Cython/Includes/cpython/ref.pxd +67 -0
- Cython/Includes/cpython/sequence.pxd +134 -0
- Cython/Includes/cpython/set.pxd +119 -0
- Cython/Includes/cpython/slice.pxd +70 -0
- Cython/Includes/cpython/time.pxd +129 -0
- Cython/Includes/cpython/tuple.pxd +72 -0
- Cython/Includes/cpython/type.pxd +53 -0
- Cython/Includes/cpython/unicode.pxd +639 -0
- Cython/Includes/cpython/version.pxd +32 -0
- Cython/Includes/cpython/weakref.pxd +78 -0
- Cython/Includes/libc/__init__.pxd +1 -0
- Cython/Includes/libc/complex.pxd +35 -0
- Cython/Includes/libc/errno.pxd +127 -0
- Cython/Includes/libc/float.pxd +43 -0
- Cython/Includes/libc/limits.pxd +28 -0
- Cython/Includes/libc/locale.pxd +46 -0
- Cython/Includes/libc/math.pxd +209 -0
- Cython/Includes/libc/setjmp.pxd +10 -0
- Cython/Includes/libc/signal.pxd +64 -0
- Cython/Includes/libc/stddef.pxd +9 -0
- Cython/Includes/libc/stdint.pxd +105 -0
- Cython/Includes/libc/stdio.pxd +80 -0
- Cython/Includes/libc/stdlib.pxd +72 -0
- Cython/Includes/libc/string.pxd +50 -0
- Cython/Includes/libc/threads.pxd +84 -0
- Cython/Includes/libc/time.pxd +51 -0
- Cython/Includes/libcpp/__init__.pxd +4 -0
- Cython/Includes/libcpp/algorithm.pxd +320 -0
- Cython/Includes/libcpp/any.pxd +16 -0
- Cython/Includes/libcpp/atomic.pxd +59 -0
- Cython/Includes/libcpp/barrier.pxd +22 -0
- Cython/Includes/libcpp/bit.pxd +29 -0
- Cython/Includes/libcpp/cast.pxd +12 -0
- Cython/Includes/libcpp/cmath.pxd +518 -0
- Cython/Includes/libcpp/complex.pxd +106 -0
- Cython/Includes/libcpp/deque.pxd +165 -0
- Cython/Includes/libcpp/exception.pxd +86 -0
- Cython/Includes/libcpp/execution.pxd +15 -0
- Cython/Includes/libcpp/forward_list.pxd +63 -0
- Cython/Includes/libcpp/functional.pxd +26 -0
- Cython/Includes/libcpp/future.pxd +103 -0
- Cython/Includes/libcpp/iterator.pxd +34 -0
- Cython/Includes/libcpp/latch.pxd +17 -0
- Cython/Includes/libcpp/limits.pxd +61 -0
- Cython/Includes/libcpp/list.pxd +117 -0
- Cython/Includes/libcpp/map.pxd +252 -0
- Cython/Includes/libcpp/memory.pxd +115 -0
- Cython/Includes/libcpp/mutex.pxd +130 -0
- Cython/Includes/libcpp/numbers.pxd +15 -0
- Cython/Includes/libcpp/numeric.pxd +131 -0
- Cython/Includes/libcpp/optional.pxd +34 -0
- Cython/Includes/libcpp/pair.pxd +1 -0
- Cython/Includes/libcpp/queue.pxd +25 -0
- Cython/Includes/libcpp/random.pxd +166 -0
- Cython/Includes/libcpp/semaphore.pxd +44 -0
- Cython/Includes/libcpp/set.pxd +228 -0
- Cython/Includes/libcpp/shared_mutex.pxd +72 -0
- Cython/Includes/libcpp/span.pxd +87 -0
- Cython/Includes/libcpp/stack.pxd +11 -0
- Cython/Includes/libcpp/stop_token.pxd +105 -0
- Cython/Includes/libcpp/string.pxd +355 -0
- Cython/Includes/libcpp/string_view.pxd +181 -0
- Cython/Includes/libcpp/typeindex.pxd +15 -0
- Cython/Includes/libcpp/typeinfo.pxd +10 -0
- Cython/Includes/libcpp/unordered_map.pxd +193 -0
- Cython/Includes/libcpp/unordered_set.pxd +152 -0
- Cython/Includes/libcpp/utility.pxd +30 -0
- Cython/Includes/libcpp/vector.pxd +186 -0
- Cython/Includes/openmp.pxd +50 -0
- Cython/Includes/posix/__init__.pxd +1 -0
- Cython/Includes/posix/dlfcn.pxd +14 -0
- Cython/Includes/posix/fcntl.pxd +86 -0
- Cython/Includes/posix/ioctl.pxd +4 -0
- Cython/Includes/posix/mman.pxd +101 -0
- Cython/Includes/posix/resource.pxd +57 -0
- Cython/Includes/posix/select.pxd +21 -0
- Cython/Includes/posix/signal.pxd +73 -0
- Cython/Includes/posix/stat.pxd +98 -0
- Cython/Includes/posix/stdio.pxd +37 -0
- Cython/Includes/posix/stdlib.pxd +29 -0
- Cython/Includes/posix/strings.pxd +9 -0
- Cython/Includes/posix/time.pxd +71 -0
- Cython/Includes/posix/types.pxd +30 -0
- Cython/Includes/posix/uio.pxd +26 -0
- Cython/Includes/posix/unistd.pxd +271 -0
- Cython/Includes/posix/wait.pxd +38 -0
- Cython/Plex/Actions.pxd +24 -0
- Cython/Plex/Actions.py +119 -0
- Cython/Plex/DFA.pxd +14 -0
- Cython/Plex/DFA.py +164 -0
- Cython/Plex/Errors.py +48 -0
- Cython/Plex/Lexicons.py +178 -0
- Cython/Plex/Machines.pxd +36 -0
- Cython/Plex/Machines.py +238 -0
- Cython/Plex/Regexps.py +539 -0
- Cython/Plex/Scanners.pxd +47 -0
- Cython/Plex/Scanners.py +360 -0
- Cython/Plex/Transitions.pxd +14 -0
- Cython/Plex/Transitions.py +239 -0
- Cython/Plex/__init__.py +34 -0
- Cython/Runtime/__init__.py +1 -0
- Cython/Runtime/refnanny.pyx +237 -0
- Cython/Shadow.py +690 -0
- Cython/Shadow.pyi +521 -0
- Cython/StringIOTree.py +170 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -0
- Cython/Tempita/_tempita.py +1091 -0
- Cython/TestUtils.py +410 -0
- Cython/Tests/TestCodeWriter.py +128 -0
- Cython/Tests/TestCythonUtils.py +202 -0
- Cython/Tests/TestJediTyper.py +223 -0
- Cython/Tests/TestShadow.py +114 -0
- Cython/Tests/TestStringIOTree.py +67 -0
- Cython/Tests/TestTestUtils.py +90 -0
- Cython/Tests/__init__.py +1 -0
- Cython/Tests/xmlrunner.py +390 -0
- Cython/Utility/AsyncGen.c +1002 -0
- Cython/Utility/Buffer.c +875 -0
- Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
- Cython/Utility/Builtins.c +776 -0
- Cython/Utility/CConvert.pyx +134 -0
- Cython/Utility/CMath.c +104 -0
- Cython/Utility/CommonStructures.c +118 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2206 -0
- Cython/Utility/CpdefEnums.pyx +103 -0
- Cython/Utility/CppConvert.pyx +279 -0
- Cython/Utility/CppSupport.cpp +143 -0
- Cython/Utility/CythonFunction.c +1794 -0
- Cython/Utility/Dataclasses.c +185 -0
- Cython/Utility/Dataclasses.py +112 -0
- Cython/Utility/Embed.c +125 -0
- Cython/Utility/Exceptions.c +1012 -0
- Cython/Utility/ExtensionTypes.c +809 -0
- Cython/Utility/FunctionArguments.c +965 -0
- Cython/Utility/ImportExport.c +987 -0
- Cython/Utility/Lock.c +136 -0
- Cython/Utility/MemoryView.pxd +187 -0
- Cython/Utility/MemoryView.pyx +1481 -0
- Cython/Utility/MemoryView_C.c +1046 -0
- Cython/Utility/ModuleSetupCode.c +3059 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3342 -0
- Cython/Utility/Optimize.c +1589 -0
- Cython/Utility/Overflow.c +404 -0
- Cython/Utility/Printing.c +86 -0
- Cython/Utility/Profile.c +709 -0
- Cython/Utility/StringTools.c +1259 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1284 -0
- Cython/Utility/UFuncs.pyx +50 -0
- Cython/Utility/UFuncs_C.c +89 -0
- Cython/Utility/__init__.py +28 -0
- Cython/Utility/arrayarray.h +148 -0
- Cython/Utils.py +687 -0
- Cython/__init__.py +10 -0
- Cython/__init__.pyi +7 -0
- Cython/py.typed +0 -0
- cython-3.1.0.dist-info/COPYING.txt +19 -0
- cython-3.1.0.dist-info/LICENSE.txt +176 -0
- cython-3.1.0.dist-info/METADATA +636 -0
- cython-3.1.0.dist-info/RECORD +316 -0
- cython-3.1.0.dist-info/WHEEL +5 -0
- cython-3.1.0.dist-info/entry_points.txt +4 -0
- cython-3.1.0.dist-info/top_level.txt +3 -0
- cython.py +29 -0
- pyximport/__init__.py +4 -0
- pyximport/pyxbuild.py +160 -0
- pyximport/pyximport.py +482 -0
|
@@ -0,0 +1,1259 @@
|
|
|
1
|
+
|
|
2
|
+
//////////////////// IncludeStringH.proto ////////////////////
|
|
3
|
+
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
//////////////////// IncludeCppStringH.proto ////////////////////
|
|
7
|
+
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
//////////////////// IncludeCppStringViewH.proto ////////////////////
|
|
11
|
+
|
|
12
|
+
#include <string_view>
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//////////////////// ssize_pyunicode_strlen.proto ////////////////////
|
|
16
|
+
|
|
17
|
+
static CYTHON_INLINE Py_ssize_t __Pyx_Py_UNICODE_ssize_strlen(const Py_UNICODE *u);/*proto*/
|
|
18
|
+
|
|
19
|
+
//////////////////// ssize_pyunicode_strlen ////////////////////
|
|
20
|
+
//@requires: pyunicode_strlen
|
|
21
|
+
|
|
22
|
+
static CYTHON_INLINE Py_ssize_t __Pyx_Py_UNICODE_ssize_strlen(const Py_UNICODE *u) {
|
|
23
|
+
size_t len = __Pyx_Py_UNICODE_strlen(u);
|
|
24
|
+
if (unlikely(len > PY_SSIZE_T_MAX)) {
|
|
25
|
+
PyErr_SetString(PyExc_OverflowError, "Py_UNICODE string is too long");
|
|
26
|
+
return -1;
|
|
27
|
+
}
|
|
28
|
+
return (Py_ssize_t) len;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//////////////////// pyunicode_strlen.proto ///////////////
|
|
32
|
+
|
|
33
|
+
// There used to be a Py_UNICODE_strlen() in CPython 3.x, but it is deprecated since Py3.3.
|
|
34
|
+
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u); /* proto */
|
|
35
|
+
|
|
36
|
+
//////////////////// pyunicode_strlen /////////////////////
|
|
37
|
+
|
|
38
|
+
// Note: will not work in the limited API since Py_UNICODE is not available there.
|
|
39
|
+
// May stop working at some point after Python 3.13 (deprecated)
|
|
40
|
+
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
|
|
41
|
+
{
|
|
42
|
+
const Py_UNICODE *u_end = u;
|
|
43
|
+
while (*u_end++) ;
|
|
44
|
+
return (size_t)(u_end - u - 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//////////////////// pyunicode_from_unicode.proto //////////////////////
|
|
48
|
+
//@requires: pyunicode_strlen
|
|
49
|
+
|
|
50
|
+
#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
|
|
51
|
+
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
//////////////////// InitStrings.proto ////////////////////
|
|
55
|
+
//@proto_block: pystring_table
|
|
56
|
+
|
|
57
|
+
static int __Pyx_InitStrings(__Pyx_StringTabEntry const *t, PyObject **target, const char* const* encoding_names); /*proto*/
|
|
58
|
+
|
|
59
|
+
//////////////////// InitStrings ////////////////////
|
|
60
|
+
|
|
61
|
+
static int __Pyx_InitStrings(__Pyx_StringTabEntry const *t, PyObject **target, const char* const* encoding_names) {
|
|
62
|
+
while (t->s) {
|
|
63
|
+
PyObject *str;
|
|
64
|
+
if (t->is_unicode) {
|
|
65
|
+
if (t->intern) {
|
|
66
|
+
str = PyUnicode_InternFromString(t->s);
|
|
67
|
+
} else if (t->encoding) {
|
|
68
|
+
str = PyUnicode_Decode(t->s, t->n - 1, encoding_names[t->encoding], NULL);
|
|
69
|
+
} else {
|
|
70
|
+
str = PyUnicode_FromStringAndSize(t->s, t->n - 1);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
str = PyBytes_FromStringAndSize(t->s, t->n - 1);
|
|
74
|
+
}
|
|
75
|
+
if (!str)
|
|
76
|
+
return -1;
|
|
77
|
+
*target = str;
|
|
78
|
+
// initialise cached hash value
|
|
79
|
+
if (PyObject_Hash(str) == -1)
|
|
80
|
+
return -1;
|
|
81
|
+
++t;
|
|
82
|
+
++target;
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//////////////////// BytesContains.proto ////////////////////
|
|
88
|
+
|
|
89
|
+
static CYTHON_INLINE int __Pyx_BytesContains(PyObject* bytes, char character); /*proto*/
|
|
90
|
+
|
|
91
|
+
//////////////////// BytesContains ////////////////////
|
|
92
|
+
//@requires: IncludeStringH
|
|
93
|
+
|
|
94
|
+
static CYTHON_INLINE int __Pyx_BytesContains(PyObject* bytes, char character) {
|
|
95
|
+
const Py_ssize_t length = __Pyx_PyBytes_GET_SIZE(bytes);
|
|
96
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
97
|
+
if (unlikely(length == -1)) return -1;
|
|
98
|
+
#endif
|
|
99
|
+
const char* char_start = __Pyx_PyBytes_AsString(bytes);
|
|
100
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
101
|
+
if (unlikely(!char_start)) return -1;
|
|
102
|
+
#endif
|
|
103
|
+
return memchr(char_start, (unsigned char)character, (size_t)length) != NULL;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
//////////////////// PyUCS4InUnicode.proto ////////////////////
|
|
108
|
+
|
|
109
|
+
static CYTHON_INLINE int __Pyx_UnicodeContainsUCS4(PyObject* unicode, Py_UCS4 character); /*proto*/
|
|
110
|
+
|
|
111
|
+
//////////////////// PyUCS4InUnicode ////////////////////
|
|
112
|
+
|
|
113
|
+
static CYTHON_INLINE int __Pyx_UnicodeContainsUCS4(PyObject* unicode, Py_UCS4 character) {
|
|
114
|
+
// Note that from Python 3.7, the indices of FindChar are adjusted to match the bounds
|
|
115
|
+
// so need to check the length
|
|
116
|
+
Py_ssize_t idx = PyUnicode_FindChar(unicode, character, 0, PY_SSIZE_T_MAX, 1);
|
|
117
|
+
if (unlikely(idx == -2)) return -1;
|
|
118
|
+
// >= 0: found the index, == -1: not found
|
|
119
|
+
return idx >= 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
//////////////////// PyUnicodeContains.proto ////////////////////
|
|
124
|
+
|
|
125
|
+
static CYTHON_INLINE int __Pyx_PyUnicode_ContainsTF(PyObject* substring, PyObject* text, int eq) {
|
|
126
|
+
int result = PyUnicode_Contains(text, substring);
|
|
127
|
+
return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
//////////////////// CStringEquals.proto ////////////////////
|
|
132
|
+
|
|
133
|
+
static CYTHON_INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/
|
|
134
|
+
|
|
135
|
+
//////////////////// CStringEquals ////////////////////
|
|
136
|
+
|
|
137
|
+
static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
|
|
138
|
+
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
|
|
139
|
+
return *s1 == *s2;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
//////////////////// UnicodeEquals.proto ////////////////////
|
|
144
|
+
|
|
145
|
+
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
|
|
146
|
+
|
|
147
|
+
//////////////////// UnicodeEquals ////////////////////
|
|
148
|
+
//@requires: BytesEquals
|
|
149
|
+
|
|
150
|
+
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
|
|
151
|
+
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL
|
|
152
|
+
return PyObject_RichCompareBool(s1, s2, equals);
|
|
153
|
+
#else
|
|
154
|
+
int s1_is_unicode, s2_is_unicode;
|
|
155
|
+
if (s1 == s2) {
|
|
156
|
+
/* as done by PyObject_RichCompareBool(); also catches the (interned) empty string */
|
|
157
|
+
goto return_eq;
|
|
158
|
+
}
|
|
159
|
+
s1_is_unicode = PyUnicode_CheckExact(s1);
|
|
160
|
+
s2_is_unicode = PyUnicode_CheckExact(s2);
|
|
161
|
+
if (s1_is_unicode & s2_is_unicode) {
|
|
162
|
+
Py_ssize_t length, length2;
|
|
163
|
+
int kind;
|
|
164
|
+
void *data1, *data2;
|
|
165
|
+
#if !CYTHON_COMPILING_IN_LIMITED_API
|
|
166
|
+
if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
|
|
167
|
+
return -1;
|
|
168
|
+
#endif
|
|
169
|
+
length = __Pyx_PyUnicode_GET_LENGTH(s1);
|
|
170
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
171
|
+
if (unlikely(length < 0)) return -1;
|
|
172
|
+
#endif
|
|
173
|
+
length2 = __Pyx_PyUnicode_GET_LENGTH(s2);
|
|
174
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
175
|
+
if (unlikely(length2 < 0)) return -1;
|
|
176
|
+
#endif
|
|
177
|
+
if (length != length2) {
|
|
178
|
+
goto return_ne;
|
|
179
|
+
}
|
|
180
|
+
#if CYTHON_USE_UNICODE_INTERNALS
|
|
181
|
+
{
|
|
182
|
+
Py_hash_t hash1, hash2;
|
|
183
|
+
hash1 = ((PyASCIIObject*)s1)->hash;
|
|
184
|
+
hash2 = ((PyASCIIObject*)s2)->hash;
|
|
185
|
+
if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
|
|
186
|
+
goto return_ne;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
#endif
|
|
190
|
+
// len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
|
|
191
|
+
kind = __Pyx_PyUnicode_KIND(s1);
|
|
192
|
+
if (kind != __Pyx_PyUnicode_KIND(s2)) {
|
|
193
|
+
goto return_ne;
|
|
194
|
+
}
|
|
195
|
+
data1 = __Pyx_PyUnicode_DATA(s1);
|
|
196
|
+
data2 = __Pyx_PyUnicode_DATA(s2);
|
|
197
|
+
if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
|
|
198
|
+
goto return_ne;
|
|
199
|
+
} else if (length == 1) {
|
|
200
|
+
goto return_eq;
|
|
201
|
+
} else {
|
|
202
|
+
int result = memcmp(data1, data2, (size_t)(length * kind));
|
|
203
|
+
return (equals == Py_EQ) ? (result == 0) : (result != 0);
|
|
204
|
+
}
|
|
205
|
+
} else if ((s1 == Py_None) & s2_is_unicode) {
|
|
206
|
+
goto return_ne;
|
|
207
|
+
} else if ((s2 == Py_None) & s1_is_unicode) {
|
|
208
|
+
goto return_ne;
|
|
209
|
+
} else {
|
|
210
|
+
int result;
|
|
211
|
+
PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
|
|
212
|
+
if (!py_result)
|
|
213
|
+
return -1;
|
|
214
|
+
result = __Pyx_PyObject_IsTrue(py_result);
|
|
215
|
+
Py_DECREF(py_result);
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
return_eq:
|
|
219
|
+
return (equals == Py_EQ);
|
|
220
|
+
return_ne:
|
|
221
|
+
return (equals == Py_NE);
|
|
222
|
+
#endif
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
//////////////////// BytesEquals.proto ////////////////////
|
|
227
|
+
|
|
228
|
+
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
|
|
229
|
+
|
|
230
|
+
//////////////////// BytesEquals ////////////////////
|
|
231
|
+
//@requires: IncludeStringH
|
|
232
|
+
|
|
233
|
+
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
|
|
234
|
+
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL || \
|
|
235
|
+
!(CYTHON_ASSUME_SAFE_SIZE && CYTHON_ASSUME_SAFE_MACROS)
|
|
236
|
+
return PyObject_RichCompareBool(s1, s2, equals);
|
|
237
|
+
#else
|
|
238
|
+
if (s1 == s2) {
|
|
239
|
+
/* as done by PyObject_RichCompareBool(); also catches the (interned) empty string */
|
|
240
|
+
return (equals == Py_EQ);
|
|
241
|
+
} else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
|
|
242
|
+
const char *ps1, *ps2;
|
|
243
|
+
Py_ssize_t length = PyBytes_GET_SIZE(s1);
|
|
244
|
+
if (length != PyBytes_GET_SIZE(s2))
|
|
245
|
+
return (equals == Py_NE);
|
|
246
|
+
// len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
|
|
247
|
+
ps1 = PyBytes_AS_STRING(s1);
|
|
248
|
+
ps2 = PyBytes_AS_STRING(s2);
|
|
249
|
+
if (ps1[0] != ps2[0]) {
|
|
250
|
+
return (equals == Py_NE);
|
|
251
|
+
} else if (length == 1) {
|
|
252
|
+
return (equals == Py_EQ);
|
|
253
|
+
} else {
|
|
254
|
+
int result;
|
|
255
|
+
#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000)
|
|
256
|
+
Py_hash_t hash1, hash2;
|
|
257
|
+
hash1 = ((PyBytesObject*)s1)->ob_shash;
|
|
258
|
+
hash2 = ((PyBytesObject*)s2)->ob_shash;
|
|
259
|
+
if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
|
|
260
|
+
return (equals == Py_NE);
|
|
261
|
+
}
|
|
262
|
+
#endif
|
|
263
|
+
result = memcmp(ps1, ps2, (size_t)length);
|
|
264
|
+
return (equals == Py_EQ) ? (result == 0) : (result != 0);
|
|
265
|
+
}
|
|
266
|
+
} else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
|
|
267
|
+
return (equals == Py_NE);
|
|
268
|
+
} else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
|
|
269
|
+
return (equals == Py_NE);
|
|
270
|
+
} else {
|
|
271
|
+
int result;
|
|
272
|
+
PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
|
|
273
|
+
if (!py_result)
|
|
274
|
+
return -1;
|
|
275
|
+
result = __Pyx_PyObject_IsTrue(py_result);
|
|
276
|
+
Py_DECREF(py_result);
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
#endif
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
//////////////////// GetItemIntByteArray.proto ////////////////////
|
|
283
|
+
|
|
284
|
+
#define __Pyx_GetItemInt_ByteArray(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
|
|
285
|
+
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
|
|
286
|
+
__Pyx_GetItemInt_ByteArray_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
|
|
287
|
+
(PyErr_SetString(PyExc_IndexError, "bytearray index out of range"), -1))
|
|
288
|
+
|
|
289
|
+
static CYTHON_INLINE int __Pyx_GetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i,
|
|
290
|
+
int wraparound, int boundscheck);
|
|
291
|
+
|
|
292
|
+
//////////////////// GetItemIntByteArray ////////////////////
|
|
293
|
+
|
|
294
|
+
static CYTHON_INLINE int __Pyx_GetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i,
|
|
295
|
+
int wraparound, int boundscheck) {
|
|
296
|
+
Py_ssize_t length;
|
|
297
|
+
if (wraparound | boundscheck) {
|
|
298
|
+
length = __Pyx_PyByteArray_GET_SIZE(string);
|
|
299
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
300
|
+
if (unlikely(length < 0)) return -1;
|
|
301
|
+
#endif
|
|
302
|
+
if (wraparound & unlikely(i < 0)) i += length;
|
|
303
|
+
if ((!boundscheck) || likely(__Pyx_is_valid_index(i, length))) {
|
|
304
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
305
|
+
char *asString = PyByteArray_AsString(string);
|
|
306
|
+
return likely(asString) ? (unsigned char) asString[i] : -1;
|
|
307
|
+
#else
|
|
308
|
+
return (unsigned char) (PyByteArray_AS_STRING(string)[i]);
|
|
309
|
+
#endif
|
|
310
|
+
} else {
|
|
311
|
+
PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
|
|
312
|
+
return -1;
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
316
|
+
char *asString = PyByteArray_AsString(string);
|
|
317
|
+
return likely(asString) ? (unsigned char) asString[i] : -1;
|
|
318
|
+
#else
|
|
319
|
+
return (unsigned char) (PyByteArray_AS_STRING(string)[i]);
|
|
320
|
+
#endif
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
//////////////////// SetItemIntByteArray.proto ////////////////////
|
|
326
|
+
|
|
327
|
+
#define __Pyx_SetItemInt_ByteArray(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
|
|
328
|
+
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
|
|
329
|
+
__Pyx_SetItemInt_ByteArray_Fast(o, (Py_ssize_t)i, v, wraparound, boundscheck) : \
|
|
330
|
+
(PyErr_SetString(PyExc_IndexError, "bytearray index out of range"), -1))
|
|
331
|
+
|
|
332
|
+
static CYTHON_INLINE int __Pyx_SetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i, unsigned char v,
|
|
333
|
+
int wraparound, int boundscheck);
|
|
334
|
+
|
|
335
|
+
//////////////////// SetItemIntByteArray ////////////////////
|
|
336
|
+
|
|
337
|
+
static CYTHON_INLINE int __Pyx_SetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i, unsigned char v,
|
|
338
|
+
int wraparound, int boundscheck) {
|
|
339
|
+
Py_ssize_t length;
|
|
340
|
+
if (wraparound | boundscheck) {
|
|
341
|
+
length = __Pyx_PyByteArray_GET_SIZE(string);
|
|
342
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
343
|
+
if (unlikely(length < 0)) return -1;
|
|
344
|
+
#endif
|
|
345
|
+
if (wraparound & unlikely(i < 0)) i += length;
|
|
346
|
+
if ((!boundscheck) || likely(__Pyx_is_valid_index(i, length))) {
|
|
347
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
348
|
+
char *asString = PyByteArray_AsString(string);
|
|
349
|
+
if (unlikely(!asString)) return -1;
|
|
350
|
+
asString[i] = (char)v;
|
|
351
|
+
#else
|
|
352
|
+
PyByteArray_AS_STRING(string)[i] = (char) v;
|
|
353
|
+
#endif
|
|
354
|
+
return 0;
|
|
355
|
+
} else {
|
|
356
|
+
PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
|
|
357
|
+
return -1;
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
361
|
+
char *asString = PyByteArray_AsString(string);
|
|
362
|
+
if (unlikely(!asString)) return -1;
|
|
363
|
+
asString[i] = (char)v;
|
|
364
|
+
#else
|
|
365
|
+
PyByteArray_AS_STRING(string)[i] = (char) v;
|
|
366
|
+
#endif
|
|
367
|
+
return 0;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
//////////////////// GetItemIntUnicode.proto ////////////////////
|
|
373
|
+
|
|
374
|
+
#define __Pyx_GetItemInt_Unicode(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
|
|
375
|
+
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
|
|
376
|
+
__Pyx_GetItemInt_Unicode_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
|
|
377
|
+
(PyErr_SetString(PyExc_IndexError, "string index out of range"), (Py_UCS4)-1))
|
|
378
|
+
|
|
379
|
+
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i,
|
|
380
|
+
int wraparound, int boundscheck);
|
|
381
|
+
|
|
382
|
+
//////////////////// GetItemIntUnicode ////////////////////
|
|
383
|
+
|
|
384
|
+
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i,
|
|
385
|
+
int wraparound, int boundscheck) {
|
|
386
|
+
Py_ssize_t length;
|
|
387
|
+
if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return (Py_UCS4)-1;
|
|
388
|
+
if (wraparound | boundscheck) {
|
|
389
|
+
length = __Pyx_PyUnicode_GET_LENGTH(ustring);
|
|
390
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
391
|
+
if (unlikely(length < 0)) return (Py_UCS4)-1;
|
|
392
|
+
#endif
|
|
393
|
+
if (wraparound & unlikely(i < 0)) i += length;
|
|
394
|
+
if ((!boundscheck) || likely(__Pyx_is_valid_index(i, length))) {
|
|
395
|
+
return __Pyx_PyUnicode_READ_CHAR(ustring, i);
|
|
396
|
+
} else {
|
|
397
|
+
PyErr_SetString(PyExc_IndexError, "string index out of range");
|
|
398
|
+
return (Py_UCS4)-1;
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
return __Pyx_PyUnicode_READ_CHAR(ustring, i);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
/////////////// decode_c_string_utf16.proto ///////////////
|
|
407
|
+
|
|
408
|
+
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) {
|
|
409
|
+
int byteorder = 0;
|
|
410
|
+
return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
|
|
411
|
+
}
|
|
412
|
+
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) {
|
|
413
|
+
int byteorder = -1;
|
|
414
|
+
return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
|
|
415
|
+
}
|
|
416
|
+
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) {
|
|
417
|
+
int byteorder = 1;
|
|
418
|
+
return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/////////////// decode_cpp_string.proto ///////////////
|
|
422
|
+
//@requires: IncludeCppStringH
|
|
423
|
+
//@requires: decode_c_bytes
|
|
424
|
+
|
|
425
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_cpp_string(
|
|
426
|
+
std::string cppstring, Py_ssize_t start, Py_ssize_t stop,
|
|
427
|
+
const char* encoding, const char* errors,
|
|
428
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
|
|
429
|
+
return __Pyx_decode_c_bytes(
|
|
430
|
+
cppstring.data(), cppstring.size(), start, stop, encoding, errors, decode_func);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/////////////// decode_cpp_string_view.proto ///////////////
|
|
434
|
+
//@requires: IncludeCppStringViewH
|
|
435
|
+
//@requires: decode_c_bytes
|
|
436
|
+
|
|
437
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_cpp_string_view(
|
|
438
|
+
std::string_view cppstring, Py_ssize_t start, Py_ssize_t stop,
|
|
439
|
+
const char* encoding, const char* errors,
|
|
440
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
|
|
441
|
+
return __Pyx_decode_c_bytes(
|
|
442
|
+
cppstring.data(), cppstring.size(), start, stop, encoding, errors, decode_func);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/////////////// decode_c_string.proto ///////////////
|
|
446
|
+
|
|
447
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
|
|
448
|
+
const char* cstring, Py_ssize_t start, Py_ssize_t stop,
|
|
449
|
+
const char* encoding, const char* errors,
|
|
450
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
|
|
451
|
+
|
|
452
|
+
/////////////// decode_c_string ///////////////
|
|
453
|
+
//@requires: IncludeStringH
|
|
454
|
+
//@requires: decode_c_string_utf16
|
|
455
|
+
|
|
456
|
+
/* duplicate code to avoid calling strlen() if start >= 0 and stop >= 0 */
|
|
457
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
|
|
458
|
+
const char* cstring, Py_ssize_t start, Py_ssize_t stop,
|
|
459
|
+
const char* encoding, const char* errors,
|
|
460
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
|
|
461
|
+
Py_ssize_t length;
|
|
462
|
+
if (unlikely((start < 0) | (stop < 0))) {
|
|
463
|
+
size_t slen = strlen(cstring);
|
|
464
|
+
if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) {
|
|
465
|
+
PyErr_SetString(PyExc_OverflowError,
|
|
466
|
+
"c-string too long to convert to Python");
|
|
467
|
+
return NULL;
|
|
468
|
+
}
|
|
469
|
+
length = (Py_ssize_t) slen;
|
|
470
|
+
if (start < 0) {
|
|
471
|
+
start += length;
|
|
472
|
+
if (start < 0)
|
|
473
|
+
start = 0;
|
|
474
|
+
}
|
|
475
|
+
if (stop < 0)
|
|
476
|
+
stop += length;
|
|
477
|
+
}
|
|
478
|
+
if (unlikely(stop <= start))
|
|
479
|
+
return __Pyx_NewRef(EMPTY(unicode));
|
|
480
|
+
length = stop - start;
|
|
481
|
+
cstring += start;
|
|
482
|
+
if (decode_func) {
|
|
483
|
+
return decode_func(cstring, length, errors);
|
|
484
|
+
} else {
|
|
485
|
+
return PyUnicode_Decode(cstring, length, encoding, errors);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/////////////// decode_c_bytes.proto ///////////////
|
|
490
|
+
|
|
491
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_c_bytes(
|
|
492
|
+
const char* cstring, Py_ssize_t length, Py_ssize_t start, Py_ssize_t stop,
|
|
493
|
+
const char* encoding, const char* errors,
|
|
494
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
|
|
495
|
+
|
|
496
|
+
/////////////// decode_c_bytes ///////////////
|
|
497
|
+
//@requires: decode_c_string_utf16
|
|
498
|
+
|
|
499
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_c_bytes(
|
|
500
|
+
const char* cstring, Py_ssize_t length, Py_ssize_t start, Py_ssize_t stop,
|
|
501
|
+
const char* encoding, const char* errors,
|
|
502
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
|
|
503
|
+
if (unlikely((start < 0) | (stop < 0))) {
|
|
504
|
+
if (start < 0) {
|
|
505
|
+
start += length;
|
|
506
|
+
if (start < 0)
|
|
507
|
+
start = 0;
|
|
508
|
+
}
|
|
509
|
+
if (stop < 0)
|
|
510
|
+
stop += length;
|
|
511
|
+
}
|
|
512
|
+
if (stop > length)
|
|
513
|
+
stop = length;
|
|
514
|
+
if (unlikely(stop <= start))
|
|
515
|
+
return __Pyx_NewRef(EMPTY(unicode));
|
|
516
|
+
length = stop - start;
|
|
517
|
+
cstring += start;
|
|
518
|
+
if (decode_func) {
|
|
519
|
+
return decode_func(cstring, length, errors);
|
|
520
|
+
} else {
|
|
521
|
+
return PyUnicode_Decode(cstring, length, encoding, errors);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/////////////// decode_bytes.proto ///////////////
|
|
526
|
+
//@requires: decode_c_bytes
|
|
527
|
+
|
|
528
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_bytes(
|
|
529
|
+
PyObject* string, Py_ssize_t start, Py_ssize_t stop,
|
|
530
|
+
const char* encoding, const char* errors,
|
|
531
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
|
|
532
|
+
char* as_c_string;
|
|
533
|
+
Py_ssize_t size;
|
|
534
|
+
#if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
535
|
+
as_c_string = PyBytes_AS_STRING(string);
|
|
536
|
+
size = PyBytes_GET_SIZE(string);
|
|
537
|
+
#else
|
|
538
|
+
if (PyBytes_AsStringAndSize(string, &as_c_string, &size) < 0) {
|
|
539
|
+
return NULL;
|
|
540
|
+
}
|
|
541
|
+
#endif
|
|
542
|
+
return __Pyx_decode_c_bytes(
|
|
543
|
+
as_c_string, size,
|
|
544
|
+
start, stop, encoding, errors, decode_func);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/////////////// decode_bytearray.proto ///////////////
|
|
548
|
+
//@requires: decode_c_bytes
|
|
549
|
+
|
|
550
|
+
static CYTHON_INLINE PyObject* __Pyx_decode_bytearray(
|
|
551
|
+
PyObject* string, Py_ssize_t start, Py_ssize_t stop,
|
|
552
|
+
const char* encoding, const char* errors,
|
|
553
|
+
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
|
|
554
|
+
char* as_c_string;
|
|
555
|
+
Py_ssize_t size;
|
|
556
|
+
#if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
557
|
+
as_c_string = PyByteArray_AS_STRING(string);
|
|
558
|
+
size = PyByteArray_GET_SIZE(string);
|
|
559
|
+
#else
|
|
560
|
+
if (!(as_c_string = PyByteArray_AsString(string))) return NULL;
|
|
561
|
+
if ((size = PyByteArray_Size(string)) < 0) return NULL;
|
|
562
|
+
#endif
|
|
563
|
+
return __Pyx_decode_c_bytes(
|
|
564
|
+
as_c_string, size,
|
|
565
|
+
start, stop, encoding, errors, decode_func);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/////////////// PyUnicode_Substring.proto ///////////////
|
|
569
|
+
|
|
570
|
+
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring(
|
|
571
|
+
PyObject* text, Py_ssize_t start, Py_ssize_t stop);
|
|
572
|
+
|
|
573
|
+
/////////////// PyUnicode_Substring ///////////////
|
|
574
|
+
|
|
575
|
+
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring(
|
|
576
|
+
PyObject* text, Py_ssize_t start, Py_ssize_t stop) {
|
|
577
|
+
Py_ssize_t length;
|
|
578
|
+
#if !CYTHON_COMPILING_IN_LIMITED_API
|
|
579
|
+
if (unlikely(__Pyx_PyUnicode_READY(text) == -1)) return NULL;
|
|
580
|
+
#endif
|
|
581
|
+
length = __Pyx_PyUnicode_GET_LENGTH(text);
|
|
582
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
583
|
+
if (unlikely(length < 0)) return NULL;
|
|
584
|
+
#endif
|
|
585
|
+
if (start < 0) {
|
|
586
|
+
start += length;
|
|
587
|
+
if (start < 0)
|
|
588
|
+
start = 0;
|
|
589
|
+
}
|
|
590
|
+
if (stop < 0)
|
|
591
|
+
stop += length;
|
|
592
|
+
else if (stop > length)
|
|
593
|
+
stop = length;
|
|
594
|
+
if (stop <= start)
|
|
595
|
+
return __Pyx_NewRef(EMPTY(unicode));
|
|
596
|
+
if (start == 0 && stop == length)
|
|
597
|
+
return __Pyx_NewRef(text);
|
|
598
|
+
#if CYTHON_COMPILING_IN_LIMITED_API
|
|
599
|
+
// PyUnicode_Substring() does not support negative indexing but is otherwise fine to use.
|
|
600
|
+
return PyUnicode_Substring(text, start, stop);
|
|
601
|
+
#else
|
|
602
|
+
return PyUnicode_FromKindAndData(PyUnicode_KIND(text),
|
|
603
|
+
PyUnicode_1BYTE_DATA(text) + start*PyUnicode_KIND(text), stop-start);
|
|
604
|
+
#endif
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/////////////// py_unicode_predicate.proto ///////////////
|
|
608
|
+
|
|
609
|
+
// isprintable() is lacking C-API support in PyPy
|
|
610
|
+
#if CYTHON_COMPILING_IN_LIMITED_API{{if method_name == 'isprintable'}} || (CYTHON_COMPILING_IN_PYPY && !defined(Py_UNICODE_ISPRINTABLE)){{endif}}
|
|
611
|
+
static int __Pyx_Py_UNICODE_{{method_name.upper()}}(Py_UCS4 uchar);/*proto*/
|
|
612
|
+
#else
|
|
613
|
+
{{if method_name == 'istitle'}}
|
|
614
|
+
// Py_UNICODE_ISTITLE() doesn't match unicode.istitle() as the latter
|
|
615
|
+
// additionally allows character that comply with Py_UNICODE_ISUPPER()
|
|
616
|
+
static CYTHON_INLINE int __Pyx_Py_UNICODE_ISTITLE(Py_UCS4 uchar) {
|
|
617
|
+
return Py_UNICODE_ISTITLE(uchar) || Py_UNICODE_ISUPPER(uchar);
|
|
618
|
+
}
|
|
619
|
+
{{else}}
|
|
620
|
+
#define __Pyx_Py_UNICODE_{{method_name.upper()}}(u) Py_UNICODE_{{method_name.upper()}}(u)
|
|
621
|
+
{{endif}}
|
|
622
|
+
#endif
|
|
623
|
+
|
|
624
|
+
/////////////// py_unicode_predicate ///////////////
|
|
625
|
+
|
|
626
|
+
{{py:
|
|
627
|
+
from operator import methodcaller
|
|
628
|
+
|
|
629
|
+
char_matches_unicode_type = methodcaller(method_name)
|
|
630
|
+
|
|
631
|
+
def first_nonascii_chr(method_name, _matches=char_matches_unicode_type):
|
|
632
|
+
from sys import maxunicode
|
|
633
|
+
|
|
634
|
+
for code_point in range(128, maxunicode):
|
|
635
|
+
if _matches(chr(code_point)):
|
|
636
|
+
return code_point
|
|
637
|
+
return maxunicode
|
|
638
|
+
|
|
639
|
+
def format_chr_for_c(i):
|
|
640
|
+
c = chr(i)
|
|
641
|
+
if c == "'":
|
|
642
|
+
return r"(Py_UCS4)'\''"
|
|
643
|
+
if c == '\\':
|
|
644
|
+
return r"(Py_UCS4)'\\'"
|
|
645
|
+
if c.isprintable():
|
|
646
|
+
return f"(Py_UCS4)'{c}'"
|
|
647
|
+
return str(i)
|
|
648
|
+
}}
|
|
649
|
+
|
|
650
|
+
#if CYTHON_COMPILING_IN_LIMITED_API{{if method_name == 'isprintable'}} || (CYTHON_COMPILING_IN_PYPY && !defined(Py_UNICODE_ISPRINTABLE)){{endif}}
|
|
651
|
+
static int __Pyx_Py_UNICODE_{{method_name.upper()}}(Py_UCS4 uchar) {
|
|
652
|
+
int result;
|
|
653
|
+
PyObject *py_result, *ustring;
|
|
654
|
+
// Add a fast path for ascii - the switch statements get prohibitively big if we try to include
|
|
655
|
+
// all of unicode.
|
|
656
|
+
if (uchar < {{first_nonascii_chr(method_name)}}) {
|
|
657
|
+
switch (uchar) {
|
|
658
|
+
{{for i in range(128):}}
|
|
659
|
+
{{if char_matches_unicode_type(chr(i)) }}
|
|
660
|
+
case {{format_chr_for_c(i)}}:
|
|
661
|
+
{{endif}}
|
|
662
|
+
{{endfor}}
|
|
663
|
+
return 1;
|
|
664
|
+
}
|
|
665
|
+
return 0;
|
|
666
|
+
}
|
|
667
|
+
ustring = PyUnicode_FromOrdinal(uchar);
|
|
668
|
+
if (!ustring) goto bad;
|
|
669
|
+
py_result = PyObject_CallMethod(ustring, "{{method_name}}", NULL);
|
|
670
|
+
Py_DECREF(ustring);
|
|
671
|
+
if (!py_result) goto bad;
|
|
672
|
+
result = PyObject_IsTrue(py_result);
|
|
673
|
+
Py_DECREF(py_result);
|
|
674
|
+
if (result == -1) goto bad;
|
|
675
|
+
return result != 0;
|
|
676
|
+
|
|
677
|
+
bad:
|
|
678
|
+
PyErr_Clear();
|
|
679
|
+
return 0; /* cannot fail */
|
|
680
|
+
}
|
|
681
|
+
#endif
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
/////////////// unicode_tailmatch.proto ///////////////
|
|
685
|
+
|
|
686
|
+
static int __Pyx_PyUnicode_Tailmatch(
|
|
687
|
+
PyObject* s, PyObject* substr, Py_ssize_t start, Py_ssize_t end, int direction); /*proto*/
|
|
688
|
+
|
|
689
|
+
/////////////// unicode_tailmatch ///////////////
|
|
690
|
+
|
|
691
|
+
// Python's unicode.startswith() and unicode.endswith() support a
|
|
692
|
+
// tuple of prefixes/suffixes, whereas it's much more common to
|
|
693
|
+
// test for a single unicode string.
|
|
694
|
+
|
|
695
|
+
static int __Pyx_PyUnicode_TailmatchTuple(PyObject* s, PyObject* substrings,
|
|
696
|
+
Py_ssize_t start, Py_ssize_t end, int direction) {
|
|
697
|
+
Py_ssize_t i, count = __Pyx_PyTuple_GET_SIZE(substrings);
|
|
698
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
699
|
+
if (unlikely(count < 0)) return -1;
|
|
700
|
+
#endif
|
|
701
|
+
for (i = 0; i < count; i++) {
|
|
702
|
+
Py_ssize_t result;
|
|
703
|
+
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
|
|
704
|
+
result = PyUnicode_Tailmatch(s, PyTuple_GET_ITEM(substrings, i),
|
|
705
|
+
start, end, direction);
|
|
706
|
+
#else
|
|
707
|
+
PyObject* sub = __Pyx_PySequence_ITEM(substrings, i);
|
|
708
|
+
if (unlikely(!sub)) return -1;
|
|
709
|
+
result = PyUnicode_Tailmatch(s, sub, start, end, direction);
|
|
710
|
+
Py_DECREF(sub);
|
|
711
|
+
#endif
|
|
712
|
+
if (result) {
|
|
713
|
+
return (int) result;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return 0;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
static int __Pyx_PyUnicode_Tailmatch(PyObject* s, PyObject* substr,
|
|
720
|
+
Py_ssize_t start, Py_ssize_t end, int direction) {
|
|
721
|
+
if (unlikely(PyTuple_Check(substr))) {
|
|
722
|
+
return __Pyx_PyUnicode_TailmatchTuple(s, substr, start, end, direction);
|
|
723
|
+
}
|
|
724
|
+
return (int) PyUnicode_Tailmatch(s, substr, start, end, direction);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
/////////////// bytes_tailmatch.proto ///////////////
|
|
729
|
+
|
|
730
|
+
static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg,
|
|
731
|
+
Py_ssize_t start, Py_ssize_t end, int direction); /*proto*/
|
|
732
|
+
static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr,
|
|
733
|
+
Py_ssize_t start, Py_ssize_t end, int direction); /*proto*/
|
|
734
|
+
|
|
735
|
+
/////////////// bytes_tailmatch ///////////////
|
|
736
|
+
|
|
737
|
+
static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg,
|
|
738
|
+
Py_ssize_t start, Py_ssize_t end, int direction) {
|
|
739
|
+
char* self_ptr;
|
|
740
|
+
Py_ssize_t self_len;
|
|
741
|
+
char* sub_ptr;
|
|
742
|
+
Py_ssize_t sub_len;
|
|
743
|
+
int retval;
|
|
744
|
+
|
|
745
|
+
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030b0000
|
|
746
|
+
PyObject *converted_arg = NULL;
|
|
747
|
+
#else
|
|
748
|
+
Py_buffer view;
|
|
749
|
+
view.obj = NULL;
|
|
750
|
+
#endif
|
|
751
|
+
|
|
752
|
+
#if !(CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE)
|
|
753
|
+
if (PyBytes_AsStringAndSize(self, &self_ptr, &self_len) == -1) return -1;
|
|
754
|
+
#else
|
|
755
|
+
self_ptr = PyBytes_AS_STRING(self);
|
|
756
|
+
self_len = PyBytes_GET_SIZE(self);
|
|
757
|
+
#endif
|
|
758
|
+
|
|
759
|
+
if (PyBytes_Check(arg)) {
|
|
760
|
+
#if !(CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE)
|
|
761
|
+
if (PyBytes_AsStringAndSize(arg, &sub_ptr, &sub_len) == -1) return -1;
|
|
762
|
+
#else
|
|
763
|
+
sub_ptr = PyBytes_AS_STRING(arg);
|
|
764
|
+
sub_len = PyBytes_GET_SIZE(arg);
|
|
765
|
+
#endif
|
|
766
|
+
}
|
|
767
|
+
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030b0000
|
|
768
|
+
else if (PyByteArray_Check(arg)) {
|
|
769
|
+
// The Limited API fallback is inefficient,
|
|
770
|
+
// so special-case bytearray to be a bit faster. Keep this to the Limited
|
|
771
|
+
// API only since the buffer protocol code is good enough otherwise.
|
|
772
|
+
sub_ptr = PyByteArray_AsString(arg);
|
|
773
|
+
if (unlikely(!sub_ptr)) return -1;
|
|
774
|
+
sub_len = PyByteArray_Size(arg);
|
|
775
|
+
if (unlikely(sub_len < 0)) return -1;
|
|
776
|
+
} else {
|
|
777
|
+
// Where buffer protocol is unavailable, just convert to bytes
|
|
778
|
+
// (which is probably inefficient, but does work)
|
|
779
|
+
// First check that the object is a buffer (since PyBytes_FromObject)
|
|
780
|
+
// is more flexible than what endswith accepts.
|
|
781
|
+
PyObject *as_memoryview = PyMemoryView_FromObject(arg);
|
|
782
|
+
if (!as_memoryview) return -1;
|
|
783
|
+
Py_DECREF(as_memoryview);
|
|
784
|
+
converted_arg = PyBytes_FromObject(arg);
|
|
785
|
+
if (!converted_arg) return -1;
|
|
786
|
+
if (PyBytes_AsStringAndSize(converted_arg, &sub_ptr, &sub_len) == -1) {
|
|
787
|
+
Py_DECREF(converted_arg);
|
|
788
|
+
return -1;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
}
|
|
792
|
+
#else // LIMITED_API >= 030B0000 or !LIMITED_API
|
|
793
|
+
else {
|
|
794
|
+
if (unlikely(PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) == -1))
|
|
795
|
+
return -1;
|
|
796
|
+
sub_ptr = (char*) view.buf;
|
|
797
|
+
sub_len = view.len;
|
|
798
|
+
}
|
|
799
|
+
#endif
|
|
800
|
+
|
|
801
|
+
if (end > self_len)
|
|
802
|
+
end = self_len;
|
|
803
|
+
else if (end < 0)
|
|
804
|
+
end += self_len;
|
|
805
|
+
if (end < 0)
|
|
806
|
+
end = 0;
|
|
807
|
+
if (start < 0)
|
|
808
|
+
start += self_len;
|
|
809
|
+
if (start < 0)
|
|
810
|
+
start = 0;
|
|
811
|
+
|
|
812
|
+
if (direction > 0) {
|
|
813
|
+
/* endswith */
|
|
814
|
+
if (end-sub_len > start)
|
|
815
|
+
start = end - sub_len;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
if (start + sub_len <= end)
|
|
819
|
+
retval = !memcmp(self_ptr+start, sub_ptr, (size_t)sub_len);
|
|
820
|
+
else
|
|
821
|
+
retval = 0;
|
|
822
|
+
|
|
823
|
+
#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030b0000
|
|
824
|
+
Py_XDECREF(converted_arg);
|
|
825
|
+
#else
|
|
826
|
+
if (view.obj)
|
|
827
|
+
PyBuffer_Release(&view);
|
|
828
|
+
#endif
|
|
829
|
+
|
|
830
|
+
return retval;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
static int __Pyx_PyBytes_TailmatchTuple(PyObject* self, PyObject* substrings,
|
|
834
|
+
Py_ssize_t start, Py_ssize_t end, int direction) {
|
|
835
|
+
Py_ssize_t i, count = __Pyx_PyTuple_GET_SIZE(substrings);
|
|
836
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
837
|
+
if (unlikely(count < 0)) return -1;
|
|
838
|
+
#endif
|
|
839
|
+
for (i = 0; i < count; i++) {
|
|
840
|
+
int result;
|
|
841
|
+
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
|
|
842
|
+
result = __Pyx_PyBytes_SingleTailmatch(self, PyTuple_GET_ITEM(substrings, i),
|
|
843
|
+
start, end, direction);
|
|
844
|
+
#else
|
|
845
|
+
PyObject* sub = __Pyx_PySequence_ITEM(substrings, i);
|
|
846
|
+
if (unlikely(!sub)) return -1;
|
|
847
|
+
result = __Pyx_PyBytes_SingleTailmatch(self, sub, start, end, direction);
|
|
848
|
+
Py_DECREF(sub);
|
|
849
|
+
#endif
|
|
850
|
+
if (result) {
|
|
851
|
+
return result;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return 0;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr,
|
|
858
|
+
Py_ssize_t start, Py_ssize_t end, int direction) {
|
|
859
|
+
if (unlikely(PyTuple_Check(substr))) {
|
|
860
|
+
return __Pyx_PyBytes_TailmatchTuple(self, substr, start, end, direction);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
return __Pyx_PyBytes_SingleTailmatch(self, substr, start, end, direction);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
/////////////// bytes_index.proto ///////////////
|
|
868
|
+
|
|
869
|
+
static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t index, int check_bounds); /*proto*/
|
|
870
|
+
|
|
871
|
+
/////////////// bytes_index ///////////////
|
|
872
|
+
|
|
873
|
+
static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t index, int check_bounds) {
|
|
874
|
+
const char *asString;
|
|
875
|
+
if (index < 0) {
|
|
876
|
+
Py_ssize_t size = __Pyx_PyBytes_GET_SIZE(bytes);
|
|
877
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
878
|
+
if (unlikely(size < 0)) return (char) -1;
|
|
879
|
+
#endif
|
|
880
|
+
index += size;
|
|
881
|
+
}
|
|
882
|
+
if (check_bounds) {
|
|
883
|
+
Py_ssize_t size = __Pyx_PyBytes_GET_SIZE(bytes);
|
|
884
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
885
|
+
if (unlikely(size < 0)) return (char) -1;
|
|
886
|
+
#endif
|
|
887
|
+
if (unlikely(!__Pyx_is_valid_index(index, size))) {
|
|
888
|
+
PyErr_SetString(PyExc_IndexError, "string index out of range");
|
|
889
|
+
return (char) -1;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
asString = __Pyx_PyBytes_AsString(bytes);
|
|
893
|
+
#if !CYTHON_ASSUME_SAFE_MACROS
|
|
894
|
+
if (unlikely(!asString)) return (char)-1;
|
|
895
|
+
#endif
|
|
896
|
+
return asString[index];
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
//////////////////// StringJoin.proto ////////////////////
|
|
901
|
+
|
|
902
|
+
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values); /*proto*/
|
|
903
|
+
|
|
904
|
+
//////////////////// StringJoin ////////////////////
|
|
905
|
+
//@requires: ObjectHandling.c::PyObjectCallMethod1
|
|
906
|
+
|
|
907
|
+
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
|
|
908
|
+
// avoid unused function
|
|
909
|
+
(void) __Pyx_PyObject_CallMethod1;
|
|
910
|
+
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030e0000 || defined(PyBytes_Join)
|
|
911
|
+
return PyBytes_Join(sep, values);
|
|
912
|
+
#elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 || defined(_PyBytes_Join)
|
|
913
|
+
return _PyBytes_Join(sep, values);
|
|
914
|
+
#else
|
|
915
|
+
return __Pyx_PyObject_CallMethod1(sep, PYIDENT("join"), values);
|
|
916
|
+
#endif
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
/////////////// JoinPyUnicode.proto ///////////////
|
|
921
|
+
|
|
922
|
+
static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength,
|
|
923
|
+
Py_UCS4 max_char);
|
|
924
|
+
|
|
925
|
+
/////////////// JoinPyUnicode ///////////////
|
|
926
|
+
//@requires: IncludeStringH
|
|
927
|
+
|
|
928
|
+
static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength,
|
|
929
|
+
Py_UCS4 max_char) {
|
|
930
|
+
#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
|
|
931
|
+
PyObject *result_uval;
|
|
932
|
+
int result_ukind, kind_shift;
|
|
933
|
+
Py_ssize_t i, char_pos;
|
|
934
|
+
void *result_udata;
|
|
935
|
+
|
|
936
|
+
if (max_char > 1114111) max_char = 1114111;
|
|
937
|
+
result_uval = PyUnicode_New(result_ulength, max_char);
|
|
938
|
+
if (unlikely(!result_uval)) return NULL;
|
|
939
|
+
result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
|
|
940
|
+
kind_shift = (result_ukind == PyUnicode_4BYTE_KIND) ? 2 : result_ukind - 1;
|
|
941
|
+
result_udata = PyUnicode_DATA(result_uval);
|
|
942
|
+
assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0);
|
|
943
|
+
|
|
944
|
+
if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - result_ulength < 0))
|
|
945
|
+
goto overflow;
|
|
946
|
+
|
|
947
|
+
char_pos = 0;
|
|
948
|
+
for (i=0; i < value_count; i++) {
|
|
949
|
+
int ukind;
|
|
950
|
+
Py_ssize_t ulength;
|
|
951
|
+
void *udata;
|
|
952
|
+
PyObject *uval = values[i];
|
|
953
|
+
#if !CYTHON_COMPILING_IN_LIMITED_API
|
|
954
|
+
if (__Pyx_PyUnicode_READY(uval) == (-1))
|
|
955
|
+
goto bad;
|
|
956
|
+
#endif
|
|
957
|
+
ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
|
|
958
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
959
|
+
if (unlikely(ulength < 0)) goto bad;
|
|
960
|
+
#endif
|
|
961
|
+
if (unlikely(!ulength))
|
|
962
|
+
continue;
|
|
963
|
+
if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos))
|
|
964
|
+
goto overflow;
|
|
965
|
+
ukind = __Pyx_PyUnicode_KIND(uval);
|
|
966
|
+
udata = __Pyx_PyUnicode_DATA(uval);
|
|
967
|
+
if (ukind == result_ukind) {
|
|
968
|
+
memcpy((char *)result_udata + (char_pos << kind_shift), udata, (size_t) (ulength << kind_shift));
|
|
969
|
+
} else {
|
|
970
|
+
#if PY_VERSION_HEX >= 0x030d0000
|
|
971
|
+
if (unlikely(PyUnicode_CopyCharacters(result_uval, char_pos, uval, 0, ulength) < 0)) goto bad;
|
|
972
|
+
#elif CYTHON_COMPILING_IN_CPYTHON || defined(_PyUnicode_FastCopyCharacters)
|
|
973
|
+
_PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
|
|
974
|
+
#else
|
|
975
|
+
Py_ssize_t j;
|
|
976
|
+
for (j=0; j < ulength; j++) {
|
|
977
|
+
Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
|
|
978
|
+
__Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
|
|
979
|
+
}
|
|
980
|
+
#endif
|
|
981
|
+
}
|
|
982
|
+
char_pos += ulength;
|
|
983
|
+
}
|
|
984
|
+
return result_uval;
|
|
985
|
+
overflow:
|
|
986
|
+
PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
|
|
987
|
+
bad:
|
|
988
|
+
Py_DECREF(result_uval);
|
|
989
|
+
return NULL;
|
|
990
|
+
#else
|
|
991
|
+
// non-CPython fallback
|
|
992
|
+
Py_ssize_t i;
|
|
993
|
+
PyObject *result = NULL;
|
|
994
|
+
PyObject *value_tuple = PyTuple_New(value_count);
|
|
995
|
+
if (unlikely(!value_tuple)) return NULL;
|
|
996
|
+
CYTHON_UNUSED_VAR(max_char);
|
|
997
|
+
CYTHON_UNUSED_VAR(result_ulength);
|
|
998
|
+
|
|
999
|
+
for (i=0; i<value_count; i++) {
|
|
1000
|
+
if (__Pyx_PyTuple_SET_ITEM(value_tuple, i, values[i]) != (0)) goto bad;
|
|
1001
|
+
Py_INCREF(values[i]);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
result = PyUnicode_Join(EMPTY(unicode), value_tuple);
|
|
1005
|
+
|
|
1006
|
+
bad:
|
|
1007
|
+
Py_DECREF(value_tuple);
|
|
1008
|
+
return result;
|
|
1009
|
+
#endif
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
/////////////// BuildPyUnicode.proto ///////////////
|
|
1014
|
+
|
|
1015
|
+
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, const char* chars, int clength,
|
|
1016
|
+
int prepend_sign, char padding_char);
|
|
1017
|
+
|
|
1018
|
+
/////////////// BuildPyUnicode ///////////////
|
|
1019
|
+
|
|
1020
|
+
// Create a PyUnicode object from an ASCII char*, e.g. a formatted number.
|
|
1021
|
+
|
|
1022
|
+
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, const char* chars, int clength,
|
|
1023
|
+
int prepend_sign, char padding_char) {
|
|
1024
|
+
PyObject *uval;
|
|
1025
|
+
Py_ssize_t uoffset = ulength - clength;
|
|
1026
|
+
#if CYTHON_USE_UNICODE_INTERNALS
|
|
1027
|
+
Py_ssize_t i;
|
|
1028
|
+
void *udata;
|
|
1029
|
+
uval = PyUnicode_New(ulength, 127);
|
|
1030
|
+
if (unlikely(!uval)) return NULL;
|
|
1031
|
+
udata = PyUnicode_DATA(uval);
|
|
1032
|
+
if (uoffset > 0) {
|
|
1033
|
+
i = 0;
|
|
1034
|
+
if (prepend_sign) {
|
|
1035
|
+
__Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
|
|
1036
|
+
i++;
|
|
1037
|
+
}
|
|
1038
|
+
for (; i < uoffset; i++) {
|
|
1039
|
+
__Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
for (i=0; i < clength; i++) {
|
|
1043
|
+
__Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
#else
|
|
1047
|
+
// non-CPython
|
|
1048
|
+
{
|
|
1049
|
+
PyObject *sign = NULL, *padding = NULL;
|
|
1050
|
+
uval = NULL;
|
|
1051
|
+
if (uoffset > 0) {
|
|
1052
|
+
prepend_sign = !!prepend_sign;
|
|
1053
|
+
if (uoffset > prepend_sign) {
|
|
1054
|
+
padding = PyUnicode_FromOrdinal(padding_char);
|
|
1055
|
+
if (likely(padding) && uoffset > prepend_sign + 1) {
|
|
1056
|
+
PyObject *tmp = PySequence_Repeat(padding, uoffset - prepend_sign);
|
|
1057
|
+
Py_DECREF(padding);
|
|
1058
|
+
padding = tmp;
|
|
1059
|
+
}
|
|
1060
|
+
if (unlikely(!padding)) goto done_or_error;
|
|
1061
|
+
}
|
|
1062
|
+
if (prepend_sign) {
|
|
1063
|
+
sign = PyUnicode_FromOrdinal('-');
|
|
1064
|
+
if (unlikely(!sign)) goto done_or_error;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
uval = PyUnicode_DecodeASCII(chars, clength, NULL);
|
|
1069
|
+
if (likely(uval) && padding) {
|
|
1070
|
+
PyObject *tmp = PyUnicode_Concat(padding, uval);
|
|
1071
|
+
Py_DECREF(uval);
|
|
1072
|
+
uval = tmp;
|
|
1073
|
+
}
|
|
1074
|
+
if (likely(uval) && sign) {
|
|
1075
|
+
PyObject *tmp = PyUnicode_Concat(sign, uval);
|
|
1076
|
+
Py_DECREF(uval);
|
|
1077
|
+
uval = tmp;
|
|
1078
|
+
}
|
|
1079
|
+
done_or_error:
|
|
1080
|
+
Py_XDECREF(padding);
|
|
1081
|
+
Py_XDECREF(sign);
|
|
1082
|
+
}
|
|
1083
|
+
#endif
|
|
1084
|
+
|
|
1085
|
+
return uval;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
//////////////////// ByteArrayAppendObject.proto ////////////////////
|
|
1090
|
+
|
|
1091
|
+
static CYTHON_INLINE int __Pyx_PyByteArray_AppendObject(PyObject* bytearray, PyObject* value);
|
|
1092
|
+
|
|
1093
|
+
//////////////////// ByteArrayAppendObject ////////////////////
|
|
1094
|
+
//@requires: ByteArrayAppend
|
|
1095
|
+
|
|
1096
|
+
static CYTHON_INLINE int __Pyx_PyByteArray_AppendObject(PyObject* bytearray, PyObject* value) {
|
|
1097
|
+
Py_ssize_t ival;
|
|
1098
|
+
#if CYTHON_USE_PYLONG_INTERNALS
|
|
1099
|
+
if (likely(PyLong_CheckExact(value)) && likely(__Pyx_PyLong_IsCompact(value))) {
|
|
1100
|
+
if (__Pyx_PyLong_IsZero(value)) {
|
|
1101
|
+
ival = 0;
|
|
1102
|
+
} else {
|
|
1103
|
+
ival = __Pyx_PyLong_CompactValue(value);
|
|
1104
|
+
if (unlikely(ival > 255)) goto bad_range;
|
|
1105
|
+
}
|
|
1106
|
+
} else
|
|
1107
|
+
#endif
|
|
1108
|
+
{
|
|
1109
|
+
// CPython calls PyNumber_Index() internally
|
|
1110
|
+
ival = __Pyx_PyIndex_AsSsize_t(value);
|
|
1111
|
+
if (unlikely(!__Pyx_is_valid_index(ival, 256))) {
|
|
1112
|
+
if (ival == -1 && PyErr_Occurred())
|
|
1113
|
+
return -1;
|
|
1114
|
+
goto bad_range;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return __Pyx_PyByteArray_Append(bytearray, ival);
|
|
1118
|
+
bad_range:
|
|
1119
|
+
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
|
|
1120
|
+
return -1;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
//////////////////// ByteArrayAppend.proto ////////////////////
|
|
1124
|
+
|
|
1125
|
+
static CYTHON_INLINE int __Pyx_PyByteArray_Append(PyObject* bytearray, int value);
|
|
1126
|
+
|
|
1127
|
+
//////////////////// ByteArrayAppend ////////////////////
|
|
1128
|
+
//@requires: ObjectHandling.c::PyObjectCallMethod1
|
|
1129
|
+
|
|
1130
|
+
static CYTHON_INLINE int __Pyx_PyByteArray_Append(PyObject* bytearray, int value) {
|
|
1131
|
+
PyObject *pyval, *retval;
|
|
1132
|
+
#if CYTHON_COMPILING_IN_CPYTHON
|
|
1133
|
+
if (likely(__Pyx_is_valid_index(value, 256))) {
|
|
1134
|
+
Py_ssize_t n = Py_SIZE(bytearray);
|
|
1135
|
+
if (likely(n != PY_SSIZE_T_MAX)) {
|
|
1136
|
+
if (unlikely(PyByteArray_Resize(bytearray, n + 1) < 0))
|
|
1137
|
+
return -1;
|
|
1138
|
+
PyByteArray_AS_STRING(bytearray)[n] = value;
|
|
1139
|
+
return 0;
|
|
1140
|
+
}
|
|
1141
|
+
} else {
|
|
1142
|
+
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
|
|
1143
|
+
return -1;
|
|
1144
|
+
}
|
|
1145
|
+
#endif
|
|
1146
|
+
pyval = PyLong_FromLong(value);
|
|
1147
|
+
if (unlikely(!pyval))
|
|
1148
|
+
return -1;
|
|
1149
|
+
retval = __Pyx_PyObject_CallMethod1(bytearray, PYIDENT("append"), pyval);
|
|
1150
|
+
Py_DECREF(pyval);
|
|
1151
|
+
if (unlikely(!retval))
|
|
1152
|
+
return -1;
|
|
1153
|
+
Py_DECREF(retval);
|
|
1154
|
+
return 0;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
//////////////////// PyObjectFormat.proto ////////////////////
|
|
1159
|
+
|
|
1160
|
+
#if CYTHON_USE_UNICODE_WRITER
|
|
1161
|
+
static PyObject* __Pyx_PyObject_Format(PyObject* s, PyObject* f);
|
|
1162
|
+
#else
|
|
1163
|
+
#define __Pyx_PyObject_Format(s, f) PyObject_Format(s, f)
|
|
1164
|
+
#endif
|
|
1165
|
+
|
|
1166
|
+
//////////////////// PyObjectFormat ////////////////////
|
|
1167
|
+
|
|
1168
|
+
#if CYTHON_USE_UNICODE_WRITER
|
|
1169
|
+
static PyObject* __Pyx_PyObject_Format(PyObject* obj, PyObject* format_spec) {
|
|
1170
|
+
int ret;
|
|
1171
|
+
_PyUnicodeWriter writer;
|
|
1172
|
+
|
|
1173
|
+
if (likely(PyFloat_CheckExact(obj))) {
|
|
1174
|
+
// copied from CPython 3.5 "float__format__()" in floatobject.c
|
|
1175
|
+
_PyUnicodeWriter_Init(&writer);
|
|
1176
|
+
ret = _PyFloat_FormatAdvancedWriter(
|
|
1177
|
+
&writer,
|
|
1178
|
+
obj,
|
|
1179
|
+
format_spec, 0, PyUnicode_GET_LENGTH(format_spec));
|
|
1180
|
+
} else if (likely(PyLong_CheckExact(obj))) {
|
|
1181
|
+
// copied from CPython 3.5 "long__format__()" in longobject.c
|
|
1182
|
+
_PyUnicodeWriter_Init(&writer);
|
|
1183
|
+
ret = _PyLong_FormatAdvancedWriter(
|
|
1184
|
+
&writer,
|
|
1185
|
+
obj,
|
|
1186
|
+
format_spec, 0, PyUnicode_GET_LENGTH(format_spec));
|
|
1187
|
+
} else {
|
|
1188
|
+
return PyObject_Format(obj, format_spec);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
if (unlikely(ret == -1)) {
|
|
1192
|
+
_PyUnicodeWriter_Dealloc(&writer);
|
|
1193
|
+
return NULL;
|
|
1194
|
+
}
|
|
1195
|
+
return _PyUnicodeWriter_Finish(&writer);
|
|
1196
|
+
}
|
|
1197
|
+
#endif
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
//////////////////// PyObjectFormatSimple.proto ////////////////////
|
|
1201
|
+
|
|
1202
|
+
#if CYTHON_COMPILING_IN_PYPY
|
|
1203
|
+
#define __Pyx_PyObject_FormatSimple(s, f) ( \
|
|
1204
|
+
likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) : \
|
|
1205
|
+
PyObject_Format(s, f))
|
|
1206
|
+
#elif CYTHON_USE_TYPE_SLOTS
|
|
1207
|
+
// Py3 nicely returns unicode strings from str() and repr(), which makes this quite efficient for builtin types.
|
|
1208
|
+
// In Py3.8+, tp_str() delegates to tp_repr(), so we call tp_repr() directly here.
|
|
1209
|
+
#define __Pyx_PyObject_FormatSimple(s, f) ( \
|
|
1210
|
+
likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) : \
|
|
1211
|
+
likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_repr(s) : \
|
|
1212
|
+
likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_repr(s) : \
|
|
1213
|
+
PyObject_Format(s, f))
|
|
1214
|
+
#else
|
|
1215
|
+
#define __Pyx_PyObject_FormatSimple(s, f) ( \
|
|
1216
|
+
likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) : \
|
|
1217
|
+
PyObject_Format(s, f))
|
|
1218
|
+
#endif
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
//////////////////// PyObjectFormatAndDecref.proto ////////////////////
|
|
1222
|
+
|
|
1223
|
+
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f);
|
|
1224
|
+
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f);
|
|
1225
|
+
|
|
1226
|
+
//////////////////// PyObjectFormatAndDecref ////////////////////
|
|
1227
|
+
|
|
1228
|
+
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) {
|
|
1229
|
+
if (unlikely(!s)) return NULL;
|
|
1230
|
+
if (likely(PyUnicode_CheckExact(s))) return s;
|
|
1231
|
+
return __Pyx_PyObject_FormatAndDecref(s, f);
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) {
|
|
1235
|
+
PyObject *result;
|
|
1236
|
+
if (unlikely(!s)) return NULL;
|
|
1237
|
+
result = PyObject_Format(s, f);
|
|
1238
|
+
Py_DECREF(s);
|
|
1239
|
+
return result;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
//////////////////// PyUnicode_Unicode.proto ////////////////////
|
|
1244
|
+
|
|
1245
|
+
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj);/*proto*/
|
|
1246
|
+
|
|
1247
|
+
//////////////////// PyUnicode_Unicode ////////////////////
|
|
1248
|
+
|
|
1249
|
+
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj) {
|
|
1250
|
+
if (unlikely(obj == Py_None))
|
|
1251
|
+
obj = PYUNICODE("None");
|
|
1252
|
+
return __Pyx_NewRef(obj);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
//////////////////// PyObject_Unicode.proto ////////////////////
|
|
1257
|
+
|
|
1258
|
+
#define __Pyx_PyObject_Unicode(obj) \
|
|
1259
|
+
(likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj))
|