Example #1
0
def callableobj(obj): #{{{
    if not iscallable(obj):
        return None
    if _ism(obj) or _isf(obj) or isclass(obj):
#    if any(f(obj) for f in (_ism, _isf, isclassmethod, isstaticmethod)):
        return obj
    elif hasattr(obj, '__call__') and _ism(obj.__call__):
        return obj.__call__
    else:
        obj = callable_wrapper(obj)
    return obj
Example #2
0
def cargnames(obj): #{{{
    obj = callableobj(obj)
    isc = isclass(obj)
    if not obj: return None
    elif isc:
        obj = obj.__init__
        obj = callable_wrapper(obj) if needs_wrapping(obj) else obj
    fargnames, fvargs, fvkey, fdef = getargspec(obj)
    if isc and fargnames:
        fargnames = fargnames[1:]
    return fargnames, fvargs, fvkey
Example #3
0
def cgetargspec(obj): #{{{
    obj = callableobj(obj)
    isc = isclass(obj)
    if not obj: return None
    elif isc:
        obj = obj.__init__
        obj = callable_wrapper(obj) if needs_wrapping(obj) else obj
    fargnames, fvargs, fvkey, fdef = getargspec(obj)
    if isc and fargnames:
        fargnames = fargnames[1:]
    if not fdef:
        return fargnames, fvargs, fvkey, {}
    numargs = len(fargnames)
    numdef = len(fdef)
    diff = numargs - numdef
    admatch = fargnames[diff:]
    return fargnames, fvargs, fvkey, dict(zip(admatch, fdef))
Example #4
0
def cargdefstr(obj): #{{{
    obj = callableobj(obj)
    isc = isclass(obj)
    if not obj: return None
    elif isc:
        obj = obj.__init__
        obj = callable_wrapper(obj) if needs_wrapping(obj) else obj
    fargnames, fvargs, fvkey, fdef = getargspec(obj)
    if isc and fargnames:
        fargnames = fargnames[1:]
    argstr = formatargspec(fargnames, fvargs, fvkey, fdef)[1:-1]
    other = []
    if fvargs:
        other.append(''.join(['*', fvargs]))
    if fvkey:
        other.append(''.join(['**', fvkey]))
    callstr = ', '.join(fargnames + other)
    return argstr, callstr