From bf1399fa2bc2f34a480a27f2a8ec98f2e479ddc2 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 19 Jan 2014 13:23:38 +1300 Subject: [PATCH] Handle views that don't support search gracefully This includes all key/value formatted views, e.g. the image view. We need to support these ultimately, but no time before the next release. --- libmproxy/console/flowview.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 45d57721b..6c4a2651c 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -3,6 +3,10 @@ import urwid import common, grideditor, contentview from .. import utils, flow, controller + +class SearchError(Exception): pass + + def _mkhelp(): text = [] keys = [ @@ -296,7 +300,10 @@ class FlowView(common.WWrap): # generate the body, highlight the words and get focus headers, msg, body = self.conn_text_raw(text) - body, focus_position = self.search_highlight_text(body, search_string) + try: + body, focus_position = self.search_highlight_text(body, search_string) + except SearchError: + return "Search not supported in this view." if focus_position == None: # no results found. @@ -347,8 +354,10 @@ class FlowView(common.WWrap): if i != start_line: start_index = 0 - text, style = text_object.get_text() - + try: + text, style = text_object.get_text() + except AttributeError: + raise SearchError() find_index = text.find(search_string, start_index) if find_index != -1: before = text[:find_index]