1 /* Generated by Cython 0.29.21 */
2
3 #define PY_SSIZE_T_CLEAN
4 #include "Python.h"
5 #ifndef Py_PYTHON_H
6 #error Python headers needed to compile C extensions, please install development version of Python.
7 #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
8 #error Cython requires Python 2.6+ or Python 3.3+.
9 #else
10 #define CYTHON_ABI "0_29_21"
11 #define CYTHON_HEX_VERSION 0x001D15F0
12 #define CYTHON_FUTURE_DIVISION 1
13 #include <stddef.h>
14 #ifndef offsetof
15 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
16 #endif
17 #if !defined(WIN32) && !defined(MS_WINDOWS)
18 #ifndef __stdcall
19 #define __stdcall
20 #endif
21 #ifndef __cdecl
22 #define __cdecl
23 #endif
24 #ifndef __fastcall
25 #define __fastcall
26 #endif
27 #endif
28 #ifndef DL_IMPORT
29 #define DL_IMPORT(t) t
30 #endif
31 #ifndef DL_EXPORT
32 #define DL_EXPORT(t) t
33 #endif
34 #define __PYX_COMMA ,
35 #ifndef HAVE_LONG_LONG
36 #if PY_VERSION_HEX >= 0x02070000
37 #define HAVE_LONG_LONG
38 #endif
39 #endif
40 #ifndef PY_LONG_LONG
41 #define PY_LONG_LONG LONG_LONG
42 #endif
43 #ifndef Py_HUGE_VAL
44 #define Py_HUGE_VAL HUGE_VAL
45 #endif
46 #ifdef PYPY_VERSION
47 #define CYTHON_COMPILING_IN_PYPY 1
48 #define CYTHON_COMPILING_IN_PYSTON 0
49 #define CYTHON_COMPILING_IN_CPYTHON 0
50 #undef CYTHON_USE_TYPE_SLOTS
51 #define CYTHON_USE_TYPE_SLOTS 0
52 #undef CYTHON_USE_PYTYPE_LOOKUP
53 #define CYTHON_USE_PYTYPE_LOOKUP 0
54 #if PY_VERSION_HEX < 0x03050000
55 #undef CYTHON_USE_ASYNC_SLOTS
56 #define CYTHON_USE_ASYNC_SLOTS 0
57 #elif !defined(CYTHON_USE_ASYNC_SLOTS)
58 #define CYTHON_USE_ASYNC_SLOTS 1
59 #endif
60 #undef CYTHON_USE_PYLIST_INTERNALS
61 #define CYTHON_USE_PYLIST_INTERNALS 0
62 #undef CYTHON_USE_UNICODE_INTERNALS
63 #define CYTHON_USE_UNICODE_INTERNALS 0
64 #undef CYTHON_USE_UNICODE_WRITER
65 #define CYTHON_USE_UNICODE_WRITER 0
66 #undef CYTHON_USE_PYLONG_INTERNALS
67 #define CYTHON_USE_PYLONG_INTERNALS 0
68 #undef CYTHON_AVOID_BORROWED_REFS
69 #define CYTHON_AVOID_BORROWED_REFS 1
70 #undef CYTHON_ASSUME_SAFE_MACROS
71 #define CYTHON_ASSUME_SAFE_MACROS 0
72 #undef CYTHON_UNPACK_METHODS
73 #define CYTHON_UNPACK_METHODS 0
74 #undef CYTHON_FAST_THREAD_STATE
75 #define CYTHON_FAST_THREAD_STATE 0
76 #undef CYTHON_FAST_PYCALL
77 #define CYTHON_FAST_PYCALL 0
78 #undef CYTHON_PEP489_MULTI_PHASE_INIT
79 #define CYTHON_PEP489_MULTI_PHASE_INIT 0
80 #undef CYTHON_USE_TP_FINALIZE
81 #define CYTHON_USE_TP_FINALIZE 0
82 #undef CYTHON_USE_DICT_VERSIONS
83 #define CYTHON_USE_DICT_VERSIONS 0
84 #undef CYTHON_USE_EXC_INFO_STACK
85 #define CYTHON_USE_EXC_INFO_STACK 0
86 #elif defined(PYSTON_VERSION)
87 #define CYTHON_COMPILING_IN_PYPY 0
88 #define CYTHON_COMPILING_IN_PYSTON 1
89 #define CYTHON_COMPILING_IN_CPYTHON 0
90 #ifndef CYTHON_USE_TYPE_SLOTS
91 #define CYTHON_USE_TYPE_SLOTS 1
92 #endif
93 #undef CYTHON_USE_PYTYPE_LOOKUP
94 #define CYTHON_USE_PYTYPE_LOOKUP 0
95 #undef CYTHON_USE_ASYNC_SLOTS
96 #define CYTHON_USE_ASYNC_SLOTS 0
97 #undef CYTHON_USE_PYLIST_INTERNALS
98 #define CYTHON_USE_PYLIST_INTERNALS 0
99 #ifndef CYTHON_USE_UNICODE_INTERNALS
100 #define CYTHON_USE_UNICODE_INTERNALS 1
101 #endif
102 #undef CYTHON_USE_UNICODE_WRITER
103 #define CYTHON_USE_UNICODE_WRITER 0
104 #undef CYTHON_USE_PYLONG_INTERNALS
105 #define CYTHON_USE_PYLONG_INTERNALS 0
106 #ifndef CYTHON_AVOID_BORROWED_REFS
107 #define CYTHON_AVOID_BORROWED_REFS 0
108 #endif
109 #ifndef CYTHON_ASSUME_SAFE_MACROS
110 #define CYTHON_ASSUME_SAFE_MACROS 1
111 #endif
112 #ifndef CYTHON_UNPACK_METHODS
113 #define CYTHON_UNPACK_METHODS 1
114 #endif
115 #undef CYTHON_FAST_THREAD_STATE
116 #define CYTHON_FAST_THREAD_STATE 0
117 #undef CYTHON_FAST_PYCALL
118 #define CYTHON_FAST_PYCALL 0
119 #undef CYTHON_PEP489_MULTI_PHASE_INIT
120 #define CYTHON_PEP489_MULTI_PHASE_INIT 0
121 #undef CYTHON_USE_TP_FINALIZE
122 #define CYTHON_USE_TP_FINALIZE 0
123 #undef CYTHON_USE_DICT_VERSIONS
124 #define CYTHON_USE_DICT_VERSIONS 0
125 #undef CYTHON_USE_EXC_INFO_STACK
126 #define CYTHON_USE_EXC_INFO_STACK 0
127 #else
128 #define CYTHON_COMPILING_IN_PYPY 0
129 #define CYTHON_COMPILING_IN_PYSTON 0
130 #define CYTHON_COMPILING_IN_CPYTHON 1
131 #ifndef CYTHON_USE_TYPE_SLOTS
132 #define CYTHON_USE_TYPE_SLOTS 1
133 #endif
134 #if PY_VERSION_HEX < 0x02070000
135 #undef CYTHON_USE_PYTYPE_LOOKUP
136 #define CYTHON_USE_PYTYPE_LOOKUP 0
137 #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
138 #define CYTHON_USE_PYTYPE_LOOKUP 1
139 #endif
140 #if PY_MAJOR_VERSION < 3
141 #undef CYTHON_USE_ASYNC_SLOTS
142 #define CYTHON_USE_ASYNC_SLOTS 0
143 #elif !defined(CYTHON_USE_ASYNC_SLOTS)
144 #define CYTHON_USE_ASYNC_SLOTS 1
145 #endif
146 #if PY_VERSION_HEX < 0x02070000
147 #undef CYTHON_USE_PYLONG_INTERNALS
148 #define CYTHON_USE_PYLONG_INTERNALS 0
149 #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
150 #define CYTHON_USE_PYLONG_INTERNALS 1
151 #endif
152 #ifndef CYTHON_USE_PYLIST_INTERNALS
153 #define CYTHON_USE_PYLIST_INTERNALS 1
154 #endif
155 #ifndef CYTHON_USE_UNICODE_INTERNALS
156 #define CYTHON_USE_UNICODE_INTERNALS 1
157 #endif
158 #if PY_VERSION_HEX < 0x030300F0
159 #undef CYTHON_USE_UNICODE_WRITER
160 #define CYTHON_USE_UNICODE_WRITER 0
161 #elif !defined(CYTHON_USE_UNICODE_WRITER)
162 #define CYTHON_USE_UNICODE_WRITER 1
163 #endif
164 #ifndef CYTHON_AVOID_BORROWED_REFS
165 #define CYTHON_AVOID_BORROWED_REFS 0
166 #endif
167 #ifndef CYTHON_ASSUME_SAFE_MACROS
168 #define CYTHON_ASSUME_SAFE_MACROS 1
169 #endif
170 #ifndef CYTHON_UNPACK_METHODS
171 #define CYTHON_UNPACK_METHODS 1
172 #endif
173 #ifndef CYTHON_FAST_THREAD_STATE
174 #define CYTHON_FAST_THREAD_STATE 1
175 #endif
176 #ifndef CYTHON_FAST_PYCALL
177 #define CYTHON_FAST_PYCALL 1
178 #endif
179 #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
180 #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
181 #endif
182 #ifndef CYTHON_USE_TP_FINALIZE
183 #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
184 #endif
185 #ifndef CYTHON_USE_DICT_VERSIONS
186 #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
187 #endif
188 #ifndef CYTHON_USE_EXC_INFO_STACK
189 #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
190 #endif
191 #endif
192 #if !defined(CYTHON_FAST_PYCCALL)
193 #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
194 #endif
195 #if CYTHON_USE_PYLONG_INTERNALS
196 #include "longintrepr.h"
197 #undef SHIFT
198 #undef BASE
199 #undef MASK
200 #ifdef SIZEOF_VOID_P
201 enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
202 #endif
203 #endif
204 #ifndef __has_attribute
205 #define __has_attribute(x) 0
206 #endif
207 #ifndef __has_cpp_attribute
208 #define __has_cpp_attribute(x) 0
209 #endif
210 #ifndef CYTHON_RESTRICT
211 #if defined(__GNUC__)
212 #define CYTHON_RESTRICT __restrict__
213 #elif defined(_MSC_VER) && _MSC_VER >= 1400
214 #define CYTHON_RESTRICT __restrict
215 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
216 #define CYTHON_RESTRICT restrict
217 #else
218 #define CYTHON_RESTRICT
219 #endif
220 #endif
221 #ifndef CYTHON_UNUSED
222 # if defined(__GNUC__)
223 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
224 # define CYTHON_UNUSED __attribute__ ((__unused__))
225 # else
226 # define CYTHON_UNUSED
227 # endif
228 # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
229 # define CYTHON_UNUSED __attribute__ ((__unused__))
230 # else
231 # define CYTHON_UNUSED
232 # endif
233 #endif
234 #ifndef CYTHON_MAYBE_UNUSED_VAR
235 # if defined(__cplusplus)
CYTHON_MAYBE_UNUSED_VAR(const T &)236 template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
237 # else
238 # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
239 # endif
240 #endif
241 #ifndef CYTHON_NCP_UNUSED
242 # if CYTHON_COMPILING_IN_CPYTHON
243 # define CYTHON_NCP_UNUSED
244 # else
245 # define CYTHON_NCP_UNUSED CYTHON_UNUSED
246 # endif
247 #endif
248 #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
249 #ifdef _MSC_VER
250 #ifndef _MSC_STDINT_H_
251 #if _MSC_VER < 1300
252 typedef unsigned char uint8_t;
253 typedef unsigned int uint32_t;
254 #else
255 typedef unsigned __int8 uint8_t;
256 typedef unsigned __int32 uint32_t;
257 #endif
258 #endif
259 #else
260 #include <stdint.h>
261 #endif
262 #ifndef CYTHON_FALLTHROUGH
263 #if defined(__cplusplus) && __cplusplus >= 201103L
264 #if __has_cpp_attribute(fallthrough)
265 #define CYTHON_FALLTHROUGH [[fallthrough]]
266 #elif __has_cpp_attribute(clang::fallthrough)
267 #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
268 #elif __has_cpp_attribute(gnu::fallthrough)
269 #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
270 #endif
271 #endif
272 #ifndef CYTHON_FALLTHROUGH
273 #if __has_attribute(fallthrough)
274 #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
275 #else
276 #define CYTHON_FALLTHROUGH
277 #endif
278 #endif
279 #if defined(__clang__ ) && defined(__apple_build_version__)
280 #if __apple_build_version__ < 7000000
281 #undef CYTHON_FALLTHROUGH
282 #define CYTHON_FALLTHROUGH
283 #endif
284 #endif
285 #endif
286
287 #ifndef __cplusplus
288 #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
289 #endif
290 #ifndef CYTHON_INLINE
291 #if defined(__clang__)
292 #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
293 #else
294 #define CYTHON_INLINE inline
295 #endif
296 #endif
297 template<typename T>
__Pyx_call_destructor(T & x)298 void __Pyx_call_destructor(T& x) {
299 x.~T();
300 }
301 template<typename T>
302 class __Pyx_FakeReference {
303 public:
__Pyx_FakeReference()304 __Pyx_FakeReference() : ptr(NULL) { }
__Pyx_FakeReference(const T & ref)305 __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
operator ->()306 T *operator->() { return ptr; }
operator &()307 T *operator&() { return ptr; }
operator T&()308 operator T&() { return *ptr; }
operator ==(U other)309 template<typename U> bool operator ==(U other) { return *ptr == other; }
operator !=(U other)310 template<typename U> bool operator !=(U other) { return *ptr != other; }
311 private:
312 T *ptr;
313 };
314
315 #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
316 #define Py_OptimizeFlag 0
317 #endif
318 #define __PYX_BUILD_PY_SSIZE_T "n"
319 #define CYTHON_FORMAT_SSIZE_T "z"
320 #if PY_MAJOR_VERSION < 3
321 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
322 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
323 PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
324 #define __Pyx_DefaultClassType PyClass_Type
325 #else
326 #define __Pyx_BUILTIN_MODULE_NAME "builtins"
327 #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2
328 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
329 PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
330 #else
331 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
332 PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
333 #endif
334 #define __Pyx_DefaultClassType PyType_Type
335 #endif
336 #ifndef Py_TPFLAGS_CHECKTYPES
337 #define Py_TPFLAGS_CHECKTYPES 0
338 #endif
339 #ifndef Py_TPFLAGS_HAVE_INDEX
340 #define Py_TPFLAGS_HAVE_INDEX 0
341 #endif
342 #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
343 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
344 #endif
345 #ifndef Py_TPFLAGS_HAVE_FINALIZE
346 #define Py_TPFLAGS_HAVE_FINALIZE 0
347 #endif
348 #ifndef METH_STACKLESS
349 #define METH_STACKLESS 0
350 #endif
351 #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
352 #ifndef METH_FASTCALL
353 #define METH_FASTCALL 0x80
354 #endif
355 typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
356 typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
357 Py_ssize_t nargs, PyObject *kwnames);
358 #else
359 #define __Pyx_PyCFunctionFast _PyCFunctionFast
360 #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
361 #endif
362 #if CYTHON_FAST_PYCCALL
363 #define __Pyx_PyFastCFunction_Check(func)\
364 ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
365 #else
366 #define __Pyx_PyFastCFunction_Check(func) 0
367 #endif
368 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
369 #define PyObject_Malloc(s) PyMem_Malloc(s)
370 #define PyObject_Free(p) PyMem_Free(p)
371 #define PyObject_Realloc(p) PyMem_Realloc(p)
372 #endif
373 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
374 #define PyMem_RawMalloc(n) PyMem_Malloc(n)
375 #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n)
376 #define PyMem_RawFree(p) PyMem_Free(p)
377 #endif
378 #if CYTHON_COMPILING_IN_PYSTON
379 #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
380 #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
381 #else
382 #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
383 #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
384 #endif
385 #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
386 #define __Pyx_PyThreadState_Current PyThreadState_GET()
387 #elif PY_VERSION_HEX >= 0x03060000
388 #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
389 #elif PY_VERSION_HEX >= 0x03000000
390 #define __Pyx_PyThreadState_Current PyThreadState_GET()
391 #else
392 #define __Pyx_PyThreadState_Current _PyThreadState_Current
393 #endif
394 #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
395 #include "pythread.h"
396 #define Py_tss_NEEDS_INIT 0
397 typedef int Py_tss_t;
PyThread_tss_create(Py_tss_t * key)398 static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
399 *key = PyThread_create_key();
400 return 0;
401 }
PyThread_tss_alloc(void)402 static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
403 Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
404 *key = Py_tss_NEEDS_INIT;
405 return key;
406 }
PyThread_tss_free(Py_tss_t * key)407 static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
408 PyObject_Free(key);
409 }
PyThread_tss_is_created(Py_tss_t * key)410 static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
411 return *key != Py_tss_NEEDS_INIT;
412 }
PyThread_tss_delete(Py_tss_t * key)413 static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
414 PyThread_delete_key(*key);
415 *key = Py_tss_NEEDS_INIT;
416 }
PyThread_tss_set(Py_tss_t * key,void * value)417 static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
418 return PyThread_set_key_value(*key, value);
419 }
PyThread_tss_get(Py_tss_t * key)420 static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
421 return PyThread_get_key_value(*key);
422 }
423 #endif
424 #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
425 #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
426 #else
427 #define __Pyx_PyDict_NewPresized(n) PyDict_New()
428 #endif
429 #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
430 #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
431 #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
432 #else
433 #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
434 #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
435 #endif
436 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
437 #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
438 #else
439 #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
440 #endif
441 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
442 #define CYTHON_PEP393_ENABLED 1
443 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
444 0 : _PyUnicode_Ready((PyObject *)(op)))
445 #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
446 #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
447 #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
448 #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
449 #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
450 #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
451 #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
452 #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
453 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
454 #else
455 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u))
456 #endif
457 #else
458 #define CYTHON_PEP393_ENABLED 0
459 #define PyUnicode_1BYTE_KIND 1
460 #define PyUnicode_2BYTE_KIND 2
461 #define PyUnicode_4BYTE_KIND 4
462 #define __Pyx_PyUnicode_READY(op) (0)
463 #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
464 #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
465 #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
466 #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
467 #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
468 #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
469 #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
470 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
471 #endif
472 #if CYTHON_COMPILING_IN_PYPY
473 #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
474 #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
475 #else
476 #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
477 #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
478 PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
479 #endif
480 #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
481 #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
482 #endif
483 #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
484 #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
485 #endif
486 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
487 #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
488 #endif
489 #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
490 #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
491 #if PY_MAJOR_VERSION >= 3
492 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
493 #else
494 #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
495 #endif
496 #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
497 #define PyObject_ASCII(o) PyObject_Repr(o)
498 #endif
499 #if PY_MAJOR_VERSION >= 3
500 #define PyBaseString_Type PyUnicode_Type
501 #define PyStringObject PyUnicodeObject
502 #define PyString_Type PyUnicode_Type
503 #define PyString_Check PyUnicode_Check
504 #define PyString_CheckExact PyUnicode_CheckExact
505 #ifndef PyObject_Unicode
506 #define PyObject_Unicode PyObject_Str
507 #endif
508 #endif
509 #if PY_MAJOR_VERSION >= 3
510 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
511 #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
512 #else
513 #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
514 #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
515 #endif
516 #ifndef PySet_CheckExact
517 #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
518 #endif
519 #if PY_VERSION_HEX >= 0x030900A4
520 #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
521 #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
522 #else
523 #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
524 #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
525 #endif
526 #if CYTHON_ASSUME_SAFE_MACROS
527 #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
528 #else
529 #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
530 #endif
531 #if PY_MAJOR_VERSION >= 3
532 #define PyIntObject PyLongObject
533 #define PyInt_Type PyLong_Type
534 #define PyInt_Check(op) PyLong_Check(op)
535 #define PyInt_CheckExact(op) PyLong_CheckExact(op)
536 #define PyInt_FromString PyLong_FromString
537 #define PyInt_FromUnicode PyLong_FromUnicode
538 #define PyInt_FromLong PyLong_FromLong
539 #define PyInt_FromSize_t PyLong_FromSize_t
540 #define PyInt_FromSsize_t PyLong_FromSsize_t
541 #define PyInt_AsLong PyLong_AsLong
542 #define PyInt_AS_LONG PyLong_AS_LONG
543 #define PyInt_AsSsize_t PyLong_AsSsize_t
544 #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
545 #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
546 #define PyNumber_Int PyNumber_Long
547 #endif
548 #if PY_MAJOR_VERSION >= 3
549 #define PyBoolObject PyLongObject
550 #endif
551 #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
552 #ifndef PyUnicode_InternFromString
553 #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
554 #endif
555 #endif
556 #if PY_VERSION_HEX < 0x030200A4
557 typedef long Py_hash_t;
558 #define __Pyx_PyInt_FromHash_t PyInt_FromLong
559 #define __Pyx_PyInt_AsHash_t PyInt_AsLong
560 #else
561 #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
562 #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
563 #endif
564 #if PY_MAJOR_VERSION >= 3
565 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
566 #else
567 #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
568 #endif
569 #if CYTHON_USE_ASYNC_SLOTS
570 #if PY_VERSION_HEX >= 0x030500B1
571 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
572 #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
573 #else
574 #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
575 #endif
576 #else
577 #define __Pyx_PyType_AsAsync(obj) NULL
578 #endif
579 #ifndef __Pyx_PyAsyncMethodsStruct
580 typedef struct {
581 unaryfunc am_await;
582 unaryfunc am_aiter;
583 unaryfunc am_anext;
584 } __Pyx_PyAsyncMethodsStruct;
585 #endif
586
587 #if defined(WIN32) || defined(MS_WINDOWS)
588 #define _USE_MATH_DEFINES
589 #endif
590 #include <math.h>
591 #ifdef NAN
592 #define __PYX_NAN() ((float) NAN)
593 #else
__PYX_NAN()594 static CYTHON_INLINE float __PYX_NAN() {
595 float value;
596 memset(&value, 0xFF, sizeof(value));
597 return value;
598 }
599 #endif
600 #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
601 #define __Pyx_truncl trunc
602 #else
603 #define __Pyx_truncl truncl
604 #endif
605
606 #define __PYX_MARK_ERR_POS(f_index, lineno) \
607 { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
608 #define __PYX_ERR(f_index, lineno, Ln_error) \
609 { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
610
611 #ifndef __PYX_EXTERN_C
612 #ifdef __cplusplus
613 #define __PYX_EXTERN_C extern "C"
614 #else
615 #define __PYX_EXTERN_C extern
616 #endif
617 #endif
618
619 #define __PYX_HAVE__cchardet___cchardet
620 #define __PYX_HAVE_API__cchardet___cchardet
621 /* Early includes */
622 #include "uchardet.h"
623 #ifdef _OPENMP
624 #include <omp.h>
625 #endif /* _OPENMP */
626
627 #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
628 #define CYTHON_WITHOUT_ASSERTIONS
629 #endif
630
631 typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
632 const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
633
634 #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
635 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
636 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
637 #define __PYX_DEFAULT_STRING_ENCODING ""
638 #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
639 #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
640 #define __Pyx_uchar_cast(c) ((unsigned char)c)
641 #define __Pyx_long_cast(x) ((long)x)
642 #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
643 (sizeof(type) < sizeof(Py_ssize_t)) ||\
644 (sizeof(type) > sizeof(Py_ssize_t) &&\
645 likely(v < (type)PY_SSIZE_T_MAX ||\
646 v == (type)PY_SSIZE_T_MAX) &&\
647 (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
648 v == (type)PY_SSIZE_T_MIN))) ||\
649 (sizeof(type) == sizeof(Py_ssize_t) &&\
650 (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
651 v == (type)PY_SSIZE_T_MAX))) )
__Pyx_is_valid_index(Py_ssize_t i,Py_ssize_t limit)652 static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
653 return (size_t) i < (size_t) limit;
654 }
655 #if defined (__cplusplus) && __cplusplus >= 201103L
656 #include <cstdlib>
657 #define __Pyx_sst_abs(value) std::abs(value)
658 #elif SIZEOF_INT >= SIZEOF_SIZE_T
659 #define __Pyx_sst_abs(value) abs(value)
660 #elif SIZEOF_LONG >= SIZEOF_SIZE_T
661 #define __Pyx_sst_abs(value) labs(value)
662 #elif defined (_MSC_VER)
663 #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
664 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
665 #define __Pyx_sst_abs(value) llabs(value)
666 #elif defined (__GNUC__)
667 #define __Pyx_sst_abs(value) __builtin_llabs(value)
668 #else
669 #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
670 #endif
671 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
672 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
673 #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
674 #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
675 #define __Pyx_PyBytes_FromString PyBytes_FromString
676 #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
677 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
678 #if PY_MAJOR_VERSION < 3
679 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
680 #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
681 #else
682 #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
683 #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
684 #endif
685 #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
686 #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
687 #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
688 #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
689 #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
690 #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
691 #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
692 #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
693 #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
694 #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
695 #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
696 #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
697 #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
698 #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
699 #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
700 #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
__Pyx_Py_UNICODE_strlen(const Py_UNICODE * u)701 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
702 const Py_UNICODE *u_end = u;
703 while (*u_end++) ;
704 return (size_t)(u_end - u - 1);
705 }
706 #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
707 #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
708 #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
709 #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
710 #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
711 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
712 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
713 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
714 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
715 #define __Pyx_PySequence_Tuple(obj)\
716 (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
717 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
718 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
719 #if CYTHON_ASSUME_SAFE_MACROS
720 #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
721 #else
722 #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
723 #endif
724 #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
725 #if PY_MAJOR_VERSION >= 3
726 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
727 #else
728 #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
729 #endif
730 #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
731 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
732 static int __Pyx_sys_getdefaultencoding_not_ascii;
__Pyx_init_sys_getdefaultencoding_params(void)733 static int __Pyx_init_sys_getdefaultencoding_params(void) {
734 PyObject* sys;
735 PyObject* default_encoding = NULL;
736 PyObject* ascii_chars_u = NULL;
737 PyObject* ascii_chars_b = NULL;
738 const char* default_encoding_c;
739 sys = PyImport_ImportModule("sys");
740 if (!sys) goto bad;
741 default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
742 Py_DECREF(sys);
743 if (!default_encoding) goto bad;
744 default_encoding_c = PyBytes_AsString(default_encoding);
745 if (!default_encoding_c) goto bad;
746 if (strcmp(default_encoding_c, "ascii") == 0) {
747 __Pyx_sys_getdefaultencoding_not_ascii = 0;
748 } else {
749 char ascii_chars[128];
750 int c;
751 for (c = 0; c < 128; c++) {
752 ascii_chars[c] = c;
753 }
754 __Pyx_sys_getdefaultencoding_not_ascii = 1;
755 ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
756 if (!ascii_chars_u) goto bad;
757 ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
758 if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
759 PyErr_Format(
760 PyExc_ValueError,
761 "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
762 default_encoding_c);
763 goto bad;
764 }
765 Py_DECREF(ascii_chars_u);
766 Py_DECREF(ascii_chars_b);
767 }
768 Py_DECREF(default_encoding);
769 return 0;
770 bad:
771 Py_XDECREF(default_encoding);
772 Py_XDECREF(ascii_chars_u);
773 Py_XDECREF(ascii_chars_b);
774 return -1;
775 }
776 #endif
777 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
778 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
779 #else
780 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
781 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
782 static char* __PYX_DEFAULT_STRING_ENCODING;
__Pyx_init_sys_getdefaultencoding_params(void)783 static int __Pyx_init_sys_getdefaultencoding_params(void) {
784 PyObject* sys;
785 PyObject* default_encoding = NULL;
786 char* default_encoding_c;
787 sys = PyImport_ImportModule("sys");
788 if (!sys) goto bad;
789 default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
790 Py_DECREF(sys);
791 if (!default_encoding) goto bad;
792 default_encoding_c = PyBytes_AsString(default_encoding);
793 if (!default_encoding_c) goto bad;
794 __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
795 if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
796 strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
797 Py_DECREF(default_encoding);
798 return 0;
799 bad:
800 Py_XDECREF(default_encoding);
801 return -1;
802 }
803 #endif
804 #endif
805
806
807 /* Test for GCC > 2.95 */
808 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
809 #define likely(x) __builtin_expect(!!(x), 1)
810 #define unlikely(x) __builtin_expect(!!(x), 0)
811 #else /* !__GNUC__ or GCC < 2.95 */
812 #define likely(x) (x)
813 #define unlikely(x) (x)
814 #endif /* __GNUC__ */
__Pyx_pretend_to_initialize(void * ptr)815 static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
816
817 static PyObject *__pyx_m = NULL;
818 static PyObject *__pyx_d;
819 static PyObject *__pyx_b;
820 static PyObject *__pyx_cython_runtime = NULL;
821 static PyObject *__pyx_empty_tuple;
822 static PyObject *__pyx_empty_bytes;
823 static PyObject *__pyx_empty_unicode;
824 static int __pyx_lineno;
825 static int __pyx_clineno = 0;
826 static const char * __pyx_cfilenm= __FILE__;
827 static const char *__pyx_filename;
828
829
830 static const char *__pyx_f[] = {
831 "stringsource",
832 "src/cchardet/_cchardet.pyx",
833 };
834
835 /*--- Type declarations ---*/
836 struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector;
837
838 /* "cchardet/_cchardet.pyx":35
839 * return None, None
840 *
841 * cdef class UniversalDetector: # <<<<<<<<<<<<<<
842 * cdef uchardet_t _ud
843 * cdef int _done
844 */
845 struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector {
846 PyObject_HEAD
847 uchardet_t _ud;
848 int _done;
849 int _closed;
850 PyObject *_detected_charset;
851 float _detected_confidence;
852 };
853
854
855 /* --- Runtime support code (head) --- */
856 /* Refnanny.proto */
857 #ifndef CYTHON_REFNANNY
858 #define CYTHON_REFNANNY 0
859 #endif
860 #if CYTHON_REFNANNY
861 typedef struct {
862 void (*INCREF)(void*, PyObject*, int);
863 void (*DECREF)(void*, PyObject*, int);
864 void (*GOTREF)(void*, PyObject*, int);
865 void (*GIVEREF)(void*, PyObject*, int);
866 void* (*SetupContext)(const char*, int, const char*);
867 void (*FinishContext)(void**);
868 } __Pyx_RefNannyAPIStruct;
869 static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
870 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
871 #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
872 #ifdef WITH_THREAD
873 #define __Pyx_RefNannySetupContext(name, acquire_gil)\
874 if (acquire_gil) {\
875 PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
876 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
877 PyGILState_Release(__pyx_gilstate_save);\
878 } else {\
879 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
880 }
881 #else
882 #define __Pyx_RefNannySetupContext(name, acquire_gil)\
883 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
884 #endif
885 #define __Pyx_RefNannyFinishContext()\
886 __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
887 #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
888 #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
889 #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
890 #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
891 #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
892 #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
893 #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
894 #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
895 #else
896 #define __Pyx_RefNannyDeclarations
897 #define __Pyx_RefNannySetupContext(name, acquire_gil)
898 #define __Pyx_RefNannyFinishContext()
899 #define __Pyx_INCREF(r) Py_INCREF(r)
900 #define __Pyx_DECREF(r) Py_DECREF(r)
901 #define __Pyx_GOTREF(r)
902 #define __Pyx_GIVEREF(r)
903 #define __Pyx_XINCREF(r) Py_XINCREF(r)
904 #define __Pyx_XDECREF(r) Py_XDECREF(r)
905 #define __Pyx_XGOTREF(r)
906 #define __Pyx_XGIVEREF(r)
907 #endif
908 #define __Pyx_XDECREF_SET(r, v) do {\
909 PyObject *tmp = (PyObject *) r;\
910 r = v; __Pyx_XDECREF(tmp);\
911 } while (0)
912 #define __Pyx_DECREF_SET(r, v) do {\
913 PyObject *tmp = (PyObject *) r;\
914 r = v; __Pyx_DECREF(tmp);\
915 } while (0)
916 #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
917 #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
918
919 /* PyObjectGetAttrStr.proto */
920 #if CYTHON_USE_TYPE_SLOTS
921 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
922 #else
923 #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
924 #endif
925
926 /* GetBuiltinName.proto */
927 static PyObject *__Pyx_GetBuiltinName(PyObject *name);
928
929 /* ArgTypeTest.proto */
930 #define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
931 ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
932 __Pyx__ArgTypeTest(obj, type, name, exact))
933 static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);
934
935 /* PyObjectCall.proto */
936 #if CYTHON_COMPILING_IN_CPYTHON
937 static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
938 #else
939 #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
940 #endif
941
942 /* PyThreadStateGet.proto */
943 #if CYTHON_FAST_THREAD_STATE
944 #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
945 #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
946 #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
947 #else
948 #define __Pyx_PyThreadState_declare
949 #define __Pyx_PyThreadState_assign
950 #define __Pyx_PyErr_Occurred() PyErr_Occurred()
951 #endif
952
953 /* PyErrFetchRestore.proto */
954 #if CYTHON_FAST_THREAD_STATE
955 #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
956 #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
957 #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
958 #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
959 #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
960 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
961 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
962 #if CYTHON_COMPILING_IN_CPYTHON
963 #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
964 #else
965 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
966 #endif
967 #else
968 #define __Pyx_PyErr_Clear() PyErr_Clear()
969 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
970 #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
971 #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
972 #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
973 #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
974 #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
975 #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
976 #endif
977
978 /* RaiseException.proto */
979 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
980
981 /* RaiseArgTupleInvalid.proto */
982 static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
983 Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
984
985 /* KeywordStringCheck.proto */
986 static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed);
987
988 /* PyObject_GenericGetAttrNoDict.proto */
989 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
990 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
991 #else
992 #define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
993 #endif
994
995 /* PyObject_GenericGetAttr.proto */
996 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
997 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
998 #else
999 #define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
1000 #endif
1001
1002 /* PyErrExceptionMatches.proto */
1003 #if CYTHON_FAST_THREAD_STATE
1004 #define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
1005 static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
1006 #else
1007 #define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err)
1008 #endif
1009
1010 /* PyObjectGetAttrStrNoError.proto */
1011 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);
1012
1013 /* SetupReduce.proto */
1014 static int __Pyx_setup_reduce(PyObject* type_obj);
1015
1016 /* PyDictVersioning.proto */
1017 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
1018 #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
1019 #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
1020 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
1021 (version_var) = __PYX_GET_DICT_VERSION(dict);\
1022 (cache_var) = (value);
1023 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
1024 static PY_UINT64_T __pyx_dict_version = 0;\
1025 static PyObject *__pyx_dict_cached_value = NULL;\
1026 if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
1027 (VAR) = __pyx_dict_cached_value;\
1028 } else {\
1029 (VAR) = __pyx_dict_cached_value = (LOOKUP);\
1030 __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
1031 }\
1032 }
1033 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
1034 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
1035 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
1036 #else
1037 #define __PYX_GET_DICT_VERSION(dict) (0)
1038 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
1039 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP);
1040 #endif
1041
1042 /* CLineInTraceback.proto */
1043 #ifdef CYTHON_CLINE_IN_TRACEBACK
1044 #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
1045 #else
1046 static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
1047 #endif
1048
1049 /* CodeObjectCache.proto */
1050 typedef struct {
1051 PyCodeObject* code_object;
1052 int code_line;
1053 } __Pyx_CodeObjectCacheEntry;
1054 struct __Pyx_CodeObjectCache {
1055 int count;
1056 int max_count;
1057 __Pyx_CodeObjectCacheEntry* entries;
1058 };
1059 static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
1060 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
1061 static PyCodeObject *__pyx_find_code_object(int code_line);
1062 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
1063
1064 /* AddTraceback.proto */
1065 static void __Pyx_AddTraceback(const char *funcname, int c_line,
1066 int py_line, const char *filename);
1067
1068 /* CIntToPy.proto */
1069 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
1070
1071 /* CIntToPy.proto */
1072 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
1073
1074 /* CIntFromPy.proto */
1075 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
1076
1077 /* CIntFromPy.proto */
1078 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
1079
1080 /* FastTypeChecks.proto */
1081 #if CYTHON_COMPILING_IN_CPYTHON
1082 #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
1083 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
1084 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
1085 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
1086 #else
1087 #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
1088 #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
1089 #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
1090 #endif
1091 #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
1092
1093 /* CheckBinaryVersion.proto */
1094 static int __Pyx_check_binary_version(void);
1095
1096 /* InitStrings.proto */
1097 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
1098
1099
1100 /* Module declarations from 'cchardet._cchardet' */
1101 static PyTypeObject *__pyx_ptype_8cchardet_9_cchardet_UniversalDetector = 0;
1102 #define __Pyx_MODULE_NAME "cchardet._cchardet"
1103 extern int __pyx_module_is_main_cchardet___cchardet;
1104 int __pyx_module_is_main_cchardet___cchardet = 0;
1105
1106 /* Implementation of 'cchardet._cchardet' */
1107 static PyObject *__pyx_builtin_TypeError;
1108 static const char __pyx_k__3[] = "";
1109 static const char __pyx_k_ud[] = "ud";
1110 static const char __pyx_k_msg[] = "msg";
1111 static const char __pyx_k_main[] = "__main__";
1112 static const char __pyx_k_name[] = "__name__";
1113 static const char __pyx_k_test[] = "__test__";
1114 static const char __pyx_k_length[] = "length";
1115 static const char __pyx_k_reduce[] = "__reduce__";
1116 static const char __pyx_k_result[] = "result";
1117 static const char __pyx_k_getstate[] = "__getstate__";
1118 static const char __pyx_k_setstate[] = "__setstate__";
1119 static const char __pyx_k_TypeError[] = "TypeError";
1120 static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
1121 static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
1122 static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
1123 static const char __pyx_k_detected_charset[] = "detected_charset";
1124 static const char __pyx_k_Handle_data_error[] = "Handle data error";
1125 static const char __pyx_k_UniversalDetector[] = "UniversalDetector";
1126 static const char __pyx_k_cchardet__cchardet[] = "cchardet._cchardet";
1127 static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
1128 static const char __pyx_k_detected_confidence[] = "detected_confidence";
1129 static const char __pyx_k_detect_with_confidence[] = "detect_with_confidence";
1130 static const char __pyx_k_src_cchardet__cchardet_pyx[] = "src/cchardet/_cchardet.pyx";
1131 static const char __pyx_k_self__ud_cannot_be_converted_to[] = "self._ud cannot be converted to a Python object for pickling";
1132 static PyObject *__pyx_kp_u_Handle_data_error;
1133 static PyObject *__pyx_n_s_TypeError;
1134 static PyObject *__pyx_n_s_UniversalDetector;
1135 static PyObject *__pyx_kp_b__3;
1136 static PyObject *__pyx_n_s_cchardet__cchardet;
1137 static PyObject *__pyx_n_s_cline_in_traceback;
1138 static PyObject *__pyx_n_s_detect_with_confidence;
1139 static PyObject *__pyx_n_s_detected_charset;
1140 static PyObject *__pyx_n_s_detected_confidence;
1141 static PyObject *__pyx_n_s_getstate;
1142 static PyObject *__pyx_n_s_length;
1143 static PyObject *__pyx_n_s_main;
1144 static PyObject *__pyx_n_s_msg;
1145 static PyObject *__pyx_n_s_name;
1146 static PyObject *__pyx_n_s_reduce;
1147 static PyObject *__pyx_n_s_reduce_cython;
1148 static PyObject *__pyx_n_s_reduce_ex;
1149 static PyObject *__pyx_n_s_result;
1150 static PyObject *__pyx_kp_s_self__ud_cannot_be_converted_to;
1151 static PyObject *__pyx_n_s_setstate;
1152 static PyObject *__pyx_n_s_setstate_cython;
1153 static PyObject *__pyx_kp_s_src_cchardet__cchardet_pyx;
1154 static PyObject *__pyx_n_s_test;
1155 static PyObject *__pyx_n_s_ud;
1156 static PyObject *__pyx_pf_8cchardet_9_cchardet_detect_with_confidence(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_msg); /* proto */
1157 static int __pyx_pf_8cchardet_9_cchardet_17UniversalDetector___init__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self); /* proto */
1158 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_2reset(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self); /* proto */
1159 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4feed(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self, PyObject *__pyx_v_msg); /* proto */
1160 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6close(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self); /* proto */
1161 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4done___get__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self); /* proto */
1162 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6result___get__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self); /* proto */
1163 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self); /* proto */
1164 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
1165 static PyObject *__pyx_tp_new_8cchardet_9_cchardet_UniversalDetector(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
1166 static PyObject *__pyx_tuple_;
1167 static PyObject *__pyx_tuple__2;
1168 static PyObject *__pyx_tuple__4;
1169 static PyObject *__pyx_tuple__5;
1170 static PyObject *__pyx_tuple__6;
1171 static PyObject *__pyx_codeobj__7;
1172 /* Late includes */
1173
1174 /* "cchardet/_cchardet.pyx":14
1175 * cdef float uchardet_get_confidence(uchardet_t ud)
1176 *
1177 * def detect_with_confidence(bytes msg): # <<<<<<<<<<<<<<
1178 * cdef int length = len(msg)
1179 *
1180 */
1181
1182 /* Python wrapper */
1183 static PyObject *__pyx_pw_8cchardet_9_cchardet_1detect_with_confidence(PyObject *__pyx_self, PyObject *__pyx_v_msg); /*proto*/
1184 static PyMethodDef __pyx_mdef_8cchardet_9_cchardet_1detect_with_confidence = {"detect_with_confidence", (PyCFunction)__pyx_pw_8cchardet_9_cchardet_1detect_with_confidence, METH_O, 0};
__pyx_pw_8cchardet_9_cchardet_1detect_with_confidence(PyObject * __pyx_self,PyObject * __pyx_v_msg)1185 static PyObject *__pyx_pw_8cchardet_9_cchardet_1detect_with_confidence(PyObject *__pyx_self, PyObject *__pyx_v_msg) {
1186 int __pyx_lineno = 0;
1187 const char *__pyx_filename = NULL;
1188 int __pyx_clineno = 0;
1189 PyObject *__pyx_r = 0;
1190 __Pyx_RefNannyDeclarations
1191 __Pyx_RefNannySetupContext("detect_with_confidence (wrapper)", 0);
1192 if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_msg), (&PyBytes_Type), 1, "msg", 1))) __PYX_ERR(1, 14, __pyx_L1_error)
1193 __pyx_r = __pyx_pf_8cchardet_9_cchardet_detect_with_confidence(__pyx_self, ((PyObject*)__pyx_v_msg));
1194
1195 /* function exit code */
1196 goto __pyx_L0;
1197 __pyx_L1_error:;
1198 __pyx_r = NULL;
1199 __pyx_L0:;
1200 __Pyx_RefNannyFinishContext();
1201 return __pyx_r;
1202 }
1203
__pyx_pf_8cchardet_9_cchardet_detect_with_confidence(CYTHON_UNUSED PyObject * __pyx_self,PyObject * __pyx_v_msg)1204 static PyObject *__pyx_pf_8cchardet_9_cchardet_detect_with_confidence(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_msg) {
1205 int __pyx_v_length;
1206 uchardet_t __pyx_v_ud;
1207 int __pyx_v_result;
1208 PyObject *__pyx_v_detected_charset = 0;
1209 float __pyx_v_detected_confidence;
1210 PyObject *__pyx_r = NULL;
1211 __Pyx_RefNannyDeclarations
1212 Py_ssize_t __pyx_t_1;
1213 const char* __pyx_t_2;
1214 int __pyx_t_3;
1215 PyObject *__pyx_t_4 = NULL;
1216 PyObject *__pyx_t_5 = NULL;
1217 int __pyx_lineno = 0;
1218 const char *__pyx_filename = NULL;
1219 int __pyx_clineno = 0;
1220 __Pyx_RefNannySetupContext("detect_with_confidence", 0);
1221
1222 /* "cchardet/_cchardet.pyx":15
1223 *
1224 * def detect_with_confidence(bytes msg):
1225 * cdef int length = len(msg) # <<<<<<<<<<<<<<
1226 *
1227 * cdef uchardet_t ud = uchardet_new()
1228 */
1229 if (unlikely(__pyx_v_msg == Py_None)) {
1230 PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
1231 __PYX_ERR(1, 15, __pyx_L1_error)
1232 }
1233 __pyx_t_1 = PyBytes_GET_SIZE(__pyx_v_msg); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(1, 15, __pyx_L1_error)
1234 __pyx_v_length = __pyx_t_1;
1235
1236 /* "cchardet/_cchardet.pyx":17
1237 * cdef int length = len(msg)
1238 *
1239 * cdef uchardet_t ud = uchardet_new() # <<<<<<<<<<<<<<
1240 *
1241 * cdef int result = uchardet_handle_data(ud, msg, length)
1242 */
1243 __pyx_v_ud = uchardet_new();
1244
1245 /* "cchardet/_cchardet.pyx":19
1246 * cdef uchardet_t ud = uchardet_new()
1247 *
1248 * cdef int result = uchardet_handle_data(ud, msg, length) # <<<<<<<<<<<<<<
1249 * if result == -1:
1250 * uchardet_delete(ud)
1251 */
1252 if (unlikely(__pyx_v_msg == Py_None)) {
1253 PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
1254 __PYX_ERR(1, 19, __pyx_L1_error)
1255 }
1256 __pyx_t_2 = __Pyx_PyBytes_AsWritableString(__pyx_v_msg); if (unlikely((__pyx_t_2 == ((const char*)NULL)) && PyErr_Occurred())) __PYX_ERR(1, 19, __pyx_L1_error)
1257 __pyx_v_result = uchardet_handle_data(__pyx_v_ud, __pyx_t_2, __pyx_v_length);
1258
1259 /* "cchardet/_cchardet.pyx":20
1260 *
1261 * cdef int result = uchardet_handle_data(ud, msg, length)
1262 * if result == -1: # <<<<<<<<<<<<<<
1263 * uchardet_delete(ud)
1264 * raise Exception("Handle data error")
1265 */
1266 __pyx_t_3 = ((__pyx_v_result == -1L) != 0);
1267 if (unlikely(__pyx_t_3)) {
1268
1269 /* "cchardet/_cchardet.pyx":21
1270 * cdef int result = uchardet_handle_data(ud, msg, length)
1271 * if result == -1:
1272 * uchardet_delete(ud) # <<<<<<<<<<<<<<
1273 * raise Exception("Handle data error")
1274 *
1275 */
1276 uchardet_delete(__pyx_v_ud);
1277
1278 /* "cchardet/_cchardet.pyx":22
1279 * if result == -1:
1280 * uchardet_delete(ud)
1281 * raise Exception("Handle data error") # <<<<<<<<<<<<<<
1282 *
1283 * uchardet_data_end(ud)
1284 */
1285 __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple_, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 22, __pyx_L1_error)
1286 __Pyx_GOTREF(__pyx_t_4);
1287 __Pyx_Raise(__pyx_t_4, 0, 0, 0);
1288 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1289 __PYX_ERR(1, 22, __pyx_L1_error)
1290
1291 /* "cchardet/_cchardet.pyx":20
1292 *
1293 * cdef int result = uchardet_handle_data(ud, msg, length)
1294 * if result == -1: # <<<<<<<<<<<<<<
1295 * uchardet_delete(ud)
1296 * raise Exception("Handle data error")
1297 */
1298 }
1299
1300 /* "cchardet/_cchardet.pyx":24
1301 * raise Exception("Handle data error")
1302 *
1303 * uchardet_data_end(ud) # <<<<<<<<<<<<<<
1304 *
1305 * cdef bytes detected_charset = uchardet_get_charset(ud)
1306 */
1307 uchardet_data_end(__pyx_v_ud);
1308
1309 /* "cchardet/_cchardet.pyx":26
1310 * uchardet_data_end(ud)
1311 *
1312 * cdef bytes detected_charset = uchardet_get_charset(ud) # <<<<<<<<<<<<<<
1313 * cdef float detected_confidence = uchardet_get_confidence(ud)
1314 * uchardet_delete(ud)
1315 */
1316 __pyx_t_4 = __Pyx_PyBytes_FromString(uchardet_get_charset(__pyx_v_ud)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 26, __pyx_L1_error)
1317 __Pyx_GOTREF(__pyx_t_4);
1318 __pyx_v_detected_charset = ((PyObject*)__pyx_t_4);
1319 __pyx_t_4 = 0;
1320
1321 /* "cchardet/_cchardet.pyx":27
1322 *
1323 * cdef bytes detected_charset = uchardet_get_charset(ud)
1324 * cdef float detected_confidence = uchardet_get_confidence(ud) # <<<<<<<<<<<<<<
1325 * uchardet_delete(ud)
1326 *
1327 */
1328 __pyx_v_detected_confidence = uchardet_get_confidence(__pyx_v_ud);
1329
1330 /* "cchardet/_cchardet.pyx":28
1331 * cdef bytes detected_charset = uchardet_get_charset(ud)
1332 * cdef float detected_confidence = uchardet_get_confidence(ud)
1333 * uchardet_delete(ud) # <<<<<<<<<<<<<<
1334 *
1335 * if detected_charset:
1336 */
1337 uchardet_delete(__pyx_v_ud);
1338
1339 /* "cchardet/_cchardet.pyx":30
1340 * uchardet_delete(ud)
1341 *
1342 * if detected_charset: # <<<<<<<<<<<<<<
1343 * return detected_charset, detected_confidence
1344 *
1345 */
1346 __pyx_t_3 = (PyBytes_GET_SIZE(__pyx_v_detected_charset) != 0);
1347 if (__pyx_t_3) {
1348
1349 /* "cchardet/_cchardet.pyx":31
1350 *
1351 * if detected_charset:
1352 * return detected_charset, detected_confidence # <<<<<<<<<<<<<<
1353 *
1354 * return None, None
1355 */
1356 __Pyx_XDECREF(__pyx_r);
1357 __pyx_t_4 = PyFloat_FromDouble(__pyx_v_detected_confidence); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 31, __pyx_L1_error)
1358 __Pyx_GOTREF(__pyx_t_4);
1359 __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 31, __pyx_L1_error)
1360 __Pyx_GOTREF(__pyx_t_5);
1361 __Pyx_INCREF(__pyx_v_detected_charset);
1362 __Pyx_GIVEREF(__pyx_v_detected_charset);
1363 PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_detected_charset);
1364 __Pyx_GIVEREF(__pyx_t_4);
1365 PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
1366 __pyx_t_4 = 0;
1367 __pyx_r = __pyx_t_5;
1368 __pyx_t_5 = 0;
1369 goto __pyx_L0;
1370
1371 /* "cchardet/_cchardet.pyx":30
1372 * uchardet_delete(ud)
1373 *
1374 * if detected_charset: # <<<<<<<<<<<<<<
1375 * return detected_charset, detected_confidence
1376 *
1377 */
1378 }
1379
1380 /* "cchardet/_cchardet.pyx":33
1381 * return detected_charset, detected_confidence
1382 *
1383 * return None, None # <<<<<<<<<<<<<<
1384 *
1385 * cdef class UniversalDetector:
1386 */
1387 __Pyx_XDECREF(__pyx_r);
1388 __Pyx_INCREF(__pyx_tuple__2);
1389 __pyx_r = __pyx_tuple__2;
1390 goto __pyx_L0;
1391
1392 /* "cchardet/_cchardet.pyx":14
1393 * cdef float uchardet_get_confidence(uchardet_t ud)
1394 *
1395 * def detect_with_confidence(bytes msg): # <<<<<<<<<<<<<<
1396 * cdef int length = len(msg)
1397 *
1398 */
1399
1400 /* function exit code */
1401 __pyx_L1_error:;
1402 __Pyx_XDECREF(__pyx_t_4);
1403 __Pyx_XDECREF(__pyx_t_5);
1404 __Pyx_AddTraceback("cchardet._cchardet.detect_with_confidence", __pyx_clineno, __pyx_lineno, __pyx_filename);
1405 __pyx_r = NULL;
1406 __pyx_L0:;
1407 __Pyx_XDECREF(__pyx_v_detected_charset);
1408 __Pyx_XGIVEREF(__pyx_r);
1409 __Pyx_RefNannyFinishContext();
1410 return __pyx_r;
1411 }
1412
1413 /* "cchardet/_cchardet.pyx":42
1414 * cdef float _detected_confidence
1415 *
1416 * def __init__(self): # <<<<<<<<<<<<<<
1417 * self._ud = uchardet_new()
1418 * self._done = 0
1419 */
1420
1421 /* Python wrapper */
1422 static int __pyx_pw_8cchardet_9_cchardet_17UniversalDetector_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_1__init__(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)1423 static int __pyx_pw_8cchardet_9_cchardet_17UniversalDetector_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1424 int __pyx_r;
1425 __Pyx_RefNannyDeclarations
1426 __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
1427 if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
1428 __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
1429 if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
1430 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector___init__(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self));
1431
1432 /* function exit code */
1433 __Pyx_RefNannyFinishContext();
1434 return __pyx_r;
1435 }
1436
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector___init__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self)1437 static int __pyx_pf_8cchardet_9_cchardet_17UniversalDetector___init__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self) {
1438 int __pyx_r;
1439 __Pyx_RefNannyDeclarations
1440 __Pyx_RefNannySetupContext("__init__", 0);
1441
1442 /* "cchardet/_cchardet.pyx":43
1443 *
1444 * def __init__(self):
1445 * self._ud = uchardet_new() # <<<<<<<<<<<<<<
1446 * self._done = 0
1447 * self._closed = 0
1448 */
1449 __pyx_v_self->_ud = uchardet_new();
1450
1451 /* "cchardet/_cchardet.pyx":44
1452 * def __init__(self):
1453 * self._ud = uchardet_new()
1454 * self._done = 0 # <<<<<<<<<<<<<<
1455 * self._closed = 0
1456 * self._detected_charset = b""
1457 */
1458 __pyx_v_self->_done = 0;
1459
1460 /* "cchardet/_cchardet.pyx":45
1461 * self._ud = uchardet_new()
1462 * self._done = 0
1463 * self._closed = 0 # <<<<<<<<<<<<<<
1464 * self._detected_charset = b""
1465 * self._detected_confidence = 0.0
1466 */
1467 __pyx_v_self->_closed = 0;
1468
1469 /* "cchardet/_cchardet.pyx":46
1470 * self._done = 0
1471 * self._closed = 0
1472 * self._detected_charset = b"" # <<<<<<<<<<<<<<
1473 * self._detected_confidence = 0.0
1474 *
1475 */
1476 __Pyx_INCREF(__pyx_kp_b__3);
1477 __Pyx_GIVEREF(__pyx_kp_b__3);
1478 __Pyx_GOTREF(__pyx_v_self->_detected_charset);
1479 __Pyx_DECREF(__pyx_v_self->_detected_charset);
1480 __pyx_v_self->_detected_charset = __pyx_kp_b__3;
1481
1482 /* "cchardet/_cchardet.pyx":47
1483 * self._closed = 0
1484 * self._detected_charset = b""
1485 * self._detected_confidence = 0.0 # <<<<<<<<<<<<<<
1486 *
1487 * def reset(self):
1488 */
1489 __pyx_v_self->_detected_confidence = 0.0;
1490
1491 /* "cchardet/_cchardet.pyx":42
1492 * cdef float _detected_confidence
1493 *
1494 * def __init__(self): # <<<<<<<<<<<<<<
1495 * self._ud = uchardet_new()
1496 * self._done = 0
1497 */
1498
1499 /* function exit code */
1500 __pyx_r = 0;
1501 __Pyx_RefNannyFinishContext();
1502 return __pyx_r;
1503 }
1504
1505 /* "cchardet/_cchardet.pyx":49
1506 * self._detected_confidence = 0.0
1507 *
1508 * def reset(self): # <<<<<<<<<<<<<<
1509 * if not self._closed:
1510 * self._done = 0
1511 */
1512
1513 /* Python wrapper */
1514 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_3reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_3reset(PyObject * __pyx_v_self,CYTHON_UNUSED PyObject * unused)1515 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_3reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
1516 PyObject *__pyx_r = 0;
1517 __Pyx_RefNannyDeclarations
1518 __Pyx_RefNannySetupContext("reset (wrapper)", 0);
1519 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector_2reset(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self));
1520
1521 /* function exit code */
1522 __Pyx_RefNannyFinishContext();
1523 return __pyx_r;
1524 }
1525
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_2reset(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self)1526 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_2reset(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self) {
1527 PyObject *__pyx_r = NULL;
1528 __Pyx_RefNannyDeclarations
1529 int __pyx_t_1;
1530 __Pyx_RefNannySetupContext("reset", 0);
1531
1532 /* "cchardet/_cchardet.pyx":50
1533 *
1534 * def reset(self):
1535 * if not self._closed: # <<<<<<<<<<<<<<
1536 * self._done = 0
1537 * self._closed = 0
1538 */
1539 __pyx_t_1 = ((!(__pyx_v_self->_closed != 0)) != 0);
1540 if (__pyx_t_1) {
1541
1542 /* "cchardet/_cchardet.pyx":51
1543 * def reset(self):
1544 * if not self._closed:
1545 * self._done = 0 # <<<<<<<<<<<<<<
1546 * self._closed = 0
1547 * self._detected_charset = b""
1548 */
1549 __pyx_v_self->_done = 0;
1550
1551 /* "cchardet/_cchardet.pyx":52
1552 * if not self._closed:
1553 * self._done = 0
1554 * self._closed = 0 # <<<<<<<<<<<<<<
1555 * self._detected_charset = b""
1556 * self._detected_confidence = 0.0
1557 */
1558 __pyx_v_self->_closed = 0;
1559
1560 /* "cchardet/_cchardet.pyx":53
1561 * self._done = 0
1562 * self._closed = 0
1563 * self._detected_charset = b"" # <<<<<<<<<<<<<<
1564 * self._detected_confidence = 0.0
1565 * uchardet_reset(self._ud)
1566 */
1567 __Pyx_INCREF(__pyx_kp_b__3);
1568 __Pyx_GIVEREF(__pyx_kp_b__3);
1569 __Pyx_GOTREF(__pyx_v_self->_detected_charset);
1570 __Pyx_DECREF(__pyx_v_self->_detected_charset);
1571 __pyx_v_self->_detected_charset = __pyx_kp_b__3;
1572
1573 /* "cchardet/_cchardet.pyx":54
1574 * self._closed = 0
1575 * self._detected_charset = b""
1576 * self._detected_confidence = 0.0 # <<<<<<<<<<<<<<
1577 * uchardet_reset(self._ud)
1578 *
1579 */
1580 __pyx_v_self->_detected_confidence = 0.0;
1581
1582 /* "cchardet/_cchardet.pyx":55
1583 * self._detected_charset = b""
1584 * self._detected_confidence = 0.0
1585 * uchardet_reset(self._ud) # <<<<<<<<<<<<<<
1586 *
1587 * def feed(self, bytes msg):
1588 */
1589 uchardet_reset(__pyx_v_self->_ud);
1590
1591 /* "cchardet/_cchardet.pyx":50
1592 *
1593 * def reset(self):
1594 * if not self._closed: # <<<<<<<<<<<<<<
1595 * self._done = 0
1596 * self._closed = 0
1597 */
1598 }
1599
1600 /* "cchardet/_cchardet.pyx":49
1601 * self._detected_confidence = 0.0
1602 *
1603 * def reset(self): # <<<<<<<<<<<<<<
1604 * if not self._closed:
1605 * self._done = 0
1606 */
1607
1608 /* function exit code */
1609 __pyx_r = Py_None; __Pyx_INCREF(Py_None);
1610 __Pyx_XGIVEREF(__pyx_r);
1611 __Pyx_RefNannyFinishContext();
1612 return __pyx_r;
1613 }
1614
1615 /* "cchardet/_cchardet.pyx":57
1616 * uchardet_reset(self._ud)
1617 *
1618 * def feed(self, bytes msg): # <<<<<<<<<<<<<<
1619 * cdef int length
1620 * cdef int result
1621 */
1622
1623 /* Python wrapper */
1624 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_5feed(PyObject *__pyx_v_self, PyObject *__pyx_v_msg); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_5feed(PyObject * __pyx_v_self,PyObject * __pyx_v_msg)1625 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_5feed(PyObject *__pyx_v_self, PyObject *__pyx_v_msg) {
1626 int __pyx_lineno = 0;
1627 const char *__pyx_filename = NULL;
1628 int __pyx_clineno = 0;
1629 PyObject *__pyx_r = 0;
1630 __Pyx_RefNannyDeclarations
1631 __Pyx_RefNannySetupContext("feed (wrapper)", 0);
1632 if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_msg), (&PyBytes_Type), 1, "msg", 1))) __PYX_ERR(1, 57, __pyx_L1_error)
1633 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4feed(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self), ((PyObject*)__pyx_v_msg));
1634
1635 /* function exit code */
1636 goto __pyx_L0;
1637 __pyx_L1_error:;
1638 __pyx_r = NULL;
1639 __pyx_L0:;
1640 __Pyx_RefNannyFinishContext();
1641 return __pyx_r;
1642 }
1643
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4feed(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self,PyObject * __pyx_v_msg)1644 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4feed(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self, PyObject *__pyx_v_msg) {
1645 int __pyx_v_length;
1646 int __pyx_v_result;
1647 PyObject *__pyx_r = NULL;
1648 __Pyx_RefNannyDeclarations
1649 int __pyx_t_1;
1650 Py_ssize_t __pyx_t_2;
1651 const char* __pyx_t_3;
1652 PyObject *__pyx_t_4 = NULL;
1653 int __pyx_lineno = 0;
1654 const char *__pyx_filename = NULL;
1655 int __pyx_clineno = 0;
1656 __Pyx_RefNannySetupContext("feed", 0);
1657
1658 /* "cchardet/_cchardet.pyx":61
1659 * cdef int result
1660 *
1661 * if self._closed: # <<<<<<<<<<<<<<
1662 * return
1663 *
1664 */
1665 __pyx_t_1 = (__pyx_v_self->_closed != 0);
1666 if (__pyx_t_1) {
1667
1668 /* "cchardet/_cchardet.pyx":62
1669 *
1670 * if self._closed:
1671 * return # <<<<<<<<<<<<<<
1672 *
1673 * length = len(msg)
1674 */
1675 __Pyx_XDECREF(__pyx_r);
1676 __pyx_r = Py_None; __Pyx_INCREF(Py_None);
1677 goto __pyx_L0;
1678
1679 /* "cchardet/_cchardet.pyx":61
1680 * cdef int result
1681 *
1682 * if self._closed: # <<<<<<<<<<<<<<
1683 * return
1684 *
1685 */
1686 }
1687
1688 /* "cchardet/_cchardet.pyx":64
1689 * return
1690 *
1691 * length = len(msg) # <<<<<<<<<<<<<<
1692 * if length > 0:
1693 * result = uchardet_handle_data(self._ud, msg, length)
1694 */
1695 if (unlikely(__pyx_v_msg == Py_None)) {
1696 PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
1697 __PYX_ERR(1, 64, __pyx_L1_error)
1698 }
1699 __pyx_t_2 = PyBytes_GET_SIZE(__pyx_v_msg); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(1, 64, __pyx_L1_error)
1700 __pyx_v_length = __pyx_t_2;
1701
1702 /* "cchardet/_cchardet.pyx":65
1703 *
1704 * length = len(msg)
1705 * if length > 0: # <<<<<<<<<<<<<<
1706 * result = uchardet_handle_data(self._ud, msg, length)
1707 *
1708 */
1709 __pyx_t_1 = ((__pyx_v_length > 0) != 0);
1710 if (__pyx_t_1) {
1711
1712 /* "cchardet/_cchardet.pyx":66
1713 * length = len(msg)
1714 * if length > 0:
1715 * result = uchardet_handle_data(self._ud, msg, length) # <<<<<<<<<<<<<<
1716 *
1717 * if result == -1:
1718 */
1719 if (unlikely(__pyx_v_msg == Py_None)) {
1720 PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
1721 __PYX_ERR(1, 66, __pyx_L1_error)
1722 }
1723 __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_msg); if (unlikely((__pyx_t_3 == ((const char*)NULL)) && PyErr_Occurred())) __PYX_ERR(1, 66, __pyx_L1_error)
1724 __pyx_v_result = uchardet_handle_data(__pyx_v_self->_ud, __pyx_t_3, __pyx_v_length);
1725
1726 /* "cchardet/_cchardet.pyx":68
1727 * result = uchardet_handle_data(self._ud, msg, length)
1728 *
1729 * if result == -1: # <<<<<<<<<<<<<<
1730 * self._closed = 1
1731 * uchardet_delete(self._ud)
1732 */
1733 switch (__pyx_v_result) {
1734 case -1L:
1735
1736 /* "cchardet/_cchardet.pyx":69
1737 *
1738 * if result == -1:
1739 * self._closed = 1 # <<<<<<<<<<<<<<
1740 * uchardet_delete(self._ud)
1741 * raise Exception("Handle data error")
1742 */
1743 __pyx_v_self->_closed = 1;
1744
1745 /* "cchardet/_cchardet.pyx":70
1746 * if result == -1:
1747 * self._closed = 1
1748 * uchardet_delete(self._ud) # <<<<<<<<<<<<<<
1749 * raise Exception("Handle data error")
1750 * elif result == 0:
1751 */
1752 uchardet_delete(__pyx_v_self->_ud);
1753
1754 /* "cchardet/_cchardet.pyx":71
1755 * self._closed = 1
1756 * uchardet_delete(self._ud)
1757 * raise Exception("Handle data error") # <<<<<<<<<<<<<<
1758 * elif result == 0:
1759 * self._done = 1
1760 */
1761 __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple_, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 71, __pyx_L1_error)
1762 __Pyx_GOTREF(__pyx_t_4);
1763 __Pyx_Raise(__pyx_t_4, 0, 0, 0);
1764 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1765 __PYX_ERR(1, 71, __pyx_L1_error)
1766
1767 /* "cchardet/_cchardet.pyx":68
1768 * result = uchardet_handle_data(self._ud, msg, length)
1769 *
1770 * if result == -1: # <<<<<<<<<<<<<<
1771 * self._closed = 1
1772 * uchardet_delete(self._ud)
1773 */
1774 break;
1775 case 0:
1776
1777 /* "cchardet/_cchardet.pyx":73
1778 * raise Exception("Handle data error")
1779 * elif result == 0:
1780 * self._done = 1 # <<<<<<<<<<<<<<
1781 *
1782 * self._detected_charset = uchardet_get_charset(self._ud)
1783 */
1784 __pyx_v_self->_done = 1;
1785
1786 /* "cchardet/_cchardet.pyx":72
1787 * uchardet_delete(self._ud)
1788 * raise Exception("Handle data error")
1789 * elif result == 0: # <<<<<<<<<<<<<<
1790 * self._done = 1
1791 *
1792 */
1793 break;
1794 default: break;
1795 }
1796
1797 /* "cchardet/_cchardet.pyx":75
1798 * self._done = 1
1799 *
1800 * self._detected_charset = uchardet_get_charset(self._ud) # <<<<<<<<<<<<<<
1801 * self._detected_confidence = uchardet_get_confidence(self._ud)
1802 *
1803 */
1804 __pyx_t_4 = __Pyx_PyBytes_FromString(uchardet_get_charset(__pyx_v_self->_ud)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 75, __pyx_L1_error)
1805 __Pyx_GOTREF(__pyx_t_4);
1806 __Pyx_GIVEREF(__pyx_t_4);
1807 __Pyx_GOTREF(__pyx_v_self->_detected_charset);
1808 __Pyx_DECREF(__pyx_v_self->_detected_charset);
1809 __pyx_v_self->_detected_charset = ((PyObject*)__pyx_t_4);
1810 __pyx_t_4 = 0;
1811
1812 /* "cchardet/_cchardet.pyx":76
1813 *
1814 * self._detected_charset = uchardet_get_charset(self._ud)
1815 * self._detected_confidence = uchardet_get_confidence(self._ud) # <<<<<<<<<<<<<<
1816 *
1817 * def close(self):
1818 */
1819 __pyx_v_self->_detected_confidence = uchardet_get_confidence(__pyx_v_self->_ud);
1820
1821 /* "cchardet/_cchardet.pyx":65
1822 *
1823 * length = len(msg)
1824 * if length > 0: # <<<<<<<<<<<<<<
1825 * result = uchardet_handle_data(self._ud, msg, length)
1826 *
1827 */
1828 }
1829
1830 /* "cchardet/_cchardet.pyx":57
1831 * uchardet_reset(self._ud)
1832 *
1833 * def feed(self, bytes msg): # <<<<<<<<<<<<<<
1834 * cdef int length
1835 * cdef int result
1836 */
1837
1838 /* function exit code */
1839 __pyx_r = Py_None; __Pyx_INCREF(Py_None);
1840 goto __pyx_L0;
1841 __pyx_L1_error:;
1842 __Pyx_XDECREF(__pyx_t_4);
1843 __Pyx_AddTraceback("cchardet._cchardet.UniversalDetector.feed", __pyx_clineno, __pyx_lineno, __pyx_filename);
1844 __pyx_r = NULL;
1845 __pyx_L0:;
1846 __Pyx_XGIVEREF(__pyx_r);
1847 __Pyx_RefNannyFinishContext();
1848 return __pyx_r;
1849 }
1850
1851 /* "cchardet/_cchardet.pyx":78
1852 * self._detected_confidence = uchardet_get_confidence(self._ud)
1853 *
1854 * def close(self): # <<<<<<<<<<<<<<
1855 * if not self._closed:
1856 * uchardet_data_end(self._ud)
1857 */
1858
1859 /* Python wrapper */
1860 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_7close(PyObject * __pyx_v_self,CYTHON_UNUSED PyObject * unused)1861 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
1862 PyObject *__pyx_r = 0;
1863 __Pyx_RefNannyDeclarations
1864 __Pyx_RefNannySetupContext("close (wrapper)", 0);
1865 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6close(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self));
1866
1867 /* function exit code */
1868 __Pyx_RefNannyFinishContext();
1869 return __pyx_r;
1870 }
1871
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6close(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self)1872 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6close(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self) {
1873 PyObject *__pyx_r = NULL;
1874 __Pyx_RefNannyDeclarations
1875 int __pyx_t_1;
1876 PyObject *__pyx_t_2 = NULL;
1877 int __pyx_lineno = 0;
1878 const char *__pyx_filename = NULL;
1879 int __pyx_clineno = 0;
1880 __Pyx_RefNannySetupContext("close", 0);
1881
1882 /* "cchardet/_cchardet.pyx":79
1883 *
1884 * def close(self):
1885 * if not self._closed: # <<<<<<<<<<<<<<
1886 * uchardet_data_end(self._ud)
1887 * self._detected_charset = uchardet_get_charset(self._ud)
1888 */
1889 __pyx_t_1 = ((!(__pyx_v_self->_closed != 0)) != 0);
1890 if (__pyx_t_1) {
1891
1892 /* "cchardet/_cchardet.pyx":80
1893 * def close(self):
1894 * if not self._closed:
1895 * uchardet_data_end(self._ud) # <<<<<<<<<<<<<<
1896 * self._detected_charset = uchardet_get_charset(self._ud)
1897 * self._detected_confidence = uchardet_get_confidence(self._ud)
1898 */
1899 uchardet_data_end(__pyx_v_self->_ud);
1900
1901 /* "cchardet/_cchardet.pyx":81
1902 * if not self._closed:
1903 * uchardet_data_end(self._ud)
1904 * self._detected_charset = uchardet_get_charset(self._ud) # <<<<<<<<<<<<<<
1905 * self._detected_confidence = uchardet_get_confidence(self._ud)
1906 *
1907 */
1908 __pyx_t_2 = __Pyx_PyBytes_FromString(uchardet_get_charset(__pyx_v_self->_ud)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 81, __pyx_L1_error)
1909 __Pyx_GOTREF(__pyx_t_2);
1910 __Pyx_GIVEREF(__pyx_t_2);
1911 __Pyx_GOTREF(__pyx_v_self->_detected_charset);
1912 __Pyx_DECREF(__pyx_v_self->_detected_charset);
1913 __pyx_v_self->_detected_charset = ((PyObject*)__pyx_t_2);
1914 __pyx_t_2 = 0;
1915
1916 /* "cchardet/_cchardet.pyx":82
1917 * uchardet_data_end(self._ud)
1918 * self._detected_charset = uchardet_get_charset(self._ud)
1919 * self._detected_confidence = uchardet_get_confidence(self._ud) # <<<<<<<<<<<<<<
1920 *
1921 * uchardet_delete(self._ud)
1922 */
1923 __pyx_v_self->_detected_confidence = uchardet_get_confidence(__pyx_v_self->_ud);
1924
1925 /* "cchardet/_cchardet.pyx":84
1926 * self._detected_confidence = uchardet_get_confidence(self._ud)
1927 *
1928 * uchardet_delete(self._ud) # <<<<<<<<<<<<<<
1929 * self._closed = 1
1930 *
1931 */
1932 uchardet_delete(__pyx_v_self->_ud);
1933
1934 /* "cchardet/_cchardet.pyx":85
1935 *
1936 * uchardet_delete(self._ud)
1937 * self._closed = 1 # <<<<<<<<<<<<<<
1938 *
1939 * @property
1940 */
1941 __pyx_v_self->_closed = 1;
1942
1943 /* "cchardet/_cchardet.pyx":79
1944 *
1945 * def close(self):
1946 * if not self._closed: # <<<<<<<<<<<<<<
1947 * uchardet_data_end(self._ud)
1948 * self._detected_charset = uchardet_get_charset(self._ud)
1949 */
1950 }
1951
1952 /* "cchardet/_cchardet.pyx":78
1953 * self._detected_confidence = uchardet_get_confidence(self._ud)
1954 *
1955 * def close(self): # <<<<<<<<<<<<<<
1956 * if not self._closed:
1957 * uchardet_data_end(self._ud)
1958 */
1959
1960 /* function exit code */
1961 __pyx_r = Py_None; __Pyx_INCREF(Py_None);
1962 goto __pyx_L0;
1963 __pyx_L1_error:;
1964 __Pyx_XDECREF(__pyx_t_2);
1965 __Pyx_AddTraceback("cchardet._cchardet.UniversalDetector.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
1966 __pyx_r = NULL;
1967 __pyx_L0:;
1968 __Pyx_XGIVEREF(__pyx_r);
1969 __Pyx_RefNannyFinishContext();
1970 return __pyx_r;
1971 }
1972
1973 /* "cchardet/_cchardet.pyx":88
1974 *
1975 * @property
1976 * def done(self): # <<<<<<<<<<<<<<
1977 * return bool(self._done)
1978 *
1979 */
1980
1981 /* Python wrapper */
1982 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_4done_1__get__(PyObject *__pyx_v_self); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_4done_1__get__(PyObject * __pyx_v_self)1983 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_4done_1__get__(PyObject *__pyx_v_self) {
1984 PyObject *__pyx_r = 0;
1985 __Pyx_RefNannyDeclarations
1986 __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
1987 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4done___get__(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self));
1988
1989 /* function exit code */
1990 __Pyx_RefNannyFinishContext();
1991 return __pyx_r;
1992 }
1993
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4done___get__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self)1994 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_4done___get__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self) {
1995 PyObject *__pyx_r = NULL;
1996 __Pyx_RefNannyDeclarations
1997 PyObject *__pyx_t_1 = NULL;
1998 int __pyx_t_2;
1999 int __pyx_lineno = 0;
2000 const char *__pyx_filename = NULL;
2001 int __pyx_clineno = 0;
2002 __Pyx_RefNannySetupContext("__get__", 0);
2003
2004 /* "cchardet/_cchardet.pyx":89
2005 * @property
2006 * def done(self):
2007 * return bool(self._done) # <<<<<<<<<<<<<<
2008 *
2009 * @property
2010 */
2011 __Pyx_XDECREF(__pyx_r);
2012 __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_done); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 89, __pyx_L1_error)
2013 __Pyx_GOTREF(__pyx_t_1);
2014 __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 89, __pyx_L1_error)
2015 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2016 __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_2))); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 89, __pyx_L1_error)
2017 __Pyx_GOTREF(__pyx_t_1);
2018 __pyx_r = __pyx_t_1;
2019 __pyx_t_1 = 0;
2020 goto __pyx_L0;
2021
2022 /* "cchardet/_cchardet.pyx":88
2023 *
2024 * @property
2025 * def done(self): # <<<<<<<<<<<<<<
2026 * return bool(self._done)
2027 *
2028 */
2029
2030 /* function exit code */
2031 __pyx_L1_error:;
2032 __Pyx_XDECREF(__pyx_t_1);
2033 __Pyx_AddTraceback("cchardet._cchardet.UniversalDetector.done.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2034 __pyx_r = NULL;
2035 __pyx_L0:;
2036 __Pyx_XGIVEREF(__pyx_r);
2037 __Pyx_RefNannyFinishContext();
2038 return __pyx_r;
2039 }
2040
2041 /* "cchardet/_cchardet.pyx":92
2042 *
2043 * @property
2044 * def result(self): # <<<<<<<<<<<<<<
2045 * if len(self._detected_charset):
2046 * return self._detected_charset, self._detected_confidence
2047 */
2048
2049 /* Python wrapper */
2050 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_6result_1__get__(PyObject *__pyx_v_self); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_6result_1__get__(PyObject * __pyx_v_self)2051 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_6result_1__get__(PyObject *__pyx_v_self) {
2052 PyObject *__pyx_r = 0;
2053 __Pyx_RefNannyDeclarations
2054 __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
2055 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6result___get__(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self));
2056
2057 /* function exit code */
2058 __Pyx_RefNannyFinishContext();
2059 return __pyx_r;
2060 }
2061
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6result___get__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self)2062 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_6result___get__(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self) {
2063 PyObject *__pyx_r = NULL;
2064 __Pyx_RefNannyDeclarations
2065 PyObject *__pyx_t_1 = NULL;
2066 Py_ssize_t __pyx_t_2;
2067 int __pyx_t_3;
2068 PyObject *__pyx_t_4 = NULL;
2069 int __pyx_lineno = 0;
2070 const char *__pyx_filename = NULL;
2071 int __pyx_clineno = 0;
2072 __Pyx_RefNannySetupContext("__get__", 0);
2073
2074 /* "cchardet/_cchardet.pyx":93
2075 * @property
2076 * def result(self):
2077 * if len(self._detected_charset): # <<<<<<<<<<<<<<
2078 * return self._detected_charset, self._detected_confidence
2079 * else:
2080 */
2081 __pyx_t_1 = __pyx_v_self->_detected_charset;
2082 __Pyx_INCREF(__pyx_t_1);
2083 if (unlikely(__pyx_t_1 == Py_None)) {
2084 PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
2085 __PYX_ERR(1, 93, __pyx_L1_error)
2086 }
2087 __pyx_t_2 = PyBytes_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(1, 93, __pyx_L1_error)
2088 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2089 __pyx_t_3 = (__pyx_t_2 != 0);
2090 if (__pyx_t_3) {
2091
2092 /* "cchardet/_cchardet.pyx":94
2093 * def result(self):
2094 * if len(self._detected_charset):
2095 * return self._detected_charset, self._detected_confidence # <<<<<<<<<<<<<<
2096 * else:
2097 * return None, None
2098 */
2099 __Pyx_XDECREF(__pyx_r);
2100 __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->_detected_confidence); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 94, __pyx_L1_error)
2101 __Pyx_GOTREF(__pyx_t_1);
2102 __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 94, __pyx_L1_error)
2103 __Pyx_GOTREF(__pyx_t_4);
2104 __Pyx_INCREF(__pyx_v_self->_detected_charset);
2105 __Pyx_GIVEREF(__pyx_v_self->_detected_charset);
2106 PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->_detected_charset);
2107 __Pyx_GIVEREF(__pyx_t_1);
2108 PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
2109 __pyx_t_1 = 0;
2110 __pyx_r = __pyx_t_4;
2111 __pyx_t_4 = 0;
2112 goto __pyx_L0;
2113
2114 /* "cchardet/_cchardet.pyx":93
2115 * @property
2116 * def result(self):
2117 * if len(self._detected_charset): # <<<<<<<<<<<<<<
2118 * return self._detected_charset, self._detected_confidence
2119 * else:
2120 */
2121 }
2122
2123 /* "cchardet/_cchardet.pyx":96
2124 * return self._detected_charset, self._detected_confidence
2125 * else:
2126 * return None, None # <<<<<<<<<<<<<<
2127 */
2128 /*else*/ {
2129 __Pyx_XDECREF(__pyx_r);
2130 __Pyx_INCREF(__pyx_tuple__2);
2131 __pyx_r = __pyx_tuple__2;
2132 goto __pyx_L0;
2133 }
2134
2135 /* "cchardet/_cchardet.pyx":92
2136 *
2137 * @property
2138 * def result(self): # <<<<<<<<<<<<<<
2139 * if len(self._detected_charset):
2140 * return self._detected_charset, self._detected_confidence
2141 */
2142
2143 /* function exit code */
2144 __pyx_L1_error:;
2145 __Pyx_XDECREF(__pyx_t_1);
2146 __Pyx_XDECREF(__pyx_t_4);
2147 __Pyx_AddTraceback("cchardet._cchardet.UniversalDetector.result.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2148 __pyx_r = NULL;
2149 __pyx_L0:;
2150 __Pyx_XGIVEREF(__pyx_r);
2151 __Pyx_RefNannyFinishContext();
2152 return __pyx_r;
2153 }
2154
2155 /* "(tree fragment)":1
2156 * def __reduce_cython__(self): # <<<<<<<<<<<<<<
2157 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2158 * def __setstate_cython__(self, __pyx_state):
2159 */
2160
2161 /* Python wrapper */
2162 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_9__reduce_cython__(PyObject * __pyx_v_self,CYTHON_UNUSED PyObject * unused)2163 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
2164 PyObject *__pyx_r = 0;
2165 __Pyx_RefNannyDeclarations
2166 __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
2167 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector_8__reduce_cython__(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self));
2168
2169 /* function exit code */
2170 __Pyx_RefNannyFinishContext();
2171 return __pyx_r;
2172 }
2173
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self)2174 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self) {
2175 PyObject *__pyx_r = NULL;
2176 __Pyx_RefNannyDeclarations
2177 PyObject *__pyx_t_1 = NULL;
2178 int __pyx_lineno = 0;
2179 const char *__pyx_filename = NULL;
2180 int __pyx_clineno = 0;
2181 __Pyx_RefNannySetupContext("__reduce_cython__", 0);
2182
2183 /* "(tree fragment)":2
2184 * def __reduce_cython__(self):
2185 * raise TypeError("self._ud cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<<
2186 * def __setstate_cython__(self, __pyx_state):
2187 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2188 */
2189 __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
2190 __Pyx_GOTREF(__pyx_t_1);
2191 __Pyx_Raise(__pyx_t_1, 0, 0, 0);
2192 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2193 __PYX_ERR(0, 2, __pyx_L1_error)
2194
2195 /* "(tree fragment)":1
2196 * def __reduce_cython__(self): # <<<<<<<<<<<<<<
2197 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2198 * def __setstate_cython__(self, __pyx_state):
2199 */
2200
2201 /* function exit code */
2202 __pyx_L1_error:;
2203 __Pyx_XDECREF(__pyx_t_1);
2204 __Pyx_AddTraceback("cchardet._cchardet.UniversalDetector.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2205 __pyx_r = NULL;
2206 __Pyx_XGIVEREF(__pyx_r);
2207 __Pyx_RefNannyFinishContext();
2208 return __pyx_r;
2209 }
2210
2211 /* "(tree fragment)":3
2212 * def __reduce_cython__(self):
2213 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2214 * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
2215 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2216 */
2217
2218 /* Python wrapper */
2219 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_11__setstate_cython__(PyObject * __pyx_v_self,PyObject * __pyx_v___pyx_state)2220 static PyObject *__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
2221 PyObject *__pyx_r = 0;
2222 __Pyx_RefNannyDeclarations
2223 __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
2224 __pyx_r = __pyx_pf_8cchardet_9_cchardet_17UniversalDetector_10__setstate_cython__(((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
2225
2226 /* function exit code */
2227 __Pyx_RefNannyFinishContext();
2228 return __pyx_r;
2229 }
2230
__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector * __pyx_v_self,CYTHON_UNUSED PyObject * __pyx_v___pyx_state)2231 static PyObject *__pyx_pf_8cchardet_9_cchardet_17UniversalDetector_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
2232 PyObject *__pyx_r = NULL;
2233 __Pyx_RefNannyDeclarations
2234 PyObject *__pyx_t_1 = NULL;
2235 int __pyx_lineno = 0;
2236 const char *__pyx_filename = NULL;
2237 int __pyx_clineno = 0;
2238 __Pyx_RefNannySetupContext("__setstate_cython__", 0);
2239
2240 /* "(tree fragment)":4
2241 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2242 * def __setstate_cython__(self, __pyx_state):
2243 * raise TypeError("self._ud cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<<
2244 */
2245 __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error)
2246 __Pyx_GOTREF(__pyx_t_1);
2247 __Pyx_Raise(__pyx_t_1, 0, 0, 0);
2248 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2249 __PYX_ERR(0, 4, __pyx_L1_error)
2250
2251 /* "(tree fragment)":3
2252 * def __reduce_cython__(self):
2253 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2254 * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
2255 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2256 */
2257
2258 /* function exit code */
2259 __pyx_L1_error:;
2260 __Pyx_XDECREF(__pyx_t_1);
2261 __Pyx_AddTraceback("cchardet._cchardet.UniversalDetector.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2262 __pyx_r = NULL;
2263 __Pyx_XGIVEREF(__pyx_r);
2264 __Pyx_RefNannyFinishContext();
2265 return __pyx_r;
2266 }
2267
__pyx_tp_new_8cchardet_9_cchardet_UniversalDetector(PyTypeObject * t,CYTHON_UNUSED PyObject * a,CYTHON_UNUSED PyObject * k)2268 static PyObject *__pyx_tp_new_8cchardet_9_cchardet_UniversalDetector(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
2269 struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *p;
2270 PyObject *o;
2271 if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
2272 o = (*t->tp_alloc)(t, 0);
2273 } else {
2274 o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
2275 }
2276 if (unlikely(!o)) return 0;
2277 p = ((struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)o);
2278 p->_detected_charset = ((PyObject*)Py_None); Py_INCREF(Py_None);
2279 return o;
2280 }
2281
__pyx_tp_dealloc_8cchardet_9_cchardet_UniversalDetector(PyObject * o)2282 static void __pyx_tp_dealloc_8cchardet_9_cchardet_UniversalDetector(PyObject *o) {
2283 struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *p = (struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector *)o;
2284 #if CYTHON_USE_TP_FINALIZE
2285 if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
2286 if (PyObject_CallFinalizerFromDealloc(o)) return;
2287 }
2288 #endif
2289 Py_CLEAR(p->_detected_charset);
2290 (*Py_TYPE(o)->tp_free)(o);
2291 }
2292
__pyx_getprop_8cchardet_9_cchardet_17UniversalDetector_done(PyObject * o,CYTHON_UNUSED void * x)2293 static PyObject *__pyx_getprop_8cchardet_9_cchardet_17UniversalDetector_done(PyObject *o, CYTHON_UNUSED void *x) {
2294 return __pyx_pw_8cchardet_9_cchardet_17UniversalDetector_4done_1__get__(o);
2295 }
2296
__pyx_getprop_8cchardet_9_cchardet_17UniversalDetector_result(PyObject * o,CYTHON_UNUSED void * x)2297 static PyObject *__pyx_getprop_8cchardet_9_cchardet_17UniversalDetector_result(PyObject *o, CYTHON_UNUSED void *x) {
2298 return __pyx_pw_8cchardet_9_cchardet_17UniversalDetector_6result_1__get__(o);
2299 }
2300
2301 static PyMethodDef __pyx_methods_8cchardet_9_cchardet_UniversalDetector[] = {
2302 {"reset", (PyCFunction)__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_3reset, METH_NOARGS, 0},
2303 {"feed", (PyCFunction)__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_5feed, METH_O, 0},
2304 {"close", (PyCFunction)__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_7close, METH_NOARGS, 0},
2305 {"__reduce_cython__", (PyCFunction)__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_9__reduce_cython__, METH_NOARGS, 0},
2306 {"__setstate_cython__", (PyCFunction)__pyx_pw_8cchardet_9_cchardet_17UniversalDetector_11__setstate_cython__, METH_O, 0},
2307 {0, 0, 0, 0}
2308 };
2309
2310 static struct PyGetSetDef __pyx_getsets_8cchardet_9_cchardet_UniversalDetector[] = {
2311 {(char *)"done", __pyx_getprop_8cchardet_9_cchardet_17UniversalDetector_done, 0, (char *)0, 0},
2312 {(char *)"result", __pyx_getprop_8cchardet_9_cchardet_17UniversalDetector_result, 0, (char *)0, 0},
2313 {0, 0, 0, 0, 0}
2314 };
2315
2316 static PyTypeObject __pyx_type_8cchardet_9_cchardet_UniversalDetector = {
2317 PyVarObject_HEAD_INIT(0, 0)
2318 "cchardet._cchardet.UniversalDetector", /*tp_name*/
2319 sizeof(struct __pyx_obj_8cchardet_9_cchardet_UniversalDetector), /*tp_basicsize*/
2320 0, /*tp_itemsize*/
2321 __pyx_tp_dealloc_8cchardet_9_cchardet_UniversalDetector, /*tp_dealloc*/
2322 #if PY_VERSION_HEX < 0x030800b4
2323 0, /*tp_print*/
2324 #endif
2325 #if PY_VERSION_HEX >= 0x030800b4
2326 0, /*tp_vectorcall_offset*/
2327 #endif
2328 0, /*tp_getattr*/
2329 0, /*tp_setattr*/
2330 #if PY_MAJOR_VERSION < 3
2331 0, /*tp_compare*/
2332 #endif
2333 #if PY_MAJOR_VERSION >= 3
2334 0, /*tp_as_async*/
2335 #endif
2336 0, /*tp_repr*/
2337 0, /*tp_as_number*/
2338 0, /*tp_as_sequence*/
2339 0, /*tp_as_mapping*/
2340 0, /*tp_hash*/
2341 0, /*tp_call*/
2342 0, /*tp_str*/
2343 0, /*tp_getattro*/
2344 0, /*tp_setattro*/
2345 0, /*tp_as_buffer*/
2346 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
2347 0, /*tp_doc*/
2348 0, /*tp_traverse*/
2349 0, /*tp_clear*/
2350 0, /*tp_richcompare*/
2351 0, /*tp_weaklistoffset*/
2352 0, /*tp_iter*/
2353 0, /*tp_iternext*/
2354 __pyx_methods_8cchardet_9_cchardet_UniversalDetector, /*tp_methods*/
2355 0, /*tp_members*/
2356 __pyx_getsets_8cchardet_9_cchardet_UniversalDetector, /*tp_getset*/
2357 0, /*tp_base*/
2358 0, /*tp_dict*/
2359 0, /*tp_descr_get*/
2360 0, /*tp_descr_set*/
2361 0, /*tp_dictoffset*/
2362 __pyx_pw_8cchardet_9_cchardet_17UniversalDetector_1__init__, /*tp_init*/
2363 0, /*tp_alloc*/
2364 __pyx_tp_new_8cchardet_9_cchardet_UniversalDetector, /*tp_new*/
2365 0, /*tp_free*/
2366 0, /*tp_is_gc*/
2367 0, /*tp_bases*/
2368 0, /*tp_mro*/
2369 0, /*tp_cache*/
2370 0, /*tp_subclasses*/
2371 0, /*tp_weaklist*/
2372 0, /*tp_del*/
2373 0, /*tp_version_tag*/
2374 #if PY_VERSION_HEX >= 0x030400a1
2375 0, /*tp_finalize*/
2376 #endif
2377 #if PY_VERSION_HEX >= 0x030800b1
2378 0, /*tp_vectorcall*/
2379 #endif
2380 #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
2381 0, /*tp_print*/
2382 #endif
2383 };
2384
2385 static PyMethodDef __pyx_methods[] = {
2386 {0, 0, 0, 0}
2387 };
2388
2389 #if PY_MAJOR_VERSION >= 3
2390 #if CYTHON_PEP489_MULTI_PHASE_INIT
2391 static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
2392 static int __pyx_pymod_exec__cchardet(PyObject* module); /*proto*/
2393 static PyModuleDef_Slot __pyx_moduledef_slots[] = {
2394 {Py_mod_create, (void*)__pyx_pymod_create},
2395 {Py_mod_exec, (void*)__pyx_pymod_exec__cchardet},
2396 {0, NULL}
2397 };
2398 #endif
2399
2400 static struct PyModuleDef __pyx_moduledef = {
2401 PyModuleDef_HEAD_INIT,
2402 "_cchardet",
2403 0, /* m_doc */
2404 #if CYTHON_PEP489_MULTI_PHASE_INIT
2405 0, /* m_size */
2406 #else
2407 -1, /* m_size */
2408 #endif
2409 __pyx_methods /* m_methods */,
2410 #if CYTHON_PEP489_MULTI_PHASE_INIT
2411 __pyx_moduledef_slots, /* m_slots */
2412 #else
2413 NULL, /* m_reload */
2414 #endif
2415 NULL, /* m_traverse */
2416 NULL, /* m_clear */
2417 NULL /* m_free */
2418 };
2419 #endif
2420 #ifndef CYTHON_SMALL_CODE
2421 #if defined(__clang__)
2422 #define CYTHON_SMALL_CODE
2423 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
2424 #define CYTHON_SMALL_CODE __attribute__((cold))
2425 #else
2426 #define CYTHON_SMALL_CODE
2427 #endif
2428 #endif
2429
2430 static __Pyx_StringTabEntry __pyx_string_tab[] = {
2431 {&__pyx_kp_u_Handle_data_error, __pyx_k_Handle_data_error, sizeof(__pyx_k_Handle_data_error), 0, 1, 0, 0},
2432 {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
2433 {&__pyx_n_s_UniversalDetector, __pyx_k_UniversalDetector, sizeof(__pyx_k_UniversalDetector), 0, 0, 1, 1},
2434 {&__pyx_kp_b__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 0, 0},
2435 {&__pyx_n_s_cchardet__cchardet, __pyx_k_cchardet__cchardet, sizeof(__pyx_k_cchardet__cchardet), 0, 0, 1, 1},
2436 {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
2437 {&__pyx_n_s_detect_with_confidence, __pyx_k_detect_with_confidence, sizeof(__pyx_k_detect_with_confidence), 0, 0, 1, 1},
2438 {&__pyx_n_s_detected_charset, __pyx_k_detected_charset, sizeof(__pyx_k_detected_charset), 0, 0, 1, 1},
2439 {&__pyx_n_s_detected_confidence, __pyx_k_detected_confidence, sizeof(__pyx_k_detected_confidence), 0, 0, 1, 1},
2440 {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
2441 {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1},
2442 {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
2443 {&__pyx_n_s_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 0, 0, 1, 1},
2444 {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
2445 {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
2446 {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
2447 {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
2448 {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1},
2449 {&__pyx_kp_s_self__ud_cannot_be_converted_to, __pyx_k_self__ud_cannot_be_converted_to, sizeof(__pyx_k_self__ud_cannot_be_converted_to), 0, 0, 1, 0},
2450 {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
2451 {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
2452 {&__pyx_kp_s_src_cchardet__cchardet_pyx, __pyx_k_src_cchardet__cchardet_pyx, sizeof(__pyx_k_src_cchardet__cchardet_pyx), 0, 0, 1, 0},
2453 {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
2454 {&__pyx_n_s_ud, __pyx_k_ud, sizeof(__pyx_k_ud), 0, 0, 1, 1},
2455 {0, 0, 0, 0, 0, 0, 0}
2456 };
__Pyx_InitCachedBuiltins(void)2457 static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
2458 __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 2, __pyx_L1_error)
2459 return 0;
2460 __pyx_L1_error:;
2461 return -1;
2462 }
2463
__Pyx_InitCachedConstants(void)2464 static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
2465 __Pyx_RefNannyDeclarations
2466 __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
2467
2468 /* "cchardet/_cchardet.pyx":22
2469 * if result == -1:
2470 * uchardet_delete(ud)
2471 * raise Exception("Handle data error") # <<<<<<<<<<<<<<
2472 *
2473 * uchardet_data_end(ud)
2474 */
2475 __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Handle_data_error); if (unlikely(!__pyx_tuple_)) __PYX_ERR(1, 22, __pyx_L1_error)
2476 __Pyx_GOTREF(__pyx_tuple_);
2477 __Pyx_GIVEREF(__pyx_tuple_);
2478
2479 /* "cchardet/_cchardet.pyx":33
2480 * return detected_charset, detected_confidence
2481 *
2482 * return None, None # <<<<<<<<<<<<<<
2483 *
2484 * cdef class UniversalDetector:
2485 */
2486 __pyx_tuple__2 = PyTuple_Pack(2, Py_None, Py_None); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 33, __pyx_L1_error)
2487 __Pyx_GOTREF(__pyx_tuple__2);
2488 __Pyx_GIVEREF(__pyx_tuple__2);
2489
2490 /* "(tree fragment)":2
2491 * def __reduce_cython__(self):
2492 * raise TypeError("self._ud cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<<
2493 * def __setstate_cython__(self, __pyx_state):
2494 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2495 */
2496 __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_self__ud_cannot_be_converted_to); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 2, __pyx_L1_error)
2497 __Pyx_GOTREF(__pyx_tuple__4);
2498 __Pyx_GIVEREF(__pyx_tuple__4);
2499
2500 /* "(tree fragment)":4
2501 * raise TypeError("self._ud cannot be converted to a Python object for pickling")
2502 * def __setstate_cython__(self, __pyx_state):
2503 * raise TypeError("self._ud cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<<
2504 */
2505 __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_self__ud_cannot_be_converted_to); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 4, __pyx_L1_error)
2506 __Pyx_GOTREF(__pyx_tuple__5);
2507 __Pyx_GIVEREF(__pyx_tuple__5);
2508
2509 /* "cchardet/_cchardet.pyx":14
2510 * cdef float uchardet_get_confidence(uchardet_t ud)
2511 *
2512 * def detect_with_confidence(bytes msg): # <<<<<<<<<<<<<<
2513 * cdef int length = len(msg)
2514 *
2515 */
2516 __pyx_tuple__6 = PyTuple_Pack(6, __pyx_n_s_msg, __pyx_n_s_length, __pyx_n_s_ud, __pyx_n_s_result, __pyx_n_s_detected_charset, __pyx_n_s_detected_confidence); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(1, 14, __pyx_L1_error)
2517 __Pyx_GOTREF(__pyx_tuple__6);
2518 __Pyx_GIVEREF(__pyx_tuple__6);
2519 __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(1, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_cchardet__cchardet_pyx, __pyx_n_s_detect_with_confidence, 14, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(1, 14, __pyx_L1_error)
2520 __Pyx_RefNannyFinishContext();
2521 return 0;
2522 __pyx_L1_error:;
2523 __Pyx_RefNannyFinishContext();
2524 return -1;
2525 }
2526
__Pyx_InitGlobals(void)2527 static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
2528 if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(1, 1, __pyx_L1_error);
2529 return 0;
2530 __pyx_L1_error:;
2531 return -1;
2532 }
2533
2534 static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
2535 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
2536 static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
2537 static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
2538 static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
2539 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
2540 static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
2541
__Pyx_modinit_global_init_code(void)2542 static int __Pyx_modinit_global_init_code(void) {
2543 __Pyx_RefNannyDeclarations
2544 __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
2545 /*--- Global init code ---*/
2546 __Pyx_RefNannyFinishContext();
2547 return 0;
2548 }
2549
__Pyx_modinit_variable_export_code(void)2550 static int __Pyx_modinit_variable_export_code(void) {
2551 __Pyx_RefNannyDeclarations
2552 __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
2553 /*--- Variable export code ---*/
2554 __Pyx_RefNannyFinishContext();
2555 return 0;
2556 }
2557
__Pyx_modinit_function_export_code(void)2558 static int __Pyx_modinit_function_export_code(void) {
2559 __Pyx_RefNannyDeclarations
2560 __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
2561 /*--- Function export code ---*/
2562 __Pyx_RefNannyFinishContext();
2563 return 0;
2564 }
2565
__Pyx_modinit_type_init_code(void)2566 static int __Pyx_modinit_type_init_code(void) {
2567 __Pyx_RefNannyDeclarations
2568 int __pyx_lineno = 0;
2569 const char *__pyx_filename = NULL;
2570 int __pyx_clineno = 0;
2571 __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
2572 /*--- Type init code ---*/
2573 if (PyType_Ready(&__pyx_type_8cchardet_9_cchardet_UniversalDetector) < 0) __PYX_ERR(1, 35, __pyx_L1_error)
2574 #if PY_VERSION_HEX < 0x030800B1
2575 __pyx_type_8cchardet_9_cchardet_UniversalDetector.tp_print = 0;
2576 #endif
2577 if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8cchardet_9_cchardet_UniversalDetector.tp_dictoffset && __pyx_type_8cchardet_9_cchardet_UniversalDetector.tp_getattro == PyObject_GenericGetAttr)) {
2578 __pyx_type_8cchardet_9_cchardet_UniversalDetector.tp_getattro = __Pyx_PyObject_GenericGetAttr;
2579 }
2580 if (PyObject_SetAttr(__pyx_m, __pyx_n_s_UniversalDetector, (PyObject *)&__pyx_type_8cchardet_9_cchardet_UniversalDetector) < 0) __PYX_ERR(1, 35, __pyx_L1_error)
2581 if (__Pyx_setup_reduce((PyObject*)&__pyx_type_8cchardet_9_cchardet_UniversalDetector) < 0) __PYX_ERR(1, 35, __pyx_L1_error)
2582 __pyx_ptype_8cchardet_9_cchardet_UniversalDetector = &__pyx_type_8cchardet_9_cchardet_UniversalDetector;
2583 __Pyx_RefNannyFinishContext();
2584 return 0;
2585 __pyx_L1_error:;
2586 __Pyx_RefNannyFinishContext();
2587 return -1;
2588 }
2589
__Pyx_modinit_type_import_code(void)2590 static int __Pyx_modinit_type_import_code(void) {
2591 __Pyx_RefNannyDeclarations
2592 __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
2593 /*--- Type import code ---*/
2594 __Pyx_RefNannyFinishContext();
2595 return 0;
2596 }
2597
__Pyx_modinit_variable_import_code(void)2598 static int __Pyx_modinit_variable_import_code(void) {
2599 __Pyx_RefNannyDeclarations
2600 __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
2601 /*--- Variable import code ---*/
2602 __Pyx_RefNannyFinishContext();
2603 return 0;
2604 }
2605
__Pyx_modinit_function_import_code(void)2606 static int __Pyx_modinit_function_import_code(void) {
2607 __Pyx_RefNannyDeclarations
2608 __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
2609 /*--- Function import code ---*/
2610 __Pyx_RefNannyFinishContext();
2611 return 0;
2612 }
2613
2614
2615 #ifndef CYTHON_NO_PYINIT_EXPORT
2616 #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
2617 #elif PY_MAJOR_VERSION < 3
2618 #ifdef __cplusplus
2619 #define __Pyx_PyMODINIT_FUNC extern "C" void
2620 #else
2621 #define __Pyx_PyMODINIT_FUNC void
2622 #endif
2623 #else
2624 #ifdef __cplusplus
2625 #define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
2626 #else
2627 #define __Pyx_PyMODINIT_FUNC PyObject *
2628 #endif
2629 #endif
2630
2631
2632 #if PY_MAJOR_VERSION < 3
2633 __Pyx_PyMODINIT_FUNC init_cchardet(void) CYTHON_SMALL_CODE; /*proto*/
init_cchardet(void)2634 __Pyx_PyMODINIT_FUNC init_cchardet(void)
2635 #else
2636 __Pyx_PyMODINIT_FUNC PyInit__cchardet(void) CYTHON_SMALL_CODE; /*proto*/
2637 __Pyx_PyMODINIT_FUNC PyInit__cchardet(void)
2638 #if CYTHON_PEP489_MULTI_PHASE_INIT
2639 {
2640 return PyModuleDef_Init(&__pyx_moduledef);
2641 }
2642 static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
2643 #if PY_VERSION_HEX >= 0x030700A1
2644 static PY_INT64_T main_interpreter_id = -1;
2645 PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
2646 if (main_interpreter_id == -1) {
2647 main_interpreter_id = current_id;
2648 return (unlikely(current_id == -1)) ? -1 : 0;
2649 } else if (unlikely(main_interpreter_id != current_id))
2650 #else
2651 static PyInterpreterState *main_interpreter = NULL;
2652 PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
2653 if (!main_interpreter) {
2654 main_interpreter = current_interpreter;
2655 } else if (unlikely(main_interpreter != current_interpreter))
2656 #endif
2657 {
2658 PyErr_SetString(
2659 PyExc_ImportError,
2660 "Interpreter change detected - this module can only be loaded into one interpreter per process.");
2661 return -1;
2662 }
2663 return 0;
2664 }
2665 static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
2666 PyObject *value = PyObject_GetAttrString(spec, from_name);
2667 int result = 0;
2668 if (likely(value)) {
2669 if (allow_none || value != Py_None) {
2670 result = PyDict_SetItemString(moddict, to_name, value);
2671 }
2672 Py_DECREF(value);
2673 } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
2674 PyErr_Clear();
2675 } else {
2676 result = -1;
2677 }
2678 return result;
2679 }
2680 static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
2681 PyObject *module = NULL, *moddict, *modname;
2682 if (__Pyx_check_single_interpreter())
2683 return NULL;
2684 if (__pyx_m)
2685 return __Pyx_NewRef(__pyx_m);
2686 modname = PyObject_GetAttrString(spec, "name");
2687 if (unlikely(!modname)) goto bad;
2688 module = PyModule_NewObject(modname);
2689 Py_DECREF(modname);
2690 if (unlikely(!module)) goto bad;
2691 moddict = PyModule_GetDict(module);
2692 if (unlikely(!moddict)) goto bad;
2693 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
2694 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
2695 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
2696 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
2697 return module;
2698 bad:
2699 Py_XDECREF(module);
2700 return NULL;
2701 }
2702
2703
2704 static CYTHON_SMALL_CODE int __pyx_pymod_exec__cchardet(PyObject *__pyx_pyinit_module)
2705 #endif
2706 #endif
2707 {
2708 PyObject *__pyx_t_1 = NULL;
2709 int __pyx_lineno = 0;
2710 const char *__pyx_filename = NULL;
2711 int __pyx_clineno = 0;
2712 __Pyx_RefNannyDeclarations
2713 #if CYTHON_PEP489_MULTI_PHASE_INIT
2714 if (__pyx_m) {
2715 if (__pyx_m == __pyx_pyinit_module) return 0;
2716 PyErr_SetString(PyExc_RuntimeError, "Module '_cchardet' has already been imported. Re-initialisation is not supported.");
2717 return -1;
2718 }
2719 #elif PY_MAJOR_VERSION >= 3
2720 if (__pyx_m) return __Pyx_NewRef(__pyx_m);
2721 #endif
2722 #if CYTHON_REFNANNY
2723 __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
2724 if (!__Pyx_RefNanny) {
2725 PyErr_Clear();
2726 __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
2727 if (!__Pyx_RefNanny)
2728 Py_FatalError("failed to import 'refnanny' module");
2729 }
2730 #endif
2731 __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit__cchardet(void)", 0);
2732 if (__Pyx_check_binary_version() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2733 #ifdef __Pxy_PyFrame_Initialize_Offsets
2734 __Pxy_PyFrame_Initialize_Offsets();
2735 #endif
2736 __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(1, 1, __pyx_L1_error)
2737 __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(1, 1, __pyx_L1_error)
2738 __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(1, 1, __pyx_L1_error)
2739 #ifdef __Pyx_CyFunction_USED
2740 if (__pyx_CyFunction_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2741 #endif
2742 #ifdef __Pyx_FusedFunction_USED
2743 if (__pyx_FusedFunction_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2744 #endif
2745 #ifdef __Pyx_Coroutine_USED
2746 if (__pyx_Coroutine_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2747 #endif
2748 #ifdef __Pyx_Generator_USED
2749 if (__pyx_Generator_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2750 #endif
2751 #ifdef __Pyx_AsyncGen_USED
2752 if (__pyx_AsyncGen_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2753 #endif
2754 #ifdef __Pyx_StopAsyncIteration_USED
2755 if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2756 #endif
2757 /*--- Library function declarations ---*/
2758 /*--- Threads initialization code ---*/
2759 #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
2760 #ifdef WITH_THREAD /* Python build with threading support? */
2761 PyEval_InitThreads();
2762 #endif
2763 #endif
2764 /*--- Module creation code ---*/
2765 #if CYTHON_PEP489_MULTI_PHASE_INIT
2766 __pyx_m = __pyx_pyinit_module;
2767 Py_INCREF(__pyx_m);
2768 #else
2769 #if PY_MAJOR_VERSION < 3
2770 __pyx_m = Py_InitModule4("_cchardet", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
2771 #else
2772 __pyx_m = PyModule_Create(&__pyx_moduledef);
2773 #endif
2774 if (unlikely(!__pyx_m)) __PYX_ERR(1, 1, __pyx_L1_error)
2775 #endif
2776 __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(1, 1, __pyx_L1_error)
2777 Py_INCREF(__pyx_d);
2778 __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(1, 1, __pyx_L1_error)
2779 Py_INCREF(__pyx_b);
2780 __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(1, 1, __pyx_L1_error)
2781 Py_INCREF(__pyx_cython_runtime);
2782 if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(1, 1, __pyx_L1_error);
2783 /*--- Initialize various global constants etc. ---*/
2784 if (__Pyx_InitGlobals() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2785 #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
2786 if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2787 #endif
2788 if (__pyx_module_is_main_cchardet___cchardet) {
2789 if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2790 }
2791 #if PY_MAJOR_VERSION >= 3
2792 {
2793 PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(1, 1, __pyx_L1_error)
2794 if (!PyDict_GetItemString(modules, "cchardet._cchardet")) {
2795 if (unlikely(PyDict_SetItemString(modules, "cchardet._cchardet", __pyx_m) < 0)) __PYX_ERR(1, 1, __pyx_L1_error)
2796 }
2797 }
2798 #endif
2799 /*--- Builtin init code ---*/
2800 if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2801 /*--- Constants init code ---*/
2802 if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2803 /*--- Global type/function init code ---*/
2804 (void)__Pyx_modinit_global_init_code();
2805 (void)__Pyx_modinit_variable_export_code();
2806 (void)__Pyx_modinit_function_export_code();
2807 if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(1, 1, __pyx_L1_error)
2808 (void)__Pyx_modinit_type_import_code();
2809 (void)__Pyx_modinit_variable_import_code();
2810 (void)__Pyx_modinit_function_import_code();
2811 /*--- Execution code ---*/
2812 #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
2813 if (__Pyx_patch_abc() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2814 #endif
2815
2816 /* "cchardet/_cchardet.pyx":14
2817 * cdef float uchardet_get_confidence(uchardet_t ud)
2818 *
2819 * def detect_with_confidence(bytes msg): # <<<<<<<<<<<<<<
2820 * cdef int length = len(msg)
2821 *
2822 */
2823 __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cchardet_9_cchardet_1detect_with_confidence, NULL, __pyx_n_s_cchardet__cchardet); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
2824 __Pyx_GOTREF(__pyx_t_1);
2825 if (PyDict_SetItem(__pyx_d, __pyx_n_s_detect_with_confidence, __pyx_t_1) < 0) __PYX_ERR(1, 14, __pyx_L1_error)
2826 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2827
2828 /* "cchardet/_cchardet.pyx":1
2829 * cdef extern from *: # <<<<<<<<<<<<<<
2830 * ctypedef char* const_char_ptr "const char*"
2831 *
2832 */
2833 __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error)
2834 __Pyx_GOTREF(__pyx_t_1);
2835 if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
2836 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2837
2838 /*--- Wrapped vars code ---*/
2839
2840 goto __pyx_L0;
2841 __pyx_L1_error:;
2842 __Pyx_XDECREF(__pyx_t_1);
2843 if (__pyx_m) {
2844 if (__pyx_d) {
2845 __Pyx_AddTraceback("init cchardet._cchardet", __pyx_clineno, __pyx_lineno, __pyx_filename);
2846 }
2847 Py_CLEAR(__pyx_m);
2848 } else if (!PyErr_Occurred()) {
2849 PyErr_SetString(PyExc_ImportError, "init cchardet._cchardet");
2850 }
2851 __pyx_L0:;
2852 __Pyx_RefNannyFinishContext();
2853 #if CYTHON_PEP489_MULTI_PHASE_INIT
2854 return (__pyx_m != NULL) ? 0 : -1;
2855 #elif PY_MAJOR_VERSION >= 3
2856 return __pyx_m;
2857 #else
2858 return;
2859 #endif
2860 }
2861
2862 /* --- Runtime support code --- */
2863 /* Refnanny */
2864 #if CYTHON_REFNANNY
__Pyx_RefNannyImportAPI(const char * modname)2865 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
2866 PyObject *m = NULL, *p = NULL;
2867 void *r = NULL;
2868 m = PyImport_ImportModule(modname);
2869 if (!m) goto end;
2870 p = PyObject_GetAttrString(m, "RefNannyAPI");
2871 if (!p) goto end;
2872 r = PyLong_AsVoidPtr(p);
2873 end:
2874 Py_XDECREF(p);
2875 Py_XDECREF(m);
2876 return (__Pyx_RefNannyAPIStruct *)r;
2877 }
2878 #endif
2879
2880 /* PyObjectGetAttrStr */
2881 #if CYTHON_USE_TYPE_SLOTS
__Pyx_PyObject_GetAttrStr(PyObject * obj,PyObject * attr_name)2882 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
2883 PyTypeObject* tp = Py_TYPE(obj);
2884 if (likely(tp->tp_getattro))
2885 return tp->tp_getattro(obj, attr_name);
2886 #if PY_MAJOR_VERSION < 3
2887 if (likely(tp->tp_getattr))
2888 return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
2889 #endif
2890 return PyObject_GetAttr(obj, attr_name);
2891 }
2892 #endif
2893
2894 /* GetBuiltinName */
__Pyx_GetBuiltinName(PyObject * name)2895 static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
2896 PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
2897 if (unlikely(!result)) {
2898 PyErr_Format(PyExc_NameError,
2899 #if PY_MAJOR_VERSION >= 3
2900 "name '%U' is not defined", name);
2901 #else
2902 "name '%.200s' is not defined", PyString_AS_STRING(name));
2903 #endif
2904 }
2905 return result;
2906 }
2907
2908 /* ArgTypeTest */
__Pyx__ArgTypeTest(PyObject * obj,PyTypeObject * type,const char * name,int exact)2909 static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
2910 {
2911 if (unlikely(!type)) {
2912 PyErr_SetString(PyExc_SystemError, "Missing type object");
2913 return 0;
2914 }
2915 else if (exact) {
2916 #if PY_MAJOR_VERSION == 2
2917 if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
2918 #endif
2919 }
2920 else {
2921 if (likely(__Pyx_TypeCheck(obj, type))) return 1;
2922 }
2923 PyErr_Format(PyExc_TypeError,
2924 "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
2925 name, type->tp_name, Py_TYPE(obj)->tp_name);
2926 return 0;
2927 }
2928
2929 /* PyObjectCall */
2930 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx_PyObject_Call(PyObject * func,PyObject * arg,PyObject * kw)2931 static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
2932 PyObject *result;
2933 ternaryfunc call = func->ob_type->tp_call;
2934 if (unlikely(!call))
2935 return PyObject_Call(func, arg, kw);
2936 if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
2937 return NULL;
2938 result = (*call)(func, arg, kw);
2939 Py_LeaveRecursiveCall();
2940 if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
2941 PyErr_SetString(
2942 PyExc_SystemError,
2943 "NULL result without error in PyObject_Call");
2944 }
2945 return result;
2946 }
2947 #endif
2948
2949 /* PyErrFetchRestore */
2950 #if CYTHON_FAST_THREAD_STATE
__Pyx_ErrRestoreInState(PyThreadState * tstate,PyObject * type,PyObject * value,PyObject * tb)2951 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
2952 PyObject *tmp_type, *tmp_value, *tmp_tb;
2953 tmp_type = tstate->curexc_type;
2954 tmp_value = tstate->curexc_value;
2955 tmp_tb = tstate->curexc_traceback;
2956 tstate->curexc_type = type;
2957 tstate->curexc_value = value;
2958 tstate->curexc_traceback = tb;
2959 Py_XDECREF(tmp_type);
2960 Py_XDECREF(tmp_value);
2961 Py_XDECREF(tmp_tb);
2962 }
__Pyx_ErrFetchInState(PyThreadState * tstate,PyObject ** type,PyObject ** value,PyObject ** tb)2963 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
2964 *type = tstate->curexc_type;
2965 *value = tstate->curexc_value;
2966 *tb = tstate->curexc_traceback;
2967 tstate->curexc_type = 0;
2968 tstate->curexc_value = 0;
2969 tstate->curexc_traceback = 0;
2970 }
2971 #endif
2972
2973 /* RaiseException */
2974 #if PY_MAJOR_VERSION < 3
__Pyx_Raise(PyObject * type,PyObject * value,PyObject * tb,CYTHON_UNUSED PyObject * cause)2975 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
2976 CYTHON_UNUSED PyObject *cause) {
2977 __Pyx_PyThreadState_declare
2978 Py_XINCREF(type);
2979 if (!value || value == Py_None)
2980 value = NULL;
2981 else
2982 Py_INCREF(value);
2983 if (!tb || tb == Py_None)
2984 tb = NULL;
2985 else {
2986 Py_INCREF(tb);
2987 if (!PyTraceBack_Check(tb)) {
2988 PyErr_SetString(PyExc_TypeError,
2989 "raise: arg 3 must be a traceback or None");
2990 goto raise_error;
2991 }
2992 }
2993 if (PyType_Check(type)) {
2994 #if CYTHON_COMPILING_IN_PYPY
2995 if (!value) {
2996 Py_INCREF(Py_None);
2997 value = Py_None;
2998 }
2999 #endif
3000 PyErr_NormalizeException(&type, &value, &tb);
3001 } else {
3002 if (value) {
3003 PyErr_SetString(PyExc_TypeError,
3004 "instance exception may not have a separate value");
3005 goto raise_error;
3006 }
3007 value = type;
3008 type = (PyObject*) Py_TYPE(type);
3009 Py_INCREF(type);
3010 if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
3011 PyErr_SetString(PyExc_TypeError,
3012 "raise: exception class must be a subclass of BaseException");
3013 goto raise_error;
3014 }
3015 }
3016 __Pyx_PyThreadState_assign
3017 __Pyx_ErrRestore(type, value, tb);
3018 return;
3019 raise_error:
3020 Py_XDECREF(value);
3021 Py_XDECREF(type);
3022 Py_XDECREF(tb);
3023 return;
3024 }
3025 #else
__Pyx_Raise(PyObject * type,PyObject * value,PyObject * tb,PyObject * cause)3026 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
3027 PyObject* owned_instance = NULL;
3028 if (tb == Py_None) {
3029 tb = 0;
3030 } else if (tb && !PyTraceBack_Check(tb)) {
3031 PyErr_SetString(PyExc_TypeError,
3032 "raise: arg 3 must be a traceback or None");
3033 goto bad;
3034 }
3035 if (value == Py_None)
3036 value = 0;
3037 if (PyExceptionInstance_Check(type)) {
3038 if (value) {
3039 PyErr_SetString(PyExc_TypeError,
3040 "instance exception may not have a separate value");
3041 goto bad;
3042 }
3043 value = type;
3044 type = (PyObject*) Py_TYPE(value);
3045 } else if (PyExceptionClass_Check(type)) {
3046 PyObject *instance_class = NULL;
3047 if (value && PyExceptionInstance_Check(value)) {
3048 instance_class = (PyObject*) Py_TYPE(value);
3049 if (instance_class != type) {
3050 int is_subclass = PyObject_IsSubclass(instance_class, type);
3051 if (!is_subclass) {
3052 instance_class = NULL;
3053 } else if (unlikely(is_subclass == -1)) {
3054 goto bad;
3055 } else {
3056 type = instance_class;
3057 }
3058 }
3059 }
3060 if (!instance_class) {
3061 PyObject *args;
3062 if (!value)
3063 args = PyTuple_New(0);
3064 else if (PyTuple_Check(value)) {
3065 Py_INCREF(value);
3066 args = value;
3067 } else
3068 args = PyTuple_Pack(1, value);
3069 if (!args)
3070 goto bad;
3071 owned_instance = PyObject_Call(type, args, NULL);
3072 Py_DECREF(args);
3073 if (!owned_instance)
3074 goto bad;
3075 value = owned_instance;
3076 if (!PyExceptionInstance_Check(value)) {
3077 PyErr_Format(PyExc_TypeError,
3078 "calling %R should have returned an instance of "
3079 "BaseException, not %R",
3080 type, Py_TYPE(value));
3081 goto bad;
3082 }
3083 }
3084 } else {
3085 PyErr_SetString(PyExc_TypeError,
3086 "raise: exception class must be a subclass of BaseException");
3087 goto bad;
3088 }
3089 if (cause) {
3090 PyObject *fixed_cause;
3091 if (cause == Py_None) {
3092 fixed_cause = NULL;
3093 } else if (PyExceptionClass_Check(cause)) {
3094 fixed_cause = PyObject_CallObject(cause, NULL);
3095 if (fixed_cause == NULL)
3096 goto bad;
3097 } else if (PyExceptionInstance_Check(cause)) {
3098 fixed_cause = cause;
3099 Py_INCREF(fixed_cause);
3100 } else {
3101 PyErr_SetString(PyExc_TypeError,
3102 "exception causes must derive from "
3103 "BaseException");
3104 goto bad;
3105 }
3106 PyException_SetCause(value, fixed_cause);
3107 }
3108 PyErr_SetObject(type, value);
3109 if (tb) {
3110 #if CYTHON_COMPILING_IN_PYPY
3111 PyObject *tmp_type, *tmp_value, *tmp_tb;
3112 PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
3113 Py_INCREF(tb);
3114 PyErr_Restore(tmp_type, tmp_value, tb);
3115 Py_XDECREF(tmp_tb);
3116 #else
3117 PyThreadState *tstate = __Pyx_PyThreadState_Current;
3118 PyObject* tmp_tb = tstate->curexc_traceback;
3119 if (tb != tmp_tb) {
3120 Py_INCREF(tb);
3121 tstate->curexc_traceback = tb;
3122 Py_XDECREF(tmp_tb);
3123 }
3124 #endif
3125 }
3126 bad:
3127 Py_XDECREF(owned_instance);
3128 return;
3129 }
3130 #endif
3131
3132 /* RaiseArgTupleInvalid */
__Pyx_RaiseArgtupleInvalid(const char * func_name,int exact,Py_ssize_t num_min,Py_ssize_t num_max,Py_ssize_t num_found)3133 static void __Pyx_RaiseArgtupleInvalid(
3134 const char* func_name,
3135 int exact,
3136 Py_ssize_t num_min,
3137 Py_ssize_t num_max,
3138 Py_ssize_t num_found)
3139 {
3140 Py_ssize_t num_expected;
3141 const char *more_or_less;
3142 if (num_found < num_min) {
3143 num_expected = num_min;
3144 more_or_less = "at least";
3145 } else {
3146 num_expected = num_max;
3147 more_or_less = "at most";
3148 }
3149 if (exact) {
3150 more_or_less = "exactly";
3151 }
3152 PyErr_Format(PyExc_TypeError,
3153 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
3154 func_name, more_or_less, num_expected,
3155 (num_expected == 1) ? "" : "s", num_found);
3156 }
3157
3158 /* KeywordStringCheck */
__Pyx_CheckKeywordStrings(PyObject * kwdict,const char * function_name,int kw_allowed)3159 static int __Pyx_CheckKeywordStrings(
3160 PyObject *kwdict,
3161 const char* function_name,
3162 int kw_allowed)
3163 {
3164 PyObject* key = 0;
3165 Py_ssize_t pos = 0;
3166 #if CYTHON_COMPILING_IN_PYPY
3167 if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
3168 goto invalid_keyword;
3169 return 1;
3170 #else
3171 while (PyDict_Next(kwdict, &pos, &key, 0)) {
3172 #if PY_MAJOR_VERSION < 3
3173 if (unlikely(!PyString_Check(key)))
3174 #endif
3175 if (unlikely(!PyUnicode_Check(key)))
3176 goto invalid_keyword_type;
3177 }
3178 if ((!kw_allowed) && unlikely(key))
3179 goto invalid_keyword;
3180 return 1;
3181 invalid_keyword_type:
3182 PyErr_Format(PyExc_TypeError,
3183 "%.200s() keywords must be strings", function_name);
3184 return 0;
3185 #endif
3186 invalid_keyword:
3187 PyErr_Format(PyExc_TypeError,
3188 #if PY_MAJOR_VERSION < 3
3189 "%.200s() got an unexpected keyword argument '%.200s'",
3190 function_name, PyString_AsString(key));
3191 #else
3192 "%s() got an unexpected keyword argument '%U'",
3193 function_name, key);
3194 #endif
3195 return 0;
3196 }
3197
3198 /* PyObject_GenericGetAttrNoDict */
3199 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
__Pyx_RaiseGenericGetAttributeError(PyTypeObject * tp,PyObject * attr_name)3200 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
3201 PyErr_Format(PyExc_AttributeError,
3202 #if PY_MAJOR_VERSION >= 3
3203 "'%.50s' object has no attribute '%U'",
3204 tp->tp_name, attr_name);
3205 #else
3206 "'%.50s' object has no attribute '%.400s'",
3207 tp->tp_name, PyString_AS_STRING(attr_name));
3208 #endif
3209 return NULL;
3210 }
__Pyx_PyObject_GenericGetAttrNoDict(PyObject * obj,PyObject * attr_name)3211 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
3212 PyObject *descr;
3213 PyTypeObject *tp = Py_TYPE(obj);
3214 if (unlikely(!PyString_Check(attr_name))) {
3215 return PyObject_GenericGetAttr(obj, attr_name);
3216 }
3217 assert(!tp->tp_dictoffset);
3218 descr = _PyType_Lookup(tp, attr_name);
3219 if (unlikely(!descr)) {
3220 return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
3221 }
3222 Py_INCREF(descr);
3223 #if PY_MAJOR_VERSION < 3
3224 if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
3225 #endif
3226 {
3227 descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
3228 if (unlikely(f)) {
3229 PyObject *res = f(descr, obj, (PyObject *)tp);
3230 Py_DECREF(descr);
3231 return res;
3232 }
3233 }
3234 return descr;
3235 }
3236 #endif
3237
3238 /* PyObject_GenericGetAttr */
3239 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
__Pyx_PyObject_GenericGetAttr(PyObject * obj,PyObject * attr_name)3240 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
3241 if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
3242 return PyObject_GenericGetAttr(obj, attr_name);
3243 }
3244 return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
3245 }
3246 #endif
3247
3248 /* PyErrExceptionMatches */
3249 #if CYTHON_FAST_THREAD_STATE
__Pyx_PyErr_ExceptionMatchesTuple(PyObject * exc_type,PyObject * tuple)3250 static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
3251 Py_ssize_t i, n;
3252 n = PyTuple_GET_SIZE(tuple);
3253 #if PY_MAJOR_VERSION >= 3
3254 for (i=0; i<n; i++) {
3255 if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
3256 }
3257 #endif
3258 for (i=0; i<n; i++) {
3259 if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
3260 }
3261 return 0;
3262 }
__Pyx_PyErr_ExceptionMatchesInState(PyThreadState * tstate,PyObject * err)3263 static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
3264 PyObject *exc_type = tstate->curexc_type;
3265 if (exc_type == err) return 1;
3266 if (unlikely(!exc_type)) return 0;
3267 if (unlikely(PyTuple_Check(err)))
3268 return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
3269 return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
3270 }
3271 #endif
3272
3273 /* PyObjectGetAttrStrNoError */
__Pyx_PyObject_GetAttrStr_ClearAttributeError(void)3274 static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
3275 __Pyx_PyThreadState_declare
3276 __Pyx_PyThreadState_assign
3277 if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
3278 __Pyx_PyErr_Clear();
3279 }
__Pyx_PyObject_GetAttrStrNoError(PyObject * obj,PyObject * attr_name)3280 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
3281 PyObject *result;
3282 #if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
3283 PyTypeObject* tp = Py_TYPE(obj);
3284 if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
3285 return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
3286 }
3287 #endif
3288 result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
3289 if (unlikely(!result)) {
3290 __Pyx_PyObject_GetAttrStr_ClearAttributeError();
3291 }
3292 return result;
3293 }
3294
3295 /* SetupReduce */
__Pyx_setup_reduce_is_named(PyObject * meth,PyObject * name)3296 static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
3297 int ret;
3298 PyObject *name_attr;
3299 name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name);
3300 if (likely(name_attr)) {
3301 ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
3302 } else {
3303 ret = -1;
3304 }
3305 if (unlikely(ret < 0)) {
3306 PyErr_Clear();
3307 ret = 0;
3308 }
3309 Py_XDECREF(name_attr);
3310 return ret;
3311 }
__Pyx_setup_reduce(PyObject * type_obj)3312 static int __Pyx_setup_reduce(PyObject* type_obj) {
3313 int ret = 0;
3314 PyObject *object_reduce = NULL;
3315 PyObject *object_reduce_ex = NULL;
3316 PyObject *reduce = NULL;
3317 PyObject *reduce_ex = NULL;
3318 PyObject *reduce_cython = NULL;
3319 PyObject *setstate = NULL;
3320 PyObject *setstate_cython = NULL;
3321 #if CYTHON_USE_PYTYPE_LOOKUP
3322 if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD;
3323 #else
3324 if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD;
3325 #endif
3326 #if CYTHON_USE_PYTYPE_LOOKUP
3327 object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
3328 #else
3329 object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
3330 #endif
3331 reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD;
3332 if (reduce_ex == object_reduce_ex) {
3333 #if CYTHON_USE_PYTYPE_LOOKUP
3334 object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
3335 #else
3336 object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
3337 #endif
3338 reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD;
3339 if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
3340 reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython);
3341 if (likely(reduce_cython)) {
3342 ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
3343 ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
3344 } else if (reduce == object_reduce || PyErr_Occurred()) {
3345 goto __PYX_BAD;
3346 }
3347 setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
3348 if (!setstate) PyErr_Clear();
3349 if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
3350 setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython);
3351 if (likely(setstate_cython)) {
3352 ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
3353 ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
3354 } else if (!setstate || PyErr_Occurred()) {
3355 goto __PYX_BAD;
3356 }
3357 }
3358 PyType_Modified((PyTypeObject*)type_obj);
3359 }
3360 }
3361 goto __PYX_GOOD;
3362 __PYX_BAD:
3363 if (!PyErr_Occurred())
3364 PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
3365 ret = -1;
3366 __PYX_GOOD:
3367 #if !CYTHON_USE_PYTYPE_LOOKUP
3368 Py_XDECREF(object_reduce);
3369 Py_XDECREF(object_reduce_ex);
3370 #endif
3371 Py_XDECREF(reduce);
3372 Py_XDECREF(reduce_ex);
3373 Py_XDECREF(reduce_cython);
3374 Py_XDECREF(setstate);
3375 Py_XDECREF(setstate_cython);
3376 return ret;
3377 }
3378
3379 /* PyDictVersioning */
3380 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
__Pyx_get_tp_dict_version(PyObject * obj)3381 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
3382 PyObject *dict = Py_TYPE(obj)->tp_dict;
3383 return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
3384 }
__Pyx_get_object_dict_version(PyObject * obj)3385 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
3386 PyObject **dictptr = NULL;
3387 Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
3388 if (offset) {
3389 #if CYTHON_COMPILING_IN_CPYTHON
3390 dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
3391 #else
3392 dictptr = _PyObject_GetDictPtr(obj);
3393 #endif
3394 }
3395 return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
3396 }
__Pyx_object_dict_version_matches(PyObject * obj,PY_UINT64_T tp_dict_version,PY_UINT64_T obj_dict_version)3397 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
3398 PyObject *dict = Py_TYPE(obj)->tp_dict;
3399 if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
3400 return 0;
3401 return obj_dict_version == __Pyx_get_object_dict_version(obj);
3402 }
3403 #endif
3404
3405 /* CLineInTraceback */
3406 #ifndef CYTHON_CLINE_IN_TRACEBACK
__Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState * tstate,int c_line)3407 static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
3408 PyObject *use_cline;
3409 PyObject *ptype, *pvalue, *ptraceback;
3410 #if CYTHON_COMPILING_IN_CPYTHON
3411 PyObject **cython_runtime_dict;
3412 #endif
3413 if (unlikely(!__pyx_cython_runtime)) {
3414 return c_line;
3415 }
3416 __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
3417 #if CYTHON_COMPILING_IN_CPYTHON
3418 cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
3419 if (likely(cython_runtime_dict)) {
3420 __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
3421 use_cline, *cython_runtime_dict,
3422 __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
3423 } else
3424 #endif
3425 {
3426 PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
3427 if (use_cline_obj) {
3428 use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
3429 Py_DECREF(use_cline_obj);
3430 } else {
3431 PyErr_Clear();
3432 use_cline = NULL;
3433 }
3434 }
3435 if (!use_cline) {
3436 c_line = 0;
3437 PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
3438 }
3439 else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
3440 c_line = 0;
3441 }
3442 __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
3443 return c_line;
3444 }
3445 #endif
3446
3447 /* CodeObjectCache */
__pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry * entries,int count,int code_line)3448 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
3449 int start = 0, mid = 0, end = count - 1;
3450 if (end >= 0 && code_line > entries[end].code_line) {
3451 return count;
3452 }
3453 while (start < end) {
3454 mid = start + (end - start) / 2;
3455 if (code_line < entries[mid].code_line) {
3456 end = mid;
3457 } else if (code_line > entries[mid].code_line) {
3458 start = mid + 1;
3459 } else {
3460 return mid;
3461 }
3462 }
3463 if (code_line <= entries[mid].code_line) {
3464 return mid;
3465 } else {
3466 return mid + 1;
3467 }
3468 }
__pyx_find_code_object(int code_line)3469 static PyCodeObject *__pyx_find_code_object(int code_line) {
3470 PyCodeObject* code_object;
3471 int pos;
3472 if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
3473 return NULL;
3474 }
3475 pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
3476 if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
3477 return NULL;
3478 }
3479 code_object = __pyx_code_cache.entries[pos].code_object;
3480 Py_INCREF(code_object);
3481 return code_object;
3482 }
__pyx_insert_code_object(int code_line,PyCodeObject * code_object)3483 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
3484 int pos, i;
3485 __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
3486 if (unlikely(!code_line)) {
3487 return;
3488 }
3489 if (unlikely(!entries)) {
3490 entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
3491 if (likely(entries)) {
3492 __pyx_code_cache.entries = entries;
3493 __pyx_code_cache.max_count = 64;
3494 __pyx_code_cache.count = 1;
3495 entries[0].code_line = code_line;
3496 entries[0].code_object = code_object;
3497 Py_INCREF(code_object);
3498 }
3499 return;
3500 }
3501 pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
3502 if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
3503 PyCodeObject* tmp = entries[pos].code_object;
3504 entries[pos].code_object = code_object;
3505 Py_DECREF(tmp);
3506 return;
3507 }
3508 if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
3509 int new_max = __pyx_code_cache.max_count + 64;
3510 entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
3511 __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
3512 if (unlikely(!entries)) {
3513 return;
3514 }
3515 __pyx_code_cache.entries = entries;
3516 __pyx_code_cache.max_count = new_max;
3517 }
3518 for (i=__pyx_code_cache.count; i>pos; i--) {
3519 entries[i] = entries[i-1];
3520 }
3521 entries[pos].code_line = code_line;
3522 entries[pos].code_object = code_object;
3523 __pyx_code_cache.count++;
3524 Py_INCREF(code_object);
3525 }
3526
3527 /* AddTraceback */
3528 #include "compile.h"
3529 #include "frameobject.h"
3530 #include "traceback.h"
__Pyx_CreateCodeObjectForTraceback(const char * funcname,int c_line,int py_line,const char * filename)3531 static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
3532 const char *funcname, int c_line,
3533 int py_line, const char *filename) {
3534 PyCodeObject *py_code = 0;
3535 PyObject *py_srcfile = 0;
3536 PyObject *py_funcname = 0;
3537 #if PY_MAJOR_VERSION < 3
3538 py_srcfile = PyString_FromString(filename);
3539 #else
3540 py_srcfile = PyUnicode_FromString(filename);
3541 #endif
3542 if (!py_srcfile) goto bad;
3543 if (c_line) {
3544 #if PY_MAJOR_VERSION < 3
3545 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
3546 #else
3547 py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
3548 #endif
3549 }
3550 else {
3551 #if PY_MAJOR_VERSION < 3
3552 py_funcname = PyString_FromString(funcname);
3553 #else
3554 py_funcname = PyUnicode_FromString(funcname);
3555 #endif
3556 }
3557 if (!py_funcname) goto bad;
3558 py_code = __Pyx_PyCode_New(
3559 0,
3560 0,
3561 0,
3562 0,
3563 0,
3564 __pyx_empty_bytes, /*PyObject *code,*/
3565 __pyx_empty_tuple, /*PyObject *consts,*/
3566 __pyx_empty_tuple, /*PyObject *names,*/
3567 __pyx_empty_tuple, /*PyObject *varnames,*/
3568 __pyx_empty_tuple, /*PyObject *freevars,*/
3569 __pyx_empty_tuple, /*PyObject *cellvars,*/
3570 py_srcfile, /*PyObject *filename,*/
3571 py_funcname, /*PyObject *name,*/
3572 py_line,
3573 __pyx_empty_bytes /*PyObject *lnotab*/
3574 );
3575 Py_DECREF(py_srcfile);
3576 Py_DECREF(py_funcname);
3577 return py_code;
3578 bad:
3579 Py_XDECREF(py_srcfile);
3580 Py_XDECREF(py_funcname);
3581 return NULL;
3582 }
__Pyx_AddTraceback(const char * funcname,int c_line,int py_line,const char * filename)3583 static void __Pyx_AddTraceback(const char *funcname, int c_line,
3584 int py_line, const char *filename) {
3585 PyCodeObject *py_code = 0;
3586 PyFrameObject *py_frame = 0;
3587 PyThreadState *tstate = __Pyx_PyThreadState_Current;
3588 if (c_line) {
3589 c_line = __Pyx_CLineForTraceback(tstate, c_line);
3590 }
3591 py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
3592 if (!py_code) {
3593 py_code = __Pyx_CreateCodeObjectForTraceback(
3594 funcname, c_line, py_line, filename);
3595 if (!py_code) goto bad;
3596 __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
3597 }
3598 py_frame = PyFrame_New(
3599 tstate, /*PyThreadState *tstate,*/
3600 py_code, /*PyCodeObject *code,*/
3601 __pyx_d, /*PyObject *globals,*/
3602 0 /*PyObject *locals*/
3603 );
3604 if (!py_frame) goto bad;
3605 __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
3606 PyTraceBack_Here(py_frame);
3607 bad:
3608 Py_XDECREF(py_code);
3609 Py_XDECREF(py_frame);
3610 }
3611
3612 /* CIntToPy */
__Pyx_PyInt_From_int(int value)3613 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
3614 const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
3615 const int is_unsigned = neg_one > const_zero;
3616 if (is_unsigned) {
3617 if (sizeof(int) < sizeof(long)) {
3618 return PyInt_FromLong((long) value);
3619 } else if (sizeof(int) <= sizeof(unsigned long)) {
3620 return PyLong_FromUnsignedLong((unsigned long) value);
3621 #ifdef HAVE_LONG_LONG
3622 } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
3623 return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
3624 #endif
3625 }
3626 } else {
3627 if (sizeof(int) <= sizeof(long)) {
3628 return PyInt_FromLong((long) value);
3629 #ifdef HAVE_LONG_LONG
3630 } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
3631 return PyLong_FromLongLong((PY_LONG_LONG) value);
3632 #endif
3633 }
3634 }
3635 {
3636 int one = 1; int little = (int)*(unsigned char *)&one;
3637 unsigned char *bytes = (unsigned char *)&value;
3638 return _PyLong_FromByteArray(bytes, sizeof(int),
3639 little, !is_unsigned);
3640 }
3641 }
3642
3643 /* CIntToPy */
__Pyx_PyInt_From_long(long value)3644 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
3645 const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
3646 const int is_unsigned = neg_one > const_zero;
3647 if (is_unsigned) {
3648 if (sizeof(long) < sizeof(long)) {
3649 return PyInt_FromLong((long) value);
3650 } else if (sizeof(long) <= sizeof(unsigned long)) {
3651 return PyLong_FromUnsignedLong((unsigned long) value);
3652 #ifdef HAVE_LONG_LONG
3653 } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
3654 return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
3655 #endif
3656 }
3657 } else {
3658 if (sizeof(long) <= sizeof(long)) {
3659 return PyInt_FromLong((long) value);
3660 #ifdef HAVE_LONG_LONG
3661 } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
3662 return PyLong_FromLongLong((PY_LONG_LONG) value);
3663 #endif
3664 }
3665 }
3666 {
3667 int one = 1; int little = (int)*(unsigned char *)&one;
3668 unsigned char *bytes = (unsigned char *)&value;
3669 return _PyLong_FromByteArray(bytes, sizeof(long),
3670 little, !is_unsigned);
3671 }
3672 }
3673
3674 /* CIntFromPyVerify */
3675 #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
3676 __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
3677 #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
3678 __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
3679 #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
3680 {\
3681 func_type value = func_value;\
3682 if (sizeof(target_type) < sizeof(func_type)) {\
3683 if (unlikely(value != (func_type) (target_type) value)) {\
3684 func_type zero = 0;\
3685 if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
3686 return (target_type) -1;\
3687 if (is_unsigned && unlikely(value < zero))\
3688 goto raise_neg_overflow;\
3689 else\
3690 goto raise_overflow;\
3691 }\
3692 }\
3693 return (target_type) value;\
3694 }
3695
3696 /* CIntFromPy */
__Pyx_PyInt_As_long(PyObject * x)3697 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
3698 const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
3699 const int is_unsigned = neg_one > const_zero;
3700 #if PY_MAJOR_VERSION < 3
3701 if (likely(PyInt_Check(x))) {
3702 if (sizeof(long) < sizeof(long)) {
3703 __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
3704 } else {
3705 long val = PyInt_AS_LONG(x);
3706 if (is_unsigned && unlikely(val < 0)) {
3707 goto raise_neg_overflow;
3708 }
3709 return (long) val;
3710 }
3711 } else
3712 #endif
3713 if (likely(PyLong_Check(x))) {
3714 if (is_unsigned) {
3715 #if CYTHON_USE_PYLONG_INTERNALS
3716 const digit* digits = ((PyLongObject*)x)->ob_digit;
3717 switch (Py_SIZE(x)) {
3718 case 0: return (long) 0;
3719 case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
3720 case 2:
3721 if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
3722 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3723 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3724 } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
3725 return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
3726 }
3727 }
3728 break;
3729 case 3:
3730 if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
3731 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3732 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3733 } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
3734 return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
3735 }
3736 }
3737 break;
3738 case 4:
3739 if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
3740 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3741 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3742 } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
3743 return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
3744 }
3745 }
3746 break;
3747 }
3748 #endif
3749 #if CYTHON_COMPILING_IN_CPYTHON
3750 if (unlikely(Py_SIZE(x) < 0)) {
3751 goto raise_neg_overflow;
3752 }
3753 #else
3754 {
3755 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
3756 if (unlikely(result < 0))
3757 return (long) -1;
3758 if (unlikely(result == 1))
3759 goto raise_neg_overflow;
3760 }
3761 #endif
3762 if (sizeof(long) <= sizeof(unsigned long)) {
3763 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
3764 #ifdef HAVE_LONG_LONG
3765 } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
3766 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
3767 #endif
3768 }
3769 } else {
3770 #if CYTHON_USE_PYLONG_INTERNALS
3771 const digit* digits = ((PyLongObject*)x)->ob_digit;
3772 switch (Py_SIZE(x)) {
3773 case 0: return (long) 0;
3774 case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
3775 case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
3776 case -2:
3777 if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
3778 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3779 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3780 } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3781 return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3782 }
3783 }
3784 break;
3785 case 2:
3786 if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
3787 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3788 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3789 } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3790 return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3791 }
3792 }
3793 break;
3794 case -3:
3795 if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3796 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3797 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3798 } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3799 return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3800 }
3801 }
3802 break;
3803 case 3:
3804 if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
3805 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3806 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3807 } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3808 return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3809 }
3810 }
3811 break;
3812 case -4:
3813 if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3814 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3815 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3816 } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
3817 return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3818 }
3819 }
3820 break;
3821 case 4:
3822 if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
3823 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3824 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3825 } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
3826 return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3827 }
3828 }
3829 break;
3830 }
3831 #endif
3832 if (sizeof(long) <= sizeof(long)) {
3833 __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
3834 #ifdef HAVE_LONG_LONG
3835 } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
3836 __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
3837 #endif
3838 }
3839 }
3840 {
3841 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
3842 PyErr_SetString(PyExc_RuntimeError,
3843 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
3844 #else
3845 long val;
3846 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
3847 #if PY_MAJOR_VERSION < 3
3848 if (likely(v) && !PyLong_Check(v)) {
3849 PyObject *tmp = v;
3850 v = PyNumber_Long(tmp);
3851 Py_DECREF(tmp);
3852 }
3853 #endif
3854 if (likely(v)) {
3855 int one = 1; int is_little = (int)*(unsigned char *)&one;
3856 unsigned char *bytes = (unsigned char *)&val;
3857 int ret = _PyLong_AsByteArray((PyLongObject *)v,
3858 bytes, sizeof(val),
3859 is_little, !is_unsigned);
3860 Py_DECREF(v);
3861 if (likely(!ret))
3862 return val;
3863 }
3864 #endif
3865 return (long) -1;
3866 }
3867 } else {
3868 long val;
3869 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
3870 if (!tmp) return (long) -1;
3871 val = __Pyx_PyInt_As_long(tmp);
3872 Py_DECREF(tmp);
3873 return val;
3874 }
3875 raise_overflow:
3876 PyErr_SetString(PyExc_OverflowError,
3877 "value too large to convert to long");
3878 return (long) -1;
3879 raise_neg_overflow:
3880 PyErr_SetString(PyExc_OverflowError,
3881 "can't convert negative value to long");
3882 return (long) -1;
3883 }
3884
3885 /* CIntFromPy */
__Pyx_PyInt_As_int(PyObject * x)3886 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
3887 const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
3888 const int is_unsigned = neg_one > const_zero;
3889 #if PY_MAJOR_VERSION < 3
3890 if (likely(PyInt_Check(x))) {
3891 if (sizeof(int) < sizeof(long)) {
3892 __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
3893 } else {
3894 long val = PyInt_AS_LONG(x);
3895 if (is_unsigned && unlikely(val < 0)) {
3896 goto raise_neg_overflow;
3897 }
3898 return (int) val;
3899 }
3900 } else
3901 #endif
3902 if (likely(PyLong_Check(x))) {
3903 if (is_unsigned) {
3904 #if CYTHON_USE_PYLONG_INTERNALS
3905 const digit* digits = ((PyLongObject*)x)->ob_digit;
3906 switch (Py_SIZE(x)) {
3907 case 0: return (int) 0;
3908 case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
3909 case 2:
3910 if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
3911 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3912 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3913 } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
3914 return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
3915 }
3916 }
3917 break;
3918 case 3:
3919 if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
3920 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3921 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3922 } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
3923 return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
3924 }
3925 }
3926 break;
3927 case 4:
3928 if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
3929 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3930 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3931 } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
3932 return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
3933 }
3934 }
3935 break;
3936 }
3937 #endif
3938 #if CYTHON_COMPILING_IN_CPYTHON
3939 if (unlikely(Py_SIZE(x) < 0)) {
3940 goto raise_neg_overflow;
3941 }
3942 #else
3943 {
3944 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
3945 if (unlikely(result < 0))
3946 return (int) -1;
3947 if (unlikely(result == 1))
3948 goto raise_neg_overflow;
3949 }
3950 #endif
3951 if (sizeof(int) <= sizeof(unsigned long)) {
3952 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
3953 #ifdef HAVE_LONG_LONG
3954 } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
3955 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
3956 #endif
3957 }
3958 } else {
3959 #if CYTHON_USE_PYLONG_INTERNALS
3960 const digit* digits = ((PyLongObject*)x)->ob_digit;
3961 switch (Py_SIZE(x)) {
3962 case 0: return (int) 0;
3963 case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
3964 case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
3965 case -2:
3966 if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
3967 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3968 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3969 } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
3970 return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3971 }
3972 }
3973 break;
3974 case 2:
3975 if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
3976 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3977 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3978 } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
3979 return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3980 }
3981 }
3982 break;
3983 case -3:
3984 if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
3985 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3986 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3987 } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
3988 return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3989 }
3990 }
3991 break;
3992 case 3:
3993 if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
3994 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3995 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3996 } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
3997 return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3998 }
3999 }
4000 break;
4001 case -4:
4002 if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
4003 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4004 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4005 } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
4006 return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4007 }
4008 }
4009 break;
4010 case 4:
4011 if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
4012 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4013 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4014 } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
4015 return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4016 }
4017 }
4018 break;
4019 }
4020 #endif
4021 if (sizeof(int) <= sizeof(long)) {
4022 __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
4023 #ifdef HAVE_LONG_LONG
4024 } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
4025 __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
4026 #endif
4027 }
4028 }
4029 {
4030 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
4031 PyErr_SetString(PyExc_RuntimeError,
4032 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
4033 #else
4034 int val;
4035 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
4036 #if PY_MAJOR_VERSION < 3
4037 if (likely(v) && !PyLong_Check(v)) {
4038 PyObject *tmp = v;
4039 v = PyNumber_Long(tmp);
4040 Py_DECREF(tmp);
4041 }
4042 #endif
4043 if (likely(v)) {
4044 int one = 1; int is_little = (int)*(unsigned char *)&one;
4045 unsigned char *bytes = (unsigned char *)&val;
4046 int ret = _PyLong_AsByteArray((PyLongObject *)v,
4047 bytes, sizeof(val),
4048 is_little, !is_unsigned);
4049 Py_DECREF(v);
4050 if (likely(!ret))
4051 return val;
4052 }
4053 #endif
4054 return (int) -1;
4055 }
4056 } else {
4057 int val;
4058 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
4059 if (!tmp) return (int) -1;
4060 val = __Pyx_PyInt_As_int(tmp);
4061 Py_DECREF(tmp);
4062 return val;
4063 }
4064 raise_overflow:
4065 PyErr_SetString(PyExc_OverflowError,
4066 "value too large to convert to int");
4067 return (int) -1;
4068 raise_neg_overflow:
4069 PyErr_SetString(PyExc_OverflowError,
4070 "can't convert negative value to int");
4071 return (int) -1;
4072 }
4073
4074 /* FastTypeChecks */
4075 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx_InBases(PyTypeObject * a,PyTypeObject * b)4076 static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
4077 while (a) {
4078 a = a->tp_base;
4079 if (a == b)
4080 return 1;
4081 }
4082 return b == &PyBaseObject_Type;
4083 }
__Pyx_IsSubtype(PyTypeObject * a,PyTypeObject * b)4084 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
4085 PyObject *mro;
4086 if (a == b) return 1;
4087 mro = a->tp_mro;
4088 if (likely(mro)) {
4089 Py_ssize_t i, n;
4090 n = PyTuple_GET_SIZE(mro);
4091 for (i = 0; i < n; i++) {
4092 if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
4093 return 1;
4094 }
4095 return 0;
4096 }
4097 return __Pyx_InBases(a, b);
4098 }
4099 #if PY_MAJOR_VERSION == 2
__Pyx_inner_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)4100 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
4101 PyObject *exception, *value, *tb;
4102 int res;
4103 __Pyx_PyThreadState_declare
4104 __Pyx_PyThreadState_assign
4105 __Pyx_ErrFetch(&exception, &value, &tb);
4106 res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
4107 if (unlikely(res == -1)) {
4108 PyErr_WriteUnraisable(err);
4109 res = 0;
4110 }
4111 if (!res) {
4112 res = PyObject_IsSubclass(err, exc_type2);
4113 if (unlikely(res == -1)) {
4114 PyErr_WriteUnraisable(err);
4115 res = 0;
4116 }
4117 }
4118 __Pyx_ErrRestore(exception, value, tb);
4119 return res;
4120 }
4121 #else
__Pyx_inner_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)4122 static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
4123 int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
4124 if (!res) {
4125 res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
4126 }
4127 return res;
4128 }
4129 #endif
__Pyx_PyErr_GivenExceptionMatchesTuple(PyObject * exc_type,PyObject * tuple)4130 static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
4131 Py_ssize_t i, n;
4132 assert(PyExceptionClass_Check(exc_type));
4133 n = PyTuple_GET_SIZE(tuple);
4134 #if PY_MAJOR_VERSION >= 3
4135 for (i=0; i<n; i++) {
4136 if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
4137 }
4138 #endif
4139 for (i=0; i<n; i++) {
4140 PyObject *t = PyTuple_GET_ITEM(tuple, i);
4141 #if PY_MAJOR_VERSION < 3
4142 if (likely(exc_type == t)) return 1;
4143 #endif
4144 if (likely(PyExceptionClass_Check(t))) {
4145 if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
4146 } else {
4147 }
4148 }
4149 return 0;
4150 }
__Pyx_PyErr_GivenExceptionMatches(PyObject * err,PyObject * exc_type)4151 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
4152 if (likely(err == exc_type)) return 1;
4153 if (likely(PyExceptionClass_Check(err))) {
4154 if (likely(PyExceptionClass_Check(exc_type))) {
4155 return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
4156 } else if (likely(PyTuple_Check(exc_type))) {
4157 return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
4158 } else {
4159 }
4160 }
4161 return PyErr_GivenExceptionMatches(err, exc_type);
4162 }
__Pyx_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)4163 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
4164 assert(PyExceptionClass_Check(exc_type1));
4165 assert(PyExceptionClass_Check(exc_type2));
4166 if (likely(err == exc_type1 || err == exc_type2)) return 1;
4167 if (likely(PyExceptionClass_Check(err))) {
4168 return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
4169 }
4170 return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
4171 }
4172 #endif
4173
4174 /* CheckBinaryVersion */
__Pyx_check_binary_version(void)4175 static int __Pyx_check_binary_version(void) {
4176 char ctversion[4], rtversion[4];
4177 PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
4178 PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
4179 if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
4180 char message[200];
4181 PyOS_snprintf(message, sizeof(message),
4182 "compiletime version %s of module '%.100s' "
4183 "does not match runtime version %s",
4184 ctversion, __Pyx_MODULE_NAME, rtversion);
4185 return PyErr_WarnEx(NULL, message, 1);
4186 }
4187 return 0;
4188 }
4189
4190 /* InitStrings */
__Pyx_InitStrings(__Pyx_StringTabEntry * t)4191 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
4192 while (t->p) {
4193 #if PY_MAJOR_VERSION < 3
4194 if (t->is_unicode) {
4195 *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
4196 } else if (t->intern) {
4197 *t->p = PyString_InternFromString(t->s);
4198 } else {
4199 *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
4200 }
4201 #else
4202 if (t->is_unicode | t->is_str) {
4203 if (t->intern) {
4204 *t->p = PyUnicode_InternFromString(t->s);
4205 } else if (t->encoding) {
4206 *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
4207 } else {
4208 *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
4209 }
4210 } else {
4211 *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
4212 }
4213 #endif
4214 if (!*t->p)
4215 return -1;
4216 if (PyObject_Hash(*t->p) == -1)
4217 return -1;
4218 ++t;
4219 }
4220 return 0;
4221 }
4222
__Pyx_PyUnicode_FromString(const char * c_str)4223 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
4224 return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
4225 }
__Pyx_PyObject_AsString(PyObject * o)4226 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
4227 Py_ssize_t ignore;
4228 return __Pyx_PyObject_AsStringAndSize(o, &ignore);
4229 }
4230 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
4231 #if !CYTHON_PEP393_ENABLED
__Pyx_PyUnicode_AsStringAndSize(PyObject * o,Py_ssize_t * length)4232 static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
4233 char* defenc_c;
4234 PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
4235 if (!defenc) return NULL;
4236 defenc_c = PyBytes_AS_STRING(defenc);
4237 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
4238 {
4239 char* end = defenc_c + PyBytes_GET_SIZE(defenc);
4240 char* c;
4241 for (c = defenc_c; c < end; c++) {
4242 if ((unsigned char) (*c) >= 128) {
4243 PyUnicode_AsASCIIString(o);
4244 return NULL;
4245 }
4246 }
4247 }
4248 #endif
4249 *length = PyBytes_GET_SIZE(defenc);
4250 return defenc_c;
4251 }
4252 #else
__Pyx_PyUnicode_AsStringAndSize(PyObject * o,Py_ssize_t * length)4253 static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
4254 if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
4255 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
4256 if (likely(PyUnicode_IS_ASCII(o))) {
4257 *length = PyUnicode_GET_LENGTH(o);
4258 return PyUnicode_AsUTF8(o);
4259 } else {
4260 PyUnicode_AsASCIIString(o);
4261 return NULL;
4262 }
4263 #else
4264 return PyUnicode_AsUTF8AndSize(o, length);
4265 #endif
4266 }
4267 #endif
4268 #endif
__Pyx_PyObject_AsStringAndSize(PyObject * o,Py_ssize_t * length)4269 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
4270 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
4271 if (
4272 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
4273 __Pyx_sys_getdefaultencoding_not_ascii &&
4274 #endif
4275 PyUnicode_Check(o)) {
4276 return __Pyx_PyUnicode_AsStringAndSize(o, length);
4277 } else
4278 #endif
4279 #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
4280 if (PyByteArray_Check(o)) {
4281 *length = PyByteArray_GET_SIZE(o);
4282 return PyByteArray_AS_STRING(o);
4283 } else
4284 #endif
4285 {
4286 char* result;
4287 int r = PyBytes_AsStringAndSize(o, &result, length);
4288 if (unlikely(r < 0)) {
4289 return NULL;
4290 } else {
4291 return result;
4292 }
4293 }
4294 }
__Pyx_PyObject_IsTrue(PyObject * x)4295 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
4296 int is_true = x == Py_True;
4297 if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
4298 else return PyObject_IsTrue(x);
4299 }
__Pyx_PyObject_IsTrueAndDecref(PyObject * x)4300 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
4301 int retval;
4302 if (unlikely(!x)) return -1;
4303 retval = __Pyx_PyObject_IsTrue(x);
4304 Py_DECREF(x);
4305 return retval;
4306 }
__Pyx_PyNumber_IntOrLongWrongResultType(PyObject * result,const char * type_name)4307 static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
4308 #if PY_MAJOR_VERSION >= 3
4309 if (PyLong_Check(result)) {
4310 if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
4311 "__int__ returned non-int (type %.200s). "
4312 "The ability to return an instance of a strict subclass of int "
4313 "is deprecated, and may be removed in a future version of Python.",
4314 Py_TYPE(result)->tp_name)) {
4315 Py_DECREF(result);
4316 return NULL;
4317 }
4318 return result;
4319 }
4320 #endif
4321 PyErr_Format(PyExc_TypeError,
4322 "__%.4s__ returned non-%.4s (type %.200s)",
4323 type_name, type_name, Py_TYPE(result)->tp_name);
4324 Py_DECREF(result);
4325 return NULL;
4326 }
__Pyx_PyNumber_IntOrLong(PyObject * x)4327 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
4328 #if CYTHON_USE_TYPE_SLOTS
4329 PyNumberMethods *m;
4330 #endif
4331 const char *name = NULL;
4332 PyObject *res = NULL;
4333 #if PY_MAJOR_VERSION < 3
4334 if (likely(PyInt_Check(x) || PyLong_Check(x)))
4335 #else
4336 if (likely(PyLong_Check(x)))
4337 #endif
4338 return __Pyx_NewRef(x);
4339 #if CYTHON_USE_TYPE_SLOTS
4340 m = Py_TYPE(x)->tp_as_number;
4341 #if PY_MAJOR_VERSION < 3
4342 if (m && m->nb_int) {
4343 name = "int";
4344 res = m->nb_int(x);
4345 }
4346 else if (m && m->nb_long) {
4347 name = "long";
4348 res = m->nb_long(x);
4349 }
4350 #else
4351 if (likely(m && m->nb_int)) {
4352 name = "int";
4353 res = m->nb_int(x);
4354 }
4355 #endif
4356 #else
4357 if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
4358 res = PyNumber_Int(x);
4359 }
4360 #endif
4361 if (likely(res)) {
4362 #if PY_MAJOR_VERSION < 3
4363 if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
4364 #else
4365 if (unlikely(!PyLong_CheckExact(res))) {
4366 #endif
4367 return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
4368 }
4369 }
4370 else if (!PyErr_Occurred()) {
4371 PyErr_SetString(PyExc_TypeError,
4372 "an integer is required");
4373 }
4374 return res;
4375 }
4376 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
4377 Py_ssize_t ival;
4378 PyObject *x;
4379 #if PY_MAJOR_VERSION < 3
4380 if (likely(PyInt_CheckExact(b))) {
4381 if (sizeof(Py_ssize_t) >= sizeof(long))
4382 return PyInt_AS_LONG(b);
4383 else
4384 return PyInt_AsSsize_t(b);
4385 }
4386 #endif
4387 if (likely(PyLong_CheckExact(b))) {
4388 #if CYTHON_USE_PYLONG_INTERNALS
4389 const digit* digits = ((PyLongObject*)b)->ob_digit;
4390 const Py_ssize_t size = Py_SIZE(b);
4391 if (likely(__Pyx_sst_abs(size) <= 1)) {
4392 ival = likely(size) ? digits[0] : 0;
4393 if (size == -1) ival = -ival;
4394 return ival;
4395 } else {
4396 switch (size) {
4397 case 2:
4398 if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
4399 return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4400 }
4401 break;
4402 case -2:
4403 if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
4404 return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4405 }
4406 break;
4407 case 3:
4408 if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
4409 return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4410 }
4411 break;
4412 case -3:
4413 if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
4414 return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4415 }
4416 break;
4417 case 4:
4418 if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
4419 return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4420 }
4421 break;
4422 case -4:
4423 if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
4424 return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4425 }
4426 break;
4427 }
4428 }
4429 #endif
4430 return PyLong_AsSsize_t(b);
4431 }
4432 x = PyNumber_Index(b);
4433 if (!x) return -1;
4434 ival = PyInt_AsSsize_t(x);
4435 Py_DECREF(x);
4436 return ival;
4437 }
4438 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
4439 return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
4440 }
4441 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
4442 return PyInt_FromSize_t(ival);
4443 }
4444
4445
4446 #endif /* Py_PYTHON_H */
4447