Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7d8239d
replaced type by isinstance in intelmqdump.py
Spiritedswordsman Aug 14, 2025
6f178e0
replaced type to isinstance in intelmqctl.py
Spiritedswordsman Aug 14, 2025
6af9ee5
replaced type with isinstance in expert.py
Spiritedswordsman Aug 14, 2025
1c276ed
replaced type with isinstance in expert.py
Spiritedswordsman Aug 14, 2025
cf3add7
replaced type with isinstance in expert.py
Spiritedswordsman Aug 14, 2025
9cab088
replaced type with isinstance in parser_csv.py
Spiritedswordsman Aug 14, 2025
7a43050
replaced type with isinstance in parser.py
Spiritedswordsman Aug 14, 2025
fa3e58c
replaced type with isinstance in harmonization.py
Spiritedswordsman Aug 14, 2025
6e3ac70
replaced type with isinstance in bot.py
Spiritedswordsman Aug 14, 2025
4436e98
replaced type with isinstance in pipeline.py
Spiritedswordsman Aug 14, 2025
6e8d78c
replaced type with isinstance in test.py
Spiritedswordsman Aug 14, 2025
65ce94e
replaced type with isinstance in upgrades.py
Spiritedswordsman Aug 14, 2025
ef8f00f
replaced type with isinstance in utils.py
Spiritedswordsman Aug 14, 2025
552728d
replaced type by isinstance in message.py
Spiritedswordsman Aug 14, 2025
4dbcb08
replaced type by isinstance in test_message.py
Spiritedswordsman Aug 14, 2025
f8b695d
replaced type with isinstance in bot.py
Spiritedswordsman Aug 14, 2025
8009076
replaced files with isinstance in harmonization.py
Spiritedswordsman Aug 14, 2025
158be13
replaced type with isinstance in upgrades.py
Spiritedswordsman Aug 14, 2025
cafbf3f
replaced type with isinstance in pipeline.py
Spiritedswordsman Aug 14, 2025
26ceba7
Updated expert.py
Spiritedswordsman Aug 15, 2025
c2d0ae5
Update expert.py
Spiritedswordsman Aug 15, 2025
2449d85
Update expert.py
Spiritedswordsman Aug 15, 2025
9a5f8fd
Update bot.py
Spiritedswordsman Aug 15, 2025
7e1b555
Update test.py
Spiritedswordsman Aug 15, 2025
23f58e7
Update test_message.py
Spiritedswordsman Aug 15, 2025
db2ac4e
Update message.py
Spiritedswordsman Aug 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions intelmq/bin/intelmqctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def read_bot_log(self, bot_id, log_level, number_of_lines):
if self._parameters.logging_handler == 'syslog':
log_message = utils.parse_logline(line, regex=utils.SYSLOG_REGEX)

if type(log_message) is not dict:
if not isinstance(log_message, dict):
if self._parameters.logging_handler == 'file':
message_overflow = '\n'.join([line, message_overflow])
continue
Expand Down Expand Up @@ -1084,7 +1084,7 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None,
result['traceback'] = traceback.format_exc()
result['success'] = False
else:
if type(retval) is str:
if isinstance(retval, str):
self._logger.error('Upgrade %r failed: %s', function, retval)
result['message'] = retval
result['success'] = False
Expand Down Expand Up @@ -1176,7 +1176,7 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None,
result['traceback'] = traceback.format_exc()
result['success'] = False
else:
if type(retval) is str:
if isinstance(retval, str):
self._logger.error('%s: Upgrade failed: %s', docstring, retval)
result['message'] = retval
result['success'] = False
Expand Down
4 changes: 2 additions & 2 deletions intelmq/bin/intelmqdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def save_file(handle, content):
def load_meta(dump):
retval = []
for key, value in dump.items():
if type(value['traceback']) is not list:
if not isinstance(value['traceback'], list):
error = value['traceback'].splitlines()[-1]
else:
error = value['traceback'][-1].strip()
Expand Down Expand Up @@ -410,7 +410,7 @@ def main(argv=None):
len(value['message']['raw']) > args.truncate):
value['message']['raw'] = value['message'][
'raw'][:args.truncate] + '...[truncated]'
if type(value['traceback']) is not list:
if not isinstance(value['traceback'], list):
value['traceback'] = value['traceback'].splitlines()
pprint.pprint(value)
elif answer[0] == 'e':
Expand Down
8 changes: 4 additions & 4 deletions intelmq/bots/experts/filter/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ def process(self):
except ValueError:
self.logger.error("Could not parse time.source %s.", event.get('time.source'))
else:
if type(self.not_after) is datetime and event_time > self.not_after:
if isinstance(self.not_after, datetime) and event_time > self.not_after:
self.acknowledge_message()
self.logger.debug("Filtered out event with time.source %s.", event.get('time.source'))
return
if type(self.not_before) is datetime and event_time < self.not_before:
if isinstance(self.not_before, datetime) and event_time < self.not_before:
self.acknowledge_message()
self.logger.debug("Filtered out event with time.source %r.", event.get('time.source'))
return

