Robert Brewer avatar 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.

Comments (0)

Files changed (5)

cherrypy/_cphttptools.py

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

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

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

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"""

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.