--- a/lib/map.py Sat Feb 07 06:54:52 2009 +0200
+++ b/lib/map.py Sat Feb 07 16:33:27 2009 +0200
@@ -13,14 +13,14 @@
def __init__ (self, url) :
super(MappingError, self).__init__("URL not found: %s" % (url, ), status='404 Not Found')
-class Mapper (object) :
+class Mapper (handler.RequestHandler) :
"""
- Translates requests to handlers
+ Looks up the handler to use based on the URL
"""
- def map_request (self, request) :
+ def handle_request (self, request) :
"""
- Map the given request, returning a Handler
+ Map the given request
"""
abstract
@@ -73,40 +73,24 @@
Returns the appropriate handler
"""
+ # find handler to use
+ handler = None
+
# just test each mapping in turn
for mapping in self.mappings :
handler = mapping.test(request)
if handler :
- return handler
-
- # fail, not found
- raise MappingError(request.get_page_name())
+ break
-class FilesystemMapper (Mapper) :
- """
- Translates requests to handlers based on a filesystem directory containing various kinds of files
- """
-
- def __init__ (self, path) :
- """
- Create, path is where the pages are stored
- """
+ if not handler :
+ # fail, not found
+ raise MappingError(request.get_page_name())
- # store
- self.path = path
-
- def map_request (self, request) :
- """
- Looks up the appropriate Page, and then returns a generic Handler
- """
-
- # XXX: harcoded
- return handler.Handler(handler.handle_request)
+ # passthrough
+ return handler.handle_request(request)
# "friendly" names
-fstree = FilesystemMapper
-
map = SimpleMapping
mapre = RegexpMapping