@@ -303,21 +303,6 @@ class EmptyStatement(Exception):
303303DisabledCommand = namedtuple ('DisabledCommand' , ['command_function' , 'help_function' ])
304304
305305
306- class RedirectionSavedState (object ):
307- # Created by each command to store information about their redirection
308- def __init__ (self ):
309- # Tells if the command is redirecting
310- self .redirecting = False
311-
312- # If the command created a process to pipe to, then then is its reader
313- self .pipe_proc_reader = None
314-
315- # Used to restore values after the command ends
316- self .saved_self_stdout = None
317- self .saved_sys_stdout = None
318- self .saved_pipe_proc_reader = None
319-
320-
321306class Cmd (cmd .Cmd ):
322307 """An easy but powerful framework for writing line-oriented command interpreters.
323308
@@ -433,12 +418,11 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, persistent
433418 # Used load command to store the current script dir as a LIFO queue to support _relative_load command
434419 self ._script_dir = []
435420
436- # A flag used to protect critical sections in the main thread from stopping due to a KeyboardInterrupt
421+ # Context manager used to protect critical sections in the main thread from stopping due to a KeyboardInterrupt
437422 self .sigint_protection = utils .ContextFlag ()
438423
439424 # If the current command created a process to pipe to, then this will be a ProcReader object.
440- # Otherwise the value will be None. This member is used to know when a pipe process can be killed
441- # and also waited upon.
425+ # Otherwise it will be None. Its used to know when a pipe process can be killed and/or waited upon.
442426 self .cur_pipe_proc_reader = None
443427
444428 # Used by complete() for readline tab completion
@@ -1724,7 +1708,7 @@ def onecmd_plus_hooks(self, line: str) -> bool:
17241708 # Keep track of whether or not we were already redirecting before this command
17251709 already_redirecting = self .redirecting
17261710
1727- # This will be a RedirectionSavedState object for the command
1711+ # This will be a utils. RedirectionSavedState object for the command
17281712 saved_state = None
17291713
17301714 try :
@@ -1900,22 +1884,19 @@ def _complete_statement(self, line: str) -> Statement:
19001884 raise EmptyStatement ()
19011885 return statement
19021886
1903- def _redirect_output (self , statement : Statement ) -> Tuple [bool , RedirectionSavedState ]:
1887+ def _redirect_output (self , statement : Statement ) -> Tuple [bool , utils . RedirectionSavedState ]:
19041888 """Handles output redirection for >, >>, and |.
19051889
19061890 :param statement: a parsed statement from the user
1907- :return: A bool telling if an error occurred and a RedirectionSavedState object
1891+ :return: A bool telling if an error occurred and a utils. RedirectionSavedState object
19081892 """
19091893 import io
19101894 import subprocess
19111895
19121896 redir_error = False
19131897
19141898 # Initialize the saved state
1915- saved_state = RedirectionSavedState ()
1916- saved_state .saved_self_stdout = self .stdout
1917- saved_state .saved_sys_stdout = sys .stdout
1918- saved_state .saved_pipe_proc_reader = self .cur_pipe_proc_reader
1899+ saved_state = utils .RedirectionSavedState (self .stdout , sys .stdout , self .cur_pipe_proc_reader )
19191900
19201901 if not self .allow_redirection :
19211902 return redir_error , saved_state
@@ -1990,7 +1971,7 @@ def _redirect_output(self, statement: Statement) -> Tuple[bool, RedirectionSaved
19901971
19911972 return redir_error , saved_state
19921973
1993- def _restore_output (self , statement : Statement , saved_state : RedirectionSavedState ) -> None :
1974+ def _restore_output (self , statement : Statement , saved_state : utils . RedirectionSavedState ) -> None :
19941975 """Handles restoring state after output redirection as well as
19951976 the actual pipe operation if present.
19961977
0 commit comments