[Twisted-Python] Question about plugins tutorial

Christopher Armstrong radix at twistedmatrix.com
Wed Apr 4 08:46:33 MDT 2007


On 4/4/07, Brian Costlow <brian.costlow at gmail.com> wrote:
> But I'm looking at the Plugins as a way to abstract multiple back-end
> actions taken in response to data recieved by a number of asynchronous
> events (off of LineReciever and XML-RPC). The plug-in is going to need
> to keep some intermediate state data in some cases, which won't work
> if they all get the same object. So I was thinking of something along
> these lines:
>
> # 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?

Yep: making your plugins factories is a common pattern. There's also
often a conditional checking something about 'n' before calling the
fooFactory on it (for example, is it the one the user requested by
name? etc)

-- 
Christopher Armstrong
International Man of Twistery
http://radix.twistedmatrix.com/
http://twistedmatrix.com/
http://canonical.com/




More information about the Twisted-Python mailing list