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,
)
| 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)) |