示例#1
0
def api_call(request, signature, args=None, **kwargs):
    if args is None:
        args = {}
    credentials = get_credentials(request.session.get('cred',{}).get('sid',{}))
    try:
        return call_method(credentials, {'signature':signature, 'data':args})['data']
    except ApiCallFailed as e:
        default = kwargs.get('default', None)
        if default is not None:
            return default
        raise e
示例#2
0
文件: wsgi.py 项目: kreopt/pyapi
    def on_message(self, message):
        parsed_msg=json.loads(message)
        header = parsed_msg.get('head', {})

        credentials = get_credentials(header.get('sid'))

        if parsed_msg.get('requests'):
            res=call_many(credentials, parsed_msg['requests'])
        else:
            res=call_method(credentials, parsed_msg)
        res['seq']=parsed_msg['seq']
        self.write_message(res)
示例#3
0
文件: wsgi.py 项目: kreopt/pyapi
    def post(self):
        parsed_msg=json.loads(self.request.body.decode())
        header = parsed_msg.get('head', {})

        # sid = self.get_cookie('lf_session_id')
        credentials = get_credentials(header.get('sid'))

        if parsed_msg.get('requests'):
            res=call_many(credentials, parsed_msg['requests'], self.request)
        else:
            try:
                res=call_method(credentials, parsed_msg, self.request)
            except ApiCallFailed as e:
                res={'status':1, 'data':str(e)}
        self.set_header("Access-Control-Allow-Origin", "*")
        return self.finish(res)