o
    ›¨ÊhA  ã                   @   s    d Z ddlmZ ddlmZ ddlmZ zddlmZ ddl	m
Z
 W n ey/   d Z
ZY nw zdd	lmZ W n eyC   dZY nw d
ZG dd„ deƒZdS )zCouchbase result store backend.é    )Ú
_parse_url)ÚImproperlyConfiguredé   )ÚKeyValueStoreBackend)ÚPasswordAuthenticator)ÚClusterN)Ú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ƒ j|i |¤Ž || _td u rtdƒ‚d  } } } }}|r:t|ƒ\}	}}}}}}	|r8| d¡nd }| j	j
 dd ¡}
|
d urPt|
tƒsOtdƒ‚ni }
|pZ|
 d| j¡| _t|pe|
 d| j¡ƒ| _|pp|
 d| j¡| _|pz|
 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ÚsuperÚ__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__© úK/var/www/html/env/lib/python3.10/site-packages/celery/backends/couchbase.pyr   ,   s2   ÿ
ÿÿ
zCouchbaseBackend.__init__c                 C   s~   | j du r<| jr| jrd| j› d| j› �}nd| j› �}| jr*| jr*t| j| jƒ}nd}t||ƒ}| | j¡}| ¡ | _ | j S )z Connect to the Couchbase server.Nzcouchbase://ú:)	r   r   r   r   r   r   r   r   Údefault_collection)r    ÚuriÚoptÚclusterr   r,   r,   r-   Ú_get_connectionM   s   


z CouchbaseBackend._get_connectionc                 C   s   |   ¡ S ©N)r3   )r    r,   r,   r-   Ú
connection`   s   zCouchbaseBackend.connectionc                 C   s   | j  |¡jS r4   )r5   r   Úcontent©r    Úkeyr,   r,   r-   r   d   s   zCouchbaseBackend.getc                 C   s:   t d ur| jj||| jt d� d S | jj||| jd� d S )N)ÚttlÚformat)r9   )r   r5   ÚupsertÚexpires)r    r8   Úvaluer,   r,   r-   Úsetg   s   zCouchbaseBackend.setc                 C   s   | j  |¡S r4   )r5   Ú	get_multi)r    Úkeysr,   r,   r-   Úmgetn   s   zCouchbaseBackend.mgetc                 C   s   | j  |¡ d S r4   )r5   Úremover7   r,   r,   r-   Údeleteq   s   zCouchbaseBackend.deleter4   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   ÚquietÚsupports_autoexpireÚtimeoutÚstrÚkey_tr   r3   Úpropertyr5   r   r>   rA   rC   Ú__classcell__r,   r,   r*   r-   r	      s&    !
r	   )rG   Úkombu.utils.urlr   Úcelery.exceptionsr   Úbaser   Úcouchbase.authr   Úcouchbase.clusterr   ÚImportErrorÚcouchbase_core._libcouchbaser   Ú__all__r	   r,   r,   r,   r-   Ú<module>   s"    ÿÿ