Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class MultiDictMixin:
def get_one(self, key, default=None, predicate=None, type=None):
# `predicate` comes from `inspect.getmembers`.
try:
values = self[key]
except LookupError:
pass
else:
for value in values:
if not predicate or predicate(value):
return value if not type else type(value)
return default
class FrozenMultiDict(MultiDictMixin, FrozenDict):
pass
def cached_property(getter):
"""Limited version of `functools.lru_cache`. But `__hash__` is not required.
"""
@functools.wraps(getter)
def helper(self):
key = '_cached_property_' + getter.__name__
if key in self.__dict__:
return self.__dict__[key]
result = self.__dict__[key] = getter(self)
return result