summaryrefslogtreecommitdiff
path: root/_pytest/pastebin.py
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2014-10-22 21:52:40 -0200
committerBruno Oliveira <nicoddemus@gmail.com>2014-10-22 21:52:40 -0200
commit537dca477bf7ef9294b4a6466a1063c64ad2c17a (patch)
tree8e7f5a7cb08c028a9da0529c3e152adf847c3439 /_pytest/pastebin.py
parent8480111012a5d0c96d9870f2527ba249d796f57a (diff)
downloadpytest-537dca477bf7ef9294b4a6466a1063c64ad2c17a.tar.gz
Fixing --pastebin option by using a POST request instead of a XMLRPC call
fixes #614 --HG-- branch : fix-pastebin
Diffstat (limited to '_pytest/pastebin.py')
-rw-r--r--_pytest/pastebin.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/_pytest/pastebin.py b/_pytest/pastebin.py
index 4151fbf0d..be4b464f8 100644
--- a/_pytest/pastebin.py
+++ b/_pytest/pastebin.py
@@ -3,10 +3,6 @@ import pytest
import py, sys
import tempfile
-class url:
- base = "http://bpaste.net"
- xmlrpc = base + "/xmlrpc/"
- show = base + "/show/"
def pytest_addoption(parser):
group = parser.getgroup("terminal reporting")
@@ -28,22 +24,45 @@ def pytest_configure(config):
def pytest_unconfigure(config):
if hasattr(config, '_pastebinfile'):
+ # get terminal contents and delete file
config._pastebinfile.seek(0)
sessionlog = config._pastebinfile.read()
config._pastebinfile.close()
del config._pastebinfile
- proxyid = getproxy().newPaste("python", sessionlog)
- pastebinurl = "%s%s" % (url.show, proxyid)
- sys.stderr.write("pastebin session-log: %s\n" % pastebinurl)
+ # 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 getproxy():
+def create_new_paste(contents):
+ """
+ Creates a new paste using bpaste.net service.
+
+ :contents: paste contents
+ :returns: url to the pasted contents
+ """
+ import re
if sys.version_info < (3, 0):
- from xmlrpclib import ServerProxy
+ from urllib import urlopen, urlencode
+ else:
+ from urllib.request import urlopen
+ from urllib.parse import urlencode
+
+ params = {
+ 'code': contents,
+ 'lexer': 'python3' if sys.version_info[0] == 3 else 'python',
+ 'expiry': '1week',
+ }
+ url = 'https://bpaste.net'
+ response = urlopen(url, data=urlencode(params)).read()
+ m = re.search(r'href="/raw/(\w+)"', response)
+ if m:
+ return '%s/show/%s' % (url, m.group(1))
else:
- from xmlrpc.client import ServerProxy
- return ServerProxy(url.xmlrpc).pastes
+ return 'bad response: ' + response
def pytest_terminal_summary(terminalreporter):
if terminalreporter.config.option.pastebin != "failed":
@@ -51,9 +70,6 @@ def pytest_terminal_summary(terminalreporter):
tr = terminalreporter
if 'failed' in tr.stats:
terminalreporter.write_sep("=", "Sending information to Paste Service")
- if tr.config.option.debug:
- terminalreporter.write_line("xmlrpcurl: %s" %(url.xmlrpc,))
- serverproxy = getproxy()
for rep in terminalreporter.stats.get('failed'):
try:
msg = rep.longrepr.reprtraceback.reprentries[-1].reprfileloc
@@ -63,6 +79,5 @@ def pytest_terminal_summary(terminalreporter):
rep.toterminal(tw)
s = tw.stringio.getvalue()
assert len(s)
- proxyid = serverproxy.newPaste("python", s)
- pastebinurl = "%s%s" % (url.show, proxyid)
+ pastebinurl = create_new_paste(s)
tr.write_line("%s --> %s" %(msg, pastebinurl))