summaryrefslogtreecommitdiffstats
path: root/third_party/python/json_e/jsone/__init__.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/python/json_e/jsone/__init__.py
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/json_e/jsone/__init__.py')
-rw-r--r--third_party/python/json_e/jsone/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/third_party/python/json_e/jsone/__init__.py b/third_party/python/json_e/jsone/__init__.py
new file mode 100644
index 0000000000..e8720e7f98
--- /dev/null
+++ b/third_party/python/json_e/jsone/__init__.py
@@ -0,0 +1,25 @@
+from __future__ import absolute_import, print_function, unicode_literals
+
+import re
+from .render import renderValue, containsFunctions
+from .shared import JSONTemplateError, DeleteMarker, TemplateError, fromNow
+from . import builtins
+
+_context_re = re.compile(r'[a-zA-Z_][a-zA-Z0-9_]*$')
+
+
+def render(template, context):
+ if type(context) != dict:
+ raise TemplateError("context must be a dictionary")
+ if not all(_context_re.match(c) for c in context):
+ raise TemplateError('top level keys of context must follow '
+ '/[a-zA-Z_][a-zA-Z0-9_]*/')
+ full_context = {'now': fromNow('0 seconds', None)}
+ full_context.update(builtins.build())
+ full_context.update(context)
+ rv = renderValue(template, full_context)
+ if rv is DeleteMarker:
+ return None
+ if containsFunctions(rv):
+ raise TemplateError('evaluated template contained uncalled functions')
+ return rv