Decorator method for Workbench methods returning a str
191630
def r_to_s(func):
    """"""

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        """"""

        class ReprToStr(str):
            """Replaces a class __repr__ with it's string representation"""
            def __repr__(self):
                return str(self)
        return ReprToStr(func(*args, **kwargs))
    return wrapper
479883
def get_decorators(func):
    
    decorators = []
    # Parse the source code of the function with ast to find the names of
    # all of its decorators.
    tree = ast.parse(inspect.getsource(func))
    for node in ast.iter_child_nodes(tree):
        for dnode in node.decorator_list:
            if isinstance(dnode, ast.Name):
                decorator = func.func_globals[dnode.id]
            elif isinstance(dnode, ast.Attribute):
                module = func.func_globals[dnode.value.id]
                decorator = getattr(module, dnode.attr)
            else:
                raise Exception("Unable to handle decorator node: %s" % dnode)
            decorators.append(decorator)
    return decorators
66453
async def getWorkerType(self, *args, **kwargs):
        

        return await self._makeApiCall(self.funcinfo["getWorkerType"], *args, **kwargs)
1322695
def _fullqualname_method_py2(obj):
    

    if obj.__self__ is None:
        # unbound methods
        module = obj.im_class.__module__
        cls = obj.im_class.__name__
    else:
        # bound methods
        if inspect.isclass(obj.__self__):
            # methods decorated with @classmethod
            module = obj.__self__.__module__
            cls = obj.__self__.__name__
        else:
            module = obj.__self__.__class__.__module__
            cls = obj.__self__.__class__.__name__

    return module + '.' + cls + '.' + obj.__func__.__name__
1346113
def _get_wrapper_args(routine):
        
        ret = ''

        for parameter_info in routine['parameters']:
            if ret:
                ret += ', '

            ret += parameter_info['name']

        return ret
391990
def _get_method(name, func):
    ""
    def method(self, *args, **kw):
        return func(self, *args, **kw)
    method.__name__ = name
    return method
755430
def _get_decoratables(self, atype):
        
        result = []
        defmsg = "Skipping {}; not decoratable or already decorated."
        for varname in self.shell.run_line_magic("who_ls", atype):
            varobj = self.shell.user_ns.get(varname, None)
            decorate = False
            
            if varobj is None: # Nothing useful can be done.
                continue
            
            if atype in ["classobj", "type"]:
                #Classes are only relevant if they have no __file__
                #attribute; all other classes should be decorated by the
                #full acorn machinery.
                if (not hasattr(varobj, "__acorn__") and
                    hasattr(varobj, "__module__") and
                    varobj.__module__ == "__main__" and
                    not hasattr(varobj, "__file__")):
                    decorate = True
                else:
                    msg.std(defmsg.format(varname), 3)
                    
            elif atype in ["function", "staticmethod"]:
                # %who_ls will only return functions from the *user*
                # namespace, so we don't have a lot to worry about here.
                func = None
                if atype == "staticmethod" and hasattr(varobj, "__func__"):
                    func = varobj.__func__
                elif atype == "function":
                    func = varobj

                if (func is not None and
                    not hasattr(func, "__acorn__") and
                    hasattr(func, "__code__") and
                    "<ipython-input" in func.__code__.co_filename):
                    decorate = True
                else:
                    msg.std(defmsg.format(varname), 3)
                    
            if decorate:
                self.entities[atype][varname] = varobj
                result.append((varname, varobj))
                
        return result
326361
def print_args(output=sys.stdout):
    
    def decorator(func):
        """The decorator function.
        """
        @wraps(func)
        def _(*args, **kwargs):
            """The decorated function.
            """
            output.write(
                "Args: {0}, KwArgs: {1}\n".format(str(args), str(kwargs)))
            return func(*args, **kwargs)
        return _
    return decorator
1200996
def methods(*meth):
    
    def decorator(f):
        if not hasattr(f, '_methods_cache'):
            f._methods_cache = [m.upper() for m in meth]
        return f
    return decorator
1018191
def log_method(log, level=logging.DEBUG):
    """"""

    def decorator(func):
        func_name = func.__name__

        @six.wraps(func)
        def wrapper(self, *args, **kwargs):
            if log.isEnabledFor(level):
                pretty_args = []
                if args:
                    pretty_args.extend(str(a) for a in args)
                if kwargs:
                    pretty_args.extend(
                        "%s=%s" % (k, v) for k, v in six.iteritems(kwargs))
                log.log(level, "%s(%s)", func_name, ", ".join(pretty_args))
            return func(self, *args, **kwargs)

        return wrapper

    return decorator
894221
def _get_wrapper(self):
        
        if self.args_type == "MODULE_FUNCTION":
            return getattr(self.obj, self.prop)
        elif self.args_type == "FUNCTION":
            return getattr(self.g, self.obj.__name__)
        elif self.args_type == "PURE":
            return getattr(self.pure, "func")
        else:
            ErrorHandler.wrapper_object_not_found_error()
859149
def func_factory(p, method: str) -> callable:
    

    def callback(pretty: bool = False):
        res = getattr(p, method)
        dump = partial(json.dumps, indent=4) if pretty else partial(json.dumps)
        click.echo(dump(res))

    return callback
