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:
Aldo Cortesi 2011-01-28 12:07:27 +13:00
parent 93ef691bad
commit dfefe3cdda
3 changed files with 16 additions and 7 deletions

View File

@ -244,12 +244,15 @@ 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:
if utils.isBin(conn.content):
self._view_binary(conn, txt)
else:
self._view_normal(conn, txt)
return urwid.ListBox([urwid.Text(txt)])
@ -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

View File

@ -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):

View File

@ -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(),