AlkantarClanX12

Your IP : 3.149.23.124


Current Path : /proc/self/root/opt/alt/python39/lib64/python3.9/email/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python39/lib64/python3.9/email/__pycache__/headerregistry.cpython-39.pyc

a

R�f�P�@szdZddlmZddlmZddlmZddlmZGdd�d�ZGdd	�d	�Z	Gd
d�de
�Zdd
�ZGdd�d�Z
Gdd�de
�ZGdd�d�ZGdd�de�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�d�ZGd d!�d!�ZGd"d#�d#e�ZGd$d%�d%e�ZGd&d'�d'�ZGd(d)�d)�Zeeeeeeeeeeeeeeeeeeeed*�ZGd+d,�d,�Zd-S).a;Representing and manipulating email headers via custom objects.

This module provides an implementation of the HeaderRegistry API.
The implementation is designed to flexibly follow RFC5322 rules.

Eventually HeaderRegistry will be a public API, but it isn't yet,
and will probably change some before that happens.

�)�MappingProxyType)�utils)�errors)�_header_value_parserc@s^eZdZddd�Zedd��Zedd��Zed	d
��Zedd��Zd
d�Z	dd�Z
dd�ZdS)�Address�NcCs�d�td||||f��}d|vs(d|vr0td��|dur�|s@|rHtd��t�|�\}}|rjtd�||���|jrz|jd�|j}|j	}||_
||_||_dS)	a�Create an object representing a full email address.

        An address can have a 'display_name', a 'username', and a 'domain'.  In
        addition to specifying the username and domain separately, they may be
        specified together by using the addr_spec keyword *instead of* the
        username and domain keywords.  If an addr_spec string is specified it
        must be properly quoted according to RFC 5322 rules; an error will be
        raised if it is not.

        An Address object has display_name, username, domain, and addr_spec
        attributes, all of which are read-only.  The addr_spec and the string
        value of the object are both quoted according to RFC5322 rules, but
        without any Content Transfer Encoding.

        rN�
�
z8invalid arguments; address parts cannot contain CR or LFz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r)
�join�filter�
ValueError�	TypeError�parserZ
get_addr_spec�format�all_defects�
local_part�domain�
_display_name�	_username�_domain)�self�display_name�usernamer�	addr_specZinputsZa_s�rest�r�9/opt/alt/python39/lib64/python3.9/email/headerregistry.py�__init__s$�
zAddress.__init__cCs|jS�N�r�rrrrr<szAddress.display_namecCs|jSr)rr rrrr@szAddress.usernamecCs|jSr)rr rrrrDszAddress.domaincCs<|j}tj�|�st�|�}|jr0|d|jS|s8dS|S)z�The addr_spec (username@domain) portion of the address, quoted
        according to RFC 5322 rules, but with no Content Transfer Encoding.
        �@�<>)rrZ
DOT_ATOM_ENDS�
isdisjoint�quote_stringr)rZlprrrrHs
zAddress.addr_speccCsd�|jj|j|j|j�S)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r�	__class__�__name__rrrr rrr�__repr__Vs�zAddress.__repr__cCsF|j}tj�|�st�|�}|r@|jdkr.dn|j}d�||�S|jS)Nr"rz{} <{}>)rr�SPECIALSr#r$rr)r�disprrrr�__str__[s
zAddress.__str__cCs2t|t�stS|j|jko0|j|jko0|j|jkSr)�
isinstancer�NotImplementedrrr�r�otherrrr�__eq__ds

�
�zAddress.__eq__)rrrN)r&�
__module__�__qualname__r�propertyrrrrr'r*r/rrrrrs
*




	rc@sFeZdZddd�Zedd��Zedd��Zdd	�Zd
d�Zdd
�Z	dS)�GroupNcCs||_|rt|�nt�|_dS)aCreate an object representing an address group.

        An address group consists of a display_name followed by colon and a
        list of addresses (see Address) terminated by a semi-colon.  The Group
        is created by specifying a display_name and a possibly empty list of
        Address objects.  A Group can also be used to represent a single
        address that is not in a group, which is convenient when manipulating
        lists that are a combination of Groups and individual Addresses.  In
        this case the display_name should be set to None.  In particular, the
        string representation of a Group whose display_name is None is the same
        as the Address object, if there is one and only one Address object in
        the addresses list.

        N)r�tuple�
