o
    j|b                  	   @   sb  d dl Z e jeeeeeeed d dlZd dlZd dlmZ d dlmZ ddl	m
Z
 ddlmZ ddlmZ d	d
lmZmZmZmZmZ d	dlmZmZmZmZ d	dlmZ d Zd Zd ZdZda dd Z!g dZ"e"g d Z#G dd dZ$dd Z%G dd dZ&G dd de&Z'G dd de&Z(G dd deZ)ede)fddZ*G d d! d!Z+G d"d# d#Z,dS )$    N)make_lexiconlexiconprint_functionerrorwarningosplatform)	normalize)contextmanager   )Utils)Scanner)UnrecognizedInput   )r   r   hold_errorsrelease_errorsCompileError)any_string_prefixft_string_prefixesr   IDENT)r   c                   C   s   t st a t S N)r   r    r   r   Y/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Cython/Compiler/Scanning.pyget_lexicon    s   r   )globalnonlocaldefclassprintdelpassbreakcontinuereturnraiseimportexectryexceptfinallywhileifelifelseforinassertandornotislambdafromyieldwith)	includeZctypedefZcdefZcpdefZcimportZDEFZIFZELIFELSEc                   @   s>   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZdS )CompileTimeScopeNc                 C   s   i | _ || _d S r   )entriesouter)selfr=   r   r   r   __init__;      
zCompileTimeScope.__init__c                 C   s   || j |< d S r   r<   )r>   namevaluer   r   r   declare?      zCompileTimeScope.declarec                 C   s   | j | d S r   )r<   updater>   otherr   r   r   rF   B      zCompileTimeScope.updatec                 C   s
   | j | S r   rA   r>   rB   r   r   r   lookup_hereE      
zCompileTimeScope.lookup_herec                 C   s
   || j v S r   rA   rJ   r   r   r   __contains__H   rL   zCompileTimeScope.__contains__c                 C   s6   z|  |W S  ty   | j}|r|| Y S  w r   )rK   KeyErrorr=   lookup)r>   rB   r=   r   r   r   rO   K   s   zCompileTimeScope.lookupr   )	__name__
__module____qualname__r?   rD   rF   rK   rM   rO   r   r   r   r   r;   9   s    
r;   c                  C   s   t  } d}t|t D ]
\}}| || qdd l}d}|D ]}| |t|| qddlm} | d| | dt	 | dt
 | dt t | }|S )	N)ZUNAME_SYSNAMEZUNAME_NODENAMEZUNAME_RELEASEZUNAME_VERSIONZUNAME_MACHINEr   )*FalseTrueabsallanyasciibinbool	bytearraybyteschrcomplexdictdivmod	enumeratefilterfloatformat	frozensethashhexintlenlistmapmaxminnextoctordpowrangereprreversedroundsetslicesortedstrsumtuplezip)reducer}   unicodelongxrange)r;   r|   r   unamerD   builtinsgetattr	functoolsr}   ry   rh   rr   )ZbenvnamesrB   rC   r   r}   Zdenvr   r   r   initial_compile_time_envV   s   r   c                   @   st   e Zd ZdZdZdZdZdZdZdd Z	dd	 Z
d
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )SourceDescriptorz<
    A SourceDescriptor should be considered immutable.
    NFpyx c                 C   s   J r   r   r>   r   r   r   __str__      zSourceDescriptor.__str__c                 C   s.   t j|\}}|dv r|dd  pd| _d S )N)z.pyxz.pxdz.pyr   r   )r   pathsplitext
_file_type)r>   filenamerB   extr   r   r   set_file_type_from_name   s   z(SourceDescriptor.set_file_type_from_namec                 C   s
   | j dv S )N)r   Zpxdr   r   r   r   r   is_cython_file   rL   zSourceDescriptor.is_cython_filec                 C   s
   | j dkS )Npyr   r   r   r   r   is_python_file   rL   zSourceDescriptor.is_python_filec                 C   s"   | j d u r|  dd| _ | j S )N\/)_escaped_descriptionget_descriptionreplacer   r   r   r   get_escaped_description   s   
