Hacked By AnonymousFox

Current Path : /opt/alt/python36/lib64/python3.6/email/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/email/__pycache__/headerregistry.cpython-36.pyc

3

� f�O�@sjdZddlmZddlmZddlmZddlmZGdd�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'�Zeeeeeeeeeeeeeeeeeeed(�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�djtd||||f��}d|ks(d|kr0td��|dk	r�|s@|rHtd��tj|�\}}|rjtdj||���|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/python36/lib64/python3.6/email/headerregistry.py�__init__s"

zAddress.__init__cCs|jS)N)r)rrrrr<szAddress.display_namecCs|jS)N)r)rrrrr@szAddress.usernamecCs|jS)N)r)rrrrrDszAddress.domaincCsTt|j�}t|�t|tj�kr.tj|j�}n|j}|jrH|d|jS|sPdS|S)z�The addr_spec (username@domain) portion of the address, quoted
        according to RFC 5322 rules, but with no Content Transfer Encoding.
        �@z<>)�setr�lenrZ
DOT_ATOM_ENDS�quote_stringr)r�namesetZlprrrrHs
zAddress.addr_speccCsdj|jj|j|j|j�S)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r�	__class__�__name__rrr)rrrr�__repr__XszAddress.__repr__cCs^t|j�}t|�t|tj�kr.tj|j�}n|j}|rX|jdkrFdn|j}dj||�S|jS)Nz<>rz{} <{}>)rrr r�SPECIALSr!rr)rr"�disprrrr�__str__]s
zAddress.__str__cCs8t|�t|�krdS|j|jko6|j|jko6|j|jkS)NF)�typerrr)r�otherrrr�__eq__hs
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�	addressesrrrrrszGroup.__init__cCs|jS)N)r)rrrrr�szGroup.display_namecCs|jS)N)r1)rrrrr2�szGroup.addressescCsdj|jj|j|j�S)Nz${}(display_name={!r}, addresses={!r})rr#r$rr2)rrrrr%�szGroup.__repr__cCs�|jdkr&t|j�dkr&t|jd�S|j}|dk	r\t|�}t|�t|tj�kr\tj|�}djdd�|jD��}|r~d|n|}dj	||�S)N�rz, css|]}t|�VqdS)N)�str)�.0�xrrr�	<genexpr>�sz Group.__str__.<locals>.<genexpr>� z{}:{};)
rr r2r4rrr&r!r
r)rr'r"Zadrstrrrrr(�s
z
Group.__str__cCs,t|�t|�krdS|j|jko*|j|jkS)NF)r)rr2)rr*rrrr+�szGroup.__eq__)NN)
r$r,r-rr.rr2r%r(r+rrrrr/ps
r/c@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}|j||�tj|d�r4tj|d�|d<tj||d�}|d=|j|f|�|S)N�defects�decoded)�parserZ_has_surrogates�	_sanitizer4�__new__�init)�cls�name�value�kwdsrrrrr>�szBaseHeader.__new__cCs||_||_||_dS)N)�_name�_parse_tree�_defects)rrA�
parse_treer:rrrr?�szBaseHeader.initcCs|jS)N)rD)rrrrrA�szBaseHeader.namecCs
t|j�S)N)r0rF)rrrrr:�szBaseHeader.defectscCst|jj|jjt|�f|jfS)N)�_reconstruct_headerr#r$�	__bases__r4�__dict__)rrrr�
__reduce__�s
zBaseHeader.__reduce__cCstj||�S)N)r4r>)r@rBrrr�_reconstruct�szBaseHeader._reconstructcCs`tjtjtj|jd�tjdd�g�g�}|jrH|jtjtjdd�g��|j|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-sepr8Zfws)�policy)
rZHeaderZHeaderLabelZ
ValueTerminalrArE�appendZCFWSListZWhiteSpaceTerminal�fold)rrN�headerrrrrP�szBaseHeader.foldN)
r$r,r-�__doc__r>r?r.rAr:rK�classmethodrLrPrrrrr9�s 

r9cCst||i�j|�S)N)r)rL)Zcls_name�basesrBrrrrH
srHc@s&eZdZdZeej�Zedd��Z	dS)�UnstructuredHeaderNcCs"|j|�|d<t|d�|d<dS)NrGr;)�value_parserr4)r@rBrCrrrr<szUnstructuredHeader.parse)
r$r,r-�	max_count�staticmethodr�get_unstructuredrVrSr<rrrrrUs
rUc@seZdZdZdS)�UniqueUnstructuredHeaderr3N)r$r,r-rWrrrrrZsrZcsFeZdZdZdZeej�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|djtj��d|d<d|d<tj�|d<dSt|t�rJtj|�}||d<tj	|d�|d<|j
|d�|d<dS)Nr:�datetimerr;rG)rOrZHeaderMissingRequiredValuerZ	TokenList�
isinstancer4rZparsedate_to_datetimeZformat_datetimerV)r@rBrCrrrr<.s

zDateHeader.parsecs|jd�|_t�j||�dS)Nr\)�pop�	_datetime�superr?)r�args�kw)r#rrr?<szDateHeader.initcCs|jS)N)r_)rrrrr\@szDateHeader.datetime)r$r,r-rRrWrXrrYrVrSr<r?r.r\�
__classcell__rr)r#rr[s	
r[c@seZdZdZdS)�UniqueDateHeaderr3N)r$r,r-rWrrrrrdEsrdcsPeZdZdZedd��Zedd��Z�fdd�Ze	dd	��Z
e	d
d��Z�ZS)�
AddressHeaderNcCs tj|�\}}|std��|S)Nzthis should not happen)rZget_address_list�AssertionError)rB�address_listrrrrVNszAddressHeader.value_parsercCs�t|t�rZ|j|�|d<}g}x,|jD]"}|jt|jdd�|jD���q(Wt|j	�}n"t
|d�sj|g}dd�|D�}g}||d<||d<djd	d�|D��|d
<d|kr�|j|d
�|d<dS)NrGcSs*g|]"}t|jpd|jpd|jp"d��qS)r)rrrr)r5Zmbrrr�
<listcomp>]sz'AddressHeader.parse.<locals>.<listcomp>�__iter__cSs&g|]}t|d�std|g�n|�qS)r2N)�hasattrr/)r5�itemrrrrhfs�groupsr:z, cSsg|]}t|��qSr)r4)r5rkrrrrhlsr;)r]r4rVr2rOr/rZ
all_mailboxes�listrrjr
)r@rBrCrgrlZaddrr:rrrr<Ts$


zAddressHeader.parsecs(t|jd��|_d|_t�j||�dS)Nrl)r0r^�_groupsr1r`r?)rrarb)r#rrr?pszAddressHeader.initcCs|jS)N)rn)rrrrrluszAddressHeader.groupscCs&|jdkr tdd�|jD��|_|jS)NcSsg|]}|jD]}|�qqSr)r2)r5�group�addressrrrrh|sz+AddressHeader.addresses.<locals>.<listcomp>)r1r0rn)rrrrr2ys
zAddressHeader.addresses)
r$r,r-rWrXrVrSr<r?r.rlr2rcrr)r#rreJsrec@seZdZdZdS)�UniqueAddressHeaderr3N)r$r,r-rWrrrrrq�srqc@seZdZedd��ZdS)�SingleAddressHeadercCs(t|j�dkrtdj|j���|jdS)Nr3z9value of single address header {} is not a single addressr)r r2rrrA)rrrrrp�s
zSingleAddressHeader.addressN)r$r,r-r.rprrrrrr�srrc@seZdZdZdS)�UniqueSingleAddressHeaderr3N)r$r,r-rWrrrrrs�srscsZeZdZdZeej�Zedd��Z	�fdd�Z
edd��Zedd	��Z
ed
d��Z�ZS)�MIMEVersionHeaderr3cCs�|j|�|d<}t|�|d<|dj|j�|jdkr<dn|j|d<|j|d<|jdk	rtdj|d|d�|d<nd|d<dS)NrGr;r:�major�minorz{}.{}�version)rVr4�extendrrvrur)r@rBrCrGrrrr<�s

