All pastes #840294 Raw Edit

Something

public text v1 · immutable
#840294 ·published 2007-12-31 17:59 UTC
rendered paste body
def getParameters(website,content,user,version):
    "Return the parameters array for the selected pastebin"
    params={}
    
    if website == "http://archlinux.pastebin.com":
	params['poster']=user
        params['code2']=content
        params['parent_pid']="" #For reply, "" means homepage (new thread)
	params['format']="text" #The format, for syntax hilighting
	params['paste']="Send" 
        params['remember']="0" #Do you want a cookie ?
	params['expiry']="f" #The expiration, f = forever
	params['regexp']="None"
    elif website == "http://pastebin.ca":
	params['name']=user
        params['content']=content
	params['type']="1" #The expiration, 1 = raw
	params['save']="0" #Do you want a cookie ?
	params['s']="Submit Post"
	params['regexp']='">http://pastebin.ca/(.*)</a></p><p>'   
    elif re.search("http://.*\.pastebin\.com", website):
	params['poster']=user
        params['code2']=content
        params['parent_pid']="" #For reply, "" means homepage (new thread)
	params['format']="text" #The format, for syntax hilighting
	params['paste']="Send" 
        params['remember']="0" #Do you want a cookie ?
	params['expiry']="f" #The expiration, f = forever
	params['regexp']="None"
    elif website == "http://pastebin.com":
	params['poster']=user
        params['code2']=content
        params['parent_pid']="" #For reply, "" means homepage (new thread)
	params['format']="text" #The format, for syntax hilighting
	params['paste']="Send" 
        params['remember']="0" #Do you want a cookie ?
	params['expiry']="f" #The expiration, f = forever
	params['regexp']="None"
    elif website == "http://rafb.net":
	params['lang']="C"
        params['nick']=user
	params['desc']=""
	params['cvt_tabs']="No" 
        params['text']=content
	params['submit']="Paste"
	params['regexp']='">http://rafb.net/p/(.*?)</a></p><p>' 
    else:
	sys.exit("Unknown website, please post a request for this pastebin to be added ("+website+")")
    return params

#Check if a filename is passed as an argument, otherwise show the usages
try:
    filename=sys.argv[1]
except:
    sys.exit("usage: "+sys.argv[0]+" [filename|-] [URL]\n\nDefault pastebin: "+defaultPB+"\nVersion: "+version)
    
#If - is specified as a filename read from stdin, otherwise load the specified file.
if filename == "-":
    content=sys.stdin.read()
else:
    try:
        f=open(filename)
        content=f.read()
        f.close()        
    except:
        sys.exit("Unable to read from: "+filename)

#Check if an extra pastebin is pasted as an argument otherwise use the default Pastebin
try:
    website=sys.argv[2]
except:
    website=defaultPB

user=os.environ.get('USER') #Get the current username from the environment
params=getParameters(website,content,user,version) #Get the parameters array
reLink=params['regexp'] #Extract the regexp
params['regexp']=None #Remove the regexp from what will be sent
params=urllib.urlencode(params) #Convert to a format usable with the HTML POST

page=urllib.urlopen(website+'/',params) #Send the informations and be redirected to the final page

try:
    if reLink != "None": #Check if we have to apply a regexp
	print website+"/"+re.split(reLink, page.read())[1] #Print the result of the Regexp
    else:
	print page.url #Get the final page and show the url
except:
    sys.exit("Unable to read or parse the result page, it could be a server timeout or a change server side, try with another pastebin.")