7 from urlparse import urljoin
9 paste_host = 'paste.ubuntu.com'
12 def http_post_form_with_auth(host, path, form):
13 form_data = urllib.urlencode(form).strip()
14 connection = httplib.HTTPConnection(host)
15 connection.request('POST', path, form_data, {
17 'Content-type': 'application/x-www-form-urlencoded',
18 'Content-length': str(len(form_data)),
20 return connection.getresponse()
22 if __name__ == '__main__':
23 poster = os.environ.get("USER")
28 title = "The loser %s didn't even add a title" % poster
29 form = (('poster', poster), ('title', title), ('syntax', syntax), ('content', sys.stdin.read()))
30 response = http_post_form_with_auth(paste_host, paste_path, form)
31 location = response.getheader('Location')
33 print urljoin('http://' + paste_host, location)
35 print 'Unexpected response:\n%s' % response.getheaders()