Current File : //lib/python2.7/site-packages/cloudinit/templater.pyo
�
oB�]c@s�ddlZddlZyddlmZeZWneefk
rQe	ZnXy:ddl
mZddlmZ
ddlmZeZWn9eefk
r�ddlmZeZe	ZeZnXddlmZddlmZddlmZeje�Zejd	ej�Zejd
�Z dZ!edefd
��Y�Z"d�Z#d�Z$d�Z%dd�Z&dd�Z'd�Z(dS(i����N(tTemplate(timplements_to_string(tDebugUndefined(tidentity(tlog(t
type_utils(tutils##\s*template:(.*)s)\$\{([A-Za-z0-9_.]+)\}|\$([A-Za-z0-9_.]+)uCI_MISSING_JINJA_VAR/tUndefinedJinjaVariablecBs eZdZd�Zd�ZRS(s>Class used to represent any undefined jinja template variable.cCsdt|jfS(Nu%s%s(tMISSING_JINJA_PREFIXt_undefined_name(tself((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyt__str__1scCs=t|�jtd�}tdjd|jd|���dS(NtshUndefined jinja variable: "{this}-{other}". Jinja tried subtraction. Perhaps you meant "{this}_{other}"?tthistother(tstrtreplaceRt	TypeErrortformatR	(R
R((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyt__sub__4s	(t__name__t
__module__t__doc__RR(((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyR-s	cs�fd�}tj||�S(s�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�}n|dkrHtd��ntj|jd��}�}x`t|�dkr�|j�}t|t	�s�t
d|tj|�|f��n||}qiW|j�}t|t	�s	t
d||tj|�f��nt
||�S(Niis,Match encountered but no valid group presentt.sRCan not traverse into non-dictionary '%s' of type %s while looking for subkey '%s's<Can not extract key '%s' from non-dictionary '%s' of type %s(tgrouptNonetRuntimeErrortcollectionstdequetsplittlentpopleftt
isinstancetdictRttutobj_nameR(tmatchtnametpathtselected_paramstkey(tparams(s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytreplacerDs*(t
BASIC_MATCHERtsub(tcontentR)R*((R)s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytbasic_render<scCsvd�}d�}|jd�dkrB|jdd�\}}n|}d}tj|�}|s�tr�tjd�d||fSd	t|fSn�|jd�j	�j
�}|dkr�td|��n|d
kr�tr�tj
d�d	t|fS|d
krtrd
||fS|dkrFtrFtj
d
�d	t|fS|dkretred||fSd	t|fSdS(NcSst|d|g�j�S(Nt
searchList(t	CTemplatetrespond(R-R)((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytcheetah_renderdscSs>|jd�rdnd}t|dtdt�j|�|S(Ns
Rt	undefinedttrim_blocks(tendswitht	JTemplateRtTruetrender(R-R)tadd((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytjinja_rendergs	s
i����iRs3Using Cheetah as the renderer for unknown template.tcheetahtbasictjinjas.Unknown template rendering type '%s' requestedscJinja not available as the selected renderer for desired template, reverting to the basic renderer.seCheetah not available as the selected renderer for desired template, reverting to the basic renderer.(R=R;R<(tfindRtTYPE_MATCHERR$tCHEETAH_AVAILABLEtLOGtdebugR.Rtlowertstript
ValueErrortJINJA_AVAILABLEtwarning(ttextR2R:tidenttrestt
type_matcht
template_type((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytdetect_templatebs6		








cCs\|si}nttj|dt�jd��\}}}tjd||�|||�S(Ntdecodesutf-8s+Rendering content of '%s' using renderer %s(RMRt	load_filetFalseRNRARB(tfnR)RLtrendererR-((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytrender_from_file�s	*i�cCs)t||�}tj||d|�dS(Ntmode(RSRt
write_file(RQtoutfnR)RTtcontents((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytrender_to_file�scCs)t||�}tj||d|�dS(spRender string (or py2 unicode) to file.
    Warning: py2 str with non-ascii chars will cause UnicodeDecodeError.RTN(t
render_stringRRU(R-RVR)RTRW((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytrender_string_to_file�scCs1|si}nt|�\}}}|||�S(shRender string (or py2 unicode).
    Warning: py2 str with non-ascii chars will cause UnicodeDecodeError.(RM(R-R)t_template_typeRR((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyRY�s	()RtretCheetah.TemplateRR0R7R@tImportErrortAttributeErrorRPtjinja2.runtimeRtjinja2R6Rt
JUndefinedRFtcloudinit.helpersRtobjectt	cloudinitRtloggingRR"Rt	getLoggerRRAtcompiletIR?R+RRR.RMRSRXRZRY(((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyt<module>
s>



	&	-