Files
SIA/sia/entry.py

56 lines
1.4 KiB
Python

from abc import ABC, abstractmethod
from datetime import datetime
import xml.etree.ElementTree as ET
class Entry(ABC):
"""
Abstract base class for all entry types in the working memory.
"""
def __init__(self, id: str, timestamp: datetime):
"""
Initialize a new entry with provided id and timestamp.
Args:
id: Unique identifier for this entry
timestamp: Creation timestamp for this entry
"""
self._id = id
self._timestamp = timestamp
@property
def id(self) -> str:
"""Get entry's unique identifier."""
return self._id
@property
def timestamp(self) -> datetime:
"""Get entry's creation timestamp."""
return self._timestamp
@abstractmethod
def update(self) -> None:
"""
Update the entry's state.
Must be implemented by concrete classes.
"""
pass
@abstractmethod
def generate_context(self) -> ET.Element:
"""
Generate an XML Element representing this entry's context.
Must be implemented by concrete classes.
Returns:
ET.Element: XML element containing the entry's data
"""
pass
def cleanup(self) -> None:
"""
Clean up any resources used by this entry.
Should be overridden by classes that need cleanup.
Default implementation does nothing.
"""
pass