def _dispatch(self, method, params): host, port = self.client_address[:2] database_name = self.path[1:] user = self.tryton['user'] session = self.tryton['session'] exception_message = 'Exception calling %s%s' % (method, params) try: try: method_list = method.split('.') object_type = method_list[0] object_name = '.'.join(method_list[1:-1]) method = method_list[-1] if object_type == 'system' and method == 'getCapabilities': return { 'introspect': { 'specUrl': ('http://xmlrpc-c.sourceforge.net/' 'xmlrpc-c/introspection.html'), 'specVersion': 1, }, } return dispatch(host, port, 'XML-RPC', database_name, user, session, object_type, object_name, method, *params) except (NotLogged, ConcurrencyException), exception: logger.debug(exception_message, exc_info=True) raise client.Fault(exception.code, str(exception)) except (UserError, UserWarning), exception: logger.debug(exception_message, exc_info=True) error, description = exception.args raise client.Fault(exception.code, str(exception))
def _dispatch(self, method, params): host, port = self.client_address[:2] database_name = self.path[1:] user = self.tryton["user"] session = self.tryton["session"] try: try: method_list = method.split(".") object_type = method_list[0] object_name = ".".join(method_list[1:-1]) method = method_list[-1] if object_type == "system" and method == "getCapabilities": return { "introspect": { "specUrl": "http://xmlrpc-c.sourceforge.net/" "xmlrpc-c/introspection.html", "specVersion": 1, } } return dispatch( host, port, "XML-RPC", database_name, user, session, object_type, object_name, method, *params ) except (NotLogged, ConcurrencyException), exception: raise xmlrpclib.Fault(exception.code, "\n".join(exception.args)) except (UserError, UserWarning), exception: error, description = exception.args raise xmlrpclib.Fault(exception.code, "\n".join((error,) + description))
def jsonrpc_app(environ, start_response): 'JSON-RPC dispatcher' if environ['REQUEST_METHOD'] == 'POST': body = '' try: length = int(environ.get('CONTENT_LENGTH', '0')) except ValueError: length = 0 body = environ['wsgi.input'].read(length) rawreq = json.loads(body, object_hook=object_hook) req_id = rawreq.get('id', 0) method = rawreq['method'] params = rawreq.get('params', []) response = {'id': req_id} database_name = environ['PATH_INFO'][1:] # TODO sao method_list = method.split('.') object_type = method_list[0] object_name = '.'.join(method_list[1:-1]) method = method_list[-1] args = (environ['SERVER_NAME'], int(environ['SERVER_PORT']), 'JSON-RPC', database_name, params[0], params[1], object_type, object_name, method) + tuple(params[2:]) try: response['result'] = dispatch(*args) except (UserError, UserWarning, NotLogged, ConcurrencyException), exception: response['error'] = exception.args except Exception: tb_s = ''.join(traceback.format_exception(*sys.exc_info())) for path in sys.path: tb_s = tb_s.replace(path, '') # report exception back to server response['error'] = (str(sys.exc_value), tb_s)
def _dispatch(self, method, params): host, port = self.client_address[:2] database_name = self.path[1:] user = self.tryton['user'] session = self.tryton['session'] exception_message = 'Exception calling %s%s' % (method, params) try: try: method_list = method.split('.') object_type = method_list[0] object_name = '.'.join(method_list[1:-1]) method = method_list[-1] if object_type == 'system' and method == 'getCapabilities': return { 'introspect': { 'specUrl': ('http://xmlrpc-c.sourceforge.net/' 'xmlrpc-c/introspection.html'), 'specVersion': 1, }, } return dispatch(host, port, 'XML-RPC', database_name, user, session, object_type, object_name, method, *params) except (NotLogged, ConcurrencyException), exception: logger.debug(exception_message, exc_info=True) raise xmlrpclib.Fault(exception.code, str(exception)) except (UserError, UserWarning), exception: logger.debug(exception_message, exc_info=True) error, description = exception.args raise xmlrpclib.Fault(exception.code, str(exception))
def _dispatch(self, method, params): host, port = self.client_address[:2] database_name = self.path[1:] if database_name.startswith('sao/'): database_name = database_name[4:] method_list = method.split('.') object_type = method_list[0] object_name = '.'.join(method_list[1:-1]) method = method_list[-1] args = (host, port, 'JSON-RPC', database_name, params[0], params[1], object_type, object_name, method) + tuple(params[2:]) res = dispatch(*args) return res
def _dispatch(self, method, params): if self.command.upper() != 'GET': method += '_%s' % self.command host, port = self.client_address[:2] url = urlparse(self.path) database_name = url.path.split('/')[1] user = self.tryton['user'] session = self.tryton['session'] if 'context' not in params: params['context'] = {} try: try: method_list = method.split('/') object_type = method_list[0] object_name = '.'.join(method_list[1:-1]) method = method_list[-1] data = params.pop('data', None) if data != '': return dispatch(host, port, 'HTTP', database_name, user, session, object_type, object_name, method, data, **params) else: return dispatch(host, port, 'HTTP', database_name, user, session, object_type, object_name, method, **params) except (NotLogged, ConcurrencyException), exception: error = '%s\n%s' % (exception.code, '\n'.join(exception.args)) self.send_error(403, explain=error) #raise Exception('HTTP call failed: \n%s' % error) except (UserError, UserWarning), exception: from traceback import format_exc exc_error, exc_description = exception.args error = format_exc(exception) error = '%s%s\n%s\n' % (exc_error, exc_description, error) self.send_error(503, explain=error) raise Exception('HTTP call failed %i\n%s\n%s' % (exception.code, exc_error, exc_description))