csonpath 0.18.0__tar.gz → 0.19.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.
Files changed (44) hide show
  1. {csonpath-0.18.0 → csonpath-0.19.0}/Makefile +2 -0
  2. {csonpath-0.18.0/csonpath.egg-info → csonpath-0.19.0}/PKG-INFO +3 -1
  3. {csonpath-0.18.0 → csonpath-0.19.0}/README.md +2 -0
  4. {csonpath-0.18.0 → csonpath-0.19.0/csonpath.egg-info}/PKG-INFO +3 -1
  5. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath.h +39 -1
  6. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_do.h +33 -1
  7. {csonpath-0.18.0 → csonpath-0.19.0}/pyproject.toml +2 -2
  8. {csonpath-0.18.0 → csonpath-0.19.0}/LICENSE +0 -0
  9. {csonpath-0.18.0 → csonpath-0.19.0}/MANIFEST.in +0 -0
  10. {csonpath-0.18.0 → csonpath-0.19.0}/configure +0 -0
  11. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath.egg-info/SOURCES.txt +0 -0
  12. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath.egg-info/dependency_links.txt +0 -0
  13. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath.egg-info/requires.txt +0 -0
  14. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath.egg-info/top_level.txt +0 -0
  15. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_json-c.h +0 -0
  16. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_my_fuzzing.h +0 -0
  17. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_python.c +0 -0
  18. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_undef.h +0 -0
  19. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_yyjson.h +0 -0
  20. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_yyjson_const.h +0 -0
  21. {csonpath-0.18.0 → csonpath-0.19.0}/csonpath_yyjson_mut.h +0 -0
  22. {csonpath-0.18.0 → csonpath-0.19.0}/setup.cfg +0 -0
  23. {csonpath-0.18.0 → csonpath-0.19.0}/setup.py +0 -0
  24. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/.git +0 -0
  25. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/.github/workflows/c-cpp.yml +0 -0
  26. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/.gitignore +0 -0
  27. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/LICENSE +0 -0
  28. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/Makefile +0 -0
  29. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/README.md +0 -0
  30. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/clib.json +0 -0
  31. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/formal_verification.md +0 -0
  32. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/re.c +0 -0
  33. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/re.h +0 -0
  34. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/scripts/exrex.py +0 -0
  35. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/scripts/regex_test.py +0 -0
  36. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/scripts/regex_test_neg.py +0 -0
  37. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test1.c +0 -0
  38. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test2.c +0 -0
  39. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test3.c +0 -0
  40. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test_compile.c +0 -0
  41. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test_print.c +0 -0
  42. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test_rand.c +0 -0
  43. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test_rand_neg.c +0 -0
  44. {csonpath-0.18.0 → csonpath-0.19.0}/tiny-regex-c/tests/test_thread.c +0 -0
@@ -101,6 +101,8 @@ cov:
101
101
  rm -rf coverage-c coverage-c.html coverage-py coverage-rust build
102
102
  find . -name '*.gcov' -delete
103
103
  $(MAKE) CFLAGS='--coverage -O0 -g' LDFLAGS='--coverage' tests-c
104
+ $(MAKE) CFLAGS='--coverage -O0 -g' LDFLAGS='--coverage' csonpath
105
+ bash tests/cli/run.sh ./csonpath
104
106
  CFLAGS='--coverage -O0' LDFLAGS='--coverage' python setup.py build_ext --inplace --force
105
107
  python -m coverage run -m pytest
106
108
  python -m coverage html -d coverage-py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csonpath
