Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib/python3.7/site-packages/future/backports/email/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/future/backports/email/__pycache__/message.cpython-37.pyc

B

�A�[���@s�dZddlmZmZmZddlmZmZmZm	Z	dgZ
ddlZddlZddl
Z
ddlZddlmZmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZejZd
Ze�d�Z dd�Z!ddd�Z"dd�Z#dd�Z$Gdd�de%�Z&dS)z8Basic message object for the email package object model.�)�absolute_import�division�unicode_literals)�list�range�str�zip�MessageN)�BytesIO�StringIO)�
as_native_str)�utils)�errors)�compat32)�charset)�decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCs4t|��d�\}}}|s$|��dfS|��|��fS)N�;)r�	partition�strip)�param�a�sep�b�r�O/opt/alt/python37/lib/python3.7/site-packages/future/backports/email/message.py�_splitparam"srTcCs�|dk	r�t|�dkr�t|t�rL|d7}t�|d|d|d�}d||fSy|�d�Wn2tk
r�|d7}t�|dd	�}d||fSX|s�t�|�r�d
|t�	|�fSd||fSn|SdS)a~Convenience function to format and return a key=value pair.

    This will quote the value if needed or if quote is true.  If value is a
    three tuple (charset, language, value), it will be encoded according
    to RFC2231 rules.  If it contains non-ascii characters it will likewise
    be encoded according to RFC2231 rules, using the utf-8 charset and
    a null language.
    Nr�*��z%s=%s�asciizutf-8�z%s="%s")
�len�
isinstance�tupler
�encode_rfc2231�encode�UnicodeEncodeError�	tspecials�search�quote)r�valuer)rrr�_formatparam,s	
r+cCs�dt|�}g}x�|dd�dkr�|dd�}|�d�}x<|dkrt|�dd|�|�dd|�drt|�d|d�}q:W|dkr�t|�}|d|�}d|kr�|�d�}|d|�����d||dd���}|�|���||d�}qW|S)Nrrr�"z\"r�=)r�find�countr!�indexr�lower�append)�s�plist�end�f�irrr�_parseparamNs 
*
,r8cCs4t|t�r&|d|dt�|d�fSt�|�SdS)Nrrr)r"r#r
�unquote)r*rrr�
_unquotevaluebs
r:c@s�eZdZdZefdd�Zedd�dd��Zd`d
d�Zdd
�Z	dd�Z
dd�Zdd�Zdadd�Z
dbdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zdcd/d0�Zd1d2�Zd3d4�Zddd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dedIdJ�Z&dfdKdL�Z'dgdOdP�Z(dhdQdR�Z)didSdT�Z*djdUdV�Z+dkdWdX�Z,dYdZ�Z-dld[d\�Z.dmd]d^�Z/d	d_l0m1Z1dS)nr	a�Basic message object.

    A message object is defined as something that has a bunch of RFC 2822
    headers and a payload.  It may optionally have an envelope header
    (a.k.a. Unix-From or From_ header).  If the message is a container (i.e. a
    multipart or a message/rfc822), then the payload is a list of Message
    objects, otherwise it is a string.

    Message objects implement part of the `mapping' interface, which assumes
    there is exactly one occurrence of the header per message.  Some headers
    do in fact appear multiple times (e.g. Received) and for those headers,
    you must use the explicit API to set or get all the headers.  Not all of
    the mapping methods are implemented.
    cCs<||_t�|_d|_d|_d|_d|_|_g|_d|_	dS)Nz
