55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
import xml.etree.ElementTree as ET
|
|
|
|
from . import Entry
|
|
|
|
class ParseErrorEntry(Entry):
|
|
"""
|
|
Entry type for parse and validation errors.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
id: str,
|
|
content: str,
|
|
error: str,
|
|
):
|
|
"""
|
|
Initialize a new parse error entry.
|
|
|
|
Args:
|
|
id: Unique identifier for this entry
|
|
content: Original content that failed to parse
|
|
error: Error message describing the failure
|
|
"""
|
|
super().__init__(id)
|
|
self.content = content
|
|
self.error = 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
|
|
|
|
def serialize(self):
|
|
"""
|
|
Collect all public attributes of the entry into a dictionary.
|
|
"""
|
|
return {
|
|
"type": "parse_error",
|
|
"id": self._id,
|
|
"content": self.content,
|
|
"error": self.error,
|
|
} |