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,14 +244,17 @@ 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: 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)]) return urwid.ListBox([urwid.Text(txt)])
def view_request(self): def view_request(self):
@ -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

View File

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

View File

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