Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae99579

Browse files
committed
sum: Refactor algorithm selection
1 parent3b05327 commitae99579

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

‎userland/utilities/sum.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def sum_sysv(data: bytes) -> str:
2323
returnf"{checksum:03}{-(len(data)//-512)}"
2424

2525

26-
SUM_ALGORITHMS= {"bsd":sum_bsd,"sysv":sum_sysv}
27-
2826
parser=core.ExtendedOptionParser(
2927
usage="%prog [OPTION] [FILE]...",
3028
)
@@ -33,15 +31,15 @@ def sum_sysv(data: bytes) -> str:
3331
"-r",
3432
dest="algorithm",
3533
action="store_const",
36-
const="bsd",
37-
default="bsd",
38-
help="use the BSD (16-bit) checksum algorithm (1KiB blocks)",
34+
const=sum_bsd,
35+
default=sum_bsd,
36+
help="use the BSD (16-bit) checksum algorithm (1KiB blocks) (default)",
3937
)
4038
parser.add_option(
4139
"-s",
4240
dest="algorithm",
4341
action="store_const",
44-
const="sysv",
42+
const=sum_sysv,
4543
help="use the System V sum algorithm (512B blocks)",
4644
)
4745

@@ -52,11 +50,11 @@ def python_userland_sum(opts, args: list[str]) -> int:
5250

5351
fornameinargsor ["-"]:
5452
ifname=="-":
55-
print(SUM_ALGORITHMS[opts.algorithm](sys.stdin.buffer.read()))
53+
print(opts.algorithm(sys.stdin.buffer.read()))
5654
else:
5755
try:
5856
withopen(name,"rb")asf:
59-
print(f"{SUM_ALGORITHMS[opts.algorithm](f.read())}{name}")
57+
print(f"{opts.algorithm(f.read())}{name}")
6058
exceptOSErrorase:
6159
failed=True
6260
core.perror(e)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp