json-e
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: json-e | ||
| Version: 4.7.1 | ||
| Version: 4.8.0 | ||
| Summary: A data-structure parameterization system written for embedding context in JSON objects | ||
@@ -5,0 +5,0 @@ Home-page: https://json-e.js.org |
+10
-0
@@ -69,2 +69,5 @@ from __future__ import absolute_import, print_function, unicode_literals | ||
| def is_int(v): | ||
| return isinstance(v, int) | ||
| def is_string(v): | ||
@@ -105,2 +108,9 @@ return isinstance(v, string) | ||
| @builtin("range", minArgs=2) | ||
| def range_builtin(start, stop, step=1): | ||
| if step == 0 or not all([is_int(n) for n in [start, stop, step]]): | ||
| raise BuiltinError("invalid arguments to builtin: range") | ||
| return list(range(start, stop, step)) | ||
| @builtin("lowercase", argument_tests=[is_string]) | ||
@@ -107,0 +117,0 @@ def lowercase(v): |
+39
-0
@@ -307,2 +307,41 @@ from __future__ import absolute_import, print_function, unicode_literals | ||
| @operator("$reduce") | ||
| def reduce(template, context): | ||
| EACH_RE = r"each\([a-zA-Z_][a-zA-Z0-9_]*,\s*[a-zA-Z_][a-zA-Z0-9_]*(,\s*([a-zA-Z_][a-zA-Z0-9_]*))?\)" | ||
| checkUndefinedProperties(template, [r"\$reduce", "initial", EACH_RE]) | ||
| value = renderValue(template["$reduce"], context) | ||
| if not isinstance(value, list): | ||
| raise TemplateError("$reduce value must evaluate to an array") | ||
| if len(template) != 3: | ||
| raise TemplateError("$reduce must have exactly three properties") | ||
| each_keys = [k for k in template if k.startswith("each(")] | ||
| if len(each_keys) != 1: | ||
| raise TemplateError("$reduce requires each(..)") | ||
| each_key = each_keys[0] | ||
| each_args = [x.strip() for x in each_key[5:-1].split(",")] | ||
| each_acc = each_args[0] | ||
| each_var = each_args[1] | ||
| each_idx = each_args[2] if len(each_args) > 2 else None | ||
| each_template = template[each_key] | ||
| resultValue = template["initial"] | ||
| subcontext = context.copy() | ||
| for i, elt in enumerate(value): | ||
| if each_idx is None: | ||
| subcontext[each_acc] = resultValue | ||
| subcontext[each_var] = elt | ||
| else: | ||
| subcontext[each_acc] = resultValue | ||
| subcontext[each_var] = elt | ||
| subcontext[each_idx] = i | ||
| r = renderValue(each_template, subcontext) | ||
| if r is not DeleteMarker: | ||
| resultValue = r | ||
| return resultValue | ||
| @operator("$find") | ||
@@ -309,0 +348,0 @@ def find(template, context): |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: json-e | ||
| Version: 4.7.1 | ||
| Version: 4.8.0 | ||
| Summary: A data-structure parameterization system written for embedding context in JSON objects | ||
@@ -5,0 +5,0 @@ Home-page: https://json-e.js.org |
+1
-1
@@ -5,3 +5,3 @@ import json | ||
| version = "4.7.1" | ||
| version = "4.8.0" | ||
@@ -8,0 +8,0 @@ description = "A data-structure parameterization system written for embedding context in JSON objects" |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
49482
3.58%1262
3.19%