Hacked By AnonymousFox

Current Path : /proc/thread-self/root/proc/self/root/opt/alt/python35/lib64/python3.5/email/__pycache__/
Upload File :
Current File : //proc/thread-self/root/proc/self/root/opt/alt/python35/lib64/python3.5/email/__pycache__/header.cpython-35.pyc



��Yf$^�@s^dZdddgZddlZddlZddlZddlZddlmZddlm	Z
e
jZdZd	Z
d
ZdZdZd
ZdZed�Zed�ZejdejejBejB�Zejd�Zejd�ZejjZdd�Zddd	dd�ZGdd�d�Z Gdd�d�Z!Gdd�de"�Z#dS)z+Header encoding and decoding functionality.�Header�
decode_header�make_header�N)�HeaderParseError)�charset�
� � ���Nz 	zus-asciizutf-8ai
  =\?                   # literal =?
  (?P<charset>[^?]*?)   # non-greedy up to the next ? is the charset
  \?                    # literal ?
  (?P<encoding>[qb])    # either a "q" or a "b", case insensitive
  \?                    # literal ?
  (?P<encoded>.*?)      # non-greedy up to the next ?= is the encoded string
  \?=                   # literal ?=
  z[\041-\176]+:$z
\n[^ \t]+:cCs�t|d�r#dd�|jD�Stj|�s?|dfgSg}x�|j�D]�}tj|�}d}x�|r|jd�}|r�|j�}d}|r�|j|ddf�|rp|jd�j	�}|jd�j	�}|jd�}|j|||f�qpWqRWg}	xkt
|�D]]\}
}|
dkr)|dr)||
d	dr)||
ddj�r)|	j|
d�q)Wxt|	�D]
}||=q�Wg}
x|D]�\}}}|dkr�|
j||f�q�|d
krt
jj|�}|
j||f�q�|dkr�t|�d}|rT|d
dd|�7}yt
jj|�}Wn!tjk
r�td��Yq�X|
j||f�q�td|��q�Wg}d}}x�|
D]�\}}t|t�r�t|d�}|dkr|}|}q�||krB|j||f�|}|}q�|dkr_|t|7}q�||7}q�W|j||f�|S)a;Decode a message header value without converting charset.

    Returns a list of (string, charset) pairs containing each of the decoded
    parts of the header.  Charset is None for non-encoded parts of the header,
    otherwise a lower-case string containing the name of the character set
    specified in the encoded string.

    header may be a string that may or may not contain RFC2047 encoded words,
    or it may be a Header object.

    An email.errors.HeaderParseError may be raised when certain decoding error
    occurs (e.g. a base64 decoding exception).
    �_chunkscSs:g|]0\}}tj|t|��t|�f�qS�)�_charsetZ_encode�str)�.0�stringrrr�1/opt/alt/python35/lib64/python3.5/email/header.py�
<listcomp>Ms	z!decode_header.<locals>.<listcomp>NTrF���q�b�z===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)�hasattrr
�ecre�search�
splitlines�split�pop�lstrip�append�lower�	enumerate�isspace�reversed�email�
quoprimimeZ
header_decode�lenZ
base64mime�decode�binascii�Errorr�AssertionError�
isinstancer�bytes�BSPACE)�headerZwords�line�parts�firstZ	unencodedr�encodingZencodedZdroplist�n�w�dZ
decoded_wordsZencoded_stringZwordZpaderrZ	collapsedZ	last_word�last_charsetrrrr=sz	
	@
		cCsntd|d|d|�}xL|D]D\}}|dk	rVt|t�rVt|�}|j||�q"W|S)a�Create a Header from a sequence of pairs as returned by decode_header()

    decode_header() takes a header value string and returns a sequence of
    pairs of the format (decoded_string, charset) where charset is the string
    name of the character set.

    This function takes one of those sequence of pairs and returns a Header
    instance.  Optional maxlinelen, header_name, and continuation_ws are as in
    the Header constructor.
    �
maxlinelen�header_name�continuation_wsN)rr-�Charsetr!)Zdecoded_seqr9r:r;�h�srrrrr�s	c@s�eZdZdddddddd�Zdd�Zdd	�Zddd
d�Zdd
�Zddddd�Zdd�Z	dS)rNr�strictcCs�|dkrt}nt|t�s0t|�}||_||_g|_|dk	rj|j|||�|dkr|t}||_|dkr�d|_	nt
|�d|_	dS)aDCreate a MIME-compliant header that can contain many character sets.

        Optional s is the initial header value.  If None, the initial header
        value is not set.  You can later append to the header with .append()
        method calls.  s may be a byte string or a Unicode string, but see the
        .append() documentation for semantics.

        Optional charset serves two purposes: it has the same meaning as the
        charset argument to the .append() method.  It also sets the default
        character set for all subsequent .append() calls that omit the charset
        argument.  If charset is not provided in the constructor, the us-ascii
        charset is used both as s's initial charset and as the default for
        subsequent .append() calls.

        The maximum line length can be specified explicitly via maxlinelen. For
        splitting the first line to a shorter value (to account for the field
        header which isn't included in s, e.g. `Subject') pass in the name of
        the field in header_name.  The default maxlinelen is 78 as recommended
        by RFC 2822.

        continuation_ws must be RFC 2822 compliant folding whitespace (usually
        either a space or a hard tab) which will be prepended to continuation
        lines.

        errors is passed through to the .append() call.
        Nrr)�USASCIIr-r<r�_continuation_wsr
