comparison mercurial/hgweb/hgwebdir_mod.py @ 5566:d74fc8dec2b4

Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 30 Nov 2007 18:23:18 +0100
parents 22713dce19f6
children e15f7db0f0ee
comparison
equal deleted inserted replaced
5565:feac5b0bf9ba 5566:d74fc8dec2b4
9 import os, mimetools, cStringIO 9 import os, mimetools, cStringIO
10 from mercurial.i18n import gettext as _ 10 from mercurial.i18n import gettext as _
11 from mercurial import ui, hg, util, templater 11 from mercurial import ui, hg, util, templater
12 from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen 12 from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen
13 from hgweb_mod import hgweb 13 from hgweb_mod import hgweb
14 from request import wsgirequest
14 15
15 # This is a stopgap 16 # This is a stopgap
16 class hgwebdir(object): 17 class hgwebdir(object):
17 def __init__(self, config, parentui=None): 18 def __init__(self, config, parentui=None):
18 def cleannames(items): 19 def cleannames(items):
58 59
59 def run(self): 60 def run(self):
60 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): 61 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
61 raise RuntimeError("This function is only intended to be called while running as a CGI script.") 62 raise RuntimeError("This function is only intended to be called while running as a CGI script.")
62 import mercurial.hgweb.wsgicgi as wsgicgi 63 import mercurial.hgweb.wsgicgi as wsgicgi
63 from request import wsgiapplication 64 wsgicgi.launch(self)
64 def make_web_app(): 65
65 return self 66 def __call__(self, env, respond):
66 wsgicgi.launch(wsgiapplication(make_web_app)) 67 req = wsgirequest(env, respond)
68 self.run_wsgi(req)
69 return req
67 70
68 def run_wsgi(self, req): 71 def run_wsgi(self, req):
69 def header(**map): 72 def header(**map):
70 header_file = cStringIO.StringIO( 73 header_file = cStringIO.StringIO(
71 ''.join(tmpl("header", encoding=util._encoding, **map))) 74 ''.join(tmpl("header", encoding=util._encoding, **map)))