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

�N�gц�@shdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZmZmZddlZddlmZmZmZddlmZdd	lmZdd
lmZddlZ ddl!Z ddl"Z ddl#Z ddl$Z ddl%Z ddl&Z ddl'm(Z(ddl)m*Z*m+Z+m,Z,dd
l-m.Z.ddl/m0Z0zddl1m2Z2Wne3y�ddlm2Z2Ynwe�4e5�Z6ddgZ7e	�8d�Z9e0ej:�Z;Gdd�de�Z<Gdd�de.�Z=e+d�dd��Z>e,d�dRdd��Z?e,d�dd��Z@e*d �d!d"��ZAe*d#�d$d%��ZBe*d&�d'd&��ZCe*d(�dSd*d(��ZDe*d+�dTd,d+��ZEe*d-�d.d-��ZFe*�d/d0��ZGe*d1�dRd2d1��ZHe*d3�dRd4d3��ZIe*d5�dRd6d5��ZJe*d7�d8d9��ZKe*�d:d;��ZLe*d<�d=d>��ZMe*d?�d@dA��ZNe*dB�dCdD��ZOe*dE�dFdE��ZPe*dG�dHdG��ZQe*dI�dJdI��ZRe*dK�dLdK��ZSe*dM�dNdM��ZTzejUZUWn
eV�y�ejWZUYnweUdOdP��ZXGdQd�de�ZYdS)UzK
Jinja loading utils to enable a more powerful backend for jinja templates
�N)�Hashable)�wraps)�minidom)�Element�
SubElement�tostring)�
BaseLoader�TemplateNotFound�nodes)�TemplateModule)�TemplateRuntimeError)�	Extension��
TemplateError)�jinja_filter�jinja_global�
jinja_test)�OrderedDict)�Version)�Markup�SaltCacheLoader�SerializerExtensionz$91633EBF-1C86-5E33-935A-28061F4B480Ec@sZeZdZdZ				ddd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�ZdS)rz�
    A special jinja Template Loader for salt.
    Requested templates are always fetched from the server
    to guarantee that the file is up to date.
    Templates are cached like regular salt states
    and only loaded once per loader instance.
    �base�utf-8FNcCs�||_||_||_||_|jr"||jdvrg|_n|d||_ntj�|dd|�g|_t�	d|j�g|_
||_|du|_dS)NZpillar_rootsZcachedir�fileszJinja search path: %s)
�opts�saltenv�encoding�pillar_rend�
searchpath�os�path�join�log�debug�cached�_file_client�_close_file_client)�selfrrrrr&�r)�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/jinja.py�__init__<szSaltCacheLoader.__init__cCsL|jdust|jd�r|jjd|jdkr#tj�|j|j�|_d|_|jS)zC
        Return a file client. Instantiates on first call.
        NrZ
file_rootsT)r&�hasattrr�saltZ
fileclientZget_file_clientrr'�r(r)r)r*�file_clientTs

��zSaltCacheLoader.file_clientcCs(tjj�|�}|��}|�|dd|j�S)z3
        Cache a file from the salt master
        �T)r-�utils�url�creater/Zget_filer)r(�templateZsaltpathZfclr)r)r*�
cache_filefszSaltCacheLoader.cache_filecCs4||jvr|�|�}|dur|j�|�dSdSdS)z(
        Cache a file only once
        FN)r%r5�append)r(r4�retr)r)r*�check_cachens

�zSaltCacheLoader.check_cachec
	s�|}|�dd�ddvrd}nd}|ra|rd|jvr$t�d|�t|��|jd}tj�d�||f��}|�dd�dd	krHt�d
|�t|��|j�	di��	d�d
kratj�
|�ratj�||�}|�|�|r�|r�tj�
|��dd�}|}|r�|j�	d|�}|}||dkr�dn||�dd�d�}|j�|�||jvs�tj�|�r�|jD]I}	tj�|	|��z7tjj��d��%}
|
���|j�}tj������fdd�}|�|fWd�WS1s�wYWq�ty�Yq�wt|��)a{
        Salt-specific loader to find imported jinja files.

        Jinja imports will be interpreted as originating from the top
        of each of the directories in the searchpath when the template
        name does not begin with './' or '../'.  When a template name
        begins with './' or '../' then the import will be relative to
        the importing file.

        �/�r)�..�.TF�tpldirz<Relative path "%s" cannot be resolved without an environmentr;zCDiscarded template path "%s": attempts to ascend outside of salt://rr/�local�\r0r<)�tplfiler=Ztpldot�rbcs(z	tj����kWStyYdSw�NF)r r!�getmtime�OSErrorr)��filepath�mtimer)r*�uptodate�s
