HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/cache.cpython-310.pyc
o

�N�g�-�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlZddlZddlZddlmZe�e�ZGdd�d�ZGdd�de�ZGdd	�d	e�ZGd
d�d�ZGdd
�d
�ZGdd�d�Zdd�Zdd�ZdS)z 
In-memory caching used by Salt
�N)�zmqc@seZdZdZedd��ZdS)�CacheFactoryz2
    Cache which can use a number of backends
    cOs\t�d|�|dkrt|g|�Ri|��S|dkr't||dg|�Ri|��St�d�dS)NzFactory backend: %sZmemoryZdiskZminion_cache_pathz-CacheFactory received unrecognized cache type)�log�debug�	CacheDict�	CacheDisk�error)�clsZbackend�ttl�args�kwargs�r
�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/cache.py�factoryszCacheFactory.factoryN)�__name__�
__module__�__qualname__�__doc__�classmethodrr
r
r
rrsrc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
rzA
    Subclass of dict that will lazily delete items past ttl
    cOs(tj|g|�Ri|��||_i|_dS�N)�dict�__init__�_ttl�_key_cache_time)�selfr
rrr
r
rr/s
zCacheDict.__init__cCsB||jvrdSt��|j||jkr|j|=t�||�dSdS�zK
        Enforce the TTL to a specific key, delete if its past TTL
        N)r�timerr�__delitem__�r�keyr
r
r�_enforce_ttl_key4s
�zCacheDict._enforce_ttl_keycC�|�|�t�||�S�z?
        Check if the key is ttld out, then do the get
        )r r�__getitem__rr
r
rr#>�
zCacheDict.__getitem__cCs t��|j|<t�|||�dS�z8
        Make sure to update the key cache time
        N)rrr�__setitem__�rr�valr
r
rr&EszCacheDict.__setitem__cCr!r)r r�__contains__rr
r
rr)L�
zCacheDict.__contains__N)	rrrrrr r#r&r)r
r
r
rr*s
rcs`eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Z�Z
S)rz�
    Class that represents itself as a dictionary to a consumer
    but uses a disk-based backend. Serialization and de-serialization
    is done with msgpack
    cs2t�j|g|�Ri|��||_i|_|��dSr)�superr�_path�_dict�_read)rr
�pathrr��	__class__r
rrXszCacheDisk.__init__cCs>||jvrdSt��|j||jkr|j|=|j|=dSdSr)rrrr-rr
r
rr ^s
�zCacheDisk._enforce_ttl_keycC�|�|�|j�|�Sr)r r-r)rr
r
rr)hr*zCacheDisk.__contains__cCr2r")r r-r#rr
r
rr#lr$zCacheDisk.__getitem__cCs(t��|j|<|j�||�|��dSr%)rrr-r&�_writer'r
r
rr&sszCacheDisk.__setitem__cCs |j|=|j�|�|��dS)z8
        Make sure to remove the key cache time
        N)rr-rr3rr
r
rr|szCacheDisk.__delitem__cCs |j��|j��|��dS�z!
        Clear the cache
        N)r�clearr-r3�rr
r
rr5�s

zCacheDisk.clearc
CsFtjjjrtj�|j�sdSdtj�|j�krdSz%tjj	�
|jd��}tjjj|tdd�}Wd�n1s8wYWn0t
yHYdStjjjjtfyn}zt�tj�rct�d|j|�WYd}~dSd}~wwd|vr~|d|_|d|_n||_tj�|j�}|jD]}||j|<q�t�tj�r�t�d	|�dSdS)
z#
        Read in from disk
        Nr�rbF)�encoding�rawz"Error reading cache file at %r: %s�CacheDisk_cachetime�CacheDisk_datazDisk cache retrieved: %s)�salt�utils�msgpack�HAS_MSGPACK�osr/�existsr,�getsize�files�fopen�loadZ__salt_system_encoding__�FileNotFoundError�
exceptionsZUnpackException�
ValueErrorr�isEnabledFor�logging�DEBUGrr-r�getmtime)r�fp_�cache�exc�	timestamprr
r
rr.�s:�����

�zCacheDisk._readcCsdtjjjsdStjj�|jd��}|j|jd�}tjj�	||�Wd�dS1s+wYdS)z#
        Write out to disk
        Nzwb+)r;r:)
r<r=r>r?Z
atomicfileZatomic_openr,r-r�dump)rrMrNr
r
rr3�s
�"�zCacheDisk._write)rrrrrr r)r#r&rr5r.r3�
__classcell__r
r
r0rrQs
			$rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�CacheCliz�
    Connection client for the ConCache. Should be used by all
    components that need the list of currently connected minions
    cCs�||_tj�|jdd�|_tj�|jdd�|_t��}|�tj	�|_
|j
�tjd�|j
�
d|j�|�tj�|_|j�tjd�|j�
d|j�dS)z<
        Sets up the zmq-connection to the ConCache
        Zsock_dirz
con_cache.ipczcon_upd.ipc�dzipc://�N)�optsr@r/�joinZ
cache_sockZcache_upd_sockrZContext�socketZREQ�creq_out�
setsockoptZLINGER�connectZPUB�cupd_out)rrV�contextr
r
rr�szCacheCli.__init__cCs|jjtj�|�dd�dS)z=
        published the given minions to the ConCache
        F�ZtrackN)r\�sendr<�payload�dumps)r�minionsr
r
r�	put_cache�szCacheCli.put_cachecCs2tj�d�}|jj|dd�tj�|j���}|S)zP
        queries the ConCache for a list of currently connected minions
        rbFr^)r<r`rarYr_�loads�recv)r�msgZmin_listr
