Skip to content
This repository has been archived by the owner on Oct 13, 2018. It is now read-only.

Commit

Permalink
Sublime 3 ready. Added compatibility to Python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartTC committed Sep 24, 2013
1 parent 6dbf5b7 commit 15f32b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Empty file added .sublime-package
Empty file.
20 changes: 9 additions & 11 deletions dpaste.py
@@ -1,10 +1,9 @@
import sublime, sublime_plugin

import sublime
import sublime_plugin
import urllib
import urllib2
import sys

sep = """
DPASTE_API_URL = 'http://dpaste.de/api/'
SEP = """
# ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------
Expand All @@ -13,11 +12,9 @@
"""

def paste_code(content):
request = urllib2.Request(
'http://dpaste.de/api/',
urllib.urlencode([('content', content)]),
)
response = urllib2.urlopen(request)
data = urllib.parse.urlencode({'content': content})
data = data.encode('utf8')
response = urllib.request.urlopen(DPASTE_API_URL, data)
return response.read()[1:-1]


Expand All @@ -27,9 +24,10 @@ def run(self, edit):
regions = len(regions) == 0 and [sublime.Region(0, self.view.size())] \
or regions
region_data = [self.view.substr(region) for region in regions]
content = sep.join(region_data)
content = SEP.join(region_data)

paste_url = paste_code(content)
paste_url = paste_url.decode('utf8')

sublime.status_message('Pasted to %s and copied to your clipboard!' % paste_url)
sublime.set_clipboard(paste_url)
Expand Down

0 comments on commit 15f32b6

Please sign in to comment.