Exemplo n.º 1
0
def _InitializeUnboundMethods():
    # Sort the items by length, so parents get created before children.
    items = ApiFunction.unboundFunctions().items()
    items.sort(key=lambda x: len(x[0]))

    for name, func in items:
        signature = func.getSignature()
        if signature.get('hidden', False):
            continue

        # Create nested objects as needed.
        name_parts = name.split('.')
        target = Algorithms
        while len(name_parts) > 1:
            first = name_parts[0]
            if not hasattr(target, first):
                setattr(target, first, _AlgorithmsContainer())
            target = getattr(target, first)
            name_parts = name_parts[1:]

        # Attach the function.
        # We need a copy of the function to attach properties.
        def GenerateFunction(f):
            return lambda *args, **kwargs: f.call(*args, **kwargs)  # pylint: disable=unnecessary-lambda

        bound = GenerateFunction(func)
        bound.signature = signature
        bound.__doc__ = str(func)
        setattr(target, name_parts[0], bound)
Exemplo n.º 2
0
def _InitializeUnboundMethods():
    # Sort the items by length, so parents get created before children.
    items = ApiFunction.unboundFunctions().items()
    items.sort(key=lambda x: len(x[0]))

    for name, func in items:
        signature = func.getSignature()
        if signature.get("hidden", False):
            continue

        # Create nested objects as needed.
        name_parts = name.split(".")
        target = Algorithms
        while len(name_parts) > 1:
            first = name_parts[0]
            if not hasattr(target, first):
                setattr(target, first, _AlgorithmsContainer())
            target = getattr(target, first)
            name_parts = name_parts[1:]

        # Attach the function.
        # We need a copy of the function to attach properties.
        def GenerateFunction(f):
            return lambda *args, **kwargs: f.call(*args, **kwargs)  # pylint: disable=unnecessary-lambda

        bound = GenerateFunction(func)
        bound.signature = signature
        bound.__doc__ = str(func)
        setattr(target, name_parts[0], bound)