�z,SaltCacheLoader.get_source.<locals>.uptodateN)�split�globalsr#�warningr	r r!�normpathr"�get�isabs�relpathr8�dirname�replace�updater%�existsrr-r1rZfopen�read�decoderrCrD)
r(�environmentr4Z	_templateZis_relative�	base_pathr=r@ZtpldataZspathZifile�contentsrHr)rEr*�
get_sourcewsj�
���
�

�
*��zSaltCacheLoader.get_sourcecCsL|jdurdS|jdurdS|j}d|_z|��WdSty%YdSwrB)r'r&�destroy�AttributeError)r(r/r)r)r*rZ�s

�zSaltCacheLoader.destroycCs|��|S�N)r/r.r)r)r*�	__enter__�szSaltCacheLoader.__enter__cGs|��dSr\)rZ)r(�argsr)r)r*�__exit__�szSaltCacheLoader.__exit__)rrFN)�__name__�
__module__�__qualname__�__doc__r+r/r5r8rYrZr]r_r)r)r)r*r3s
�	Qc@s eZdZdZdd�Zdd�ZdS)�
PrintableDicta@
    Ensures that dict str() and repr() are YAML friendly.

    .. code-block:: python

        mapping = OrderedDict([('a', 'b'), ('c', None)])
        print mapping
        # OrderedDict([('a', 'b'), ('c', None)])

        decorated = PrintableDict(mapping)
        print decorated
        # {'a': 'b', 'c': None}
    cCs\g}|��D]\}}t|t�r|�|�d|���q|�|�d|���qdd�|�dS�Nz: �{z, �})�items�
isinstance�strr6r"�r(�output�key�valuer)r)r*�__str__�s
zPrintableDict.__str__cCs<g}|��D]\}}|�|�d|���qdd�|�dSre)rhr6r"rkr)r)r*�__repr__�szPrintableDict.__repr__N)r`rarbrcrorpr)r)r)r*rd�srd�raisecCst|��r\r)�msgr)r)r*�jinja_raisesrs�matchFcCs>d}|r	|tjO}|r|tjO}t�||�}|�|�rdSdS)z6Returns true if a sequence of chars matches a pattern.rTF)�re�I�M�compilert)�txt�rgx�
ignorecase�	multiline�flag�compiled_rgxr)r)r*�
test_matchs

rZequaltocCs||kS)z%Returns true if two values are equal.r))rn�otherr)r)r*�test_equaltosr��skipcCsdS)z�
    Suppress data output

    .. code-block:: yaml

        {% my_string = "foo" %}

        {{ my_string|skip }}

    will be rendered as empty string,

    r0r)��datar)r)r*�skip_filtersr�ZsequencecCst|ttttf�s|gS|S)a�
    Ensure sequenced data.

    **sequence**

        ensure that parsed data is a sequence

    .. code-block:: jinja

        {% set my_string = "foo" %}
        {% set my_list = ["bar", ] %}
        {% set my_dict = {"baz": "qux"} %}

        {{ my_string|sequence|first }}
        {{ my_list|sequence|first }}
        {{ my_dict|sequence|first }}


    will be rendered as:

    .. code-block:: yaml

        foo
        bar
        baz
    )ri�list�tuple�set�dictr�r)r)r*�ensure_sequence_filter,sr��to_boolcCsb|durdSt|t�r
|St|ttff�r|��dvSt|t�r$|dkSt|t�s/t|�dkSdS)z�
    Returns the logical value.

    .. code-block:: jinja

        {{ 'yes' | to_bool }}

    will be rendered as:

    .. code-block:: text

        True
    NF)Zyes�1�truer)ri�boolrj�lower�intr�len��valr)r)r*r�Ms


�indent�cs�|durtjdtdd�|}d|�d}t|t�r!t���t|�}||7}|r1|��|���}n|��}|�d�}|rL|||��fdd	�|D��7}|rR�|}|S)
z�
    A ported version of the "indent" filter containing a fix for indenting Markup
    objects. If the minion has Jinja version 2.11 or newer, the "indent" filter
    from upstream will be used, and this one will be ignored.
    NzRThe 'indentfirst' argument is renamed to 'first' and will be removed in Jinja 3.0.�)�
stacklevel� �
rc3s �|]}|r
�|n|VqdSr\r))�.0�line�Z	indentionr)r*�	<genexpr>�s�
�zindent.<locals>.<genexpr>)�warnings�warn�DeprecationWarningrirr"�
splitlines�pop)�s�width�firstZblankZindentfirst�newline�rv�linesr)r�r*r�is0�

��tojsoncKsR|�dd�|dur||d<tjjj|fi|���dd��dd��d	d
��dd�S)
z�
    Implementation of tojson filter (only present in Jinja 2.9 and later).
    Unlike the Jinja built-in filter, this allows arbitrary options to be
    passed in to the underlying JSON library.
    �ensure_asciiTNr��<z\u003c�>z\u003e�&z\u0026�'z\u0027)�
setdefaultr-r1�json�dumpsrQ)r�r��optionsr)r)r*r��s��quotecC�
t�|�S)z�
    Wraps a text around quotes.

    .. code-block:: jinja

        {% set my_text = 'my_text' %}
        {{ my_text | quote }}

    will be rendered as:

    .. code-block:: text

        'my_text'
    )�shlexr�)ryr)r)r*r��s
cCr�r\)ru�escape)rnr)r)r*�regex_escape�s
r��regex_searchcC�>d}|r	|tjO}|r|tjO}t�|||�}|sdS|��S)z�
    Searches for a pattern in the text.

    .. code-block:: jinja

        {% set my_text = 'abcd' %}
        {{ my_text | regex_search('^(.*)BC(.*)$', ignorecase=True) }}

    will be rendered as:

    .. code-block:: text

        ('a', 'd')
    rN)rurvrw�search�groups�ryrzr{r|r}�objr)r)r*r���

�regex_matchcCr�)z�
    Searches for a pattern in the text.

    .. code-block:: jinja

        {% set my_text = 'abcd' %}
        {{ my_text | regex_match('^(.*)BC(.*)$', ignorecase=True) }}

    will be rendered as:

    .. code-block:: text

        ('a', 'd')
    rN)rurvrwrtr�r�r)r)r*r��r��
regex_replacecCs8d}|r	|tjO}|r|tjO}t�||�}|�||�S)a 
    Searches for a pattern and replaces with a sequence of characters.

    .. code-block:: jinja

        {% set my_text = 'lets replace spaces' %}
        {{ my_text | regex_replace('\s+', '__') }}

    will be rendered as:

    .. code-block:: text

        lets__replace__spaces
    r)rurvrwrx�sub)ryrzr�r{r|r}r~r)r)r*r��s

�uuidcCstt�ttjj�|���S)z�
    Returns a UUID corresponding to the value passed as argument.

    .. code-block:: jinja

        {{ 'example' | uuid }}

    will be rendered as:

    .. code-block:: text

        f4efeff8-c219-578a-bad7-3dc280612ec8
    )rjr�Zuuid5�GLOBAL_UUIDr-r1�stringutilsZto_strr�r)r)r*�uuid_
sr�cCs>d}t|t�r
t|�}|Sg}|D]}||vr|�|�q|S)z�
    Removes duplicates from a list.

    .. code-block:: jinja

        {% set my_list = ['a', 'b', 'c', 'a', 'b'] -%}
        {{ my_list | unique }}

    will be rendered as:

    .. code-block:: text

        ['a', 'b', 'c']
    N)rirr�r6)�valuesr7rnr)r)r*�unique"s
�
�r��mincC�t|�S)z�
    Returns the min value.

    .. code-block:: jinja

        {% set my_list = [1,2,3,4] -%}
        {{ my_list | min }}

    will be rendered as:

    .. code-block:: text

        1
    )r��r�r)r)r*�lst_min=�r��maxcCr�)z�
    Returns the max value.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | max }}

    will be rendered as:

    .. code-block:: text

        4
    )r�r�r)r)r*�lst_maxPr�r�ZavgcCs&t|t�stt|�t|��St|�S)z�
    Returns the average value of a list.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | avg }}

    will be rendered as:

    .. code-block:: yaml

        2.5
    )rir�float�sumr�)�lstr)r)r*�lst_avgcs
