lane lines fixes started
This commit is contained in:
parent
986e5e180e
commit
557fd6e697
24
proxy.py
24
proxy.py
@ -1,6 +1,6 @@
|
|||||||
from typing import List, Protocol, Tuple, Union
|
from typing import List, Protocol, Tuple, Union
|
||||||
|
|
||||||
def MakeAttrs(css:str|Tuple[str, ...]|None, id:str|None, attributes: dict[str, str | None] = {}) -> str:
|
def MakeAttrs(css:str|Tuple[str, ...]|None, id:str|None, attributes: dict[str, str | None]) -> str:
|
||||||
if css:
|
if css:
|
||||||
attributes['class'] = " ".join(css) if isinstance(css, (list, tuple)) else css
|
attributes['class'] = " ".join(css) if isinstance(css, (list, tuple)) else css
|
||||||
if id:
|
if id:
|
||||||
@ -17,8 +17,9 @@ class ComplexProxyLeaf(dict):
|
|||||||
def __init__(self, name:str):
|
def __init__(self, name:str):
|
||||||
self.name = name
|
self.name = name
|
||||||
def __call__(self, css:str|None = None, id:str|None = None):
|
def __call__(self, css:str|None = None, id:str|None = None):
|
||||||
self.attrs = MakeAttrs(css, id)
|
clone = ComplexProxyLeaf(self.name)
|
||||||
return self
|
clone.attrs = MakeAttrs(css, id, {})
|
||||||
|
return clone
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f'<{self.name} {self.attrs}/>'
|
return f'<{self.name} {self.attrs}/>'
|
||||||
|
|
||||||
@ -28,29 +29,38 @@ class ComplexProxyBranch(ComplexProxyLeaf):
|
|||||||
def __init__(self, name:str):
|
def __init__(self, name:str):
|
||||||
self.name = name
|
self.name = name
|
||||||
def __call__(self, css:str|None = None, id:str|None = None):
|
def __call__(self, css:str|None = None, id:str|None = None):
|
||||||
self.attrs = MakeAttrs(css, id)
|
clone = ComplexProxyBranch(self.name)
|
||||||
return self
|
clone.attrs = MakeAttrs(css, id, {})
|
||||||
|
return clone
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f'<{self.name} {self.attrs}></{self.name}>'
|
print("dump", self.attrs)
|
||||||
|
copy = self.attrs
|
||||||
|
self.attrs = ""
|
||||||
|
return f'<{self.name} {copy}></{self.name}>'
|
||||||
def __getitem__(self, key:Union[str, 'ComplexProxyBranch', ComplexProxyLeaf, Tuple[Union[str, 'ComplexProxyBranch', ComplexProxyLeaf], ...]]) -> str:
|
def __getitem__(self, key:Union[str, 'ComplexProxyBranch', ComplexProxyLeaf, Tuple[Union[str, 'ComplexProxyBranch', ComplexProxyLeaf], ...]]) -> str:
|
||||||
if isinstance(key, tuple):
|
if isinstance(key, tuple):
|
||||||
children = "".join(str(k) for k in key)
|
children = "".join(str(k) for k in key)
|
||||||
else:
|
else:
|
||||||
children = key
|
children = key
|
||||||
|
print("child", self.attrs)
|
||||||
return f'<{self.name} {self.attrs}>{children}</{self.name}>'
|
return f'<{self.name} {self.attrs}>{children}</{self.name}>'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IMG = ComplexProxyLeaf("img")
|
IMG = ComplexProxyLeaf("img")
|
||||||
BR = ComplexProxyLeaf("br")
|
BR = ComplexProxyLeaf("br")
|
||||||
A = ComplexProxyBranch("a")
|
A = ComplexProxyBranch("a")
|
||||||
|
|
||||||
print(
|
print(
|
||||||
A
|
A
|
||||||
[
|
[
|
||||||
"click here",
|
"click here",
|
||||||
BR,
|
BR,
|
||||||
|
A(css="test"),
|
||||||
A(css="www.site.com")
|
A(css="www.site.com")
|
||||||
[
|
[
|
||||||
IMG(id="image.png")
|
IMG(id="image.png")
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user