7Ȍ\dZddlZddlZddlmZddlmZddlmZiZGddZ dS)zGprovides the Lexer class for parsing template strings into parse trees.N) exceptions) parsetree)adjust_whitespaceceZdZ ddZedZddZdZdZdZ e j dZ d Z d Zd Zd Zd ZdZdZdZdZdZdS)LexerNc&||_||_tj|j|_d|_d|_d|_d|_g|_ g|_ g|_ ||_ | g|_ dSt|ds |g|_ dS||_ dS)Nr__iter__)textfilenamer TemplateNodetemplatematched_linenomatched_charposlinenomatch_positiontag control_line ternary_stackencoding preprocessorhasattr)selfr r input_encodingrs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/mako/lexer.py__init__zLexer.__init__s   !.t}==   &   "D   z22 -!-D    ,D   c8|j|j|j|jdS)N)sourcerposr )r rrr )rs rexception_kwargszLexer.exception_kwargs*s)i)'    rc t||f}nG#t$r:|rtj||ntj|}|t||f<YnwxYw||S)z>compile the given regexp, cache the reg, and call match_reg().) _regexp_cacheKeyErrorrecompile match_reg)rregexpflagsregs rmatchz Lexer.match3s 10CC 1 1 1/4L"*VU+++"*V:L:LC-0M65/ * * * 1~~c"""sAAAc|j}||j|j}|r|\}}||kr|dzn||_|j|_|dz }|dkr0||jkr%|jd|dzd}||z |_|xj|j||j dz 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%899  K ::<DDTJJ JKK rcd|j}d|}d}d}d} |d}|r|dtj}|r<|d|z}|r`|r|dksX|dksR|dksL|j||jt |dz |dfS|s#|d|ztj}|r||dd z }||dd z}||dd z }||dd z}||dd z }||ddz}tj dd|zfi|j )N|rTz#.*\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((E JJ>E JJw011E K K 1__ a=1;L;LI 4#6U[[^^9L9L#LLKKNN   K #9G#CRTJJ u{{1~~33C888 u{{1~~33C888 u{{1~~33C888 u{{1~~33C888 Q!5!5c!:!:: Q!5!5c!:!:: ,$/373H rc|d|j|d|j|d|j|j|d<||i|}t |jr&|jdj|n|j j||j r|j d}|j|t|tj r||js?|jr8|jdr+|jddj|t|tjrBt |jr|jd|_|j|dSt|tj r%|jr4|j |jdS|jr6|j ||jgdS|j rG|j d|jr"|jd|dS|j rZ|j d|js7t-jd|jd|j djdfi|jdSdSdS) 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"(DI...(D$7888%!5666!]zw''' tx== - HRL  % %d + + + + M  & &t , , ,   > -b1M   & &t , , ,tY%:;; >&00>> > &  > &r*  >"2&r*077=== dIM * * 48}} +"hrl HOOD ! ! ! ! ! i3 4 4 z !%%'''"&&((((( !((..."))"-----" t'8'<'G'G (( "2&--d33333" 4+DWHT> ! ??6? + + MFO,,../D%O%%dkk'8&D&DEEA}w!6!6 1578wwqzzBKK22 %%dkk'8&D&DEEA,-Laggajjj>3LWO   {{?33%    1F%&KK22  $$s )E??:F9c(||jd|j|j\|_|_|jD]}||j|_||jt|j|_ |j |jkrn| rn| r<| rQ| rf|r{|r|r|r|j |jkrnt%jdt|jr*t%jd|jdjzfi|jt|jrUt%jd|jdjz|j|jdj|jdj|j|jS)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_textr MakoExceptionrrCrUr!rrr r)rpreprocs rparsez Lexer.parses$#'#9#9 ItT]DM$ $   ty( + +G **DII t'''di.. ?"T_44~~ $$&& &&(( !!## ##%% !!## &&((    "T_44*+=>> > tx== ,&")=='  t ! ! ,4#B'/0 !"%,!"%)  }rcd}||tjtjztjz}|sdS|\}}}||_i}|r=tjd|D]'}|\}} } | p| } | dd} | ||<(| tj |||r|j n|dkr|dtj}|s*tjd|j d jzfi|j| tj|d |Sd S) 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    D24K"$     5$||~~u   'zz(Closing tag without opening tag: r rLzClosing tag does not match tag: <%>TF) r+rArrrCrBr!rUrYrr+s rrwzLexer.match_tag_endDs 9::  tx==  0>kk!nn%+ "%Q77 00{{1~~~~tx|';';';=+ HLLNNN45rc~|dtj}|sdS|}|r|SdS)Nz\ZFT)r+r%r@rB)rr+strings rrrzLexer.match_endXsC 5"$'' 5  M4rc|dtjtjz}|r9|d}|r |t j|dSdS)Na (.*?) # anything, followed by: ( (?<=\n)(?=[ \t]*(?=%|\#\#)) # an eval or line-based # comment preceded by a # consumed newline and whitespace | (?=\${) # an expression | (?=>D 7  66645rc |d}|rv|j|j}}|dd\}}t |dz}|t j||ddk||dSdS) Nz<%(!)?Fz%>r-r !rr T) r+rrrJrr`rCoderB)rr+liner r r4s rrxzLexer.match_python_blocks 9%%  +T-A#D--eU;;ID#%T**T1D    A#%    45rcd|d}|sdS|j|j}}|ddd\}}|dkr|dd\}}nd}|dd }|t j|||| dS) Nz\${FTz\|r9r7r~r-r) r+rrrJrr`r Expressionstrip)rr+rr r r4escapess rrszLexer.match_expressions 6"" 5')=c))$t<< c #::00t<>{{1~~ s??/66B  0047+ XXa^^NE7%E 4,-- $44?FwwM/&r*2g==$4444!22!6!>!>!>@/   Y2GUD I I I I   Y. 5 5 5trc|dtj}|r5|tj|ddSdS)z*matches the multiline version of a commentz<%doc>(.*?)r TF)r+r%r@r`rrrBrs rruzLexer.match_commentsM 0"$77     Y. A ? ? ?45r)NNN)N)__name__ __module__ __qualname__rpropertyr!r+r'rJr`r%r&rdror|rvrwrrryrxrsrtrurrrrs7EI----,  X  # # # #,&&&P000d?@@J(%(%(%T666p000d(   :&*$$$Lrr) __doc__rfr%makorr mako.pygenrr#rrrrrsNM (((((( BBBBBBBBBBr