+
    i                       a  R t.0 t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	 ^ RI
Ht ^ RIHtHt ^ RIHt ^ RIHt ^ RIHtHtHtHt ^ R	IHtHt ] ^ k  ^ R
IHt ^ RIHt ]PF                  ! ]$4      t% ! R R]!4      t& ! R R]!4      t' ! R R]PP                  4      t)RR lt*RR lt+R R lt,RR lt-R#   ]  d    ]!t]PD                  ! R4      t Lqi ; i)    N)EACCES)OptionalType)handlers)b64d
json_dumpsPaths)
PER_ALWAYS)MISSING_JINJA_PREFIXJinjaSyntaxParsingExceptiondetect_templaterender_string)	load_jsonload_text_file)UndefinedError)operator_rez[-.]c                       ] tR t^"tRtR# )JinjaLoadError N__name__
__module____qualname____firstlineno____static_attributes__r       C/usr/lib/python3/dist-packages/cloudinit/handlers/jinja_template.pyr   r   "       r   r   c                       ] tR t^&tRtR# )NotJinjaErrorr   Nr   r   r   r   r!   r!   &   r   r   r!   c                   >   a  ] tR t^*t o R.tV 3R lR ltR tRtV tR# )JinjaTemplatePartHandlerz## template: jinjac                    < V ^8  d   QhRS[ /# )   pathsr	   )format__classdict__s   "r   __annotate__%JinjaTemplatePartHandler.__annotate__.   s     3 3e 3r   c                    \         P                  P                  V \        ^R7       Wn        / V n        VP                  R. 4       F(  pVP                  4        F  pW0P
                  V&   K  	  K*  	  R# )   )versionsub_handlersN)r   Handler__init__r   r&   r.   get
list_types)selfr&   _kwargshandlerctypes   &&,  r   r0   !JinjaTemplatePartHandler.__init__.   s`    !!$
A!>
{{>26G ++-+2!!%( . 7r   c                F   V\         P                  9   d   R # V P                  P                  R4      p \	        WCV4      pT'       g   R # \         P                  ! T4      p
T P                  P                  T
4      pT'       g   \        P                  RTT
4       R # TP                  ^8X  d   TP                  YY8YV4       R # TP                  ^8X  d   TP                  YY8T4       R # R #   \
         d,   p	\        P                  RT\        T	4      4        R p	?	R # R p	?	ii ; i)Ninstance_data_sensitivez=Ignoring jinja template for %s. Failed to render template. %szPIgnoring jinja template for %s. Could not find supported sub-handler for type %s)r   CONTENT_SIGNALSr&   get_runpathrender_jinja_payload_from_filer   LOGwarningstrtype_from_starts_withr.   r1   handler_versionhandle_part)r3   datar6   filenamepayload	frequencyheadersjinja_json_filerendered_payloadesubtypesub_handlers   &&&&&&&     r   rB   $JinjaTemplatePartHandler.handle_part6   s
   H,,,**001JK	=?   001AB''++G4KK+	 &&!+##X ((A-##X .3 + 	KK0A	 	s   C* *D 5 DD )r&   r.   N)	r   r   r   r   prefixesr0   rB   r   __classdictcell__)r(   s   @r   r#   r#   *   s!     $%H3 3$ $r   r#   c                   \        V 4      ^ ,          R8w  d   \        R4      h/ pRp\        P                  P	                  V4      '       g   \        RV,          4      h \        \        V4      4      p\        YYC4      pT'       g   R# T#   \         dN   pRp\        T\        \        34      '       d   TP                  \        8X  d
   RT,          p\        T4      ThRp?ii ; i)a#  Render a jinja template sourcing variables from jinja_vars_path.

@param payload: String of jinja template content. Should begin with
    ## template: jinja\n.
@param payload_fn: String representing the filename from which the payload
    was read used in error reporting. Generally in part-handling this is
    'part-##'.
@param instance_data_file: A path to a json file containing variables that
    will be used as jinja template variables.

@return: A string of jinja-rendered content with the jinja header removed.
    Returns None on error.
jinjazPayload is not a jinja templateNzFCannot render jinja template vars. Instance data not yet present at %sz"Loading Jinja instance data failedzGCannot render jinja template vars. No read permission on '%s'. Try sudo)r   r!   ospathexistsr   r   r   	Exception
isinstanceIOErrorOSErrorerrnor   render_jinja_payload)rE   
payload_fninstance_data_filedebuginstance_datarI   rJ   msgs   &&&&    r   r<   r<   ]   s      w"g-=>>M77>>,--12
 	

)!.1C"DE ,]   )2a'7+,,ww& &(:;  S!q()s   B C#ACC#c                 $   \        VVP                  R . 4      RR7      pV'       d    \        P                  R\	        V4      4        \        W4      p\        P                  ! R\        ,          T4       Uu. uF   pRTP                  \        R4      ,          NK"  	  ppT'       d'   \        P                  R	TR
P                  T4      4       T#   \        \        3 d,   p\        P                  RT\        T4      4        Rp?R# Rp?ii ; iu upi )zbase64-encoded-keysT)decode_pathsinclude_key_aliaseszConverted jinja variables
%sz"Ignoring jinja template for %s: %sNz%s[^\s]+z'%s' z:Could not render jinja template variables in file '%s': %sz, )convert_jinja_instance_datar1   r=   r]   r   r   	TypeErrorJUndefinedErrorr>   r?   refindallr   replacejoin)	rE   r[   r^   r]   instance_jinja_varsrI   rJ   varwarningss	   &&&&     r   rZ   rZ      s    5"&&'<bA 
 		+Z8K-L	
(F ::..0@

C 	12666
   HIIh	

  ' 8*c!fMs   C 6&DD
 DD
c                F    V ^8  d   QhR\         R\        \         ,          /# )r%   	orig_namereturn)r?   r   )r'   s   "r   r)   r)      s        r   c                N    \         P                  ! \        RV 4      pW8w  d   V# R# )ac  Return a jinja variable alias, replacing any operators with underscores.

Provide underscore-delimited key aliases to simplify dot-notation
attribute references for keys which contain operators "." or "-".
This provides for simpler short-hand jinja attribute notation
allowing one to avoid quoting keys which contain operators.
{{ ds.v1_0.config.user_network_config }} instead of
{{ ds['v1.0'].config["user.network-config"] }}.

:param orig_name: String representing a jinja variable name to scrub/alias.

:return: A string with any jinja operators replaced if needed. Otherwise,
    none if no alias required.
_N)rg   subr   )ro   
alias_names   & r   get_jinja_variable_aliasru      s%     S)4Jr   c           	     n   / pV Uu. uF  qfP                  RR4      NK  	  pp\        V P                  4       4       F  w  rxV'       d   RP                  WV4      MTp	W9   d   \	        V4      p\        V\        4      '       dh   \        VV	VVVR7      WW&   \        P                  ! RV4      '       d8   WW,          P                  4        F  w  r\        P                  ! V4      WZ&   K  	  MWV&   V'       g   K  \        V4      pV'       g   K  \        P                  ! WW,          4      W\&   K  	  V# u upi )zProcess instance-data.json dict for use in jinja templates.

Replace hyphens with underscores for jinja templates and decode any
base64_encoded_keys.
-rr   z	{0}{1}{2})sepra   rb   zv\d+$)ri   sorteditemsr'   r   rV   dictrd   rg   matchcopydeepcopyru   )rC   prefixrx   ra   rb   resultrS   keyvaluekey_pathsubkeysubvaluert   s   &&&&&        r   rd   rd      s    F7CD|tLLc*|LDTZZ\*
;A;%%f37s#KEeT""5)$7FK xx#&&(.(9(9(;$F%)]]8%<FN )<  3K1#6Jz%)]]6;%?"+ +, M/ Es   D2c                V    V ^8  d   Qh/ ^ \         9   d   \        \        ,          ;R&   # )r%   rf   )__conditional_annotations__r   rU   )r'   s   "r   r)   r)      s    & !  i  ' r   )F)rc   /r   F)/r   r}   loggingrR   rg   rY   r   typingr   r   	cloudinitr   cloudinit.atomic_helperr   r   cloudinit.helpersr
   cloudinit.settingsr   cloudinit.templaterr   r   r   r   cloudinit.utilr   r   jinja2.exceptionsr   rf   jinja2.lexerr   ImportErrorrU   compile	getLoggerr   r=   r   r!   r/   r#   r<   rZ   ru   rd   r)   )r   s   @r   <module>r      s      	 	  !  4 # )  5  &C( !	Y 		I 	0x// 0f*Z<* G  &O**W%K&s   B8 8CC