diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-08-25 13:23:46 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-08-25 13:25:59 +1200 |
commit | 87463049f117931994e9a3d99f62aff2be79e7e2 (patch) | |
tree | cbd2cc4974c5afb8b52e0cea4cad564d7a5a25bf /libmproxy/console/grideditor.py | |
parent | 514e19b17215ae6d5a785cfd22370eea5a132c38 (diff) | |
download | mitmproxy-87463049f117931994e9a3d99f62aff2be79e7e2.tar.gz mitmproxy-87463049f117931994e9a3d99f62aff2be79e7e2.tar.bz2 mitmproxy-87463049f117931994e9a3d99f62aff2be79e7e2.zip |
Add a "R" shortcut to GridEditor, letting the user read unescaped data from file.
Diffstat (limited to 'libmproxy/console/grideditor.py')
-rw-r--r-- | libmproxy/console/grideditor.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py index d1df2f2e..34c089b2 100644 --- a/libmproxy/console/grideditor.py +++ b/libmproxy/console/grideditor.py @@ -28,6 +28,7 @@ def _mkhelp(): ("e", "spawn external editor on current field"), ("q", "return to flow view"), ("r", "read value from file"), + ("R", "read unescaped value from file"), ("esc", "return to flow view/exit field edit mode"), ("tab", "next field"), ("enter", "edit field"), @@ -142,14 +143,15 @@ class GridWalker(urwid.ListWalker): if self.lst: return self.lst[self.focus][0][self.focus_col] - def set_current_value(self, val): - try: - val = val.decode("string-escape") - except ValueError: - self.editor.master.statusbar.message("Invalid Python-style string encoding.", 1000) - return - errors = self.lst[self.focus][1] + def set_current_value(self, val, unescaped): + if not unescaped: + try: + val = val.decode("string-escape") + except ValueError: + self.editor.master.statusbar.message("Invalid Python-style string encoding.", 1000) + return + errors = self.lst[self.focus][1] emsg = self.editor.is_error(self.focus_col, val) if emsg: self.editor.master.statusbar.message(emsg, 1000) @@ -186,7 +188,7 @@ class GridWalker(urwid.ListWalker): def stop_edit(self): if self.editing: self.editor.master.statusbar.update(footer) - self.set_current_value(self.editing.get_edit_value()) + self.set_current_value(self.editing.get_edit_value(), False) self.editing = False self._modified() @@ -301,10 +303,10 @@ class GridEditor(common.WWrap): except ValueError: return None - def read_file(self, p): + def read_file(self, p, unescaped=False): p = os.path.expanduser(p) d = file(p, "r").read() - self.walker.set_current_value(d) + self.walker.set_current_value(d, unescaped) self.walker._modified() def keypress(self, size, key): @@ -342,12 +344,14 @@ class GridEditor(common.WWrap): self.walker.delete_focus() elif key == "r": self.master.path_prompt("Read file: ", "", self.read_file) + elif key == "R": + self.master.path_prompt("Read unescaped file: ", "", self.read_file, True) elif key == "e": o = self.walker.get_current_value() if o is not None: n = self.master.spawn_editor(o.encode("string-escape")) n = utils.clean_hanging_newline(n) - self.walker.set_current_value(n) + self.walker.set_current_value(n, False) self.walker._modified() elif key in ["enter"]: self.walker.start_edit() |