§
    ÎÑßjÇ  ã                  ón  — U d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZmZmZmZ erddlmZ ddlmZ  ej        e¦  «        Zd	ed
<   e G d„ de¦  «        ¦   «         Ze G d„ de¦  «        ¦   «         Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Zg d¢ZdS )zMCache Protocol and built-in implementations for Python interpreter discovery.é    )ÚannotationsN)ÚcontextmanagerÚsuppress)Úsha256)ÚTYPE_CHECKINGÚFinalÚProtocolÚruntime_checkable)Ú	Generator)ÚPathzFinal[logging.Logger]Ú_LOGGERc                  óJ   — e Zd ZdZdd„Zdd„Zdd
„Zdd„Zedd„¦   «         Z	dS )ÚContentStorez/A store for reading and writing cached content.ÚreturnÚboolc                ó   — dS )z)Return whether the cached content exists.N© ©Úselfs    úK/opt/saltstack/salt/lib/python3.11/site-packages/python_discovery/_cache.pyÚexistszContentStore.exists   ó   € àˆó    údict | Nonec                ó   — dS )z?Read the cached content, or ``None`` if unavailable or corrupt.Nr   r   s    r   ÚreadzContentStore.read   r   r   ÚcontentÚdictÚNonec                ó   — dS )zi
        Persist *content* to the store.

        :param content: interpreter metadata to cache.
        Nr   ©r   r   s     r   ÚwritezContentStore.write   ó	   € ð 	ˆr   c                ó   — dS )zDelete the cached content.Nr   r   s    r   ÚremovezContentStore.remove&   r   r   úGenerator[None]c                ó   — dS )z>Context manager that acquires an exclusive lock on this store.Nr   r   s    r   ÚlockedzContentStore.locked*   s	   € ð 	ˆr   N©r   r   ©r   r   ©r   r   r   r   ©r   r   ©r   r&   ©
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r%   r   r(   r   r   r   r   r      sŠ   € € € € € à9Ð9ðð ð ð ðð ð ð ðð ð ð ðð ð ð ð ðð ð ñ „^ðð ð r   r   c                  ó"   — e Zd ZdZd
d„Zdd„Zd	S )ÚPyInfoCachez3Cache interface for Python interpreter information.Úpathr   r   r   c                ó   — dS )ú…
        Return the content store for the interpreter at *path*.

        :param path: absolute path to a Python executable.
        Nr   ©r   r5   s     r   Úpy_infozPyInfoCache.py_info4   r#   r   r   c                ó   — dS )ú*Remove all cached interpreter information.Nr   r   s    r   Úpy_info_clearzPyInfoCache.py_info_clear<   r   r   N)r5   r   r   r   r,   ©r/   r0   r1   r2   r9   r<   r   r   r   r4   r4   0   sB   € € € € € à=Ð=ðð ð ð ðð ð ð ð ð r   r4   c                  ój   — e Zd ZdZdd„Zedd	„¦   «         Zdd„Zdd„Zdd„Z	dd„Z
edd„¦   «         ZdS )ÚDiskContentStorez0JSON file-based content store with file locking.Úfolderr   ÚkeyÚstrr   r   c                ó"   — || _         || _        d S ©N©Ú_folderÚ_key)r   r@   rA   s      r   Ú__init__zDiskContentStore.__init__D   s   € ØˆŒØˆŒ	ˆ	ˆ	r   c                ó&   — | j         | j        › d�z  S )Nú.jsonrE   r   s    r   Ú_filezDiskContentStore._fileH   s   € àŒ| ¤Ð1Ð1Ð1Ñ1Ð1r   r   c                ó4   — | j                              ¦   «         S rD   )rK   r   r   s    r   r   zDiskContentStore.existsL   s   € ØŒz× Ò Ñ"Ô"Ð"r   r   c                ó²  — d\  }}	 t          j        | j                             d¬¦  «        ¦  «        }t                               d| j        ¦  «         |S # t          $ r d}Y n1t          $ r% t                               d| j        d¬¦  «         Y nw xY w|r@t          t          ¦  «        5  |  	                    ¦   «          d d d ¦  «         n# 1 swxY w Y   d S )N©NFúutf-8©Úencodingzgot python info from %sTzfailed to read %s)Úexc_info)
ÚjsonÚloadsrK   Ú	read_textr   ÚdebugÚ
ValueErrorÚOSErrorr   r%   )r   ÚdataÚ
bad_formats      r   r   zDiskContentStore.readO   s-  € Ø&Ñˆˆjð	Ý”:˜dœj×2Ò2¸GÐ2ÑDÔDÑEÔEˆDõ �MŠMÐ3°T´ZÑ@Ô@Ð@ØˆKøõ ð 	ð 	ð 	ØˆJˆJˆJÝð 	Jð 	Jð 	JÝ�MŠMÐ-¨t¬zÀDˆMÑIÔIÐIÐIÐIð	Jøøøð
 ð 	Ý�'Ñ"Ô"ð ð Ø—’‘”�ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð àˆts)   ‡-A ÁBÁ$+BÂBÂ+CÃCÃCr   r   c                óà   — | j                              dd¬¦  «         | j                             t	          j        |dd¬¦  «        d¬¦  «         t                               d| j        ¦  «         d S )NT©ÚparentsÚexist_oké   )Ú	sort_keysÚindentrO   rP   zwrote python info at %s)rF   ÚmkdirrK   Ú
