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

�N�gb�@sdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmmZddlZddlZddlZddlZddlZddlZdZ zddl!Z!dZ Wn	e"y�Ynwzddl#Z#Wne"y�dZ#Ynwzddl$Z$Wne"y�dZ$Ynwzddl%Z%Wne"y�dZ%Ynwzddl&Z&Wne"y�dZ&Ynwzddl'Z'Wne"y�ddl(mm'Z'Ynwzddl)Z)Wne"y�dZ)Ynwzddl*m+Z+Wne"�y!zddl,m+Z+Wne"�ydZ+YnwYnwdZ-e�.e/�Z0dd�Z1dd	�Z2d
d�Z3dd
�Z4dd�Z5dd�Z6dd�Z7dd�Z8d/dd�Z9dd�Z:dd�Z;d0dd�Z<dd �Z=d!d"�Z>d#d$�Z?					%	d1d&d'�Z@d2d)d*�ZA			d3d+d,�ZBd2d-d.�ZCdS)4z@
Generate the salt thin tarball from the installed python files
�NFT)�ssl_match_hostnamecCsjz	tj�||�}Wntyd}Ynw|dur3tj�|�}z	|j�|�W|Sty2YdSwdS)z�
    Import a module from a specific path. Path can be a full or relative path
    to a .py file.

    :name: The name of the module to import
    :path: The path of the module to import
    N)�	importlib�util�spec_from_file_location�
ValueError�module_from_spec�loader�exec_module�OSError)�name�path�spec�lib�r�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/thin.py�
import_module^s����rcCsPttd�r	t��StjD]}tdtj�|d��}t|d�r#|��Sqtd��)a�
    Some versions of Virtualenv ship a site.py without getsitepackages. This
    method will first try and return sitepackages from the default site module
    if no method exists we will try importing the site module from every other
    path in sys.paths until we find a getsitepackages method to return the
    results from. If for some reason no gesitepackages method can be found a
    RuntimeError will be raised

    :return: A list containing all global site-packages directories.
    �getsitepackages�sitezsite.pyz)Unable to locate a getsitepackages method)	�hasattrrr�sysrr�os�join�RuntimeError)rrrrrrts


�rcCs�g}g}zt�}Wntyt�d�Ynw|D],}tj�||�d��}t||�}|r2|�|�tj�||d�}t||�}|rF|�|�q|S)z�
    Finds and imports a module from site packages directories.

    :name: The name of the module to import
    :return: A list of imported modules, if no modules are imported an empty
             list is returned.
    z!No site package directories found�.py�__init__.py)	rr�log�debugrrrr�append)rZlibsZ
site_pathsZ	site_pathrrrrr�find_site_modules�s$
�



�rcOsBd}d|fd|ffD]\}}|�|tjj�|��}q
tjj�|�S)a%
    Return salt-call source, based on configuration.
    This will include additional namespaces for another versions of Salt,
    if needed (e.g. older interpreters etc).

    :dirs: List of directories to include in the system path
    :namespaces: Dictionary of namespace
    :return:
    a�# -*- coding: utf-8 -*-
import os
import sys

# Namespaces is a map: {namespace: major/minor version}, like {'2016.11.4': [2, 6]}
# Appears only when configured in Master configuration.
namespaces = %namespaces%

# Default system paths alongside the namespaces
syspaths = %dirs%
syspaths.append('py{0}'.format(sys.version_info[0]))

curr_ver = (sys.version_info[0], sys.version_info[1],)

namespace = ''
for ns in namespaces:
    if curr_ver == tuple(namespaces[ns]):
        namespace = ns
        break

for base in syspaths:
    sys.path.insert(0, os.path.join(os.path.dirname(__file__),
                                    namespace and os.path.join(namespace, base) or base))

if __name__ == '__main__':
    from salt.scripts import salt_call
    salt_call()