now = datetime.now(tz=timezone.utc)
if type(self.not_after) is timedelta and event_time > (now - self.not_after):
if isinstance(self.not_after, timedelta) and event_time > (now - self.not_after):
self.acknowledge_message()
self.logger.debug("Filtered out event with time.source %r.", event.get('time.source'))
return
if type(self.not_before) is timedelta and event_time < (now - self.not_before):
if isinstance(self.not_before, timedelta) and event_time < (now - self.not_before):
self.acknowledge_message()
self.logger.debug("Filtered out event with time.source %r.", event.get('time.source'))
return
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/experts/format_field/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FormatFieldExpertBot(ExpertBot):
split_column = None

def init(self):
if type(self.strip_columns) is str:
if isinstance(self.strip_columns, str):
self.strip_columns = [column.strip() for column in self.strip_columns.split(",")]

def process(self):
Expand Down
6 changes: 3 additions & 3 deletions intelmq/bots/experts/rdap/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def init(self):

# get bootstrapped servers
for service in self.rdap_bootstrapped_servers:
if type(self.rdap_bootstrapped_servers[service]) is str:
if isinstance(self.rdap_bootstrapped_servers[service], str):
self.__rdap_directory[service] = {"url": self.rdap_bootstrapped_servers[service]}
elif type(self.rdap_bootstrapped_servers) is dict:
elif isinstance(self.rdap_bootstrapped_servers, dict):
self.__rdap_directory[service] = self.rdap_bootstrapped_servers[service]

def parse_entities(self, vcardArray) -> list:
vcard = []
for vcardentry in vcardArray:
if type(vcardentry) is str:
if isinstance(vcardentry, str):
continue

for vcarddata in vcardentry:
Expand Down
2 changes: 1 addition & 1 deletion intelmq/bots/parsers/generic/parser_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GenericCsvParserBot(ParserBot):

def init(self):
# convert columns to an array
if type(self.columns) is str:
if isinstance(self.columns, str):
self.columns = [column.strip() for column in self.columns.split(",")]

if self.type_translation and isinstance(self.type_translation, str): # not-empty string
Expand Down
4 changes: 2 additions & 2 deletions intelmq/bots/parsers/html_table/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def init(self):
raise MissingDependencyError("beautifulsoup4")

# convert columns to an array
if type(self.columns) is str:
if isinstance(self.columns, str):
self.columns = [column.strip() for column in self.columns.split(",")]
if self.ignore_values is None:
self.ignore_values = len(self.columns) * ['']
if type(self.ignore_values) is str:
if isinstance(self.ignore_values, str):
self.ignore_values = [value.strip() for value in self.ignore_values.split(",")]

if len(self.columns) != len(self.ignore_values):
Expand Down
5 changes: 2 additions & 3 deletions intelmq/lib/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ def __reset_total_path_stats(self):
"""Initially set destination paths to 0 to reset them in stats cache"""
if not self.destination_queues:
return
queues_type = type(self.destination_queues)
if queues_type is dict:
if isinstance(self.destination_queues, dict):
for path in self.destination_queues.keys():
self.__message_counter["path_total"][path] = 0
else:
Expand Down Expand Up @@ -1240,7 +1239,7 @@ def process(self):
value = self.parse_line(line, report)
if value is None:
continue
elif type(value) is list or isinstance(value, types.GeneratorType):
elif isinstance(value, list) or isinstance(value, types.GeneratorType):
# filter out None
events: list[libmessage.Event] = list(filter(bool, value))
else:
Expand Down
2 changes: 1 addition & 1 deletion intelmq/lib/harmonization.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def is_valid(value: str, sanitize: bool = False) -> bool:
if not GenericType.is_valid(value):
return False

if type(value) is not str:
if not isinstance(value, str):
return False

