Mercurial > piecrust2
annotate piecrust/templating/base.py @ 1188:a7c43131d871
bake: Fix file write flushing problem with Python 3.8+
Writing the cache files fails in Python 3.8 because it looks like flushing
behaviour has changed. We need to explicitly flush. And even then, in very
rare occurrences, it looks like it can still run into racing conditions,
so we do a very hacky and ugly "retry" loop when fetching cached data :(
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 15 Jun 2021 22:36:23 -0700 |
parents | c4cf3cfe2726 |
children |
rev | line source |
---|---|
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 class TemplateNotFoundError(Exception): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 pass |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
128
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
7 class TemplatingError(Exception): |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
8 def __init__(self, message, filename=None, lineno=-1): |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
9 super(TemplatingError, self).__init__() |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
10 self.message = message |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
11 self.filename = filename |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
12 self.lineno = lineno |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
13 |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
14 def __str__(self): |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
15 msg = '' |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
16 if self.filename: |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
17 msg += self.filename |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
18 if self.lineno >= 0: |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
19 msg += ', line %d' % self.lineno |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
20 msg += ': ' + self.message |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
21 return msg |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
22 |
28444014ce7d
Fix error reporting and counting of lines.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
23 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 class TemplateEngine(object): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 EXTENSIONS = [] |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 def initialize(self, app): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 self.app = app |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 |
1011
c4cf3cfe2726
bake: Better performance stats, and add callback to preload templates.
Ludovic Chabant <ludovic@chabant.com>
parents:
924
diff
changeset
|
30 def populateCache(self): |
c4cf3cfe2726
bake: Better performance stats, and add callback to preload templates.
Ludovic Chabant <ludovic@chabant.com>
parents:
924
diff
changeset
|
31 pass |
c4cf3cfe2726
bake: Better performance stats, and add callback to preload templates.
Ludovic Chabant <ludovic@chabant.com>
parents:
924
diff
changeset
|
32 |
924
1bb704434ee2
formatting: Remove segment parts, you can use template tags instead.
Ludovic Chabant <ludovic@chabant.com>
parents:
454
diff
changeset
|
33 def renderSegment(self, path, segment, data): |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 raise NotImplementedError() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 def renderFile(self, paths, data): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 raise NotImplementedError() |