Permalink
Browse files

start tearing things apart to make a proper wsgi enabled version of w…

…scompose/pinwin
  • Loading branch information...
1 parent abf1b2c commit a2bc914c89f89a85c7b2b4cb8d4e3d11a16833dd straup committed Apr 23, 2011
Showing with 268 additions and 263 deletions.
  1. +45 −0 wscompose/WSGIComposeServer.py
  2. +181 −263 wscompose/__init__.py
  3. +42 −0 wscompose/help.py
@@ -0,0 +1,45 @@
+import urlparse
+import wscompose
+
+def application(environ, start_response):
+
+ # path_info = environ.get('PATH_INFO', None)
+
+ query_string = environ.get('QUERY_STRING', None)
+ params = urlparse.parse_qs(query_string)
+
+ ws = wscompose.wscompose()
+
+ try:
+
+ if len(params.keys()) == 0:
+
+ status = '200 OK'
+ content_type = 'text/plain'
+ data = ws.help()
+
+ else:
+
+ ws.load_ctx(params)
+
+ status = '200 OK'
+ content_type = 'text/plain'
+ data = str(params)
+
+ except Exception, e:
+
+ print >> environ['wsgi.errors'], "[gunistache] failed to handle request:" + str(e)
+ status = '500 SERVER ERROR'
+ content_type = 'text/plain'
+ data = str(e)
+
+ # mod_wsgi hates unicode apparently
+ # so make sure everything is a str.
+
+ response_headers = [
+ ('Content-type', str(content_type)),
+ ('Content-Length', str(len(data)))
+ ]
+
+ start_response(status, response_headers)
+ return iter([data])
Oops, something went wrong.

0 comments on commit a2bc914

Please sign in to comment.