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__/path.cpython-310.pyc
o

�N�g-�@s
dZddlZddlZddlZddlZddlmZddlZddl	Zddl
ZddlmZddl
mZzddlZdZWneyCdZYnwe�e�Zdd	�Zd
d�Zdd
�Zdd�Zed�d!dd��Zdd�Zed�dd��Zdd�Zdd�Zd!dd�Zdd�Zdd �Z dS)"zw
Platform independent versions of some os/os.path functions. Gets around PY2's
lack of support for reading NTFS links.
�N)�Iterable)�CommandNotFoundError)�jinja_filterTFcCstj�|�S)z(
    Equivalent to os.path.islink()
    )�os�path�islink�r�r	�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/path.pyrsrcCs0t�|�}tjj��r|�d�r|dd�}|S)z%
    Equivalent to os.readlink()
    z\\?\�N)r�readlink�salt�utils�platform�
is_windows�
startswith)r�baser	r	r
r#s


rcCs&t�|�}|dkrdS|d@rdSdS)zC
    Returns True if path is a reparse point; False otherwise.
    ���FiT)�	win32fileZGetFileAttributesW)r�resultr	r	r
�_is_reparse_point1s
rc	Cshtj�|�}t|�sdSd}zt�|ddddd�}t�|ddd�}W|r)t�|�|S|r3t�|�ww)a
    Retrieves the reparse point data structure for the given path.

    If the path is not a reparse point, None is returned.

    See http://msdn.microsoft.com/en-us/library/ff552012.aspx for details on the
    REPARSE_DATA_BUFFER structure returned.
    Nl��i i�	i@)rr�normpathrrZCreateFileWZDeviceIoControlZCloseHandle)rZ
fileHandleZreparseDatar	r	r
�_get_reparse_data=s2
�
�
��r�whichcsr|s	t�d�dSdd��dd�}dd��tjj�tj�d	d
�����	tj
�}tjj��sAt
|��gd�}|��fdd
�|D��tjj��r~tjj�tj�dd�����	tj
�}dd�|D��tj�|�\}}|���vrtd
g}�}n�f��fdd�	}nd
g}�}||�r�|S|D]$}ttj�|�|�}	|D]}|	|}
||
�}||�r�|	|Sq�q�t�d||�dS)z(
    Python clone of /usr/bin/which
    zBNo executable was passed to be searched by salt.utils.path.which()NcSstj�|�ot�|tj�S)z�
        This returns truth if posixy semantics (which python simulates on
        windows) states that this is executable.
        )rr�isfile�access�X_OKrr	r	r
�is_executable_commonqsz#which.<locals>.is_executable_commoncSsNtj�|�r%t|�}tj�|�stj�|�\}}t||�}|}tj�|�s|S)zl
        This will take a path and recursively follow the link until we get to a
        real file.
        )rrrr�isabs�split�join)r�res�	directory�_r	r	r
�resolvexs
�	zwhich.<locals>.resolvecSstj�|�\}}|��|vS)z�
        Extract the extension from the specified path, lowercase it so we
        can be insensitive, and then check it against the available exts.
        )rr�splitext�lower)rZext_membership�p�extr	r	r
�has_executable_ext�sz!which.<locals>.has_executable_ext�PATH�)z/sbinz/binz	/usr/sbinz/usr/binz/usr/local/sbinz/usr/local/bincsg|]}|�vr|�qSr	r	��.0r))r#r	r
�
<listcomp>��zwhich.<locals>.<listcomp>�PATHEXTz.EXEcSsh|]}|���qSr	)r()r/r*r	r	r
�	<setcomp>�szwhich.<locals>.<setcomp>cs�|�o�||�S�Nr	)rZ
membership)r+rr	r
�
is_executable�s
�zwhich.<locals>.is_executablez:'%s' could not be found in the following search path: '%s')�log�errorr
r�stringutils�
to_unicoder�environ�getr!�pathseprr�set�extend�to_strrr'r(r"�
expandvarsZtrace)�exer&Zsystem_pathZ
extended_path�pathextr%r*r5rr)ZpextZrpr	)r+rr#r
rfsL
	�cCs@t|t�r|g}t|t�sdS|D]}t|�}|sq|SdS)zT
    Scan over some possible executables and return the first one that is found
    N)�
