Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgwebdir_mod.py @ 36911:93717f082af9
hgweb: use modern response type for index generation
Differential Revision: https://phab.mercurial-scm.org/D2827
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 11 Mar 2018 15:37:59 -0700 |
parents | 092ab4ba7ee5 |
children | 6a0e4efbc61e |
comparison
equal
deleted
inserted
replaced
36910:092ab4ba7ee5 | 36911:93717f082af9 |
---|---|
14 from ..i18n import _ | 14 from ..i18n import _ |
15 | 15 |
16 from .common import ( | 16 from .common import ( |
17 ErrorResponse, | 17 ErrorResponse, |
18 HTTP_NOT_FOUND, | 18 HTTP_NOT_FOUND, |
19 HTTP_OK, | |
20 HTTP_SERVER_ERROR, | 19 HTTP_SERVER_ERROR, |
21 cspvalues, | 20 cspvalues, |
22 get_contact, | 21 get_contact, |
23 get_mtime, | 22 get_mtime, |
24 ismember, | 23 ismember, |
398 # top-level index | 397 # top-level index |
399 | 398 |
400 repos = dict(self.repos) | 399 repos = dict(self.repos) |
401 | 400 |
402 if (not virtual or virtual == 'index') and virtual not in repos: | 401 if (not virtual or virtual == 'index') and virtual not in repos: |
403 wsgireq.respond(HTTP_OK, ctype) | 402 return self.makeindex(req, res, tmpl) |
404 return self.makeindex(req, tmpl) | |
405 | 403 |
406 # nested indexes and hgwebs | 404 # nested indexes and hgwebs |
407 | 405 |
408 if virtual.endswith('/index') and virtual not in repos: | 406 if virtual.endswith('/index') and virtual not in repos: |
409 subdir = virtual[:-len('index')] | 407 subdir = virtual[:-len('index')] |
410 if any(r.startswith(subdir) for r in repos): | 408 if any(r.startswith(subdir) for r in repos): |
411 wsgireq.respond(HTTP_OK, ctype) | 409 return self.makeindex(req, res, tmpl, subdir) |
412 return self.makeindex(req, tmpl, subdir) | |
413 | 410 |
414 def _virtualdirs(): | 411 def _virtualdirs(): |
415 # Check the full virtual path, each parent, and the root ('') | 412 # Check the full virtual path, each parent, and the root ('') |
416 if virtual != '': | 413 if virtual != '': |
417 yield virtual | 414 yield virtual |
440 raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst)) | 437 raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst)) |
441 | 438 |
442 # browse subdirectories | 439 # browse subdirectories |
443 subdir = virtual + '/' | 440 subdir = virtual + '/' |
444 if [r for r in repos if r.startswith(subdir)]: | 441 if [r for r in repos if r.startswith(subdir)]: |
445 wsgireq.respond(HTTP_OK, ctype) | 442 return self.makeindex(req, res, tmpl, subdir) |
446 return self.makeindex(req, tmpl, subdir) | |
447 | 443 |
448 # prefixes not found | 444 # prefixes not found |
449 wsgireq.respond(HTTP_NOT_FOUND, ctype) | 445 wsgireq.respond(HTTP_NOT_FOUND, ctype) |
450 return tmpl("notfound", repo=virtual) | 446 return tmpl("notfound", repo=virtual) |
451 | 447 |
453 wsgireq.respond(err, ctype) | 449 wsgireq.respond(err, ctype) |
454 return tmpl('error', error=err.message or '') | 450 return tmpl('error', error=err.message or '') |
455 finally: | 451 finally: |
456 tmpl = None | 452 tmpl = None |
457 | 453 |
458 def makeindex(self, req, tmpl, subdir=""): | 454 def makeindex(self, req, res, tmpl, subdir=""): |
459 self.refresh() | 455 self.refresh() |
460 sortable = ["name", "description", "contact", "lastchange"] | 456 sortable = ["name", "description", "contact", "lastchange"] |
461 sortcolumn, descending = None, False | 457 sortcolumn, descending = None, False |
462 if 'sort' in req.qsparams: | 458 if 'sort' in req.qsparams: |
463 sortcolumn = req.qsparams['sort'] | 459 sortcolumn = req.qsparams['sort'] |
476 | 472 |
477 entries = indexentries(self.ui, self.repos, req, | 473 entries = indexentries(self.ui, self.repos, req, |
478 self.stripecount, sortcolumn=sortcolumn, | 474 self.stripecount, sortcolumn=sortcolumn, |
479 descending=descending, subdir=subdir) | 475 descending=descending, subdir=subdir) |
480 | 476 |
481 return tmpl("index", entries=entries, subdir=subdir, | 477 res.setbodygen(tmpl( |
482 pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), | 478 'index', |
483 sortcolumn=sortcolumn, descending=descending, | 479 entries=entries, |
484 **dict(sort)) | 480 subdir=subdir, |
481 pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), | |
482 sortcolumn=sortcolumn, | |
483 descending=descending, | |
484 **dict(sort))) | |
485 | |
486 return res.sendresponse() | |
485 | 487 |
486 def templater(self, wsgireq, nonce): | 488 def templater(self, wsgireq, nonce): |
487 | 489 |
488 def motd(**map): | 490 def motd(**map): |
489 if self.motd is not None: | 491 if self.motd is not None: |