mapres 2.2.1__tar.gz → 2.3__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.2.1
3
+ Version: 2.3
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.2.1"
10
+ version = "2.3"
11
11
  description = "A powerfull mapping utility"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.9"
@@ -33,6 +33,7 @@ class DataMap:
33
33
  def get_syntax(cls):
34
34
  return getattr(cls, "__syntax__", syntax.braces)
35
35
 
36
+
36
37
  # decorator
37
38
  def datamap(
38
39
  _cls = None,
@@ -46,7 +47,12 @@ def datamap(
46
47
  cls.__mode__ = mode
47
48
  namespace = dict(cls.__dict__)
48
49
  namespace["__dict__"] = {}
50
+ # preserve any rules class defined in the original namespace by attaching it to the generated class
51
+ rules_obj = namespace.get("rules", None)
49
52
  cls = type(cls.__name__, (DataMap,), namespace)
53
+ # attach rules (if present) to the new class so validators can read them via the datamap class
54
+ if rules_obj is not None:
55
+ setattr(cls, "rules", rules_obj)
50
56
  return dataclass(frozen=False)(cls)
51
57
  return wrap if _cls is None else wrap(_cls)
52
58
 
@@ -55,4 +61,4 @@ def datamap(
55
61
  datamap.braces = datamap(syntax=syntax.braces)
56
62
  datamap.angles = datamap(syntax=syntax.angles)
57
63
  datamap.dollars = datamap(syntax=syntax.dollars)
58
- datamap.percents = datamap(syntax=syntax.percents)
64
+ datamap.percents = datamap(syntax=syntax.percents)
@@ -88,7 +88,12 @@ class MapResolver:
88
88
  continue
89
89
  if k in d:
90
90
  return str(d[k])
91
- raise MissingKeyError(f"Missing key '{k}' in any layer")
91
+
92
+ if k in ctx:
93
+ return str(ctx[k])
94
+
95
+ raise MissingKeyError(f"Missing key '{k}' in any layer or context")
96
+
92
97
  try:
93
98
  text = re.sub(pattern, repl, text)
94
99
  except re.error as exc:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapres
3
- Version: 2.2.1
3
+ Version: 2.3
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