_addresses)rr�	addressesrrrrnszGroup.__init__cCs|jSrrr rrrr�szGroup.display_namecCs|jSr)r5r rrrr6�szGroup.addressescCsd�|jj|j|j�S)Nz${}(display_name={!r}, addresses={!r})rr%r&rr6r rrrr'�s�zGroup.__repr__cCs||jdur&t|j�dkr&t|jd�S|j}|durJtj�|�sJt�|�}d�dd�|jD��}|rld|n|}d�	||�S)N�r�, css|]}t|�VqdSr��str)�.0�xrrr�	<genexpr>��z Group.__str__.<locals>.<genexpr>� z{}:{};)
r�lenr6r:rr(r#r$r
r)rr)Zadrstrrrrr*�s
z
Group.__str__cCs&t|t�stS|j|jko$|j|jkSr)r+r3r,rr6r-rrrr/�s


�zGroup.__eq__)NN)
r&r0r1rr2rr6r'r*r/rrrrr3ls



r3c@sTeZdZdZdd�Zdd�Zedd��Zedd	��Zd
d�Z	e
dd
��Zdd�ZdS)�
BaseHeadera|Base class for message headers.

    Implements generic behavior and provides tools for subclasses.

    A subclass must define a classmethod named 'parse' that takes an unfolded
    value string and a dictionary as its arguments.  The dictionary will
    contain one key, 'defects', initialized to an empty list.  After the call
    the dictionary must contain two additional keys: parse_tree, set to the
    parse tree obtained from parsing the header, and 'decoded', set to the
    string value of the idealized representation of the data from the value.
    (That is, encoded words are decoded, and values that have canonical
    representations are so represented.)

    The defects key is intended to collect parsing defects, which the message
    parser will subsequently dispose of as appropriate.  The parser should not,
    insofar as practical, raise any errors.  Defects should be added to the
    list instead.  The standard header parsers register defects for RFC
    compliance issues, for obsolete RFC syntax, and for unrecoverable parsing
    errors.

    The parse method may add additional keys to the dictionary.  In this case
    the subclass must define an 'init' method, which will be passed the
    dictionary as its keyword arguments.  The method should use (usually by
    setting them as the value of similarly named attributes) and remove all the
    extra keys added by its parse method, and then use super to call its parent
    class with the remaining arguments and keywords.

    The subclass should also make sure that a 'max_count' attribute is defined
    that is either None or 1. XXX: need to better define this API.

    cCs`dgi}|�||�t�|d�r4t�|d�|d<t�||d�}|d=|j|fi|��|S)N�defects�decoded)�parserZ_has_surrogates�	_sanitizer:�__new__�init)�cls�name�value�kwdsrrrrrF�szBaseHeader.__new__cCs||_||_||_dSr)�_name�_parse_tree�_defects)rrI�
parse_treerBrrrrG�szBaseHeader.initcCs|jSr)rLr rrrrI�szBaseHeader.namecCs
t|j�Sr)r4rNr rrrrB�szBaseHeader.defectscCst|jj|jjt|�f|jfSr)�_reconstruct_headerr%r&�	__bases__r:�__dict__r rrr�
__reduce__�s��zBaseHeader.__reduce__cCst�||�Sr)r:rF)rHrJrrr�_reconstruct�szBaseHeader._reconstructc	Cs`t�t�t�|jd�t�dd�g�g�}|jrH|�t�t�dd�g��|�|j�|j	|d�S)atFold header according to policy.

        The parsed representation of the header is folded according to
        RFC5322 rules, as modified by the policy.  If the parse tree
        contains surrogateescaped bytes, the bytes are CTE encoded using
        the charset 'unknown-8bit".

        Any non-ASCII characters in the parse tree are CTE encoded using
        charset utf-8. XXX: make this a policy setting.

        The returned value is an ASCII-only string possibly containing linesep
        characters, and ending with a linesep character.  The string includes
        the header name and the ': ' separator.

        zheader-name�:z
header-sepr?Zfws)�policy)
rZHeaderZHeaderLabelZ
ValueTerminalrIrM�appendZCFWSListZWhiteSpaceTerminal�fold)rrV�headerrrrrX�s
���zBaseHeader.foldN)
r&r0r1�__doc__rFrGr2rIrBrS�classmethodrTrXrrrrrA�s 




