Ejemplo n.º 1
0
 def write_channel(self, out_data):
     """Generic handler that will write to both SSH and telnet channel."""
     if self.protocol == 'ssh':
         self.remote_conn.sendall(write_bytes(out_data))
     elif self.protocol == 'telnet':
         self.remote_conn.write(write_bytes(out_data))
     else:
         raise ValueError("Invalid protocol specified")
Ejemplo n.º 2
0
 def write_channel(self, out_data):
     """Generic handler that will write to both SSH and telnet channel."""
     if self.protocol == 'ssh':
         self.remote_conn.sendall(write_bytes(out_data))
     elif self.protocol == 'telnet':
         self.remote_conn.write(write_bytes(out_data))
     else:
         raise ValueError("Invalid protocol specified")
Ejemplo n.º 3
0
def test_invalid_data_to_bytes():
    """Convert an invalid data type to bytes"""
    try:
        utilities.write_bytes(456779)
    except ValueError as exc:
        assert isinstance(exc, ValueError)
        return

    assert False
Ejemplo n.º 4
0
def test_invalid_data_to_bytes():
    """Convert an invalid data type to bytes"""
    try:
        utilities.write_bytes(456779)
    except ValueError as exc:
        assert isinstance(exc, ValueError)
        return

    assert False
Ejemplo n.º 5
0
 def _write_channel(self, out_data):
     """Generic handler that will write to both SSH and telnet channel."""
     if self.protocol == 'ssh':
         self.remote_conn.sendall(write_bytes(out_data))
     elif self.protocol == 'telnet':
         self.remote_conn.write(write_bytes(out_data))
     else:
         raise ValueError("Invalid protocol specified")
     try:
         log.debug("write_channel: {}".format(write_bytes(out_data)))
     except UnicodeDecodeError:
         # Don't log non-ASCII characters; this is null characters and telnet IAC (PY2)
         pass
Ejemplo n.º 6
0
    def _write_channel(self, out_data):
        """Generic handler that will write to both SSH and telnet channel.

        :param out_data: data to be written to the channel
        :type out_data: str (can be either unicode/byte string)
        """
        if self.protocol == 'ssh':
            self.remote_conn.sendall(write_bytes(out_data))
        elif self.protocol == 'telnet':
            self.remote_conn.write(write_bytes(out_data))
        elif self.protocol == 'serial':
            self.remote_conn.write(write_bytes(out_data))
            self.remote_conn.flush()
        else:
            raise ValueError("Invalid protocol specified")
        try:
            log.debug("write_channel: {}".format(write_bytes(out_data)))
        except UnicodeDecodeError:
            # Don't log non-ASCII characters; this is null characters and telnet IAC (PY2)
            pass
Ejemplo n.º 7
0
    def write(self, data: str) -> None:
        if self.session_log is not None and len(data) > 0:
            # Hide the password and secret in the session_log
            for hidden_data in self.no_log.values():
                data = data.replace(hidden_data, "********")

            if isinstance(self.session_log, io.BufferedIOBase):
                self.session_log.write(
                    write_bytes(data, encoding=self.file_encoding))
            else:
                self.session_log.write(data)

            assert isinstance(self.session_log,
                              io.BufferedIOBase) or isinstance(
                                  self.session_log, io.TextIOBase)
            self.session_log.flush()
Ejemplo n.º 8
0
def test_bytes_to_bytes():
    """Convert bytes to bytes"""
    result = b"hello world"
    assert utilities.write_bytes(result) == result
Ejemplo n.º 9
0
def test_string_to_bytes():
    """Convert string to bytes"""
    assert utilities.write_bytes("test") == b"test"
Ejemplo n.º 10
0
def test_bytes_to_bytes():
    """Convert bytes to bytes"""
    result = b"hello world"
    assert utilities.write_bytes(result) == result
Ejemplo n.º 11
0
def test_string_to_bytes():
    """Convert string to bytes"""
    assert utilities.write_bytes("test") == b"test"
Ejemplo n.º 12
0
 def write_channel(self, out_data: str) -> None:
     if self.remote_conn is None:
         raise WriteException(
             "Attempt to write data, but there is no active channel.")
     self.remote_conn.sendall(write_bytes(out_data, encoding=self.encoding))