File: //usr/lib/python3/dist-packages/cloudinit/__pycache__/templater.cpython-39.pyc
a
��`� � @ s d dl Z d dlZzd dlmZ dZW n eefy> dZY n0 z d dlmZ d dlm
Z dZW n eefy~ dZe
ZY n0 d dlmZ d dlmZ d dlmZ e�e�Ze�d ej�Ze�d
�ZdZG dd
� 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 e Zd ZdZdd� Zdd� ZdS )�UndefinedJinjaVariablez>Class used to represent any undefined jinja template variable.c C s dt | jf S )Nz%s%s)�MISSING_JINJA_PREFIX�_undefined_name)�self� r �5/usr/lib/python3/dist-packages/cloudinit/templater.py�__str__- s zUndefinedJinjaVariable.__str__c C s( t |��td�}tdj| j|d���d S )N� zhUndefined jinja variable: "{this}-{other}". Jinja tried subtraction. Perhaps you meant "{this}_{other}"?)�this�other)�str�replacer � TypeError�formatr )r
r r r r �__sub__0 s ��zUndefinedJinjaVariable.__sub__N)�__name__�
__module__�__qualname__�__doc__r
r r r r r r * s r c s � 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'.
c s� | � d�}|d u r| � d�}|d u r,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��paramsr r �replacer@ s2
��
��zbasic_render.<locals>.replacer)�
BASIC_MATCHER�sub)�contentr- r. r r, r �basic_render8 s r2 c C s dd� }dd� }| � d�dkr0| �dd�\}}n| }d}t�|�}|sjtr^t�d � d
|| fS dt| fS n�|�d�� � �
� }|dvr�td
| ��|dkr�ts�t�
d� dt|fS |dkr�tr�d||fS |d
kr�ts�t�
d� dt|fS |d
k�r t�r d
||fS dt|fS d S )Nc S s t | |gd��� S )N)Z
searchList)� CTemplateZrespond)r1 r- r r r �cheetah_render` s z'detect_template.<locals>.cheetah_renderc S s0 | � d�rdnd}t| tdd�jf i |��| S )N�
r T)� undefined�trim_blocks)�endswith� JTemplater �render)r1 r- �addr r r �jinja_renderc s �
��z%detect_template.<locals>.jinja_renderr5 ���r r z3Using Cheetah as the renderer for unknown template.�cheetah�basic)�jinjar>