lib/map.py
branchsites
changeset 35 79ea0e2a6cc2
parent 32 be954df4f0e8
equal deleted inserted replaced
34:09196d5b2a39 35:79ea0e2a6cc2
     3 """
     3 """
     4 
     4 
     5 import http
     5 import http
     6 import handler
     6 import handler
     7 
     7 
     8 class MappingError (http.ResponseError) :
     8 class MapperError (http.ResponseError) :
     9     """
     9     """
    10         URL could not be mapped
    10         URL could not be mapped
    11     """
    11     """
    12 
    12 
    13     def __init__ (self, url) :
    13     def __init__ (self, url) :
    14         super(MappingError, self).__init__("URL not found: %s" % (url, ), status='404 Not Found')
    14         super(MapperError, self).__init__("URL not found: %s" % (url, ), status='404 Not Found')
    15 
    15 
    16 class Mapper (handler.RequestHandler) :
    16 class Mapper (handler.RequestHandler) :
    17     """
    17     """
    18         Looks up the handler to use based on the URL
    18         Looks up the handler to use based on the URL
    19     """
    19     """
    57         pass
    57         pass
    58 
    58 
    59     def test (self, request) :
    59     def test (self, request) :
    60         xxx
    60         xxx
    61 
    61 
    62 class StaticMapping (Mapper) :
    62 class StaticMapper (Mapper) :
    63     """
    63     """
    64         Translates requests to handlers using a list of pre-determined Mapping's
    64         Translates requests to handlers using a list of pre-determined Mapping's
    65     """
    65     """
    66 
    66 
    67     def __init__ (self, mappings) :
    67     def __init__ (self, mappings) :
    83             if handler :
    83             if handler :
    84                 break
    84                 break
    85         
    85         
    86         if not handler :
    86         if not handler :
    87             # fail, not found
    87             # fail, not found
    88             raise MappingError(request.get_page_name())
    88             raise MapperError(request.get_page_name())
    89         
    89         
    90         # passthrough
    90         # passthrough
    91         return handler.handle_request(request)
    91         return handler.handle_request(request)
    92 
    92 
    93 # "friendly" names
    93 # "friendly" names