????

Your IP : 13.59.219.20


Current Path : /usr/lib/python3.6/site-packages/future/backports/email/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/future/backports/email/__pycache__/generator.cpython-36.opt-1.pyc

3

�c@L�@s.dZddlmZddlmZddlmZddlmZddlmZddlmZdd	d
gZ	ddl
Z
ddlZddlZddl
Z
ddlZddlmZmZdd
lmZddlmZddlmZddljjjZdZdZe
jde
j �Z!Gdd�de"�Z#Gdd
�d
e#�Z$dZ%Gdd	�d	e#�Z&e'e(ej)d��Z*de*Z+e#j,Z,dS)z:Classes to generate plain text from a message object tree.�)�print_function)�unicode_literals)�division)�absolute_import)�super)�str�	Generator�DecodedGenerator�BytesGeneratorN)�StringIO�BytesIO)�compat32)�Header)�_has_surrogates�_�
z^From c@s�eZdZdZd(dd�Zdd�Zd)d	d
�Zdd�Zd
Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZeZdd�Zdd�Zd d!�Zd"d#�Zed*d$d%��Zed&d'��ZdS)+rz�Generates output from a Message object tree.

    This basic generator writes the message to the given file object as plain
    text.
    TNcKs8d|kr|d}|d=nd}||_||_||_||_dS)N�policy)�_fp�
_mangle_from_�maxheaderlenr)�self�outfp�mangle_from_rZ_3to2kwargsr�r�/usr/lib/python3.6/generator.py�__init__+szGenerator.__init__cCs|jj|�dS)N)r�write)r�srrrrHszGenerator.writeFcCs�|jdkr|jn|j}|dk	r*|j|d�}|jdk	rB|j|jd�}|j|_|j|j�|_d|_|jd�|_|j}|j}zL||_||_|r�|j	�}|s�dt
jt
j
��}|j||j�|j
|�Wd||_||_XdS)azPrint 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.

        N)�linesep)�max_line_length�zFrom nobody )r�clonerr�_NL�_encode�_encoded_NLZ_EMPTYZ_encoded_EMTPYZget_unixfrom�timeZctimer�_write)r�msg�unixfromrrZold_gen_policyZold_msg_policyZufromrrr�flattenLs,
zGenerator.flattencCs|j||jd|jd�S)z1Clone this generator with the exact same options.N)r)�	__class__rr)r�fprrrr!{szGenerator.cloner cCst�S)N)r)rrrr�_new_buffer�szGenerator._new_buffercCs|S)Nr)rrrrrr#�szGenerator._encodecCs�|sdS|jd�}x0|dd�D] }|j|jd��|j|j�q W|djd�}|j|�t|d�t|�kr||j|j�dS)NT�z
���r.r.)�
splitlinesr�rstripr"�len)r�lines�lineZlaststrippedrrr�_write_lines�s

zGenerator._write_linescCsh|j}z|j�|_}|j|�Wd||_Xt|dd�}|dkrL|j|�n||�|jj|j��dS)N�_write_headers)rr,�	_dispatch�getattrr5r�getvalue)rr'ZoldfpZsfp�methrrrr&�szGenerator._writecCst|j�}|j�}tj||f�jdd�}t|d|d�}|dkrh|jdd�}t|d|d�}|dkrh|j}||�dS)N�-rZ_handle_)�get_content_maintype�get_content_subtype�
UNDERSCORE�join�replacer7�
_writeBody)rr'�main�subZspecificr9Zgenericrrrr6�szGenerator._dispatchcCs:x(|j�D]\}}|j|jj||��q
W|j|j�dS)N)�	raw_itemsrrZfoldr")rr'�h�vrrrr5�szGenerator._write_headerscCs�|j�}|dkrdSt|t�s.tdt|���t|j�rd|jd�}|dk	rd|d=|j||�|j�}|j	rvt
jd|�}|j|�dS)Nzstring payload expected: %s�charsetzcontent-transfer-encodingz>From )
�get_payload�
isinstancer�	TypeError�typer�_payloadZ	get_paramZset_payloadr�fcrerBr4)rr'�payloadrFrrr�_handle_text�s


zGenerator._handle_textcCs�g}|j�}|dkrg}n(t|t�r2|j|�dSt|t�sB|g}x>|D]6}|j�}|j|�}|j|d|jd�|j	|j
��qHW|j�}|s�|jj
|�}|j|�}|j|�|jdk	r�|jr�tjd|j�}	n|j}	|j|	�|j|j�|jd||j�|�r|jj|jd��x4|D],}
|j|jd||j�|jj|
��qW|j|jd|d�|jdk	�r�|j|j�|j�r�tjd|j�}n|j}|j|�dS)NF)r(rz>From z--r)rGrHrr�listr,r!r)r"�appendr8Zget_boundaryr$r>�_make_boundaryZset_boundary�preamblerrLrBr4r�pop�epilogue)rr'ZmsgtextsZsubparts�partr�g�boundaryZalltextrRZ	body_partrTrrr�_handle_multipart�sL









