File: //usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/make_mime.cpython-38.pyc
U
ӇgZ � @ s� d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z dZ
e�e�Z
dZdd � Zd
d� Zddd
�Zddd�Zdd� Zdd� Zedkr�e�e� � 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 ]p\}\}}}|�� }t||t�� �}|�dd| � |�� �� } | t� krvd| |d f }
|� |
� |� |� qt
� }|D ]}
|�|
� q�||fS )NzContent-Dispositionzattachment; filename="%s"z3content type %r for attachment %s may be incorrect!� )� enumerate�readr �sys�getdefaultencodingZ
add_headerZget_content_type�lower�get_content_types�appendr Zattach)�filesZsub_messages�errors�iZfh�filenameZformat_type�contentsZsub_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 s` z&| � dd�\}}t|d�||�� fW S tk
rZ } zt�| d| �|�W 5 d}~X Y nX dS )z@Return file content type by reading the first line of the input.�:r �rzInvalid value for %rN)�split�open�strip�
ValueError�argparseZ
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'