Merge pull request #1400 from mhils/fix-copy-clipboard

py3: fix copy to clipboard
This commit is contained in:
Maximilian Hils 2016-07-21 20:09:42 -07:00 committed by GitHub
commit 6dcdc89857

View File

@ -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: