diff options
author | Mikhail Borisov <borisov.mikhail@gmail.com> | 2022-02-10 16:45:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:39 +0300 |
commit | a6a92afe03e02795227d2641b49819b687f088f8 (patch) | |
tree | f6984a1d27d5a7ec88a6fdd6e20cd5b7693b6ece /contrib/python/ipython/py2/IPython/lib/clipboard.py | |
parent | c6dc8b8bd530985bc4cce0137e9a5de32f1087cb (diff) | |
download | ydb-a6a92afe03e02795227d2641b49819b687f088f8.tar.gz |
Restoring authorship annotation for Mikhail Borisov <borisov.mikhail@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/ipython/py2/IPython/lib/clipboard.py')
-rw-r--r-- | contrib/python/ipython/py2/IPython/lib/clipboard.py | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/contrib/python/ipython/py2/IPython/lib/clipboard.py b/contrib/python/ipython/py2/IPython/lib/clipboard.py index ac9b685c7d..713313da33 100644 --- a/contrib/python/ipython/py2/IPython/lib/clipboard.py +++ b/contrib/python/ipython/py2/IPython/lib/clipboard.py @@ -1,72 +1,72 @@ -""" Utilities for accessing the platform's clipboard. -""" - -import subprocess - -from IPython.core.error import TryNext -import IPython.utils.py3compat as py3compat - -class ClipboardEmpty(ValueError): - pass - -def win32_clipboard_get(): - """ Get the current clipboard's text on Windows. - - Requires Mark Hammond's pywin32 extensions. - """ - try: - import win32clipboard - except ImportError: - raise TryNext("Getting text from the clipboard requires the pywin32 " - "extensions: http://sourceforge.net/projects/pywin32/") - win32clipboard.OpenClipboard() - try: - text = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT) - except (TypeError, win32clipboard.error): - try: - text = win32clipboard.GetClipboardData(win32clipboard.CF_TEXT) - text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) - except (TypeError, win32clipboard.error): - raise ClipboardEmpty - finally: - win32clipboard.CloseClipboard() - return text - -def osx_clipboard_get(): - """ Get the clipboard's text on OS X. - """ - p = subprocess.Popen(['pbpaste', '-Prefer', 'ascii'], - stdout=subprocess.PIPE) - text, stderr = p.communicate() - # Text comes in with old Mac \r line endings. Change them to \n. - text = text.replace(b'\r', b'\n') - text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) - return text - -def tkinter_clipboard_get(): - """ Get the clipboard's text using Tkinter. - - This is the default on systems that are not Windows or OS X. It may - interfere with other UI toolkits and should be replaced with an - implementation that uses that toolkit. - """ - try: - from tkinter import Tk, TclError # Py 3 - except ImportError: - try: - from Tkinter import Tk, TclError # Py 2 - except ImportError: - raise TryNext("Getting text from the clipboard on this platform " - "requires Tkinter.") - root = Tk() - root.withdraw() - try: - text = root.clipboard_get() - except TclError: - raise ClipboardEmpty - finally: - root.destroy() - text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) - return text - - +""" Utilities for accessing the platform's clipboard. +""" + +import subprocess + +from IPython.core.error import TryNext +import IPython.utils.py3compat as py3compat + +class ClipboardEmpty(ValueError): + pass + +def win32_clipboard_get(): + """ Get the current clipboard's text on Windows. + + Requires Mark Hammond's pywin32 extensions. + """ + try: + import win32clipboard + except ImportError: + raise TryNext("Getting text from the clipboard requires the pywin32 " + "extensions: http://sourceforge.net/projects/pywin32/") + win32clipboard.OpenClipboard() + try: + text = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT) + except (TypeError, win32clipboard.error): + try: + text = win32clipboard.GetClipboardData(win32clipboard.CF_TEXT) + text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) + except (TypeError, win32clipboard.error): + raise ClipboardEmpty + finally: + win32clipboard.CloseClipboard() + return text + +def osx_clipboard_get(): + """ Get the clipboard's text on OS X. + """ + p = subprocess.Popen(['pbpaste', '-Prefer', 'ascii'], + stdout=subprocess.PIPE) + text, stderr = p.communicate() + # Text comes in with old Mac \r line endings. Change them to \n. + text = text.replace(b'\r', b'\n') + text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) + return text + +def tkinter_clipboard_get(): + """ Get the clipboard's text using Tkinter. + + This is the default on systems that are not Windows or OS X. It may + interfere with other UI toolkits and should be replaced with an + implementation that uses that toolkit. + """ + try: + from tkinter import Tk, TclError # Py 3 + except ImportError: + try: + from Tkinter import Tk, TclError # Py 2 + except ImportError: + raise TryNext("Getting text from the clipboard on this platform " + "requires Tkinter.") + root = Tk() + root.withdraw() + try: + text = root.clipboard_get() + except TclError: + raise ClipboardEmpty + finally: + root.destroy() + text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) + return text + + |