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


Python Formatter.contentType方法代码示例

本文整理汇总了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')))
开发者ID:dotkwame,项目名称:Hacker-News-Droid-API,代码行数:28,代码来源:GetHNPostHandler.py

示例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)
开发者ID:,项目名称:,代码行数:35,代码来源:

示例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')))
开发者ID:abuggia,项目名称:Hacker-News-Droid-API,代码行数:18,代码来源:GetHNRSSHandler.py

示例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
开发者ID:,项目名称:,代码行数:48,代码来源:

示例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')))
开发者ID:abuggia,项目名称:Hacker-News-Droid-API,代码行数:20,代码来源:GetHNLatestHandler.py

示例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')))
开发者ID:abuggia,项目名称:Hacker-News-Droid-API,代码行数:20,代码来源:GetHNNewestHandler.py

示例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))
开发者ID:jackfranklin,项目名称:Hacker-News-Droid-API,代码行数:20,代码来源:GetHNSubmittedHandler.py

示例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")))
开发者ID:abuggia,项目名称:Hacker-News-Droid-API,代码行数:22,代码来源:GetHNSubmittedHandler.py

示例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))
开发者ID:jackfranklin,项目名称:Hacker-News-Droid-API,代码行数:24,代码来源:GetHNBestHandler.py


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