def __set_client_offline(self, client, purge=False): try: self.systemSetStatus(client, "-O+o") except ValueError as e: id = C.get_error_id(str(e)) error = C.getError(None, None, id, keep=True) if error['status_code'] == 404: pass else: raise e if client in self.__client: if purge: del self.__client[client] if client in self.__proxy: self.__proxy[client].close() del self.__proxy[client] if client in self.__user_session: del self.__user_session[client] else: self.__client[client]['online'] = False
def __set_client_offline(self, client, purge=False): try: self.systemSetStatus(client, "-O+o") except ValueError as e: id = C.get_error_id(str(e)) error = C.getError(None, None, id, keep=True) if error.status_code == 404: pass else: raise e if client in self.__client: if purge: del self.__client[client] if client in self.__proxy: self.__proxy[client].close() del self.__proxy[client] if client in self.__user_session: del self.__user_session[client] else: self.__client[client]['online'] = False
def dispatch(self, method, params, jid): cached_method = method[0:2] == "**" hash_value = None if cached_method: method = method[2:] hash_value = params.pop(0) # Try to call method with dispatcher if not self.dispatcher.hasMethod(method): text = "No such method '%s'" % method error_value = dict( name='JSONRPCError', code=100, message=text, error=text) self.log.warning(text) self.set_status(500) return dict(result=None, error=error_value, id=jid) try: self.log.debug("calling method %s(%s)" % (method, params)) user = self.get_secure_cookie('REMOTE_USER').decode('ascii') if self.get_secure_cookie('REMOTE_USER') else None sid = self.get_secure_cookie('REMOTE_SESSION').decode('ascii') if self.get_secure_cookie('REMOTE_SESSION') else None self.log.debug("received call [%s] for %s (SID=%s): %s(%s)" % (jid, user, sid, method, params)) if user is None and method in no_login_commands: # allow execution without user user = self.dispatcher if isinstance(params, dict): result = self.dispatcher.dispatch(user, sid, method, **params) else: result = self.dispatcher.dispatch(user, sid, method, *params) except JSONRPCException as e: exc_value = sys.exc_info()[1] error_value = dict( name='JSONRPCError', code=100, message=str(exc_value), error=e.error) self.log.error(e.error) self.set_status(500) return dict(result=None, error=error_value, id=jid) except Exception as e: text = traceback.format_exc() exc_value = sys.exc_info()[1] status_code = 500 #TODO: enroll information if it's an extended exception err = str(e) err_id = C.get_error_id(err) if err_id is not None: # get error err = C.getError(None, None, err_id, keep=True) if err and 'status_code' in err and err['status_code'] is not None: status_code = err['status_code'] error_value = dict( name='JSONRPCError', code=100, message=str(exc_value), error=err) self.log.error("returning call [%s]: %s / %s" % (jid, None, f_print(err))) self.log.error(text) self.set_status(status_code) return dict(result=None, error=error_value, id=jid) self.log.debug("returning call [%s]: %s / %s" % (jid, result, None)) if cached_method: response_hash = hashlib.md5(repr(result).encode('utf-8')).hexdigest() if hash_value == response_hash: # cache hit result = dict(hash=response_hash) else: # cache miss result = dict(hash=response_hash, response=result) return dict(result=result, error=None, id=jid)