csonpath 0.0.3__tar.gz → 0.0.4__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.0.3
3
+ Version: 0.0.4
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.0.3
3
+ Version: 0.0.4
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Provides-Extra: dev
@@ -30,6 +30,7 @@ enum csonpath_instuction_raw {
30
30
  CSONPATH_INST_GET_ARRAY_SMALL,
31
31
  CSONPATH_INST_GET_ARRAY_BIG,
32
32
  CSONPATH_INST_FILTER_KEY_EQ,
33
+ CSONPATH_INST_FILTER_KEY_NOT_EQ,
33
34
  CSONPATH_INST_FILTER_OPERAND_STR,
34
35
  CSONPATH_INST_FILTER_OPERAND_BYTE, /* store the same way it's in ARRAY_SMALL */
35
36
  CSONPATH_INST_FILTER_OPERAND_INT, /* store the same way it's in ARRAY_BIG */
@@ -181,6 +182,7 @@ again:
181
182
  {
182
183
  int end;
183
184
 
185
+ do_array:
184
186
  cjp->inst_lst[cjp->inst_idx - 1].next += 1;
185
187
  ++walker;
186
188
  if (*walker == '*') {
@@ -193,25 +195,49 @@ again:
193
195
  to_check = *walker;
194
196
  goto again;
195
197
  } else if (*walker == '?') {
198
+ int have_blank;
196
199
  cjp->inst_lst[cjp->inst_idx - 1].next += 1;
197
200
  ++walker;
198
201
  for (next = walker; isalnum(*next); ++next);
199
202
  if (!*next) {
203
+ CSONPATH_COMPILE_ERR(tmp, walker - orig,
204
+ "filter miss condition");
200
205
  goto error;
201
206
  }
202
207
  to_check = *next;
203
208
  *next = 0;
204
- for (++next; isblank(*next); ++next);
205
- if (!*next)
209
+ have_blank = isblank(to_check);
210
+
211
+ for (++next; isblank(*next); ++next) {
212
+ have_blank = 1;
213
+ }
214
+
215
+ if (*next && have_blank &&
216
+ to_check != '=' && to_check != '!') {
217
+ to_check = *next;
218
+ ++next;
219
+ }
220
+
221
+ if (!*next) {
222
+ CSONPATH_COMPILE_ERR(tmp, next - orig,
223
+ "filter miss condition");
224
+
206
225
  goto error;
226
+ }
207
227
  /* = and == are the same here */
208
228
  if (to_check == '=') {
209
229
  csonpath_push_inst(cjp, CSONPATH_INST_FILTER_KEY_EQ);
210
230
  if (next[0] == '=')
211
231
  ++next;
232
+ } else if (to_check == '!' && next[0] == '=') {
233
+ csonpath_push_inst(cjp, CSONPATH_INST_FILTER_KEY_NOT_EQ);
234
+ ++next;
212
235
  } else {
236
+ CSONPATH_COMPILE_ERR(tmp, next - orig,
237
+ "'%c': unsuported operation", to_check);
213
238
  goto error;
214
239
  }
240
+ for (;isblank(*next); ++next);
215
241
  cjp->inst_lst[cjp->inst_idx - 1].next = next - walker;
216
242
  walker = next;
217
243
  if (*walker == '"' || *walker == '\'') {
@@ -220,8 +246,11 @@ again:
220
246
  cjp->inst_lst[cjp->inst_idx - 1].next++;
221
247
  csonpath_push_inst(cjp, CSONPATH_INST_FILTER_OPERAND_STR);
222
248
  for (next = walker; *next && *next != end; ++next);
223
- if (!*next)
249
+ if (!*next) {
250
+ CSONPATH_COMPILE_ERR(tmp, walker - orig,
251
+ "broken filter");
224
252
  goto error;
253
+ }
225
254
  *next = 0;
226
255
  ++next;
227
256
  to_check = *next;
@@ -229,8 +258,12 @@ again:
229
258
  int n;
230
259
 
231
260
  for (next = walker; isdigit(*next); ++next);
232
- if (next == walker)
261
+ if (next == walker) {
262
+ CSONPATH_COMPILE_ERR(tmp, walker - orig,
263
+ "'%c': broken filter with number",
264
+ *walker);
233
265
  goto error;
266
+ }
234
267
  n = atoi(walker);
235
268
  if (n < 100) {
236
269
  *walker = n;
@@ -241,6 +274,8 @@ again:
241
274
  csonpath_push_inst(cjp, CSONPATH_INST_FILTER_OPERAND_INT);
242
275
  }
243
276
  if (!*next) {
277
+ CSONPATH_COMPILE_ERR(tmp, walker - orig,
278
+ "compilation error");
244
279
  goto error;
245
280
  }
246
281
  to_check = *next;
@@ -328,9 +363,22 @@ again:
328
363
  inst = CSONPATH_INST_FIND_ALL;
329
364
  cjp->inst_lst[cjp->inst_idx - 1].next += 1;
330
365
  ++walker;
331
- }
366
+ } else if (*walker == '*') {
367
+ inst = CSONPATH_INST_GET_ALL;
368
+ ++walker;
369
+ if (*walker != '.' && *walker != '[' && *walker != '\0')
370
+ CSONPATH_COMPILE_ERR(tmp, walker - orig, "unsuported characters '%c' after '*'", *walker);
371
+ csonpath_push_inst(cjp, inst);
372
+ to_check = *walker;
373
+ goto again;
374
+ }
332
375
  for (next = walker; *next && *next != '[' && *next != '.' && *next != '|';
333
376
  ++next);
377
+ if (next == walker) {
378
+ if (*next == '[')
379
+ goto do_array;
380
+ CSONPATH_COMPILE_ERR(tmp, walker - orig, "empty getter");
381
+ }
334
382
  to_check = *next;
335
383
  *next = 0;
336
384
 
@@ -161,9 +161,11 @@ static CSONPATH_DO_RET_TYPE csonpath_do_internal(struct csonpath cjp[static 1],
161
161
  walker += cjp->inst_lst[idx].next;
162
162
  break;
163
163
  case CSONPATH_INST_FILTER_KEY_EQ:
164
+ case CSONPATH_INST_FILTER_KEY_NOT_EQ:
164
165
  {
165
166
  CSONPATH_JSON el;
166
167
  char *filter_key = walker;
168
+ int operation = cjp->inst_lst[idx].inst;
167
169
  walker += cjp->inst_lst[idx].next;
168
170
  ++idx;
169
171
 
@@ -178,7 +180,9 @@ static CSONPATH_DO_RET_TYPE csonpath_do_internal(struct csonpath cjp[static 1],
178
180
 
179
181
  CSONPATH_FOREACH_EXT(el, el2, {
180
182
  if (!strcmp((char *)neested_key, filter_key)) {
181
- if (CSONPATH_EQUAL_STR(el2, walker)) {
183
+ _Bool eq_ret = CSONPATH_EQUAL_STR(el2, walker);
184
+ if ((operation == CSONPATH_INST_FILTER_KEY_NOT_EQ && !eq_ret) ||
185
+ (operation == CSONPATH_INST_FILTER_KEY_EQ && eq_ret)) {
182
186
  CSONPATH_DO_RET_TYPE tret =
183
187
  csonpath_do_internal(cjp, origin, el, tmp, idx + 1,
184
188
  walker + cjp->inst_lst[idx].next
@@ -281,7 +285,8 @@ static CSONPATH_DO_RET_TYPE csonpath_do_(struct csonpath cjp[static 1],
281
285
  (void)ctx;
282
286
  csonpath_compile(cjp);
283
287
  if (cjp->inst_lst[0].inst == CSONPATH_INST_BROKEN) {
284
- CSONPATH_GETTER_ERR("fail to compile: %s\n", cjp->compile_error);
288
+ CSONPATH_GETTER_ERR("fail to compile: %s\n", cjp->compile_error ?
289
+ cjp->compile_error : "(unknow error)");
285
290
  return CSONPATH_NONE_FOUND_RET;
286
291
  }
287
292
 
@@ -149,7 +149,7 @@ static PyObject *PyCsonPath_new(PyTypeObject *subtype, PyObject* args,
149
149
 
150
150
  if (csonpath_compile(ret) < 0) {
151
151
  char *error = ret->compile_error;
152
- PyErr_Format(PyExc_ValueError, "compilation fail %s", error);
152
+ PyErr_Format(PyExc_ValueError, "compilation fail %s", error ? error : "(unknow error)");
153
153
  csonpath_destroy(ret);
154
154
  return NULL;
155
155
  }
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "csonpath"
7
- version = "0.0.3"
7
+ version = "0.0.4"
8
8
  readme = "README.md"
9
9
 
10
10
  [tool.setuptools]
File without changes
File without changes
File without changes
File without changes