ó
P'—^c           @@  s  d  Z  d d l m Z d d l Z d d l Z y  d d l m Z m Z m Z Wn7 e	 k
 r‡ d d l
 m Z d d l m Z m Z n Xd d l m Z m Z d d l m Z m Z d d	 l m Z d
 d d d d d g Z e d d g ƒ Z e e ƒ Z e j d d k r/d d l m Z m Z d „  Z n d d l m Z m Z d „  Z d
 e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e  f d „  ƒ  YZ" e j# d „ Z$ d e% f d „  ƒ  YZ& d e% f d „  ƒ  YZ' e d d d e( d  d d! d d" e* ƒ d d d# „ ƒ Z+ d e& f d$ „  ƒ  YZ, d S(%   sN   
    celery.task.http
    ~~~~~~~~~~~~~~~~

    Webhook task implementation.

i    (   t   absolute_importN(   t	   parse_qslt	   urlencodet   urlparse(   R   (   R   R   (   t   shared_taskt   __version__(   t   itemst   reraise(   t   get_task_loggert   InvalidResponseErrort   RemoteExecuteErrort   UnknownStatusErrort   HttpDispatcht   dispatcht   URLt   GETt   HEADi   (   t   Requestt   urlopenc         C@  s   t  |  t ƒ s t |  ƒ S|  S(   N(   t
   isinstancet   dict(   t   tup(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt   utf8dict#   s    
c         C@  s   t  d „  |  Dƒ ƒ S(   sY   With a dict's items() tuple return a new dict with any utf-8
        keys/values encoded.c         s@  sH   |  ]> \ } } | j  d  ƒ t | t ƒ r9 | j  d  ƒ n | f Vq d S(   s   utf-8N(   t   encodeR   t   unicode(   t   .0t   kt   v(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pys	   <genexpr>0   s   (   R   (   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR   ,   s    c           B@  s   e  Z d  Z RS(   s+   The remote server gave an invalid response.(   t   __name__t
   __module__t   __doc__(    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR	   5   s   c           B@  s   e  Z d  Z RS(   s$   The remote task gave a custom error.(   R   R   R   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR
   9   s   c           B@  s   e  Z d  Z RS(   s)   The remote server gave an unknown status.(   R   R   R   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR   =   s   c         C@  s¹   |  s t  d ƒ ‚ n  y | |  ƒ } Wn9 t k
 r` } t t  t  t | ƒ ƒ t j ƒ  d ƒ n X| d } | d k r | d S| d k r£ t | j d ƒ ƒ ‚ n t t | ƒ ƒ ‚ d S(	   s3   Extract the response text from a raw JSON response.s   Empty responsei   t   statust   successt   retvalt   failuret   reasonN(	   R	   t
   ValueErrorR   t   strt   syst   exc_infoR
   t   getR   (   t   raw_responset   loadst   payloadt   excR   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt   extract_responseA   s    	!
t
   MutableURLc           B@  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sI  Object wrapping a Uniform Resource Locator.

    Supports editing the query parameter list.
    You can convert the object back to a string, the query will be
    properly urlencoded.

    Examples

        >>> url = URL('http://www.google.com:6580/foo/bar?x=3&y=4#foo')
        >>> url.query
        {'x': '3', 'y': '4'}
        >>> str(url)
        'http://www.google.com:6580/foo/bar?y=4&x=3#foo'
        >>> url.query['x'] = 10
        >>> url.query.update({'George': 'Costanza'})
        >>> str(url)
        'http://www.google.com:6580/foo/bar?y=4&x=10&George=Costanza#foo'

    c         C@  s/   t  | ƒ |  _ t t |  j d ƒ ƒ |  _ d  S(   Ni   (   R   t   partsR   R   t   query(   t   selft   url(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt   __init__h   s    c         C@  s®   |  j  \ } } } } } } t t t |  j ƒ ƒ ƒ } | d | | pI d | r^ d j | ƒ n d | rv d j | ƒ n d | rŽ d j | ƒ n d g } d j d „  | Dƒ ƒ S(   Ns   ://t   /s   ;{0}t    s   ?{0}s   #{0}c         s@  s   |  ] } | r | Vq d  S(   N(    (   R   t   c(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pys	   <genexpr>s   s    (   R/   R   R   R   R0   t   formatt   join(   R1   t   schemet   netloct   patht   paramsR0   t   fragmentt
   components(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt   __str__l   s    c         C@  s   d j  t |  ƒ j |  ƒ S(   Ns
   <{0}: {1}>(   R7   t   typeR   (   R1   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt   __repr__u   s    (   R   R   R   R3   R?   RA   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR.   T   s   			c           B@  sP   e  Z d  Z d j d e ƒ Z d Z d „  Z d „  Z d „  Z	 e
 d „  ƒ Z RS(   s&  Make task HTTP request and collect the task result.

    :param url: The URL to request.
    :param method: HTTP method used. Currently supported methods are `GET`
        and `POST`.
    :param task_kwargs: Task keyword arguments.
    :param logger: Logger used for user/system feedback.

    s   celery/{version}t   versioni   c         K@  s7   | |  _  | |  _ | |  _ | j d ƒ p- t |  _ d  S(   Nt   logger(   R2   t   methodt   task_kwargsR(   RC   (   R1   R2   RD   RE   t   kwargs(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR3   †   s    			c         C@  sU   t  | | ƒ } x- t |  j ƒ D] \ } } | j | | ƒ q Wt | ƒ } | j ƒ  S(   s-   Perform HTTP request and return the response.(   R   R   t   http_headerst
   add_headerR   t   read(   R1   R2   RD   R<   t   requestt   keyt   valt   response(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt   make_requestŒ   s
    c         C@  s}   t  |  j ƒ } d } |  j t k r: | j j |  j ƒ n t t	 t
 |  j ƒ ƒ ƒ } |  j t | ƒ |  j | ƒ } t | ƒ S(   s$   Dispatch callback and return result.N(   R.   R2   t   NoneRD   t   GET_METHODSR0   t   updateRE   R   R   R   RN   R%   R-   (   R1   R2   R<   R)   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR   ”   s    c         C@  s   i |  j  d 6} | S(   Ns
   User-Agent(   t
   user_agent(   R1   t   headers(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyRG   Ÿ   s    (   R   R   R   R7   t   celery_versionRR   t   timeoutR3   RN   R   t   propertyRG   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR   y   s   				t   names   celery.http_dispatcht   bindR2   RD   t   accept_magic_kwargsc         K@  s(   t  | p |  j | p |  j | ƒ j ƒ  S(   sé  Task dispatching to an URL.

    :keyword url: The URL location of the HTTP callback task.
    :keyword method: Method to use when dispatching the callback. Usually
        `GET` or `POST`.
    :keyword \*\*kwargs: Keyword arguments to pass on to the HTTP callback.

    .. attribute:: url

        If this is set, this is used as the default URL for requests.
        Default is to require the user of the task to supply the url as an
        argument, as this attribute is intended for subclasses.

    .. attribute:: method

        If this is set, this is the default method used for requests.
        Default is to require the user of the task to supply the method as an
        argument, as this attribute is intended for subclasses.

    (   R   R2   RD   R   (   R1   R2   RD   RF   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR   ¥   s    c           B@  s5   e  Z d  Z d Z d d d „ Z d „  Z d „  Z RS(   sÒ   HTTP Callback URL

    Supports requesting an URL asynchronously.

    :param url: URL to request.
    :keyword dispatcher: Class used to dispatch the request.
        By default this is :func:`dispatch`.

    c         C@  si   t  t |  ƒ j | ƒ | |  _ | p+ |  j |  _ |  j d  k re |  j rY |  j j d n t |  _ n  d  S(   Ns   celery.http_dispatch(   t   superR   R3   t   appt
   dispatcherRO   t   tasksR   (   R1   R2   R\   R[   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR3   Í   s    	c         K@  s   |  j  j t |  ƒ d |  S(   NR   (   R\   t   delayR%   (   R1   RF   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt	   get_asyncØ   s    c         K@  s   |  j  j t |  ƒ d |  S(   Nt   POST(   R\   R^   R%   (   R1   RF   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt
   post_asyncÛ   s    N(   R   R   R   RO   R\   R3   R_   Ra   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyR   Á   s
   		(-   R   t
   __future__R    t   anyjsonR&   t   urllib.parseR   R   R   t   ImportErrort   urllibt   celeryR   R   RT   t   celery.fiveR   R   t   celery.utils.logR   t   __all__t	   frozensetRP   R   RC   t   version_infot   urllib.requestR   R   R   t   urllib2t	   ExceptionR	   R
   R   R*   R-   t   objectR.   R   t   TrueRO   t   FalseR   R   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/task/http.pyt   <module>   s<    			%,