z%dirs%z%namespaces%)�replace�salt�utils�json�dumps�stringutils�to_bytes)�dirs�
namespaces�templateZtgtZcntrrr�_get_salt_call�s
r)cCstj�|dd�S)z-
    Return the path to the thin tarball
    �thinzthin.tgz)rrr)�cachedirrrr�	thin_path�sr,cCsgd�}tj�|�|vS)zj
    Return True if module is share-able between major Python versions.

    :param mod:
    :return:
    )r �jinja2�msgpack�certifi)rr�basename)�modZ	shareablerrr�
_is_shareable�sr2cCsLtj�|j��d�ddkr|�tj�|j��dS|�|j�dd��dS)z]
    Add a dependency to the top list.

    :param obj:
    :param is_file:
    :return:
    �.r�__init__�.pycrN)rrr0�__file__�splitr�dirnamer)�	container�objrrr�_add_dependency�sr;cCs4tjj�tjd�}tdi|��}tjjj|dd�S)z�
    This function is called externally from the alternative
    Python interpreter from within _get_tops function.

    :param extra_mods:
    :param so_mods:
    :return:
    �F)�ensure_asciiNr)r r!r"�loadsr�argv�get_topsr#)�extra�topsrrr�gte�s	rCcCsi}gd�}|rt|�dkr|�d�|D]l}|r||vrqtjj�|�s/t�d|�iS|dd�|�g}t	j
|t	jd�}|��\}}	t
j�tjj�|��d��}
|r[t
j�|
�sct�d	||�qt
j�|
��d
�ddkrwt
j�|
�}
n|
�d
d�}
|
||<q|S)a�
    Get top directories for the ssh_ext_alternatives dependencies
    automatically for the given python version. This allows
    the user to add the dependency paths automatically.

    :param py_ver:
        python binary to use to detect binaries

    :param exclude:
        list of modules not to auto detect

    :param ext_py_ver:
        the py-version from the ssh_ext_alternatives config
    )
r-�yaml�tornador.r/�singledispatch�
concurrent�singledispatch_helpersr�
markupsafe�
backports_abc�looseversion�	packaging��r�distroz5%s does not exist. Could not auto detect dependenciesz-czimport {0}; print({0}.__file__))�stdout�
zGCould not auto detect file location for module %s for python version %sr3rr4Zpyc�py)�tuplerr r!r�whichr�error�format�
subprocess�Popen�PIPE�communicater�abspath�data�decode�rstrip�existsr0r7r8r)�py_ver�exclude�
ext_py_ver�files�modsr1Zpy_shell_cmd�cmdrP�_Zmod_filerrr�get_tops_pythons4
�
rgcCs�t�|�pi}i}gd�}g}|��D]�\}}|||<|�d�}d}|s'd}n	t|ttf�s0d}|r8tj�	|��t|�dkrGd|vrG|�
d�|�d�d	krRtd
��|�d�D]O}|d|p`d}	|	sjt�
d|�qW|	�d
�r}tj�|	�s}t�
d||	�qW|	�d
�s�tj�tj�|	d��s�t�
d||	�qW|�
|	�||vr�|�|�|��qWd�|�}|r�d�|�}
t�|
�tjj	|
d��|||d<q|S)zb
    Get top directories for the dependencies, based on external configuration.

    :return:
    )r-rDrEr.�
py-versionNz@Alternative Salt library: missing specific locked Python versionz`Alternative Salt library: specific locked Python version should be a list of major/minor versionrMrO�dependenciesZinheritz#This feature is not yet implemented�z#Module %s has missing configurationrz:Module %s configured with not a file or does not exist: %srz3Module %s is not a Python importable module with %sz, zRMissing dependencies for the alternative version in the external configuration: {})�msg)�copy�deepcopy�items�get�
isinstancerS�listr �
exceptions�SaltSystemExitr�NotImplementedErrorr�warning�endswithrr�isfiler�pop�indexrVrU)�configZalternatives�requiredrB�ns�cfgZlocked_py_version�err_msg�depr1rkrrr�get_ext_tops?sf
�
���
�
�
r�cCsFi}|s|S|D]}t||�dg��}|stj�d��|||<q|S)zZ
    Get namespaces from the existing configuration.

    :param config:
    :return:
    rhztAn alternative version is configured, but not defined to what Python's major/minor version it should be constrained.)rSror rrrs)rzr'r|Zconstraint_versionrrr�_get_ext_namespaces�s�
