def _parse_function_simplified(symbol, member_of=""): results = {} inside_class = True if member_of != "" else False if member_of: func_name = member_of + " : " + symbol.name + '(' else: func_name = symbol.name + '(' # We store the arguments to compare with default backwards defaults = [] for value in symbol.args.defaults: # TODO: In some cases we can have something like: a=os.path defaults.append(value) arguments = [] for arg in reversed(symbol.args.args): if arg.__class__ is not _ast.Name or arg.id == 'self': continue argument = arg.id if defaults: value = defaults.pop() arg_default = _map_type.get(value.__class__, None) if arg_default is None: if value.__class__ is _ast.Attribute: arg_default = model.expand_attribute(value) elif value.__class__ is _ast.Name: arg_default = value.id else: arg_default = 'object' argument += '=' + arg_default arguments.append(argument) func_name += ', '.join(reversed(arguments)) if symbol.args.vararg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '*' try: func_name += symbol.args.vararg except: func_name += symbol.args.vararg.arg if symbol.args.kwarg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '**' try: func_name += symbol.args.kwarg except: func_name += symbol.args.kwarg.arg func_name += ')' for sym in symbol.body: if sym.__class__ is ast.FunctionDef: result = _parse_function_simplified(sym, symbol.name) results.update(result) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 results[lineno] = (func_name, 'f', inside_class) return results
def _parse_function_simplified(symbol, member_of=""): results = {} inside_class = True if member_of != "" else False if member_of: func_name = member_of + " : " + symbol.name + '(' else: func_name = symbol.name + '(' #We store the arguments to compare with default backwards defaults = [] for value in symbol.args.defaults: #TODO: In some cases we can have something like: a=os.path defaults.append(value) arguments = [] for arg in reversed(symbol.args.args): if arg.__class__ is not _ast.Name or arg.id == 'self': continue argument = arg.id if defaults: value = defaults.pop() arg_default = _map_type.get(value.__class__, None) if arg_default is None: if value.__class__ is _ast.Attribute: arg_default = model.expand_attribute(value) elif value.__class__ is _ast.Name: arg_default = value.id else: arg_default = 'object' argument += '=' + arg_default arguments.append(argument) func_name += ', '.join(reversed(arguments)) if symbol.args.vararg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '*' try: func_name += symbol.args.vararg except: func_name += symbol.args.vararg.arg if symbol.args.kwarg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '**' try: func_name += symbol.args.kwarg except: func_name += symbol.args.kwarg.arg func_name += ')' for sym in symbol.body: if sym.__class__ is ast.FunctionDef: result = _parse_function_simplified(sym, symbol.name) results.update(result) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 results[lineno] = (func_name, 'f', inside_class) return results
def _parse_function(symbol, with_docstrings): docstring = {} attrs = {} func = {'functions': {}} func_name = symbol.name + '(' #We store the arguments to compare with default backwards defaults = [] for value in symbol.args.defaults: #TODO: In some cases we can have something like: a=os.path defaults.append(value) arguments = [] for arg in reversed(symbol.args.args): if arg.__class__ is not _ast.Name or arg.id == 'self': continue argument = arg.id if defaults: value = defaults.pop() arg_default = _map_type.get(value.__class__, None) if arg_default is None: if value.__class__ is _ast.Attribute: arg_default = model.expand_attribute(value) elif value.__class__ is _ast.Name: arg_default = value.id else: arg_default = 'object' argument += '=' + arg_default arguments.append(argument) func_name += ', '.join(reversed(arguments)) if symbol.args.vararg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '*' + symbol.args.vararg.arg# antes no terminaba con '.arg' if symbol.args.kwarg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '**' + symbol.args.kwarg.arg# antes no terminaba con '.arg' func_name += ')' for sym in symbol.body: if sym.__class__ is ast.Assign: result = _parse_assign(sym) attrs.update(result[1]) elif sym.__class__ is ast.FunctionDef: result = _parse_function(sym, with_docstrings) if with_docstrings: docstring.update(result['docstring']) func['functions'][result['name']] = {'lineno': result['lineno'], 'functions': result['functions']} if with_docstrings: docstring[symbol.lineno] = ast.get_docstring(symbol, clean=True) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 return {'name': func_name, 'lineno': lineno, 'attrs': attrs, 'docstring': docstring, 'functions': func}
def _parse_function(symbol, with_docstrings): docstring = {} attrs = {} func = {"functions": {}} func_name = symbol.name + "(" # We store the arguments to compare with default backwards defaults = [] for value in symbol.args.defaults: # TODO: In some cases we can have something like: a=os.path defaults.append(value) arguments = [] for arg in reversed(symbol.args.args): if arg.__class__ is not _ast.Name or arg.id == "self": continue argument = arg.id if defaults: value = defaults.pop() arg_default = _map_type.get(value.__class__, None) if arg_default is None: if value.__class__ is _ast.Attribute: arg_default = model.expand_attribute(value) elif value.__class__ is _ast.Name: arg_default = value.id else: arg_default = "object" argument += "=" + arg_default arguments.append(argument) func_name += ", ".join(reversed(arguments)) if symbol.args.vararg is not None: if not func_name.endswith("("): func_name += ", " func_name += "*" + symbol.args.vararg if symbol.args.kwarg is not None: if not func_name.endswith("("): func_name += ", " func_name += "**" + symbol.args.kwarg func_name += ")" for sym in symbol.body: if sym.__class__ is ast.Assign: result = _parse_assign(sym) attrs.update(result[1]) elif sym.__class__ is ast.FunctionDef: result = _parse_function(sym, with_docstrings) if with_docstrings: docstring.update(result["docstring"]) func["functions"][result["name"]] = {"lineno": result["lineno"], "functions": result["functions"]} if with_docstrings: docstring[symbol.lineno] = ast.get_docstring(symbol, clean=True) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 return {"name": func_name, "lineno": lineno, "attrs": attrs, "docstring": docstring, "functions": func}
def _parse_class(symbol, with_docstrings): docstring = {} attr = {} func = {} clazz = {} name = symbol.name + '(' name += ', '.join([ model.expand_attribute(base) for base in symbol.bases]) name += ')' for sym in symbol.body: if isinstance(sym, ast.Assign): result = _parse_assign(sym) attr.update(result[0]) attr.update(result[1]) elif isinstance(sym, ast.FunctionDef): result = _parse_function(sym, with_docstrings) attr.update(result['attrs']) if with_docstrings: docstring.update(result['docstring']) func[result['name']] = { 'lineno': result['lineno'], 'functions': result['functions'] } elif isinstance(sym, ast.ClassDef): result = _parse_class(sym, with_docstrings) clazz[result['name']] = { 'lineno': result['lineno'], 'members': { 'attributes': result['attributes'], 'functions': result['functions'] } } docstring.update(result['docstring']) if with_docstrings: docstring[symbol.lineno] = ast.get_docstring(symbol, clean=True) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 return { 'name': name, 'attributes': attr, 'functions': func, 'lineno': lineno, 'docstring': docstring, 'classes': clazz }
def _parse_class_simplified(symbol): results = {} name = symbol.name + '(' name += ', '.join([model.expand_attribute(base) for base in symbol.bases]) name += ')' for sym in symbol.body: if isinstance(sym, ast.FunctionDef): result = _parse_function_simplified(sym, symbol.name) results.update(result) elif isinstance(sym, ast.ClassDef): result = _parse_class_simplified(sym) results.update(result) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 results[lineno] = (name, 'c') return results
def _parse_class_simplified(symbol): results = {} name = symbol.name + "(" name += ", ".join([model.expand_attribute(base) for base in symbol.bases]) name += ")" for sym in symbol.body: if sym.__class__ is ast.FunctionDef: result = _parse_function_simplified(sym, symbol.name) results.update(result) elif sym.__class__ is ast.ClassDef: result = _parse_class_simplified(sym) results.update(result) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 results[lineno] = (name, "c") return results
def _parse_class_simplified(symbol): results = {} name = symbol.name + '(' name += ', '.join([ model.expand_attribute(base) for base in symbol.bases]) name += ')' for sym in symbol.body: if isinstance(sym, ast.FunctionDef): result = _parse_function_simplified(sym, symbol.name) results.update(result) elif isinstance(sym, ast.ClassDef): result = _parse_class_simplified(sym) results.update(result) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 results[lineno] = (name, 'c') return results
def _parse_class(symbol, with_docstrings): docstring = {} attr = {} func = {} clazz = {} name = symbol.name + "(" name += ", ".join([model.expand_attribute(base) for base in symbol.bases]) name += ")" for sym in symbol.body: if sym.__class__ is ast.Assign: result = _parse_assign(sym) attr.update(result[0]) attr.update(result[1]) elif sym.__class__ is ast.FunctionDef: result = _parse_function(sym, with_docstrings) attr.update(result["attrs"]) if with_docstrings: docstring.update(result["docstring"]) func[result["name"]] = {"lineno": result["lineno"], "functions": result["functions"]} elif sym.__class__ is ast.ClassDef: result = _parse_class(sym, with_docstrings) clazz[result["name"]] = { "lineno": result["lineno"], "members": {"attributes": result["attributes"], "functions": result["functions"]}, } docstring.update(result["docstring"]) if with_docstrings: docstring[symbol.lineno] = ast.get_docstring(symbol, clean=True) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 return { "name": name, "attributes": attr, "functions": func, "lineno": lineno, "docstring": docstring, "classes": clazz, }
def _parse_function(symbol, with_docstrings): docstring = {} attrs = {} func = {'functions': {}} func_name = symbol.name + '(' # We store the arguments to compare with default backwards defaults = [] for value in symbol.args.defaults: # TODO: In some cases we can have something like: a=os.path defaults.append(value) arguments = [] for arg in reversed(symbol.args.args): if not isinstance(arg, _ast.Name) or arg.id == "self": continue argument = arg.id if defaults: value = defaults.pop() arg_default = _map_type.get(value.__class__, None) if arg_default is None: if isinstance(value, _ast.Attribute): arg_default = model.expand_attribute(value) elif isinstance(value, _ast.Name): arg_default = value.id else: arg_default = 'object' argument += '=' + arg_default arguments.append(argument) func_name += ', '.join(reversed(arguments)) if symbol.args.vararg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '*' func_name += symbol.args.vararg.arg if symbol.args.kwarg is not None: if not func_name.endswith('('): func_name += ', ' func_name += '**' func_name += symbol.args.kwarg.arg func_name += ')' for sym in symbol.body: if isinstance(sym, ast.Assign): result = _parse_assign(sym) attrs.update(result[1]) elif isinstance(sym, ast.FunctionDef): result = _parse_function(sym, with_docstrings) if with_docstrings: docstring.update(result['docstring']) func['functions'][result['name']] = { 'lineno': result['lineno'], 'functions': result['functions'] } if with_docstrings: docstring[symbol.lineno] = ast.get_docstring(symbol, clean=True) lineno = symbol.lineno for decorator in symbol.decorator_list: lineno += 1 return { 'name': func_name, 'lineno': lineno, 'attrs': attrs, 'docstring': docstring, 'functions': func }