def cmd(self, cmd_str, wait_ret=True):
if not isinstance(cmd_str, str):
raise TypeError("Invalid command string", cmd_str)
if not self.is_open:
raise attenuator.Error("Telnet connection not open for commands")
cmd_str.strip(self.tx_cmd_separator)
self._tn.read_until(_ascii_string(self.prompt), 2)
self._tn.write(_ascii_string(cmd_str + self.tx_cmd_separator))
if wait_ret is False:
return None
match_idx, match_val, ret_text = self._tn.expect(
[_ascii_string("\S+" + self.rx_cmd_separator)], 1)
if match_idx == -1:
raise attenuator.Error(
"Telnet command failed to return valid data")
ret_text = ret_text.decode()
ret_text = ret_text.strip(self.tx_cmd_separator + self.rx_cmd_separator
+ self.prompt)
return ret_text
评论列表
文章目录