MINI MINI MANI MO

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

3


 \O@sjdZddlmZddlmZddlmZddlmZGdddZGdd	d	Z	Gd
dde
Zdd
ZGdddZ
Gddde
ZGdddZGdddeZGdddZGdddeZGdddeZGdddeZGdddZGd d!d!ZGd"d#d#eZGd$d%d%eZGd&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^eZdZdddZeddZeddZed	d
ZeddZd
dZ	ddZ
ddZdS)AddressNcCsl|dk	rV|s|rtdtj|\}}|r:tdj|||jrJ|jd|j}|j}||_||_	||_
dS)aCreate 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)	TypeErrorparserZ
get_addr_spec
ValueErrorformatall_defects
local_partdomain
_display_name	_username_domain)selfdisplay_nameusernamer	addr_specZa_srestr,/usr/lib64/python3.6/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.domaincCsTt|j}t|t|tjkr.tj|j}n|j}|jrH|d|jS|sPdS|S)zThe addr_spec (username@domain) portion of the address, quoted
        according to RFC 5322 rules, but with no Content Transfer Encoding.
        @z<>)setrlenr	Z
DOT_ATOM_ENDSquote_stringr)rnamesetZlprrrrCs
zAddress.addr_speccCsdj|jj|j|j|jS)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r	__class____name__rrr)rrrr__repr__SszAddress.__repr__cCs^t|j}t|t|tjkr.tj|j}n|j}|rX|jdkrFdn|j}dj||S|jS)Nz<>rz{} <{}>)rrrr	SPECIALSrrr)rrdisprrrr__str__Xs
zAddress.__str__cCs8t|t|krdS|j|jko6|j|jko6|j|jkS)NF)typerrr)rotherrrr__eq__cs
zAddress.__eq__)rrrN)r 
__module____qualname__rpropertyrrrrr!r$r'rrrrrs
%rc@sFeZdZdddZeddZeddZdd	Zd
dZd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)rtuple
_addresses)rr	addressesrrrrmszGroup.__init__cCs|jS)N)r)rrrrrszGroup.display_namecCs|jS)N)r-)rrrrr.szGroup.addressescCsdj|jj|j|jS)Nz${}(display_name={!r}, addresses={!r})rrr rr.)rrrrr!szGroup.__repr__cCs|jdkr&t|jdkr&t|jdS|j}|dk	r\t|}t|t|tjkr\tj|}djdd|jD}|r~d|n|}dj	||S)Nrz, css|]}t|VqdS)N)str).0xrrr	<genexpr>sz Group.__str__.<locals>.<genexpr> z{}:{};)
rrr.r0rr	r"rjoinr)rr#rZadrstrrrrr$s
z
Group.__str__cCs,t|t|krdS|j|jko*|j|jkS)NF)r%rr.)rr&rrrr'szGroup.__eq__)NN)
r r(r)rr*rr.r!r$r'rrrrr+ks
r+c@sTeZdZdZddZddZeddZedd	Zd
dZ	e
dd
ZddZ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|dr4tj|d|d<tj||d}|d=|j|f||S)Ndefectsdecoded)parserZ_has_surrogates	_sanitizer0__new__init)clsnamevaluekwdsrrrrr;szBaseHeader.__new__cCs||_||_||_dS)N)_name_parse_tree_defects)rr>
parse_treer7rrrr<szBaseHeader.initcCs|jS)N)rA)rrrrr>szBaseHeader.namecCs
t|jS)N)r,rC)rrrrr7szBaseHeader.defectscCst|jj|jjt|f|jfS)N)_reconstruct_headerrr 	__bases__r0__dict__)rrrr
__reduce__s
zBaseHeader.__reduce__cCstj||S)N)r0r;)r=r?rrr_reconstructszBaseHeader._reconstructcCs`tjtjtj|jdtjddgg}|jrH|jtjtjddg|j|j|j	|dS)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>rBappendZCFWSListZWhiteSpaceTerminalfold)rrKheaderrrrrMszBaseHeader.foldN)
r r(r)__doc__r;r<r*r>r7rHclassmethodrIrMrrrrr6s 

r6cCst||ij|S)N)r%rI)Zcls_namebasesr?rrrrEsrEc@s&eZdZdZeejZeddZ	dS)UnstructuredHeaderNcCs"|j||d<t|d|d<dS)NrDr8)value_parserr0)r=r?r@rrrr9szUnstructuredHeader.parse)
r r(r)	max_countstaticmethodr	get_unstructuredrSrPr9rrrrrR	s
rRc@seZdZdZdS)UniqueUnstructuredHeaderr/N)r r(r)rTrrrrrWsrWcsFeZdZdZdZeejZe	ddZ
fddZeddZ
ZS)	
DateHeaderaHeader 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|djtjd|d<d|d<tj|d<dSt|trJtj|}||d<tj	|d|d<|j
|d|d<dS)Nr7datetimerr8rD)rLrZHeaderMissingRequiredValuer	Z	TokenList
isinstancer0rZparsedate_to_datetimeZformat_datetimerS)r=r?r@rrrr9)s

zDateHeader.parsecs|jd|_tj||dS)NrY)pop	_datetimesuperr<)rargskw)rrrr<7szDateHeader.initcCs|jS)N)r\)rrrrrY;szDateHeader.datetime)r r(r)rOrTrUr	rVrSrPr9r<r*rY
__classcell__rr)rrrXs	
rXc@seZdZdZdS)UniqueDateHeaderr/N)r r(r)rTrrrrra@sracsPeZdZdZeddZeddZfddZe	dd	Z
e	d
dZZS)
AddressHeaderNcCs tj|\}}|std|S)Nzthis should not happen)r	Zget_address_listAssertionError)r?address_listrrrrSIszAddressHeader.value_parsercCst|trZ|j||d<}g}x,|jD]"}|jt|jdd|jDq(Wt|j	}n"t
|dsj|g}dd|D}g}||d<||d<djd	d|D|d
<d|kr|j|d
|d<dS)NrDcSs*g|]"}t|jpd|jpd|jp"dqS)r)rrr
r)r1Zmbrrr
<listcomp>Xsz'AddressHeader.parse.<locals>.<listcomp>__iter__cSs&g|]}t|dstd|gn|qS)r.N)hasattrr+)r1itemrrrreasgroupsr7z, cSsg|]}t|qSr)r0)r1rhrrrregsr8)rZr0rSr.rLr+rZ
all_mailboxeslistrrgr5)r=r?r@rdriZaddrr7rrrr9Os$


zAddressHeader.parsecs(t|jd|_d|_tj||dS)Nri)r,r[_groupsr-r]r<)rr^r_)rrrr<kszAddressHeader.initcCs|jS)N)rk)rrrrripszAddressHeader.groupscCs&|jdkr tdd|jD|_|jS)NcSsg|]}|jD]}|qqSr)r.)r1groupaddressrrrrewsz+AddressHeader.addresses.<locals>.<listcomp>)r-r,rk)rrrrr.ts
zAddressHeader.addresses)
r r(r)rTrUrSrPr9r<r*rir.r`rr)rrrbEsrbc@seZdZdZdS)UniqueAddressHeaderr/N)r r(r)rTrrrrrn|srnc@seZdZeddZdS)SingleAddressHeadercCs(t|jdkrtdj|j|jdS)Nr/z9value of single address header {} is not a single addressr)rr.r
rr>)rrrrrms
zSingleAddressHeader.addressN)r r(r)r*rmrrrrrosroc@seZdZdZdS)UniqueSingleAddressHeaderr/N)r r(r)rTrrrrrpsrpcsZeZdZdZeejZeddZ	fddZ
eddZedd	Z
ed
dZZS)MIMEVersionHeaderr/cCs|j||d<}t||d<|dj|j|jdkr<dn|j|d<|j|d<|jdk	rtdj|d|d|d<nd|d<dS)NrDr8r7majorminorz{}.{}version)rSr0extendrrsrrr)r=r?r@rDrrrr9s

