File: //lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/make_mime.cpython-310.pyc
o
x[hZ � @ s� d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z dZ
e�e�Z
dZdd � Zd
d� Zddd
�Zddd�Zdd� Zdd� ZedkrOe�e� � dS dS )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 C s� g }g }t | �D ]8\}\}}}|�� }t||t�� �}|�dd| � |�� �� } | t� vr;d| |d f }
|� |
� |� |� qt
� }|D ]}
|�|
� qF||fS )NzContent-Dispositionzattachment; filename="%s"z3content type %r for attachment %s 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_message� r �?/usr/lib/python3/dist-packages/cloudinit/cmd/devel/make_mime.py�create_mime_message s( �
�
r c
C sR z| � dd�\}}t|d�||�� fW S ty( } z t�| d| �|�d}~ww )z@Return file content type by reading the first line of the input.�:r �rzInvalid value for %rN)�split�open�strip�
ValueError�argparse�
ArgumentError)�textr r �er r r �file_content_type. s ����r) c
C s^ | st �� } t| _t| _| jdddtdg ddd� | jdd d
ddd
� | jddd
ddd
� | 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.)r, r- r/ z-fz--forcez$Ignore unknown content-type warnings)r% �ArgumentParser�__doc__�description�EPILOG�epilog�add_argumentr) )�parserr r r �
get_parser9 s: �
��r8 Fc s t � fdd�t�� D ��S )z�Return a list of cloud-init supported content types. Optionally
strip out the leading 'text/' of the type if strip_prefix=True.
c s g | ]}� r|� d d�n|�qS )ztext/� )�replace)�.0�ctype��strip_prefixr r �
<listcomp>f s ��z%get_content_types.<locals>.<listcomp>)�sortedr �valuesr= r r= r r
a s
��r
c C s� |j rtd�tdd��� dS t|j�\}}|r;|jrdnd}|D ]}tj� |� d|� d�� q!tj� d� |js;d S t|� dS )
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.
�
Tr= r �WARNING�ERRORz: z-Invalid content-types, override with --force
r )
�
list_types�print�joinr
r r �forcer �stderr�write)�name�argsr r �level�errorr r r �handle_argsm s rO c C s t � �� } tt| �S �N)r8 �
parse_argsrO �NAME)rL r r r �main� s
rS �__main__rP )F)r2 r% �loggingr �email.mime.multipartr �email.mime.textr �cloudinit.handlersr rR � getLogger�__name__�LOGr4 r r) r8 r
rO rS �exitr r r r �<module> s(
�
(