grizzled.proxy module
Overview
The grizzled.forwarder module contains classes that make building proxies
easier.
Classes
class Forwarder
The grizzled.forwarder.Forwarder class is intended to be used as
a mixin, to make it easier for classes to forward calls to another
class. T0 mix Forwarder into a class, simply include it as one of
the base classes.
WARNING: Forwarder intercepts calls to __getattr__, so
don't mix it in if your class is already overriding __getattr__.
Examples
Forward all unimplemented methods to a file:
from grizzled.forwarder import Forwarder class MyFileWrapper(Forwarder): def __init__(self, file): Forwarder.__init__(self, file) w = MyFileWrapper(open('/tmp/foo')) for line in w.readlines(): print(line)
Forward all unimplemented calls, except name, to the specified
object. Calls to name will raise an AttributeError:
from grizzled.forwarder import Forwarder class MyFileWrapper(Forwarder): def __init__(self, file): Forwarder.__init__(self, file, 'name')
Ancestors (in MRO)
- Forwarder
- builtins.object
Static methods
def __init__(
self, wrapped, *exceptions)
Initialize a new Forwarder that will pass unimplemented calls
(method calls, attribute accesses, etc.) to the specified object.
Parameters
wrapped(object): the object to which to pass unknown attributesexceptions(stror sequence ofstr): one or more names (as separate arguments) of methods that should not be intercepted (and will, therefore, result inAttributeErrorexceptions if invoked, absent any other intervention).