zMIMEVersionHeader.parsecs6|jd|_|jd|_|jd|_tj||dS)Nrtrrrs)r[_version_major_minorr]r<)rr^r_)rrrr<szMIMEVersionHeader.initcCs|jS)N)rw)rrrrrrszMIMEVersionHeader.majorcCs|jS)N)rx)rrrrrsszMIMEVersionHeader.minorcCs|jS)N)rv)rrrrrtszMIMEVersionHeader.version)r r(r)rTrUr	Zparse_mime_versionrSrPr9r<r*rrrsrtr`rr)rrrqs
rqcs8eZdZdZeddZfddZeddZZ	S)ParameterizedMIMEHeaderr/cCsZ|j||d<}t||d<|dj|j|jdkrBi|d<ndd|jD|d<dS)NrDr8r7paramscSs&i|]\}}tj|tj|jqSr)rr:lower)r1r>r?rrr
<dictcomp>sz1ParameterizedMIMEHeader.parse.<locals>.<dictcomp>)rSr0rurrz)r=r?r@rDrrrr9s

zParameterizedMIMEHeader.parsecs|jd|_tj||dS)Nrz)r[_paramsr]r<)rr^r_)rrrr<szParameterizedMIMEHeader.initcCs
t|jS)N)rr})rrrrrzszParameterizedMIMEHeader.params)
r r(r)rTrPr9r<r*rzr`rr)rrrys
rycsJeZdZeejZfddZeddZ	eddZ
eddZZS)	ContentTypeHeadercs2tj||tj|jj|_tj|jj|_dS)N)	r]r<rr:rBmaintype	_maintypesubtype_subtype)rr^r_)rrrr<szContentTypeHeader.initcCs|jS)N)r)rrrrrszContentTypeHeader.maintypecCs|jS)N)r)rrrrrszContentTypeHeader.subtypecCs|jd|jS)N/)rr)rrrrcontent_typeszContentTypeHeader.content_type)
r r(r)rUr	Zparse_content_type_headerrSr<r*rrrr`rr)rrr~s

r~cs2eZdZeejZfddZeddZ	Z
S)ContentDispositionHeadercs2tj|||jj}|dkr"|ntj||_dS)N)r]r<rBcontent_dispositionrr:_content_disposition)rr^r_Zcd)rrrr<szContentDispositionHeader.initcCs|jS)N)r)rrrrrsz,ContentDispositionHeader.content_disposition)r r(r)rUr	Z parse_content_disposition_headerrSr<r*rr`rr)rrrs
rcsBeZdZdZeejZeddZ	fddZ
eddZZ
S)ContentTransferEncodingHeaderr/cCs2|j||d<}t||d<|dj|jdS)NrDr8r7)rSr0rur)r=r?r@rDrrrr9sz#ContentTransferEncodingHeader.parsecs"tj||tj|jj|_dS)N)r]r<rr:rBcte_cte)rr^r_)rrrr<sz"ContentTransferEncodingHeader.initcCs|jS)N)r)rrrrrsz!ContentTransferEncodingHeader.cte)r r(r)rTrUr	Z&parse_content_transfer_encoding_headerrSrPr9r<r*rr`rr)rrrs

r)ZsubjectZdatezresent-datez	orig-dateZsenderz
resent-senderZtoz	resent-toZccz	resent-ccZbccz
resent-bccfromzresent-fromzreply-tozmime-versionzcontent-typezcontent-dispositionzcontent-transfer-encodingc@s8eZdZdZeedfddZddZddZd	d
Z	dS)HeaderRegistryz%A header_factory and header registry.TcCs&i|_||_||_|r"|jjtdS)aCreate 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_classupdate_default_header_map)rrrZuse_default_maprrrr's
zHeaderRegistry.__init__cCs||j|j<dS)zLRegister cls as the specialized class for handling "name" headers.

        N)rr{)rr>r=rrrmap_to_type9szHeaderRegistry.map_to_typecCs,|jj|j|j}td|j||jfiS)N_)rgetr{rr%r r)rr>r=rrr__getitem__?szHeaderRegistry.__getitem__cCs||||S)aCreate 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__Cs
zHeaderRegistry.__call__N)
r r(r)rOr6rRrrrrrrrrr#srN)rOtypesrZemailrrrr	rr+r0r6rErRrWrXrarbrnrorprqryr~rrrrrrrr<module>	sR[6d'7
%

OHA YOOOO