comparison mercurial/hgweb/hgweb_mod.py @ 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 50a277e6ceae
children c050548307a4
comparison
equal deleted inserted replaced
6148:31d81d476a7f 6149:b023915aa1bc
197 ext = spec[2] 197 ext = spec[2]
198 if fn.endswith(ext): 198 if fn.endswith(ext):
199 req.form['node'] = [fn[:-len(ext)]] 199 req.form['node'] = [fn[:-len(ext)]]
200 req.form['type'] = [type_] 200 req.form['type'] = [type_]
201 201
202 # actually process the request 202 # process this if it's a protocol request
203
204 cmd = req.form.get('cmd', [''])[0]
205 if cmd in protocol.__all__:
206 method = getattr(protocol, cmd)
207 method(self, req)
208 return
209
210 # process the web interface request
203 211
204 try: 212 try:
205 213
206 cmd = req.form.get('cmd', [''])[0] 214 tmpl = self.templater(req)
207 if cmd in protocol.__all__: 215 ctype = tmpl('mimetype', encoding=self.encoding)
208 method = getattr(protocol, cmd) 216 ctype = templater.stringify(ctype)
209 method(self, req) 217
218 if cmd == '':
219 req.form['cmd'] = [tmpl.cache['default']]
220 cmd = req.form['cmd'][0]
221
222 if cmd not in webcommands.__all__:
223 msg = 'No such method: %s' % cmd
224 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
225 elif cmd == 'file' and 'raw' in req.form.get('style', []):
226 self.ctype = ctype
227 content = webcommands.rawfile(self, req, tmpl)
210 else: 228 else:
211 tmpl = self.templater(req) 229 content = getattr(webcommands, cmd)(self, req, tmpl)
212 ctype = tmpl('mimetype', encoding=self.encoding) 230 req.respond(HTTP_OK, ctype)
213 ctype = templater.stringify(ctype) 231
214 232 req.write(content)
215 if cmd == '': 233 del tmpl
216 req.form['cmd'] = [tmpl.cache['default']]
217 cmd = req.form['cmd'][0]
218
219 if cmd not in webcommands.__all__:
220 msg = 'No such method: %s' % cmd
221 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
222 elif cmd == 'file' and 'raw' in req.form.get('style', []):
223 self.ctype = ctype
224 content = webcommands.rawfile(self, req, tmpl)
225 else:
226 content = getattr(webcommands, cmd)(self, req, tmpl)
227 req.respond(HTTP_OK, ctype)
228
229 req.write(content)
230 del tmpl
231 234
232 except revlog.LookupError, err: 235 except revlog.LookupError, err:
233 req.respond(HTTP_NOT_FOUND, ctype) 236 req.respond(HTTP_NOT_FOUND, ctype)
234 req.write(tmpl('error', error='revision not found: %s' % err.name)) 237 req.write(tmpl('error', error='revision not found: %s' % err.name))
235 except (hg.RepoError, revlog.RevlogError), inst: 238 except (hg.RepoError, revlog.RevlogError), inst: