# HG changeset patch # User David Barts # Date 1559360577 25200 # Node ID e08e24707da19d104960436357f9618fc8de8073 # Parent 935f8013f5402fb9e6108b6c6ff35f54ea664194 Recognize index.pspx (and index.html, and index.htm if static). diff -r 935f8013f540 -r e08e24707da1 tincan.py --- a/tincan.py Fri May 31 19:40:06 2019 -0700 +++ b/tincan.py Fri May 31 20:42:57 2019 -0700 @@ -384,6 +384,9 @@ _FLOOP = "tincan.forwards" _FORIG = "tincan.origin" _FTYPE = "tincan.iserror" +_INDEX = "/index" + _TEXTEN +_LINDEX = len(_INDEX) +_INDICES = [ _INDEX, "/index.html", "/index.htm" ] class _TinCanBaseRoute(object): """ @@ -440,6 +443,13 @@ def launch(self): self.logger.info("adding static route: %s", self._urlpath) self._app.route(self._urlpath, 'GET', self) + for i in _INDICES: + if self._urlpath.endswith(i): + li = len(i) + for j in [ self._urlpath[:1-li], self._urlpath[:-li] ]: + if j: + self.logger.info("adding static route: %s", j) + self._app.route(j, 'GET', self) def _parse_date(self, ims): """ @@ -590,7 +600,7 @@ raise TinCanError("{0}: invalid #template: {1!s}".format(self._urlpath, e)) from e except IndexError as e: raise TinCanError("{0}: invalid #template".format(self._urlpath)) from e - self._body = self._mktemplate(tfile.body, self.urljoin(rtpath)) + self._body = self._mktemplate(tfile.body, self.urljoin(*rtpath)) else: self._body = self._mktemplate(self._template.body, self._urlpath) self._body.prepare() @@ -622,8 +632,14 @@ if not methods: raise TinCanError("{0}: no #methods specified".format(self._urlpath)) # Register this thing with Bottle - self.logger.info("adding route: %s (%s)", self._origin, ','.join(methods)) + mtxt = ','.join(methods) + self.logger.info("adding route: %s (%s)", self._origin, mtxt) self._app.route(self._origin, methods, self) + if self._origin.endswith(_INDEX): + for i in [ self._origin[:1-_LINDEX], self._origin[:-_LINDEX] ]: + if i: + self.logger.info("adding route: %s (%s)", i, mtxt) + self._app.route(i, methods, self) def _mktemplate(self, source, name): try: