Skip to content

Commit

Permalink
loader: Restore reload functionality
Browse files Browse the repository at this point in the history
TurboGears requires it
  • Loading branch information
jackrosenthal committed Sep 29, 2024
1 parent d80a6a3 commit 45e8137
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kajiki/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@


class Loader:
def __init__(self):
def __init__(self, reload=False): # noqa: FBT002
self._reload = reload
self.modules = {}

def import_(self, name, **kwargs):
"""Returns the template if it is already in the cache,
else loads the template, caches it and returns it.
"""
mod = self.modules.get(name)
if mod:
if not self._reload and mod:
return mod
mod = self._load(name, **kwargs)
mod.loader = self
Expand All @@ -41,12 +42,13 @@ class FileLoader(Loader):
def __init__(
self,
path,
reload=False, # noqa: FBT002
force_mode=None,
autoescape_text=False, # noqa: FBT002
xml_autoblocks=None,
**template_options,
):
super().__init__()
super().__init__(reload=reload)
from kajiki import TextTemplate, XMLTemplate

if isinstance(path, str):
Expand Down Expand Up @@ -108,8 +110,8 @@ def _load(self, name, encoding="utf-8", **kwargs):


class PackageLoader(FileLoader):
def __init__(self, force_mode=None):
super().__init__(None, force_mode=force_mode)
def __init__(self, reload=False, force_mode=None): # noqa: FBT002
super().__init__(None, reload=reload, force_mode=force_mode)

def _find_resource(self, name):
package, module = name.rsplit(".", 1)
Expand Down

0 comments on commit 45e8137

Please sign in to comment.