[Zope] dictionary usage
Greg Steffensen
greg.steffensen at richmond.edu
Mon May 3 12:17:39 EDT 2004
I've been trying to roll my own RSS parsing in Zope by using Mark
Hammond's feedparser python module. I've been able to get it to
install it successfully, and have been able to get Zope to let Scripts
(Python) import it natively, by creating a new directory called
"Other" in the Products directory, and putting an __init__.py file in
it with the following 2 lines:
from Products.PythonScripts.Utility import allow_module
allow_module('feedparser')
Basically, the parser is supposed to return a dictionary containing
the rss feed information. If I create and run the following python
script:
import feedparser
uri = 'http://slashdot.org/slashdot.rdf'
return feedparser.parse(uri)
and click the "test" view in the ZMI, I see a single, REALLY long line
of text that is the string representation of the output dictionary
(the real output, with live data from slashdot). And this seems to be
a real dictionary, not just a string, because
len(feedparser.parse(uri)) returns 9. But I can't seem to access any
of the dictionary functionality, because when I try to, the ZMI keeps
asking me to log in again (even though I'm logged in as the site
manager), won't accept any of my login credentials (either site
manager or emergency user), and then, when I ultimately click
"cancel", tells my I don't have the authorization to access this
element in this context. For example, if I create and run the
following python script
import feedparser
data = feedparser.parse('http://slashdot.org/slashdot.rdf')
return data['channel']
I receive the error message "You are not authorized to access
'channel' in this context.". What's going on? Placing the
feedparser.parse() functionality in an external method doesn't help
either, I get the same results (viewing the top dictionary returns
shows a string representation of the dictionary, viewing any
subelement of the dictionary causes an "Unauthorized error).
Feedparser doesn't have any outside dependencies (at least, I
certainly didn't install any, and it works perfectly in the python
shell). Does Zope restrict the use of dictionaries somehow? Are
there some other access granting commands I should put in __init__.py
? I'm using Zope 2.7 with python 2.3 on linux. Any help is greatly
appreciated!
Greg Steffensen
More information about the Zope
mailing list