r��unioncCs0t|t�rt|t�rt|�t|�BSt||�S)z�
    Returns the union of two lists.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | union([2, 4, 6]) }}

    will be rendered as:

    .. code-block:: text

        [1, 2, 3, 4, 6]
    �rirr�r��Zlst1�lst2r)r)r*r�xs�	intersectcs:t|t�rt�t�rt|�t��@St�fdd�|D��S)z�
    Returns the intersection of two lists.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | intersect([2, 4, 6]) }}

    will be rendered as:

    .. code-block:: text

        [2, 4]
    csg|]}|�vr|�qSr)r)�r�Zele�r�r)r*�
<listcomp>��zintersect.<locals>.<listcomp>r�r�r)r�r*r����
differencecs:t|t�rt�t�rt|�t��St�fdd�|D��S)z�
    Returns the difference of two lists.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | difference([2, 4, 6]) }}

    will be rendered as:

    .. code-block:: text

        [1, 3, 6]
    csg|]}|�vr|�qSr)r)r�r�r)r*r��r�zdifference.<locals>.<listcomp>r�r�r)r�r*r��r��symmetric_differencecsBt�t�rt�t�rt��t��ASt��fdd�t���D��S)z�
    Returns the symmetric difference of two lists.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | symmetric_difference([2, 4, 6]) }}

    will be rendered as:

    .. code-block:: text

        [1, 3]
    csg|]}|t���vr|�qSr))r�r�r�r)r*r��sz(symmetric_difference.<locals>.<listcomp>)rirr�r�r�r�r)r�r*r��s
