[svn r63188] allow reversed retrieval of methods
--HG-- branch : trunk
This commit is contained in:
parent
4fe51e646c
commit
2aae6540ff
|
@ -120,7 +120,7 @@ class PyPlugins:
|
||||||
def isregistered(self, plugin):
|
def isregistered(self, plugin):
|
||||||
return plugin in self._plugins
|
return plugin in self._plugins
|
||||||
|
|
||||||
def listattr(self, attrname, plugins=None, extra=()):
|
def listattr(self, attrname, plugins=None, extra=(), reverse=False):
|
||||||
l = []
|
l = []
|
||||||
if plugins is None:
|
if plugins is None:
|
||||||
plugins = self._plugins
|
plugins = self._plugins
|
||||||
|
@ -131,6 +131,8 @@ class PyPlugins:
|
||||||
l.append(getattr(plugin, attrname))
|
l.append(getattr(plugin, attrname))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
|
if reverse:
|
||||||
|
l.reverse()
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def call_each(self, methname, *args, **kwargs):
|
def call_each(self, methname, *args, **kwargs):
|
||||||
|
|
|
@ -154,14 +154,18 @@ class TestPyPlugins:
|
||||||
def test_listattr(self):
|
def test_listattr(self):
|
||||||
plugins = PyPlugins()
|
plugins = PyPlugins()
|
||||||
class api1:
|
class api1:
|
||||||
x = 42
|
|
||||||
class api2:
|
|
||||||
x = 41
|
x = 41
|
||||||
|
class api2:
|
||||||
|
x = 42
|
||||||
|
class api3:
|
||||||
|
x = 43
|
||||||
plugins.register(api1())
|
plugins.register(api1())
|
||||||
plugins.register(api2())
|
plugins.register(api2())
|
||||||
|
plugins.register(api3())
|
||||||
l = list(plugins.listattr('x'))
|
l = list(plugins.listattr('x'))
|
||||||
l.sort()
|
assert l == [41, 42, 43]
|
||||||
assert l == [41, 42]
|
l = list(plugins.listattr('x', reverse=True))
|
||||||
|
assert l == [43, 42, 41]
|
||||||
|
|
||||||
def test_notify_anonymous_ordered(self):
|
def test_notify_anonymous_ordered(self):
|
||||||
plugins = PyPlugins()
|
plugins = PyPlugins()
|
||||||
|
|
Loading…
Reference in New Issue