σ
P'^c           @@  sΫ   d  Z  d d l m Z d d l Z y4 d d l m Z d d l m Z d d l m	 Z	 Wn e
 k
 rw d Z Z Z	 n Xd d l m Z d d l m Z d d	 l m Z d
 d l m Z d g Z d e f d     YZ d S(   sc   
    celery.backends.couchbase
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    CouchBase result store backend.

i    (   t   absolute_importN(   t	   Couchbase(   t
   Connection(   t   NotFoundError(   t
   _parse_url(   t   ImproperlyConfigured(   t   maybe_timedeltai   (   t   KeyValueStoreBackendt   CouchBaseBackendc           B@  s   e  Z d  Z d Z d Z d Z d Z d Z e	 Z
 d Z e Z d Z d Z d d  Z d   Z e d    Z d   Z d	   Z d
   Z d   Z RS(   s   CouchBase backend.

    :raises celery.exceptions.ImproperlyConfigured: if
        module :mod:`couchbase` is not available.

    t   defaultt	   localhosti  g      @c         O@  s³  t  t |   j | |   | |  _ | j d  pC t |  j j j  |  _	 t
 d  k rd t d   n  d  } } } } } | rΏ t |  \ }	 } } } } } }	 | rΆ | j d  n d  } n  |  j j j d d   }
 |
 d  k	 rt |
 t  s
t d   q
n i  }
 | p"|
 j d |  j  |  _ t | pC|
 j d |  j   |  _ | pd|
 j d |  j  |  _ | p|
 j d	 |  j  |  _ | p |
 j d
 |  j  |  _ d  |  _ d  S(   Nt   expiressG   You need to install the couchbase library to use the CouchBase backend.t   /t!   CELERY_COUCHBASE_BACKEND_SETTINGSs6   Couchbase backend settings should be grouped in a dictt   hostt   portt   buckett   usernamet   password(   t   superR   t   __init__t   urlt   getR   t   appt   conft   CELERY_TASK_RESULT_EXPIRESR   R   t   NoneR   R   t   stript
   isinstancet   dictR   t   intR   R   R   R   t   _connection(   t   selfR   t   argst   kwargst   uhostt   uportt   unamet   upasst   ubuckett   _t   config(    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyR   0   s.    	!$c         C@  s»   |  j  d k r΄ i |  j d 6|  j d 6} |  j rL | j i |  j d 6 n  |  j ro | j i |  j d 6 n  |  j r | j i |  j d 6 n  t j	 d |  t
 |   |  _  n  |  j  S(   s    Connect to the Couchbase server.R   R   R   R   R   s   couchbase settings %rN(   R   R   R   R   R   t   updateR   R   t   loggingt   debugR   (   R    R"   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyt   _get_connectionS   s    			c         C@  s
   |  j    S(   N(   R-   (   R    (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyt
   connectionc   s    c         C@  s0   y |  j  j |  j SWn t k
 r+ d  SXd  S(   N(   R.   R   t   valueR   R   (   R    t   key(    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyR   g   s    c         C@  s   |  j  j | |  d  S(   N(   R.   t   set(   R    R0   R/   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyR1   m   s    c         C@  s    g  | D] } |  j  |  ^ q S(   N(   R   (   R    t   keysR0   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyt   mgetp   s    c         C@  s   |  j  j |  d  S(   N(   R.   t   delete(   R    R0   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyR4   s   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   t   Falset   quiett	   conncachet   Truet
   unlock_gilt   timeoutt
   transcoderR   R-   t   propertyR.   R   R1   R3   R4   (    (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyR      s$   #				(   R7   t
   __future__R    R+   t	   couchbaseR   t   couchbase.connectionR   t   couchbase.exceptionsR   t   ImportErrorR   t   kombu.utils.urlR   t   celery.exceptionsR   t   celery.utils.timeutilsR   t   baseR   t   __all__R   (    (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/backends/couchbase.pyt   <module>   s   	