
    g?                     T    S r SSKrSSKrSSKJr  SSKJr  SSKJr  0 r " S S5      r	g)zGprovides the Lexer class for parsing template strings into parse trees.    N)
exceptions)	parsetree)adjust_whitespacec                       \ rS rSr SS jr\S 5       rSS jrS rS r	S r
\R                  " S	5      rS
 rS rS rS rS rS rS rS rS rS rS rSrg)Lexer   Nc                 *   Xl         X l        [        R                  " U R                  5      U l        SU l        SU l        SU l        SU l        / U l	        / U l
        / U l        X0l        Uc  / U l        g [        US5      (       d	  U/U l        g X@l        g )N   r   __iter__)textfilenamer   TemplateNodetemplatematched_linenomatched_charposlinenomatch_positiontagcontrol_lineternary_stackencodingpreprocessorhasattr)selfr   r   input_encodingr   s        R/Users/Alptekin/Desktop/izin_takip/venv/lib/python3.13/site-packages/mako/lexer.py__init__Lexer.__init__   s     	 !..t}}= & "Dz22!-D ,    c                 `    U R                   U R                  U R                  U R                  S.$ )N)sourcer   posr   )r   r   r   r   )r   s    r   exception_kwargsLexer.exception_kwargs*   s.     ii))''	
 	
