mercurial/hgweb/hgweb_mod.py
changeset 26132 9df8c729e2e7
parent 25777 1c2a8db33b8f
child 26133 44ed220ef26f
equal deleted inserted replaced
26131:0a9009d56fea 26132:9df8c729e2e7
    60         urlel = os.path.dirname(urlel)
    60         urlel = os.path.dirname(urlel)
    61     return reversed(breadcrumb)
    61     return reversed(breadcrumb)
    62 
    62 
    63 
    63 
    64 class hgweb(object):
    64 class hgweb(object):
       
    65     """HTTP server for individual repositories.
       
    66 
       
    67     Instances of this class serve HTTP responses for a particular
       
    68     repository.
       
    69 
       
    70     Instances are typically used as WSGI applications.
       
    71 
       
    72     Some servers are multi-threaded. On these servers, there may
       
    73     be multiple active threads inside __call__.
       
    74     """
    65     def __init__(self, repo, name=None, baseui=None):
    75     def __init__(self, repo, name=None, baseui=None):
    66         if isinstance(repo, str):
    76         if isinstance(repo, str):
    67             if baseui:
    77             if baseui:
    68                 u = baseui.copy()
    78                 u = baseui.copy()
    69             else:
    79             else:
   155             self.mtime = st.st_mtime
   165             self.mtime = st.st_mtime
   156         if request:
   166         if request:
   157             self.repo.ui.environ = request.env
   167             self.repo.ui.environ = request.env
   158 
   168 
   159     def run(self):
   169     def run(self):
       
   170         """Start a server from CGI environment.
       
   171 
       
   172         Modern servers should be using WSGI and should avoid this
       
   173         method, if possible.
       
   174         """
   160         if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
   175         if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
   161             raise RuntimeError("This function is only intended to be "
   176             raise RuntimeError("This function is only intended to be "
   162                                "called while running as a CGI script.")
   177                                "called while running as a CGI script.")
   163         import mercurial.hgweb.wsgicgi as wsgicgi
   178         import mercurial.hgweb.wsgicgi as wsgicgi
   164         wsgicgi.launch(self)
   179         wsgicgi.launch(self)
   165 
   180 
   166     def __call__(self, env, respond):
   181     def __call__(self, env, respond):
       
   182         """Run the WSGI application.
       
   183 
       
   184         This may be called by multiple threads.
       
   185         """
   167         req = wsgirequest(env, respond)
   186         req = wsgirequest(env, respond)
   168         return self.run_wsgi(req)
   187         return self.run_wsgi(req)
   169 
   188 
   170     def run_wsgi(self, req):
   189     def run_wsgi(self, req):
   171 
   190         """Internal method to run the WSGI application.
       
   191 
       
   192         This is typically only called by Mercurial. External consumers
       
   193         should be using instances of this class as the WSGI application.
       
   194         """
   172         self.refresh(req)
   195         self.refresh(req)
   173 
   196 
   174         # work with CGI variables to create coherent structure
   197         # work with CGI variables to create coherent structure
   175         # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
   198         # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
   176 
   199