HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/templates.cpython-310.pyc
o

�N�gN^�@sdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZmZm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(dd	l)m*Z*dd
l+m,Z,e�-e.�Z/ej0�1edd�Z2dZ3e�4e3�Z5Gd
d�d�Z6Gdd�d�Z7dd�Z8dd�Z9dd�Z:dd�Z;dd�Z<d+dd�Z=d+dd�Z>d+dd �Z?d+d!d"�Z@d+d#d$�ZAd+d%d&�ZBd,d(d)�ZCe9e>�ZDe9e?�ZEe9e@�ZFe9eA�ZGe9eB�ZHeDeEeCeFeGeHd*�ZIdS)-z
Template render systems
�N)�Path)�__path__)�CommandExecutionError�SaltInvocationError�SaltRenderError)�NamedLoaderContext)�__file_client__)�JinjaFilter�JinjaGlobal�	JinjaTest)�OrderedDict)�VersionZ	templateszutf-8c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
AliasedLoaderah
    Light wrapper around the LazyLoader to redirect 'cmd.run' calls to
    'cmd.shell', for easy use of shellisms during templating calls

    Dotted aliases ('cmd.run') must resolve to another dotted alias
    (e.g. 'cmd.shell')

    Non-dotted aliases ('cmd') must resolve to a dictionary of function
    aliases for that module (e.g. {'run': 'shell'})
    cCs
||_dS�N��wrapped)�selfr�r�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/templates.py�__init__<�
zAliasedLoader.__init__cCs
|j|Srr�r�namerrr�__getitem__?rzAliasedLoader.__getitem__cC�t|j|�Sr��getattrrrrrr�__getattr__B�zAliasedLoader.__getattr__cCs
||jvSrrrrrr�__contains__ErzAliasedLoader.__contains__N)�__name__�
__module__�__qualname__�__doc__rrrrrrrrr0src@s eZdZdZdd�Zdd�ZdS)�
AliasedModulea
    Light wrapper around module objects returned by the LazyLoader's getattr
    for the purposes of `salt.cmd.run()` syntax in templates

    Allows for aliasing specific functions, such as `run` to `shell` for easy
    use of shellisms during templating calls
    cCs||_||_dSr)�aliasesr)rrr%rrrrRs
zAliasedModule.__init__cCrrrrrrrrVrzAliasedModule.__getattr__N)r r!r"r#rrrrrrr$Isr$c
Csi}|�dd�}|rktt|����}|s|�dd�d}n-|�|�d��r1|dt|�d�}n|�|�d��rE|d	t|�d�}nt�d
�d|vrV|�dd�dnd}|�	t
|||ra|nd|�dd�d
��|�	t
||�dd�|�dd�|�dd�d��|S)ao
    Generate SLS/Template Context Items

    Return values:

    tplpath - full path to template on filesystem including filename
    tplfile - relative path to template -- relative to file roots
    tpldir - directory of the template relative to file roots. If none, "."
    tpldot - tpldir using dots instead of slashes, if none, ""
    slspath - directory containing current sls - (same as tpldir), if none, ""
    sls_path - slspath with underscores separating parts, if none, ""
    slsdotpath - slspath with dots separating parts, if none, ""
    slscolonpath- slspath with colons separating parts, if none, ""

    �.�/����z.sls�Nz	/init.sls�	z(Failed to determine proper template pathr�)ZtplpathZtplfileZtpldirZtpldot�:�_)�slspathZ
slsdotpathZslscolonpathZsls_path)�replace�strr�as_posix�rsplit�endswith�len�log�warning�update�dict)�tmplpath�sls�sls_contextr/�templaterrr�generate_sls_contextZs:


��



��	r>cs	d�fdd�	}�|_|S)a
    Each template processing function below, ``render_*_tmpl``, is wrapped by
    ``render_tmpl`` before being inserted into the ``TEMPLATE_REGISTRY``.  Some
    actions are taken here that are common to all renderers.  Perhaps a
    standard decorator construct would have been more legible.

    :param function render_str: Template rendering function to be wrapped.
        Each function is responsible for rendering the source data for its
        repective template language.

    :returns function render_tmpl: The wrapper function
    FNc

