diff -r 82df0bb66ca7 -r 71ab68f31a1c sites/irclogs.qmsk.net/urltree.py --- a/sites/irclogs.qmsk.net/urltree.py Sat Feb 07 21:02:33 2009 +0200 +++ b/sites/irclogs.qmsk.net/urltree.py Sat Feb 07 21:21:10 2009 +0200 @@ -263,7 +263,7 @@ """ # start with the defaults - kwargs = self.defaults() + kwargs = self.defaults.copy() # then add all the values for label_value in label_values : @@ -403,7 +403,7 @@ # found something? if not match : - raise URLError("No child found for label") + raise URLError("No child found for label: %s + %s + %s" % (self.get_url(), label, '/'.join(str(l) for l in label_path))) # ok, recurse into the match url, label_value = match.match(label_path) @@ -414,7 +414,30 @@ # return the match return url, label_value - + + def get_url (self) : + """ + Returns the URL for this node, by iterating over our parents + """ + + # URL segments in reverse order + segments = [''] + + # start with ourself + node = self + + # iterate up to root + while node : + segments.append(str(node.label)) + + node = node.parent + + # reverse + segments.reverse() + + # return + return '/'.join(segments) + def dump (self, indent=0) : """ Returns a multi-line string representation of this Node @@ -470,15 +493,13 @@ Returns an (URL, [LabelValue]) tuple. """ - # normalize the URL - url = os.path.normpath(url) - # split it into labels path = url.split('/') - - # ensure that it starts with a / - root_label = path.pop(0) - assert self.root.label.match(root_label), "URL must begin with root" + + # empty URL is empty + if url : + # ensure that it doesn't start with a / + assert not self.root.label.match(path[0]), "URL must not begin with root" # just match starting at root return self.root.match(path) @@ -488,10 +509,13 @@ Looks up the request's URL, and invokes its handler """ - # get the request's URL path - url, label_values = self.match(request.get_page_name()) + # get the requested URL + request_url = request.get_page_name() + + # find the URL+values to use + url, label_values = self.match(request_url) # let the URL handle it - url.execute(request, label_values) + return url.execute(request, label_values)