@@ -60,10 +60,32 @@ def __len__(self) -> int:
6060 return len (self ._raw )
6161
6262 def __str__ (self ) -> str :
63- return str ( self . _raw )
63+ from . _display import _Indentation
6464
65- def __repr__ (self ) -> str :
66- return repr (self ._raw )
65+ res = ""
66+
67+ indent = _Indentation (True )
68+
69+ for edge in self .root ().traverse ():
70+ if edge .closed :
71+ if edge .node .has_children :
72+ indent .deindent ()
73+
74+ continue
75+
76+ if edge .node .has_children :
77+ indent .indent (edge .node .next_sibling is not None )
78+ res += str (indent ) + str (edge .node ) + "\n "
79+
80+ else :
81+ indent .indent (edge .node .next_sibling is not None )
82+ res += str (indent ) + str (edge .node ) + "\n "
83+ indent .deindent ()
84+
85+ return res [:- 1 ] # remove the last '\n'
86+
87+ def __repr__ (self ):
88+ return f"TreeDom(len={ len (self )} , namespaces={ self .namespaces ()} )"
6789
6890
6991class _ConfigNode :
@@ -550,10 +572,11 @@ def __gt__(self, value): # pragma: no cover
550572
551573class AttrsList :
552574 """
553- This type is only designed for communicating with element attributes.
554-
575+ This type is only designed for communicating with element attributes.
576+
555577 Really it's a list, but has a behaviour between dictionary and list to provide you easy-to-use management.
556578 """
579+
557580 __slots__ = ("__raw" ,)
558581
559582 def __init__ (self , attrs : _rustlib .AttrsList ):
@@ -729,14 +752,10 @@ def __setitem__(
729752 self .__raw .update_item (index , val [0 ], val [1 ])
730753
731754 @typing .overload
732- def __getitem__ (
733- self , index : typing .Union [str , _rustlib .QualName ]
734- ) -> str : ...
755+ def __getitem__ (self , index : typing .Union [str , _rustlib .QualName ]) -> str : ...
735756
736757 @typing .overload
737- def __getitem__ (
738- self , index : int
739- ) -> typing .Tuple [_rustlib .QualName , str ]: ...
758+ def __getitem__ (self , index : int ) -> typing .Tuple [_rustlib .QualName , str ]: ...
740759
741760 def __getitem__ (self , index ):
742761 if not isinstance (index , int ):
@@ -889,6 +908,7 @@ class ProcessingInstruction(BaseNode):
889908 a Node which embeds an instruction targeting a specific application but that can
890909 be ignored by any other applications which don't recognize the instruction.
891910 """
911+
892912 _CONFIG = _ConfigNode (_rustlib .ProcessingInstruction , (Ordering .APPEND , Ordering .PREPEND ))
893913
894914 @property
0 commit comments