Commits

Robert Brewer  committed d2e5df3

1. Moved RequestHandled exception from basefilter to cperror. Application code may raise it as desired.
2. Changed staticfilter's handling of relative paths. Rather than use current working directory, it now uses the module in which cpg.root was defined as a base.

  • Participants
  • Parent commits 0616050

Comments (0)

Files changed (5)

File cherrypy/_cphttptools.py

                     
                     applyFilters('beforeFinalize')
                     finalize()
-                except basefilter.RequestHandled:
+                except cperror.RequestHandled:
                     pass
             finally:
                 applyFilters('onEndResource')

File cherrypy/cperror.py

 class WrongConfigValue(Error):
     """ Happens when unrepr can't parse a config value """
     pass
+
+class RequestHandled(Exception):
+    """Exception raised when no further request handling should occur."""
+    pass

File cherrypy/lib/filter/basefilter.py

 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
-class RequestHandled(Exception):
-    """Exception raised when no further request handling should occur."""
-    pass
-
-
 class BaseFilter(object):
     """
     Base class for filters. Derive new filter classes from this, then

File cherrypy/lib/filter/cachefilter.py

     def onStartResource(self):
         # We have to dynamically import cpg because Python can't handle
         #   circular module imports :-(
-        global cpg
-        from cherrypy import cpg
+        global cpg, cperror
+        from cherrypy import cpg, cperror
         cpg.threadData.cacheable = True
     
     def beforeMain(self):
                 # serve it & get out from the request
                 cpg.response.status, cpg.response.headers, body = obj
                 cpg.response.body = body
-            raise basefilter.RequestHandled
+            raise cperror.RequestHandled
     
     def onEndResource(self):
         """Close & fix the cache entry after content was fully written"""

File cherrypy/lib/filter/staticfilter.py

 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
-import os, time, mimetypes
+import os, sys, time, mimetypes
 from basefilter import BaseFilter
 
 
             extraPath = cpg.request.path[len(section) + 1:]
             filename = os.path.join(staticDir, extraPath)
         
+        # If filename is relative, make absolute using cpg.root's module.
+        if not os.path.isabs(filename):
+            root = os.path.dirname(sys.modules[cpg.root.__module__].__file__)
+            filename = os.path.join(root, filename)
+        
         # Serve filename
         try:
             stat = os.stat(filename)