sN|duri}d|vrt|d�|d<|�|�|}d|vsJ�d|vs%J�d|vr5t||d�}|�|�t|t�r�|r?|}n^z(|durKtj�||�}t�	|dt
��}|��}Wd�n1sawYWn5tt
tfy�}	ztjj�|�r�td|d�WYd}	~	Stjd||	tjd	��d}	~	ww|��}|��z0�|||�}
tjj��r�d
}tjjj|
t
d��dtjf�r�d}tj�|
���}
|r�|
tj7}
Wn"t y�}	zt�!d
��d}	~	wt"y�td
t#�$�d�YSw|r�td|
d�St%j&dd
tjjj'd��}|�(tjjj)|
t
d��Wd�n	1�swYtd|j*d�S)N�salt�opts�saltenvr;�rT��result�dataz,Exception occurred while reading file %s: %s)Zexc_info_on_loglevelF��encoding�
zRendering exception occurred�wb)�delete�prefix)+rr8r>�
isinstancer1�os�path�join�codecs�open�SLS_ENCODING�read�UnicodeDecodeError�
ValueError�OSErrorr?�utils�filesZ	is_binaryr9r6�error�logging�DEBUG�close�platformZ
is_windows�stringutils�
to_unicoder4�linesep�
splitlinesr�	exception�	Exception�	traceback�
format_exc�tempfileZNamedTemporaryFileZTEMPFILE_PREFIX�write�to_bytesr)
ZtmplsrcZfrom_str�to_str�contextr:�kwsr<�tmplstrZ_tmplsrc�exc�output�newlineZoutf��
render_strrr�render_tmpl�s�



�������
�
�����	z#wrap_tmpl_func.<locals>.render_tmpl)FFNNrp)rqrrrrpr�wrap_tmpl_func�s�NrscCs*z
dd�|D�dWStyYdSw)�C
    Return the line number where the template error was found
    cSsg|]
}|ddvr|�qS)�)ztop-level template coder=z<module>r)�.0�xrrr�
<listcomp>�s
�z)_get_jinja_error_slug.<locals>.<listcomp>r)N)�
IndexError��tb_datarrr�_get_jinja_error_slug�s���r|cCs*z
t|�}dj|�WStyYdSw)zB
    Return an understandable message from jinja error output
    z
{0}({1}):
{3}N)r|�formatry)r{�linerrr�_get_jinja_error_messages�rcCs$zt|�dWStyYdSw)rtr(N)r|ryrzrrr�_get_jinja_error_lines�r�cCs&|si}d}t|�}t|�}t|�}d}d}d|vr/|ddkr.tj�|d�r.|d}d}n|d�dd	�}|d�|�sLtj�|d�rLd}|d}|r�|r�d
|��d�d
�}t	j
j�|��}	t	j
j
�|	���}
Wd�n1suwY|t	j
j
j|
|dd�7}nd
|�d
�}d}||fS)
z�
    Return the error line and error message output from
    a stacktrace.
    If we are in a macro, also output inside the message the
    exact location of the error in the macro
    r,FNr;rz	<unknown>Tr&r'rHz    <======================)Zmarker)r|r�rrMrN�existsr0r4rar?rWrX�fopenr^r_rSZget_context)�tracerj�outrYr~�msgZadd_logZ
template_pathZfilenZfp_Ztemplate_contentsrrr�_get_jinja_errors:��

�r�c
s�|d}|d}d}d}|rt|t�s|�t�}|�tj�r"tj}n|�d�r)d}�z�|s9|r8t�tj	�
|��}ntjj
j|||�dd�|�dt���d�}g|d	��ttjd
�r`�d�d�ttjd
�rm�d�d�ttjd�rz�d�d��d�tjj
j�|�di�}|�di�}t|t�r�|ni}t|t�r�|ni}|�dd�r�t�d�t�d�d|d<d|d<|�dd�r�t�d�t�d�d|d<d|d<�fdd�}	d|vr�|ddkr�|	|d�n|	|d�|�d d�r�tjjd7i���}
ntjjd7d!tji���}
|
j�d"�}|
j�t j!�|
j�t"j#�tjj
j$t%d#�k�r,||
jd"<|
j&�t'j(�t)|
j&d$<tjj
j*|
j&d%<tjj+j,|
jd&<i}|�-�D]E\}
}t|t��skt|t.��re|��||
<n|||
<�qNztjj/j0|td'�||
<W�qNt1�y�t�d(t�tjj+�|�||
<Y�qNw|
j&�|�z|
�2|�}|j3d7i|��}Wn�tj4j5�y�}z!t6�7t8�9�d)�}t:||d*�\}}|�s�d}t;d+|�|��||��d}~wtj4j<tj4j=tj4j>f�y}z!t6�7t8�9�d)�}t:||d*�\}}|�sd}t;d,|�|��||��d}~wt?t@f�y=}z t6�7t8�9�d)�}t:||d*�\}}|�s/d}t;d-�A||�||��d}~wtB�y�}zSt6�C�}t6�7t8�9�d)�}t:||d*�\}}|�s`d}n|d|��7}t�d.�tjd/dd0�t�d1|�t�d2|�t�d3|�t�d4|�t;d5|�|��|||d6��d}~wwW|�r�t|tjj
j��r�|�D�n|�r�t|tjj
j��r�|�D�www|�r�||7}|S)8aU
    Render a Jinja template.

    :param str tmplstr: A string containing the source to be rendered.

    :param dict context: Any additional context data used by the renderer.

    :param str tmplpath: Base path from which ``tmplstr`` may load additional
        template files.

    :returns str: The string rendered by the template.
    r@rANFrH�_pillar_rendZ