z(SourceDescriptor.get_escaped_descriptionc                 C   s$   z| j |j kW S  ty   Y dS w NF	_cmp_nameAttributeErrorrG   r   r   r   __gt__   
   zSourceDescriptor.__gt__c                 C   s$   z| j |j k W S  ty   Y dS w r   r   rG   r   r   r   __lt__   r   zSourceDescriptor.__lt__c                 C   s$   z| j |j kW S  ty   Y dS w r   r   rG   r   r   r   __le__   r   zSourceDescriptor.__le__c                 C      | S r   r   r   r   r   r   __copy__   r   zSourceDescriptor.__copy__c                 C   r   r   r   )r>   memor   r   r   __deepcopy__   r   zSourceDescriptor.__deepcopy__)rP   rQ   rR   __doc__r   Zin_utility_coder   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   y   s"    r   c                   @   s^   e Zd ZdZdddZdddZdddZd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )FileSourceDescriptora7  
    Represents a code source. A code source is a more generic abstraction
    for a "filename" (as sometimes the code doesn't come from a file).
    Instances of code sources are passed to Scanner.__init__ as the
    optional name argument and will be passed back when asking for
    the position()-tuple.
    Nc                 C   s   t |}|| _|p|| _z
tj| j| _W n ty$   | j| _Y nw tj	dtj
 }||r;|t|d  n|| _| | || _i | _d S )N.)r   decode_filenamer   path_descriptionr   r   relpath_short_path_description
ValueErrorabspathsep
startswithri   	file_pathr   r   _lines)r>   r   r   Zworkdirr   r   r   r?      s   

 

zFileSourceDescriptor.__init__c                 C   s|   ||f}| j |}|d ur|S | j||d}dd | D }W d    n1 s+w   Y  || j v r7|nd | j |< |S )Nencodingerror_handlingc                 S      g | ]}|  qS r   rstrip.0liner   r   r   
<listcomp>       z2FileSourceDescriptor.get_lines.<locals>.<listcomp>)r   getget_file_object	readlines)r>   r   r   keylinesfr   r   r   	get_lines   s   zFileSourceDescriptor.get_linesc                 C   s   t | j||S r   )r   Zopen_source_filer   r>   r   r   r   r   r   r      rI   z$FileSourceDescriptor.get_file_objectc                 C      | j S r   )r   r   r   r   r   r         z$FileSourceDescriptor.get_descriptionc                 C   s:   | j }tt tjj }||r|t|d  S |S r   )	r   r   r   r   getcwdr   r   r   ri   )r>   r   cwdr   r   r   get_error_description   s
   
z*FileSourceDescriptor.get_error_descriptionc                 C   r   r   )r   r   r   r   r   get_filenametable_entry   r   z,FileSourceDescriptor.get_filenametable_entryc                 C      t |to
| j|jkS r   )
isinstancer   r   rG   r   r   r   __eq__      zFileSourceDescriptor.__eq__c                 C   s
   t | jS r   )rf   r   r   r   r   r   __hash__   rL   zFileSourceDescriptor.__hash__c                 C   
   d| j  S )Nz<FileSourceDescriptor:%s>)r   r   r   r   r   __repr__   rL   zFileSourceDescriptor.__repr__r   NN)rP   rQ   rR   r   r?   r   r   r   r   r   r   r   r   r   r   r   r   r      s    


r   c                   @   sN   e Zd ZdZdd ZdddZdd ZeZd	d
 Zdd Z	dd Z
dd ZdS )StringSourceDescriptorzu
    Instances of this class can be used instead of a filenames if the
    code originates from a string object.
    c                 C   s$   || _ dd | D | _|| _d S )Nc                 S   r   r   r   r   r   r   r   r      r   z3StringSourceDescriptor.__init__.<locals>.<listcomp>)rB   
splitlines	codelinesr   )r>   rB   coder   r   r   r?      s   
zStringSourceDescriptor.__init__Nc                    s     s| j S  fdd| j D S )Nc                    s   g | ]}|   qS r   )encodedecoder   r   r   r   r     s    z4StringSourceDescriptor.get_lines.<locals>.<listcomp>)r   r   r   r   r   r      s
   z StringSourceDescriptor.get_linesc                 C   r   r   rB   r   r   r   r   r     r   z&StringSourceDescriptor.get_descriptionc                 C   s   dS )Nz<stringsource>r   r   r   r   r   r     r   z.StringSourceDescriptor.get_filenametable_entryc                 C   s   t | S r   )idr   r   r   r   r     s   zStringSourceDescriptor.__hash__c                 C   r   r   )r   r   rB   rG   r   r   r   r     r   zStringSourceDescriptor.__eq__c                 C   r   )Nz<StringSourceDescriptor:%s>r   r   r   r   r   r     rL   zStringSourceDescriptor.__repr__r   )rP   rQ   rR   r   r?   r   r   r   r   r   r   r   r   r   r   r   r      s    
