How to use the multidict._multidict_py._Base function in multidict

To help you get started, we’ve selected a few multidict 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 aio-libs / multidict / multidict / _multidict_py.py View on Github external
raise TypeError(
                "ctor requires CIMultiDict or CIMultiDictProxy instance"
                ", not {}".format(type(arg))
            )

        self._impl = arg._impl

    def _title(self, key):
        return key.title()

    def copy(self):
        """Return a copy of itself."""
        return CIMultiDict(self.items())


class MultiDict(_Base, MutableMultiMapping):
    """Dictionary with the support for duplicate keys."""

    def __init__(self, *args, **kwargs):
        self._impl = _Impl()

        self._extend(args, kwargs, self.__class__.__name__, self._extend_items)

    def __reduce__(self):
        return (self.__class__, (list(self.items()),))

    def _title(self, key):
        return key

    def _key(self, key):
        if isinstance(key, str):
            return key
github aio-libs / multidict / multidict / _multidict_py.py View on Github external
return False
        return True

    def __contains__(self, key):
        identity = self._title(key)
        for i, k, v in self._impl._items:
            if i == identity:
                return True
        return False

    def __repr__(self):
        body = ", ".join("'{}': {!r}".format(k, v) for k, v in self.items())
        return "<{}({})>".format(self.__class__.__name__, body)


class MultiDictProxy(_Base, MultiMapping):
    """Read-only proxy for MultiDict instance."""

    def __init__(self, arg):
        if not isinstance(arg, (MultiDict, MultiDictProxy)):
            raise TypeError(
                "ctor requires MultiDict or MultiDictProxy instance"
                ", not {}".format(type(arg))
            )

        self._impl = arg._impl

    def __reduce__(self):
        raise TypeError("can't pickle {} objects".format(self.__class__.__name__))

    def copy(self):
        """Return a copy of itself."""
github aio-libs / multidict / multidict / _multidict_py.py View on Github external
def getversion(md):
    if not isinstance(md, _Base):
        raise TypeError("Parameter should be multidict or proxy")
    return md._impl._version