How to use the urlpath.MultiDictMixin function in urlpath

To help you get started, we’ve selected a few urlpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chrono-meter / urlpath / urlpath.py View on Github external
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

urlpath

Object-oriented URL from `urllib.parse` and `pathlib`

Python-2.0
Latest version published 3 years ago

Package Health Score

43 / 100
Full package analysis