Skip to content

Commit c444802

Browse files
committed
pylint
1 parent a2ccdca commit c444802

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

tests/email_validator.py

+36-38
Original file line numberDiff line numberDiff line change
@@ -366,39 +366,39 @@ def validate_email_domain(hostname, result_dict, global_translation, local_trans
366366

367367
# 1 - Get Email servers
368368
# dns_lookup
369-
rating, ipv4_servers, ipv6_servers = Validate_MX_Records(
369+
rating, ipv4_servers, ipv6_servers = validate_mx_records(
370370
global_translation, rating, result_dict, local_translation, hostname)
371371

372372
# If we have -1.0 in rating, we have no MX records, ignore test.
373373
if rating.get_overall() != -1.0:
374374
# 1.2 - Check operational
375375
if support_port25 and len(ipv4_servers) > 0:
376-
rating = Validate_IPv4_Operation_Status(
376+
rating = validate_ip4_operation_status(
377377
global_translation, rating, local_translation, ipv4_servers)
378378

379379
# 1.2 - Check operational
380380
if support_port25 and support_ipv6 and len(ipv6_servers) > 0:
381-
rating = Validate_IPv6_Operation_Status(
381+
rating = validate_ip6_operation_status(
382382
global_translation, rating, local_translation, ipv6_servers)
383383

384384
# 1.4 - Check TLS
385385
# 1.5 - Check PKI
386386
# 1.6 - Check DNSSEC
387387
# 1.7 - Check DANE
388388
# 1.8 - Check MTA-STS policy
389-
rating = Validate_MTA_STS_Policy(global_translation, rating, local_translation, hostname)
389+
rating = validate_mta_sts_policy(global_translation, rating, local_translation, hostname)
390390
# 1.9 - Check SPF policy
391-
rating = Validate_SPF_Policies(
391+
rating = validate_spf_policies(
392392
global_translation, rating, result_dict, local_translation, hostname)
393393
# 2.0 - Check DMARK
394-
rating = Validate_DMARC_Policies(
394+
rating = validate_dmarc_policies(
395395
global_translation, rating, result_dict, local_translation, hostname)
396396

397397

398398
return rating, result_dict
399399

400400

401-
def Validate_MTA_STS_Policy(global_translation, rating, local_translation, hostname):
401+
def validate_mta_sts_policy(global_translation, rating, local_translation, hostname):
402402
has_mta_sts_policy = False
403403
# https://www.rfc-editor.org/rfc/rfc8461#section-3.1
404404
mta_sts_results = dns_lookup('_mta-sts.' + hostname, dns.rdatatype.TXT)
@@ -471,8 +471,8 @@ def Validate_MTA_STS_Policy(global_translation, rating, local_translation, hostn
471471
has_version = True
472472
elif 'mode' in key:
473473
if value == 'enforce':
474-
a = 1
475-
elif value == 'testing' or value == 'none':
474+
_ = 1
475+
elif value in ('testing', 'none'):
476476
mta_sts_records_not_enforced_rating = Rating(
477477
global_translation, REVIEW_SHOW_IMPROVEMENTS_ONLY)
478478
mta_sts_records_not_enforced_rating.set_overall(3.0)
@@ -525,11 +525,11 @@ def Validate_MTA_STS_Policy(global_translation, rating, local_translation, hostn
525525
return rating
526526

527527

528-
def Validate_DMARC_Policies(global_translation, rating, result_dict, local_translation, hostname):
529-
dmarc_result_dict = Validate_DMARC_Policy(local_translation, hostname, result_dict)
528+
def validate_dmarc_policies(global_translation, rating, result_dict, local_translation, hostname):
529+
dmarc_result_dict = validate_dmarc_policy(local_translation, hostname, result_dict)
530530
result_dict.update(dmarc_result_dict)
531531

532-
rating = Rate_has_DMARC_Policies(global_translation, rating, result_dict, local_translation)
532+
rating = rate_has_dmarc_policies(global_translation, rating, result_dict, local_translation)
533533
# rating = Rate_Invalid_format_DMARC_Policies(
534534
# global_translation,
535535
# rating,
@@ -539,7 +539,7 @@ def Validate_DMARC_Policies(global_translation, rating, result_dict, local_trans
539539
return rating
540540

541541

542-
def Validate_DMARC_Policy(local_translation, hostname, result_dict):
542+
def validate_dmarc_policy(local_translation, hostname, result_dict):
543543
# https://proton.me/support/anti-spoofing-custom-domain
544544

545545
dmarc_results = dns_lookup(f"_dmarc.{hostname}", "TXT")
@@ -626,7 +626,7 @@ def Validate_DMARC_Policy(local_translation, hostname, result_dict):
626626
result_dict['dmarc-warnings'].append(
627627
local_translation(
628628
'TEXT_REVIEW_DMARC_FO_USES_DEFAULT'))
629-
elif field == '1' or field == 'd' or field == 's':
629+
elif field in ('1', 'd', 's'):
630630
result_dict['dmarc-fo'].append(field)
631631
else:
632632
result_dict['dmarc-errors'].append(
@@ -677,9 +677,7 @@ def Validate_DMARC_Policy(local_translation, hostname, result_dict):
677677
return result_dict
678678

679679

680-
681-
682-
def Rate_has_DMARC_Policies(global_translation, rating, result_dict, local_translation):
680+
def rate_has_dmarc_policies(global_translation, rating, result_dict, local_translation):
683681
if 'dmarc-has-policy' in result_dict:
684682
no_dmarc_record_rating = Rating(global_translation, REVIEW_SHOW_IMPROVEMENTS_ONLY)
685683
no_dmarc_record_rating.set_overall(5.0)
@@ -805,37 +803,37 @@ def Rate_has_DMARC_Policies(global_translation, rating, result_dict, local_trans
805803
return rating
806804

807805

808-
def Validate_SPF_Policies(global_translation, rating, result_dict, local_translation, hostname):
809-
spf_result_dict = Validate_SPF_Policy(
806+
def validate_spf_policies(global_translation, rating, result_dict, local_translation, hostname):
807+
spf_result_dict = validate_spf_policy(
810808
global_translation,
811809
local_translation,
812810
hostname,
813811
result_dict)
814812
result_dict.update(spf_result_dict)
815813

816-
rating = Rate_has_SPF_Policies(global_translation, rating, result_dict, local_translation)
817-
rating = Rate_Invalid_format_SPF_Policies(
814+
rating = rate_has_spf_policies(global_translation, rating, result_dict, local_translation)
815+
rating = rate_invalid_format_spf_policies(
818816
global_translation,
819817
rating,
820818
result_dict,
821819
local_translation)
822-
rating = Rate_Too_many_DNS_lookup_for_SPF_Policies(
820+
rating = rate_too_many_dns_lookup_for_spf_policies(
823821
global_translation, rating, result_dict, local_translation)
824-
rating = Rate_Use_of_PTR_for_SPF_Policies(
822+
rating = rate_use_of_ptr_for_spf_policies(
825823
global_translation,
826824
rating,
827825
result_dict,
828826
local_translation)
829827

830-
rating = Rate_Fail_Configuration_for_SPF_Policies(
828+
rating = rate_fail_configuration_for_spf_policies(
831829
global_translation, rating, result_dict, local_translation)
832830

833-
rating = Rate_GDPR_for_SPF_Policies(global_translation, rating, result_dict, local_translation)
831+
rating = rate_gdpr_for_spf_policies(global_translation, rating, result_dict, local_translation)
834832

835833
return rating
836834

837835

838-
def Rate_Use_of_PTR_for_SPF_Policies(global_translation, rating, result_dict, local_translation):
836+
def rate_use_of_ptr_for_spf_policies(global_translation, rating, result_dict, local_translation):
839837
if 'spf-uses-ptr' in result_dict:
840838
has_spf_record_ptr_being_used_rating = Rating(
841839
global_translation, REVIEW_SHOW_IMPROVEMENTS_ONLY)
@@ -847,7 +845,7 @@ def Rate_Use_of_PTR_for_SPF_Policies(global_translation, rating, result_dict, lo
847845
return rating
848846

849847

850-
def Rate_Fail_Configuration_for_SPF_Policies(
848+
def rate_fail_configuration_for_spf_policies(
851849
global_translation,
852850
rating,
853851
result_dict,
@@ -895,7 +893,7 @@ def Rate_Fail_Configuration_for_SPF_Policies(
895893
return rating
896894

897895

898-
def Rate_Invalid_format_SPF_Policies(global_translation, rating, result_dict, local_translation):
896+
def rate_invalid_format_spf_policies(global_translation, rating, result_dict, local_translation):
899897
if 'spf-uses-none-standard' in result_dict:
900898
has_spf_unknown_section_rating = Rating(
901899
global_translation, REVIEW_SHOW_IMPROVEMENTS_ONLY)
@@ -915,7 +913,7 @@ def Rate_Invalid_format_SPF_Policies(global_translation, rating, result_dict, lo
915913
return rating
916914

917915

918-
def Rate_has_SPF_Policies(global_translation, rating, result_dict, local_translation):
916+
def rate_has_spf_policies(global_translation, rating, result_dict, local_translation):
919917
has_spf_records_rating = Rating(global_translation, REVIEW_SHOW_IMPROVEMENTS_ONLY)
920918
if 'spf-has-policy' in result_dict:
921919
txt = local_translation('TEXT_REVIEW_SPF_DNS_RECORD_SUPPORT')
@@ -935,7 +933,7 @@ def Rate_has_SPF_Policies(global_translation, rating, result_dict, local_transla
935933
return rating
936934

937935

938-
def Rate_Too_many_DNS_lookup_for_SPF_Policies(
936+
def rate_too_many_dns_lookup_for_spf_policies(
939937
global_translation,
940938
rating,
941939
result_dict,
@@ -952,7 +950,7 @@ def Rate_Too_many_DNS_lookup_for_SPF_Policies(
952950
return rating
953951

954952

955-
def Rate_GDPR_for_SPF_Policies(global_translation, rating, result_dict, local_translation):
953+
def rate_gdpr_for_spf_policies(global_translation, rating, result_dict, local_translation):
956954
spf_addresses = []
957955
if 'spf-ipv4' not in result_dict:
958956
result_dict['spf-ipv4'] = []
@@ -971,7 +969,7 @@ def Rate_GDPR_for_SPF_Policies(global_translation, rating, result_dict, local_tr
971969
country_code = ''
972970
country_code = get_best_country_code(
973971
ip_address, country_code)
974-
if country_code == '' or country_code == '-':
972+
if country_code in ('', '-'):
975973
country_code = 'unknown'
976974

977975
if is_country_code_in_eu_or_on_exception_list(country_code):
@@ -1005,7 +1003,7 @@ def Rate_GDPR_for_SPF_Policies(global_translation, rating, result_dict, local_tr
10051003
return rating
10061004

10071005

1008-
def Validate_SPF_Policy(global_translation, local_translation, hostname, result_dict):
1006+
def validate_spf_policy(global_translation, local_translation, hostname, result_dict):
10091007
# https://proton.me/support/anti-spoofing-custom-domain
10101008

10111009
if 'spf-dns-lookup-count' in result_dict and result_dict['spf-dns-lookup-count'] >= 10:
@@ -1048,7 +1046,7 @@ def Validate_SPF_Policy(global_translation, local_translation, hostname, result_
10481046
result_dict['spf-ipv6'].append(data)
10491047
elif section.startswith('include:') or section.startswith('+include:'):
10501048
spf_domain = section[8:]
1051-
subresult_dict = Validate_SPF_Policy(
1049+
subresult_dict = validate_spf_policy(
10521050
global_translation, local_translation, spf_domain, result_dict)
10531051
result_dict.update(subresult_dict)
10541052
elif section.startswith('?all'):
@@ -1111,7 +1109,7 @@ def replace_network_with_first_and_last_ipaddress(spf_addresses):
11111109
spf_addresses.remove(ip_address)
11121110

11131111

1114-
def Validate_IPv6_Operation_Status(global_translation, rating, local_translation, ipv6_servers):
1112+
def validate_ip6_operation_status(global_translation, rating, local_translation, ipv6_servers):
11151113
ipv6_servers_operational = []
11161114
# 1.3 - Check Start TLS
11171115
ipv6_servers_operational_starttls = []
@@ -1161,7 +1159,7 @@ def Validate_IPv6_Operation_Status(global_translation, rating, local_translation
11611159
return rating
11621160

11631161

1164-
def Validate_IPv4_Operation_Status(global_translation, rating, local_translation, ipv4_servers):
1162+
def validate_ip4_operation_status(global_translation, rating, local_translation, ipv4_servers):
11651163
ipv4_servers_operational = []
11661164
# 1.3 - Check Start TLS
11671165
ipv4_servers_operational_starttls = []
@@ -1209,7 +1207,7 @@ def Validate_IPv4_Operation_Status(global_translation, rating, local_translation
12091207
return rating
12101208

12111209

1212-
def Validate_MX_Records(global_translation, rating, result_dict, local_translation, hostname):
1210+
def validate_mx_records(global_translation, rating, result_dict, local_translation, hostname):
12131211
email_results = dns_lookup(hostname, dns.rdatatype.MX)
12141212
email_servers = []
12151213
# 1.1 - Check IPv4 and IPv6 support
@@ -1289,7 +1287,7 @@ def Validate_MX_Records(global_translation, rating, result_dict, local_translati
12891287
country_code = ''
12901288
country_code = get_best_country_code(
12911289
ip_address, country_code)
1292-
if country_code == '' or country_code == '-':
1290+
if country_code in ('', '-'):
12931291
country_code = 'unknown'
12941292

12951293
if is_country_code_in_eu_or_on_exception_list(country_code):

0 commit comments

Comments
 (0)