mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Merge pull request #1400 from mhils/fix-copy-clipboard
py3: fix copy to clipboard
This commit is contained in:
commit
6dcdc89857
@ -134,7 +134,11 @@ def save_data(path, data):
|
||||
if not path:
|
||||
return
|
||||
try:
|
||||
with open(path, "wb") as f:
|
||||
if isinstance(data, bytes):
|
||||
mode = "wb"
|
||||
else:
|
||||
mode = "w"
|
||||
with open(path, mode) as f:
|
||||
f.write(data)
|
||||
except IOError as v:
|
||||
signals.status_message.send(message=v.strerror)
|
||||
@ -193,10 +197,9 @@ def ask_scope_and_callback(flow, cb, *args):
|
||||
def copy_to_clipboard_or_prompt(data):
|
||||
# pyperclip calls encode('utf-8') on data to be copied without checking.
|
||||
# if data are already encoded that way UnicodeDecodeError is thrown.
|
||||
toclip = ""
|
||||
try:
|
||||
toclip = data.decode('utf-8')
|
||||
except (UnicodeDecodeError):
|
||||
if isinstance(data, bytes):
|
||||
toclip = data.decode("utf8", "replace")
|
||||
else:
|
||||
toclip = data
|
||||
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user