added maps, maps validation and debug, fetch methods for html and class inserts.
This commit is contained in:
parent
d6ec5d9afa
commit
9ade76e79a
|
|
@ -6,6 +6,7 @@ class BaseContainer:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.content = []
|
self.content = []
|
||||||
self.optionals = []
|
self.optionals = []
|
||||||
|
self.map = {}
|
||||||
|
|
||||||
def add(self, other):
|
def add(self, other):
|
||||||
self.content.append(other)
|
self.content.append(other)
|
||||||
|
|
@ -13,6 +14,21 @@ class BaseContainer:
|
||||||
def class_name(self):
|
def class_name(self):
|
||||||
return self.__class__.__name__
|
return self.__class__.__name__
|
||||||
|
|
||||||
|
def validate(self, other):
|
||||||
|
"""
|
||||||
|
Takes a list as input and checks if every element is in map.
|
||||||
|
:return: Bool
|
||||||
|
"""
|
||||||
|
for o in other:
|
||||||
|
if o not in self.map:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def debug_map(self):
|
||||||
|
print(f'Debug for {self.class_name()} <{id(self)}>')
|
||||||
|
for k, v in self.map.items():
|
||||||
|
print(f'{k} = {v}')
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.content)
|
return len(self.content)
|
||||||
|
|
||||||
|
|
@ -29,6 +45,9 @@ class BaseContainer:
|
||||||
def __getslice__(self, start, end):
|
def __getslice__(self, start, end):
|
||||||
return self.content[start:end]
|
return self.content[start:end]
|
||||||
|
|
||||||
|
def __rshift__(self, other):
|
||||||
|
return self.map[other]()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if len(self) != len(other):
|
if len(self) != len(other):
|
||||||
return False
|
return False
|
||||||
|
|
@ -59,6 +78,35 @@ class BaseContainer:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseContainerWithOptionals(BaseContainer):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.map['html_insert'] = self.fetch_html_insert
|
||||||
|
self.map['class_insert'] = self.fetch_class_insert
|
||||||
|
|
||||||
|
def fetch_html_insert(self):
|
||||||
|
"""
|
||||||
|
Returns a list of all html_inserts, and an empty list if none exist.
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
rlist = []
|
||||||
|
for o in self.optionals:
|
||||||
|
if o.label == 'optional:insert':
|
||||||
|
rlist += [o]
|
||||||
|
return rlist
|
||||||
|
|
||||||
|
def fetch_class_insert(self):
|
||||||
|
"""
|
||||||
|
Returns a list of all class_inserts, and an empty list if none exist.
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
rlist = []
|
||||||
|
for o in self.optionals:
|
||||||
|
if o.label == 'optional:class':
|
||||||
|
rlist += [o]
|
||||||
|
return rlist
|
||||||
|
|
||||||
|
|
||||||
# Define containers all the Enhanced text elements, divs, headers, list and any element that can be a container
|
# Define containers all the Enhanced text elements, divs, headers, list and any element that can be a container
|
||||||
class TextContainer(BaseContainer):
|
class TextContainer(BaseContainer):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue