@@ -23,8 +23,6 @@ def sum_sysv(data: bytes) -> str:
23
23
return f"{ checksum :03} { - (len (data )// - 512 )} "
24
24
25
25
26
- SUM_ALGORITHMS = {"bsd" :sum_bsd ,"sysv" :sum_sysv }
27
-
28
26
parser = core .ExtendedOptionParser (
29
27
usage = "%prog [OPTION] [FILE]..." ,
30
28
)
@@ -33,15 +31,15 @@ def sum_sysv(data: bytes) -> str:
33
31
"-r" ,
34
32
dest = "algorithm" ,
35
33
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) " ,
39
37
)
40
38
parser .add_option (
41
39
"-s" ,
42
40
dest = "algorithm" ,
43
41
action = "store_const" ,
44
- const = "sysv" ,
42
+ const = sum_sysv ,
45
43
help = "use the System V sum algorithm (512B blocks)" ,
46
44
)
47
45
@@ -52,11 +50,11 @@ def python_userland_sum(opts, args: list[str]) -> int:
52
50
53
51
for name in args or ["-" ]:
54
52
if name == "-" :
55
- print (SUM_ALGORITHMS [ opts .algorithm ] (sys .stdin .buffer .read ()))
53
+ print (opts .algorithm (sys .stdin .buffer .read ()))
56
54
else :
57
55
try :
58
56
with open (name ,"rb" )as f :
59
- print (f"{ SUM_ALGORITHMS [ opts .algorithm ] (f .read ())} { name } " )
57
+ print (f"{ opts .algorithm (f .read ())} { name } " )
60
58
except OSError as e :
61
59
failed = True
62
60
core .perror (e )