[Zope-dev] ZBabel Object incompatibility with Zope 2.5 b2

Joachim Werner joe@iuveno-net.de
Tue, 11 Dec 2001 18:07:04 +0100


Hi!

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
problems:



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:
            try:
                self._v_alreadyLooking = 1
                trueObject = self._getTrueObject()
                if hasattr(trueObject, name):
                    return Rewrapper((trueObject.getId(), name))      <=
HERE THE REWRAPPER IS CALLED
#                    return getattr(trueObject, name)

            finally:
                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:

http://cvs.iuveno-net.de/CVS/cvsweb.cgi/ZBabel/ZBabelObject.py

Joachim