D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
lib
/
python3.6
/
site-packages
/
cloudinit
/
cmd
/
devel
/
__pycache__
/
Filename :
make_mime.cpython-36.pyc
back
Copy
3 \�meZ � @ s� d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z dZ eje�Z dZdd � Zd d� Zddd �Zddd�Zdd� Zdd� Zedkr�eje� � 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 }x|t | �D ]p\}\}}}|j� }t||tj� �}|jdd| � |j� j� } | t� krxd| |d f } |j | � |j |� qW t � }x|D ]} |j| � q�W ||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.6/make_mime.py�create_mime_message s$ r c C s^ y$| j dd�\}}t|d�||j� fS tk rX } ztj| d| �|�W Y dd}~X 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 j� } 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'