Mercurial > cgi-bin > hgweb.cgi > tincan
comparison tincan.py @ 34:0fb455b46e5f draft header-includes
Add cache.
author | David Barts <n5jrn@me.com> |
---|---|
date | Mon, 27 May 2019 20:09:55 -0700 |
parents | cc975bf7a3fa |
children | 41da0b3d2156 |
comparison
equal
deleted
inserted
replaced
33:cc975bf7a3fa | 34:0fb455b46e5f |
---|---|
348 if self.fname == "": | 348 if self.fname == "": |
349 raise ValueError("empty file name") | 349 raise ValueError("empty file name") |
350 if not self.fname.endswith(_IEXTEN): | 350 if not self.fname.endswith(_IEXTEN): |
351 raise ValueError("file does not end in {0}".format(_IEXTEN)) | 351 raise ValueError("file does not end in {0}".format(_IEXTEN)) |
352 | 352 |
353 # Using a cache is likely to help efficiency a lot, since many pages | |
354 # will typically #include the same standard stuff. | |
355 _tcache = {} | |
356 def _get_template(name, direct): | |
357 aname = os.path.abspath(os.path.join(direct, name)) | |
358 if aname not in _tcache: | |
359 tmpl = ChameleonTemplate(name=name, lookup=[direct]) | |
360 tmpl.prepare() | |
361 assert aname == tmpl.filename | |
362 _tcache[aname] = tmpl | |
363 return _tcache[aname] | |
364 | |
353 # R o u t e s | 365 # R o u t e s |
354 # | 366 # |
355 # Represents a route in TinCan. Our launcher creates these on-the-fly based | 367 # Represents a route in TinCan. Our launcher creates these on-the-fly based |
356 # on the files it finds. | 368 # on the files it finds. |
357 | 369 |
481 if include.in_lib: | 493 if include.in_lib: |
482 fdir = os.path.join(self._fsroot, _WINF, "tlib") | 494 fdir = os.path.join(self._fsroot, _WINF, "tlib") |
483 else: | 495 else: |
484 fdir = os.path.join(self._fsroot, *self._subdir) | 496 fdir = os.path.join(self._fsroot, *self._subdir) |
485 try: | 497 try: |
486 tmpl = ChameleonTemplate(name=include.fname, lookup=[fdir]) | 498 tmpl = _get_template(include.fname, fdir) |
487 tmpl.prepare() | |
488 except Exception as e: | 499 except Exception as e: |
489 raise TinCanError("{0}: bad #include: {1!s}".format(self._urlpath, e)) from e | 500 raise TinCanError("{0}: bad #include: {1!s}".format(self._urlpath, e)) from e |
490 self._includes[include.vname] = tmpl.tpl | 501 self._includes[include.vname] = tmpl.tpl |
491 # If this is an #errors page, register it as such. | 502 # If this is an #errors page, register it as such. |
492 if oheader.errors is not None: | 503 if oheader.errors is not None: |