fileclient)�pillar_rendZ_file_client)�
extensions�loaderZwith_r�zjinja2.ext.with_Zdoz
jinja2.ext.doZloopcontrolszjinja2.ext.loopcontrols�	jinja_envZ
jinja_sls_envZjinja_trim_blockszJinja2 trim_blocks is enabledzzjinja_trim_blocks is deprecated and will be removed in a future release, please use jinja_env and/or jinja_sls_env insteadTZtrim_blocksZjinja_lstrip_blockszJinja2 lstrip_blocks is enabledz|jinja_lstrip_blocks is deprecated and will be removed in a future release, please use jinja_env and/or jinja_sls_env insteadZ
lstrip_blockscsT|��D]#\}}|��}ttj|���r!t�d|||�|�|<qt�d|�qdS)Nz)Jinja2 environment %s was set to %s by %sz'Jinja2 environment %s is not recognized)	�items�lower�hasattr�jinja2�defaults�upperr6�debugr7)r@Zoptname�k�v�Zenv_argsrr�opt_jinja_env_helper�s�
�z/render_jinja_tmpl.<locals>.opt_jinja_env_helperr;r,Zallow_undefinedZ	undefined�indentz2.11Zodict�show_full_context�listrFzDFailed to decode using default encoding (%s), trying system encodingru)rjzJinja variable zJinja syntax error: z5Problem running salt function in Jinja template: {}{}zJinja Errorz
Exception:)�exc_infozOut: %szLine: %szTmplStr: %szTraceStr: %sz
Jinja error: )r�r)ErLr1�decoderRr4rMr`r�ZFileSystemLoaderrN�dirnamer?rW�jinjaZSaltCacheLoader�getr�valuer��ext�appendZSerializerExtensionr9r6r�r7ZsandboxZSandboxedEnvironmentZStrictUndefined�filtersZtestsr8rZsalt_jinja_testsr	Zsalt_jinja_filtersZ
JINJA_VERSIONr
�globalsr
Zsalt_jinja_globalsrr�rEZis_listr�rr^r_rTZfrom_string�render�
exceptionsZUndefinedErrorrd�
extract_tb�sysr�r�rZTemplateRuntimeErrorZTemplateSyntaxErrorZ
SecurityErrorrrr}rcre�destroy)rlrjr:r@rAr�roZ
opt_jinja_envZopt_jinja_sls_envr�r�Z
indent_filterZdecoded_context�keyr�r=rnrmr�r~r�Ztracestrrr�r�render_jinja_tmplJs*


�
�
�
�
�

��

���
������
����0��
�r�c		Csddl}ddlm}ddlm}|d}d}|s+|r*ddlm}|tj�	|�gd�}n
||d||�
d	d
�d�}z:z)||dd
|vrI|d
�dd�nd|d�jdi|��WW|rat
||�rb|��SSStyrt|j������w|rt
||�r�|��www)aT
    Render a Mako template.

    :param str tmplstr: A string containing the source to be rendered.

    :param dict context: Any additional context data used by the renderer.

    :param str tmplpath: Base path from which ``tmplstr`` may load additional
        template files.

    :returns str: The string rendered by the template.
    rN��Template)�SaltMakoTemplateLookuprA)�TemplateLookup)�directoriesr@r�F)r�Tr;r&r')Zstrict_undefinedZuri�lookupr)Zmako.exceptionsZ
mako.templater�Zsalt.utils.makor�Zmako.lookupr�rMrNr�r�r0r�rLr�rcrr�Ztext_error_template)	rlrjr:�makor�r�rAr�r�rrr�render_mako_tmplsB
�����	
���
�r�cCs ddlm}||�jdi|��S)a
    Render a Wempy template.

    :param str tmplstr: A string containing the source to be rendered.

    :param dict context: Any additional context data used by the renderer.

    :param str tmplpath: Unused.

    :returns str: The string rendered by the template.
    r)�TemplateParserNr)Zwemplate.wemplater�r�)rlrjr:r�rrr�render_wempy_tmpl<sr�cCsz|�dd�}|dks|dkrddlm}||�}n|dkr(ddlm}||�}n
dd	lm}||�}|jdi|���|�S)a�
    Render a Genshi template. A method should be passed in as part of the
    context. If no method is passed in, xml is assumed. Valid methods are:

    .. code-block:

        - xml
        - xhtml
        - html
        - text
        - newtext
        - oldtext

    Note that the ``text`` method will call ``NewTextTemplate``. If ``oldtext``
    is desired, it must be called explicitly
    �methodZxml�textZnewtextr)�NewTextTemplateZoldtext)�OldTextTemplate)�MarkupTemplateNr)r�Zgenshi.templater�r�r�Zgenerater�)rlrjr:r�r�Ztmplr�r�rrr�render_genshi_tmplMs

r�cCsjddlm}|�|�}||gd�}t|t�rt|�}nt|t�r%t|�}n	td�t|����t	j
j�|�S)z$
    Render a Cheetah template.
    rr�)Z
namespacesz>Unknown type {!s} for Cheetah template while trying to render.)
ZCheetah.Templater��compilerLr1�bytesrr}�typer?rWrEr�)rlrjr:r�ZtclassrE�resrrr�render_cheetah_tmplos




��r�FcKs|tj�|�siStj�|�}|�d�d}tj�||�}tjj	|||d�}|dur,t
��tj�|�}|j�
|�|tj|<d|vrdd|vrdt|d|d�gd�}|D]}	d|	�d�}
t||
||	�qS|D]
}t||||�qfz:|��}|r~d	|d
�WStjj��}
tjj�|
d��}|�tjj�|��Wd�n1s�wYd	|
d
�WSty�t��}d|d
�YSw)
z�
    Render a template from a python source file

    Returns::

        {'result': bool,
         'data': <Error data or rendered file path>}
    r&r)r�NZ__env__rA)r?ZgrainsZpillarr@�__TrCzw+F)rMrN�isfile�basename�split�	importlib�	machinery�SourceFileLoader�util�spec_from_file_location�ImportError�module_from_specr��exec_moduler��modules�setattr�runr?rWrXZmkstempr�rgr^rircrdre)Zsfn�string�kwargsZ
base_fnamerr��spec�mod�builtinsZbuiltin�arg�kwargrEZtgt�targetZtrbrrr�py�s@	
��r�)r�r�r�ZwempyZgenshiZcheetahr)F)Jr#rPZimportlib.machineryr��importlib.utilrZrMr�rfrd�pathlibrr�Z
jinja2.extZjinja2.sandboxZsalt.modules.matchr?Zsalt.utils.dataZsalt.utils.dateutilsZsalt.utils.filesZsalt.utils.hashutilsZsalt.utils.httpZsalt.utils.jinjaZsalt.utils.networkZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.yamlencodingrZsaltpathZsalt.exceptionsrrrZsalt.loader.contextrZsalt.loader.dunderrZsalt.utils.decorators.jinjar	r
rZsalt.utils.odictrZsalt.utils.versionsr
�	getLoggerr r6rNrOZTEMPLATE_DIRNAMErR�
getencoderZSLS_ENCODERrr$r>rsr|rr�r�r�r�r�r�r�r�ZJINJAZMAKOZWEMPYZGENSHIZCHEETAHZTEMPLATE_REGISTRYrrrr�<module>s|

=`

.
G
,

"
/
