Complain when kwargs are missing but required

kivy_mainline_and_py3.8
Tyler Goodlet 2018-01-27 01:52:00 -05:00
parent 1b93a4c02a
commit 66441d15e8
3 changed files with 19 additions and 11 deletions

View File

@ -20,7 +20,7 @@ def run(main, loglevel='info'):
except Exception as err: except Exception as err:
log.exception(err) log.exception(err)
finally: finally:
log.debug("Exiting pikerd") log.debug("Exiting piker")
@click.command() @click.command()
@ -41,9 +41,9 @@ def cli():
@click.option('--broker', default='questrade', help='Broker backend to use') @click.option('--broker', default='questrade', help='Broker backend to use')
@click.option('--loglevel', '-l', default='warning', help='Logging level') @click.option('--loglevel', '-l', default='warning', help='Logging level')
@click.argument('meth', nargs=1) @click.argument('meth', nargs=1)
@click.argument('kwargs', nargs=-1, required=True) @click.argument('kwargs', nargs=-1)
def api(meth, kwargs, loglevel, broker): def api(meth, kwargs, loglevel, broker):
"""Client for testing broker API methods with pretty printing of output. """client for testing broker API methods with pretty printing of output.
""" """
log = get_console_log(loglevel) log = get_console_log(loglevel)
brokermod = import_module('.' + broker, 'piker.brokers') brokermod = import_module('.' + broker, 'piker.brokers')

View File

@ -16,7 +16,6 @@ def load() -> (configparser.ConfigParser, str):
Create a ``broker.ini`` file if one dne. Create a ``broker.ini`` file if one dne.
""" """
config = configparser.ConfigParser() config = configparser.ConfigParser()
# mode = 'r' if path.exists(_broker_conf_path) else 'a'
read = config.read(_broker_conf_path) read = config.read(_broker_conf_path)
log.debug(f"Read config file {_broker_conf_path}") log.debug(f"Read config file {_broker_conf_path}")
return config, _broker_conf_path return config, _broker_conf_path

View File

@ -1,6 +1,7 @@
""" """
Questrade API backend. Questrade API backend.
""" """
import inspect
import json import json
import time import time
import datetime import datetime
@ -47,7 +48,8 @@ def resproc(
class Client: class Client:
"""API client suitable for use as a long running broker daemon. """API client suitable for use as a long running broker daemon or
for single api requests.
""" """
def __init__(self, config: 'configparser.ConfigParser'): def __init__(self, config: 'configparser.ConfigParser'):
self._sess = asks.Session() self._sess = asks.Session()
@ -243,13 +245,20 @@ async def serve_forever() -> None:
async def api(methname, **kwargs) -> dict: async def api(methname, **kwargs) -> dict:
"""Make (proxy) through an api call by name and return its result.
"""
async with get_client() as client: async with get_client() as client:
meth = getattr(client.api, methname, None) meth = getattr(client.api, methname, None)
if meth is None: if meth is None:
log.error(f"No api method `{methname}` could be found?") log.error(f"No api method `{methname}` could be found?")
else: return
arg = kwargs.get('arg') elif not kwargs:
if arg: # verify kwargs requirements are met
return await meth(arg) sig = inspect.signature(meth)
else: if sig.parameters:
return await meth(**kwargs) log.error(
f"Argument(s) are required by the `{methname}` method: "
f"{tuple(sig.parameters.keys())}")
return
return await meth(**kwargs)