3
- Version: 0.18.0
3
+ Version: 0.19.0
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Provides-Extra: dev
@@ -30,6 +30,7 @@ Out of the box it ships with C backends for [json-c](https://github.com/json-c/j
30
30
  | Array index | `$.array[0]` | Access by zero-based index |
31
31
  | Wildcard `[*]` | `$.array[*].field` | Iterate all array elements |
32
32
  | Recursive descent `..` | `$..name` | Search recursively for a key |
33
+ | Recursive descent wildcard `..*` | `$..*` | Return all descendants |
33
34
  | Union `,` (inside brackets) | `$['a','b']`, `$.array[0,1]`, `$.items[?n==1, ?n==2]` | Match all listed selectors at once |
34
35
  | OR fallback `\|` | `$.a \| $.b` | Try the left path first; fall back to the right one if it does not match. Only the first successful path is used. |
35
36
  | Filters | `$.items[?price > 10]` | Filter array elements |
@@ -37,6 +38,7 @@ Out of the box it ships with C backends for [json-c](https://github.com/json-c/j
37
38
  | Multiple filters (`&`) | `$.items[?a=1 & b=2]` | Combine conditions |
38
39
  | Subpath expressions | `$.obj[$.key]` | Use JSON values as dynamic path keys |
39
40
  | `@` current object | `$.items[?@.price > 10]` | Reference the current element in filters |
41
+ | Type selectors | `$..["@odata.id"]@string()`, `$.*@integer()` | Filter matches by JSON type (`string`, `integer`, `null`) |
40
42
 
41
43
  ### Operations
42
44
  - **Find First** — retrieve the first match.
@@ -21,6 +21,7 @@ Out of the box it ships with C backends for [json-c](https://github.com/json-c/j
21
21
  | Array index | `$.array[0]` | Access by zero-based index |
22
22
  | Wildcard `[*]` | `$.array[*].field` | Iterate all array elements |
23
23
  | Recursive descent `..` | `$..name` | Search recursively for a key |
24
+ | Recursive descent wildcard `..*` | `$..*` | Return all descendants |
24
25
  | Union `,` (inside brackets) | `$['a','b']`, `$.array[0,1]`, `$.items[?n==1, ?n==2]` | Match all listed selectors at once |
25
26
  | OR fallback `\|` | `$.a \| $.b` | Try the left path first; fall back to the right one if it does not match. Only the first successful path is used. |
26
27
  | Filters | `$.items[?price > 10]` | Filter array elements |
@@ -28,6 +29,7 @@ Out of the box it ships with C backends for [json-c](https://github.com/json-c/j
28
29
  | Multiple filters (`&`) | `$.items[?a=1 & b=2]` | Combine conditions |
29
30
  | Subpath expressions | `$.obj[$.key]` | Use JSON values as dynamic path keys |
30
31
  | `@` current object | `$.items[?@.price > 10]` | Reference the current element in filters |
32
+ | Type selectors | `$..["@odata.id"]@string()`, `$.*@integer()` | Filter matches by JSON type (`string`, `integer`, `null`) |
31
33
 
32
34
  ### Operations
33
35
  - **Find First** — retrieve the first match.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csonpath
3
- Version: 0.18.0
3
+ Version: 0.19.0
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Provides-Extra: dev
@@ -30,6 +30,7 @@ Out of the box it ships with C backends for [json-c](https://github.com/json-c/j
30
30
  | Array index | `$.array[0]` | Access by zero-based index |
31
31
  | Wildcard `[*]` | `$.array[*].field` | Iterate all array elements |
32
32
  | Recursive descent `..` | `$..name` | Search recursively for a key |
33
+ | Recursive descent wildcard `..*` | `$..*` | Return all descendants |
33
34
  | Union `,` (inside brackets) | `$['a','b']`, `$.array[0,1]`, `$.items[?n==1, ?n==2]` | Match all listed selectors at once |
34
35
  | OR fallback `\|` | `$.a \| $.b` | Try the left path first; fall back to the right one if it does not match. Only the first successful path is used. |
35
36
  | Filters | `$.items[?price > 10]` | Filter array elements |
@@ -37,6 +38,7 @@ Out of the box it ships with C backends for [json-c](https://github.com/json-c/j
37
38
  | Multiple filters (`&`) | `$.items[?a=1 & b=2]` | Combine conditions |
38
39
  | Subpath expressions | `$.obj[$.key]` | Use JSON values as dynamic path keys |
39
40
  | `@` current object | `$.items[?@.price > 10]` | Reference the current element in filters |
41
+ | Type selectors | `$..["@odata.id"]@string()`, `$.*@integer()` | Filter matches by JSON type (`string`, `integer`, `null`) |
40
42
 
41
43
  ### Operations
42
44
  - **Find First** — retrieve the first match.
@@ -89,6 +89,7 @@ enum csonpath_instuction_raw {
89
89
  CSONPATH_INST_UNION_JMP,
90
90
  CSONPATH_INST_UNION_END,
91
91
  CSONPATH_INST_FIND_ALL,
92
+ CSONPATH_INST_TYPECHECK,
92
93
  CSONPATH_INST_RANGE,
93
94
  CSONPATH_INST_OR,
94
95
  CSONPATH_INST_END,
@@ -118,6 +119,7 @@ static int csonpath_instuction_len[] = {
118
119
  1, /* E.5000 CSONPATH_INST_UNION_JMP */
119
120
  1, /* E.6 CSONPATH_INST_UNION_END */
120
121
  -1, /* F CSONPATH_INST_FIND_ALL */
122
+ 2, /* F.1 CSONPATH_INST_TYPECHECK */
121
123
  1, /* 10 CSONPATH_INST_RANGE */
122
124
  1, /* 11 CSONPATH_INST_OR */
123
125
  1, /* 12 CSONPATH_INST_END */
@@ -149,6 +151,7 @@ CSONPATH_UNUSED static const char *csonpath_instuction_str[] = {
149
151
  "UNION_JMP",
150
152
  "UNION_END",
151
153
  "FIND_ALL",
154
+ "TYPECHECK",
152
155
  "RANGE",
153
156
  "OR",
154
157
  "END",
@@ -462,6 +465,27 @@ root_again:
462
465
  }
463
466
 
464
467
  switch (to_check) {
468
+ case '@':
469
+ ++walker;
470
+ if (!strncmp(walker, "string", 6)) {
471
+ csonpath_push_char(cjp, CSONPATH_INST_TYPECHECK, inst_idx);
472
+ csonpath_push_char(cjp, CSONPATH_STR, inst_idx);
473
+ walker += 6;
474
+ } else if (!strncmp(walker, "integer", 7)) {
475
+ csonpath_push_char(cjp, CSONPATH_INST_TYPECHECK, inst_idx);
476
+ csonpath_push_char(cjp, CSONPATH_INTEGER, inst_idx);
477
+ walker += 7;
478
+ } else if (!strncmp(walker, "null", 4)) {
479
+ csonpath_push_char(cjp, CSONPATH_INST_TYPECHECK, inst_idx);
480
+ csonpath_push_char(cjp, CSONPATH_NONE, inst_idx);
481
+ walker += 4;
482
+ } else {
483
+ CSONPATH_COMPILE_ERR(tmp, walker - orig, "unknow type selector");
484
+ }
485
+ CSONPATH_SKIP('(', walker);
486
+ CSONPATH_SKIP(')', walker);
487
+ to_check = *walker;
488
+ goto again;
465
489
  case '[':
466
490
  {
467
491
  int end;
@@ -925,10 +949,24 @@ root_again:
925
949
  if (*walker == '.') {
926
950
  inst = CSONPATH_INST_FIND_ALL;
927
951
  ++walker;
952
+ if (*walker == '*') {
953
+ ++walker;
954
+ /*
955
+ * Encode $..* as FIND_ALL followed by the GET_ALL byte and a NUL.
956
+ * GET_ALL (0x0E) is a non-printable control character, so it can
957
+ * never appear raw in a valid JSON key; this avoids collision with
958
+ * real recursive-descent keys like $..name.
959
+ */
960
+ csonpath_push_char(cjp, CSONPATH_INST_FIND_ALL, inst_idx);
961
+ csonpath_push_char(cjp, CSONPATH_INST_GET_ALL, inst_idx);
962
+ csonpath_push_char(cjp, 0, inst_idx);
963
+ to_check = *walker;
964
+ goto again;
965
+ }
928
966
  } else if (*walker == '*') {
929
967
  inst = CSONPATH_INST_GET_ALL;
930
968
  ++walker;
931
- if (*walker != '.' && *walker != '[' && *walker != '\0') {
969
+ if (*walker != '.' && *walker != '[' && *walker != '\0' && *walker != '@') {
932
970
  CSONPATH_COMPILE_ERR(tmp, walker - orig, "unsuported characters '%c' after '*'", *walker);
933
971
  goto error;
934
972
  }
@@ -145,13 +145,14 @@ static CSONPATH_DO_RET_TYPE csonpath_do_dotdot(const struct csonpath cjp[const s
145
145
  (void)ctx;
146
146
 
147
147
  CSONPATH_DO_FIND_ALL_PRE_LOOP;
148
+ const int is_wildcard = (unsigned char)walker[1] == CSONPATH_INST_GET_ALL;
148
149
  if (is_obj) {
149
150
  const char *key;
150
151
  CSONPATH_FOREACH_OBJ(tmp, el, key) {
151
152
  key_idx = (intptr_t)key;
152
153
  (void)key_idx;
153
154
  CSONPATH_DO_FOREACH_PRE_SET;
154
- if (!strcmp(key, walker + 1)) {
155
+ if (is_wildcard || !strcmp(key, walker + 1)) {
155
156
  if (!next_inst)
156
157
  next_inst = csonpath_walker_next_inst(walker);
157
158
  tret = csonpath_do_internal(cjp, origin, el, tmp,
@@ -169,6 +170,14 @@ static CSONPATH_DO_RET_TYPE csonpath_do_dotdot(const struct csonpath cjp[const s
169
170
  CSONPATH_FOREACH_ARRAY(tmp, el, key_idx) {
170
171
  (void)key_idx;
171
172
  CSONPATH_DO_FOREACH_PRE_SET;
173
+ if (is_wildcard) {
174
+ if (!next_inst)
175
+ next_inst = csonpath_walker_next_inst(walker);
176
+ tret = csonpath_do_internal(cjp, origin, el, tmp,
177
+ next_inst
178
+ CSONPATH_DO_EXTRA_ARGS_NEESTED);
179
+ CSONPATH_DO_FIND_ALL;
180
+ }
172
181
  if (CSONPATH_IS_OBJ(el) || CSONPATH_IS_ARRAY(el)) {
173
182
  tret = csonpath_do_dotdot(cjp, origin, el, tmp, walker
174
183
  CSONPATH_DO_EXTRA_ARGS_NEESTED);
@@ -415,6 +424,29 @@ static CSONPATH_DO_RET_TYPE csonpath_do_internal(const struct csonpath cjp[const
415
424
  walker = owalker;
416
425
  break;
417
426
  }
427
+ case CSONPATH_INST_TYPECHECK:
428
+ {
429
+ int type = (unsigned char)walker[1];
430
+ ++walker;
431
+ switch (type) {
432
+ case CSONPATH_STR:
433
+ if (!CSONPATH_IS_STR(tmp))
434
+ return CSONPATH_NONE_FOUND_RET;
435
+ break;
436
+ case CSONPATH_INTEGER:
437
+ if (!CSONPATH_IS_NUM(tmp))
438
+ return CSONPATH_NONE_FOUND_RET;
439
+ break;
440
+ case CSONPATH_NONE:
441
+ if (!CSONPATH_IS_NULL(tmp))
442
+ return CSONPATH_NONE_FOUND_RET;
443
+ break;
444
+ default:
445
+ CSONPATH_GETTER_ERR("unknown typecheck %d, is csonpath corrupted ?\n", type);
446
+ break;
447
+ }
448
+ break;
449
+ }
418
450
  case CSONPATH_INST_GET_OBJ:
419
451
  {
420
452
  CSONPATH_UNUSED const char *this_idx = &walker[1];
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "csonpath"
7
- version = "0.18.0"
7
+ version = "0.19.0"
8
8
  readme = "README.md"
9
9
 
10
10
  [tool.setuptools]
@@ -27,7 +27,7 @@ test-command = "pytest {project}/tests/python"
27
27
  before-build = "choco install mingw -y"
28
28
 
29
29
  [tool.bumpversion]
30
- current_version = "0.18.0"
30
+ current_version = "0.19.0"
31
31
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
32
32
  serialize = ["{major}.{minor}.{patch}"]
33
33
  search = "{current_version}"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes