aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-03-13 23:03:46 +1100
committerAldo Cortesi <aldo@nullcube.com>2015-03-13 23:04:07 +1100
commit60dce08d546aef3698509bdb2572e9868902e016 (patch)
tree38f93dd04ba607b915dd9ebf6d60b27815c63b49
parent87a3c710415878968f2333e1d7bc4adeccc3a9cb (diff)
downloadmitmproxy-60dce08d546aef3698509bdb2572e9868902e016.tar.gz
mitmproxy-60dce08d546aef3698509bdb2572e9868902e016.tar.bz2
mitmproxy-60dce08d546aef3698509bdb2572e9868902e016.zip
Remove compatibility shim used to interop with older versions of Urwid
-rw-r--r--libmproxy/console/__init__.py16
-rw-r--r--libmproxy/console/common.py22
-rw-r--r--libmproxy/console/flowlist.py4
-rw-r--r--libmproxy/console/flowview.py18
-rw-r--r--libmproxy/console/grideditor.py32
5 files changed, 35 insertions, 57 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py
index 26c05aaf..627c6d18 100644
--- a/libmproxy/console/__init__.py
+++ b/libmproxy/console/__init__.py
@@ -85,7 +85,7 @@ class PathEdit(urwid.Edit, _PathCompleter):
return urwid.Edit.keypress(self, size, key)
-class ActionBar(common.WWrap):
+class ActionBar(urwid.WidgetWrap):
def __init__(self):
self.message("")
@@ -94,7 +94,7 @@ class ActionBar(common.WWrap):
def path_prompt(self, prompt, text):
self.expire = None
- self.w = PathEdit(prompt, text)
+ self._w = PathEdit(prompt, text)
def prompt(self, prompt, text = ""):
self.expire = None
@@ -103,19 +103,19 @@ class ActionBar(common.WWrap):
# We can remove it once veryone is beyond 1.0.1
if isinstance(prompt, basestring):
prompt = unicode(prompt)
- self.w = urwid.Edit(prompt, text or "")
+ self._w = urwid.Edit(prompt, text or "")
def message(self, message, expire=None):
self.expire = expire
- self.w = urwid.Text(message)
+ self._w = urwid.Text(message)
-class StatusBar(common.WWrap):
+class StatusBar(urwid.WidgetWrap):
def __init__(self, master, helptext):
self.master, self.helptext = master, helptext
self.ab = ActionBar()
- self.ib = common.WWrap(urwid.Text(""))
- self.w = urwid.Pile([self.ib, self.ab])
+ self.ib = urwid.WidgetWrap(urwid.Text(""))
+ self._w = urwid.Pile([self.ib, self.ab])
def get_status(self):
r = []
@@ -237,7 +237,7 @@ class StatusBar(common.WWrap):
align="right"
),
]), "heading")
- self.ib.set_w(status)
+ self.ib._w = status
def update(self, text):
self.helptext = text
diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py
index c0da9bb3..6c0f481b 100644
--- a/libmproxy/console/common.py
+++ b/libmproxy/console/common.py
@@ -364,25 +364,3 @@ def format_flow(f, focus, extended=False, hostheader=False, padding=2):
return flowcache.format_flow(
tuple(sorted(d.items())), focus, extended, padding
)
-
-
-def int_version(v):
- SIG = 3
- v = urwid.__version__.split("-")[0].split(".")
- x = 0
- for i in range(min(SIG, len(v))):
- x += int(v[i]) * 10**(SIG-i)
- return x
-
-
-# We have to do this to be portable over 0.9.8 and 0.9.9 If compatibility
-# becomes a pain to maintain, we'll just mandate 0.9.9 or newer.
-class WWrap(urwid.WidgetWrap):
- if int_version(urwid.__version__) >= 990:
- def set_w(self, x):
- self._w = x
-
- def get_w(self):
- return self._w
-
- w = property(get_w, set_w)
diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py
index 145331b2..8a2d2b91 100644
--- a/libmproxy/console/flowlist.py
+++ b/libmproxy/console/flowlist.py
@@ -92,12 +92,12 @@ class BodyPile(urwid.Pile):
return self.focus_item.keypress(tsize, key)
-class ConnectionItem(common.WWrap):
+class ConnectionItem(urwid.WidgetWrap):
def __init__(self, master, state, flow, focus):
self.master, self.state, self.flow = master, state, flow
self.f = focus
w = self.get_text()
- common.WWrap.__init__(self, w)
+ urwid.WidgetWrap.__init__(self, w)
def get_text(self):
return common.format_flow(
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index 5c91512c..89e75aad 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -19,7 +19,7 @@ def _mkhelp():
("D", "duplicate flow"),
("e", "edit request/response"),
("f", "load full body data"),
- ("g", "copy response(content/headers) to clipboard"),
+ ("g", "copy response(content/headers) to clipboard"),
("m", "change body display mode for this entity"),
(None,
common.highlight_key("automatic", "a") +
@@ -84,14 +84,14 @@ footer = [
]
-class FlowViewHeader(common.WWrap):
+class FlowViewHeader(urwid.WidgetWrap):
def __init__(self, master, f):
self.master, self.flow = master, f
- self.w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
+ self._w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
def refresh_flow(self, f):
if f == self.flow:
- self.w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
+ self._w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
class CallbackCache:
@@ -106,7 +106,7 @@ class CallbackCache:
cache = CallbackCache()
-class FlowView(common.WWrap):
+class FlowView(urwid.WidgetWrap):
REQ = 0
RESP = 1
@@ -331,7 +331,7 @@ class FlowView(common.WWrap):
merged = self.conn_text_merge(headers, msg, body)
list_box = urwid.ListBox(merged)
list_box.set_focus(focus_position + 2)
- self.w = self.wrap_body(const, list_box)
+ self._w = self.wrap_body(const, list_box)
self.master.statusbar.redraw()
self.last_displayed_body = list_box
@@ -455,7 +455,7 @@ class FlowView(common.WWrap):
def view_request(self):
self.state.view_flow_mode = common.VIEW_FLOW_REQUEST
body = self.conn_text(self.flow.request)
- self.w = self.wrap_body(common.VIEW_FLOW_REQUEST, body)
+ self._w = self.wrap_body(common.VIEW_FLOW_REQUEST, body)
self.master.statusbar.redraw()
def view_response(self):
@@ -475,7 +475,7 @@ class FlowView(common.WWrap):
)
]
)
- self.w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
+ self._w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
self.master.statusbar.redraw()
def refresh_flow(self, c=None):
@@ -656,7 +656,7 @@ class FlowView(common.WWrap):
self.view_request()
elif key in ("up", "down", "page up", "page down"):
# Why doesn't this just work??
- self.w.keypress(size, key)
+ self._w.keypress(size, key)
elif key == "a":
self.flow.accept_intercept(self.master)
self.master.view_flow(self.flow)
diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py
index 438d0ad7..37bc5ae4 100644
--- a/libmproxy/console/grideditor.py
+++ b/libmproxy/console/grideditor.py
@@ -15,7 +15,7 @@ footer_editing = [
]
-class SText(common.WWrap):
+class SText(urwid.WidgetWrap):
def __init__(self, txt, focused, error):
txt = txt.encode("string-escape")
w = urwid.Text(txt, wrap="any")
@@ -26,10 +26,10 @@ class SText(common.WWrap):
w = urwid.AttrWrap(w, "focusfield")
elif error:
w = urwid.AttrWrap(w, "field_error")
- common.WWrap.__init__(self, w)
+ urwid.WidgetWrap.__init__(self, w)
def get_text(self):
- return self.w.get_text()[0]
+ return self._w.get_text()[0]
def keypress(self, size, key):
return key
@@ -38,21 +38,21 @@ class SText(common.WWrap):
return True
-class SEdit(common.WWrap):
+class SEdit(urwid.WidgetWrap):
def __init__(self, txt):
txt = txt.encode("string-escape")
w = urwid.Edit(edit_text=txt, wrap="any", multiline=True)
w = urwid.AttrWrap(w, "editfield")
- common.WWrap.__init__(self, w)
+ urwid.WidgetWrap.__init__(self, w)
def get_text(self):
- return self.w.get_text()[0]
+ return self._w.get_text()[0]
def selectable(self):
return True
-class GridRow(common.WWrap):
+class GridRow(urwid.WidgetWrap):
def __init__(self, focused, editing, editor, values):
self.focused, self.editing, self.editor = focused, editing, editor
@@ -76,14 +76,14 @@ class GridRow(common.WWrap):
)
if focused is not None:
w.set_focus_column(focused)
- common.WWrap.__init__(self, w)
+ urwid.WidgetWrap.__init__(self, w)
def get_edit_value(self):
return self.editing.get_text()
def keypress(self, s, k):
if self.editing:
- w = self.w.column_widths(s)[self.focused]
+ w = self._w.column_widths(s)[self.focused]
k = self.editing.keypress((w,), k)
return k
@@ -213,7 +213,7 @@ class GridListBox(urwid.ListBox):
FIRST_WIDTH_MAX = 40
FIRST_WIDTH_MIN = 20
-class GridEditor(common.WWrap):
+class GridEditor(urwid.WidgetWrap):
title = None
columns = None
headings = None
@@ -248,7 +248,7 @@ class GridEditor(common.WWrap):
self.walker = GridWalker(self.value, self)
self.lb = GridListBox(self.walker)
- self.w = urwid.Frame(
+ self._w = urwid.Frame(
self.lb,
header = urwid.Pile([title, h])
)
@@ -257,9 +257,9 @@ class GridEditor(common.WWrap):
def show_empty_msg(self):
if self.walker.lst:
- self.w.set_footer(None)
+ self._w.set_footer(None)
else:
- self.w.set_footer(
+ self._w.set_footer(
urwid.Text(
[
("highlight", "No values. Press "),
@@ -297,7 +297,7 @@ class GridEditor(common.WWrap):
if self.walker.focus == pf and self.walker.focus_col != pfc:
self.walker.start_edit()
else:
- self.w.keypress(size, key)
+ self._w.keypress(size, key)
return None
key = common.shortcuts(key)
@@ -336,7 +336,7 @@ class GridEditor(common.WWrap):
elif key in ["enter"]:
self.walker.start_edit()
elif not self.handle_key(key):
- return self.w.keypress(size, key)
+ return self._w.keypress(size, key)
def is_error(self, col, val):
"""
@@ -507,4 +507,4 @@ class HostPatternEditor(GridEditor):
try:
re.compile(val, re.IGNORECASE)
except re.error as e:
- return "Invalid regex: %s" % str(e) \ No newline at end of file
+ return "Invalid regex: %s" % str(e)