AlkantarClanX12

Your IP : 3.16.135.226


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



��Yf�N�&@s)dZddlmZddlmZddlmZddlmZGdd�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'�Zd(ed)ed*ed+ed,ed-ed.ed/ed0ed1ed2ed3ed4ed5ed6ed7ed8ed9ed:eiZGd;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�eZdZdddddd�Zedd��Zedd��Zed	d
��Zedd��Zd
d�Z	dd�Z
dd�ZdS)�Address�NcCs�|dk	r|s|r$td��tj|�\}}|rWtdj||���|jrm|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.

        Nz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r)�	TypeError�parserZ
get_addr_spec�
ValueError�format�all_defects�
local_part�domain�
_display_name�	_username�_domain)�self�display_name�usernamer�	addr_specZa_s�rest�r�9/opt/alt/python35/lib64/python3.5/email/headerregistry.py�__init__s		
				zAddress.__init__cCs|jS)N)r)rrrrr7szAddress.display_namecCs|jS)N)r)rrrrr;szAddress.usernamecCs|jS)N)r)rrrrr?szAddress.domaincCsrt|j�}t|�t|tj�krCtj|j�}n	|j}|jrd|d|jS|sndS|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�lenr	Z
DOT_ATOM_ENDS�quote_stringr)r�namesetZlprrrrCs		zAddress.addr_speccCs%dj|jj|j|j|j�S)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r�	__class__�__name__rrr)rrrr�__repr__Ss	zAddress.__repr__cCs�t|j�}t|�t|tj�krCtj|j�}n	|j}|r�|jdkrgdn|j}dj||�S|jS)Nz<>rz{} <{}>)rrrr	�SPECIALSrrr)rr�disprrrr�__str__Xs	zAddress.__str__cCsPt|�t|�krdS|j|jkoO|j|jkoO|j|jkS)NF)�typerrr)r�otherrrr�__eq__cs
zAddress.__eq__)r �
__module__�__qualname__r�propertyrrrrr!r$r'rrrrrs%rc@sjeZdZdddd�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�	addressesrrrrms	zGroup.__init__cCs|jS)N)r)rrrrrszGroup.display_namecCs|jS)N)r-)rrrrr.�szGroup.addressescCsdj|jj|j|j�S)Nz${}(display_name={!r}, addresses={!r})rrr rr.)rrrrr!�s	zGroup.__repr__cCs�|jdkr5t|j�dkr5t|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{}:{};)
rrr.r0rr	r"r�joinr)rr#rZadrstrrrrr$�s$	z
Group.__str__cCs>t|�t|�krdS|j|jko=|j|jkS)NF)r%rr.)rr&rrrr'�szGroup.__eq__)
r r(r)rr*rr.r!r$r'rrrrr+ksr+c@s|eZdZdZdd�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.

    cCswdgi}|j||�tj|d�rFtj|d�|d<tj||d�}|d=|j||�|S)N�defects�decoded)�parserZ_has_surrogates�	_sanitizer0�__new__�init)�cls�name�value�kwdsrrrrr;�szBaseHeader.__new__cCs||_||_||_dS)N)�_name�_parse_tree�_defects)rr>�
parse_treer7rrrr<�s		zBaseHeader.initcCs|jS)N)rA)rrrrr>�szBaseHeader.namecCs
t|j�S)N)r,rC)rrrrr7�szBaseHeader.defectscCs+t|jj|jjt|�f|jfS)N)�_reconstruct_headerrr �	__bases__r0�__dict__)rrrr�
__reduce__�s
		zBaseHeader.__reduce__cCstj||�S)N)r0r;)r=r?rrr�_reconstruct�szBaseHeader._reconstructcCsmtjtjtj|jd�tjdd�g�tjtjdd�g�|jg�}|jd|�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-sepr4Zfws�policy)	r	ZHeaderZHeaderLabelZ
ValueTerminalr>ZCFWSListZWhiteSpaceTerminalrB�fold)rrK�headerrrrrL�szBaseHeader.foldN)
r r(r)�__doc__r;r<r*r>r7rH�classmethodrIrLrrrrr6�s 

