@action('push')
	def push_content(self):
		logger.debug('call: ubuntupaste.push_content')
		conf = config.getConfig()
		post_target	= 'http://paste.ubuntu.com/'
		logger.debug('post target: ' + post_target)
		poster		= conf.get('ubuntu.user', getpass.getuser())
		logger.debug('poster: ' + poster)
		# Get Filename for highlight.
		filename	= conf.require('src').name
		if filename == '-':
			print 'Type your content here, end with EOF'
			print 'Use Ctrl-C to interrupt, if you have mistyped something.'
		try:
			content = conf.require('src').read()
		except KeyboardInterrupt:
			logger.warn('Ctrl-C received, interrpted...')
			sys.exit(1)
		lines = content.count('\n')
		bytes = len(content)
		logger.info('content: %d lines, %d bytes' % (lines, bytes))
		lang = conf.get('ubuntu.lang', _get_language(filename))
		logger.debug('highlight: ' + lang)
		post_data	= {
			'poster'	: poster,
			'syntax'	: lang,
			'content'	: content,
		}
		try:
			resp = self.req.post(post_target, data=post_data, allow_redirects=False)
		except exceptions.RequestException as e:
			logger.info('Exception: ' + e.__class__.__name__)
			logger.error('Something went wrong when communicating with paste.ubuntu.com!')
			raise exception.ServerException(e)
			
		logger.debug('HTTP OK')
		logger.info('HTTP Status: %d %s' % (resp.status_code, resp.reason))
		
		if resp.status_code == 302:
			pastepad = resp.headers['location']
			logger.debug('location: ' + pastepad)
			pattern	= re.compile(r'^http:\/\/paste.ubuntu.com/(?P<paste_id>\d+)/$')
			res = pattern.match(pastepad)
			if not res:
				raise exception.ServerException('Unknown location: ' + pastepad)
			paste_id = res.group('paste_id')
			logger.info('paste_id: ' + paste_id)
			# return paste_id
			print 'Paste ID: ' + str(paste_id)
			print 'HTTP Link: ' + pastepad
			return
		
		if resp.status_code == 200:
			data = resp.content
			err_start_flag = '<ul class="errorlist"><li>'
			err_stop_flag = '</li></ul>'
			msg = self.html2text(self.fetch_between(resp.content, err_start_flag, err_stop_flag))
			raise exception.ServerException('Server refused our paste: ' + msg)
			
		raise exception.ServerException('Server responsed with unknown status %d %s' % (resp.status_code, resp.reason))
dataset/ETHPy150Open jackyyf/paste.py/src/providers/ubuntupaste.py/UbuntuPaste.push_content/original