r   c                      [         X4   nU R	                  U5      $ ! [         a@    U(       a  [        R                  " X5      O[        R                  " U5      nU[         X4'    NZf = f)z>compile the given regexp, cache the reg, and call match_reg().)_regexp_cacheKeyErrorrecompile	match_reg)r   regexpflagsregs       r   matchLexer.match3   s\    	10C
 ~~c""	  	1/4"**V+"**V:LC-0M6/*	1s   
 AA'&A'c                    U R                   nUR                  U R                  U R                   5      nU(       a  UR                  5       u  pEXT:X  a  US-   OUU l         U R                  U l        US-
  nUS:  a0  X`R                  :  a!  U R                  SUS-    R                  S5      nX&-
  U l        U =R                  U R                  X R                    R                  S5      -  sl        U$ )zmatch the given regular expression object to the current text
position.

if a match occurs, update the current text and line position.

r
   r   N
)
r   r.   r   spanr   r   
textlengthrfindr   count)r   r-   mpr.   startendcps          r   r*   Lexer.match_reg>   s       		$))T%8%89 ::<LU-0\#'sD"&++DaBQw2/YYxa(..t4#%7D KK499R*=*=>DDTJJKr   c                 &   U R                   nSR                  U5      nSnSnSn U R                  S5      nU(       a  M  U R                  S[        R                  5      nU(       a  MD  U R                  SU-  5      nU(       a]  U(       a  US:  dP  US:  dJ  US:  dD  U R
                  X0R                   [        UR                  S5      5      -
   UR                  S5      4$ U(       d#  U R                  SU-  [        R                  5      nU(       a  XXR                  S5      R                  S5      -  nXXR                  S5      R                  S	5      -  nXhR                  S5      R                  S
5      -  nXhR                  S5      R                  S5      -  nXxR                  S5      R                  S5      -  nXxR                  S5      R                  S5      -  nGM  [        R                  " SSR                  U5      -  40 U R                  D6e)N|r   z#.*\nz+(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1z(%s)r
   z(.*?)(?=\"|\'|#|%s){}()[]zExpected: %s,)r   joinr.   r(   Sr   lengroupr5   r   SyntaxExceptionr#   )	r   watch_nestingr   startpostext_rebrace_levelparen_levelbracket_levelr.   s	            r   parse_until_textLexer.parse_until_textT   s   &&))D/JJx(EJJ>E JJw01E 1_a=1;L II #6#6U[[^9L#L KKN	  

#9G#CRTTJ{{1~33C88{{1~33C88{{1~33C88{{1~33C88Q!5!5c!::Q!5!5c!::,,$/373H3H r   c                 <   UR                  SU R                  5        UR                  SU R                  5        UR                  SU R                  5        U R                  US'   U" U0 UD6n[        U R                  5      (       a)  U R                  S   R                  R                  U5        O%U R                  R                  R                  U5        U R                  (       a  U R                  S   nUR                  R                  U5        [        U[        R                  5      (       a   UR                  UR                  5      (       dP  U R                   (       a?  U R                   S   (       a+  U R                   S   S   R                  R                  U5        [        U[        R"                  5      (       aJ  [        U R                  5      (       a  U R                  S   Ul        U R                  R                  U5        g [        U[        R                  5      (       Gav  UR&                  (       a5  U R                  R)                  5         U R                   R)                  5         g UR*                  (       a7  U R                  R                  U5        U R                   R                  / 5        g U R                  (       aL  U R                  S   R                  UR                  5      (       a  U R                   S   R                  U5        g U R                  (       ay  U R                  S   R                  UR                  5      (       dK  [,        R.                  " SUR                  < SU R                  S   R                  < S340 U R0                  D6eg g g )	Nr!   r   r"   r   	Keyword 'z#' not a legal ternary for keyword '')
setdefaultr   r   r   r   rF   r   nodesappendr   r   
isinstancer   ControlLine
is_ternarykeywordr   Tagparentisendpop
is_primaryr   rH   r#   )r   nodeclsargskwargsnodecontrol_frames         r   append_nodeLexer.append_node|   s   (DII.(D$7$78%!5!56!]]z''txx==HHRL%%d+MM&&t,
  --b1M&&t, tY%:%:;;%00>>&&&&r*""2&r*0077=dIMM**488}}"hhrlHHOOD!i3344zz!!%%'""&&(!!((.""))"-""t'8'8'<'G'G( ( ""2&--d3""4+<+<R+@+K+K, , !00||T%6%6r%:%B%BD ++ ," 5r   z #.*coding[:=]\s*([-\w.]+).*\r?\nc                    [        U[        5      (       aJ  U R                  R                  U5      nU=(       a    UR	                  S5      =(       d    U=(       d    SnXa4$ UR                  [        R                  5      (       a  U[        [        R                  5      S nSnU R                  R                  UR                  SS5      5      nUbQ  UR	                  S5      S:w  a<  [        R                  " SUR	                  S5      -  UR                  SS5      SSU5      eONU R                  R                  UR                  SS5      5      nU(       a  UR	                  S5      O
U=(       d    SnU(       a   UR                  U5      nXq4$ Xq4$ ! [         a.    [        R                  " SU-  UR                  SS5      SSU5      ef = f)zgiven string/unicode or bytes/string, determine encoding
from magic encoding comment, return body as unicode
or raw if decode_raw=False

r
   zutf-8NignorezHFound utf-8 BOM in file, with conflicting magic encoding comment of '%s'r   z0Unicode decode operation of encoding '%s' failed)rX   str
_coding_rer.   rG   
startswithcodecsBOM_UTF8rF   decoder   CompileExceptionUnicodeDecodeError)r   r   
decode_rawknown_encodingr   mr   parsed_encodings           r   decode_raw_streamLexer.decode_raw_stream   s    dC  %%d+A'QWWQZD>DWH>!??6??++FOO,./D%O%%dkk'8&DEA}w!6 11578wwqzBKK2  %%dkk'8&DEA,-aggaj>3LWO
{{?3 $$$$ &  11F%&KK2 s   8F 8Gc                 V   U R                  U R                  SU R                  U R                  5      u  U l        U l        U R                   H  nU" U R                  5      U l        M     U R                  U R                  5        [        U R                  5      U l         U R                  U R                  :  a  OU R                  5       (       a  OU R                  5       (       a  MI  U R                  5       (       a  M`  U R                  5       (       a  Mw  U R                  5       (       a  M  U R                  5       (       a  M  U R!                  5       (       a  M  U R#                  5       (       a  M  U R%                  5       (       a  M  U R                  U R                  :  a  O[&        R(                  " S5      e[        U R*                  5      (       a;  [&        R,                  " SU R*                  S   R.                  -  40 U R0                  D6e[        U R2                  5      (       av  [&        R,                  " SU R2                  S   R.                  -  U R                  U R2                  S   R4                  U R2                  S   R6                  U R                  5      eU R8                  $ )NTzassertion failedUnclosed tag: <%%%s>rR   z"Unterminated control keyword: '%s')rv   r   r   r   r   r*   rk   rF   r3   r   	match_endmatch_expressionmatch_control_linematch_commentmatch_tag_startmatch_tag_endmatch_python_blockmatch_percent
match_textr   MakoExceptionr   rH   r[   r#   r   r   r"   r   )r   preprocs     r   parseLexer.parse   s   #'#9#9IItT]]DMM$
 ty ((G		*DI )
 	t'dii.""T__4~~$$&&&&((!!####%%!!##&&((!!##  ""T__4**+=>>txx==,,&")=)==''  t  !!,,4##B'//0		!!"%,,!!"%))  }}r   c                 :   SnU R                  U[        R                  [        R                  -  [        R                  -  5      nU(       d  gUR                  5       u  p4nX0l        0 nU(       aD  [        R                  " SU5       H)  nUu  pn
U	=(       d    U
nUR                  SS5      nXU'   M+     U R                  [        R                  X65        U(       a  U R                  R                  5         gUS:X  a  U R                  S[        R                  5      nU(       d;  [        R                  " SU R                  S	   R                  -  40 U R                   D6eU R                  [        R"                  UR%                  S
5      5        U R'                  5       $ g)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*(?:'([^']*)'|\"([^\"]*)\")
r1   r   z(.*?)(?=\</%text>)ry   rR   r
   T)r.   r(   IrE   Xgroupsr[   findallreplacerf   r   r\   r   r_   r   rH   r#   TextrG   r   )r   r-   r.   r[   attrr^   
attributesattkeyval1val2r   s               r   r~   Lexer.match_tag_start  sP     

DD244K"$$

 $||~u
zz<d #&4|t||FD1"&3 	<HHLLN  JJ4bdd;E 00*TXXb\-A-AA++  Y^^U[[^<%%''r   c                    U R                  S5      nU(       a  [        U R                  5      (       d3  [        R                  " SUR                  S5      -  40 U R                  D6eU R                  S   R                  UR                  S5      :w  aP  [        R                  " SUR                  S5      < SU R                  S   R                  < S340 U R                  D6eU R                  R                  5         gg	)
Nz\</%[\t ]*([^\t ]+?)[\t ]*>z(Closing tag without opening tag: </%%%s>r
   rR   zClosing tag </%z> does not match tag: <%>TF)	r.   rF   r   r   rH   rG   r#   r[   r_   r   r.   s     r   r   Lexer.match_tag_endF  s    

9:txx== 00>kk!n% ++ 
 "%%Q7 00{{1~txx|';';= ++ 
 HHLLNr   c                     U R                  S[        R                  5      nU(       d  gUR                  5       nU(       a  U$ g)Nz\ZFT)r.   r(   rE   rG   )r   r.   strings      r   rz   Lexer.match_endZ  s2    

5"$$'Mr   c                     U R                  S[        R                  5      nU(       aE  U R                  [        R
                  UR                  S5      S-   UR                  S5      -   5        gg)Nz(?<=^)(\s*)%%(%*)r
   %   TF)r.   r(   Mrf   r   r   rG   r   s     r   r   Lexer.match_percente  sS    

/6A 4u{{1~ E r   c                     U R                  S[        R                  [        R                  -  5      nU(       a9  UR	                  S5      nU(       a   U R                  [        R                  U5        gg)Na  
                (.*?)         # anything, followed by:
                (
                 (?<=\n)(?=[ \t]*(?=%|\#\#))  # an eval or line-based
                                            # comment, preceded by a
                                            # consumed newline and whitespace
                 |
                 (?=\${)      # an expression
                 |
                 (?=</?%)  # a substitution or block or call start or end
                              # - don't consume
                 |
                 (\\\r?\n)    # an escaped newline  - throw away
                 |
                 \Z           # end of string
                )r
   TF)r.   r(   r   rE   rG   rf   r   r   )r   r.   r   s      r   r   Lexer.match_texto  sU    

  DD244K#
( ;;q>D  6r   c                    U R                  S5      nU(       am  U R                  U R                  p2U R                  SS5      u  pE[	        U5      S-   nU R                  [        R                  UUR                  S5      S:H  UUS9  gg)	Nz<%(!)?Fz%>r1   r
   !r   r"   T)	r.   r   r   rO   r   rf   r   CoderG   )r   r.   liner"   r   r8   s         r   r   Lexer.match_python_block  s    

9%++T-A-A#--eU;ID %T*T1DA#%   r   c                 J   U R                  S5      nU(       d  gU R                  U R                  p2U R                  SSS5      u  pEUS:X  a  U R                  SS5      u  peOSnUR	                  SS	5      nU R                  [        R                  UUR                  5       UUS
9  g)Nz\${FTz\|r>   r<    r   r1   r   )	r.   r   r   rO   r   rf   r   
Expressionstrip)r   r.   r   r"   r   r8   escapess          r   r{   Lexer.match_expression  s    

6"'')=)=c))$t<	#:00t<LGSG||FD)  MMO 	 	
 r   c                 0   U R                  S[        R                  5      nU(       d  gUR                  S5      nUR                  S5      nUS:X  Ga%  [        R                   " SU5      nU(       d$  [        R
                  " SU-  40 U R                  D6eUR                  SS5      u  pVUS LnU(       a  [        U R                  5      (       d*  [        R
                  " SU< S	U< S
340 U R                  D6eU R                  S   R                  U:w  aA  [        R
                  " SU< SU R                  S   R                  < S
340 U R                  D6eU R                  [        R                  XeU5        gU R                  [        R                  U5        g)NzC(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\\r?\n)|[^\r\n])*)(?:\r?\n|\Z)Fr
   r   r   z(end)?(\w+)\s*(.*)zInvalid control line: '%s'zNo starting keyword 'z' for 'rT   rR   rS   z' doesn't match keyword 'T)r.   r(   r   rG   r   rH   r#   rF   r   r[   rf   r   rY   Comment)r   r.   operatorr   m2r^   r[   s          r   r|   Lexer.match_control_line  sp   

DD

 ;;q>{{1~s?/6B 00047++   XXa^NE%E4,,--$44?FM//  &&r*22g=$44!2!22!6!>!>@ // 
 Y22GDI  Y..5r   c                     U R                  S[        R                  5      nU(       a0  U R                  [        R
                  UR                  S5      5        gg)z*matches the multiline version of a commentz<%doc>(.*?)</%doc>r
   TF)r.   r(   rE   rf   r   r   rG   r   s     r   r}   Lexer.match_comment  s>    

0"$$7Y..A?r   )r   r   r   r[   r   r   r   r   r   r   r   r   r   r3   )NNN)N)__name__
__module____qualname____firstlineno__r   propertyr#   r.   r*   rO   rf   r(   r)   rk   rv   r   r~   r   rz   r   r   r   r{   r|   r}   __static_attributes__ r   r   r   r      s    EI-, 
 
	#,&P0d ?@J(%T8t0d(	:&*$Lr   r   )
__doc__rm   r(   makor   r   
mako.pygenr   r&   r   r   r   r   <module>r      s+    N  	   (N Nr   