ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python34/lib64/python3.4/email/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python34/lib64/python3.4/email/__pycache__/generator.cpython-34.pyc

�
e f�M�@sdZdddgZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZd	Z
d
Zejdej�ZGdd�d�ZGd
d�de�ZdZGdd�de�Zeeejd��ZdeZejZdS)z:Classes to generate plain text from a message object tree.�	Generator�DecodedGenerator�BytesGenerator�N)�deepcopy)�StringIO�BytesIO)�_has_surrogates�_�
z^From c@seZdZdZdddddd�Zdd�Zd	dd
d�Zdd
�ZdZdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZeZdd�Zdd �Zd!d"�Zd#d$�Zedd%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.
    TN�policycCs(||_||_||_||_dS)a�Create 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.  If no policy is specified,
        the policy associated with the Message object passed to the
        flatten method is used.

        N)�_fp�
_mangle_from_�maxheaderlenr)�self�outfp�mangle_from_rr�r�4/opt/alt/python34/lib64/python3.4/email/generator.py�__init__#s			zGenerator.__init__cCs|jj|�dS)N)r�write)r�srrrr@szGenerator.writeFcCs?|jdkr|jn|j}|dk	rB|jd|�}n|jdk	ri|jd|j�}n|j|_|j|j�|_d|_|jd�|_|j}|j}zn||_||_|r|j	�}|sdt
jt
j
��}n|j||j�n|j
|�Wd||_||_XdS)a�Print 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 specified
        when the Generator instance was created or, if none was specified,
        from the policy associated with the msg.

        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�flattenDs,!						zGenerator.flattencCs|j||jdd|j�S)z1Clone this generator with the exact same options.Nr)�	__class__r
