# HG changeset patch # User Gregory Szorc # Date 2015-08-22 20:58:59 # Node ID 9df8c729e2e7a15e2e7cf703d71e848701a4cc82 # Parent 0a9009d56feaea3fbd7c5c5cede289c948dbe456 hgweb: add some documentation It took longer than I wanted to grok how the various parts of hgweb worked. So I added some class and method documentation to help whoever hacks on this next. diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -62,6 +62,16 @@ def makebreadcrumb(url, prefix=''): class hgweb(object): + """HTTP server for individual repositories. + + Instances of this class serve HTTP responses for a particular + repository. + + Instances are typically used as WSGI applications. + + Some servers are multi-threaded. On these servers, there may + be multiple active threads inside __call__. + """ def __init__(self, repo, name=None, baseui=None): if isinstance(repo, str): if baseui: @@ -157,6 +167,11 @@ class hgweb(object): self.repo.ui.environ = request.env def run(self): + """Start a server from CGI environment. + + Modern servers should be using WSGI and should avoid this + method, if possible. + """ if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): raise RuntimeError("This function is only intended to be " "called while running as a CGI script.") @@ -164,11 +179,19 @@ class hgweb(object): wsgicgi.launch(self) def __call__(self, env, respond): + """Run the WSGI application. + + This may be called by multiple threads. + """ req = wsgirequest(env, respond) return self.run_wsgi(req) def run_wsgi(self, req): + """Internal method to run the WSGI application. + This is typically only called by Mercurial. External consumers + should be using instances of this class as the WSGI application. + """ self.refresh(req) # work with CGI variables to create coherent structure diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -79,6 +79,13 @@ def geturlcgivars(baseurl, port): return name, str(port), path class hgwebdir(object): + """HTTP server for multiple repositories. + + Given a configuration, different repositories will be served depending + on the request path. + + Instances are typically used as WSGI applications. + """ def __init__(self, conf, baseui=None): self.conf = conf self.baseui = baseui diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -40,6 +40,12 @@ def normalize(form): return form class wsgirequest(object): + """Higher-level API for a WSGI request. + + WSGI applications are invoked with 2 arguments. They are used to + instantiate instances of this class, which provides higher-level APIs + for obtaining request parameters, writing HTTP output, etc. + """ def __init__(self, wsgienv, start_response): version = wsgienv['wsgi.version'] if (version < (1, 0)) or (version >= (2, 0)):