How to use the pyperclip.PyperclipException function in pyperclip

To help you get started, we’ve selected a few pyperclip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitmproxy / mitmproxy / test / mitmproxy / addons / test_cut.py View on Github external
with mock.patch('pyperclip.copy') as pc:
            tctx.command(c.clip, "@all", "request.method")
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            tctx.command(c.clip, "@all", "request.content")
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            tctx.command(c.clip, "@all", "request.method,request.content")
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            log_message = "Pyperclip could not find a " \
                          "copy/paste mechanism for your system."
            pc.side_effect = pyperclip.PyperclipException(log_message)
            tctx.command(c.clip, "@all", "request.method")
            assert tctx.master.has_log(log_message, level="error")
github mitmproxy / mitmproxy / test / mitmproxy / addons / test_export.py View on Github external
with taddons.context() as tctx:
        with pytest.raises(exceptions.CommandError):
            e.clip("nonexistent", tflow.tflow(resp=True))

        with mock.patch('pyperclip.copy') as pc:
            e.clip("raw", tflow.tflow(resp=True))
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            e.clip("curl", tflow.tflow(resp=True))
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            log_message = "Pyperclip could not find a " \
                          "copy/paste mechanism for your system."
            pc.side_effect = pyperclip.PyperclipException(log_message)
            e.clip("raw", tflow.tflow(resp=True))
            assert tctx.master.has_log(log_message, level="error")
github asweigart / pyperclip / tests / test_pyperclip.py View on Github external
self.copy(-1)
        self.assertEqual(self.paste(), '-1')

        # Test copying a float.
        self.copy(3.141592)
        self.assertEqual(self.paste(), '3.141592')

        # Test copying bools.
        self.copy(True)
        self.assertEqual(self.paste(), 'True')

        self.copy(False)
        self.assertEqual(self.paste(), 'False')

        # All other non-str values raise an exception.
        with self.assertRaises(PyperclipException):
            self.copy(None)

        with self.assertRaises(PyperclipException):
            self.copy([2, 4, 6, 8])
github mitmproxy / mitmproxy / mitmproxy / addons / export.py View on Github external
def clip(self, fmt: str, f: flow.Flow) -> None:
        """
            Export a flow to the system clipboard.
        """
        if fmt not in formats:
            raise exceptions.CommandError("No such export format: %s" % fmt)
        func = formats[fmt]  # type: typing.Any
        v = strutils.always_str(func(f))
        try:
            pyperclip.copy(v)
        except pyperclip.PyperclipException as e:
            ctx.log.error(str(e))
github crew102 / reprexpy / reprexpy / reprex.py View on Github external
def _get_source_code(code, code_file):
    if code is not None:
        code_str = code
    elif code_file is not None:
        with open(code_file) as fi:
            code_str = fi.read()
    else:
        try:
            code_str = pyperclip.paste()
        except pyperclip.PyperclipException:
            raise Exception(
                'Could not retrieve code from the clipboard. '
                'Try putting your code in a file and using '
                'the `code_file` parameter instead of using the clipboard.'
            )
    return code_str
github mitmproxy / mitmproxy / mitmproxy / addons / cut.py View on Github external
fp = io.StringIO(newline="")
        if len(cuts) == 1 and len(flows) == 1:
            v = extract(cuts[0], flows[0])
            fp.write(strutils.always_str(v))  # type: ignore
            ctx.log.alert("Clipped single cut.")
        else:
            writer = csv.writer(fp)
            for f in flows:
                vals = [extract(c, f) for c in cuts]
                writer.writerow(
                    [strutils.always_str(v) for v in vals]
                )
            ctx.log.alert("Clipped %s cuts as CSV." % len(cuts))
        try:
            pyperclip.copy(fp.getvalue())
        except pyperclip.PyperclipException as e:
            ctx.log.error(str(e))
github python-cmd2 / cmd2 / cmd2 / clipboard.py View on Github external
# coding=utf-8
"""
This module provides basic ability to copy from and paste to the clipboard/pastebuffer.
"""
import pyperclip
# noinspection PyProtectedMember
from pyperclip import PyperclipException

# Can we access the clipboard?  Should always be true on Windows and Mac, but only sometimes on Linux
try:
    # Try getting the contents of the clipboard
    _ = pyperclip.paste()
except (PyperclipException, FileNotFoundError, ValueError):
    # NOTE: FileNotFoundError is for Windows Subsystem for Linux (WSL) when Windows paths are removed from $PATH
    # NOTE: ValueError is for headless Linux systems without Gtk installed
    can_clip = False
else:
    can_clip = True


def get_paste_buffer() -> str:
    """Get the contents of the clipboard / paste buffer.

    :return: contents of the clipboard
    """
    pb_str = pyperclip.paste()
    return pb_str
github zlorb / locust.replay / locust_extractor.py View on Github external
def code_clip(self, flows: typing.Sequence[flow.Flow]) -> None:
        """Export a flow to the system clipboard as locust code."""
        ctx.log.info(str(type(flows)))
        data = strutils.always_str(self.context.locust_code(flows[0]))
        if len(flows)>1:
            for f in flows[1:]:
                v = strutils.always_str(self.context.locust_task(f))
                tmp = data[:-100]
                tmp += v + '\n'
                tmp += data[-100:]
                data = tmp
        try:
            pyperclip.copy(data)
        except pyperclip.PyperclipException as e:
            ctx.log.error(str(e))
github microsoft / msticpy / msticpy / common / keyvault_client.py View on Github external
def _prompt_for_code(device_code):
    # copy code to clipboard
    try:
        pyperclip.copy(device_code["user_code"])
    except PyperclipException:
        # On Linux this can fail if clipboard support not installed
        pass
    verif_uri = device_code.get("verification_url", device_code.get("verification_uri"))
    title = "Authentication needed for KeyVault access."
    logon_mssg = "User code {} copied to clipboard.".format(device_code["user_code"])

    if is_ipython():
        display(HTML(f"<h3>{title}</h3>"))
        logon_mssg += "<br><a href="{}">".format(verif_uri)
        logon_mssg += "Click to open logon page</a><br>"
    else:
        print(title)
        print("-" * len(title))
        logon_mssg += "\nOpen the URL '{}' in a browser\n".format(verif_uri)
    logon_mssg += "then press Ctrl/Cmd-V to paste your code to authenticate. "
    if "expires_in" in device_code: