Changeset ef964d8 in flexoentity for flexoentity/id_factory.py
- Timestamp:
- 11/27/25 18:12:23 (7 weeks ago)
- Branches:
- master
- Children:
- 4e11d58
- Parents:
- 9a50e0b
- File:
-
- 1 edited
-
flexoentity/id_factory.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
flexoentity/id_factory.py
r9a50e0b ref964d8 78 78 from flexoentity import logger 79 79 80 def canonical_seed(obj) -> str: 81 """ 82 I transform *obj* into a deterministic, comparable text form. 83 84 I remove irrelevant formatting differences so that two equal 85 pieces of data always yield the same hash seed. 86 87 Rules: 88 - If *obj* is a string, I normalize whitespace. 89 - If *obj* is a dict, I JSON-encode it with sorted keys. 90 - If *obj* is an object, I recurse on its __dict__. 91 - Otherwise, I coerce *obj* to str(). 92 """ 93 94 if isinstance(obj, str): 95 text = " ".join(obj.split()) 96 return text 97 if isinstance(obj, dict): 98 return json.dumps(obj, sort_keys=True, separators=(",", ":")) 99 if hasattr(obj, "__dict__"): 100 return canonical_seed(obj.__dict__) 101 return str(obj) 102 80 def canonical_seed(text: str) -> str: 81 """Canonicalize identity-only text_seed.""" 82 if not text: 83 return "" 84 # remove control characters 85 s = re.sub(r"[\t\r\n]+", " ", text) 86 # collapse multiple spaces 87 s = re.sub(r"\s+", " ", s) 88 return s.strip() 103 89 104 90 class FlexOID(str): … … 346 332 347 333 @staticmethod 348 def clone_new_base(domain : str, entity_type: str, state: str, text: str) -> "FlexOID":334 def clone_new_base(domain_id: str, entity_type: str, state: str, text: str) -> "FlexOID": 349 335 """ 350 336 I start a completely new lineage (version 1) for a derived entity. … … 352 338 not share version history with its origin. 353 339 """ 354 return FlexOID.safe_generate(domain , entity_type, state, text, version=1)340 return FlexOID.safe_generate(domain_id, entity_type, state, text, version=1) 355 341 356 342 def to_dict(self) -> dict:
Note:
See TracChangeset
for help on using the changeset viewer.
