Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/hgweb/hgweb_mod.py @ 2539:8a8d9ada4528
Merged WSGI fixes from http://hg.omnifarious.org/~hopper/webmerc/
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 30 Jun 2006 21:36:45 +0200 |
parents | f4b7d71c1c60 |
children | 1120302009d7 |
comparison
equal
deleted
inserted
replaced
2531:7a90e0c77f43 | 2539:8a8d9ada4528 |
---|---|
648 p = util.normpath(path) | 648 p = util.normpath(path) |
649 if p[:2] == "..": | 649 if p[:2] == "..": |
650 raise Exception("suspicious path") | 650 raise Exception("suspicious path") |
651 return p | 651 return p |
652 | 652 |
653 def run(self, req): | 653 def run(self): |
654 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): | |
655 raise RuntimeError("This function is only intended to be called while running as a CGI script.") | |
656 import mercurial.hgweb.wsgicgi as wsgicgi | |
657 from request import wsgiapplication | |
658 def make_web_app(): | |
659 return self | |
660 wsgicgi.launch(wsgiapplication(make_web_app)) | |
661 | |
662 def run_wsgi(self, req): | |
654 def header(**map): | 663 def header(**map): |
655 header_file = cStringIO.StringIO(''.join(self.t("header", **map))) | 664 header_file = cStringIO.StringIO(''.join(self.t("header", **map))) |
656 msg = mimetools.Message(header_file, 0) | 665 msg = mimetools.Message(header_file, 0) |
657 req.header(msg.items()) | 666 req.header(msg.items()) |
658 yield header_file.read() | 667 yield header_file.read() |
668 | |
669 def rawfileheader(**map): | |
670 req.header([('Content-type', map['mimetype']), | |
671 ('Content-disposition', 'filename=%s' % map['file']), | |
672 ('Content-length', str(len(map['raw'])))]) | |
673 yield '' | |
659 | 674 |
660 def footer(**map): | 675 def footer(**map): |
661 yield self.t("footer", | 676 yield self.t("footer", |
662 motd=self.repo.ui.config("web", "motd", ""), | 677 motd=self.repo.ui.config("web", "motd", ""), |
663 **map) | 678 **map) |
712 self.t = templater.templater(m, templater.common_filters, | 727 self.t = templater.templater(m, templater.common_filters, |
713 defaults={"url": url, | 728 defaults={"url": url, |
714 "repo": self.reponame, | 729 "repo": self.reponame, |
715 "header": header, | 730 "header": header, |
716 "footer": footer, | 731 "footer": footer, |
732 "rawfileheader": rawfileheader, | |
717 }) | 733 }) |
718 | 734 |
719 if not req.form.has_key('cmd'): | 735 if not req.form.has_key('cmd'): |
720 req.form['cmd'] = [self.t.cache['default'],] | 736 req.form['cmd'] = [self.t.cache['default'],] |
721 | 737 |