diff --git a/couchdbkit/version.py b/couchdbkit/version.py index b871467..e5f66a3 100644 --- a/couchdbkit/version.py +++ b/couchdbkit/version.py @@ -5,5 +5,5 @@ from __future__ import absolute_import from six.moves import map -version_info = (0, 9, 0, 3, 8) +version_info = (0, 9, 1) __version__ = ".".join(map(str, version_info)) diff --git a/couchdbkit/wsgi/__init__.py b/couchdbkit/wsgi/__init__.py deleted file mode 100644 index 21d0b7c..0000000 --- a/couchdbkit/wsgi/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 - -# -# This file is part of couchdbkit released under the MIT license. -# See the NOTICE for more information. - - diff --git a/couchdbkit/wsgi/handler.py b/couchdbkit/wsgi/handler.py deleted file mode 100644 index 20e8d1d..0000000 --- a/couchdbkit/wsgi/handler.py +++ /dev/null @@ -1,133 +0,0 @@ -# -*- coding: utf-8 - -# -# This file is part of couchdbkit released under the MIT license. -# See the NOTICE for more information. - -from __future__ import absolute_import -import sys -import StringIO -import traceback -from six.moves.urllib.parse import unquote - -from restkit.util import url_encode - -from .. import __version__ -from ..external import External - -def _normalize_name(name): - return "-".join([w.lower().capitalize() for w in name.split("-")]) - -class WSGIRequest(object): - - SERVER_VERSION = "couchdbkit/%s" % __version__ - - def __init__(self, line): - self.line = line - self.response_status = 200 - self.response_headers = {} - self.start_response_called = False - - def read(self): - headers = self.parse_headers() - - length = headers.get("CONTENT_LENGTH") - if self.line["body"] and self.line["body"] != "undefined": - length = len(self.line["body"]) - body = StringIO.StringIO(self.line["body"]) - - else: - body = StringIO.StringIO() - - # path - script_name, path_info = self.line['path'][:2], self.line['path'][2:] - if path_info: - path_info = "/%s" % "/".join(path_info) - else: - path_info = "" - script_name = "/%s" % "/".join(script_name) - - # build query string - args = [] - query_string = None - for k, v in self.line["query"].items(): - if v is None: - continue - else: - args.append((k,v)) - if args: query_string = url_encode(dict(args)) - - # raw path could be useful - path = "%s%s" % (path_info, query_string) - - # get server address - if ":" in self.line["headers"]["Host"]: - server_address = self.line["headers"]["Host"].split(":") - else: - server_address = (self.line["headers"]["Host"], 80) - - environ = { - "wsgi.url_scheme": 'http', - "wsgi.input": body, - "wsgi.errors": StringIO.StringIO(), - "wsgi.version": (1, 0), - "wsgi.multithread": False, - "wsgi.multiprocess": True, - "wsgi.run_once": False, - "SCRIPT_NAME": script_name, - "SERVER_SOFTWARE": self.SERVER_VERSION, - "COUCHDB_INFO": self.line["info"], - "COUCHDB_REQUEST": self.line, - "REQUEST_METHOD": self.line["verb"].upper(), - "PATH_INFO": unquote(path_info), - "QUERY_STRING": query_string, - "RAW_URI": path, - "CONTENT_TYPE": headers.get('CONTENT-TYPE', ''), - "CONTENT_LENGTH": length, - "REMOTE_ADDR": self.line['peer'], - "REMOTE_PORT": 0, - "SERVER_NAME": server_address[0], - "SERVER_PORT": int(server_address[1]), - "SERVER_PROTOCOL": "HTTP/1.1" - } - - for key, value in headers.items(): - key = 'HTTP_' + key.replace('-', '_') - if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): - environ[key] = value - - return environ - - def start_response(self, status, response_headers): - self.response_status = int(status.split(" ")[0]) - for name, value in response_headers: - name = _normalize_name(name) - self.response_headers[name] = value.strip() - self.start_response_called = True - - def parse_headers(self): - headers = {} - for name, value in self.line.get("headers", {}).items(): - name = name.strip().upper().encode("utf-8") - headers[name] = value.strip().encode("utf-8") - return headers - -class WSGIHandler(External): - - def __init__(self, application, stdin=sys.stdin, - stdout=sys.stdout): - External.__init__(self, stdin=stdin, stdout=stdout) - self.app = application - - def handle_line(self, line): - try: - req = WSGIRequest(line) - response = self.app(req.read(), req.start_response) - except: - self.send_response(500, "".join(traceback.format_exc()), - {"Content-Type": "text/plain"}) - return - - content = "".join(response).encode("utf-8") - self.send_response(req.response_status, content, req.response_headers) - - diff --git a/couchdbkit/wsgi/proxy.py b/couchdbkit/wsgi/proxy.py deleted file mode 100644 index a858286..0000000 --- a/couchdbkit/wsgi/proxy.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- coding: utf-8 - -# -# This file is part of couchdbkit released under the MIT license. -# See the NOTICE for more information. - -from __future__ import absolute_import -import six.moves.urllib.parse - -from restkit.contrib.wsgi_proxy import HostProxy, ALLOWED_METHODS -from webob import Request - -class CouchdbProxy(object): - """\ - WSGI application to proxy a couchdb server. - - Simple usage to proxy a CouchDB server on default url:: - - from couchdbkit.wsgi import CouchdbProxy - application = CouchdbProxy() - """ - - def __init__(self, uri="http://127.0.0.1:5984", - allowed_method=ALLOWED_METHODS, **kwargs): - self.proxy = HostProxy(uri, allowed_methods=allowed_method, - **kwargs) - - def do_proxy(self, req, environ, start_response): - """\ - return proxy response. Can be overrided to add authentification and - such. It's better to override do_proxy method than the __call__ - """ - return req.get_response(self.proxy) - - def __call__(self, environ, start_response): - req = Request(environ) - if 'RAW_URI' in req.environ: - # gunicorn so we can use real path non encoded - u = six.moves.urllib.parse.urlparse(req.environ['RAW_URI']) - req.environ['PATH_INFO'] = u.path - - resp = self.do_proy(req, environ, start_response) - return resp(environ, start_response)