zGenerator._handle_multipartcCs0|j}|jdd�|_z|j|�Wd||_XdS)Nr)r)rr!rX)rr'�prrr�_handle_multipart_signed/s
z"Generator._handle_multipart_signedcCs�g}x�|j�D]t}|j�}|j|�}|j|d|jd�|j�}|j|j�}|rx|d|jkrx|j	|jj
|dd���q|j	|�qW|jj|jj
|��dS)NF)r(rr-r.r.)
rGr,r!r)r"r8�splitr$�_encoded_EMPTYrPr>rr)rr'ZblocksrUrrV�textr2rrr�_handle_message_delivery_status:s
z)Generator._handle_message_delivery_statuscCs^|j�}|j|�}|j}t|t�rD|j|jd�d|jd�|j�}n
|j	|�}|j
j|�dS)NrF)r(r)r,r!rKrHrOr)rGr"r8r#rr)rr'rrVrMrrr�_handle_messageOs




zGenerator._handle_messagecCsztjtj�}d	t|d}|dkr(|S|}d}xD|jdtj|�dtj�}|j	|�sZP|dt
|�}|d7}q2W|S)
N�=�z==rz^--z(--)?$�.r-z===============)�randomZ	randrange�sys�maxsize�_fmt�_compile_re�re�escape�	MULTILINE�searchr)�clsr]�tokenrW�bZcounterZcrerrrrQhs
zGenerator._make_boundarycCstj||�S)N)rh�compile)rlr�flagsrrrrgzszGenerator._compile_re)TN)FN)N)�__name__�
__module__�__qualname__�__doc__rrr)r!r\r,r#r4r&r6r5rNr@rXrZr^r_�classmethodrQrgrrrrr!s*

/

;csTeZdZdZdZdd�Zdd�Zdd�Zd	d
�Z�fdd�Z	e	Z
ed
d��Z�Z
S)r
a�Generates 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.
    �cCs|jjt|�jdd��dS)N�ascii�surrogateescape)rrr�encode)rrrrrr�szBytesGenerator.writecCst�S)N)r)rrrrr,�szBytesGenerator._new_buffercCs
|jd�S)Nrw)ry)rrrrrr#�szBytesGenerator._encodecCs<x*|j�D]\}}|jj|jj||��q
W|j|j�dS)N)rCrrrZfold_binaryr")rr'rDrErrrr5�szBytesGenerator._write_headerscs^|jdkrdSt|j�rJ|jjdkrJ|jr<tjd|j�|_|j|j�ntt	|�j
|�dS)NZ7bitz>From )rKrrZcte_typerrLrBr4rr
rN)rr')r*rrrN�s
zBytesGenerator._handle_textcCstj|jd�|�S)Nrw)rhrory)rlrrprrrrg�szBytesGenerator._compile_re)rqrrrsrtr\rr,r#r5rNr@rurg�
__classcell__rr)r*rr
~s
zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c@s"eZdZdZd	dd�Zdd�ZdS)
r	z�Generates 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.
    T�NNcCs*tj||||�|dkr t|_n||_dS)a�Like 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)rr�_FMTrf)rrrrZfmtrrrr�szDecodedGenerator.__init__cCs�x�|j�D]v}|j�}|dkr4t|jdd�|d�q
|dkr>q
t|j|j�|j�|j�|jd�|jdd�|jd	d
�d�|d�q
WdS)Nr]F)�decode)�fileZ	multipartz
[no filename]zContent-Descriptionz[no description]zContent-Transfer-Encodingz
[no encoding])rJ�maintype�subtype�filename�description�encoding)	�walkr;�printrGrfZget_content_typer<�get_filename�get)rr'rUrrrrr6�s 
zDecodedGenerator._dispatch)Tr{N)rqrrrsrtrr6rrrrr	�s
r-z%%0%dd)-rtZ
__future__rrrrZfuture.builtinsrr�__all__rhrdr%rc�warnings�iorrZ"future.backports.email._policybaser
Zfuture.backports.email.headerrZfuture.backports.email.utilsrZfuture.backports.email.charsetZ	backportsZemailrFZ_charsetr=�NLrorjrL�objectrr
r|r	r1�reprreZ_widthrfrQrrrr�<module>s:
_68