r   c                   @   sV  e Zd Z		dRddZdd Zdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd ZdddddZdefdd Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zdefd1d2Zd3d4 Zd5d6 Zd7d8 Zd9d: ZdSd;d<Zd=d> ZdTd?d@Z dTdAdBZ!dTdCdDZ"dEdF Z#dGdH Z$dUdKe%j&fdLdMZ'dNdO Z(dPdQ Z)dS )VPyrexScannerNTc	           
      C   s  t | t ||| | rd| _t}	nd| _t}	dd |	D | _d| _|rB|j	| _	|j
| _
|j| _|j| _|j| _|jrA|   n || _	|j
| _
t | _d| _d| _t|jdd rb| j|jj || _|| _t| _dg| _d| _d| _g | _d| _d | _| d	 d
| _|   d S )NTFc                 S   s   i | ]}||qS r   r   )r   keywordr   r   r   
<dictcomp>1  s    z)PyrexScanner.__init__.<locals>.<dictcomp>r   r   compile_time_env INDENTr   ) r   r?   r   r   Zin_python_filepy_reserved_wordspyx_reserved_wordskeywordsasync_enabledcontextZincluded_filesr   Zcompile_time_evalZcompile_time_exprenter_asyncr   r   optionsrF   parse_commentssource_encodingtrace_scannertraceindentation_stackindentation_charbracket_nesting_levelft_string_state_stackin_ft_string_expr_prescanput_back_on_failurebeginsyrn   )
r>   filer   Zparent_scannerscoper   r   r   Zinitial_posr   r   r   r   r?   '  sH   
zPyrexScanner.__init__c                 C   s"   |  s	td|}| t| d S )NNFKC)isasciir	   producer   r>   textr   r   r   normalize_identV  s   
zPyrexScanner.normalize_identc                 C   s   | j r| d| d S d S )Ncommentline)r   r   r   r   r   r   r   [  s   zPyrexScanner.commentlinec                 C   s   |  ||dd d S )N_r   )r   r   )r>   r   symbolr   r   r   strip_underscores_  s   zPyrexScanner.strip_underscoresc                 C   s
   | j d S N)r   r   r   r   r   current_levelb  rL   zPyrexScanner.current_levelc                 C   s   |  j d7  _ |S Nr   r   r   r   r   r   open_bracket_actione     z PyrexScanner.open_bracket_actionc                 C   s   |  j d8  _ |S r  r  r   r   r   r   close_bracket_actioni  r
  z!PyrexScanner.close_bracket_actionc                 C   s
   |  |S r   )r	  r   r   r   r   open_brace_actionm  rL   zPyrexScanner.open_brace_actionc                 C   s   |dksJ | j r;| j d  | jkr;| j d  s+|  jd8  _| jdkr+| d | | j d j | j d   |  jd8  _|S )N}r  r   r   END_FT_STRING_EXPR)r   r   in_format_specifierr   r   r   scanner_statepop_bracket_stater   r   r   r   close_brace_actionp  s   

