Example #1
0
    def _restructure_output(self,
                            output: bytes,
                            strip_prompt: bool = False) -> bytes:
        """
        Clean up preceding empty lines, and strip prompt if desired

        Args:
            output: bytes from channel
            strip_prompt: bool True/False whether to strip prompt or not

        Returns:
            bytes: output of joined output lines optionally with prompt removed

        Raises:
            N/A

        """
        output = normalize_lines(output=output)

        if strip_prompt:
            # could be compiled elsewhere, but allow users to modify the prompt whenever they want
            prompt_pattern = get_prompt_pattern(
                prompt="", class_prompt=self.comms_prompt_pattern)
            output = re.sub(pattern=prompt_pattern, repl=b"", string=output)

        # lstrip the return character out of the final result before storing, also remove any extra
        # whitespace to the right if any
        output = output.lstrip(self.comms_return_char.encode()).rstrip()
        return output
Example #2
0
    def _restructure_output(self,
                            output: bytes,
                            strip_prompt: bool = False) -> bytes:
        """
        Clean up preceding empty lines, and strip prompt if desired

        Args:
            output: bytes from channel
            strip_prompt: bool True/False whether to strip prompt or not

        Returns:
            bytes: output of joined output lines optionally with prompt removed

        Raises:
            N/A

        """
        output = normalize_lines(output=output)

        if not strip_prompt:
            return output

        # could be compiled elsewhere, but allow for users to modify the prompt whenever they want
        prompt_pattern = get_prompt_pattern(
            prompt="", class_prompt=self.comms_prompt_pattern)
        output = re.sub(pattern=prompt_pattern, repl=b"", string=output)
        return output