$94 GRAYBYTE WORDPRESS FILE MANAGER $96

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/_pytest/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/_pytest//pastebin.py
"""Submit failure or test session information to a pastebin service."""
import tempfile
from io import StringIO
from typing import IO
from typing import Union

import pytest
from _pytest.config import Config
from _pytest.config import create_terminal_writer
from _pytest.config.argparsing import Parser
from _pytest.stash import StashKey
from _pytest.terminal import TerminalReporter


pastebinfile_key = StashKey[IO[bytes]]()


def pytest_addoption(parser: Parser) -> None:
    group = parser.getgroup("terminal reporting")
    group._addoption(
        "--pastebin",
        metavar="mode",
        action="store",
        dest="pastebin",
        default=None,
        choices=["failed", "all"],
        help="Send failed|all info to bpaste.net pastebin service",
    )


@pytest.hookimpl(trylast=True)
def pytest_configure(config: Config) -> None:
    if config.option.pastebin == "all":
        tr = config.pluginmanager.getplugin("terminalreporter")
        # If no terminal reporter plugin is present, nothing we can do here;
        # this can happen when this function executes in a worker node
        # when using pytest-xdist, for example.
        if tr is not None:
            # pastebin file will be UTF-8 encoded binary file.
            config.stash[pastebinfile_key] = tempfile.TemporaryFile("w+b")
            oldwrite = tr._tw.write

            def tee_write(s, **kwargs):
                oldwrite(s, **kwargs)
                if isinstance(s, str):
                    s = s.encode("utf-8")
                config.stash[pastebinfile_key].write(s)

            tr._tw.write = tee_write


def pytest_unconfigure(config: Config) -> None:
    if pastebinfile_key in config.stash:
        pastebinfile = config.stash[pastebinfile_key]
        # Get terminal contents and delete file.
        pastebinfile.seek(0)
        sessionlog = pastebinfile.read()
        pastebinfile.close()
        del config.stash[pastebinfile_key]
        # Undo our patching in the terminal reporter.
        tr = config.pluginmanager.getplugin("terminalreporter")
        del tr._tw.__dict__["write"]
        # Write summary.
        tr.write_sep("=", "Sending information to Paste Service")
        pastebinurl = create_new_paste(sessionlog)
        tr.write_line("pastebin session-log: %s\n" % pastebinurl)


def create_new_paste(contents: Union[str, bytes]) -> str:
    """Create a new paste using the bpaste.net service.

    :contents: Paste contents string.
    :returns: URL to the pasted contents, or an error message.
    """
    import re
    from urllib.request import urlopen
    from urllib.parse import urlencode

    params = {"code": contents, "lexer": "text", "expiry": "1week"}
    url = "https://bpa.st"
    try:
        response: str = (
            urlopen(url, data=urlencode(params).encode("ascii")).read().decode("utf-8")
        )
    except OSError as exc_info:  # urllib errors
        return "bad response: %s" % exc_info
    m = re.search(r'href="/raw/(\w+)"', response)
    if m:
        return f"{url}/show/{m.group(1)}"
    else:
        return "bad response: invalid format ('" + response + "')"


