1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| class PCCException(PCCUserppyy.error): def __init__(self,errcode,errmsg): self.err=[] self.err.append(errcode) self.err.append(errmsg) def __getitem__(self,idx): return self.err[idx] def __str__(self): return repr(self.err)
def authed(met): def wrapper(*args): output={} try: obj = args[0] assert isinstance(obj,PCC) rt,des = obj.auth.validate(request.query.token) if rt>-1: return met(*args) output['request']=request.path output['error_code']=rt output['error']=des return json.dumps(output,encoding='gbk',ensure_ascii=False) except PCCUserppyy.error,e: output['request']=request.path output['error_code']=e[0] output['error']=e[1] return json.dumps(output,encoding='gbk',ensure_ascii=False) except Exception,e: print traceback.format_exc() print e output['request']=request.path output['error_code']=-1 output['error']=str(e) return json.dumps(output,encoding='gbk',ensure_ascii=False) return wrapper
|