Zope REQUEST question

Terry Hancock hancock at anansispaceworks.com
Thu Apr 17 19:19:00 CEST 2003


Okay, this is a little tricky to explain.  This is technically a Zope 
question, but it has to do with programming products in Python.

I'm doing a Forbidden Thing with a Zope product, which is overloading its 
__getattr__ function.  It's a necessary Evil, though. ;-)

And actually, it works really well, as far as it goes.  It *is* a nightmare 
to debug, which is why I've moved nearly all of the code out of this part 
so it can be tested independently.

Anyway, it turns out, I need to be able to access the REQUEST object
from there (I'm trying to implement an HTTP_REFERER block).

So far, I've tried:

getattr(self, 'REQUEST')

and

ObjectManager.__getattr__(self, 'REQUEST')

which should do the same thing, except the ObjectManager.__getattr__ 
is much safer (it's not recursive).  I'm not sure why I thought that REQUEST
would be an attribute of the object at this point, but I'm pretty sure I 
read this somewhere and didn't just think it up out of thin air. However, 
in this case at least, it's wrong -- these both give me attribute errors 
(at least my object returns "not found" which is what happens when you
raise an attribute error from inside of __getattr__ -- other errors usually
give you the traceback you'd normally expect).

Does anyone have a better idea for how to get the REQUEST?

Cheers,
Terry

-- 
Terry Hancock
Anansi Spaceworks http://www.AnansiSpaceworks.com/





More information about the Python-list mailing list