abstractSSHclass何时实例化robotframework ssh库中的具体类实例

时间:2015-10-07 08:22:32

标签: python abstract-class robotframework

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

此处描述了关键字“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中调用所选择的具体实现是什么时候选择它?

1 个答案:

答案 0 :(得分:1)

具体类在“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)

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

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

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