mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 10:16:27 +00:00
Make pretty-printing more robust.
Also, since BeautifulSoup is so damn slow, print a statusbar message saying that we're calculating a pretty version of the response. Maybe I should add hangman or something, becuase on a 200k document this can take ages.
This commit is contained in:
parent
93ef691bad
commit
dfefe3cdda
@ -244,12 +244,15 @@ class ConnectionView(WWrap):
|
|||||||
)
|
)
|
||||||
txt.append("\n\n")
|
txt.append("\n\n")
|
||||||
if conn.content:
|
if conn.content:
|
||||||
if utils.isBin(conn.content):
|
if self.state.viewmode == VIEW_BINARY:
|
||||||
self._view_binary(conn, txt)
|
|
||||||
elif self.state.viewmode == VIEW_BINARY:
|
|
||||||
self._view_binary(conn, txt)
|
self._view_binary(conn, txt)
|
||||||
elif self.state.viewmode == VIEW_PRETTY:
|
elif self.state.viewmode == VIEW_PRETTY:
|
||||||
|
self.master.statusbar.update("Calculating pretty mode...")
|
||||||
self._view_pretty(conn, txt)
|
self._view_pretty(conn, txt)
|
||||||
|
self.master.statusbar.update("")
|
||||||
|
else:
|
||||||
|
if utils.isBin(conn.content):
|
||||||
|
self._view_binary(conn, txt)
|
||||||
else:
|
else:
|
||||||
self._view_normal(conn, txt)
|
self._view_normal(conn, txt)
|
||||||
return urwid.ListBox([urwid.Text(txt)])
|
return urwid.ListBox([urwid.Text(txt)])
|
||||||
@ -528,7 +531,6 @@ class StatusBar(WWrap):
|
|||||||
self.ab = ActionBar()
|
self.ab = ActionBar()
|
||||||
self.ib = urwid.AttrWrap(urwid.Text(""), 'foot')
|
self.ib = urwid.AttrWrap(urwid.Text(""), 'foot')
|
||||||
self.w = urwid.Pile([self.ib, self.ab])
|
self.w = urwid.Pile([self.ib, self.ab])
|
||||||
self.redraw()
|
|
||||||
|
|
||||||
def redraw(self):
|
def redraw(self):
|
||||||
status = urwid.Columns([
|
status = urwid.Columns([
|
||||||
@ -541,6 +543,7 @@ class StatusBar(WWrap):
|
|||||||
align="right"),
|
align="right"),
|
||||||
])
|
])
|
||||||
self.ib.set_w(status)
|
self.ib.set_w(status)
|
||||||
|
self.master.drawscreen()
|
||||||
|
|
||||||
def update(self, text):
|
def update(self, text):
|
||||||
self.text = text
|
self.text = text
|
||||||
|
@ -47,8 +47,9 @@ def prettybody(s):
|
|||||||
Return a list of pretty-printed lines.
|
Return a list of pretty-printed lines.
|
||||||
"""
|
"""
|
||||||
s = BeautifulSoup.BeautifulStoneSoup(s)
|
s = BeautifulSoup.BeautifulStoneSoup(s)
|
||||||
s = s.prettify()
|
s = s.prettify().strip()
|
||||||
return s.split("\n")
|
parts = s.split("\n")
|
||||||
|
return [repr(i)[1:-1] for i in parts]
|
||||||
|
|
||||||
|
|
||||||
def hexdump(s):
|
def hexdump(s):
|
||||||
|
@ -228,6 +228,11 @@ class uprettybody(libpry.AutoTree):
|
|||||||
s = "<html><p></p></html>"
|
s = "<html><p></p></html>"
|
||||||
assert utils.prettybody(s)
|
assert utils.prettybody(s)
|
||||||
|
|
||||||
|
s = "".join([chr(i) for i in range(256)])
|
||||||
|
print utils.prettybody(s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
umake_bogus_cert(),
|
umake_bogus_cert(),
|
||||||
|
Loading…
Reference in New Issue
Block a user