csonpath 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csonpath
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Provides-Extra: dev
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csonpath
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Provides-Extra: dev
@@ -571,16 +571,20 @@ again:
571
571
  }
572
572
 
573
573
  /* helper use multiple times */
574
- #define CSONPATH_DO_GET_NOTFOUND_UPDATER(this_idx) \
575
- if (to_check == CSONPATH_INST_GET_OBJ) { \
576
- tmp = CSONPATH_NEW_OBJECT(); \
577
- CSONPATH_APPEND_AT(ctx, this_idx, tmp); \
578
- } else { \
579
- tmp = CSONPATH_NEW_ARRAY(); \
580
- CSONPATH_APPEND_AT(ctx, this_idx, tmp); \
581
- } \
582
- walker += cjp->inst_lst[idx].next; \
583
- goto next_inst;
574
+ #define CSONPATH_DO_GET_NOTFOUND_UPDATER(this_idx) \
575
+ do { \
576
+ int append_ret = 0; \
577
+ if (to_check == CSONPATH_INST_GET_OBJ) { \
578
+ tmp = CSONPATH_NEW_OBJECT(); \
579
+ append_ret = CSONPATH_APPEND_AT(ctx, this_idx, tmp); \
580
+ } else { \
581
+ tmp = CSONPATH_NEW_ARRAY(); \
582
+ append_ret = CSONPATH_APPEND_AT(ctx, this_idx, tmp); \
583
+ } \
584
+ walker += cjp->inst_lst[idx].next; \
585
+ if (append_ret < 0) return append_ret; \
586
+ goto next_inst; \
587
+ } while (0)
584
588
 
585
589
  #define CSONPATH_GOTO_ON_RELOOP(where) \
586
590
  nb_res += tret; if (need_reloop_in) goto where;
@@ -719,7 +723,7 @@ again:
719
723
  int nb_res = 0;
720
724
 
721
725
  #define CSONPATH_DO_RET_TYPE int
722
- #define CSONPATH_DO_FUNC_NAME update_or_ceate
726
+ #define CSONPATH_DO_FUNC_NAME update_or_create
723
727
 
724
728
  /*
725
729
  * assuming tmp == value can only be true,
@@ -730,9 +734,9 @@ again:
730
734
  if (tmp == value) { \
731
735
  *need_reloop = 1; \
732
736
  if (child_info->type == CSONPATH_INTEGER) \
733
- CSONPATH_APPEND_AT(ctx, child_info->idx, to_update); \
737
+ return CSONPATH_APPEND_AT(ctx, child_info->idx, to_update); \
734
738
  else \
735
- CSONPATH_APPEND_AT(ctx, child_info->key, to_update); \
739
+ return CSONPATH_APPEND_AT(ctx, child_info->key, to_update); \
736
740
  return 1; \
737
741
  } \
738
742
  return 0;
@@ -809,7 +813,7 @@ again:
809
813
  int nb_res = 0;
810
814
 
811
815
  #define CSONPATH_DO_RET_TYPE int
812
- #define CSONPATH_DO_FUNC_NAME update_or_ceate_callback
816
+ #define CSONPATH_DO_FUNC_NAME update_or_create_callback
813
817
  #define CSONPATH_DO_RETURN \
814
818
  if (tmp == value) { \
815
819
  *need_reloop = 1; \
@@ -62,14 +62,33 @@
62
62
  PyList_Append(array, el); \
63
63
  })
64
64
 
65
- static void python_set_or_insert_item(PyObject *array, Py_ssize_t at, PyObject *el)
65
+ static int pydict_try_setitemstring(PyObject *obj, const char * const at, PyObject *el)
66
66
  {
67
- if (at >= PyList_Size(array)) {
67
+ if (!PyDict_Check(obj)) {
68
+ PyErr_Format(PyExc_ValueError, "Unable to follow path: Dict expected");
69
+ return -1;
70
+ }
71
+ PyDict_SetItemString(obj, at, el);
72
+ return 1;
73
+ }
74
+
75
+ static int python_set_or_insert_item(PyObject *array, Py_ssize_t at, PyObject *el)
76
+ {
77
+ if (!PyList_Check(array)) {
78
+ PyErr_Format(PyExc_ValueError, "Unable to follow path: List expected");
79
+ return -1;
80
+ }
81
+ size_t s = PyList_Size(array);
82
+ if (at >= s) {
83
+ for (;s < at; ++s)
84
+ PyList_Insert(array, s, Py_None);
85
+
68
86
  PyList_Insert(array, at, el);
69
87
  } else {
70
88
  Py_INCREF(el);
71
89
  PyList_SetItem(array, at, el);
72
90
  }
91
+ return 1;
73
92
  }
74
93
 
75
94
  #define CSONPATH_APPEND_AT(array, at, el) \
@@ -80,12 +99,12 @@ static void python_set_or_insert_item(PyObject *array, Py_ssize_t at, PyObject
80
99
  unsigned long: python_set_or_insert_item, \
81
100
  long long: python_set_or_insert_item, \
82
101
  unsigned long long: python_set_or_insert_item, \
83
- const char *: PyDict_SetItemString, \
84
- char *: PyDict_SetItemString \
102
+ const char *: pydict_try_setitemstring, \
103
+ char *: pydict_try_setitemstring \
85
104
  ) (array, at, el)
86
105
 
87
106
 
88
- #define CSONPATH_FOREACH_EXT(obj, el, code, key_idx) \
107
+ #define CSONPATH_FOREACH_EXT(obj, el, code, key_idx) \
89
108
  if (PyDict_Check(obj)) { \
90
109
  PyObject *key_; \
91
110
  Py_ssize_t pos_ = 0; \
@@ -219,7 +238,9 @@ static PyObject *update_or_create(PyCsonPathObject *self, PyObject* args)
219
238
 
220
239
  if (!PyArg_ParseTuple(args, "OO", &json, &value))
221
240
  BAD_ARG();
222
- int ret = csonpath_update_or_ceate(self->cp, json, value);
241
+ int ret = csonpath_update_or_create(self->cp, json, value);
242
+ if (ret < 0)
243
+ return NULL;
223
244
  return PyLong_FromLong(ret);
224
245
  }
225
246
 
@@ -229,7 +250,7 @@ static PyObject *update_or_create_callback(PyCsonPathObject *self, PyObject* arg
229
250
 
230
251
  if (!PyArg_ParseTuple(args, "OO|O", &json, &callback, &udata))
231
252
  BAD_ARG();
232
- int ret = csonpath_update_or_ceate_callback(self->cp, json, callback, udata);
253
+ int ret = csonpath_update_or_create_callback(self->cp, json, callback, udata);
233
254
  return PyLong_FromLong(ret);
234
255
  }
235
256
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "csonpath"
7
- version = "0.2.0"
7
+ version = "0.4.0"
8
8
  readme = "README.md"
9
9
 
10
10
  [tool.setuptools]
@@ -22,7 +22,7 @@ dev = [
22
22
  testpaths = ["tests/python"]
23
23
 
24
24
  [tool.bumpversion]
25
- current_version = "0.2.0"
25
+ current_version = "0.4.0"
26
26
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
27
27
  serialize = ["{major}.{minor}.{patch}"]
28
28
  search = "{current_version}"
File without changes
File without changes
File without changes
File without changes
File without changes