zPyrexScanner.close_brace_actionc                 C   s`   | j r.| j d  | jkr.|  jd8  _| jdkr| d | | j d j | j d   |S )Nr  r   r   r  )r   r   r   r   r   r  set_in_format_specifierr   r   r   r   colon_action}  s   

zPyrexScanner.colon_actionc                 C   s(   | j dkr| d | dd d S d S )Nr   r   NEWLINEr   )r   r   r   r   r   r   r   newline_action  s   

zPyrexScanner.newline_actionZ	SQ_STRINGZ	DQ_STRINGZ
TSQ_STRINGZ
TDQ_STRING)'"z'''z"""r   c                 C   sJ   |r|d t v r|dd  }|r|d t v s| | j|  | d d S )Nr   r   ZBEGIN_STRING)r   r   string_statesr   r   r   r   r   begin_string_action  s
   z PyrexScanner.begin_string_actionc                 C   s"   |  | jrdnd | d d S )NFT_STRING_EXPR_PRESCANr   Z
END_STRING)r   r   r   r   r   r   r   end_string_action  s   zPyrexScanner.end_string_actionc                 C   s   d|v pd|v }|r*|d t v s|d tv r*|dd  }|r*|d t v s|d tv s| j|  d|r4dnd }| jt| | | | d d S )NrRr   r   Z_FTr   ZBEGIN_FT_STRING)r   r   r  r   appendFTStringStater   r   )r>   r   Zis_rawZft_string_stater   r   r   begin_ft_string_action  s   
z#PyrexScanner.begin_ft_string_actionc                 C   s,   | j   | | jrdnd | d d S )Nr  r   ZEND_FT_STRING)r   popr   r   r   r   r   r   r   end_ft_string_action  s   
z!PyrexScanner.end_ft_string_actionc                 C   sJ   |  j d7  _ |s| jd | j  | d |  jd7  _| d d S )Nr   r  r  {)r   r   push_bracket_stater   r   r   )r>   started_ft_string_exprr   r   r   #_handle_open_single_ft_string_brace  s   
z0PyrexScanner._handle_open_single_ft_string_bracec                 C   s   t |}d}| jd  r| | |d8 }d}| jd  r!J |d }t|D ]}| dd q)||d 8 }|rG|dks@J | | d S d S )NFr  r   Tr   CHARSr$  )ri   r   r  r'  rr   r   )r>   r   len_textr&  double_bracesr  r   r   r   open_ft_string_brace_action  s   
z(PyrexScanner.open_ft_string_brace_actionc                 C   sZ   | j d  }|d u s| j|k r"| jd|  dd | dd d S | | dd d S )Nr  z/f-string or t-string: single '}' is not allowedF)posfatalr  )r   r   r   get_current_scan_posr   r  )r>   Zft_string_bracket_levelr   r   r   $_handle_close_single_ft_string_brace  s   z1PyrexScanner._handle_close_single_ft_string_bracec                 C   s~   t |}|r| jd  r|   |d8 }|r| jd  s|d }t|D ]}| dd q&||d 8 }|r=|   d S d S )Nr  r   r   r(  r  )ri   r   r  r/  rr   r   )r>   r   r)  r*  r  r   r   r   close_ft_string_brace_action  s   z)PyrexScanner.close_ft_string_brace_actionc                 C   s   |  | | d d S )NzUnclosed string literal)r  error_at_scanposr   r   r   r   unclosed_string_action  s   
z#PyrexScanner.unclosed_string_actionc                 C   s   |  d |r+|d }| jdkr|| _n
| j|kr| d ||ddkr+| d |  }t|}||kr9d S ||krK| j| | dd d S ||  k rb| j	  | dd ||  k sQ||  kro| d d S d S )Nr   r   r   zMixed use of tabs and spacesr   DEDENTzInconsistent indentation)
r   r   r1  r   r  ri   r   r  r   r"  )r>   r   cr  Z	new_levelr   r   r   indentation_action  s.   





zPyrexScanner.indentation_actionc                 C   sB   t | jdkr| dd | j  t | jdks| dd d S )Nr   r3  r   EOF)ri   r   r   r"  r   r   r   r   
eof_action  s
   
zPyrexScanner.eof_actionc                 C   s   z|   \}}W n ty   | d Y d S w |tkrP|| jv rJ|dkr3t| jjv r3| jdd  n|dkrE| jj	dkrE| jdd  n| j| }| j
|}| jd ur`| j|||  f || _|| _d S )NzUnrecognized characterr   r&      )readr   r1  r   r   r   r   Zfuture_directivesr"  Zlanguage_levelintern_ustringr   r  positionr   systringr   )r>   r   r<  r  r   coltr   r   r   rn     s&   



zPyrexScanner.nextc                 C   sT   | j | jf}|  }|   | j | jf}| | j | j|   |\| _ | _|| _|S r   )r   r<  r;  rn   unreadlast_token_position_tuple)r>   saved	saved_posrn   r   r   r   peek,  s   zPyrexScanner.peekc                 C   s*   |  | j| j| j || _|| _|| _d S r   )r?  r   r<  r@  )r>   r   r<  r,  r   r   r   put_back6  s   
zPyrexScanner.put_backc                 C   s:   |d u r|   }| jdkrt|d t||}|r|d S )Nr   z!Possible inconsistent indentation)r;  r   r   )r>   messager,  r-  errr   r   r   r   =  s   


