AlkantarClanX12

Your IP : 18.117.172.189


Current Path : /lib64/python3.8/email/__pycache__/
Upload File :
Current File : //lib64/python3.8/email/__pycache__/policy.cpython-38.pyc

U

e5d�(�@s�dZddlZddlZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	d
ddd
ddgZe�d�ZeGdd�de��Ze�Ze`ejdd�Zejdd�Zejddd�Zejdd�ZdS)zcThis will be the home for the policy that hooks in the new
code that adds all the email6 features.
�N)�Policy�Compat32�compat32�_extend_docstrings)�_has_surrogates)�HeaderRegistry)�raw_data_manager)�EmailMessagerrr�EmailPolicy�default�strict�SMTP�HTTPz\n|\rcspeZdZdZeZdZdZe�Z	e
Z�fdd�Zdd�Z
dd	�Zd
d�Zdd
�Zdd�Zdd�Zddd�Z�ZS)r
aQ+
    PROVISIONAL

    The API extensions enabled by this policy are currently provisional.
    Refer to the documentation for details.

    This policy adds new header parsing and folding algorithms.  Instead of
    simple strings, headers are custom objects with custom attributes
    depending on the type of the field.  The folding algorithm fully
    implements RFCs 2047 and 5322.

    In addition to the settable attributes listed above that apply to
    all Policies, this policy adds the following additional attributes:

    utf8                -- if False (the default) message headers will be
                           serialized as ASCII, using encoded words to encode
                           any non-ASCII characters in the source strings.  If
                           True, the message headers will be serialized using
                           utf8 and will not contain encoded words (see RFC
                           6532 for more on this serialization format).

    refold_source       -- if the value for a header in the Message object
                           came from the parsing of some source, this attribute
                           indicates whether or not a generator should refold
                           that value when transforming the message back into
                           stream form.  The possible values are:

                           none  -- all source values use original folding
                           long  -- source values that have any line that is
                                    longer than max_line_length will be
                                    refolded
                           all  -- all values are refolded.

                           The default is 'long'.

    header_factory      -- a callable that takes two arguments, 'name' and
                           'value', where 'name' is a header field name and
                           'value' is an unfolded header field value, and
                           returns a string-like object that represents that
                           header.  A default header_factory is provided that
                           understands some of the RFC5322 header field types.
                           (Currently address fields and date fields have
                           special treatment, while all other fields are
                           treated as unstructured.  This list will be
                           completed before the extension is marked stable.)

    content_manager     -- an object with at least two methods: get_content
                           and set_content.  When the get_content or
                           set_content method of a Message object is called,
                           it calls the corresponding method of this object,
                           passing it the message object as its first argument,
                           and any arguments or keywords that were passed to
                           it as additional arguments.  The default
                           content_manager is
                           :data:`~email.contentmanager.raw_data_manager`.

    F�longcs*d|krt�|dt��t�jf|�dS)N�header_factory)�object�__setattr__r�super�__init__)�self�kw��	__class__��$/usr/lib64/python3.8/email/policy.pyr]szEmailPolicy.__init__cCs|j|jS)z�+
        The implementation for this class returns the max_count attribute from
        the specialized header class that would be used to construct a header
        of type 'name'.
        )rZ	max_count)r�namerrr�header_max_countdszEmailPolicy.header_max_countcCs>|d�dd�\}}|�d�d�|dd��}||�d�fS)ac+
        The name is parsed as everything up to the ':' and returned unmodified.
        The value is determined by stripping leading whitespace off the
        remainder of the first line, joining all subsequent lines together, and
        stripping any trailing carriage return or linefeed characters.  (This
        is the same as Compat32).

        r�:�z 	�N�
)�split�lstrip�join�rstrip)rZsourcelinesr�valuerrr�header_source_parsevs	zEmailPolicy.header_source_parsecCsVt|d�r$|j��|��kr$||fSt|t�rFt|���dkrFtd��||�||�fS)a�+
        The name is returned unchanged.  If the input value has a 'name'
        attribute and it matches the name ignoring case, the value is returned
        unchanged.  Otherwise the name and value are passed to header_factory
        method, and the resulting custom header object is returned as the
        value.  In this case a ValueError is raised if the input value contains
        CR or LF characters.

        rrzDHeader values may not contain linefeed or carriage return characters)	�hasattrr�lower�
isinstance�str�len�
splitlines�
ValueErrorr�rrr%rrr�header_store_parse�s

zEmailPolicy.header_store_parsecCs*t|d�r|Sd�t�|��}|�||�S)ai+
        If the value has a 'name' attribute, it is returned to unmodified.
        Otherwise the name and the value with any linesep characters removed
        are passed to the header_factory method, and the resulting custom
        header object is returned.  Any surrogateescaped bytes get turned
        into the unicode unknown-character glyph.

        rr)r'r#�linesep_splitterr!rr.rrr�header_fetch_parse�s	
zEmailPolicy.header_fetch_parsecCs|j||dd�S)a+
        Header folding is controlled by the refold_source policy setting.  A
        value is considered to be a 'source value' if and only if it does not
        have a 'name' attribute (having a 'name' attribute means it is a header
        object of some sort).  If a source value needs to be refolded according
        to the policy, it is converted into a custom header object by passing
        the name and the value with any linesep characters removed to the
        header_factory method.  Folding of a custom header object is done by
        calling its fold method with the current policy.

        Source values are split into lines using splitlines.  If the value is
        not to be refolded, the lines are rejoined using the linesep from the
        policy and returned.  The exception is lines containing non-ascii
        binary data.  In that case the value is refolded regardless of the
        refold_source setting, which causes the binary data to be CTE encoded
        using the unknown-8bit charset.

        T��
refold_binary)�_foldr.rrr�fold�szEmailPolicy.foldcCs0|j|||jdkd�}|jr dnd}|�|d�S)a+
        The same as fold if cte_type is 7bit, except that the returned value is
        bytes.

        If cte_type is 8bit, non-ASCII binary data is converted back into
        bytes.  Headers with binary data are not refolded, regardless of the
        refold_header setting, since there is no way to know whether the binary
        data consists of single byte characters or multibyte characters.

        If utf8 is true, headers are encoded to utf8, otherwise to ascii with
        non-ASCII unicode rendered as encoded words.

        Z7bitr2�utf8�ascii�surrogateescape)r4Zcte_typer6�encode)rrr%Zfolded�charsetrrr�fold_binary�szEmailPolicy.fold_binarycs�t|d�r|j|d�S|jr"|jntj�|��}|jdkp�|jdko�|rdt|d�t|�d�kp�t�fdd�|d	d�D��}|s�|r�t	|�r�|�
|d
�|��j|d�S|d|j�|�|jS)Nr)Zpolicy�allrr�c3s|]}t|��kVqdS)N)r+)�.0�x��maxlenrr�	<genexpr>�sz$EmailPolicy._fold.<locals>.<genexpr>rrz: )
r'r5�max_line_length�sys�maxsizer,�
refold_sourcer+�anyrrr#�linesep)rrr%r3�linesZrefoldrr@rr4�s


 �zEmailPolicy._fold)F)�__name__�
__module__�__qualname__�__doc__r	Zmessage_factoryr6rFrrrZcontent_managerrrr&r/r1r5r;r4�
__classcell__rrrrr
s:
T)Zraise_on_defectr )rH)rHrC)r6)rM�rerDZemail._policybaserrrrZemail.utilsrZemail.headerregistryrZemail.contentmanagerrZ
email.messager	�__all__�compiler0r
rrZclonerr
rZSMTPUTF8rrrr�<module>s4�
@