[Zope3-dev] Re: RFC: The browser:page compromise

Tres Seaver tseaver at palladion.com
Thu Apr 20 13:18:56 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Philipp von Weitershausen wrote:
> http://dev.zope.org/Zope3/TheBrowserPageCompromise
> 
> I've long been thinking about how to make <browser:page /> simpler and
> less magical. Some radical ideas weren't received well and I couldn't
> convince even myself 100% that they were the way to go. Other
> brainstormings were dead ends.
> 
> I therefore call this proposal a compromise. It simplifies, but it
> shouldn't annoy (Tres...). Note that I'm specifically only addressing
> <browser:page />, not <browser:view />; nor am I coming up with a
> framework for dealing with forms and their handlers (Jeff...).
> 
> 'Nuff said. Your turn :)

- -1 on breaking ZCML in the wild.  Propose *new* directives which have
new semantics, but for existing directives, we should clean up the
implementation rather than modifying semantics.  E.g., we should be able
to rip out the gunk which synthesizes new classes in 'browser:page':   I
think it derives from a period before we could assign a
'__Security_checker__' attribute to instances, and so *had* to have a
class in order to make the checker stuff work.

Here is an example from my 'pushpage' product, which has a directive for
registering pages using filesystem templates::

  class PushPageFactory:

      def __init__(self, template, mapper, checker=None):
          if getattr(template, 'read', None) is not None:
              template = template.read()
          self.template = PushPageTemplate()
          self.template.write(template)
          self.mapper = mapper
          self.checker = checker

      def __call__(self, context, request):
          page = PushPage(context, request, self.template, self.mapper)
          if self.checker is not None:
              page.__Security_checker__ = self.checker
          return page


The directive handler instantiates the factory::

  def pushpageViewDirective(_context,
                            for_,
                            name,
                            permission,
                            template,
                            mapping,
                            layer=IDefaultBrowserLayer,
                           ):
      """ Create and register factory for pushpage-driven views.
      """
      if for_ is not None:
          _context.action(
              discriminator = None,
              callable = provideInterface,
              args = ('', for_)
              )

      if permission == 'zope.Public':
          permission = CheckerPublic

      template = os.path.abspath(str(_context.path(template)))
      if not os.path.isfile(template):
          raise ConfigurationError("No such file", template)

      required = {'__call__': permission,
                  '__getitem__': permission,
                  'browserDefault': permission,
                  'publishTraverse': permission,
                 }

      checker = Checker(required)

      factory = PushPageFactory(open(template, 'r'), mapping, checker)

      _context.action(
          discriminator = ('view', for_, name, IBrowserRequest, layer),
          callable = handler,
          args = ('provideAdapter',
                  (for_, layer), Interface, name, factory,
                  _context.info),
          )


Note this implementation does not require majyk classes -- the factory
instances here function in place of the synthesize classes.



Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFER8KA+gerLs4ltQ4RAh0kAJ9vvKtqAcPfZh0+2ujqpJefWGgsFQCeNzhi
r8E8Ewhpv/aJdP0t20vpZok=
=Z27s
-----END PGP SIGNATURE-----



More information about the Zope3-dev mailing list