2023-10-15 22:21:30 +00:00
|
|
|
from typing import List, Optional, Union
|
2023-10-15 14:34:19 +00:00
|
|
|
|
|
|
|
|
2022-11-01 18:57:50 +00:00
|
|
|
class DrawerNode:
|
2021-08-26 22:22:15 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.children = []
|
|
|
|
|
|
|
|
def append(self, child):
|
|
|
|
self.children.append(child)
|
|
|
|
|
|
|
|
|
2022-11-01 18:57:50 +00:00
|
|
|
class PropertyDrawerNode(DrawerNode):
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Properties: {}>".format(len(self.children))
|
2021-08-26 22:22:15 +00:00
|
|
|
|
|
|
|
|
2022-11-01 18:57:50 +00:00
|
|
|
class LogbookDrawerNode(DrawerNode):
|
2021-08-26 22:22:15 +00:00
|
|
|
def __repr__(self):
|
2022-05-16 21:17:28 +00:00
|
|
|
return "<LogBook: {}>".format(len(self.children))
|
|
|
|
|
|
|
|
|
2022-11-01 18:57:50 +00:00
|
|
|
class ResultsDrawerNode(DrawerNode):
|
2022-05-16 21:17:28 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "<Results: {}>".format(len(self.children))
|
2021-08-26 22:22:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PropertyNode:
|
|
|
|
def __init__(self, key, value):
|
|
|
|
self.key = key
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def __repr__(self):
|
2023-01-03 23:36:20 +00:00
|
|
|
return "{{{}: {}}}".format(self.key, self.value)
|
2021-08-26 22:22:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ListGroupNode:
|
|
|
|
def __init__(self):
|
|
|
|
self.children = []
|
|
|
|
|
|
|
|
def append(self, child):
|
|
|
|
self.children.append(child)
|
|
|
|
|
2022-11-03 22:01:21 +00:00
|
|
|
def get_raw(self):
|
2024-08-18 20:44:00 +00:00
|
|
|
return "\n".join([c.get_raw() for c in self.children])
|
2022-11-03 22:01:21 +00:00
|
|
|
|
2021-08-26 22:22:15 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "<List: {}>".format(len(self.children))
|
|
|
|
|
2024-08-18 20:44:00 +00:00
|
|
|
|
2022-09-27 21:55:07 +00:00
|
|
|
class TableNode:
|
|
|
|
def __init__(self):
|
|
|
|
self.children = []
|
|
|
|
|
|
|
|
def append(self, child):
|
|
|
|
self.children.append(child)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Table: {}>".format(len(self.children))
|
|
|
|
|
2024-08-18 20:44:00 +00:00
|
|
|
|
2022-09-27 21:55:07 +00:00
|
|
|
class TableSeparatorRow:
|
|
|
|
def __init__(self, orig=None):
|
|
|
|
self.orig = orig
|
|
|
|
|
2024-08-18 20:44:00 +00:00
|
|
|
|
2022-09-27 21:55:07 +00:00
|
|
|
class TableRow:
|
|
|
|
def __init__(self, cells, orig=None):
|
|
|
|
self.cells = cells
|
|
|
|
self.orig = orig
|
2021-08-26 22:22:15 +00:00
|
|
|
|
2024-08-18 20:44:00 +00:00
|
|
|
|
2021-08-26 22:22:15 +00:00
|
|
|
class Text:
|
|
|
|
def __init__(self, content):
|
|
|
|
self.content = content
|
|
|
|
|
2022-11-03 22:01:21 +00:00
|
|
|
def get_raw(self):
|
2024-08-18 20:44:00 +00:00
|
|
|
return "".join(self.content.get_raw())
|
2022-11-03 22:01:21 +00:00
|
|
|
|
2021-08-26 22:22:15 +00:00
|
|
|
|
|
|
|
class ListItem:
|
2022-05-06 18:18:44 +00:00
|
|
|
def __init__(self, tag, content, orig=None):
|
|
|
|
self.tag = tag
|
2021-08-26 22:22:15 +00:00
|
|
|
self.content = content
|
2022-05-06 18:18:44 +00:00
|
|
|
self.orig = orig
|
2021-08-26 22:22:15 +00:00
|
|
|
|
2022-11-03 22:01:21 +00:00
|
|
|
def get_raw(self):
|
|
|
|
return get_raw_contents(self.orig)
|
|
|
|
|
2021-08-26 22:22:15 +00:00
|
|
|
|
|
|
|
class BlockNode:
|
2022-11-01 18:57:50 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.children = []
|
|
|
|
|
2021-08-26 22:22:15 +00:00
|
|
|
def append(self, child):
|
2022-11-01 18:57:50 +00:00
|
|
|
self.children.append(child)
|
2021-08-26 22:22:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CodeBlock(BlockNode):
|
2022-11-15 20:07:36 +00:00
|
|
|
def __init__(self, header, subtype, arguments):
|
2022-11-01 18:57:50 +00:00
|
|
|
super().__init__()
|
2021-08-26 22:22:15 +00:00
|
|
|
self.header = header
|
2023-10-15 22:21:30 +00:00
|
|
|
self.lines: Optional[List] = None
|
2022-08-28 19:23:44 +00:00
|
|
|
self.subtype = subtype
|
2022-11-15 20:07:36 +00:00
|
|
|
self.arguments = arguments
|
2021-08-26 22:22:15 +00:00
|
|
|
|
2022-05-07 21:33:32 +00:00
|
|
|
def set_lines(self, lines):
|
|
|
|
self.lines = lines
|
2021-08-26 22:22:15 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2023-10-15 22:21:30 +00:00
|
|
|
return "<Code: {}>".format(len(self.lines or []))
|
2022-11-03 22:01:21 +00:00
|
|
|
|
2024-08-18 20:44:00 +00:00
|
|
|
|
|
|
|
DomNode = Union[
|
|
|
|
DrawerNode,
|
|
|
|
PropertyNode,
|
|
|
|
ListGroupNode,
|
|
|
|
TableNode,
|
|
|
|
TableSeparatorRow,
|
|
|
|
TableRow,
|
|
|
|
Text,
|
|
|
|
ListItem,
|
|
|
|
BlockNode,
|
|
|
|
]
|
|
|
|
|
|
|
|
ContainerDomNode = Union[
|
|
|
|
DrawerNode,
|
|
|
|
ListGroupNode,
|
|
|
|
TableNode,
|
|
|
|
BlockNode,
|
|
|
|
]
|
2023-10-15 22:21:30 +00:00
|
|
|
|
2022-11-03 22:01:21 +00:00
|
|
|
from .utils import get_raw_contents
|