Skip to content

Commit

Permalink
Update code style for Black 23.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Apr 26, 2023
1 parent 024867c commit 8ac8a30
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 374 deletions.
18 changes: 4 additions & 14 deletions irrd/integration_tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,7 @@ def _start_irrds(self):
os.mkdir(self.piddir1)
os.mkdir(self.piddir2)

print(
textwrap.dedent(
f"""
print(textwrap.dedent(f"""
Preparing to start IRRd for integration test.
IRRd #1 running on HTTP port {self.port_http1}, whois port {self.port_whois1}
Expand All @@ -824,9 +822,7 @@ def _start_irrds(self):
Database URL: {self.database_url2}
PID file: {self.pidfile2}
Logfile: {self.logfile2}
"""
)
)
"""))

with open(self.roa_source1, "w") as roa_file:
ujson.dump(
Expand Down Expand Up @@ -969,9 +965,7 @@ def _submit_update(self, config_path, request):
with a specific config path. Request is the raw RPSL update, possibly
signed with inline PGP.
"""
email = (
textwrap.dedent(
"""
email = textwrap.dedent("""
From [email protected]@localhost Thu Jan 5 10:04:48 2018
Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1])
by hostname (Postfix) with ESMTPS id 740AD310597
Expand All @@ -987,11 +981,7 @@ def _submit_update(self, config_path, request):
Content-Type: text/plain; charset=utf-8
Mime-Version: 1.0
"""
)
.lstrip()
.encode("utf-8")
)
""").lstrip().encode("utf-8")
email += base64.b64encode(request.encode("utf-8"))

script = IRRD_ROOT_PATH + "/irrd/scripts/submit_email.py"
Expand Down
45 changes: 10 additions & 35 deletions irrd/mirroring/tests/test_nrtm_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ def test_generate_serial_range_v3(self, prepare_generator):
generator, mock_dh = prepare_generator
result = generator.generate("TEST", "3", 110, 190, mock_dh)

assert (
result
== textwrap.dedent(
"""
assert result == textwrap.dedent("""
%START Version: 3 TEST 110-190
ADD 120
Expand All @@ -72,18 +69,13 @@ def test_generate_serial_range_v3(self, prepare_generator):
object 2 🌈
%END TEST"""
).strip()
)
%END TEST""").strip()

def test_generate_serial_range_v1(self, prepare_generator):
generator, mock_dh = prepare_generator
result = generator.generate("TEST", "1", 110, 190, mock_dh)

assert (
result
== textwrap.dedent(
"""
assert result == textwrap.dedent("""
%START Version: 1 TEST 110-190
ADD
Expand All @@ -95,18 +87,13 @@ def test_generate_serial_range_v1(self, prepare_generator):
object 2 🌈
%END TEST"""
).strip()
)
%END TEST""").strip()

def test_generate_until_last(self, prepare_generator, config_override):
generator, mock_dh = prepare_generator
result = generator.generate("TEST", "3", 110, None, mock_dh)

assert (
result
== textwrap.dedent(
"""
assert result == textwrap.dedent("""
%START Version: 3 TEST 110-200
ADD 120
Expand All @@ -118,9 +105,7 @@ def test_generate_until_last(self, prepare_generator, config_override):
object 2 🌈
%END TEST"""
).strip()
)
%END TEST""").strip()

def test_serial_range_start_higher_than_low(self, prepare_generator):
generator, mock_dh = prepare_generator
Expand Down Expand Up @@ -208,10 +193,7 @@ def test_v3_range_limit_not_set(self, prepare_generator, config_override):

result = generator.generate("TEST", "3", 110, 190, mock_dh)

assert (
result
== textwrap.dedent(
"""
assert result == textwrap.dedent("""
%START Version: 3 TEST 110-190
ADD 120
Expand All @@ -223,9 +205,7 @@ def test_v3_range_limit_not_set(self, prepare_generator, config_override):
object 2 🌈
%END TEST"""
).strip()
)
%END TEST""").strip()

def test_range_limit_exceeded(self, prepare_generator, config_override):
generator, mock_dh = prepare_generator
Expand All @@ -248,10 +228,7 @@ def test_include_auth_hash(self, prepare_generator):
generator, mock_dh = prepare_generator
result = generator.generate("TEST", "3", 110, 190, mock_dh, False)

assert (
result
== textwrap.dedent(
"""
assert result == textwrap.dedent("""
%START Version: 3 TEST 110-190
ADD 120
Expand All @@ -263,6 +240,4 @@ def test_include_auth_hash(self, prepare_generator):
object 2 🌈
%END TEST"""
).strip()
)
%END TEST""").strip()
7 changes: 2 additions & 5 deletions irrd/rpki/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,12 @@ def render_rpsl_text(self, last_modified=None):
remarks_fill = RPSL_ATTRIBUTE_TEXT_WIDTH * " "
remarks = get_setting("rpki.pseudo_irr_remarks").replace("\n", "\n" + remarks_fill).strip()
remarks = remarks.format(asn=self.asn, prefix=self.prefix_str)
rpsl_object_text = (
f"""
rpsl_object_text = f"""
{object_class_display}{self.prefix_str}
descr: RPKI ROA for {self.prefix_str} / AS{self.asn}
remarks: {remarks}
max-length: {self.max_length}
origin: AS{self.asn}
source: {RPKI_IRR_PSEUDO_SOURCE} # Trust Anchor: {self.trust_anchor}
""".strip()
+ "\n"
)
""".strip() + "\n"
return rpsl_object_text
10 changes: 2 additions & 8 deletions irrd/rpki/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,7 @@ def test_valid_process(self, monkeypatch, mock_scopefilter):
"rpki_max_length": 26,
"source": "RPKI",
}
assert (
roa_importer.roa_objs[0]._rpsl_object.render_rpsl_text()
== textwrap.dedent(
"""
assert roa_importer.roa_objs[0]._rpsl_object.render_rpsl_text() == textwrap.dedent("""
route: 192.0.2.0/24
descr: RPKI ROA for 192.0.2.0/24 / AS64496
remarks: This AS64496 route object represents routing data retrieved
Expand All @@ -207,10 +204,7 @@ def test_valid_process(self, monkeypatch, mock_scopefilter):
max-length: 26
origin: AS64496
source: RPKI # Trust Anchor: APNIC RPKI Root
"""
).strip()
+ "\n"
)
""").strip() + "\n"

def test_invalid_rpki_json(self, monkeypatch, mock_scopefilter):
mock_dh = Mock(spec=DatabaseHandler)
Expand Down
9 changes: 2 additions & 7 deletions irrd/rpki/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ def test_notify_regular(self, monkeypatch, config_override):
expected_recipients = {"[email protected]", "[email protected]", "[email protected]"}
assert actual_recipients == expected_recipients
assert mock_email.mock_calls[0][1][1] == "route(6) objects in TEST marked RPKI invalid"
assert (
mock_email.mock_calls[0][1][2]
== textwrap.dedent(
"""
assert mock_email.mock_calls[0][1][2] == textwrap.dedent("""
This is to notify that 1 route(6) objects for which you are a
contact have been marked as RPKI invalid. This concerns
objects in the TEST database.
Expand Down Expand Up @@ -124,9 +121,7 @@ def test_notify_regular(self, monkeypatch, config_override):
mnt-by: DOESNOTEXIST-MNT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
).strip()
)
""").strip()