r)r�fprrrrus	zGenerator.clonercCst�S)N)r)rrrr�_new_buffer�szGenerator._new_buffercCs|S)Nr)rrrrrr�szGenerator._encodecCs�|s
dS|jd�}x>|dd�D],}|j|jd��|j|j�q*W|djd�}|j|�t|d�t|�kr�|j|j�ndS)NT�z
���r'r')�
splitlinesr�rstripr�len)r�lines�lineZlaststrippedrrr�_write_lines�s
zGenerator._write_linescCs�|j}z-d|_|j�|_}|j|�Wd||_|j}|`X|r�t|�}|jd|d�|jd|d�nt|dd�}|dkr�|j|�n
||�|jj|j	��dS)Nzcontent-transfer-encodingrzcontent-typer&�_write_headers)
r�
_munge_cter%�	_dispatchrZreplace_header�getattrr.r�getvalue)rr ZoldfpZsfpZ	munge_cte�methrrrr�s"				
zGenerator._writecCs�|j�}|j�}tj||f�jdd�}t|d|d�}|dkr�|jdd�}t|d|d�}|dkr�|j}q�n||�dS)N�-r	Z_handle_)�get_content_maintype�get_content_subtype�
UNDERSCORE�join�replacer1�
_writeBody)rr �main�subZspecificr3Zgenericrrrr0�s!zGenerator._dispatchcCsMx6|j�D](\}}|j|jj||��q
W|j|j�dS)N)�	raw_itemsrrZfoldr)rr �h�vrrrr.�s zGenerator._write_headerscCs�|j�}|dkrdSt|t�sDtdt|���nt|j�r�|jd�}|dk	r�t|�}|d=|j	||�|j�}|d|df|_
q�n|jr�tj
d|�}n|j|�dS)Nzstring payload expected: %s�charsetzcontent-transfer-encodingzcontent-typez>From )�get_payload�
isinstance�str�	TypeError�typer�_payloadZ	get_paramrZset_payloadr/r
�fcrer<r-)rr �payloadr@rrr�_handle_text�s"	zGenerator._handle_textcCsCg}|j�}|dkr'g}n;t|t�rG|j|�dSt|t�sb|g}nxX|D]P}|j�}|j|�}|j|ddd|j�|j	|j
��qiW|j�}|s|jj
|�}|j|�}|j|�n|jdk	rY|jr0tjd|j�}	n	|j}	|j|	�|j|j�n|jd||j�|r�|jj|jd��nx=|D]5}
|j|jd||j�|jj|
�q�W|j|jd|d|j�|jdk	r?|jr&tjd|j�}n	|j}|j|�ndS)Nr!Frz>From z--r)rArBrCr�listr%rr"r�appendr2Zget_boundaryrr8�_make_boundaryZset_boundary�preambler
rGr<r-r�pop�epilogue)rr ZmsgtextsZsubparts�partr�g�boundaryZalltextrMZ	body_partrOrrr�_handle_multipart�sJ	

		

#		zGenerator._handle_multipartcCs@|j}|jdd�|_z|j|�Wd||_XdS)Nrr)rrrS)rr �prrr�_handle_multipart_signed5s
	z"Generator._handle_multipart_signedcCs�g}x�|j�D]�}|j�}|j|�}|j|ddd|j�|j�}|j|j�}|r�|d|jkr�|j	|jj
|dd���q|j	|�qW|jj|jj
|��dS)Nr!Frr&r'r')
rAr%rr"rr2�splitr�_encoded_EMPTYrKr8rr)rr ZblocksrPrrQ�textr+rrr�_handle_message_delivery_status@s&z)Generator._handle_message_delivery_statuscCs�|j�}|j|�}|j}t|t�rg|j|jd�ddd|j�|j�}n|j	|�}|j
j|�dS)Nrr!Fr)r%rrFrBrJr"rArr2rrr)rr rrQrHrrr�_handle_messageUs
	%zGenerator._handle_messagecCs�tjtj�}d	t|d}|dkr4|S|}d}x[|jdtj|�dtj�}|j	|�s|Pn|dt
|�}|d7}qCW|S)
N�=�z==rz^--z(--)?$�.r&z===============)�randomZ	randrange�sys�maxsize�_fmt�_compile_re�re�escape�	MULTILINE�searchrC)�clsrX�tokenrR�bZcounterZcrerrrrLns&zGenerator._make_boundarycCstj||�S)N)rc�compile)rgr�flagsrrrrb�szGenerator._compile_re)�__name__�
__module__�__qualname__�__doc__rrr"rrWr%rr-rr0r.rIr:rSrUrYrZ�classmethodrLrbrrrrrs,	1
#
:csveZdZdZdZdd�Zdd�Zdd�Zd	d
�Z�fdd�Z	e	Z
ed
d��Z�S)ra�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 |jj|jdd��dS)N�ascii�surrogateescape)rr�encode)rrrrrr�szBytesGenerator.writecCst�S)N)r)rrrrr%�szBytesGenerator._new_buffercCs
|jd�S)Nrr)rt)rrrrrr�szBytesGenerator._encodecCsPx9|j�D]+\}}|jj|jj||��q
W|j|j�dS)N)r=rrrZfold_binaryr)rr r>r?rrrr.�s#zBytesGenerator._write_headerscs�|jdkrdSt|j�rl|jjdkrl|jrYtjd|j�|_n|j|j�ntt	|�j
|�dS)NZ7bitz>From )rFrrZcte_typer
rGr<r-�superrrI)rr )r#rrrI�s"	zBytesGenerator._handle_textcCstj|jd�|�S)Nrr)rcrjrt)rgrrkrrrrb�szBytesGenerator._compile_re)
rlrmrnrorWrr%rr.rIr:rprbrr)r#rr�s
zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c@s7eZdZdZddddd�Zdd�ZdS)	rz�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�_FMTra)rrrrZfmtrrrr�szDecodedGenerator.__init__cCs�x�|j�D]�}|j�}|dkrJt|jdd�d|�q
|dkrYq
t|ji|j�d6|j�d6|j�d6|jd	�d
6|jdd�d
6|jdd�d6d|�q
WdS)NrX�decodeF�fileZ	multipartrE�maintype�subtypez
[no filename]�filenamezContent-Descriptionz[no description]ZdescriptionzContent-Transfer-Encodingz
[no encoding]�encoding)	�walkr5�printrAraZget_content_typer6�get_filename�get)rr rPrzrrrr0�s 


	
	zDecodedGenerator._dispatch)rlrmrnrorr0rrrrr�sr&z%%0%dd)ro�__all__rcr_rr^�copyr�iorrZemail.utilsrr7�NLrjrerGrrrwrr*�reprr`Z_widthrarLrrrr�<module>s&�m79


Zerion Mini Shell 1.0