Skip to content

Commit

Permalink
contrib: bpf_inspect: adjust syntax for python < 3.12
Browse files Browse the repository at this point in the history
Python 3.12 introduces the ability to nest the quote character within
f-strings. Previously, this was not allowed. While contrib scripts don't
have any specific requirement for code quality or compatibility, it
would be nice to make this runnable on Python versions prior to 3.12.

Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 authored and osandov committed Jul 11, 2024
1 parent d564e96 commit 5dd3f47
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions contrib/bpf_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ def list_bpf_progs(show_details=False):
print(f"\tlinked: {BpfProg(linked_prog)}")

for map_ in bpf_prog.get_used_maps():
print(f"\t{"used map:":9} {map_}")
print(f"\t{'used map:':9} {map_}")

for index, subprog in bpf_prog.get_subprogs():
print(f"\t{f"func[{index:>2}]:":9} {subprog}")
print(f"\t{f'func[{index:>2}]:':9} {subprog}")


def __list_bpf_progs(args):
Expand Down Expand Up @@ -242,16 +242,16 @@ def __repr__(self):
array = self.get_prog_array()
poke_progs = self.get_poke_progs()

owner_str = f"{"owner:":9} {owner}" if owner else ""
owner_str = f"{'owner:':9} {owner}" if owner else ""
array_str = (
"\n\t".join(
f"{f"idx[{index:>3}]:":9} {BpfProg(prog)}" for index, prog in array
f"{f'idx[{index:>3}]:':9} {BpfProg(prog)}" for index, prog in array
)
if array
else ""
)
poke_progs_str = (
"\n\t".join(f"{"poke:":9} {BpfProg(poke)}" for poke in poke_progs)
"\n\t".join(f"{'poke:':9} {BpfProg(poke)}" for poke in poke_progs)
if poke_progs
else ""
)
Expand Down Expand Up @@ -345,7 +345,7 @@ def __repr__(self):
mode = self.get_mode()

ifname, ifindex = dev.name.string_().decode(), dev.ifindex.value_()
return f"{"netdev:":<9} {ifname}({ifindex})" + f"\n\t{"mode:":<9} {mode}"
return f"{'netdev:':<9} {ifname}({ifindex})" + f"\n\t{'mode:':<9} {mode}"


def show_bpf_link_details(link):
Expand Down

0 comments on commit 5dd3f47

Please sign in to comment.