
    YeIi?                     \    d Z ddlZddlZddlmZ ddlmZ ddlmZ i Z G d d          Z	dS )zGprovides the Lexer class for parsing template strings into parse trees.    N)
exceptions)	parsetree)adjust_whitespacec                       e Zd Z	 ddZed             ZddZd Zd Zd Z	 e
j        d          Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )LexerNc                 &   || _         || _        t          j        | j                  | _        d| _        d| _        d| _        d| _        g | _	        g | _
        g | _        || _        |	g | _        d S t          |d          s
|g| _        d S || _        d S )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        O/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/mako/lexer.py__init__zLexer.__init__   s     	 !.t}== & "Dz22 	-!-D ,D    c                 8    | j         | j        | j        | j        dS )N)sourcer   posr   )r   r   r   r   )r   s    r   exception_kwargszLexer.exception_kwargs*   s)     i)'	
 
 	
r   c                     	 t           ||f         }nG# t          $ r: |rt          j        ||          nt          j        |          }|t           ||f<   Y nw xY w|                     |          S )z>compile the given regexp, cache the reg, and call match_reg().)_regexp_cacheKeyErrorrecompile	match_reg)r   regexpflagsregs       r   matchzLexer.match3   s    	10CC 	1 	1 	1/4L"*VU+++"*V:L:LC-0M65/***	1 ~~c"""s    AAAc                    | j         }|                    | j        | j                   }|r|                                \  }}||k    r|dz   n|| _         | j        | _        |dz
  }|dk    r0|| j        k     r%| j        d|dz                                d          }||z
  | _        | xj        | j        || j                  	                    d          z  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	   r   N
)
r   r+   r   spanr   r   
textlengthrfindr   count)r   r*   mpr+   startendcps          r   r'   zLexer.match_reg>   s      		$)T%899 	K ::<<LUC-0E\\#''sD"&+DaBQww2//Yxax(..t44#%7D KK49R$*=%=>DDTJJJKKr   c                 d   | j         }d                    |          }d}d}d}	 |                     d          }|r|                     dt          j                  }|r<|                     d|z            }|r`|r|dk    sX|dk    sR|dk    sL| j        || j         t          |                    d                    z
           |                    d          fS |s#|                     d|z  t          j                  }|r||                    d                              d	          z  }||                    d                              d
          z  }||                    d                              d          z  }||                    d                              d          z  }||                    d                              d          z  }||                    d                              d          z  }t          j
        dd                    |          z  fi | j        )N|r   Tz#.*\nz+(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1z(%s)r	   z(.*?)(?=\"|\'|#|%s){}()[]zExpected: %s,)r   joinr+   r%   Sr   lengroupr1   r   SyntaxExceptionr!   )	r   watch_nestingr   startpostext_rebrace_levelparen_levelbracket_levelr+   s	            r   parse_until_textzLexer.parse_until_textT   s.   &))D// 	JJx((E JJ> E  JJw011E KK 1__a=1;L;L I 4#6U[[^^9L9L#LL KKNN	   K

#9G#CRTJJ u{{1~~33C888u{{1~~33C888u{{1~~33C888u{{1~~33C888Q!5!5c!:!::Q!5!5c!:!::,$/ 373H  r   c                     |                     d| j                   |                     d| j                   |                     d| j                   | j        |d<    ||i |}t          | j                  r&| j        d         j                            |           n| j	        j                            |           | j
        r| j
        d         }|j                            |           t          |t          j                  r|                    |j                  s?| j        r8| j        d         r+| j        d         d         j                            |           t          |t          j                  rBt          | j                  r| j        d         |_        | j                            |           d S t          |t          j                  r%|j        r4| j
                                         | j                                         d S |j        r6| j
                            |           | j                            g            d S | j
        rG| j
        d                             |j                  r"| j        d                             |           d S | j
        rZ| j
        d                             |j                  s7t-          j        d|j        d| j
        d         j        dfi | j        d S d S d S )	Nr   r   r    r   	Keyword 'z#' not a legal ternary for keyword '')
