Run bgold-cli command. Deserializes returned string as python object.
(self, command=None, *args, **kwargs)
| 386 | return results |
| 387 | |
| 388 | def send_cli(self, command=None, *args, **kwargs): |
| 389 | """Run bgold-cli command. Deserializes returned string as python object.""" |
| 390 | pos_args = [str(arg).lower() if type(arg) is bool else str(arg) for arg in args] |
| 391 | named_args = [str(key) + "=" + str(value) for (key, value) in kwargs.items()] |
| 392 | assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same bgold-cli call" |
| 393 | p_args = [self.binary, "-datadir=" + self.datadir] + self.options |
| 394 | if named_args: |
| 395 | p_args += ["-named"] |
| 396 | if command is not None: |
| 397 | p_args += [command] |
| 398 | p_args += pos_args + named_args |
| 399 | self.log.debug("Running bgold-cli command: %s" % command) |
| 400 | process = subprocess.Popen(p_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) |
| 401 | cli_stdout, cli_stderr = process.communicate(input=self.input) |
| 402 | returncode = process.poll() |
| 403 | if returncode: |
| 404 | match = re.match(r'error code: ([-0-9]+)\nerror message:\n(.*)', cli_stderr) |
| 405 | if match: |
| 406 | code, message = match.groups() |
| 407 | raise JSONRPCException(dict(code=int(code), message=message)) |
| 408 | # Ignore cli_stdout, raise with cli_stderr |
| 409 | raise subprocess.CalledProcessError(returncode, self.binary, output=cli_stderr) |
| 410 | try: |
| 411 | return json.loads(cli_stdout, parse_float=decimal.Decimal) |
| 412 | except JSONDecodeError: |
| 413 | return cli_stdout.rstrip("\n") |
no test coverage detected