r�rjcCs�g}tttttttttt	t
ttt
tg}td�}|r|d}nt}t�d|�|�|�tr2|�t�|D]}|rDt�d|j�t||�q4dd�|�d�D�D][}|t�vr�|t�vr�z3t|�t�|<tj�t�|j�\}}tj�|�\}	}
|	dkr�|�|�n|�tj� ||	d	��WqOt!y�}ztj"d
||dd�WYd
}~qOd
}~wwqOdd�|�d�D�D].}zt|�t�|<|�t�|j�Wq�t!y�}ztj"d|dd�WYd
}~q�d
}~ww|S)z�
    Get top directories for the dependencies, based on Python interpreter.

    :param extra_mods:
    :param so_mods:
    :return:
    �contextvarsrzUsing contextvars %rzAdding module to the tops: "%s"cS�g|]}|r|�qSrr��.0�mrrr�
<listcomp>��zget_tops.<locals>.<listcomp>�,r4rz&Unable to import extra-module "%s": %sT)�exc_infoNcSr�rrr�rrrr��r�zUnable to import so-module "%s")#r rOr-rDrEr.r/rFrGrHrrIrJrKrLr�py_contextvarsrrr�has_immutables�
immutables�__name__r;r7�locals�globals�
__import__rrr6�splitextr�ImportErrorrU)�
extra_mods�so_modsrBrd�modulesr�r1Zmoddir�modname�baserf�errrrrr@�sp�



��������r@cCs�g}t�|���D]\}}t|�}|dkr|�d�q	|dkr$|�d�q	t�|�p+i}|��D]\}}|�dj|g|�d��R��q0|�d�tjj	�
tj�
|��S)a�
    Based on the Salt SSH configuration, create a YAML configuration
    for the supported Python interpreter versions. This is then written into the thin.tgz
    archive and then verified by salt.client.ssh.ssh_py_shim.get_executable()

    Note: Current versions of Salt only Support Python 3, but the versions of Python
    (2.7,3.0) remain to include support for ssh_ext_alternatives if user is targeting an
    older version of Salt.
    :return:
    �zpy2:2:7rNzpy3:3:0z{}:{}:{}rhrj)rlrmrn�intrrVror r!r$r%r�linesepr)rB�extended_cfgZpymapr`Zcfg_copyr|r}rrr�_get_supported_py_config�s
� 
r�cCs6tjtj�|�dtj�|�dd�\}}t�|�|S)z�
    Make sure thintar temporary name is concurrent and secure.

    :param tarname: name of the chosen tarball
    :return: prefixed tarname
    z.thin-r<)�dir�prefix�suffix)�tempfileZmkstemprrr8r��close)ZtarnameZtfdZtmp_tarnamerrr�_get_thintar_prefix�s

�
r�cCsxt�|�}|��D]U\}}|�d�r^dt|�ddg�d�}|�d�r(|d}g}||�d�}|r@|��D]}	|�|	�q7ni||d<t|||dd�}
|
D]}	|
|	||d|	<qQq	t|���D]�\}}|�d	�g|�d�}|�d�\}}
|D]�}t	j
�|�}t	j
�|�t	j
�
|�}}t	�|�t|�r�d
p�d|��}t�d|||�t	j
�|�s�t�d
|�q}t	j
�|�s�t	j
�t	j
�||��r�|j|t	j
�|||�d�q}tjj
j|dd�D]X\}}}|D]P}|�d��s6|�t	j
�||��t	j
�||||�}t|d��r'z|�t	j
�|||��d}Wnt�y&t�d|�Ynw|�r6|jt	j
�||�|d�q�q�q}qedS)NZauto_detect�pythonrhrjrZpy_binri)rarbr�pyallrRz/Packing alternative "%s" to "%s/%s" destinationz;File path %s does not exist. Unable to add to salt-ssh thin��arcnameT��followlinks�r5z.pyo�getinfo�&ZIP: Unable to add "%s" with "getinfo")rlrmrnro�str�keysrrgr�rr�normpathr0r8�chdirr2rrr_rU�isdirr�addr r!�os_walkrvrr��KeyError)r��digest_collector�tfprzr|r}r`raZdepsrZ	auto_depsrBZpy_ver_majorZpy_ver_minor�topr��top_dirname�site_pkg_dir�rootr&rcrr�rrr�_pack_alternatives~


�
��
���������r��gzipc%Csltjdkrtj�d��|dvrt�d|�d}tj�	|d�}tj�
|�s)t�|�tj�	|d|dkr4dp5d	�}tj�	|d
�}	tj�	|d�}
tj�	|d�}tj�	|d
�}tj�	|d�}
tjj
��}tjj�|d��}|�td*it|����Wd�n1s�wYtj�|��r|s�tj�|	�r�tjj�|	��}|��tjjk}Wd�n1s�wY|dur�tj�|
�r�tjj�|
��}|��ttjd�k}Wd�n1s�wYnd}|�rz
t�d|�t�|�Wn,t�y}zt�d||�tj�|��rtj�d�|���WYd}~nd}~ww|Sd}i}t||d�}||tjj <tjj�|d��}|�t!||d��Wd�n	1�sLwYt"|�}|dk�rct#j$|ddd�}n|d	k�r|t%j&|dt'�rst%j(�put%j)d�}|j|_*zt�+�}Wnt�y�d}Ynwd}t�d�|�,�D]�\}}|D]�}|�r�tj�-|��s��q�tj�.|�}tj�/|�}tj�
|��r�t�0|�nt1�2�}t%�&|�}|�3|�tj�	||�}t�0|�t4|��r�d�p�d |��}t�d!||�tj�
|��stj�tj�	||���r|j*|tj�	||�d"��q�tjjj5|dd#�D]Y\}} }!|!D]P}"|"�6d$��su|�*tj�	||"��tj�	|||"�}#t7|d%��rfz|�8tj�	|||"��d}#Wnt9�yet�d&|#�Ynw|#�ru|j*tj�	||"�|#d"��q&�q|du�r�t:�;|�d}�q��q�|�r�t�d'�t<|||�t�0|�tjj�|	d(��}|�tjj�Wd�n	1�s�wYtjj�|
d(��}|�ttjj ��Wd�n	1�s�wYtjj�|
d(��}|�|�=��Wd�n	1�s�wYt�0tj�/|	��d)D]}$|�*|$��q	|�r*t�>|tj?��r*t�>|tj@��r*t�0|�|�A�t:�B||�|S)+a�
    Generate the salt-thin tarball and print the location of the tarball
    Optional additional mods to include (e.g. mako) can be supplied as a comma
    delimited string.  Permits forcing an overwrite of the output file as well.

    CLI Example:

    .. code-block:: bash

        salt-run thin.generate
        salt-run thin.generate mako
        salt-run thin.generate mako,wempy 1
        salt-run thin.generate overwrite=1
    )rNz;The minimum required python version to run salt-ssh is "3".)r��zipzCUnknown compression type: "%s". Falling back to "gzip" compression.r�r*zthin.�tgzr��version�.thin-gen-py-version�	salt-call�supported-versions�
code-checksum�wbr�NFrTzRemoving %s archive filez Error while removing %s file: %sz/Unable to remove {} file. See logs for details.z$Failed %s tops for Python binary %s.�r�r�)rBr��w:gz��dereference�w)�compressionz7Packing default libraries based on current Salt versionrRz Packing "%s" to "%s" destinationr�r�r�r�r�z4Packing libraries based on alternative Salt versions�w+)r�r�r�r�r�)r�)Cr�version_infor rrrsrrurrrr��makedirsr!�	hashutilsZDigestCollectorrc�fopen�writer)r�rw�readr��__version__r�r�remover
rUr_rVr@�majorr�r��tarfile�open�zipfile�ZipFile�zlib�ZIP_DEFLATEDZ
ZIP_STOREDr��getcwdrn�isabsr0r8r�r��mkdtemp�
extractallr2r�rvrr�r��shutil�rmtreer��digest�access�R_OK�X_OKr��move)%r+r��	overwriter�Zabsonly�compressr�Zthindir�thintarZthinverZ	pythinver�	salt_callZ	pymap_cfg�
code_checksumr��fp_�fh_�excZtops_failure_msg�tops_py_version_mappingrBZtmp_thintarr��	start_dir�tempdirr`r�r�r��eggr�r�r&rcrr��fnamerrr�gen_thinJs
��
���������	���

��



����

��,

���&
r��sha1cCs�t|�}tj�|dd�}tj�|�r5tjj�|d��}d|�	��
��d�}Wd�n1s/wYnd}|tjj�||�fS)�9
    Return the checksum of the current thin tarball
    r*r��r�'Nz'0')
r�rrrrwr r!rcr�r��stripr��get_hash)r+�formr�Zcode_checksum_pathZfhr�rrr�thin_sum�s��r�cCs�tj�|d�}tj�|�st�|�tj�|d�}tj�|d�}tj�|d�}tj�|d�}tjj�|d��}	|	�	t
��Wd�n1sGwYtj�|�r�|s�tj�|�r�tjj�|��}
|
��tj
jk}Wd�n1stwY|dur�tj�|�r�tjj�|��}
|
��ttjd	�k}Wd�n1s�wYnd
}|r�zt�|�Wnty�Ynw|Si}t||d�}||d<tj|d
d
d�}
zt��}Wnty�d}Ynwd}d}|��D]�\}}|D]�}tj�|�}tj�|�}tj�|��rt�|�nt��}t�|�}|� |�tj�||�}t�|�tj�|��s=|
j!|tj�d|��|�d�q�tjjj"|d
d�D];\}}}|D]2}|�#d��rW�qM|�$d��ritj�||�|v�ri�qM|
j!tj�||�tj�d|��||�d��qM�qF|du�r�t%�&|�d}q�q�t�|�|
�!d�tjj�|d��}	|	�	tj
j�Wd�n	1�s�wYtjj�|d��}	|	�	ttjd	��Wd�n	1�s�wYt�tj�|��|
�!d�|
�!d�|�r�t�|�|
�'�|S)a�
    Generate the salt-min tarball and print the location of the tarball
    Optional additional mods to include (e.g. mako) can be supplied as a comma
    delimited string.  Permits forcing an overwrite of the output file as well.

    CLI Example:

    .. code-block:: bash

        salt-run min.generate
        salt-run min.generate mako
        salt-run min.generate mako,wempy 1
        salt-run min.generate overwrite=1
    �minzmin.tgzr�z.min-gen-py-versionr�r�NFrTr��3r�r�)xzsalt/__init__.pyz
salt/utilszsalt/utils/__init__.pyzsalt/utils/atomicfile.pyzsalt/utils/validatezsalt/utils/validate/__init__.pyzsalt/utils/validate/path.pyzsalt/utils/decoratorsz!salt/utils/decorators/__init__.pyzsalt/utils/cache.pyzsalt/utils/xdg.pyzsalt/utils/odict.pyzsalt/utils/minions.pyzsalt/utils/dicttrim.pyzsalt/utils/sdb.pyzsalt/utils/migrations.pyzsalt/utils/files.pyzsalt/utils/parsers.pyzsalt/utils/locales.pyzsalt/utils/lazy.pyzsalt/utils/s3.pyzsalt/utils/dictupdate.pyzsalt/utils/verify.pyzsalt/utils/args.pyzsalt/utils/kinds.pyzsalt/utils/xmlutil.pyzsalt/utils/debug.pyzsalt/utils/jid.pyzsalt/utils/openstackz salt/utils/openstack/__init__.pyzsalt/utils/openstack/swift.pyzsalt/utils/asynchronous.pyzsalt/utils/process.pyzsalt/utils/jinja.pyzsalt/utils/rsax931.pyzsalt/utils/context.pyzsalt/utils/minion.pyzsalt/utils/error.pyzsalt/utils/aws.pyzsalt/utils/timed_subprocess.pyzsalt/utils/zeromq.pyzsalt/utils/schedule.pyzsalt/utils/url.pyzsalt/utils/yamlencoding.pyzsalt/utils/network.pyzsalt/utils/http.pyzsalt/utils/gzip_util.pyzsalt/utils/vt.pyzsalt/utils/templates.pyzsalt/utils/aggregation.pyzsalt/utils/yaml.pyzsalt/utils/yamldumper.pyzsalt/utils/yamlloader.pyzsalt/utils/event.pyzsalt/utils/state.pyzsalt/serializerszsalt/serializers/__init__.pyzsalt/serializers/yamlex.pyzsalt/template.pyzsalt/_compat.pyzsalt/loader.pyzsalt/clientzsalt/client/__init__.pyzsalt/extzsalt/ext/__init__.pyzsalt/ext/ipaddress.pyzsalt/version.pyzsalt/syspaths.pyz
salt/defaultszsalt/defaults/__init__.pyzsalt/defaults/exitcodes.pyzsalt/rendererszsalt/renderers/__init__.pyzsalt/renderers/jinja.pyzsalt/renderers/yaml.pyzsalt/moduleszsalt/modules/__init__.pyzsalt/modules/test.pyzsalt/modules/selinux.pyzsalt/modules/cmdmod.pyzsalt/modules/saltutil.pyzsalt/minion.pyzsalt/pillarzsalt/pillar/__init__.pyzsalt/utils/textformat.pyzsalt/log_handlerszsalt/log_handlers/__init__.pyzsalt/_logging/__init__.pyzsalt/_logging/handlers.pyzsalt/_logging/impl.pyzsalt/_logging/mixins.pyzsalt/clizsalt/cli/__init__.pyzsalt/cli/caller.pyzsalt/cli/daemons.pyzsalt/cli/salt.pyzsalt/cli/call.pyzsalt/fileserverzsalt/fileserver/__init__.pyzsalt/channelzsalt/channel/__init__.pyzsalt/channel/client.pyzsalt/transportzsalt/transport/__init__.pyzsalt/transport/client.pyzsalt/exceptions.pyzsalt/grainszsalt/grains/__init__.pyzsalt/grains/extra.pyzsalt/scripts.pyz
salt/state.pyzsalt/fileclient.pyz
salt/crypt.pyzsalt/config.pyzsalt/beaconszsalt/beacons/__init__.pyzsalt/payload.pyzsalt/outputzsalt/output/__init__.pyzsalt/output/nested.pyrRr�r�r�r r�)(rrrr�r�r r!rcr�r�r)rwr�r�r�r�rr�r�r
r@r�r�r�rnr0r8r�r�r�r�r�r�r�r�rv�
startswithr�r�r�)r+r�r�r�Zmindir�mintarZminverZpyminverr�r�r�r�rBr�r�r�Z	min_filesr`r�r�r�r�r�r&rcrrrr�gen_min
s�
������{


�
��

��
!
��


rcCst|�}tjj�||�S)r�)rr r!r�r�)r+r�rrrr�min_sum�sr)NN)rjrj)rjFrjTr�N)r�)rjFrj)D�__doc__r�r�rl�importlib.utilr�loggingrr�rrWrr�r�r�rOr-rKr.rLrDr Zsalt.exceptionsZsalt.ext.tornado�extrEZsalt.utils.filesZsalt.utils.hashutilsZsalt.utils.jsonZsalt.utils.pathZsalt.utils.stringutilsZsalt.versionr�r�r�r�r/rFrHrJZsalt.ext.backports_abcrIZ	backportsrZsalt.extrG�	getLoggerr�rrrrr)r,r2r;rCrgr�r�r@r�r�r�r�r�rrrrrr�<module>s�����������
-

?C
AF
�
5
�i