
    x[h              
          % S r SSKrSSKrSSKrSSKJr  SSKJrJr  SSK	J
r
  SSKJr  SSKJr  SSKJr  S	rS
rSr\R(                  " \5      rSS/\S/S.r\\S'   S\S\S\
S\SS4
S jrS rSS\S\\   4S jjrS rS r S r!g)z"Write Files: write arbitrary files    N)Optional)
url_helperutil)Cloud)Config)
MetaSchema)PER_INSTANCEi  Fz
text/plaincc_write_filesallwrite_files)iddistros	frequencyactivate_by_schema_keysmetanamecfgcloudargsreturnc                 Z   UR                  S/ 5      nU Vs/ s H(  n[        R                  " US[        5      (       a  M&  UPM*     nnU(       d  [        R                  SU 5        g [        R                  " UR                  5      n[        XUR                  R                  U5        g s  snf )Nr   deferzESkipping module named %s, no/empty 'write_files' key in configuration)getr   get_cfg_option_boolDEFAULT_DEFERLOGdebugfetch_ssl_detailspathsr   distrodefault_owner)r   r   r   r   	file_listffiltered_filesssl_detailss           A/usr/lib/python3/dist-packages/cloudinit/config/cc_write_files.pyhandler'   "   s    r*I A''7MB 	
  
 		;	

 	((5Kell&@&@+Ns   %B( B(c                     U (       d  Sn U R                  5       R                  5       n U S;   a  S/$ U S;   a  SS/$ U S;   a  S/$ U [        :X  a  [        /$ U (       a  [        R	                  SU [        5        [        /$ )N )gzgzipapplication/x-gzip)z	gz+base64zgzip+base64zgz+b64zgzip+b64application/base64)b64base64z%Unknown encoding type %s, assuming %s)lowerstripTEXT_PLAIN_ENCr   warning)encoding_types    r&   canonicalize_extractionr5   4   s    !'')//1M&$%%JJ$&:;;
 ))$%%&3	

     ownerr%   c           
         U(       d  g [        U5       GHJ  u  pEUR                  S5      nU(       d  [        R                  SUS-   U 5        M:  [        R
                  R                  U5      n[        UR                  SS 5      UUR                  SS 5      UR                  SS 5      5      nUc  [        R                  SUS-   U 5        M  [        R                  " UR                  SU5      5      u  p[        UR                  S	5      [        5      n
[        R                  " US
5      (       a  SOSn[        R                  " XgXXS9  [        R                  " XhU	5        GMM     g )Npathz3No path provided to write for entry %s in module %s   sourcecontentencodingz>No content could be loaded for entry %s in module %s; skippingr7   permissionsappendabwb)omodemodeusergroup)	enumerater   r   r3   osr9   abspathread_url_or_decoder   extract_usergroupdecode_permsDEFAULT_PERMSr   
write_filechownbyname)r   filesr7   r%   if_infor9   contentsugpermsrB   s               r&   r   r   M   s,   u%	zz&!KKEA
 wwt$%JJx&JJy$'JJz4(	
 KKA	  ''

7E(BCVZZ6F00BB%!	
 	!$C &r6   c                 n   U c  U$  [        U [        [        45      (       a  [        U 5      $ [        [        U 5      S5      $ ! [        [
        4 ab    / nX4 H=  n UR                  SU-  5        M  ! [         a    UR                  SU-  5         M;  f = f   [        R                  " S/UQ76   Us $ f = f)N   z%oz%rz0Undecodable permissions %s, returning default %s)	
isinstanceintfloatstr	TypeError
ValueErrorr?   r   r3   )permdefaultrepsrs       r&   rK   rK   u   s    |dS%L))t9 s4y!$$z" A&D1H% &D1H%& !
 	FNNs:   %A A B4A1/B41BB4BB43B4c                 t   U c  S OU R                  SS 5      n[        U5      nUc  U(       d  gS nU(       a3   [        R                  " UU R                  SS 5      SSUS9R                  nUb  U(       d  [        U5      n[        X'5      nU$ ! [
         a!    [        R                  " [        SU5        Sn NLf = f)Nurir)   headers   )rd   retriessec_betweenr%   zVFailed to retrieve contents from source "%s"; falling back to data from "contents" keyF)r   boolr   read_file_or_urlrR   	Exceptionr   logexcr   r5   extract_contents)r;   r%   r<   r=   urluse_urlresultextractionss           r&   rI   rI      s    .$fjj&=C3iGwF	  00

9d3' h " 7 .h7!'7M  	KK,	 G	s   2B (B76B7c                     U nU HK  nUS:X  a  [         R                  " USSS9nM!  US:X  a  [        R                  " U5      nM?  U[        :X  d  MK  MM     U$ )Nr,   F)quietdecoder-   )r   decomp_gzipr/   	b64decoder2   )rR   extraction_typesro   ts       r&   rl   rl      sY    F$$%%fE%HF&&%%f-F.   Mr6   )N)"__doc__r/   loggingrG   typingr   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr	   rL   r   r2   	getLogger__name__r   r   __annotations__r[   listr'   r5   dictr   rK   rI   rl    r6   r&   <module>r      s    )   	  & ! # . +! w -	j O O6 O% Ot O O$2%%C %%htn %%P*"J	r6   