[Twisted-Python] Question about plugins tutorial
Tristan Seligmann
mithrandi-twisted-python at mithrandi.za.net
Wed Apr 4 14:10:30 MDT 2007
* Brian Costlow <brian.costlow at gmail.com> [2007-04-04 10:37:20 -0400]:
> # plugin
> class Foo(object):
> implements(IPlugin, imyplugins.IMyPlugIn)
>
> def fooStuff(self):
> # do foo stuff
>
> def fooFactory(self):
> return Foo()
>
> f = Foo()
> # end plugin
>
> #call plugin from app
> for n in getPlugins(imyplugins.IMyPlugIn):
> o = n.fooFactory()
> o.fooStuff()
>
>
> Does this make sense? Is there a better way in the twisted framework
> to handle this?
The other replies to your posts raise some good points, but I would just
like to point out that classes themselves can be used as plugins. For
example:
class Foo(object):
classProvides(IPlugin, IMyPlugin):
def fooStuff(self):
"""Does foo stuff."""
for cls in getPlugins(IMyPlugin):
o = cls()
o.fooStuff()
--
mithrandi, i Ainil en-Balandor, a faer Ambar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: </pipermail/twisted-python/attachments/20070404/add198e0/attachment.sig>
More information about the Twisted-Python
mailing list