
    g                         d dl Z d dlZd dlmZmZmZmZ dZdZdZ	dZ
 G d d      Z G d d	e      Z G d
 de      Z G d de      Z G d de      Zy)    N)HTTPSConnectionPoolHTTPConnectionPoolPoolManagerProxyManager   <      c                   "    e Zd ZdZedd       Zy)TCPKeepAliveValidationMethodsa<  
    This class contains a single method whose sole purpose is to set up TCP Keep Alive probes on the socket for a
    connection. This is necessary for long-running requests which will be silently terminated by the AWS Network Load
    Balancer which kills a connection if it is idle for more than 350 seconds.
    c                    |dk(  ryt         j                  }|dk(  rKt        | j                  d      r4t        t        d      r#t        t        d      rt        t        d      rt        t        d      r| j                  j                  t        j                  t        j                  d	       | j                  j                  t        j                  t        j                  t               | j                  j                  t        j                  t        j                  t               | j                  j                  t        j                  t        j                  t               y|d
k(  rdt        t        d      rTt        | j                  dd      	 <| j                  j!                  t        j"                  d	t        dz  t        dz  f       y|dk(  rt        | j                  dd      m| j                  j                  t        j                  t        j                  d	       | j                  j                  t        j                  t$        t               yyy)a  
        Adjusts the socket settings so that the client sends a TCP keep alive probe over the connection. This is only
        applied where possible, if the ability to set the socket options is not available, for example using Anaconda,
        then the settings will be left as is.
        :param conn: The connection to update the socket settings for
        :param str protocol: The protocol of the connection
        :return: None
        httpNlinux
setsockoptSO_KEEPALIVETCP_KEEPIDLETCP_KEEPINTVLTCP_KEEPCNT   win32SIO_KEEPALIVE_VALSioctli  darwin)sysplatformhasattrsocksocketr   
SOL_SOCKETr   IPPROTO_TCPr   TCP_KEEP_IDLEr   TCP_KEEPALIVE_INTERVALr   TCP_KEEP_CNTgetattrr   r   TCP_KEEPALIVE)connprotocolr   s      A/opt/Tautulli/lib/cloudinary/api_client/tcp_keep_alive_manager.pyadjust_connection_socketz6TCPKeepAliveValidationMethods.adjust_connection_socket   s    v <<GDII|$DQWYgIh/GFO4TY`aganZpII  !2!2F4G4GKII  !3!3V5H5H-XII  !3!3V5I5IKabII  !3!3V5G5GV  WV5I%JwW[W`W`biW[P]dhPiIIOOF55=4;OQgjnQn7op !gdiit&L&XII  !2!2F4G4GKII  !3!3]DZ[ 'Y!    N)https)__name__
__module____qualname____doc__staticmethodr(    r)   r'   r   r      s     !\ !\r)   r   c                   "     e Zd ZdZ fdZ xZS )TCPKeepAliveHTTPSConnectionPoolz
    This class overrides the _validate_conn method in the HTTPSConnectionPool class. This is the entry point to use
    for modifying the socket as it is called after the socket is created and before the request is made.
    c                 X    t         t        |   |       t        j	                  |d       y)U
        Called right before a request is made, after the socket is created.
        r*   N)superr2   _validate_connr   r(   selfr%   	__class__s     r'   r6   z.TCPKeepAliveHTTPSConnectionPool._validate_connE   s'    
 	-tCDI 	&>>tWMr)   r+   r,   r-   r.   r6   __classcell__r9   s   @r'   r2   r2   ?   s    
N Nr)   r2   c                   "     e Zd ZdZ fdZ xZS )TCPKeepAliveHTTPConnectionPoola  
    This class overrides the _validate_conn method in the HTTPSConnectionPool class. This is the entry point to use
    for modifying the socket as it is called after the socket is created and before the request is made.
    In the base class this method is passed completely.
    c                 X    t         t        |   |       t        j	                  |d       y)r4   r   N)r5   r>   r6   r   r(   r7   s     r'   r6   z-TCPKeepAliveHTTPConnectionPool._validate_connW   s'    
 	,dB4H 	&>>tVLr)   r:   r<   s   @r'   r>   r>   P   s    M Mr)   r>   c                   $     e Zd ZdZd fd	Z xZS )TCPKeepAlivePoolManagerz
    This Pool Manager has only had the pool_classes_by_scheme variable changed. This now points at the TCPKeepAlive
    connection pools rather than the default connection pools.
    c                 V    t        t        | 
  d||d| t        t        d| _        y )N)	num_poolsheadersr   r*   r0   )r5   rA   __init__r>   r2   pool_classes_by_scheme)r8   rC   rD   connection_pool_kwr9   s       r'   rF   z TCPKeepAlivePoolManager.__init__h   s-    %t5q	SZq^pq/MXw&x#r)   )
   Nr+   r,   r-   r.   rF   r;   r<   s   @r'   rA   rA   b   s    
y yr)   rA   c                   $     e Zd ZdZd fd	Z xZS )TCPKeepAliveProxyManagerz
    This Proxy Manager has only had the pool_classes_by_scheme variable changed. This now points at the TCPKeepAlive
    connection pools rather than the default connection pools.
    c                 Z    t        t        | 
  d||||d| t        t        d| _        y )N)	proxy_urlrC   rD   proxy_headersrE   r0   )r5   rL   rF   r>   r2   rG   )r8   rN   rC   rD   rO   rH   r9   s         r'   rF   z!TCPKeepAliveProxyManager.__init__s   s?    &6 	MV_ipER	M9K	M 0NXw&x#r)   )rI   NNrJ   r<   s   @r'   rL   rL   m   s    
y yr)   rL   )r   r   urllib3r   r   r   r   r$   r    r!   r"   r   r2   r>   rA   rL   r0   r)   r'   <module>rQ      so     
 V V  )\ )\XN&9 N"M%7 M$yk y
y| 
yr)   