rAcCst||i��|�Sr)�typerT)�cls_name�basesrJrrrrPsrPc@s&eZdZdZeej�Zedd��Z	dS)�UnstructuredHeaderNcCs"|�|�|d<t|d�|d<dS)NrOrC)�value_parserr:�rHrJrKrrrrD
szUnstructuredHeader.parse)
r&r0r1�	max_count�staticmethodr�get_unstructuredr`r[rDrrrrr_s
r_c@seZdZdZdS)�UniqueUnstructuredHeaderr7N�r&r0r1rbrrrrresrecsFeZdZdZdZeej�Ze	dd��Z
�fdd�Zedd��Z
�ZS)	�
DateHeadera�Header whose value consists of a single timestamp.

    Provides an additional attribute, datetime, which is either an aware
    datetime using a timezone, or a naive datetime if the timezone
    in the input string is -0000.  Also accepts a datetime as input.
    The 'value' attribute is the normalized form of the timestamp,
    which means it is the output of format_datetime on the datetime.
    NcCsz|s6|d�t���d|d<d|d<t��|d<dSt|t�rJt�|�}||d<t�	|d�|d<|�
|d�|d<dS)NrB�datetimerrCrO)rWrZHeaderMissingRequiredValuerZ	TokenListr+r:rZparsedate_to_datetimeZformat_datetimer`rarrrrD(s

zDateHeader.parsecs"|�d�|_t�j|i|��dS)Nrh)�pop�	_datetime�superrG�r�args�kw�r%rrrG6szDateHeader.initcCs|jSr)rjr rrrrh:szDateHeader.datetime)r&r0r1rZrbrcrrdr`r[rDrGr2rh�
__classcell__rrrorrgs	


rgc@seZdZdZdS)�UniqueDateHeaderr7Nrfrrrrrq?srqcsPeZdZdZedd��Zedd��Z�fdd�Ze	dd	��Z
e	d
d��Z�ZS)�
AddressHeaderNcCst�|�\}}|rJd��|S)Nzthis should not happen)rZget_address_list)rJ�address_listrrrr`HszAddressHeader.value_parsercCs�t|t�rV|�|�|d<}g}|jD]"}|�t|jdd�|jD���q&t|j	�}n"t
|d�sf|g}dd�|D�}g}||d<||d<d�d	d�|D��|d
<d|vr�|�|d
�|d<dS)NrOcSs*g|]"}t|jpd|jpd|jp"d��qS)r)rrrr)r;Zmbrrr�
<listcomp>Ws
�
�z'AddressHeader.parse.<locals>.<listcomp>�__iter__cSs&g|]}t|d�std|g�n|�qS)r6N)�hasattrr3�r;�itemrrrrt`s��groupsrBr8cSsg|]}t|��qSrr9rwrrrrtfr>rC)r+r:r`r6rWr3rZ
all_mailboxes�listrrvr
)rHrJrKrsryZaddrrBrrrrDNs*


��
�zAddressHeader.parsecs,t|�d��|_d|_t�j|i|��dS)Nry)r4ri�_groupsr5rkrGrlrorrrGjszAddressHeader.initcCs|jSr)r{r rrrryoszAddressHeader.groupscCs&|jdur tdd�|jD��|_|jS)Ncss|]}|jD]
}|VqqdSr)r6)r;�group�addressrrrr=vs
�z*AddressHeader.addresses.<locals>.<genexpr>)r5r4r{r rrrr6ss
zAddressHeader.addresses)
r&r0r1rbrcr`r[rDrGr2ryr6rprrrorrrDs


rrc@seZdZdZdS)�UniqueAddressHeaderr7Nrfrrrrr~{sr~c@seZdZedd��ZdS)�SingleAddressHeadercCs(t|j�dkrtd�|j���|jdS)Nr7z9value of single address header {} is not a single addressr)r@r6rrrIr rrrr}�s
�zSingleAddressHeader.addressN)r&r0r1r2r}rrrrr�src@seZdZdZdS)�UniqueSingleAddressHeaderr7Nrfrrrrr��sr�csZeZdZdZeej�Zedd��Z	�fdd�Z
edd��Zedd	��Z
ed
d��Z�ZS)�MIMEVersionHeaderr7cCs�|�|�|d<}t|�|d<|d�|j�|jdur<dn|j|d<|j|d<|jdurtd�|d|d�|d<nd|d<dS)NrOrCrB�major�minorz{}.{}�version)r`r:�extendrr�r�r�rHrJrKrOrrrrD�s

zMIMEVersionHeader.parsecs:|�d�|_|�d�|_|�d�|_t�j|i|��dS)Nr�r�r�)ri�_version�_major�_minorrkrGrlrorrrG�szMIMEVersionHeader.initcCs|jSr)r�r rrrr��szMIMEVersionHeader.majorcCs|jSr)r�r rrrr��szMIMEVersionHeader.minorcCs|jSr)r�r rrrr��szMIMEVersionHeader.version)r&r0r1rbrcrZparse_mime_versionr`r[rDrGr2r�r�r�rprrrorr��s



r�cs8eZdZdZedd��Z�fdd�Zedd��Z�Z	S)�ParameterizedMIMEHeaderr7cCsZ|�|�|d<}t|�|d<|d�|j�|jdurBi|d<ndd�|jD�|d<dS)NrOrCrB�paramscSs&i|]\}}t�|���t�|��qSr)rrE�lower)r;rIrJrrr�
<dictcomp>�s�z1ParameterizedMIMEHeader.parse.<locals>.<dictcomp>)r`r:r�rr�r�rrrrD�s

�zParameterizedMIMEHeader.parsecs"|�d�|_t�j|i|��dS)Nr�)ri�_paramsrkrGrlrorrrG�szParameterizedMIMEHeader.initcCs
t|j�Sr)rr�r rrrr��szParameterizedMIMEHeader.params)
r&r0r1rbr[rDrGr2r�rprrrorr��s
r�csJeZdZeej�Z�fdd�Zedd��Z	edd��Z
edd��Z�ZS)	�ContentTypeHeadercs6t�j|i|��t�|jj�|_t�|jj�|_dSr)	rkrGrrErM�maintype�	_maintype�subtype�_subtyperlrorrrG�szContentTypeHeader.initcCs|jSr)r�r rrrr��szContentTypeHeader.maintypecCs|jSr)r�r rrrr��szContentTypeHeader.subtypecCs|jd|jS)N�/)r�r�r rrr�content_type�szContentTypeHeader.content_type)
r&r0r1rcrZparse_content_type_headerr`rGr2r�r�r�rprrrorr��s


