o
    ›¨Êhw  ã                   @   st   d Z ddlmZ ddlmZ ddlmZ ddlmZ zddl	Z	W n e
y+   dZ	Y nw dZd	ZG d
d„ deƒZdS )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                       sn   e Zd ZdZdZdZdZdZdZdZ	d‡ fdd„	Z
d	d
„ Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )r   zŒCouchDB backend.

    Raises:
        celery.exceptions.ImproperlyConfigured:
            if module :pypi:`pycouchdb` is not available.
    ÚdefaultÚhttpÚ	localhosti`  Nc                    sÂ   t ƒ j|i |¤Ž || _td u rttƒ‚d  } } } } }}	|r6t|ƒ\}
}}}}}	}
|	r4|	 d¡nd }	|p:| j| _|p@| j	| _	t
|pG| jƒ| _|	pN| j| _|pT| j| _|pZ| j| _d | _d S )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__© úI/var/www/html/env/lib/python3.10/site-packages/celery/backends/couchdb.pyr   $   s   
zCouchBackend.__init__c              	   C   sœ   | j r#| jr#| j› d| j › d| j› d| j› d| j› �	}tj|dd�}n| j› d| j› d| j› �}t |¡}z| | j¡W S  tj	j
yM   | | j¡ Y S w )zConnect to the CouchDB server.z://ú:ú@Úbasic)Ú
authmethod)r   r   r   r   r   r   ÚServerÚdatabaser   Ú
exceptionsÚNotFoundÚcreate)r   Úconn_stringÚserverr&   r&   r'   Ú_get_connection9   s   *
ÿzCouchBackend._get_connectionc                 C   s   | j d u r
|  ¡ | _ | j S ©N)r   r3   ©r   r&   r&   r'   Ú
connectionG   s   

zCouchBackend.connectionc                 C   s4   t |ƒ}z	| j |¡d W S  tjjy   Y d S w )NÚvalue)r   r6   Úgetr   r.   r/   ©r   Úkeyr&   r&   r'   r8   M   s   ÿzCouchBackend.getc                 C   s^   t |ƒ}||dœ}z	| j |¡ W d S  tjjy.   | j |¡}||d< | j |¡ Y d S w )N)Ú_idr7   r7   )r   r6   Úsaver   r.   ÚConflictr8   )r   r:   r7   Údatar&   r&   r'   ÚsetT   s   
üzCouchBackend.setc                    s   ‡ fdd„|D ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r&   )r8   )Ú.0r:   r5   r&   r'   Ú
<listcomp>`   s    z%CouchBackend.mget.<locals>.<listcomp>r&   )r   Úkeysr&   r5   r'   Úmget_   s   zCouchBackend.mgetc                 C   s   | j  |¡ d S r4   )r6   Údeleter9   r&   r&   r'   rD   b   s   zCouchBackend.deleter4   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r3   Úpropertyr6   r8   r?   rC   rD   Ú__classcell__r&   r&   r$   r'   r      s     
r   )rH   Úkombu.utils.encodingr   Úkombu.utils.urlr   Úcelery.exceptionsr   Úbaser   r   ÚImportErrorÚ__all__r   r   r&   r&   r&   r'   Ú<module>   s    ÿ