From 08cee23ec10f22da1eb54944c8e01564c16a5c33 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Mon, 10 Jul 2017 21:30:00 -0400 Subject: Attempt at fixing some extraneous output on Linux when using Python3 and xclip --- cmd2.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cmd2.py') diff --git a/cmd2.py b/cmd2.py index 4fee16af..e638d401 100755 --- a/cmd2.py +++ b/cmd2.py @@ -300,7 +300,12 @@ def options(option_list, arg_desc="arg"): # Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux try: - _ = pyperclip.paste() + if six.PY3 and sys.platform.startswith('linux'): + # Avoid extraneous output to stderr from xclip when clipboard is empty at cost of overwriting clipboard contents + pyperclip.copy('') + else: + # Try getting the contents of the clipboard + _ = pyperclip.paste() except pyperclip.exceptions.PyperclipException: can_clip = False else: -- cgit v1.2.1 From 839646c947c2be134dfc054222ec4e1a490b6259 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Mon, 10 Jul 2017 21:45:21 -0400 Subject: Minor attempt at ruggedization of clipboard stuff in some weird cases on Python 2 --- cmd2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cmd2.py') diff --git a/cmd2.py b/cmd2.py index e638d401..e5ee62c0 100755 --- a/cmd2.py +++ b/cmd2.py @@ -319,7 +319,8 @@ def get_paste_buffer(): """ pb_str = pyperclip.paste() - if six.PY2: + # If value returned from the clipboard is unicode and this is Python 2, convert to a "normal" Python 2 string first + if six.PY2 and not isinstance(pb_str, str): import unicodedata pb_str = unicodedata.normalize('NFKD', pb_str).encode('ascii', 'ignore') -- cgit v1.2.1