
    J                     
   S SK r S SKrS SKrS SKJr  S SKrS SKrS SKrSSKJ	r	  SSK
JrJrJrJrJrJrJrJr  SSKJrJrJrJr  SSKJr  SSKJrJr  SS	KJrJrJ r Jr  SS
K!J"r"  SSK#J$r$  SSK%J&r&J'r'J(r(  SSK)J*r*  SSKJ+r+  SSK,J-r-  SSK.J/r/  SSK0J1r1  SSK2J3r3  SSK4J5r5  SSK6J7r7  SSK8J9r9  SSK:J;r;  SSK<J=r=  SSK>J?r?   SSKJ@r@   SSKJBrB   " S S\R                  \*\+\-\/\1\3\5\7\9\;\=\?5      rDg! \A a     N1f = f! \A a     N6f = f)    N)partial   )auth)DEFAULT_NUM_POOLSDEFAULT_NUM_POOLS_SSHDEFAULT_MAX_POOL_SIZEDEFAULT_TIMEOUT_SECONDSDEFAULT_USER_AGENTIS_WINDOWS_PLATFORMMINIMUM_DOCKER_API_VERSIONSTREAM_HEADER_SIZE_BYTES)DockerExceptionInvalidVersionTLSParameterError$create_api_error_from_http_exception)	TLSConfig)SSLHTTPAdapterUnixHTTPAdapter)check_resourceconfigupdate_headersutils)json_stream)ProxyConfig)consume_socket_outputdemux_adaptorframes_iter   )BuildApiMixin)ConfigApiMixin)ContainerApiMixin)DaemonApiMixin)ExecApiMixin)ImageApiMixin)NetworkApiMixin)PluginApiMixin)SecretApiMixin)ServiceApiMixin)SwarmApiMixin)VolumeApiMixin)NpipeHTTPAdapter)SSHHTTPAdapterc            	         ^  \ rS rSrSr\R                  R                  / SQ-   rSS\S\	SSS\
4	U 4S jjrS rS r\S	 5       r\S
 5       r\S 5       r\S 5       rS rS rS$S jrS rS%S jr\" S5      S%S j5       rS rS rS&S jrS rS rS'S jrS(S jr S r!\" S5      S 5       r"S r#S r$S r%U 4S  jr&\'S! 5       r(S%S" jr)S#r*U =r+$ ))	APIClient/   a  
A low-level client for the Docker Engine API.

Example:

    >>> import docker
    >>> client = docker.APIClient(base_url='unix://var/run/docker.sock')
    >>> client.version()
    {u'ApiVersion': u'1.33',
     u'Arch': u'amd64',
     u'BuildTime': u'2017-11-19T18:46:37.000000000+00:00',
     u'GitCommit': u'f4ffd2511c',
     u'GoVersion': u'go1.9.2',
     u'KernelVersion': u'4.14.3-1-ARCH',
     u'MinAPIVersion': u'1.12',
     u'Os': u'linux',
     u'Version': u'17.10.0-ce'}

