HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/__pycache__/templater.cpython-39.pyc
a

��`��	@sddlZddlZzddlmZdZWneefy>dZYn0z ddlmZ	ddlm
ZdZWneefy~dZe
ZYn0ddlmZddlmZddlmZe�e�Ze�d	ej�Ze�d
�ZdZGdd
�d
e�Zdd�Zdd�Zdd�Zddd�Z ddd�Z!dd�Z"dS)�N)�TemplateTF)�DebugUndefined)�log)�
type_utils)�utilz##\s*template:(.*)z)\$\{([A-Za-z0-9_.]+)\}|\$([A-Za-z0-9_.]+)zCI_MISSING_JINJA_VAR/c@s eZdZdZdd�Zdd�ZdS)�UndefinedJinjaVariablez>Class used to represent any undefined jinja template variable.cCsdt|jfS)Nz%s%s)�MISSING_JINJA_PREFIX�_undefined_name)�self�r�5/usr/lib/python3/dist-packages/cloudinit/templater.py�__str__-szUndefinedJinjaVariable.__str__cCs(t|��td�}tdj|j|d���dS)N�zhUndefined jinja variable: "{this}-{other}". Jinja tried subtraction. Perhaps you meant "{this}_{other}"?)�this�other)�str�replacer�	TypeError�formatr	)r
rrrr�__sub__0s��zUndefinedJinjaVariable.__sub__N)�__name__�
__module__�__qualname__�__doc__r
rrrrrr*srcs�fdd�}t�||�S)z�This does simple replacement of bash variable like templates.

    It identifies patterns like ${a} or $a and can also identify patterns like
    ${a.b} or $a.b which will look for a key 'b' in the dictionary rooted
    by key 'a'.
    cs�|�d�}|dur|�d�}|dur,td��t�|�d��}�}t|�dkr�|��}t|t�svt	d|t
�|�|f��||}q@|��}t|t�s�t	d||t
�|�f��t||�S)N��z,Match encountered but no valid group present�.zRCan not traverse into non-dictionary '%s' of type %s while looking for subkey '%s'z<Can not extract key '%s' from non-dictionary '%s' of type %s)
�group�RuntimeError�collections�deque�split�len�popleft�
isinstance�dictr�tu�obj_namer)�match�name�pathZselected_params�key��paramsrr�replacer@s2


��

��zbasic_render.<locals>.replacer)�
BASIC_MATCHER�sub)�contentr-r.rr,r�basic_render8sr2cCsdd�}dd�}|�d�dkr0|�dd�\}}n|}d}t�|�}|sjtr^t�d	�d
||fSdt|fSn�|�d��	��
�}|dvr�td
|��|dkr�ts�t�
d�dt|fS|dkr�tr�d||fS|d
kr�ts�t�
d�dt|fS|d
k�rt�rd
||fSdt|fSdS)NcSst||gd���S)N)Z
searchList)�	CTemplateZrespond)r1r-rrr�cheetah_render`sz'detect_template.<locals>.cheetah_rendercSs0|�d�rdnd}t|tdd�jfi|��|S)N�
rT)�	undefined�trim_blocks)�endswith�	JTemplater�render)r1r-�addrrr�jinja_rendercs�
��z%detect_template.<locals>.jinja_renderr5���rrz3Using Cheetah as the renderer for unknown template.�cheetah�basic)�jinjar>r?z.Unknown template rendering type '%s' requestedr@zcJinja not available as the selected renderer for desired template, reverting to the basic renderer.zeCheetah not available as the selected renderer for desired template, reverting to the basic renderer.)�findr!�TYPE_MATCHERr(�CHEETAH_AVAILABLE�LOG�debugr2r�lower�strip�
ValueError�JINJA_AVAILABLE�warning)�textr4r<�ident�restZ
type_match�
template_typerrr�detect_template^s8


�





rOcCs>|si}ttj|dd��d��\}}}t�d||�|||�S)NF)�decodezutf-8z+Rendering content of '%s' using renderer %s)rOr�	load_filerPrDrE)�fnr-rN�rendererr1rrr�render_from_file�s�
rT�cCst||�}tj|||d�dS)N��mode)rTr�
write_file)rR�outfnr-rW�contentsrrr�render_to_file�s
r[cCst||�}tj|||d�dS)zpRender string (or py2 unicode) to file.
    Warning: py2 str with non-ascii chars will cause UnicodeDecodeError.rVN)�
render_stringrrX)r1rYr-rWrZrrr�render_string_to_file�s
r]cCs |si}t|�\}}}|||�S)zhRender string (or py2 unicode).
    Warning: py2 str with non-ascii chars will cause UnicodeDecodeError.)rO)r1r-Z_template_typerSrrrr\�sr\)rU)rU)#r�reZCheetah.Templaterr3rC�ImportError�AttributeErrorZjinja2r9rZ
JUndefinedrI�object�	cloudinitr�loggingrr&r�	getLoggerrrD�compile�IrBr/rrr2rOrTr[r]r\rrrr�<module>
s6



&-