How to use the wrapt.CallableObjectProxy function in wrapt

To help you get started, we’ve selected a few wrapt 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 bmabey / provenance / provenance / repos.py View on Github external
return ''.format(self.artifact.id, repr(self.__wrapped__))

    def __reduce__(self):
        return (load_proxy, (self.artifact.id,))

    def __reduce_ex__(self, protocol_version):
        return self.__reduce__()

    def __copy__(self):
        return ArtifactProxy(copy.copy(self.__wrapped__), self._self_artifact)

    def __deepcopy__(self, memo=None):
        return ArtifactProxy(copy.deepcopy(self.__wrapped__, memo), self._self_artifact)


class CallableArtifactProxy(wrapt.CallableObjectProxy, Proxy):

    def __init__(self, value, artifact):
        super(CallableArtifactProxy, self).__init__(value)
        self._self_artifact = artifact

    @property
    def artifact(self):
        return self._self_artifact

    def __repr__(self):
        return ''.format(self.artifact.id, repr(self.__wrapped__))

    def __reduce__(self):
        return (load_proxy, (self.artifact.id,))

    def __reduce_ex__(self, protocol_version):
github RussBaz / enforce / enforce / wrappers.py View on Github external
import typing

from wrapt import CallableObjectProxy, ObjectProxy

from .exceptions import RuntimeTypeError


class Proxy(CallableObjectProxy):
    """
    Transparent proxy with an option of attributes being saved on the proxy instance.
    """
    
    def __init__(self, wrapped):
        """
        By default, it acts as a transparent proxy
        """
        self._self_pass_through = True
        super().__init__(wrapped)

    def __setattr__(self, name, value):
        """
        Saves attribute on the proxy with a '_self_' prefix
        if '_self_pass_through' is NOT defined
        Otherwise, it is saved on the wrapped object