%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/cockpit/_vendor/ferny/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/cockpit/_vendor/ferny/__pycache__/transport.cpython-39.pyc

a

��hB�@s�ddlZddlZddlZddlZddlmZmZmZmZmZddl	m
Z
mZmZddl
mZe�e�Zedejd�ZGdd	�d	e�ZGd
d�dejej�ZdS)�N)�Any�Callable�Iterable�Sequence�TypeVar�)�InteractionAgent�InteractionHandler�get_running_loop)�get_exception_for_ssh_stderr�P)�boundcs8eZdZUeed<eed<eedd��fdd�Z�ZS)�SubprocessError�
returncode�stderrN)rr�returncst��||�||_||_dS�N)�super�__init__rr)�selfrr��	__class__��C/usr/lib/python3.9/site-packages/cockpit/_vendor/ferny/transport.pyr$szSubprocessError.__init__)�__name__�
__module__�__qualname__�int�__annotations__�strr�
__classcell__rrrrr s
rc@s�eZdZUeed<ded<eed<ejed<dZeed<dZ	d	ed
<dZ
ded<dZd
ed<dZded<dZ
ded<dZded<dZeed<dZeed<edkdegefeedeeeedd�dd��Zejdd�d d!�Zdd"�d#d$�Zd%dd&�d'd(�Zejdd)�d*d+�Zddd,�d-d.�Zee dd/�d0d1�Z!eddd2�d3d4�Z"dd"�d5d6�Z#dd"�d7d8�Z$dd"�d9d:�Z%dlddd,�d;d<�Z&ed"�d=d>�Z'dmee(e(d?�d@dA�Z)ej*dd�dBdC�Z+ejd"�dDdE�Z,ed"�dFdG�Z-dd"�dHdI�Z.dd"�dJdK�Z/dd"�dLdM�Z0ed"�dNdO�Z1ed"�dPdQ�Z2dRd"�dSdT�Z3dnddddU�dVdW�Z4e ddX�dYdZ�Z5e6e dd[�d\d]�Z7dd"�d^d_�Z8ed"�d`da�Z9dd"�dbdc�Z:dd"�ddde�Z;eddf�dgdh�Z<dd"�didj�Z=dS)o�FernyTransport�_agentz@asyncio.Task[tuple[asyncio.SubprocessTransport, FernyTransport]]�
_exec_task�_is_ssh�	_protocolF�_protocol_disconnectedNz"asyncio.SubprocessTransport | None�_subprocess_transportzasyncio.WriteTransport | None�_stdin_transportzasyncio.ReadTransport | None�_stdout_transportzException | None�
_exceptionz
str | None�_stderr_outputz
int | None�_returncode�_transport_disconnected�_closedrTztype[typing.Self]z asyncio.AbstractEventLoop | Noneztuple[typing.Self, P])�cls�protocol_factory�args�loop�interaction_handlers�is_ssh�kwargsrc	s�t�d|||�|�}||��|�_|dur2t�}t||�j��_|�d�j���|�	|j
�fdd�g|�Ri|����_tj
dd��fdd�}�j�|��|fS)	a�Connects a FernyTransport to a protocol, using the given command.

        This spawns an external command and connects the stdin and stdout of
        the command to the protocol returned by the factory.

        An instance of ferny.InteractionAgent is created and attached to the
        stderr of the spawned process, using the provided handlers.  It is the
        responsibility of the caller to ensure that:
          - a `ferny-askpass` client program is installed somewhere; and
          - any relevant command-line arguments or environment variables are
            passed correctly to the program to be spawned

        This function returns immediately and never raises exceptions, assuming
        all preconditions are met.

        If spawning the process fails then connection_lost() will be
        called with the relevant OSError, even before connection_made() is
        called.  This is somewhat non-standard behaviour, but is the easiest
        way to report these errors without making this function async.

        Once the process is successfully executed, connection_made() will be
        called and the transport can be used as normal.  connection_lost() will
        be called if the process exits or another error occurs.

        The return value of this function is the transport, but it exists in a
        semi-initialized state.  You can call .close() on it, but nothing else.
        Once .connection_made() is called, you can call all the other
        functions.

        After you call this function, `.connection_lost()` will be called on
        your Protocol, exactly once, no matter what.  Until that happens, you
        are responsible for holding a reference to the returned transport.

        :param args: the full argv of the command to spawn
        :param loop: the event loop to use.  If none is provided, we use the
            one which is (read: must be) currently running.
        :param interaction_handlers: the handlers passed to the
            InteractionAgent
        :param is_ssh: whether we should attempt to interpret stderr as ssh
            error messages
        :param kwargs: anything else is passed through to `subprocess_exec()`
        :returns: the usual `(Transport, Protocol)` pair
        zspawn(%r, %r, %r)Nrcs�Srrr�rrr�<lambda>��z&FernyTransport.spawn.<locals>.<lambda>)�taskrc