setdefaultr   r   r   r   rA   r   nodesappendr   r   
isinstancer   ControlLine
is_ternarykeywordr   Tagparentisendpop
is_primaryr   rC   r!   )r   nodeclsargskwargsnodecontrol_frames         r   append_nodezLexer.append_node|   s"   (DI...(D$7888%!5666!]zw'''tx== 	-HRL%%d++++M&&t,,,
  	> -b1M&&t,,, tY%:;;> &00>>>
 &> &r*> "2&r*077===dIM** 	48}} +"hrlHOOD!!!!!i344 	z !%%'''"&&((((( !((..."))"-----" t'8'<'G'G( (  "2&--d33333" 4+<R+@+K+K, ,  !00|||T%6r%:%B%B%BD  +  	 	   r   z #.*coding[:=]\s*([-\w.]+).*\r?\nc                    t          |t                    r9| j                            |          }|r|                    d          p|pd}||fS |                    t          j                  r|t          t          j                  d         }d}| j                            |	                    dd                    }|[|                    d          dk    rBt          j        d|                    d          z  |	                    dd          dd|          nI| j                            |	                    dd                    }|r|                    d          n|pd}|rT	 |	                    |          }n=# t          $ r0 t          j        d|z  |	                    dd          dd|          w xY w||fS )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)rR   str
_coding_rer+   rB   
startswithcodecsBOM_UTF8rA   decoder   CompileExceptionUnicodeDecodeError)r   r   
decode_rawknown_encodingr   mr   parsed_encodings           r   decode_raw_streamzLexer.decode_raw_stream   s    dC   	"%%d++A'QWWQZZD>DWHT>!??6?++ 	MFO,,../D%O%%dkk'8&D&DEEA}w!6!6 1578wwqzzBKK22   %%dkk'8&D&DEEA,-Laggajjj>3LWO 	
{{?33%    1F%&KK22   $$s   )E? ?:F9c                 R   |                      | j        d| j        | j                  \  | _        | _        | j        D ]} || j                  | _        |                     | j                   t          | j                  | _        	 | j	        | j        k    rn| 
                                rn|                                 r<|                                 rQ|                                 rf|                                 r{|                                 r|                                 r|                                 r|                                 r| j	        | j        k    rnt'          j        d          t          | j                  r*t'          j        d| j        d         j        z  fi | j        t          | j                  rUt'          j        d| j        d         j        z  | j        | j        d         j        | j        d         j        | j                  | j        S )NTzassertion failedUnclosed tag: <%%%s>rL   z"Unterminated control keyword: '%s')ro   r   r   r   r   r'   rd   rA   r/   r   	match_endmatch_expressionmatch_control_linematch_commentmatch_tag_startmatch_tag_endmatch_python_blockmatch_percent
match_textr   MakoExceptionr   rC   rU   r!   r   r   r    r   )r   preprocs     r   parsezLexer.parse   s;   #'#9#9ItT]DM$
 $
 ty ( 	+ 	+G	**DII 	t'''di..	?"T_44~~ $$&& &&(( !!## ##%% !!## &&(( !!##    "T_44*+=>>>tx== 	,&")== '   t !! 	,4#B'/0	!"%,!"%)   }r   c                    d}|                      |t          j        t          j        z  t          j        z            }|sdS |                                \  }}}|| _        i }|r=t          j        d|          D ]'}|\  }}	}
