fCMc@sLdZdddgZddlZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z dd lmZdd lmZddljZd Zd Zejd ejZGdddZGdddeZdZGdddeZeeej dZ!de!Z"ej#Z#dS(u:Classes to generate plain text from a message object tree.u GeneratoruDecodedGeneratoruBytesGeneratoriN(udeepcopy(uStringIOuBytesIO(ucompat32(uHeader(u_has_surrogatesu_u u^From cBs|EeZdZdZdd&d'd&ddZddZd(d&ddZ d d Z d Z d d Z ddZ ddZddZddZddZddZeZddZddZddZd d!Zed&d"d#Zed$d%Zd&S()u GeneratoruGenerates output from a Message object tree. This basic generator writes the message to the given file object as plain text. upolicycCs(||_||_||_||_dS(uCreate the generator for message flattening. outfp is the output file-like object for writing the message to. It must have a write() method. Optional mangle_from_ is a flag that, when True (the default), escapes From_ lines in the body of the message by putting a `>' in front of them. Optional maxheaderlen specifies the longest length for a non-continued header. When a header line is longer (in characters, with tabs expanded to 8 spaces) than maxheaderlen, the header will split as defined in the Header class. Set maxheaderlen to zero to disable header wrapping. The default is 78, as recommended (but not required) by RFC 2822. The policy keyword specifies a policy object that controls a number of aspects of the generator's operation. The default policy maintains backward compatibility. N(u_fpu _mangle_from_u maxheaderlenupolicy(uselfuoutfpu mangle_from_u maxheaderlenupolicy((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu__init__'s   uGenerator.__init__cCs|jj|dS(N(u_fpuwrite(uselfus((u4/opt/alt/python33/lib64/python3.3/email/generator.pyuwriteCsuGenerator.writec Cs?|jdkr|jn|j}|dk rB|jd|}n|jdk ri|jd|j}n|j|_|j|j|_d|_|jd|_ |j}|j}zn||_||_|r|j }|sdt j t j }n|j ||jn|j|Wd||_||_XdS(uzPrint the message object tree rooted at msg to the output file specified when the Generator instance was created. unixfrom is a flag that forces the printing of a Unix From_ delimiter before the first object in the message tree. If the original message has no From_ delimiter, a `standard' one is crafted. By default, this is False to inhibit the printing of any From_ delimiter. Note that for subobjects, no From_ line is printed. linesep specifies the characters used to indicate a new line in the output. The default value is determined by the policy. ulinesepumax_line_lengthuu From nobody N(upolicyuNoneucloneu maxheaderlenulinesepu_NLu_encodeu _encoded_NLu_EMPTYu_encoded_EMTPYu get_unixfromutimeuctimeuwriteu_write(uselfumsguunixfromulinesepupolicyuold_gen_policyuold_msg_policyuufrom((u4/opt/alt/python33/lib64/python3.3/email/generator.pyuflattenGs,!         uGenerator.flattencCs|j||jdd|jS(u1Clone this generator with the exact same options.upolicyN(u __class__u _mangle_from_uNoneupolicy(uselfufp((u4/opt/alt/python33/lib64/python3.3/email/generator.pyuclonevs uGenerator.cloneucCstS(N(uStringIO(uself((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _new_buffersuGenerator._new_buffercCs|S(N((uselfus((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_encodesuGenerator._encodecCs|s dS|jd}x>|ddD],}|j|jd|j|jq*W|djd}|j|t|dt|kr|j|jndS(Niu Tiii(u splitlinesuTrueuwriteurstripu_NLulen(uselfulinesulineu laststripped((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _write_liness uGenerator._write_linesc Cs|j}z-d|_|j|_}|j|Wd||_|j}|`X|rt|}|jd|d|jd|dnt|dd}|dkr|j|n |||jj |j dS(Nucontent-transfer-encodingiu content-typeiu_write_headers( u_fpuNoneu _munge_cteu _new_bufferu _dispatchudeepcopyureplace_headerugetattru_write_headersuwriteugetvalue(uselfumsguoldfpusfpu munge_cteumeth((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_writes"       uGenerator._writecCs|j}|j}tj||fjdd}t|d|d}|dkr|jdd}t|d|d}|dkr|j}qn||dS(Nu-u_u_handle_(uget_content_maintypeuget_content_subtypeu UNDERSCOREujoinureplaceugetattruNoneu _writeBody(uselfumsgumainusubuspecificumethugeneric((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _dispatchs  !  uGenerator._dispatchcCsMx6|jD](\}}|j|jj||q W|j|jdS(N(u raw_itemsuwriteupolicyufoldu_NL(uselfumsguhuv((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_write_headerss uGenerator._write_headerscCs|j}|dkrdSt|tsDtdt|nt|jr|jd}|dk rt |}|d=|j |||j}|d|df|_ qn|j rt jd|}n|j|dS(Nustring payload expected: %sucharsetucontent-transfer-encodingu content-typeu>From (u get_payloaduNoneu isinstanceustru TypeErrorutypeu_has_surrogatesu_payloadu get_paramudeepcopyu set_payloadu _munge_cteu _mangle_from_ufcreusubu _write_lines(uselfumsgupayloaducharset((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _handle_texts"      uGenerator._handle_textc CsCg}|j}|dkr'g}n;t|trG|j|dSt|tsb|g}nxX|D]P}|j}|j|}|j|ddd|j |j |j qiW|j }|s|jj|}|j|}|j|n|jdk rY|jr0tjd|j} n |j} |j| |j|j n|jd||j |r|jj|jdnx=|D]5} |j|j d||j |jj| qW|j|j d|d|j |jdk r?|jr&tjd|j} n |j} |j| ndS(Nuunixfromulinesepu>From u--iF(u get_payloaduNoneu isinstanceustruwriteulistu _new_bufferucloneuflattenuFalseu_NLuappendugetvalueu get_boundaryu _encoded_NLujoinu_make_boundaryu set_boundaryupreambleu _mangle_from_ufcreusubu _write_linesu_fpupopuepilogue( uselfumsgumsgtextsusubpartsupartusuguboundaryualltextupreambleu body_partuepilogue((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_handle_multipartsJ            #  uGenerator._handle_multipartc Cs@|j}|jdd|_z|j|Wd||_XdS(Numax_line_lengthi(upolicyucloneu_handle_multipart(uselfumsgup((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_handle_multipart_signed6s  u"Generator._handle_multipart_signedcCsg}x|jD]}|j}|j|}|j|ddd|j|j}|j|j}|r|d|j kr|j |jj |ddq|j |qW|j j |jj |dS(NuunixfromulinesepiFii(u get_payloadu _new_bufferucloneuflattenuFalseu_NLugetvalueusplitu _encoded_NLu_encoded_EMPTYuappendujoinu_fpuwrite(uselfumsgublocksupartusugutextulines((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_handle_message_delivery_statusAs  &u)Generator._handle_message_delivery_statuscCs|j}|j|}|j}t|trg|j|jdddd|j|j }n|j |}|j j |dS(NiuunixfromulinesepF( u _new_bufferucloneu_payloadu isinstanceulistuflattenu get_payloaduFalseu_NLugetvalueu_encodeu_fpuwrite(uselfumsgusugupayload((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_handle_messageVs  %uGenerator._handle_messagecCstjtj}d t|d}|dkr4|S|}d}xZ|jdtj|dtj }|j |s|Pn|dt |}|d7}qC|S( Nu=iu==iu^--u(--)?$u.iu===============( urandomu randrangeusysumaxsizeu_fmtuNoneu _compile_reureuescapeu MULTILINEusearchustr(uclsutextutokenuboundaryubucounterucre((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_make_boundaryos & uGenerator._make_boundarycCstj||S(N(ureucompile(uclsusuflags((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _compile_resuGenerator._compile_reNTF(u__name__u __module__u __qualname__u__doc__uNoneuTrueu__init__uwriteuFalseuflattenucloneu_encoded_EMPTYu _new_bufferu_encodeu _write_linesu_writeu _dispatchu_write_headersu _handle_textu _writeBodyu_handle_multipartu_handle_multipart_signedu_handle_message_delivery_statusu_handle_messageu classmethodu_make_boundaryu _compile_re(u __locals__((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu Generators, /    #   :  csz|EeZdZdZdZddZddZddZd d Zfd d Z e Z e d dZ S(uBytesGeneratoruGenerates a bytes version of a Message object tree. Functionally identical to the base Generator except that the output is bytes and not string. When surrogates were used in the input to encode bytes, these are decoded back to bytes for output. If the policy has cte_type set to 7bit, then the message is transformed such that the non-ASCII bytes are properly content transfer encoded, using the charset unknown-8bit. The outfp object must accept bytes in its write method. scCs |jj|jdddS(Nuasciiusurrogateescape(u_fpuwriteuencode(uselfus((u4/opt/alt/python33/lib64/python3.3/email/generator.pyuwritesuBytesGenerator.writecCstS(N(uBytesIO(uself((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _new_buffersuBytesGenerator._new_buffercCs |jdS(Nuascii(uencode(uselfus((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_encodesuBytesGenerator._encodecCsPx9|jD]+\}}|jj|jj||q W|j|jdS(N(u raw_itemsu_fpuwriteupolicyu fold_binaryu_NL(uselfumsguhuv((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu_write_headerss#uBytesGenerator._write_headerscs|jdkrdSt|jrl|jjdk rl|jrYtjd|j|_n|j|jnt t |j |dS(Nu7bitu>From ( u_payloaduNoneu_has_surrogatesupolicyucte_typeu _mangle_from_ufcreusubu _write_linesusuperuBytesGeneratoru _handle_text(uselfumsg(u __class__(u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _handle_texts" uBytesGenerator._handle_textcCstj|jd|S(Nuascii(ureucompileuencode(uclsusuflags((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _compile_resuBytesGenerator._compile_re( u__name__u __module__u __qualname__u__doc__u_encoded_EMPTYuwriteu _new_bufferu_encodeu_write_headersu _handle_textu _writeBodyu classmethodu _compile_re(u __locals__((u __class__u4/opt/alt/python33/lib64/python3.3/email/generator.pyuBytesGenerators      uD[Non-text (%(type)s) part of message omitted, filename %(filename)s]cBs;|EeZdZdZdddddZddZdS( uDecodedGeneratoruGenerates a text representation of a message. Like the Generator base class, except that non-text parts are substituted with a format string representing the part. iNcCs;tj|||||dkr.t|_n ||_dS(uLike Generator.__init__() except that an additional optional argument is allowed. Walks through all subparts of a message. If the subpart is of main type `text', then it prints the decoded payload of the subpart. Otherwise, fmt is a format string that is used instead of the message payload. fmt is expanded with the following keywords (in %(keyword)s format): type : Full MIME type of the non-text part maintype : Main MIME type of the non-text part subtype : Sub-MIME type of the non-text part filename : Filename of the non-text part description: Description associated with the non-text part encoding : Content transfer encoding of the non-text part The default value for fmt is None, meaning [Non-text (%(type)s) part of message omitted, filename %(filename)s] N(u Generatoru__init__uNoneu_FMTu_fmt(uselfuoutfpu mangle_from_u maxheaderlenufmt((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu__init__s  uDecodedGenerator.__init__cCsx|jD]}|j}|dkrJt|jddd|q |dkrYq t|ji|jd6|jd6|jd6|jdd 6|j d d d 6|j d dd6d|q WdS(Nutextudecodeufileu multipartutypeumaintypeusubtypeu [no filename]ufilenameuContent-Descriptionu[no description]u descriptionuContent-Transfer-Encodingu [no encoding]uencodingF( uwalkuget_content_maintypeuprintu get_payloaduFalseu_fmtuget_content_typeuget_content_subtypeu get_filenameuget(uselfumsgupartumaintype((u4/opt/alt/python33/lib64/python3.3/email/generator.pyu _dispatchs           uDecodedGenerator._dispatchNT(u__name__u __module__u __qualname__u__doc__uTrueuNoneu__init__u _dispatch(u __locals__((u4/opt/alt/python33/lib64/python3.3/email/generator.pyuDecodedGeneratorsiu%%0%dd($u__doc__u__all__ureusysutimeurandomuwarningsucopyudeepcopyuiouStringIOuBytesIOuemail._policybaseucompat32u email.headeruHeaderu email.utilsu_has_surrogatesu email.charsetucharsetu_charsetu UNDERSCOREuNLucompileu MULTILINEufcreu GeneratoruBytesGeneratoru_FMTuDecodedGeneratorulenureprumaxsizeu_widthu_fmtu_make_boundary(((u4/opt/alt/python33/lib64/python3.3/email/generator.pyus.     j79