oB]c@soddlZddlmZddlmZddlmZddlmZddl Z ddl m Z ddl m Z ddlmZmZdd l mZe jeZe jZe jZe jZd Zd d gZd dgZdgZd ZdZdZddddddddgZdZ dgZ!dZ"dZ#de$fdYZ%dZ&ed Z'dS(!iN(tMIMEBase(t MIMEMultipart(tMIMENonMultipart(tMIMEText(thandlers(tlog(tread_file_or_urltUrlError(tutils Content-Types text/plainstext/x-not-multipartstext/x-include-urlstext/x-include-once-urlstext/cloud-config-archivestext/cloud-configsapplication/octet-streamsapplication/gzipsapplication/gzip-compressedsapplication/gzippedsapplication/x-compresssapplication/x-compressedsapplication/x-gunzipsapplication/x-gzipsapplication/x-gzip-compressedsNumber-AttachmentscCs||=|||tinclude_once_ontlinetlc_linet include_urltinclude_once_fntrespturletmessagetioetnew_msg((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyR9sR              c Cstj|dgdttf}x|D]}t|tjrPi|d6}nt|tseq(n|jdd}|jd}|st }t|tj rt }nt j ||}n|jdd\}} |dkrt|tj r|j}nt|d | } nt|| } | j|d |krXt| |d nd |kr| jd t|d nxgt|jD]S} | jdd dd d tjtjfkrqn| j| || qW|j|| q(WdS(NtdefaulttallowedRstttypeR$ittextt_subtypeRs launch-indexs Launch-Indexscontent-disposition(RRKRtsetRtsixt string_typestdictRItARCHIVE_UNDEF_TYPEt binary_typetARCHIVE_UNDEF_BINARY_TYPERR R4RHRRR5RRRtkeysRgtATTACHMENT_FIELDR7R<( RtarchiveR>tentriestentRstmtypeR~RDRER theader((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyR;s@!       cCst|krd|tt|tt|nd}yt|jt}Wn-ttfk rt|tt|nX|S(s Return the number of attachments to this MIMEMultipart by looking at its 'Number-Attachments' header. t0iN(RR'R RRNRIRORP(Rt outer_msgt new_countt fetched_count((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyt_multi_part_count,s   cCsH|j|}|j||d|j||j||ddS(s Attach a message to an outer message. outermsg must be a MIMEMultipart. Modifies a header in the outer message to keep track of number of attachments. iN(RRatattach(RRR?t part_count((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyR<>s N( t__name__t __module__RRRRSR^RaR9R;R'RR<(((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyRJs  I    : / cCs,|jpd}|jdkr(tStS(NRt multipart(tget_content_maintypeRgR-R*(R?t part_maintype((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyR&JscCs|sd}nd}t|tjr<|jd}n|}tj|dt}d|dd!jkrtj|j d}n|||}|S(sJconvert a string (more likely bytes) or a message into a mime message.RcSs8|jdd\}}t||}|j||S(NR$i(R4RR5(RUt content_typeRDRER ((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyt create_binmsgYs sutf-8RHs mime-version:ii( RRt text_typetencodeRR,R*Rgtmessage_from_stringRH(traw_dataRRtbdataR ((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyRSs  ((RXtemail.mime.baseRtemail.mime.multipartRtemail.mime.nonmultipartRtemail.mime.textRRt cloudinitRRtloggingtcloudinit.url_helperRRRt getLoggerRR/tNOT_MULTIPART_TYPER_t OCTET_TYPER7R3R8R:R2RRR+RRJR RtobjectRR&R(((s7/usr/lib/python2.7/site-packages/cloudinit/user_data.pyt sH