HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/__pycache__/lazy.cpython-310.pyc
o

;jt��@spddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl!Zddl"Zddl#Zddl$m%Z%zddl&Z'Wn
e(y�ddl'Z'Ynwe�)e*�Z+dZ,dZ-dZ.dZ/gZ0ej1j2D]
Z3e0�4e3d	e.f�q�ej1j5D]
Z3e0�4e3d	e,f�q�ej1j6D]
Z3e0�4e3d	e-f�q�e,ej1j7e-ej1j8e.ej1j9iZ:e�;ej<j=��>�Z?d
Z@e	�AdjBe
jCdd���ZDdaEeF�ZGdd
�ZHdd�ZIGdd�de�ZJGdd�d�ZKGdd�d�ZLGdd�dejMjNjO�ZPdd�ZQdS)�N)�MutableMapping)�zipimporter)�Depends�����rbzsalt.loadedz\.cpython-{}{}(\.opt-[1-9])?cCsJ|tjvrdSd�|�d�d�}t�t|��}t||j�|tj|<dS)Nz"'''Salt loaded {} parent module'''�.���)	�sys�modules�format�split�types�
ModuleType�str�exec�__dict__)�name�code�module�r�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py�_generate_moduleNs
rcCs|�tt��r	dSdS)N�int�ext)�
startswithr�SALT_BASE_PATH)Zmodule_pathrrr�	_mod_typeYsrc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�FilterDictWrapperzx
    Create a dict which wraps another dict with a specific key suffix on get

    This is to replace "filter_load"
    cCs||_||_dS�N��_dict�suffix)�self�dr$rrr�__init__fs
zFilterDictWrapper.__init__cCs||j|<dSr!�r#)r%�key�valrrr�__setitem__jszFilterDictWrapper.__setitem__cCs|j|=dSr!r(�r%r)rrr�__delitem__m�zFilterDictWrapper.__delitem__cCs|j||jSr!r"r,rrr�__getitem__pszFilterDictWrapper.__getitem__cCs
t|j�Sr!)�lenr#�r%rrr�__len__ss
zFilterDictWrapper.__len__ccs.�|jD]}|�|j�r|�|jd�VqdS)N�)r#�endswithr$�replacer,rrr�__iter__vs�
��zFilterDictWrapper.__iter__N)
�__name__�
__module__�__qualname__�__doc__r'r+r-r/r2r6rrrrr _sr c@s<eZdZdZdd�Zedd��Zdd�Zdd	�Zd
d�Z	dS)
�
LoadedFunca�
    The functions loaded by LazyLoader instances using subscript notation
    'a[k]' will be wrapped with LoadedFunc.

      - Makes sure functions are called with the correct loader's context.
      - Provides access to a wrapped func's __global__ attribute

    :param func str: The function name to wrap
    :param LazyLoader loader: The loader instance to use in the context when the wrapped callable is called.
    cCs||_||_t�||j�dSr!)r�loader�	functools�update_wrapper�func)r%rr<rrrr'�szLoadedFunc.__init__cCs|jj|jSr!)r<r#rr1rrrr?�szLoadedFunc.funccCst|j|�Sr!)�getattrr?�r%rrrr�__getattr__�r.zLoadedFunc.__getattr__cOs�|j}tj�|j�}|durddl}|�|j�}|j�|j	�d}t
|d�rJt|jt
jjj�sJd|jjvrJ|jjddurCd|jd<nd|jd<d}|jjrVt|jj�|�}|jj|g|�Ri|��}|rn|jd|jjd<|S)NrF�__opts__�testT)r?rr
�getr8rrr�update�__globals__�hasattr�
isinstancerC�saltr<�context�NamedLoaderContext�opts�inject_globals�global_injector_decorator�run)r%�args�kwargsZrun_func�modrZset_test�retrrr�__call__�s(

zLoadedFunc.__call__cCsd|jj�d|j�d�S)N�<z name=�>)�	__class__r7rr1rrr�__repr__�szLoadedFunc.__repr__N)
r7r8r9r:r'�propertyr?rBrUrYrrrrr;|s
r;c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�	LoadedModz:
    This class is used as a proxy to a loaded module
    �rSr<cCs||_||_dS)zd
        Return the wrapped func's globals via this object's __globals__
        attribute.
        Nr\)r%rSr<rrrr'�s
