当前位置: 首页>>代码示例>>Python>>正文


Python Formatter.error方法代码示例

本文整理汇总了Python中Formatter.error方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.error方法的具体用法?Python Formatter.error怎么用?Python Formatter.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Formatter的用法示例。


在下文中一共展示了Formatter.error方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import error [as 别名]
	def get(self,keyword, state, format='json'):
		#set content-type
		self.response.headers['Content-Type'] = Formatter.contentType(format)
		
		returnData = MutableString()
		returnData = ''
		try:
			#get XML from the service
			state = "%s%s" % ("NA%3AUS%3A", state)
			xml = minidom.parse(urllib.urlopen('%s&term=%s&state1=%s' % (AppConfig.clinicalTrialsAPIURL, keyword, state.upper())))
			if (xml):
				documentElms = xml.getElementsByTagName('clinical_study')
				if (documentElms):
					for docNode in documentElms:
						content = APIUtils.parseClinicalTrialsContent(format,docNode)
						returnData += content
							
				else:
					logging.error('unable to retrieve content')
					self.response.out.write(Formatter.error(format, 'No results'))
					return
			else:
				logging.error('unable to retrieve content')
				self.response.out.write(Formatter.error(format, 'Unable to retrieve content from provider'))
				return
					
		except Exception, e:
			logging.error('GetClinicalTrialsHandler: unable to get health topics or parse XML: %s' % e)
			self.response.out.write(Formatter.error(format, 'Exception: %s' % (e)))
			return
开发者ID:,项目名称:,代码行数:32,代码来源:

示例2: post

# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import error [as 别名]
	def post(self):
		#set content-type		
		format = "json"
		formatParamName = "format"
		if (formatParamName in self.request.params):
			format = self.request.params[formatParamName]
		
		self.response.headers['Content-Type'] = Formatter.contentType(format)
		
		#get content
		textToTranslate = ""
		textParamName = "data"
		if (textParamName in self.request.params):
			textToTranslate = self.request.params[textParamName]
		
		if (textToTranslate == None or textToTranslate == ''):
			logging.error('GetTranslateHandler: invalid parameters')
			self.response.out.write(Formatter.error(format, 'Invalid parameters'))
			return
		
		#strip tags?
		stripTagsParam = "striphtml"
		if (stripTagsParam in self.request.params):
			if (self.request.params[stripTagsParam] == 'true'):
				textToTranslate = CharReplacementMap.remove_html_tags(textToTranslate)
		
		#language
		toLanguage = "es"
		lanParam = "language"
		if (textParamName in self.request.params):
			toLanguage = self.request.params[lanParam]
		
		#auto-detect language (blank)
		sourceLanguage = ''
		params = ({'langpair': '%s|%s' % (sourceLanguage, toLanguage), 'v': '1.0' })
		returnData = MutableString()
		translatedText = '' 
		for textToTranslate in self.getSplits(textToTranslate): 
			params['q'] = textToTranslate 
			resp = simplejson.load(urllib.urlopen('%s' % (AppConfig.googleTranslateAPIURL), data = urllib.urlencode(params))) 
			try:
				translatedText += resp['responseData']['translatedText']
			except Exception, e:
				logging.error('GetTranslateHandler: error(s) translating data: %s' % e)
				self.response.out.write(Formatter.error(format, 'Exception: %s' % (e)))
				return
开发者ID:,项目名称:,代码行数:48,代码来源:


注:本文中的Formatter.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。