codeplain 0.3.13.dev47__py3-none-any.whl → 0.3.13.dev48__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.
plain2code_nodes.py CHANGED
@@ -1,119 +1,3 @@
1
- from pathlib import Path
2
- from typing import Mapping, Sequence, TextIO
1
+ """Compatibility shim: the parser now lives in the ``plain-parser`` package."""
3
2
 
4
- from liquid2 import Environment, RenderContext, Template, TemplateNotFoundError
5
- from liquid2.builtin import IncludeTag
6
- from liquid2.builtin.tags.include_tag import IncludeNode
7
-
8
-
9
- class Plain2CodeIncludeNode(IncludeNode):
10
- def render_to_output(self, context: RenderContext, buffer: TextIO) -> int:
11
- """Render the node to the output buffer."""
12
- name = self.name.evaluate(context)
13
- whitespaces = 0
14
- is_comment = False
15
- i = self.token.start
16
- while self.token.source[i] != "\n" and i >= 0:
17
- if self.token.source[i] == " ":
18
- whitespaces += 1
19
- elif self.token.source[i] == ">":
20
- is_comment = True
21
- break
22
- else:
23
- whitespaces = 0
24
- i -= 1
25
-
26
- if is_comment:
27
- return buffer.write(str(self))
28
-
29
- try:
30
- template = context.env.get_template(str(name), context=context, tag=self.tag, whitespaces=whitespaces)
31
- except TemplateNotFoundError as err:
32
- detail = str(err)
33
- long_message = f"""Template not found: {detail}
34
- The required template could not be found. Templates are searched in the following order (highest to lowest precedence):
35
-
36
- 1. The directory containing your .plain file
37
- 2. The directory specified by --template-dir (if provided)
38
- 3. The built-in 'standard_template_library' directory
39
-
40
- Please ensure that the missing template exists in one of these locations, or specify the correct --template-dir if using custom templates.
41
- """
42
- wrapped = TemplateNotFoundError(long_message)
43
- wrapped.token = self.name.token
44
- wrapped.template_name = context.template.full_name()
45
- raise wrapped from err
46
-
47
- namespace: dict[str, object] = dict(arg.evaluate(context) for arg in self.args)
48
-
49
- character_count = 0
50
-
51
- with context.extend(namespace, template=template):
52
- if self.var:
53
- val = self.var.evaluate(context)
54
- key = self.alias or template.name.split(".")[0]
55
-
56
- if isinstance(val, Sequence) and not isinstance(val, str):
57
- context.raise_for_loop_limit(len(val))
58
- for itm in val:
59
- namespace[key] = itm
60
- character_count += template.render_with_context(context, buffer, partial=True)
61
- else:
62
- namespace[key] = val
63
- character_count = template.render_with_context(context, buffer, partial=True)
64
- else:
65
-
66
- character_count = template.render_with_context(context, buffer, partial=True)
67
-
68
- return character_count
69
-
70
-
71
- class Plain2CodeIncludeTag(IncludeTag):
72
- node_class = Plain2CodeIncludeNode
73
-
74
-
75
- class Plain2CodeLoaderMixin:
76
- def __init__(self, *args, **kwargs):
77
- if not hasattr(self, "get_source"):
78
- raise NotImplementedError("Class must implement get_source")
79
- super().__init__(*args, **kwargs)
80
-
81
- def load(
82
- self,
83
- env: Environment,
84
- name: str,
85
- *,
86
- globals: Mapping[str, object] | None = None,
87
- context: RenderContext | None = None,
88
- **kwargs: object,
89
- ) -> Template:
90
- """
91
- Find and parse template source code.
92
-
93
- Args:
94
- env: The `Environment` attempting to load the template source text.
95
- name: A name or identifier for a template's source text.
96
- globals: A mapping of render context variables attached to the
97
- resulting template.
98
- context: An optional render context that can be used to narrow the template
99
- source search space.
100
- kwargs: Arbitrary arguments that can be used to narrow the template source
101
- search space.
102
- """
103
- source, full_name, uptodate, matter = self.get_source(env, name, context=context, **kwargs)
104
- whitespaces = kwargs.get("whitespaces", 0)
105
- assert isinstance(whitespaces, int)
106
- source = source.rstrip().replace("\n", "\n" + " " * whitespaces)
107
-
108
- path = Path(full_name)
109
-
110
- template = env.from_string(
111
- source,
112
- name=path.name,
113
- path=path,
114
- globals=globals,
115
- overlay_data=matter,
116
- )
117
-
118
- template.uptodate = uptodate
119
- return template
3
+ from plain_parser.liquid_nodes import * # noqa: F401,F403
plain2code_utils.py CHANGED
@@ -1,19 +1,4 @@
1
- import re
2
- from typing import Optional
3
-
4
- #
5
- MAX_BASE64_BLOB_LENGTH = 8192
6
-
7
- # Matches a long contiguous base64 / base64url run, optionally preceded by a data: URI header.
8
- _BASE64_BLOB_PATTERN = re.compile(
9
- r"(?:data:[\w.+-]+/[\w.+-]+;base64,)?[A-Za-z0-9+/_-]{%d,}={0,2}" % MAX_BASE64_BLOB_LENGTH
10
- )
11
-
12
-
13
- def find_large_base64_blob(text: str) -> Optional[str]:
14
- """Return the first contiguous base64 blob at or above the threshold, or None."""
15
- match = _BASE64_BLOB_PATTERN.search(text)
16
- return match.group(0) if match else None
1
+ from plain_parser.loaders import MAX_BASE64_BLOB_LENGTH, find_large_base64_blob # noqa: F401
17
2
 
18
3
 
19
4
  def format_duration_hms(total_seconds: float) -> str: