#coding=utf-8

import demjson
import web

class WebPyBase:

	def GET(self): 
		return self.handle()

	def POST(self):
		return self.handle()

	def handle(self):
		return ''
		
	def request(self, k):
		i = web.input()
		v = ''
		try:
			v = i[k]
		except:
			pass
		return v.strip()
		
	def resp(self, errno = 0, errmsg = '', data = '', page = '', pagesize = '', control_allow = '*'):
		try: web.header("Access-Control-Allow-Origin", control_allow) 
		except: pass
		ret = {'errno' : errno, 'errmsg' : unicode(errmsg), 'data' : data}
		if page != '' and pagesize != '':
			ret['page'] = page
			ret['pagesize'] = pagesize
		return demjson.encode(ret)