Mercurial > hg-stable
changeset 6149:b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
The protocol functions are already pretty careful about not raising
exceptions to the caller, and have their own error handling. We can formalize
this a little bit to make it clearer (before, the exception handlers for
a limited number of exceptions coming from the interface bits would blow up
because some variables aren't instantiated for the protocol calls).
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 20 Feb 2008 10:50:10 +0100 |
parents | 31d81d476a7f |
children | 8bc4fe428103 |
files | mercurial/hgweb/hgweb_mod.py |
diffstat | 1 files changed, 27 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py Tue Feb 19 19:34:18 2008 -0300 +++ b/mercurial/hgweb/hgweb_mod.py Wed Feb 20 10:50:10 2008 +0100 @@ -199,35 +199,38 @@ req.form['node'] = [fn[:-len(ext)]] req.form['type'] = [type_] - # actually process the request + # process this if it's a protocol request + + cmd = req.form.get('cmd', [''])[0] + if cmd in protocol.__all__: + method = getattr(protocol, cmd) + method(self, req) + return + + # process the web interface request try: - cmd = req.form.get('cmd', [''])[0] - if cmd in protocol.__all__: - method = getattr(protocol, cmd) - method(self, req) - else: - tmpl = self.templater(req) - ctype = tmpl('mimetype', encoding=self.encoding) - ctype = templater.stringify(ctype) - - if cmd == '': - req.form['cmd'] = [tmpl.cache['default']] - cmd = req.form['cmd'][0] + tmpl = self.templater(req) + ctype = tmpl('mimetype', encoding=self.encoding) + ctype = templater.stringify(ctype) + + if cmd == '': + req.form['cmd'] = [tmpl.cache['default']] + cmd = req.form['cmd'][0] - if cmd not in webcommands.__all__: - msg = 'No such method: %s' % cmd - raise ErrorResponse(HTTP_BAD_REQUEST, msg) - elif cmd == 'file' and 'raw' in req.form.get('style', []): - self.ctype = ctype - content = webcommands.rawfile(self, req, tmpl) - else: - content = getattr(webcommands, cmd)(self, req, tmpl) - req.respond(HTTP_OK, ctype) + if cmd not in webcommands.__all__: + msg = 'No such method: %s' % cmd + raise ErrorResponse(HTTP_BAD_REQUEST, msg) + elif cmd == 'file' and 'raw' in req.form.get('style', []): + self.ctype = ctype + content = webcommands.rawfile(self, req, tmpl) + else: + content = getattr(webcommands, cmd)(self, req, tmpl) + req.respond(HTTP_OK, ctype) - req.write(content) - del tmpl + req.write(content) + del tmpl except revlog.LookupError, err: req.respond(HTTP_NOT_FOUND, ctype)