zMIMEVersionHeader.parsecs6|jd�|_|jd�|_|jd�|_t�j||�dS)Nrwrurv)r^�_version�_major�_minorr`r?)rrarb)r#rrr?�szMIMEVersionHeader.initcCs|jS)N)rz)rrrrru�szMIMEVersionHeader.majorcCs|jS)N)r{)rrrrrv�szMIMEVersionHeader.minorcCs|jS)N)ry)rrrrrw�szMIMEVersionHeader.version)r$r,r-rWrXrZparse_mime_versionrVrSr<r?r.rurvrwrcrr)r#rrt�s
rtcs8eZdZdZedd��Z�fdd�Zedd��Z�Z	S)�ParameterizedMIMEHeaderr3cCsZ|j|�|d<}t|�|d<|dj|j�|jdkrBi|d<ndd�|jD�|d<dS)NrGr;r:�paramscSs&i|]\}}tj|�tj|�j��qSr)rr=�lower)r5rArBrrr�
<dictcomp>�sz1ParameterizedMIMEHeader.parse.<locals>.<dictcomp>)rVr4rxrr})r@rBrCrGrrrr<�s

zParameterizedMIMEHeader.parsecs|jd�|_t�j||�dS)Nr})r^�_paramsr`r?)rrarb)r#rrr?�szParameterizedMIMEHeader.initcCs
t|j�S)N)rr�)rrrrr}�szParameterizedMIMEHeader.params)
r$r,r-rWrSr<r?r.r}rcrr)r#rr|�s
r|csJeZdZeej�Z�fdd�Zedd��Z	edd��Z
edd��Z�ZS)	�ContentTypeHeadercs2t�j||�tj|jj�|_tj|jj�|_dS)N)	r`r?rr=rE�maintype�	_maintype�subtype�_subtype)rrarb)r#rrr?�szContentTypeHeader.initcCs|jS)N)r�)rrrrr��szContentTypeHeader.maintypecCs|jS)N)r�)rrrrr��szContentTypeHeader.subtypecCs|jd|jS)N�/)r�r�)rrrr�content_type�szContentTypeHeader.content_type)
r$r,r-rXrZparse_content_type_headerrVr?r.r�r�r�rcrr)r#rr��s

r�cs2eZdZeej�Z�fdd�Zedd��Z	�Z
S)�ContentDispositionHeadercs2t�j||�|jj}|dkr"|ntj|�|_dS)N)r`r?rE�content_dispositionrr=�_content_disposition)rrarbZcd)r#rrr?�szContentDispositionHeader.initcCs|jS)N)r�)rrrrr��sz,ContentDispositionHeader.content_disposition)r$r,r-rXrZ parse_content_disposition_headerrVr?r.r�rcrr)r#rr��s
r�csBeZdZdZeej�Zedd��Z	�fdd�Z
edd��Z�Z
S)�ContentTransferEncodingHeaderr3cCs2|j|�|d<}t|�|d<|dj|j�dS)NrGr;r:)rVr4rxr)r@rBrCrGrrrr<sz#ContentTransferEncodingHeader.parsecs"t�j||�tj|jj�|_dS)N)r`r?rr=rE�cte�_cte)rrarb)r#rrr?sz"ContentTransferEncodingHeader.initcCs|jS)N)r�)rrrrr�sz!ContentTransferEncodingHeader.cte)r$r,r-rWrXrZ&parse_content_transfer_encoding_headerrVrSr<r?r.r�rcrr)r#rr��s

