This time I need some specialists to help ...

Here is some code from ZBabel Objects. ZBabel objects are folders that hold
localized versions of anything you want to internationalize and pass getting
attributes and calling objects to one of these localized versions depending
on your language choice.

In Zope 2.4 this works fine. But with Zope 2.5 b2 there are recursion

class ZBabelObject(Folder):
    '''ZBabelObject class '''


    def __getattr__(self, name):
        '''__getattr__(self, name) --> try to get an attribute from the
localized object; return attr'''
        if name[0] != '_' and not self._v_alreadyLooking:
                self._v_alreadyLooking = 1
                trueObject = self._getTrueObject()
                if hasattr(trueObject, name):
                    return Rewrapper((trueObject.getId(), name))      <=
#                    return getattr(trueObject, name)

                self._v_alreadyLooking = 0

        return Base.__getattr__(self, name)

Look at the code above: the __getattr__ code calls the Rewrapper to make
sure that the object gets the right context. If you replace the line by the
commented-out one, the attributes work, but calling the object will not
work. E.g., an image width or height will be passed fine, but calling the
image will cause an authorization request even for managers. It seems as
though __call__ will look for some security assertions via __getattr__ (?),
but can't find them due to the missing wrapper. I have no clue.

Here is the Rewrapper code:

class Rewrapper(Base):

    def __init__(self, path):
        self._path = path

    def __of__(self, parent):
        ob = parent
        for p in self._path:
            ob = getattr(ob, p)   <= HERE WE GET A RECURSION ERROR
        return ob

When the code is run unchanged with 2.5, we get an infinite recursion (well,
Zope halts it after a few recursions) at the marked line, which is bad.

Does anybody have a clue why that happens NOW, and what has change in that
respect from 2.4 to 2.5?

Maybe there are alternative implementations? The aim is that the localized
object just behaves like a normal image, DTML Method, whatever, but actually
maps to different contained object versions.

BTW: The full code is available here:



Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to