PL i?TdZddlZddlZddlmZddlmZddlmZiZGddZ y)zGprovides the Lexer class for parsing template strings into parse trees.N) exceptions) parsetree)adjust_whitespaceceZdZ ddZedZddZdZdZdZ e jdZ d Z d Zd Zd Zd ZdZdZdZdZdZdZy)LexerNc$||_||_tj|j|_d|_d|_d|_d|_g|_ g|_ g|_ ||_ |g|_ yt|ds |g|_ y||_ y)Nr__iter__)textfilenamer TemplateNodetemplatematched_linenomatched_charposlinenomatch_positiontag control_line ternary_stackencoding preprocessorhasattr)selfr r input_encodingrs P/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mako/lexer.py__init__zLexer.__init__s   !..t}}=   &   "D z2!-D  ,D c`|j|j|j|jdS)N)sourcerposr )r rrr )rs rexception_kwargszLexer.exception_kwargs*s.ii))''   rc t||f}|j |S#t$r;|rtj||ntj|}|t||f<YTwxYw)z>compile the given regexp, cache the reg, and call match_reg().) _regexp_cacheKeyErrorrecompile match_reg)rregexpflagsregs rmatchz Lexer.match3sb 10C ~~c""  1/4"**VU+"**V:LC-0M65/ * 1s AA"!A"c|j}|j|j|j}|r|j\}}||k(r|dzn||_|j|_|dz }|dk\r0||j kr!|jd|dzjd}||z |_|xj|j||jjdz c_|S)zmatch the given regular expression object to the current text position. if a match occurs, update the current text and line position. r rN ) rr+r spanrr textlengthrfindrcount)rr*mpr+startendcps rr'zLexer.match_reg>s  $))T%8%89  ::DDTJ JK rc|j}dj|}d}d}d} |jd}|r|jdtj}|r8|jd|z}|rV|r|dkDsO|dkDsJ|dkDsE|j ||jt |jdz |jdfS|s#|jd|ztj}|r||jdjdz }||jdjd z}||jdjd z }||jdjd z}||jdjd z }||jdjd z}tjddj|zfi|j)N|rz#.*\nz+(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1z(%s)r z(.*?)(?=\"|\'|#|%s){}()[]z Expected: %s,) rjoinr+r%Sr lengroupr1rSyntaxExceptionr!) r watch_nestingr startpostext_re brace_level paren_level bracket_levelr+s rparse_until_textzLexer.parse_until_textTs&&))D/   JJx(EJJ>EJJw01E 1_ a=1;LII 4#6#6U[[^9L#LKKN   #9G#CRTTJu{{1~33C88 u{{1~33C88 u{{1~33C88 u{{1~33C88 Q!5!5c!:: Q!5!5c!:: ,,$/373H3H rc|jd|j|jd|j|jd|j|j|d<||i|}t |j r)|j djj|n%|jjj||jr|jd}|jj|t|tjr|j|jsF|j r:|j dr+|j ddjj|t|tj"rEt |j r|j d|_|j j|yt|tjrU|j&r5|jj)|j j)y|j*r7|jj||j jgy|jrG|jdj|jr|j dj|y|jrq|jdj|jsHt-j.d|jd|jdjdfi|j0yyy) Nrrr r Keyword 'z#' not a legal ternary for keyword '') setdefaultr rrr rArnodesappendrr isinstancer ControlLine is_ternarykeywordrTagparentisendpop is_primaryrrCr!)rnodeclsargskwargsnode control_frames r append_nodezLexer.append_node|s(DII.(D$7$78%!5!56!]]z'' txx= HHRL   % %d + MM   & &t ,    --b1M    & &t ,tY%:%:;%00>&&&&r*""2&r*0077= dIMM *488}"hhrl HHOOD ! i33 4zz!!%%'""&&(!!((.""))"-""t'8'8'<'G'G (""2&--d3""4+<+t|tr<|jj|}|xr|j dxs|xsd}||fS|j t jr|tt jd}d}|jj|jdd}||j ddk7rtjd|j dz|jdddd||jj|jdd}|r|j dn|xsd}|r |j|}||fS||fS#t$r-tjd|z|jdddd|wxYw)zgiven string/unicode or bytes/string, determine encoding from magic encoding comment, return body as unicode or raw if decode_raw=False r zutf-8NignorezHFound utf-8 BOM in file, with conflicting magic encoding comment of '%s'rz0Unicode decode operation of encoding '%s' failed) rRstr _coding_rer+rB startswithcodecsBOM_UTF8rAdecoderCompileExceptionUnicodeDecodeError)rr decode_rawknown_encodingr mrparsed_encodings rdecode_raw_streamzLexer.decode_raw_streams dC %%d+A'QWWQZD>DWHT> ! ??6?? +FOO,./D%O%%dkk'8&DEA}w!6 11578wwqzBKK2 %%dkk'8&DEA,-aggaj>3LWO  {{?3$$$$&  11F%&KK2  s E&&6Fc|j|jd|j|j\|_|_|jD]}||j|_|j |j t|j|_ |j|jkDrn|jrn|jr=|jrN|jr_|jrp|jr|j!r|j#r|j%r|j|jkDrnt'j(dt|j*r:t'j,d|j*dj.zfi|j0t|j2rut'j,d|j2dj.z|j|j2dj4|j2dj6|j|j8S)NTzassertion failedUnclosed tag: <%%%s>rLz"Unterminated control keyword: '%s')ror rr rr'rdrAr/r match_endmatch_expressionmatch_control_line match_commentmatch_tag_start match_tag_endmatch_python_block match_percent match_textr MakoExceptionrrCrUr!rrr r)rpreprocs rparsez Lexer.parses#'#9#9 IItT]]DMM$   ty(( +G *DI + t'dii.""T__4~~$$&&&(!!###%!!#&&(!!# ""T__4**+=> > txx=,,&")=)==''  t  !,,4##B'//0 !!"%,,!!"%))  }}rcd}|j|tjtjztjz}|sy|j \}}}||_i}|r>tjd|D]%}|\}} } | xs| } | jdd} | ||<'|jtj|||r|jjy |dk(r|jdtj}|s:tjd|jd j zfi|j |jtj"|j%d |j'Sy ) Na \<% # opening tag ([\w\.\:]+) # keyword ((?:\s+\w+|\s*=\s*|"[^"]*?"|'[^']*?'|\s*,\s*)*) # attrname, = \ # sign, string expression # comma is for backwards compat # identified in #366 \s* # more whitespace (/)?> # closing Fz)\s*(\w+)\s*=\s*(?:'([^']*)'|\"([^\"]*)\") r-r z(.*?)(?=\)rqrLr T)r+r%Ir@XgroupsrUfindallreplacer`rrVrrYrrCr!TextrBrw) rr*r+rUattrrX attributesattkeyval1val2r s rrvzLexer.match_tag_starts_    DD244K"$$   $||~u  zzz(Closing tag without opening tag: r rLzClosing tag does not match tag: <%>TF) r+rArrrCrBr!rUrYrr+s rrwzLexer.match_tag_endFs 9: txx= 00>kk!n%++ "%%Q7 00{{1~txx|';';=++ HHLLNrcr|jdtj}|sy|j}|r|Sy)Nz\ZFT)r+r%r@rB)rr+strings rrrzLexer.match_endZs2 5"$$' Mrc|jdtj}|rE|jtj |j ddz|j dzyy)Nz(?<=^)(\s*)%%(%*)r %TF)r+r%Mr`rrrBrs rryzLexer.match_percentesS /6     A 4u{{1~ E rc|jdtjtjz}|r4|j d}|r |j t j|yy)Na (.*?) # anything, followed by: ( (?<=\n)(?=[ \t]*(?=%|\#\#)) # an eval or line-based # comment, preceded by a # consumed newline and whitespace | (?=\${) # an expression | (?=D  6rc|jd}|rr|j|j}}|jdd\}}t |dz}|j t j||jddk(||yy) Nz<%(!)?Fz%>r-r !rr T) r+rrrJrr`rCoderB)rr+liner r r4s rrxzLexer.match_python_blocks 9% ++T-A-A#D--eU;ID#%T*T1D    A#%  rcJ|jd}|sy|j|j}}|jddd\}}|dk(r|jdd\}}nd}|j dd }|j t j||j|| y) Nz\${FTz\|r9r7rr-r) r+rrrJrr`r Expressionstrip)rr+rr r r4escapess rrszLexer.match_expressions 6"'')=)=c))$t< c #:00tt j d |d |jd jd fi|j |jtj|||y|jtj|y)NzC(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\\r?\n)|[^\r\n])*)(?:\r?\n|\Z)Fr rrz(end)?(\w+)\s*(.*)zInvalid control line: '%s'zNo starting keyword 'z' for 'rNrLrMz' doesn't match keyword 'T)r+r%rrBrrCr!rArrUr`rrSComment)rr+operatorr m2rXrUs rrtzLexer.match_control_linesq   DD  ;;q>{{1~ s?/6B 00047++ XXa^NE7%E4,,-$44?FM//&&r*22g=$44!2!22!6!>!>@//   Y22GUD I   Y.. 5rc|jdtj}|r0|jtj |j dyy)z*matches the multiline version of a commentz<%doc>(.*?)r TF)r+r%r@r`rrrBrs rruzLexer.match_comments> 0"$$7    Y.. A ?r)NNN)N)__name__ __module__ __qualname__rpropertyr!r+r'rJr`r%r&rdror}rvrwrrryrzrxrsrtrurrrrsEI-,   #,&P0d?@J(%T8t0d( :&*$Lrr) __doc__rfr%makorr mako.pygenrr#rrrrrs+N ( NNr