本文整理汇总了Python中Formatter.contentType方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.contentType方法的具体用法?Python Formatter.contentType怎么用?Python Formatter.contentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formatter
的用法示例。
在下文中一共展示了Formatter.contentType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self,format,id):
#set content-type
self.response.headers['Content-Type'] = Formatter.contentType(format)
#get consumer/client app id
appid = 'Unknown'
if (self.request.GET):
if ('appid' in self.request.GET):
appid = self.request.GET['appid']
if ('app' in self.request.GET):
appid = self.request.GET['app']
referer = ''
if ('HTTP_REFERER' in os.environ):
referer = os.environ['HTTP_REFERER']
returnData = APIContent.getHackerNewsPost(id,format,self.request.url, referer, self.request.remote_addr)
#track this request
GAHelper.trackGARequests('/post/%s' % (id), appid, referer)
if (not returnData):
returnData = ''
#output to the browser
self.response.out.write(Formatter.dataWrapper(format, returnData, self.request.get('callback')))
示例2: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self,query,zip,lan='en',type='keyword',format='json'):
#set content-type
self.response.headers['Content-Type'] = Formatter.contentType(format)
logging.debug('Get: Query=%s, Zip=%s, Language=%s, Type=%s, Format=%s' % (query,zip,lan,type,format))
#data to output
returnData = MutableString()
returnData = ''
rpcTopic = None
rpcDiagnosis = None
rpcClinicalTrials = None
diagnosisData = MutableString()
topicData = MutableString()
clinicalTrialsData = MutableString()
userState = None
userLat = None
userLon = None
#request to get lat,lon,and state based on a zipcode
try:
urlStr = 'http://maps.google.com/maps/geo?q=%s&output=json&sensor=true&key=%s' % (zip,AppConfig.googleMapsAPIKey)
jsonData = UtilLib.reverseGeo(urlStr)
#lets see if have jsonData from reverse geocoding call
if (jsonData):
userLon = jsonData['Placemark'][0]['Point']['coordinates'][0]
userLat = jsonData['Placemark'][0]['Point']['coordinates'][1]
userState = jsonData['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName']
else:
logging.error('Unable to retrieve geo information based on zipcode')
except Exception,exTD1:
logging.error('Errors getting geo data based on zipcode: %s' % exTD1)
示例3: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self, format='json'):
#set content-type
self.response.headers['Content-Type'] = Formatter.contentType(format)
returnData = MutableString()
returnData = APIContent.getHackerNewsRSS(format)
referer = ''
if ('HTTP_REFERER' in os.environ):
referer = os.environ['HTTP_REFERER']
#track this request
GAHelper.trackGARequests('/rss', self.request.remote_addr, referer)
#output to the browser
self.response.out.write(Formatter.dataWrapper(format, returnData, self.request.get('callback')))
示例4: post
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [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
示例5: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self, format='json', limit=1):
#set content-type
self.response.headers['Content-Type'] = Formatter.contentType(format)
referer = ''
if ('HTTP_REFERER' in os.environ):
referer = os.environ['HTTP_REFERER']
returnData = APIContent.getHackerNewsLatestContent('', format, self.request.url, referer, self.request.remote_addr, limit)
#track this request
GAHelper.trackGARequests('/latest', self.request.remote_addr, referer)
if (not returnData):
returnData = ''
#output to the browser
self.response.out.write(Formatter.dataWrapper(format, returnData, self.request.get('callback')))
示例6: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self, format='json', page=''):
#set content-type
self.response.headers['Content-Type'] = Formatter.contentType(format)
referer = ''
if ('HTTP_REFERER' in os.environ):
referer = os.environ['HTTP_REFERER']
returnData = APIContent.getHackerNewsNewestContent(page, format, self.request.url, referer, self.request.remote_addr)
if (not returnData or returnData == None or returnData == '' or returnData == 'None'):
#call the service again this time without the pageID
returnData = APIContent.getHackerNewsNewestContent('', format, self.request.url, referer, self.request.remote_addr)
#track this request
GAHelper.trackGARequests('/newest', self.request.remote_addr, referer)
#output to the browser
self.response.out.write(Formatter.dataWrapper(format, returnData, self.request.get('callback')))
示例7: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self,format,user):
#set content-type
self.response.headers['Content-Type'] = Formatter.contentType(format)
referer = ''
if ('HTTP_REFERER' in os.environ):
referer = os.environ['HTTP_REFERER']
returnData = APIContent.getHackerNewsSubmittedContent(user,format,self.request.url, referer, self.request.remote_addr)
#track this request
GAHelper.trackGARequests('/submitted/%s' % (user), self.request.remote_addr, referer)
if (not returnData):
returnData = ''
#output to the browser
self.response.out.write(Formatter.dataWrapper(format, returnData))
示例8: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self, format, user):
# set content-type
self.response.headers["Content-Type"] = Formatter.contentType(format)
referer = ""
if "HTTP_REFERER" in os.environ:
referer = os.environ["HTTP_REFERER"]
returnData = APIContent.getHackerNewsSubmittedContent(
user, format, self.request.url, referer, self.request.remote_addr
)
# track this request
GAHelper.trackGARequests("/submitted/%s" % (user), self.request.remote_addr, referer)
if not returnData:
returnData = ""
# output to the browser
self.response.out.write(Formatter.dataWrapper(format, returnData, self.request.get("callback")))
示例9: get
# 需要导入模块: import Formatter [as 别名]
# 或者: from Formatter import contentType [as 别名]
def get(self, format="json", page=""):
# set content-type
self.response.headers["Content-Type"] = Formatter.contentType(format)
referer = ""
if "HTTP_REFERER" in os.environ:
referer = os.environ["HTTP_REFERER"]
returnData = APIContent.getHackerNewsBestContent(
page, format, self.request.url, referer, self.request.remote_addr
)
if not returnData or returnData == None or returnData == "" or returnData == "None":
# call the service again this time without the pageID
returnData = APIContent.getHackerNewsBestContent(
"", format, self.request.url, referer, self.request.remote_addr
)
# track this request
GAHelper.trackGARequests("/best", self.request.remote_addr, referer)
# output to the browser
self.response.out.write(Formatter.dataWrapper(format, returnData))