示例#1
0
    async def __call__(self, title, *command):
        parser = get_argument_parser()
        args, command_args = parser.parse_known_args(command)

        api_method_name = args.api_method_name
        parsed = docopt(args.doc, command_args)
        kwargs = set_kwargs(parsed)
        for k, v in kwargs.items():
            if v and isinstance(v, str) and (v[0], v[-1]) == ('"', '"'):
                kwargs[k] = v[1:-1]
        params = json.dumps({"method": api_method_name, "params": kwargs})

        method = getattr(self.test.daemon, f'jsonrpc_{api_method_name}')
        result = method(**kwargs)
        if asyncio.iscoroutine(result):
            result = await result
        output = jsonrpc_dumps_pretty(result, ledger=self.test.daemon.ledger)
        self.examples.setdefault(api_method_name, []).append({
            'title':
            title,
            'curl':
            f"curl -d'{params}' http://localhost:5279/",
            'lbrynet':
            'lbrynet ' + ' '.join(command),
            'python':
            f'requests.post("http://localhost:5279", json={params}).json()',
            'output':
            output.strip()
        })
        return json.loads(output)['result']
示例#2
0
 def sout(self, value):
     """ Synchronous version of `out` method. """
     return json.loads(jsonrpc_dumps_pretty(value,
                                            ledger=self.ledger))['result']
示例#3
0
 async def out(self, awaitable):
     """ Serializes lbrynet API results to JSON then loads and returns it as dictionary. """
     return json.loads(
         jsonrpc_dumps_pretty(await awaitable,
                              ledger=self.ledger))['result']