��method_callcOst||dd��|i|��S)Nc_sdSr\r))r^�kwargsr)r)r*�<lambda>�szmethod_call.<locals>.<lambda>)�getattr)r�Zf_nameZf_argsZf_kwargsr)r)r*r��scCstjj�dd�|��D��S)NcSsi|]\}}||�qSr)r)�r�rmrnr)r)r*�
<dictcomp>�sz%show_full_context.<locals>.<dictcomp>)r-r1r�Zsimple_types_filterrh)�ctxr)r)r*�show_full_context�s�r�cs�eZdZdZhd�Z�fdd�Zdd�Zd,d	d
�Zd-dd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
hd�Zhd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd.d*d+�Z�ZS)/ra�
    Yaml and Json manipulation.

    **Format filters**

    Allows jsonifying or yamlifying any data structure. For example, this dataset:

    .. code-block:: python

        data = {
            'foo': True,
            'bar': 42,
            'baz': [1, 2, 3],
            'qux': 2.0
        }

    .. code-block:: jinja

        yaml = {{ data|yaml }}
        json = {{ data|json }}
        python = {{ data|python }}
        xml  = {{ {'root_node': data}|xml }}

    will be rendered as::

        yaml = {bar: 42, baz: [1, 2, 3], foo: true, qux: 2.0}
        json = {"baz": [1, 2, 3], "foo": true, "bar": 42, "qux": 2.0}
        python = {'bar': 42, 'baz': [1, 2, 3], 'foo': True, 'qux': 2.0}
        xml = """<<?xml version="1.0" ?>
                 <root_node bar="42" foo="True" qux="2.0">
                  <baz>1</baz>
                  <baz>2</baz>
                  <baz>3</baz>
                 </root_node>"""

    The yaml filter takes an optional flow_style parameter to control the
    default-flow-style parameter of the YAML dumper.

    .. code-block:: jinja

        {{ data|yaml(False) }}

    will be rendered as:

    .. code-block:: yaml

        bar: 42
        baz:
          - 1
          - 2
          - 3
        foo: true
        qux: 2.0

    **Load filters**

    Strings and variables can be deserialized with **load_yaml** and
    **load_json** tags and filters. It allows one to manipulate data directly
    in templates, easily:

    .. code-block:: jinja

        {%- set yaml_src = "{foo: it works}"|load_yaml %}
        {%- set json_src = '{"bar": "for real"}'|load_json %}
        Dude, {{ yaml_src.foo }} {{ json_src.bar }}!

    will be rendered as::

        Dude, it works for real!

    **Load tags**

    Salt implements ``load_yaml`` and ``load_json`` tags. They work like
    the `import tag`_, except that the document is also deserialized.

    Syntaxes are ``{% load_yaml as [VARIABLE] %}[YOUR DATA]{% endload %}``
    and ``{% load_json as [VARIABLE] %}[YOUR DATA]{% endload %}``

    For example:

    .. code-block:: jinja

        {% load_yaml as yaml_src %}
            foo: it works
        {% endload %}
        {% load_json as json_src %}
            {
                "bar": "for real"
            }
        {% endload %}
        Dude, {{ yaml_src.foo }} {{ json_src.bar }}!

    will be rendered as::

        Dude, it works for real!

    **Import tags**

    External files can be imported and made available as a Jinja variable.

    .. code-block:: jinja

        {% import_yaml "myfile.yml" as myfile %}
        {% import_json "defaults.json" as defaults %}
        {% import_text "completeworksofshakespeare.txt" as poems %}

    **Catalog**

    ``import_*`` and ``load_*`` tags will automatically expose their
    target variable to import. This feature makes catalog of data to
    handle.

    for example:

    .. code-block:: jinja

        # doc1.sls
        {% load_yaml as var1 %}
            foo: it works
        {% endload %}
        {% load_yaml as var2 %}
            bar: for real
        {% endload %}

    .. code-block:: jinja

        # doc2.sls
        {% from "doc1.sls" import var1, var2 as local2 %}
        {{ var1.foo }} {{ local2.bar }}

    ** Escape Filters **

    .. versionadded:: 2017.7.0

    Allows escaping of strings so they can be interpreted literally by another
    function.

    For example:

    .. code-block:: jinja

        regex_escape = {{ 'https://example.com?foo=bar%20baz' | regex_escape }}

    will be rendered as::

        regex_escape = https\:\/\/example\.com\?foo\=bar\%20baz

    ** Set Theory Filters **

    .. versionadded:: 2017.7.0

    Performs set math using Jinja filters.

    For example:

    .. code-block:: jinja

        unique = {{ ['foo', 'foo', 'bar'] | unique }}

    will be rendered as::

        unique = ['foo', 'bar']

    ** Salt State Parameter Format Filters **

    .. versionadded:: 3005

    Renders a formatted multi-line YAML string from a Python dictionary. Each
    key/value pair in the dictionary will be added as a single-key dictionary
    to a list that will then be sent to the YAML formatter.

    For example:

    .. code-block:: jinja

        {% set thing_params = {
            "name": "thing",
            "changes": True,
            "warnings": "OMG! Stuff is happening!"
           }
        %}

        thing:
          test.configurable_test_state:
            {{ thing_params | dict_to_sls_yaml_params | indent }}

    will be rendered as::

    .. code-block:: yaml

        thing:
          test.configurable_test_state:
            - name: thing
            - changes: true
            - warnings: OMG! Stuff is happening!

    .. _`import tag`: https://jinja.palletsprojects.com/en/2.11.x/templates/#import
    >�import_text�import_json�	load_json�	load_yaml�profile�import_yaml�	load_textcs�t��|�|jj�|j|j|j|j|j	|j
|j|jt
jt
jt
jt
jt
jtt
jd��|jjdur8|j|j_dS|jj�t���fdd��}||j_dS)N)�yamlr�Zxml�pythonr�r�r��dict_to_sls_yaml_params�combinations�combinations_with_replacement�compress�permutations�product�zip�zip_longestcs�|�|��Sr\��	finalizer�r(r�r�r)r*�wrapper�sz-SerializerExtension.__init__.<locals>.wrapper)�superr+rV�filtersrR�format_yaml�format_json�
format_xml�
format_pythonr�r�r�r��	itertoolsr�r�r�r�r�r�r��finalizer�r)r(rVr���	__class__r�r*r+�s2��zSerializerExtension.__init__cs�fdd���|�S)zA
        Ensure that printed mappings are YAML friendly.
        csTt|ttf�rt�fdd�|��D��St|tttf�r(|��fdd�|D��S|S)Ncsg|]
