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")
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")
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
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
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
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
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()
def test_bytes_to_bytes(): """Convert bytes to bytes""" result = b"hello world" assert utilities.write_bytes(result) == result
def test_string_to_bytes(): """Convert string to bytes""" assert utilities.write_bytes("test") == b"test"
def test_bytes_to_bytes(): """Convert bytes to bytes""" result = b"hello world" assert utilities.write_bytes(result) == result
def test_string_to_bytes(): """Convert string to bytes""" assert utilities.write_bytes("test") == b"test"
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))