r
r�
get_cached�szCacheCli.get_cachedN)rrrrrrcrgr
r
r
rrS�s
rSc@s4eZdZdZ	ddd�Zdd	�Zd
d�Zdd
�ZdS)�
CacheRegexz�
    Create a regular expression object cache for the most frequently
    used patterns to minimize compilation of the same patterns over
    and over again
    ���皙�����?�cCsj||_||_||_t|||�|_|j|kr(t|d�d|_|j|kr(||_||_i|_t��|_dS)N�rU)	�prepend�append�size�int�
clear_size�max_agerNrrP)rrnrorpZ
keep_fractionrsr
r
rr�s

zCacheRegex.__init__cCs|j��dSr4)rNr5r6r
r
rr5szCacheRegex.clearcCsd|jt��|jkr|��t��|_dSt|j���}|��t|j	�D]
}|j||d=q%dS)zb
        Sweep the cache and remove the outdated or least frequently
        used entries
        rmN)
rsrrPr5�listrN�values�sort�rangerr)rZpaterns�idxr
r
r�sweeps�zCacheRegex.sweepcCs�z|j|dd7<|j|dWStyYnwt|j�|jkr)|��t�|j�|�|j���}d||t	�	�g|j|<|S)z�
        Get a compiled regular expression object based on pattern and
        cache it when it is not in the cache already
        rrU)
rN�KeyError�lenrpry�re�compilernror)r�patternZregexr
r
r�gets�zCacheRegex.getN)ririrjrkrl)rrrrrr5ryrr
r
r
rrh�s
�rhc@s$eZdZdd�Zdd�Zdd�ZdS)�ContextCachecCs&||_tj�|dd|�d��|_dS)z(
        Create a context cache
        Zcachedirr]z.pN)rVr@r/rW�
cache_path)rrV�namer
r
rr(s zContextCache.__init__cCsptj�tj�|j��st�tj�|j��tjj�	|jd��}tj
�||�Wd�dS1s1wYdS)z1
        Cache the given context to disk
        zw+bN)r@r/�isdir�dirnamer��mkdirr<r=rCrDr`rQ)rr]rNr
r
r�
cache_context/s
"�zContextCache.cache_contextcCsLtjj�|jd��}tjj�tj�|��Wd�S1swYdS)z4
        Retrieve a context cache from disk
        r7N)	r<r=rCrDr��data�decoder`rE)rrNr
r
r�get_cache_context8s$�zContextCache.get_cache_contextN)rrrrr�r�r
r
r
rr�'s	r�cst����fdd��}|S)z�
    A decorator to be used module functions which need to cache their
    context.

    To evaluate a __context__ and re-hydrate it if a given key
    is empty or contains no items, pass a list of keys to evaulate.
    cs�z	�jd��}Wnty�jd}Ynwz	�jd��}Wnty/�jd}Ynw�jd}t||�}|sNtj�|j�rNtj	j
�||���n|�
|��|i|��S)N�__context__Z__opts__r)�__globals__�value�AttributeErrorr�r@r/�isfiler�r<r=Z
dictupdate�updater�r�)rrZfunc_contextZ	func_optsZ	func_name�
context_cache��funcr
r�context_cache_wrapIs$��

�
z)context_cache.<locals>.context_cache_wrap)�	functools�wraps)r�r�r
r�rr�@s	r�cCstj�|�st�|�tjj�tjj�|d�d��^}|�	d�d�|�
��}|tjjkrnt
�dt|��|�d�|�tjj�t�|�D]}|dkrdtjj�||�}tj�|�r_t�|�qEt�|�qE	Wd�dS	Wd�dS1szwYdS)	z�
    Check that the cached version matches the Salt version.
    If the cached version does not match the Salt version, wipe the cache.

    :return: ``True`` if cache version matches, otherwise ``False``
    Z
cache_versionza+r�
z#Cache version mismatch clearing: %sNFT)r@r/r��makedirsr<r=rCrDrW�seek�	readlines�version�__version__r�warning�repr�truncate�write�listdirr��remove�shutil�rmtree)r��filer��itemZ	item_pathr
r
r�verify_cache_versionas.
�


��$�r�)rr�rJr@r|r�rZsalt.configr<Zsalt.payloadZsalt.utils.atomicfileZsalt.utils.dataZsalt.utils.dictupdateZsalt.utils.filesZsalt.utils.msgpackZsalt.utils.pathZsalt.versionZsalt.utils.zeromqr�	getLoggerrrrrrrrSrhr�r�r�r
r
r
r�<module>s4
'q*;!