Args:
    base_url (str): URL to the Docker server. For example,
        ``unix:///var/run/docker.sock`` or ``tcp://127.0.0.1:1234``.
    version (str): The version of the API to use. Set to ``auto`` to
        automatically detect the server's version. Default: ``1.35``
    timeout (int): Default timeout for API calls, in seconds.
    tls (bool or :py:class:`~docker.tls.TLSConfig`): Enable TLS. Pass
        ``True`` to enable it with default options, or pass a
        :py:class:`~docker.tls.TLSConfig` object to use custom
        configuration.
    user_agent (str): Set a custom user agent for requests to the server.
    credstore_env (dict): Override environment variables when calling the
        credential store process.
    use_ssh_client (bool): If set to `True`, an ssh connection is made
        via shelling out to the ssh client. Ensure the ssh client is
        installed and configured on the host.
    max_pool_size (int): The maximum number of connections
        to save in the pool.
)_auth_configs_general_configs_versionbase_urltimeoutNFc
                 x  > [         TU ]  5         U(       a  U(       d  [        S5      eXl        X0l        XPR
                  S'   [        R                  " 5       U l        U R                  R                  S0 5      n
 X   n[        R                  " U5      U l        [        R                  " U R                  US9U l        Xpl        [$        R&                  " U[(        [+        U5      S9nUR-                  S5      (       a  U=(       d    [.        O[0        nUR-                  S5      (       aG  [3        XUU	S	9U l        U R7                  S
U R4                  5        U R9                  SS5        SU l        GOUR-                  S5      (       aK  [(        (       d  [;        S5      e [=        XUU	S	9U l        U R7                  S
U R4                  5        SU l        OUR-                  S5      (       aG   [A        XUXS9U l        U R7                  SU R4                  5        U R9                  SS5        SU l        O^[C        U[D        5      (       a  URG                  U 5        O1U(       a*  [I        US9U l        U R7                  SU R4                  5        Xl        Ub)  [C        U[J        5      (       a*  URM                  5       S:X  a  U RO                  5       U l(        OX l(        [C        U RP                  [J        5      (       d-  [;        SRS                  [U        U5      RV                  5      5      e[$        RX                  " U RP                  [Z        5      (       a  []        SRS                  [Z        5      5      eg ! [         a    U
R                  S0 5      n GNf = f! [>         a    [;        S5      ef = f! [>         a    [;        S5      ef = f)Nz5If using TLS, the base_url argument must be provided.z
User-Agentproxiesdefault)config_dictcredstore_env)tlszssh://zhttp+unix://)pool_connectionsmax_pool_sizezhttp+docker://http://https://zhttp+docker://localhostznpipe://z2The npipe:// protocol is only supported on Windowsz4Install pypiwin32 package to enable npipe:// supporthttp+docker://localnpipe)r;   r<   	shell_outz1Install paramiko package to enable ssh:// supporthttp+docker://ssh)r;   autoz4Version parameter must be a string or None. Found {}z>API versions below {} are no longer supported by this library.)/super__init__r   r3   r4   headersr   load_general_configr1   getKeyErrorr   	from_dict_proxy_configsr   load_configr0   r9   r   
parse_hostr   bool
startswithr   r   r   _custom_adaptermount_unmountr   r+   	NameErrorr,   
isinstancer   configure_clientr   strlower_retrieve_server_versionr2   formattype__name__
version_ltr   r   )selfr3   versionr4   r:   
user_agent	num_poolsr9   use_ssh_clientr<   proxy_configr6   	__class__s               $lib/third_party/docker/api/client.pyrD   APIClient.__init__i   s_   
 	x#G  !%/\" & : : <,,00B?	6",G *33G<!----]
 +##)tCy

 )) 6!6/@ 	 ~..#2I+$D  JJ')=)=>MM)Z0 6DM  ,,&&%H '7	"/($ JJ')=)=>6DM  **'5	"/($ JJ*D,@,@AMM)Z0/DM #y))$$T*'5%.(0$

:t';';<$M ?z ' # "  " '.mmo&? 99;DM#M$----!FMMM** 
 DMM+EFF !6"<=  Ga  	6"&&y"5G	6J  %J   %G s*   :M' N
 &N# 'NN
N #N9c                      U R                  SS9S   $ ! [         a    [        S5      e[         a  n[        SU 35      eS nAff = f)NF)api_version
ApiVersionzAInvalid response from docker daemon: key "ApiVersion" is missing.z)Error while fetching server API version: )r]   rH   r   	Exception)r\   es     rc   rW   "APIClient._retrieve_server_version   s`    
	<<E<2<@@ 	!   	!;A3? 	s    AA  Ac                 >    UR                  SU R                  5        U$ )zbPrepare the kwargs for an HTTP request by inserting the timeout
parameter, if not already present.r4   )
setdefaultr4   )r\   kwargss     rc   _set_request_timeoutAPIClient._set_request_timeout   s     	)T\\2    c                 F    U R                   " U40 U R                  U5      D6$ N)postrn   r\   urlrm   s      rc   _postAPIClient._post   s!    yyB 9 9& ABBrp   c                 F    U R                   " U40 U R                  U5      D6$ rr   )rG   rn   rt   s      rc   _getAPIClient._get   !    xxAt88@AArp   c                 F    U R                   " U40 U R                  U5      D6$ rr   )putrn   rt   s      rc   _putAPIClient._put   r{   rp   c                 F    U R                   " U40 U R                  U5      D6$ rr   )deletern   rt   s      rc   _deleteAPIClient._delete   s!    {{3D$";";F"CDDrp   c           	         U H<  n[        U[        5      (       a  M  [        SR                  U[	        U5      5      5      e   [        [        R                  R                  SS9n[        XR5      nUR                  SS5      (       a4  SR                  U R                  U R                  UR                  " U6 5      $ U R                   UR                  " U6  3$ )Nz+Expected a string but found {} ({}) insteadz/:)safeversioned_apiTz{}/v{}{})rS   rU   
ValueErrorrX   rY   r   urllibparsequotemaprG   r3   r2   )r\   pathfmtargsrm   argquote_fs         rc   _urlAPIClient._url   s    Cc3'' $fS$s)4   &,,,,487!::ot,,$$t}}gnnd.C  mm_W^^T%:$;<<rp   c                      UR                  5         g! [        R                  R                   a  n[	        U5      UeSnAff = f)z1Raises stored :class:`APIError`, if one occurred.N)raise_for_statusrequests
exceptions	HTTPErrorr   )r\   responseri   s      rc   _raise_for_statusAPIClient._raise_for_status	  s?    	A%%'"",, 	A6q9q@	As    A=Ac                     U(       a	  U(       a   eU R                  U5        U(       a  UR                  5       $ U(       a  UR                  $ UR                  $ rr   )r   jsoncontenttext)r\   r   r   binarys       rc   _resultAPIClient._result  sC    V$$x(==?"###}}rp   c                    0 nUbA  [        U[        5      (       a,  [        UR                  5       5       H  u  pVUc  M
  XdU'   M     OUb  UnSU;  a  0 US'   SUS   S'   U R                  " U4S[
        R                  " U5      0UD6$ )NrE   zapplication/jsonzContent-Typedata)rS   dictiteritemsrv   r   dumps)r\   ru   r   rm   data2kvs          rc   
_post_jsonAPIClient._post_json  s     
4 6 6TZZ\*= !H + EF" "F9,>y.)zz#@DJJu$5@@@rp   c                      U=(       d    SSSS.$ )Nr   )stdoutstderrstream )r\   overrides     rc   _attach_paramsAPIClient._attach_params*  s     

 	
rp   	containerc                    U R                  SU5      n[        R                  " SX0R                  U5      S9nUR	                  5       R
                  nUR                  SSS5      nUR                  SSS5      nU R                  U5      $ )	Nz/containers/{0}/attach/wsPOST)paramsr=   zws://r   r>   zwss://)r   r   Requestr   prepareru   replace_create_websocket_connection)r\   r   r   ru   reqfull_urls         rc   _attach_websocketAPIClient._attach_websocket1  sz    ii3Y?vs3F3Fv3NO;;=$$##Iw:##J!<00::rp   c                 .    [         R                  " U5      $ rr   )	websocketcreate_connection)r\   ru   s     rc   r   &APIClient._create_websocket_connection:  s    **3//rp   c                 $   U R                  U5        U R                  S:X  a5  UR                  R                  R                  R                  R
                  nOU R                  R                  S5      (       a+  UR                  R                  R                  R                  nOVUR                  R                  R                  R                  nU R                  R                  S5      (       a  UR                  n Xl	        U$ ! [         a     U$ f = f)Nr?   rA   r>   )r   r3   raw_fpfpsockrN   channel_sock	_responseAttributeError)r\   r   r   s      rc   _get_raw_response_socket"APIClient._get_raw_response_socket=  s    x(==66<<##&&**//D]]%%&9::<<##&&..D<<##&&**D}}''
33zz	 &N   	 	s   9D 
DDc              #     #    UR                   R                  R                  (       a  U(       a$  [        U R	                  US5      5       Sh  vN   gUR                   nUR
                  (       ds  UR                  S5      nU(       d  gUR                  R                  (       a'  XCR                  UR                  R                  5      -  nUv   UR
                  (       d  Mr  ggU R                  XS9v   g N7f)z?Generator for data coming from a chunked-encoded HTTP response.FNr   )r   )	r   r   chunkedr   _stream_helperclosedread
chunk_leftr   )r\   r   decodereaderr   s        rc   r   APIClient._stream_helperS  s      <<##&t':':8U'KLLL! --!;;q>Dzz,,FJJ,A,A BBJ !--- ,,x,55 Ms   AC8C6BC8"C8c              #      #    U R                  USS9n[        U5      nSn X4-
  [        :  a  gX$U[        -    n[        R                  " SU5      u  pgU[        -   nX-   n	U	nX(U	 v   MH  7f)zEA generator of multiplexed data blocks read from a buffered
response.Tr   r   >BxxxLN)r   lenr   structunpack_from)
r\   r   buf
buf_lengthwalkerheader_lengthstartends
             rc   _multiplexed_buffer_helper$APIClient._multiplexed_buffer_helperh  s      ll8Dl1X
"%==)A ABF**8V<IA55E.CFC.  s   A'A)c              #   4  #    U R                  U5      nU R                  U5         UR                  R                  [        5      nU(       d  g[
        R                  " SU5      u  pEU(       d  MJ  UR                  R                  U5      nU(       d  gUv   Mr  7f)zEA generator of multiplexed data blocks coming from a response
stream.r   N)r   _disable_socket_timeoutr   r   r   r   unpack)r\   r   socketr   r   r   r   s          rc   #_multiplexed_response_stream_helper-APIClient._multiplexed_response_stream_helperx  s      ..x8$$V,\\&&'?@Fh7IA<<$$V,DJ s   BBc              #      #    U R                  U5        U R                  U5      nU R                  U5        UR                  X#5       Sh  vN   g N7f)z;Stream result for TTY-enabled container and raw binary dataN)r   r   r   iter_content)r\   r   
chunk_sizer   r   s        rc   _stream_raw_resultAPIClient._stream_raw_result  sG     x( ..x8$$V,((<<<s   AA
AAc                     U R                  U5      n[        XS5      nU(       a
  S U 5       nO	S U 5       nU(       a  U$  [        XdS9UR                  5         $ ! UR                  5         f = f)zConsume all data from the socket, close the response and return the
data. If stream=True, then a generator is returned instead and the
caller is responsible for closing the response.
c              3   2   #    U  H  n[        U6 v   M     g 7frr   )r   ).0frames     rc   	<genexpr>.APIClient._read_from_socket.<locals>.<genexpr>  s     :cU=%(cs   c              3   *   #    U  H	  u  pUv   M     g 7frr   r   )r   r   r   s      rc   r   r     s     -IQ4s   )demux)r   r   r   close)r\   r   r   ttyr   r   gens          rc   _read_from_socketAPIClient._read_from_socket  sa    
 ..x8&&:c:C .-CJ!,S>  s   A A,c                     U[        USS5      /nU HU  n[        US5      (       d  M  Sn[        US5      (       a  UR                  5       nUb  US:X  a  MD  UR                  S5        MW     g)a  Depending on the combination of python version and whether we're
connecting over http or https, we might need to access _sock, which
may or may not exist; or we may need to just settimeout on socket
itself, which also may or may not have settimeout on it. To avoid
missing the correct one, we try both.

We also do not want to set the timeout if it is already disabled, as
you run the risk of changing a socket that was non-blocking to
blocking, for example when using gevent.
r   N
settimeout
gettimeoutg        )getattrhasattrr  r  )r\   r   socketssr4   s        rc   r   !APIClient._disable_socket_timeout  sj     767D9:A1l++Gq,'',,. 'S.LL rp   c                 4    U R                  U5      nUS   S   $ )NConfigTty)inspect_container)r\   r   conts      rc   _check_is_ttyAPIClient._check_is_tty  s!    %%i0H~e$$rp   c                 D    U R                  X#U R                  U5      5      $ rr   )_get_result_ttyr  )r\   r   r   ress       rc   _get_resultAPIClient._get_result  s     ##F1C1CI1NOOrp   c                     U(       a(  U(       a  U R                  U5      $ U R                  USS9$ U R                  U5        SnU(       a  U R                  U5      $ UR	                  U R                  U5       Vs/ s H  oUPM     sn5      $ s  snf )NTr   rp   )r   r   r   r   joinr   )r\   r   r  is_ttysepxs         rc   r  APIClient._get_result_tty  s     394**3/ /S./ 	s#;;C@@88 ;;C@A@q@A As   9Bc                 L    U H  nU R                   R                  U5        M      g rr   )adapterspop)r\   r   protos      rc   rQ   APIClient._unmount  s    EMMe$ rp   c                    >  [         TU ]  U5      $ ! [        R                  R                   a)  nU R
                  (       a  U R
                  s S nA$ UeS nAff = frr   )rC   get_adapterr   r   InvalidSchemarO   )r\   ru   ri   rb   s      rc   r!  APIClient.get_adapter  sN    	7&s++""00 	##+++		s     AAAAAc                     U R                   $ rr   )r2   )r\   s    rc   rf   APIClient.api_version  s    }}rp   c                 J    [         R                  " XR                  S9U l        g)z
Force a reload of the auth configuration

Args:
    dockercfg_path (str): Use a custom path for the Docker config file
        (default ``$HOME/.docker/config.json`` if present,
        otherwise ``$HOME/.dockercfg``)

Returns:
    None
)r9   N)r   rK   r9   r0   )r\   dockercfg_paths     rc   reload_configAPIClient.reload_config  s      "--*<*<
rp   )r0   rO   r1   rJ   r2   r3   r9   r4   )FFrr   )F)r   T)TF),rZ   
__module____qualname____firstlineno____doc__r   Session	__attrs__r	   r
   r   rD   rW   rn   r   rv   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  rQ   r!  propertyrf   r(  __static_attributes____classcell__)rb   s   @rc   r.   r.   /   sP   $L   ** .9 9I !%d0e.$#E4	iV C C B B B B E E=$AA 
 K ; !;0,6*! *	=!28 K % !%P %  
 
rp   r.   )Er   r   r   	functoolsr   r   requests.exceptionsr    r   	constantsr   r   r   r	   r
   r   r   r   errorsr   r   r   r   r:   r   	transportr   r   r   r   r   r   utils.json_streamr   utils.proxyr   utils.socketr   r   r   buildr   r    r   r!   daemonr"   exec_apir#   imager$   networkr%   pluginr&   secretr'   servicer(   swarmr)   volumer*   r+   ImportErrorr,   r.  r.   r   rp   rc   <module>rG     s           O O O< <  7 A A + % L L   " ( " "   $ " " $   "	,	*
U
U
  		
  		s$   >C- C9 -C65C69DD