s�t�d�|�|�jusJ�z&|��\}}|�us6J�t�d�WnPtjyXYdSty�}z$t�d|���|�WYd}~dSd}~00�j|us�J��j	dus�J��j
dus�J��j��dS)Nzexec_completed(%r, %r)z
  success.z  OSError %r)
�logger�debugr#�result�asyncioZCancelledError�OSError�closer'r(r)r"�start)r9�	transport�me�excr6rr�exec_completed�s 
z,FernyTransport.spawn.<locals>.exec_completed)r:r;r$r
r�_interaction_completedr"�
setdefault�filenoZcreate_taskZsubprocess_execr#r=ZTaskZadd_done_callback)	r/r0r1r2r3r4r5�protocolrDrr6r�spawn@s5(zFernyTransport.spawn)rHrcCs
||_dSr�r%�rrHrrrr�szFernyTransport.__init__)rcCs:t�d|�|j��s(t�d|j�dS|jdurJ|jsJt�d|j�dS|jdurbt�d�dS|jrvt�d�dSd|_|jdur�t�d|j�|j	�
|j�n�|jdks�|jr�t�d	�|j	�
d�nj|j
r�|jd
kr�t�d|j�|j	�
t|j��n8t�d|j|j�|jdu�s J�|j	�
t|j|j��dS)
Nz_consider_disconnect(%r)z  exec_task still running %rz  transport still connected %rz  agent still runningz  already disconnectedTz  disconnect with exception %rrz  clean disconnect�z  disconnect with ssh error %rz)  disconnect with exit code %r, stderr %r)r:r;r#�doner'r-r+r&r*r%�connection_lostr,r.r$rrr6rrr�_consider_disconnect�s4





z#FernyTransport._consider_disconnectzasyncio.Future[str])�futurerc
Csxt�d||�z|��|_t�d|j�Wn@tyj}z(t�d|�d|_|�|�WYd}~n
d}~00|��dS)Nz_interaction_completed(%r, %r)z  stderr: %rz  exception: %r�)r:r;r<r+�	Exceptionr?rO)rrPrCrrrrE�s
 z%FernyTransport._interaction_completed)rArcCs�t�d||�t|tj�sJ�||_|�d�}t|tj�s>J�||_|�d�}t|tj	�s^J�||_
|�d�}|duszJ�t�d||j�|j�|�dS)Nzconnection_made(%r, %r)rr�zcalling connection_made(%r, %r))
r:r;�
isinstancer=ZSubprocessTransportr'Zget_pipe_transportZWriteTransportr(Z
ReadTransportr)r%�connection_made)rrAZstdin_transportZstdout_transportZstderr_transportrrrrU�s


zFernyTransport.connection_made)rCrcCs0t�d||�|jdur||_d|_|��dS)Nzconnection_lost(%r, %r)T)r:r;r*r-rO�rrCrrrrN�s

zFernyTransport.connection_lost)�fd�datarcCs0t�d||t|��|dks J�|j�|�dS)Nzpipe_data_received(%r, %r, %r)r)r:r;�lenr%Z
data_received)rrWrXrrr�pipe_data_received�sz!FernyTransport.pipe_data_received)rWrCrcCsbt�d|||�|dvsJ�t|t�r*d}|dur>|�|�n |dkr^|js^|j��s^|��dS)Nz pipe_connection_lost(%r, %r, %r))rrr)r:r;rT�BrokenPipeErrorr?r.r%Zeof_received)rrWrCrrr�pipe_connection_losts

