# HG changeset patch # User David Barts # Date 1559083799 25200 # Node ID 41da0b3d2156d02a896ace8d280c9d6356210cc7 # Parent 0fb455b46e5f0c763178054487f47be566cdfadb Rename #include to #load (more descriptive). diff -r 0fb455b46e5f -r 41da0b3d2156 tincan.py --- a/tincan.py Mon May 27 20:09:55 2019 -0700 +++ b/tincan.py Tue May 28 15:49:59 2019 -0700 @@ -40,9 +40,9 @@ def __str__(self): return "line {0}: {1}".format(self.line, self.message) -class IncludeError(TinCanException): +class LoadError(TinCanException): """ - Raised when we run into problems #include'ing something, usually + Raised when we run into problems #load'ing something, usually because it doesn't exist. """ def __init__(self, message, source): @@ -51,7 +51,7 @@ self.source = source def __str__(self): - return "{0}: #include error: {1}".format(self.source, self.message) + return "{0}: #load error: {1}".format(self.source, self.message) class ForwardException(TinCanException): """ @@ -128,7 +128,7 @@ """ _NAMES = [ "errors", "forward", "methods", "python", "template" ] _FNAMES = [ "hidden" ] - _ANAMES = [ "include" ] + _ANAMES = [ "load" ] def __init__(self, string): # Initialize our state @@ -187,7 +187,7 @@ # C h a m e l e o n # -# Support for Chameleon templates (the kind TinCan uses by default). +# Support for Chameleon templates (the kind TinCan uses). class ChameleonTemplate(bottle.BaseTemplate): def prepare(self, **options): @@ -327,9 +327,9 @@ # I n c l u s i o n # # Most processing is in the TinCanRoute class; this just interprets and -# represents arguments to the #include header directive. +# represents arguments to the #load header directive. -class _IncludedFile(object): +class _LoadedFile(object): def __init__(self, raw): if raw.startswith('<') and raw.endswith('>'): raw = raw[1:-1] @@ -351,7 +351,7 @@ raise ValueError("file does not end in {0}".format(_IEXTEN)) # Using a cache is likely to help efficiency a lot, since many pages -# will typically #include the same standard stuff. +# will typically #load the same standard stuff. _tcache = {} def _get_template(name, direct): aname = os.path.abspath(os.path.join(direct, name)) @@ -383,10 +383,10 @@ custom code-behind, only two variables are available to your template: request (bottle.Request) and error (bottle.HTTPError). """ - def __init__(self, template, includes, klass): + def __init__(self, template, loads, klass): self._template = template self._template.prepare() - self._includes = includes + self._loads = loads self._class = klass def __call__(self, e): @@ -394,7 +394,7 @@ try: obj = self._class(bottle.request, e) obj.handle() - tvars = self._includes.copy() + tvars = self._loads.copy() tvars.update(obj.export()) return self._template.render(tvars) except bottle.HTTPResponse as e: @@ -423,7 +423,7 @@ self._subdir = subdir self._seen = set() self._app = launcher.app - self._save_includes = launcher.debug + self._save_loads = launcher.debug def launch(self): """ @@ -467,7 +467,7 @@ self._python_specified = True # Obtain a class object by importing and introspecting a module. self._getclass() - # Build body object (#template) and obtain #includes. + # Build body object (#template) and obtain #loads. if self._header.template is not None: if not self._header.template.endswith(_TEXTEN): raise TinCanError("{0}: #template files must end in {1}".format(self._urlpath, _TEXTEN)) @@ -483,22 +483,22 @@ else: self._body = ChameleonTemplate(source=self._template.body) self._body.prepare() - # Process includes - self._includes = {} - for include in self._header.include: + # Process loads + self._loads = {} + for load in self._header.load: try: - include = _IncludedFile(include) + load = _LoadedFile(load) except ValueError as e: - raise TinCanError("{0}: bad #include: {1!s}".format(self._urlpath, e)) from e - if include.in_lib: + raise TinCanError("{0}: bad #load: {1!s}".format(self._urlpath, e)) from e + if load.in_lib: fdir = os.path.join(self._fsroot, _WINF, "tlib") else: fdir = os.path.join(self._fsroot, *self._subdir) try: - tmpl = _get_template(include.fname, fdir) + tmpl = _get_template(load.fname, fdir) except Exception as e: - raise TinCanError("{0}: bad #include: {1!s}".format(self._urlpath, e)) from e - self._includes[include.vname] = tmpl.tpl + raise TinCanError("{0}: bad #load: {1!s}".format(self._urlpath, e)) from e + self._loads[load.vname] = tmpl.tpl # If this is an #errors page, register it as such. if oheader.errors is not None: self._mkerror(oheader.errors) @@ -525,7 +525,7 @@ if not errors: errors = range(_ERRMIN, _ERRMAX+1) route = _TinCanErrorRoute(ChameleonTemplate(source=self._template.body), - self._includes, self._class) + self._loads, self._class) for error in errors: if error < _ERRMIN or error > _ERRMAX: raise TinCanError("{0}: bad #errors code".format(self._urlpath)) @@ -638,7 +638,7 @@ try: obj = self._class(bottle.request, bottle.response) obj.handle() - tvars = self._includes.copy() + tvars = self._loads.copy() tvars.update(obj.export()) return self._body.render(tvars) except ForwardException as fwd: