oB]c@sddlZddlZyddlmZeZWneefk rQe ZnXy:ddl m Z ddl mZ ddl mZeZWn9eefk rddlmZeZ e ZeZnXddlmZddlmZddlmZejeZejd ejZejd Z d Z!e d efd YZ"dZ#dZ$dZ%ddZ&ddZ'dZ(dS(iN(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 eZdZdZdZRS(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__R R(((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyR-s csfd}tj||S(sThis 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|dkrHtdntj|jd}}x`t|dkr|j}t|t st d|t j ||fn||}qiW|j}t|t s t d||t j |fnt ||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 RuntimeErrort collectionstdequetsplittlentpopleftt 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}|jddkrB|jdd\}}n |}d}tj|}|strtjdd||fSd t|fSn|jdj j }|dkrt d |n|d krt rtj d d t|fS|d krt rd ||fS|dkrFt rFtj d d t|fS|dkretred||fSd t|fSdS(NcSst|d|gjS(Nt searchList(t CTemplatetrespond(R-R)((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytcheetah_renderdscSs>|jdrdnd}t|dtdtj||S(Ns R t undefinedt trim_blocks(tendswitht JTemplateRtTruetrender(R-R)tadd((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyt jinja_rendergs s iiR 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|dtjd\}}}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_files  *icCs)t||}tj||d|dS(Ntmode(RSRt write_file(RQtoutfnR)RTtcontents((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pytrender_to_filescCs)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_filescCs1|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.pyRYs ()RtretCheetah.TemplateRR0R7R@t ImportErrortAttributeErrorRPtjinja2.runtimeRtjinja2R6Rt JUndefinedRFtcloudinit.helpersRtobjectt cloudinitRtloggingRR"Rt getLoggerRRAtcompiletIR?R+RRR.RMRSRXRZRY(((s7/usr/lib/python2.7/site-packages/cloudinit/templater.pyt s>       & -