%PDF- %PDF-
Mini Shell

Mini Shell

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

3

�AdM�@sUddlZddlZddlZddlmZddlmZddlmZ	ddlm
Z
ddlmZe
y$ddlmZddlmZd	ZeZ
Wn eefk
r�d
ZeZ
YnXeje�Zejdej�Zejd�Zd
ZGdd�de
�Zdd�Z dd�Z!dd�Z"ddd�Z#d dd�Z$dd�Z%dd�Z&dS)!�N)�Type)�log)�
type_utils)�util)�
write_file)�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|�jtd�}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rr
r
r�__sub__2szUndefinedJinjaVariable.__sub__N)�__name__�
__module__�__qualname__�__doc__rrr
r
r
rr	,sr	cs�fdd�}tj||�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�|jd�}|dkr|jd�}|dkr,td��tj|jd��}�}xBt|�dkr�|j�}t|t�sxt	d|t
j|�|f��||}qBW|j�}t|t�s�t	d||t
j|�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)�paramsr
r�replacerDs(



zbasic_render.<locals>.replacer)�
BASIC_MATCHER�sub)�contentr-r.r
)r-r�basic_render<sr2cCs�dd�}|jd�d
kr(|jdd�\}}n|}d}tj|�}|sHdt|fS|jd�j�j�}|dkrntd|��|dkr�t	r�t
jd	�dt|fS|dkr�t	r�d||fSdt|fSdS)NcSs0|jd�rdnd}t|tddgd�jf|�|S)N�
rTz
jinja2.ext.do)Z	undefinedZtrim_blocks�
extensions)�endswith�	JTemplater	Zrender)r1r-�addr
r
r�jinja_rendercsz%detect_template.<locals>.jinja_renderr3rr�basic�jinjaz.Unknown template rendering type '%s' requestedzcJinja not available as the selected renderer for desired template, reverting to the basic renderer.���)r:r9)�findr#�TYPE_MATCHERr)r2r�lower�strip�
ValueError�JINJA_AVAILABLE�LOGZwarning)�textr8Zident�restZ
type_match�
template_typer
r
r�detect_templatebs(




rFcCs4|si}ttj|��\}}}tjd||�|||�S)Nz+Rendering content of '%s' using renderer %s)rFrZ	load_filerB�debug)�fnr-rE�rendererr1r
r
r�render_from_file�s
rJ�cCst||�}tj|||d�dS)N)�mode)rJrr)rH�outfnr-rL�contentsr
r
r�render_to_file�s
rOcCst||�}tj|||d�dS)z
Render string)rLN)�
render_stringrr)r1rMr-rLrNr
r
r�render_string_to_file�s
rQcCs |si}t|�\}}}|||�S)z
Render string)rF)r1r-Z_template_typerIr
r
rrP�srPcCsjt|d��}|j�}WdQRXd|i}t||�j�d}tj|�|dkrXtjj|�nt	||dd�dS)N�r�variantr3�-�w)Zomode)
�open�readrP�rstriprZ	load_yaml�sys�stdout�writer)rS�template�outputZfhrNZ
tpl_paramsr
r
r�render_cloudcfg�s
r^)rK)rK)'r!�rerYZtypingrZ	cloudinitrZloggingrr(rZcloudinit.atomic_helperrZ
JUndefinedZjinja2rZ_DebugUndefinedrr6rA�ImportError�AttributeError�objectZ	getLoggerrrB�compile�Ir=r/r
r	r2rFrJrOrQrPr^r
r
r
r�<module>s:


&)



Zerion Mini Shell 1.0