r6cCst||i�j|�S)N)r%rI)Zcls_name�basesr?rrrrEsrEc@s7eZdZdZeej�Zedd��Z	dS)�UnstructuredHeaderNcCs+|j|�|d<t|d�|d<dS)NrDr8)�value_parserr0)r=r?r@rrrr9szUnstructuredHeader.parse)
r r(r)�	max_count�staticmethodr	�get_unstructuredrRrOr9rrrrrQsrQc@seZdZdZdS)�UniqueUnstructuredHeaderr/N)r r(r)rSrrrrrVsrVcsaeZdZdZdZeej�Ze	dd��Z
�fdd�Zedd��Z
�S)	�
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.
    NcCs�|sE|djtj��d|d<d|d<tj�|d<dSt|t�rctj|�}||d<tj	|d�|d<|j
|d�|d<dS)Nr7�datetimerr8rD)�appendrZHeaderMissingRequiredValuer	Z	TokenList�
isinstancer0rZparsedate_to_datetimeZformat_datetimerR)r=r?r@rrrr9&s


zDateHeader.parsecs)|jd�|_t�j||�dS)NrX)�pop�	_datetime�superr<)r�args�kw)rrrr<4szDateHeader.initcCs|jS)N)r\)rrrrrX8szDateHeader.datetime)r r(r)rNrSrTr	rUrRrOr9r<r*rXrr)rrrWs	rWc@seZdZdZdS)�UniqueDateHeaderr/N)r r(r)rSrrrrr`=sr`cspeZdZdZedd��Zedd��Z�fdd�Ze	dd	��Z
e	d
d��Z�S)�
AddressHeaderNcCs,tj|�\}}|s(td��|S)Nzthis should not happen)r	Zget_address_list�AssertionError)r?�address_listrrrrRFszAddressHeader.value_parsercCst|t�r{|j|�|d<}g}x:|jD]/}|jt|jdd�|jD���q6Wt|j	�}n1t
|d�s�|g}dd�|D�}g}||d<||d<djd	d�|D��|d
<d|kr|j|d
�|d<dS)NrDcSs=g|]3}t|jpd|jp'd|jp3d��qS)r)rrr
r)r1Zmbrrr�
<listcomp>Us	z'AddressHeader.parse.<locals>.<listcomp>�__iter__cSs7g|]-}t|d�s-td|g�n|�qS)r.N)�hasattrr+)r1�itemrrrrd^s	�groupsr7z, cSsg|]}t|��qSr)r0)r1rgrrrrdds	r8)rZr0rRr.rYr+rZ
all_mailboxes�listrrfr5)r=r?r@rcrhZaddrr7rrrr9Ls$			


 zAddressHeader.parsecs8t|jd��|_d|_t�j||�dS)Nrh)r,r[�_groupsr-r]r<)rr^r_)rrrr<hs	zAddressHeader.initcCs|jS)N)rj)rrrrrhmszAddressHeader.groupscCs5|jdkr.tdd�|jD��|_|jS)NcSs&g|]}|jD]}|�qqSr)r.)r1�group�addressrrrrdts	z+AddressHeader.addresses.<locals>.<listcomp>)r-r,rj)rrrrr.qszAddressHeader.addresses)r r(r)rSrTrRrOr9r<r*rhr.rr)rrraBsrac@seZdZdZdS)�UniqueAddressHeaderr/N)r r(r)rSrrrrrmysrmc@s"eZdZedd��ZdS)�SingleAddressHeadercCs8t|j�dkr-tdj|j���|jdS)Nr/z9value of single address header {} is not a single addressr)rr.r
rr>)rrrrrl�s	zSingleAddressHeader.addressN)r r(r)r*rlrrrrrn~srnc@seZdZdZdS)�UniqueSingleAddressHeaderr/N)r r(r)rSrrrrro�srocseZdZdZeej�Zedd��Z	�fdd�Z
edd��Zedd	��Z
ed
d��Z�S)�MIMEVersionHeaderr/cCs�|j|�|d<}t|�|d<|dj|j�|jdkrPdn|j|d<|j|d<|jdk	r�dj|d|d�|d<n
d|d<dS)NrDr8r7�major�minorz{}.{}�version)rRr0�extendrrrrqr)r=r?r@rDrrrr9�s"
!zMIMEVersionHeader.parsecsM|jd�|_|jd�|_|jd�|_t�j||�dS)Nrsrqrr)r[�_version�_major�_minorr]r<)rr^r_)rrrr<�szMIMEVersionHeader.initcCs|jS)N)rv)rrrrrq�szMIMEVersionHeader.majorcCs|jS)N)rw)rrrrrr�szMIMEVersionHeader.minorcCs|jS)N)ru)rrrrrs�szMIMEVersionHeader.version)r r(r)rSrTr	Zparse_mime_versionrRrOr9r<r*rqrrrsrr)rrrp�srpcsLeZdZdZedd��Z�fdd�Zedd��Z�S)�ParameterizedMIMEHeaderr/cCsu|j|�|d<}t|�|d<|dj|j�|jdkrWi|d<ndd�|jD�|d<dS)NrDr8r7�paramscSs7i|]-\}}tj|�tj|�j��qSr)rr:�lower)r1r>r?rrr�
<dictcomp>�s	z1ParameterizedMIMEHeader.parse.<locals>.<dictcomp>)rRr0rtrry)r=r?r@rDrrrr9�s
	zParameterizedMIMEHeader.parsecs)|jd�|_t�j||�dS)Nry)r[�_paramsr]r<)rr^r_)rrrr<�szParameterizedMIMEHeader.initcCs
t|j�S)N)rr|)rrrrry�szParameterizedMIMEHeader.params)	r r(r)rSrOr9r<r*ryrr)rrrx�s
rxcsgeZdZeej�Z�fdd�Zedd��Z	edd��Z
edd��Z�S)	�ContentTypeHeadercsGt�j||�tj|jj�|_tj|jj�|_dS)N)	r]r<rr:rB�maintype�	_maintype�subtype�_subtype)rr^r_)rrrr<�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)rTr	Zparse_content_type_headerrRr<r*r~r�r�rr)rrr}�s
r}csCeZdZeej�Z�fdd�Zedd��Z	�S)�ContentDispositionHeadercsGt�j||�|jj}|dkr1|ntj|�|_dS)N)r]r<rB�content_dispositionrr:�_content_disposition)rr^r_Zcd)rrrr<�szContentDispositionHeader.initcCs|jS)N)r�)rrrrr��sz,ContentDispositionHeader.content_disposition)
r r(r)rTr	Z parse_content_disposition_headerrRr<r*r�rr)rrr��sr�cs[eZdZdZeej�Zedd��Z	�fdd�Z
edd��Z�S)�ContentTransferEncodingHeaderr/cCs?|j|�|d<}t|�|d<|dj|j�dS)NrDr8r7)rRr0rtr)r=r?r@rDrrrr9�sz#ContentTransferEncodingHeader.parsecs/t�j||�tj|jj�|_dS)N)r]r<rr:rB�cte�_cte)rr^r_)rrrr<�sz"ContentTransferEncodingHeader.initcCs|jS)N)r�)rrrrr�sz!ContentTransferEncodingHeader.cte)
r r(r)rSrTr	Z&parse_content_transfer_encoding_headerrRrOr9r<r*r�rr)rrr��s
r�ZsubjectZdatezresent-datez	orig-dateZsenderz
resent-senderZtoz	resent-toZccz	resent-ccZbccz
resent-bcc�fromzresent-fromzreply-tozmime-versionzcontent-typezcontent-dispositionzcontent-transfer-encodingc@sOeZdZdZeeddd�Zdd�Zdd�Zd	d
�Z	dS)�HeaderRegistryz%A header_factory and header registry.TcCs5i|_||_||_|r1|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�rz)rr>r=rrr�map_to_type6szHeaderRegistry.map_to_typecCs>|jj|j�|j�}td|j||jfi�S)N�_)r��getrzr�r%r r�)rr>r=rrr�__getitem__<szHeaderRegistry.__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)rr>r?rrr�__call__@s
zHeaderRegistry.__call__N)
r r(r)rNr6rQrr�r�r�rrrrr� sr�N)rN�typesrZemailrrrr	rr+r0r6rErQrVrWr`rarmrnrorprxr}r�r�r�r�rrrr�<module>	sR[6a'7
%