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