σ
P'^c           @@ sY  d  d l  m Z m Z d  d l m Z d  d l m Z y d  d l m Z Wn! e	 k
 rm d  d l
 m Z n Xd  d l m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d	 l m Z m Z e d
    Z d   Z d   Z d   Z d   Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   i    (   t   absolute_importt   unicode_literals(   t   contextmanager(   t   wraps(   t
   addinfourl(   t   dumps(   t	   from_utf8(   t
   WhateverIOt   items(   t   http(   t   AppCaset   Casec         #@ sG   t  j } t |    f d    } | t  _ z	 t VWd  | t  _ Xd  S(   Nc         @ s(     |   \ } } t  t |  | |   S(   N(   R   R   (   t   urlt   argst   kwargst   response_datat   headers(   t   response_method(    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   _mocked   s    (   R	   t   urlopenR   t   True(   R   R   R   (    (   R   sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   mock_urlopen   s    			c         @ s     f d   S(   Nc         @ s
     g  f S(   N(    (   t   r(   t   res(    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   <lambda>&   t    (    (   R   (    (   R   sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt	   _response%   s    c         C@ s   t  t i d d 6|  d 6  S(   Nu   successu   statusu   retval(   R   R   (   t   value(    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   success_response)   s    c         C@ s   t  t i d d 6|  d 6  S(   Nu   failureu   statusu   reason(   R   R   (   t   reason(    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   fail_response-   s    c           C@ s   t  t i d d 6t d 6  S(   Nu   u.u.u.uu   statusu   retval(   R   R   R   (    (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   unknown_response1   s    t   test_encodingsc           B@ s   e  Z d    Z RS(   c         C@ sv   d } i d d 6t  d  t  |  6} xI t t j t |    D], \ } } |  j | t  |  j | t  qB Wd  S(   Nu   foobaru   Γ¦rbadΓ¦gzaΓ₯Γ₯ΓΓΓu   fΓΈlelser Γ¦r langΓ©u   xuzzybaz(   R   R   R	   t   utf8dictt   assertIsInstancet   str(   t   selft   ukt   dt   keyR   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_utf8dict7   s    
((   t   __name__t
   __module__R(   (    (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyR    5   s   t   test_MutableURLc           B@ s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C@ s   t  j d  } |  j i d d 6d d 6d d 6| j  d | j d	 <t  j t |   } |  j i d d 6d d 6d d 6d d	 6| j  d  S(
   Nu"   http://example.com?x=10&y=20&z=Foou   10u   xu   20u   yu   Foou   zu   Georgeu   name(   R	   t
   MutableURLt   assertDictContainsSubsett   queryR#   (   R$   R   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_url_queryC   s    c         C@ s<   d } t  j |  } |  j t |  j d  d d  d  S(   Nu(   https://e.com:808/foo/bar#zeta?x=10&y=20u   ?i    u   https://e.com:808/foo/bar#zeta(   R	   R,   t   assertEqualR#   t   split(   R$   R   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_url_keeps_everythingO   s
    c         C@ s/   t  j d  } |  j t |  j d   d  S(   Nu   http://e.com/foo/baru   <MutableURL: http://e.com(   R	   R,   t
   assertTruet   reprt
   startswith(   R$   R   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test___repr__X   s    c         C@ sR   t  j d  } i d d 6| _ t  j t |   } |  j | j i d d 6 d  S(   Nu   http://e.com/foo/bar/?x=10u   xxxu   zzz(   R	   R,   R.   R#   R0   (   R$   R   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_set_query\   s    (   R)   R*   R/   R2   R6   R7   (    (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyR+   A   s   				t   test_HttpDispatchc           B@ s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c      
   C@ sV   t  t d   > t j d d i d d 6d d 6 } |  j | j   d  Wd  QXd  S(   Nid   u   http://example.com/mulu   GETi
   u   xu   y(   R   R   R	   t   HttpDispatchR0   t   dispatch(   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_dispatch_successe   s    c      
   C@ sc   t  t d   K t j d d i d d 6d d 6 } |  j t j   | j   Wd  QXWd  QXd  S(   Nu   Invalid moon alignmentu   http://example.com/mulu   GETi
   u   xu   y(   R   R   R	   R9   t   assertRaisest   RemoteExecuteErrorR:   (   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_dispatch_failurek   s
    c      
   C@ sc   t  t d   K t j d d i d d 6d d 6 } |  j t j   | j   Wd  QXWd  QXd  S(   Nu    u   http://example.com/mulu   GETi
   u   xu   y(   R   R   R	   R9   R<   t   InvalidResponseErrorR:   (   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_dispatch_empty_responser   s
    c      
   C@ sc   t  t d   K t j d d i d d 6d d 6 } |  j t j   | j   Wd  QXWd  QXd  S(   Nu   {'#{:'''u   http://example.com/mulu   GETi
   u   xu   y(   R   R   R	   R9   R<   R?   R:   (   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_dispatch_non_jsony   s
    c      
   C@ s`   t  t    K t j d d i d d 6d d 6 } |  j t j   | j   Wd  QXWd  QXd  S(   Nu   http://example.com/mulu   GETi
   u   xu   y(   R   R   R	   R9   R<   t   UnknownStatusErrorR:   (   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_dispatch_unknown_status   s
    c      
   C@ sV   t  t d   > t j d d i d d 6d d 6 } |  j | j   d  Wd  QXd  S(   Nid   u   http://example.com/mulu   POSTi
   u   xu   y(   R   R   R	   R9   R0   R:   (   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_dispatch_POST   s    (   R)   R*   R;   R>   R@   RA   RC   RD   (    (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyR8   c   s   					t   test_URLc           B@ s   e  Z d    Z d   Z RS(   c      	   C@ sl   t  |  j j _ t t d   E t j d d |  j j d d d d  } |  j	 | j
   d  Wd  QXd  S(   Nid   u   http://example.com/mult   appt   xi
   t   y(   R   RF   t   conft   CELERY_ALWAYS_EAGERR   R   R	   t   URLt	   get_asyncR0   t   get(   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_URL_get_async   s    c      	   C@ sl   t  |  j j _ t t d   E t j d d |  j j d d d d  } |  j	 | j
   d  Wd  QXd  S(   Nid   u   http://example.com/mulRF   RG   i
   RH   (   R   RF   RI   RJ   R   R   R	   RK   t
   post_asyncR0   RM   (   R$   R&   (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   test_URL_post_async   s    (   R)   R*   RN   RP   (    (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyRE      s   	N(    t
   __future__R    R   t
   contextlibR   t	   functoolsR   t   urllibR   t   ImportErrort   urllib.requestt   anyjsonR   t   kombu.utils.encodingR   t   celery.fiveR   R   t   celery.taskR	   t   celery.tests.caseR
   R   R   R   R   R   R   R    R+   R8   RE   (    (    (    sG   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/compat_modules/test_http.pyt   <module>   s(   				"+