def test_notify_disabled(self, monkeypatch, config_override):
config_override(
Expand Down
8 changes: 2 additions & 6 deletions irrd/scripts/expire_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@ def expire_journal(skip_confirmation: bool, expire_before: datetime, source: str
return 1

if not skip_confirmation:
print(
textwrap.dedent(
f"""
print(textwrap.dedent(f"""
Found {affected_object_count} journal entries to delete from the journal for {source}.
This is the only record of history kept by IRRd itself.
After deletion, this can not be recovered.
To confirm deleting these entries for {source}, type 'yes':
"""
).strip()
)
""").strip())
confirmation = input("> ")
if confirmation != "yes":
print("Deletion cancelled.")
Expand Down
12 changes: 4 additions & 8 deletions irrd/scripts/irr_rpsl_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,7 @@ def format_as_text(response):
Format an IRRd HTTP response into a human-friendly text.
"""
summary = response["summary"]
user_report = textwrap.dedent(
f"""
user_report = textwrap.dedent(f"""
SUMMARY OF UPDATE:
Number of objects found: {summary["objects_found"]:3}
Expand All @@ -658,8 +657,7 @@ def format_as_text(response):
DETAILED EXPLANATION:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
)
""")
for object_result in response["objects"]:
user_report += "---\n"
user_report += format_report_object(object_result)
Expand Down Expand Up @@ -776,8 +774,7 @@ def metadata(metadata_values):
except IndexError as error:
raise ValueError() from error

description = textwrap.dedent(
"""\
description = textwrap.dedent("""\
Read RPSL submissions from stdin and return a response on stdout.
Errors or debug info are printed to stderr. This program accepts
the arguments for irrdv3's version of irr_rpsl_submit but ignores
Expand All @@ -804,8 +801,7 @@ def metadata(metadata_values):
16 - unexpected response
32 - an unidentified error
"""
)
""")

parser = argparse.ArgumentParser(
add_help=False,
Expand Down
16 changes: 4 additions & 12 deletions irrd/scripts/irrd_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def user_mfa_clear(email, session_provider: ORMSessionProvider):
+ (["TOTP"] if user.has_totp else [])
)

click.echo(
textwrap.dedent(
f"""
click.echo(textwrap.dedent(f"""
You are about to remove multi-factor authentication for user:
{user.name} ({user.email})
Expand All @@ -76,9 +74,7 @@ def user_mfa_clear(email, session_provider: ORMSessionProvider):
It is your own responsibility to determine that the legitimate
user has lost access to their two-factor methods.
The user will be notified of this change.
"""
)
)
"""))
click.confirm(f"Are you sure you want to remove two-factor authentication for {email}?", abort=True)
for webauthn in user.webauthns:
session_provider.session.delete(webauthn)
Expand Down Expand Up @@ -116,16 +112,12 @@ def user_change_override(email: str, enable: bool, session_provider: ORMSessionP
raise click.ClickException("User already has no override permission.")

if enable:
click.echo(
textwrap.dedent(
f"""
click.echo(textwrap.dedent(f"""
You are about to assign override permission for user:
{user.name} ({user.email})
This will allow the user to edit any object in the database.
"""
)
)
"""))
click.confirm(f"Are you sure you want to assign this permission to {email}?", abort=True)

user.override = enable
Expand Down
5 changes: 1 addition & 4 deletions irrd/server/graphql/tests/test_schema_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def test_schema_generator():
assert generator.graphql_types["RPSLAsBlock"]["descr"] == "[String!]"
assert generator.graphql_types["RPSLAsBlock"]["techCObjs"] == "[RPSLContactUnion!]"
assert generator.graphql_types["RPSLRtrSet"]["rtr-set"] == "String"
assert (
generator.type_defs
== """enum RPKIStatus {
assert generator.type_defs == """enum RPKIStatus {
valid
invalid
not_found
Expand Down Expand Up @@ -570,4 +568,3 @@ def test_schema_generator():
}
union RPSLContactUnion = RPSLPerson | RPSLRole"""
)
Loading

0 comments on commit 8ac8a30

Please sign in to comment.