Beispiel #1
0
           Returns the dereferenced name as both value and repr if the name
           list is defined.
           Otherwise returns the name index and its repr().
        """
        argval = name_index
        if name_list is not None:
            argval = name_list[name_index]
            argrepr = argval
        else:
            argrepr = repr(argval)
        return argval, argrepr

    from xoutil import collections

    _Instruction = collections.namedtuple(
        "_Instruction",
        "opname opcode arg argval argrepr offset starts_line is_jump_target"
    )

    class Instruction(_Instruction):
        """Details for a bytecode operation

           Defined fields:
             opname - human readable name for operation
             opcode - numeric code for operation
             arg - numeric argument to operation (if any), otherwise None
             argval - resolved arg value (if known), otherwise same as arg
             argrepr - human readable description of operation argument
             offset - start index of operation within bytecode sequence
             starts_line - line started by this opcode (if any), otherwise None
             is_jump_target - True if other code jumps to here, otherwise False
        """
Beispiel #2
0
    if any(not callable(func) for func in funcs):
        raise TypeError('First arguments of `power` must be callables')
    if not isinstance(times, int):
        raise TypeError('Last argument of `power` must be int')
    if len(funcs) > 1:
        base = (compose(funcs), )
    else:
        base = (funcs[0], )
    return compose(*(base * times))


if not py33:
    from threading import RLock
    from xoutil.collections import namedtuple

    _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize",
                                          "currsize"])

    # Back-ported lru_cache from py33. But take note that if running with at
    # least py3 we will use Python's version, so don't mess with internals.

    WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__qualname__', '__doc__',
                           '__annotations__')
    WRAPPER_UPDATES = ('__dict__',)

    def update_wrapper(wrapper,
                       wrapped,
                       assigned=WRAPPER_ASSIGNMENTS,
                       updated=WRAPPER_UPDATES):
        """Update a wrapper function to look like the wrapped function

           wrapper is the function to be updated
Beispiel #3
0
                head, tail = '{}'
            items = ', '.join(type_name(t, affirm) for t in obj)
            return str('%s%s%s' % (head, items, tail))
        else:
            return type_name(type(obj))
    else:
        return None


# TODO: Implement a safe version for `attrgetter`

if not getattr(_pm, 'getfullargspec', None):
    from xoutil.collections import namedtuple
    FullArgSpec = namedtuple(
        'FullArgSpec',
        'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults,'
        'annotations'
    )

    def getfullargspec(func):
        import inspect
        spec = inspect.getargspec(func)
        return FullArgSpec(
            spec.args, spec.varargs, spec.keywords, spec.defaults,
            None, None, None
        )


# get rid of unused global variables
del _pm, _copy_python_module_members