[Zope] Some __bobo_traverse__ help

Garito garito at sistes.net
Sat Mar 24 23:02:08 EDT 2007


Hi!
Some one could help me to construct a correct __bobo_traverse__ or wrapper
for my necesities.

The clues:

I have this model of __bobo_traverse__:

def __bobo_traverse__(self, REQUEST, nombre):
        obj = getattr(self, nombre, None)
        if obj is None:
            self.REQUEST.set('TraversalRequestNameStack',
self.REQUEST["TraversalRequestNameStack"]
+ [nombre])
            if hasattr(self, 'index.html'): return getattr(self, 'index.html
')
            else:
                resultado = self.__call__()
                if type(resultado) == type(unicode()): return
WrapperUnicode(resultado)
                elif type(resultado) == type(str()): return
WrapperStr(resultado)
                elif type(resultado) == type(dict()): return
WrapperDict(resultado)
                else: return resultado
        return obj

With this Wrapper classes:

class WrapperStr(str):
    """ """
    __roles__ = None

    def __bobo_traverse__(self, REQUEST, nombre):
        obj = getattr(self, nombre, None)
        if obj is None: return self
        else: return obj

class WrapperUnicode(unicode):
    """ """
    __roles__ = None

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

    def __bobo_traverse__(self, REQUEST, nombre):
        obj = getattr(self, nombre, None)
        if obj is None: return self
        else: return obj.__of__(self)

    def __call__(self):
        return self.cadena

    def __str__(self):
        return str(self.cadena.decode('latin-1'))

class WrapperDict(dict):
    """ """
    __roles__ = None

    def __bobo_traverse__(self, REQUEST, nombre):
        obj = getattr(self, nombre, None)
        if obj is None: return self
        else: return obj

With this version I have the security problem I'm asking this days. The last
opinion was the Wrapper classes are the problem but you could see the
wrappers I can do with the information I have

But if I change the __bobo_traverse__ to this:

def __bobo_traverse__(self, REQUEST, nombre):
        obj = getattr(self, nombre, None)
        if obj is None:
            self.REQUEST.set('TraversalRequestNameStack',
self.REQUEST["TraversalRequestNameStack"]
+ [nombre])
            if hasattr(self, 'index.html'): return getattr(self, 'index.html
')
            else:
                obj = getattr(self, 'lanzador', None)
        return obj

Where lanzador is a page template with this code:

<tal:b tal:replace='structure here' />

Then it works perfect!! (we can conclude, then, that Martijn has good clues
about the problem, thanks again!)

Here my petition of help:

Could someone explain or point me to how the wrappers need to be? I don't
like so much the idea that all my work depends on a page template with 1
line of code if I could implement it at product code

Thank you!

-- 
Mis Cosas
http://blogs.sistes.net/Garito
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20070325/c5de00b4/attachment.htm


More information about the Zope mailing list