Mercurial > cgi-bin > hgweb.cgi > tincan
diff tincan.py @ 28:4c6d3704e51f draft chameleon-load
Fails; the thing apparently wants strings and not objects.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 26 May 2019 18:14:14 -0700 |
parents | f6a1492fe56e |
children |
line wrap: on
line diff
--- a/tincan.py Sun May 26 17:06:32 2019 -0700 +++ b/tincan.py Sun May 26 18:14:14 2019 -0700 @@ -207,9 +207,9 @@ if base is not None: encoding = config.get("encoding", "utf-8") if subdir is not None: - self.expression_types['load'] = \ + self.expression_types['lload'] = \ _LoaderFactory(base, subdir, encoding) - self.expression_types['lload'] = \ + self.expression_types['load'] = \ _LoaderFactory(os.path.join(base,_WINF,"tlib"), [], encoding) class _LoaderFactory(object): @@ -228,9 +228,10 @@ """ Two of two helper classes for the above. """ + _EXTEN = ".pt" def __init__(self, based_on, string): - if not (string.endswith(".pspx") or string.endswith(".pt")): - raise ValueError("loaded templates must end in .pspx or .pt") + if not string.endswith(self._EXTEN): + raise ValueError("loaded templates must end in {0}".format(self._EXTEN)) self.path = string self.params = based_on @@ -242,7 +243,9 @@ npath = os.path.join(self.params.base, *normalized) with open(npath, "r", encoding=self.params.encoding) as fp: contents = fp.read() - value = ast.Str(contents) + value = ast.Call(func=TinCanChameleon, args=[contents], + kwargs={"base": self.params.base, "subdir": self.params.subdir, + "encoding": self.params.encoding}) return [ast.Assign(targets=[target], value=value)] # U t i l i t i e s