MCPcopy Create free account
hub / github.com/pytest-dev/pytest / create_new_paste

Function create_new_paste

src/_pytest/pastebin.py:69–91  ·  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: Union[str, bytes])

Source from the content-addressed store, hash-verified

67
68
69def create_new_paste(contents: Union[str, bytes]) -> str:
70 """Create a new paste using the bpaste.net service.
71
72 :contents: Paste contents string.
73 :returns: URL to the pasted contents, or an error message.
74 """
75 import re
76 from urllib.request import urlopen
77 from urllib.parse import urlencode
78
79 params = {"code": contents, "lexer": "text", "expiry": "1week"}
80 url = "https://bpa.st"
81 try:
82 response: str = (
83 urlopen(url, data=urlencode(params).encode("ascii")).read().decode("utf-8")
84 )
85 except OSError as exc_info: # urllib errors
86 return "bad response: %s" % exc_info
87 m = re.search(r'href="/raw/(\w+)"', response)
88 if m:
89 return f"{url}/show/{m.group(1)}"
90 else:
91 return "bad response: invalid format ('" + response + "')"
92
93
94def pytest_terminal_summary(terminalreporter: TerminalReporter) -> None:

Callers 2

pytest_unconfigureFunction · 0.85
pytest_terminal_summaryFunction · 0.85

Calls 1

readMethod · 0.45

Tested by

no test coverage detected