blob: ef8e0a0296e26f34df4ab6ce75f0feb966708c2d [file] [log] [blame]
showard9484c312009-01-07 21:07:28 +00001#!/usr/bin/python
2
3import cgi, urllib2
4
5script = """\
6Content-Type: text/javascript
7
8%(callback)s(%(result)s);
9"""
10
11form = cgi.FieldStorage()
12path = form['path'].value
13callback = form['callback'].value
14
15try:
16 file_contents = urllib2.urlopen('http://localhost' + path).read()
17 escaped_contents = file_contents.replace(
18 '\\', '\\\\').replace( # get rid of backslashes
19 '"', r'\"').replace( # escape quotes
20 '\n', '\\n') # escape newlines
21 result = '{"contents" : "%s"}' % escaped_contents
22except urllib2.HTTPError:
23 result = '{"error" : "File not found"}'
24
25print script % dict(callback=callback, result=result)