Current File : //usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/make_mime.cpython-312.pyc
�

ӇgZ����dZddlZddlZddlZddlmZddlmZddlm	Z	dZ
eje�Z
dZd�Zd	�Zdd
�Zdd�Zd�Zd
�Zedk(rej*e��yy)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||tj��}|jdd|z�|j
�j�}	|	t�vrd|	�d|dz�d�}
|j|
�|j|���t�}|D]}
|j|
��||fS)NzContent-Dispositionzattachment; 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_messagers����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��	|jdd�\}}t|d�||j�fS#t$r}t	j
|d|z�|�d}~wwxYw)z@Return file content type by reading the first line of the input.�:r�rzInvalid value for %rN)�split�open�strip�
ValueError�argparse�
ArgumentError)�textrr�es    r�file_content_typer,.sj���!%���C��!3���,��X�s�#�X�|�/A�/A�/C�D�D�����$�$��(�D�1�
��	���s�14�	A�A�Ac
���|stj�}t|_t|_|j
dddtdgdd��|j
dd	d
dd�
�|j
ddd
dd�
�|S)aBuild 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--attachrrz<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.)r0r1r3z-fz--forcez$Ignore unknown content-type warnings)r(�ArgumentParser�__doc__�description�EPILOG�epilog�add_argumentr,)�parsers r�
get_parserr<9s�����(�(�*�� �F���F�M�
�����
�
���'�
B��	��������
5����������
3����Mr c	��ttj�D�cgc]}|r|jdd�n|��c}�Scc}w)z�Return a list of cloud-init supported content types.  Optionally
    strip out the leading 'text/' of the type if strip_prefix=True.
    ztext/�)�sortedr�values�replace)�strip_prefix�ctypes  rrrasI���-�3�3�5�	
��+7�E�M�M�'�2�&�E�A�	
����	
s�Ac��|jr%tdjtd����yt	|j
�\}}|rh|jrdnd}|D]'}tjj|�d|�d���)tjjd�|jsy	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)rBr�WARNING�ERRORz: z-Invalid content-types, override with --force
r)
�
list_types�print�joinrrr�forcer
�stderr�write)�name�argsrr�level�errors      r�handle_argsrRms������
�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�}tt|�S�N)r<�
parse_argsrR�NAME)rOs r�mainrW�s���<�"�"�$�D��t�T�"�"r �__main__rT)F)r6r(�loggingr
�email.mime.multipartr�email.mime.textr�cloudinit.handlersrrV�	getLogger�__name__�LOGr8rr,r<rrRrW�exit�r r�<module>rbs{��
7���
�.�$�2����g����!��-��&�.�%�P	�
�2#�
�z���C�H�H�T�V��r