diff options
author | Sean B. Palmer <sbp@aldebaran.local> | 2010-11-13 11:55:04 +0000 |
---|---|---|
committer | Sean B. Palmer <sbp@aldebaran.local> | 2010-11-13 11:55:04 +0000 |
commit | 5ebe01386d46f0a3a50b2b02416d8e7ee222af7e (patch) | |
tree | 7128595c9a945d507f47d8177d8871ddc88169dc /modules/search.py | |
parent | ca95157acbe6e340573130e45a851b39e547159d (diff) | |
download | bot-5ebe01386d46f0a3a50b2b02416d8e7ee222af7e.tar.gz bot-5ebe01386d46f0a3a50b2b02416d8e7ee222af7e.tar.bz2 bot-5ebe01386d46f0a3a50b2b02416d8e7ee222af7e.zip |
Services fixes, and a standard JSON API.
Diffstat (limited to 'modules/search.py')
-rwxr-xr-x | modules/search.py | 13 |
1 files changed, 1 insertions, 12 deletions
diff --git a/modules/search.py b/modules/search.py index df7ce65..7a0e3ad 100755 --- a/modules/search.py +++ b/modules/search.py @@ -10,23 +10,12 @@ http://inamidst.com/phenny/ import re import web -r_string = re.compile(r'("(\\.|[^"\\])*")') -r_json = re.compile(r'^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]+$') -env = {'__builtins__': None, 'null': None, 'true': True, 'false': False} - -def json(text): - """Evaluate JSON text safely (we hope).""" - if r_json.match(r_string.sub('', text)): - text = r_string.sub(lambda m: 'u' + m.group(1), text) - return eval(text.strip(' \t\r\n'), env, {}) - raise ValueError('Input must be serialised JSON.') - def search(query): """Search using AjaxSearch, and return its JSON.""" uri = 'http://ajax.googleapis.com/ajax/services/search/web' args = '?v=1.0&safe=off&q=' + web.urllib.quote(query.encode('utf-8')) bytes = web.get(uri + args) - return json(bytes) + return web.json(bytes) def result(query): results = search(query) |