Skip to content

Commit

Permalink
Update utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vstar37 authored Dec 28, 2024
1 parent e0611e7 commit e28560a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ def sort_dict(obj):
def subtract_rules(base_data, subtract_data):
"""从 base_data 中剔除 subtract_data 的规则"""
for key in ["process_name", "domain", "domain_suffix", "ip_cidr", "domain_regex"]:
# 获取 base_data 和 subtract_data 中的规则,确保它们是可哈希的
base_list = base_data["rules"].get(key, [])
subtract_list = subtract_data["rules"].get(key, [])
# 处理 base_data 和 subtract_data 中的规则,检查它们的类型
base_list = base_data["rules"].get(key, []) if isinstance(base_data["rules"], dict) else base_data["rules"]
subtract_list = subtract_data["rules"].get(key, []) if isinstance(subtract_data["rules"], dict) else subtract_data["rules"]

# 将元素转换为可哈希类型(例如元组),避免字典等不可哈希的类型
# 如果是字典元素,转为元组来避免字典不可哈希的问题
base_set = set(tuple(item.items()) if isinstance(item, dict) else item for item in base_list)
subtract_set = set(tuple(item.items()) if isinstance(item, dict) else item for item in subtract_list)

Expand Down

0 comments on commit e28560a

Please sign in to comment.