[Mpuls-commits] r1607 - in wasko/branches/2.0: . mpulsweb/config

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 16 11:32:42 CET 2010


Author: bh
Date: 2010-02-16 11:32:41 +0100 (Tue, 16 Feb 2010)
New Revision: 1607

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/mpulsweb/config/middleware.py
Log:
* mpulsweb/config/middleware.py (MyPylonsApp.find_controller): Do
not catch Exceptions, especially ones raised by __import__, unless
necessary to implement the desired functionality, and even then,
at least print a full traceback.  The base class method we
override doesn't catch exceptions either.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-02-16 10:26:21 UTC (rev 1606)
+++ wasko/branches/2.0/ChangeLog	2010-02-16 10:32:41 UTC (rev 1607)
@@ -1,3 +1,11 @@
+2010-02-16  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/config/middleware.py (MyPylonsApp.find_controller): Do
+	not catch Exceptions, especially ones raised by __import__, unless
+	necessary to implement the desired functionality, and even then,
+	at least print a full traceback.  The base class method we
+	override doesn't catch exceptions either.
+
 2010-02-16  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	* waskaweb/lib/evaluation.py (Evaluation_14.perform): Evaluation is

Modified: wasko/branches/2.0/mpulsweb/config/middleware.py
===================================================================
--- wasko/branches/2.0/mpulsweb/config/middleware.py	2010-02-16 10:26:21 UTC (rev 1606)
+++ wasko/branches/2.0/mpulsweb/config/middleware.py	2010-02-16 10:32:41 UTC (rev 1607)
@@ -28,51 +28,44 @@
         the URL has been resolved.
         
         """
+        # Check to see if we've cached the class instance for this name
+        if controller in self.controller_classes:
+            return self.controller_classes[controller]
+
+        # Pull the controllers class name, import controller
+        full_module_name = config['mpuls.app.instance'] + \
+                           '.controllers.' + controller.replace('/', '.')
+
+        # Hide the traceback here if the import fails (bad syntax and such)
+        __traceback_hide__ = 'before_and_this'
+
+        # Try to import the controller. 
+        # First try to import it from the configured configuration instance (WASKA, WASKO, JMD...)
+        # If the controller can not be imported (e.g it was not defined
+        # here) try to load it from the base appication
         try:
-            # Check to see if we've cached the class instance for this name
-            if controller in self.controller_classes:
-                return self.controller_classes[controller]
-            
-            # Pull the controllers class name, import controller
-            full_module_name = config['mpuls.app.instance'] + \
+            __import__(full_module_name)
+        except ImportError:
+            log.exception("Exception while loading module %r", full_module_name)
+            full_module_name = 'mpulsweb' + \
                                '.controllers.' + controller.replace('/', '.')
-            
-            # Hide the traceback here if the import fails (bad syntax and such)
-            __traceback_hide__ = 'before_and_this'
+            log.debug("Module not found! Trying to load from base location: %s" % full_module_name)
+            __import__(full_module_name)
 
-            # Try to import the controller. 
-            # First try to import it from the configured configuration instance (WASKA, WASKO, JMD...)
-            # If the controller can not be imported (e.g it was not defined
-            # here) try to load it from the base appication
-            try:
-                __import__(full_module_name)
-            except ImportError:
-                full_module_name = 'mpulsweb' + \
-                                   '.controllers.' + controller.replace('/', '.')
-                log.debug("Module not found! Trying to load from base location: %s" % full_module_name)
-                try:
-                    __import__(full_module_name)
-                except ImportError, e:
-                    log.error("Module not found!")
-                    log.exception(e)
-                    raise
+        if hasattr(sys.modules[full_module_name], '__controller__'):
+            mycontroller = getattr(sys.modules[full_module_name],
+                sys.modules[full_module_name].__controller__)
+        else:
+            module_name = controller.split('/')[-1]
+            class_name = class_name_from_module_name(module_name) + 'Controller'
+            if self.log_debug:
+                log.debug("Found controller, module: '%s', class: '%s'",
+                          full_module_name, class_name)
+            mycontroller = getattr(sys.modules[full_module_name], class_name)
+        self.controller_classes[controller] = mycontroller
+        return mycontroller
 
-            if hasattr(sys.modules[full_module_name], '__controller__'):
-                mycontroller = getattr(sys.modules[full_module_name],
-                    sys.modules[full_module_name].__controller__)
-            else:
-                module_name = controller.split('/')[-1]
-                class_name = class_name_from_module_name(module_name) + 'Controller'
-                if self.log_debug:
-                    log.debug("Found controller, module: '%s', class: '%s'",
-                              full_module_name, class_name)
-                mycontroller = getattr(sys.modules[full_module_name], class_name)
-            self.controller_classes[controller] = mycontroller
-            return mycontroller
-        except Exception, e:
-            log.debug(e)
 
-
 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
     """Create a Pylons WSGI application and return it
 



More information about the Mpuls-commits mailing list