a 97a€_ã@sNdZddlmZddlmZddlmZddlmZmZmZm Z m Z gd¢Z ddl Z ddl Z ddlmZdd lmZdd lmZddlmmmZdd lmZmZejZd Zd ZdZdZdZ dZ!dZ"edƒZ#edƒZ$e  %de j&e j'Be j(B¡Z)e  %d¡Z*e  %d¡Z+dd„Z,d"dd„Z-Gdd„de.ƒZ/Gdd„de.ƒZ0Gd d!„d!e1ƒZ2dS)#z+Header encoding and decoding functionality.é)Úunicode_literals)Údivision)Úabsolute_import)ÚbytesÚrangeÚstrÚsuperÚzip)ÚHeaderÚ decode_headerÚ make_headerN)Úemail)Ú base64mime)ÚHeaderParseError)Ú _max_appendÚ header_decodeÚ ú ó z ÚéNz úus-asciizutf-8ai =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= z[\041-\176]+:$z \n[^ \t]+:c Cs˜t|dƒrdd„|jDƒSt |¡s.|dfgSg}| ¡D]€}t |¡}d}|r:| d¡}|rj| ¡}d}|r~| |ddf¡|rL| d¡  ¡}| d¡  ¡}| d¡}| |||f¡qLq:ddl } g} t |ƒD]J\} } | dkrÐ| drÐ|| d drÐ|| dd  ¡rÐ|  | d¡qÐt | ƒD] } || =q$g}|D]Â\}}}|dur^| ||f¡nœ|d kr€t|ƒ}| ||f¡nz|d krît|ƒd }|r°|d dd |…7}zt |¡}WntjyÜtdƒ‚Yn0| ||f¡n td|ƒ‚q:g}d}}|D]v\}}t|tƒr,t|dƒ}|dur@|}|}nB||krb| ||f¡|}|}n |durz|t|7}n||7}q| ||f¡|S)a;Decode a message header value without converting charset. Returns a list of (string, charset) pairs containing each of the decoded parts of the header. Charset is None for non-encoded parts of the header, otherwise a lower-case string containing the name of the character set specified in the encoded string. header may be a string that may or may not contain RFC2047 encoded words, or it may be a Header object. An email.errors.HeaderParseError may be raised when certain decoding error occurs (e.g. a base64 decoding exception). Ú_chunkscSs(g|] \}}t |t|ƒ¡t|ƒf‘qS©)Ú_charsetÚ_encoder)Ú.0ÚstringÚcharsetrrúx/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/future/backports/email/header.pyÚ Nsÿz!decode_header..NTrFééÚqÚbéz===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)ÚhasattrrÚecreÚsearchÚ splitlinesÚsplitÚpopÚlstripÚappendÚlowerÚsysÚ enumerateÚisspaceÚreversedrÚlenrÚdecodeÚbinasciiÚErrorrÚAssertionErrorÚ isinstancerrÚBSPACE)ÚheaderÚwordsÚlineÚpartsÚfirstÚ unencodedrÚencodingÚencodedr/ÚdroplistÚnÚwÚdÚ decoded_wordsÚencoded_stringÚwordÚpaderrÚ collapsedÚ last_wordÚ last_charsetrrrr >s~ ÿ      4             r cCsFt|||d}|D].\}}|dur4t|tƒs4t|ƒ}| ||¡q|S)a¼Create a Header from a sequence of pairs as returned by decode_header() decode_header() takes a header value string and returns a sequence of pairs of the format (decoded_string, charset) where charset is the string name of the character set. This function takes one of those sequence of pairs and returns a Header instance. Optional maxlinelen, header_name, and continuation_ws are as in the Header constructor. )Ú maxlinelenÚ header_nameÚcontinuation_wsN)r r8ÚCharsetr-)Ú decoded_seqrMrNrOÚhÚsrrrrr s ÿ r c@sReZdZddd„Zdd„Zdd „Zd d „Zdd d „Zdd„Zddd„Z dd„Z dS)r NrÚstrictcCs||durt}nt|tƒs t|ƒ}||_||_g|_|durH| |||¡|durTt}||_|durjd|_ nt |ƒd|_ dS)aDCreate a MIME-compliant header that can contain many character sets. Optional s is the initial header value. If None, the initial header value is not set. You can later append to the header with .append() method calls. s may be a byte string or a Unicode string, but see the .append() documentation for semantics. Optional charset serves two purposes: it has the same meaning as the charset argument to the .append() method. It also sets the default character set for all subsequent .append() calls that omit the charset argument. If charset is not provided in the constructor, the us-ascii charset is used both as s's initial charset and as the default for subsequent .append() calls. The maximum line length can be specified explicitly via maxlinelen. For splitting the first line to a shorter value (to account for the field header which isn't included in s, e.g. `Subject') pass in the name of the field in header_name. The default maxlinelen is 78 as recommended by RFC 2822. continuation_ws must be RFC 2822 compliant folding whitespace (usually either a space or a hard tab) which will be prepended to continuation lines. errors is passed through to the .append() call. Nrr") ÚUSASCIIr8rPrÚ_continuation_wsrr-Ú MAXLINELENÚ _maxlinelenÚ _headerlenr3)ÚselfrSrrMrNrOÚerrorsrrrÚ__init__´s zHeader.__init__c CsÄ| ¡g}d}d}|jD]ž\}}|}|tjkrH| dd¡}| dd¡}|r˜|o\| |d¡}|dvr‚|dvr˜|s˜| t¡d}n|dvr˜|s˜| t¡|o¨| |d¡}|}| |¡qt   |¡S)z&Return the string value of the header.NÚasciiÚsurrogateescapeÚreplacer©Nréÿÿÿÿ) Ú _normalizerrÚ UNKNOWN8BITÚencoder4Ú _nonctextr-ÚSPACEÚ EMPTYSTRINGÚjoin) rZÚuchunksÚlastcsÚ lastspacerrÚnextcsÚoriginal_bytesÚhasspacerrrÚ__str__ãs*        zHeader.__str__cCs |t|ƒkS©N)r©rZÚotherrrrÚ__eq__sz Header.__eq__cCs ||k SrprrqrrrÚ__ne__ sz Header.__ne__cCs´|dur|j}nt|tƒs"t|ƒ}t|tƒsZ|jp4d}|tjkrN| dd¡}n | ||¡}|jpbd}|tjkr z| ||¡Wn t yž|dkr–‚t }Yn0|j   ||f¡dS)a.Append a string to the MIME header. Optional charset, if given, should be a Charset instance or the name of a character set (which will be converted to a Charset instance). A value of None (the default) means that the charset given in the constructor is used. s may be a byte string or a Unicode string. If it is a byte string (i.e. isinstance(s, str) is false), then charset is the encoding of that byte string, and a UnicodeError will be raised if the string cannot be decoded with that charset. If s is a Unicode string, then charset is a hint specifying the character set of the characters in the string. In either case, when producing an RFC 2822 compliant header using RFC 2047 rules, the string will be encoded using the output codec of the charset. If the string cannot be encoded to the output codec, a UnicodeError will be raised. Optional `errors' is passed as the errors argument to the decode call if s is a byte string. Nrr^) rr8rPrÚ input_codecrcr4Ú output_codecrdÚUnicodeEncodeErrorÚUTF8rr-)rZrSrr[Ú input_charsetÚoutput_charsetrrrr- s$         z Header.appendcCs| ¡p|dvS)z=True if string s is not a ctext character of RFC822. )ú(ú)ú\)r1)rZrSrrrre7szHeader._nonctextú;, rcCs¨| ¡|dur|j}|dkr"d}t|j||j|ƒ}d}d}}|jD]&\}} |dur¤|oh| |d¡}ddl} |dvr|r†| dvr¤| ¡n| dvr¤|s¤| ¡|o´| |d¡}| }d}|  ¡} | rÞ|  d| d| ¡n|  dd| ¡| dd…D]`} |  ¡| j dur*|  |jd |   ¡| ¡qø|   ¡} | dt| ƒt| ƒ…}|  || | ¡qøt| ƒdkrF|  ¡qF|jr€| ¡| |¡}t |¡r¤td  |¡ƒ‚|S) aÔEncode a message header into an RFC-compliant format. There are many issues involved in converting a given string for use in an email header. Only certain character sets are readable in most email clients, and as header strings can only contain a subset of 7-bit ASCII, care must be taken to properly convert and encode (with Base64 or quoted-printable) header strings. In addition, there is a 75-character length limit on any given encoded header field, so line-wrapping must be performed, even with double-byte character sets. Optional maxlinelen specifies the maximum length of each generated line, exclusive of the linesep string. Individual lines may be longer than maxlinelen if a folding point cannot be found. The first line will be shorter by the length of the header name plus ": " if a header name was specified at Header construction time. The default value for maxlinelen is determined at header construction time. Optional splitchars is a string containing characters which should be given extra weight by the splitting algorithm during normal header wrapping. This is in very rough support of RFC 2822's `higher level syntactic breaks': split points preceded by a splitchar are preferred during line splitting, with the characters preferred in the order in which they appear in the string. Space and tab may be included in the string to indicate whether preference should be given to one over the other as a split point when other split chars do not appear in the line being split. Splitchars does not affect RFC 2047 encoded lines. Optional linesep is a string to be used to separate the lines of the value. The default value is the most useful for typical Python applications, but it can be set to \r\n to produce RFC-compliant line separators when needed. Nri@Br`raFrr!rz8header value appears to contain an embedded header: {!r})rbrXÚ_ValueFormatterrYrVrrer/Úadd_transitionr)ÚfeedÚnewlineÚheader_encodingr,r3Ú_strÚ_embeded_headerr(rÚformat)rZÚ splitcharsrMÚlinesepÚ formatterrjrnrkrrr/Úlinesr<ÚslineÚfwsÚvaluerrrrd<sZ!ÿ    ÿ    ÿz Header.encodecCsxg}d}g}|jD]B\}}||kr.| |¡q|durJ| t |¡|f¡|g}|}q|rn| t |¡|f¡||_dSrp)rr-rfrh)rZÚchunksrLÚ last_chunkrrrrrrbs zHeader._normalize)NNNNrrT)NrT)r~Nr) Ú__name__Ú __module__Ú __qualname__r\rorsrtr-rerdrbrrrrr ³sþ /  + Qr c@sTeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)rcCs0||_||_t|ƒ|_||_g|_t|ƒ|_dSrp)Ú_maxlenrVr3Ú_continuation_ws_lenÚ _splitcharsÚ_linesÚ _AccumulatorÚ _current_line)rZÚ headerlenÚmaxlenrOr‡rrrr\¡s  z_ValueFormatter.__init__cCs| ¡| |j¡Srp)r‚rhr–)rZrˆrrrr„©sz_ValueFormatter._strcCs | t¡Srp)r„ÚNL©rZrrrro­sz_ValueFormatter.__str__cCsp|j ¡}|dkr|jj|Žt|jƒdkrb|j ¡rP|jdt|jƒ7<n|j t|jƒ¡|j ¡dS)N)rrrra) r˜r+Úpushr3Ú is_onlywsr–rr-Úreset)rZÚ end_of_linerrrr‚°s   z_ValueFormatter.newlinecCs|j dd¡dS)Nrr)r˜rrœrrrr€»sz_ValueFormatter.add_transitioncCsÀ|jdur| |||j¡dS| || ¡¡}z| d¡}WntyPYdS0|durf| ||¡z | ¡}Wnty†YdS0| ¡|j   |j |¡|D]}|j   |j |¡q¤dS©Nr)rƒÚ _ascii_splitr•Úheader_encode_linesÚ _maxlengthsr+Ú IndexErrorÚ _append_chunkr‚r˜rrVr–r-)rZrŒrrÚ encoded_linesÚ first_lineÚ last_liner<rrrr¾s$     z_ValueFormatter.feedccs&|jt|jƒV|j|jVqdSrp)r“r3r˜r”rœrrrr¤ãsz_ValueFormatter._maxlengthscCsft dtd||¡}|dr0dg|dd…<n | d¡tt|ƒgdŽD]\}}| ||¡qLdS)Nz([z]+)rrr")Úrer*ÚFWSr+r Úiterr¦)rZrŒrr‡r=Úpartrrrr¢és  z_ValueFormatter._ascii_splitcCs|j ||¡t|jƒ|jkr|jD]v}t|j ¡dddƒD]T}| ¡rn|j|d}|rn|d|krnq˜|j|dd}|r@|d|kr@q˜q@q&qÚq&|j ¡\}}|jj dkrÈ|  ¡|sÈd}|j ||¡dS|j  |¡}|j   t|jƒ¡|j |¡dS)Nr!rrar)r˜rr3r“r•rÚ part_countr1r+Ú _initial_sizer‚Úpop_fromr–r-rrŸ)rZrŒrÚchÚiÚprevpartr­Ú remainderrrrr¦ÿs.   z_ValueFormatter._append_chunkN) rr‘r’r\r„ror‚r€rr¤r¢r¦rrrrr s %rcsjeZdZd‡fdd„ Zdd„Zddd„Z‡fdd „Zd d „Zd d „Zddd„Z dd„Z ‡fdd„Z ‡Z S)r—rcs||_tƒ ¡dSrp)r¯rr\)rZÚ initial_size©Ú __class__rrr\"sz_Accumulator.__init__cCs| ||f¡dSrp)r-)rZrŒrrrrr&sz_Accumulator.pushcCs||d…}g||d…<|Srpr)rZr²Úpoppedrrrr°)s  z_Accumulator.pop_fromcs| ¡dkrdStƒ ¡S)Nr)rr)r®rr+rœr¶rrr+.s z_Accumulator.popcCstdd„|Dƒ|jƒS)Ncss"|]\}}t|ƒt|ƒVqdSrp)r3©rrŒr­rrrÚ 4óz'_Accumulator.__len__..)Úsumr¯rœrrrÚ__len__3sÿz_Accumulator.__len__cCst dd„|Dƒ¡S)Ncss |]\}}t ||f¡VqdSrp©rgrhr¹rrrrº8sÿz'_Accumulator.__str__..r¾rœrrrro7s ÿz_Accumulator.__str__NcCs"|dur g}||dd…<d|_dSr¡)r¯)rZÚstartvalrrrrŸ;s z_Accumulator.resetcCs|jdko| pt|ƒ ¡Sr¡)r¯rr1rœrrrržAsz_Accumulator.is_onlywscs tƒ ¡Srp)rr½rœr¶rrr®Dsz_Accumulator.part_count)r)r)N) rr‘r’r\rr°r+r½rorŸržr®Ú __classcell__rrr¶rr— s   r—)NNr)3Ú__doc__Ú __future__rrrZfuture.builtinsrrrrr Ú__all__rªr5Zfuture.backportsr Zfuture.backports.emailrZfuture.backports.email.errorsrZfuture.backports.email.charsetZ backportsrrZ!future.backports.email.quoprimimerrrPr›rfr9ÚSPACE8rgrWr«rUrxÚcompileÚVERBOSEÚ IGNORECASEÚ MULTILINEr'Úfcrer…r r Úobjectr rÚlistr—rrrrÚsH      ø  _ÿ n