%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/handlers/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/handlers/__pycache__/jinja_template.cpython-312.pyc

�

�f����UddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZm
Z
ddlmZddlmZddlmZmZmZmZdd	lmZmZeeed
<	ddlmZddlm Z ejFe$�Z%Gd�de�Z&Gd�de�Z'Gd�de
jP�Z)	dd�Z*dd�Z+de,dee,fd�Z-	dd�Z.y#e!$reZejDd
�Z Y�rwxYw)�N)�EACCES)�Optional�Type)�handlers)�b64d�
json_dumps)�Paths)�
PER_ALWAYS)�MISSING_JINJA_PREFIX�JinjaSyntaxParsingException�detect_template�
render_string)�	load_json�load_text_file�JUndefinedError)�UndefinedError)�operator_rez[-.]c��eZdZy)�JinjaLoadErrorN��__name__�
__module__�__qualname__���C/usr/lib/python3/dist-packages/cloudinit/handlers/jinja_template.pyrr"���rrc��eZdZy)�
NotJinjaErrorNrrrrrr&rrrc�$�eZdZdgZdefd�Zd�Zy)�JinjaTemplatePartHandlerz## template: jinja�pathsc���tjj|td��||_i|_|j
dg�D]&}|j�D]}||j
|<��(y)N�)�version�sub_handlers)r�Handler�__init__r
r"r&�get�
list_types)�selfr"�_kwargs�handler�ctypes     rr(z!JinjaTemplatePartHandler.__init__.sn�����!�!�$�
�A�!�>���
�����{�{�>�2�6�	3�G� �+�+�-�
3��+2��!�!�%�(�
3�	3rc��|tjvry|jjd�}	t	|||�}|sytj|�}
|jj|
�}|stjd||
�y|jdk(r|j||||||�y|jdk(r|j|||||�yy#t
$r*}	tjd|t|	��Yd}	~	yd}	~	wwxYw)N�instance_data_sensitivez=Ignoring jinja template for %s. Failed to render template. %szPIgnoring jinja template for %s. Could not find supported sub-handler for type %sr$�)r�CONTENT_SIGNALSr"�get_runpath�render_jinja_payload_from_filer�LOG�warning�str�type_from_starts_withr&r)�handler_version�handle_part)r+�datar.�filename�payload�	frequency�headers�jinja_json_file�rendered_payload�e�subtype�sub_handlers            rr:z$JinjaTemplatePartHandler.handle_part6s���H�,�,�,���*�*�0�0�1J�K��	�=���?� �� ���0�0�1A�B���'�'�+�+�G�4����K�K�+���	
�
��&�&�!�+��#�#��e�X�'7��G�
��
(�
(�A�
-��#�#��e�X�'7��
�.��3+�	��K�K�0���A��	
�
��	�s�
C�	D	� D�D	N)rrr�prefixesr	r(r:rrrr!r!*s��$�%�H�3�e�3�$rr!c��t|�ddk7rtd��i}d}tjj	|�std|z��	t
t|��}t||||�}|sy|S#t$rA}d}t|ttf�r|jtk(rd|z}t|�|�d}~wwxYw)aRRender a jinja template payload sourcing variables from jinja_vars_path.

    @param payload: String of jinja template content. Should begin with
        ## template: jinja
.
    @param payload_fn: String representing the filename from which the payload
        was read used in error reporting. Generally in part-handling this is
        'part-##'.
    @param instance_data_file: A path to a json file containing variables that
        will be used as jinja template variables.

    @return: A string of jinja-rendered content with the jinja header removed.
        Returns None on error.
    r�jinjazPayload is not a jinja templateNzFCannot render jinja template vars. Instance data not yet present at %sz"Loading Jinja instance data failedzGCannot render jinja template vars. No read permission on '%s'. Try sudo)r
