From f531f7da81864f135ff1a5f7d69e15fbe8a27210 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 24 Sep 2008 23:49:44 +0000 Subject: 354: Added NameSpace.__todict__() method that returns copy of NameSpace.__map; updated NameSpace unit test to also test __todict__() --- ipalib/plugable.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'ipalib/plugable.py') diff --git a/ipalib/plugable.py b/ipalib/plugable.py index cd130a19..e1d728d4 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -545,13 +545,13 @@ class NameSpace(ReadOnly): def __len__(self): """ - Returns the number of members. + Return the number of members. """ return len(self.__members) def __iter__(self): """ - Iterates through the member names. + Iterate through the member names. If this instance was created with ``sort=True``, the names will be in alphabetical order; otherwise the names will be in the same order as @@ -564,7 +564,7 @@ class NameSpace(ReadOnly): def __call__(self): """ - Iterates through the members. + Iterate through the members. If this instance was created with ``sort=True``, the members will be in alphabetical order by name; otherwise the members will be in the @@ -577,13 +577,13 @@ class NameSpace(ReadOnly): def __contains__(self, name): """ - Returns True if namespace has a member named ``name``. + Return True if namespace has a member named ``name``. """ return name in self.__map def __getitem__(self, spec): """ - Returns a member by name or index, or returns a slice of members. + Return a member by name or index, or returns a slice of members. :param spec: The name or index of a member, or a slice object. """ @@ -597,7 +597,7 @@ class NameSpace(ReadOnly): def __repr__(self): """ - Returns a pseudo-valid expression that could create this instance. + Return a pseudo-valid expression that could create this instance. """ return '%s(<%d members>, sort=%r)' % ( self.__class__.__name__, @@ -605,6 +605,12 @@ class NameSpace(ReadOnly): self.__sort, ) + def __todict__(self): + """ + Return a copy of the private dict mapping name to member. + """ + return dict(self.__map) + class Registrar(DictProxy): """ -- cgit