
    hw                     z    d Z ddlmZ ddlmZ ddlmZ ddlmZ 	 ddl	Z	dZd	Z G d
 de      Zy# e
$ r dZ	Y w xY w)zCouchDB result store backend.    )bytes_to_str)
_parse_url)ImproperlyConfigured   )KeyValueStoreBackendN)CouchBackendzKYou need to install the pycouchdb library to use the CouchDB result backendc                   j     e Zd ZdZdZdZdZdZdZdZ	d fd	Z
d Zed	        Zd
 Zd Zd Zd Z xZS )r   zCouchDB backend.

    Raises:
        celery.exceptions.ImproperlyConfigured:
            if module :pypi:`pycouchdb` is not available.
    defaulthttp	localhosti`  Nc                    t        |   |i | || _        t        t	        t
              d x}x}x}x}x}}	|r(t        |      \  }
}}}}}	}
|	r|	j                  d      nd }	|xs | j                  | _        |xs | j                  | _	        t        |xs | j                        | _        |	xs | j                  | _        |xs | j                  | _        |xs | j                  | _        d | _        y )N/)super__init__url	pycouchdbr   ERR_LIB_MISSINGr   stripschemehostintport	containerusernamepassword_connection)selfr   argskwargsuschemeuhostuportunameupass
ucontainer_	__class__s              S/var/www/Befach/backend/env/lib/python3.12/site-packages/celery/backends/couchdb.pyr   zCouchBackend.__init__$   s    $)&)&77?CCC%C%C%C%*;Ec?8AueUE:q2<))#.$J,&TYY	*+	#5t~~..    c           	         | j                   rf| j                  rZ| j                   d| j                    d| j                   d| j                   d| j                   	}t        j                  |d      }n=| j                   d| j                   d| j                   }t        j                  |      }	 |j                  | j                        S # t
        j                  j                  $ r |j                  | j                        cY S w xY w)zConnect to the CouchDB server.z://:@basic)
authmethod)r   r   r   r   r   r   Serverdatabaser   
exceptionsNotFoundcreate)r   conn_stringservers      r(   _get_connectionzCouchBackend._get_connection9   s    ==T]]![[MT]]O1T]]O1TYYKWXY]YbYbXcdK%%kgFF![[MTYYKqDK%%k2F	1??4>>22##,, 	1==00	1s   1C 8DDc                 \    | j                   | j                         | _         | j                   S N)r   r6   )r   s    r(   
connectionzCouchBackend.connectionG   s+    ##335Dr)   c                     t        |      }	 | j                  j                  |      d   S # t        j                  j
                  $ r Y y w xY w)Nvalue)r   r9   getr   r1   r2   r   keys     r(   r<   zCouchBackend.getM   sI    3	??&&s+G44##,, 		s   + A
Ac                    t        |      }||d}	 | j                  j                  |       y # t        j                  j
                  $ r> | j                  j                  |      }||d<   | j                  j                  |       Y y w xY w)N)_idr;   r;   )r   r9   saver   r1   Conflictr<   )r   r>   r;   datas       r(   setzCouchBackend.setT   sw    3U+	'OO  &##,, 	'??&&s+D!DMOO  &		's   . AB	B	c                 J    |D cg c]  }| j                  |       c}S c c}w r8   )r<   )r   keysr>   s      r(   mgetzCouchBackend.mget_   s    )-.#...s    c                 :    | j                   j                  |       y r8   )r9   deleter=   s     r(   rI   zCouchBackend.deleteb   s    s#r)   r8   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r6   propertyr9   r<   rD   rG   rI   __classcell__)r'   s   @r(   r   r      sZ     IFDDHH *1    
	'/$r)   r   )rM   kombu.utils.encodingr   kombu.utils.urlr   celery.exceptionsr   baser   r   ImportError__all__r   r    r)   r(   <module>rW      sO    # - & 2 & 
N$' N$  Is   0 ::