|
47 | 47 | import pydoc |
48 | 48 | import types |
49 | 49 | from cStringIO import StringIO |
| 50 | +from urlparse import urljoin |
| 51 | +from xmlrpclib import ServerProxy, Error as XMLRPCError |
50 | 52 |
|
51 | 53 | # These are used for syntax hilighting. |
52 | 54 | from pygments import highlight |
@@ -797,32 +799,20 @@ def write2file(self): |
797 | 799 | def pastebin(self): |
798 | 800 | """Upload to a pastebin and display the URL in the status bar.""" |
799 | 801 |
|
| 802 | + pasteservice_url = 'http://paste.pocoo.org/' |
| 803 | + pasteservice = ServerProxy(urljoin(pasteservice_url, '/xmlrpc/')) |
| 804 | + |
800 | 805 | 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) |
808 | 806 |
|
809 | 807 | self.statusbar.message('Posting data to pastebin...') |
810 | 808 | 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: |
814 | 811 | self.statusbar.message( 'Upload failed: %s' % str(e) ) |
815 | 812 | 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) |
826 | 816 |
|
827 | 817 | def make_list(self, items): |
828 | 818 | """Compile a list of items. At the moment this simply returns |
|
0 commit comments