\}}|�|�f�qSr)r)r���explorer)r*r��szBSerializerExtension.finalizer.<locals>.explore.<locals>.<listcomp>csg|]}�|��qSr)r))r�rnrr)r*r��s)	rir�rrdrhr�r�r�rr�rr)r*r�s�z.SerializerExtension.finalizer.<locals>.explorer)r�r)rr*r��s	zSerializerExtension.finalizerTNcCsHtjjj|||d���}zt|�WSty#ttjj�|��YSw)N)�	sort_keysr�)	r-r1r�r��stripr�UnicodeDecodeErrorr��
to_unicode)r(rnrr�Zjson_txtr)r)r*r��s��
�zSerializerExtension.format_jsoncCsdtjjj||d���}|�d�r|dt|�d�}zt|�WSty1ttjj	�
|��YSw)N)Zdefault_flow_stylez
...r�)r-r1r�Z	safe_dumpr	�endswithr�rr
r�r)r(rn�
flow_styleZyaml_txtr)r)r*r��s��

�zSerializerExtension.format_yamlcs:dd��d��fdd�	�tt�t��|����jdd��S)	a9Render a formatted multi-line XML string from a complex Python
        data structure. Supports tag attributes and nested dicts/lists.

        :param value: Complex data structure representing XML contents
        :returns: Formatted XML string rendered with newlines and indentation
        :rtype: str
        cSsNt|ttf�rt|dt�r|}|Sg}|St|t�r#t|���}|Std��)Nrz1Value is not a dict or list. Cannot render as XML)rir�r�rjr�rhr)rnZxmlvalr)r)r*�normalize_iters	�
���z6SerializerExtension.format_xml.<locals>.normalize_iterNcs�d}|D]Y\}}t|t�r|D]
}�||ff|�qn|dur%t||�}nt|�}t|ttttf�r8t|�|_qt|t	�rGdd�|�
�D�|_dd��|�D�D]\}}�||ff|�qPq|S)NcSs(i|]\}}t|ttf�s|t|��qSr))rir�r�rj)r��attrr�r)r)r*r�s��zHSerializerExtension.format_xml.<locals>.recurse_tree.<locals>.<dictcomp>cSs"g|]
}t|dttf�r|�qS)r:)rir�r�)r��itemr)r)r*r�"s��zHSerializerExtension.format_xml.<locals>.recurse_tree.<locals>.<listcomp>)rir�rrrjr�r�r��textr�rhZattrib)Zxmliter�elementr��tagZattrsrr��r�recurse_treer)r*rs,
�

