σ
O'^c           @@  sσ   d  Z  d d l m Z d d l Z d d l m Z m Z d d l m Z d d l	 m
 Z
 d d l m Z d d	 l m Z y d d l Z Wn e k
 r‘ d Z n Xd
 Z d Z d Z d   Z d e j f d     YZ d e j f d     YZ d S(   s‘   
kombu.transport.couchdb
=======================

CouchDB transport.

:copyright: (c) 2010 - 2013 by David Clymer.
:license: BSD, see LICENSE for more details.

i    (   t   absolute_importN(   t   loadst   dumps(   t   Empty(   t   uuid4(   t   bytes_to_stri   (   t   virtuali`  t   kombu_defaults#   David Clymer <david@zettazebra.com>c         C@  sH   d d l  m } | j d d d  } | j |   sD | j |   n  d  S(   Ni    (   t   designt   kombut   messagessv   
        function (doc) {
          if (doc.queue && doc.payload)
            emit(doc.queue, doc);
        }
        (   t   couchdbR   t   ViewDefinitiont   get_doct   sync(   t   dbR   t   view(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   create_message_view"   s
    	t   Channelc           B@  sY   e  Z d Z e Z d    Z d   Z d   Z d   Z	 d   Z
 d   Z e d    Z RS(   c         K@  s5   |  j  j i t   j d 6| d 6t |  d 6 d  S(   Nt   _idt   queuet   payload(   t   clientt   saveR   t   hexR   (   t   selfR   t   messaget   kwargs(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   _put4   s    c         C@  s[   |  j  | d d } | s' t    n  | j d j } |  j j |  t t | d   S(   Nt   limiti   i    R   (   t   _queryR   t   rowst   valueR   t   deleteR   R   (   R   R   t   resultt   item(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   _get9   s    c         C@  s=   |  j  |  } x! | D] } |  j j | j  q Wt |  S(   N(   R   R   R!   R    t   len(   R   R   R"   R#   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   _purgeB   s    c         C@  s   t  |  j |   S(   N(   R%   R   (   R   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   _sizeH   s    c         C@  sδ   |  j  j } | j } | j r$ d p' d } | s= | d k rF t } n  | j pR t } t j d | | j	 | f  } y( | j
 r | j
 | j f | j _ n  Wn t k
 r― n Xy | | SWn! t j j k
 rί | j |  SXd  S(   Nt   httpst   httpt   /s   %s://%s:%s/(   t
   connectionR   t   virtual_hostt   sslt   DEFAULT_DATABASEt   portt   DEFAULT_PORTR   t   Servert   hostnamet   useridt   passwordt   resourcet   credentialst   AttributeErrorR)   t   ResourceNotFoundt   create(   R   t   conninfot   dbnamet   protoR/   t   server(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   _openK   s&    			c         K@  s;   |  j  s" t |  j  t |  _  n  |  j j d d | | S(   Ns   kombu/messagest   key(   t   view_createdR   R   t   TrueR   (   R   R   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyR   a   s    	c         C@  s(   |  j  d  k r! |  j   |  _  n  |  j  S(   N(   t   _clientt   NoneR>   (   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyR   h   s    N(   t   __name__t
   __module__RC   RB   t   FalseR@   R   R$   R&   R'   R>   R   t   propertyR   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyR   /   s   							t	   Transportc        	   B@  sΦ   e  Z e Z d  Z e Z e j j e	 j
 e e d d
  e e d d
  e e d d
  f Z e j j e e d d
  e e d d
  e e d d
  e e d d
  e e d d
  f Z d Z d Z d   Z d	   Z RS(   i   t	   HTTPErrort   ServerErrort   Unauthorizedt   PreconditionFailedt   ResourceConflictR8   R   c         O@  s8   t  d  k r t d   n  t t |   j | |   d  S(   Ns-   Missing couchdb library (pip install couchdb)(   R   RC   t   ImportErrort   superRH   t   __init__(   R   t   argsR   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyRP      s    c         C@  s   t  j S(   N(   R   t   __version__(   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   driver_version   s    N(   RD   RE   R   t   polling_intervalR0   t   default_portR   RH   t   connection_errorst   sockett   errort   getattrR   RC   t   channel_errorst   driver_typet   driver_nameRP   RS   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyRH   o   s$   			(   t   __doc__t
   __future__R    RW   t   anyjsonR   R   t
   kombu.fiveR   t   kombu.utilsR   t   kombu.utils.encodingR   t    R   R   RN   RC   R0   R.   t
   __author__R   R   RH   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/couchdb.pyt   <module>
   s"   
	@