On Thu, Feb 12, 2009 at 07:28:23PM +0100, Sebastian Bartos wrote:
> Was playing with the event system a bit, and ended up with the
> following, which works fine:
> import zope.event
> class MyEvent:
>     pass
> event = MyEvent()
> def f(event):
>     if isinstance(event, zope.app.appsetup.interfaces.ProcessStarting):
>         """Put stuff you want to execute after server startup here. """
>         principalPermissionManager.grantAllPermissionsToPrincipal("use")
> zope.event.subscribers.append(f)
> ...
> Is this a good zopey way?

An emphatic No.  This slows down the processing of every event by
performing an extra function call and an if statement, instead of using
a hash-driven dispatch that zope.component provides for subscribers.

The <subscriber /> ZCML directive is a good Zopey way.  ZCML:

  <subscriber handler=".module.grantStuffOnStartup" />


  def grantStuffOnStartup(event):

Also, if you're hardcoding the principal ID here, you might as well just
do it in ZCML:

  <grantAll principal="use" />

and if you're not hardcoding/want to be able to adjust the grant later
through the web, you should really use the IPrincipalRoleMap adapter on
the root folder that will store the grant persistently in the DB rather
than in memory.

Marius Gedminas
There is an almost obvious extension of interfaces that would allow formal
specification of arguments and return values.  We suspect it leads to the dark
        -- Jim Fulton

Attachment: signature.asc
Description: Digital signature

Zope3-users mailing list

Reply via email to