zLoadedMod.__init__cCs>z|j|j�d|��WStytd|�d|j����w)zC
        Run the wrapped function in the loader's context.
        r
zNo attribute by the name of z was found on )r<rS�KeyError�AttributeErrorrArrrrB�s��zLoadedMod.__getattr__cCsd�|jj|jj|j�S�Nz<{} module='{}.{}'>)rrXr7r<�loaded_base_namerSr1rrrrY�s�zLoadedMod.__repr__N)r7r8r9r:�	__slots__r'rBrYrrrrr[�sr[cseZdZdZeZ													d:�fdd�	Zdd�Zd	d
�Zdd�Z	d
d�Z
�fdd�Zdd�Zdd�Z
dd�Zdd�Z�fdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd;d0d1�Zd2d3�Zd4d5�Zd6d7�Zed8d9��Z �Z!S)<�
LazyLoadera�
    A pseduo-dictionary which has a set of keys which are the
    name of the module and function, delimited by a dot. When
    the value of the key is accessed, the function is then loaded
    from disk and into memory.

    .. note::

        Iterating over keys will cause all modules to be loaded.

    :param list module_dirs: A list of directories on disk to search for modules
    :param dict opts: The salt options dictionary.
    :param str tag: The tag for the type of module to load
    :param func mod_type_check: A function which can be used to verify files
    :param dict pack: A dictionary of function to be packed into modules as they are loaded
    :param list whitelist: A list of modules to whitelist
    :param bool virtual_enable: Whether or not to respect the __virtual__ function when loading modules.
    :param str virtual_funcs: The name of additional functions in the module to call to verify its functionality.
                                If not true, the module will not load.
    :param list extra_module_dirs: A list of directories that will be able to import from
    :param str pack_self: Pack this module into a variable by this name into modules loaded
    :returns: A LazyLoader object which functions as a dictionary. Keys are 'module.function' and values
    are function references themselves which are loaded on-demand.
    # TODO:
        - move modules_max_memory into here
        - singletons (per tag)
    NrTcs�d|_i|_|durin||_|jD]}t|j|tjjj�r)|j|��|j|<q|dur0i}t	�
|�}dD]}||vrOt||tjjj�rO||��||<q7|�d�}tjjj
|d�|_|�|�|_|
|_||_||_d|_|ptt|_|pyt|_||_d|jvr�d|jd<|j��D]\}}|dur�|j�|i�tjj�|j|�|j|<q�||_||_d|_i|_ t!�|_"t!�|_#|	r�|	ng|_$|dur�g}||_%|r�|ng|_&g|_'t!|j�d�(|j|jdd	kr�d
nd	�g��|_)i|_*d
g|_+t,D]\}}}|||f|j*|<|j+�-|�q�t.�/�|_0|j0�|�1�Wd�n	1�s$wYt2��3�t4|j�d��t4|j�d|���t4|j�d
��t4|j�d|���dS)zz
        In pack, if any of the values are None they will be replaced with an
        empty context-specific dict
        N)�pillar�grains�multiprocessing)Z
threadsafe�__context__Tzdisable_{}{}r�sr3�.int�.int.�.ext�.ext.)5�
parent_loaderrN�packrIrJr<rKrL�value�copy�deepcopyrE�utilsZContextDict�context_dict�_LazyLoader__prep_mod_optsrM�	pack_self�module_dirs�tagZ
_gc_finalizer�LOADED_BASE_NAMEr`r�mod_type_check�(_only_pack_properly_namespaced_functions�items�
setdefault�NamespacedDictWrapper�	whitelist�virtual_enable�initial_load�missing_modules�set�loaded_modules�loaded_files�static_modules�
virtual_funcs�extra_module_dirs�_clean_module_dirsr�disabled�
suffix_map�suffix_order�SUFFIXES�append�	threading�RLock�_lock�_refresh_file_mapping�superr'r)r%rurMrvr`rxrmr}r~r��proxyr�r�rtry�iZthreadsafety�k�vr$�mode�kind�rXrrr'�s�
�

��

�


����

�
zLazyLoader.__init__cCs|Sr!rr1rrr�	__enter___szLazyLoader.__enter__cCs|��dSr!)�destroy)r%�exc_typeZexc_valZexc_tbrrr�__exit__br.zLazyLoader.__exit__cCs�|��t|d�r|jdurt|jd�r|j��t|d�r)t|jt�r)|j��t|d�r3|j��t|d�r=|j	��t|d�rI|j
��dSdS)z9
        Destroy the loader and clean up modules
        rrNr�rmr#r�r�)�
