3 from argparse import ArgumentParser
6 from urllib.parse import urljoin
11 paste_host = 'paste.ubuntu.com'
15 if __name__ == '__main__':
16 poster = os.environ.get("USER")
18 parser = ArgumentParser()
19 parser.add_argument("-f", "--format", default="text", help="format of paste")
20 parser.add_argument("title", default="The loser %s didn't even add a title" % poster, nargs="?")
21 args = parser.parse_args()
23 form = (('poster', poster), ('title', args.title), ('syntax', args.format), ('content', sys.stdin.read()))
24 response = requests.post('https://%s/%s' % (paste_host, paste_path.lstrip('/')), data=form, allow_redirects=False)
25 location = response.headers['Location']
27 print(urljoin('https://' + paste_host, location))
29 print('Unexpected response:\n%s' % response.headers)