##// END OF EJS Templates
hgweb: use try/except/finally
Matt Mackall -
r25083:ef36536a default
parent child Browse files
Show More
@@ -176,71 +176,70 b' class hgwebdir(object):'
176 176
177 177 def run_wsgi(self, req):
178 178 try:
179 try:
180 self.refresh()
179 self.refresh()
181 180
182 virtual = req.env.get("PATH_INFO", "").strip('/')
183 tmpl = self.templater(req)
184 ctype = tmpl('mimetype', encoding=encoding.encoding)
185 ctype = templater.stringify(ctype)
181 virtual = req.env.get("PATH_INFO", "").strip('/')
182 tmpl = self.templater(req)
183 ctype = tmpl('mimetype', encoding=encoding.encoding)
184 ctype = templater.stringify(ctype)
186 185
187 # a static file
188 if virtual.startswith('static/') or 'static' in req.form:
189 if virtual.startswith('static/'):
190 fname = virtual[7:]
191 else:
192 fname = req.form['static'][0]
193 static = self.ui.config("web", "static", None,
194 untrusted=False)
195 if not static:
196 tp = self.templatepath or templater.templatepaths()
197 if isinstance(tp, str):
198 tp = [tp]
199 static = [os.path.join(p, 'static') for p in tp]
200 staticfile(static, fname, req)
201 return []
186 # a static file
187 if virtual.startswith('static/') or 'static' in req.form:
188 if virtual.startswith('static/'):
189 fname = virtual[7:]
190 else:
191 fname = req.form['static'][0]
192 static = self.ui.config("web", "static", None,
193 untrusted=False)
194 if not static:
195 tp = self.templatepath or templater.templatepaths()
196 if isinstance(tp, str):
197 tp = [tp]
198 static = [os.path.join(p, 'static') for p in tp]
199 staticfile(static, fname, req)
200 return []
202 201
203 # top-level index
204 elif not virtual:
205 req.respond(HTTP_OK, ctype)
206 return self.makeindex(req, tmpl)
202 # top-level index
203 elif not virtual:
204 req.respond(HTTP_OK, ctype)
205 return self.makeindex(req, tmpl)
207 206
208 # nested indexes and hgwebs
207 # nested indexes and hgwebs
209 208
210 repos = dict(self.repos)
211 virtualrepo = virtual
212 while virtualrepo:
213 real = repos.get(virtualrepo)
214 if real:
215 req.env['REPO_NAME'] = virtualrepo
216 try:
217 # ensure caller gets private copy of ui
218 repo = hg.repository(self.ui.copy(), real)
219 return hgweb(repo).run_wsgi(req)
220 except IOError, inst:
221 msg = inst.strerror
222 raise ErrorResponse(HTTP_SERVER_ERROR, msg)
223 except error.RepoError, inst:
224 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
209 repos = dict(self.repos)
210 virtualrepo = virtual
211 while virtualrepo:
212 real = repos.get(virtualrepo)
213 if real:
214 req.env['REPO_NAME'] = virtualrepo
215 try:
216 # ensure caller gets private copy of ui
217 repo = hg.repository(self.ui.copy(), real)
218 return hgweb(repo).run_wsgi(req)
219 except IOError, inst:
220 msg = inst.strerror
221 raise ErrorResponse(HTTP_SERVER_ERROR, msg)
222 except error.RepoError, inst:
223 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
225 224
226 up = virtualrepo.rfind('/')
227 if up < 0:
228 break
229 virtualrepo = virtualrepo[:up]
225 up = virtualrepo.rfind('/')
226 if up < 0:
227 break
228 virtualrepo = virtualrepo[:up]
230 229
231 # browse subdirectories
232 subdir = virtual + '/'
233 if [r for r in repos if r.startswith(subdir)]:
234 req.respond(HTTP_OK, ctype)
235 return self.makeindex(req, tmpl, subdir)
230 # browse subdirectories
231 subdir = virtual + '/'
232 if [r for r in repos if r.startswith(subdir)]:
233 req.respond(HTTP_OK, ctype)
234 return self.makeindex(req, tmpl, subdir)
236 235
237 # prefixes not found
238 req.respond(HTTP_NOT_FOUND, ctype)
239 return tmpl("notfound", repo=virtual)
236 # prefixes not found
237 req.respond(HTTP_NOT_FOUND, ctype)
238 return tmpl("notfound", repo=virtual)
240 239
241 except ErrorResponse, err:
242 req.respond(err, ctype)
243 return tmpl('error', error=err.message or '')
240 except ErrorResponse, err:
241 req.respond(err, ctype)
242 return tmpl('error', error=err.message or '')
244 243 finally:
245 244 tmpl = None
246 245
General Comments 0
You need to be logged in to leave comments. Login now