Uploaded Test files
This commit is contained in:
parent
f584ad9d97
commit
2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions
15
venv/Lib/site-packages/prompt_toolkit/clipboard/__init__.py
Normal file
15
venv/Lib/site-packages/prompt_toolkit/clipboard/__init__.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from .base import Clipboard, ClipboardData, DummyClipboard, DynamicClipboard
|
||||
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
|
||||
|
||||
__all__ = [
|
||||
"Clipboard",
|
||||
"ClipboardData",
|
||||
"DummyClipboard",
|
||||
"DynamicClipboard",
|
||||
"InMemoryClipboard",
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
107
venv/Lib/site-packages/prompt_toolkit/clipboard/base.py
Normal file
107
venv/Lib/site-packages/prompt_toolkit/clipboard/base.py
Normal file
|
@ -0,0 +1,107 @@
|
|||
"""
|
||||
Clipboard for command line interface.
|
||||
"""
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import Callable, Optional
|
||||
|
||||
from prompt_toolkit.selection import SelectionType
|
||||
|
||||
__all__ = [
|
||||
"Clipboard",
|
||||
"ClipboardData",
|
||||
"DummyClipboard",
|
||||
"DynamicClipboard",
|
||||
]
|
||||
|
||||
|
||||
class ClipboardData:
|
||||
"""
|
||||
Text on the clipboard.
|
||||
|
||||
:param text: string
|
||||
:param type: :class:`~prompt_toolkit.selection.SelectionType`
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, text: str = "", type: SelectionType = SelectionType.CHARACTERS
|
||||
) -> None:
|
||||
|
||||
self.text = text
|
||||
self.type = type
|
||||
|
||||
|
||||
class Clipboard(metaclass=ABCMeta):
|
||||
"""
|
||||
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: ClipboardData) -> None:
|
||||
"""
|
||||
Set data to the clipboard.
|
||||
|
||||
:param data: :class:`~.ClipboardData` instance.
|
||||
"""
|
||||
|
||||
def set_text(self, text: str) -> None: # Not abstract.
|
||||
"""
|
||||
Shortcut for setting plain text on clipboard.
|
||||
"""
|
||||
self.set_data(ClipboardData(text))
|
||||
|
||||
def rotate(self) -> None:
|
||||
"""
|
||||
For Emacs mode, rotate the kill ring.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_data(self) -> ClipboardData:
|
||||
"""
|
||||
Return clipboard data.
|
||||
"""
|
||||
|
||||
|
||||
class DummyClipboard(Clipboard):
|
||||
"""
|
||||
Clipboard implementation that doesn't remember anything.
|
||||
"""
|
||||
|
||||
def set_data(self, data: ClipboardData) -> None:
|
||||
pass
|
||||
|
||||
def set_text(self, text: str) -> None:
|
||||
pass
|
||||
|
||||
def rotate(self) -> None:
|
||||
pass
|
||||
|
||||
def get_data(self) -> ClipboardData:
|
||||
return ClipboardData()
|
||||
|
||||
|
||||
class DynamicClipboard(Clipboard):
|
||||
"""
|
||||
Clipboard class that can dynamically returns any Clipboard.
|
||||
|
||||
:param get_clipboard: Callable that returns a :class:`.Clipboard` instance.
|
||||
"""
|
||||
|
||||
def __init__(self, get_clipboard: Callable[[], Optional[Clipboard]]) -> None:
|
||||
self.get_clipboard = get_clipboard
|
||||
|
||||
def _clipboard(self) -> Clipboard:
|
||||
return self.get_clipboard() or DummyClipboard()
|
||||
|
||||
def set_data(self, data: ClipboardData) -> None:
|
||||
self._clipboard().set_data(data)
|
||||
|
||||
def set_text(self, text: str) -> None:
|
||||
self._clipboard().set_text(text)
|
||||
|
||||
def rotate(self) -> None:
|
||||
self._clipboard().rotate()
|
||||
|
||||
def get_data(self) -> ClipboardData:
|
||||
return self._clipboard().get_data()
|
46
venv/Lib/site-packages/prompt_toolkit/clipboard/in_memory.py
Normal file
46
venv/Lib/site-packages/prompt_toolkit/clipboard/in_memory.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from collections import deque
|
||||
from typing import Deque, Optional
|
||||
|
||||
from .base import Clipboard, ClipboardData
|
||||
|
||||
__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: Optional[ClipboardData] = None, max_size: int = 60
|
||||
) -> None:
|
||||
|
||||
assert max_size >= 1
|
||||
|
||||
self.max_size = max_size
|
||||
self._ring: Deque[ClipboardData] = deque()
|
||||
|
||||
if data is not None:
|
||||
self.set_data(data)
|
||||
|
||||
def set_data(self, data: ClipboardData) -> None:
|
||||
self._ring.appendleft(data)
|
||||
|
||||
while len(self._ring) > self.max_size:
|
||||
self._ring.pop()
|
||||
|
||||
def get_data(self) -> ClipboardData:
|
||||
if self._ring:
|
||||
return self._ring[0]
|
||||
else:
|
||||
return ClipboardData()
|
||||
|
||||
def rotate(self) -> None:
|
||||
if self._ring:
|
||||
# Add the very first item at the end.
|
||||
self._ring.append(self._ring.popleft())
|
42
venv/Lib/site-packages/prompt_toolkit/clipboard/pyperclip.py
Normal file
42
venv/Lib/site-packages/prompt_toolkit/clipboard/pyperclip.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from typing import Optional
|
||||
|
||||
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) -> None:
|
||||
self._data: Optional[ClipboardData] = None
|
||||
|
||||
def set_data(self, data: ClipboardData) -> None:
|
||||
self._data = data
|
||||
pyperclip.copy(data.text)
|
||||
|
||||
def get_data(self) -> ClipboardData:
|
||||
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,
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue