[PATCH] upstream

This commit is contained in:
Parthiv Patel committed 2023-10-23 10:44:57 +00:00
1 parent 953b7926f7
commit f785f6223c
3 files changed
+44 -3

No files matched your search

+8
View File
@@ -30,6 +30,14 @@ FileStorage.save = lambda self, dst, buffer_size=1<<20: copyfileobj(self.stream,
Request.json_module = Response.json_module = scriptsafe
get_func_code = getattr(Rule, '_get_func_code', None)
if get_func_code:
@staticmethod
def _get_func_code(code, name):
assert isinstance(code, CodeType)
return get_func_code(code, name)
Rule._get_func_code = _get_func_code
orig_literal_eval = ast.literal_eval
def literal_eval(expr):
+34
View File
@@ -1576,6 +1576,40 @@ pickle.dump = pickle_.dump
pickle.dumps = pickle_.dumps
class ReadonlyDict(Mapping):
"""Helper for an unmodifiable dictionary, not even updatable using `dict.update`.
This is similar to a `frozendict`, with one drawback and one advantage:
- `dict.update` works for a `frozendict` but not for a `ReadonlyDict`.
- `json.dumps` works for a `frozendict` by default but not for a `ReadonlyDict`.
This comes from the fact `frozendict` inherits from `dict`
while `ReadonlyDict` inherits from `collections.abc.Mapping`.
So, depending on your needs,
whether you absolutely must prevent the dictionary from being updated (e.g., for security reasons)
or you require it to be supported by `json.dumps`, you can choose either option.
E.g.
data = ReadonlyDict({'foo': 'bar'})
data['baz'] = 'xyz' # raises exception
data.update({'baz', 'xyz'}) # raises exception
dict.update(data, {'baz': 'xyz'}) # raises exception
"""
def __init__(self, data):
self.__data = dict(data)
def __getitem__(self, key):
return self.__data[key]
def __len__(self):
return len(self.__data)
def __iter__(self):
return iter(self.__data)
class DotDict(dict):
"""Helper for dot.notation access to dictionary attributes
+2 -3
View File
@@ -56,9 +56,8 @@ def locate_node(arch, spec):
expr = spec.get('expr')
try:
xPath = etree.ETXPath(expr)
except etree.XPathSyntaxError:
_logger.error("XPathSyntaxError while parsing xpath %r", expr)
raise
except etree.XPathSyntaxError as e:
raise ValidationError(_("Invalid Expression while parsing xpath %r", expr)) from e
nodes = xPath(arch)
return nodes[0] if nodes else None
elif spec.tag == 'field':