Generated by Cython 0.29.32
Yellow lines hint at Python interaction.
Click on a line that starts with a "+
" to see the C code that Cython generated for it.
Raw output: cetl.c
+01: from itertools import chain
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_chain); __Pyx_GIVEREF(__pyx_n_s_chain); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_chain); __pyx_t_2 = __Pyx_Import(__pyx_n_s_itertools, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_chain); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_chain, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
02:
03:
+04: cpdef get_field(str dot_path, record):
static PyObject *__pyx_pw_6aiodeu_4cetl_1get_field(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_6aiodeu_4cetl_get_field(PyObject *__pyx_v_dot_path, PyObject *__pyx_v_record, CYTHON_UNUSED int __pyx_skip_dispatch) { PyObject *__pyx_v_field = 0; PyObject *__pyx_v_fields = 0; PyObject *__pyx_v_dp = 0; PyObject *__pyx_v_val = NULL; PyObject *__pyx_7genexpr__pyx_v_val = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_field", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("aiodeu.cetl.get_field", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_field); __Pyx_XDECREF(__pyx_v_fields); __Pyx_XDECREF(__pyx_v_dp); __Pyx_XDECREF(__pyx_v_val); __Pyx_XDECREF(__pyx_7genexpr__pyx_v_val); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6aiodeu_4cetl_1get_field(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6aiodeu_4cetl_get_field[] = "\n Returns data in dict with dot path\n\n :param dot_path:\n :param record:\n :return:\n "; static PyObject *__pyx_pw_6aiodeu_4cetl_1get_field(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_dot_path = 0; PyObject *__pyx_v_record = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_field (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dot_path,&__pyx_n_s_record,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dot_path)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_record)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_field", 1, 2, 2, 1); __PYX_ERR(0, 4, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_field") < 0)) __PYX_ERR(0, 4, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_dot_path = ((PyObject*)values[0]); __pyx_v_record = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("get_field", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("aiodeu.cetl.get_field", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dot_path), (&PyUnicode_Type), 1, "dot_path", 1))) __PYX_ERR(0, 4, __pyx_L1_error) __pyx_r = __pyx_pf_6aiodeu_4cetl_get_field(__pyx_self, __pyx_v_dot_path, __pyx_v_record); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_6aiodeu_4cetl_get_field(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dot_path, PyObject *__pyx_v_record) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_field", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_6aiodeu_4cetl_get_field(__pyx_v_dot_path, __pyx_v_record, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("aiodeu.cetl.get_field", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
05: """
06: Returns data in dict with dot path
07:
08: :param dot_path:
09: :param record:
10: :return:
11: """
12: cdef str field
13: cdef list fields
+14: field, *fields = dot_path.split(".")
if (unlikely(__pyx_v_dot_path == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "split"); __PYX_ERR(0, 14, __pyx_L1_error) } __pyx_t_1 = PyUnicode_Split(__pyx_v_dot_path, __pyx_kp_u_, -1L); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t index = -1; PyObject** temps[2] = {&__pyx_t_2}; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; for (index=0; index < 1; index++) { PyObject* item = __pyx_t_4(__pyx_t_3); if (unlikely(!item)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(item); *(temps[index]) = item; } goto __pyx_L4_unpacking_done; __pyx_L3_unpacking_failed:; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_4 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 14, __pyx_L1_error) __pyx_L4_unpacking_done:; if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 14, __pyx_L1_error) } __pyx_t_5 = PySequence_List(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_field = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __pyx_v_fields = ((PyObject*)__pyx_t_5); __pyx_t_5 = 0;
+15: cdef str dp = ".".join(fields)
__pyx_t_1 = PyUnicode_Join(__pyx_kp_u_, __pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_dp = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+16: if not field:
__pyx_t_6 = (__pyx_v_field != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_field) != 0);
__pyx_t_7 = ((!__pyx_t_6) != 0);
if (__pyx_t_7) {
/* … */
}
+17: if record is None:
__pyx_t_7 = (__pyx_v_record == Py_None); __pyx_t_6 = (__pyx_t_7 != 0); if (__pyx_t_6) { /* … */ }
+18: return ""
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_kp_u__2); __pyx_r = __pyx_kp_u__2; goto __pyx_L0;
+19: return record
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_record); __pyx_r = __pyx_v_record; goto __pyx_L0;
+20: if isinstance(record, dict):
__pyx_t_6 = PyDict_Check(__pyx_v_record);
__pyx_t_7 = (__pyx_t_6 != 0);
if (__pyx_t_7) {
/* … */
}
+21: val = record.get(field)
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_record, __pyx_n_s_get); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); } } __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_2, __pyx_v_field) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_field); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_val = __pyx_t_1; __pyx_t_1 = 0;
+22: return get_field(dp, val)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_6aiodeu_4cetl_get_field(__pyx_v_dp, __pyx_v_val, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+23: elif isinstance(record, list):
__pyx_t_7 = PyList_Check(__pyx_v_record);
__pyx_t_6 = (__pyx_t_7 != 0);
if (__pyx_t_6) {
/* … */
}
+24: if len(record):
__pyx_t_8 = PyObject_Length(__pyx_v_record); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 24, __pyx_L1_error) __pyx_t_6 = (__pyx_t_8 != 0); if (__pyx_t_6) { /* … */ }
+25: val = record[0].get(field)
__pyx_t_5 = __Pyx_GetItemInt(__pyx_v_record, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_v_field) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_field); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_val = __pyx_t_1; __pyx_t_1 = 0;
+26: return get_field(dp, val)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_6aiodeu_4cetl_get_field(__pyx_v_dp, __pyx_v_val, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+27: return [get_field(dp, val) for val in record]
__Pyx_XDECREF(__pyx_r); { /* enter inner scope */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_1); if (likely(PyList_CheckExact(__pyx_v_record)) || PyTuple_CheckExact(__pyx_v_record)) { __pyx_t_2 = __pyx_v_record; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_record); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 27, __pyx_L11_error) } for (;;) { if (likely(!__pyx_t_9)) { if (likely(PyList_CheckExact(__pyx_t_2))) { if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 27, __pyx_L11_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 27, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_5); #endif } else { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 27, __pyx_L11_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 27, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_5); #endif } } else { __pyx_t_5 = __pyx_t_9(__pyx_t_2); if (unlikely(!__pyx_t_5)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 27, __pyx_L11_error) } break; } __Pyx_GOTREF(__pyx_t_5); } __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_val, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __pyx_f_6aiodeu_4cetl_get_field(__pyx_v_dp, __pyx_7genexpr__pyx_v_val, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 27, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_5); if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 27, __pyx_L11_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_7genexpr__pyx_v_val); __pyx_7genexpr__pyx_v_val = 0; goto __pyx_L14_exit_scope; __pyx_L11_error:; __Pyx_XDECREF(__pyx_7genexpr__pyx_v_val); __pyx_7genexpr__pyx_v_val = 0; goto __pyx_L1_error; __pyx_L14_exit_scope:; } /* exit inner scope */ __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
28: else:
+29: if record is None:
/*else*/ { __pyx_t_6 = (__pyx_v_record == Py_None); __pyx_t_7 = (__pyx_t_6 != 0); if (__pyx_t_7) { /* … */ }
+30: return ""
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_kp_u__2); __pyx_r = __pyx_kp_u__2; goto __pyx_L0;
+31: return record
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_record); __pyx_r = __pyx_v_record; goto __pyx_L0; }
32:
33:
+34: cpdef get_conditional_data(list items, str dot_path, values):
static PyObject *__pyx_pw_6aiodeu_4cetl_3get_conditional_data(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_6aiodeu_4cetl_get_conditional_data(PyObject *__pyx_v_items, PyObject *__pyx_v_dot_path, PyObject *__pyx_v_values, CYTHON_UNUSED int __pyx_skip_dispatch) { PyObject *__pyx_v_item = NULL; PyObject *__pyx_v_item_value = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_conditional_data", 0); __Pyx_INCREF(__pyx_v_values); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("aiodeu.cetl.get_conditional_data", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_item); __Pyx_XDECREF(__pyx_v_item_value); __Pyx_XDECREF(__pyx_v_values); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6aiodeu_4cetl_3get_conditional_data(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6aiodeu_4cetl_2get_conditional_data[] = "\n Returns contitional data from within a dict\n\n :param items:\n :param dot_path:\n :param values:\n :return:\n "; static PyObject *__pyx_pw_6aiodeu_4cetl_3get_conditional_data(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_items = 0; PyObject *__pyx_v_dot_path = 0; PyObject *__pyx_v_values = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_conditional_data (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,&__pyx_n_s_dot_path,&__pyx_n_s_values,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dot_path)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_conditional_data", 1, 3, 3, 1); __PYX_ERR(0, 34, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_values)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_conditional_data", 1, 3, 3, 2); __PYX_ERR(0, 34, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_conditional_data") < 0)) __PYX_ERR(0, 34, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_items = ((PyObject*)values[0]); __pyx_v_dot_path = ((PyObject*)values[1]); __pyx_v_values = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("get_conditional_data", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 34, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("aiodeu.cetl.get_conditional_data", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_items), (&PyList_Type), 1, "items", 1))) __PYX_ERR(0, 34, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dot_path), (&PyUnicode_Type), 1, "dot_path", 1))) __PYX_ERR(0, 34, __pyx_L1_error) __pyx_r = __pyx_pf_6aiodeu_4cetl_2get_conditional_data(__pyx_self, __pyx_v_items, __pyx_v_dot_path, __pyx_v_values); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_6aiodeu_4cetl_2get_conditional_data(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_items, PyObject *__pyx_v_dot_path, PyObject *__pyx_v_values) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_conditional_data", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_6aiodeu_4cetl_get_conditional_data(__pyx_v_items, __pyx_v_dot_path, __pyx_v_values, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("aiodeu.cetl.get_conditional_data", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
35: """
36: Returns contitional data from within a dict
37:
38: :param items:
39: :param dot_path:
40: :param values:
41: :return:
42: """
+43: if not isinstance(values, list):
__pyx_t_1 = PyList_Check(__pyx_v_values);
__pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
if (__pyx_t_2) {
/* … */
}
+44: values = [values]
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_values); __Pyx_GIVEREF(__pyx_v_values); PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_values); __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_3); __pyx_t_3 = 0;
+45: for item in items:
if (unlikely(__pyx_v_items == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); __PYX_ERR(0, 45, __pyx_L1_error) } __pyx_t_3 = __pyx_v_items; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; for (;;) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_5); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 45, __pyx_L1_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_5); __pyx_t_5 = 0; /* … */ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+46: item_value = get_field(dot_path, item)
__pyx_t_5 = __pyx_f_6aiodeu_4cetl_get_field(__pyx_v_dot_path, __pyx_v_item, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_XDECREF_SET(__pyx_v_item_value, __pyx_t_5); __pyx_t_5 = 0;
+47: if item_value in values:
__pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_item_value, __pyx_v_values, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 47, __pyx_L1_error) __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { /* … */ }
+48: return item
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_item); __pyx_r = __pyx_v_item; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0;
+49: return None
__Pyx_XDECREF(__pyx_r); __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0;
50:
51:
+52: cpdef list explode_lists(list data, str field):
static PyObject *__pyx_pw_6aiodeu_4cetl_5explode_lists(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_6aiodeu_4cetl_explode_lists(PyObject *__pyx_v_data, PyObject *__pyx_v_field, CYTHON_UNUSED int __pyx_skip_dispatch) { PyObject *__pyx_8genexpr1__pyx_v_d = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("explode_lists", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("aiodeu.cetl.explode_lists", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_d); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6aiodeu_4cetl_5explode_lists(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6aiodeu_4cetl_4explode_lists[] = "\n Explode field within a dict of a list of dicts. Calls below function.\n\n :param data:\n :param field:\n :return:\n "; static PyObject *__pyx_pw_6aiodeu_4cetl_5explode_lists(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_data = 0; PyObject *__pyx_v_field = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("explode_lists (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,&__pyx_n_s_field,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_field)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("explode_lists", 1, 2, 2, 1); __PYX_ERR(0, 52, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "explode_lists") < 0)) __PYX_ERR(0, 52, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_data = ((PyObject*)values[0]); __pyx_v_field = ((PyObject*)values[1]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("explode_lists", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 52, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("aiodeu.cetl.explode_lists", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyList_Type), 1, "data", 1))) __PYX_ERR(0, 52, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_field), (&PyUnicode_Type), 1, "field", 1))) __PYX_ERR(0, 52, __pyx_L1_error) __pyx_r = __pyx_pf_6aiodeu_4cetl_4explode_lists(__pyx_self, __pyx_v_data, __pyx_v_field); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_6aiodeu_4cetl_4explode_lists(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data, PyObject *__pyx_v_field) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("explode_lists", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_6aiodeu_4cetl_explode_lists(__pyx_v_data, __pyx_v_field, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("aiodeu.cetl.explode_lists", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
53: """
54: Explode field within a dict of a list of dicts. Calls below function.
55:
56: :param data:
57: :param field:
58: :return:
59: """
+60: return list(chain(*[explode_list(d, field) for d in data]))
__Pyx_XDECREF(__pyx_r); __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_chain); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { /* enter inner scope */ __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); __PYX_ERR(0, 60, __pyx_L5_error) } __pyx_t_3 = __pyx_v_data; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; for (;;) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_5); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 60, __pyx_L5_error) #else __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 60, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_d, __pyx_t_5); __pyx_t_5 = 0; if (!(likely(PyDict_CheckExact(__pyx_8genexpr1__pyx_v_d))||((__pyx_8genexpr1__pyx_v_d) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_8genexpr1__pyx_v_d)->tp_name), 0))) __PYX_ERR(0, 60, __pyx_L5_error) __pyx_t_5 = __pyx_f_6aiodeu_4cetl_explode_list(((PyObject*)__pyx_8genexpr1__pyx_v_d), __pyx_v_field, 0, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 60, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_5); if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 60, __pyx_L5_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_d); __pyx_8genexpr1__pyx_v_d = 0; goto __pyx_L8_exit_scope; __pyx_L5_error:; __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_d); __pyx_8genexpr1__pyx_v_d = 0; goto __pyx_L1_error; __pyx_L8_exit_scope:; } /* exit inner scope */ __pyx_t_3 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0;
61:
62:
+63: cpdef list explode_list(dict data, str field, str prefix = None):
static PyObject *__pyx_pw_6aiodeu_4cetl_7explode_list(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_6aiodeu_4cetl_explode_list(PyObject *__pyx_v_data, PyObject *__pyx_v_field, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_6aiodeu_4cetl_explode_list *__pyx_optional_args) { PyObject *__pyx_v_prefix = ((PyObject*)Py_None); PyObject *__pyx_v_data_list = 0; PyObject *__pyx_v_field_list = 0; PyObject *__pyx_v_top_level_data = 0; PyObject *__pyx_v_d = 0; PyObject *__pyx_v_row = NULL; PyObject *__pyx_8genexpr2__pyx_v_key = NULL; PyObject *__pyx_8genexpr2__pyx_v_value = NULL; PyObject *__pyx_8genexpr3__pyx_v_key = NULL; PyObject *__pyx_8genexpr3__pyx_v_value = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("explode_list", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_prefix = __pyx_optional_args->prefix; } } __Pyx_INCREF(__pyx_v_prefix); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_12); __Pyx_XDECREF(__pyx_t_13); __Pyx_AddTraceback("aiodeu.cetl.explode_list", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_data_list); __Pyx_XDECREF(__pyx_v_field_list); __Pyx_XDECREF(__pyx_v_top_level_data); __Pyx_XDECREF(__pyx_v_d); __Pyx_XDECREF(__pyx_v_row); __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_key); __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_value); __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_key); __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_value); __Pyx_XDECREF(__pyx_v_prefix); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_6aiodeu_4cetl_7explode_list(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6aiodeu_4cetl_6explode_list[] = "\n Explode a dict in to a list of dicts on a particular field that is a nested list. This will duplicate top level\n fields.\n\n :param data:\n :param field:\n :param prefix:\n :return:\n "; static PyObject *__pyx_pw_6aiodeu_4cetl_7explode_list(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_data = 0; PyObject *__pyx_v_field = 0; PyObject *__pyx_v_prefix = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("explode_list (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,&__pyx_n_s_field,&__pyx_n_s_prefix,0}; PyObject* values[3] = {0,0,0}; values[2] = ((PyObject*)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_field)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("explode_list", 0, 2, 3, 1); __PYX_ERR(0, 63, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_prefix); if (value) { values[2] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "explode_list") < 0)) __PYX_ERR(0, 63, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_data = ((PyObject*)values[0]); __pyx_v_field = ((PyObject*)values[1]); __pyx_v_prefix = ((PyObject*)values[2]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("explode_list", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 63, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("aiodeu.cetl.explode_list", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyDict_Type), 1, "data", 1))) __PYX_ERR(0, 63, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_field), (&PyUnicode_Type), 1, "field", 1))) __PYX_ERR(0, 63, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_prefix), (&PyUnicode_Type), 1, "prefix", 1))) __PYX_ERR(0, 63, __pyx_L1_error) __pyx_r = __pyx_pf_6aiodeu_4cetl_6explode_list(__pyx_self, __pyx_v_data, __pyx_v_field, __pyx_v_prefix); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_6aiodeu_4cetl_6explode_list(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data, PyObject *__pyx_v_field, PyObject *__pyx_v_prefix) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("explode_list", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.prefix = __pyx_v_prefix; __pyx_t_1 = __pyx_f_6aiodeu_4cetl_explode_list(__pyx_v_data, __pyx_v_field, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("aiodeu.cetl.explode_list", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
64: """
65: Explode a dict in to a list of dicts on a particular field that is a nested list. This will duplicate top level
66: fields.
67:
68: :param data:
69: :param field:
70: :param prefix:
71: :return:
72: """
+73: if prefix is None:
__pyx_t_1 = (__pyx_v_prefix == ((PyObject*)Py_None)); __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { /* … */ }
+74: prefix = "%s." % field
__pyx_t_3 = PyUnicode_Format(__pyx_kp_u_s, __pyx_v_field); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_prefix, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0;
+75: cdef list data_list = []
__pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_data_list = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0;
+76: cdef list field_list = data[field]
if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 76, __pyx_L1_error) } __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_data, __pyx_v_field); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 76, __pyx_L1_error) __pyx_v_field_list = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0;
+77: cdef dict top_level_data = {key: value for key, value in data.items() if key != field}
{ /* enter inner scope */ __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = 0; if (unlikely(__pyx_v_data == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); __PYX_ERR(0, 77, __pyx_L6_error) } __pyx_t_8 = __Pyx_dict_iterator(__pyx_v_data, 1, __pyx_n_s_items, (&__pyx_t_6), (&__pyx_t_7)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 77, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = __pyx_t_8; __pyx_t_8 = 0; while (1) { __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_4, __pyx_t_6, &__pyx_t_5, &__pyx_t_8, &__pyx_t_9, NULL, __pyx_t_7); if (unlikely(__pyx_t_10 == 0)) break; if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 77, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_key, __pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_value, __pyx_t_9); __pyx_t_9 = 0; __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_8genexpr2__pyx_v_key, __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 77, __pyx_L6_error) if (__pyx_t_2) { if (unlikely(PyDict_SetItem(__pyx_t_3, (PyObject*)__pyx_8genexpr2__pyx_v_key, (PyObject*)__pyx_8genexpr2__pyx_v_value))) __PYX_ERR(0, 77, __pyx_L6_error) } } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_key); __pyx_8genexpr2__pyx_v_key = 0; __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_value); __pyx_8genexpr2__pyx_v_value = 0; goto __pyx_L10_exit_scope; __pyx_L6_error:; __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_key); __pyx_8genexpr2__pyx_v_key = 0; __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_value); __pyx_8genexpr2__pyx_v_value = 0; goto __pyx_L1_error; __pyx_L10_exit_scope:; } /* exit inner scope */ __pyx_v_top_level_data = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0;
78: cdef dict d
+79: for row in field_list:
if (unlikely(__pyx_v_field_list == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); __PYX_ERR(0, 79, __pyx_L1_error) } __pyx_t_3 = __pyx_v_field_list; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; for (;;) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 79, __pyx_L1_error) #else __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_XDECREF_SET(__pyx_v_row, __pyx_t_4); __pyx_t_4 = 0; /* … */ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+80: d = {}
__pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_d, ((PyObject*)__pyx_t_4)); __pyx_t_4 = 0;
+81: d.update(top_level_data)
__pyx_t_4 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_update, __pyx_v_d, __pyx_v_top_level_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 81, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+82: d.update({f"{prefix}{key}": value for key, value in row.items()})
{ /* enter inner scope */ __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L15_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = 0; if (unlikely(__pyx_v_row == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); __PYX_ERR(0, 82, __pyx_L15_error) } __pyx_t_8 = __Pyx_dict_iterator(__pyx_v_row, 0, __pyx_n_s_items, (&__pyx_t_11), (&__pyx_t_7)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 82, __pyx_L15_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = __pyx_t_8; __pyx_t_8 = 0; while (1) { __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_9, __pyx_t_11, &__pyx_t_5, &__pyx_t_8, &__pyx_t_12, NULL, __pyx_t_7); if (unlikely(__pyx_t_10 == 0)) break; if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 82, __pyx_L15_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GOTREF(__pyx_t_12); __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_key, __pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_value, __pyx_t_12); __pyx_t_12 = 0; __pyx_t_12 = __Pyx_PyUnicode_Unicode(__pyx_v_prefix); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 82, __pyx_L15_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_8 = __Pyx_PyObject_FormatSimple(__pyx_8genexpr3__pyx_v_key, __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 82, __pyx_L15_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_13 = __Pyx_PyUnicode_Concat(__pyx_t_12, __pyx_t_8); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 82, __pyx_L15_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(PyDict_SetItem(__pyx_t_4, (PyObject*)__pyx_t_13, (PyObject*)__pyx_8genexpr3__pyx_v_value))) __PYX_ERR(0, 82, __pyx_L15_error) __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_key); __pyx_8genexpr3__pyx_v_key = 0; __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_value); __pyx_8genexpr3__pyx_v_value = 0; goto __pyx_L18_exit_scope; __pyx_L15_error:; __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_key); __pyx_8genexpr3__pyx_v_key = 0; __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_value); __pyx_8genexpr3__pyx_v_value = 0; goto __pyx_L1_error; __pyx_L18_exit_scope:; } /* exit inner scope */ __pyx_t_9 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_update, __pyx_v_d, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+83: data_list.append(d)
__pyx_t_14 = __Pyx_PyList_Append(__pyx_v_data_list, __pyx_v_d); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 83, __pyx_L1_error)
+84: return data_list
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_data_list); __pyx_r = __pyx_v_data_list; goto __pyx_L0;