o
    ›¨Êhß  ã                   @   s¤   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dZd	gZd
ZdZe	dd�Zdd„ Zdd„ ZG dd„ dƒZeeedd„ dœZG dd„ deƒZd	S )z-Memcached and in-memory cache result backend.é    )Úbytes_to_strÚensure_bytes)Úcached_property)ÚImproperlyConfigured)ÚLRUCacheé   )ÚKeyValueStoreBackend)ÚCacheBackendNzBThe Memcached backend requires either pylibmc or python-memcached.zYThe cache backend {0!r} is unknown,
Please use one of the following backends instead: {1}iˆ  )Úlimitc                  C   st   t d d u r6dt} }zdd l}d} W n ty.   zdd l}W n ty+   ttƒ‚w Y nw | ||ft d< t d S )Nr   FT)Ú_impr   ÚpylibmcÚImportErrorÚmemcacher   ÚREQUIRES_BACKEND)Ú
is_pylibmcÚmemcache_key_tr   © r   úG/var/www/html/env/lib/python3.10/site-packages/celery/backends/cache.pyÚimport_best_memcache   s   
ÿÿþr   c                     s.   t ƒ \}}}|j }‰ |s‡ fdd„}||fS )Nc                     s   |  dd ¡ ˆ | i |¤ŽS )NÚ	behaviors)Úpop)ÚargsÚkwargs©Ú_Clientr   r   ÚClient2   s   z!get_best_memcache.<locals>.Client)r   r   )r   r   r   r   Úkey_tr   r   r   r   Úget_best_memcache+   s
   
r   c                   @   sF   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zddd„Zdd„ Z	dS )ÚDummyClientc                 O   s
   t | _d S ©N)Ú_DUMMY_CLIENT_CACHEÚcache)Úselfr   r   r   r   r   Ú__init__;   s   
zDummyClient.__init__c                 O   ó   | j  |¡S r   )r!   Úget©r"   Úkeyr   r   r   r   r   r%   >   ó   zDummyClient.getc                    s   | j ‰ ‡ fdd„|D ƒS )Nc                    s   i | ]}|ˆ v r|ˆ | “qS r   r   )Ú.0Úk©r!   r   r   Ú
<dictcomp>C   s    z)DummyClient.get_multi.<locals>.<dictcomp>r+   ©r"   Úkeysr   r+   r   Ú	get_multiA   s   zDummyClient.get_multic                 O   s   || j |< d S r   r+   )r"   r'   Úvaluer   r   r   r   r   ÚsetE   ó   zDummyClient.setc                 O   s   | j  |d ¡ d S r   )r!   r   r&   r   r   r   ÚdeleteH   ó   zDummyClient.deleter   c                 C   ó   | j  ||¡S r   )r!   Úincr)r"   r'   Údeltar   r   r   r6   K   r2   zDummyClient.incrc                 C   s   d S r   r   )r"   r'   Úexpirer   r   r   ÚtouchN   s   zDummyClient.touchN)r   )
Ú__name__Ú
__module__Ú__qualname__r#   r%   r/   r1   r3   r6   r9   r   r   r   r   r   9   s    
r   c                   C   s   t tfS r   )r   r   r   r   r   r   Ú<lambda>V   s    r=   )r   Ú	memcachedr   Úmemoryc                       s”   e Zd ZdZdZdZdZdZ		d‡ fdd„	Zdd„ Z	dd	„ Z
d
d„ Zdd„ Z‡ fdd„Zdd„ Zdd„ Zedd„ ƒZd‡ fdd„	Zdd„ Z‡  ZS )r	   zCache result backend.NTc           	   
      sÚ   |si n|}t ƒ j|fi |¤Ž || _t| jjjfi |¤Ž| _|p'|p'| jjj| _	| j	r?| j	 
d¡\| _	}}| d¡ d¡| _| j|td�| _zt| j	 ƒ \| _| _W n tyf   tt | j	d t¡¡ƒ‚w |  ¡  d S )Nú://ú/ú;)Útypez, )Úsuperr#   ÚurlÚdictÚappÚconfÚcache_backend_optionsÚoptionsÚcache_backendÚbackendÚ	partitionÚrstripÚsplitÚserversÚprepare_expiresÚintÚexpiresÚbackendsr   r   ÚKeyErrorr   ÚUNKNOWN_BACKENDÚformatÚjoinÚ_encode_prefixes)	r"   rG   rS   rL   rJ   rE   r   Ú_rP   ©Ú	__class__r   r   r#   b   s&   ÿÿÿzCacheBackend.__init__c                 C   r$   r   )Úclientr%   ©r"   r'   r   r   r   r%   w   r(   zCacheBackend.getc                 C   r$   r   )r]   r/   r-   r   r   r   Úmgetz   r(   zCacheBackend.mgetc                 C   s   | j  ||| j¡S r   )r]   r1   rS   ©r"   r'   r0   r   r   r   r1   }   r4   zCacheBackend.setc                 C   r$   r   )r]   r3   r^   r   r   r   r3   €   r(   zCacheBackend.deletec                    s8   |   |d ¡}| jj|d| jd� tƒ j||fi |¤ŽS )Nr   )Útime)Úget_key_for_chordr]   r1   rS   rD   Ú_apply_chord_incr)r"   Úheader_result_argsÚbodyr   Ú	chord_keyr[   r   r   rc   ƒ   s   ÿÿzCacheBackend._apply_chord_incrc                 C   r$   r   )r]   r6   r^   r   r   r   r6   ‰   r(   zCacheBackend.incrc                 C   r5   r   )r]   r9   r`   r   r   r   r8   Œ   r2   zCacheBackend.expirec                 C   s   | j | jfi | j¤ŽS r   )r   rP   rJ   )r"   r   r   r   r]   �   s   zCacheBackend.clientr   c                    sN   |si n|}d  | j¡}| j› d|› d�}| || j| jdœ¡ tƒ  ||¡S )NrB   r@   rA   )rL   rS   rJ   )rX   rP   rL   ÚupdaterS   rJ   rD   Ú
__reduce__)r"   r   r   rP   rL   r[   r   r   rh   “   s   þÿzCacheBackend.__reduce__c                 O   s   d  | j¡}| j› d|› d�S )zcReturn the backend as an URI.

        This properly handles the case of multiple servers.
        rB   r@   rA   )rX   rP   rL   )r"   r   r   rP   r   r   r   Úas_uri�   s   zCacheBackend.as_uri)NNNN)r   N)r:   r;   r<   Ú__doc__rP   Úsupports_autoexpireÚsupports_native_joinÚimplements_incrr#   r%   r_   r1   r3   rc   r6   r8   r   r]   rh   ri   Ú__classcell__r   r   r[   r   r	   Z   s(    ÿ

r	   )rj   Úkombu.utils.encodingr   r   Úkombu.utils.objectsr   Úcelery.exceptionsr   Úcelery.utils.functionalr   Úbaser   Ú__all__r   r   rV   r    r   r   r   rT   r	   r   r   r   r   Ú<module>   s(    
ü