feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +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

View File

@@ -0,0 +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))
def rotate(self):
"""
For Emacs mode, rotate the kill ring.
"""
@abstractmethod
def get_data(self):
"""
Return clipboard data.
"""

View File

@@ -0,0 +1,42 @@
from .base import Clipboard, ClipboardData
from collections import deque
__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)
self._ring.appendleft(data)
while len(self._ring) > self.max_size:
self._ring.pop()
def get_data(self):
if self._ring:
return self._ring[0]
else:
return ClipboardData()
def rotate(self):
if self._ring:
# Add the very first item at the end.
self._ring.append(self._ring.popleft())

View File

@@ -0,0 +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)