Skip to content

Commit 7f8168d

Browse files
committed
blacken the repository
1 parent 21e510d commit 7f8168d

File tree

4 files changed

+494
-303
lines changed

4 files changed

+494
-303
lines changed

setup.py

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,53 @@
1111

1212

1313
def readme():
14-
with open('README.md') as f:
14+
with open("README.md") as f:
1515
return f.read()
1616

1717

18-
with open('requirements.txt') as fp:
18+
with open("requirements.txt") as fp:
1919
reqs = [line.strip() for line in fp.readlines() if line]
2020

21-
with open('requirements-dev.txt') as fp:
21+
with open("requirements-dev.txt") as fp:
2222
lines = [line.strip() for line in fp.readlines() if line]
23-
dev_reqs = [line for line in lines if line and '-r requirements.txt' not in line]
23+
dev_reqs = [line for line in lines if line and "-r requirements.txt" not in line]
2424

2525

2626
setup(
27-
name='trustymail',
27+
name="trustymail",
2828
version=__version__,
29-
description='Scan domains and return data based on trustworthy email best practices',
29+
description="Scan domains and return data based on trustworthy email best practices",
3030
long_description=readme(),
31-
long_description_content_type='text/markdown',
32-
31+
long_description_content_type="text/markdown",
3332
# NCATS "homepage"
3433
url="https://www.us-cert.gov/resources/ncats",
3534
# The project's main homepage
36-
download_url='https://github.com/cisagov/trustymail',
37-
35+
download_url="https://github.com/cisagov/trustymail",
3836
# Author details
39-
author='Cyber and Infrastructure Security Agency',
40-
author_email='[email protected]',
41-
42-
license='License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
43-
37+
author="Cyber and Infrastructure Security Agency",
38+
author_email="[email protected]",
39+
license="License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
4440
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
4541
classifiers=[
4642
# How mature is this project? Common values are
4743
# 3 - Alpha
4844
# 4 - Beta
4945
# 5 - Production/Stable
50-
'Development Status :: 4 - Beta',
51-
46+
"Development Status :: 4 - Beta",
5247
# Indicate who your project is intended for
53-
'Intended Audience :: Developers',
54-
48+
"Intended Audience :: Developers",
5549
# Pick your license as you wish (should match "license" above)
56-
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
57-
50+
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
5851
# Specify the Python versions you support here. In particular, ensure
5952
# that you indicate whether you support Python 2, Python 3 or both.
60-
'Programming Language :: Python :: 3',
61-
'Programming Language :: Python :: 3.6',
62-
'Programming Language :: Python :: 3.7',
53+
"Programming Language :: Python :: 3",
54+
"Programming Language :: Python :: 3.6",
55+
"Programming Language :: Python :: 3.7",
6356
],
64-
6557
# What does your project relate to?
66-
keywords='email authentication, STARTTLS',
67-
68-
packages=['trustymail'],
69-
58+
keywords="email authentication, STARTTLS",
59+
packages=["trustymail"],
7060
install_requires=reqs,
71-
72-
extras_require={
73-
'dev': dev_reqs,
74-
},
75-
76-
scripts=['scripts/trustymail']
61+
extras_require={"dev": dev_reqs},
62+
scripts=["scripts/trustymail"],
7763
)

trustymail/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals, absolute_import, print_function
22

3-
__version__ = '0.7.5'
3+
__version__ = "0.7.5"
44

5-
PublicSuffixListFilename = 'public_suffix_list.dat'
5+
PublicSuffixListFilename = "public_suffix_list.dat"
66
PublicSuffixListReadOnly = False

trustymail/domain.py

Lines changed: 125 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ def get_psl():
2020

2121
def download_psl():
2222
fresh_psl = publicsuffix.fetch()
23-
with open(PublicSuffixListFilename, 'w', encoding='utf-8') as fresh_psl_file:
23+
with open(PublicSuffixListFilename, "w", encoding="utf-8") as fresh_psl_file:
2424
fresh_psl_file.write(fresh_psl.read())
2525

