Spade
Mini Shell
| Directory:~$ /lib/python2.7/site-packages/requests_toolbelt/adapters/ |
| [Home] [System Details] [Kill Me] |
�
ӵ
Yc@s�dZddlZddlZddlZddlmZddlmZddlmZddlm Z
dejfd ��YZd
efd��YZ
dS(s/The implementation of the
SocketOptionsAdapter.i����N(tadaptersi(t
connection(tpoolmanager(t
exceptionstSocketOptionsAdaptercBsreZdZedk rBeejdejej dfg�Z
ngZ
eje
jd�d�Zed�ZRS(sdAn 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
tdefault_socket_optionsis�This 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.cKs2|jd|j�|_tt|�j|�dS(Ntsocket_options(tpoptdefault_optionsRtsuperRt__init__(tselftkwargs((sM/usr/lib/python2.7/site-packages/requests_toolbelt/adapters/socket_options.pyR
4s c Cs\tjdkr<tjd|d|d|d|j�|_ntt|�j|||�dS(Nit num_poolstmaxsizetblockR(trequestst __build__RtPoolManagerRR Rtinit_poolmanager(RtconnectionsRR((sM/usr/lib/python2.7/site-packages/requests_toolbelt/adapters/socket_options.pyR:s N(t__name__t
__module__t__doc__RtNonetgetattrtHTTPConnectiontsockettIPPROTO_TCPtTCP_NODELAYRtwarningstwarntexctRequestsVersionTooOldR
tFalseR(((sM/usr/lib/python2.7/site-packages/requests_toolbelt/adapters/socket_options.pyRs tTCPKeepAliveAdaptercBseZdZd�ZRS(sJAn
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):
- ``idle``
- ``interval``
- ``count``
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)
cKs�|jdtj�}|jdd�}|jdd�}|jdd�}|tjtjdftjtj|ftjtj|fg}t td d�dk r�|tjtj|fg7}ntt
|�jd||�dS(
NRtidlei<tintervalitcountiitTCP_KEEPIDLE(RRRRt
SOL_SOCKETtSO_KEEPALIVERt
TCP_KEEPINTVLtTCP_KEEPCNTRRR'R R#R
(RRRR$R%R&((sM/usr/lib/python2.7/site-packages/requests_toolbelt/adapters/socket_options.pyR
cs (RRRR
(((sM/usr/lib/python2.7/site-packages/requests_toolbelt/adapters/socket_options.pyR#Is(RRRRRt_compatRRtRR
tHTTPAdapterRR#(((sM/usr/lib/python2.7/site-packages/requests_toolbelt/adapters/socket_options.pyt<module>s;