CasperSecurity

Current Path : /lib/python3/dist-packages/cloudinit/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/__pycache__/templater.cpython-310.pyc

o

쑛h��	@s&UddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
ZddlmZddl
mZeed<zdd	lmZdd
lmZdZeZWneefyZdZeZYnwe�e�Zd
ZGdd�de�ZGdd�de�Ze	�d�dd��Z dd�Z!dd�Z"d dd�Z#dd�Z$d!dd�Z%dS)"�N)�Any)�TemplateSyntaxError)�performance)�
type_utils)�util)�
write_file�
JUndefined)�DebugUndefined)�TemplateTFzCI_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.pyr/s�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 Cs�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__rrrrr.s(�������
�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___s��zUndefinedJinjaVariable.__sub__N)r(r)r*�__doc__r$r5rrrrr.Ysr.zRendering basic templatecs�fdd�}t�d||�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�replacerrs2


���

��zbasic_render.<locals>.replacerz)\$\{([A-Za-z0-9_.]+)\}|\$([A-Za-z0-9_.]+))�re�sub)�contentrIrJrrHr�basic_renderis	�rNcCs�dd�}|�d�dkr|�dd�\}}n|}d}t�d|tj�}|s'dt|fS|�d�����}|d	vr:t	d
|��|dkrJt
sJt�d�dt|fS|dkrUt
rUd||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%z##\s*template:(.*)�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=rKrD�IrNr9�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;�loggingrKr��typingr�jinja2r�	cloudinitrrrBr�cloudinit.atomic_helperr�__annotations__r	�_DebugUndefinedr
rUrcr�ImportError�AttributeError�object�	getLoggerr(rdr/rr.�timedrNrkrprurwr�rrrr�<module>s>
�
+
(2

Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY