From b28f0c0694a32a49e5a2d83b18038c6f2aae131c Mon Sep 17 00:00:00 2001 From: Louis Sobel Date: Wed, 18 Apr 2012 00:04:49 -0400 Subject: [PATCH] Tightened up sessions, added redirects and setting headers from dbpy --- drapache/dbapiserver.py | 2 +- drapache/dbpybuiltins.py | 23 +++++++++++++++++++++++ drapache/dbpyexecute.py | 1 + requirements.txt | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drapache/dbapiserver.py b/drapache/dbapiserver.py index eeca76a..baed243 100644 --- a/drapache/dbapiserver.py +++ b/drapache/dbapiserver.py @@ -63,7 +63,7 @@ def serve(self,path): #first check if it doesn't end with a slash if not path.endswith('/'): redirect_location = path+'/' - if self.query_string: + if self.request.query_string: redirect_location += '?'+self.request.query_string return ResponseObject(301,'redirect',headers={'Location':redirect_location}) diff --git a/drapache/dbpybuiltins.py b/drapache/dbpybuiltins.py index 8389c2e..83c68e1 100644 --- a/drapache/dbpybuiltins.py +++ b/drapache/dbpybuiltins.py @@ -17,6 +17,8 @@ import dropbox import os.path + +import markdown import StringIO @@ -230,6 +232,27 @@ def start_session(): def destroy_session(): session.destroy() + @register + def set_response_header(key,value): + response.set_header(key,value) + + @register + def set_response_status(status): + response.status = status + + @register + def redirect(where,immediately=True): + set_response_status(302) + set_response_header('Location',where) + + if immediately: + die("redirecting") + + + @register + def markdown_to_html(markdown_string): + return markdown.markdown(markdown_string) + @register def pretty_print(thingy,pre=True): """ diff --git a/drapache/dbpyexecute.py b/drapache/dbpyexecute.py index a932ef9..5034216 100644 --- a/drapache/dbpyexecute.py +++ b/drapache/dbpyexecute.py @@ -18,6 +18,7 @@ import sandbox as pysandbox from util import ResponseObject import dbpybuiltins + import dbapiio class Timeout(Exception): diff --git a/requirements.txt b/requirements.txt index 5e78259..26d6cd3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,8 @@ dropbox==1.3 -e git+git://github.com/haypo/pysandbox.git#egg=sandbox +markdown +beaker + ### only needed if using mysql for the subdomain list #Mysql-python