Mercurial > cgi-bin > hgweb.cgi > tincan
comparison tincan.py @ 67:b5e72129ef72 draft
Support #errors w/ no params, as documented.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 14 Jul 2019 14:47:33 -0700 |
parents | f33cb3e93473 |
children | 61667621e19d |
comparison
equal
deleted
inserted
replaced
66:f33cb3e93473 | 67:b5e72129ef72 |
---|---|
133 Parses and represents a set of header lines. | 133 Parses and represents a set of header lines. |
134 """ | 134 """ |
135 _NAMES = [ "errors", "forward", "methods", "python", "template" ] | 135 _NAMES = [ "errors", "forward", "methods", "python", "template" ] |
136 _FNAMES = [ "hidden" ] | 136 _FNAMES = [ "hidden" ] |
137 _ANAMES = [ "load" ] | 137 _ANAMES = [ "load" ] |
138 _ONAMES = [ "errors" ] | |
138 | 139 |
139 def __init__(self, string): | 140 def __init__(self, string): |
140 # Initialize our state | 141 # Initialize our state |
141 for i in self._NAMES: | 142 for i in self._NAMES: |
142 setattr(self, i, None) | 143 setattr(self, i, None) |
177 if name in self._FNAMES: | 178 if name in self._FNAMES: |
178 setattr(self, name, True) | 179 setattr(self, name, True) |
179 continue | 180 continue |
180 # Get parameter | 181 # Get parameter |
181 if rpa is None: | 182 if rpa is None: |
182 raise TemplateHeaderError("Missing parameter.", count) | 183 if name in self._ONAMES: |
184 rpa = "" | |
185 else: | |
186 raise TemplateHeaderError("Missing parameter.", count) | |
183 param = rpa.strip() | 187 param = rpa.strip() |
184 for i in [ "'", '"']: | 188 for i in [ "'", '"']: |
185 if param.startswith(i) and param.endswith(i): | 189 if param.startswith(i) and param.endswith(i): |
186 param = ast.literal_eval(param) | 190 param = ast.literal_eval(param) |
187 break | 191 break |
583 # self.logger.debug("forwarding from: %s", self._urlpath) # debug | 587 # self.logger.debug("forwarding from: %s", self._urlpath) # debug |
584 self._redirect() | 588 self._redirect() |
585 # self.logger.debug("forwarded to: %s", self._urlpath) # debug | 589 # self.logger.debug("forwarded to: %s", self._urlpath) # debug |
586 # If this is a #hidden page, we ignore it for now, since hidden pages | 590 # If this is a #hidden page, we ignore it for now, since hidden pages |
587 # don't get routes made for them. | 591 # don't get routes made for them. |
588 if oheader.hidden and not oheader.errors: | 592 if oheader.hidden and oheader.errors is None: |
589 return | 593 return |
590 # Get the code-behind #python | 594 # Get the code-behind #python |
591 if self._header.python is None: | 595 if self._header.python is None: |
592 self._python_specified = False | 596 self._python_specified = False |
593 else: | 597 else: |
685 def _getclass(self): | 689 def _getclass(self): |
686 try: | 690 try: |
687 pypath = os.path.normpath(os.path.join(self._fsroot, *self._splitpath(self._python))) | 691 pypath = os.path.normpath(os.path.join(self._fsroot, *self._splitpath(self._python))) |
688 except IndexError as e: | 692 except IndexError as e: |
689 raise TinCanError("{0}: invalid #python".format(self._urlpath)) from e | 693 raise TinCanError("{0}: invalid #python".format(self._urlpath)) from e |
690 klass = ErrorPage if self._header.errors else Page | 694 klass = ErrorPage if self._header.errors is not None else Page |
691 # Give 'em a default code-behind if they don't furnish one | 695 # Give 'em a default code-behind if they don't furnish one |
692 pytime = self._gettime(pypath) | 696 pytime = self._gettime(pypath) |
693 if not pytime: | 697 if not pytime: |
694 if self._python_specified: | 698 if self._python_specified: |
695 raise TinCanError("{0}: #python file not found".format(self._urlpath)) | 699 raise TinCanError("{0}: #python file not found".format(self._urlpath)) |