r�)ZsubjectZdatezresent-datez	orig-dateZsenderz
resent-senderZtoz	resent-toZccz	resent-ccZbccz
resent-bcc�fromzresent-fromzreply-tozmime-versionzcontent-typezcontent-dispositionzcontent-transfer-encodingc@s8eZdZdZeedfdd�Zdd�Zdd�Zd	d
�Z	dS)�HeaderRegistryz%A header_factory and header registry.TcCs&i|_||_||_|r"|jjt�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_maprrrr,s
zHeaderRegistry.__init__cCs||j|j�<dS)zLRegister cls as the specialized class for handling "name" headers.

        N)r�r~)rrAr@rrr�map_to_type>szHeaderRegistry.map_to_typecCs,|jj|j�|j�}td|j||jfi�S)N�_)r��getr~r�r)r$r�)rrAr@rrr�__getitem__DszHeaderRegistry.__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)rrArBrrr�__call__Hs
zHeaderRegistry.__call__N)
r$r,r-rRr9rUrr�r�r�rrrrr�(sr�N)rR�typesrZemailrrrrrr/r4r9rHrUrZr[rdrerqrrrsrtr|r�r�r�r�r�rrrr�<module>	sR`6d'7
%

Hacked By AnonymousFox1.0, Coded By AnonymousFox