Mercurial > cgi-bin > hgweb.cgi > tincan
comparison tincan.py @ 12:496d43d551d2 draft
More redirecting fixes and improved error reportage.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 15 May 2019 00:16:06 -0700 |
parents | 8037bad7d5a8 |
children | 6de828de4409 |
comparison
equal
deleted
inserted
replaced
11:8037bad7d5a8 | 12:496d43d551d2 |
---|---|
359 oheader = None | 359 oheader = None |
360 while True: | 360 while True: |
361 try: | 361 try: |
362 self._template = TemplateFile(self._fspath) | 362 self._template = TemplateFile(self._fspath) |
363 except IOError as e: | 363 except IOError as e: |
364 raise TinCanError(str(e)) from e | 364 if oheader is not None: |
365 note = "{0}: invalid #forward: ".format(self._origin) | |
366 else: | |
367 note = "" | |
368 raise TinCanError("{0}{1!s}".format(note, e)) from e | |
365 try: | 369 try: |
366 self._header = TemplateHeader(self._template.header) | 370 self._header = TemplateHeader(self._template.header) |
367 except TemplateHeaderError as e: | 371 except TemplateHeaderError as e: |
368 raise TinCanError("{0}: {1!s}".format(self._fspath, e)) from e | 372 raise TinCanError("{0}: {1!s}".format(self._fspath, e)) from e |
369 if oheader is None: | 373 if oheader is None: |
370 oheader = self._header # save original header | 374 oheader = self._header # save original header |
371 elif (oheader.errors is None) != (self._header.errors is None): | 375 elif (oheader.errors is None) != (self._header.errors is None): |
372 raise TinCanError("{0}: invalid #forward".format(self._origin)) | 376 raise TinCanError("{0}: invalid #forward".format(self._origin)) |
373 if self._header.forward is None: | 377 if self._header.forward is None: |
374 break | 378 break |
375 print("forwarding from:", self._urlpath) # debug | 379 # print("forwarding from:", self._urlpath) # debug |
376 self._redirect() | 380 self._redirect() |
377 print("forwarded to:", self._urlpath) # debug | 381 # print("forwarded to:", self._urlpath) # debug |
378 # If this is a #hidden page, we ignore it for now, since hidden pages | 382 # If this is a #hidden page, we ignore it for now, since hidden pages |
379 # don't get routes made for them. | 383 # don't get routes made for them. |
380 if oheader.hidden and not oheader.errors: | 384 if oheader.hidden and not oheader.errors: |
381 return | 385 return |
382 # Get the code-behind #python | 386 # Get the code-behind #python |
483 if ext != _TEXTEN: | 487 if ext != _TEXTEN: |
484 raise TinCanError("{0}: invalid #forward".format(self._urlpath)) | 488 raise TinCanError("{0}: invalid #forward".format(self._urlpath)) |
485 self._subdir = rlist | 489 self._subdir = rlist |
486 self._python = name + _PEXTEN | 490 self._python = name + _PEXTEN |
487 self._fspath = os.path.join(self._fsroot, *self._subdir, rname) | 491 self._fspath = os.path.join(self._fsroot, *self._subdir, rname) |
488 self._urlpath = self._urljoin(*self._subdir, rname) | 492 self._urlpath = '/' + self._urljoin(*self._subdir, rname) |
489 | 493 |
490 def _urljoin(self, *args): | 494 def _urljoin(self, *args): |
491 args = list(args) | 495 args = list(args) |
492 if args[0] == '/': | 496 if args[0] == '/': |
493 args[0] = '' | 497 args[0] = '' |