mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
don't raise when pyperclip doesn't find a clipboard, fix #2816
This commit is contained in:
parent
957a630bb5
commit
7733252627
@ -139,4 +139,7 @@ class Cut:
|
||||
[strutils.always_str(v) or "" for v in vals] # type: ignore
|
||||
)
|
||||
ctx.log.alert("Clipped %s cuts as CSV." % len(cuts))
|
||||
pyperclip.copy(fp.getvalue())
|
||||
try:
|
||||
pyperclip.copy(fp.getvalue())
|
||||
except pyperclip.PyperclipException as e:
|
||||
ctx.log.error(str(e))
|
||||
|
@ -77,4 +77,7 @@ class Export():
|
||||
raise exceptions.CommandError("No such export format: %s" % fmt)
|
||||
func = formats[fmt] # type: typing.Any
|
||||
v = strutils.always_str(func(f))
|
||||
pyperclip.copy(v)
|
||||
try:
|
||||
pyperclip.copy(v)
|
||||
except pyperclip.PyperclipException as e:
|
||||
ctx.log.error(str(e))
|
||||
|
@ -7,6 +7,7 @@ from mitmproxy.test import taddons
|
||||
from mitmproxy.test import tflow
|
||||
from mitmproxy.test import tutils
|
||||
import pytest
|
||||
import pyperclip
|
||||
from unittest import mock
|
||||
|
||||
|
||||
@ -89,6 +90,13 @@ def test_cut_clip():
|
||||
tctx.command(c.clip, "@all", "request.method,request.content")
|
||||
assert pc.called
|
||||
|
||||
with mock.patch('pyperclip.copy') as pc:
|
||||
log_message = "Pyperclip could not find a " \
|
||||
"copy/paste mechanism for your system."
|
||||
pc.side_effect = pyperclip.PyperclipException(log_message)
|
||||
tctx.command(c.clip, "@all", "request.method")
|
||||
assert tctx.master.has_log(log_message, level="error")
|
||||
|
||||
|
||||
def test_cut_save(tmpdir):
|
||||
f = str(tmpdir.join("path"))
|
||||
|
@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import pyperclip
|
||||
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy.addons import export # heh
|
||||
from mitmproxy.test import tflow
|
||||
@ -111,7 +113,7 @@ def test_export_open(exception, log_message, tmpdir):
|
||||
|
||||
def test_clip(tmpdir):
|
||||
e = export.Export()
|
||||
with taddons.context():
|
||||
with taddons.context() as tctx:
|
||||
with pytest.raises(exceptions.CommandError):
|
||||
e.clip("nonexistent", tflow.tflow(resp=True))
|
||||
|
||||
@ -122,3 +124,10 @@ def test_clip(tmpdir):
|
||||
with mock.patch('pyperclip.copy') as pc:
|
||||
e.clip("curl", tflow.tflow(resp=True))
|
||||
assert pc.called
|
||||
|
||||
with mock.patch('pyperclip.copy') as pc:
|
||||
log_message = "Pyperclip could not find a " \
|
||||
"copy/paste mechanism for your system."
|
||||
pc.side_effect = pyperclip.PyperclipException(log_message)
|
||||
e.clip("raw", tflow.tflow(resp=True))
|
||||
assert tctx.master.has_log(log_message, level="error")
|
||||
|
Loading…
Reference in New Issue
Block a user