if len(value) == 0:
Expand Down
4 changes: 2 additions & 2 deletions intelmq/lib/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ def __eq__(self, other: dict) -> bool:
Comparison with other types e.g. dicts does not check the harmonization_config.
"""
dict_eq = super().__eq__(other)
if dict_eq and issubclass(type(other), Message):
type_eq = type(self) is type(other)
if dict_eq and isinstance(other, Message):
type_eq = isinstance(self, other)
harm_eq = self.harmonization_config == other.harmonization_config if hasattr(other, 'harmonization_config') else False
if type_eq and harm_eq:
return True
Expand Down
5 changes: 2 additions & 3 deletions intelmq/lib/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ def set_queues(self, queues: Optional[str], queues_type: str):
self.internal_queue = None if queues is None else f'{queues}-internal'

elif queues_type == "destination":
type_ = type(queues)
if type_ is list:
if isinstance(queues, list):
q = {"_default": queues}
elif type_ is str:
elif isinstance(queues, str):
q = {"_default": queues.split()}
elif isinstance(queues, dict):
q = queues
Expand Down
6 changes: 3 additions & 3 deletions intelmq/lib/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def setUpClass(cls):
'time.observation': '2016-01-01T00:00:00+00:00'}
elif cls.bot_type != 'collector' and cls.default_input_message == '':
cls.default_input_message = {'__type': 'Event'}
if type(cls.default_input_message) is dict:
if isinstance(cls.default_input_message, dict):
cls.default_input_message = \
utils.decode(json.dumps(cls.default_input_message))

Expand Down Expand Up @@ -268,9 +268,9 @@ def prepare_source_queue(self):
self.input_message = [self.input_message]
self.input_queue = []
for msg in self.input_message:
if type(msg) is dict:
if isinstance(msg, dict):
self.input_queue.append(json.dumps(msg))
elif issubclass(type(msg), message.Message):
elif isinstance(msg, message.Message):
self.input_queue.append(msg.serialize())
else:
self.input_queue.append(msg)
Expand Down
4 changes: 2 additions & 2 deletions intelmq/lib/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def v100_dev7_modify_syntax(configuration, harmonization, dry_run, **kwargs):
if bot["module"] == "intelmq.bots.experts.modify.expert":
if "configuration_path" in bot["parameters"]:
config = load_configuration(bot["parameters"]["configuration_path"])
if type(config) is dict:
if isinstance(config, dict):
new_config = modify_expert_convert_config(config)
if len(config) != len(new_config):
return 'Error converting modify expert syntax. Different size of configurations. Please report this.'
Expand Down Expand Up @@ -527,7 +527,7 @@ def v221_feed_changes(configuration, harmonization, dry_run, **kwargs):
continue
columns = bot["parameters"]["columns"]
# convert columns to an array
if type(columns) is str:
if isinstance(columns, str):
columns = [column.strip() for column in columns.split(",")]
if columns == ULRHAUS_OLD:
changed = True
Expand Down
6 changes: 3 additions & 3 deletions intelmq/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def flatten_queues(queues: Union[list, dict]) -> Iterator[str]:
Returns:
flattened_queues: queues without dictionaries as values, just lists with the values
"""
return (item for sublist in (queues.values() if type(queues) is dict else queues) for item in
(sublist if type(sublist) is list else [sublist]))
return (item for sublist in (queues.values() if isinstance(queues, dict) else queues) for item in
(sublist if isinstance(sublist, list) else [sublist]))


def load_configuration(configuration_filepath: str) -> dict:
Expand Down Expand Up @@ -395,7 +395,7 @@ def log(name: str, log_path: Union[str, bool] = intelmq.DEFAULT_LOGGING_PATH,
handler.setLevel(log_level)
handler.setFormatter(logging.Formatter(LOG_FORMAT))
elif syslog:
if type(syslog) is tuple or type(syslog) is list:
if isinstance(syslog, tuple) or isinstance(syslog, list):
handler = logging.handlers.SysLogHandler(address=tuple(syslog))
else:
handler = logging.handlers.SysLogHandler(address=syslog)
Expand Down
12 changes: 5 additions & 7 deletions intelmq/tests/lib/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ def add_event_examples(self, event):
def test_report_type(self):
""" Test if MessageFactory returns a Report. """
report = self.new_report()
self.assertEqual(type(report),
message.Report)
self.assertTrue(isinstance(report, message.Report))

def test_event_type(self):
""" Test if MessageFactory returns a Event. """
event = self.new_event()
self.assertEqual(type(event),
message.Event)
self.assertTrue(isinstance(event, message.Event))

def test_report_init_auto(self):
""" Test if serialize does pass auto=True """
Expand Down Expand Up @@ -582,9 +580,9 @@ def test_protocol_length(self):
def test_message_from_dict_return_type(self):
""" Test if from_dict() returns the correct class. """
event = {'__type': 'Event'}
event_type = type(message.MessageFactory.from_dict(event,
harmonization=HARM))
self.assertTrue(event_type is message.Event,
event_message = message.MessageFactory.from_dict(event,harmonization=HARM)
event_type = type(event_message)
self.assertTrue(isinstance(event_message, message.Event),
msg=f'Type is {event_type} instead of Event.')

def test_event_init_check(self):
Expand Down
Loading