zPyrexScanner.errorc                 C   s   |   }| ||d d S NT)r.  r   )r>   rE  r,  r   r   r   r1  E  s   zPyrexScanner.error_at_scanposc                 C   s&   | j |kr|   d S | || d S r   )r   rn   expectedr>   whatrE  r   r   r   expectK  s   
zPyrexScanner.expectc                 C   s0   | j tkr| j|kr|   d S | || d S r   )r   r   r<  rn   rH  rI  r   r   r   expect_keywordQ  s   zPyrexScanner.expect_keywordc                 C   s@   |r	|  | d S | jtkr| j}n| j}|  d||f  d S )NzExpected '%s', found '%s')r   r   r   r<  )r>   rJ  rE  foundr   r   r   rH  W  s   
zPyrexScanner.expectedc                 C      |  dd d S )Nr   z)Expected an increase in indentation levelrK  r   r   r   r   expect_indenta  rI   zPyrexScanner.expect_indentc                 C   rN  )Nr3  z(Expected a decrease in indentation levelrO  r   r   r   r   expect_dedentd  rI   zPyrexScanner.expect_dedentExpected a newlineFignore_semicolonc                 C   sR   d }|r| j dkr|  }|   | j dkr| d| |d ur't|d d S d S )N;r6  r  zuseless trailing semicolon)r   r;  rn   rK  r   )r>   rE  rS  Zuseless_trailing_semicolonr   r   r   expect_newlineg  s   
zPyrexScanner.expect_newlinec                 C   s4   |  j d7  _ | j dkrd| jd< d| jd< d S d S )Nr   asyncawait)r   r   r   r   r   r   r   r  s
   

zPyrexScanner.enter_asyncc                 C   s`   | j dksJ |  j d8  _ | j s,| jd= | jd= | jdv r.t| j| j| _| _d S d S d S )Nr   r   rW  rV  )rV  rW  )r   r   r   r   r   r:  r<  r   r   r   r   
exit_asyncx  s   
zPyrexScanner.exit_async)NNNNTNrG  r   )rR  F)*rP   rQ   rR   r?   r   r   r  r  r	  r  r  r  r  r  r  ry   r  r  r!  r#  r'  r+  r/  r0  r2  r5  r7  rn   rC  rD  r   r1  rK  rL  rH  rP  rQ  cythonZbintrU  r   rX  r   r   r   r   r     sV    	
/
$





r   scannerc              
   c   s&   t  }z| j}g | _| j| j|  f}zCz|V  W n ty, } zW Y d }~nd }~ww W |rJ| jrIt| jd d D ]}| j|  q<| j|  n
|d urT|| j || _n-|rw| jrst| jd d D ]}| j|  qf| j|  || _w |d ur|| j || _w W t	dd d S t	dd w )Nr  T)ignore)
r   r   r   r<  r;  r   rt   rD  extendr   )rZ  errorsr   Zinitial_stateerD  r   r   r   tentatively_scan  s@   



r_  c                   @   sB   e Zd Zdd Zdd Zdd Zdd Zd	efd
dZdd Z	dS )r   c                 C   s   || _ g | _d S r   )r  bracket_states)r>   r  r   r   r   r?     r@   zFTStringState.__init__c                 C   s   | j sd S | j d jS r  )r`  r   r   r   r   r   r        z#FTStringState.bracket_nesting_levelc                 C   s   | j sdS | j d jS )NFr  r`  r  r   r   r   r   r    ra  z!FTStringState.in_format_specifierc                 C   s   d| j d _d S )NTr  rb  r   r   r   r   r    rI   z%FTStringState.set_in_format_specifierr   c                 C   s   | j t| d S r   )r`  r  FTStringBracketStater>   r   r   r   r   r%    s   z FTStringState.push_bracket_statec                 C   s   | j   d S r   )r`  r"  r   r   r   r   r    rE   zFTStringState.pop_bracket_stateN)
rP   rQ   rR   r?   r   r  r  rh   r%  r  r   r   r   r   r     s    r   c                   @   s0   e Zd ZU dZeed< eed< defddZdS )rc  r   r  r   r  c                 C   s   || _ d| _d S r   re  rd  r   r   r   r?     r@   zFTStringBracketState.__init__N)rP   rQ   rR   	__slots__rh   __annotations__rZ   r?   r   r   r   r   rc    s
   
 rc  )-rY  rD   objectr   r   unicodedatar	   
contextlibr
   r   r   ZPlex.Scannersr   ZPlex.Errorsr   ZErrorsr   r   r   r   r   ZLexiconr   r   r   r   Futurer   Zdebug_scannerr   Zscanner_debug_flagsZscanner_dump_filer   r   r   r   r;   r   r   r   r   r   r_  r   rc  r   r   r   r   <module>   sF   	#;A)  e