def add_method(m, c): m = method[1] ret = {} extract_function(method[0], ret, m, get_class_name(str(clazz))) ret['module'] = x ret['klass'] = c key = c + '.' + m add_to_method_desc(key, ret) add_method(m, get_class_name(str(clazz))) for c in additional_class_names: add_method(m, c)是什么意思
时间: 2023-05-25 15:02:46 浏览: 50
这段代码为一个函数,函数名为add_method。函数接收两个参数,分别为方法m和类c。
函数中调用了另一个函数extract_function,会将方法m的相关信息提取出来,保存在一个字典中。字典中还包含了该方法所在的模块x和类名c。
然后,函数将类名和方法名用“.”链接起来,作为一个唯一的key,并调用另一个函数add_to_method_desc,将这个key和字典ret添加到方法描述字典中。
接着,函数循环遍历additional_class_names列表中的类名,并调用add_method函数,传入相应的类名参数,实现将方法m添加到不同类的方法描述字典中。
总的来说,这段代码的作用是将一个方法的相关信息添加到方法描述字典中,并支持将同一个方法添加到不同的类的方法描述字典中。
相关问题
for method in methods: def add_method(m, c): m = method[1] ret = {} extract_function(method[0], ret, m, get_class_name(str(clazz))) ret['module'] = x ret['klass'] = c key = c + '.' + m add_to_method_desc(key, ret) add_method(m, get_class_name(str(clazz))) for c in additional_class_names: add_method(m, c)是什么意思
这段代码是定义了一个函数add_method,然后在循环中调用它来添加一个方法的描述信息。具体来说,循环中遍历了一个类clazz的方法列表methods,然后将其名称和类名作为参数传入add_method函数中。在add_method函数中,将方法名m和类名c保存起来,并调用extract_function函数来提取方法的描述信息并保存在一个字典中。最后将模块名x也保存在字典中,碰到重名的情况下也考虑了将方法描述信息添加到额外类名additional_class_names的所有类中。最后调用add_to_method_desc函数将方法描述信息保存到一个全局的字典中。
def loadJson(filename): ret_json = None try: with open(filename, "r") as json_file: ret_json = json.load(json_file) except Exception as e: print(f"Error while opening {filename}.\nerror message: {e}") return ret_json #json file로부터 읽어온다. def getUrls(json_dict, url_type:int = 0, max_len:int = -1): if url_type <0 or url_type >1: raise Exception("Invalid Parameter(url_type) Error!") if url_type == 0: ret_url_list = [obj['url'] for obj in json_dict] if url_type == 1: ret_url_list = [obj['url'] for obj in json_dict['_embedded']['phish']] if max_len != -1: if len(ret_url_list) > max_len: ret_url_list = ret_url_list[:max_len] random.shuffle(ret_url_list) return ret_url_list # input : filepath # output : url list def getUrls_f(_filenames, url_type: int = 0, max_len:int = -1): ret_url_list = [] if type(_filenames) == str: json_dict = loadJson(_filenames) ret_url_list = getUrls(json_dict, url_type, max_len) if type(_filenames) == list: for filename in _filenames: json_dict = loadJson(filename) ret_url_list.extend(getUrls(json_dict, url_type, max_len)) return ret_url_list
这段代码是一个用于从 JSON 文件中读取 URL 的函数。它包含两个函数,loadJson 和 getUrls。
loadJson 函数接受一个文件名作为参数,尝试打开该文件并将其解析为 JSON 数据。如果出现任何错误,它将打印错误信息并返回 None。否则,它将返回解析后的 JSON 数据。
getUrls 函数接受一个 JSON 字典、一个 url_type 参数和一个 max_len 参数。url_type 参数指定从 JSON 数据中提取 URL 的方式,0 表示直接从 JSON 数据中提取,1 表示从嵌入式 JSON 数据中提取。max_len 参数指定最多返回多少个 URL。如果未指定 max_len 或 max_len 为负数,则返回所有 URL。
getUrls_f 函数接受一个文件名列表、url_type 参数和 max_len 参数。它调用 loadJson 和 getUrls 函数以从所有文件中提取 URL,并将它们存储在一个列表中。然后,它返回该列表。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)