Changeset 923
- Timestamp:
- 01/10/06 17:55:08
- Files:
-
- trunk/cherrypy/_cptree.py (modified) (1 diff)
- trunk/cherrypy/test/test_objectmapping.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cptree.py
r912 r923 51 51 else: 52 52 cherrypy.config.update(file=conf, baseurl=baseurl) 53 54 def mount_point(self, path=None): 55 """The 'root path' of the app which governs the given path, or None. 56 57 If path is None, cherrypy.request.object_path is used. 58 """ 59 60 if path is None: 61 try: 62 import cherrypy 63 path = cherrypy.request.object_path 64 except AttributeError: 65 return None 66 67 while path: 68 if path in self.mount_points: 69 return path 70 71 # Move one node up the tree and try again. 72 if path == "/": 73 break 74 path = path[:path.rfind("/")] or "/" 75 76 return None 77 78 def url(self, path, mount_point=None): 79 """Return 'path', prefixed with mount_point. 80 81 If mount_point is None, cherrypy.request.object_path will be used 82 to find a mount point. 83 """ 84 85 if mount_point is None: 86 mount_point = self.mount_point() 87 if mount_point is None: 88 return path 89 90 from cherrypy.lib import httptools 91 return httptools.urljoin(mount_point, path) 53 92 trunk/cherrypy/test/test_objectmapping.py
r910 r923 70 70 index.exposed = True 71 71 72 def method(self): 73 return "method for dir2" 74 method.exposed = True 72 def mount_point(self): 73 return cherrypy.tree.mount_point() 74 mount_point.exposed = True 75 76 def tree_url(self): 77 return cherrypy.tree.url("/extra") 78 tree_url.exposed = True 75 79 76 80 def posparam(self, *vpath): … … 118 122 119 123 def testObjectMapping(self): 120 def run():121 prefix = self.mount_point 124 for url in mount_points: 125 prefix = self.mount_point = url 122 126 if prefix == "/": 123 127 prefix = "" … … 169 173 self.getPage("/page%2Fname") 170 174 self.assertBody("default:('page/name',)") 171 172 for url in mount_points: 173 self.mount_point = url 174 run() 175 176 self.getPage("/dir1/dir2/mount_point") 177 self.assertBody(url) 178 self.getPage("/dir1/dir2/tree_url") 179 self.assertBody(prefix + "/extra") 175 180 176 181 self.mount_point = ""

