From 1585be0001f5fb1a73cb467a2972dca1c78a9215 Mon Sep 17 00:00:00 2001 From: uruun Date: Mon, 2 Sep 2024 20:02:40 +0200 Subject: [PATCH 1/2] remove print_function compatibility --- src/SSHLibrary/library.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/SSHLibrary/library.py b/src/SSHLibrary/library.py index aba4026de..4568a4c0e 100644 --- a/src/SSHLibrary/library.py +++ b/src/SSHLibrary/library.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import re from .logger import logger From 4a235c08d629df2b4fe1e3156d88c1275bd2ab09 Mon Sep 17 00:00:00 2001 From: uruun Date: Mon, 2 Sep 2024 20:02:47 +0200 Subject: [PATCH 2/2] remove paramiko hacks --- src/SSHLibrary/client.py | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/SSHLibrary/client.py b/src/SSHLibrary/client.py index cf5cb4340..cfdcb09c5 100644 --- a/src/SSHLibrary/client.py +++ b/src/SSHLibrary/client.py @@ -26,7 +26,7 @@ from .config import (Configuration, IntegerEntry, NewlineEntry, StringEntry, TimeEntry) from robot.api import logger -from robot.utils import is_bytes, is_string, is_truthy, is_list_like +from robot.utils import is_bytes, is_string, is_truthy from .pythonforward import LocalPortForwarding try: @@ -46,29 +46,7 @@ ) -# There doesn't seem to be a simpler way to increase banner timeout -def _custom_start_client(self, *args, **kwargs): - self.banner_timeout = 45 - self._orig_start_client(*args, **kwargs) - - -paramiko.transport.Transport._orig_start_client = \ - paramiko.transport.Transport.start_client -paramiko.transport.Transport.start_client = _custom_start_client - - -# See http://code.google.com/p/robotframework-sshlibrary/issues/detail?id=55 -def _custom_log(self, level, msg, *args): - escape = lambda s: s.replace('%', '%%') - if is_list_like(msg): - msg = [escape(m) for m in msg] - else: - msg = escape(msg) - return self._orig_log(level, msg, *args) - - -paramiko.sftp_client.SFTPClient._orig_log = paramiko.sftp_client.SFTPClient._log -paramiko.sftp_client.SFTPClient._log = _custom_log +BANNER_TIMEOUT = 45 class SSHClientException(RuntimeError): @@ -900,7 +878,8 @@ def _login(self, username, password, allow_agent=False, look_for_keys=False, pro self.client.connect(self.config.host, self.config.port, username, password, look_for_keys=look_for_keys, allow_agent=allow_agent, - timeout=float(self.config.timeout), sock=sock_tunnel) + timeout=float(self.config.timeout), sock=sock_tunnel, + banner_timeout=BANNER_TIMEOUT) except paramiko.SSHException: pass transport = self.client.get_transport() @@ -911,7 +890,8 @@ def _login(self, username, password, allow_agent=False, look_for_keys=False, pro self.client.connect(self.config.host, self.config.port, username, password, look_for_keys=look_for_keys, allow_agent=allow_agent, - timeout=float(self.config.timeout), sock=sock_tunnel) + timeout=float(self.config.timeout), sock=sock_tunnel, + banner_timeout=BANNER_TIMEOUT) transport = self.client.get_transport() transport.set_keepalive(keep_alive_interval) except paramiko.AuthenticationException: @@ -958,7 +938,7 @@ def _login_with_public_key(self, username, key_file, password, allow_agent, look allow_agent=allow_agent, look_for_keys=look_for_keys, timeout=float(self.config.timeout), - sock=sock_tunnel) + sock=sock_tunnel, banner_timeout=BANNER_TIMEOUT) transport = self.client.get_transport() transport.set_keepalive(keep_alive_interval) except paramiko.AuthenticationException: @@ -981,7 +961,7 @@ def get_banner_without_login(host, port=22): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: - client.connect(str(host), int(port), username="bad-username") + client.connect(str(host), int(port), username="bad-username", banner_timeout=BANNER_TIMEOUT) except paramiko.AuthenticationException: return client.get_transport().get_banner() except Exception: