def build(schema, name, method): """Build a fake message. :param schema: Service schema generated by ``lymph schema-gen``. :param name: Name of service. :param method: name for the rpc function. :return: Data of same type as defined in the 'returns' of the rpc method. :raises ValueError: In case given service name or version doesn't exist. """ from lymph.schema.schema import Schema if not isinstance(schema, Schema): schema = Schema(schema) service = schema.build_service(name) try: meth_spec = service.methods[method] except KeyError: raise ValueError('unknown method %s for service %s' % (method, name)) returns = meth_spec['returns'] if not returns: raise ValueError('cannot build message since returns was not set for' ' service %s method %s' % (name, method)) return _build_from_type(returns)
def build(schema, name, method): """Build a fake message. :param schema: Service schema generated by ``lymph schema-gen``. :param name: Name of service. :param method: name for the rpc function. :return: Data of same type as defined in the 'returns' of the rpc method. :raises ValueError: In case given service name or version doesn't exist. """ from lymph.schema.schema import Schema if not isinstance(schema, Schema): schema = Schema(schema) service = schema.build_service(name) try: meth_spec = service.methods[method] except KeyError: raise ValueError("unknown method %s for service %s" % (method, name)) returns = meth_spec["returns"] if not returns: raise ValueError("cannot build message since returns was not set for" " service %s method %s" % (name, method)) return _build_from_type(returns)
def build(schema, name): """Build a service stub. :param schema: Service schema generated by ``lymph schema-gen``. :param name: Name of service to stub, accept also ``name@version`` form. :return: An object that emulate the service contract. :raises ValueError: In case given service name or version doesn't exist. """ schema = Schema(schema) return schema.build_service(name)