MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / clip

Method clip

mitmproxy/addons/cut.py:151–176  ·  view source on GitHub ↗

Send cuts to the clipboard. If there are multiple flows or cuts, the format is UTF-8 encoded CSV. If there is exactly one row and one column, the data is written to file as-is, with raw bytes preserved.

(
        self,
        flows: Sequence[flow.Flow],
        cuts: mitmproxy.types.CutSpec,
    )

Source from the content-addressed store, hash-verified

149
150 @command.command("cut.clip")
151 def clip(
152 self,
153 flows: Sequence[flow.Flow],
154 cuts: mitmproxy.types.CutSpec,
155 ) -> None:
156 """
157 Send cuts to the clipboard. If there are multiple flows or cuts, the
158 format is UTF-8 encoded CSV. If there is exactly one row and one
159 column, the data is written to file as-is, with raw bytes preserved.
160 """
161 v: str | bytes
162 fp = io.StringIO(newline="")
163 if len(cuts) == 1 and len(flows) == 1:
164 v = extract_str(cuts[0], flows[0])
165 fp.write(v)
166 logger.log(ALERT, "Clipped single cut.")
167 else:
168 writer = csv.writer(fp)
169 for f in flows:
170 vals = [extract_str(c, f) for c in cuts]
171 writer.writerow(vals)
172 logger.log(ALERT, "Clipped %s cuts as CSV." % len(cuts))
173 try:
174 pyperclip.copy(fp.getvalue())
175 except pyperclip.PyperclipException as e:
176 logger.error(str(e))

Callers

nothing calls this directly

Calls 6

extract_strFunction · 0.85
getvalueMethod · 0.80
writeMethod · 0.45
logMethod · 0.45
copyMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected