o
    wvXji  ã                   @   sØ   d Z ddlmZmZ ddl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y5   Y nw zdd	lmZ dd
lmZ ddlmZ ddlmZ W n ey_   d Z ZZY nw dZG dd„ deƒZdS )zCouchbase result store backend.é    )Úabsolute_importÚunicode_literalsN)Ústr_t)Ú
_parse_url)ÚImproperlyConfiguredé   )ÚKeyValueStoreBackend)Ú	Couchbase)Ú
Connection)ÚNotFoundError)ÚFMT_AUTO)ÚCouchbaseBackendc                       sz   e Zd ZdZdZdZdZdZdZdZ	dZ
dZe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ŽCouchbase backend.

    Raises:
        celery.exceptions.ImproperlyConfigured:
            if module :pypi:`couchbase` is not available.
    ÚdefaultÚ	localhosti›  NFTg      @c                    s  |  dt¡ tt| ƒj|i |¤Ž || _td u rtdƒ‚d  } } } }}|r<t|ƒ\}	}}}}}}	|r:| 	d¡nd }| j
j dd ¡}
|
d urRt|
tƒsQtdƒ‚ni }
|p\|
 d| j¡| _t|pg|
 d| j¡ƒ| _|pr|
 d| j¡| _|p||
 d	| j¡| _|p†|
 d
| j¡| _d | _d S )NÚexpires_typezGYou need to install the couchbase library to use the Couchbase backend.ú/Úcouchbase_backend_settingsz6Couchbase backend settings should be grouped in a dictÚhostÚportÚbucketÚusernameÚpassword)Ú
setdefaultÚintÚsuperr   Ú__init__Úurlr	   r   r   ÚstripÚappÚconfÚgetÚ
isinstanceÚdictr   r   r   r   r   Ú_connection)Úselfr   ÚargsÚkwargsÚuhostÚuportÚunameÚupassÚubucketÚ_Úconfig©Ú	__class__© úV/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/backends/couchbase.pyr   2   s2   ÿ
ÿÿ
zCouchbaseBackend.__init__c                 C   s|   | j du r;| j| jdœ}| jr| d| ji¡ | jr"| d| ji¡ | jr-| d| ji¡ t d|¡ t	di |¤Ž| _ | j S )z Connect to the Couchbase server.N)r   r   r   r   r   zcouchbase settings %rr0   )
r#   r   r   r   Úupdater   r   ÚloggingÚdebugr
   )r$   r&   r0   r0   r1   Ú_get_connectionS   s   
z CouchbaseBackend._get_connectionc                 C   s   |   ¡ S ©N)r5   ©r$   r0   r0   r1   Ú
connectionc   s   zCouchbaseBackend.connectionc                 C   s&   z| j  |¡jW S  ty   Y d S w r6   )r8   r    Úvaluer   ©r$   Úkeyr0   r0   r1   r    g   s
   ÿzCouchbaseBackend.getc                 C   s   | j j||| jtd� d S )N)ÚttlÚformat)r8   ÚsetÚexpiresr   )r$   r;   r9   Ústater0   r0   r1   r>   m   s   zCouchbaseBackend.setc                    s   ‡ fdd„|D ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r0   )r    )Ú.0r;   r7   r0   r1   Ú
<listcomp>q   s    z)CouchbaseBackend.mget.<locals>.<listcomp>r0   )r$   Úkeysr0   r7   r1   Úmgetp   s   zCouchbaseBackend.mgetc                 C   s   | j  |¡ d S r6   )r8   Údeleter:   r0   r0   r1   rE   s   s   zCouchbaseBackend.deleter6   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   ÚquietÚsupports_autoexpireÚtimeoutr   Úkey_tr   r5   Úpropertyr8   r    r>   rD   rE   Ú__classcell__r0   r0   r.   r1   r      s&    !
r   )rI   Ú
__future__r   r   r3   Úkombu.utils.encodingr   Úkombu.utils.urlr   Úcelery.exceptionsr   Úbaser   Úcouchbase_ffiÚImportErrorÚ	couchbaser	   Úcouchbase.connectionr
   Úcouchbase.exceptionsr   r   Ú__all__r   r0   r0   r0   r1   Ú<module>   s,   ÿÿ