MCPcopy
hub / github.com/mitmproxy/mitmproxy / format_xml

Function format_xml

mitmproxy/contentviews/_view_xml_html.py:209–244  ·  view source on GitHub ↗
(tokens: Iterable[Token])

Source from the content-addressed store, hash-verified

207
208
209def format_xml(tokens: Iterable[Token]) -> str:
210 out = io.StringIO()
211
212 context = ElementStack()
213
214 for prev2, prev1, token, next1, next2 in sliding_window.window(tokens, 2, 2):
215 if isinstance(token, Tag):
216 if token.is_opening:
217 out.write(indent_text(token.data, context.indent))
218
219 if not is_inline(prev2, prev1, token, next1, next2):
220 out.write("\n")
221
222 context.push_tag(token.tag)
223 elif token.is_closing:
224 context.pop_tag(token.tag)
225
226 if is_inline(prev2, prev1, token, next1, next2):
227 out.write(token.data)
228 else:
229 out.write(indent_text(token.data, context.indent))
230 out.write("\n")
231
232 else: # self-closing
233 out.write(indent_text(token.data, context.indent))
234 out.write("\n")
235 elif isinstance(token, Text):
236 if is_inline(prev2, prev1, token, next1, next2):
237 out.write(token.text)
238 else:
239 out.write(indent_text(token.data, context.indent))
240 out.write("\n")
241 else: # pragma: no cover
242 raise RuntimeError()
243
244 return out.getvalue()
245
246
247class XmlHtmlContentview(Contentview):

Callers 1

prettifyMethod · 0.85

Calls 7

push_tagMethod · 0.95
pop_tagMethod · 0.95
ElementStackClass · 0.85
indent_textFunction · 0.85
is_inlineFunction · 0.85
getvalueMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…