Current Dir: /snap/core22/2437/usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/
[FILE] hotplug_hook.cpython-310.pyc [ edit | delete | rename ]
[FILE] logs.cpython-310.pyc [ edit | delete | rename ]
[FILE] make_mime.cpython-310.pyc [ edit | delete | rename ]
[FILE] net_convert.cpython-310.pyc [ edit | delete | rename ]
[FILE] parser.cpython-310.pyc [ edit | delete | rename ]
[FILE] render.cpython-310.pyc [ edit | delete | rename ]
[FILE] __init__.cpython-310.pyc [ edit | delete | rename ]
Viewing: /snap/core22/2437/usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/make_mime.cpython-310.pyc
o
�t�h � @ s� d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z m
Z
ddlmZ dZ
e�e�ZdZd d
� Zdefdd
�Z dde
ej dejfdd�Zddede e fdd�Zdedejdefdd�Zdd� Zedkrse�e� � dS dS )z0Generate multi-part mime messages for user-data.� N)�
MIMEMultipart)�MIMEText)�List�Optional)�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 �textc
C sR z| � dd�\}}t|d�||�� fW S ty( } z t�dd| �|�d}~ww )z@Return file content type by reading the first line of the input.�:r �rNzInvalid value for %r)�split�open�strip�
ValueError�argparse�
ArgumentError)r! r r �er r r �file_content_type/ s ����r+ �parser�returnc
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.)r0 r1 r3 z-fz--forcez$Ignore unknown content-type warnings)r( �ArgumentParser�__doc__�description�EPILOG�epilog�add_argumentr+ )r, r r r �
get_parser: s:
�
��r; F�strip_prefixc 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�r<