HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/cloudinit/handlers/__pycache__/jinja_template.cpython-38.pyc
U

Ӈg��@sXUddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZm
Z
ddlmZddlmZddlmZmZmZmZdd	lmZmZeeed
<zddlmZddlm Z Wn"e!k
r�eZe�"d
�Z YnXe�#e$�Z%Gdd�de�Z&Gdd�de�Z'Gdd�de
j(�Z)d!dd�Z*d"dd�Z+e,ee,d�dd�Z-d#dd �Z.dS)$�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@seZdZdS)�JinjaLoadErrorN��__name__�
__module__�__qualname__�rr�C/usr/lib/python3/dist-packages/cloudinit/handlers/jinja_template.pyr"src@seZdZdS)�
NotJinjaErrorNrrrrrr&src@s(eZdZdgZed�dd�Zdd�ZdS)�JinjaTemplatePartHandlerz## template: jinja)�pathscKsLtjj|tdd�||_i|_|�dg�D]}|��D]}||j|<q6q*dS)N�)�version�sub_handlers)r�Handler�__init__r	rr�getZ
list_types)�selfrZ_kwargsZhandler�ctyperrrr!.sz!JinjaTemplatePartHandler.__init__c
Cs�|tjkrdS|j�d�}zt|||�}Wn:tk
rd}	zt�d|t|	��WY�dSd}	~	XYnX|sndSt�	|�}
|j
�|
�}|s�t�d||
�dS|jdkr�|�
||||||�n|jdkr�|�
|||||�dS)NZinstance_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�)rZCONTENT_SIGNALSrZget_runpath�render_jinja_payload_from_filer�LOG�warning�strZtype_from_starts_withrr"Zhandler_version�handle_part)r#�datar$�filename�payloadZ	frequencyZheadersZjinja_json_file�rendered_payload�eZsubtypeZsub_handlerrrrr*6sX
��
�
�
�z$JinjaTemplatePartHandler.handle_partN)rrr�prefixesrr!r*rrrrr*srFc
Cs�t|�ddkrtd��i}d}tj�|�s8td|��ztt|��}WnPtk
r�}z2d}t	|t
tf�r~|jt
kr~d|}t|�|�W5d}~XYnXt||||�}|s�dS|S)aKRender a jinja template sourcing variables from jinja_vars_path.

    @param payload: String of jinja template content. Should begin with
        ## template: jinja\n.
    @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.
    rZjinjazPayload 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_fnZinstance_data_file�debug�
instance_datar.r/�msgrrrr&]s<��
���r&c
Cs�t||�dg�dd�}|r*t�dt|��zt||�}Wn>ttfk
rv}zt�d|t	|��WY�dSd}~XYnXdd�t
�dt|�D�}|r�t�d	|d
�
|��|S)Nzbase64-encoded-keysT)�decode_paths�include_key_aliaseszConverted jinja variables
%sz"Ignoring jinja template for %s: %scSsg|]}d|�td��qS)z'%s'�)�replacer
)�.0�varrrr�
<listcomp>�s�z(render_jinja_payload.<locals>.<listcomp>z%s[^\s]+z:Could not render jinja template variables in file '%s': %sz, )�convert_jinja_instance_datar"r'r;rr
�	TypeErrorrr(r)�re�findallr
�join)r-r:r<r;Zinstance_jinja_varsr.r/�warningsrrrr9�s8
�����r9)�	orig_name�returncCst�td|�}||kr|SdS)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)rG�subr)rK�
alias_namerrr�get_jinja_variable_alias�srPr@�/rcCs�i}dd�|D�}t|���D]�\}}|r8d�|||�n|}||krLt|�}t|t�r�t|||||d�||<t�d|�r�||��D]\}	}
t	�
|
�||	<q�n|||<|rt|�}|rt	�
||�||<q|S)z�Process instance-data.json dict for use in jinja templates.

    Replace hyphens with underscores for jinja templates and decode any
    base64_encoded_keys.
    cSsg|]}|�dd��qS)�-rM)rA)rBr2rrrrD�sz/convert_jinja_instance_data.<locals>.<listcomp>z	{0}{1}{2})�sepr>r?zv\d+$)�sorted�items�formatrr5�dictrErG�match�copy�deepcopyrP)r+�prefixrSr>r?�result�key�valueZkey_pathZsubkeyZsubvaluerOrrrrE�s.
�
rE)F)F)r@rQrF)/rYZloggingr1rGr8r�typingrrZ	cloudinitrZcloudinit.atomic_helperrrZcloudinit.helpersrZcloudinit.settingsr	Zcloudinit.templaterr
rrr
Zcloudinit.utilrrr4�__annotations__Zjinja2.exceptionsrrZjinja2.lexerr�ImportError�compileZ	getLoggerrr'rrr rr&r9r)rPrErrrr�<module>s@
4�
-
