import argparse
import enum
import os
import sys

import requests

Link = ''
Endpoint = ''
Result = enum.IntEnum('Result', 'Success InvalidData InvalidSyntax InvalidExpiration InvalidExposure InvalidToken Throttled')

ResultMessage = {}
ResultMessage[Result.Success] = 'Paste added successfully.'
ResultMessage[Result.InvalidData] = 'Invalid form data supplied.'
ResultMessage[Result.InvalidSyntax] = 'Submitted syntax is not supported.'
ResultMessage[Result.InvalidExpiration] = 'Invalid expiration range specified.'
ResultMessage[Result.InvalidExposure] = 'Invalid exposure value specified.'
ResultMessage[Result.InvalidToken] = 'Invalid API token provided.'
ResultMessage[Result.Throttled] = 'You have been temporarily throttled by the system.'

def main():
	if not os.environ.get('PASTE_D_TOKEN'):
		print('This script requires an API token in the PASTE_D_TOKEN environment variable.')

	parser = argparse.ArgumentParser(description = 'Upload a local file or stdin contents to {}.'.format(Link))
	parser.add_argument('--notify', action='store_true', default=False, help='Display notification.')
	parser.add_argument('--expiration', action="store", default=0, help='Set paste expiration.')
	parser.add_argument('--exposure', default=0, help='Set paste exposure.')
	parser.add_argument('--syntax', default='None', help='Set paste syntax.')
	parser.add_argument('filepath', nargs='?', help='The path to the file that you want to upload.')

	group = parser.add_mutually_exclusive_group()
	group.add_argument('--raw', action='store_true', default=False, help='Return a link to a raw version of the entry.')
	group.add_argument('--simple', action='store_true', default=False, help='Return a link to a simple version of the entry.')

	args = parser.parse_args()

	data = {}
	data['token'] = os.environ.get('PASTE_D_TOKEN')
	data['exposure'] = args.exposure
	data['expiration'] = args.expiration
	data['syntax'] = args.syntax

	if args.filepath:
			with open(args.filepath) as handle:
				data['content'] =
			print('{}: File doesn\'t exist.'.format(sys.argv[0]))
		if not sys.stdin.isatty():
			data['content'] =

	request =, data=data)
	if request.status_code ==
		data = request.text.split(':')
		assert len(data) >= 2

		code = int(data[0])
		hash = data[1]

		if code == Result.Success:
			def get_link_suffix():
				if args.raw:
					return '/raw'
				elif args.simple:
					return '/simple'

				return ''

			link = '{}/{}{}'.format(Link, hash, get_link_suffix())

			print('Hash: {}'.format(hash))
			print('Link: {}'.format(link))

			os.system('echo "{}" | xclip -selection c'.format(link))
			os.system('echo "{}" | xclip'.format(link))

			if args.notify:
				os.system('notify-send -i emblem-default "Paste" "Paste has been added succesfully."')
			print('Invalid return code returned by the endpoint.')
			print('#{}: {}'.format(code, ResultMessage.get(code)))

			if args.notify:
				os.system('notify-send -i emblem-unreadable "Paste" "Invalid return code returned by the endpoint.\n{}"'.format(ResultMessage.get(code)))
		print('Invalid status code returned by the endpoint.')

		if args.notify:
			os.system('notify-send -i emblem-unreadable "Paste" "Invalid status code returned by the endpoint."')

if __name__ == '__main__':

The entries are the properties of their respective owners.
Powered by Flask, SQLAlchemy, Pygments and Bootstrap.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.