r!�
MAXLINELEN�_maxlinelen�
_headerlenr()�selfr>rr9r:r;�errorsrrr�__init__�s					zHeader.__init__c	Cs|j�g}d}d}x�|jD]�\}}|}|tjkrk|jdd�}|jdd�}|r�|o�|j|d�}|dkr�|d	kr�|r�|jt�d}n |d
kr�|r�|jt�|o�|j|d�}|}|j|�q&Wt	j
|�S)z&Return the string value of the header.N�ascii�surrogateescape�replacer�us-asciir)NrK)NrK)NrK���)�
_normalizer
r�UNKNOWN8BIT�encoder)�	_nonctextr!�SPACE�EMPTYSTRING�join)	rEZuchunks�lastcs�	lastspacerrZnextcsZoriginal_bytes�hasspacerrr�__str__�s*

	
zHeader.__str__cCs|t|�kS)N)r)rE�otherrrr�__eq__sz
Header.__eq__cCs�|dkr|j}nt|t�s3t|�}t|t�s�|jpNd}|tjkru|jdd�}n|j||�}|jp�d}|tjkr�y|j||�Wn't	k
r�|dkr��t
}YnX|jj||f�dS)a.Append a string to the MIME header.

        Optional charset, if given, should be a Charset instance or the name
        of a character set (which will be converted to a Charset instance).  A
        value of None (the default) means that the charset given in the
        constructor is used.

        s may be a byte string or a Unicode string.  If it is a byte string
        (i.e. isinstance(s, str) is false), then charset is the encoding of
        that byte string, and a UnicodeError will be raised if the string
        cannot be decoded with that charset.  If s is a Unicode string, then
        charset is a hint specifying the character set of the characters in
        the string.  In either case, when producing an RFC 2822 compliant
        header using RFC 2047 rules, the string will be encoded using the
        output codec of the charset.  If the string cannot be encoded to the
        output codec, a UnicodeError will be raised.

        Optional `errors' is passed as the errors argument to the decode
        call if s is a byte string.
        Nzus-asciirI)
rr-r<rZinput_codecrNr)Zoutput_codecrO�UnicodeEncodeError�UTF8r
r!)rEr>rrFZ
input_charsetZoutput_charsetrrrr!	s$
z
Header.appendcCs|j�p|dkS)z=True if string s is not a ctext character of RFC822.
        �(�)�\)r\r]r^)r$)rEr>rrrrP4szHeader._nonctextz;, 	rcCsD|j�|dkr|j}|dkr1d}t|j||j|�}d}d}}x�|jD]�\}}	|dk	r�|o�|j|d�}|d
kr�|s�|	dkr�|j�n|	dkr�|r�|j�|o�|j|d
�}|	}d}|j�}
|
r1|j	d|
d|	�n|j	dd|	�x�|
dd�D]�}|j
�|	jdk	r�|j	|jd|j�|	�qU|j�}|dt
|�t
|��}
|j	|
||	�qUWt
|
�dkrf|j
�qfW|jr
|j�|j|�}tj|�r@td	j|���|S)a�Encode a message header into an RFC-compliant format.

        There are many issues involved in converting a given string for use in
        an email header.  Only certain character sets are readable in most
        email clients, and as header strings can only contain a subset of
        7-bit ASCII, care must be taken to properly convert and encode (with
        Base64 or quoted-printable) header strings.  In addition, there is a
        75-character length limit on any given encoded header field, so
        line-wrapping must be performed, even with double-byte character sets.

        Optional maxlinelen specifies the maximum length of each generated
        line, exclusive of the linesep string.  Individual lines may be longer
        than maxlinelen if a folding point cannot be found.  The first line
        will be shorter by the length of the header name plus ": " if a header
        name was specified at Header construction time.  The default value for
        maxlinelen is determined at header construction time.

        Optional splitchars is a string containing characters which should be
        given extra weight by the splitting algorithm during normal header
        wrapping.  This is in very rough support of RFC 2822's `higher level
        syntactic breaks':  split points preceded by a splitchar are preferred
        during line splitting, with the characters preferred in the order in
        which they appear in the string.  Space and tab may be included in the
        string to indicate whether preference should be given to one over the
        other as a split point when other split chars do not appear in the line
        being split.  Splitchars does not affect RFC 2047 encoded lines.

        Optional linesep is a string to be used to separate the lines of
        the value.  The default value is the most useful for typical
        Python applications, but it can be set to \r\n to produce RFC-compliant
        line separators when needed.
        Nri@B�us-asciirFrrz8header value appears to contain an embedded header: {!r})Nr_)Nr_)Nr_rL)rMrC�_ValueFormatterrDrAr
