本文整理汇总了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
示例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