Mercurial > cgi-bin > hgweb.cgi > tincan
comparison tincan.py @ 69:c168aad7a731 draft
Fix template error reportage.
author | David Barts <n5jrn@me.com> |
---|---|
date | Mon, 15 Jul 2019 08:13:51 -0700 |
parents | 61667621e19d |
children | a78c74c73d98 |
comparison
equal
deleted
inserted
replaced
68:61667621e19d | 69:c168aad7a731 |
---|---|
566 # Build master and header objects, process #forward directives | 566 # Build master and header objects, process #forward directives |
567 oheader = None | 567 oheader = None |
568 while True: | 568 while True: |
569 try: | 569 try: |
570 self._template = TemplateFile(self._fspath) | 570 self._template = TemplateFile(self._fspath) |
571 except IOError as e: | 571 except (OSError, UnicodeError) as e: |
572 if oheader is not None: | 572 raise TinCanError("{0}: {1!s}".format(self._fspath, e)) from e |
573 note = "{0}: invalid #forward: ".format(self._origin) | |
574 else: | |
575 note = "" | |
576 raise TinCanError("{0}{1!s}".format(note, e)) from e | |
577 try: | 573 try: |
578 self._header = TemplateHeader(self._template.header) | 574 self._header = TemplateHeader(self._template.header) |
579 except TemplateHeaderError as e: | 575 except TemplateHeaderError as e: |
580 raise TinCanError("{0}: {1!s}".format(self._fspath, e)) from e | 576 raise TinCanError("{0}: {1!s}".format(self._fspath, e)) from e |
581 if oheader is None: | 577 if oheader is None: |
603 self._getclass() | 599 self._getclass() |
604 # Build body object (#template) and obtain #loads. | 600 # Build body object (#template) and obtain #loads. |
605 if self._header.template is not None: | 601 if self._header.template is not None: |
606 if not _casef(self._header.template).endswith(_TEXTEN): | 602 if not _casef(self._header.template).endswith(_TEXTEN): |
607 raise TinCanError("{0}: #template files must end in {1}".format(self._urlpath, _TEXTEN)) | 603 raise TinCanError("{0}: #template files must end in {1}".format(self._urlpath, _TEXTEN)) |
604 tpath = None | |
608 try: | 605 try: |
609 rtpath = self._splitpath(self._header.template) | 606 rtpath = self._splitpath(self._header.template) |
610 tpath = os.path.normpath(os.path.join(self._fsroot, *rtpath)) | 607 tpath = os.path.normpath(os.path.join(self._fsroot, *rtpath)) |
611 tfile = TemplateFile(tpath) | 608 tfile = TemplateFile(tpath) |
612 except OSError as e: | 609 except OSError as e: |
613 raise TinCanError("{0}: invalid #template: {1!s}".format(self._urlpath, e)) from e | 610 raise TinCanError("{0}: invalid #template: {1!s}".format(self._urlpath, e)) from e |
611 except UnicodeError as e: | |
612 raise TinCanError("{0}: {1!s}".format(tpath, e)) from e | |
614 except IndexError as e: | 613 except IndexError as e: |
615 raise TinCanError("{0}: invalid #template".format(self._urlpath)) from e | 614 raise TinCanError("{0}: invalid #template".format(self._urlpath)) from e |
616 self._body = self._mktemplate(tfile.body, self.urljoin(*rtpath)) | 615 self._body = self._mktemplate(tfile.body, self.urljoin(*rtpath)) |
617 else: | 616 else: |
618 self._body = self._mktemplate(self._template.body, self._urlpath) | 617 self._body = self._mktemplate(self._template.body, self._urlpath) |