lib/http.py
changeset 10 d83b10c210e3
parent 9 2a47b00f60b0
child 14 b88d23696b98
equal deleted inserted replaced
9:2a47b00f60b0 10:d83b10c210e3
    39             /foo/bar.cgi    -> /foo
    39             /foo/bar.cgi    -> /foo
    40         """
    40         """
    41 
    41 
    42         return os.path.dirname(self.env['SCRIPT_NAME'])
    42         return os.path.dirname(self.env['SCRIPT_NAME'])
    43     
    43     
       
    44     def get_page_prefix (self) :
       
    45         """
       
    46             Returns the URL path root for page URLs, based on REQUEST_URI with PATH_INFO removed
       
    47 
       
    48             /                   -> 
       
    49             /foo.cgi            -> /foo.cgi
       
    50             /foo.cgi/index      -> /foo.cgi
       
    51             /foo.cgi/quux/bar   -> /foo.cgi
       
    52             /quux/foo.cgi/bar   -> /quux/foo.cgi
       
    53             /bar                -> 
       
    54         """
       
    55         
       
    56         # XXX: request uri path without the query string
       
    57         request_path = self.env.get('REQUEST_URI', '').split('?', 1)[0].rstrip('/')
       
    58 
       
    59         # path info
       
    60         page_name = self.get_page_name()
       
    61 
       
    62         # special-case for empty page_name
       
    63         if not page_name :
       
    64             return request_path
       
    65         
       
    66         # sanity-check
       
    67         assert request_path.endswith(page_name)
       
    68         
       
    69         # trim
       
    70         return request_path[:-len(page_name)].rstrip('/')
       
    71 
    44     def get_page_name (self) :
    72     def get_page_name (self) :
    45         """
    73         """
    46             Returns the requested page path with no leading slash, i.e.
    74             Returns the requested page path with no leading slash, i.e.
    47 
    75 
    48             /foo.cgi        -> 
    76             /foo.cgi        ->