clean_modulesrHrrr�rIrm�dict�clearr#r�r�r1rrrr�es






�zLazyLoader.destroyc	Cs�t|�}|tvr
dSt�|�z[|j�d�|j�d|j��|j�d�|j�d|j��h}|j�d|j�d�|j�d|j�d�g}ttj�D]}|�|j�rb||vrRqE|D]
}|�|�ratj|=nqTqEWt�	|�dSt�	|�w)a\
        Clean modules and free memory for this loader's tag only.

        Removes loaded modules from sys.modules to allow garbage collection,
        but only for modules belonging to this loader's tag (e.g., 'grains', 'modules').
        This prevents interfering with other active loaders (e.g., runners, states).

        Base stub modules are preserved as they are shared infrastructure.

        Note: This method does NOT clear the loader's internal state (_dict, loaded_modules, etc.)
        as the loader may still be referenced and used after cleanup. The modules will be
        garbage collected when they're no longer referenced.

        Note: Injected loaders in pack (e.g., __utils__, __salt__, __states__) are
        NOT cleaned up because they are shared infrastructure. They will be cleaned
        up when explicitly destroyed.
        Nrhrirjrkr
)
�id�_cleaning_loaders�addr`rv�listrr
r�discard)r%Z	loader_idZ
base_stubsZtag_prefixesr�prefixrrrr�vs2

	
�	�
���zLazyLoader.clean_modulescst��|�t||�S)z�
        Override the __getitem__ in order to decorate the returned function if we need
        to last-minute inject globals
        )r�r/r;)r%�itemr�rrr/�s
zLazyLoader.__getitem__cCs�|dvr
t�||�Szt�||�WStyYnw||jvr=|js=|�|�D]}||jvr0q(|�|�r<||jvr<nq(||jvrGt	||�St|��)z�
        Allow for "direct" attribute access-- this allows jinja templates to
        access things like `salt.test.ping()`
        )�__getstate__�__setstate__)
�object�__getattribute__rBr^r��loaded�_iter_filesr��_load_moduler[)r%�mod_namerrrrrB�s"�
�

zLazyLoader.__getattr__cCsd�|jj|j|j�Sr_)rrXr7r`rvr1rrrrY�s�zLazyLoader.__repr__cCsr|�d�d}||jvrd|�d�Sz|j|}Wnty(d|�d�YSw|dur3d�||�Sd|�d�S)z�
        Return the error string for a missing function.

        This can range from "not available' to "__virtual__" returned False
        r
r�'z' is not available.Nz#'{}' __virtual__ returned False: {}z' __virtual__ returned False)rr�r�r]r)r%Z
function_namer��reasonrrr�missing_fun_string�s
��zLazyLoader.missing_fun_stringcs�|j�dd�dur8d|jvr8ztd�at��t�|jd<d|jvr(|j�d�Wnt	y7t
�d�Ynw|j�dd�durWd|jvrWt�|jd<d|jvrW|j�d�ddtf|jd<i|_
g��fd	d
�}|jD�]V}ztdd�t�|�D��}Wn	ty�Yqmwzd
d�tt�tj�|d���D�}Wn	ty�Ynw|�|�|D�]}�z	tj�|�\}}|�d�r�Wq�tj�|�\}}	t�||�}zt����d��dd�d�}
Wntt t!fy�d}
Ynwz
|jd�"|
�}Wnt#�yt
�$d|
||
�YWq�w|	|jv�rWq�||j%v�r"t
�$d|�Wq�tj�||�}|	dk�rOt�|�}
|jD]}d|k�r?�q6d|��}||
v�rKn�q6Wq�z|j
|d}|j
|d}Wn
t#�yiYn=wd||	fv�r�||	k�r�t
�&d||j
|d�|	dk�r�|dk�r�||k�r�Wq�n|�r�|j�"|	�|j�"|�k�r�Wq�|�s�|	dk�r�Wq�||	|f|j
|<Wq�t�y�Yq�wqm|j'D]}|�d�d}|ddf|j
|<�q�dS)z7
        refresh the mapping of the FS on disk
        Z
