ķ
o
\c           @   sF   d  Z  d d l m Z d d l m Z m Z d e f d     YZ d S(   sē   
requests_toolbelt.source_adapter
================================

This file contains an implementation of the SourceAddressAdapter originally
demonstrated on the Requests GitHub page.
i˙˙˙˙(   t   HTTPAdapteri   (   t   poolmanagert
   basestringt   SourceAddressAdapterc           B   s,   e  Z d  Z d   Z e d  Z d   Z RS(   s9  
    A Source Address Adapter for Python Requests that enables you to choose the
    local address to bind to. This allows you to send your HTTP requests from a
    specific interface and IP address.

    Two address formats are accepted. The first is a string: this will set the
    local IP address to the address given in the string, and will also choose a
    semi-random high port for the local port number.

    The second is a two-tuple of the form (ip address, port): for example,
    ``('10.10.10.10', 8999)``. This will set the local IP address to the first
    element, and the local port to the second element. If ``0`` is used as the
    port number, a semi-random high port will be selected.

    .. warning:: Setting an explicit local port can have negative interactions
                 with connection-pooling in Requests: in particular, it risks
                 the possibility of getting "Address in use" errors. The
                 string-only argument is generally preferred to the tuple-form.

    Example usage:

    .. code-block:: python

        import requests
        from requests_toolbelt.adapters.source import SourceAddressAdapter

        s = requests.Session()
        s.mount('http://', SourceAddressAdapter('10.10.10.10'))
        s.mount('https://', SourceAddressAdapter(('10.10.10.10', 8999))
    c         K   sb   t  | t  r! | d f |  _ n' t  | t  r< | |  _ n t d   t t |   j |   d  S(   Ni    s<   source_address must be IP address string or (ip, port) tuple(   t
   isinstanceR   t   source_addresst   tuplet	   TypeErrort   superR   t   __init__(   t   selfR   t   kwargs(    (    sV   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/adapters/source.pyR	   -   s    	c      	   C   s.   t  j d | d | d | d |  j  |  _  d  S(   Nt	   num_poolst   maxsizet   blockR   (   R   t   PoolManagerR   (   R
   t   connectionsR   R   (    (    sV   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/adapters/source.pyt   init_poolmanager9   s
    	c         O   s&   |  j  | d <t t |   j | |   S(   NR   (   R   R   R   t   proxy_manager_for(   R
   t   argsR   (    (    sV   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/adapters/source.pyR   @   s    (   t   __name__t
   __module__t   __doc__R	   t   FalseR   R   (    (    (    sV   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/adapters/source.pyR      s   	N(   R   t   requests.adaptersR    t   _compatR   R   R   (    (    (    sV   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/adapters/source.pyt   <module>   s   