text/plain)
�policyr�_headers�	_unixfrom�_payload�_charset�preamble�epilogue�defects�
_default_type)�selfr;rrr�__init__|szMessage.__init__zutf-8)�encodingcCs|��S)zwReturn the entire formatted message as a string.
        This includes the headers, body, and envelope header.
        )�	as_string)rDrrr�__str__�szMessage.__str__FrcCs6ddlm}t�}||d|d�}|j||d�|��S)aWReturn the entire formatted message as a (unicode) string.
        Optional `unixfrom' when True, means include the Unix From_ envelope
        header.

        This is a convenience method and may not generate the message exactly
        as you intend.  For more flexibility, use the flatten() method of a
        Generator instance.
        r)�	GeneratorF)�mangle_from_�maxheaderlen)�unixfrom)Z future.backports.email.generatorrIr�flatten�getvalue)rDrLrKrI�fp�grrrrG�s
	zMessage.as_stringcCst|jt�S)z6Return True if the message consists of multiple parts.)r"r>r)rDrrr�is_multipart�szMessage.is_multipartcCs
||_dS)N)r=)rDrLrrr�set_unixfrom�szMessage.set_unixfromcCs|jS)N)r=)rDrrr�get_unixfrom�szMessage.get_unixfromcCs$|jdkr|g|_n|j�|�dS)z�Add the given payload to the current payload.

        The current payload will always be a list of objects after this method
        is called.  If you want to set the payload to a scalar object, use
        set_payload() instead.
        N)r>r2)rD�payloadrrr�attach�s

zMessage.attachNcCs�|��r(|rdS|dkr|jS|j|S|dk	rNt|jt�sNtdt|j���|j}t|�dd����}t|t��rt|�}t	�
|�r�|�dd�}|s�y|�|�
dd�d�}Wn tk
r�|�dd�}YnXn6|�ry|�d�}Wn tk
�r|�d	�}YnX|�s|S|d
k�r&t	�|�S|dk�rhtd�|����\}}x|D]}|j�||��qLW|S|d
k�r�t|�}	t�}
ytj|	|
dd�|
��Stjk
�r�|SXt|t��r�|S|S)aZReturn a reference to the payload.

        The payload will either be a list object or a string.  If you mutate
        the list object, you modify the message's payload in place.  Optional
        i returns that index into the payload.

        Optional decode is a flag indicating whether the payload should be
        decoded or not, according to the Content-Transfer-Encoding header
        (default is False).

        When True and the message is not a multipart, the payload will be
        decoded if this header's value is `quoted-printable' or `base64'.  If
        some other encoding is used, or the header is missing, or if the
        payload has bogus data (i.e. bogus base64 or uuencoded data), the
        payload is returned as-is.

        If the message is a multipart and the decode flag is True, then None
        is returned.
        NzExpected list, got %szcontent-transfer-encodingr r�surrogateescaper�replacezraw-unicode-escapezquoted-printable�base64�)z
x-uuencode�uuencode�uuezx-uueT)�quiet)rQr>r"r�	TypeError�typer�getr1r
�_has_surrogatesr%�decode�	get_param�LookupError�UnicodeErrorZ_qdecoder�join�
splitlinesr;�
handle_defectr
�uurN�Error)rDr7rarT�cte�bpayloadr*rB�defect�in_file�out_filerrr�get_payload�sX"






zMessage.get_payloadcCs||_|dk	r|�|�dS)z�Set the payload to the given value.

        Optional charset sets the message's default character set.  See
        set_charset() for details.
        N)r>�set_charset)rDrTrrrr�set_payloadszMessage.set_payloadcCs�|dkr|�d�d|_dSt|t�s.t|�}||_d|krH|�dd�d|krf|jdd|��d�n|�d|���||��kr�|�|j�|_d|kr�|�	�}y||�Wn.t