cython_enableT�.pyx�	pyximportz]Cython is enabled in the options but not present in the system path. Skipping Cython modules.Zenable_zip_modules�.zipr3cs��|�dS)a
            Hack so we can get the optimization level that we replaced (if
            any) out of the re.sub call below. We use a list here because
            it is a persistent data structure that we will be able to
            access after re.sub is called.
            r3)r�)�obj�Z	opt_matchrr�_replace_pre_ext"s
z:LazyLoader._refresh_file_mapping.<locals>._replace_pre_extcss�|]	}|dkr|VqdS)�__pycache__Nr��.0�xrrr�	<genexpr>0s�z3LazyLoader._refresh_file_mapping.<locals>.<genexpr>cSsg|]	}tj�d|��qS)r�)�os�path�joinr�rrr�
<listcomp>4s��z4LazyLoader._refresh_file_mapping.<locals>.<listcomp>r��_r�-rrZoptimization_orderz�Disallowed optimization level %d for module name '%s', skipping. Add %d to the 'optimization_order' config option if you do not want to ignore this optimization level.z,Skipping %s, it is disabled by configurationr'rz'Module/package collision: '%s' and '%s'z.pycr
�.oN)(rMrEr��
__import__r��install�tupler�r��ImportError�log�info�MODULE_KIND_PKG_DIRECTORY�file_mappingru�sortedr��listdir�OSErrorr�r��extendrr�splitext�PY3_PRE_EXT�subr�pop�group�rsplitr^�
IndexError�
ValueError�indexr]�tracer��errorr�)r%r�Zmod_dir�filesZ
pycache_files�filename�dirname�basenameZf_noextr�	opt_levelZ	opt_index�fpathZsubfilesr$Z	init_fileZcurr_extZcurr_opt_index�smodrr�rr��s�

���


�
��


"��
��





���
��
���
X�z LazyLoader._refresh_file_mappingcsd|j�%t���t�|_i|_t�|_t|d�r|��d|_	Wd�dS1s+wYdS)z 
        Clear the dict
        rMFN)
r�r�r�r�r�r�r�rHr�rr1r�rrr��s

"�zLazyLoader.clearcCs�d|jvr(|�di�}t|tjjj�r|��}||jd<tj	j�
|jd�|jd<d|jvrP|�di�}t|tjjj�r?|��}||jd<tj	j�
|jd�|jd<i}t|���D]
\}}|dkraqX|||<qXd|jvrp||jd<|S)z;
        Strip out of the opts any logger instance
        Z
__grains__rdZ
__pillar__rc�loggerrC)
rmrErIrJr<rKrLrnrrrqr|r�rz)r%rMrdrcZmod_optsr)r*rrrZ__prep_mod_opts�s0


�


�


zLazyLoader.__prep_mod_optsccs\�||jvr	|V|jD]	}||vr|Vq|j�dd�s*|jD]}||vr)|Vq dSdS)zW
        Iterate over all file_mapping files in order of closeness to mod_name
        Zlazy_loader_strict_matchingFN)r�rMrE)r%r�r�rrrr��s�

�
��zLazyLoader._iter_filescsJ�fdd�t��D�}|D]}|j��jd�r"t�|�|�|�q
dS)Nc3s,�|]}tt�|��j�rt�|�VqdSr!)rIr@rX)r�Zsname�rSrrr��s��
�z0LazyLoader._reload_submodules.<locals>.<genexpr>r
)�dirr7r�	importlib�reload�_reload_submodules)r%rSZ
submodulesZ	submodulerr�rr��s
�

��zLazyLoader._reload_submodulescCs2|jD]}|tjvrtj�|�|j�|�qdSr!)r�rr�r�r�)r%�	directoryrrrZ__populate_sys_path�s

��zLazyLoader.__populate_sys_pathcCspd}|jD]}|tjvrtj�|�d}qg|_t��|r4|jD]}|tjvr3tj|dur3tj|=q!dSdS)NFT)r�rr��remover��invalidate_cachesr��path_importer_cache)r%Zinvalidate_path_importer_cacher�rrrZ__clean_sys_path�s 

�

