176: PluginProxy now subclasses from SetProxy

This commit is contained in:
Jason Gerard DeRose 2008-08-15 03:41:17 +00:00
parent 233293fb4a
commit db8099febc
2 changed files with 9 additions and 17 deletions

View File

@ -351,7 +351,7 @@ class Plugin(ReadOnly):
) )
class PluginProxy(ReadOnly): class PluginProxy(SetProxy):
""" """
Allows access to only certain attributes on a `Plugin`. Allows access to only certain attributes on a `Plugin`.
@ -390,8 +390,8 @@ class PluginProxy(ReadOnly):
self.__public__ = base.__public__ self.__public__ = base.__public__
self.name = getattr(target, name_attr) self.name = getattr(target, name_attr)
self.doc = target.doc self.doc = target.doc
lock(self)
assert type(self.__public__) is frozenset assert type(self.__public__) is frozenset
super(PluginProxy, self).__init__(self.__public__)
def implements(self, arg): def implements(self, arg):
""" """
@ -411,31 +411,23 @@ class PluginProxy(ReadOnly):
""" """
return self.__class__(self.__base, self.__target, name_attr) return self.__class__(self.__base, self.__target, name_attr)
def __iter__(self):
"""
Iterates (in ascending order) though the attribute names this proxy is
allowing access to.
"""
for name in sorted(self.__public__):
yield name
def __getitem__(self, key): def __getitem__(self, key):
""" """
If this proxy allows access to an attribute named `key`, return that If this proxy allows access to an attribute named ``key``, return that
attribute. attribute.
""" """
if key in self.__public__: if key in self.__public__:
return getattr(self.__target, key) return getattr(self.__target, key)
raise KeyError('no proxy attribute %r' % key) raise KeyError('no public attribute %r' % key)
def __getattr__(self, name): def __getattr__(self, name):
""" """
If this proxy allows access to an attribute named `name`, return that If this proxy allows access to an attribute named ``name``, return
attribute. that attribute.
""" """
if name in self.__public__: if name in self.__public__:
return getattr(self.__target, name) return getattr(self.__target, name)
raise AttributeError('no proxy attribute %r' % name) raise AttributeError('no public attribute %r' % name)
def __call__(self, *args, **kw): def __call__(self, *args, **kw):
""" """

View File

@ -410,14 +410,14 @@ class test_Plugin(ClassChecker):
raises(AssertionError, sub.finalize, api) raises(AssertionError, sub.finalize, api)
class test_Proxy(ClassChecker): class test_PluginProxy(ClassChecker):
""" """
Tests the `plugable.PluginProxy` class. Tests the `plugable.PluginProxy` class.
""" """
_cls = plugable.PluginProxy _cls = plugable.PluginProxy
def test_class(self): def test_class(self):
assert self.cls.__bases__ == (plugable.ReadOnly,) assert self.cls.__bases__ == (plugable.SetProxy,)
def test_proxy(self): def test_proxy(self):
# Setup: # Setup: