MCPcopy
hub / github.com/pytest-dev/pytest / create_new_paste

Function create_new_paste

src/_pytest/pastebin.py:76–102  ·  view source on GitHub ↗

Create a new paste using the bpaste.net service. :contents: Paste contents string. :returns: URL to the pasted contents, or an error message.

(contents: str | bytes)

Source from the content-addressed store, hash-verified

74
75
76def create_new_paste(contents: str | bytes) -> str:
77 """Create a new paste using the bpaste.net service.
78
79 :contents: Paste contents string.
80 :returns: URL to the pasted contents, or an error message.
81 """
82 import re
83 from urllib.error import HTTPError
84 from urllib.parse import urlencode
85 from urllib.request import urlopen
86
87 params = {"code": contents, "lexer": "text", "expiry": "1week"}
88 url = "https://bpa.st"
89 try:
90 response: str = (
91 urlopen(url, data=urlencode(params).encode("ascii")).read().decode("utf-8")
92 )
93 except HTTPError as e:
94 with e: # HTTPErrors are also http responses that must be closed!
95 return f"bad response: {e}"
96 except OSError as e: # eg urllib.error.URLError
97 return f"bad response: {e}"
98 m = re.search(r'href="/raw/(\w+)"', response)
99 if m:
100 return f"{url}/show/{m.group(1)}"
101 else:
102 return "bad response: invalid format ('" + response + "')"
103
104
105def pytest_terminal_summary(terminalreporter: TerminalReporter) -> None:

Callers 2

pytest_unconfigureFunction · 0.85
pytest_terminal_summaryFunction · 0.85

Calls 2

groupMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…