Commits

Anonymous committed 92e30a9

First attempt at InternalRedirect

Comments (0)

Files changed (3)

 
 import cpg, urllib, sys, time, traceback, types, StringIO, cgi, os
 import mimetypes, sha, random, string, _cputil, cperror, Cookie
+from lib.filter import basefilter
 
 """
 Common Service Code for CherryPy
             cpg.request.fileTypeMap[key] = valueList.type
 
 def applyFilterList(methodName):
-    filterList = _cputil.getSpecialFunction('_cpFilterList')
-    for filter in filterList:
-        method = getattr(filter, methodName, None)
-        if method:
-            method()
+    try:
+        filterList = _cputil.getSpecialFunction('_cpFilterList')
+        for filter in filterList:
+            method = getattr(filter, methodName, None)
+            if method:
+                method()
+    except basefilter.InternalRedirect:
+        # If we get an InternalRedirect, we start the filter list
+        #   from scratch. Is cpg.request.path has been modified by
+        #   the hook, then a new filter list will be applied.
+        # We use recursion so if there is an infinite loop, we'll
+        #   get the regular python "recursion limit exceeded" exception.
+        applyFilterList(methodName)
 
 def insertIntoHeaderMap(key,value):
     normalizedKey = '-'.join([s.capitalize() for s in key.split('-')])
     """ An empty class """
     pass
 
-class ThreadAwareClass:
+class ThreadAwareClass(object):
     """ A thread-safe class for storing/retrieving
         thread-specific variables """
 
 def getSpecialFunction(name):
     """ Return the special function """
 
-    # First, we look in the right-most object if this special function is implemented.
-    # If not, then we try the previous object and so on until we reach cpg.root
+    # First, we look for the method in the right-most object
+    # If it's not there, we try the previous object and so on until
+    # we reach cpg.root
     # If it's still not there, we use the implementation from the
     # "_cpdefaults.py" module
     
         try:
             path = cpg.request.path
         except:
-            path = ''
+            path = '/'
         if path:
-            pathList = path.split('/')
+            pathList = path.split('/')[1:]
 
             obj = cpg.root
             previousObj = None

lib/filter/basefilter.py

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
+class InternalRedirect(Exception): pass
+
 class BaseInputFilter(object):
     """
     Base class for input filters. Derive new filter classes from this, then
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.