MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / ElementStack

Class ElementStack

mitmproxy/contentviews/_view_xml_html.py:179–206  ·  view source on GitHub ↗

Keep track of how deeply nested our document is.

Source from the content-addressed store, hash-verified

177
178
179class ElementStack:
180 """
181 Keep track of how deeply nested our document is.
182 """
183
184 def __init__(self):
185 self.open_tags = []
186 self.indent = ""
187
188 def push_tag(self, tag: str):
189 if len(self.open_tags) > 16:
190 return
191 self.open_tags.append(tag)
192 if tag not in NO_INDENT_TAGS:
193 self.indent += " " * INDENT
194
195 def pop_tag(self, tag: str):
196 if tag in self.open_tags:
197 remove_indent = 0
198 while True:
199 t = self.open_tags.pop()
200 if t not in NO_INDENT_TAGS:
201 remove_indent += INDENT
202 if t == tag:
203 break
204 self.indent = self.indent[:-remove_indent]
205 else:
206 pass # this closing tag has no start tag. let's keep indentation as-is.
207
208
209def format_xml(tokens: Iterable[Token]) -> str:

Callers 1

format_xmlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…