2015-10-07 37 views
0

當使用關鍵字「」打開連接「」我知道爲什麼ssh機器人庫使用抽象客戶?它有2個具體的實現。 Java和Python。 我不確定何時調用具體實現以及框架如何在python和java實現之間進行選擇?什麼時候abstractSSHclass實例化robotframework ssh庫中的具體類實例

關鍵字 「開放連接」 在這裏描述

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. 
    """ 

但是使用抽象客戶端時,當是選擇具體的實現inv在Python中進行了修改,它是如何選擇的?

... 
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進口,這是其中:在library.py方法get_connection -

回答

1

的具體類是「獲取連接」關鍵字內實例化的決定使用Python或Java客戶端。

在我寫這篇文章的時候,client.py比單個if語句僅此而已:

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