MCPcopy
hub / github.com/mitmproxy/mitmproxy / spawn_editor

Method spawn_editor

mitmproxy/tools/console/master.py:134–155  ·  view source on GitHub ↗
(self, data: T)

Source from the content-addressed store, hash-verified

132 return self.get_editor()
133
134 def spawn_editor(self, data: T) -> T:
135 text = isinstance(data, str)
136 fd, name = tempfile.mkstemp("", "mitmproxy", text=text)
137 with_hexeditor = isinstance(data, bytes) and strutils.is_mostly_bin(data)
138 with open(fd, "w" if text else "wb") as f:
139 f.write(data)
140 if with_hexeditor:
141 c = self.get_hex_editor()
142 else:
143 c = self.get_editor()
144 cmd = shlex.split(c)
145 cmd.append(name)
146 with self.uistopped():
147 try:
148 subprocess.call(cmd)
149 except Exception:
150 signals.status_message.send(message="Can't start editor: %s" % c)
151 else:
152 with open(name, "r" if text else "rb") as f:
153 data = f.read()
154 os.unlink(name)
155 return data
156
157 def spawn_external_viewer(self, data, contenttype):
158 if contenttype:

Callers 3

test_spawn_editorFunction · 0.80
edit_focusMethod · 0.80
cmd_spawn_editorMethod · 0.80

Calls 9

get_hex_editorMethod · 0.95
get_editorMethod · 0.95
uistoppedMethod · 0.95
writeMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
callMethod · 0.45
sendMethod · 0.45
readMethod · 0.45

Tested by 1

test_spawn_editorFunction · 0.64