X Tutup
Skip to content

Commit b422374

Browse files
committed
use paste.pocoo.org for pastebin instead of dead rafb.net/paste
1 parent 2c8ac57 commit b422374

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

bpython/cli.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import pydoc
4848
import types
4949
from cStringIO import StringIO
50+
from urlparse import urljoin
51+
from xmlrpclib import ServerProxy, Error as XMLRPCError
5052

5153
# These are used for syntax hilighting.
5254
from pygments import highlight
@@ -797,32 +799,20 @@ def write2file(self):
797799
def pastebin(self):
798800
"""Upload to a pastebin and display the URL in the status bar."""
799801

802+
pasteservice_url = 'http://paste.pocoo.org/'
803+
pasteservice = ServerProxy(urljoin(pasteservice_url, '/xmlrpc/'))
804+
800805
s = self.getstdout()
801-
url = 'http://rafb.net/paste/paste.php'
802-
pdata = {
803-
'lang': 'Python',
804-
'cvt_tabs': 'No',
805-
'text': s
806-
}
807-
pdata = urllib.urlencode(pdata)
808806

809807
self.statusbar.message('Posting data to pastebin...')
810808
try:
811-
u = urllib.urlopen(url, data=pdata)
812-
d = u.read()
813-
except (socket.error, socket.timeout, IOError), e:
809+
paste_id = pasteservice.pastes.newPaste('pycon', s)
810+
except XMLRPCError, e:
814811
self.statusbar.message( 'Upload failed: %s' % str(e) )
815812
return
816-
817-
rx = re.search('(http://rafb.net/p/[0-9a-zA-Z]+\.html)', d)
818-
if not rx:
819-
self.statusbar.message(
820-
'Error parsing pastebin URL! Please report a bug.')
821-
return
822-
823-
824-
r_url = rx.groups()[0]
825-
self.statusbar.message('Pastebin URL: %s' % r_url, 10)
813+
814+
paste_url = urljoin(pasteservice_url, '/show/%s/' % paste_id)
815+
self.statusbar.message('Pastebin URL: %s' % paste_url, 10)
826816

827817
def make_list(self, items):
828818
"""Compile a list of items. At the moment this simply returns

0 commit comments

Comments
 (0)
X Tutup