PersistentObjects 0.1.4__tar.gz → 0.1.5__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: PersistentObjects
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: JSON-backed attribute-persistent object with namespace support
5
5
  Author: Tornado300
6
6
  License-Expression: MIT
@@ -66,11 +66,36 @@ class _PersistentState:
66
66
 
67
67
 
68
68
  class _Namespace:
69
+ _instances = {}
70
+
71
+ def __new__(cls, root, key):
72
+ # Create unique identifier for this namespace
73
+ instance_key = (id(root), key)
74
+
75
+ if instance_key in cls._instances:
76
+ return cls._instances[instance_key]
77
+
78
+ instance = super().__new__(cls)
79
+ cls._instances[instance_key] = instance
80
+ return instance
81
+
69
82
  def __init__(self, root, key):
83
+ # Prevent re-initialization
84
+ if hasattr(self, "_initialized"):
85
+ return
86
+
87
+ self._initialized = True
70
88
  self._root = root
71
89
  self._key = key
72
90
 
73
91
  def __getattr__(self, name):
92
+ if name.startswith("_"):
93
+ raise AttributeError(name)
94
+ if name.endswith("_"):
95
+ try:
96
+ return super().__getattribute__(name[:-1])
97
+ except AttributeError:
98
+ raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'.\n Notice: Attribute '{name}' is not persistent!")
74
99
  try:
75
100
  return self._root._data[self._key][name]
76
101
  except KeyError:
@@ -81,6 +106,10 @@ class _Namespace:
81
106
  super().__setattr__(name, value)
82
107
  return
83
108
 
109
+ if name.endswith("_"):
110
+ super().__setattr__(name[:-1], value)
111
+ return
112
+
84
113
  with self._root._lock:
85
114
  bucket = self._root._data.setdefault(self._key, {})
86
115
  bucket[name] = value
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PersistentObjects
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: JSON-backed attribute-persistent object with namespace support
5
5
  Author: Tornado300
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PersistentObjects"
7
- version = "0.1.4"
7
+ version = "0.1.5"
8
8
  description = "JSON-backed attribute-persistent object with namespace support"
9
9
  authors = [
10
10
  { name="Tornado300" }