isinstance�strrr)ZexesrArr	r	r
�	which_bin�s

rEZ	path_joincs�dd�|D�}tjjjd
i|��}|�dd�}|r tjj�|�|r$tntj��fdd�|D�}z|�d�}Wn
t	yAYdSwtjj
�|�}|sN|}ndd�|D�}�j|gtjj
�|��R�}��|�S)aw
    This functions tries to solve some issues when joining multiple absolute
    paths on both *nix and windows platforms.

    See tests/unit/utils/path_join_test.py for some examples on what's being
    talked about here.

    The "use_posixpath" kwarg can be be used to force joining using poxixpath,
    which is useful for Salt fileserver paths on Windows masters.
    cSsg|]	}tjj�|��qSr	)r
rr8r?)r/�partr	r	r
r0�szjoin.<locals>.<listcomp>�
use_posixpathFcsg|]}��|��qSr	)rr.��pathlibr	r
r0�rr-cSsg|]}|�tj��qSr	)�lstripr�sepr.r	r	r
r0r1Nr	)r
r�argsZclean_kwargs�popZinvalid_kwargs�	posixpathrr�
IndexErrorr8r9r"�data�decoder)�parts�kwargsrG�root�ret�strippedr	rHr
r"�s$�
r"cCs,|durtd��t|�std|�d���dS)z�
    Simple convenience function for modules to use for gracefully blowing up
    if a required tool is not available in the system path.

    Lazily import `salt.modules.cmdmod` to avoid any sort of circular
    dependencies.
    Nz'None' is not a valid command.�'z' is not in the path)rr)Zcommandr	r	r
�check_or_dies
�rYcCsVd}t|t�r|�dd�|D��}|St|t�r)dt|�}d�||�}|�|�}|S)z4
    Remove illegal path characters for windows
    z<>:|?*cSsi|]}t|�d�qS)r%)�ord)r/�cr	r	r
�
<dictcomp>,rJz%sanitize_win_path.<locals>.<dictcomp>r%r-)rCrD�	translate�len�	maketrans)ZwinpathZintabZouttabZtrantabr	r	r
�sanitize_win_path&s

�
r`c	Cs�tj�dd�}ddt�|�f}|rt|t�s|g}t�}|r+|D]
}|�t�|��q d}|D]}tj||tj	d�dur>d}q/|sS|D]}tj||tj	d�durRd}qC|S)	a
    .. versionadded:: 2017.7.3

    Checks that the path is safe for modification by Salt. For example, you
    wouldn't want to have salt delete the contents of ``C:\Windows``. The
    following directories are considered unsafe:

    - C:\, D:\, E:\, etc.
    - \
    - C:\Windows

    Args:

        path (str): The path to check

        allow_paths (str, list): A directory or list of directories inside of
            path that may be safe. For example: ``C:\Windows\TEMP``

    Returns:
        bool: True if safe, otherwise False
    Z
SystemRootz
C:\Windowsz
[a-z]\:\\$z\\$T)�flagsNF)
rr:r;�re�escaperC�list�append�match�
IGNORECASE)	rZ
allow_pathZsystem_rootZ
deny_pathsZallow_paths�itemZ	good_pathZd_path�a_pathr	r	r
�	safe_path4s,���rjcosF�tjj�|�}tj|g|�Ri|��D]}tjjj|dd�VqdS)z]
    This is a helper than ensures that all paths returned from os.walk are
    unicode.
    T)Zpreserve_tuplesN)r
rr8r?r�walkrQrR)�toprMrTZ	top_queryrhr	r	r
�os_walkms
��rmcCs$tj�|�}tj�|�}tj�|�S)z�
    Expands all user and environment variables
    .. versionadded:: 3005

    Args:

        path (str): A path to a file or directory

    Returns:
        str: A fully expanded, real path
    )rr�
expanduserr@�realpathrr	r	r
�expandwsrpr4)!�__doc__�loggingrrOrb�collections.abcrZsalt.utils.argsr
Zsalt.utils.platformZsalt.utils.stringutilsZsalt.exceptionsrZsalt.utils.decorators.jinjarrZ
HAS_WIN32FILE�ImportError�	getLogger�__name__r6rrrrrrEr"rYr`rjrmrpr	r	r	r
�<module>s@�
)y
&
9