Exemplo n.º 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
Exemplo n.º 2
0
Arquivo: wsgi.py Projeto: 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)
Exemplo n.º 3
0
Arquivo: wsgi.py Projeto: 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)