Access error trying to use pyRXP example wrapper from an external method
Hi all, I'm a bit rusty on Zope and Python (was never that good to start with...), and I was hoping to be able to do something quick this evening but I've hit a brick wall. I have the following very simple external method: def niceXML(XMLstring): import pyRXP import xmlutils tree = pyRXP.Parser().parse(XMLstring) return xmlutils.TagWrapper(tree) pyRXP is the parser provided by the ReportLab folks. I had used their example xmlutils wrapper before in straight Python and rather liked it, so I wanted to use it from Zope using the external method above. However, although I can call the external method and get the wrapper object from Zope, everytime I try to use the object within Zope (e.g. object[0], object.TagName, etc.), Zope returns the error "Not allowed to access <0, or TagName, or etc.> in this context". I assume it has something to do with how the xmlutils wrapper works, but I haven't dared look at the code yet. Anybody has any pointer as to what might be wrong here to make my troubleshooting job a bit easier (and faster!)? Thanks ahead, Jean
Well, allright, I did have a peek in the xmlutils code, and I guess the issue is that the TagWrapper class redefines such things as __len__ and __getitem__ to do its thing. I'm guessing that's what Zope's security mechanism doesn't like, but I have no clue how to fix it, so hints would still be appreciated! BTW, I have tested pyRXP and xmlutils in the Python shell, and they work fine from there. -- Jean Jean Lagarde wrote:
Hi all,
I'm a bit rusty on Zope and Python (was never that good to start with...), and I was hoping to be able to do something quick this evening but I've hit a brick wall. I have the following very simple external method:
def niceXML(XMLstring):
import pyRXP import xmlutils
tree = pyRXP.Parser().parse(XMLstring)
return xmlutils.TagWrapper(tree)
pyRXP is the parser provided by the ReportLab folks. I had used their example xmlutils wrapper before in straight Python and rather liked it, so I wanted to use it from Zope using the external method above. However, although I can call the external method and get the wrapper object from Zope, everytime I try to use the object within Zope (e.g. object[0], object.TagName, etc.), Zope returns the error "Not allowed to access <0, or TagName, or etc.> in this context". I assume it has something to do with how the xmlutils wrapper works, but I haven't dared look at the code yet.
Anybody has any pointer as to what might be wrong here to make my troubleshooting job a bit easier (and faster!)?
Thanks ahead,
Jean
Never mind, figured it out. The key was to put __allow_access_to_unprotected_subobjects__=1 in the TagWrapper class definition Cheers, Jean
On Mon, Dec 09, 2002 at 08:32:51PM -0800, Jean Lagarde wrote: object[0], object.TagName, etc.), Zope returns the error "Not allowed to
access <0, or TagName, or etc.> in this context". I assume it has something to do with how the xmlutils wrapper works, but I haven't dared look at the code yet.
Not sure if this is your problem, but: Any attributes or methods you call in Zope must be allowed by the Zope security mechanisms; anything that has no security declarations is assumed to be disallowed. But if you set a class variable __allow_access_to_unprotected subobjects__ = 1 ... you can quickly get around that limitation. -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
participants (2)
-
Jean Lagarde -
Paul Winkler