File tree 5 files changed +30
-37
lines changed
5 files changed +30
-37
lines changed Original file line number Diff line number Diff line change @@ -44,9 +44,13 @@ def create_utility(
44
44
func : Callable [[Values , list [Any ]], int ],
45
45
) -> Callable [[], None ]:
46
46
def execute_utility ():
47
- sys .exit (
47
+ try :
48
+ sys .exit (
48
49
func (* parser .parse_args ()) if parser else func (Values (), sys .argv [1 :])
49
50
)
51
+ except KeyboardInterrupt :
52
+ print ()
53
+ sys .exit (130 )
50
54
51
55
return execute_utility
52
56
Original file line number Diff line number Diff line change @@ -111,29 +111,25 @@ def format_exponents(factors: Iterable[int]) -> str:
111
111
def python_userland_factor (opts , args : list [str ]) -> int :
112
112
failed = False
113
113
114
- try :
115
- for arg in args or core .readwords_stdin ():
116
- try :
117
- num = int (arg )
118
- if num < 0 :
119
- raise ValueError
120
- except ValueError :
121
- failed = True
122
- core .perror (f"'{ arg } ' is not a valid positive integer" )
123
- continue
124
-
125
- if num < 2 :
126
- print (f"{ num } :" )
127
- continue
128
-
129
- factors = sorted (factorize (num ))
130
-
131
- print (
132
- f"{ num } : { format_exponents (factors ) if opts .exponents
133
- else " " .join (map (str , factors ))} "
134
- )
135
- except KeyboardInterrupt :
136
- print ()
137
- return 130
114
+ for arg in args or core .readwords_stdin ():
115
+ try :
116
+ num = int (arg )
117
+ if num < 0 :
118
+ raise ValueError
119
+ except ValueError :
120
+ failed = True
121
+ core .perror (f"'{ arg } ' is not a valid positive integer" )
122
+ continue
123
+
124
+ if num < 2 :
125
+ print (f"{ num } :" )
126
+ continue
127
+
128
+ factors = sorted (factorize (num ))
129
+
130
+ print (
131
+ f"{ num } : { format_exponents (factors ) if opts .exponents
132
+ else " " .join (map (str , factors ))} "
133
+ )
138
134
139
135
return int (failed )
Original file line number Diff line number Diff line change @@ -36,13 +36,9 @@ def python_userland_reset(opts, args: list[str]) -> int:
36
36
if opts .q :
37
37
if not term :
38
38
core .perror ("unknown terminal type " )
39
- try :
40
- while True :
41
- if term := input ("Terminal type? " ):
42
- break
43
- except KeyboardInterrupt :
44
- print ()
45
- return 130
39
+ while True :
40
+ if term := input ("Terminal type? " ):
41
+ break
46
42
47
43
print (term )
48
44
return 0
Original file line number Diff line number Diff line change @@ -28,10 +28,6 @@ def python_userland_sleep(_, args) -> int:
28
28
parser .error (f"invalid duration: { spec } " )
29
29
total_secs += Decimal (spec [:- 1 ]) * multiplier
30
30
31
- try :
32
- time .sleep (float (total_secs ))
33
- except KeyboardInterrupt :
34
- print ()
35
- return 130
31
+ time .sleep (float (total_secs ))
36
32
37
33
return 0
Original file line number Diff line number Diff line change @@ -14,4 +14,5 @@ def python_userland_yes(_, args) -> int:
14
14
while True :
15
15
print (string )
16
16
except KeyboardInterrupt :
17
+ # Do not emit a trailing newline on keyboard interrupt.
17
18
return 130
You can’t perform that action at this time.
0 commit comments