Commits

Robert Brewer committed 131829c

New _cpconfig--tests now pass again. Plus it's even faster.

Comments (0)

Files changed (1)

cherrypy/_cpconfig.py

             autoreload.reloadFiles.append(file)
         _load(file)
 
-def get(key, defaultValue = None):
+def get(key, defaultValue=None, returnSection=False):
+    # Look, ma, no Python function calls! Uber-fast.
     global cpg
     if not cpg:
         import cpg
+    
     try:
         path = cpg.request.path
     except AttributeError:
         path = "/"
-    return _getFor(path, key, defaultValue)
-
-def _getFor(path, key, defaultValue):
-    if path == "":
-        path = "/"
-    try:
-        return configMap[path][key]
-    except KeyError:
-        if path != "/":
-            i = path.rfind("/")
-            if i < 0:
-                return defaultValue
-            return _getFor(path[:i], key, defaultValue)
-        else:
-            return defaultValue
+    
+    while True:
+        if path == "":
+            path = "/"
+        try:
+            result = configMap[path][key]
+        except KeyError:
+            if path != "/":
+                i = path.rfind("/")
+                if i < 0:
+                    result = defaultValue
+                else:
+                    path = path[:i]
+                    continue
+            else:
+                result = defaultValue
+        break
+    
+    if returnSection:
+        return path
+    else:
+        return result
 
 class CaseSensitiveConfigParser(ConfigParser.ConfigParser):
     """ Sub-class of ConfigParser that keeps the case of options and
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.