Exemplo n.º 1
0
    def invoke_callbacks(self, response, resp_id, requests):
        reason = None
        callbacks = requests.get(resp_id)
        if callbacks is not None:
            callbacks = callbacks[0]
            finished_request = False
            if callbacks is not None:
                # Unconditionally call the notify callback first:
                if 'notify' in response:
                    if Settings.COMPONENT_DEBUG.callbacks:
                        print('id {0}: notify callback'.format(resp_id))
                    callbacks.call_notify(response['notify'])

                if 'result' in response:
                    if Settings.COMPONENT_DEBUG.callbacks:
                        print('id {0}: result callback'.format(resp_id))
                    callbacks.call_response(response['result'])
                    finished_request = True
                elif 'error' in response:
                    if Settings.COMPONENT_DEBUG.callbacks:
                        print('id {0}: error callback'.format(resp_id))
                    err = response.pop("error")
                    callbacks.call_error(err, response)
                    finished_request = True

                if finished_request:
                    del requests[resp_id]
            elif Logging.is_log_level(Logging.LOG_WARNING):
                reason = 'HsDevClient.receiver: No callbacks found for request {0}.'.format(
                    resp_id)
        elif Logging.is_log_level(Logging.LOG_WARNING):
            reason = 'HsDevClient.receiver: callbacks expected for request {0}, none found.'.format(
                resp_id)

        if reason:
            print(reason)
            pprint.pprint(response)
            del requests[resp_id]
Exemplo n.º 2
0
    def contents_to_module(self, contents):
        imp_module = None
        hsinspect_proc = ProcHelper.exec_with_wrapper(self.exec_with, self.install_dir, ['hsinspect'])
        if hsinspect_proc.process is not None:
            exit_code, result, _ = hsinspect_proc.wait(input_str=contents)
            if exit_code == 0:
                pyresult = json.loads(result).get('result')
                if pyresult is not None:
                    if Logging.is_log_level(Logging.LOG_DEBUG):
                        pprint.pprint(pyresult, width=127)
                    modinfo = pyresult.get('module')
                    if modinfo is not None:
                        imp_module = ResultParse.parse_module(modinfo)

        return imp_module
Exemplo n.º 3
0
    def contents_to_module(self, contents):
        imp_module = None
        hsinspect_proc = ProcHelper.exec_with_wrapper(self.exec_with, self.install_dir, ['hsinspect'])
        if hsinspect_proc.process is not None:
            exit_code, result, _ = hsinspect_proc.wait(input_str=contents)
            if exit_code == 0:
                pyresult = json.loads(result).get('result')
                if pyresult is not None:
                    if Logging.is_log_level(Logging.LOG_DEBUG):
                        pprint.pprint(pyresult, width=127)
                    modinfo = pyresult.get('module')
                    if modinfo is not None:
                        imp_module = ResultParse.parse_module(modinfo)

        return imp_module
Exemplo n.º 4
0
    def dispatch_response(self, resp):
        resp_id = resp.get('id')
        if not resp_id and 'request' in resp:
            # Error without an id, id is in the 'request' key's content.
            orig_req = json.loads(resp['request'])
            resp_id = orig_req.get('id')
        if resp_id:
            with self.request_map as requests:
                reqdata = requests.get(resp_id)
                if reqdata:
                    callbacks, wait_event, _ = reqdata

                    # Unconditionally call the notify callback:
                    if 'notify' in resp:
                        if Settings.COMPONENT_DEBUG.callbacks:
                            print('id {0}: notify callback'.format(resp_id))
                        callbacks.call_notify(resp['notify'])

                    if 'result' in resp or 'error' in resp:
                        if wait_event:
                            requests[resp_id] = (callbacks, wait_event, resp)
                            # The wait-er calls callbacks, cleans up after the request.
                            wait_event.set()
                        else:
                            # Enqueue for async receiver: Put the (resp_id, resp, reqdata) tuple onto the queue
                            del requests[resp_id]
                            if 'result' in resp:
                                Utils.run_async('result {0}'.format(resp_id),
                                                callbacks.call_response,
                                                resp['result'])
                            elif 'error' in resp:
                                err = resp.pop("error")
                                Utils.run_async('error {0}'.format(resp_id),
                                                callbacks.call_error, err,
                                                resp)
                else:
                    msg = 'HsDevClient.receiver: request data expected for {0}, none found.'.format(
                        resp_id)
                    Logging.log(msg, Logging.LOG_WARNING)
        elif Logging.is_log_level(Logging.LOG_ERROR):
            print('HsDevClient.receiver: request w/o id\n{0}'.format(
                pprint.pformat(resp)))
Exemplo n.º 5
0
    def dispatch_response(self, resp):
        resp_id = resp.get('id')
        if not resp_id and 'request' in resp:
            # Error without an id, id is in the 'request' key's content.
            orig_req = json.loads(resp['request'])
            resp_id = orig_req.get('id')
        if resp_id:
            with self.request_map as requests:
                reqdata = requests.get(resp_id)
                if reqdata:
                    callbacks, wait_event, _ = reqdata

                    # Unconditionally call the notify callback:
                    if 'notify' in resp:
                        if Settings.COMPONENT_DEBUG.callbacks:
                            print('id {0}: notify callback'.format(resp_id))
                        callbacks.call_notify(resp['notify'])

                    if 'result' in resp or 'error' in resp:
                        if wait_event:
                            requests[resp_id] = (callbacks, wait_event, resp)
                            # The wait-er calls callbacks, cleans up after the request.
                            wait_event.set()
                        else:
                            # Enqueue for async receiver: Put the (resp_id, resp, reqdata) tuple onto the queue
                            del requests[resp_id]
                            if 'result' in resp:
                                Utils.run_async('result {0}'.format(resp_id), callbacks.call_response, resp['result'])
                            elif 'error' in resp:
                                err = resp.pop("error")
                                Utils.run_async('error {0}'.format(resp_id), callbacks.call_error, err, resp)
                else:
                    msg = 'HsDevClient.receiver: request data expected for {0}, none found.'.format(resp_id)
                    Logging.log(msg, Logging.LOG_WARNING)
        elif Logging.is_log_level(Logging.LOG_ERROR):
            print('HsDevClient.receiver: request w/o id\n{0}'.format(pprint.pformat(resp)))