[Zope] Mark Pilgrim's Feed Parser in Zope

Jonathan dev101 at magma.ca
Wed Jul 26 18:17:11 EDT 2006


<snip>
I found a way to test if the "ExternalMethod" really returned a dict here:

http://infrae.com/mailman_/pipermail/silva-dev/2004q2/001091.html

And you were right! This is not seen as as a valid dictionary (nor is it
seen as a string):

stuff = container.externalmethod(feedurl=feedurl)
test = same_type(stuff, {})
print test
return printed

returns "0"

However, interestingly enough, if I copy and paste the all the text that
is returned by the external method into the script, I am able to confirm
that it is a dictionary:

stuff= {'lastbuilddate': u'Mon, 24 Jul 2006 12:06:18 EDT', u'subtitle': 
'U.S.',
u'generator': 'NPR/RSS Generator 2.0 etc...'}

test = same_type(stuff, {})
print test
return printed

returns "1"

Also, I tried to render the copied text from the external method using the
page template, and received a different error message:

"TypeError: string indices must be integers" (see the attached traceback).

I don't know if this last test will be useful, but I thought I'd give it
a try.

Do you know if there is a way of changing the data type of an object?

Do you know if there is a listing of data types that I could test for?
</snip>

There is an easy, but potentially dangerous way to turn a string 
representative of a python dictionary back into a 'real' python 
dictionary... only do this if you are sure of the contents of the 
dictionary:  in an external method:

def string2dict(instr):
        dict = {}
        dict['__builtins__'] = None
        return eval(instr, dict)


hth

Jonathan




Thanks kindly,

John T.





--------------------------------------------------------------------------------


> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
> 



More information about the Zope mailing list