from datetime import datetime import xml.etree.ElementTree as ET from .entry import Entry from .io_buffer import IOBuffer class WriteEntry(Entry): """ Entry type for writing content to standard output. Attributes: content: Text content to write to stdout io_buffer: Buffer to use for IO operations _written: Whether the content has been written """ def __init__( self, id: str, timestamp: datetime, content: str, io_buffer: IOBuffer, ): """ Initialize a new write entry. Args: id: Unique identifier for this entry timestamp: Creation timestamp for this entry content: Text to write to stdout io_buffer: Buffer to use for IO operations """ super().__init__(id, timestamp) self.content = content self.io_buffer = io_buffer self._written = False def update(self) -> None: """ Write the content to stdout if not already written. Uses the provided IO buffer for the actual write operation. """ if not self._written: self.io_buffer.write(self.content) self._written = True def generate_context(self) -> ET.Element: """ Generate an XML Element representing this write entry. Returns: ET.Element: XML element containing the entry's data """ element = ET.Element("write_stdout", {"id": self.id}) element.text = self.content return element