ó žòœMc@sjdZddlZddlZddlmZmZmZddlmZiZ de fd„ƒYZ dS(sGprovides the Lexer class for parsing template strings into parse trees.iÿÿÿÿN(t parsetreet exceptionstutil(tadjust_whitespacetLexercBs¼eZdeddd„Zed„ƒZdd„Zd„Zd„Z d„Z e j dƒZ d„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„ZRS(cCsÓ||_||_tj|jƒ|_d|_d|_d|_d|_g|_ g|_ ||_ ||_ t jr|rtjdƒ‚n|dkr¨g|_n't|dƒsÆ|g|_n ||_dS(Niis4Mako for Python 3 does not support disabling Unicodet__iter__(ttexttfilenameRt TemplateNodettemplatetmatched_linenotmatched_charpostlinenotmatch_positionttagt control_linetdisable_unicodetencodingRtpy3kRtUnsupportedErrortNonet preprocessorthasattr(tselfRRRtinput_encodingR((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyt__init__s&             cCs,i|jd6|jd6|jd6|jd6S(NtsourceR tposR(RR R R(R((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pytexception_kwargs+s   cCsoyt||f}WnKtk ra|r?tj||ƒ}ntj|ƒ}|t||fcompile the given regexp, cache the reg, and call match_reg().(t _regexp_cachetKeyErrortretcompilet match_reg(Rtregexptflagstreg((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pytmatch2s cCsû|j}|j|j|jƒ}|r÷|jƒ\}}||krU|d|_n ||_|j|_tjd|j||j!ƒ}|d}x<|dkrÑ||jkrÑ|j|dkrÑ|d8}q–W|||_ |jt |ƒ7_n|S(sšmatch the given regular expression object to the current text position. if a match occurs, update the current text and line position. is\nis ( R R%RtspanR R Rtfindallt textlengthR tlen(RR$tmpR%tstarttendtlinestcp((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyR!@s     1 cGs<|j}x,tr7|jdƒ}|r-q n|jdƒ}|r’|jd|jdƒtjƒ}|s4tjd|jdƒ|j‚q4q |jddj |ƒƒ}|rç|j ||jt |jdƒƒ!|jdƒfS|jddj |ƒtjƒ}|s tjd d j |ƒ|j‚q q WdS( Ns#.*\ns(\"\"\"|\'\'\'|\"|\')s.*?%sisUnmatched '%s's(%s)t|s.*?(?=\"|\'|#|%s)s Expected: %st,( R tTrueR%tgroupRtSRtSyntaxExceptionRtjoinRR)(RRtstartposR%tm((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pytparse_until_text\s.  " #" cOs~|jd|jƒ|jd|jƒ|jd|jƒ|j|d<|||Ž}t|jƒr~|jdjj|ƒn|j jj|ƒt |t j ƒrØt|jƒrÅ|jd|_ n|jj|ƒn¢t |t jƒrz|jr|jjƒqz|jr|jj|ƒqzt|jƒrz|jdj|jƒ rztjd|j|jdjf|j‚qzndS(NRR RRiÿÿÿÿs1Keyword '%s' not a legal ternary for keyword '%s'(t setdefaultRR R RR)RtnodestappendR t isinstanceRtTagtparentt ControlLinetisendRtpopt is_primaryt is_ternarytkeywordRR4R(Rtnodeclstargstkwargstnode((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyt append_nodexs.   s #.*coding[:=]\s*([-\w.]+).*\r?\nc Cs™t|tƒrL|jj|ƒ}|r6|jdƒp?|p?d}||fS|jtjƒrð|ttjƒ}d}|jj|j ddƒƒ}|dk r2|jdƒdkr2t j d|jdƒ|j ddƒdd|ƒ‚q2nB|jj|j ddƒƒ}|r&|jdƒ}n |p/d}|ry|j |ƒ}Wqt k r‹}t j d||j ddƒdd|ƒ‚qXn||fS( s§given string/unicode or bytes/string, determine encoding from magic encoding comment, return body as unicode or raw if decode_raw=False itasciisutf-8tignoresHFound utf-8 BOM in file, with conflicting magic encoding comment of '%s'is0Unicode decode operation of encoding '%s' failedN(R<tunicodet _coding_reR%R2t startswithtcodecstBOM_UTF8R)tdecodeRRtCompileExceptiontUnicodeDecodeError( RRt decode_rawtknown_encodingRR7Rtparsed_encodingte((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pytdecode_raw_stream”s8! !  cCsà|j|j|j |j|jƒ\|_|_x#|jD]}||jƒ|_q;W|j|jƒt|jƒ|_ xÓt rN|j |j kr˜Pn|j ƒr¨Pn|j ƒrºq|n|jƒrÌq|n|jƒrÞq|n|jƒrðq|n|jƒrq|n|jƒrq|n|jƒr&q|n|j |j kr<Pntjdƒ‚q|Wt|jƒr„tjd|jdj|j‚nt|jƒrÙtjd|jdj|j|jdj|jdj|jƒ‚n|jS(Nsassertion failedsUnclosed tag: <%%%s>iÿÿÿÿs"Unterminated control keyword: '%s'(RXRRRRRR!RMR)R(R1R t match_endtmatch_expressiontmatch_control_linet match_commenttmatch_tag_startt match_tag_endtmatch_python_blockt match_textRRRRR4RDRRR RR (Rtpreproc((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pytparse¼sR             c Cso|jdtjtjBtjBƒ}|rg|jdƒ|jdƒ|jdƒ}}}||_i}|rÄxTtjd|ƒD]=}|\}}} |pž| } | jddƒ} | || # closing iiis)\s*(\w+)\s*=\s*(?:'([^']*)'|\"([^\"]*)\")s s Rs(.*?)(?=\)sUnclosed tag: <%%%s>iÿÿÿÿ(R%RtIR3tXR2RDR'treplaceRIRR=RRARR4RtTextR^R1tFalse( RR%RDtattrR@t attributestatttkeytval1tval2R((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyR]ðs6 /    cCs¶|jdƒ}|r®t|jƒsItjd|jdƒ|j‚nT|jdj|jdƒkrtjd|jdƒ|jdjf|j‚n|jjƒt St SdS(Ns\s(Closing tag without opening tag: iiÿÿÿÿs.Closing tag does not match tag: <%%%s>( R%R)RRR4R2RRDRAR1Rg(RR%((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyR^s  cCs@|jdtjƒ}|r8|jƒ}|r1|StSntSdS(Ns\Z(R%RR3R2R1Rg(RR%tstring((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyRY-s cCsY|jdtjtjBƒ}|rQ|jdƒ}|rM|jtj|ƒntSt SdS(Nsá (.*?) # anything, followed by: ( (?<=\n)(?=[ \t]*(?=%|\#\#)) # an eval or line-based # comment preceded by a # consumed newline and whitespace | (?=\${) # an expression | (?=\#\*) # multiline comment | (?=s it!R R( R%R R R8RRIRtCodeR2R1Rg(RR%tlineRRR,((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyR_Ts"cCs°|jdƒ}|r¨|j|j}}|jddƒ\}}|dkrd|jdƒ\}}nd}|jddƒ}|jtj||jƒd|d |ƒt St SdS( Ns\${s\|t}R/ts s R R( R%R R R8ReRIRt ExpressiontstripR1Rg(RR%RqRRR,tescapes((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyRZds  cCsT|jdtjƒ}|rL|jdƒ}|jdƒ}|dkr5tjd|ƒ}|sytjd||j‚n|jddƒ\}}|dk }|rt|j ƒsÔtjd||f|j‚q|j dj |krtjd ||j dj f|j‚qn|j t j |||ƒn|j t j|ƒtStSdS( NsB(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\r?\n)|[^\r\n])*)(?:\r?\n|\Z)iit%s(end)?(\w+)\s*(.*)sInvalid control line: '%s's!No starting keyword '%s' for '%s'iÿÿÿÿs'Keyword '%s' doesn't match keyword '%s'(R%RtMR2RR4RRR)RRDRIRR?tCommentR1Rg(RR%toperatorRtm2R@RD((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyR[vs8   cCsC|jdtjƒ}|r;|jtj|jdƒƒtStSdS(s*matches the multiline version of a comments<%doc>(.*?)iN( R%RR3RIRRyR2R1Rg(RR%((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyR\—s N(t__name__t __module__RRgRtpropertyRR%R!R8RIRR RMRXRbR]R^RYR`R_RZR[R\(((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyRs&     ( 4 +     !( t__doc__RROtmakoRRRt mako.pygenRRtobjectR(((s0/usr/lib/python2.7/vendor-packages/mako/lexer.pyts