mapres 2.1__tar.gz → 2.2__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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapres
3
- Version: 2.1
3
+ Version: 2.2
4
4
  Summary: A powerfull mapping utility
5
5
  Author: iFamished
6
6
  License: MIT
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "mapres"
10
- version = "2.1"
10
+ version = "2.2"
11
11
  description = "A powerfull mapping utility"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.9"
@@ -61,32 +61,38 @@ class MapResolver:
61
61
  return text
62
62
 
63
63
  # layered maps
64
- def _apply_maps(self, text: str, ctx: dict, layerstack: LayerStack) -> str:
64
+ def _apply_maps(self, text: str, ctx: dict, layerstack: LayerStack):
65
+ syntax_patterns = []
65
66
  for m in layerstack:
66
-
67
- # class-based layer
68
67
  if isinstance(m, type) and hasattr(m, "as_map"):
69
68
  m = m()
70
69
  if hasattr(m, "as_map"):
71
- pattern = m.get_syntax()
72
- d = m.as_map()
70
+ syntax_patterns.append(m.get_syntax())
73
71
  elif isinstance(m, dict):
74
72
  pattern = ctx.get("syntax")
75
- if not pattern:
76
- continue
77
- d = m
78
- else:
79
- continue
80
-
81
- def repl(match: re.Match) -> str:
73
+ if pattern:
74
+ syntax_patterns.append(pattern)
75
+ syntax_patterns = list(dict.fromkeys(syntax_patterns))
76
+ for pattern in syntax_patterns:
77
+ def repl(match: re.Match):
82
78
  k = match.group(1)
83
- if k not in d:
84
- raise MissingKeyError(f"Missing key '{k}' in layer {m}")
85
- return str(d[k])
79
+ for m in layerstack:
80
+ layer = m
81
+ if isinstance(layer, type) and hasattr(layer, "as_map"):
82
+ layer = layer()
83
+ if hasattr(layer, "as_map"):
84
+ d = layer.as_map()
85
+ elif isinstance(layer, dict):
86
+ d = layer
87
+ else:
88
+ continue
89
+ if k in d:
90
+ return str(d[k])
91
+ raise MissingKeyError(f"Missing key '{k}' in any layer")
86
92
  try:
87
93
  text = re.sub(pattern, repl, text)
88
94
  except re.error as exc:
89
- raise MapSyntaxError(f"Regex error in layer {m}: {exc}") from exc
95
+ raise MapSyntaxError(f"Regex error in syntax pattern {pattern}: {exc}") from exc
90
96
  return text
91
97
 
92
98
  # context
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapres
3
- Version: 2.1
3
+ Version: 2.2
4
4
  Summary: A powerfull mapping utility
5
5
  Author: iFamished
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes