File: //snap/core18/current/usr/lib/python3/dist-packages/cloudinit/__pycache__/templater.cpython-36.pyc
3
�AdM � @ s U d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dlm
Z
d dlmZ e
y$d dlmZ d dlmZ d ZeZ
W n eefk
r� d
ZeZ
Y nX eje�Zejdej�Zejd�Zd
ZG dd� 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 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 |�jtd�}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__2 s zUndefinedJinjaVariable.__sub__N)�__name__�
__module__�__qualname__�__doc__r r r
r
r
r r , s r c s � fdd�}t j|| �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� | j d�}|d kr| j d�}|d kr,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 �replacerD s(
zbasic_render.<locals>.replacer)�
BASIC_MATCHER�sub)�contentr- r. r
)r- r �basic_render<