Source code for ddf.ddf
"""Sample Implementation of Node and AntLink classes."""
import datetime
from dataclasses import dataclass
from uuid import UUID
UUID_VERSION = 7
"""UUIDs should use version 7 to be able to encode a datetime."""
[docs]
@dataclass
class NodeId:
"""Represent a Node.
For security reasons: use any version of UUID (i.e. UUIDv4)
"""
uuid: UUID
def __hash__(self) -> int:
return self.uuid.__hash__()
[docs]
@dataclass
class ObjectId:
"""Represent an object.
This could be a reference to a timestamp or a batch.
"""
uuid: UUID
def __hash__(self) -> int:
return self.uuid.__hash__()
[docs]
def pretty_print_uuid7(uuid: UUID) -> str:
if uuid.version == UUID_VERSION:
return datetime.datetime.fromtimestamp(uuid.time).strftime("%c")
else:
return ""