mercurial/hgweb/hgwebdir_mod.py
changeset 15003 a31b8e03af28
parent 15002 b55c1c6a793e
child 16239 287f76b3f502
equal deleted inserted replaced
15002:b55c1c6a793e 15003:a31b8e03af28
    49     for path in paths:
    49     for path in paths:
    50         path = os.path.normpath(path)
    50         path = os.path.normpath(path)
    51         yield (prefix + '/' +
    51         yield (prefix + '/' +
    52                util.pconvert(path[len(roothead):]).lstrip('/')).strip('/'), path
    52                util.pconvert(path[len(roothead):]).lstrip('/')).strip('/'), path
    53 
    53 
       
    54 def geturlcgivars(baseurl, port):
       
    55     """
       
    56     Extract CGI variables from baseurl
       
    57 
       
    58     >>> geturlcgivars("http://host.org/base", "80")
       
    59     ('host.org', '80', '/base')
       
    60     >>> geturlcgivars("http://host.org:8000/base", "80")
       
    61     ('host.org', '8000', '/base')
       
    62     >>> geturlcgivars('/base', 8000)
       
    63     ('', '8000', '/base')
       
    64     >>> geturlcgivars("base", '8000')
       
    65     ('', '8000', '/base')
       
    66     >>> geturlcgivars("http://host", '8000')
       
    67     ('host', '8000', '/')
       
    68     >>> geturlcgivars("http://host/", '8000')
       
    69     ('host', '8000', '/')
       
    70     """
       
    71     u = util.url(baseurl)
       
    72     name = u.host or ''
       
    73     if u.port:
       
    74         port = u.port
       
    75     path = u.path or ""
       
    76     if not path.startswith('/'):
       
    77         path = '/' + path
       
    78 
       
    79     return name, str(port), path
       
    80 
    54 class hgwebdir(object):
    81 class hgwebdir(object):
    55     refreshinterval = 20
    82     refreshinterval = 20
    56 
    83 
    57     def __init__(self, conf, baseui=None):
    84     def __init__(self, conf, baseui=None):
    58         self.conf = conf
    85         self.conf = conf
   364                                              "sessionvars": sessionvars})
   391                                              "sessionvars": sessionvars})
   365         return tmpl
   392         return tmpl
   366 
   393 
   367     def updatereqenv(self, env):
   394     def updatereqenv(self, env):
   368         if self._baseurl is not None:
   395         if self._baseurl is not None:
   369             u = util.url(self._baseurl)
   396             name, port, path = geturlcgivars(self._baseurl, env['SERVER_PORT'])
   370             env['SERVER_NAME'] = u.host
   397             env['SERVER_NAME'] = name
   371             if u.port:
   398             env['SERVER_PORT'] = port
   372                 env['SERVER_PORT'] = u.port
       
   373             path = u.path or ""
       
   374             if not path.startswith('/'):
       
   375                 path = '/' + path
       
   376             env['SCRIPT_NAME'] = path
   399             env['SCRIPT_NAME'] = path