2626
# Download the psl if necessary
2727
if not PublicSuffixListReadOnly:
2828
if not path.exists(PublicSuffixListFilename):
2929
download_psl()
3030
else:
31-
psl_age = datetime.now() - datetime.fromtimestamp(stat(PublicSuffixListFilename).st_mtime)
31+
psl_age = datetime.now() - datetime.fromtimestamp(
32+
stat(PublicSuffixListFilename).st_mtime
33+
)
3234
if psl_age > timedelta(hours=24):
3335
download_psl()
3436

35-
with open(PublicSuffixListFilename, encoding='utf-8') as psl_file:
37+
with open(PublicSuffixListFilename, encoding="utf-8") as psl_file:
3638
psl = publicsuffix.PublicSuffixList(psl_file)
3739

3840
return psl
@@ -54,13 +56,22 @@ def format_list(record_list):
5456
if not record_list:
5557
return None
5658

57-
return ', '.join(record_list)
59+
return ", ".join(record_list)
5860

5961

6062
class Domain:
6163
base_domains = {}
6264

63-
def __init__(self, domain_name, timeout, smtp_timeout, smtp_localhost, smtp_ports, smtp_cache, dns_hostnames):
65+
def __init__(
66+
self,
67+
domain_name,
68+
timeout,
69+
smtp_timeout,
70+
smtp_localhost,
71+
smtp_ports,
72+
smtp_cache,
73+
dns_hostnames,
74+
):
6475
self.domain_name = domain_name.lower()
6576

