Skip to content

Instantly share code, notes, and snippets.

@def
Created November 10, 2010 09:58
Show Gist options
  • Save def/670633 to your computer and use it in GitHub Desktop.
Save def/670633 to your computer and use it in GitHub Desktop.
from gevent import http
import psyco_gevent
psyco_gevent.make_psycopg_green()
from psycopg2.pool import SimpleConnectionPool
dsn = 'dbname=test host=127.0.0.1 port=5433 user=test password=123'
dbpool = SimpleConnectionPool(10,15,dsn)
def handler(request):
if request.uri.startswith('/recall/'):
hash = request.uri.split('/')[2]
conn = dbpool.getconn()
cur = conn.cursor()
cur.execute("select content from snapshot where hash='%s';" % hash)
resp = cur.fetchone()
dbpool.putconn(conn)
if resp:
request.add_output_header('Content-Type', 'text/xml')
request.send_reply(200,'OK', '%s' % resp)
else:
request.send_reply(404, "Not Found", "<h1>Not Found</h1>")
else:
request.add_output_header('Content-Type', 'text/html')
request.send_reply(404, "Not Found", "<h1>Not Found</h1>")
print 'Serving on 8088...'
http.HTTPServer(('0.0.0.0', 8088), handler).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment