[Grok-dev] grokcore.component and trusted adapters

Christian Zagrodnick cz at gocept.com
Thu Aug 6 09:57:55 EDT 2009


Hoi,

constantly I require trusted adapters.

Normally adapters are untrusted, that is, the adapt's self.context is
security proxied, the adapter itself is not. Trusted adapters on the
contrary have an unproxied self.context, but the adapters are
*themselves* proxied.

Now in ZCML that was easy:

	<adapter … trusted="yes" />

With grokcore.component that's not possible. It also doesn't belong
there, as grokcore.component doesn't know about security. I suppose
support for trusted adapters should be put to grokcore.security. So my
favourite spelling would be:

	class Adapter(grokcore.component.Adapter):
		grokcore.component.context(ISomething)
		gokcore.component.implements(ISomethingElse)
		grokcore.security.trusted()


But it doesn't seem to be easily possible to implement. Somebody got an
idea? Other comments?


BTW: meanwhile I helped myself with a base class and __new__. But I
don't quite like that:


class Adapter(grokcore.component.Adapter):

    grokcore.component.baseclass()

    def __new__(cls, context):
        # Trusted adapter
        instance = object.__new__(cls)
        if zope.security.proxy.removeSecurityProxy(context) is context:
            # Context is unwrapped. Basically do nothing special here.
            wrap = lambda x: x
        else:
            # Context is wrapped. Unwrap and wrap adapter
            wrap = zope.security.proxy.ProxyFactory
            context = zope.security.proxy.removeSecurityProxy(context)
        instance.__init__(context)
        return wrap(instance)



-- 
Christian Zagrodnick · cz at gocept.com
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 4 · fax +49 345 1229889 1
Zope and Plone consulting and development




More information about the Grok-dev mailing list