o
    DfA                     @   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	   zCouchbase 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__ R/home/ubuntu/webapp/venv/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"    