aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2012-12-22 18:26:15 -0600
committerBryan Bishop <kanzure@gmail.com>2012-12-22 18:26:15 -0600
commit4d250095cba36b32ce3e5083d453525209eeee06 (patch)
treefe0fe6dffb5d56a9407d98bc375c663a0817b784 /libmproxy/console
parent0451eb193ef0abaf875bfd8ad2a1ac4bd68c3efe (diff)
downloadmitmproxy-4d250095cba36b32ce3e5083d453525209eeee06.tar.gz
mitmproxy-4d250095cba36b32ce3e5083d453525209eeee06.tar.bz2
mitmproxy-4d250095cba36b32ce3e5083d453525209eeee06.zip
fix external viewer using shlex
This makes spawn_external_viewer not crash when $EDITOR or $PAGER have spaces or multiple arguments. In addition, spawn_external_viewer now chmods the file to read-only to remind users who use only an $EDITOR that this function does not read the file when the user returns. Also, some of the redundant exception case handling for editing has been consolidated. fixes #79
Diffstat (limited to 'libmproxy/console')
-rw-r--r--libmproxy/console/__init__.py26
-rw-r--r--libmproxy/console/flowview.py2
2 files changed, 18 insertions, 10 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py
index 544fbd6e..26f955d0 100644
--- a/libmproxy/console/__init__.py
+++ b/libmproxy/console/__init__.py
@@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import mailcap, mimetypes, tempfile, os, subprocess, glob, time, shlex
+import mailcap, mimetypes, tempfile, os, subprocess, glob, time, shlex, stat
import os.path, sys, weakref
import urwid
from .. import controller, utils, flow
@@ -504,7 +504,7 @@ class ConsoleMaster(flow.FlowMaster):
os.write(fd, data)
os.close(fd)
c = os.environ.get("EDITOR")
- #If no EDITOR is set, assume 'vi'
+ # if no EDITOR is set, assume 'vi'
if not c:
c = "vi"
cmd = shlex.split(c)
@@ -513,12 +513,10 @@ class ConsoleMaster(flow.FlowMaster):
try:
subprocess.call(cmd)
except:
- self.statusbar.message("Can't start editor: %s" % c)
- self.ui.start()
- os.unlink(name)
- return data
+ self.statusbar.message("Can't start editor: %s" % " ".join(c))
+ else:
+ data = open(name).read()
self.ui.start()
- data = open(name).read()
os.unlink(name)
return data
@@ -531,6 +529,9 @@ class ConsoleMaster(flow.FlowMaster):
os.write(fd, data)
os.close(fd)
+ # read-only to remind the user that this is a view function
+ os.chmod(name, stat.S_IREAD)
+
cmd = None
shell = False
@@ -540,10 +541,17 @@ class ConsoleMaster(flow.FlowMaster):
if cmd:
shell = True
if not cmd:
+ # hm which one should get priority?
c = os.environ.get("PAGER") or os.environ.get("EDITOR")
- cmd = [c, name]
+ if not c:
+ c = "less"
+ cmd = shlex.split(c)
+ cmd.append(name)
self.ui.stop()
- subprocess.call(cmd, shell=shell)
+ try:
+ subprocess.call(cmd, shell=shell)
+ except:
+ self.statusbar.message("Can't start external viewer: %s" % " ".join(c))
self.ui.start()
os.unlink(name)
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index 3473c474..4215f170 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -343,7 +343,7 @@ class FlowView(common.WWrap):
self.flow.backup()
if part == "r":
c = self.master.spawn_editor(conn.content or "")
- conn.content = c.rstrip("\n")
+ conn.content = c.rstrip("\n") # what?
elif part == "f":
if not conn.get_form_urlencoded() and conn.content:
self.master.prompt_onekey(