Ë
    x[hZ  ã                   óÒ   — d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 dZ
 ej                  e«      ZdZd„ Zd	„ Zdd
„Zdd„Zd„ Zd„ Zedk(  r ej*                   e«       «       yy)z0Generate multi-part mime messages for user-data.é    N)ÚMIMEMultipart)ÚMIMEText)ÚINCLUSION_TYPES_MAPz	make-mimezUExample: make-mime -a config.yaml:cloud-config -a script.sh:x-shellscript > user-datac                 ó¼  — g }g }t        | «      D ]¥  \  }\  }}}|j                  «       }t        ||t        j                  «       «      }|j                  dd|z  «       |j                  «       j                  «       }	|	t        «       vrd|	›d|dz   ›d�}
|j                  |
«       |j                  |«       Œ§ t        «       }|D ]  }
|j                  |
«       Œ ||fS )NzContent-Dispositionzattachment; filename="%s"zcontent type z for attachment é   z may be incorrect!)Ú	enumerateÚreadr   ÚsysÚgetdefaultencodingÚ
add_headerÚget_content_typeÚlowerÚget_content_typesÚappendr   Úattach)ÚfilesÚsub_messagesÚerrorsÚiÚfhÚfilenameÚformat_typeÚcontentsÚsub_messageÚcontent_typeÚmsgÚcombined_messages               ú?/usr/lib/python3/dist-packages/cloudinit/cmd/devel/make_mime.pyÚcreate_mime_messager      së   € Ø€LØ€FÜ*3°EÓ*:ò )Ñ&ˆÑ&ˆB�˜+Ø—7‘7“9ˆÜ˜x¨´c×6LÑ6LÓ6NÓOˆØ×ÑØ!Ð#>À(Ñ#Kô	
ð #×3Ñ3Ó5×;Ñ;Ó=ˆØÔ0Ó2Ò2âØ�A“ðˆCð �M‰M˜#ÔØ×Ñ˜KÕ(ð)ô %“ÐØò %ˆØ×Ñ Õ$ð%à˜fÐ%Ð%ó    c                 ó¾   — 	 | j                  dd«      \  }}t        |d«      ||j                  «       fS # t        $ r}t	        j
                  | d| z  «      |‚d}~ww xY w)z@Return file content type by reading the first line of the input.ú:r   ÚrzInvalid value for %rN)ÚsplitÚopenÚstripÚ
ValueErrorÚargparseÚArgumentError)Útextr   r   Úes       r   Úfile_content_typer,   .   sj   € ðØ!%§¡¨C°Ó!3Ñˆ�,Ü�X˜sÓ# X¨|×/AÑ/AÓ/CÐDÐDøÜò Ü×$Ñ$ØÐ(¨DÑ1ó
àð	ûðús   ‚14 ´	A½AÁAc           
      óð   — | st        j                  «       } t        | _        t        | _        | j                  dddt        dg dd¬«       | j                  dd	d
dd¬«       | j                  ddd
dd¬«       | S )a  Build or extend and arg parser for make-mime utility.

    @param parser: Optional existing ArgumentParser instance representing the
        subcommand which will be extended to support the args of this utility.

    @returns: ArgumentParser with proper argument configuration.
    z-az--attachr   r   z<file>:<content-type>z3attach the given file as the specified content-type)ÚdestÚtypeÚactionÚdefaultÚmetavarÚhelpz-lz--list-typesÚ
store_trueFz&List support cloud-init content types.)r0   r1   r3   z-fz--forcez$Ignore unknown content-type warnings)r(   ÚArgumentParserÚ__doc__ÚdescriptionÚEPILOGÚepilogÚadd_argumentr,   )Úparsers    r   Ú
get_parserr<   9   sž   € ñ Ü×(Ñ(Ó*ˆä €FÔÜ€F„MØ
×ÑØØØÜØØØ'ØBð ô 	ð ×ÑØØØØØ5ð ô ð ×ÑØØØØØ3ð ô ð €Mr    c           	      óŠ   — t        t        j                  «       D �cg c]  }| r|j                  dd«      n|‘Œ c}«      S c c}w )z‰Return a list of cloud-init supported content types.  Optionally
    strip out the leading 'text/' of the type if strip_prefix=True.
    ztext/Ú )Úsortedr   ÚvaluesÚreplace)Ústrip_prefixÚctypes     r   r   r   a   sI   € ô ô -×3Ñ3Ó5ö	
àñ +7ˆE�M‰M˜' 2Ô&¸EÑAò	
óð ùò	
s   œA c                 ó€  — |j                   r%t        dj                  t        d¬«      «      «       yt	        |j
                  «      \  }}|rh|j                  rdnd}|D ]'  }t        j                  j                  |› d|› d�«       Œ) t        j                  j                  d«       |j                  sy	t        |«       y)
a<  Create a multi-part MIME archive for use as user-data.  Optionally
       print out the list of supported content types of cloud-init.

    Also setup CLI log handlers to report to stderr since this is a development
    utility which should be run by a human on the CLI.

    @return 0 on success, 1 on failure.
    ú
T)rB   r   ÚWARNINGÚERRORz: z-Invalid content-types, override with --force
r   )
Ú
list_typesÚprintÚjoinr   r   r   Úforcer
   ÚstderrÚwrite)ÚnameÚargsr   r   ÚlevelÚerrors         r   Úhandle_argsrR   m   s    € ð ‡‚Üˆd�i‰iÔ)°tÔ<Ó=Ô>Øä2°4·:±:Ó>ÑÐ�fÙØ!ŸZšZ‘	¨WˆØò 	4ˆEÜ�J‰J×Ñ ˜w b¨¨¨rÐ2Õ3ð	4ä�
‰
×ÑÐIÔJØ�zŠzØÜ	Ð
ÔØr    c                  óR   — t        «       j                  «       } t        t        | «      S ©N)r<   Ú
parse_argsrR   ÚNAME)rO   s    r   ÚmainrW   †   s   € Ü‹<×"Ñ"Ó$€DÜ”t˜TÓ"Ð"r    Ú__main__rT   )F)r6   r(   Úloggingr
   Úemail.mime.multipartr   Úemail.mime.textr   Úcloudinit.handlersr   rV   Ú	getLoggerÚ__name__ÚLOGr8   r   r,   r<   r   rR   rW   Úexit© r    r   ú<module>rb      s{   ðñ
 7ã Û Û 
Ý .Ý $å 2à€Ø€g×Ñ˜Ó!€ð-ð ò&ò.ó%óP	òò2#ð
 ˆzÒØ€C‡H�H‰T‹VÕð r    