diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index c93d23c..71cd737 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -144,7 +144,7 @@ def _parse_report_record(record, ip_db_path=None, offline=False, else: auth_results = new_record["auth_results"].copy() - if type(auth_results["dkim"]) != list: + if not isinstance(auth_results["dkim"], list): auth_results["dkim"] = [auth_results["dkim"]] for result in auth_results["dkim"]: if "domain" in result and result["domain"] is not None: @@ -159,7 +159,7 @@ def _parse_report_record(record, ip_db_path=None, offline=False, new_result["result"] = "none" new_record["auth_results"]["dkim"].append(new_result) - if type(auth_results["spf"]) != list: + if not isinstance(auth_results["spf"], list): auth_results["spf"] = [auth_results["spf"]] for result in auth_results["spf"]: new_result = OrderedDict([("domain", result["domain"])]) @@ -282,7 +282,7 @@ def parse_aggregate_report_xml(xml, ip_db_path=None, offline=False, new_report_metadata["begin_date"] = date_range["begin"] new_report_metadata["end_date"] = date_range["end"] if "error" in report["report_metadata"]: - if type(report["report_metadata"]["error"]) != list: + if not isinstance(report["report_metadata"]["error"], list): errors = [report["report_metadata"]["error"]] else: errors = report["report_metadata"]["error"] @@ -824,7 +824,7 @@ def parse_report_email(input_, offline=False, ip_db_path=None, for part in msg.walk(): content_type = part.get_content_type() payload = part.get_payload() - if type(payload) != list: + if not isinstance(payload, list): payload = [payload] payload = payload[0].__str__() if content_type == "message/feedback-report": diff --git a/parsedmarc/elastic.py b/parsedmarc/elastic.py index bfc2925..5e0652c 100644 --- a/parsedmarc/elastic.py +++ b/parsedmarc/elastic.py @@ -181,7 +181,7 @@ def set_hosts(hosts, use_ssl=False, ssl_cert_path=None, password (str): The password to use for authentication timeout (float): Timeout in seconds """ - if type(hosts) != list: + if not isinstance(hosts, list): hosts = [hosts] conn_params = { "hosts": hosts, diff --git a/parsedmarc/kafkaclient.py b/parsedmarc/kafkaclient.py index 11a913b..02bf833 100644 --- a/parsedmarc/kafkaclient.py +++ b/parsedmarc/kafkaclient.py @@ -96,8 +96,8 @@ class KafkaClient(object): aggregate_topic (str): The name of the Kafka topic """ - if (type(aggregate_reports) == dict or - type(aggregate_reports) == OrderedDict): + if (isinstance(aggregate_reports, dict) or + isinstance(aggregate_reports, OrderedDict)): aggregate_reports = [aggregate_reports] if len(aggregate_reports) < 1: @@ -141,7 +141,7 @@ class KafkaClient(object): forensic_topic (str): The name of the Kafka topic """ - if type(forensic_reports) == dict: + if isinstance(forensic_reports, dict): forensic_reports = [forensic_reports] if len(forensic_reports) < 1: diff --git a/parsedmarc/splunk.py b/parsedmarc/splunk.py index 0d11966..3628523 100644 --- a/parsedmarc/splunk.py +++ b/parsedmarc/splunk.py @@ -64,7 +64,7 @@ class HECClient(object): """ logger.debug("Saving aggregate reports to Splunk") - if type(aggregate_reports) == dict: + if isinstance(aggregate_reports, dict): aggregate_reports = [aggregate_reports] if len(aggregate_reports) < 1: @@ -130,7 +130,7 @@ class HECClient(object): to save in Splunk """ logger.debug("Saving forensic reports to Splunk") - if type(forensic_reports) == dict: + if isinstance(forensic_reports, dict): forensic_reports = [forensic_reports] if len(forensic_reports) < 1: diff --git a/parsedmarc/utils.py b/parsedmarc/utils.py index f973a37..e272848 100644 --- a/parsedmarc/utils.py +++ b/parsedmarc/utils.py @@ -409,7 +409,7 @@ def is_outlook_msg(content): Returns: bool: A flag that indicates if the file is an Outlook MSG file """ - return type(content) == bytes and content.startswith( + return isinstance(content, bytes) and content.startswith( b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1") @@ -459,7 +459,7 @@ def parse_email(data, strip_attachment_payloads=False): dict: Parsed email data """ - if type(data) == bytes: + if isinstance(data, bytes): if is_outlook_msg(data): data = convert_outlook_msg(data) data = data.decode("utf-8", errors="replace")