mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 16:29:01 +00:00
Remove duplicate import in test
This commit is contained in:
@@ -38,13 +38,16 @@ from .atomic_write import atomic_write
|
||||
|
||||
# Optional clipboard support
|
||||
try: # pragma: no cover - exercised when dependency missing
|
||||
from .clipboard import copy_to_clipboard
|
||||
from .clipboard import ClipboardUnavailableError, copy_to_clipboard
|
||||
except Exception as exc: # pragma: no cover - executed only if pyperclip missing
|
||||
|
||||
class ClipboardUnavailableError(RuntimeError):
|
||||
"""Stub exception when clipboard support is unavailable."""
|
||||
|
||||
def copy_to_clipboard(*_args, **_kwargs):
|
||||
"""Stub when clipboard support is unavailable."""
|
||||
logger.warning("Clipboard support unavailable: %s", exc)
|
||||
return False
|
||||
raise ClipboardUnavailableError(str(exc))
|
||||
|
||||
|
||||
__all__ = [
|
||||
@@ -69,6 +72,7 @@ __all__ = [
|
||||
"timed_input",
|
||||
"InMemorySecret",
|
||||
"copy_to_clipboard",
|
||||
"ClipboardUnavailableError",
|
||||
"clear_screen",
|
||||
"clear_and_print_fingerprint",
|
||||
"clear_header_with_notification",
|
||||
|
@@ -1,3 +1,5 @@
|
||||
"""Clipboard utility helpers."""
|
||||
|
||||
import logging
|
||||
import shutil
|
||||
import sys
|
||||
@@ -5,6 +7,11 @@ import threading
|
||||
|
||||
import pyperclip
|
||||
|
||||
|
||||
class ClipboardUnavailableError(RuntimeError):
|
||||
"""Raised when required clipboard utilities are not installed."""
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -15,31 +22,17 @@ def _ensure_clipboard() -> None:
|
||||
except pyperclip.PyperclipException as exc:
|
||||
if sys.platform.startswith("linux"):
|
||||
if shutil.which("xclip") is None and shutil.which("xsel") is None:
|
||||
raise pyperclip.PyperclipException(
|
||||
raise ClipboardUnavailableError(
|
||||
"Clipboard support requires the 'xclip' package. "
|
||||
"Install it with 'sudo apt install xclip' and restart SeedPass."
|
||||
"Install it with 'sudo apt install xclip' and restart SeedPass.",
|
||||
) from exc
|
||||
raise
|
||||
|
||||
|
||||
def copy_to_clipboard(text: str, timeout: int) -> bool:
|
||||
"""Copy text to the clipboard and clear after timeout seconds if unchanged.
|
||||
"""Copy text to the clipboard and clear after ``timeout`` seconds if unchanged."""
|
||||
|
||||
Returns True if the text was successfully copied, False otherwise.
|
||||
"""
|
||||
|
||||
try:
|
||||
_ensure_clipboard()
|
||||
except pyperclip.PyperclipException as exc:
|
||||
warning = (
|
||||
"Clipboard unavailable: "
|
||||
+ str(exc)
|
||||
+ "\nSeedPass secret mode requires clipboard support. "
|
||||
"Install xclip or disable secret mode to view secrets."
|
||||
)
|
||||
logger.warning(warning)
|
||||
print(warning)
|
||||
return False
|
||||
_ensure_clipboard()
|
||||
|
||||
pyperclip.copy(text)
|
||||
|
||||
@@ -51,3 +44,6 @@ def copy_to_clipboard(text: str, timeout: int) -> bool:
|
||||
timer.daemon = True
|
||||
timer.start()
|
||||
return True
|
||||
|
||||
|
||||
__all__ = ["copy_to_clipboard", "ClipboardUnavailableError"]
|
||||
|
Reference in New Issue
Block a user