[Zope] __getitem__ and returning a PageTemplateFile instance

Dieter Maurer dieter at handshake.de
Thu Oct 20 15:43:24 EDT 2005


Anders Bruun Olsen wrote at 2005-10-20 11:52 +0200:
>On Wed, Oct 19, 2005 at 09:47:50PM +0200, Dieter Maurer wrote:
>> >Zope has encountered a problem publishing your object.
>> >Cannot locate object at: http://localhost:8080/vitester/asonhe 
>> This is a "NotFound" problem.
>>    Zope is unable to locate "vitester/asonhe"
>> Are you sure, "vitester/asonhe" is there?
>
>asonhe is not there, but vitester has a __getitem__ method which
>executes a PageTemplateFile instance and returns it. I.e.

Thus, it returns a string.

However, ZPublisher requires that all intermediate traversal
steps return an object which is not of a simple type and does
have a docstring. A string is a simple type, you cannot use it
during traversal...

>return self.test(self, self.REQUEST, value=value)
>(where self.test is a PageTemplateFile)

This results in a string (a simple type)...

>It actually works if I just do:
>
>return self.test.__of__(self)

This results in a "PageTemplateFile", which has a docstring
and is not of simple type.

>But that way I can't put any values in there. How can I do this then?

Can can return a wrapper and give it a docstring.

    class Wrapper:
      '''a wrapper around a string.''' # this is the docstring

      def __init__(self, str):
        self.str = str

      def __call__(self): return self.str

Some security declarations might be necessary as well.
Probably, a class attribute "__roles__ = None" is sufficient.

-- 
Dieter


More information about the Zope mailing list