k
r�|�|j�|_|�d|�YnXdS)	a�Set the charset of the payload to a given character set.

        charset can be a Charset instance, a string naming a character set, or
        None.  If it is a string it will be converted to a Charset instance.
        If charset is None, the charset parameter will be removed from the
        Content-Type field.  Anything else will generate a TypeError.

        The message will be assumed to be of type text/* encoded with
        charset.input_charset.  It will be converted to charset.output_charset
        and encoded properly, if needed, when generating the plain text
        representation of the message.  MIME headers (MIME-Version,
        Content-Type, Content-Transfer-Encoding) will be added as needed.
        NrzMIME-Versionz1.0zContent-Typez
text/plain)rzContent-Transfer-Encoding)�	del_paramr?r"�Charset�
add_header�get_output_charset�	set_param�body_encoder>�get_body_encodingr])rDrrjrrrrps,

zMessage.set_charsetcCs|jS)zKReturn the Charset instance associated with the message's payload.
        )r?)rDrrr�get_charsetEszMessage.get_charsetcCs
t|j�S)z9Return the total number of headers, including duplicates.)r!r<)rDrrr�__len__MszMessage.__len__cCs
|�|�S)a-Get a header value.

        Return None if the header is missing instead of raising an exception.

        Note that if the header appeared multiple times, exactly which
        occurrence gets returned is undefined.  Use get_all() to get all
        the values matching a header field name.
        )r_)rD�namerrr�__getitem__Qs	zMessage.__getitem__cCsv|j�|�}|r\|��}d}x>|jD]4\}}|��|kr$|d7}||kr$td�||���q$W|j�|j�||��dS)z�Set the value of a header.

        Note: this does not overwrite an existing header with the same field
        name.  Use __delitem__() first to delete any existing headers.
        rrz/There may be at most {} {} headers in a messageN)r;�header_max_countr1r<�
ValueError�formatr2�header_store_parse)rDr{�val�	max_count�lname�found�k�vrrr�__setitem__\szMessage.__setitem__cCsF|��}t�}x,|jD]"\}}|��|kr|�||f�qW||_dS)zwDelete all occurrences of a header, if present.

        Does not raise an exception if the header is missing.
        N)r1rr<r2)rDr{�
newheadersr�r�rrr�__delitem__nszMessage.__delitem__cCs|��dd�|jD�kS)NcSsg|]\}}|���qSr)r1)�.0r�r�rrr�
<listcomp>{sz(Message.__contains__.<locals>.<listcomp>)r1r<)rDr{rrr�__contains__zszMessage.__contains__ccsx|jD]\}}|VqWdS)N)r<)rD�fieldr*rrr�__iter__}szMessage.__iter__cCsdd�|jD�S)a.Return a list of all the message's header field names.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        cSsg|]\}}|�qSrr)r�r�r�rrrr��sz Message.keys.<locals>.<listcomp>)r<)rDrrr�keys�szMessage.keyscs�fdd��jD�S)a)Return a list of all the message's header values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        csg|]\}}�j�||��qSr)r;�header_fetch_parse)r�r�r�)rDrrr��sz"Message.values.<locals>.<listcomp>)r<)rDr)rDr�values�s
zMessage.valuescs�fdd��jD�S)a'Get all the message's header fields and values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        cs"g|]\}}|�j�||�f�qSr)r;r�)r�r�r�)rDrrr��sz!Message.items.<locals>.<listcomp>)r<)rDr)rDr�items�s
z
Message.itemscCs:|��}x,|jD]"\}}|��|kr|j�||�SqW|S)z~Get a header value.

        Like __getitem__() but return failobj instead of None when the field
        is missing.
        )r1r<r;r�)rDr{�failobjr�r�rrrr_�s
zMessage.getcCs|j�||f�dS)z�Store name and value in the model without modification.

        This is an "internal" API, intended only for use by a parser.
        N)r<r2)rDr{r*rrr�set_raw�szMessage.set_rawcCst|j���S)z�Return the (name, value) header pairs without modification.

        This is an "internal" API, intended only for use by a generator.
        )�iterr<�copy)rDrrr�	raw_items�szMessage.raw_itemscCsLg}|��}x2|jD](\}}|��|kr|�|j�||��qW|sH|S|S)aQReturn a list of all the values for the named field.

        These will be sorted in the order they appeared in the original
        message, and may contain duplicates.  Any fields deleted and
        re-inserted are always appended to the header list.

        If no such fields exist, failobj is returned (defaults to None).
        )r1r<r2r;r�)rDr{r�r�r�r�rrr�get_all�s	zMessage.get_allcKstg}xH|��D]<\}}|dkr2|�|�dd��q|�t|�dd�|��qW|dk	rb|�d|�t�|�||<dS)u�Extended header setting.

        name is the header field to add.  keyword arguments can be used to set
        additional parameters for the header field, with underscores converted
        to dashes.  Normally the parameter will be added as key="value" unless
        value is None, in which case only the key will be added.  If a
        parameter value contains non-ASCII characters it can be specified as a
        three-tuple of (charset, language, value), in which case it will be
        encoded according to RFC2231 rules.  Otherwise it will be encoded using
        the utf-8 charset and a language of ''.

        Examples:

        msg.add_header('content-disposition', 'attachment', filename='bud.gif')
        msg.add_header('content-disposition', 'attachment',
                       filename=('utf-8', '', 'Fußballer.ppt'))
        msg.add_header('content-disposition', 'attachment',
                       filename='Fußballer.ppt'))
        N�_�-r)r�r2rWr+�insert�	SEMISPACEre)rD�_name�_value�_params�partsr�r�rrrrt�szMessage.add_headercCs^|��}xPttt|j��|j�D].\}\}}|��|kr |j�||�|j|<Pq Wt|��dS)z�Replace a header.

        Replace the first matching header found in the message, retaining
        header order and case.  If no matching header was found, a KeyError is
        raised.
        N)r1rrr!r<r;r��KeyError)rDr�r�r7r�r�rrr�replace_header�s$zMessage.replace_headercCsHt�}|�d|�}||kr"|��St|�d��}|�d�dkrDdS|S)a0Return the message's content type.

        The returned string is coerced to lower case of the form
        `maintype/subtype'.  If there was no Content-Type header in the
        message, the default type as given by get_default_type() will be
        returned.  Since according to RFC 2045, messages always have a default
        type this will always return a value.

        RFC 2045 defines a message's default type to be text/plain unless it
        appears inside a multipart/digest container, in which case it would be
        message/rfc822.
        zcontent-typer�/rz
text/plain)�objectr_�get_default_typerr1r/)rD�missingr*�ctyperrr�get_content_types
zMessage.get_content_typecCs|��}|�d�dS)z�Return the message's main content type.

        This is the `maintype' part of the string returned by
        get_content_type().
        r�r)r��split)rDr�rrr�get_content_maintypeszMessage.get_content_maintypecCs|��}|�d�dS)z�Returns the message's sub-content type.

        This is the `subtype' part of the string returned by
        get_content_type().
        r�r)r�r�)rDr�rrr�get_content_subtype(szMessage.get_content_subtypecCs|jS)aReturn the `default' content type.

        Most messages have a default content type of text/plain, except for
        messages that are subparts of multipart/digest containers.  Such
        subparts have a default content type of message/rfc822.
        )rC)rDrrrr�1szMessage.get_default_typecCs
||_dS)z�Set the `default' content type.

        ctype should be either "text/plain" or "message/rfc822", although this
        is not enforced.  The default content type is not stored in the
        Content-Type header.
        N)rC)rDr�rrr�set_default_type:szMessage.set_default_typec		Cs�t�}|�||�}||kr|Sg}xdt|�D]X}y$|�dd�\}}|��}|��}Wn tk
rt|��}d}YnX|�||f�q,Wt�|�}|S)Nr-rr )	r�r_r8r�rr~r2r
�
decode_params)	rDr��headerr�r*�params�pr{r�rrr�_get_params_preserveCs 

zMessage._get_params_preserve�content-typeTcCs8t�}|�||�}||kr|S|r0dd�|D�S|SdS)amReturn the message's Content-Type parameters, as a list.

        The elements of the returned list are 2-tuples of key/value pairs, as
        split on the `=' sign.  The left hand side of the `=' is the key,
        while the right hand side is the value.  If there is no `=' sign in
        the parameter the value is the empty string.  The value is as
        described in the get_param() method.

        Optional failobj is the object to return if there is no Content-Type
        header.  Optional header is the header to search instead of
        Content-Type.  If unquote is True, the value is unquoted.
        cSsg|]\}}|t|�f�qSr)r:)r�r�r�rrrr�jsz&Message.get_params.<locals>.<listcomp>N)r�r�)rDr�r�r9r�r�rrr�
get_paramsXs
zMessage.get_paramscCsJ||kr|Sx8|�||�D](\}}|��|��kr|r>t|�S|SqW|S)aReturn the parameter value if found in the Content-Type header.

        Optional failobj is the object to return if there is no Content-Type
        header, or the Content-Type header has no such parameter.  Optional
        header is the header to search instead of Content-Type.

        Parameter keys are always compared case insensitively.  The return
        value can either be a string, or a 3-tuple if the parameter was RFC
        2231 encoded.  When it's a 3-tuple, the elements of the value are of
        the form (CHARSET, LANGUAGE, VALUE).  Note that both CHARSET and
        LANGUAGE can be None, in which case you should consider VALUE to be
        encoded in the us-ascii charset.  You can usually ignore LANGUAGE.
        The parameter value (either the returned string, or the VALUE item in
        the 3-tuple) is always unquoted, unless unquote is set to False.

        If your application doesn't care whether the parameter was RFC 2231
        encoded, it can turn the return value into a string as follows:

            param = msg.get_param('foo')
            param = email.utils.collapse_rfc2231_value(rawparam)

        )r�r1r:)rDrr�r�r9r�r�rrrrbnszMessage.get_param�Content-Typer cCs�t|t�s|r|||f}||kr2|��dkr2d}n
|�|�}|j||d�st|s\t|||�}q�t�|t|||�g�}nfd}x`|j||d�D]N\}}	d}
|��|��kr�t|||�}
nt||	|�}
|s�|
}q�t�||
g�}q�W||�|�kr�||=|||<dS)a�Set a parameter in the Content-Type header.

        If the parameter already exists in the header, its value will be
        replaced with the new value.

        If header is Content-Type and has not yet been defined for this
        message, it will be set to "text/plain" and the new parameter and
        value will be appended as per RFC 2045.

        An alternate header can specified in the header argument, and all
        parameters will be quoted as necessary unless requote is False.

        If charset is specified, the parameter will be encoded according to RFC
        2231.  Optional language specifies the RFC 2231 language, defaulting
        to the empty string.  Both charset and language should be strings.
        zcontent-typez
text/plain)r�r )r�r9N)	r"r#r1r_rbr+r�rer�)rDrr*r��requoter�languager��	old_param�	old_value�append_paramrrrrv�s.

zMessage.set_paramcCs�||krdSd}xR|j||d�D]@\}}|��|��kr |sJt|||�}q t�|t|||�g�}q W||�|�kr�||=|||<dS)a>Remove the given parameter completely from the Content-Type header.

        The header will be re-written in place without the parameter or its
        value. All values will be quoted as necessary unless requote is
        False.  Optional header specifies an alternative to the Content-Type
        header.
        Nr )r�r9)r�r1r+r�rer_)rDrr�r��	new_ctyper�r�rrrrr�szMessage.del_paramcCs�|�d�dkst�|��dkr,|d=d|d<||kr@|||<dS|j||d�}||=|||<x(|dd�D]\}}|�||||�qjWdS)	aKSet the main type and subtype for the Content-Type header.

        type must be a string in the form "maintype/subtype", otherwise a
        ValueError is raised.

        This method replaces the Content-Type header, keeping all the
        parameters in place.  If requote is False, this leaves the existing
        header's quoting as is.  Otherwise, the parameters will be quoted (the
        default).

        An alternative header can be specified in the header argument.  When
        the Content-Type header is set, we'll always also add a MIME-Version
        header.
        r�rzcontent-typezmime-versionz1.0zMIME-VersionN)r�r9)r/r~r1r�rv)rDr^r�r�r�r�r�rrr�set_type�szMessage.set_typecCsDt�}|�d|d�}||kr*|�d|d�}||kr6|St�|���S)a@Return the filename associated with the payload if present.

        The filename is extracted from the Content-Disposition header's
        `filename' parameter, and it is unquoted.  If that header is missing
        the `filename' parameter, this method falls back to looking for the
        `name' parameter.
        �filenamezcontent-dispositionr{zcontent-type)r�rbr
�collapse_rfc2231_valuer)rDr�r�r�rrr�get_filename�szMessage.get_filenamecCs,t�}|�d|�}||kr|St�|���S)z�Return the boundary associated with the payload if present.

        The boundary is extracted from the Content-Type header's `boundary'
        parameter, and it is unquoted.
        �boundary)r�rbr
r��rstrip)rDr�r�r�rrr�get_boundarys
zMessage.get_boundarycCs t�}|�|d�}||kr$t�d��g}d}xB|D]:\}}|��dkr^|�dd|f�d}q2|�||f�q2W|s�|�dd|f�g}x�|jD]�\}	}
|	��dk�rg}x6|D].\}}
|
dkr�|�|�q�|�d||
f�q�Wt�|�}
|�|j	�
|	|
��q�|�|	|
f�q�W||_d	S)
a�Set the boundary parameter in Content-Type to 'boundary'.

        This is subtly different than deleting the Content-Type header and
        adding a new one with a new boundary parameter via add_header().  The
        main difference is that using the set_boundary() method preserves the
        order of the Content-Type header in the original message.

        HeaderParseError is raised if the message has no Content-Type header.
        zcontent-typezNo Content-Type header foundFr�z"%s"Tr z%s=%sN)r�r�r�HeaderParseErrorr1r2r<r�rer;r�)rDr�r�r��	newparams�foundp�pk�pvr��hr�r�r�r�rrr�set_boundarys2


zMessage.set_boundaryc	Cs�t�}|�d|�}||kr|St|t�rr|dp2d}y|d�d�}t||�}Wn ttfk
rp|d}YnXy|�d�Wntk
r�|SX|��S)z�Return the charset parameter of the Content-Type header.

        The returned string is always coerced to lower case.  If there is no
        Content-Type header, or if that header has no charset parameter,
        failobj is returned.
        rrzus-asciirzraw-unicode-escape)	r�rbr"r#r%rrcrdr1)rDr�r�r�pcharset�as_bytesrrr�get_content_charsetAs 
zMessage.get_content_charsetcs�fdd�|��D�S)a�Return a list containing the charset(s) used in this message.

        The returned list of items describes the Content-Type headers'
        charset parameter for this message and all the subparts in its
        payload.

        Each item will either be a string (the value of the charset parameter
        in the Content-Type header of that part) or the value of the
        'failobj' parameter (defaults to None), if the part does not have a
        main MIME type of "text", or the charset is not defined.

        The list will contain one string for each part of the message, plus
        one for the container message (i.e. self), so that a non-multipart
        message will still return a list of length 1.
        csg|]}|����qSr)r�)r��part)r�rrr�osz(Message.get_charsets.<locals>.<listcomp>)�walk)rDr�r)r�r�get_charsets_szMessage.get_charsets)r�)Fr)NF)N)N)N)Nr�T)Nr�T)r�TNr )r�T)r�T)N)N)N)N)2�__name__�
__module__�__qualname__�__doc__rrErrHrGrQrRrSrUrorqrpryrzr|r�r�r�r�r�r�r�r_r�r�r�rtr�r�r�r�r�r�r�r�rbrvrrr�r�r�r�r�r�Z future.backports.email.iteratorsr�rrrrr	ms\

[

&


				

!
/

 


.

)NT)'r��
__future__rrrZfuture.builtinsrrrr�__all__�rerhrX�binascii�ior
rZfuture.utilsrZfuture.backports.emailr
rZ"future.backports.email._policybaserrr?Z%future.backports.email._encoded_wordsrrsr��compiler'rr+r8r:r�r	rrrr�<module>s,


"

Hacked By AnonymousFox1.0, Coded By AnonymousFox