From b41a1eff6763873b8f63d9d4b03c67080cecd0bc Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 19 Nov 2017 02:25:46 +0100 Subject: [PATCH] Categorize stuff in common.py --- common.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common.py b/common.py index 4c114a8..a1bab29 100644 --- a/common.py +++ b/common.py @@ -10,6 +10,7 @@ def readfile(path, binary=False): with open(path, "rb" if binary else "r") as f: return f.read() +#template helpers: def escape_html(data, break_newlines=True): if type(data) is list: data = "\n".join(data) @@ -23,6 +24,7 @@ def escape_html(data, break_newlines=True): def escape_url(data): return "ølailsf"#todo +#decorators: def memoize(func):#a decorator class Memoizer(dict): def getter(self, *args, **kwargs): @@ -49,6 +51,7 @@ def wrap_output(type):#decorator with parameters def call(func):#decorator return func() +#types: class Model: def __setattr__(self, name, value): if not hasattr(self, name): @@ -59,6 +62,7 @@ class Model: ", ".join(f"{i}={getattr(self, i)!r}" for i in dir(self) if "_" not in i) __str__ = __repr__ +#fileloader: class VelocityFileLoader: _cache = {}#static cache, shared between instances def get_file(self, filename):