KU of Decorator

gzip.GzipFile decorates a file with compress/decompress functionality

0 threading.RLock decorates thread.Lock with reentrancy & ownership functionality

0 codecs classes decorate a file with generic encoding and decoding functionality

Proxy client code y needs to access an object t

0 however, something interferes w/that...: & t lives remotely, or in persisted form « access restrictions may apply (security) & lifetime or performance issues 0 proxy object tt "sneaks in the middle": 0 tt wraps t, may create/delete it at need 0 may intercept, call, delegate, ... 0 y uses tt as it would use t

Toy Example Proxy class RestrictingProxy(object):

self._makeit = f, a, k self._block = block def __getattr__(self, name):

if name in self._block:

raise AttributeError, name if not hasattr(self, '_wrapped'): f, a, k = self._makeit self._wrapped = f(*a, **k) return getattr(self.„wrapped, name)

KU of Proxy the values in a shelve.Shelf proxy for persisted objects (get instantiated at need)

0 weakref.proxy proxies for any existing object but doesn't "keep it alive"

0 idlelib.RemoteDebagger uses proxies (for frames, code objects, dicts, and a debugger object) across RPC to let a Python process be debugged from a separate GUI process

Was this article helpful?

0 0

Post a comment