mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +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,14 +244,17 @@ class ConnectionView(WWrap):
|
||||
)
|
||||
txt.append("\n\n")
|
||||
if conn.content:
|
||||
if utils.isBin(conn.content):
|
||||
self._view_binary(conn, txt)
|
||||
elif self.state.viewmode == VIEW_BINARY:
|
||||
if self.state.viewmode == VIEW_BINARY:
|
||||
self._view_binary(conn, txt)
|
||||
elif self.state.viewmode == VIEW_PRETTY:
|
||||
self.master.statusbar.update("Calculating pretty mode...")
|
||||
self._view_pretty(conn, txt)
|
||||
self.master.statusbar.update("")
|
||||
else:
|
||||
self._view_normal(conn, txt)
|
||||
if utils.isBin(conn.content):
|
||||
self._view_binary(conn, txt)
|
||||
else:
|
||||
self._view_normal(conn, txt)
|
||||
return urwid.ListBox([urwid.Text(txt)])
|
||||
|
||||
def view_request(self):
|
||||
@ -528,7 +531,6 @@ class StatusBar(WWrap):
|
||||
self.ab = ActionBar()
|
||||
self.ib = urwid.AttrWrap(urwid.Text(""), 'foot')
|
||||
self.w = urwid.Pile([self.ib, self.ab])
|
||||
self.redraw()
|
||||
|
||||
def redraw(self):
|
||||
status = urwid.Columns([
|
||||
@ -541,6 +543,7 @@ class StatusBar(WWrap):
|
||||
align="right"),
|
||||
])
|
||||
self.ib.set_w(status)
|
||||
self.master.drawscreen()
|
||||
|
||||
def update(self, text):
|
||||
self.text = text
|
||||
|
@ -47,8 +47,9 @@ def prettybody(s):
|
||||
Return a list of pretty-printed lines.
|
||||
"""
|
||||
s = BeautifulSoup.BeautifulStoneSoup(s)
|
||||
s = s.prettify()
|
||||
return s.split("\n")
|
||||
s = s.prettify().strip()
|
||||
parts = s.split("\n")
|
||||
return [repr(i)[1:-1] for i in parts]
|
||||
|
||||
|
||||
def hexdump(s):
|
||||
|
@ -228,6 +228,11 @@ class uprettybody(libpry.AutoTree):
|
||||
s = "<html><p></p></html>"
|
||||
assert utils.prettybody(s)
|
||||
|
||||
s = "".join([chr(i) for i in range(256)])
|
||||
print utils.prettybody(s)
|
||||
|
||||
|
||||
|
||||
|
||||
tests = [
|
||||
umake_bogus_cert(),
|
||||
|
Loading…
Reference in New Issue
Block a user