
    $h                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r   " S S	\R                  5      r " S
 S\5      rg)z/The implementation of the SocketOptionsAdapter.    N)adapters   )
connection)poolmanager)
exceptionsc                      ^  \ rS rSrSr\b-  \" \R                  S\R                  \R                  S4/5      rO/ r\R                  " \R                  S5        U 4S jrS	U 4S jjrSrU =r$ )
SocketOptionsAdapter   a(  An adapter for requests that allows users to specify socket options.

Since version 2.4.0 of requests, it is possible to specify a custom list
of socket options that need to be set before establishing the connection.

Example usage::

    >>> import socket
    >>> import requests
    >>> from requests_toolbelt.adapters import socket_options
    >>> s = requests.Session()
    >>> opts = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 0)]
    >>> adapter = socket_options.SocketOptionsAdapter(socket_options=opts)
    >>> s.mount('http://', adapter)

You can also take advantage of the list of default options on this class
to keep using the original options in addition to your custom options. In
that case, ``opts`` might look like::

    >>> opts = socket_options.SocketOptionsAdapter.default_options + opts

default_socket_options   zThis version of Requests is only compatible with a version of urllib3 which is too old to support setting options on a socket. This adapter is functionally useless.c                 p   > UR                  SU R                  5      U l        [        [        U ]  " S0 UD6  g )Nsocket_options )popdefault_optionsr   superr	   __init__)selfkwargs	__class__s     a/var/www/html/shao/venv/lib/python3.13/site-packages/requests_toolbelt/adapters/socket_options.pyr   SocketOptionsAdapter.__init__5   s5    $jj)9)-)=)=? 	"D2<V<    c                    > [         R                  S:  a'  [        R                  " UUUU R                  S9U l        g [
        [        U ]  XU5        g )Ni  )	num_poolsmaxsizeblockr   )requests	__build__r   PoolManagerr   r   r	   init_poolmanager)r   connectionsr   r   r   s       r   r!   %SocketOptionsAdapter.init_poolmanager;   sM    )*66%#22	 D &>er   )r   r   )F)__name__
__module____qualname____firstlineno____doc__r   getattrHTTPConnectionsocketIPPROTO_TCPTCP_NODELAYr   warningswarnexcRequestsVersionTooOldr   r!   __static_attributes____classcell__r   s   @r   r	   r	      sn    . !%%$  &"4"4a89
 c//.	/= r   r	   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )TCPKeepAliveAdapterJ   a
  An adapter for requests that turns on TCP Keep-Alive by default.

The adapter sets 4 socket options:

- ``SOL_SOCKET`` ``SO_KEEPALIVE`` - This turns on TCP Keep-Alive
- ``IPPROTO_TCP`` ``TCP_KEEPINTVL`` 20 - Sets the keep alive interval
- ``IPPROTO_TCP`` ``TCP_KEEPCNT`` 5 - Sets the number of keep alive probes
- ``IPPROTO_TCP`` ``TCP_KEEPIDLE`` 60 - Sets the keep alive time if the
  socket library has the ``TCP_KEEPIDLE`` constant

The latter three can be overridden by keyword arguments (respectively):

- ``interval``
- ``count``
- ``idle``

You can use this adapter like so::

   >>> from requests_toolbelt.adapters import socket_options
   >>> tcp = socket_options.TCPKeepAliveAdapter(idle=120, interval=10)
   >>> s = requests.Session()
   >>> s.mount('http://', tcp)

c                   > UR                  S[        R                  5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nU[        R                  [        R
                  S4/-   n[        [        S	S 5      b&  U[        R                  [        R                  U4/-  nO;[        R                  S
:X  a'  [        [        SS5      nU[        R                  Xd4/-  n[        [        SS 5      b%  U[        R                  [        R                  U4/-  n[        [        SS 5      b%  U[        R                  [        R                  U4/-  n[        [        U ]>  " SSU0UD6  g )Nr   idle<   interval   count   r   TCP_KEEPINTVLdarwinTCP_KEEPALIVE   TCP_KEEPCNTTCP_KEEPIDLEr   )r   r	   r   r+   
SOL_SOCKETSO_KEEPALIVEr)   r,   r?   sysplatformrC   rD   r   r6   r   )r   r   r   r9   r;   r=   rA   r   s          r   r   TCPKeepAliveAdapter.__init__d   s]   $4$8$H$HJzz&"%::j"-

7A&' 3 3Q7+
 
 6?D1= 2 2F4H4H ( * + +N\\X% $FOTBM 2 2MLMMN6=$/; 2 2F4F4FNOON6>40< 2 2F4G4GNOON!41 	
)	
-3	
r   r   )r$   r%   r&   r'   r(   r   r2   r3   r4   s   @r   r6   r6   J   s    2
 
r   r6   )r(   r+   r.   rG   r   r   _compatr   r    r   r0   HTTPAdapterr	   r6   r   r   r   <module>rM      s@    5   
     !  88// 8v7
. 7
r   