changeset 58:e08e24707da1 draft

Recognize index.pspx (and index.html, and index.htm if static).
author David Barts <n5jrn@me.com>
date Fri, 31 May 2019 20:42:57 -0700
parents 935f8013f540
children 60907204a265
files tincan.py
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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: