abstractSSHclass 什么时候在 robotframework ssh 库中实例化一个具体的 class 实例

When does abstractSSHclass instantiate a concrete class instance in robotframework ssh library

当使用关键字“"Open Connection"”时 我知道为什么 ssh 机器人库使用抽象客户端吗?它有 2 个具体实现。 Java 和 Python。 我不确定何时调用具体实现以及框架如何在 python 和 java 实现之间进行选择?

此处描述了关键字 "open connection"

https://github.com/robotframework/SSHLibrary/blob/master/src/SSHLibrary/library.py

def open_connection(self, host, alias=None, port=22, timeout=None,
                        newline=None, prompt=None, term_type=None, width=None,
                        height=None, path_separator=None, encoding=None):


client = SSHClient(host, alias, port, timeout, newline, prompt,
                           term_type, width, height, path_separator, encoding)

它调用这个:

https://github.com/robotframework/SSHLibrary/blob/master/src/SSHLibrary/abstractclient.py

class AbstractSSHClient(object):
    """Base class for the SSH client implementation.
    This class defines the public API. Subclasses (:py:class:`pythonclient.
    PythonSSHClient` and :py:class:`javaclient.JavaSSHClient`) provide the
    language specific concrete implementations.
    """

但是在使用抽象客户端时,何时会在 python 中调用所选择的具体实现以及如何选择它?

具体class在"Get Connection"关键字内实例化——library.py中的方法get_connection:

...
from .client import SSHClient
...
def get_connection(self, index_or_alias=None, index=False, host=False,
                   alias=False, port=False, timeout=False, newline=False,
                   prompt=False, term_type=False, width=False, height=False,
                   encoding=False):
...
    client = SSHClient(host, alias, port, timeout, newline, prompt,
                       term_type, width, height, path_separator, encoding)

在上面的代码中,SSHClient 是从 client.py 导入的,这是决定使用 python 或 java 客户端的地方。

在我写这篇文章的时候,client.py 只不过是一个 if 语句:

if sys.platform.startswith('java'):
    from javaclient import JavaSSHClient as SSHClient
else:
    from pythonclient import PythonSSHClient as SSHClient