python-liquid 1.11.0__py3-none-any.whl → 1.12.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- liquid/__init__.py +5 -1
- liquid/builtin/loaders/__init__.py +104 -0
- liquid/exceptions.py +4 -0
- liquid/loaders.py +4 -0
- liquid/utils/cache.py +5 -0
- {python_liquid-1.11.0.dist-info → python_liquid-1.12.0.dist-info}/METADATA +1 -1
- {python_liquid-1.11.0.dist-info → python_liquid-1.12.0.dist-info}/RECORD +9 -9
- {python_liquid-1.11.0.dist-info → python_liquid-1.12.0.dist-info}/WHEEL +0 -0
- {python_liquid-1.11.0.dist-info → python_liquid-1.12.0.dist-info}/licenses/LICENSE +0 -0
liquid/__init__.py
CHANGED
|
@@ -19,6 +19,8 @@ from .loaders import DictLoader
|
|
|
19
19
|
from .loaders import FileExtensionLoader
|
|
20
20
|
from .loaders import FileSystemLoader
|
|
21
21
|
from .loaders import PackageLoader
|
|
22
|
+
from .loaders import make_choice_loader
|
|
23
|
+
from .loaders import make_file_system_loader
|
|
22
24
|
|
|
23
25
|
from .context import Context
|
|
24
26
|
from .context import DebugUndefined
|
|
@@ -44,7 +46,7 @@ from .static_analysis import ContextualTemplateAnalysis
|
|
|
44
46
|
|
|
45
47
|
from . import future
|
|
46
48
|
|
|
47
|
-
__version__ = "1.
|
|
49
|
+
__version__ = "1.12.0"
|
|
48
50
|
|
|
49
51
|
__all__ = (
|
|
50
52
|
"AwareBoundTemplate",
|
|
@@ -67,6 +69,8 @@ __all__ = (
|
|
|
67
69
|
"FutureBoundTemplate",
|
|
68
70
|
"FutureContext",
|
|
69
71
|
"is_undefined",
|
|
72
|
+
"make_choice_loader",
|
|
73
|
+
"make_file_system_loader",
|
|
70
74
|
"Markup",
|
|
71
75
|
"Mode",
|
|
72
76
|
"PackageLoader",
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Iterable
|
|
3
|
+
from typing import List
|
|
4
|
+
from typing import Union
|
|
5
|
+
|
|
1
6
|
from .base_loader import BaseLoader
|
|
2
7
|
from .base_loader import DictLoader
|
|
3
8
|
from .base_loader import TemplateNamespace
|
|
@@ -22,8 +27,107 @@ __all__ = (
|
|
|
22
27
|
"DictLoader",
|
|
23
28
|
"FileExtensionLoader",
|
|
24
29
|
"FileSystemLoader",
|
|
30
|
+
"make_choice_loader",
|
|
31
|
+
"make_file_system_loader",
|
|
25
32
|
"PackageLoader",
|
|
26
33
|
"TemplateNamespace",
|
|
27
34
|
"TemplateSource",
|
|
28
35
|
"UpToDate",
|
|
29
36
|
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def make_file_system_loader(
|
|
40
|
+
search_path: Union[str, Path, Iterable[Union[str, Path]]],
|
|
41
|
+
*,
|
|
42
|
+
encoding: str = "utf-8",
|
|
43
|
+
ext: str = ".liquid",
|
|
44
|
+
auto_reload: bool = True,
|
|
45
|
+
namespace_key: str = "",
|
|
46
|
+
cache_size: int = 300,
|
|
47
|
+
) -> BaseLoader:
|
|
48
|
+
"""A _file system_ template loader factory.
|
|
49
|
+
|
|
50
|
+
Returns one of `CachingFileSystemLoader`, `FileExtensionLoader` or
|
|
51
|
+
`FileSystemLoader` depending in the given arguments.
|
|
52
|
+
|
|
53
|
+
A `CachingFileSystemLoader` is returned if _cache_size_ is greater than 0.
|
|
54
|
+
Otherwise a `FileExtensionLoader` is returned if _ext_ is not empty.
|
|
55
|
+
If _ext_ is empty, a `FileSystemLoader` is returned.
|
|
56
|
+
|
|
57
|
+
_auto_reload_ and _namespace_key_ are ignored if _cache_key_ is less than 1.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
search_path: One or more paths to search.
|
|
61
|
+
encoding: Open template files with the given encoding.
|
|
62
|
+
ext: A default file extension. Should include a leading period.
|
|
63
|
+
auto_reload: If `True`, automatically reload a cached template if it has been
|
|
64
|
+
updated.
|
|
65
|
+
namespace_key: The name of a global render context variable or loader keyword
|
|
66
|
+
argument that resolves to the current loader "namespace" or "scope".
|
|
67
|
+
|
|
68
|
+
If you're developing a multi-user application, a good namespace might be
|
|
69
|
+
`uid`, where `uid` is a unique identifier for a user and templates are
|
|
70
|
+
arranged in folders named for each `uid` inside the search path.
|
|
71
|
+
cache_size: The maximum number of templates to hold in the cache before removing
|
|
72
|
+
the least recently used template.
|
|
73
|
+
|
|
74
|
+
_New in version 1.12.0_
|
|
75
|
+
"""
|
|
76
|
+
if cache_size > 0:
|
|
77
|
+
return CachingFileSystemLoader(
|
|
78
|
+
search_path=search_path,
|
|
79
|
+
encoding=encoding,
|
|
80
|
+
ext=ext,
|
|
81
|
+
auto_reload=auto_reload,
|
|
82
|
+
namespace_key=namespace_key,
|
|
83
|
+
cache_size=cache_size,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if ext:
|
|
87
|
+
return FileExtensionLoader(
|
|
88
|
+
search_path=search_path,
|
|
89
|
+
encoding=encoding,
|
|
90
|
+
ext=ext,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
return FileSystemLoader(search_path=search_path, encoding=encoding)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def make_choice_loader(
|
|
97
|
+
loaders: List[BaseLoader],
|
|
98
|
+
*,
|
|
99
|
+
auto_reload: bool = True,
|
|
100
|
+
namespace_key: str = "",
|
|
101
|
+
cache_size: int = 300,
|
|
102
|
+
) -> BaseLoader:
|
|
103
|
+
"""A _choice loader_ factory.
|
|
104
|
+
|
|
105
|
+
Returns one of `CachingChoiceLoader` or `ChoiceLoader` depending on the
|
|
106
|
+
given arguments.
|
|
107
|
+
|
|
108
|
+
A `CachingChoiceLoader` is returned if _cache_size_ > 0, otherwise a
|
|
109
|
+
`ChoiceLoader` is returned.
|
|
110
|
+
|
|
111
|
+
_auto_reload_ and _namespace_key_ are ignored if _cache_key_ is less than 1.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
loaders: A list of loaders implementing `liquid.loaders.BaseLoader`.
|
|
115
|
+
auto_reload: If `True`, automatically reload a cached template if it
|
|
116
|
+
has been updated.
|
|
117
|
+
namespace_key: The name of a global render context variable or loader
|
|
118
|
+
keyword argument that resolves to the current loader "namespace" or
|
|
119
|
+
"scope".
|
|
120
|
+
cache_size: The maximum number of templates to hold in the cache before
|
|
121
|
+
removing the least recently used template.
|
|
122
|
+
|
|
123
|
+
_New in version 1.12.0_
|
|
124
|
+
"""
|
|
125
|
+
if cache_size > 0:
|
|
126
|
+
return CachingChoiceLoader(
|
|
127
|
+
loaders=loaders,
|
|
128
|
+
auto_reload=auto_reload,
|
|
129
|
+
namespace_key=namespace_key,
|
|
130
|
+
cache_size=cache_size,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
return ChoiceLoader(loaders=loaders)
|
liquid/exceptions.py
CHANGED
liquid/loaders.py
CHANGED
|
@@ -10,6 +10,8 @@ from .builtin.loaders import PackageLoader
|
|
|
10
10
|
from .builtin.loaders import TemplateNamespace
|
|
11
11
|
from .builtin.loaders import TemplateSource
|
|
12
12
|
from .builtin.loaders import UpToDate
|
|
13
|
+
from .builtin.loaders import make_choice_loader
|
|
14
|
+
from .builtin.loaders import make_file_system_loader
|
|
13
15
|
|
|
14
16
|
__all__ = (
|
|
15
17
|
"BaseLoader",
|
|
@@ -19,6 +21,8 @@ __all__ = (
|
|
|
19
21
|
"DictLoader",
|
|
20
22
|
"FileExtensionLoader",
|
|
21
23
|
"FileSystemLoader",
|
|
24
|
+
"make_choice_loader",
|
|
25
|
+
"make_file_system_loader",
|
|
22
26
|
"PackageLoader",
|
|
23
27
|
"TemplateNamespace",
|
|
24
28
|
"TemplateSource",
|
liquid/utils/cache.py
CHANGED
|
@@ -36,6 +36,8 @@ from collections import abc
|
|
|
36
36
|
from collections import deque
|
|
37
37
|
from threading import Lock
|
|
38
38
|
|
|
39
|
+
from liquid.exceptions import CacheCapacityValueError
|
|
40
|
+
|
|
39
41
|
|
|
40
42
|
class LRUCache(abc.MutableMapping):
|
|
41
43
|
"""A simple LRU Cache implementation."""
|
|
@@ -45,6 +47,9 @@ class LRUCache(abc.MutableMapping):
|
|
|
45
47
|
# won't do any harm.
|
|
46
48
|
|
|
47
49
|
def __init__(self, capacity: int):
|
|
50
|
+
if capacity < 1:
|
|
51
|
+
raise CacheCapacityValueError("cache size must be greater than 1")
|
|
52
|
+
|
|
48
53
|
self.capacity = capacity
|
|
49
54
|
self._mapping = {}
|
|
50
55
|
self._queue = deque()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-liquid
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.12.0
|
|
4
4
|
Summary: A Python engine for the Liquid template language.
|
|
5
5
|
Project-URL: Change Log, https://github.com/jg-rp/liquid/blob/main/CHANGES.md
|
|
6
6
|
Project-URL: Documentation, https://jg-rp.github.io/liquid/
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
liquid/__init__.py,sha256=
|
|
1
|
+
liquid/__init__.py,sha256=0nYsF01jFXyXrxYCLnglEp0H4H7fHG7_tyh91X4td5o,2173
|
|
2
2
|
liquid/analyze_tags.py,sha256=PKMBk4lFWNwkfuMY9ulou6QeSq676IgQmC88JqfeO0k,7503
|
|
3
3
|
liquid/ast.py,sha256=zawW4ryxo_0ExGKpMYUifbtD7F5SlmlMrDJvCVTfWCM,8313
|
|
4
4
|
liquid/chain_map.py,sha256=nxkw3wwF6ddlGarIuL7Ii2elm4dU80LySgdQx1oift0,1517
|
|
5
5
|
liquid/context.py,sha256=cHn0IYhtOM3xlujn1M0fY0KO9WMS8sMNj9AWjTxicZg,26261
|
|
6
6
|
liquid/environment.py,sha256=9PhcexMoKW30pmFzfo8so7pZhweO_WCk6SRQp0w-jdo,30780
|
|
7
|
-
liquid/exceptions.py,sha256=
|
|
7
|
+
liquid/exceptions.py,sha256=gbqQcwJmChp6FCGQdxTWo0mstQtAqmp3-MkUT-evlFI,6691
|
|
8
8
|
liquid/expression.py,sha256=NwI8ZIbfqY8HejYZJiNTRCdu_KvEkPtDD9_PIepsmsk,35252
|
|
9
9
|
liquid/filter.py,sha256=AOBC4cU4eLLiiUvLfb9L0zZvR38ln0BSKqlIy41AUd4,6315
|
|
10
10
|
liquid/lex.py,sha256=pizKyPdIqRNT6TN5NolRhBI3oBpTyoYwJS_DCyyQhg8,15137
|
|
11
11
|
liquid/limits.py,sha256=N3InvvDMg9lTVc6vUhKftV206Oz8D3Pmg_a_jZtgyro,1675
|
|
12
|
-
liquid/loaders.py,sha256=
|
|
12
|
+
liquid/loaders.py,sha256=aXh-hiDyYV6gaBEWRkUORawkhJ4hbBwXP8Sbv9c4j7c,937
|
|
13
13
|
liquid/mode.py,sha256=nYm-oYRkcZk1j-pmYPXMBqfQMMfYYB13SHI2OWHHFr0,207
|
|
14
14
|
liquid/output.py,sha256=QEL_dg4Opb63W0pv1P-4IpUX36uAtuJf9sKxZbVLGxk,773
|
|
15
15
|
liquid/parse.py,sha256=50BT569pjW1sYAofiJ2SVzZgzKlma9lKPStF7EPfE1w,27131
|
|
@@ -33,7 +33,7 @@ liquid/builtin/filters/extra.py,sha256=7_8mUD6DlNLBti-TVCeqzI2NpCmua_OJrwYa5re6c
|
|
|
33
33
|
liquid/builtin/filters/math.py,sha256=ZEzeX5Rw9gTTtIEnR951MXl_1Fv9j2ntfM9EDzmSYlU,3804
|
|
34
34
|
liquid/builtin/filters/misc.py,sha256=z4DXSqidAqZ0F3W5Kr__mebAghDmzYzGr4BzE5-tsFY,3436
|
|
35
35
|
liquid/builtin/filters/string.py,sha256=GJMl2nFcygAz73snVsud4lX0Gk0VhwGbhldeX558SSo,9964
|
|
36
|
-
liquid/builtin/loaders/__init__.py,sha256=
|
|
36
|
+
liquid/builtin/loaders/__init__.py,sha256=9B7KAc-HoNd-pUNwJ-Syzr_8JsBD2S7feYwulUWtrtk,4309
|
|
37
37
|
liquid/builtin/loaders/base_loader.py,sha256=ks_tfzx1t0Dg2gW0Ewr-jHn4KKd5oUWXdREh_n2zHEY,9509
|
|
38
38
|
liquid/builtin/loaders/caching_file_system_loader.py,sha256=3_rGFWv2A3caYmGiaXqjJF-kqEFnU5oZj9R95y1Qc3w,2681
|
|
39
39
|
liquid/builtin/loaders/choice_loader.py,sha256=89rXKA6LR66BqA5ZQEOM9JwRIjPdLUtb3_DyJel8C4I,4566
|
|
@@ -176,11 +176,11 @@ liquid/golden/url_encode_filter.py,sha256=pT6u0Ib44AgIKeHUdNGgpRZNjZzFwRwkvhjY8w
|
|
|
176
176
|
liquid/golden/where_filter.py,sha256=8myDb6AUCMU3qgBihU8-O-MehzeLEXUsXe7q9XGVckg,3858
|
|
177
177
|
liquid/golden/whitespace_control.py,sha256=uAcIIuE1DFWRQhP3fQmI0S3LumMGlIfvWQMIqbxbWMw,7809
|
|
178
178
|
liquid/utils/__init__.py,sha256=X8Dc_jIJKRCccurGqHGqin8IJswNUta-cV9XoRANmEQ,230
|
|
179
|
-
liquid/utils/cache.py,sha256=
|
|
179
|
+
liquid/utils/cache.py,sha256=9fgOrkocCSSQNHNjXmeh0EssK6ZfFmF6pB-0asogSLc,6457
|
|
180
180
|
liquid/utils/cache.pyi,sha256=4Vgtz5vk9IDPnD43AOnby1kWEJJgGH3fsHgQ-B7qa4M,543
|
|
181
181
|
liquid/utils/html.py,sha256=47ACnJLEMSRkDgqDLBujmT091pk0EjoapmlZxkzz3D8,1755
|
|
182
182
|
liquid/utils/text.py,sha256=1SwDECNMaqnnZ05je_AZZgxqzZd6U-mvq5jNU3W1-Qk,841
|
|
183
|
-
python_liquid-1.
|
|
184
|
-
python_liquid-1.
|
|
185
|
-
python_liquid-1.
|
|
186
|
-
python_liquid-1.
|
|
183
|
+
python_liquid-1.12.0.dist-info/METADATA,sha256=z32jYN1wGgKeuwpN8lzbgd1Ck3furve1KTkBD7FARPE,7925
|
|
184
|
+
python_liquid-1.12.0.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
|
|
185
|
+
python_liquid-1.12.0.dist-info/licenses/LICENSE,sha256=yAFURzud5ERNHt1rZIPnTLJ92ep7q8y5yG9g5DUMR_E,1075
|
|
186
|
+
python_liquid-1.12.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|