Your IP : 216.73.216.31


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

U

�AdM�	@sUddlZddlZddlZddlmZddlmZddlmZ	ddlm
Z
ddlmZee
d<z$ddlmZdd	lmZd
ZeZWn eefk
r�dZeZYnXe�e�Ze�dej�Ze�d
�ZdZGdd�de�Z dd�Z!dd�Z"dd�Z#d dd�Z$d!dd�Z%dd�Z&dd�Z'dS)"�N)�Type)�log)�
type_utils)�util)�
write_file�
JUndefined)�DebugUndefined)�TemplateTFz##\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__2s��zUndefinedJinjaVariable.__sub__N)�__name__�
__module__�__qualname__�__doc__rrrrrrr
,sr
cs�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�}|dkr|�d�}|dkr,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�tuZobj_namer)�match�name�pathZselected_params�key��paramsrr�replacerDs0


��

��zbasic_render.<locals>.replacer)�
BASIC_MATCHER�sub)�contentr/r0rr.r�basic_render<sr4cCs�dd�}|�d�dkr(|�dd�\}}n|}d}t�|�}|sHdt|fS|�d�����}|dkrntd	|��|d
kr�t	s�t
�d�dt|fS|d
kr�t	r�d
||fSdt|fSdS)NcSs0|�d�rdnd}t|tddgd�jf|�|S)N�
rTz
jinja2.ext.do)Z	undefinedZtrim_blocks�
extensions)�endswith�	JTemplater
Zrender)r3r/�addrrr�jinja_rendercs����z%detect_template.<locals>.jinja_renderr5���rr�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_MATCHERr*r4r �lower�strip�
ValueError�JINJA_AVAILABLE�LOGZwarning)�textr:Zident�restZ
type_match�
template_typerrr�detect_templatebs.


���

rHcCs4|si}tt�|��\}}}t�d||�|||�S)Nz+Rendering content of '%s' using renderer %s)rHrZ	load_filerD�debug)�fnr/rG�rendererr3rrr�render_from_file�s
rL�cCst||�}tj|||d�dS)N��mode)rLrr)rJ�outfnr/rO�contentsrrr�render_to_file�s
rRcCst||�}tj|||d�dS)�
Render stringrNN)�
render_stringrr)r3rPr/rOrQrrr�render_string_to_file�s
rUcCs |si}t|�\}}}|||�S)rS)rH)r3r/Z_template_typerKrrrrT�srTc	Csjt|d��}|��}W5QRXd|i}t||���d}t�|�|dkrXtj�|�nt	||dd�dS)N�r�variantr5�-�w)Zomode)
�open�readrT�rstriprZ	load_yaml�sys�stdout�writer)rW�template�outputZfhrQZ
tpl_paramsrrr�render_cloudcfg�s
rb)rM)rM)(r"�rer]�typingrZ	cloudinitrZloggingrr)rZcloudinit.atomic_helperr�__annotations__Zjinja2rZ_DebugUndefinedr	r8rCr�ImportError�AttributeError�objectZ	getLoggerrrD�compile�Ir?r1rr
r4rHrLrRrUrTrbrrrr�<module>s:


&)