diff options
author | Ivan Blinkov <ivan@blinkov.ru> | 2022-02-10 16:47:11 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:11 +0300 |
commit | 5b283123c882433dafbaf6b338adeea16c1a0ea0 (patch) | |
tree | 339adc63bce23800021202ae4a8328a843dc447a /contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard | |
parent | 1aeb9a455974457866f78722ad98114bafc84e8a (diff) | |
download | ydb-5b283123c882433dafbaf6b338adeea16c1a0ea0.tar.gz |
Restoring authorship annotation for Ivan Blinkov <ivan@blinkov.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard')
4 files changed, 121 insertions, 121 deletions
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/__init__.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/__init__.py index 5c9cc8df31..56202ddd3b 100644 --- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/__init__.py +++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/__init__.py @@ -1,8 +1,8 @@ -from .base import Clipboard, ClipboardData -from .in_memory import InMemoryClipboard - - -# We are not importing `PyperclipClipboard` here, because it would require the -# `pyperclip` module to be present. - -#from .pyperclip import PyperclipClipboard +from .base import Clipboard, ClipboardData +from .in_memory import InMemoryClipboard + + +# We are not importing `PyperclipClipboard` here, because it would require the +# `pyperclip` module to be present. + +#from .pyperclip import PyperclipClipboard diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/base.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/base.py index 71be6148eb..803c0b0e7d 100644 --- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/base.py +++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/base.py @@ -1,62 +1,62 @@ -""" -Clipboard for command line interface. -""" -from __future__ import unicode_literals -from abc import ABCMeta, abstractmethod -from six import with_metaclass -import six - -from prompt_toolkit.selection import SelectionType - -__all__ = ( - 'Clipboard', - 'ClipboardData', -) - - -class ClipboardData(object): - """ - Text on the clipboard. - - :param text: string - :param type: :class:`~prompt_toolkit.selection.SelectionType` - """ - def __init__(self, text='', type=SelectionType.CHARACTERS): - assert isinstance(text, six.string_types) - assert type in (SelectionType.CHARACTERS, SelectionType.LINES, SelectionType.BLOCK) - - self.text = text - self.type = type - - -class Clipboard(with_metaclass(ABCMeta, object)): - """ - Abstract baseclass for clipboards. - (An implementation can be in memory, it can share the X11 or Windows - keyboard, or can be persistent.) - """ - @abstractmethod - def set_data(self, data): - """ - Set data to the clipboard. - - :param data: :class:`~.ClipboardData` instance. - """ - - def set_text(self, text): # Not abstract. - """ - Shortcut for setting plain text on clipboard. - """ - assert isinstance(text, six.string_types) - self.set_data(ClipboardData(text)) - +""" +Clipboard for command line interface. +""" +from __future__ import unicode_literals +from abc import ABCMeta, abstractmethod +from six import with_metaclass +import six + +from prompt_toolkit.selection import SelectionType + +__all__ = ( + 'Clipboard', + 'ClipboardData', +) + + +class ClipboardData(object): + """ + Text on the clipboard. + + :param text: string + :param type: :class:`~prompt_toolkit.selection.SelectionType` + """ + def __init__(self, text='', type=SelectionType.CHARACTERS): + assert isinstance(text, six.string_types) + assert type in (SelectionType.CHARACTERS, SelectionType.LINES, SelectionType.BLOCK) + + self.text = text + self.type = type + + +class Clipboard(with_metaclass(ABCMeta, object)): + """ + Abstract baseclass for clipboards. + (An implementation can be in memory, it can share the X11 or Windows + keyboard, or can be persistent.) + """ + @abstractmethod + def set_data(self, data): + """ + Set data to the clipboard. + + :param data: :class:`~.ClipboardData` instance. + """ + + def set_text(self, text): # Not abstract. + """ + Shortcut for setting plain text on clipboard. + """ + assert isinstance(text, six.string_types) + self.set_data(ClipboardData(text)) + def rotate(self): """ For Emacs mode, rotate the kill ring. """ - @abstractmethod - def get_data(self): - """ - Return clipboard data. - """ + @abstractmethod + def get_data(self): + """ + Return clipboard data. + """ diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/in_memory.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/in_memory.py index a8591b91f9..081666ab80 100644 --- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/in_memory.py +++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/in_memory.py @@ -1,36 +1,36 @@ -from .base import Clipboard, ClipboardData - +from .base import Clipboard, ClipboardData + from collections import deque -__all__ = ( - 'InMemoryClipboard', -) - - -class InMemoryClipboard(Clipboard): - """ - Default clipboard implementation. - Just keep the data in memory. +__all__ = ( + 'InMemoryClipboard', +) + + +class InMemoryClipboard(Clipboard): + """ + Default clipboard implementation. + Just keep the data in memory. This implements a kill-ring, for Emacs mode. - """ + """ def __init__(self, data=None, max_size=60): assert data is None or isinstance(data, ClipboardData) assert max_size >= 1 - + self.max_size = max_size self._ring = deque() if data is not None: self.set_data(data) - def set_data(self, data): - assert isinstance(data, ClipboardData) + def set_data(self, data): + assert isinstance(data, ClipboardData) self._ring.appendleft(data) - + while len(self._ring) > self.max_size: self._ring.pop() - def get_data(self): + def get_data(self): if self._ring: return self._ring[0] else: diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/pyperclip.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/pyperclip.py index 2dc49ae8cb..61ab3aac0a 100644 --- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/pyperclip.py +++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/clipboard/pyperclip.py @@ -1,39 +1,39 @@ -from __future__ import absolute_import, unicode_literals -import pyperclip - -from prompt_toolkit.selection import SelectionType -from .base import Clipboard, ClipboardData - -__all__ = ( - 'PyperclipClipboard', -) - - -class PyperclipClipboard(Clipboard): - """ - Clipboard that synchronizes with the Windows/Mac/Linux system clipboard, - using the pyperclip module. - """ - def __init__(self): - self._data = None - - def set_data(self, data): - assert isinstance(data, ClipboardData) - self._data = data - pyperclip.copy(data.text) - - def get_data(self): - text = pyperclip.paste() - - # When the clipboard data is equal to what we copied last time, reuse - # the `ClipboardData` instance. That way we're sure to keep the same - # `SelectionType`. - if self._data and self._data.text == text: - return self._data - - # Pyperclip returned something else. Create a new `ClipboardData` - # instance. - else: - return ClipboardData( - text=text, - type=SelectionType.LINES if '\n' in text else SelectionType.LINES) +from __future__ import absolute_import, unicode_literals +import pyperclip + +from prompt_toolkit.selection import SelectionType +from .base import Clipboard, ClipboardData + +__all__ = ( + 'PyperclipClipboard', +) + + +class PyperclipClipboard(Clipboard): + """ + Clipboard that synchronizes with the Windows/Mac/Linux system clipboard, + using the pyperclip module. + """ + def __init__(self): + self._data = None + + def set_data(self, data): + assert isinstance(data, ClipboardData) + self._data = data + pyperclip.copy(data.text) + + def get_data(self): + text = pyperclip.paste() + + # When the clipboard data is equal to what we copied last time, reuse + # the `ClipboardData` instance. That way we're sure to keep the same + # `SelectionType`. + if self._data and self._data.text == text: + return self._data + + # Pyperclip returned something else. Create a new `ClipboardData` + # instance. + else: + return ClipboardData( + text=text, + type=SelectionType.LINES if '\n' in text else SelectionType.LINES) |