Kirill Simonov  committed 6ffd61f

Implemented the WSGI handler as an adapter.

Also, fixed minor bugs in the implementation of adapters.

  • Participants
  • Parent commits 948c594

Comments (0)

Files changed (6)

 .. autoclass:: InvalidSyntaxError
+.. automodule:: htsql.wsgi
+.. autoclass:: WSGI
+   :members: __call__
 .. automodule::

File src/htsql/

-from .util import aresubclasses, toposort
+from .util import listof, subclassof, aresubclasses, toposort
 from .context import context
+import sys
 class Adapter(object):
         if cls.is_realized:
             return super(Adapter, cls).__new__(cls, *args, **kwds)
         # Extract polymorphic parameters.
-        assert cls.signature is not None and len(args) >= cls.signature
+        assert cls.signature is not None and len(args) >= len(cls.signature)
         objects = args[:len(cls.signature)]
         # Specialize the interface for the given parameters.
         realization = cls.realize(*objects)
     def __init__(self, adapters):
         # Sanity check on the argument.
-        assert isinstance(adapters, listof(subclass(Adapter)))
+        assert isinstance(adapters, listof(subclassof(Adapter)))
         # List of active adapters.
         self.adapters = adapters
         # A mapping: interface -> (signature -> realization).
     for name in sorted(locals):
         obj = locals[name]
         if (isinstance(obj, type) and issubclass(obj, Adapter)
-                and obj.__name__ == module_name):
+                and obj.__module__ == module_name):
     return adapters

File src/htsql/

 from __future__ import with_statement
-from .error import HTTPError
 from .context import context
+from .addon import Addon
+from .adapter import AdapterRegistry
 from .util import DB
-from .tr.parser import QueryParser
-import urllib
+from .wsgi import WSGI
+import pkg_resources
 class Application(object):
         Implements the WSGI entry point.
         with self:
-            # Parse and echo the query.
-            path_info = environ['PATH_INFO']
-            query_string = environ.get('QUERY_STRING')
-            uri = urllib.quote(path_info)
-            if query_string:
-                uri += '?'+query_string
-            parser = QueryParser(uri)
-            try:
-                syntax = parser.parse()
-            except HTTPError, exc:
-                return exc(environ, start_response)
-            start_response("200 OK", [('Content-Type', 'text/plain')])
-            return [str(syntax), "\n"]
+            wsgi = WSGI()
+            return wsgi(environ, start_response)

File src/htsql/ctl/

         # Create an application and update the testing state.  The created
         # application will be in effect for the subsequent tests in the
         # current suite and all the nested suites unless overriden.
-        from htsql import Application
+        from htsql.application import Application = None
    = Application(self.input.db)

File src/htsql/ctl/

     def run(self):
         # Create the HTSQL application.
-        from htsql import Application
+        from htsql.application import Application
         app = Application(self.db)
         # Prepare a WSGI `environ` variable.

File src/htsql/

 from addon import Addon
+from wsgi import wsgi_adapters
 class HTSQL_CORE(Addon):
     Declares the `htsql.core` addon.
-    adapters = []
+    adapters = wsgi_adapters