write_textrS   Údumpsr   rV   r!   s     r   r"   zDiskContentStore.write_   sg   € ØŒ×Ò 4°$ÐÑ7Ô7Ð7ØŒ
×Ò�dœj¨¸DÈÐKÑKÔKÐV]ÐÑ^Ô^Ð^Ý�ŠÐ/°´Ñ<Ô<Ð<Ð<Ð<r   c                óÐ   — t          t          ¦  «        5  | j                             ¦   «          d d d ¦  «         n# 1 swxY w Y   t                               d| j        ¦  «         d S )Nzremoved python info at %s)r   rX   rK   Úunlinkr   rV   r   s    r   r%   zDiskContentStore.removed   s–   € Ý•gÑÔð 	 ð 	 ØŒJ×ÒÑÔÐð	 ð 	 ð 	 ñ 	 ô 	 ð 	 ð 	 ð 	 ð 	 ð 	 ð 	 øøøð 	 ð 	 ð 	 ð 	 å�ŠÐ1°4´:Ñ>Ô>Ð>Ð>Ð>s   •;»?Á?r&   c              #  óÜ   K  — ddl m} | j        | j        › d�z  }|j                             dd¬¦  «          |t          |¦  «        ¦  «        5  d V — d d d ¦  «         d S # 1 swxY w Y   d S )Nr   )ÚFileLockz.lockTr\   )Úfilelockrh   rF   rG   Úparentrb   rB   )r   rh   Ú	lock_paths      r   r(   zDiskContentStore.lockedi   sÎ   è è € à%Ð%Ð%Ð%Ð%Ð%à”L d¤iÐ#6Ð#6Ð#6Ñ6ˆ	ØÔ×Ò t°dÐÑ;Ô;Ð;ØˆX•c˜)‘n”nÑ%Ô%ð 	ð 	ØˆEˆEˆEð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   ÁA!Á!A%Á(A%N)r@   r   rA   rB   r   r   ©r   r   r)   r*   r+   r,   r-   )r/   r0   r1   r2   rH   ÚpropertyrK   r   r   r"   r%   r   r(   r   r   r   r?   r?   A   s¾   € € € € € Ø:Ð:ðð ð ð ð ð2ð 2ð 2ñ „Xð2ð#ð #ð #ð #ðð ð ð ð =ð =ð =ð =ð
?ð ?ð ?ð ?ð
 ðð ð ñ „^ðð ð r   r?   c                  óB   — e Zd ZdZdd„Zedd„¦   «         Zdd
„Zdd„ZdS )Ú	DiskCachez—
    File-system based Python interpreter info cache (``<root>/py_info/4/<sha256>.json``).

    :param root: root directory for the on-disk cache.
    Úrootr   r   r   c                ó   — || _         d S rD   ©Ú_root)r   rp   s     r   rH   zDiskCache.__init__z   s   € ØˆŒ
ˆ
ˆ
r   c                ó   — | j         dz  dz  S )Nr9   Ú4rr   r   s    r   Ú_py_info_dirzDiskCache._py_info_dir}   s   € àŒz˜IÑ%¨Ñ+Ð+r   r5   r?   c                ó®   — t          t          |¦  «                             d¦  «        ¦  «                             ¦   «         }t	          | j        |¦  «        S )r7   rO   )r   rB   ÚencodeÚ	hexdigestr?   rv   )r   r5   rA   s      r   r9   zDiskCache.py_info�   sD   € õ •S˜‘Y”Y×%Ò% gÑ.Ô.Ñ/Ô/×9Ò9Ñ;Ô;ˆÝ Ô 1°3Ñ7Ô7Ð7r   c                ó  — | j         }|                     ¦   «         rb|                     ¦   «         D ]O}|j        dk    r@t	          t
          ¦  «        5  |                     ¦   «          ddd¦  «         n# 1 swxY w Y   ŒNdS dS )r;   rJ   N)rv   r   ÚiterdirÚsuffixr   rX   rf   )r   r@   Úentrys      r   r<   zDiskCache.py_info_clearŠ   sÅ   € àÔ"ˆØ�=Š=‰?Œ?ð 	'ØŸšÑ)Ô)ð 'ð '�Ø”< 7Ò*Ð*Ý!¥'Ñ*Ô*ð 'ð 'ØŸš™œ˜ð'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'ð 'ð 'ð 'øøøð 'ð 'ð 'ð 'øð	'ð 	'ð'ð 's   ÁA2Á2A6	Á9A6	N)rp   r   r   r   rl   )r5   r   r   r?   r,   )	r/   r0   r1   r2   rH   rm   rv   r9   r<   r   r   r   ro   ro   s   sz   € € € € € ðð ðð ð ð ð ð,ð ,ð ,ñ „Xð,ð8ð 8ð 8ð 8ð'ð 'ð 'ð 'ð 'ð 'r   ro   c                  óJ   — e Zd ZdZdd„Zdd„Zdd
„Zdd„Zedd„¦   «         Z	dS )ÚNoOpContentStorezDContent store that does nothing -- implements ContentStore protocol.r   r   c                ó   — dS rN   r   r   s    r   r   zNoOpContentStore.exists—   s   € Øˆur   r   c                ó   — d S rD   r   r   s    r   r   zNoOpContentStore.readš   s   € Øˆtr   r   r   r   c                ó   — d S rD   r   r!   s     r   r"   zNoOpContentStore.write�   ó   € Øˆr   c                ó   — d S rD   r   r   s    r   r%   zNoOpContentStore.remove    rƒ   r   r&   c              #  ó   K  — d V — d S rD   r   r   s    r   r(   zNoOpContentStore.locked£   s   è è € àˆˆˆˆˆr   Nr)   r*   r+   r,   r-   r.   r   r   r   r   r   ”   sŠ   € € € € € ØNÐNðð ð ð ðð ð ð ðð ð ð ðð ð ð ð ðð ð ñ „^ðð ð r   r   c                  ó"   — e Zd ZdZd
d„Zdd„Zd	S )Ú	NoOpCachez;Cache that does nothing -- implements PyInfoCache protocol.r5   r   r   r   c                ó   — t          ¦   «         S rD   )r   r8   s     r   r9   zNoOpCache.py_info«   s   € ÝÑ!Ô!Ð!r   r   c                ó   — d S rD   r   r   s    r   r<   zNoOpCache.py_info_clear®   rƒ   r   N)r5   r   r   r   r,   r=   r   r   r   r‡   r‡   ¨   sB   € € € € € ØEÐEð"ð "ð "ð "ðð ð ð ð ð r   r‡   )r   ro   r?   r‡   r   r4   )r2   Ú
__future__r   rS   ÚloggingÚ
contextlibr   r   Úhashlibr   Útypingr   r   r	   r
   Úcollections.abcr   Úpathlibr   Ú	getLoggerr/   r   Ú__annotations__r   r4   r?   ro   r   r‡   Ú__all__r   r   r   ú<module>r”      só  ðØ SÐ SÐ Sà "Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ø Ð Ð Ð Ð Ð Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dàð Ø)Ð)Ð)Ð)Ð)Ð)ØÐÐÐÐÐà!2 Ô!2°8Ñ!<Ô!<€Ð <Ð <Ð <Ñ <ð ðð ð ð ð �8ñ ô ñ Ôðð: ðð ð ð ð �(ñ ô ñ Ôðð /ð /ð /ð /ð /ñ /ô /ð /ðd'ð 'ð 'ð 'ð 'ñ 'ô 'ð 'ðBð ð ð ð �|ñ ô ð ð(ð ð ð ð �ñ ô ð ðð ð €€€r   