
    P                     <    S SK Jr  S SK Jr  S SKJr   " S S5      rg)   )errors)utils)CancellableStreamc                       \ rS rSr\R
                  " S5         S
S j5       rS rSS jr\R
                  " S5        SS j5       r	S	r
g)ExecApiMixin   	containerNc           
         U	b<  [         R                  " U R                  S5      (       a  [        R                  " S5      e[        U[        5      (       a  [         R                  " U5      n[        U	[        5      (       a  [         R                   R                  U	5      n	UUUUUUUUU	S.	nU
b@  [         R                  " U R                  S5      (       a  [        R                  " S5      eXS'   U(       a  XS'   O"SU R                  ;   a  U R                  S   US'   U R                  SU5      nU R                  XS	9nU R                  US
5      $ )as  
Sets up an exec instance in a running container.

Args:
    container (str): Target container where exec instance will be
        created
    cmd (str or list): Command to be executed
    stdout (bool): Attach to stdout. Default: ``True``
    stderr (bool): Attach to stderr. Default: ``True``
    stdin (bool): Attach to stdin. Default: ``False``
    tty (bool): Allocate a pseudo-TTY. Default: False
    privileged (bool): Run as privileged.
    user (str): User to execute command as. Default: root
    environment (dict or list): A dictionary or a list of strings in
        the following format ``["PASSWORD=xxx"]`` or
        ``{"PASSWORD": "xxx"}``.
    workdir (str): Path to working directory for this exec session
    detach_keys (str): Override the key sequence for detaching
        a container. Format is a single character `[a-Z]`
        or `ctrl-<value>` where `<value>` is one of:
        `a-z`, `@`, `^`, `[`, `,` or `_`.
        ~/.docker/config.json is used by default.

Returns:
    (dict): A dictionary with an exec ``Id`` key.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z1.25z;Setting environment for exec is not supported in API < 1.25)		ContainerUser
PrivilegedTtyAttachStdinAttachStdoutAttachStderrCmdEnvz1.35z/workdir is not supported for API version < 1.35
WorkingDir
detachKeysz/containers/{0}/exec)dataT)r   
version_lt_versionr   InvalidVersion
isinstancestrsplit_commanddictformat_environment_general_configs_url
_post_json_result)selfr	   cmdstdoutstderrstdintty
privilegeduserenvironmentworkdirdetach_keysr   urlress                  &lib/third_party/docker/api/exec_api.pyexec_createExecApiMixin.exec_create   s:   F "u'7'7v'N'N''M  c3%%c*Ck4((++88EK #$ ""

 v66++E  ")!,T222!%!6!6|!DDii.	:ooco-||C&&    c                     [        U[        5      (       a  UR                  S5      nU R                  U R	                  SU5      5      nU R                  US5      $ )a  
Return low-level information about an exec command.

Args:
    exec_id (str): ID of the exec instance

Returns:
    (dict): Dictionary of values returned by the endpoint.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
Idz/exec/{0}/jsonT)r   r   get_getr    r"   )r#   exec_idr/   s      r0   exec_inspectExecApiMixin.exec_inspectQ   sJ     gt$$kk$'Gii		"2G<=||C&&r3   c                     [        U[        5      (       a  UR                  S5      nX#S.nU R                  SU5      nU R	                  XTS9nU R                  U5        g)z
Resize the tty session used by the specified exec command.

Args:
    exec_id (str): ID of the exec instance
    height (int): Height of tty session
    width (int): Width of tty session
r5   )hwz/exec/{0}/resize)paramsN)r   r   r6   r    _post_raise_for_status)r#   r8   heightwidthr>   r.   r/   s          r0   exec_resizeExecApiMixin.exec_resized   sV     gt$$kk$'G*ii*G4jjj,s#r3   r8   c                 `   UUS.nU(       a  0 OSSS.nU R                  U R                  SU5      UUSS9n	U(       a"   U R                  U	5      U	R                  5         $ U(       a  U R	                  U	5      $ U R                  XX6S9n
U(       a  [        X5      $ U
$ ! U	R                  5         f = f)	a  
Start a previously set up exec instance.

Args:
    exec_id (str): ID of the exec instance
    detach (bool): If true, detach from the exec command.
        Default: False
    tty (bool): Allocate a pseudo-TTY. Default: False
    stream (bool): Return response data progressively as an iterator
        of strings, rather than a single string.
    socket (bool): Return the connection socket to allow custom
        read/write operations. Must be closed by the caller when done.
    demux (bool): Return stdout and stderr separately

Returns:

    (generator or str or tuple): If ``stream=True``, a generator
    yielding response chunks. If ``socket=True``, a socket object for
    the connection. A string containing response data otherwise. If
    ``demux=True``, a tuple with two elements of type byte: stdout and
    stderr.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)r   DetachUpgradetcp)
ConnectionrG   z/exec/{0}/startT)headersr   stream)r(   demux)r!   r    r"   close_get_raw_response_socket_read_from_socketr   )r#   r8   detachr(   rK   socketrL   r   rJ   r/   outputs              r0   
exec_startExecApiMixin.exec_startv   s    @ 

 "#%

 ooII'1	  
 ||C(		0055'''J$V11M 		s   B B- )	TTFFF NNN)NN)FFFFF)__name__
__module____qualname____firstlineno__r   check_resourcer1   r9   rC   rS   __static_attributes__rU   r3   r0   r   r      sZ    
+&>BCE@DG' 'G'R'&$$ )$BG',: %:r3   r   N)rV   r   r   typesr   r   rU   r3   r0   <module>r^      s      %k kr3   