r�cs2eZdZeej�Z�fdd�Zedd��Z	�Z
S)�ContentDispositionHeadercs6t�j|i|��|jj}|dur&|nt�|�|_dSr)rkrGrM�content_dispositionrrE�_content_disposition)rrmrnZcdrorrrG�szContentDispositionHeader.initcCs|jSr)r�r rrrr��sz,ContentDispositionHeader.content_disposition)r&r0r1rcrZ parse_content_disposition_headerr`rGr2r�rprrrorr��s
r�csBeZdZdZeej�Zedd��Z	�fdd�Z
edd��Z�Z
S)�ContentTransferEncodingHeaderr7cCs2|�|�|d<}t|�|d<|d�|j�dS�NrOrCrB�r`r:r�rr�rrrrD�sz#ContentTransferEncodingHeader.parsecs&t�j|i|��t�|jj�|_dSr)rkrGrrErM�cte�_cterlrorrrGsz"ContentTransferEncodingHeader.initcCs|jSr)r�r rrrr�sz!ContentTransferEncodingHeader.cte)r&r0r1rbrcrZ&parse_content_transfer_encoding_headerr`r[rDrGr2r�rprrrorr��s

r�c@s&eZdZdZeej�Zedd��Z	dS)�MessageIDHeaderr7cCs2|�|�|d<}t|�|d<|d�|j�dSr�r�r�rrrrDszMessageIDHeader.parseN)
r&r0r1rbrcrZparse_message_idr`r[rDrrrrr�
s
r�)Zsubject�datezresent-datez	orig-dateZsenderz
resent-sender�toz	resent-toZccz	resent-ccZbccz
resent-bcc�fromzresent-fromzreply-tozmime-versionzcontent-typezcontent-dispositionzcontent-transfer-encodingz
message-idc@s8eZdZdZeedfdd�Zdd�Zdd�Zd	d
�Z	dS)�HeaderRegistryz%A header_factory and header registry.TcCs&i|_||_||_|r"|j�t�dS)a�Create a header_factory that works with the Policy API.

        base_class is the class that will be the last class in the created
        header class's __bases__ list.  default_class is the class that will be
        used if "name" (see __call__) does not appear in the registry.
        use_default_map controls whether or not the default mapping of names to
        specialized classes is copied in to the registry when the factory is
        created.  The default is True.

        N)�registry�
base_class�
default_class�update�_default_header_map)rr�r�Zuse_default_maprrrr3s
zHeaderRegistry.__init__cCs||j|��<dS)zLRegister cls as the specialized class for handling "name" headers.

        N)r�r��rrIrHrrr�map_to_typeEszHeaderRegistry.map_to_typecCs,|j�|��|j�}td|j||jfi�S)N�_)r��getr�r�r\r&r�r�rrr�__getitem__KszHeaderRegistry.__getitem__cCs||||�S)a�Create a header instance for header 'name' from 'value'.

        Creates a header instance by creating a specialized class for parsing
        and representing the specified header by combining the factory
        base_class with a specialized class from the registry or the
        default_class, and passing the name and value to the constructed
        class's constructor.

        r)rrIrJrrr�__call__Os
zHeaderRegistry.__call__N)
r&r0r1rZrAr_rr�r�r�rrrrr�/s�
r�N)rZ�typesrZemailrrrrrr3r:rArPr_rergrqrrr~rr�r�r�r�r�r�r�r�r�rrrr�<module>sX	\4d'7
%