a
    ƹDf                     @   s2   d Z dgZddlmZ G dd deZedkr.dS )a"  
This module contains the derived class for secure shell (ssh) launchers
See the following for an example.


Usage
=====

A typical call to a 'ssh pipe' will roughly follow this example:

    >>> # instantiate the pipe, providing it with a unique identifier
    >>> pipe = Pipe('launcher')
    >>>
    >>> # configure the pipe to perform the command on the selected host
    >>> pipe(command='hostname', host='remote.host.edu')
    >>>
    >>> # execute the launch and retrieve the response
    >>> pipe.launch()
    >>> print(pipe.response())
 
Pipe    )r   c                       s.   e Zd ZdZd fdd	Zdd ZeZ  ZS )r   z>a popen-based ssh-pipe for parallel and distributed computing.Nc                    sF   | dd| _| dd| _| dd| _tt| j|fi | dS )a  create a ssh pipe

Inputs:
    name: a unique identifier (string) for the pipe
    host: hostname to recieve command [user@host is also valid]
    command: a command to send  [default = 'echo <name>']
    launcher: remote service mechanism (i.e. ssh, rsh)  [default = 'ssh']
    options: remote service options (i.e. -v, -N, -L)  [default = '']
    background: run in background  [default = False]
    decode: ensure response is 'ascii'  [default = True]
    stdin: file-like object to serve as standard input for the remote process
        launchersshoptions host	localhostN)popr   r   r   superr   __init__)selfnamekwds	__class__ e/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pathos/secure/connection.pyr   '   s
    zPipe.__init__c                    sz   j du rd j  _ n jr4 j  jdd  _  jrP j  jdd  _  jrp j  jdd   _ d} j |s j |r j dd  _  j	du rddl
}|j	 _	| D ]|\}}|dkr| _ q|dkr| _q|d	kr| _q|d
kr| _q|dkr| _q|dkr,| _q|dkr| _	qd _d j j j j f  _ g d}t fdd|D S )a3  configure a remote command using given keywords:

(Re)configure the copier for the following inputs:
    host: hostname to recieve command [user@host is also valid]
    command: a command to send  [default = 'echo <name>']
    launcher: remote service mechanism (i.e. ssh, rsh)  [default = 'ssh']
    options: remote service options (i.e. -v, -N, -L)  [default = '']
    background: run in background  [default = False]
    decode: ensure response is 'ascii'  [default = True]
    stdin: file-like object to serve as standard input for the remote process
        Nzecho %s   )"'r   commandr   r   r   
backgrounddecodestdinz%s %s %s "%s")messager   r   r   r   r   codecc                 3   s   | ]}|t  |fV  qd S )N)getattr).0ir   r   r   	<genexpr>k       zPipe.config.<locals>.<genexpr>)r   r   r   splitr   r   strip
startswithendswithr   sysitemsr   r   Z_stdoutdict)r   r   quoter'   keyvaluenamesr   r    r   config:   sJ    




zPipe.config)N)__name__
__module____qualname____doc__r   r.   __call____classcell__r   r   r   r   r   $   s
   4__main__N)r2   __all__Zpathos.connectionr   Z_Piper/   r   r   r   r   <module>
   s
   N