Skip to content

Commit

Permalink
Fix support for Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
seanthegeek committed Sep 12, 2023
1 parent 9fabd36 commit 4f61bbf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: "3.10"
python-version: "3.8"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
Expand Down
84 changes: 42 additions & 42 deletions checkdmarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""Validates and parses SPF amd DMARC DNS records"""

import logging
from typing import Union
from typing import Union, List
from collections import OrderedDict
from re import compile, IGNORECASE
import json
Expand Down Expand Up @@ -607,9 +607,9 @@ def get_base_domain(domain: str) -> str:
return psl.privatesuffix(domain) or domain


def _query_dns(domain: str, record_type: str, nameservers: list[str] = None,
def _query_dns(domain: str, record_type: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0, cache: ExpiringDict = None) -> list[str]:
timeout: float = 2.0, cache: ExpiringDict = None) -> List[str]:
"""
Queries DNS
Expand Down Expand Up @@ -659,9 +659,9 @@ def _query_dns(domain: str, record_type: str, nameservers: list[str] = None,
return records


def _get_nameservers(domain: str, nameservers: list[str] = None,
def _get_nameservers(domain: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> list[str]:
timeout: float = 2.0) -> List[str]:
"""
Queries DNS for a list of nameservers
Expand Down Expand Up @@ -694,9 +694,9 @@ def _get_nameservers(domain: str, nameservers: list[str] = None,
return answers


def _get_mx_hosts(domain: str, nameservers: list[str] = None,
def _get_mx_hosts(domain: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> list[OrderedDict]:
timeout: float = 2.0) -> List[OrderedDict]:
"""
Queries DNS for a list of Mail Exchange hosts
Expand Down Expand Up @@ -737,9 +737,9 @@ def _get_mx_hosts(domain: str, nameservers: list[str] = None,
return hosts


def _get_a_records(domain: str, nameservers: list[str] = None,
def _get_a_records(domain: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> list[str]:
timeout: float = 2.0) -> List[str]:
"""
Queries DNS for A and AAAA records
Expand Down Expand Up @@ -775,9 +775,9 @@ def _get_a_records(domain: str, nameservers: list[str] = None,
return addresses


def _get_reverse_dns(ip_address: str, nameservers: list[str] = None,
def _get_reverse_dns(ip_address: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> list[str]:
timeout: float = 2.0) -> List[str]:
"""
Queries for an IP addresses reverse DNS hostname(s)
Expand Down Expand Up @@ -807,9 +807,9 @@ def _get_reverse_dns(ip_address: str, nameservers: list[str] = None,
return hostnames


def _get_txt_records(domain: str, nameservers: list[str] = None,
def _get_txt_records(domain: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> list[str]:
timeout: float = 2.0) -> List[str]:
"""
Queries DNS for TXT records
Expand Down Expand Up @@ -841,7 +841,7 @@ def _get_txt_records(domain: str, nameservers: list[str] = None,
return records


def _query_dmarc_record(domain: str, nameservers: list[str] = None,
def _query_dmarc_record(domain: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0,
ignore_unrelated_records: bool = False
Expand Down Expand Up @@ -924,7 +924,7 @@ def _query_dmarc_record(domain: str, nameservers: list[str] = None,


def _query_bmi_record(domain: str, selector: str = "default",
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0):
"""
Expand Down Expand Up @@ -994,7 +994,7 @@ def _query_bmi_record(domain: str, selector: str = "default",
return bimi_record


def query_dmarc_record(domain: str, nameservers: list[str] = None,
def query_dmarc_record(domain: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0,
ignore_unrelated_records: bool = False) -> OrderedDict:
Expand Down Expand Up @@ -1054,7 +1054,7 @@ def query_dmarc_record(domain: str, nameservers: list[str] = None,


def query_bimi_record(domain: str, selector: str = "default",
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -1113,7 +1113,7 @@ def query_bimi_record(domain: str, selector: str = "default",

def get_dmarc_tag_description(
tag: str,
value: Union[str, list[str]] = None) -> OrderedDict:
value: Union[str, List[str]] = None) -> OrderedDict:
"""
Get the name, default value, and description for a DMARC tag, amd/or a
description for a tag value
Expand Down Expand Up @@ -1191,7 +1191,7 @@ def parse_dmarc_report_uri(uri: str) -> OrderedDict:

def check_wildcard_dmarc_report_authorization(
domain: str,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> bool:
"""
Expand Down Expand Up @@ -1244,7 +1244,7 @@ def check_wildcard_dmarc_report_authorization(

def verify_dmarc_report_destination(source_domain: str,
destination_domain: str,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> bool:
"""
Expand Down Expand Up @@ -1314,7 +1314,7 @@ def verify_dmarc_report_destination(source_domain: str,
def parse_dmarc_record(
record: str, domain: str, parked: bool = False,
include_tag_descriptions: bool = False,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0,
syntax_error_marker: str = SYNTAX_ERROR_MARKER) -> OrderedDict:
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def parse_dmarc_record(

def get_dmarc_record(domain: str,
include_tag_descriptions: bool = False,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -1604,7 +1604,7 @@ def get_dmarc_record(domain: str,


def query_spf_record(domain: str,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -1678,7 +1678,7 @@ def query_spf_record(domain: str,
def parse_spf_record(
record: str, domain: str,
parked: bool = False, seen: bool = None,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
recursion: OrderedDict = None,
timeout: float = 2.0,
Expand Down Expand Up @@ -1952,7 +1952,7 @@ def parse_spf_record(
("parsed", parsed), ("warnings", warnings)])


def get_spf_record(domain: str, nameservers: list[str] = None,
def get_spf_record(domain: str, nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -2211,9 +2211,9 @@ def test_starttls(hostname: str,


def get_mx_hosts(domain: str, skip_tls: bool = False,
approved_hostnames: list[str] = None,
approved_hostnames: List[str] = None,
parked: bool = False,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0):
"""
Expand Down Expand Up @@ -2350,8 +2350,8 @@ def get_mx_hosts(domain: str, skip_tls: bool = False,
return OrderedDict([("hosts", hosts), ("warnings", warnings)])


def get_nameservers(domain: str, approved_nameservers: list[str] = None,
nameservers: list[str] = None,
def get_nameservers(domain: str, approved_nameservers: List[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> dict:
"""
Expand Down Expand Up @@ -2392,7 +2392,7 @@ def get_nameservers(domain: str, approved_nameservers: list[str] = None,
return OrderedDict([("hostnames", ns_records), ("warnings", warnings)])


def test_dnssec(domain: str, nameservers: list[str] = None,
def test_dnssec(domain: str, nameservers: List[str] = None,
timeout: float = 2.0) -> bool:
"""
Check for DNSSEC on the given domain
Expand Down Expand Up @@ -2431,15 +2431,15 @@ def test_dnssec(domain: str, nameservers: list[str] = None,
return False


def check_domains(domains: list[str], parked: bool = False,
approved_nameservers: list[str] = None,
def check_domains(domains: List[str], parked: bool = False,
approved_nameservers: List[str] = None,
approved_mx_hostnames: bool = None,
skip_tls: bool = False,
include_dmarc_tag_descriptions: bool = False,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0,
wait: float = 0.0) -> Union[OrderedDict, list[OrderedDict]]:
wait: float = 0.0) -> Union[OrderedDict, List[OrderedDict]]:
"""
Check the given domains for SPF and DMARC records, parse them, and return
them
Expand Down Expand Up @@ -2540,8 +2540,8 @@ def check_domains(domains: list[str], parked: bool = False,


def check_ns(domain: str,
approved_nameservers: list[str] = None,
nameservers: list[str] = None,
approved_nameservers: List[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -2579,9 +2579,9 @@ def check_ns(domain: str,
return ns_results


def check_mx(domain: str, approved_mx_hostnames: list[str] = None,
def check_mx(domain: str, approved_mx_hostnames: List[str] = None,
skip_tls: bool = False,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -2629,7 +2629,7 @@ def check_mx(domain: str, approved_mx_hostnames: list[str] = None,
def check_dmarc(domain: str, parked: bool = False,
include_dmarc_tag_descriptions: bool = False,
ignore_unrelated_records: bool = False,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -2692,7 +2692,7 @@ def check_dmarc(domain: str, parked: bool = False,


def check_spf(domain: str, parked: bool = False,
nameservers: list[str] = None,
nameservers: List[str] = None,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> OrderedDict:
"""
Expand Down Expand Up @@ -2755,7 +2755,7 @@ def check_spf(domain: str, parked: bool = False,
return spf_results


def results_to_json(results: Union[dict, list[dict]]) -> str:
def results_to_json(results: Union[dict, List[dict]]) -> str:
"""
Converts a dictionary of results or list of results to a JSON string
Expand All @@ -2768,7 +2768,7 @@ def results_to_json(results: Union[dict, list[dict]]) -> str:
return json.dumps(results, ensure_ascii=False, indent=2)


def results_to_csv_rows(results: Union[dict, list[dict]]) -> list[dict]:
def results_to_csv_rows(results: Union[dict, List[dict]]) -> List[dict]:
"""
Converts a results dictionary or list of dictionaries and returns a
list of CSV row dictionaries
Expand Down

0 comments on commit 4f61bbf

Please sign in to comment.