# # # patch "wrapper.py" # from [904f434b11952f8634568a5de0f80298efb872df] # to [1cdf75ce5311b1fd168aff335e1de92049f8174d] # ============================================================ --- wrapper.py 904f434b11952f8634568a5de0f80298efb872df +++ wrapper.py 1cdf75ce5311b1fd168aff335e1de92049f8174d @@ -16,8 +16,8 @@ # paranoid sane_uri_re = re.compile('^\w+$') -def get_file(req): - mt = Monotone(config.monotone, config.dbfile) +def get_file(req, vars): + mt = vars['mt'] form = util.FieldStorage(req) if not form.has_key('id'): return apache.HTTP_BAD_REQUEST @@ -36,8 +36,8 @@ req.write(mt.file(id)) return apache.OK -def get_diff(req): - mt = Monotone(config.monotone, config.dbfile) +def get_diff(req, vars): + mt = vars['mt'] form = util.FieldStorage(req) if not form.has_key('id1') or not form.has_key('id2'): return apache.HTTP_BAD_REQUEST @@ -50,7 +50,7 @@ req.write(mt.diff(id1, id2, files)) return apache.OK -def get_tar(req): +def get_tar(req, vars): "make a tar file out of a given manifest ID" class DummyFile: def __init__(self, buf): @@ -64,7 +64,7 @@ return rv def write(self, s): self.buf += s - mt = Monotone(config.monotone, config.dbfile) + mt = vars['mt'] form = util.FieldStorage(req) if not form.has_key('id'): return apache.HTTP_BAD_REQUEST @@ -106,32 +106,37 @@ slash = uri.rfind('/') if slash <> -1: uri = uri[slash+1:] + # most monotone output is utf8 + req.content_type = "text/html; charset=utf-8" + + # common variables which all handlers (PSP or not) + # should have access to; ensure that these variables + # are cleaned up + mt = Monotone(config.monotone, config.dbfile) + def our_link (link_type, link_to, description=None, no_quote=False): + return common.link(mt, link_type, link_to, description, no_quote) + vars = { + 'mt' : mt, + 'link' : our_link, + 'hq' : common.html_escape(), + 'template' : Template() + } + req.register_cleanup(cleanup, (req, vars)) + # # these handlers don't use PSP, for example if they need # to return binary or otherwise pristine data to the user # agent # if handlers.has_key(uri): - return handlers[uri](req) + return handlers[uri](req, vars) # # PSP or 404 # try: if uri.endswith('.psp') and sane_uri_re.match(uri[:-4]): - req.content_type = "text/html" - mt = Monotone(config.monotone, config.dbfile) - def our_link (link_type, link_to, description=None, no_quote=False): - return common.link(mt, link_type, link_to, description, no_quote) - vars = { - 'mt' : mt, - 'link' : our_link, - 'hq' : common.html_escape(), - 'template' : Template() - } - req.register_cleanup(cleanup, (req, vars)) - # most monotone output is utf8 - req.content_type = "text/html; charset=utf-8" + req.content_type = "text/html" instance = psp.PSP(req, filename=uri, vars=vars) instance.run() return apache.OK