57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
from datetime import datetime
|
|
import xml.etree.ElementTree as ET
|
|
|
|
from .entry import Entry
|
|
|
|
class ParseErrorEntry(Entry):
|
|
"""
|
|
Entry type for parse and validation errors.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
id: str,
|
|
timestamp: datetime,
|
|
content: str,
|
|
error: str,
|
|
):
|
|
"""
|
|
Initialize a new parse error entry.
|
|
|
|
Args:
|
|
id: Unique identifier for this entry
|
|
timestamp: Creation timestamp for this entry
|
|
content: Original content that failed to parse
|
|
error: Error message describing the failure
|
|
"""
|
|
super().__init__(id, timestamp)
|
|
self._content = content
|
|
self._error = error
|
|
|
|
@property
|
|
def content(self) -> str:
|
|
"""Get the original content that failed to parse."""
|
|
return self._content
|
|
|
|
@property
|
|
def error(self) -> str:
|
|
"""Get the error message describing the failure."""
|
|
return self._error
|
|
|
|
def update(self) -> None:
|
|
pass
|
|
|
|
def generate_context(self) -> ET.Element:
|
|
"""
|
|
Generate an XML Element representing this parse error entry.
|
|
|
|
Returns:
|
|
ET.Element: XML element containing the entry's data
|
|
"""
|
|
element = ET.Element("parse_error", {"id": self._id})
|
|
error_elem = ET.SubElement(element, "error")
|
|
error_elem.text = self._error
|
|
content_elem = ET.SubElement(element, "content")
|
|
content_elem.text = self._content
|
|
|
|
return element |