[svn r63188] allow reversed retrieval of methods

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-21 16:14:22 +01:00
parent 4fe51e646c
commit 2aae6540ff
2 changed files with 11 additions and 5 deletions

View File

@ -120,7 +120,7 @@ class PyPlugins:
def isregistered(self, plugin):
return plugin in self._plugins
def listattr(self, attrname, plugins=None, extra=()):
def listattr(self, attrname, plugins=None, extra=(), reverse=False):
l = []
if plugins is None:
plugins = self._plugins
@ -131,6 +131,8 @@ class PyPlugins:
l.append(getattr(plugin, attrname))
except AttributeError:
continue
if reverse:
l.reverse()
return l
def call_each(self, methname, *args, **kwargs):

View File

@ -154,14 +154,18 @@ class TestPyPlugins:
def test_listattr(self):
plugins = PyPlugins()
class api1:
x = 42
class api2:
x = 41
class api2:
x = 42
class api3:
x = 43
plugins.register(api1())
plugins.register(api2())
plugins.register(api3())
l = list(plugins.listattr('x'))
l.sort()
assert l == [41, 42]
assert l == [41, 42, 43]
l = list(plugins.listattr('x', reverse=True))
assert l == [43, 42, 41]
def test_notify_anonymous_ordered(self):
plugins = PyPlugins()