From 17b34de28d374e7c2b189d796475668779f2ce3a Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Fri, 5 Jun 2015 15:19:57 -0300 Subject: [PATCH 1/2] fix #607 decode data before sending it to pyperclip --- libmproxy/console/common.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 57d4c994d..2395a67df 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -284,8 +284,15 @@ def copy_flow(part, scope, flow, master, state): signals.status_message.send(message="No contents to copy.") return + # this is because pyperclip does an encode('utf-8') without checking if data is already encoded or not + toclip = "" try: - pyperclip.copy(data) + toclip = data.decode('utf-8') + except (UnicodeDecodeError): + toclip = data + + try: + pyperclip.copy(toclip) except (RuntimeError, UnicodeDecodeError, AttributeError): def save(k): if k == "y": From 1befa9477c0494fe4400dc62ee0c0907c32d46bd Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Fri, 5 Jun 2015 15:33:36 -0300 Subject: [PATCH 2/2] fix #607 fix message --- libmproxy/console/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 2395a67df..e5bebf7f2 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -284,7 +284,8 @@ def copy_flow(part, scope, flow, master, state): signals.status_message.send(message="No contents to copy.") return - # this is because pyperclip does an encode('utf-8') without checking if data is already encoded or not + # 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')