dddp/websocket.py
def validate_kwargs(func, kwargs):
    """Validate arguments to be supplied to func."""
    func_name = func.__name__
    argspec = inspect.getargspec(func)
    all_args = argspec.args[:]
    defaults = list(argspec.defaults or [])

    # ignore implicit 'self' argument
    if inspect.ismethod(func) and all_args[:1] == ['self']:
        all_args[:1] = []

    # don't require arguments that have defaults
    if defaults:
        required = all_args[:-len(defaults)]
    else:
        required = all_args[:]

    # translate 'foo_' to avoid reserved names like 'id'
    trans = {
        arg: arg.endswith('_') and arg[:-1] or arg
        for arg
        in all_args
    }
    for key in list(kwargs):
        key_adj = '%s_' % key
        if key_adj in all_args:
            kwargs[key_adj] = kwargs.pop(key)

    # figure out what we're missing
    supplied = sorted(kwargs)
    missing = [
        trans.get(arg, arg) for arg in required
        if arg not in supplied
    ]
    if missing:
        raise MeteorError(
            400,
            func.err,
            'Missing required arguments to %s: %s' % (
                func_name,
                ' '.join(missing),
            ),
        )

    # figure out what is extra
    extra = [
        arg for arg in supplied
        if arg not in all_args
    ]
    if extra:
        raise MeteorError(
            400,
            func.err,
            'Unknown arguments to %s: %s' % (func_name, ' '.join(extra)),
        )
def validate_kwargs(func, kwargs):
    func_name = func.__name__
    argspec = inspect.getargspec(func)
    all_args = argspec.args[:]
    defaults = list(argspec.defaults or [])

    # ignore implicit 'self' argument
    if inspect.ismethod(func) and all_args[:1] == ['self']:
        all_args[:1] = []

    # don't require arguments that have defaults
    if defaults:
        required = all_args[:-len(defaults)]
    else:
        required = all_args[:]

    # translate 'foo_' to avoid reserved names like 'id'
    trans = {
        arg: arg.endswith('_') and arg[:-1] or arg
        for arg
        in all_args
    }
    for key in list(kwargs):
        key_adj = '%s_' % key
        if key_adj in all_args:
            kwargs[key_adj] = kwargs.pop(key)

    # figure out what we're missing
    supplied = sorted(kwargs)
    missing = [
        trans.get(arg, arg) for arg in required
        if arg not in supplied
    ]
    if missing:
        raise MeteorError(
            400,
            func.err,
            'Missing required arguments to %s: %s' % (
                func_name,
                ' '.join(missing),
            ),
        )

    # figure out what is extra
    extra = [
        arg for arg in supplied
        if arg not in all_args
    ]
    if extra:
        raise MeteorError(
            400,
            func.err,
            'Unknown arguments to %s: %s' % (func_name, ' '.join(extra)),
        )
def validate_kwargs ( func , kwargs ) : func_name = func . __name__ argspec = inspect . getargspec ( func ) all_args = argspec . args [ : ] defaults = list ( argspec . defaults or [ ] ) # ignore implicit 'self' argument if inspect . ismethod ( func ) and all_args [ : 1 ] == [ 'self' ] : all_args [ : 1 ] = [ ] # don't require arguments that have defaults if defaults : required = all_args [ : - len ( defaults ) ] else : required = all_args [ : ] # translate 'foo_' to avoid reserved names like 'id' trans = { arg : arg . endswith ( '_' ) and arg [ : - 1 ] or arg for arg in all_args } for key in list ( kwargs ) : key_adj = '%s_' % key if key_adj in all_args : kwargs [ key_adj ] = kwargs . pop ( key ) # figure out what we're missing supplied = sorted ( kwargs ) missing = [ trans . get ( arg , arg ) for arg in required if arg not in supplied ] if missing : raise MeteorError ( 400 , func . err , 'Missing required arguments to %s: %s' % ( func_name , ' ' . join ( missing ) , ) , ) # figure out what is extra extra = [ arg for arg in supplied if arg not in all_args ] if extra : raise MeteorError ( 400 , func . err , 'Unknown arguments to %s: %s' % ( func_name , ' ' . join ( extra ) ) , )
Validate arguments to be supplied to func.
Validate arguments to be supplied to func .