r�os�path�existsrrr�	Exception�
isinstance�IOError�OSError�errnor�render_jinja_payload)r=�
payload_fn�instance_data_file�debug�
instance_datarArB�msgs        rr4r4]s��� �w���"�g�-��=�>�>��M���
�7�7�>�>�,�-��
�1�
2�
�	
�
)�!�.�1C�"D�E�
�,���]�E���������)�2���a�'�7�+�,��w�w�&� �&�(:�;���S�!�q�(��)�s�A6�6	C�?<B;�;Cc���t||jdg�d��}|rtjdt	|��	t||�}tjdtz|�D�cgc]}d|jtd�z��}}|r&tjd	|d
j|��|S#ttf$r*}tjd|t|��Yd}~yd}~wwxYwcc}w)Nzbase64-encoded-keysT)�decode_paths�include_key_aliaseszConverted jinja variables
%sz"Ignoring jinja template for %s: %sz%s[^\s]+z'%s'�z:Could not render jinja template variables in file '%s': %sz, )�convert_jinja_instance_datar)r5rSrr�	TypeErrorrr6r7�re�findallr�replace�join)	r=rQrTrS�instance_jinja_varsrArB�var�warningss	         rrPrP�s���5��"�&�&�'<�b�A� ���

��	�	�+�Z�8K�-L�	
��(��2E�F���:�:��.�.�0@�
���	����1�2�6�6��H������H���I�I�h��	
�
���
��'�����8�*�c�!�f�M�����s�B8�, C4�8C1� C,�,C1�	orig_name�returnc�H�tjtd|�}||k7r|Sy)a�Return a jinja variable alias, replacing any operators with underscores.

    Provide underscore-delimited key aliases to simplify dot-notation
    attribute references for keys which contain operators "." or "-".
    This provides for simpler short-hand jinja attribute notation
    allowing one to avoid quoting keys which contain operators.
    {{ ds.v1_0.config.user_network_config }} instead of
    {{ ds['v1.0'].config["user.network-config"] }}.

    :param orig_name: String representing a jinja variable name to scrub/alias.

    :return: A string with any jinja operators replaced if needed. Otherwise,
        none if no alias required.
    �_N)r\�subr)rc�
alias_names  r�get_jinja_variable_aliasri�s'������S�)�4�J��Y����rc��i}|D�cgc]}|jdd���}}t|j��D]�\}}|rdj|||�n|}	|	|vrt	|�}t|t�r]t||	|||��||<tjd|�r9||j�D]\}
}tj|�||
<�n|||<|s��t|�}|s��tj||�||<��|Scc}w)z�Process instance-data.json dict for use in jinja templates.

    Replace hyphens with underscores for jinja templates and decode any
    base64_encoded_keys.
    �-rfz	{0}{1}{2})�seprWrXzv\d+$)
r^�sorted�items�formatrrL�dictrZr\�match�copy�deepcopyri)
r;�prefixrlrWrX�resultrI�key�value�key_path�subkey�subvaluerhs
             rrZrZ�s���F�7C�D�t�D�L�L��c�*�D�L�D��T�Z�Z�\�*�@�
��U�;A�;�%�%�f�c�3�7�s���|�#���K�E��e�T�"�5����)�$7��F�3�K��x�x��#�&�(.�s��(9�(9�(;�=�$�F�H�%)�]�]�8�%<�F�6�N�=� �F�3�K��1�#�6�J��%)�]�]�6�#�;�%?��z�"�+@�,�M��/Es�D	)F)rY�/rF)/rr�loggingrHr\rOr�typingrr�	cloudinitr�cloudinit.atomic_helperrr�cloudinit.helpersr	�cloudinit.settingsr
�cloudinit.templaterrrr
r�cloudinit.utilrrrK�__annotations__�jinja2.exceptionsrr�jinja2.lexerr�ImportError�compile�	getLoggerrr5rrr'r!r4rPr7rirZrrr�<module>r�s�����	�	��!��4�#�)���5��i�� �&�C�(��g����!��	�Y�	�	�I�	�0�x�/�/�0�h49�*�Z�<�����
��,DI� ��G�&��O��"�*�*�W�%�K�&�s�B:�:C�C

Zerion Mini Shell 1.0