MCPcopy
hub / github.com/mitmproxy/mitmproxy / beautify

Function beautify

mitmproxy/contentviews/_view_javascript.py:20–41  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

18
19
20def beautify(data):
21 data = strutils.escape_special_areas(data, SPECIAL_AREAS, DELIMITERS)
22
23 data = re.sub(r"\s*{\s*(?!};)", " {\n", data)
24 data = re.sub(r"\s*;\s*", ";\n", data)
25 data = re.sub(r"(?<!{)\s*}(;)?\s*", r"\n}\1\n", data)
26
27 beautified = io.StringIO()
28 indent_level = 0
29
30 for line in data.splitlines(True):
31 if line.endswith("{\n"):
32 beautified.write(" " * 2 * indent_level + line)
33 indent_level += 1
34 elif line.startswith("}"):
35 indent_level -= 1
36 beautified.write(" " * 2 * indent_level + line)
37 else:
38 beautified.write(" " * 2 * indent_level + line)
39
40 data = strutils.unescape_special_areas(beautified.getvalue())
41 return data
42
43
44class JavaScriptContentview(Contentview):

Callers 2

test_format_xmlFunction · 0.90
prettifyMethod · 0.70

Calls 2

getvalueMethod · 0.80
writeMethod · 0.45

Tested by 1

test_format_xmlFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…