6677
self.base_domain_name = get_public_suffix(self.domain_name)
@@ -71,7 +82,16 @@ def __init__(self, domain_name, timeout, smtp_timeout, smtp_localhost, smtp_port
7182
self.is_base_domain = False
7283
if self.base_domain_name not in Domain.base_domains:
7384
# Populate DMARC for parent.
74-
domain = trustymail.scan(self.base_domain_name, timeout, smtp_timeout, smtp_localhost, smtp_ports, smtp_cache, {'mx': False, 'starttls': False, 'spf': False, 'dmarc': True}, dns_hostnames)
85+
domain = trustymail.scan(
86+
self.base_domain_name,
87+
timeout,
88+
smtp_timeout,
89+
smtp_localhost,
90+
smtp_ports,
91+
smtp_cache,
92+
{"mx": False, "starttls": False, "spf": False, "dmarc": True},
93+
dns_hostnames,
94+
)
7595
Domain.base_domains[self.base_domain_name] = domain
7696
self.base_domain = Domain.base_domains[self.base_domain_name]
7797

@@ -127,8 +147,15 @@ def has_supports_smtp(self):
127147
"""
128148
result = None
129149
if len(self.starttls_results) > 0:
130-
result = len(filter(lambda x: self.starttls_results[x]['supports_smtp'],
131-
self.starttls_results.keys())) > 0
150+
result = (
151+
len(
152+
filter(
153+
lambda x: self.starttls_results[x]["supports_smtp"],
154+
self.starttls_results.keys(),
155+
)
156+
)
157+
> 0
158+
)
132159
return result
133160

134161
def has_starttls(self):
@@ -138,8 +165,15 @@ def has_starttls(self):
138165
"""
139166
result = None
140167
if len(self.starttls_results) > 0:
141-
result = len(filter(lambda x: self.starttls_results[x]['starttls'],
142-
self.starttls_results.keys())) > 0
168+
result = (
169+
len(
170+
filter(
171+
lambda x: self.starttls_results[x]["starttls"],
172+
self.starttls_results.keys(),
173+
)
174+
)
175+
> 0
176+
)
143177
return result
144178

145179
def has_spf(self):
@@ -160,7 +194,7 @@ def add_mx_record(self, record):
160194
# the record will contain a trailing period if it is a FQDN.
161195
if self.mail_servers is None:
162196
self.mail_servers = []
163-
self.mail_servers.append(record.exchange.to_text().rstrip('.').lower())
197+
self.mail_servers.append(record.exchange.to_text().rstrip(".").lower())
164198

165199
def parent_has_dmarc(self):
166200
ans = self.has_dmarc()
@@ -190,7 +224,7 @@ def get_dmarc_policy(self):
190224
ans = self.dmarc_policy
191225
# If the policy was never set, or isn't in the list of valid
192226
# policies, check the parents.
193-
if ans is None or ans.lower() not in ['quarantine', 'reject', 'none']:
227+
if ans is None or ans.lower() not in ["quarantine", "reject", "none"]:
194228
if self.base_domain:
195229
# We check the *subdomain* policy in case one was
196230
# explicitly set. If one was not explicitly set then
@@ -207,7 +241,7 @@ def get_dmarc_subdomain_policy(self):
207241
ans = self.dmarc_subdomain_policy
208242
# If the policy was never set, or isn't in the list of valid
209243
# policies, check the parents.
210-
if ans is None or ans.lower() not in ['quarantine', 'reject', 'none']:
244+
if ans is None or ans.lower() not in ["quarantine", "reject", "none"]:
211245
if self.base_domain:
212246
ans = self.base_domain.get_dmarc_subdomain_policy()
213247
else:
@@ -256,57 +290,84 @@ def generate_results(self):
256290
mail_servers_that_support_smtp = None
257291
mail_servers_that_support_starttls = None
258292
else:
259-
mail_servers_that_support_smtp = [x for x in self.starttls_results.keys() if self.starttls_results[x][
260-
'supports_smtp']]
261-
mail_servers_that_support_starttls = [x for x in self.starttls_results.keys() if self.starttls_results[x][
262-
'starttls']]
293+
mail_servers_that_support_smtp = [
294+
x
295+
for x in self.starttls_results.keys()
296+
if self.starttls_results[x]["supports_smtp"]
297+
]
298+
mail_servers_that_support_starttls = [
299+
x
300+
for x in self.starttls_results.keys()
301+
if self.starttls_results[x]["starttls"]
302+
]
263303
domain_supports_smtp = bool(mail_servers_that_support_smtp)
264-
domain_supports_starttls = domain_supports_smtp and all([self.starttls_results[x]['starttls'] for x in mail_servers_that_support_smtp])
265-
266-
results = OrderedDict([
267-
('Domain', self.domain_name),
268-
('Base Domain', self.base_domain_name),
269-
('Live', self.is_live),
270-
271-
('MX Record', self.has_mail()),
272-
('MX Record DNSSEC', self.mx_records_dnssec),
273-
('Mail Servers', format_list(self.mail_servers)),
274-
('Mail Server Ports Tested', format_list([str(port) for port in self.ports_tested])),
275-
('Domain Supports SMTP Results', format_list(mail_servers_that_support_smtp)),
276-
# True if and only if at least one mail server speaks SMTP
277-
('Domain Supports SMTP', domain_supports_smtp),
278-
('Domain Supports STARTTLS Results', format_list(mail_servers_that_support_starttls)),
279-
# True if and only if all mail servers that speak SMTP
280-
# also support STARTTLS
281-
('Domain Supports STARTTLS', domain_supports_starttls),
282-
283-
('SPF Record', self.has_spf()),
284-
('SPF Record DNSSEC', self.spf_dnssec),
285-
('Valid SPF', self.valid_spf),
286-
('SPF Results', format_list(self.spf)),
287-
288-
('DMARC Record', self.has_dmarc()),
289-
('DMARC Record DNSSEC', self.dmarc_dnssec),
290-
('Valid DMARC', self.has_dmarc() and self.valid_dmarc),
291-
('DMARC Results', format_list(self.dmarc)),
292-
293-
('DMARC Record on Base Domain', self.parent_has_dmarc()),
294-
('DMARC Record on Base Domain DNSSEC', self.parent_dmarc_dnssec()),
295-
('Valid DMARC Record on Base Domain', self.parent_has_dmarc() and self.parent_valid_dmarc()),
296-
('DMARC Results on Base Domain', self.parent_dmarc_results()),
297-
('DMARC Policy', self.get_dmarc_policy()),
298-
('DMARC Subdomain Policy', self.get_dmarc_subdomain_policy()),
299-
('DMARC Policy Percentage', self.get_dmarc_pct()),
300-
301-
("DMARC Aggregate Report URIs", format_list(self.get_dmarc_aggregate_uris())),
302-
("DMARC Forensic Report URIs", format_list(self.get_dmarc_forensic_uris())),
303-
304-
('DMARC Has Aggregate Report URI', self.get_dmarc_has_aggregate_uri()),
305-
('DMARC Has Forensic Report URI', self.get_dmarc_has_forensic_uri()),
306-
('DMARC Reporting Address Acceptance Error', self.dmarc_reports_address_error),
307-
308-
('Syntax Errors', format_list(self.syntax_errors)),
309-
('Debug Info', format_list(self.debug_info))
310-
])
304+
domain_supports_starttls = domain_supports_smtp and all(
305+
[
306+
self.starttls_results[x]["starttls"]
307+
for x in mail_servers_that_support_smtp
308+
]
309+
)
310+
311+
results = OrderedDict(
312+
[
313+
("Domain", self.domain_name),
314+
("Base Domain", self.base_domain_name),
315+
("Live", self.is_live),
316+
("MX Record", self.has_mail()),
317+
("MX Record DNSSEC", self.mx_records_dnssec),
318+
("Mail Servers", format_list(self.mail_servers)),
319+
(
320+
"Mail Server Ports Tested",
321+
format_list([str(port) for port in self.ports_tested]),
322+
),
323+
(
324+
"Domain Supports SMTP Results",
325+
format_list(mail_servers_that_support_smtp),
326+
),
327+
# True if and only if at least one mail server speaks SMTP
328+
("Domain Supports SMTP", domain_supports_smtp),
329+
(
330+
"Domain Supports STARTTLS Results",
331+
format_list(mail_servers_that_support_starttls),
332+
),
333+
# True if and only if all mail servers that speak SMTP
334+
# also support STARTTLS
335+
("Domain Supports STARTTLS", domain_supports_starttls),
336+
("SPF Record", self.has_spf()),
337+
("SPF Record DNSSEC", self.spf_dnssec),
338+
("Valid SPF", self.valid_spf),
339+
("SPF Results", format_list(self.spf)),
340+
("DMARC Record", self.has_dmarc()),
341+
("DMARC Record DNSSEC", self.dmarc_dnssec),
342+
("Valid DMARC", self.has_dmarc() and self.valid_dmarc),
343+
("DMARC Results", format_list(self.dmarc)),
344+
("DMARC Record on Base Domain", self.parent_has_dmarc()),
345+
("DMARC Record on Base Domain DNSSEC", self.parent_dmarc_dnssec()),
346+
(
347+
"Valid DMARC Record on Base Domain",
348+
self.parent_has_dmarc() and self.parent_valid_dmarc(),
349+
),
350+
("DMARC Results on Base Domain", self.parent_dmarc_results()),
351+
("DMARC Policy", self.get_dmarc_policy()),
352+
("DMARC Subdomain Policy", self.get_dmarc_subdomain_policy()),
353+
("DMARC Policy Percentage", self.get_dmarc_pct()),
354+
(
355+
"DMARC Aggregate Report URIs",
356+
format_list(self.get_dmarc_aggregate_uris()),
357+
),
358+
(
359+
"DMARC Forensic Report URIs",
360+
format_list(self.get_dmarc_forensic_uris()),
361+
),
362+
("DMARC Has Aggregate Report URI", self.get_dmarc_has_aggregate_uri()),
363+
("DMARC Has Forensic Report URI", self.get_dmarc_has_forensic_uri()),
364+
(
365+
"DMARC Reporting Address Acceptance Error",
366+
self.dmarc_reports_address_error,
367+
),
368+
("Syntax Errors", format_list(self.syntax_errors)),
369+
("Debug Info", format_list(self.debug_info)),
370+
]
371+
)
311372

312373
return results

0 commit comments

Comments
 (0)