1374675
def decorator(caller, _func=None):
    """"""
    if _func is not None:  # return a decorated function
        # this is obsolete behavior; you should use decorate instead
        return decorate(_func, caller)
    # else return a decorator function
    defaultargs, defaults = '', ()
    if inspect.isclass(caller):
        name = caller.__name__.lower()
        doc = 'decorator(%s) converts functions/generators into ' \
            'factories of %s objects' % (caller.__name__, caller.__name__)
    elif inspect.isfunction(caller):
        if caller.__name__ == '<lambda>':
            name = '_lambda_'
        else:
            name = caller.__name__
        doc = caller.__doc__
        nargs = caller.__code__.co_argcount
        ndefs = len(caller.__defaults__ or ())
        defaultargs = ', '.join(caller.__code__.co_varnames[nargs-ndefs:nargs])
        if defaultargs:
            defaultargs += ','
        defaults = caller.__defaults__
    else:  # assume caller is an object with a __call__ method
        name = caller.__class__.__name__.lower()
        doc = caller.__call__.__doc__
    evaldict = dict(_call=caller, _decorate_=decorate)
    dec = FunctionMaker.create(
        '%s(func, %s)' % (name, defaultargs),
        'if func is None: return lambda func:  _decorate_(func, _call, (%s))\n'
        'return _decorate_(func, _call, (%s))' % (defaultargs, defaultargs),
        evaldict, doc=doc, module=caller.__module__, __wrapped__=caller)
    if defaults:
        dec.__defaults__ = (None,) + defaults
    return dec
1090152
def output(self):
        
        def decorator(outputMethod):
            return MethodicalOutput(machine=self, method=outputMethod)
        return decorator
573083
def get_method_docstring(cls, method_name):
    
    method = getattr(cls, method_name, None)
    if method is None:
        return
    docstrign = inspect.getdoc(method)
    if docstrign is None:
        for base in cls.__bases__:
            docstrign = get_method_docstring(base, method_name)
            if docstrign:
                return docstrign
        else:
            return None

    return docstrign
1219880
def decorators(self):
        
        res = collections.defaultdict(list)
        mmap = {}

        def get_val(na, default=None):
            ret = None
            if isinstance(na, ast.Num):
                repr_n = repr(na.n)
                val = na.n
                vtype = float if '.' in repr_n else int
                ret = vtype(val)

            elif isinstance(na, ast.Str):
                ret = str(na.s)

            elif isinstance(na, ast.Name):
                # http://stackoverflow.com/questions/12700893/
                ret = getattr(builtins, na.id, None)
                if not ret:
                    ret = na.id
                    if ret == 'True':
                        ret = True
                    elif ret == 'False':
                        ret = False

            elif isinstance(na, ast.Dict):
                if na.keys:
                    ret = {get_val(na_[0]): get_val(na_[1]) for na_ in zip(na.keys, na.values)}
                else:
                    ret = {}

            elif isinstance(na, (ast.List, ast.Tuple)):
                if na.elts:
                    ret = [get_val(na_) for na_ in na.elts]
                else:
                    ret = []

                if isinstance(na, ast.Tuple):
                    ret = tuple(ret)

            else:
                ret = default

            return ret

        def is_super(childnode, parentnode):
            """returns true if child node has a super() call to parent node"""
            ret = False
            for n in childnode.body:
                if not isinstance(n, ast.Expr): continue

                try:
                    func = n.value.func
                    func_name = func.attr
                    if func_name == parentnode.name:
                        ret = isinstance(func.value, ast.Call)
                        break

                except AttributeError as e:
                    ret = False

            return ret

        def visit_FunctionDef(node):
            """ https://docs.python.org/2/library/ast.html#ast.NodeVisitor.visit """

            add_decs = True
            if node.name in res:
                add_decs = is_super(mmap[node.name], node)

            mmap[node.name] = node

            if add_decs:
                for n in node.decorator_list:
                    d = {}
                    name = ''
                    args = []
                    kwargs = {}
                    if isinstance(n, ast.Call):
                        name = n.func.attr if isinstance(n.func, ast.Attribute) else n.func.id
                        for an in n.args:
                            args.append(get_val(an))

                        for an in n.keywords:
                            kwargs[an.arg] = get_val(an.value)

                    else:
                        name = n.attr if isinstance(n, ast.Attribute) else n.id

                    d = {
                        "name": name,
                        "args": args,
                        "kwargs": kwargs
                    }
                    m = self.module
                    decor = getattr(m, name, None)
                    if decor:
                        d["decorator"] = decor

                    #res[node.name].append((name, args, kwargs))
                    res[node.name].append(self.decorator_class(**d))

        node_iter = ast.NodeVisitor()
        node_iter.visit_FunctionDef = visit_FunctionDef
        for target_cls in inspect.getmro(self.controller_class):
            if target_cls == Controller: break
            node_iter.visit(ast.parse(inspect.getsource(target_cls)))

        return res
106777
def decorator(caller, _func=None):
    """"""
    if _func is not None:  # return a decorated function
        # this is obsolete behavior; you should use decorate instead
        return decorate(_func, caller)
    # else return a decorator function
    if inspect.isclass(caller):
        name = caller.__name__.lower()
        doc = 'decorator(%s) converts functions/generators into ' \
              'factories of %s objects' % (caller.__name__, caller.__name__)
    elif inspect.isfunction(caller):
        if caller.__name__ == '<lambda>':
            name = '_lambda_'
        else:
            name = caller.__name__
        doc = caller.__doc__
    else:  # assume caller is an object with a __call__ method
        name = caller.__class__.__name__.lower()
        doc = caller.__call__.__doc__
    evaldict = dict(_call_=caller, _decorate_=decorate)
    return FunctionMaker.create(
        '%s(func)' % name, 'return _decorate_(func, _call_)',
        evaldict, doc=doc, module=caller.__module__,
        __wrapped__=caller)