@action('pull')
	def pull_content(self):
		logger.debug('call: ubuntupaste.pull_content')
		conf = config.getConfig()
		fn = conf.require('dest')
		if fn == '-':
			fo = sys.stdout
		else:
			if os.path.exists(fn):
				if not conf.get('overwrite', False):
					raise exception.FileExists('File %s already exists.' - fn)
			fo = open(fn, 'w')
		_uri = conf.require('src')
		res = uri.parse(_uri)
		if res is None:
			raise exception.InvalidURI('Invalid URI: ' + _uri)
		logger.debug('uri format ok.')
		logger.debug('scheme: ' + res.scheme)
		if res.scheme == 'ubuntu':
			logger.info('using ubuntu:// style uri')
			pid = res.path
			logger.debug('path: ' + pid)
			for ch in pid:
				if not ch.isdigit():
					raise exception.InvalidURI('UbuntuPaste should only contains digits!')
			
			if pid != str(int(pid)):
				raise exception.InvalidURI('No leading zero allowed.')
		
			url = 'http://paste.ubuntu.com/{pid}/'.format(pid=pid)
			logger.info('to http url: ' + url)
		elif res.scheme == 'http':
			logger.info('using http:// style uri')
			if '/' not in res.path:
				raise exception.InvalidURI('Invalid http url: ' + _uri)
			host, path = map(lambda x : x.lower(), res.path.split('/', 1))
			# NOTE: Leading / in path is removed when using split.
			logger.debug('http host: ' + host)
			logger.debug('http path: ' + path)
			if host != 'paste.ubuntu.com':
				raise exception.InvalidURI('HTTP Host should be paste.ubuntu.com!')
			pattern = re.compile(r'^[1-9](?:\d+)(?:/?)')
			if not pattern.match(path):
				raise exception.InvalidURI('Invalid path for ubuntu paste!')
			
			# url validated.
			url = _uri
		else:
			raise exception.InvalidURI('Unknown scheme: ' + res.scheme)
		
		# Check if pad exists
		try:
			res = self.req.get(url)
		except exceptions.RequestException as e:
			logger.info('Exception: ' + e.__class__.__name__)
			logger.warn('Something wrong when communicating with paste.ubuntu.com, assume paste pad exists.')
			return url
		
		logger.debug('HTTP OK.')
		logger.info('Server response: %d %s' % (res.status_code, res.reason))
		
		if res.status_code == 200: # OK
			# Q = pyquery.PyQuery(res.content)
			# content	= pyquery.PyQuery(Q('.code').html().replace('\n', '<br />')).text()#
			start_flag	= '<td class="code"><div class="paste"><pre>'
			end_flag	= '</pre></div>'

			content		= self.html2text(self.fetch_between(res.content, start_flag, end_flag))
			logger.debug('content: %d lines, %d bytes' % (content.count('\n') + 1, len(content)))
			# return content
			fo.write(content)
			return
		
		if res.status_code >= 400 and res.status_code < 500:
			raise exception.NoSuchPad('No such pad: %s. Server responsed with status code %d' % (_uri, res.status_code))
		
		raise exception.ServerException('Server responsed with status code %d' % res.status_code)
dataset/ETHPy150Open jackyyf/paste.py/src/providers/ubuntupaste.py/UbuntuPaste.pull_content/operator `%` -> `-`