z#FernyTransport.pipe_connection_lostcCsBt�d|�|jdusJ�|j��|_t�d|j�|j��dS)Nzprocess_exited(%r)z  ._returncode = %r)r:r;r'�get_returncoder,r"�force_completionr6rrr�process_exiteds
zFernyTransport.process_exitedcCst�d|�|j��dS)Nzpause_writing(%r))r:r;r%�
pause_writingr6rrrr`szFernyTransport.pause_writingcCst�d|�|j��dS)Nzresume_writing(%r))r:r;r%�resume_writingr6rrrraszFernyTransport.resume_writingcCs�t�d||�d|_|jdur0t�d|�||_|j��sNt�d�|j��|jdur�t�d�t�	t
��|j��Wd�n1s�0Y|j�
�dS)Nz
close(%r, %r)Tz  setting exception %rz  cancelling _exec_taskz  closing _subprocess_transport)r:r;r.r*r#rM�cancelr'�
contextlib�suppress�PermissionErrorr?r"r^rVrrrr? s





(zFernyTransport.closecCs|jdusJ�|j��Sr)r'�
is_closingr6rrrrf0szFernyTransport.is_closing)�name�defaultrcCs|jdusJ�|j�||�Sr)r'�get_extra_info)rrgrhrrrri4szFernyTransport.get_extra_infocCst|tj�sJ�||_dSr)rTr=�Protocolr%rKrrr�set_protocol8szFernyTransport.set_protocolcCs|jSrrJr6rrr�get_protocol<szFernyTransport.get_protocolcCs�|jdusJ�z|j��WSty6|jjYSty~z |jjj}|�|jj�WYdSt	yxYYdS0Yn0dS)NTF)
r)�
is_reading�NotImplementedErrorZ_paused�AttributeErrorZ_loopZ	_selectorZget_keyZ_fileno�KeyError)r�selectorrrrrm?s
zFernyTransport.is_readingcCs|jdusJ�|j��dSr)r)�
pause_readingr6rrrrrOszFernyTransport.pause_readingcCs|jdusJ�|j��dSr)r)�resume_readingr6rrrrsSszFernyTransport.resume_readingcCs4|jdusJ�|jdusJ�|j��|j��dSr)r(r'�abort�killr6rrrrtWs
zFernyTransport.abortcCs|jdusJ�|j��Sr)r(�
can_write_eofr6rrrrv]szFernyTransport.can_write_eofcCs|jdusJ�|j��Sr)r(�get_write_buffer_sizer6rrrrwasz$FernyTransport.get_write_buffer_sizeztuple[int, int]cCs|jdusJ�|j��Sr)r(�get_write_buffer_limitsr6rrrrxesz&FernyTransport.get_write_buffer_limits)�high�lowrcCs|jdusJ�|j�||�Sr)r(�set_write_buffer_limits)rryrzrrrr{isz&FernyTransport.set_write_buffer_limits)rXrcCs|jdusJ�|j�|�Sr)r(�write)rrXrrrr|mszFernyTransport.write)�list_of_datarcCs|jdusJ�|j�|�Sr)r(�
writelines)rr}rrrr~qszFernyTransport.writelinescCs|jdusJ�|j��Sr)r(�	write_eofr6rrrruszFernyTransport.write_eofcCs|jdusJ�|j��Sr)r'�get_pidr6rrrr�{szFernyTransport.get_pidcCs|jSr)r,r6rrrr]szFernyTransport.get_returncodecCs|jdusJ�|j��dSr)r'rur6rrrru�szFernyTransport.kill)�numberrcCs|jdusJ�|j�|�dSr)r'�send_signal)rr�rrrr��szFernyTransport.send_signalcCs|jdusJ�|j��dSr)r'�	terminater6rrrr��szFernyTransport.terminate)NrT)N)N)NN)>rrrrr�boolr=rjr&r'r(r)r*r+r,r-r.�classmethodrrrrr	rrIrrOrEZ
BaseTransportrUrNr�bytesrZr\r_r`rar?rf�objectriZBaseProtocolrkrlrmrrrsrtrvrwrxr{r|rr~rr�r]rur�r�rrrrr!*st

�
�c,
r!)r=rcZlogging�typingrrrrrZinteraction_agentrr	r
Z
ssh_errorsrZ	getLoggerrr:rjrrRrZ	TransportZSubprocessProtocolr!rrrr�<module>s


Zerion Mini Shell 1.0