ó
Be¤Vc           @   s½   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 d	 e j
 f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d S(   s_   The App Engine Transport Adapter for requests.

This requires a version of requests >= 2.10.0.
iÿÿÿÿN(   t   adapters(   t   sessionsi   (   t
   exceptions(   t
   gaecontrib(   t   timeoutt   AppEngineAdapterc           B   s&   e  Z d  Z e d „ Z e d „ Z RS(   sv  A transport adapter for Requests to use urllib3's GAE support.

    Implements request's HTTPAdapter API.

    When deploying to Google's App Engine service, some of Requests'
    functionality is broken. There is underlying support for GAE in urllib3.
    This functionality, however, is opt-in and needs to be enabled explicitly
    for Requests to be able to use it.
    c         O   s0   t  ƒ  | |  _ t t |  ƒ j |  | | Ž d  S(   N(   t   _check_versiont   _validate_certificatet   superR   t   __init__(   t   selft   validate_certificatet   argst   kwargs(    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR	   /   s    	c         C   s   t  |  j ƒ |  _ d  S(   N(   t   _AppEnginePoolManagerR   t   poolmanager(   R
   t   connectionst   maxsizet   block(    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyt   init_poolmanager4   s    (   t   __name__t
   __module__t   __doc__t   TrueR	   t   FalseR   (    (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR   $   s   	R   c           B   s,   e  Z d  Z e d „ Z d „  Z d „  Z RS(   sK  Implements urllib3's PoolManager API expected by requests.

    While a real PoolManager map hostnames to reusable Connections,
    AppEngine has no concept of a reusable connection to a host.
    So instead, this class constructs a small Connection per request,
    that is returned to the Adapter and used to access the URL.
    c         C   s   t  j d | ƒ |  _ d  S(   NR   (   R   t   AppEngineManagert   appengine_manager(   R
   R   (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR	   A   s    	c         C   s   t  |  j | ƒ S(   N(   t   _AppEngineConnectionR   (   R
   t   url(    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyt   connection_from_urlE   s    c         C   s   d  S(   N(    (   R
   (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyt   clearH   s    (   R   R   R   R   R	   R   R   (    (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR   8   s   	R   c        	   B   s>   e  Z d  Z d „  Z d d d e e e j j d d d „ Z	 RS(   s¬  Implements urllib3's HTTPConnectionPool API's urlopen().

    This Connection's urlopen() is called with a host-relative path,
    so in order to properly support opening the URL, we need to store
    the full URL when this Connection is constructed from the PoolManager.

    This code wraps AppEngineManager.urlopen(), which exposes a different
    API than in the original urllib3 urlopen(), and thus needs this adapter.
    c         C   s   | |  _  | |  _ d  S(   N(   R   R   (   R
   R   R   (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR	   W   s    	c         K   sb   |  j  j | ƒ s+ t d |  j  | f ƒ ‚ |  j j | |  j  d | d | d | d | d | | S(   NsŽ   AppEngineConnection constructed with (%s), and called urlopen with (%s). Expected the latter to be the host-relative equivalent of the former.t   bodyt   headerst   retriest   redirectR   (   R   t   endswitht   AssertionErrorR   t   urlopen(   R
   t   methodR   R   R    R!   R"   t   assert_same_hostR   t   pool_timeoutt   release_connt   response_kw(    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR%   [   s    			N(
   R   R   R   R	   t   NoneR   R   t   Timeoutt   DEFAULT_TIMEOUTR%   (    (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR   L   s   				c           C   s   t  ƒ  t t _ d S(   s  Sets up all Sessions to use AppEngineAdapter by default.

    If you don't want to deal with configuring your own Sessions,
    or if you use libraries that use requests directly (ie requests.post),
    then you may prefer to monkeypatch and auto-configure all Sessions.
    N(   R   R   R   t   HTTPAdapter(    (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyt   monkeypatchv   s    c           C   s.   t  d  k r* t j d j t j ƒ ƒ ‚ n  d  S(   Ns^   The toolbelt requires at least Requests 2.10.0 to be installed. Version {0} was found instead.(   R   R+   t   exct   VersionMismatchErrort   formatt   requestst   __version__(    (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyR   „   s    (   R   R3   R    R   t    R   R0   t   _compatR   R   R.   R   t   objectR   R   R/   R   (    (    (    sH   /usr/lib/python2.7/dist-packages/requests_toolbelt/adapters/appengine.pyt   <module>   s   *	