annotate jadestache.py @ 42:530650b3bc40 default tip

something changed in pom to break pyjwt. switched to jwskate
author drewp@bigasterisk.com
date Wed, 14 Dec 2022 22:07:19 -0800
parents 293a694304b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
1 import pyjade
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
2 import pyjade.exceptions
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
3 import pystache
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
4
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
5
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
6 class _JadeLoader(pystache.loader.Loader):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
7 """
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
8 expands jade of incoming files. Also includes a cache so it doesn't
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
9 read the same file twice
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10 """
41
293a694304b8 reformat
drewp@bigasterisk.com
parents: 30
diff changeset
11
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
12 def __init__(self, *args, **kw):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
13 pystache.renderer.Loader.__init__(self, *args, **kw)
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
14 self.seen = {} # path : expanded jade
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
15
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
16 def read(self, path, encoding=None):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
17 if path in self.seen:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
18 return self.seen[path]
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
19
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
20 b = pystache.common.read(path)
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
21
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
22 if encoding is None:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
23 encoding = self.file_encoding
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
24
28
7c82ffbca5d0 py3 and k8s upgrade
drewp@bigasterisk.com
parents: 2
diff changeset
25 src = self.str(b, encoding)
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
26
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
27 expanded = pyjade.utils.process(src)
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
28 self.seen[path] = expanded
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
29 return expanded
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
30
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
31
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
32 class Renderer(pystache.renderer.Renderer):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
33 """
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
34 pystache renderer that expands base jade syntax on its input
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
35 files. No jade data interpolation happens, so you could use these
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
36 same templates in the browser with js mustache.
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
37
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
38 Files need to end with .mustache since it's the mustache loader
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
39 that's going to look for them.
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
40 """
41
293a694304b8 reformat
drewp@bigasterisk.com
parents: 30
diff changeset
41
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
42 def __init__(self, *args, **kw):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
43 debug = False
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
44 if 'debug' in kw:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
45 debug = kw['debug']
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
46 del kw['debug']
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
47 pystache.renderer.Renderer.__init__(self, *args, **kw)
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
48 self._loader = None if debug else self._new_loader()
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
49
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
50 def _new_loader(self):
30
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
51 return _JadeLoader(file_encoding=self.file_encoding,
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
52 extension=self.file_extension,
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
53 to_unicode=self.str,
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
54 search_dirs=self.search_dirs)
e86642cf7393 style and requirements.txt cleanup
drewp@bigasterisk.com
parents: 28
diff changeset
55
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
56 def _make_loader(self):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
57 if self._loader is not None:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
58 return self._loader
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
59 else:
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
60 # this is for debug mode, to make the templates get reread
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
61 return self._new_loader()