|	p|
}|                    dd          }|||<   (| 	                    t          j        ||           |r| j                                         n|dk    r|                      dt          j                  }|s*t          j        d| j        d	         j        z  fi | j        | 	                    t          j        |                    d
                     |                                 S d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(.*?)(?=\</%text>)rq   rL   r	   T)r+   r%   Ir@   XgroupsrU   findallreplacer`   r   rV   r   rY   r   rC   r!   TextrB   rw   )r   r*   r+   rU   attrrX   
attributesattkeyval1val2r   s               r   rv   zLexer.match_tag_start  s     

D24K"$
 

  	5$||~~u
 	'z<d  ' ' #&T4|t||FD11"&
3<<< 
	(HLLNNNNJJ4bd;;E  0*TXb\-AA +   Y^U[[^^<<<%%'''tr   c                    |                      d          }|rt          | j                  s-t          j        d|                    d          z  fi | j        | j        d         j        |                    d          k    rAt          j        d|                    d          d| j        d         j        dfi | j        | j                                         dS d	S )
Nz\</%[\t ]*([^\t ]+?)[\t ]*>z(Closing tag without opening tag: </%%%s>r	   rL   zClosing tag </%z> does not match tag: <%>TF)	r+   rA   r   r   rC   rB   r!   rU   rY   r   r+   s     r   rw   zLexer.match_tag_endF  s    

9:: 	tx==  0>kk!nn%  +  
 "%Q77 00{{1~~~~tx|';';';=  +  
 HLLNNN45r   c                 ~    |                      dt          j                  }|sdS |                                }|r|S dS )Nz\ZFT)r+   r%   r@   rB   )r   r+   strings      r   rr   zLexer.match_endZ  sC    

5"$'' 	5 	M4r   c                     |                      dt          j                  }|rN|                     t          j        |                    d          dz   |                    d          z              dS dS )Nz(?<=^)(\s*)%%(%*)r	   %   TF)r+   r%   Mr`   r   r   rB   r   s     r   ry   zLexer.match_percente  si    

/66 	A 4u{{1~~ E   45r   c                     |                      dt          j        t          j        z            }|r9|                    d          }|r |                     t          j        |           dS dS )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   r@   rB   r`   r   r   )r   r+   r   s      r   rz   zLexer.match_texto  sj    

  D24K#
 
(  	;;q>>D 7  66645r   c                     |                      d          }|rv| j        | j        }}|                     dd          \  }}t	          |          dz   }|                     t          j        ||                    d          dk    ||           dS dS )	Nz<%(!)?Fz%>r-   r	   !r   r    T)	r+   r   r   rJ   r   r`   r   CoderB   )r   r+   liner    r   r4   s         r   rx   zLexer.match_python_block  s    

9%% 	+T-A#D--eU;;ID# %T**T1DA#%     45r   c                 d   |                      d          }|sdS | j        | j        }}|                     ddd          \  }}|dk    r|                     dd          \  }}nd}|                    dd	          }|                     t          j        ||                                ||
           dS )Nz\${FTz\|r9   r7    r   r-   r   )	r+   r   r   rJ   r   r`   r   
Expressionstrip)r   r+   r   r    r   r4   escapess          r   rs   zLexer.match_expression  s    

6"" 	5')=c))$t<<	c#::00t<<LGSSG||FD)) MMOO 	 	
 	
 	
 tr   c                    |                      dt          j                  }|sdS |                    d          }|                    d          }|dk    rt          j         d|          }|st	          j        d|z  fi | j        |                    dd          \  }}|d u}|rvt          | j                  st	          j        d|d	|d
fi | j        | j        d         j	        |k    r.t	          j        d|d| j        d         j	        d
fi | j        | 
                    t          j        |||           n | 
                    t          j        |           dS )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 'rN   rL   rM   z' doesn't match keyword 'T)r+   r%   r   rB   r   rC   r!   rA   r   rU   r`   r   rS   Comment)r   r+   operatorr   m2rX   rU   s          r   rt   zLexer.match_control_line  s   

D
 

  	5;;q>>{{1~~s??/66B  0047 +    XXa^^NE7%E 4,-- 
$44?FwwM /   &r*2g==$4444!22!6!>!>!>@  /  
 Y2GUDIIIIY.555tr   c                     |                      dt          j                  }|r5|                     t          j        |                    d                     dS dS )z*matches the multiline version of a commentz<%doc>(.*?)</%doc>r	   TF)r+   r%   r@   r`   r   r   rB   r   s     r   ru   zLexer.match_comment  sM    

0"$77 	Y.A???45r   )NNN)N)__name__
__module____qualname__r   propertyr!   r+   r'   rJ   r`   r%   r&   rd   ro   r}   rv   rw   rr   ry   rz   rx   rs   rt   ru    r   r   r   r      sF       EI- - - -, 
 
 X
	# 	# 	# 	#  ,& & &P0 0 0d ?@@J(% (% (%T8 8 8t0 0 0d  (	 	 	    :  &  *$ $ $L    r   r   )
__doc__rf   r%   makor   r   
mako.pygenr   r#   r   r   r   r   <module>r      s    N M  				             ( ( ( ( ( (N N N N N N N N N Nr   