Skip to content

Commit

Permalink
Add json support by Soren
Browse files Browse the repository at this point in the history
  • Loading branch information
stgraber committed Jan 24, 2011
2 parents acd6cc3 + b583517 commit 9628c55
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pastebinit
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ except ImportError:

try:
import urllib, os, sys, re, getopt, xml.dom.minidom, gettext
try:
import json # For python 2.6 and newer
except ImportError:
try:
import simplejson as json
except ImportError:
json = None
from gettext import gettext as _
import configobj

Expand Down Expand Up @@ -303,9 +310,24 @@ try:
if "regexp" in params:
reLink = params['regexp']
del params["regexp"]
params = urllib.urlencode(params) #Convert to a format usable with the HTML POST

if 'post_format' in params:
post_format = params['post_format']
del params['post_format']
else:
post_format = 'standard'

url_opener = pasteURLopener()

if post_format == 'json':
if json:
params = json.dumps(params)
url_opener.addheader('Content-type: text/json')
else:
sys.exit(_("Could not find any json library."))
else:
params = urllib.urlencode(params) #Convert to a format usable with the HTML POST

page = url_opener.open(website, params) #Send the informations and be redirected to the final page

try:
Expand Down

0 comments on commit 9628c55

Please sign in to comment.