[z3-checkins] r54765 - z3/deliverance/DeliveranceVHoster/trunk/dvhoster

magicbronson at codespeak.net magicbronson at codespeak.net
Thu May 15 22:49:54 CEST 2008


Author: magicbronson
Date: Thu May 15 22:49:50 2008
New Revision: 54765

Modified:
   z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py
   z3/deliverance/DeliveranceVHoster/trunk/dvhoster/wsgiapp.py
Log:
refactor creation of Transcluder middleware. now it's created in wsgiapp.py which is a less surprising place for it.

Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py	Thu May 15 22:49:50 2008
@@ -9,8 +9,6 @@
 from wsgifilter import proxyapp
 from wsgifilter import relocateresponse
 from deliverance.wsgimiddleware import DeliveranceMiddleware
-from dvhoster.socket_error import SocketErrorToHTTPServerException
-from dvhoster.socket_error import RetryOnceOnSocketError
 from dvhoster.model import DomainInfoSet, DomainInfoApp
 from dvhoster import current_environ
 from dvhoster.debuginterp import Renderer
@@ -19,9 +17,6 @@
 from dvhoster import uritemplate
 from dvhoster.scrubber import scrub_environ_host
 
-import transcluder
-from transcluder.middleware import TranscluderMiddleware
-
 from paste import fileapp
 # I hate this in-memory cache of files, so I'm globally disabling it
 # here at least:
@@ -67,29 +62,6 @@
         logger = make_logger(app_conf.get('logger'), 'dvhoster')
         self.logger = logger
 
-        # transcluder configuration 
-        self.transcluder_enabled = asbool(app_conf.get('transcluder_enabled', False))
-        ok_hosts = app_conf.get('transcluder_ok_hosts')
-
-        if not ok_hosts or ok_hosts == 'all':
-            self.transcluder_ok_hosts = transcluder.helpers.all_urls
-        elif ok_hosts == 'none':
-            self.transcluder_ok_hosts = transcluder.helpers.no_urls
-        elif ok_hosts == 'localhost':
-            self.transcluder_ok_hosts = transcluder.helpers.localhost_only
-        else:
-            self.transcluder_ok_hosts = transcluder.helpers.make_regex_predicate(ok_hosts)
-
-        self.transcluder_deptracker = transcluder.deptracker.DependencyTracker()
-
-        poolsize = 0
-        try:
-            poolsize = int(app_conf.get('transcluder_pool_size'))
-        except:
-            pass
-        
-        self.transcluder_pool = transcluder.tasklist.TaskList(poolsize=poolsize)
-            
     def __call__(self, environ, start_response):
         """
         WSGI interface
@@ -181,15 +153,6 @@
                 remote=remote_uri,
                 force_host=True)
 
-        if self.transcluder_enabled: 
-            app = TranscluderMiddleware(app,
-                                        deptracker=self.transcluder_deptracker,
-                                        tasklist=self.transcluder_pool,
-                                        include_predicate=self.transcluder_ok_hosts,
-                                        recursion_predicate=self.transcluder_ok_hosts)
-            app = RetryOnceOnSocketError(app)
-            app = SocketErrorToHTTPServerException(app)
-
         if should_theme_uri:
             if self.rewrite_links:
                 app = relocateresponse.RelocateMiddleware(

Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/wsgiapp.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/wsgiapp.py	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/wsgiapp.py	Thu May 15 22:49:50 2008
@@ -10,11 +10,22 @@
 from eyvind.lib.authmiddleware import AuthenticationMiddleware
 from dvhoster.custom_error import CustomErrorHTTPExceptionHandler
 
+import transcluder
+from transcluder.middleware import TranscluderMiddleware
+from dvhoster.socket_error import RetryOnceOnSocketError, SocketErrorToHTTPServerException
+
+
 def make_app(global_conf, **app_conf):
     """Create a WSGI application and return it"""
     custom_error_dir = app_conf['custom_error_dir'] = app_conf.get('custom_error_dir', global_conf.get('custom_error_dir','.'))
+
     app = DeliveranceDispatcher(app_conf)
     app = CustomErrorHTTPExceptionHandler(app, custom_error_dir)
+
+    transcluder_enabled = asbool(app_conf.get('transcluder_enabled', False))
+    if transcluder_enabled:
+        app = _create_transcluder(app, app_conf)
+
     app = RecursiveMiddleware(app)
     app = AuthenticationMiddleware(app, app_conf)
     app = EnvironScrubber(app, app_conf)
@@ -30,4 +41,32 @@
         folded_conf.update(app_conf)
         app = ErrorMiddleware(
             app, global_conf=folded_conf)
+
+    return app
+
+def _create_transcluder(app, app_conf):
+    ok_hosts = app_conf.get('transcluder_ok_hosts')
+
+    if not ok_hosts or ok_hosts == 'all':
+        transcluder_ok_hosts = transcluder.helpers.all_urls
+    elif ok_hosts == 'none':
+        transcluder_ok_hosts = transcluder.helpers.no_urls
+    elif ok_hosts == 'localhost':
+        transcluder_ok_hosts = transcluder.helpers.localhost_only
+    else:
+        transcluder_ok_hosts = transcluder.helpers.make_regex_predicate(ok_hosts)
+
+    transcluder_deptracker = transcluder.deptracker.DependencyTracker()
+
+    poolsize = int(app_conf.get('transcluder_pool_size', 0))
+    transcluder_pool = transcluder.tasklist.TaskList(poolsize=poolsize)
+
+    app = TranscluderMiddleware(app,
+                                deptracker=transcluder_deptracker,
+                                tasklist=transcluder_pool,
+                                include_predicate=transcluder_ok_hosts,
+                                recursion_predicate=transcluder_ok_hosts)
+    app = RetryOnceOnSocketError(app)
+    app = SocketErrorToHTTPServerException(app)
+    
     return app


More information about the z3-checkins mailing list