You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2009/03/20 22:50:02 UTC
[Solr Wiki] Update of "SolPython" by MattGood
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.
The following page has been changed by MattGood:
http://wiki.apache.org/solr/SolPython
The comment on the change is:
add Python 2.6's "literal_eval" as a safe alternative to "eval"
------------------------------------------------------------------------------
print 'name field =', doc['name']
}}}
+ With Python 2.6 you can use the literal_eval function instead of eval. This only evaluates "safe" syntax for the built-in data types and not any executable code:
+ {{{
+ import ast
+ rsp = ast.literal_eval(conn.read())
+ }}}
+
== Using normal JSON ==
Using {{{eval}}} is generally considered bad form and dangerous in Python. In theory if you trust the remote server it is okay, but if something goes wrong it means someone can run arbitrary code on your server (attacking eval is very easy).