diff -r e94ab812c0c8 -r 185504387370 lib/map.py --- a/lib/map.py Sun Feb 08 03:13:11 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -""" - Handles mapping URLs to request handlers -""" - -import http -import handler - -class MapperError (http.ResponseError) : - """ - URL could not be mapped - """ - - def __init__ (self, url) : - super(MapperError, self).__init__("URL not found: %s" % (url, ), status='404 Not Found') - -class Mapper (handler.RequestHandler) : - """ - Looks up the handler to use based on the URL - """ - - def handle_request (self, request) : - """ - Map the given request - """ - - abstract - -class Mapping (object) : - """ - A mapping object for StaticMapping - """ - - def test (self, request) : - """ - Either return a handler, or None - """ - - abstract - -class RegexpMapping (object) : - """ - A mapping object that uses regular expressions - """ - - def __init__ (self, regexp, handler) : - pass - - def test (self, request) : - xxx - -class SimpleMapping (object) : - """ - A mapping object that uses simple expressions - """ - - def __init__ (self, expression, handler) : - pass - - def test (self, request) : - xxx - -class StaticMapper (Mapper) : - """ - Translates requests to handlers using a list of pre-determined Mapping's - """ - - def __init__ (self, mappings) : - # store - self.mappings = mappings - - def handle_request (self, request) : - """ - 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 : - break - - if not handler : - # fail, not found - raise MapperError(request.get_page_name()) - - # passthrough - return handler.handle_request(request) - -# "friendly" names -map = SimpleMapping -mapre = RegexpMapping -