Commits

Alexander Solovyov committed 49b0dc8

ability to override request class

Comments (0)

Files changed (3)

svarga/core/conf/local_settings.py

 APPS_INIT = [
     'svarga.template.apps.contribute',
     'svarga.core.database.database_init',
+    'svarga.core.handler.request_class_init',
     ]
 
 # Enabled template loaders

svarga/core/env.py

         """
 
         s = Settings(s)
-        _static_urls = getattr(s, 'STATIC_URLS', {})
-        _middlewares = map(import_attribute, getattr(s, 'MIDDLEWARES', []))
 
         # Define new environment class
         class Env(object):
-            # Request processing middlewares
-            middlewares = _middlewares
-            # Settings
-            settings = s
-            # Static URLs
-            static_urls = _static_urls
+            settings = Settings(s)
+            middlewares = map(import_attribute, getattr(s, 'MIDDLEWARES', []))
+            static_urls = getattr(s, 'STATIC_URLS', {})
 
             @classmethod
             def get_static_url(cls, name):

svarga/core/handler.py

-from werkzeug import Request, ClosingIterator
+from werkzeug import ClosingIterator
 from werkzeug.exceptions import HTTPException
 from werkzeug.routing import RequestRedirect
 
     return url_conf
 
 
+def request_class_init(app_settings, env_class):
+    env_class.Request = import_attribute(
+        getattr(env_class.settings, 'REQUEST_CLASS',
+                'werkzeug.wrappers.Request'))
+
+
 class SvargaHandler(object):
     """Main Svarga request handler.
 
 
     def __call__(self, environ, start_response):
         "Process WSGI request"
-        request = Request(environ)
+        request = Environment.get_class().Request(environ)
 
         def do_response(response):
             return ClosingIterator(response(environ, start_response),