temparse 0.0.2__tar.gz → 0.0.4__tar.gz
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.
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "temparse"
|
|
3
|
-
version = "0.0.
|
|
4
|
-
license = "MIT"
|
|
5
|
-
requires-python = ">=3.14"
|
|
6
|
-
readme = "README.md"
|
|
3
|
+
version = "0.0.4"
|
|
7
4
|
description = "temparse is template + parse"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
license = "MIT"
|
|
8
8
|
classifiers = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
"Environment :: Web Environment",
|
|
10
|
+
"Intended Audience :: Developers",
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Topic :: Software Development :: Code Generators",
|
|
13
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
14
14
|
]
|
|
15
15
|
dependencies = []
|
|
16
16
|
|
|
17
|
-
[project.urls]
|
|
18
|
-
homepage = "https://github.com/jiang-zhexin/temparse"
|
|
19
|
-
|
|
20
17
|
[[project.authors]]
|
|
21
18
|
name = "jiang-zhexin"
|
|
22
19
|
email = "162887873+jiang-zhexin@users.noreply.github.com"
|
|
23
20
|
|
|
24
|
-
[
|
|
25
|
-
|
|
26
|
-
build-backend = "uv_build"
|
|
21
|
+
[project.urls]
|
|
22
|
+
homepage = "https://github.com/jiang-zhexin/temparse"
|
|
27
23
|
|
|
28
24
|
[dependency-groups]
|
|
29
25
|
dev = [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
"pytest>=9.0.3",
|
|
27
|
+
"ruff>=0.15.15",
|
|
28
|
+
"ty>=0.0.43",
|
|
33
29
|
]
|
|
30
|
+
|
|
31
|
+
[build-system]
|
|
32
|
+
requires = ["uv_build>=0.11.15,<0.12.0"]
|
|
33
|
+
build-backend = "uv_build"
|
|
@@ -24,26 +24,30 @@ class Parser[*T]:
|
|
|
24
24
|
```
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
|
-
def __init__(self, template: Template) -> None:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
def __init__(self, template: Template, flags: re.RegexFlag = re.NOFLAG) -> None:
|
|
28
|
+
if len(template.interpolations) == 0:
|
|
29
|
+
raise ValueError("template must contain at least one interpolation")
|
|
30
|
+
|
|
31
|
+
self._template = template
|
|
32
|
+
self._flags = flags
|
|
33
|
+
self._expression = "".join(
|
|
34
|
+
re.escape(item) if isinstance(item, str) else r"(.+?)" for item in template
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
log.debug(f"match expression: {self._expression!r}")
|
|
38
|
+
|
|
39
|
+
@functools.cached_property
|
|
40
|
+
def _match_re(self) -> re.Pattern[str]:
|
|
41
|
+
return re.compile(self._expression, self._flags)
|
|
38
42
|
|
|
39
43
|
def parse(self, s: str) -> tuple[*T]:
|
|
40
|
-
m = self._match_re.
|
|
44
|
+
m = self._match_re.fullmatch(s)
|
|
41
45
|
if m is None:
|
|
42
|
-
raise ValueError(f"
|
|
46
|
+
raise ValueError(f"invalid format: {s!r}")
|
|
43
47
|
|
|
44
48
|
return tuple(
|
|
45
49
|
_convert(text, interpolation)
|
|
46
|
-
for text, interpolation in zip(m.groups(), self.
|
|
50
|
+
for text, interpolation in zip(m.groups(), self._template.interpolations)
|
|
47
51
|
)
|
|
48
52
|
|
|
49
53
|
|
|
@@ -61,16 +65,16 @@ class parse[*T]:
|
|
|
61
65
|
```
|
|
62
66
|
"""
|
|
63
67
|
|
|
64
|
-
def __new__(cls, t: Template, s: str) -> tuple[*T]:
|
|
68
|
+
def __new__(cls, t: Template, s: str, flags: re.RegexFlag = re.NOFLAG) -> tuple[*T]:
|
|
65
69
|
"""
|
|
66
70
|
Used to replace this function until [PEP 718](https://peps.python.org/pep-0718/) is accepted.
|
|
67
71
|
|
|
68
72
|
```python
|
|
69
|
-
def parse[*T](t: Template, s: str) -> tuple[*T]:
|
|
73
|
+
def parse[*T](t: Template, s: str, flags: re.RegexFlag = re.NOFLAG) -> tuple[*T]:
|
|
70
74
|
return Parser(t).parse(s)
|
|
71
75
|
```
|
|
72
76
|
"""
|
|
73
|
-
return Parser(t).parse(s)
|
|
77
|
+
return Parser(t, flags).parse(s)
|
|
74
78
|
|
|
75
79
|
|
|
76
80
|
class Conversion[T]:
|
|
File without changes
|
|
File without changes
|