start implementation on new architecture
This commit is contained in:
54
sia/read_entry.py
Normal file
54
sia/read_entry.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from datetime import datetime
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from .entry import Entry
|
||||
from .util import escape_text_for_xml
|
||||
|
||||
class ReadEntry(Entry):
|
||||
"""
|
||||
Entry type for reading content from standard input.
|
||||
|
||||
Attributes:
|
||||
content: Content read from stdin, empty until first update
|
||||
io_buffer: Buffer to use for IO operations
|
||||
_read: Whether content has been read
|
||||
"""
|
||||
|
||||
def __init__(self, io_buffer, id: str, timestamp: datetime):
|
||||
"""
|
||||
Initialize a new read entry.
|
||||
|
||||
Args:
|
||||
io_buffer: Buffer to use for IO operations
|
||||
id: Unique identifier for this entry
|
||||
timestamp: Creation timestamp for this entry
|
||||
"""
|
||||
super().__init__(id, timestamp)
|
||||
self.content = ""
|
||||
self.io_buffer = io_buffer
|
||||
self._read = False
|
||||
|
||||
def update(self) -> None:
|
||||
"""
|
||||
Read from stdin if not already read.
|
||||
Uses the provided IO buffer for the actual read operation.
|
||||
"""
|
||||
if not self._read:
|
||||
self.content = self.io_buffer.read()
|
||||
self._read = True
|
||||
|
||||
def generate_context(self) -> ET.Element:
|
||||
"""
|
||||
Generate an XML Element representing this read entry.
|
||||
|
||||
Returns:
|
||||
ET.Element: XML element containing the entry's data
|
||||
"""
|
||||
# Create root element
|
||||
element = ET.Element("read_stdin", {"id": self.id})
|
||||
|
||||
# Add content as CDATA or escaped text if content has been read
|
||||
if self._read:
|
||||
element.text = escape_text_for_xml(self.content)
|
||||
|
||||
return element
|
||||
Reference in New Issue
Block a user