���z4SerializerExtension.format_xml.<locals>.recurse_treer�)r�r\)rrZparseStringrZtoprettyxml�r(rnr)rr*r�s	���zSerializerExtension.format_xmlcCstt�|����Sr\)r�pprintZpformatr	rr)r)r*r0sz!SerializerExtension.format_pythoncCs�t|t�r	t|�}z
tjj�tjj�|��WStjjj	y`}z;d}z|j
jd}|j
j}|j
}WntyD|t|�7}Yt|��w||�d�7}|tjjj||dd�7}t|��d}~wtymtd|����w)Nz Encountered error loading yaml: r:r�z    <======================)ZmarkerzUnable to load yaml from )rirrjr-r1r�rUr�Z	safe_loadZ	YAMLErrorZproblem_markr��buffer�problemr[r�Zget_contextr)r(rn�excrrr��bufrr)r)r*r�3s.

�
���zSerializerExtension.load_yamlc
CsFt|t�r	t|�}ztjj�|�WSttt	fy"t
d|����w)NzUnable to load json from )rirrjr-r1r��loads�
ValueError�	TypeErrorr[rrr)r)r*r�Ls
�zSerializerExtension.load_jsoncCst|t�r	t|�}|Sr\)rirrjrr)r)r*r�Ts
zSerializerExtension.load_text>r�r�r�>r�r�r�cCs�|jjj|jvr
|�|�S|jjj|jvr$|�||jjj�dd�d�S|jjjdkr0|�|�S|�	d|jjj|jjj
�dS)N�_r:r�zUnknown format )�stream�currentrn�
_load_parsers�
parse_load�_import_parsers�parse_importrI�
parse_profile�fail�lineno�r(�parserr)r)r*�parse]s
�
�zSerializerExtension.parsecCsBt|j�j}|j�d�|��}|jdgdd�}|�||d||�S)N�name:aszname:endprofileT�Zdrop_needlez
profile block)�nextr r(�expectZparse_expression�parse_statements�_parse_profile_block)r(r*r(�label�bodyr)r)r*r&ms
z!SerializerExtension.parse_profilecCsd|��j��S)NZ_salt_profile_)�free_identifier�namer)r)r)r*�_create_profile_idtsz&SerializerExtension._create_profile_idcCs||t��fSr\)�time)r(r2�sourcer)r)r*�_profile_startwsz"SerializerExtension._profile_startcCst�d||t��|�dS)Nz'Time (in seconds) to render %s '%s': %s)r#r�r7)r(r2r8Z
previous_timer)r)r*�_profile_endzs
�z SerializerExtension._profile_endcCs~|�|�}t�t�|d��|�|jdt�|t�|�g��|�d��|���|�g|t�|jdt�|d�d���|�g}|S)N�storer9)Zdyn_argsr:�load)	r6r
�Assign�Name�
set_linenoZcall_methodZListZConstZExprStmt)r(r*r2r8r3r(Z
profile_idr7r)r)r*r1�s2
�����
�����z(SerializerExtension._parse_profile_blockc
Cs�|jjj}t|j�j}||jjvr|�d|��|�|j�d�|�	�}d|�
�j}|jddd�}t
�|gg|��|�t
�|t
�t
�t
�|d��|�ggdd��|�|ggdd��|���|�gS)NzUnable to parse r,r)zname:endloadTr-r<)r r!rnr.r(rVr�r'r/Zparse_assign_targetr4r5r0r
ZMacror?r=�FilterZCallr>)r(r*Zfilter_namer(�targetZ
macro_nameZ
macro_bodyr)r)r*r#�s<
��
��zSerializerExtension.parse_loadcCs||��}|j}|j}|t�t�|d��|�t�t�|d��|�d|��ggdd��|���|�g}|�||j	d|��||�S)Nr;r<Zload_�import_)
r%rAr(r
r=r>r?r@r1r4)r(r*�	converterZimport_noderAr(r3r)r)r*r%�s*��
��z SerializerExtension.parse_importFcCs|jdd�|��D�|d�S)a/
        .. versionadded:: 3005

        Render a formatted multi-line YAML string from a Python dictionary. Each
        key/value pair in the dictionary will be added as a single-key dictionary
        to a list that will then be sent to the YAML formatter.

        :param value: Python dictionary representing Salt state parameters

        :param flow_style: Setting flow_style to False will enforce indentation
                           mode

        :returns: Formatted SLS YAML string rendered with newlines and
                  indentation
        cSsg|]\}}||i�qSr)r))r�rmr�r)r)r*r��r�z?SerializerExtension.dict_to_sls_yaml_params.<locals>.<listcomp>)r
)r�rh)r(rnr
r)r)r*r��s�z+SerializerExtension.dict_to_sls_yaml_params)TN)T)F)r`rarbrc�tagsr+r�r�r�rrr�r�r�r"r$r+r&r6r9r:r1r#r%r��
__classcell__r)r)rr*r�s0H
!

	8 )FF)r�FFNr\)Zrcr�loggingZos.pathr rrur�r7r�r��collections.abcr�	functoolsrZxml.domrZxml.etree.ElementTreerrrZjinja2rr	r
Zjinja2.environmentrZjinja2.exceptionsrZ
jinja2.extr
Zsalt.fileclientr-Zsalt.utils.dataZsalt.utils.filesZsalt.utils.jsonZsalt.utils.stringutilsZsalt.utils.urlZsalt.utils.yamlZsalt.exceptionsrZsalt.utils.decorators.jinjarrrZsalt.utils.odictrZsalt.utils.versionsrZ
markupsafer�ImportError�	getLoggerr`r#�__all__ZUUIDr��__version__Z
JINJA_VERSIONrrdrsrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zpass_contextr[Zcontextfunctionr�rr)r)r)r*�<module>s��


,$



 
)