��zLazyLoader.__clean_sys_pathc2Cs4
d}|j|dd�\}}ztjj�d�\}}||vr+||vr+t�d|tjj�WdSWn	ty5Ynw|j�	|�t
j�|�}�z�z�|�
�tj�|�|dkr]t�||t���}n�|dkr�t|t�t�g�}|�d�}	t|	�dkrx|}n�|}|	dd�D]}
t||
�}q�n�|d	kr�t|��|�}n�|j|}zd�|j|�|�|j|f�}Wnty�d
�|j|�|�|j|�}Ynw|dk�rt j!j"t j!j#ft j!j$t j!j%ft j!j&t j!j'fg}
t j!j(|g|
�R�}|�)|�}|dur�t*��|j+��}|tj,|<|j-�s|�.|�n&t/|d||�}t j0j1|||d�}|du�r!t*��|�2|j+j�}|tj,|<Wn�t3�y7�t*�y|}z9d
t4|�v�rWd�|j|�}t�5|�||j6|<tj7d|j|dd�||j6|<WYd}~Wtj�8|�|�9�dSd}~wt:�y�}z!tj;d|j|dd�||j6|<WYd}~Wtj�8|�|�9�dSd}~wt<�y"}zmzt=�>t�?�d�d\}}}}Wn
t@�y�Yn1wt
j�ddd�t
j�ddd�t
j�ddd�g}|D]}|�A|��r�d|v�r�t�BtCjDjEjF��q�tj;d|j|dd�||j6|<WYd}~Wtj�8|�|�9�dSd}~wwWtj�8|�|�9�ntj�8|�|�9�wtCj+jG�H�}tI|d��rZtJ|jKtCj+jGjH��sYt�5d|�||_Kn||_KtI|d��r�tJ|jLtCj+jGjM��s�tI|d��sztN�O|jL�|_PtN�O|jP�|_L|jL�Q|jR�ntI|d��s�i|_PtN�O|jP�|_L|jL�Q|jR�|jS�T�D]N\}}|dk�r��q�t||d�}tI|d ��r�tN�O|jU�}nd}|�V||�}|du�r�tW|||��q�||k�r�t�7d!||�tW|||��q�tW|||��q�|jXdu�r@t||jXd�}tI|d ��rtN�O|jU�}nd}|�V|jX|�}|du�r$tW||jX|�n||k�r9t�7d!|jX|�tW||jX|�ntW||jX|�|jY�Zdd�d}t|d"d�} t[�\| ��r�z	|�2| |jR�Wn9t�yv}!zt�;|!�WYd}!~!n&d}!~!wt:�y�d#}"tj7d$|j||"dd�|"|j6|<|"|j6|<YdSw|j]�rd%g|j^}#|#D]k}$|�_|||$�\}%}}&}'|&du�r�t�d$|j||&�|%du�r|&|j6|<||j6v�r�|&|j6|<dS|&du�r|j6|}(|(du�r�|&|j6|<dSt4|(�})t4|&�}*|*�r|*|)�d&�v�r|)�d&|*��|j6|<dS�q�nd'}'d(|jRv�rD|jd)v�rDtI|d*��r6|jRd(d+|j`v�rDd,|j`v�rDd-}"|"|j6|<|"|j6|<dSz|ja}+t�7d.|�Wn*t�yyz|jb}+t�7d/|�Wnt�yvtc|�}+t�7d0|�YnwYnw|gtd|'�},|+D]o}-|-�ed1��r��q�t||-�}.t[�\|.��s�tJ|.tfjg��s��q�|jh�r�|.ji�e|j��s��q�t|d2i��j|-|-�}/|,D]5}0z	d�|0|/f�}1Wnt�y�|0�d|/��}1Ynw|1|jkv�r�|.|jk|1<|�l|.|�|jm�	|0��q��q�ztn�o|jk|j|�WdStp�y}z
t�qd3|�WYd}~dSd}~ww)4Nrr�z)Trying to load %s on %s, returning False.Fr�r�r
rr�z{}.{}.{}.{}r3)r<zmagic numberztFailed to import {} {}. Bad magic number. If migrating from Python2 to Python3, remove all .pyc files and try again.zFailed to import %s %s:
T��exc_infozCFailed to import %s %s, this is due most likely to a syntax error:
rrJrqz
process.pyZcliz
daemons.pyzapi.pyZ_handle_signalsz3Failed to import %s %s as the module called exit()
�__salt_loader__zOverride  __salt_loader__: %srC�
__orig_opts__�defaultzOverride  %s: %sr'z__init__ failedzError loading %s.%s: %s�__virtual__z; rr�)rdr��__proxyenabled__Z	proxytype�*z!not a proxy_minion enabled modulezTThe functions from module '%s' are being loaded from the provided __load__ attributezSThe functions from module '%s' are being loaded from the provided __all__ attributezMThe functions from module '%s' are being loaded by dir() on the loaded moduler�Z__func_alias__zBDepends.enforce_dependencies() failed for the following reason: %s)rr�r�implementation�	cache_tagrr�r�r^r�r�r�r�r��_LazyLoader__populate_sys_pathr�r��load_module�tempfileZ
gettempdirr��globals�localsr0r@rr�r�r`rxrv�	TypeErrorrr��	machinery�SourceFileLoader�SOURCE_SUFFIXES�SourcelessFileLoader�BYTECODE_SUFFIXES�ExtensionFileLoader�EXTENSION_SUFFIXES�
FileFinder�	find_specr�r<r
rr��MODULE_KIND_MAP�util�spec_from_file_locationrPr�r�warningr��debugr��_LazyLoader__clean_sys_path�	Exceptionr��
SystemExit�	traceback�
extract_tbr�r�r4�exitrJ�defaultsZ	exitcodes�EX_OKrKZ
LoaderContextrHrIr�rCrLrorpr�rFrMrmrzr��
named_context�setattrrtr7r��inspect�
isfunctionr~r��_process_virtualr�Z__load__�__all__r�r�rr=�partialryr8rEr#�_apply_outputterr�rZenforce_dependencies�RuntimeErrorr�)2r%rrSr�r$Zimplementation_tagZ
cache_tag_verZ
fpath_dirnameZtop_mod�compsZsubname�descZ
mod_namespace�loader_detailsZfile_finder�specr<�excZ	error_msgr�Zfn_r�ZcallerZtgt_fnsZtgt_fnZloader_contextZp_nameZp_valueZmod_named_contextr�r�module_nameZmodule_init�eZ
err_stringZvirtual_funcs_to_process�virtual_funcZvirtual_retZvirtual_err�virtual_aliases�existingZexisting_strZnew_strZ
funcs_to_loadZ	mod_names�attrr?�funcnameZtgt_modZ
full_funcnamerrrr�	sh����
�
����
������



��

���


$���
��"����
���
�
��




��

��

�



�


����%

������
��	�
�
����zLazyLoader._load_modulec	st�t�s	td��d�vrtd��d�����dd�\}}�j�c|�jvs+��jvr4	Wd�dS�jrI|�jvrIt�	d�|�j�t�����fd	d
�}d}d}	z||�}|sh|durh��
�d}WqTWntyz|sx��
�d}YqTwWd�|S1s�wY|S)z3
        Load a single item if you have it
        zThe key must be a string.r
z	The key 'z' should contain a '.'rNTzNFailed to load function %s because its module (%s) is not in the whitelist: %scs:��|�D]}|�jvr
q��|�r��jvrdSqdS)NTF)r�r�r�r#)r�r�r)r%rr�_inner_load�s
�z%LazyLoader._load.<locals>._inner_loadF)rIrr]rr�r�r#r}r�r�r�r�)r%r)r�r�r(rTZreloadedrr'r�_load�sN
��
��
�,�,zLazyLoader._loadcCs^|j�"|jD]}||jvs||jvrq|�|�qd|_Wd�dS1s(wYdS)z"
        Load all of them
        TN)r�r�r�r�r�r�rArrr�	_load_all�s
"�zLazyLoader._load_allcCs<|j�t�|_|��Wd�dS1swYdSr!)r�r�r�r*r1rrr�reload_modules�s
"�zLazyLoader.reload_modulescCs2t|d�r|j}|j|vr||j|_dSdSdS)zC
        Apply the __outputter__ variable to the functions
        �
__outputter__N)rHr,r7)r%r?rSZoutprrrr�s

�zLazyLoader._apply_outputterr�c

Cs�t|dt��}z�d}t|d�r�t�|j�r�z5t��}t||�}|�|�}t|t�r1|d}|d}|j	�
dd�rIt��|}	d�|	|�}
t�
|
�Wn#tym}zd	�|j|�}tj|tjd
�d}WYd}~nd}~wwt|d|�}|s�|dur�t�
d|j|�t|d�r�t|t�r�|r�|}d|||fWS|d
ur�||kr�t�d||�||kr�t�d|j||�|}n|d
ur�||kr�|d
ur�|}Wn)ty�tjd|d
d�Ynty�tjd|j|d
d�d|||fYSwd
|d|fS)a"
        Given a loaded module and its default name determine its virtual name

        This function returns a tuple. The first value will be either True or
        False and will indicate if the module should be loaded or not (i.e. if
        it threw and exception while processing its __virtual__ function). The
        second value is the determined virtual name, which may be the same as
        the value provided.

        The default name can be calculated as follows::

            module_name = mod.__name__.rsplit('.', 1)[-1]
        Z__virtual_aliases__Nr�rrZ
virtual_timerFz'Virtual function took {} seconds for {}z[Exception raised when processing __virtual__ function for {}. Module will not be loaded: {})Zexc_info_on_loglevelZ__virtualname__z�%s.__virtual__() is wrongly returning `None`. It should either return `True`, `False` or a new name. If you're the developer of the module '%s', please fix this.TzLoaded %s as virtual %sz�The module '%s' is showing some bad usage. Its __virtualname__ attribute is set to '%s' yet the __virtual__() function is returning '%s'. These values should match!zKeyError when loading %sr�z.Failed to read the virtual function for %s: %s)r@r�rHrrr��timerPrIrMrErr�rrr7r��logging�DEBUGrr�r]r	rv)
r%rSr r"r#Zerror_reason�startZvirtual_attrZvirtual�end�msgrZvirtualnamerrrr�s�


�
�����
�
����
���zLazyLoader._process_virtualcOs(t��|_|jj|j|g|�Ri|��S)zD
        Run the `_func_or_method` in this loader's context
        )�contextvarsZcopy_contextZ
_last_contextrP�_run_as)r%�_func_or_methodrQrRrrrrPZs
zLazyLoader.runc	Os�d|_z	tjjj��}Wntyd}Ynw||ur||_tjjj�|�}z!||i|��}t|tjjj	�r;|�
�}|Wd|_tjjj�|�Sd|_tjjj�|�w)zL
        Handle setting up the context properly and call the method
        N)rlrJr<rKZ
loader_ctxvarrE�LookupErrorr�rIrLrn�reset)r%r5rQrRZcurrent_loader�tokenrTrrrr4as$��zLazyLoader._run_ascOs0||g}|�|�tj|j||d�}|��|S)zR
        Run the function in a new thread with the context of this loader
        )�targetrQrR)r�r��Threadr9r0)r%r5rQrRZargslist�threadrrr�
run_in_threadvs

zLazyLoader.run_in_threadcOs|j|g|�Ri|��dSr!)rP)r<r5rQrRrrrr9�szLazyLoader.target)
NrNNNNTNNNNNT)r�)"r7r8r9r:r�Zmod_dict_classr'r�r�r�r�r/rBrYr�r�r�rsr�r�r�r
r�r)r*r+rrrPr4r<�staticmethodr9�
__classcell__rrr�rrb�s^�iG!|8
	
rbcs�fdd�}|S)z�
    Decorator used by the LazyLoader to inject globals into a function at
    execute time.

    globals
        Dictionary with global variables to inject
    cst�����fdd��}|S)NcsHtjjj�fi�����|i|��Wd�S1swYdSr!)rJrqrKZfunc_globals_inject)rQrR)�frNrr�wrapper�s$�zCglobal_injector_decorator.<locals>.inner_decorator.<locals>.wrapper)r=�wraps)r?r@�rN)r?r�inner_decorator�sz2global_injector_decorator.<locals>.inner_decoratorr)rNrCrrBrrO�s	rO)Rror=r�Zimportlib.machinery�importlib.utilrr.r��pathlib�rerr�r�r-r
r�collections.abcrZ	zipimportrZsalt.configrJZsalt.defaults.eventsZsalt.defaults.exitcodesZsalt.loader.contextZ
salt.syspathsZsalt.utils.argsZsalt.utils.contextZsalt.utils.dataZsalt.utils.dictupdateZsalt.utils.eventZsalt.utils.filesZsalt.utils.lazyZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.versionsZsalt.utils.decoratorsrZ_contextvarsr3r��	getLoggerr7r�ZMODULE_KIND_SOURCEZMODULE_KIND_COMPILEDZMODULE_KIND_EXTENSIONr�r�r�rr$r�r�rr�r�rr�PathZsyspathsZINSTALL_DIR�resolverrw�compiler�version_infor�r�r�r�rrr r;r[rqZlazyZLazyDictrbrOrrrr�<module>s��
�; 7