169: Renamed DictProxy to MagicDict

This commit is contained in:
Jason Gerard DeRose 2008-08-14 23:49:36 +00:00
parent 07cd537277
commit 88a5b3ae25
2 changed files with 10 additions and 10 deletions

View File

@ -492,11 +492,11 @@ class NameSpace(ReadOnly):
return '%s(<%d members>)' % (self.__class__.__name__, len(self)) return '%s(<%d members>)' % (self.__class__.__name__, len(self))
class DictProxy(ReadOnly): class MagicDict(ReadOnly):
""" """
A read-only dict whose items can also be accessed as attributes. A read-only dict whose items can also be accessed as attributes.
Although a DictProxy is read-only, the underlying dict can change (and is Although a MagicDict is read-only, the underlying dict can change (and is
assumed to). assumed to).
One of these is created for each allowed base in a `Registrar` instance. One of these is created for each allowed base in a `Registrar` instance.
@ -576,7 +576,7 @@ class Registrar(ReadOnly):
self.base = base self.base = base
self.name = base.__name__ self.name = base.__name__
self.sub_d = dict() self.sub_d = dict()
self.dictproxy = DictProxy(self.sub_d) self.dictproxy = MagicDict(self.sub_d)
lock(self) lock(self)
self.__allowed = allowed self.__allowed = allowed
@ -645,7 +645,7 @@ class Registrar(ReadOnly):
def __getitem__(self, key): def __getitem__(self, key):
""" """
Returns the DictProxy for plugins subclassed from the base named ``key``. Returns the MagicDict for plugins subclassed from the base named ``key``.
""" """
if key not in self.__d: if key not in self.__d:
raise KeyError('no base class named %r' % key) raise KeyError('no base class named %r' % key)

View File

@ -482,18 +482,18 @@ class test_NameSpace(ClassChecker):
no_set(ns, name) no_set(ns, name)
class test_DictProxy(ClassChecker): class test_MagicDict(ClassChecker):
""" """
Tests the `plugable.DictProxy` class. Tests the `plugable.MagicDict` class.
""" """
_cls = plugable.DictProxy _cls = plugable.MagicDict
def test_class(self): def test_class(self):
assert self.cls.__bases__ == (plugable.ReadOnly,) assert self.cls.__bases__ == (plugable.ReadOnly,)
for non_dict in ('hello', 69, object): for non_dict in ('hello', 69, object):
raises(AssertionError, self.cls, non_dict) raises(AssertionError, self.cls, non_dict)
def test_DictProxy(self): def test_MagicDict(self):
cnt = 10 cnt = 10
keys = [] keys = []
d = dict() d = dict()
@ -559,7 +559,7 @@ def test_Registrar():
for base in [Base1, Base2]: for base in [Base1, Base2]:
assert base.__name__ in r assert base.__name__ in r
dp = r[base.__name__] dp = r[base.__name__]
assert type(dp) is plugable.DictProxy assert type(dp) is plugable.MagicDict
assert len(dp) == 0 assert len(dp) == 0
# Check that TypeError is raised trying to register something that isn't # Check that TypeError is raised trying to register something that isn't
@ -573,7 +573,7 @@ def test_Registrar():
# Check that registration works # Check that registration works
r(plugin1) r(plugin1)
dp = r['Base1'] dp = r['Base1']
assert type(dp) is plugable.DictProxy assert type(dp) is plugable.MagicDict
assert len(dp) == 1 assert len(dp) == 1
assert r.Base1 is dp assert r.Base1 is dp
assert dp['plugin1'] is plugin1 assert dp['plugin1'] is plugin1