rP�add_transitionr�feed�newline�header_encodingr r(�_str�_embeded_headerrr�format)rE�
splitcharsr9�linesepZ	formatterrTrVrUrr�linesr1Zsline�fws�valuerrrrO9sR!
	




 	
	z
Header.encodecCs�g}d}g}xj|jD]_\}}||krD|j|�q|dk	rl|jtj|�|f�|g}|}qW|r�|jtj|�|f�||_dS)N)r
r!rQrS)rEZchunksr8Z
last_chunkrrrrrrM�s	
zHeader._normalize)
�__name__�
__module__�__qualname__rGrWrYr!rPrOrMrrrrr�s- +Pc@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)r`cCsF||_||_t|�|_||_g|_t|�|_dS)N)�_maxlenrAr(�_continuation_ws_len�_splitchars�_lines�_Accumulator�
_current_line)rEZ	headerlen�maxlenr;rhrrrrG�s				z_ValueFormatter.__init__cCs|j�|j|j�S)N)rcrSrs)rErirrrre�s
z_ValueFormatter._strcCs
|jt�S)N)re�NL)rErrrrW�sz_ValueFormatter.__str__cCs�|jj�}|dkr+|jj|�t|j�dkr�|jj�rl|jdt|j�7<n|jjt|j��|jj�dS)Nrrrr)rrrL)	rur�pushr(�	is_onlywsrsrr!�reset)rEZend_of_linerrrrc�sz_ValueFormatter.newlinecCs|jjdd�dS)Nrr)rurx)rErrrra�sz_ValueFormatter.add_transitioncCs�|jdkr)|j|||j�dS|j||j��}y|jd�}Wntk
rldSYnX|dk	r�|j||�y|j�}Wntk
r�dSYnX|j�|j	j
|j|�x%|D]}|jj
|j|�q�WdS)Nr)rd�_ascii_splitrrZheader_encode_lines�_maxlengthsr�
IndexError�
_append_chunkrcrurxrArsr!)rErkrrZ
encoded_linesZ
first_lineZ	last_liner1rrrrb�s$
	
	

z_ValueFormatter.feedccs/|jt|j�Vx|j|jVqWdS)N)rpr(rurq)rErrrr|�sz_ValueFormatter._maxlengthscCs�tjdtd||�}|dr>dg|dd�<n
|jd�x7tt|�gd�D]\}}|j||�qeWdS)Nz([z]+)rrr)�rer�FWSr�zip�iterr~)rErkrrhr2�partrrrr{�s

&z_ValueFormatter._ascii_splitcCs`|jj||�t|j�|jkr\x�|jD]�}x�t|jj�ddd�D]f}|j�r�|j|d}|r�|d|kr�P|j|dd}|r[|d|kr[Pq[Wq5Pq5W|jj�\}}|jj	dkr
|j
�|s
d}|jj||�dS|jj|�}|jj
t|j��|jj|�dS)NrrrrLrL)rurxr(rprr�range�
part_countr$r�
_initial_sizerc�pop_fromrsr!rrz)rErkrZch�iZprevpartr�Z	remainderrrrr~�s.&
z_ValueFormatter._append_chunkN)rmrnrorGrerWrcrarbr|r{r~rrrrr`�s%r`cs�eZdZd�fdd�Zdd�Zddd�Z�fdd	�Zd
d�Zdd
�Zddd�Z	dd�Z
�fdd�Z�S)rtrcs||_t�j�dS)N)r��superrG)rEZinitial_size)�	__class__rrrGs	z_Accumulator.__init__cCs|j||f�dS)N)r!)rErkrrrrrx#sz_Accumulator.pushcCs$||d�}g||d�<|S)Nr)rEr�Zpoppedrrrr�&sz_Accumulator.pop_fromcs#|j�dkrdSt�j�S)Nrr)rr)r�r�r)rE)r�rrr+sz_Accumulator.popcCstdd�|D�|j�S)Ncss+|]!\}}t|�t|�VqdS)N)r()rrkr�rrr�	<genexpr>1sz'_Accumulator.__len__.<locals>.<genexpr>)�sumr�)rErrr�__len__0sz_Accumulator.__len__cCstjdd�|D��S)Ncss*|] \}}tj||f�VqdS)N)rRrS)rrkr�rrrr�5sz'_Accumulator.__str__.<locals>.<genexpr>)rRrS)rErrrrW4sz_Accumulator.__str__NcCs/|dkrg}||dd�<d|_dS)Nr)r�)rEZstartvalrrrrz8sz_Accumulator.resetcCs&|jdko%|p%t|�j�S)Nr)r�rr$)rErrrry>sz_Accumulator.is_onlywscs
t�j�S)N)r�r�)rE)r�rrr�Asz_Accumulator.part_count)rmrnrorGrxr�rr�rWrzryr�rr)r�rrtsrtz        )$�__doc__�__all__rr*Zemail.quoprimimer&Zemail.base64mimeZemail.errorsrrrr<rwrQr/ZSPACE8rRrBr�r@r[�compile�VERBOSE�
IGNORECASE�	MULTILINErZfcrerfr'Z_max_appendrrrr`�listrtrrrr�<module>s<		_��

Hacked By AnonymousFox1.0, Coded By AnonymousFox