def pytest_terminal_summary(terminalreporter: TerminalReporter) -> None:
    if terminalreporter.config.option.pastebin != "failed":
        return
    if "failed" in terminalreporter.stats:
        terminalreporter.write_sep("=", "Sending information to Paste Service")
        for rep in terminalreporter.stats["failed"]:
            try:
                msg = rep.longrepr.reprtraceback.reprentries[-1].reprfileloc
            except AttributeError:
                msg = terminalreporter._getfailureheadline(rep)
            file = StringIO()
            tw = create_terminal_writer(terminalreporter.config, file)
            rep.toterminal(tw)
            s = file.getvalue()
            assert len(s)
            pastebinurl = create_new_paste(s)
            terminalreporter.write_line(f"{msg} --> {pastebinurl}")

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
_code
--
14 Aug 2025 9.24 PM
root / root
0755
_io
--
14 Aug 2025 9.24 PM
root / root
0755
_py
--
14 Aug 2025 9.24 PM
root / root
0755
assertion
--
14 Aug 2025 9.24 PM
root / root
0755
config
--
14 Aug 2025 9.24 PM
root / root
0755
mark
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
0.348 KB
17 Apr 2025 8.10 PM
root / root
0644
_argcomplete.py
3.705 KB
17 Apr 2025 8.10 PM
root / root
0644
_version.py
0.156 KB
17 Apr 2025 8.10 PM
root / root
0644
cacheprovider.py
20.891 KB
17 Apr 2025 8.10 PM
root / root
0644
capture.py
33.923 KB
17 Apr 2025 8.10 PM
root / root
0644
compat.py
12.891 KB
17 Apr 2025 8.10 PM
root / root
0644
debugging.py
13.182 KB
17 Apr 2025 8.10 PM
root / root
0644
deprecated.py
5.358 KB
17 Apr 2025 8.10 PM
root / root
0644
doctest.py
25.353 KB
17 Apr 2025 8.10 PM
root / root
0644
faulthandler.py
3.041 KB
17 Apr 2025 8.10 PM
root / root
0644
fixtures.py
65.513 KB
17 Apr 2025 8.10 PM
root / root
0644
freeze_support.py
1.308 KB
17 Apr 2025 8.10 PM
root / root
0644
helpconfig.py
8.338 KB
17 Apr 2025 8.10 PM
root / root
0644
hookspec.py
31.795 KB
17 Apr 2025 8.10 PM
root / root
0644
junitxml.py
25.113 KB
17 Apr 2025 8.10 PM
root / root
0644
legacypath.py
16.532 KB
17 Apr 2025 8.10 PM
root / root
0644
logging.py
33.233 KB
17 Apr 2025 8.10 PM
root / root
0644
main.py
31.729 KB
17 Apr 2025 8.10 PM
root / root
0644
monkeypatch.py
14.509 KB
17 Apr 2025 8.10 PM
root / root
0644
nodes.py
25.937 KB
17 Apr 2025 8.10 PM
root / root
0644
nose.py
1.648 KB
17 Apr 2025 8.10 PM
root / root
0644
outcomes.py
10.016 KB
17 Apr 2025 8.10 PM
root / root
0644
pastebin.py
3.856 KB
17 Apr 2025 8.10 PM
root / root
0644
pathlib.py
25.219 KB
17 Apr 2025 8.10 PM
root / root
0644
py.typed
0 KB
17 Apr 2025 8.10 PM
root / root
0644
pytester.py
60.519 KB
17 Apr 2025 8.10 PM
root / root
0644
pytester_assertions.py
2.272 KB
17 Apr 2025 8.10 PM
root / root
0644
python.py
69.487 KB
17 Apr 2025 8.10 PM
root / root
0644
python_api.py
37.5 KB
17 Apr 2025 8.10 PM
root / root
0644
python_path.py
0.692 KB
17 Apr 2025 8.10 PM
root / root
0644
recwarn.py
10.674 KB
17 Apr 2025 8.10 PM
root / root
0644
reports.py
20.352 KB
17 Apr 2025 8.10 PM
root / root
0644
runner.py
18.015 KB
17 Apr 2025 8.10 PM
root / root
0644
scope.py
2.814 KB
17 Apr 2025 8.10 PM
root / root
0644
setuponly.py
3.185 KB
17 Apr 2025 8.10 PM
root / root
0644
setupplan.py
1.186 KB
17 Apr 2025 8.10 PM
root / root
0644
skipping.py
9.961 KB
17 Apr 2025 8.10 PM
root / root
0644
stash.py
2.983 KB
17 Apr 2025 8.10 PM
root / root
0644
stepwise.py
4.604 KB
17 Apr 2025 8.10 PM
root / root
0644
terminal.py
52.255 KB
17 Apr 2025 8.10 PM
root / root
0644
threadexception.py
2.847 KB
17 Apr 2025 8.10 PM
root / root
0644
timing.py
0.366 KB
17 Apr 2025 8.10 PM
root / root
0644
tmpdir.py
11.434 KB
17 Apr 2025 8.10 PM
root / root
0644
unittest.py
14.462 KB
17 Apr 2025 8.10 PM
root / root
0644
unraisableexception.py
3.116 KB
17 Apr 2025 8.10 PM
root / root
0644
warning_types.py
4.369 KB
17 Apr 2025 8.10 PM
root / root
0644
warnings.py
4.951 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF