Changeset ef964d8 in flexoentity for flexoentity/id_factory.py


Ignore:
Timestamp:
11/27/25 18:12:23 (7 weeks ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
4e11d58
Parents:
9a50e0b
Message:

new serialization structure adopted and tests fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • flexoentity/id_factory.py

    r9a50e0b ref964d8  
    7878from flexoentity import logger
    7979
    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 
     80def 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()
    10389
    10490class FlexOID(str):
     
    346332
    347333    @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":
    349335        """
    350336        I start a completely new lineage (version 1) for a derived entity.
     
    352338        not share version history with its origin.
    353339        """
    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)
    355341
    356342    def to_dict(self) -> dict:
Note: See TracChangeset for help on using the changeset viewer.