From 705d04262994c03fc77273b4b4df63bd014145c9 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 25 Jul 2016 19:37:47 -0700 Subject: [PATCH] fix #1432 --- mitmproxy/console/master.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index ad46cbb4a..03ec8b635 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -13,6 +13,7 @@ import tempfile import traceback import weakref +import six import urwid from typing import Optional # noqa @@ -392,8 +393,13 @@ class ConsoleMaster(flow.FlowMaster): def spawn_editor(self, data): text = not isinstance(data, bytes) fd, name = tempfile.mkstemp('', "mproxy", text=text) - os.write(fd, data) - os.close(fd) + if six.PY2: + os.close(fd) + with open(name, "w" if text else "wb") as f: + f.write(data) + else: + with open(fd, "w" if text else "wb") as f: + f.write(data) # if no EDITOR is set, assume 'vi' c = os.environ.get("EDITOR") or "vi" cmd = shlex.split(c)