Skip to content

Commit

Permalink
Correct typos, update the error messages, cleaning the code and comme…
Browse files Browse the repository at this point in the history
…nting it a little bit more
  • Loading branch information
stgraber committed Nov 22, 2006
1 parent 5dcc396 commit ca19487
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions pastebinit
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import urllib, os, sys, re
defaultPB="http://paste.ubuntu-nl.org"

#Return the parameters depending of the pastebin used
def getParameters(website,content,user):
"Return the parameters array for the selected pastebin"
params={}
Expand All @@ -31,23 +32,22 @@ def getParameters(website,content,user):
params['poster']=user
params['code2']=content
params['parent_pid']=""
params['format']="text"
params['paste']="Send"
params['remember']="1"
params['expiry']="f"
params['format']="text" #The format, for syntax hilighting
params['paste']="Send"
params['remember']="1" #Do you want a cookie ?
params['expiry']="f" #The expiration, f = forever
else:
sys.exit("Unknown website, please post a bugreport to request this pastebin to be added ("+website+")")

return params

#Check if a filename is passed as argument, otherwise show the usages
#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|\"-\"]"+"\n\nDefault pastebin: "+defaultPB)

#Read the content and put it into content

#If - is specified as a filename read from stdin, otherwise load the specified file.
if filename == "-":
content=sys.stdin.read()
else:
Expand All @@ -56,18 +56,17 @@ else:
content=f.read()
f.close()
except:
sys.exit("Unable to open : "+filename)

#Check if an extra pastebin was pasted as parameter
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')
params=getParameters(website,content,user)
params=urllib.urlencode(params)
user=os.environ.get('USER') #Get the current username from the environment
params=getParameters(website,content,user) #Get the parameters array
params=urllib.urlencode(params) #Convert to a format usable with the HTML POST

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

0 comments on commit ca19487

Please sign in to comment.