mirror of
https://github.com/MISP/misp-galaxy.git
synced 2024-11-26 08:47:18 +00:00
update
This commit is contained in:
parent
04c07e4774
commit
86f3ada396
1 changed files with 0 additions and 20 deletions
|
@ -8,24 +8,6 @@ class Meta:
|
||||||
refs: list = field(default_factory=list)
|
refs: list = field(default_factory=list)
|
||||||
synonyms: list = field(default_factory=list)
|
synonyms: list = field(default_factory=list)
|
||||||
|
|
||||||
# def custom_asdict(obj):
|
|
||||||
# if is_dataclass(obj):
|
|
||||||
# result = {}
|
|
||||||
# for field_name, field_def in obj.__dataclass_fields__.items():
|
|
||||||
# value = getattr(obj, field_name)
|
|
||||||
# if field_name == 'meta':
|
|
||||||
# meta_value = custom_asdict(value)
|
|
||||||
# meta_value = {k: v for k, v in meta_value.items() if not (k in ['refs', 'synonyms'] and (not v or all(e is None for e in v)))}
|
|
||||||
# value = meta_value
|
|
||||||
# elif isinstance(value, (list, tuple)) and all(is_dataclass(i) for i in value):
|
|
||||||
# value = [custom_asdict(i) for i in value]
|
|
||||||
# elif isinstance(value, list) and all(e is None for e in value):
|
|
||||||
# continue
|
|
||||||
# result[field_name] = value
|
|
||||||
# return result
|
|
||||||
# else:
|
|
||||||
# return obj
|
|
||||||
|
|
||||||
def custom_asdict(obj):
|
def custom_asdict(obj):
|
||||||
if is_dataclass(obj):
|
if is_dataclass(obj):
|
||||||
result = {}
|
result = {}
|
||||||
|
@ -33,14 +15,12 @@ def custom_asdict(obj):
|
||||||
value = getattr(obj, field_name)
|
value = getattr(obj, field_name)
|
||||||
if field_name == 'meta':
|
if field_name == 'meta':
|
||||||
meta_value = custom_asdict(value)
|
meta_value = custom_asdict(value)
|
||||||
# Filter out 'refs', 'synonyms', 'country', and 'country_name' if they are None or if 'refs' and 'synonyms' are empty
|
|
||||||
meta_value = {k: v for k, v in meta_value.items() if v is not None and not (k in ['refs', 'synonyms'] and (not v or all(e is None for e in v)))}
|
meta_value = {k: v for k, v in meta_value.items() if v is not None and not (k in ['refs', 'synonyms'] and (not v or all(e is None for e in v)))}
|
||||||
value = meta_value
|
value = meta_value
|
||||||
elif isinstance(value, (list, tuple)) and all(is_dataclass(i) for i in value):
|
elif isinstance(value, (list, tuple)) and all(is_dataclass(i) for i in value):
|
||||||
value = [custom_asdict(i) for i in value]
|
value = [custom_asdict(i) for i in value]
|
||||||
elif isinstance(value, list) and all(e is None for e in value):
|
elif isinstance(value, list) and all(e is None for e in value):
|
||||||
continue
|
continue
|
||||||
# Skip the field if the value is None (specifically for 'country' and 'country_name')
|
|
||||||
if value is None and field_name in ['country', 'country_name']:
|
if value is None and field_name in ['country', 'country_name']:
|
||||||
continue
|
continue
|
||||||
result[field_name] = value
|
result[field_name] = value
|
||||||
|
|
Loading…
Reference in a new issue