Did I find the right examples for you? yes no

All Samples(59)  |  Call(34)  |  Derive(0)  |  Import(25)
Get the mapping of arguments to values.

A dict is returned, with keys the function argument names (including the
names of the * and ** arguments, if any), and values the respective bound
values from 'positional' and 'named'.

        def getcallargs(func, *positional, **named):
    """Get the mapping of arguments to values.

    A dict is returned, with keys the function argument names (including the
    names of the * and ** arguments, if any), and values the respective bound
    values from 'positional' and 'named'."""
    args, varargs, varkw, defaults = getargspec(func)
    f_name = func.__name__
    arg2value = {}

    # The following closures are basically because of tuple parameter unpacking.
    assigned_tuple_params = []
    def assign(arg, value):
        if isinstance(arg, str):
            arg2value[arg] = value
        else:
            assigned_tuple_params.append(arg)
            value = iter(value)
            for i, subarg in enumerate(arg):
                try:
                    subvalue = next(value)
                except StopIteration:
                    raise ValueError('need more than %d %s to unpack' %
                                     (i, 'values' if i > 1 else 'value'))
                assign(subarg,subvalue)
            try:
                next(value)
            except StopIteration:
                pass
            else:
                raise ValueError('too many values to unpack')
    def is_assigned(arg):
        if isinstance(arg,str):
            return arg in arg2value
        return arg in assigned_tuple_params
    if ismethod(func) and func.im_self is not None:
        # implicit 'self' (or 'cls' for classmethods) argument
        positional = (func.im_self,) + positional
    num_pos = len(positional)
    num_total = num_pos + len(named)
    num_args = len(args)
    num_defaults = len(defaults) if defaults else 0
    for arg, value in zip(args, positional):
        assign(arg, value)
    if varargs:
        if num_pos > num_args:
            assign(varargs, positional[-(num_pos-num_args):])
        else:
            assign(varargs, ())
    elif 0 < num_args < num_pos:
        raise TypeError('%s() takes %s %d %s (%d given)' % (
            f_name, 'at most' if defaults else 'exactly', num_args,
            'arguments' if num_args > 1 else 'argument', num_total))
    elif num_args == 0 and num_total:
        if varkw:
            if num_pos:
                # XXX: We should use num_pos, but Python also uses num_total:
                raise TypeError('%s() takes exactly 0 arguments '
                                '(%d given)' % (f_name, num_total))
        else:
            raise TypeError('%s() takes no arguments (%d given)' %
                            (f_name, num_total))
    for arg in args:
        if isinstance(arg, str) and arg in named:
            if is_assigned(arg):
                raise TypeError("%s() got multiple values for keyword "
                                "argument '%s'" % (f_name, arg))
            else:
                assign(arg, named.pop(arg))
    if defaults:    # fill in any missing values with the defaults
        for arg, value in zip(args[-num_defaults:], defaults):
            if not is_assigned(arg):
                assign(arg, value)
    if varkw:
        assign(varkw, named)
    elif named:
        unexpected = next(iter(named))
        if isinstance(unexpected, unicode):
            unexpected = unexpected.encode(sys.getdefaultencoding(), 'replace')
        raise TypeError("%s() got an unexpected keyword argument '%s'" %
                        (f_name, unexpected))
    unassigned = num_args - len([arg for arg in args if is_assigned(arg)])
    if unassigned:
        num_required = num_args - num_defaults
        raise TypeError('%s() takes %s %d %s (%d given)' % (
            f_name, 'at least' if defaults else 'exactly', num_required,
            'arguments' if num_required > 1 else 'argument', num_total))
    return arg2value
        


src/l/a/lazyrunner-0.01v3/lazyrunner/manager.py   lazyrunner(Download)
            # See if it was due to incompatable signature
            try:
                from inspect import getcallargs
            except ImportError:
                if "reportResults" in str(te):
 
            try:
                getcallargs(rrf, parameters, p, r)
            except TypeError:
                raiseTypeError()

src/i/d/identity.gentoo.org-HEAD/okupy/common/ssh.py   identity.gentoo.org(Download)
            h = settings.SSH_HANDLERS[cmd]
            # this is an easy way of checking if we have correct args
            inspect.getcallargs(h, *args, key=key)
        except (KeyError, TypeError):
            pass

src/r/e/reahl-component-2.1.0/reahl/component/exceptions.py   reahl-component(Download)
        else:
            call_args = args
        bound_args = inspect.getcallargs(to_check, *call_args, **kwargs)
    except TypeError, ex:
        ex.args = ((u'%s: ' % method)+ex.args[0],) + ex.args[1:]

src/p/y/pytyp-2.0.1/src/pytyp/spec/dispatch.py   pytyp(Download)
from collections import OrderedDict
from functools import wraps
from inspect import getcallargs
 
from pytyp.spec.check import unpack, verify_all
        def wrapper(obj, *args, **kargs):
            callargs = getcallargs(method, obj, *args, **kargs)
            try:
                verify_all(callargs, annotation)
            except TypeError:

src/p/h/phoebe-2.0a1/phoebe/frontend/bundle.py   phoebe(Download)
        """
        # first we need to reconstruct the arguments passed to the original function
        callargs = inspect.getcallargs(fctn,bundle,*args,**kwargs)
        dump = callargs.pop('self')
        callargstr = ','.join(["%s=%s" % (key, "\'%s\'" % callargs[key]\

src/s/p/spinoff-0.7.18/spinoff/actor/props.py   spinoff(Download)
    def __init__(self, cls, *args, **kwargs):
        if hasattr(inspect, 'getcallargs'):
            inspect.getcallargs(cls.__init__, None, *args, **kwargs)
        self.cls, self.args, self.kwargs = cls, args, kwargs
 

src/s/p/spinoff-HEAD/spinoff/actor/props.py   spinoff(Download)
    def __init__(self, cls, *args, **kwargs):
        if hasattr(inspect, 'getcallargs'):
            inspect.getcallargs(cls.__init__, None, *args, **kwargs)
        self.cls, self.args, self.kwargs = cls, args, kwargs
 

src/v/a/valideer-0.3/valideer/base.py   valideer(Download)
    def validating(func, *args, **kwargs):
        validate(inspect.getcallargs(func, *args, **kwargs), adapt=False)
        return func(*args, **kwargs)
    return validating
 
    def adapting(func, *args, **kwargs):
        adapted = validate(inspect.getcallargs(func, *args, **kwargs), adapt=True)
        argspec = inspect.getargspec(func)
 
        if argspec.varargs is argspec.keywords is None:

src/v/a/valideer-HEAD/valideer/base.py   valideer(Download)
    def validating(func, *args, **kwargs):
        validate(inspect.getcallargs(func, *args, **kwargs), adapt=False)
        return func(*args, **kwargs)
    return validating
 
    def adapting(func, *args, **kwargs):
        adapted = validate(inspect.getcallargs(func, *args, **kwargs), adapt=True)
        argspec = inspect.getargspec(func)
 
        if argspec.varargs is argspec.keywords is None:

src/d/i/dispy-HEAD/asyncoro.py   dispy(Download)
            raise Exception('Coro function %s should not be called with ' \
                            '"coro" parameter' % target.__name__)
        callargs = inspect.getcallargs(target, *args, **kwargs)
        if 'coro' not in callargs or callargs['coro'] is not None:
            raise Exception('Coro function "%s" should have "coro" argument with ' \

  1 | 2 | 3 | 4 | 5  Next