You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5468 lines
194 KiB

4 years ago
  1. /* Generated by Cython 0.28.5 */
  2. /* BEGIN: Cython Metadata
  3. {
  4. "distutils": {
  5. "depends": [],
  6. "name": "aiohttp._http_writer",
  7. "sources": [
  8. "aiohttp/_http_writer.pyx"
  9. ]
  10. },
  11. "module_name": "aiohttp._http_writer"
  12. }
  13. END: Cython Metadata */
  14. #define PY_SSIZE_T_CLEAN
  15. #include "Python.h"
  16. #ifndef Py_PYTHON_H
  17. #error Python headers needed to compile C extensions, please install development version of Python.
  18. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
  19. #error Cython requires Python 2.6+ or Python 3.3+.
  20. #else
  21. #define CYTHON_ABI "0_28_5"
  22. #define CYTHON_FUTURE_DIVISION 0
  23. #include <stddef.h>
  24. #ifndef offsetof
  25. #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
  26. #endif
  27. #if !defined(WIN32) && !defined(MS_WINDOWS)
  28. #ifndef __stdcall
  29. #define __stdcall
  30. #endif
  31. #ifndef __cdecl
  32. #define __cdecl
  33. #endif
  34. #ifndef __fastcall
  35. #define __fastcall
  36. #endif
  37. #endif
  38. #ifndef DL_IMPORT
  39. #define DL_IMPORT(t) t
  40. #endif
  41. #ifndef DL_EXPORT
  42. #define DL_EXPORT(t) t
  43. #endif
  44. #define __PYX_COMMA ,
  45. #ifndef HAVE_LONG_LONG
  46. #if PY_VERSION_HEX >= 0x02070000
  47. #define HAVE_LONG_LONG
  48. #endif
  49. #endif
  50. #ifndef PY_LONG_LONG
  51. #define PY_LONG_LONG LONG_LONG
  52. #endif
  53. #ifndef Py_HUGE_VAL
  54. #define Py_HUGE_VAL HUGE_VAL
  55. #endif
  56. #ifdef PYPY_VERSION
  57. #define CYTHON_COMPILING_IN_PYPY 1
  58. #define CYTHON_COMPILING_IN_PYSTON 0
  59. #define CYTHON_COMPILING_IN_CPYTHON 0
  60. #undef CYTHON_USE_TYPE_SLOTS
  61. #define CYTHON_USE_TYPE_SLOTS 0
  62. #undef CYTHON_USE_PYTYPE_LOOKUP
  63. #define CYTHON_USE_PYTYPE_LOOKUP 0
  64. #if PY_VERSION_HEX < 0x03050000
  65. #undef CYTHON_USE_ASYNC_SLOTS
  66. #define CYTHON_USE_ASYNC_SLOTS 0
  67. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  68. #define CYTHON_USE_ASYNC_SLOTS 1
  69. #endif
  70. #undef CYTHON_USE_PYLIST_INTERNALS
  71. #define CYTHON_USE_PYLIST_INTERNALS 0
  72. #undef CYTHON_USE_UNICODE_INTERNALS
  73. #define CYTHON_USE_UNICODE_INTERNALS 0
  74. #undef CYTHON_USE_UNICODE_WRITER
  75. #define CYTHON_USE_UNICODE_WRITER 0
  76. #undef CYTHON_USE_PYLONG_INTERNALS
  77. #define CYTHON_USE_PYLONG_INTERNALS 0
  78. #undef CYTHON_AVOID_BORROWED_REFS
  79. #define CYTHON_AVOID_BORROWED_REFS 1
  80. #undef CYTHON_ASSUME_SAFE_MACROS
  81. #define CYTHON_ASSUME_SAFE_MACROS 0
  82. #undef CYTHON_UNPACK_METHODS
  83. #define CYTHON_UNPACK_METHODS 0
  84. #undef CYTHON_FAST_THREAD_STATE
  85. #define CYTHON_FAST_THREAD_STATE 0
  86. #undef CYTHON_FAST_PYCALL
  87. #define CYTHON_FAST_PYCALL 0
  88. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  89. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  90. #undef CYTHON_USE_TP_FINALIZE
  91. #define CYTHON_USE_TP_FINALIZE 0
  92. #elif defined(PYSTON_VERSION)
  93. #define CYTHON_COMPILING_IN_PYPY 0
  94. #define CYTHON_COMPILING_IN_PYSTON 1
  95. #define CYTHON_COMPILING_IN_CPYTHON 0
  96. #ifndef CYTHON_USE_TYPE_SLOTS
  97. #define CYTHON_USE_TYPE_SLOTS 1
  98. #endif
  99. #undef CYTHON_USE_PYTYPE_LOOKUP
  100. #define CYTHON_USE_PYTYPE_LOOKUP 0
  101. #undef CYTHON_USE_ASYNC_SLOTS
  102. #define CYTHON_USE_ASYNC_SLOTS 0
  103. #undef CYTHON_USE_PYLIST_INTERNALS
  104. #define CYTHON_USE_PYLIST_INTERNALS 0
  105. #ifndef CYTHON_USE_UNICODE_INTERNALS
  106. #define CYTHON_USE_UNICODE_INTERNALS 1
  107. #endif
  108. #undef CYTHON_USE_UNICODE_WRITER
  109. #define CYTHON_USE_UNICODE_WRITER 0
  110. #undef CYTHON_USE_PYLONG_INTERNALS
  111. #define CYTHON_USE_PYLONG_INTERNALS 0
  112. #ifndef CYTHON_AVOID_BORROWED_REFS
  113. #define CYTHON_AVOID_BORROWED_REFS 0
  114. #endif
  115. #ifndef CYTHON_ASSUME_SAFE_MACROS
  116. #define CYTHON_ASSUME_SAFE_MACROS 1
  117. #endif
  118. #ifndef CYTHON_UNPACK_METHODS
  119. #define CYTHON_UNPACK_METHODS 1
  120. #endif
  121. #undef CYTHON_FAST_THREAD_STATE
  122. #define CYTHON_FAST_THREAD_STATE 0
  123. #undef CYTHON_FAST_PYCALL
  124. #define CYTHON_FAST_PYCALL 0
  125. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  126. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  127. #undef CYTHON_USE_TP_FINALIZE
  128. #define CYTHON_USE_TP_FINALIZE 0
  129. #else
  130. #define CYTHON_COMPILING_IN_PYPY 0
  131. #define CYTHON_COMPILING_IN_PYSTON 0
  132. #define CYTHON_COMPILING_IN_CPYTHON 1
  133. #ifndef CYTHON_USE_TYPE_SLOTS
  134. #define CYTHON_USE_TYPE_SLOTS 1
  135. #endif
  136. #if PY_VERSION_HEX < 0x02070000
  137. #undef CYTHON_USE_PYTYPE_LOOKUP
  138. #define CYTHON_USE_PYTYPE_LOOKUP 0
  139. #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
  140. #define CYTHON_USE_PYTYPE_LOOKUP 1
  141. #endif
  142. #if PY_MAJOR_VERSION < 3
  143. #undef CYTHON_USE_ASYNC_SLOTS
  144. #define CYTHON_USE_ASYNC_SLOTS 0
  145. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  146. #define CYTHON_USE_ASYNC_SLOTS 1
  147. #endif
  148. #if PY_VERSION_HEX < 0x02070000
  149. #undef CYTHON_USE_PYLONG_INTERNALS
  150. #define CYTHON_USE_PYLONG_INTERNALS 0
  151. #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
  152. #define CYTHON_USE_PYLONG_INTERNALS 1
  153. #endif
  154. #ifndef CYTHON_USE_PYLIST_INTERNALS
  155. #define CYTHON_USE_PYLIST_INTERNALS 1
  156. #endif
  157. #ifndef CYTHON_USE_UNICODE_INTERNALS
  158. #define CYTHON_USE_UNICODE_INTERNALS 1
  159. #endif
  160. #if PY_VERSION_HEX < 0x030300F0
  161. #undef CYTHON_USE_UNICODE_WRITER
  162. #define CYTHON_USE_UNICODE_WRITER 0
  163. #elif !defined(CYTHON_USE_UNICODE_WRITER)
  164. #define CYTHON_USE_UNICODE_WRITER 1
  165. #endif
  166. #ifndef CYTHON_AVOID_BORROWED_REFS
  167. #define CYTHON_AVOID_BORROWED_REFS 0
  168. #endif
  169. #ifndef CYTHON_ASSUME_SAFE_MACROS
  170. #define CYTHON_ASSUME_SAFE_MACROS 1
  171. #endif
  172. #ifndef CYTHON_UNPACK_METHODS
  173. #define CYTHON_UNPACK_METHODS 1
  174. #endif
  175. #ifndef CYTHON_FAST_THREAD_STATE
  176. #define CYTHON_FAST_THREAD_STATE 1
  177. #endif
  178. #ifndef CYTHON_FAST_PYCALL
  179. #define CYTHON_FAST_PYCALL 1
  180. #endif
  181. #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
  182. #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000)
  183. #endif
  184. #ifndef CYTHON_USE_TP_FINALIZE
  185. #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  186. #endif
  187. #endif
  188. #if !defined(CYTHON_FAST_PYCCALL)
  189. #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
  190. #endif
  191. #if CYTHON_USE_PYLONG_INTERNALS
  192. #include "longintrepr.h"
  193. #undef SHIFT
  194. #undef BASE
  195. #undef MASK
  196. #endif
  197. #ifndef __has_attribute
  198. #define __has_attribute(x) 0
  199. #endif
  200. #ifndef __has_cpp_attribute
  201. #define __has_cpp_attribute(x) 0
  202. #endif
  203. #ifndef CYTHON_RESTRICT
  204. #if defined(__GNUC__)
  205. #define CYTHON_RESTRICT __restrict__
  206. #elif defined(_MSC_VER) && _MSC_VER >= 1400
  207. #define CYTHON_RESTRICT __restrict
  208. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  209. #define CYTHON_RESTRICT restrict
  210. #else
  211. #define CYTHON_RESTRICT
  212. #endif
  213. #endif
  214. #ifndef CYTHON_UNUSED
  215. # if defined(__GNUC__)
  216. # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  217. # define CYTHON_UNUSED __attribute__ ((__unused__))
  218. # else
  219. # define CYTHON_UNUSED
  220. # endif
  221. # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
  222. # define CYTHON_UNUSED __attribute__ ((__unused__))
  223. # else
  224. # define CYTHON_UNUSED
  225. # endif
  226. #endif
  227. #ifndef CYTHON_MAYBE_UNUSED_VAR
  228. # if defined(__cplusplus)
  229. template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
  230. # else
  231. # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
  232. # endif
  233. #endif
  234. #ifndef CYTHON_NCP_UNUSED
  235. # if CYTHON_COMPILING_IN_CPYTHON
  236. # define CYTHON_NCP_UNUSED
  237. # else
  238. # define CYTHON_NCP_UNUSED CYTHON_UNUSED
  239. # endif
  240. #endif
  241. #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
  242. #ifdef _MSC_VER
  243. #ifndef _MSC_STDINT_H_
  244. #if _MSC_VER < 1300
  245. typedef unsigned char uint8_t;
  246. typedef unsigned int uint32_t;
  247. #else
  248. typedef unsigned __int8 uint8_t;
  249. typedef unsigned __int32 uint32_t;
  250. #endif
  251. #endif
  252. #else
  253. #include <stdint.h>
  254. #endif
  255. #ifndef CYTHON_FALLTHROUGH
  256. #if defined(__cplusplus) && __cplusplus >= 201103L
  257. #if __has_cpp_attribute(fallthrough)
  258. #define CYTHON_FALLTHROUGH [[fallthrough]]
  259. #elif __has_cpp_attribute(clang::fallthrough)
  260. #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
  261. #elif __has_cpp_attribute(gnu::fallthrough)
  262. #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
  263. #endif
  264. #endif
  265. #ifndef CYTHON_FALLTHROUGH
  266. #if __has_attribute(fallthrough)
  267. #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
  268. #else
  269. #define CYTHON_FALLTHROUGH
  270. #endif
  271. #endif
  272. #if defined(__clang__ ) && defined(__apple_build_version__)
  273. #if __apple_build_version__ < 7000000
  274. #undef CYTHON_FALLTHROUGH
  275. #define CYTHON_FALLTHROUGH
  276. #endif
  277. #endif
  278. #endif
  279. #ifndef CYTHON_INLINE
  280. #if defined(__clang__)
  281. #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  282. #elif defined(__GNUC__)
  283. #define CYTHON_INLINE __inline__
  284. #elif defined(_MSC_VER)
  285. #define CYTHON_INLINE __inline
  286. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  287. #define CYTHON_INLINE inline
  288. #else
  289. #define CYTHON_INLINE
  290. #endif
  291. #endif
  292. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  293. #define Py_OptimizeFlag 0
  294. #endif
  295. #define __PYX_BUILD_PY_SSIZE_T "n"
  296. #define CYTHON_FORMAT_SSIZE_T "z"
  297. #if PY_MAJOR_VERSION < 3
  298. #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  299. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  300. PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  301. #define __Pyx_DefaultClassType PyClass_Type
  302. #else
  303. #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  304. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  305. PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  306. #define __Pyx_DefaultClassType PyType_Type
  307. #endif
  308. #ifndef Py_TPFLAGS_CHECKTYPES
  309. #define Py_TPFLAGS_CHECKTYPES 0
  310. #endif
  311. #ifndef Py_TPFLAGS_HAVE_INDEX
  312. #define Py_TPFLAGS_HAVE_INDEX 0
  313. #endif
  314. #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  315. #define Py_TPFLAGS_HAVE_NEWBUFFER 0
  316. #endif
  317. #ifndef Py_TPFLAGS_HAVE_FINALIZE
  318. #define Py_TPFLAGS_HAVE_FINALIZE 0
  319. #endif
  320. #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  321. #ifndef METH_FASTCALL
  322. #define METH_FASTCALL 0x80
  323. #endif
  324. typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  325. typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
  326. Py_ssize_t nargs, PyObject *kwnames);
  327. #else
  328. #define __Pyx_PyCFunctionFast _PyCFunctionFast
  329. #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
  330. #endif
  331. #if CYTHON_FAST_PYCCALL
  332. #define __Pyx_PyFastCFunction_Check(func)\
  333. ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)))))
  334. #else
  335. #define __Pyx_PyFastCFunction_Check(func) 0
  336. #endif
  337. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  338. #define PyObject_Malloc(s) PyMem_Malloc(s)
  339. #define PyObject_Free(p) PyMem_Free(p)
  340. #define PyObject_Realloc(p) PyMem_Realloc(p)
  341. #endif
  342. #if CYTHON_COMPILING_IN_PYSTON
  343. #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
  344. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
  345. #else
  346. #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
  347. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
  348. #endif
  349. #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  350. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  351. #elif PY_VERSION_HEX >= 0x03060000
  352. #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
  353. #elif PY_VERSION_HEX >= 0x03000000
  354. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  355. #else
  356. #define __Pyx_PyThreadState_Current _PyThreadState_Current
  357. #endif
  358. #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
  359. #include "pythread.h"
  360. #define Py_tss_NEEDS_INIT 0
  361. typedef int Py_tss_t;
  362. static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  363. *key = PyThread_create_key();
  364. return 0; // PyThread_create_key reports success always
  365. }
  366. static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  367. Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  368. *key = Py_tss_NEEDS_INIT;
  369. return key;
  370. }
  371. static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  372. PyObject_Free(key);
  373. }
  374. static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  375. return *key != Py_tss_NEEDS_INIT;
  376. }
  377. static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  378. PyThread_delete_key(*key);
  379. *key = Py_tss_NEEDS_INIT;
  380. }
  381. static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  382. return PyThread_set_key_value(*key, value);
  383. }
  384. static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  385. return PyThread_get_key_value(*key);
  386. }
  387. #endif // TSS (Thread Specific Storage) API
  388. #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
  389. #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
  390. #else
  391. #define __Pyx_PyDict_NewPresized(n) PyDict_New()
  392. #endif
  393. #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  394. #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
  395. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
  396. #else
  397. #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
  398. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
  399. #endif
  400. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
  401. #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
  402. #else
  403. #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
  404. #endif
  405. #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  406. #define CYTHON_PEP393_ENABLED 1
  407. #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
  408. 0 : _PyUnicode_Ready((PyObject *)(op)))
  409. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  410. #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  411. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
  412. #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
  413. #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
  414. #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
  415. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
  416. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  417. #else
  418. #define CYTHON_PEP393_ENABLED 0
  419. #define PyUnicode_1BYTE_KIND 1
  420. #define PyUnicode_2BYTE_KIND 2
  421. #define PyUnicode_4BYTE_KIND 4
  422. #define __Pyx_PyUnicode_READY(op) (0)
  423. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
  424. #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  425. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  426. #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
  427. #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
  428. #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  429. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  430. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
  431. #endif
  432. #if CYTHON_COMPILING_IN_PYPY
  433. #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
  434. #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
  435. #else
  436. #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
  437. #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
  438. PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
  439. #endif
  440. #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  441. #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
  442. #endif
  443. #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  444. #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
  445. #endif
  446. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  447. #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
  448. #endif
  449. #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
  450. #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
  451. #if PY_MAJOR_VERSION >= 3
  452. #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
  453. #else
  454. #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
  455. #endif
  456. #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  457. #define PyObject_ASCII(o) PyObject_Repr(o)
  458. #endif
  459. #if PY_MAJOR_VERSION >= 3
  460. #define PyBaseString_Type PyUnicode_Type
  461. #define PyStringObject PyUnicodeObject
  462. #define PyString_Type PyUnicode_Type
  463. #define PyString_Check PyUnicode_Check
  464. #define PyString_CheckExact PyUnicode_CheckExact
  465. #define PyObject_Unicode PyObject_Str
  466. #endif
  467. #if PY_MAJOR_VERSION >= 3
  468. #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  469. #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
  470. #else
  471. #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  472. #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
  473. #endif
  474. #ifndef PySet_CheckExact
  475. #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
  476. #endif
  477. #if CYTHON_ASSUME_SAFE_MACROS
  478. #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
  479. #else
  480. #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
  481. #endif
  482. #if PY_MAJOR_VERSION >= 3
  483. #define PyIntObject PyLongObject
  484. #define PyInt_Type PyLong_Type
  485. #define PyInt_Check(op) PyLong_Check(op)
  486. #define PyInt_CheckExact(op) PyLong_CheckExact(op)
  487. #define PyInt_FromString PyLong_FromString
  488. #define PyInt_FromUnicode PyLong_FromUnicode
  489. #define PyInt_FromLong PyLong_FromLong
  490. #define PyInt_FromSize_t PyLong_FromSize_t
  491. #define PyInt_FromSsize_t PyLong_FromSsize_t
  492. #define PyInt_AsLong PyLong_AsLong
  493. #define PyInt_AS_LONG PyLong_AS_LONG
  494. #define PyInt_AsSsize_t PyLong_AsSsize_t
  495. #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
  496. #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  497. #define PyNumber_Int PyNumber_Long
  498. #endif
  499. #if PY_MAJOR_VERSION >= 3
  500. #define PyBoolObject PyLongObject
  501. #endif
  502. #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  503. #ifndef PyUnicode_InternFromString
  504. #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  505. #endif
  506. #endif
  507. #if PY_VERSION_HEX < 0x030200A4
  508. typedef long Py_hash_t;
  509. #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  510. #define __Pyx_PyInt_AsHash_t PyInt_AsLong
  511. #else
  512. #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  513. #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
  514. #endif
  515. #if PY_MAJOR_VERSION >= 3
  516. #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
  517. #else
  518. #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
  519. #endif
  520. #if CYTHON_USE_ASYNC_SLOTS
  521. #if PY_VERSION_HEX >= 0x030500B1
  522. #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
  523. #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  524. #else
  525. #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  526. #endif
  527. #else
  528. #define __Pyx_PyType_AsAsync(obj) NULL
  529. #endif
  530. #ifndef __Pyx_PyAsyncMethodsStruct
  531. typedef struct {
  532. unaryfunc am_await;
  533. unaryfunc am_aiter;
  534. unaryfunc am_anext;
  535. } __Pyx_PyAsyncMethodsStruct;
  536. #endif
  537. #if defined(WIN32) || defined(MS_WINDOWS)
  538. #define _USE_MATH_DEFINES
  539. #endif
  540. #include <math.h>
  541. #ifdef NAN
  542. #define __PYX_NAN() ((float) NAN)
  543. #else
  544. static CYTHON_INLINE float __PYX_NAN() {
  545. float value;
  546. memset(&value, 0xFF, sizeof(value));
  547. return value;
  548. }
  549. #endif
  550. #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
  551. #define __Pyx_truncl trunc
  552. #else
  553. #define __Pyx_truncl truncl
  554. #endif
  555. #define __PYX_ERR(f_index, lineno, Ln_error) \
  556. { \
  557. __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
  558. }
  559. #ifndef __PYX_EXTERN_C
  560. #ifdef __cplusplus
  561. #define __PYX_EXTERN_C extern "C"
  562. #else
  563. #define __PYX_EXTERN_C extern
  564. #endif
  565. #endif
  566. #define __PYX_HAVE__aiohttp___http_writer
  567. #define __PYX_HAVE_API__aiohttp___http_writer
  568. /* Early includes */
  569. #include <stdint.h>
  570. #include <string.h>
  571. #include <stdio.h>
  572. #ifdef _OPENMP
  573. #include <omp.h>
  574. #endif /* _OPENMP */
  575. #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
  576. #define CYTHON_WITHOUT_ASSERTIONS
  577. #endif
  578. typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
  579. const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
  580. #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
  581. #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
  582. #define __PYX_DEFAULT_STRING_ENCODING ""
  583. #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
  584. #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  585. #define __Pyx_uchar_cast(c) ((unsigned char)c)
  586. #define __Pyx_long_cast(x) ((long)x)
  587. #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
  588. (sizeof(type) < sizeof(Py_ssize_t)) ||\
  589. (sizeof(type) > sizeof(Py_ssize_t) &&\
  590. likely(v < (type)PY_SSIZE_T_MAX ||\
  591. v == (type)PY_SSIZE_T_MAX) &&\
  592. (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
  593. v == (type)PY_SSIZE_T_MIN))) ||\
  594. (sizeof(type) == sizeof(Py_ssize_t) &&\
  595. (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
  596. v == (type)PY_SSIZE_T_MAX))) )
  597. #if defined (__cplusplus) && __cplusplus >= 201103L
  598. #include <cstdlib>
  599. #define __Pyx_sst_abs(value) std::abs(value)
  600. #elif SIZEOF_INT >= SIZEOF_SIZE_T
  601. #define __Pyx_sst_abs(value) abs(value)
  602. #elif SIZEOF_LONG >= SIZEOF_SIZE_T
  603. #define __Pyx_sst_abs(value) labs(value)
  604. #elif defined (_MSC_VER)
  605. #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
  606. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  607. #define __Pyx_sst_abs(value) llabs(value)
  608. #elif defined (__GNUC__)
  609. #define __Pyx_sst_abs(value) __builtin_llabs(value)
  610. #else
  611. #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
  612. #endif
  613. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
  614. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
  615. #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
  616. #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
  617. #define __Pyx_PyBytes_FromString PyBytes_FromString
  618. #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
  619. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
  620. #if PY_MAJOR_VERSION < 3
  621. #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
  622. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  623. #else
  624. #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
  625. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
  626. #endif
  627. #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
  628. #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
  629. #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
  630. #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
  631. #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
  632. #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
  633. #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
  634. #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
  635. #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
  636. #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
  637. #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
  638. #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
  639. #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
  640. #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
  641. #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
  642. #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
  643. static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
  644. const Py_UNICODE *u_end = u;
  645. while (*u_end++) ;
  646. return (size_t)(u_end - u - 1);
  647. }
  648. #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
  649. #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
  650. #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
  651. #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
  652. #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
  653. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
  654. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
  655. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
  656. #define __Pyx_PySequence_Tuple(obj)\
  657. (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
  658. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
  659. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
  660. #if CYTHON_ASSUME_SAFE_MACROS
  661. #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
  662. #else
  663. #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
  664. #endif
  665. #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
  666. #if PY_MAJOR_VERSION >= 3
  667. #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
  668. #else
  669. #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
  670. #endif
  671. #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
  672. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  673. static int __Pyx_sys_getdefaultencoding_not_ascii;
  674. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  675. PyObject* sys;
  676. PyObject* default_encoding = NULL;
  677. PyObject* ascii_chars_u = NULL;
  678. PyObject* ascii_chars_b = NULL;
  679. const char* default_encoding_c;
  680. sys = PyImport_ImportModule("sys");
  681. if (!sys) goto bad;
  682. default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
  683. Py_DECREF(sys);
  684. if (!default_encoding) goto bad;
  685. default_encoding_c = PyBytes_AsString(default_encoding);
  686. if (!default_encoding_c) goto bad;
  687. if (strcmp(default_encoding_c, "ascii") == 0) {
  688. __Pyx_sys_getdefaultencoding_not_ascii = 0;
  689. } else {
  690. char ascii_chars[128];
  691. int c;
  692. for (c = 0; c < 128; c++) {
  693. ascii_chars[c] = c;
  694. }
  695. __Pyx_sys_getdefaultencoding_not_ascii = 1;
  696. ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
  697. if (!ascii_chars_u) goto bad;
  698. ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
  699. if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
  700. PyErr_Format(
  701. PyExc_ValueError,
  702. "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
  703. default_encoding_c);
  704. goto bad;
  705. }
  706. Py_DECREF(ascii_chars_u);
  707. Py_DECREF(ascii_chars_b);
  708. }
  709. Py_DECREF(default_encoding);
  710. return 0;
  711. bad:
  712. Py_XDECREF(default_encoding);
  713. Py_XDECREF(ascii_chars_u);
  714. Py_XDECREF(ascii_chars_b);
  715. return -1;
  716. }
  717. #endif
  718. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
  719. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
  720. #else
  721. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
  722. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  723. static char* __PYX_DEFAULT_STRING_ENCODING;
  724. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  725. PyObject* sys;
  726. PyObject* default_encoding = NULL;
  727. char* default_encoding_c;
  728. sys = PyImport_ImportModule("sys");
  729. if (!sys) goto bad;
  730. default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
  731. Py_DECREF(sys);
  732. if (!default_encoding) goto bad;
  733. default_encoding_c = PyBytes_AsString(default_encoding);
  734. if (!default_encoding_c) goto bad;
  735. __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
  736. if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
  737. strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
  738. Py_DECREF(default_encoding);
  739. return 0;
  740. bad:
  741. Py_XDECREF(default_encoding);
  742. return -1;
  743. }
  744. #endif
  745. #endif
  746. /* Test for GCC > 2.95 */
  747. #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  748. #define likely(x) __builtin_expect(!!(x), 1)
  749. #define unlikely(x) __builtin_expect(!!(x), 0)
  750. #else /* !__GNUC__ or GCC < 2.95 */
  751. #define likely(x) (x)
  752. #define unlikely(x) (x)
  753. #endif /* __GNUC__ */
  754. static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
  755. static PyObject *__pyx_m = NULL;
  756. static PyObject *__pyx_d;
  757. static PyObject *__pyx_b;
  758. static PyObject *__pyx_cython_runtime = NULL;
  759. static PyObject *__pyx_empty_tuple;
  760. static PyObject *__pyx_empty_bytes;
  761. static PyObject *__pyx_empty_unicode;
  762. static int __pyx_lineno;
  763. static int __pyx_clineno = 0;
  764. static const char * __pyx_cfilenm= __FILE__;
  765. static const char *__pyx_filename;
  766. static const char *__pyx_f[] = {
  767. "aiohttp/_http_writer.pyx",
  768. "type.pxd",
  769. };
  770. /*--- Type declarations ---*/
  771. struct __pyx_t_7aiohttp_12_http_writer_Writer;
  772. /* "aiohttp/_http_writer.pyx":19
  773. * # ----------------- writer ---------------------------
  774. *
  775. * cdef struct Writer: # <<<<<<<<<<<<<<
  776. * char *buf
  777. * Py_ssize_t size
  778. */
  779. struct __pyx_t_7aiohttp_12_http_writer_Writer {
  780. char *buf;
  781. Py_ssize_t size;
  782. Py_ssize_t pos;
  783. };
  784. /* --- Runtime support code (head) --- */
  785. /* Refnanny.proto */
  786. #ifndef CYTHON_REFNANNY
  787. #define CYTHON_REFNANNY 0
  788. #endif
  789. #if CYTHON_REFNANNY
  790. typedef struct {
  791. void (*INCREF)(void*, PyObject*, int);
  792. void (*DECREF)(void*, PyObject*, int);
  793. void (*GOTREF)(void*, PyObject*, int);
  794. void (*GIVEREF)(void*, PyObject*, int);
  795. void* (*SetupContext)(const char*, int, const char*);
  796. void (*FinishContext)(void**);
  797. } __Pyx_RefNannyAPIStruct;
  798. static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  799. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  800. #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
  801. #ifdef WITH_THREAD
  802. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  803. if (acquire_gil) {\
  804. PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
  805. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  806. PyGILState_Release(__pyx_gilstate_save);\
  807. } else {\
  808. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  809. }
  810. #else
  811. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  812. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  813. #endif
  814. #define __Pyx_RefNannyFinishContext()\
  815. __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  816. #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  817. #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  818. #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  819. #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  820. #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  821. #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  822. #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  823. #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
  824. #else
  825. #define __Pyx_RefNannyDeclarations
  826. #define __Pyx_RefNannySetupContext(name, acquire_gil)
  827. #define __Pyx_RefNannyFinishContext()
  828. #define __Pyx_INCREF(r) Py_INCREF(r)
  829. #define __Pyx_DECREF(r) Py_DECREF(r)
  830. #define __Pyx_GOTREF(r)
  831. #define __Pyx_GIVEREF(r)
  832. #define __Pyx_XINCREF(r) Py_XINCREF(r)
  833. #define __Pyx_XDECREF(r) Py_XDECREF(r)
  834. #define __Pyx_XGOTREF(r)
  835. #define __Pyx_XGIVEREF(r)
  836. #endif
  837. #define __Pyx_XDECREF_SET(r, v) do {\
  838. PyObject *tmp = (PyObject *) r;\
  839. r = v; __Pyx_XDECREF(tmp);\
  840. } while (0)
  841. #define __Pyx_DECREF_SET(r, v) do {\
  842. PyObject *tmp = (PyObject *) r;\
  843. r = v; __Pyx_DECREF(tmp);\
  844. } while (0)
  845. #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
  846. #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
  847. /* PyObjectGetAttrStr.proto */
  848. #if CYTHON_USE_TYPE_SLOTS
  849. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
  850. #else
  851. #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
  852. #endif
  853. /* GetBuiltinName.proto */
  854. static PyObject *__Pyx_GetBuiltinName(PyObject *name);
  855. /* PyThreadStateGet.proto */
  856. #if CYTHON_FAST_THREAD_STATE
  857. #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
  858. #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
  859. #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
  860. #else
  861. #define __Pyx_PyThreadState_declare
  862. #define __Pyx_PyThreadState_assign
  863. #define __Pyx_PyErr_Occurred() PyErr_Occurred()
  864. #endif
  865. /* PyErrFetchRestore.proto */
  866. #if CYTHON_FAST_THREAD_STATE
  867. #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
  868. #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
  869. #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
  870. #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
  871. #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
  872. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  873. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  874. #if CYTHON_COMPILING_IN_CPYTHON
  875. #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
  876. #else
  877. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  878. #endif
  879. #else
  880. #define __Pyx_PyErr_Clear() PyErr_Clear()
  881. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  882. #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
  883. #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
  884. #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
  885. #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
  886. #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
  887. #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
  888. #endif
  889. /* WriteUnraisableException.proto */
  890. static void __Pyx_WriteUnraisable(const char *name, int clineno,
  891. int lineno, const char *filename,
  892. int full_traceback, int nogil);
  893. /* PyCFunctionFastCall.proto */
  894. #if CYTHON_FAST_PYCCALL
  895. static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
  896. #else
  897. #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
  898. #endif
  899. /* PyFunctionFastCall.proto */
  900. #if CYTHON_FAST_PYCALL
  901. #define __Pyx_PyFunction_FastCall(func, args, nargs)\
  902. __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
  903. #if 1 || PY_VERSION_HEX < 0x030600B1
  904. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
  905. #else
  906. #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
  907. #endif
  908. #endif
  909. /* PyObjectCall.proto */
  910. #if CYTHON_COMPILING_IN_CPYTHON
  911. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
  912. #else
  913. #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
  914. #endif
  915. /* PyObjectCallMethO.proto */
  916. #if CYTHON_COMPILING_IN_CPYTHON
  917. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
  918. #endif
  919. /* PyObjectCallOneArg.proto */
  920. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
  921. /* RaiseException.proto */
  922. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
  923. /* RaiseArgTupleInvalid.proto */
  924. static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
  925. Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
  926. /* RaiseDoubleKeywords.proto */
  927. static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
  928. /* ParseKeywords.proto */
  929. static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
  930. PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
  931. const char* function_name);
  932. /* ArgTypeTest.proto */
  933. #define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
  934. ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
  935. __Pyx__ArgTypeTest(obj, type, name, exact))
  936. static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);
  937. /* ReRaiseException.proto */
  938. static CYTHON_INLINE void __Pyx_ReraiseException(void) {
  939. PyObject *type = NULL, *value = NULL, *tb = NULL;
  940. #if CYTHON_FAST_THREAD_STATE
  941. PyThreadState *tstate = PyThreadState_GET();
  942. #if PY_VERSION_HEX >= 0x030700A3
  943. type = tstate->exc_state.exc_type;
  944. value = tstate->exc_state.exc_value;
  945. tb = tstate->exc_state.exc_traceback;
  946. #else
  947. type = tstate->exc_type;
  948. value = tstate->exc_value;
  949. tb = tstate->exc_traceback;
  950. #endif
  951. #else
  952. PyErr_GetExcInfo(&type, &value, &tb);
  953. #endif
  954. if (!type || type == Py_None) {
  955. #if !CYTHON_FAST_THREAD_STATE
  956. Py_XDECREF(type);
  957. Py_XDECREF(value);
  958. Py_XDECREF(tb);
  959. #endif
  960. PyErr_SetString(PyExc_RuntimeError,
  961. "No active exception to reraise");
  962. } else {
  963. #if CYTHON_FAST_THREAD_STATE
  964. Py_INCREF(type);
  965. Py_XINCREF(value);
  966. Py_XINCREF(tb);
  967. #endif
  968. PyErr_Restore(type, value, tb);
  969. }
  970. }
  971. /* PyObjectCallNoArg.proto */
  972. #if CYTHON_COMPILING_IN_CPYTHON
  973. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
  974. #else
  975. #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
  976. #endif
  977. /* RaiseTooManyValuesToUnpack.proto */
  978. static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
  979. /* RaiseNeedMoreValuesToUnpack.proto */
  980. static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
  981. /* IterFinish.proto */
  982. static CYTHON_INLINE int __Pyx_IterFinish(void);
  983. /* UnpackItemEndCheck.proto */
  984. static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);
  985. /* GetException.proto */
  986. #if CYTHON_FAST_THREAD_STATE
  987. #define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb)
  988. static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  989. #else
  990. static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
  991. #endif
  992. /* SwapException.proto */
  993. #if CYTHON_FAST_THREAD_STATE
  994. #define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
  995. static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  996. #else
  997. static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
  998. #endif
  999. /* SaveResetException.proto */
  1000. #if CYTHON_FAST_THREAD_STATE
  1001. #define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
  1002. static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  1003. #define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
  1004. static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  1005. #else
  1006. #define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb)
  1007. #define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb)
  1008. #endif
  1009. /* Import.proto */
  1010. static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
  1011. /* ImportFrom.proto */
  1012. static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
  1013. /* GetModuleGlobalName.proto */
  1014. static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);
  1015. /* CLineInTraceback.proto */
  1016. #ifdef CYTHON_CLINE_IN_TRACEBACK
  1017. #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
  1018. #else
  1019. static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
  1020. #endif
  1021. /* CodeObjectCache.proto */
  1022. typedef struct {
  1023. PyCodeObject* code_object;
  1024. int code_line;
  1025. } __Pyx_CodeObjectCacheEntry;
  1026. struct __Pyx_CodeObjectCache {
  1027. int count;
  1028. int max_count;
  1029. __Pyx_CodeObjectCacheEntry* entries;
  1030. };
  1031. static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
  1032. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
  1033. static PyCodeObject *__pyx_find_code_object(int code_line);
  1034. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
  1035. /* AddTraceback.proto */
  1036. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  1037. int py_line, const char *filename);
  1038. /* UnicodeAsUCS4.proto */
  1039. static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);
  1040. /* ObjectAsUCS4.proto */
  1041. #define __Pyx_PyObject_AsPy_UCS4(x)\
  1042. (likely(PyUnicode_Check(x)) ? __Pyx_PyUnicode_AsPy_UCS4(x) : __Pyx__PyObject_AsPy_UCS4(x))
  1043. static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject*);
  1044. /* CIntToPy.proto */
  1045. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
  1046. /* CIntFromPy.proto */
  1047. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
  1048. /* CIntFromPy.proto */
  1049. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
  1050. /* FastTypeChecks.proto */
  1051. #if CYTHON_COMPILING_IN_CPYTHON
  1052. #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
  1053. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
  1054. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
  1055. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
  1056. #else
  1057. #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
  1058. #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
  1059. #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
  1060. #endif
  1061. #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
  1062. /* CheckBinaryVersion.proto */
  1063. static int __Pyx_check_binary_version(void);
  1064. /* PyIdentifierFromString.proto */
  1065. #if !defined(__Pyx_PyIdentifier_FromString)
  1066. #if PY_MAJOR_VERSION < 3
  1067. #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
  1068. #else
  1069. #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
  1070. #endif
  1071. #endif
  1072. /* ModuleImport.proto */
  1073. static PyObject *__Pyx_ImportModule(const char *name);
  1074. /* TypeImport.proto */
  1075. static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);
  1076. /* InitStrings.proto */
  1077. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
  1078. /* Module declarations from 'libc.stdint' */
  1079. /* Module declarations from 'libc.string' */
  1080. /* Module declarations from 'libc.stdio' */
  1081. /* Module declarations from '__builtin__' */
  1082. /* Module declarations from 'cpython.type' */
  1083. static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;
  1084. /* Module declarations from 'cpython' */
  1085. /* Module declarations from 'cpython.object' */
  1086. /* Module declarations from 'cpython.exc' */
  1087. /* Module declarations from 'cpython.mem' */
  1088. /* Module declarations from 'cpython.bytes' */
  1089. /* Module declarations from 'aiohttp._http_writer' */
  1090. static char __pyx_v_7aiohttp_12_http_writer_BUFFER[0x4000];
  1091. static PyObject *__pyx_v_7aiohttp_12_http_writer__istr = 0;
  1092. static CYTHON_INLINE void __pyx_f_7aiohttp_12_http_writer__init_writer(struct __pyx_t_7aiohttp_12_http_writer_Writer *); /*proto*/
  1093. static CYTHON_INLINE void __pyx_f_7aiohttp_12_http_writer__release_writer(struct __pyx_t_7aiohttp_12_http_writer_Writer *); /*proto*/
  1094. static CYTHON_INLINE int __pyx_f_7aiohttp_12_http_writer__write_byte(struct __pyx_t_7aiohttp_12_http_writer_Writer *, uint8_t); /*proto*/
  1095. static CYTHON_INLINE int __pyx_f_7aiohttp_12_http_writer__write_utf8(struct __pyx_t_7aiohttp_12_http_writer_Writer *, Py_UCS4); /*proto*/
  1096. static CYTHON_INLINE int __pyx_f_7aiohttp_12_http_writer__write_str(struct __pyx_t_7aiohttp_12_http_writer_Writer *, PyObject *); /*proto*/
  1097. static PyObject *__pyx_f_7aiohttp_12_http_writer_to_str(PyObject *); /*proto*/
  1098. #define __Pyx_MODULE_NAME "aiohttp._http_writer"
  1099. extern int __pyx_module_is_main_aiohttp___http_writer;
  1100. int __pyx_module_is_main_aiohttp___http_writer = 0;
  1101. /* Implementation of 'aiohttp._http_writer' */
  1102. static PyObject *__pyx_builtin_TypeError;
  1103. static const char __pyx_k_key[] = "key";
  1104. static const char __pyx_k_ret[] = "ret";
  1105. static const char __pyx_k_val[] = "val";
  1106. static const char __pyx_k_istr[] = "istr";
  1107. static const char __pyx_k_main[] = "__main__";
  1108. static const char __pyx_k_test[] = "__test__";
  1109. static const char __pyx_k_items[] = "items";
  1110. static const char __pyx_k_format[] = "format";
  1111. static const char __pyx_k_import[] = "__import__";
  1112. static const char __pyx_k_writer[] = "writer";
  1113. static const char __pyx_k_headers[] = "headers";
  1114. static const char __pyx_k_TypeError[] = "TypeError";
  1115. static const char __pyx_k_multidict[] = "multidict";
  1116. static const char __pyx_k_status_line[] = "status_line";
  1117. static const char __pyx_k_serialize_headers[] = "_serialize_headers";
  1118. static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
  1119. static const char __pyx_k_aiohttp__http_writer[] = "aiohttp._http_writer";
  1120. static const char __pyx_k_aiohttp__http_writer_pyx[] = "aiohttp/_http_writer.pyx";
  1121. static const char __pyx_k_Cannot_serialize_non_str_key_r[] = "Cannot serialize non-str key {!r}";
  1122. static PyObject *__pyx_kp_s_Cannot_serialize_non_str_key_r;
  1123. static PyObject *__pyx_n_s_TypeError;
  1124. static PyObject *__pyx_n_s_aiohttp__http_writer;
  1125. static PyObject *__pyx_kp_s_aiohttp__http_writer_pyx;
  1126. static PyObject *__pyx_n_s_cline_in_traceback;
  1127. static PyObject *__pyx_n_s_format;
  1128. static PyObject *__pyx_n_s_headers;
  1129. static PyObject *__pyx_n_s_import;
  1130. static PyObject *__pyx_n_s_istr;
  1131. static PyObject *__pyx_n_s_items;
  1132. static PyObject *__pyx_n_s_key;
  1133. static PyObject *__pyx_n_s_main;
  1134. static PyObject *__pyx_n_s_multidict;
  1135. static PyObject *__pyx_n_s_ret;
  1136. static PyObject *__pyx_n_s_serialize_headers;
  1137. static PyObject *__pyx_n_s_status_line;
  1138. static PyObject *__pyx_n_s_test;
  1139. static PyObject *__pyx_n_s_val;
  1140. static PyObject *__pyx_n_s_writer;
  1141. static PyObject *__pyx_pf_7aiohttp_12_http_writer__serialize_headers(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_status_line, PyObject *__pyx_v_headers); /* proto */
  1142. static PyObject *__pyx_tuple_;
  1143. static PyObject *__pyx_codeobj__2;
  1144. /* Late includes */
  1145. /* "aiohttp/_http_writer.pyx":25
  1146. *
  1147. *
  1148. * cdef inline void _init_writer(Writer* writer): # <<<<<<<<<<<<<<
  1149. * writer.buf = &BUFFER[0]
  1150. * writer.size = BUF_SIZE
  1151. */
  1152. static CYTHON_INLINE void __pyx_f_7aiohttp_12_http_writer__init_writer(struct __pyx_t_7aiohttp_12_http_writer_Writer *__pyx_v_writer) {
  1153. __Pyx_RefNannyDeclarations
  1154. __Pyx_RefNannySetupContext("_init_writer", 0);
  1155. /* "aiohttp/_http_writer.pyx":26
  1156. *
  1157. * cdef inline void _init_writer(Writer* writer):
  1158. * writer.buf = &BUFFER[0] # <<<<<<<<<<<<<<
  1159. * writer.size = BUF_SIZE
  1160. * writer.pos = 0
  1161. */
  1162. __pyx_v_writer->buf = (&(__pyx_v_7aiohttp_12_http_writer_BUFFER[0]));
  1163. /* "aiohttp/_http_writer.pyx":27
  1164. * cdef inline void _init_writer(Writer* writer):
  1165. * writer.buf = &BUFFER[0]
  1166. * writer.size = BUF_SIZE # <<<<<<<<<<<<<<
  1167. * writer.pos = 0
  1168. *
  1169. */
  1170. __pyx_v_writer->size = 0x4000;
  1171. /* "aiohttp/_http_writer.pyx":28
  1172. * writer.buf = &BUFFER[0]
  1173. * writer.size = BUF_SIZE
  1174. * writer.pos = 0 # <<<<<<<<<<<<<<
  1175. *
  1176. *
  1177. */
  1178. __pyx_v_writer->pos = 0;
  1179. /* "aiohttp/_http_writer.pyx":25
  1180. *
  1181. *
  1182. * cdef inline void _init_writer(Writer* writer): # <<<<<<<<<<<<<<
  1183. * writer.buf = &BUFFER[0]
  1184. * writer.size = BUF_SIZE
  1185. */
  1186. /* function exit code */
  1187. __Pyx_RefNannyFinishContext();
  1188. }
  1189. /* "aiohttp/_http_writer.pyx":31
  1190. *
  1191. *
  1192. * cdef inline void _release_writer(Writer* writer): # <<<<<<<<<<<<<<
  1193. * if writer.buf != BUFFER:
  1194. * PyMem_Free(writer.buf)
  1195. */
  1196. static CYTHON_INLINE void __pyx_f_7aiohttp_12_http_writer__release_writer(struct __pyx_t_7aiohttp_12_http_writer_Writer *__pyx_v_writer) {
  1197. __Pyx_RefNannyDeclarations
  1198. int __pyx_t_1;
  1199. __Pyx_RefNannySetupContext("_release_writer", 0);
  1200. /* "aiohttp/_http_writer.pyx":32
  1201. *
  1202. * cdef inline void _release_writer(Writer* writer):
  1203. * if writer.buf != BUFFER: # <<<<<<<<<<<<<<
  1204. * PyMem_Free(writer.buf)
  1205. *
  1206. */
  1207. __pyx_t_1 = ((__pyx_v_writer->buf != __pyx_v_7aiohttp_12_http_writer_BUFFER) != 0);
  1208. if (__pyx_t_1) {
  1209. /* "aiohttp/_http_writer.pyx":33
  1210. * cdef inline void _release_writer(Writer* writer):
  1211. * if writer.buf != BUFFER:
  1212. * PyMem_Free(writer.buf) # <<<<<<<<<<<<<<
  1213. *
  1214. *
  1215. */
  1216. PyMem_Free(__pyx_v_writer->buf);
  1217. /* "aiohttp/_http_writer.pyx":32
  1218. *
  1219. * cdef inline void _release_writer(Writer* writer):
  1220. * if writer.buf != BUFFER: # <<<<<<<<<<<<<<
  1221. * PyMem_Free(writer.buf)
  1222. *
  1223. */
  1224. }
  1225. /* "aiohttp/_http_writer.pyx":31
  1226. *
  1227. *
  1228. * cdef inline void _release_writer(Writer* writer): # <<<<<<<<<<<<<<
  1229. * if writer.buf != BUFFER:
  1230. * PyMem_Free(writer.buf)
  1231. */
  1232. /* function exit code */
  1233. __Pyx_RefNannyFinishContext();
  1234. }
  1235. /* "aiohttp/_http_writer.pyx":36
  1236. *
  1237. *
  1238. * cdef inline int _write_byte(Writer* writer, uint8_t ch): # <<<<<<<<<<<<<<
  1239. * cdef char * buf
  1240. * cdef Py_ssize_t size
  1241. */
  1242. static CYTHON_INLINE int __pyx_f_7aiohttp_12_http_writer__write_byte(struct __pyx_t_7aiohttp_12_http_writer_Writer *__pyx_v_writer, uint8_t __pyx_v_ch) {
  1243. char *__pyx_v_buf;
  1244. Py_ssize_t __pyx_v_size;
  1245. int __pyx_r;
  1246. __Pyx_RefNannyDeclarations
  1247. int __pyx_t_1;
  1248. PyObject *__pyx_t_2;
  1249. __Pyx_RefNannySetupContext("_write_byte", 0);
  1250. /* "aiohttp/_http_writer.pyx":40
  1251. * cdef Py_ssize_t size
  1252. *
  1253. * if writer.pos == writer.size: # <<<<<<<<<<<<<<
  1254. * # reallocate
  1255. * size = writer.size + BUF_SIZE
  1256. */
  1257. __pyx_t_1 = ((__pyx_v_writer->pos == __pyx_v_writer->size) != 0);
  1258. if (__pyx_t_1) {
  1259. /* "aiohttp/_http_writer.pyx":42
  1260. * if writer.pos == writer.size:
  1261. * # reallocate
  1262. * size = writer.size + BUF_SIZE # <<<<<<<<<<<<<<
  1263. * if writer.buf == BUFFER:
  1264. * buf = <char*>PyMem_Malloc(size)
  1265. */
  1266. __pyx_v_size = (__pyx_v_writer->size + 0x4000);
  1267. /* "aiohttp/_http_writer.pyx":43
  1268. * # reallocate
  1269. * size = writer.size + BUF_SIZE
  1270. * if writer.buf == BUFFER: # <<<<<<<<<<<<<<
  1271. * buf = <char*>PyMem_Malloc(size)
  1272. * if buf == NULL:
  1273. */
  1274. __pyx_t_1 = ((__pyx_v_writer->buf == __pyx_v_7aiohttp_12_http_writer_BUFFER) != 0);
  1275. if (__pyx_t_1) {
  1276. /* "aiohttp/_http_writer.pyx":44
  1277. * size = writer.size + BUF_SIZE
  1278. * if writer.buf == BUFFER:
  1279. * buf = <char*>PyMem_Malloc(size) # <<<<<<<<<<<<<<
  1280. * if buf == NULL:
  1281. * PyErr_NoMemory()
  1282. */
  1283. __pyx_v_buf = ((char *)PyMem_Malloc(__pyx_v_size));
  1284. /* "aiohttp/_http_writer.pyx":45
  1285. * if writer.buf == BUFFER:
  1286. * buf = <char*>PyMem_Malloc(size)
  1287. * if buf == NULL: # <<<<<<<<<<<<<<
  1288. * PyErr_NoMemory()
  1289. * return -1
  1290. */
  1291. __pyx_t_1 = ((__pyx_v_buf == NULL) != 0);
  1292. if (__pyx_t_1) {
  1293. /* "aiohttp/_http_writer.pyx":46
  1294. * buf = <char*>PyMem_Malloc(size)
  1295. * if buf == NULL:
  1296. * PyErr_NoMemory() # <<<<<<<<<<<<<<
  1297. * return -1
  1298. * memcpy(buf, writer.buf, writer.size)
  1299. */
  1300. __pyx_t_2 = PyErr_NoMemory(); if (unlikely(__pyx_t_2 == ((PyObject *)NULL))) __PYX_ERR(0, 46, __pyx_L1_error)
  1301. /* "aiohttp/_http_writer.pyx":47
  1302. * if buf == NULL:
  1303. * PyErr_NoMemory()
  1304. * return -1 # <<<<<<<<<<<<<<
  1305. * memcpy(buf, writer.buf, writer.size)
  1306. * else:
  1307. */
  1308. __pyx_r = -1;
  1309. goto __pyx_L0;
  1310. /* "aiohttp/_http_writer.pyx":45
  1311. * if writer.buf == BUFFER:
  1312. * buf = <char*>PyMem_Malloc(size)
  1313. * if buf == NULL: # <<<<<<<<<<<<<<
  1314. * PyErr_NoMemory()
  1315. * return -1
  1316. */
  1317. }
  1318. /* "aiohttp/_http_writer.pyx":48
  1319. * PyErr_NoMemory()
  1320. * return -1
  1321. * memcpy(buf, writer.buf, writer.size) # <<<<<<<<<<<<<<
  1322. * else:
  1323. * buf = <char*>PyMem_Realloc(writer.buf, size)
  1324. */
  1325. (void)(memcpy(__pyx_v_buf, __pyx_v_writer->buf, __pyx_v_writer->size));
  1326. /* "aiohttp/_http_writer.pyx":43
  1327. * # reallocate
  1328. * size = writer.size + BUF_SIZE
  1329. * if writer.buf == BUFFER: # <<<<<<<<<<<<<<
  1330. * buf = <char*>PyMem_Malloc(size)
  1331. * if buf == NULL:
  1332. */
  1333. goto __pyx_L4;
  1334. }
  1335. /* "aiohttp/_http_writer.pyx":50
  1336. * memcpy(buf, writer.buf, writer.size)
  1337. * else:
  1338. * buf = <char*>PyMem_Realloc(writer.buf, size) # <<<<<<<<<<<<<<
  1339. * if buf == NULL:
  1340. * PyErr_NoMemory()
  1341. */
  1342. /*else*/ {
  1343. __pyx_v_buf = ((char *)PyMem_Realloc(__pyx_v_writer->buf, __pyx_v_size));
  1344. /* "aiohttp/_http_writer.pyx":51
  1345. * else:
  1346. * buf = <char*>PyMem_Realloc(writer.buf, size)
  1347. * if buf == NULL: # <<<<<<<<<<<<<<
  1348. * PyErr_NoMemory()
  1349. * return -1
  1350. */
  1351. __pyx_t_1 = ((__pyx_v_buf == NULL) != 0);
  1352. if (__pyx_t_1) {
  1353. /* "aiohttp/_http_writer.pyx":52
  1354. * buf = <char*>PyMem_Realloc(writer.buf, size)
  1355. * if buf == NULL:
  1356. * PyErr_NoMemory() # <<<<<<<<<<<<<<
  1357. * return -1
  1358. * writer.buf = buf
  1359. */
  1360. __pyx_t_2 = PyErr_NoMemory(); if (unlikely(__pyx_t_2 == ((PyObject *)NULL))) __PYX_ERR(0, 52, __pyx_L1_error)
  1361. /* "aiohttp/_http_writer.pyx":53
  1362. * if buf == NULL:
  1363. * PyErr_NoMemory()
  1364. * return -1 # <<<<<<<<<<<<<<
  1365. * writer.buf = buf
  1366. * writer.size = size
  1367. */
  1368. __pyx_r = -1;
  1369. goto __pyx_L0;
  1370. /* "aiohttp/_http_writer.pyx":51
  1371. * else:
  1372. * buf = <char*>PyMem_Realloc(writer.buf, size)
  1373. * if buf == NULL: # <<<<<<<<<<<<<<
  1374. * PyErr_NoMemory()
  1375. * return -1
  1376. */
  1377. }
  1378. }
  1379. __pyx_L4:;
  1380. /* "aiohttp/_http_writer.pyx":54
  1381. * PyErr_NoMemory()
  1382. * return -1
  1383. * writer.buf = buf # <<<<<<<<<<<<<<
  1384. * writer.size = size
  1385. * writer.buf[writer.pos] = <char>ch
  1386. */
  1387. __pyx_v_writer->buf = __pyx_v_buf;
  1388. /* "aiohttp/_http_writer.pyx":55
  1389. * return -1
  1390. * writer.buf = buf
  1391. * writer.size = size # <<<<<<<<<<<<<<
  1392. * writer.buf[writer.pos] = <char>ch
  1393. * writer.pos += 1
  1394. */
  1395. __pyx_v_writer->size = __pyx_v_size;
  1396. /* "aiohttp/_http_writer.pyx":40
  1397. * cdef Py_ssize_t size
  1398. *
  1399. * if writer.pos == writer.size: # <<<<<<<<<<<<<<
  1400. * # reallocate
  1401. * size = writer.size + BUF_SIZE
  1402. */
  1403. }
  1404. /* "aiohttp/_http_writer.pyx":56
  1405. * writer.buf = buf
  1406. * writer.size = size
  1407. * writer.buf[writer.pos] = <char>ch # <<<<<<<<<<<<<<
  1408. * writer.pos += 1
  1409. * return 0
  1410. */
  1411. (__pyx_v_writer->buf[__pyx_v_writer->pos]) = ((char)__pyx_v_ch);
  1412. /* "aiohttp/_http_writer.pyx":57
  1413. * writer.size = size
  1414. * writer.buf[writer.pos] = <char>ch
  1415. * writer.pos += 1 # <<<<<<<<<<<<<<
  1416. * return 0
  1417. *
  1418. */
  1419. __pyx_v_writer->pos = (__pyx_v_writer->pos + 1);
  1420. /* "aiohttp/_http_writer.pyx":58
  1421. * writer.buf[writer.pos] = <char>ch
  1422. * writer.pos += 1
  1423. * return 0 # <<<<<<<<<<<<<<
  1424. *
  1425. *
  1426. */
  1427. __pyx_r = 0;
  1428. goto __pyx_L0;
  1429. /* "aiohttp/_http_writer.pyx":36
  1430. *
  1431. *
  1432. * cdef inline int _write_byte(Writer* writer, uint8_t ch): # <<<<<<<<<<<<<<
  1433. * cdef char * buf
  1434. * cdef Py_ssize_t size
  1435. */
  1436. /* function exit code */
  1437. __pyx_L1_error:;
  1438. __Pyx_WriteUnraisable("aiohttp._http_writer._write_byte", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  1439. __pyx_r = 0;
  1440. __pyx_L0:;
  1441. __Pyx_RefNannyFinishContext();
  1442. return __pyx_r;
  1443. }
  1444. /* "aiohttp/_http_writer.pyx":61
  1445. *
  1446. *
  1447. * cdef inline int _write_utf8(Writer* writer, Py_UCS4 symbol): # <<<<<<<<<<<<<<
  1448. * cdef uint64_t utf = <uint64_t> symbol
  1449. *
  1450. */
  1451. static CYTHON_INLINE int __pyx_f_7aiohttp_12_http_writer__write_utf8(struct __pyx_t_7aiohttp_12_http_writer_Writer *__pyx_v_writer, Py_UCS4 __pyx_v_symbol) {
  1452. uint64_t __pyx_v_utf;
  1453. int __pyx_r;
  1454. __Pyx_RefNannyDeclarations
  1455. int __pyx_t_1;
  1456. int __pyx_t_2;
  1457. __Pyx_RefNannySetupContext("_write_utf8", 0);
  1458. /* "aiohttp/_http_writer.pyx":62
  1459. *
  1460. * cdef inline int _write_utf8(Writer* writer, Py_UCS4 symbol):
  1461. * cdef uint64_t utf = <uint64_t> symbol # <<<<<<<<<<<<<<
  1462. *
  1463. * if utf < 0x80:
  1464. */
  1465. __pyx_v_utf = ((uint64_t)__pyx_v_symbol);
  1466. /* "aiohttp/_http_writer.pyx":64
  1467. * cdef uint64_t utf = <uint64_t> symbol
  1468. *
  1469. * if utf < 0x80: # <<<<<<<<<<<<<<
  1470. * return _write_byte(writer, <uint8_t>utf)
  1471. * elif utf < 0x800:
  1472. */
  1473. __pyx_t_1 = ((__pyx_v_utf < 0x80) != 0);
  1474. if (__pyx_t_1) {
  1475. /* "aiohttp/_http_writer.pyx":65
  1476. *
  1477. * if utf < 0x80:
  1478. * return _write_byte(writer, <uint8_t>utf) # <<<<<<<<<<<<<<
  1479. * elif utf < 0x800:
  1480. * if _write_byte(writer, <uint8_t>(0xc0 | (utf >> 6))) < 0:
  1481. */
  1482. __pyx_r = __pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)__pyx_v_utf));
  1483. goto __pyx_L0;
  1484. /* "aiohttp/_http_writer.pyx":64
  1485. * cdef uint64_t utf = <uint64_t> symbol
  1486. *
  1487. * if utf < 0x80: # <<<<<<<<<<<<<<
  1488. * return _write_byte(writer, <uint8_t>utf)
  1489. * elif utf < 0x800:
  1490. */
  1491. }
  1492. /* "aiohttp/_http_writer.pyx":66
  1493. * if utf < 0x80:
  1494. * return _write_byte(writer, <uint8_t>utf)
  1495. * elif utf < 0x800: # <<<<<<<<<<<<<<
  1496. * if _write_byte(writer, <uint8_t>(0xc0 | (utf >> 6))) < 0:
  1497. * return -1
  1498. */
  1499. __pyx_t_1 = ((__pyx_v_utf < 0x800) != 0);
  1500. if (__pyx_t_1) {
  1501. /* "aiohttp/_http_writer.pyx":67
  1502. * return _write_byte(writer, <uint8_t>utf)
  1503. * elif utf < 0x800:
  1504. * if _write_byte(writer, <uint8_t>(0xc0 | (utf >> 6))) < 0: # <<<<<<<<<<<<<<
  1505. * return -1
  1506. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1507. */
  1508. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0xc0 | (__pyx_v_utf >> 6)))) < 0) != 0);
  1509. if (__pyx_t_1) {
  1510. /* "aiohttp/_http_writer.pyx":68
  1511. * elif utf < 0x800:
  1512. * if _write_byte(writer, <uint8_t>(0xc0 | (utf >> 6))) < 0:
  1513. * return -1 # <<<<<<<<<<<<<<
  1514. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1515. * elif 0xD800 <= utf <= 0xDFFF:
  1516. */
  1517. __pyx_r = -1;
  1518. goto __pyx_L0;
  1519. /* "aiohttp/_http_writer.pyx":67
  1520. * return _write_byte(writer, <uint8_t>utf)
  1521. * elif utf < 0x800:
  1522. * if _write_byte(writer, <uint8_t>(0xc0 | (utf >> 6))) < 0: # <<<<<<<<<<<<<<
  1523. * return -1
  1524. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1525. */
  1526. }
  1527. /* "aiohttp/_http_writer.pyx":69
  1528. * if _write_byte(writer, <uint8_t>(0xc0 | (utf >> 6))) < 0:
  1529. * return -1
  1530. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f))) # <<<<<<<<<<<<<<
  1531. * elif 0xD800 <= utf <= 0xDFFF:
  1532. * # surogate pair, ignored
  1533. */
  1534. __pyx_r = __pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0x80 | (__pyx_v_utf & 0x3f))));
  1535. goto __pyx_L0;
  1536. /* "aiohttp/_http_writer.pyx":66
  1537. * if utf < 0x80:
  1538. * return _write_byte(writer, <uint8_t>utf)
  1539. * elif utf < 0x800: # <<<<<<<<<<<<<<
  1540. * if _write_byte(writer, <uint8_t>(0xc0 | (utf >> 6))) < 0:
  1541. * return -1
  1542. */
  1543. }
  1544. /* "aiohttp/_http_writer.pyx":70
  1545. * return -1
  1546. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1547. * elif 0xD800 <= utf <= 0xDFFF: # <<<<<<<<<<<<<<
  1548. * # surogate pair, ignored
  1549. * return 0
  1550. */
  1551. __pyx_t_1 = (0xD800 <= __pyx_v_utf);
  1552. if (__pyx_t_1) {
  1553. __pyx_t_1 = (__pyx_v_utf <= 0xDFFF);
  1554. }
  1555. __pyx_t_2 = (__pyx_t_1 != 0);
  1556. if (__pyx_t_2) {
  1557. /* "aiohttp/_http_writer.pyx":72
  1558. * elif 0xD800 <= utf <= 0xDFFF:
  1559. * # surogate pair, ignored
  1560. * return 0 # <<<<<<<<<<<<<<
  1561. * elif utf < 0x10000:
  1562. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0:
  1563. */
  1564. __pyx_r = 0;
  1565. goto __pyx_L0;
  1566. /* "aiohttp/_http_writer.pyx":70
  1567. * return -1
  1568. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1569. * elif 0xD800 <= utf <= 0xDFFF: # <<<<<<<<<<<<<<
  1570. * # surogate pair, ignored
  1571. * return 0
  1572. */
  1573. }
  1574. /* "aiohttp/_http_writer.pyx":73
  1575. * # surogate pair, ignored
  1576. * return 0
  1577. * elif utf < 0x10000: # <<<<<<<<<<<<<<
  1578. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0:
  1579. * return -1
  1580. */
  1581. __pyx_t_2 = ((__pyx_v_utf < 0x10000) != 0);
  1582. if (__pyx_t_2) {
  1583. /* "aiohttp/_http_writer.pyx":74
  1584. * return 0
  1585. * elif utf < 0x10000:
  1586. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0: # <<<<<<<<<<<<<<
  1587. * return -1
  1588. * if _write_byte(writer, <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1589. */
  1590. __pyx_t_2 = ((__pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0xe0 | (__pyx_v_utf >> 12)))) < 0) != 0);
  1591. if (__pyx_t_2) {
  1592. /* "aiohttp/_http_writer.pyx":75
  1593. * elif utf < 0x10000:
  1594. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0:
  1595. * return -1 # <<<<<<<<<<<<<<
  1596. * if _write_byte(writer, <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1597. * return -1
  1598. */
  1599. __pyx_r = -1;
  1600. goto __pyx_L0;
  1601. /* "aiohttp/_http_writer.pyx":74
  1602. * return 0
  1603. * elif utf < 0x10000:
  1604. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0: # <<<<<<<<<<<<<<
  1605. * return -1
  1606. * if _write_byte(writer, <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1607. */
  1608. }
  1609. /* "aiohttp/_http_writer.pyx":76
  1610. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0:
  1611. * return -1
  1612. * if _write_byte(writer, <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0: # <<<<<<<<<<<<<<
  1613. * return -1
  1614. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1615. */
  1616. __pyx_t_2 = ((__pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0x80 | ((__pyx_v_utf >> 6) & 0x3f)))) < 0) != 0);
  1617. if (__pyx_t_2) {
  1618. /* "aiohttp/_http_writer.pyx":77
  1619. * return -1
  1620. * if _write_byte(writer, <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1621. * return -1 # <<<<<<<<<<<<<<
  1622. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1623. * elif utf > 0x10FFFF:
  1624. */
  1625. __pyx_r = -1;
  1626. goto __pyx_L0;
  1627. /* "aiohttp/_http_writer.pyx":76
  1628. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0:
  1629. * return -1
  1630. * if _write_byte(writer, <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0: # <<<<<<<<<<<<<<
  1631. * return -1
  1632. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1633. */
  1634. }
  1635. /* "aiohttp/_http_writer.pyx":78
  1636. * if _write_byte(writer, <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1637. * return -1
  1638. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f))) # <<<<<<<<<<<<<<
  1639. * elif utf > 0x10FFFF:
  1640. * # symbol is too large
  1641. */
  1642. __pyx_r = __pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0x80 | (__pyx_v_utf & 0x3f))));
  1643. goto __pyx_L0;
  1644. /* "aiohttp/_http_writer.pyx":73
  1645. * # surogate pair, ignored
  1646. * return 0
  1647. * elif utf < 0x10000: # <<<<<<<<<<<<<<
  1648. * if _write_byte(writer, <uint8_t>(0xe0 | (utf >> 12))) < 0:
  1649. * return -1
  1650. */
  1651. }
  1652. /* "aiohttp/_http_writer.pyx":79
  1653. * return -1
  1654. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1655. * elif utf > 0x10FFFF: # <<<<<<<<<<<<<<
  1656. * # symbol is too large
  1657. * return 0
  1658. */
  1659. __pyx_t_2 = ((__pyx_v_utf > 0x10FFFF) != 0);
  1660. if (__pyx_t_2) {
  1661. /* "aiohttp/_http_writer.pyx":81
  1662. * elif utf > 0x10FFFF:
  1663. * # symbol is too large
  1664. * return 0 # <<<<<<<<<<<<<<
  1665. * else:
  1666. * if _write_byte(writer, <uint8_t>(0xf0 | (utf >> 18))) < 0:
  1667. */
  1668. __pyx_r = 0;
  1669. goto __pyx_L0;
  1670. /* "aiohttp/_http_writer.pyx":79
  1671. * return -1
  1672. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1673. * elif utf > 0x10FFFF: # <<<<<<<<<<<<<<
  1674. * # symbol is too large
  1675. * return 0
  1676. */
  1677. }
  1678. /* "aiohttp/_http_writer.pyx":83
  1679. * return 0
  1680. * else:
  1681. * if _write_byte(writer, <uint8_t>(0xf0 | (utf >> 18))) < 0: # <<<<<<<<<<<<<<
  1682. * return -1
  1683. * if _write_byte(writer,
  1684. */
  1685. /*else*/ {
  1686. __pyx_t_2 = ((__pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0xf0 | (__pyx_v_utf >> 18)))) < 0) != 0);
  1687. if (__pyx_t_2) {
  1688. /* "aiohttp/_http_writer.pyx":84
  1689. * else:
  1690. * if _write_byte(writer, <uint8_t>(0xf0 | (utf >> 18))) < 0:
  1691. * return -1 # <<<<<<<<<<<<<<
  1692. * if _write_byte(writer,
  1693. * <uint8_t>(0x80 | ((utf >> 12) & 0x3f))) < 0:
  1694. */
  1695. __pyx_r = -1;
  1696. goto __pyx_L0;
  1697. /* "aiohttp/_http_writer.pyx":83
  1698. * return 0
  1699. * else:
  1700. * if _write_byte(writer, <uint8_t>(0xf0 | (utf >> 18))) < 0: # <<<<<<<<<<<<<<
  1701. * return -1
  1702. * if _write_byte(writer,
  1703. */
  1704. }
  1705. /* "aiohttp/_http_writer.pyx":86
  1706. * return -1
  1707. * if _write_byte(writer,
  1708. * <uint8_t>(0x80 | ((utf >> 12) & 0x3f))) < 0: # <<<<<<<<<<<<<<
  1709. * return -1
  1710. * if _write_byte(writer,
  1711. */
  1712. __pyx_t_2 = ((__pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0x80 | ((__pyx_v_utf >> 12) & 0x3f)))) < 0) != 0);
  1713. /* "aiohttp/_http_writer.pyx":85
  1714. * if _write_byte(writer, <uint8_t>(0xf0 | (utf >> 18))) < 0:
  1715. * return -1
  1716. * if _write_byte(writer, # <<<<<<<<<<<<<<
  1717. * <uint8_t>(0x80 | ((utf >> 12) & 0x3f))) < 0:
  1718. * return -1
  1719. */
  1720. if (__pyx_t_2) {
  1721. /* "aiohttp/_http_writer.pyx":87
  1722. * if _write_byte(writer,
  1723. * <uint8_t>(0x80 | ((utf >> 12) & 0x3f))) < 0:
  1724. * return -1 # <<<<<<<<<<<<<<
  1725. * if _write_byte(writer,
  1726. * <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1727. */
  1728. __pyx_r = -1;
  1729. goto __pyx_L0;
  1730. /* "aiohttp/_http_writer.pyx":85
  1731. * if _write_byte(writer, <uint8_t>(0xf0 | (utf >> 18))) < 0:
  1732. * return -1
  1733. * if _write_byte(writer, # <<<<<<<<<<<<<<
  1734. * <uint8_t>(0x80 | ((utf >> 12) & 0x3f))) < 0:
  1735. * return -1
  1736. */
  1737. }
  1738. /* "aiohttp/_http_writer.pyx":89
  1739. * return -1
  1740. * if _write_byte(writer,
  1741. * <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0: # <<<<<<<<<<<<<<
  1742. * return -1
  1743. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1744. */
  1745. __pyx_t_2 = ((__pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0x80 | ((__pyx_v_utf >> 6) & 0x3f)))) < 0) != 0);
  1746. /* "aiohttp/_http_writer.pyx":88
  1747. * <uint8_t>(0x80 | ((utf >> 12) & 0x3f))) < 0:
  1748. * return -1
  1749. * if _write_byte(writer, # <<<<<<<<<<<<<<
  1750. * <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1751. * return -1
  1752. */
  1753. if (__pyx_t_2) {
  1754. /* "aiohttp/_http_writer.pyx":90
  1755. * if _write_byte(writer,
  1756. * <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1757. * return -1 # <<<<<<<<<<<<<<
  1758. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f)))
  1759. *
  1760. */
  1761. __pyx_r = -1;
  1762. goto __pyx_L0;
  1763. /* "aiohttp/_http_writer.pyx":88
  1764. * <uint8_t>(0x80 | ((utf >> 12) & 0x3f))) < 0:
  1765. * return -1
  1766. * if _write_byte(writer, # <<<<<<<<<<<<<<
  1767. * <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1768. * return -1
  1769. */
  1770. }
  1771. /* "aiohttp/_http_writer.pyx":91
  1772. * <uint8_t>(0x80 | ((utf >> 6) & 0x3f))) < 0:
  1773. * return -1
  1774. * return _write_byte(writer, <uint8_t>(0x80 | (utf & 0x3f))) # <<<<<<<<<<<<<<
  1775. *
  1776. *
  1777. */
  1778. __pyx_r = __pyx_f_7aiohttp_12_http_writer__write_byte(__pyx_v_writer, ((uint8_t)(0x80 | (__pyx_v_utf & 0x3f))));
  1779. goto __pyx_L0;
  1780. }
  1781. /* "aiohttp/_http_writer.pyx":61
  1782. *
  1783. *
  1784. * cdef inline int _write_utf8(Writer* writer, Py_UCS4 symbol): # <<<<<<<<<<<<<<
  1785. * cdef uint64_t utf = <uint64_t> symbol
  1786. *
  1787. */
  1788. /* function exit code */
  1789. __pyx_L0:;
  1790. __Pyx_RefNannyFinishContext();
  1791. return __pyx_r;
  1792. }
  1793. /* "aiohttp/_http_writer.pyx":94
  1794. *
  1795. *
  1796. * cdef inline int _write_str(Writer* writer, str s): # <<<<<<<<<<<<<<
  1797. * cdef Py_UCS4 ch
  1798. * for ch in s:
  1799. */
  1800. static CYTHON_INLINE int __pyx_f_7aiohttp_12_http_writer__write_str(struct __pyx_t_7aiohttp_12_http_writer_Writer *__pyx_v_writer, PyObject *__pyx_v_s) {
  1801. Py_UCS4 __pyx_v_ch;
  1802. int __pyx_r;
  1803. __Pyx_RefNannyDeclarations
  1804. PyObject *__pyx_t_1 = NULL;
  1805. PyObject *(*__pyx_t_2)(PyObject *);
  1806. PyObject *__pyx_t_3 = NULL;
  1807. Py_UCS4 __pyx_t_4;
  1808. int __pyx_t_5;
  1809. __Pyx_RefNannySetupContext("_write_str", 0);
  1810. /* "aiohttp/_http_writer.pyx":96
  1811. * cdef inline int _write_str(Writer* writer, str s):
  1812. * cdef Py_UCS4 ch
  1813. * for ch in s: # <<<<<<<<<<<<<<
  1814. * if _write_utf8(writer, ch) < 0:
  1815. * return -1
  1816. */
  1817. __pyx_t_1 = PyObject_GetIter(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
  1818. __Pyx_GOTREF(__pyx_t_1);
  1819. __pyx_t_2 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error)
  1820. for (;;) {
  1821. {
  1822. __pyx_t_3 = __pyx_t_2(__pyx_t_1);
  1823. if (unlikely(!__pyx_t_3)) {
  1824. PyObject* exc_type = PyErr_Occurred();
  1825. if (exc_type) {
  1826. if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
  1827. else __PYX_ERR(0, 96, __pyx_L1_error)
  1828. }
  1829. break;
  1830. }
  1831. __Pyx_GOTREF(__pyx_t_3);
  1832. }
  1833. __pyx_t_4 = __Pyx_PyObject_AsPy_UCS4(__pyx_t_3); if (unlikely((__pyx_t_4 == (Py_UCS4)-1) && PyErr_Occurred())) __PYX_ERR(0, 96, __pyx_L1_error)
  1834. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1835. __pyx_v_ch = __pyx_t_4;
  1836. /* "aiohttp/_http_writer.pyx":97
  1837. * cdef Py_UCS4 ch
  1838. * for ch in s:
  1839. * if _write_utf8(writer, ch) < 0: # <<<<<<<<<<<<<<
  1840. * return -1
  1841. *
  1842. */
  1843. __pyx_t_5 = ((__pyx_f_7aiohttp_12_http_writer__write_utf8(__pyx_v_writer, __pyx_v_ch) < 0) != 0);
  1844. if (__pyx_t_5) {
  1845. /* "aiohttp/_http_writer.pyx":98
  1846. * for ch in s:
  1847. * if _write_utf8(writer, ch) < 0:
  1848. * return -1 # <<<<<<<<<<<<<<
  1849. *
  1850. *
  1851. */
  1852. __pyx_r = -1;
  1853. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1854. goto __pyx_L0;
  1855. /* "aiohttp/_http_writer.pyx":97
  1856. * cdef Py_UCS4 ch
  1857. * for ch in s:
  1858. * if _write_utf8(writer, ch) < 0: # <<<<<<<<<<<<<<
  1859. * return -1
  1860. *
  1861. */
  1862. }
  1863. /* "aiohttp/_http_writer.pyx":96
  1864. * cdef inline int _write_str(Writer* writer, str s):
  1865. * cdef Py_UCS4 ch
  1866. * for ch in s: # <<<<<<<<<<<<<<
  1867. * if _write_utf8(writer, ch) < 0:
  1868. * return -1
  1869. */
  1870. }
  1871. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1872. /* "aiohttp/_http_writer.pyx":94
  1873. *
  1874. *
  1875. * cdef inline int _write_str(Writer* writer, str s): # <<<<<<<<<<<<<<
  1876. * cdef Py_UCS4 ch
  1877. * for ch in s:
  1878. */
  1879. /* function exit code */
  1880. __pyx_r = 0;
  1881. goto __pyx_L0;
  1882. __pyx_L1_error:;
  1883. __Pyx_XDECREF(__pyx_t_1);
  1884. __Pyx_XDECREF(__pyx_t_3);
  1885. __Pyx_WriteUnraisable("aiohttp._http_writer._write_str", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  1886. __pyx_r = 0;
  1887. __pyx_L0:;
  1888. __Pyx_RefNannyFinishContext();
  1889. return __pyx_r;
  1890. }
  1891. /* "aiohttp/_http_writer.pyx":103
  1892. * # --------------- _serialize_headers ----------------------
  1893. *
  1894. * cdef str to_str(object s): # <<<<<<<<<<<<<<
  1895. * typ = type(s)
  1896. * if typ is str:
  1897. */
  1898. static PyObject *__pyx_f_7aiohttp_12_http_writer_to_str(PyObject *__pyx_v_s) {
  1899. PyTypeObject *__pyx_v_typ = NULL;
  1900. PyObject *__pyx_r = NULL;
  1901. __Pyx_RefNannyDeclarations
  1902. int __pyx_t_1;
  1903. int __pyx_t_2;
  1904. PyObject *__pyx_t_3 = NULL;
  1905. PyObject *__pyx_t_4 = NULL;
  1906. PyObject *__pyx_t_5 = NULL;
  1907. PyObject *__pyx_t_6 = NULL;
  1908. __Pyx_RefNannySetupContext("to_str", 0);
  1909. /* "aiohttp/_http_writer.pyx":104
  1910. *
  1911. * cdef str to_str(object s):
  1912. * typ = type(s) # <<<<<<<<<<<<<<
  1913. * if typ is str:
  1914. * return <str>s
  1915. */
  1916. __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_s)));
  1917. __pyx_v_typ = ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_s)));
  1918. /* "aiohttp/_http_writer.pyx":105
  1919. * cdef str to_str(object s):
  1920. * typ = type(s)
  1921. * if typ is str: # <<<<<<<<<<<<<<
  1922. * return <str>s
  1923. * elif typ is _istr:
  1924. */
  1925. __pyx_t_1 = (__pyx_v_typ == (&PyString_Type));
  1926. __pyx_t_2 = (__pyx_t_1 != 0);
  1927. if (__pyx_t_2) {
  1928. /* "aiohttp/_http_writer.pyx":106
  1929. * typ = type(s)
  1930. * if typ is str:
  1931. * return <str>s # <<<<<<<<<<<<<<
  1932. * elif typ is _istr:
  1933. * return PyObject_Str(s)
  1934. */
  1935. __Pyx_XDECREF(__pyx_r);
  1936. __Pyx_INCREF(((PyObject*)__pyx_v_s));
  1937. __pyx_r = ((PyObject*)__pyx_v_s);
  1938. goto __pyx_L0;
  1939. /* "aiohttp/_http_writer.pyx":105
  1940. * cdef str to_str(object s):
  1941. * typ = type(s)
  1942. * if typ is str: # <<<<<<<<<<<<<<
  1943. * return <str>s
  1944. * elif typ is _istr:
  1945. */
  1946. }
  1947. /* "aiohttp/_http_writer.pyx":107
  1948. * if typ is str:
  1949. * return <str>s
  1950. * elif typ is _istr: # <<<<<<<<<<<<<<
  1951. * return PyObject_Str(s)
  1952. * elif not isinstance(s, str):
  1953. */
  1954. __pyx_t_2 = (__pyx_v_typ == ((PyTypeObject*)__pyx_v_7aiohttp_12_http_writer__istr));
  1955. __pyx_t_1 = (__pyx_t_2 != 0);
  1956. if (__pyx_t_1) {
  1957. /* "aiohttp/_http_writer.pyx":108
  1958. * return <str>s
  1959. * elif typ is _istr:
  1960. * return PyObject_Str(s) # <<<<<<<<<<<<<<
  1961. * elif not isinstance(s, str):
  1962. * raise TypeError("Cannot serialize non-str key {!r}".format(s))
  1963. */
  1964. __Pyx_XDECREF(__pyx_r);
  1965. __pyx_t_3 = PyObject_Str(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 108, __pyx_L1_error)
  1966. __Pyx_GOTREF(__pyx_t_3);
  1967. if (!(likely(PyString_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 108, __pyx_L1_error)
  1968. __pyx_r = ((PyObject*)__pyx_t_3);
  1969. __pyx_t_3 = 0;
  1970. goto __pyx_L0;
  1971. /* "aiohttp/_http_writer.pyx":107
  1972. * if typ is str:
  1973. * return <str>s
  1974. * elif typ is _istr: # <<<<<<<<<<<<<<
  1975. * return PyObject_Str(s)
  1976. * elif not isinstance(s, str):
  1977. */
  1978. }
  1979. /* "aiohttp/_http_writer.pyx":109
  1980. * elif typ is _istr:
  1981. * return PyObject_Str(s)
  1982. * elif not isinstance(s, str): # <<<<<<<<<<<<<<
  1983. * raise TypeError("Cannot serialize non-str key {!r}".format(s))
  1984. * else:
  1985. */
  1986. __pyx_t_1 = PyString_Check(__pyx_v_s);
  1987. __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
  1988. if (unlikely(__pyx_t_2)) {
  1989. /* "aiohttp/_http_writer.pyx":110
  1990. * return PyObject_Str(s)
  1991. * elif not isinstance(s, str):
  1992. * raise TypeError("Cannot serialize non-str key {!r}".format(s)) # <<<<<<<<<<<<<<
  1993. * else:
  1994. * return str(s)
  1995. */
  1996. __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Cannot_serialize_non_str_key_r, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error)
  1997. __Pyx_GOTREF(__pyx_t_4);
  1998. __pyx_t_5 = NULL;
  1999. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
  2000. __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
  2001. if (likely(__pyx_t_5)) {
  2002. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
  2003. __Pyx_INCREF(__pyx_t_5);
  2004. __Pyx_INCREF(function);
  2005. __Pyx_DECREF_SET(__pyx_t_4, function);
  2006. }
  2007. }
  2008. if (!__pyx_t_5) {
  2009. __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 110, __pyx_L1_error)
  2010. __Pyx_GOTREF(__pyx_t_3);
  2011. } else {
  2012. #if CYTHON_FAST_PYCALL
  2013. if (PyFunction_Check(__pyx_t_4)) {
  2014. PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_s};
  2015. __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 110, __pyx_L1_error)
  2016. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  2017. __Pyx_GOTREF(__pyx_t_3);
  2018. } else
  2019. #endif
  2020. #if CYTHON_FAST_PYCCALL
  2021. if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
  2022. PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_s};
  2023. __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 110, __pyx_L1_error)
  2024. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  2025. __Pyx_GOTREF(__pyx_t_3);
  2026. } else
  2027. #endif
  2028. {
  2029. __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 110, __pyx_L1_error)
  2030. __Pyx_GOTREF(__pyx_t_6);
  2031. __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
  2032. __Pyx_INCREF(__pyx_v_s);
  2033. __Pyx_GIVEREF(__pyx_v_s);
  2034. PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_s);
  2035. __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 110, __pyx_L1_error)
  2036. __Pyx_GOTREF(__pyx_t_3);
  2037. __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  2038. }
  2039. }
  2040. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2041. __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error)
  2042. __Pyx_GOTREF(__pyx_t_4);
  2043. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2044. __Pyx_Raise(__pyx_t_4, 0, 0, 0);
  2045. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2046. __PYX_ERR(0, 110, __pyx_L1_error)
  2047. /* "aiohttp/_http_writer.pyx":109
  2048. * elif typ is _istr:
  2049. * return PyObject_Str(s)
  2050. * elif not isinstance(s, str): # <<<<<<<<<<<<<<
  2051. * raise TypeError("Cannot serialize non-str key {!r}".format(s))
  2052. * else:
  2053. */
  2054. }
  2055. /* "aiohttp/_http_writer.pyx":112
  2056. * raise TypeError("Cannot serialize non-str key {!r}".format(s))
  2057. * else:
  2058. * return str(s) # <<<<<<<<<<<<<<
  2059. *
  2060. *
  2061. */
  2062. /*else*/ {
  2063. __Pyx_XDECREF(__pyx_r);
  2064. __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_s); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 112, __pyx_L1_error)
  2065. __Pyx_GOTREF(__pyx_t_4);
  2066. if (!(likely(PyString_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 112, __pyx_L1_error)
  2067. __pyx_r = ((PyObject*)__pyx_t_4);
  2068. __pyx_t_4 = 0;
  2069. goto __pyx_L0;
  2070. }
  2071. /* "aiohttp/_http_writer.pyx":103
  2072. * # --------------- _serialize_headers ----------------------
  2073. *
  2074. * cdef str to_str(object s): # <<<<<<<<<<<<<<
  2075. * typ = type(s)
  2076. * if typ is str:
  2077. */
  2078. /* function exit code */
  2079. __pyx_L1_error:;
  2080. __Pyx_XDECREF(__pyx_t_3);
  2081. __Pyx_XDECREF(__pyx_t_4);
  2082. __Pyx_XDECREF(__pyx_t_5);
  2083. __Pyx_XDECREF(__pyx_t_6);
  2084. __Pyx_AddTraceback("aiohttp._http_writer.to_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2085. __pyx_r = 0;
  2086. __pyx_L0:;
  2087. __Pyx_XDECREF(__pyx_v_typ);
  2088. __Pyx_XGIVEREF(__pyx_r);
  2089. __Pyx_RefNannyFinishContext();
  2090. return __pyx_r;
  2091. }
  2092. /* "aiohttp/_http_writer.pyx":115
  2093. *
  2094. *
  2095. * def _serialize_headers(str status_line, headers): # <<<<<<<<<<<<<<
  2096. * cdef Writer writer
  2097. * cdef object key
  2098. */
  2099. /* Python wrapper */
  2100. static PyObject *__pyx_pw_7aiohttp_12_http_writer_1_serialize_headers(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  2101. static PyMethodDef __pyx_mdef_7aiohttp_12_http_writer_1_serialize_headers = {"_serialize_headers", (PyCFunction)__pyx_pw_7aiohttp_12_http_writer_1_serialize_headers, METH_VARARGS|METH_KEYWORDS, 0};
  2102. static PyObject *__pyx_pw_7aiohttp_12_http_writer_1_serialize_headers(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  2103. PyObject *__pyx_v_status_line = 0;
  2104. PyObject *__pyx_v_headers = 0;
  2105. PyObject *__pyx_r = 0;
  2106. __Pyx_RefNannyDeclarations
  2107. __Pyx_RefNannySetupContext("_serialize_headers (wrapper)", 0);
  2108. {
  2109. static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_status_line,&__pyx_n_s_headers,0};
  2110. PyObject* values[2] = {0,0};
  2111. if (unlikely(__pyx_kwds)) {
  2112. Py_ssize_t kw_args;
  2113. const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
  2114. switch (pos_args) {
  2115. case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  2116. CYTHON_FALLTHROUGH;
  2117. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  2118. CYTHON_FALLTHROUGH;
  2119. case 0: break;
  2120. default: goto __pyx_L5_argtuple_error;
  2121. }
  2122. kw_args = PyDict_Size(__pyx_kwds);
  2123. switch (pos_args) {
  2124. case 0:
  2125. if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_status_line)) != 0)) kw_args--;
  2126. else goto __pyx_L5_argtuple_error;
  2127. CYTHON_FALLTHROUGH;
  2128. case 1:
  2129. if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_headers)) != 0)) kw_args--;
  2130. else {
  2131. __Pyx_RaiseArgtupleInvalid("_serialize_headers", 1, 2, 2, 1); __PYX_ERR(0, 115, __pyx_L3_error)
  2132. }
  2133. }
  2134. if (unlikely(kw_args > 0)) {
  2135. if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_serialize_headers") < 0)) __PYX_ERR(0, 115, __pyx_L3_error)
  2136. }
  2137. } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
  2138. goto __pyx_L5_argtuple_error;
  2139. } else {
  2140. values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  2141. values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  2142. }
  2143. __pyx_v_status_line = ((PyObject*)values[0]);
  2144. __pyx_v_headers = values[1];
  2145. }
  2146. goto __pyx_L4_argument_unpacking_done;
  2147. __pyx_L5_argtuple_error:;
  2148. __Pyx_RaiseArgtupleInvalid("_serialize_headers", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 115, __pyx_L3_error)
  2149. __pyx_L3_error:;
  2150. __Pyx_AddTraceback("aiohttp._http_writer._serialize_headers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2151. __Pyx_RefNannyFinishContext();
  2152. return NULL;
  2153. __pyx_L4_argument_unpacking_done:;
  2154. if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_status_line), (&PyString_Type), 1, "status_line", 1))) __PYX_ERR(0, 115, __pyx_L1_error)
  2155. __pyx_r = __pyx_pf_7aiohttp_12_http_writer__serialize_headers(__pyx_self, __pyx_v_status_line, __pyx_v_headers);
  2156. /* function exit code */
  2157. goto __pyx_L0;
  2158. __pyx_L1_error:;
  2159. __pyx_r = NULL;
  2160. __pyx_L0:;
  2161. __Pyx_RefNannyFinishContext();
  2162. return __pyx_r;
  2163. }
  2164. static PyObject *__pyx_pf_7aiohttp_12_http_writer__serialize_headers(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_status_line, PyObject *__pyx_v_headers) {
  2165. struct __pyx_t_7aiohttp_12_http_writer_Writer __pyx_v_writer;
  2166. PyObject *__pyx_v_key = 0;
  2167. PyObject *__pyx_v_val = 0;
  2168. PyObject *__pyx_r = NULL;
  2169. __Pyx_RefNannyDeclarations
  2170. int __pyx_t_1;
  2171. PyObject *__pyx_t_2 = NULL;
  2172. PyObject *__pyx_t_3 = NULL;
  2173. PyObject *__pyx_t_4 = NULL;
  2174. Py_ssize_t __pyx_t_5;
  2175. PyObject *(*__pyx_t_6)(PyObject *);
  2176. PyObject *__pyx_t_7 = NULL;
  2177. PyObject *__pyx_t_8 = NULL;
  2178. PyObject *(*__pyx_t_9)(PyObject *);
  2179. int __pyx_t_10;
  2180. int __pyx_t_11;
  2181. char const *__pyx_t_12;
  2182. PyObject *__pyx_t_13 = NULL;
  2183. PyObject *__pyx_t_14 = NULL;
  2184. PyObject *__pyx_t_15 = NULL;
  2185. PyObject *__pyx_t_16 = NULL;
  2186. PyObject *__pyx_t_17 = NULL;
  2187. PyObject *__pyx_t_18 = NULL;
  2188. __Pyx_RefNannySetupContext("_serialize_headers", 0);
  2189. /* "aiohttp/_http_writer.pyx":121
  2190. * cdef bytes ret
  2191. *
  2192. * _init_writer(&writer) # <<<<<<<<<<<<<<
  2193. *
  2194. * try:
  2195. */
  2196. __pyx_f_7aiohttp_12_http_writer__init_writer((&__pyx_v_writer));
  2197. /* "aiohttp/_http_writer.pyx":123
  2198. * _init_writer(&writer)
  2199. *
  2200. * try: # <<<<<<<<<<<<<<
  2201. * if _write_str(&writer, status_line) < 0:
  2202. * raise
  2203. */
  2204. /*try:*/ {
  2205. /* "aiohttp/_http_writer.pyx":124
  2206. *
  2207. * try:
  2208. * if _write_str(&writer, status_line) < 0: # <<<<<<<<<<<<<<
  2209. * raise
  2210. * if _write_byte(&writer, '\r') < 0:
  2211. */
  2212. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_str((&__pyx_v_writer), __pyx_v_status_line) < 0) != 0);
  2213. if (unlikely(__pyx_t_1)) {
  2214. /* "aiohttp/_http_writer.pyx":125
  2215. * try:
  2216. * if _write_str(&writer, status_line) < 0:
  2217. * raise # <<<<<<<<<<<<<<
  2218. * if _write_byte(&writer, '\r') < 0:
  2219. * raise
  2220. */
  2221. __Pyx_ReraiseException(); __PYX_ERR(0, 125, __pyx_L4_error)
  2222. /* "aiohttp/_http_writer.pyx":124
  2223. *
  2224. * try:
  2225. * if _write_str(&writer, status_line) < 0: # <<<<<<<<<<<<<<
  2226. * raise
  2227. * if _write_byte(&writer, '\r') < 0:
  2228. */
  2229. }
  2230. /* "aiohttp/_http_writer.pyx":126
  2231. * if _write_str(&writer, status_line) < 0:
  2232. * raise
  2233. * if _write_byte(&writer, '\r') < 0: # <<<<<<<<<<<<<<
  2234. * raise
  2235. * if _write_byte(&writer, '\n') < 0:
  2236. */
  2237. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), '\r') < 0) != 0);
  2238. if (unlikely(__pyx_t_1)) {
  2239. /* "aiohttp/_http_writer.pyx":127
  2240. * raise
  2241. * if _write_byte(&writer, '\r') < 0:
  2242. * raise # <<<<<<<<<<<<<<
  2243. * if _write_byte(&writer, '\n') < 0:
  2244. * raise
  2245. */
  2246. __Pyx_ReraiseException(); __PYX_ERR(0, 127, __pyx_L4_error)
  2247. /* "aiohttp/_http_writer.pyx":126
  2248. * if _write_str(&writer, status_line) < 0:
  2249. * raise
  2250. * if _write_byte(&writer, '\r') < 0: # <<<<<<<<<<<<<<
  2251. * raise
  2252. * if _write_byte(&writer, '\n') < 0:
  2253. */
  2254. }
  2255. /* "aiohttp/_http_writer.pyx":128
  2256. * if _write_byte(&writer, '\r') < 0:
  2257. * raise
  2258. * if _write_byte(&writer, '\n') < 0: # <<<<<<<<<<<<<<
  2259. * raise
  2260. *
  2261. */
  2262. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), '\n') < 0) != 0);
  2263. if (unlikely(__pyx_t_1)) {
  2264. /* "aiohttp/_http_writer.pyx":129
  2265. * raise
  2266. * if _write_byte(&writer, '\n') < 0:
  2267. * raise # <<<<<<<<<<<<<<
  2268. *
  2269. * for key, val in headers.items():
  2270. */
  2271. __Pyx_ReraiseException(); __PYX_ERR(0, 129, __pyx_L4_error)
  2272. /* "aiohttp/_http_writer.pyx":128
  2273. * if _write_byte(&writer, '\r') < 0:
  2274. * raise
  2275. * if _write_byte(&writer, '\n') < 0: # <<<<<<<<<<<<<<
  2276. * raise
  2277. *
  2278. */
  2279. }
  2280. /* "aiohttp/_http_writer.pyx":131
  2281. * raise
  2282. *
  2283. * for key, val in headers.items(): # <<<<<<<<<<<<<<
  2284. * if _write_str(&writer, to_str(key)) < 0:
  2285. * raise
  2286. */
  2287. __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_headers, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 131, __pyx_L4_error)
  2288. __Pyx_GOTREF(__pyx_t_3);
  2289. __pyx_t_4 = NULL;
  2290. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
  2291. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  2292. if (likely(__pyx_t_4)) {
  2293. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  2294. __Pyx_INCREF(__pyx_t_4);
  2295. __Pyx_INCREF(function);
  2296. __Pyx_DECREF_SET(__pyx_t_3, function);
  2297. }
  2298. }
  2299. if (__pyx_t_4) {
  2300. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L4_error)
  2301. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2302. } else {
  2303. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L4_error)
  2304. }
  2305. __Pyx_GOTREF(__pyx_t_2);
  2306. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2307. if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
  2308. __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
  2309. __pyx_t_6 = NULL;
  2310. } else {
  2311. __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 131, __pyx_L4_error)
  2312. __Pyx_GOTREF(__pyx_t_3);
  2313. __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 131, __pyx_L4_error)
  2314. }
  2315. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2316. for (;;) {
  2317. if (likely(!__pyx_t_6)) {
  2318. if (likely(PyList_CheckExact(__pyx_t_3))) {
  2319. if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
  2320. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  2321. __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 131, __pyx_L4_error)
  2322. #else
  2323. __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L4_error)
  2324. __Pyx_GOTREF(__pyx_t_2);
  2325. #endif
  2326. } else {
  2327. if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
  2328. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  2329. __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 131, __pyx_L4_error)
  2330. #else
  2331. __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L4_error)
  2332. __Pyx_GOTREF(__pyx_t_2);
  2333. #endif
  2334. }
  2335. } else {
  2336. __pyx_t_2 = __pyx_t_6(__pyx_t_3);
  2337. if (unlikely(!__pyx_t_2)) {
  2338. PyObject* exc_type = PyErr_Occurred();
  2339. if (exc_type) {
  2340. if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
  2341. else __PYX_ERR(0, 131, __pyx_L4_error)
  2342. }
  2343. break;
  2344. }
  2345. __Pyx_GOTREF(__pyx_t_2);
  2346. }
  2347. if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
  2348. PyObject* sequence = __pyx_t_2;
  2349. Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
  2350. if (unlikely(size != 2)) {
  2351. if (size > 2) __Pyx_RaiseTooManyValuesError(2);
  2352. else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
  2353. __PYX_ERR(0, 131, __pyx_L4_error)
  2354. }
  2355. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  2356. if (likely(PyTuple_CheckExact(sequence))) {
  2357. __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0);
  2358. __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1);
  2359. } else {
  2360. __pyx_t_4 = PyList_GET_ITEM(sequence, 0);
  2361. __pyx_t_7 = PyList_GET_ITEM(sequence, 1);
  2362. }
  2363. __Pyx_INCREF(__pyx_t_4);
  2364. __Pyx_INCREF(__pyx_t_7);
  2365. #else
  2366. __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 131, __pyx_L4_error)
  2367. __Pyx_GOTREF(__pyx_t_4);
  2368. __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 131, __pyx_L4_error)
  2369. __Pyx_GOTREF(__pyx_t_7);
  2370. #endif
  2371. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2372. } else {
  2373. Py_ssize_t index = -1;
  2374. __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 131, __pyx_L4_error)
  2375. __Pyx_GOTREF(__pyx_t_8);
  2376. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2377. __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
  2378. index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L11_unpacking_failed;
  2379. __Pyx_GOTREF(__pyx_t_4);
  2380. index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed;
  2381. __Pyx_GOTREF(__pyx_t_7);
  2382. if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 131, __pyx_L4_error)
  2383. __pyx_t_9 = NULL;
  2384. __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  2385. goto __pyx_L12_unpacking_done;
  2386. __pyx_L11_unpacking_failed:;
  2387. __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  2388. __pyx_t_9 = NULL;
  2389. if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  2390. __PYX_ERR(0, 131, __pyx_L4_error)
  2391. __pyx_L12_unpacking_done:;
  2392. }
  2393. __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_4);
  2394. __pyx_t_4 = 0;
  2395. __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_7);
  2396. __pyx_t_7 = 0;
  2397. /* "aiohttp/_http_writer.pyx":132
  2398. *
  2399. * for key, val in headers.items():
  2400. * if _write_str(&writer, to_str(key)) < 0: # <<<<<<<<<<<<<<
  2401. * raise
  2402. * if _write_byte(&writer, ':') < 0:
  2403. */
  2404. __pyx_t_2 = __pyx_f_7aiohttp_12_http_writer_to_str(__pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 132, __pyx_L4_error)
  2405. __Pyx_GOTREF(__pyx_t_2);
  2406. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_str((&__pyx_v_writer), ((PyObject*)__pyx_t_2)) < 0) != 0);
  2407. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2408. if (unlikely(__pyx_t_1)) {
  2409. /* "aiohttp/_http_writer.pyx":133
  2410. * for key, val in headers.items():
  2411. * if _write_str(&writer, to_str(key)) < 0:
  2412. * raise # <<<<<<<<<<<<<<
  2413. * if _write_byte(&writer, ':') < 0:
  2414. * raise
  2415. */
  2416. __Pyx_ReraiseException(); __PYX_ERR(0, 133, __pyx_L4_error)
  2417. /* "aiohttp/_http_writer.pyx":132
  2418. *
  2419. * for key, val in headers.items():
  2420. * if _write_str(&writer, to_str(key)) < 0: # <<<<<<<<<<<<<<
  2421. * raise
  2422. * if _write_byte(&writer, ':') < 0:
  2423. */
  2424. }
  2425. /* "aiohttp/_http_writer.pyx":134
  2426. * if _write_str(&writer, to_str(key)) < 0:
  2427. * raise
  2428. * if _write_byte(&writer, ':') < 0: # <<<<<<<<<<<<<<
  2429. * raise
  2430. * if _write_byte(&writer, ' ') < 0:
  2431. */
  2432. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), ':') < 0) != 0);
  2433. if (unlikely(__pyx_t_1)) {
  2434. /* "aiohttp/_http_writer.pyx":135
  2435. * raise
  2436. * if _write_byte(&writer, ':') < 0:
  2437. * raise # <<<<<<<<<<<<<<
  2438. * if _write_byte(&writer, ' ') < 0:
  2439. * raise
  2440. */
  2441. __Pyx_ReraiseException(); __PYX_ERR(0, 135, __pyx_L4_error)
  2442. /* "aiohttp/_http_writer.pyx":134
  2443. * if _write_str(&writer, to_str(key)) < 0:
  2444. * raise
  2445. * if _write_byte(&writer, ':') < 0: # <<<<<<<<<<<<<<
  2446. * raise
  2447. * if _write_byte(&writer, ' ') < 0:
  2448. */
  2449. }
  2450. /* "aiohttp/_http_writer.pyx":136
  2451. * if _write_byte(&writer, ':') < 0:
  2452. * raise
  2453. * if _write_byte(&writer, ' ') < 0: # <<<<<<<<<<<<<<
  2454. * raise
  2455. * if _write_str(&writer, to_str(val)) < 0:
  2456. */
  2457. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), ' ') < 0) != 0);
  2458. if (unlikely(__pyx_t_1)) {
  2459. /* "aiohttp/_http_writer.pyx":137
  2460. * raise
  2461. * if _write_byte(&writer, ' ') < 0:
  2462. * raise # <<<<<<<<<<<<<<
  2463. * if _write_str(&writer, to_str(val)) < 0:
  2464. * raise
  2465. */
  2466. __Pyx_ReraiseException(); __PYX_ERR(0, 137, __pyx_L4_error)
  2467. /* "aiohttp/_http_writer.pyx":136
  2468. * if _write_byte(&writer, ':') < 0:
  2469. * raise
  2470. * if _write_byte(&writer, ' ') < 0: # <<<<<<<<<<<<<<
  2471. * raise
  2472. * if _write_str(&writer, to_str(val)) < 0:
  2473. */
  2474. }
  2475. /* "aiohttp/_http_writer.pyx":138
  2476. * if _write_byte(&writer, ' ') < 0:
  2477. * raise
  2478. * if _write_str(&writer, to_str(val)) < 0: # <<<<<<<<<<<<<<
  2479. * raise
  2480. * if _write_byte(&writer, '\r') < 0:
  2481. */
  2482. __pyx_t_2 = __pyx_f_7aiohttp_12_http_writer_to_str(__pyx_v_val); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L4_error)
  2483. __Pyx_GOTREF(__pyx_t_2);
  2484. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_str((&__pyx_v_writer), ((PyObject*)__pyx_t_2)) < 0) != 0);
  2485. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2486. if (unlikely(__pyx_t_1)) {
  2487. /* "aiohttp/_http_writer.pyx":139
  2488. * raise
  2489. * if _write_str(&writer, to_str(val)) < 0:
  2490. * raise # <<<<<<<<<<<<<<
  2491. * if _write_byte(&writer, '\r') < 0:
  2492. * raise
  2493. */
  2494. __Pyx_ReraiseException(); __PYX_ERR(0, 139, __pyx_L4_error)
  2495. /* "aiohttp/_http_writer.pyx":138
  2496. * if _write_byte(&writer, ' ') < 0:
  2497. * raise
  2498. * if _write_str(&writer, to_str(val)) < 0: # <<<<<<<<<<<<<<
  2499. * raise
  2500. * if _write_byte(&writer, '\r') < 0:
  2501. */
  2502. }
  2503. /* "aiohttp/_http_writer.pyx":140
  2504. * if _write_str(&writer, to_str(val)) < 0:
  2505. * raise
  2506. * if _write_byte(&writer, '\r') < 0: # <<<<<<<<<<<<<<
  2507. * raise
  2508. * if _write_byte(&writer, '\n') < 0:
  2509. */
  2510. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), '\r') < 0) != 0);
  2511. if (unlikely(__pyx_t_1)) {
  2512. /* "aiohttp/_http_writer.pyx":141
  2513. * raise
  2514. * if _write_byte(&writer, '\r') < 0:
  2515. * raise # <<<<<<<<<<<<<<
  2516. * if _write_byte(&writer, '\n') < 0:
  2517. * raise
  2518. */
  2519. __Pyx_ReraiseException(); __PYX_ERR(0, 141, __pyx_L4_error)
  2520. /* "aiohttp/_http_writer.pyx":140
  2521. * if _write_str(&writer, to_str(val)) < 0:
  2522. * raise
  2523. * if _write_byte(&writer, '\r') < 0: # <<<<<<<<<<<<<<
  2524. * raise
  2525. * if _write_byte(&writer, '\n') < 0:
  2526. */
  2527. }
  2528. /* "aiohttp/_http_writer.pyx":142
  2529. * if _write_byte(&writer, '\r') < 0:
  2530. * raise
  2531. * if _write_byte(&writer, '\n') < 0: # <<<<<<<<<<<<<<
  2532. * raise
  2533. *
  2534. */
  2535. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), '\n') < 0) != 0);
  2536. if (unlikely(__pyx_t_1)) {
  2537. /* "aiohttp/_http_writer.pyx":143
  2538. * raise
  2539. * if _write_byte(&writer, '\n') < 0:
  2540. * raise # <<<<<<<<<<<<<<
  2541. *
  2542. * if _write_byte(&writer, '\r') < 0:
  2543. */
  2544. __Pyx_ReraiseException(); __PYX_ERR(0, 143, __pyx_L4_error)
  2545. /* "aiohttp/_http_writer.pyx":142
  2546. * if _write_byte(&writer, '\r') < 0:
  2547. * raise
  2548. * if _write_byte(&writer, '\n') < 0: # <<<<<<<<<<<<<<
  2549. * raise
  2550. *
  2551. */
  2552. }
  2553. /* "aiohttp/_http_writer.pyx":131
  2554. * raise
  2555. *
  2556. * for key, val in headers.items(): # <<<<<<<<<<<<<<
  2557. * if _write_str(&writer, to_str(key)) < 0:
  2558. * raise
  2559. */
  2560. }
  2561. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2562. /* "aiohttp/_http_writer.pyx":145
  2563. * raise
  2564. *
  2565. * if _write_byte(&writer, '\r') < 0: # <<<<<<<<<<<<<<
  2566. * raise
  2567. * if _write_byte(&writer, '\n') < 0:
  2568. */
  2569. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), '\r') < 0) != 0);
  2570. if (unlikely(__pyx_t_1)) {
  2571. /* "aiohttp/_http_writer.pyx":146
  2572. *
  2573. * if _write_byte(&writer, '\r') < 0:
  2574. * raise # <<<<<<<<<<<<<<
  2575. * if _write_byte(&writer, '\n') < 0:
  2576. * raise
  2577. */
  2578. __Pyx_ReraiseException(); __PYX_ERR(0, 146, __pyx_L4_error)
  2579. /* "aiohttp/_http_writer.pyx":145
  2580. * raise
  2581. *
  2582. * if _write_byte(&writer, '\r') < 0: # <<<<<<<<<<<<<<
  2583. * raise
  2584. * if _write_byte(&writer, '\n') < 0:
  2585. */
  2586. }
  2587. /* "aiohttp/_http_writer.pyx":147
  2588. * if _write_byte(&writer, '\r') < 0:
  2589. * raise
  2590. * if _write_byte(&writer, '\n') < 0: # <<<<<<<<<<<<<<
  2591. * raise
  2592. *
  2593. */
  2594. __pyx_t_1 = ((__pyx_f_7aiohttp_12_http_writer__write_byte((&__pyx_v_writer), '\n') < 0) != 0);
  2595. if (unlikely(__pyx_t_1)) {
  2596. /* "aiohttp/_http_writer.pyx":148
  2597. * raise
  2598. * if _write_byte(&writer, '\n') < 0:
  2599. * raise # <<<<<<<<<<<<<<
  2600. *
  2601. * return PyBytes_FromStringAndSize(writer.buf, writer.pos)
  2602. */
  2603. __Pyx_ReraiseException(); __PYX_ERR(0, 148, __pyx_L4_error)
  2604. /* "aiohttp/_http_writer.pyx":147
  2605. * if _write_byte(&writer, '\r') < 0:
  2606. * raise
  2607. * if _write_byte(&writer, '\n') < 0: # <<<<<<<<<<<<<<
  2608. * raise
  2609. *
  2610. */
  2611. }
  2612. /* "aiohttp/_http_writer.pyx":150
  2613. * raise
  2614. *
  2615. * return PyBytes_FromStringAndSize(writer.buf, writer.pos) # <<<<<<<<<<<<<<
  2616. * finally:
  2617. * _release_writer(&writer)
  2618. */
  2619. __Pyx_XDECREF(__pyx_r);
  2620. __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_writer.buf, __pyx_v_writer.pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 150, __pyx_L4_error)
  2621. __Pyx_GOTREF(__pyx_t_3);
  2622. __pyx_r = __pyx_t_3;
  2623. __pyx_t_3 = 0;
  2624. goto __pyx_L3_return;
  2625. }
  2626. /* "aiohttp/_http_writer.pyx":152
  2627. * return PyBytes_FromStringAndSize(writer.buf, writer.pos)
  2628. * finally:
  2629. * _release_writer(&writer) # <<<<<<<<<<<<<<
  2630. */
  2631. /*finally:*/ {
  2632. __pyx_L4_error:;
  2633. /*exception exit:*/{
  2634. __Pyx_PyThreadState_declare
  2635. __Pyx_PyThreadState_assign
  2636. __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0;
  2637. __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  2638. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2639. __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  2640. __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  2641. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  2642. if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
  2643. if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15) < 0)) __Pyx_ErrFetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
  2644. __Pyx_XGOTREF(__pyx_t_13);
  2645. __Pyx_XGOTREF(__pyx_t_14);
  2646. __Pyx_XGOTREF(__pyx_t_15);
  2647. __Pyx_XGOTREF(__pyx_t_16);
  2648. __Pyx_XGOTREF(__pyx_t_17);
  2649. __Pyx_XGOTREF(__pyx_t_18);
  2650. __pyx_t_10 = __pyx_lineno; __pyx_t_11 = __pyx_clineno; __pyx_t_12 = __pyx_filename;
  2651. {
  2652. __pyx_f_7aiohttp_12_http_writer__release_writer((&__pyx_v_writer));
  2653. }
  2654. if (PY_MAJOR_VERSION >= 3) {
  2655. __Pyx_XGIVEREF(__pyx_t_16);
  2656. __Pyx_XGIVEREF(__pyx_t_17);
  2657. __Pyx_XGIVEREF(__pyx_t_18);
  2658. __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
  2659. }
  2660. __Pyx_XGIVEREF(__pyx_t_13);
  2661. __Pyx_XGIVEREF(__pyx_t_14);
  2662. __Pyx_XGIVEREF(__pyx_t_15);
  2663. __Pyx_ErrRestore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
  2664. __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0;
  2665. __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_11; __pyx_filename = __pyx_t_12;
  2666. goto __pyx_L1_error;
  2667. }
  2668. __pyx_L3_return: {
  2669. __pyx_t_18 = __pyx_r;
  2670. __pyx_r = 0;
  2671. __pyx_f_7aiohttp_12_http_writer__release_writer((&__pyx_v_writer));
  2672. __pyx_r = __pyx_t_18;
  2673. __pyx_t_18 = 0;
  2674. goto __pyx_L0;
  2675. }
  2676. }
  2677. /* "aiohttp/_http_writer.pyx":115
  2678. *
  2679. *
  2680. * def _serialize_headers(str status_line, headers): # <<<<<<<<<<<<<<
  2681. * cdef Writer writer
  2682. * cdef object key
  2683. */
  2684. /* function exit code */
  2685. __pyx_L1_error:;
  2686. __Pyx_XDECREF(__pyx_t_2);
  2687. __Pyx_XDECREF(__pyx_t_3);
  2688. __Pyx_XDECREF(__pyx_t_4);
  2689. __Pyx_XDECREF(__pyx_t_7);
  2690. __Pyx_XDECREF(__pyx_t_8);
  2691. __Pyx_AddTraceback("aiohttp._http_writer._serialize_headers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2692. __pyx_r = NULL;
  2693. __pyx_L0:;
  2694. __Pyx_XDECREF(__pyx_v_key);
  2695. __Pyx_XDECREF(__pyx_v_val);
  2696. __Pyx_XGIVEREF(__pyx_r);
  2697. __Pyx_RefNannyFinishContext();
  2698. return __pyx_r;
  2699. }
  2700. static PyMethodDef __pyx_methods[] = {
  2701. {0, 0, 0, 0}
  2702. };
  2703. #if PY_MAJOR_VERSION >= 3
  2704. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2705. static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
  2706. static int __pyx_pymod_exec__http_writer(PyObject* module); /*proto*/
  2707. static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  2708. {Py_mod_create, (void*)__pyx_pymod_create},
  2709. {Py_mod_exec, (void*)__pyx_pymod_exec__http_writer},
  2710. {0, NULL}
  2711. };
  2712. #endif
  2713. static struct PyModuleDef __pyx_moduledef = {
  2714. PyModuleDef_HEAD_INIT,
  2715. "_http_writer",
  2716. 0, /* m_doc */
  2717. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2718. 0, /* m_size */
  2719. #else
  2720. -1, /* m_size */
  2721. #endif
  2722. __pyx_methods /* m_methods */,
  2723. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2724. __pyx_moduledef_slots, /* m_slots */
  2725. #else
  2726. NULL, /* m_reload */
  2727. #endif
  2728. NULL, /* m_traverse */
  2729. NULL, /* m_clear */
  2730. NULL /* m_free */
  2731. };
  2732. #endif
  2733. static __Pyx_StringTabEntry __pyx_string_tab[] = {
  2734. {&__pyx_kp_s_Cannot_serialize_non_str_key_r, __pyx_k_Cannot_serialize_non_str_key_r, sizeof(__pyx_k_Cannot_serialize_non_str_key_r), 0, 0, 1, 0},
  2735. {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  2736. {&__pyx_n_s_aiohttp__http_writer, __pyx_k_aiohttp__http_writer, sizeof(__pyx_k_aiohttp__http_writer), 0, 0, 1, 1},
  2737. {&__pyx_kp_s_aiohttp__http_writer_pyx, __pyx_k_aiohttp__http_writer_pyx, sizeof(__pyx_k_aiohttp__http_writer_pyx), 0, 0, 1, 0},
  2738. {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  2739. {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  2740. {&__pyx_n_s_headers, __pyx_k_headers, sizeof(__pyx_k_headers), 0, 0, 1, 1},
  2741. {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  2742. {&__pyx_n_s_istr, __pyx_k_istr, sizeof(__pyx_k_istr), 0, 0, 1, 1},
  2743. {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
  2744. {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
  2745. {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  2746. {&__pyx_n_s_multidict, __pyx_k_multidict, sizeof(__pyx_k_multidict), 0, 0, 1, 1},
  2747. {&__pyx_n_s_ret, __pyx_k_ret, sizeof(__pyx_k_ret), 0, 0, 1, 1},
  2748. {&__pyx_n_s_serialize_headers, __pyx_k_serialize_headers, sizeof(__pyx_k_serialize_headers), 0, 0, 1, 1},
  2749. {&__pyx_n_s_status_line, __pyx_k_status_line, sizeof(__pyx_k_status_line), 0, 0, 1, 1},
  2750. {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  2751. {&__pyx_n_s_val, __pyx_k_val, sizeof(__pyx_k_val), 0, 0, 1, 1},
  2752. {&__pyx_n_s_writer, __pyx_k_writer, sizeof(__pyx_k_writer), 0, 0, 1, 1},
  2753. {0, 0, 0, 0, 0, 0, 0}
  2754. };
  2755. static int __Pyx_InitCachedBuiltins(void) {
  2756. __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 110, __pyx_L1_error)
  2757. return 0;
  2758. __pyx_L1_error:;
  2759. return -1;
  2760. }
  2761. static int __Pyx_InitCachedConstants(void) {
  2762. __Pyx_RefNannyDeclarations
  2763. __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
  2764. /* "aiohttp/_http_writer.pyx":115
  2765. *
  2766. *
  2767. * def _serialize_headers(str status_line, headers): # <<<<<<<<<<<<<<
  2768. * cdef Writer writer
  2769. * cdef object key
  2770. */
  2771. __pyx_tuple_ = PyTuple_Pack(6, __pyx_n_s_status_line, __pyx_n_s_headers, __pyx_n_s_writer, __pyx_n_s_key, __pyx_n_s_val, __pyx_n_s_ret); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 115, __pyx_L1_error)
  2772. __Pyx_GOTREF(__pyx_tuple_);
  2773. __Pyx_GIVEREF(__pyx_tuple_);
  2774. __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(2, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple_, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_aiohttp__http_writer_pyx, __pyx_n_s_serialize_headers, 115, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 115, __pyx_L1_error)
  2775. __Pyx_RefNannyFinishContext();
  2776. return 0;
  2777. __pyx_L1_error:;
  2778. __Pyx_RefNannyFinishContext();
  2779. return -1;
  2780. }
  2781. static int __Pyx_InitGlobals(void) {
  2782. if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  2783. return 0;
  2784. __pyx_L1_error:;
  2785. return -1;
  2786. }
  2787. static int __Pyx_modinit_global_init_code(void); /*proto*/
  2788. static int __Pyx_modinit_variable_export_code(void); /*proto*/
  2789. static int __Pyx_modinit_function_export_code(void); /*proto*/
  2790. static int __Pyx_modinit_type_init_code(void); /*proto*/
  2791. static int __Pyx_modinit_type_import_code(void); /*proto*/
  2792. static int __Pyx_modinit_variable_import_code(void); /*proto*/
  2793. static int __Pyx_modinit_function_import_code(void); /*proto*/
  2794. static int __Pyx_modinit_global_init_code(void) {
  2795. __Pyx_RefNannyDeclarations
  2796. __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  2797. /*--- Global init code ---*/
  2798. __pyx_v_7aiohttp_12_http_writer__istr = Py_None; Py_INCREF(Py_None);
  2799. __Pyx_RefNannyFinishContext();
  2800. return 0;
  2801. }
  2802. static int __Pyx_modinit_variable_export_code(void) {
  2803. __Pyx_RefNannyDeclarations
  2804. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  2805. /*--- Variable export code ---*/
  2806. __Pyx_RefNannyFinishContext();
  2807. return 0;
  2808. }
  2809. static int __Pyx_modinit_function_export_code(void) {
  2810. __Pyx_RefNannyDeclarations
  2811. __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  2812. /*--- Function export code ---*/
  2813. __Pyx_RefNannyFinishContext();
  2814. return 0;
  2815. }
  2816. static int __Pyx_modinit_type_init_code(void) {
  2817. __Pyx_RefNannyDeclarations
  2818. __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  2819. /*--- Type init code ---*/
  2820. __Pyx_RefNannyFinishContext();
  2821. return 0;
  2822. }
  2823. static int __Pyx_modinit_type_import_code(void) {
  2824. __Pyx_RefNannyDeclarations
  2825. __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  2826. /*--- Type import code ---*/
  2827. __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type",
  2828. #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  2829. sizeof(PyTypeObject),
  2830. #else
  2831. sizeof(PyHeapTypeObject),
  2832. #endif
  2833. 0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(1, 9, __pyx_L1_error)
  2834. __Pyx_RefNannyFinishContext();
  2835. return 0;
  2836. __pyx_L1_error:;
  2837. __Pyx_RefNannyFinishContext();
  2838. return -1;
  2839. }
  2840. static int __Pyx_modinit_variable_import_code(void) {
  2841. __Pyx_RefNannyDeclarations
  2842. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  2843. /*--- Variable import code ---*/
  2844. __Pyx_RefNannyFinishContext();
  2845. return 0;
  2846. }
  2847. static int __Pyx_modinit_function_import_code(void) {
  2848. __Pyx_RefNannyDeclarations
  2849. __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  2850. /*--- Function import code ---*/
  2851. __Pyx_RefNannyFinishContext();
  2852. return 0;
  2853. }
  2854. #if PY_MAJOR_VERSION < 3
  2855. #ifdef CYTHON_NO_PYINIT_EXPORT
  2856. #define __Pyx_PyMODINIT_FUNC void
  2857. #else
  2858. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  2859. #endif
  2860. #else
  2861. #ifdef CYTHON_NO_PYINIT_EXPORT
  2862. #define __Pyx_PyMODINIT_FUNC PyObject *
  2863. #else
  2864. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  2865. #endif
  2866. #endif
  2867. #ifndef CYTHON_SMALL_CODE
  2868. #if defined(__clang__)
  2869. #define CYTHON_SMALL_CODE
  2870. #elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
  2871. #define CYTHON_SMALL_CODE __attribute__((cold))
  2872. #else
  2873. #define CYTHON_SMALL_CODE
  2874. #endif
  2875. #endif
  2876. #if PY_MAJOR_VERSION < 3
  2877. __Pyx_PyMODINIT_FUNC init_http_writer(void) CYTHON_SMALL_CODE; /*proto*/
  2878. __Pyx_PyMODINIT_FUNC init_http_writer(void)
  2879. #else
  2880. __Pyx_PyMODINIT_FUNC PyInit__http_writer(void) CYTHON_SMALL_CODE; /*proto*/
  2881. __Pyx_PyMODINIT_FUNC PyInit__http_writer(void)
  2882. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2883. {
  2884. return PyModuleDef_Init(&__pyx_moduledef);
  2885. }
  2886. static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
  2887. PyObject *value = PyObject_GetAttrString(spec, from_name);
  2888. int result = 0;
  2889. if (likely(value)) {
  2890. result = PyDict_SetItemString(moddict, to_name, value);
  2891. Py_DECREF(value);
  2892. } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
  2893. PyErr_Clear();
  2894. } else {
  2895. result = -1;
  2896. }
  2897. return result;
  2898. }
  2899. static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
  2900. PyObject *module = NULL, *moddict, *modname;
  2901. if (__pyx_m)
  2902. return __Pyx_NewRef(__pyx_m);
  2903. modname = PyObject_GetAttrString(spec, "name");
  2904. if (unlikely(!modname)) goto bad;
  2905. module = PyModule_NewObject(modname);
  2906. Py_DECREF(modname);
  2907. if (unlikely(!module)) goto bad;
  2908. moddict = PyModule_GetDict(module);
  2909. if (unlikely(!moddict)) goto bad;
  2910. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
  2911. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
  2912. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
  2913. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
  2914. return module;
  2915. bad:
  2916. Py_XDECREF(module);
  2917. return NULL;
  2918. }
  2919. static int __pyx_pymod_exec__http_writer(PyObject *__pyx_pyinit_module)
  2920. #endif
  2921. #endif
  2922. {
  2923. PyObject *__pyx_t_1 = NULL;
  2924. PyObject *__pyx_t_2 = NULL;
  2925. __Pyx_RefNannyDeclarations
  2926. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2927. if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0;
  2928. #elif PY_MAJOR_VERSION >= 3
  2929. if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  2930. #endif
  2931. #if CYTHON_REFNANNY
  2932. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  2933. if (!__Pyx_RefNanny) {
  2934. PyErr_Clear();
  2935. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  2936. if (!__Pyx_RefNanny)
  2937. Py_FatalError("failed to import 'refnanny' module");
  2938. }
  2939. #endif
  2940. __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit__http_writer(void)", 0);
  2941. if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2942. __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  2943. __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  2944. __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  2945. #ifdef __Pyx_CyFunction_USED
  2946. if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2947. #endif
  2948. #ifdef __Pyx_FusedFunction_USED
  2949. if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2950. #endif
  2951. #ifdef __Pyx_Coroutine_USED
  2952. if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2953. #endif
  2954. #ifdef __Pyx_Generator_USED
  2955. if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2956. #endif
  2957. #ifdef __Pyx_AsyncGen_USED
  2958. if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2959. #endif
  2960. #ifdef __Pyx_StopAsyncIteration_USED
  2961. if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2962. #endif
  2963. /*--- Library function declarations ---*/
  2964. /*--- Threads initialization code ---*/
  2965. #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  2966. #ifdef WITH_THREAD /* Python build with threading support? */
  2967. PyEval_InitThreads();
  2968. #endif
  2969. #endif
  2970. /*--- Module creation code ---*/
  2971. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2972. __pyx_m = __pyx_pyinit_module;
  2973. Py_INCREF(__pyx_m);
  2974. #else
  2975. #if PY_MAJOR_VERSION < 3
  2976. __pyx_m = Py_InitModule4("_http_writer", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  2977. #else
  2978. __pyx_m = PyModule_Create(&__pyx_moduledef);
  2979. #endif
  2980. if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  2981. #endif
  2982. __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  2983. Py_INCREF(__pyx_d);
  2984. __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  2985. __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  2986. #if CYTHON_COMPILING_IN_PYPY
  2987. Py_INCREF(__pyx_b);
  2988. #endif
  2989. if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  2990. /*--- Initialize various global constants etc. ---*/
  2991. if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2992. #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  2993. if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2994. #endif
  2995. if (__pyx_module_is_main_aiohttp___http_writer) {
  2996. if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2997. }
  2998. #if PY_MAJOR_VERSION >= 3
  2999. {
  3000. PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
  3001. if (!PyDict_GetItemString(modules, "aiohttp._http_writer")) {
  3002. if (unlikely(PyDict_SetItemString(modules, "aiohttp._http_writer", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  3003. }
  3004. }
  3005. #endif
  3006. /*--- Builtin init code ---*/
  3007. if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  3008. /*--- Constants init code ---*/
  3009. if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  3010. /*--- Global type/function init code ---*/
  3011. (void)__Pyx_modinit_global_init_code();
  3012. (void)__Pyx_modinit_variable_export_code();
  3013. (void)__Pyx_modinit_function_export_code();
  3014. (void)__Pyx_modinit_type_init_code();
  3015. if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
  3016. (void)__Pyx_modinit_variable_import_code();
  3017. (void)__Pyx_modinit_function_import_code();
  3018. /*--- Execution code ---*/
  3019. #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  3020. if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  3021. #endif
  3022. /* "aiohttp/_http_writer.pyx":9
  3023. * from cpython.object cimport PyObject_Str
  3024. *
  3025. * from multidict import istr # <<<<<<<<<<<<<<
  3026. *
  3027. * DEF BUF_SIZE = 16 * 1024 # 16KiB
  3028. */
  3029. __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
  3030. __Pyx_GOTREF(__pyx_t_1);
  3031. __Pyx_INCREF(__pyx_n_s_istr);
  3032. __Pyx_GIVEREF(__pyx_n_s_istr);
  3033. PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_istr);
  3034. __pyx_t_2 = __Pyx_Import(__pyx_n_s_multidict, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
  3035. __Pyx_GOTREF(__pyx_t_2);
  3036. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3037. __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_istr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
  3038. __Pyx_GOTREF(__pyx_t_1);
  3039. if (PyDict_SetItem(__pyx_d, __pyx_n_s_istr, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  3040. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3041. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3042. /* "aiohttp/_http_writer.pyx":14
  3043. * cdef char BUFFER[BUF_SIZE]
  3044. *
  3045. * cdef object _istr = istr # <<<<<<<<<<<<<<
  3046. *
  3047. *
  3048. */
  3049. __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_istr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error)
  3050. __Pyx_GOTREF(__pyx_t_2);
  3051. __Pyx_XGOTREF(__pyx_v_7aiohttp_12_http_writer__istr);
  3052. __Pyx_DECREF_SET(__pyx_v_7aiohttp_12_http_writer__istr, __pyx_t_2);
  3053. __Pyx_GIVEREF(__pyx_t_2);
  3054. __pyx_t_2 = 0;
  3055. /* "aiohttp/_http_writer.pyx":115
  3056. *
  3057. *
  3058. * def _serialize_headers(str status_line, headers): # <<<<<<<<<<<<<<
  3059. * cdef Writer writer
  3060. * cdef object key
  3061. */
  3062. __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7aiohttp_12_http_writer_1_serialize_headers, NULL, __pyx_n_s_aiohttp__http_writer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error)
  3063. __Pyx_GOTREF(__pyx_t_2);
  3064. if (PyDict_SetItem(__pyx_d, __pyx_n_s_serialize_headers, __pyx_t_2) < 0) __PYX_ERR(0, 115, __pyx_L1_error)
  3065. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3066. /* "aiohttp/_http_writer.pyx":1
  3067. * from libc.stdint cimport uint8_t, uint64_t # <<<<<<<<<<<<<<
  3068. * from libc.string cimport memcpy
  3069. * from cpython.exc cimport PyErr_NoMemory
  3070. */
  3071. __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  3072. __Pyx_GOTREF(__pyx_t_2);
  3073. if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  3074. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3075. /*--- Wrapped vars code ---*/
  3076. goto __pyx_L0;
  3077. __pyx_L1_error:;
  3078. __Pyx_XDECREF(__pyx_t_1);
  3079. __Pyx_XDECREF(__pyx_t_2);
  3080. if (__pyx_m) {
  3081. if (__pyx_d) {
  3082. __Pyx_AddTraceback("init aiohttp._http_writer", 0, __pyx_lineno, __pyx_filename);
  3083. }
  3084. Py_DECREF(__pyx_m); __pyx_m = 0;
  3085. } else if (!PyErr_Occurred()) {
  3086. PyErr_SetString(PyExc_ImportError, "init aiohttp._http_writer");
  3087. }
  3088. __pyx_L0:;
  3089. __Pyx_RefNannyFinishContext();
  3090. #if CYTHON_PEP489_MULTI_PHASE_INIT
  3091. return (__pyx_m != NULL) ? 0 : -1;
  3092. #elif PY_MAJOR_VERSION >= 3
  3093. return __pyx_m;
  3094. #else
  3095. return;
  3096. #endif
  3097. }
  3098. /* --- Runtime support code --- */
  3099. /* Refnanny */
  3100. #if CYTHON_REFNANNY
  3101. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
  3102. PyObject *m = NULL, *p = NULL;
  3103. void *r = NULL;
  3104. m = PyImport_ImportModule((char *)modname);
  3105. if (!m) goto end;
  3106. p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
  3107. if (!p) goto end;
  3108. r = PyLong_AsVoidPtr(p);
  3109. end:
  3110. Py_XDECREF(p);
  3111. Py_XDECREF(m);
  3112. return (__Pyx_RefNannyAPIStruct *)r;
  3113. }
  3114. #endif
  3115. /* PyObjectGetAttrStr */
  3116. #if CYTHON_USE_TYPE_SLOTS
  3117. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
  3118. PyTypeObject* tp = Py_TYPE(obj);
  3119. if (likely(tp->tp_getattro))
  3120. return tp->tp_getattro(obj, attr_name);
  3121. #if PY_MAJOR_VERSION < 3
  3122. if (likely(tp->tp_getattr))
  3123. return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
  3124. #endif
  3125. return PyObject_GetAttr(obj, attr_name);
  3126. }
  3127. #endif
  3128. /* GetBuiltinName */
  3129. static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
  3130. PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
  3131. if (unlikely(!result)) {
  3132. PyErr_Format(PyExc_NameError,
  3133. #if PY_MAJOR_VERSION >= 3
  3134. "name '%U' is not defined", name);
  3135. #else
  3136. "name '%.200s' is not defined", PyString_AS_STRING(name));
  3137. #endif
  3138. }
  3139. return result;
  3140. }
  3141. /* PyErrFetchRestore */
  3142. #if CYTHON_FAST_THREAD_STATE
  3143. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  3144. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3145. tmp_type = tstate->curexc_type;
  3146. tmp_value = tstate->curexc_value;
  3147. tmp_tb = tstate->curexc_traceback;
  3148. tstate->curexc_type = type;
  3149. tstate->curexc_value = value;
  3150. tstate->curexc_traceback = tb;
  3151. Py_XDECREF(tmp_type);
  3152. Py_XDECREF(tmp_value);
  3153. Py_XDECREF(tmp_tb);
  3154. }
  3155. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  3156. *type = tstate->curexc_type;
  3157. *value = tstate->curexc_value;
  3158. *tb = tstate->curexc_traceback;
  3159. tstate->curexc_type = 0;
  3160. tstate->curexc_value = 0;
  3161. tstate->curexc_traceback = 0;
  3162. }
  3163. #endif
  3164. /* WriteUnraisableException */
  3165. static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
  3166. CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
  3167. int full_traceback, CYTHON_UNUSED int nogil) {
  3168. PyObject *old_exc, *old_val, *old_tb;
  3169. PyObject *ctx;
  3170. __Pyx_PyThreadState_declare
  3171. #ifdef WITH_THREAD
  3172. PyGILState_STATE state;
  3173. if (nogil)
  3174. state = PyGILState_Ensure();
  3175. #ifdef _MSC_VER
  3176. else state = (PyGILState_STATE)-1;
  3177. #endif
  3178. #endif
  3179. __Pyx_PyThreadState_assign
  3180. __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
  3181. if (full_traceback) {
  3182. Py_XINCREF(old_exc);
  3183. Py_XINCREF(old_val);
  3184. Py_XINCREF(old_tb);
  3185. __Pyx_ErrRestore(old_exc, old_val, old_tb);
  3186. PyErr_PrintEx(1);
  3187. }
  3188. #if PY_MAJOR_VERSION < 3
  3189. ctx = PyString_FromString(name);
  3190. #else
  3191. ctx = PyUnicode_FromString(name);
  3192. #endif
  3193. __Pyx_ErrRestore(old_exc, old_val, old_tb);
  3194. if (!ctx) {
  3195. PyErr_WriteUnraisable(Py_None);
  3196. } else {
  3197. PyErr_WriteUnraisable(ctx);
  3198. Py_DECREF(ctx);
  3199. }
  3200. #ifdef WITH_THREAD
  3201. if (nogil)
  3202. PyGILState_Release(state);
  3203. #endif
  3204. }
  3205. /* PyCFunctionFastCall */
  3206. #if CYTHON_FAST_PYCCALL
  3207. static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
  3208. PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
  3209. PyCFunction meth = PyCFunction_GET_FUNCTION(func);
  3210. PyObject *self = PyCFunction_GET_SELF(func);
  3211. int flags = PyCFunction_GET_FLAGS(func);
  3212. assert(PyCFunction_Check(func));
  3213. assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)));
  3214. assert(nargs >= 0);
  3215. assert(nargs == 0 || args != NULL);
  3216. /* _PyCFunction_FastCallDict() must not be called with an exception set,
  3217. because it may clear it (directly or indirectly) and so the
  3218. caller loses its exception */
  3219. assert(!PyErr_Occurred());
  3220. if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
  3221. return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL);
  3222. } else {
  3223. return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs);
  3224. }
  3225. }
  3226. #endif
  3227. /* PyFunctionFastCall */
  3228. #if CYTHON_FAST_PYCALL
  3229. #include "frameobject.h"
  3230. static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
  3231. PyObject *globals) {
  3232. PyFrameObject *f;
  3233. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  3234. PyObject **fastlocals;
  3235. Py_ssize_t i;
  3236. PyObject *result;
  3237. assert(globals != NULL);
  3238. /* XXX Perhaps we should create a specialized
  3239. PyFrame_New() that doesn't take locals, but does
  3240. take builtins without sanity checking them.
  3241. */
  3242. assert(tstate != NULL);
  3243. f = PyFrame_New(tstate, co, globals, NULL);
  3244. if (f == NULL) {
  3245. return NULL;
  3246. }
  3247. fastlocals = f->f_localsplus;
  3248. for (i = 0; i < na; i++) {
  3249. Py_INCREF(*args);
  3250. fastlocals[i] = *args++;
  3251. }
  3252. result = PyEval_EvalFrameEx(f,0);
  3253. ++tstate->recursion_depth;
  3254. Py_DECREF(f);
  3255. --tstate->recursion_depth;
  3256. return result;
  3257. }
  3258. #if 1 || PY_VERSION_HEX < 0x030600B1
  3259. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
  3260. PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
  3261. PyObject *globals = PyFunction_GET_GLOBALS(func);
  3262. PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
  3263. PyObject *closure;
  3264. #if PY_MAJOR_VERSION >= 3
  3265. PyObject *kwdefs;
  3266. #endif
  3267. PyObject *kwtuple, **k;
  3268. PyObject **d;
  3269. Py_ssize_t nd;
  3270. Py_ssize_t nk;
  3271. PyObject *result;
  3272. assert(kwargs == NULL || PyDict_Check(kwargs));
  3273. nk = kwargs ? PyDict_Size(kwargs) : 0;
  3274. if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
  3275. return NULL;
  3276. }
  3277. if (
  3278. #if PY_MAJOR_VERSION >= 3
  3279. co->co_kwonlyargcount == 0 &&
  3280. #endif
  3281. likely(kwargs == NULL || nk == 0) &&
  3282. co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
  3283. if (argdefs == NULL && co->co_argcount == nargs) {
  3284. result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
  3285. goto done;
  3286. }
  3287. else if (nargs == 0 && argdefs != NULL
  3288. && co->co_argcount == Py_SIZE(argdefs)) {
  3289. /* function called with no arguments, but all parameters have
  3290. a default value: use default values as arguments .*/
  3291. args = &PyTuple_GET_ITEM(argdefs, 0);
  3292. result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
  3293. goto done;
  3294. }
  3295. }
  3296. if (kwargs != NULL) {
  3297. Py_ssize_t pos, i;
  3298. kwtuple = PyTuple_New(2 * nk);
  3299. if (kwtuple == NULL) {
  3300. result = NULL;
  3301. goto done;
  3302. }
  3303. k = &PyTuple_GET_ITEM(kwtuple, 0);
  3304. pos = i = 0;
  3305. while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
  3306. Py_INCREF(k[i]);
  3307. Py_INCREF(k[i+1]);
  3308. i += 2;
  3309. }
  3310. nk = i / 2;
  3311. }
  3312. else {
  3313. kwtuple = NULL;
  3314. k = NULL;
  3315. }
  3316. closure = PyFunction_GET_CLOSURE(func);
  3317. #if PY_MAJOR_VERSION >= 3
  3318. kwdefs = PyFunction_GET_KW_DEFAULTS(func);
  3319. #endif
  3320. if (argdefs != NULL) {
  3321. d = &PyTuple_GET_ITEM(argdefs, 0);
  3322. nd = Py_SIZE(argdefs);
  3323. }
  3324. else {
  3325. d = NULL;
  3326. nd = 0;
  3327. }
  3328. #if PY_MAJOR_VERSION >= 3
  3329. result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
  3330. args, nargs,
  3331. k, (int)nk,
  3332. d, (int)nd, kwdefs, closure);
  3333. #else
  3334. result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
  3335. args, nargs,
  3336. k, (int)nk,
  3337. d, (int)nd, closure);
  3338. #endif
  3339. Py_XDECREF(kwtuple);
  3340. done:
  3341. Py_LeaveRecursiveCall();
  3342. return result;
  3343. }
  3344. #endif
  3345. #endif
  3346. /* PyObjectCall */
  3347. #if CYTHON_COMPILING_IN_CPYTHON
  3348. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
  3349. PyObject *result;
  3350. ternaryfunc call = func->ob_type->tp_call;
  3351. if (unlikely(!call))
  3352. return PyObject_Call(func, arg, kw);
  3353. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  3354. return NULL;
  3355. result = (*call)(func, arg, kw);
  3356. Py_LeaveRecursiveCall();
  3357. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  3358. PyErr_SetString(
  3359. PyExc_SystemError,
  3360. "NULL result without error in PyObject_Call");
  3361. }
  3362. return result;
  3363. }
  3364. #endif
  3365. /* PyObjectCallMethO */
  3366. #if CYTHON_COMPILING_IN_CPYTHON
  3367. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
  3368. PyObject *self, *result;
  3369. PyCFunction cfunc;
  3370. cfunc = PyCFunction_GET_FUNCTION(func);
  3371. self = PyCFunction_GET_SELF(func);
  3372. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  3373. return NULL;
  3374. result = cfunc(self, arg);
  3375. Py_LeaveRecursiveCall();
  3376. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  3377. PyErr_SetString(
  3378. PyExc_SystemError,
  3379. "NULL result without error in PyObject_Call");
  3380. }
  3381. return result;
  3382. }
  3383. #endif
  3384. /* PyObjectCallOneArg */
  3385. #if CYTHON_COMPILING_IN_CPYTHON
  3386. static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  3387. PyObject *result;
  3388. PyObject *args = PyTuple_New(1);
  3389. if (unlikely(!args)) return NULL;
  3390. Py_INCREF(arg);
  3391. PyTuple_SET_ITEM(args, 0, arg);
  3392. result = __Pyx_PyObject_Call(func, args, NULL);
  3393. Py_DECREF(args);
  3394. return result;
  3395. }
  3396. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  3397. #if CYTHON_FAST_PYCALL
  3398. if (PyFunction_Check(func)) {
  3399. return __Pyx_PyFunction_FastCall(func, &arg, 1);
  3400. }
  3401. #endif
  3402. if (likely(PyCFunction_Check(func))) {
  3403. if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
  3404. return __Pyx_PyObject_CallMethO(func, arg);
  3405. #if CYTHON_FAST_PYCCALL
  3406. } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
  3407. return __Pyx_PyCFunction_FastCall(func, &arg, 1);
  3408. #endif
  3409. }
  3410. }
  3411. return __Pyx__PyObject_CallOneArg(func, arg);
  3412. }
  3413. #else
  3414. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  3415. PyObject *result;
  3416. PyObject *args = PyTuple_Pack(1, arg);
  3417. if (unlikely(!args)) return NULL;
  3418. result = __Pyx_PyObject_Call(func, args, NULL);
  3419. Py_DECREF(args);
  3420. return result;
  3421. }
  3422. #endif
  3423. /* RaiseException */
  3424. #if PY_MAJOR_VERSION < 3
  3425. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
  3426. CYTHON_UNUSED PyObject *cause) {
  3427. __Pyx_PyThreadState_declare
  3428. Py_XINCREF(type);
  3429. if (!value || value == Py_None)
  3430. value = NULL;
  3431. else
  3432. Py_INCREF(value);
  3433. if (!tb || tb == Py_None)
  3434. tb = NULL;
  3435. else {
  3436. Py_INCREF(tb);
  3437. if (!PyTraceBack_Check(tb)) {
  3438. PyErr_SetString(PyExc_TypeError,
  3439. "raise: arg 3 must be a traceback or None");
  3440. goto raise_error;
  3441. }
  3442. }
  3443. if (PyType_Check(type)) {
  3444. #if CYTHON_COMPILING_IN_PYPY
  3445. if (!value) {
  3446. Py_INCREF(Py_None);
  3447. value = Py_None;
  3448. }
  3449. #endif
  3450. PyErr_NormalizeException(&type, &value, &tb);
  3451. } else {
  3452. if (value) {
  3453. PyErr_SetString(PyExc_TypeError,
  3454. "instance exception may not have a separate value");
  3455. goto raise_error;
  3456. }
  3457. value = type;
  3458. type = (PyObject*) Py_TYPE(type);
  3459. Py_INCREF(type);
  3460. if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
  3461. PyErr_SetString(PyExc_TypeError,
  3462. "raise: exception class must be a subclass of BaseException");
  3463. goto raise_error;
  3464. }
  3465. }
  3466. __Pyx_PyThreadState_assign
  3467. __Pyx_ErrRestore(type, value, tb);
  3468. return;
  3469. raise_error:
  3470. Py_XDECREF(value);
  3471. Py_XDECREF(type);
  3472. Py_XDECREF(tb);
  3473. return;
  3474. }
  3475. #else
  3476. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
  3477. PyObject* owned_instance = NULL;
  3478. if (tb == Py_None) {
  3479. tb = 0;
  3480. } else if (tb && !PyTraceBack_Check(tb)) {
  3481. PyErr_SetString(PyExc_TypeError,
  3482. "raise: arg 3 must be a traceback or None");
  3483. goto bad;
  3484. }
  3485. if (value == Py_None)
  3486. value = 0;
  3487. if (PyExceptionInstance_Check(type)) {
  3488. if (value) {
  3489. PyErr_SetString(PyExc_TypeError,
  3490. "instance exception may not have a separate value");
  3491. goto bad;
  3492. }
  3493. value = type;
  3494. type = (PyObject*) Py_TYPE(value);
  3495. } else if (PyExceptionClass_Check(type)) {
  3496. PyObject *instance_class = NULL;
  3497. if (value && PyExceptionInstance_Check(value)) {
  3498. instance_class = (PyObject*) Py_TYPE(value);
  3499. if (instance_class != type) {
  3500. int is_subclass = PyObject_IsSubclass(instance_class, type);
  3501. if (!is_subclass) {
  3502. instance_class = NULL;
  3503. } else if (unlikely(is_subclass == -1)) {
  3504. goto bad;
  3505. } else {
  3506. type = instance_class;
  3507. }
  3508. }
  3509. }
  3510. if (!instance_class) {
  3511. PyObject *args;
  3512. if (!value)
  3513. args = PyTuple_New(0);
  3514. else if (PyTuple_Check(value)) {
  3515. Py_INCREF(value);
  3516. args = value;
  3517. } else
  3518. args = PyTuple_Pack(1, value);
  3519. if (!args)
  3520. goto bad;
  3521. owned_instance = PyObject_Call(type, args, NULL);
  3522. Py_DECREF(args);
  3523. if (!owned_instance)
  3524. goto bad;
  3525. value = owned_instance;
  3526. if (!PyExceptionInstance_Check(value)) {
  3527. PyErr_Format(PyExc_TypeError,
  3528. "calling %R should have returned an instance of "
  3529. "BaseException, not %R",
  3530. type, Py_TYPE(value));
  3531. goto bad;
  3532. }
  3533. }
  3534. } else {
  3535. PyErr_SetString(PyExc_TypeError,
  3536. "raise: exception class must be a subclass of BaseException");
  3537. goto bad;
  3538. }
  3539. if (cause) {
  3540. PyObject *fixed_cause;
  3541. if (cause == Py_None) {
  3542. fixed_cause = NULL;
  3543. } else if (PyExceptionClass_Check(cause)) {
  3544. fixed_cause = PyObject_CallObject(cause, NULL);
  3545. if (fixed_cause == NULL)
  3546. goto bad;
  3547. } else if (PyExceptionInstance_Check(cause)) {
  3548. fixed_cause = cause;
  3549. Py_INCREF(fixed_cause);
  3550. } else {
  3551. PyErr_SetString(PyExc_TypeError,
  3552. "exception causes must derive from "
  3553. "BaseException");
  3554. goto bad;
  3555. }
  3556. PyException_SetCause(value, fixed_cause);
  3557. }
  3558. PyErr_SetObject(type, value);
  3559. if (tb) {
  3560. #if CYTHON_COMPILING_IN_PYPY
  3561. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3562. PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
  3563. Py_INCREF(tb);
  3564. PyErr_Restore(tmp_type, tmp_value, tb);
  3565. Py_XDECREF(tmp_tb);
  3566. #else
  3567. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  3568. PyObject* tmp_tb = tstate->curexc_traceback;
  3569. if (tb != tmp_tb) {
  3570. Py_INCREF(tb);
  3571. tstate->curexc_traceback = tb;
  3572. Py_XDECREF(tmp_tb);
  3573. }
  3574. #endif
  3575. }
  3576. bad:
  3577. Py_XDECREF(owned_instance);
  3578. return;
  3579. }
  3580. #endif
  3581. /* RaiseArgTupleInvalid */
  3582. static void __Pyx_RaiseArgtupleInvalid(
  3583. const char* func_name,
  3584. int exact,
  3585. Py_ssize_t num_min,
  3586. Py_ssize_t num_max,
  3587. Py_ssize_t num_found)
  3588. {
  3589. Py_ssize_t num_expected;
  3590. const char *more_or_less;
  3591. if (num_found < num_min) {
  3592. num_expected = num_min;
  3593. more_or_less = "at least";
  3594. } else {
  3595. num_expected = num_max;
  3596. more_or_less = "at most";
  3597. }
  3598. if (exact) {
  3599. more_or_less = "exactly";
  3600. }
  3601. PyErr_Format(PyExc_TypeError,
  3602. "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
  3603. func_name, more_or_less, num_expected,
  3604. (num_expected == 1) ? "" : "s", num_found);
  3605. }
  3606. /* RaiseDoubleKeywords */
  3607. static void __Pyx_RaiseDoubleKeywordsError(
  3608. const char* func_name,
  3609. PyObject* kw_name)
  3610. {
  3611. PyErr_Format(PyExc_TypeError,
  3612. #if PY_MAJOR_VERSION >= 3
  3613. "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
  3614. #else
  3615. "%s() got multiple values for keyword argument '%s'", func_name,
  3616. PyString_AsString(kw_name));
  3617. #endif
  3618. }
  3619. /* ParseKeywords */
  3620. static int __Pyx_ParseOptionalKeywords(
  3621. PyObject *kwds,
  3622. PyObject **argnames[],
  3623. PyObject *kwds2,
  3624. PyObject *values[],
  3625. Py_ssize_t num_pos_args,
  3626. const char* function_name)
  3627. {
  3628. PyObject *key = 0, *value = 0;
  3629. Py_ssize_t pos = 0;
  3630. PyObject*** name;
  3631. PyObject*** first_kw_arg = argnames + num_pos_args;
  3632. while (PyDict_Next(kwds, &pos, &key, &value)) {
  3633. name = first_kw_arg;
  3634. while (*name && (**name != key)) name++;
  3635. if (*name) {
  3636. values[name-argnames] = value;
  3637. continue;
  3638. }
  3639. name = first_kw_arg;
  3640. #if PY_MAJOR_VERSION < 3
  3641. if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
  3642. while (*name) {
  3643. if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
  3644. && _PyString_Eq(**name, key)) {
  3645. values[name-argnames] = value;
  3646. break;
  3647. }
  3648. name++;
  3649. }
  3650. if (*name) continue;
  3651. else {
  3652. PyObject*** argname = argnames;
  3653. while (argname != first_kw_arg) {
  3654. if ((**argname == key) || (
  3655. (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
  3656. && _PyString_Eq(**argname, key))) {
  3657. goto arg_passed_twice;
  3658. }
  3659. argname++;
  3660. }
  3661. }
  3662. } else
  3663. #endif
  3664. if (likely(PyUnicode_Check(key))) {
  3665. while (*name) {
  3666. int cmp = (**name == key) ? 0 :
  3667. #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
  3668. (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
  3669. #endif
  3670. PyUnicode_Compare(**name, key);
  3671. if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
  3672. if (cmp == 0) {
  3673. values[name-argnames] = value;
  3674. break;
  3675. }
  3676. name++;
  3677. }
  3678. if (*name) continue;
  3679. else {
  3680. PyObject*** argname = argnames;
  3681. while (argname != first_kw_arg) {
  3682. int cmp = (**argname == key) ? 0 :
  3683. #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
  3684. (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
  3685. #endif
  3686. PyUnicode_Compare(**argname, key);
  3687. if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
  3688. if (cmp == 0) goto arg_passed_twice;
  3689. argname++;
  3690. }
  3691. }
  3692. } else
  3693. goto invalid_keyword_type;
  3694. if (kwds2) {
  3695. if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
  3696. } else {
  3697. goto invalid_keyword;
  3698. }
  3699. }
  3700. return 0;
  3701. arg_passed_twice:
  3702. __Pyx_RaiseDoubleKeywordsError(function_name, key);
  3703. goto bad;
  3704. invalid_keyword_type:
  3705. PyErr_Format(PyExc_TypeError,
  3706. "%.200s() keywords must be strings", function_name);
  3707. goto bad;
  3708. invalid_keyword:
  3709. PyErr_Format(PyExc_TypeError,
  3710. #if PY_MAJOR_VERSION < 3
  3711. "%.200s() got an unexpected keyword argument '%.200s'",
  3712. function_name, PyString_AsString(key));
  3713. #else
  3714. "%s() got an unexpected keyword argument '%U'",
  3715. function_name, key);
  3716. #endif
  3717. bad:
  3718. return -1;
  3719. }
  3720. /* ArgTypeTest */
  3721. static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
  3722. {
  3723. if (unlikely(!type)) {
  3724. PyErr_SetString(PyExc_SystemError, "Missing type object");
  3725. return 0;
  3726. }
  3727. else if (exact) {
  3728. #if PY_MAJOR_VERSION == 2
  3729. if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
  3730. #endif
  3731. }
  3732. else {
  3733. if (likely(__Pyx_TypeCheck(obj, type))) return 1;
  3734. }
  3735. PyErr_Format(PyExc_TypeError,
  3736. "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
  3737. name, type->tp_name, Py_TYPE(obj)->tp_name);
  3738. return 0;
  3739. }
  3740. /* PyObjectCallNoArg */
  3741. #if CYTHON_COMPILING_IN_CPYTHON
  3742. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
  3743. #if CYTHON_FAST_PYCALL
  3744. if (PyFunction_Check(func)) {
  3745. return __Pyx_PyFunction_FastCall(func, NULL, 0);
  3746. }
  3747. #endif
  3748. #ifdef __Pyx_CyFunction_USED
  3749. if (likely(PyCFunction_Check(func) || __Pyx_TypeCheck(func, __pyx_CyFunctionType))) {
  3750. #else
  3751. if (likely(PyCFunction_Check(func))) {
  3752. #endif
  3753. if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
  3754. return __Pyx_PyObject_CallMethO(func, NULL);
  3755. }
  3756. }
  3757. return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
  3758. }
  3759. #endif
  3760. /* RaiseTooManyValuesToUnpack */
  3761. static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
  3762. PyErr_Format(PyExc_ValueError,
  3763. "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
  3764. }
  3765. /* RaiseNeedMoreValuesToUnpack */
  3766. static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
  3767. PyErr_Format(PyExc_ValueError,
  3768. "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
  3769. index, (index == 1) ? "" : "s");
  3770. }
  3771. /* IterFinish */
  3772. static CYTHON_INLINE int __Pyx_IterFinish(void) {
  3773. #if CYTHON_FAST_THREAD_STATE
  3774. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  3775. PyObject* exc_type = tstate->curexc_type;
  3776. if (unlikely(exc_type)) {
  3777. if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
  3778. PyObject *exc_value, *exc_tb;
  3779. exc_value = tstate->curexc_value;
  3780. exc_tb = tstate->curexc_traceback;
  3781. tstate->curexc_type = 0;
  3782. tstate->curexc_value = 0;
  3783. tstate->curexc_traceback = 0;
  3784. Py_DECREF(exc_type);
  3785. Py_XDECREF(exc_value);
  3786. Py_XDECREF(exc_tb);
  3787. return 0;
  3788. } else {
  3789. return -1;
  3790. }
  3791. }
  3792. return 0;
  3793. #else
  3794. if (unlikely(PyErr_Occurred())) {
  3795. if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
  3796. PyErr_Clear();
  3797. return 0;
  3798. } else {
  3799. return -1;
  3800. }
  3801. }
  3802. return 0;
  3803. #endif
  3804. }
  3805. /* UnpackItemEndCheck */
  3806. static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
  3807. if (unlikely(retval)) {
  3808. Py_DECREF(retval);
  3809. __Pyx_RaiseTooManyValuesError(expected);
  3810. return -1;
  3811. } else {
  3812. return __Pyx_IterFinish();
  3813. }
  3814. return 0;
  3815. }
  3816. /* GetException */
  3817. #if CYTHON_FAST_THREAD_STATE
  3818. static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  3819. #else
  3820. static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
  3821. #endif
  3822. PyObject *local_type, *local_value, *local_tb;
  3823. #if CYTHON_FAST_THREAD_STATE
  3824. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3825. local_type = tstate->curexc_type;
  3826. local_value = tstate->curexc_value;
  3827. local_tb = tstate->curexc_traceback;
  3828. tstate->curexc_type = 0;
  3829. tstate->curexc_value = 0;
  3830. tstate->curexc_traceback = 0;
  3831. #else
  3832. PyErr_Fetch(&local_type, &local_value, &local_tb);
  3833. #endif
  3834. PyErr_NormalizeException(&local_type, &local_value, &local_tb);
  3835. #if CYTHON_FAST_THREAD_STATE
  3836. if (unlikely(tstate->curexc_type))
  3837. #else
  3838. if (unlikely(PyErr_Occurred()))
  3839. #endif
  3840. goto bad;
  3841. #if PY_MAJOR_VERSION >= 3
  3842. if (local_tb) {
  3843. if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
  3844. goto bad;
  3845. }
  3846. #endif
  3847. Py_XINCREF(local_tb);
  3848. Py_XINCREF(local_type);
  3849. Py_XINCREF(local_value);
  3850. *type = local_type;
  3851. *value = local_value;
  3852. *tb = local_tb;
  3853. #if CYTHON_FAST_THREAD_STATE
  3854. #if PY_VERSION_HEX >= 0x030700A3
  3855. tmp_type = tstate->exc_state.exc_type;
  3856. tmp_value = tstate->exc_state.exc_value;
  3857. tmp_tb = tstate->exc_state.exc_traceback;
  3858. tstate->exc_state.exc_type = local_type;
  3859. tstate->exc_state.exc_value = local_value;
  3860. tstate->exc_state.exc_traceback = local_tb;
  3861. #else
  3862. tmp_type = tstate->exc_type;
  3863. tmp_value = tstate->exc_value;
  3864. tmp_tb = tstate->exc_traceback;
  3865. tstate->exc_type = local_type;
  3866. tstate->exc_value = local_value;
  3867. tstate->exc_traceback = local_tb;
  3868. #endif
  3869. Py_XDECREF(tmp_type);
  3870. Py_XDECREF(tmp_value);
  3871. Py_XDECREF(tmp_tb);
  3872. #else
  3873. PyErr_SetExcInfo(local_type, local_value, local_tb);
  3874. #endif
  3875. return 0;
  3876. bad:
  3877. *type = 0;
  3878. *value = 0;
  3879. *tb = 0;
  3880. Py_XDECREF(local_type);
  3881. Py_XDECREF(local_value);
  3882. Py_XDECREF(local_tb);
  3883. return -1;
  3884. }
  3885. /* SwapException */
  3886. #if CYTHON_FAST_THREAD_STATE
  3887. static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  3888. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3889. #if PY_VERSION_HEX >= 0x030700A3
  3890. tmp_type = tstate->exc_state.exc_type;
  3891. tmp_value = tstate->exc_state.exc_value;
  3892. tmp_tb = tstate->exc_state.exc_traceback;
  3893. tstate->exc_state.exc_type = *type;
  3894. tstate->exc_state.exc_value = *value;
  3895. tstate->exc_state.exc_traceback = *tb;
  3896. #else
  3897. tmp_type = tstate->exc_type;
  3898. tmp_value = tstate->exc_value;
  3899. tmp_tb = tstate->exc_traceback;
  3900. tstate->exc_type = *type;
  3901. tstate->exc_value = *value;
  3902. tstate->exc_traceback = *tb;
  3903. #endif
  3904. *type = tmp_type;
  3905. *value = tmp_value;
  3906. *tb = tmp_tb;
  3907. }
  3908. #else
  3909. static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
  3910. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3911. PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
  3912. PyErr_SetExcInfo(*type, *value, *tb);
  3913. *type = tmp_type;
  3914. *value = tmp_value;
  3915. *tb = tmp_tb;
  3916. }
  3917. #endif
  3918. /* SaveResetException */
  3919. #if CYTHON_FAST_THREAD_STATE
  3920. static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  3921. #if PY_VERSION_HEX >= 0x030700A3
  3922. *type = tstate->exc_state.exc_type;
  3923. *value = tstate->exc_state.exc_value;
  3924. *tb = tstate->exc_state.exc_traceback;
  3925. #else
  3926. *type = tstate->exc_type;
  3927. *value = tstate->exc_value;
  3928. *tb = tstate->exc_traceback;
  3929. #endif
  3930. Py_XINCREF(*type);
  3931. Py_XINCREF(*value);
  3932. Py_XINCREF(*tb);
  3933. }
  3934. static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  3935. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3936. #if PY_VERSION_HEX >= 0x030700A3
  3937. tmp_type = tstate->exc_state.exc_type;
  3938. tmp_value = tstate->exc_state.exc_value;
  3939. tmp_tb = tstate->exc_state.exc_traceback;
  3940. tstate->exc_state.exc_type = type;
  3941. tstate->exc_state.exc_value = value;
  3942. tstate->exc_state.exc_traceback = tb;
  3943. #else
  3944. tmp_type = tstate->exc_type;
  3945. tmp_value = tstate->exc_value;
  3946. tmp_tb = tstate->exc_traceback;
  3947. tstate->exc_type = type;
  3948. tstate->exc_value = value;
  3949. tstate->exc_traceback = tb;
  3950. #endif
  3951. Py_XDECREF(tmp_type);
  3952. Py_XDECREF(tmp_value);
  3953. Py_XDECREF(tmp_tb);
  3954. }
  3955. #endif
  3956. /* Import */
  3957. static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
  3958. PyObject *empty_list = 0;
  3959. PyObject *module = 0;
  3960. PyObject *global_dict = 0;
  3961. PyObject *empty_dict = 0;
  3962. PyObject *list;
  3963. #if PY_MAJOR_VERSION < 3
  3964. PyObject *py_import;
  3965. py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
  3966. if (!py_import)
  3967. goto bad;
  3968. #endif
  3969. if (from_list)
  3970. list = from_list;
  3971. else {
  3972. empty_list = PyList_New(0);
  3973. if (!empty_list)
  3974. goto bad;
  3975. list = empty_list;
  3976. }
  3977. global_dict = PyModule_GetDict(__pyx_m);
  3978. if (!global_dict)
  3979. goto bad;
  3980. empty_dict = PyDict_New();
  3981. if (!empty_dict)
  3982. goto bad;
  3983. {
  3984. #if PY_MAJOR_VERSION >= 3
  3985. if (level == -1) {
  3986. if (strchr(__Pyx_MODULE_NAME, '.')) {
  3987. module = PyImport_ImportModuleLevelObject(
  3988. name, global_dict, empty_dict, list, 1);
  3989. if (!module) {
  3990. if (!PyErr_ExceptionMatches(PyExc_ImportError))
  3991. goto bad;
  3992. PyErr_Clear();
  3993. }
  3994. }
  3995. level = 0;
  3996. }
  3997. #endif
  3998. if (!module) {
  3999. #if PY_MAJOR_VERSION < 3
  4000. PyObject *py_level = PyInt_FromLong(level);
  4001. if (!py_level)
  4002. goto bad;
  4003. module = PyObject_CallFunctionObjArgs(py_import,
  4004. name, global_dict, empty_dict, list, py_level, NULL);
  4005. Py_DECREF(py_level);
  4006. #else
  4007. module = PyImport_ImportModuleLevelObject(
  4008. name, global_dict, empty_dict, list, level);
  4009. #endif
  4010. }
  4011. }
  4012. bad:
  4013. #if PY_MAJOR_VERSION < 3
  4014. Py_XDECREF(py_import);
  4015. #endif
  4016. Py_XDECREF(empty_list);
  4017. Py_XDECREF(empty_dict);
  4018. return module;
  4019. }
  4020. /* ImportFrom */
  4021. static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
  4022. PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
  4023. if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
  4024. PyErr_Format(PyExc_ImportError,
  4025. #if PY_MAJOR_VERSION < 3
  4026. "cannot import name %.230s", PyString_AS_STRING(name));
  4027. #else
  4028. "cannot import name %S", name);
  4029. #endif
  4030. }
  4031. return value;
  4032. }
  4033. /* GetModuleGlobalName */
  4034. static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
  4035. PyObject *result;
  4036. #if !CYTHON_AVOID_BORROWED_REFS
  4037. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
  4038. result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
  4039. if (likely(result)) {
  4040. Py_INCREF(result);
  4041. } else if (unlikely(PyErr_Occurred())) {
  4042. result = NULL;
  4043. } else {
  4044. #else
  4045. result = PyDict_GetItem(__pyx_d, name);
  4046. if (likely(result)) {
  4047. Py_INCREF(result);
  4048. } else {
  4049. #endif
  4050. #else
  4051. result = PyObject_GetItem(__pyx_d, name);
  4052. if (!result) {
  4053. PyErr_Clear();
  4054. #endif
  4055. result = __Pyx_GetBuiltinName(name);
  4056. }
  4057. return result;
  4058. }
  4059. /* CLineInTraceback */
  4060. #ifndef CYTHON_CLINE_IN_TRACEBACK
  4061. static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) {
  4062. PyObject *use_cline;
  4063. PyObject *ptype, *pvalue, *ptraceback;
  4064. #if CYTHON_COMPILING_IN_CPYTHON
  4065. PyObject **cython_runtime_dict;
  4066. #endif
  4067. if (unlikely(!__pyx_cython_runtime)) {
  4068. return c_line;
  4069. }
  4070. __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
  4071. #if CYTHON_COMPILING_IN_CPYTHON
  4072. cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
  4073. if (likely(cython_runtime_dict)) {
  4074. use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback);
  4075. } else
  4076. #endif
  4077. {
  4078. PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
  4079. if (use_cline_obj) {
  4080. use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
  4081. Py_DECREF(use_cline_obj);
  4082. } else {
  4083. PyErr_Clear();
  4084. use_cline = NULL;
  4085. }
  4086. }
  4087. if (!use_cline) {
  4088. c_line = 0;
  4089. PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
  4090. }
  4091. else if (PyObject_Not(use_cline) != 0) {
  4092. c_line = 0;
  4093. }
  4094. __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
  4095. return c_line;
  4096. }
  4097. #endif
  4098. /* CodeObjectCache */
  4099. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
  4100. int start = 0, mid = 0, end = count - 1;
  4101. if (end >= 0 && code_line > entries[end].code_line) {
  4102. return count;
  4103. }
  4104. while (start < end) {
  4105. mid = start + (end - start) / 2;
  4106. if (code_line < entries[mid].code_line) {
  4107. end = mid;
  4108. } else if (code_line > entries[mid].code_line) {
  4109. start = mid + 1;
  4110. } else {
  4111. return mid;
  4112. }
  4113. }
  4114. if (code_line <= entries[mid].code_line) {
  4115. return mid;
  4116. } else {
  4117. return mid + 1;
  4118. }
  4119. }
  4120. static PyCodeObject *__pyx_find_code_object(int code_line) {
  4121. PyCodeObject* code_object;
  4122. int pos;
  4123. if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
  4124. return NULL;
  4125. }
  4126. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  4127. if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
  4128. return NULL;
  4129. }
  4130. code_object = __pyx_code_cache.entries[pos].code_object;
  4131. Py_INCREF(code_object);
  4132. return code_object;
  4133. }
  4134. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
  4135. int pos, i;
  4136. __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
  4137. if (unlikely(!code_line)) {
  4138. return;
  4139. }
  4140. if (unlikely(!entries)) {
  4141. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
  4142. if (likely(entries)) {
  4143. __pyx_code_cache.entries = entries;
  4144. __pyx_code_cache.max_count = 64;
  4145. __pyx_code_cache.count = 1;
  4146. entries[0].code_line = code_line;
  4147. entries[0].code_object = code_object;
  4148. Py_INCREF(code_object);
  4149. }
  4150. return;
  4151. }
  4152. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  4153. if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
  4154. PyCodeObject* tmp = entries[pos].code_object;
  4155. entries[pos].code_object = code_object;
  4156. Py_DECREF(tmp);
  4157. return;
  4158. }
  4159. if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
  4160. int new_max = __pyx_code_cache.max_count + 64;
  4161. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
  4162. __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
  4163. if (unlikely(!entries)) {
  4164. return;
  4165. }
  4166. __pyx_code_cache.entries = entries;
  4167. __pyx_code_cache.max_count = new_max;
  4168. }
  4169. for (i=__pyx_code_cache.count; i>pos; i--) {
  4170. entries[i] = entries[i-1];
  4171. }
  4172. entries[pos].code_line = code_line;
  4173. entries[pos].code_object = code_object;
  4174. __pyx_code_cache.count++;
  4175. Py_INCREF(code_object);
  4176. }
  4177. /* AddTraceback */
  4178. #include "compile.h"
  4179. #include "frameobject.h"
  4180. #include "traceback.h"
  4181. static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
  4182. const char *funcname, int c_line,
  4183. int py_line, const char *filename) {
  4184. PyCodeObject *py_code = 0;
  4185. PyObject *py_srcfile = 0;
  4186. PyObject *py_funcname = 0;
  4187. #if PY_MAJOR_VERSION < 3
  4188. py_srcfile = PyString_FromString(filename);
  4189. #else
  4190. py_srcfile = PyUnicode_FromString(filename);
  4191. #endif
  4192. if (!py_srcfile) goto bad;
  4193. if (c_line) {
  4194. #if PY_MAJOR_VERSION < 3
  4195. py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  4196. #else
  4197. py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  4198. #endif
  4199. }
  4200. else {
  4201. #if PY_MAJOR_VERSION < 3
  4202. py_funcname = PyString_FromString(funcname);
  4203. #else
  4204. py_funcname = PyUnicode_FromString(funcname);
  4205. #endif
  4206. }
  4207. if (!py_funcname) goto bad;
  4208. py_code = __Pyx_PyCode_New(
  4209. 0,
  4210. 0,
  4211. 0,
  4212. 0,
  4213. 0,
  4214. __pyx_empty_bytes, /*PyObject *code,*/
  4215. __pyx_empty_tuple, /*PyObject *consts,*/
  4216. __pyx_empty_tuple, /*PyObject *names,*/
  4217. __pyx_empty_tuple, /*PyObject *varnames,*/
  4218. __pyx_empty_tuple, /*PyObject *freevars,*/
  4219. __pyx_empty_tuple, /*PyObject *cellvars,*/
  4220. py_srcfile, /*PyObject *filename,*/
  4221. py_funcname, /*PyObject *name,*/
  4222. py_line,
  4223. __pyx_empty_bytes /*PyObject *lnotab*/
  4224. );
  4225. Py_DECREF(py_srcfile);
  4226. Py_DECREF(py_funcname);
  4227. return py_code;
  4228. bad:
  4229. Py_XDECREF(py_srcfile);
  4230. Py_XDECREF(py_funcname);
  4231. return NULL;
  4232. }
  4233. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  4234. int py_line, const char *filename) {
  4235. PyCodeObject *py_code = 0;
  4236. PyFrameObject *py_frame = 0;
  4237. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  4238. if (c_line) {
  4239. c_line = __Pyx_CLineForTraceback(tstate, c_line);
  4240. }
  4241. py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
  4242. if (!py_code) {
  4243. py_code = __Pyx_CreateCodeObjectForTraceback(
  4244. funcname, c_line, py_line, filename);
  4245. if (!py_code) goto bad;
  4246. __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
  4247. }
  4248. py_frame = PyFrame_New(
  4249. tstate, /*PyThreadState *tstate,*/
  4250. py_code, /*PyCodeObject *code,*/
  4251. __pyx_d, /*PyObject *globals,*/
  4252. 0 /*PyObject *locals*/
  4253. );
  4254. if (!py_frame) goto bad;
  4255. __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
  4256. PyTraceBack_Here(py_frame);
  4257. bad:
  4258. Py_XDECREF(py_code);
  4259. Py_XDECREF(py_frame);
  4260. }
  4261. /* UnicodeAsUCS4 */
  4262. static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
  4263. Py_ssize_t length;
  4264. #if CYTHON_PEP393_ENABLED
  4265. length = PyUnicode_GET_LENGTH(x);
  4266. if (likely(length == 1)) {
  4267. return PyUnicode_READ_CHAR(x, 0);
  4268. }
  4269. #else
  4270. length = PyUnicode_GET_SIZE(x);
  4271. if (likely(length == 1)) {
  4272. return PyUnicode_AS_UNICODE(x)[0];
  4273. }
  4274. #if Py_UNICODE_SIZE == 2
  4275. else if (PyUnicode_GET_SIZE(x) == 2) {
  4276. Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
  4277. if (high_val >= 0xD800 && high_val <= 0xDBFF) {
  4278. Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
  4279. if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
  4280. return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
  4281. }
  4282. }
  4283. }
  4284. #endif
  4285. #endif
  4286. PyErr_Format(PyExc_ValueError,
  4287. "only single character unicode strings can be converted to Py_UCS4, "
  4288. "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
  4289. return (Py_UCS4)-1;
  4290. }
  4291. /* ObjectAsUCS4 */
  4292. static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject* x) {
  4293. long ival;
  4294. ival = __Pyx_PyInt_As_long(x);
  4295. if (unlikely(ival < 0)) {
  4296. if (!PyErr_Occurred())
  4297. PyErr_SetString(PyExc_OverflowError,
  4298. "cannot convert negative value to Py_UCS4");
  4299. return (Py_UCS4)-1;
  4300. } else if (unlikely(ival > 1114111)) {
  4301. PyErr_SetString(PyExc_OverflowError,
  4302. "value too large to convert to Py_UCS4");
  4303. return (Py_UCS4)-1;
  4304. }
  4305. return (Py_UCS4)ival;
  4306. }
  4307. /* CIntToPy */
  4308. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
  4309. const long neg_one = (long) -1, const_zero = (long) 0;
  4310. const int is_unsigned = neg_one > const_zero;
  4311. if (is_unsigned) {
  4312. if (sizeof(long) < sizeof(long)) {
  4313. return PyInt_FromLong((long) value);
  4314. } else if (sizeof(long) <= sizeof(unsigned long)) {
  4315. return PyLong_FromUnsignedLong((unsigned long) value);
  4316. #ifdef HAVE_LONG_LONG
  4317. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  4318. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  4319. #endif
  4320. }
  4321. } else {
  4322. if (sizeof(long) <= sizeof(long)) {
  4323. return PyInt_FromLong((long) value);
  4324. #ifdef HAVE_LONG_LONG
  4325. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  4326. return PyLong_FromLongLong((PY_LONG_LONG) value);
  4327. #endif
  4328. }
  4329. }
  4330. {
  4331. int one = 1; int little = (int)*(unsigned char *)&one;
  4332. unsigned char *bytes = (unsigned char *)&value;
  4333. return _PyLong_FromByteArray(bytes, sizeof(long),
  4334. little, !is_unsigned);
  4335. }
  4336. }
  4337. /* CIntFromPyVerify */
  4338. #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
  4339. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
  4340. #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
  4341. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
  4342. #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
  4343. {\
  4344. func_type value = func_value;\
  4345. if (sizeof(target_type) < sizeof(func_type)) {\
  4346. if (unlikely(value != (func_type) (target_type) value)) {\
  4347. func_type zero = 0;\
  4348. if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
  4349. return (target_type) -1;\
  4350. if (is_unsigned && unlikely(value < zero))\
  4351. goto raise_neg_overflow;\
  4352. else\
  4353. goto raise_overflow;\
  4354. }\
  4355. }\
  4356. return (target_type) value;\
  4357. }
  4358. /* CIntFromPy */
  4359. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
  4360. const long neg_one = (long) -1, const_zero = (long) 0;
  4361. const int is_unsigned = neg_one > const_zero;
  4362. #if PY_MAJOR_VERSION < 3
  4363. if (likely(PyInt_Check(x))) {
  4364. if (sizeof(long) < sizeof(long)) {
  4365. __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
  4366. } else {
  4367. long val = PyInt_AS_LONG(x);
  4368. if (is_unsigned && unlikely(val < 0)) {
  4369. goto raise_neg_overflow;
  4370. }
  4371. return (long) val;
  4372. }
  4373. } else
  4374. #endif
  4375. if (likely(PyLong_Check(x))) {
  4376. if (is_unsigned) {
  4377. #if CYTHON_USE_PYLONG_INTERNALS
  4378. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4379. switch (Py_SIZE(x)) {
  4380. case 0: return (long) 0;
  4381. case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
  4382. case 2:
  4383. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  4384. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4385. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4386. } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
  4387. return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  4388. }
  4389. }
  4390. break;
  4391. case 3:
  4392. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  4393. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4394. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4395. } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
  4396. return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  4397. }
  4398. }
  4399. break;
  4400. case 4:
  4401. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  4402. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4403. __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])))
  4404. } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
  4405. return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  4406. }
  4407. }
  4408. break;
  4409. }
  4410. #endif
  4411. #if CYTHON_COMPILING_IN_CPYTHON
  4412. if (unlikely(Py_SIZE(x) < 0)) {
  4413. goto raise_neg_overflow;
  4414. }
  4415. #else
  4416. {
  4417. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  4418. if (unlikely(result < 0))
  4419. return (long) -1;
  4420. if (unlikely(result == 1))
  4421. goto raise_neg_overflow;
  4422. }
  4423. #endif
  4424. if (sizeof(long) <= sizeof(unsigned long)) {
  4425. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
  4426. #ifdef HAVE_LONG_LONG
  4427. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  4428. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  4429. #endif
  4430. }
  4431. } else {
  4432. #if CYTHON_USE_PYLONG_INTERNALS
  4433. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4434. switch (Py_SIZE(x)) {
  4435. case 0: return (long) 0;
  4436. case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
  4437. case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
  4438. case -2:
  4439. if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
  4440. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4441. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4442. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  4443. return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4444. }
  4445. }
  4446. break;
  4447. case 2:
  4448. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  4449. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4450. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4451. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  4452. return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4453. }
  4454. }
  4455. break;
  4456. case -3:
  4457. if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  4458. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4459. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4460. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  4461. return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4462. }
  4463. }
  4464. break;
  4465. case 3:
  4466. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  4467. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4468. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4469. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  4470. return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4471. }
  4472. }
  4473. break;
  4474. case -4:
  4475. if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  4476. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4477. __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])))
  4478. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  4479. return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4480. }
  4481. }
  4482. break;
  4483. case 4:
  4484. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  4485. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4486. __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])))
  4487. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  4488. return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4489. }
  4490. }
  4491. break;
  4492. }
  4493. #endif
  4494. if (sizeof(long) <= sizeof(long)) {
  4495. __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
  4496. #ifdef HAVE_LONG_LONG
  4497. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  4498. __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
  4499. #endif
  4500. }
  4501. }
  4502. {
  4503. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  4504. PyErr_SetString(PyExc_RuntimeError,
  4505. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  4506. #else
  4507. long val;
  4508. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  4509. #if PY_MAJOR_VERSION < 3
  4510. if (likely(v) && !PyLong_Check(v)) {
  4511. PyObject *tmp = v;
  4512. v = PyNumber_Long(tmp);
  4513. Py_DECREF(tmp);
  4514. }
  4515. #endif
  4516. if (likely(v)) {
  4517. int one = 1; int is_little = (int)*(unsigned char *)&one;
  4518. unsigned char *bytes = (unsigned char *)&val;
  4519. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  4520. bytes, sizeof(val),
  4521. is_little, !is_unsigned);
  4522. Py_DECREF(v);
  4523. if (likely(!ret))
  4524. return val;
  4525. }
  4526. #endif
  4527. return (long) -1;
  4528. }
  4529. } else {
  4530. long val;
  4531. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  4532. if (!tmp) return (long) -1;
  4533. val = __Pyx_PyInt_As_long(tmp);
  4534. Py_DECREF(tmp);
  4535. return val;
  4536. }
  4537. raise_overflow:
  4538. PyErr_SetString(PyExc_OverflowError,
  4539. "value too large to convert to long");
  4540. return (long) -1;
  4541. raise_neg_overflow:
  4542. PyErr_SetString(PyExc_OverflowError,
  4543. "can't convert negative value to long");
  4544. return (long) -1;
  4545. }
  4546. /* CIntFromPy */
  4547. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
  4548. const int neg_one = (int) -1, const_zero = (int) 0;
  4549. const int is_unsigned = neg_one > const_zero;
  4550. #if PY_MAJOR_VERSION < 3
  4551. if (likely(PyInt_Check(x))) {
  4552. if (sizeof(int) < sizeof(long)) {
  4553. __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
  4554. } else {
  4555. long val = PyInt_AS_LONG(x);
  4556. if (is_unsigned && unlikely(val < 0)) {
  4557. goto raise_neg_overflow;
  4558. }
  4559. return (int) val;
  4560. }
  4561. } else
  4562. #endif
  4563. if (likely(PyLong_Check(x))) {
  4564. if (is_unsigned) {
  4565. #if CYTHON_USE_PYLONG_INTERNALS
  4566. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4567. switch (Py_SIZE(x)) {
  4568. case 0: return (int) 0;
  4569. case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
  4570. case 2:
  4571. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  4572. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4573. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4574. } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
  4575. return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  4576. }
  4577. }
  4578. break;
  4579. case 3:
  4580. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  4581. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4582. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4583. } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
  4584. return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  4585. }
  4586. }
  4587. break;
  4588. case 4:
  4589. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  4590. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4591. __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])))
  4592. } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
  4593. return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  4594. }
  4595. }
  4596. break;
  4597. }
  4598. #endif
  4599. #if CYTHON_COMPILING_IN_CPYTHON
  4600. if (unlikely(Py_SIZE(x) < 0)) {
  4601. goto raise_neg_overflow;
  4602. }
  4603. #else
  4604. {
  4605. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  4606. if (unlikely(result < 0))
  4607. return (int) -1;
  4608. if (unlikely(result == 1))
  4609. goto raise_neg_overflow;
  4610. }
  4611. #endif
  4612. if (sizeof(int) <= sizeof(unsigned long)) {
  4613. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
  4614. #ifdef HAVE_LONG_LONG
  4615. } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
  4616. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  4617. #endif
  4618. }
  4619. } else {
  4620. #if CYTHON_USE_PYLONG_INTERNALS
  4621. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4622. switch (Py_SIZE(x)) {
  4623. case 0: return (int) 0;
  4624. case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
  4625. case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
  4626. case -2:
  4627. if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
  4628. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4629. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4630. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  4631. return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4632. }
  4633. }
  4634. break;
  4635. case 2:
  4636. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  4637. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4638. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4639. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  4640. return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4641. }
  4642. }
  4643. break;
  4644. case -3:
  4645. if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  4646. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4647. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4648. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  4649. return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4650. }
  4651. }
  4652. break;
  4653. case 3:
  4654. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  4655. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4656. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4657. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  4658. return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4659. }
  4660. }
  4661. break;
  4662. case -4:
  4663. if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  4664. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4665. __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])))
  4666. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  4667. return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4668. }
  4669. }
  4670. break;
  4671. case 4:
  4672. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  4673. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4674. __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])))
  4675. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  4676. return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4677. }
  4678. }
  4679. break;
  4680. }
  4681. #endif
  4682. if (sizeof(int) <= sizeof(long)) {
  4683. __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
  4684. #ifdef HAVE_LONG_LONG
  4685. } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
  4686. __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
  4687. #endif
  4688. }
  4689. }
  4690. {
  4691. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  4692. PyErr_SetString(PyExc_RuntimeError,
  4693. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  4694. #else
  4695. int val;
  4696. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  4697. #if PY_MAJOR_VERSION < 3
  4698. if (likely(v) && !PyLong_Check(v)) {
  4699. PyObject *tmp = v;
  4700. v = PyNumber_Long(tmp);
  4701. Py_DECREF(tmp);
  4702. }
  4703. #endif
  4704. if (likely(v)) {
  4705. int one = 1; int is_little = (int)*(unsigned char *)&one;
  4706. unsigned char *bytes = (unsigned char *)&val;
  4707. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  4708. bytes, sizeof(val),
  4709. is_little, !is_unsigned);
  4710. Py_DECREF(v);
  4711. if (likely(!ret))
  4712. return val;
  4713. }
  4714. #endif
  4715. return (int) -1;
  4716. }
  4717. } else {
  4718. int val;
  4719. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  4720. if (!tmp) return (int) -1;
  4721. val = __Pyx_PyInt_As_int(tmp);
  4722. Py_DECREF(tmp);
  4723. return val;
  4724. }
  4725. raise_overflow:
  4726. PyErr_SetString(PyExc_OverflowError,
  4727. "value too large to convert to int");
  4728. return (int) -1;
  4729. raise_neg_overflow:
  4730. PyErr_SetString(PyExc_OverflowError,
  4731. "can't convert negative value to int");
  4732. return (int) -1;
  4733. }
  4734. /* FastTypeChecks */
  4735. #if CYTHON_COMPILING_IN_CPYTHON
  4736. static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
  4737. while (a) {
  4738. a = a->tp_base;
  4739. if (a == b)
  4740. return 1;
  4741. }
  4742. return b == &PyBaseObject_Type;
  4743. }
  4744. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
  4745. PyObject *mro;
  4746. if (a == b) return 1;
  4747. mro = a->tp_mro;
  4748. if (likely(mro)) {
  4749. Py_ssize_t i, n;
  4750. n = PyTuple_GET_SIZE(mro);
  4751. for (i = 0; i < n; i++) {
  4752. if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
  4753. return 1;
  4754. }
  4755. return 0;
  4756. }
  4757. return __Pyx_InBases(a, b);
  4758. }
  4759. #if PY_MAJOR_VERSION == 2
  4760. static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
  4761. PyObject *exception, *value, *tb;
  4762. int res;
  4763. __Pyx_PyThreadState_declare
  4764. __Pyx_PyThreadState_assign
  4765. __Pyx_ErrFetch(&exception, &value, &tb);
  4766. res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
  4767. if (unlikely(res == -1)) {
  4768. PyErr_WriteUnraisable(err);
  4769. res = 0;
  4770. }
  4771. if (!res) {
  4772. res = PyObject_IsSubclass(err, exc_type2);
  4773. if (unlikely(res == -1)) {
  4774. PyErr_WriteUnraisable(err);
  4775. res = 0;
  4776. }
  4777. }
  4778. __Pyx_ErrRestore(exception, value, tb);
  4779. return res;
  4780. }
  4781. #else
  4782. static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
  4783. int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
  4784. if (!res) {
  4785. res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
  4786. }
  4787. return res;
  4788. }
  4789. #endif
  4790. static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
  4791. Py_ssize_t i, n;
  4792. assert(PyExceptionClass_Check(exc_type));
  4793. n = PyTuple_GET_SIZE(tuple);
  4794. #if PY_MAJOR_VERSION >= 3
  4795. for (i=0; i<n; i++) {
  4796. if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
  4797. }
  4798. #endif
  4799. for (i=0; i<n; i++) {
  4800. PyObject *t = PyTuple_GET_ITEM(tuple, i);
  4801. #if PY_MAJOR_VERSION < 3
  4802. if (likely(exc_type == t)) return 1;
  4803. #endif
  4804. if (likely(PyExceptionClass_Check(t))) {
  4805. if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
  4806. } else {
  4807. }
  4808. }
  4809. return 0;
  4810. }
  4811. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
  4812. if (likely(err == exc_type)) return 1;
  4813. if (likely(PyExceptionClass_Check(err))) {
  4814. if (likely(PyExceptionClass_Check(exc_type))) {
  4815. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
  4816. } else if (likely(PyTuple_Check(exc_type))) {
  4817. return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
  4818. } else {
  4819. }
  4820. }
  4821. return PyErr_GivenExceptionMatches(err, exc_type);
  4822. }
  4823. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
  4824. assert(PyExceptionClass_Check(exc_type1));
  4825. assert(PyExceptionClass_Check(exc_type2));
  4826. if (likely(err == exc_type1 || err == exc_type2)) return 1;
  4827. if (likely(PyExceptionClass_Check(err))) {
  4828. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
  4829. }
  4830. return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
  4831. }
  4832. #endif
  4833. /* CheckBinaryVersion */
  4834. static int __Pyx_check_binary_version(void) {
  4835. char ctversion[4], rtversion[4];
  4836. PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
  4837. PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
  4838. if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
  4839. char message[200];
  4840. PyOS_snprintf(message, sizeof(message),
  4841. "compiletime version %s of module '%.100s' "
  4842. "does not match runtime version %s",
  4843. ctversion, __Pyx_MODULE_NAME, rtversion);
  4844. return PyErr_WarnEx(NULL, message, 1);
  4845. }
  4846. return 0;
  4847. }
  4848. /* ModuleImport */
  4849. #ifndef __PYX_HAVE_RT_ImportModule
  4850. #define __PYX_HAVE_RT_ImportModule
  4851. static PyObject *__Pyx_ImportModule(const char *name) {
  4852. PyObject *py_name = 0;
  4853. PyObject *py_module = 0;
  4854. py_name = __Pyx_PyIdentifier_FromString(name);
  4855. if (!py_name)
  4856. goto bad;
  4857. py_module = PyImport_Import(py_name);
  4858. Py_DECREF(py_name);
  4859. return py_module;
  4860. bad:
  4861. Py_XDECREF(py_name);
  4862. return 0;
  4863. }
  4864. #endif
  4865. /* TypeImport */
  4866. #ifndef __PYX_HAVE_RT_ImportType
  4867. #define __PYX_HAVE_RT_ImportType
  4868. static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
  4869. size_t size, int strict)
  4870. {
  4871. PyObject *py_module = 0;
  4872. PyObject *result = 0;
  4873. PyObject *py_name = 0;
  4874. char warning[200];
  4875. Py_ssize_t basicsize;
  4876. #ifdef Py_LIMITED_API
  4877. PyObject *py_basicsize;
  4878. #endif
  4879. py_module = __Pyx_ImportModule(module_name);
  4880. if (!py_module)
  4881. goto bad;
  4882. py_name = __Pyx_PyIdentifier_FromString(class_name);
  4883. if (!py_name)
  4884. goto bad;
  4885. result = PyObject_GetAttr(py_module, py_name);
  4886. Py_DECREF(py_name);
  4887. py_name = 0;
  4888. Py_DECREF(py_module);
  4889. py_module = 0;
  4890. if (!result)
  4891. goto bad;
  4892. if (!PyType_Check(result)) {
  4893. PyErr_Format(PyExc_TypeError,
  4894. "%.200s.%.200s is not a type object",
  4895. module_name, class_name);
  4896. goto bad;
  4897. }
  4898. #ifndef Py_LIMITED_API
  4899. basicsize = ((PyTypeObject *)result)->tp_basicsize;
  4900. #else
  4901. py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
  4902. if (!py_basicsize)
  4903. goto bad;
  4904. basicsize = PyLong_AsSsize_t(py_basicsize);
  4905. Py_DECREF(py_basicsize);
  4906. py_basicsize = 0;
  4907. if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
  4908. goto bad;
  4909. #endif
  4910. if (!strict && (size_t)basicsize > size) {
  4911. PyOS_snprintf(warning, sizeof(warning),
  4912. "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
  4913. module_name, class_name, basicsize, size);
  4914. if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
  4915. }
  4916. else if ((size_t)basicsize != size) {
  4917. PyErr_Format(PyExc_ValueError,
  4918. "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
  4919. module_name, class_name, basicsize, size);
  4920. goto bad;
  4921. }
  4922. return (PyTypeObject *)result;
  4923. bad:
  4924. Py_XDECREF(py_module);
  4925. Py_XDECREF(result);
  4926. return NULL;
  4927. }
  4928. #endif
  4929. /* InitStrings */
  4930. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
  4931. while (t->p) {
  4932. #if PY_MAJOR_VERSION < 3
  4933. if (t->is_unicode) {
  4934. *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
  4935. } else if (t->intern) {
  4936. *t->p = PyString_InternFromString(t->s);
  4937. } else {
  4938. *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
  4939. }
  4940. #else
  4941. if (t->is_unicode | t->is_str) {
  4942. if (t->intern) {
  4943. *t->p = PyUnicode_InternFromString(t->s);
  4944. } else if (t->encoding) {
  4945. *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
  4946. } else {
  4947. *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
  4948. }
  4949. } else {
  4950. *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
  4951. }
  4952. #endif
  4953. if (!*t->p)
  4954. return -1;
  4955. if (PyObject_Hash(*t->p) == -1)
  4956. return -1;
  4957. ++t;
  4958. }
  4959. return 0;
  4960. }
  4961. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
  4962. return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
  4963. }
  4964. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
  4965. Py_ssize_t ignore;
  4966. return __Pyx_PyObject_AsStringAndSize(o, &ignore);
  4967. }
  4968. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  4969. #if !CYTHON_PEP393_ENABLED
  4970. static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  4971. char* defenc_c;
  4972. PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
  4973. if (!defenc) return NULL;
  4974. defenc_c = PyBytes_AS_STRING(defenc);
  4975. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  4976. {
  4977. char* end = defenc_c + PyBytes_GET_SIZE(defenc);
  4978. char* c;
  4979. for (c = defenc_c; c < end; c++) {
  4980. if ((unsigned char) (*c) >= 128) {
  4981. PyUnicode_AsASCIIString(o);
  4982. return NULL;
  4983. }
  4984. }
  4985. }
  4986. #endif
  4987. *length = PyBytes_GET_SIZE(defenc);
  4988. return defenc_c;
  4989. }
  4990. #else
  4991. static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  4992. if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
  4993. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  4994. if (likely(PyUnicode_IS_ASCII(o))) {
  4995. *length = PyUnicode_GET_LENGTH(o);
  4996. return PyUnicode_AsUTF8(o);
  4997. } else {
  4998. PyUnicode_AsASCIIString(o);
  4999. return NULL;
  5000. }
  5001. #else
  5002. return PyUnicode_AsUTF8AndSize(o, length);
  5003. #endif
  5004. }
  5005. #endif
  5006. #endif
  5007. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  5008. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  5009. if (
  5010. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  5011. __Pyx_sys_getdefaultencoding_not_ascii &&
  5012. #endif
  5013. PyUnicode_Check(o)) {
  5014. return __Pyx_PyUnicode_AsStringAndSize(o, length);
  5015. } else
  5016. #endif
  5017. #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
  5018. if (PyByteArray_Check(o)) {
  5019. *length = PyByteArray_GET_SIZE(o);
  5020. return PyByteArray_AS_STRING(o);
  5021. } else
  5022. #endif
  5023. {
  5024. char* result;
  5025. int r = PyBytes_AsStringAndSize(o, &result, length);
  5026. if (unlikely(r < 0)) {
  5027. return NULL;
  5028. } else {
  5029. return result;
  5030. }
  5031. }
  5032. }
  5033. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
  5034. int is_true = x == Py_True;
  5035. if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
  5036. else return PyObject_IsTrue(x);
  5037. }
  5038. static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
  5039. #if PY_MAJOR_VERSION >= 3
  5040. if (PyLong_Check(result)) {
  5041. if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
  5042. "__int__ returned non-int (type %.200s). "
  5043. "The ability to return an instance of a strict subclass of int "
  5044. "is deprecated, and may be removed in a future version of Python.",
  5045. Py_TYPE(result)->tp_name)) {
  5046. Py_DECREF(result);
  5047. return NULL;
  5048. }
  5049. return result;
  5050. }
  5051. #endif
  5052. PyErr_Format(PyExc_TypeError,
  5053. "__%.4s__ returned non-%.4s (type %.200s)",
  5054. type_name, type_name, Py_TYPE(result)->tp_name);
  5055. Py_DECREF(result);
  5056. return NULL;
  5057. }
  5058. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
  5059. #if CYTHON_USE_TYPE_SLOTS
  5060. PyNumberMethods *m;
  5061. #endif
  5062. const char *name = NULL;
  5063. PyObject *res = NULL;
  5064. #if PY_MAJOR_VERSION < 3
  5065. if (likely(PyInt_Check(x) || PyLong_Check(x)))
  5066. #else
  5067. if (likely(PyLong_Check(x)))
  5068. #endif
  5069. return __Pyx_NewRef(x);
  5070. #if CYTHON_USE_TYPE_SLOTS
  5071. m = Py_TYPE(x)->tp_as_number;
  5072. #if PY_MAJOR_VERSION < 3
  5073. if (m && m->nb_int) {
  5074. name = "int";
  5075. res = m->nb_int(x);
  5076. }
  5077. else if (m && m->nb_long) {
  5078. name = "long";
  5079. res = m->nb_long(x);
  5080. }
  5081. #else
  5082. if (likely(m && m->nb_int)) {
  5083. name = "int";
  5084. res = m->nb_int(x);
  5085. }
  5086. #endif
  5087. #else
  5088. if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
  5089. res = PyNumber_Int(x);
  5090. }
  5091. #endif
  5092. if (likely(res)) {
  5093. #if PY_MAJOR_VERSION < 3
  5094. if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
  5095. #else
  5096. if (unlikely(!PyLong_CheckExact(res))) {
  5097. #endif
  5098. return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
  5099. }
  5100. }
  5101. else if (!PyErr_Occurred()) {
  5102. PyErr_SetString(PyExc_TypeError,
  5103. "an integer is required");
  5104. }
  5105. return res;
  5106. }
  5107. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  5108. Py_ssize_t ival;
  5109. PyObject *x;
  5110. #if PY_MAJOR_VERSION < 3
  5111. if (likely(PyInt_CheckExact(b))) {
  5112. if (sizeof(Py_ssize_t) >= sizeof(long))
  5113. return PyInt_AS_LONG(b);
  5114. else
  5115. return PyInt_AsSsize_t(x);
  5116. }
  5117. #endif
  5118. if (likely(PyLong_CheckExact(b))) {
  5119. #if CYTHON_USE_PYLONG_INTERNALS
  5120. const digit* digits = ((PyLongObject*)b)->ob_digit;
  5121. const Py_ssize_t size = Py_SIZE(b);
  5122. if (likely(__Pyx_sst_abs(size) <= 1)) {
  5123. ival = likely(size) ? digits[0] : 0;
  5124. if (size == -1) ival = -ival;
  5125. return ival;
  5126. } else {
  5127. switch (size) {
  5128. case 2:
  5129. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  5130. return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  5131. }
  5132. break;
  5133. case -2:
  5134. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  5135. return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  5136. }
  5137. break;
  5138. case 3:
  5139. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  5140. return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  5141. }
  5142. break;
  5143. case -3:
  5144. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  5145. return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  5146. }
  5147. break;
  5148. case 4:
  5149. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  5150. 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]));
  5151. }
  5152. break;
  5153. case -4:
  5154. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  5155. 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]));
  5156. }
  5157. break;
  5158. }
  5159. }
  5160. #endif
  5161. return PyLong_AsSsize_t(b);
  5162. }
  5163. x = PyNumber_Index(b);
  5164. if (!x) return -1;
  5165. ival = PyInt_AsSsize_t(x);
  5166. Py_DECREF(x);
  5167. return ival;
  5168. }
  5169. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  5170. return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
  5171. }
  5172. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
  5173. return PyInt_FromSize_t(ival);
  5174. }
  5175. #endif /* Py_PYTHON_H */