o
    fN                  	   @   sX  d dl mZ 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 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eZ%dd Z&G dd deZ'G dd de'Z(G dd de'Z)G dd deZ*e
ej+eddd  Z,dS )!    )absolute_importN)make_lexiconlexiconprint_functionerrorwarningosplatform)	normalize)contextmanager   )Utils)Scanner)UnrecognizedInput   )r   r   hold_errorsrelease_errorsCompileError)any_string_prefixr   IDENT)r   c                   C   s   t st a t S N)r   r    r   r   T/var/www/html/mig_web/myenv/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)	includectypedefcdefcpdefcimportDEFIF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)selfrD   r   r   r   __init__<   s   
zCompileTimeScope.__init__c                 C   s   || j |< d S r   rC   )rE   namevaluer   r   r   declare@   s   zCompileTimeScope.declarec                 C   s   | j | d S r   )rC   updaterE   otherr   r   r   rK   C      zCompileTimeScope.updatec                 C   s
   | j | S r   rG   rE   rH   r   r   r   lookup_hereF      
zCompileTimeScope.lookup_herec                 C   s
   || j v S r   rG   rO   r   r   r   __contains__I   rQ   zCompileTimeScope.__contains__c                 C   s6   z|  |W S  ty   | j}|r|| Y S  w r   )rP   KeyErrorrD   lookup)rE   rH   rD   r   r   r   rT   L   s   zCompileTimeScope.lookupr   )	__name__
__module____qualname__rF   rJ   rK   rP   rR   rT   r   r   r   r   rB   :   s    
rB   c               	   C   s   t  } d}t|t D ]
\}}| || qzdd l}W n ty*   dd l}Y nw d}|D ]}z| |t|| W q/ t	yE   Y q/w ddl
m} | d| | dt|dt|d | dt|dt|d	 | d
t|d
t|d t | }|S )N)UNAME_SYSNAMEUNAME_NODENAMEUNAME_RELEASEUNAME_VERSIONUNAME_MACHINEr   )*FalseTrueabsallanyasciibinbool	bytearraybyteschrcmpcomplexdictdivmod	enumeratefilterfloatformat	frozensethashhexintlenlistmapmaxminoctordpowrangereprreversedroundsetslicesortedstrsumtuplezip)reducer   unicoder   longrs   xranger|   )rB   r   r	   unamerJ   __builtin__ImportErrorbuiltinsgetattrAttributeError	functoolsr   )benvnamesrH   rI   r   r   denvr   r   r   initial_compile_time_envW   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   rE   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)rE   filenamerH   extr   r   r   set_file_type_from_name   s   z(SourceDescriptor.set_file_type_from_namec                 C   s
   | j dv S )N)r   pxdr   r   r   r   r   is_cython_file   rQ   zSourceDescriptor.is_cython_filec                 C   s
   | j dkS )Npyr   r   r   r   r   is_python_file   rQ   zSourceDescriptor.is_python_filec                 C   s4   | j d u r|  ddd}|dd| _ | j S )NASCIIreplace\/)_escaped_descriptionget_descriptionencodedecoder   )rE   esc_descr   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_namer   rL   r   r   r   __gt__   
   zSourceDescriptor.__gt__c                 C   s$   z| j |j k W S  ty   Y dS w r   r   rL   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   rL   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   )rE   memor   r   r   __deepcopy__   r   zSourceDescriptor.__deepcopy__)rU   rV   rW   __doc__r   in_utility_coder   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s"    	r   c                   @   sT   e Zd Z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   sf   t |}|p|| _|| _tjdtj }||r#|t	|d  n|| _
| | || _i | _d S )N.)r   decode_filenamepath_descriptionr   r   r   abspathsep
startswithrt   	file_pathr   r   _lines)rE   r   r   workdirr   r   r   rF      s   

 

zFileSourceDescriptor.__init__c                 C   s   ||f}z| j | }|d ur|W S W n	 ty   Y nw tj| j||d}t|}W d    n1 s4w   Y  || j v rE|| j |< |S d | j |< |S )Nencodingerror_handling)r   rS   r   open_source_filer   ru   )rE   r   r   keylinesfr   r   r   	get_lines   s"   




zFileSourceDescriptor.get_linesc                 C   s*   zt j| jW S  ty   | j Y S w r   )r   r   relpathr   
ValueErrorr   r   r   r   r      s
   
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   rt   )rE   r   cwdr   r   r   get_error_description   s
   
z*FileSourceDescriptor.get_error_descriptionc                 C      | j S r   )r   r   r   r   r   get_filenametable_entry      z,FileSourceDescriptor.get_filenametable_entryc                 C      t |to
| j|jkS r   )
isinstancer   r   rL   r   r   r   __eq__      zFileSourceDescriptor.__eq__c                 C   s
   t | jS r   )rq   r   r   r   r   r   __hash__   rQ   zFileSourceDescriptor.__hash__c                 C   
   d| j  S )Nz<FileSourceDescriptor:%s>)r   r   r   r   r   __repr__   rQ   zFileSourceDescriptor.__repr__r   NN)rU   rV   rW   r   rF   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 | _|| _d S )Nc                 S   s   g | ]}|d  qS )
r   ).0xr   r   r   
<listcomp>
  s    z3StringSourceDescriptor.__init__.<locals>.<listcomp>r   )rH   split	codelinesr   )rE   rH   coder   r   r   rF     s   
zStringSourceDescriptor.__init__Nc                    s     s| j S  fdd| j D S )Nc                    s   g | ]}|   qS r   )r   r   )r   liner   r   r   r     s    z4StringSourceDescriptor.get_lines.<locals>.<listcomp>)r   )rE   r   r   r   r   r   r     s
   z StringSourceDescriptor.get_linesc                 C   r   r   rH   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   rH   rL   r   r   r   r   "  r   zStringSourceDescriptor.__eq__c                 C   r   )Nz<StringSourceDescriptor:%s>r   r   r   r   r   r   %  rQ   zStringSourceDescriptor.__repr__r   )rU   rV   rW   r   rF   r   r   r   r   r   r   r   r   r   r   r   r     s    
r   c                   @   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d Z	dd Z
ddd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)Zd*d+ Zd@d,d-Zd@d.d/Zd@d0d1Zd2d3 Zd4d5 ZdAd8d9Zd:d; Zd<d= ZdS )B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| _d | _| d d	| _|   d S )
NTFc                 S   s   i | ]}||qS r   r   )r   keywordr   r   r   
<dictcomp>>  s    z)PyrexScanner.__init__.<locals>.<dictcomp>r   r   compile_time_envINDENTr   )r   rF   r   r   in_python_filepy_reserved_wordspyx_reserved_wordskeywordsasync_enabledcontextincluded_filesr   compile_time_evalcompile_time_exprenter_asyncr   r   optionsrK   parse_commentssource_encodingtrace_scannertraceindentation_stackindentation_charbracket_nesting_levelput_back_on_failurebeginsynext)
rE   filer   parent_scannerscoper   r   r   initial_posr   r   r   r   rF   4  sD   
zPyrexScanner.__init__c                 C   s<   z| d W n ty   td|}Y nw | t| d S )Nrb   NFKC)r   UnicodeEncodeErrorr
   producer   rE   textr   r   r   normalize_ident`  s   zPyrexScanner.normalize_identc                 C   s   | j r| d| d S d S )Ncommentline)r   r  r  r   r   r   r  g  s   zPyrexScanner.commentlinec                 C   s   |  ||dd d S )N_r   )r  r   )rE   r  symbolr   r   r   strip_underscoresk  s   zPyrexScanner.strip_underscoresc                 C   s
   | j d S )N)r   r   r   r   r   current_leveln  rQ   zPyrexScanner.current_levelc                 C   s   |  j d7  _ |S Nr   r  r  r   r   r   open_bracket_actionq     z PyrexScanner.open_bracket_actionc                 C   s   |  j d8  _ |S r  r  r  r   r   r   close_bracket_actionu  r  z!PyrexScanner.close_bracket_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_actiony  s   

zPyrexScanner.newline_action	SQ_STRING	DQ_STRING
TSQ_STRING
TDQ_STRING)'"z'''z"""c                 C   sJ   |d d t v r|dd  }|d d t v s| | j|  | d d S )Nr   BEGIN_STRING)r   r  string_statesr  r  r   r   r   begin_string_action  s
   z PyrexScanner.begin_string_actionc                 C   s   |  d | d d S )Nr   
END_STRING)r  r  r  r   r   r   end_string_action     
zPyrexScanner.end_string_actionc                 C   s   |  | | d d S )NzUnclosed string literal)r'  error_at_scanposr  r   r   r   unclosed_string_action  r(  z#PyrexScanner.unclosed_string_actionc                 C   s   |  d |r+|d }| jd u 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   zMixed use of tabs and spacesr   DEDENTzInconsistent indentation)
r  r   r)  r   r  rt   r   appendr  pop)rE   r  cr  	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   r+  r   EOF)rt   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   r)  r   r   r   r   future_directivesr-  language_levelintern_ustringr  r,  positionr  systringr   )rE   r  r9  r  r   coltr   r   r   r    s&   



zPyrexScanner.nextc                 C   sT   | j | jf}|  }|   | j | jf}| | j | j|   |\| _ | _|| _|S r   )r  r9  r8  r  unreadlast_token_position_tuple)rE   saved	saved_posr  r   r   r   peek  s   zPyrexScanner.peekc                 C   s*   |  | j| j| j || _|| _|| _d S r   )r<  r  r9  r=  )rE   r  r9  posr   r   r   put_back  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)r8  r  r   )rE   messagerA  fatalerrr   r   r   r     s   


zPyrexScanner.errorc                 C   s   |   }| ||d d S NT)get_current_scan_posr   )rE   rC  rA  r   r   r   r)    s   zPyrexScanner.error_at_scanposc                 C   s&   | j |kr|   d S | || d S r   )r  r  expectedrE   whatrC  r   r   r   expect  s   
zPyrexScanner.expectc                 C   s0   | j tkr| j|kr|   d S | || d S r   )r  r   r9  r  rH  rI  r   r   r   expect_keyword  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   r9  )rE   rJ  rC  foundr   r   r   rH    s   
zPyrexScanner.expectedc                 C      |  dd d S )Nr   z)Expected an increase in indentation levelrK  r   r   r   r   expect_indent  rN   zPyrexScanner.expect_indentc                 C   rN  )Nr+  z(Expected a decrease in indentation levelrO  r   r   r   r   expect_dedent  rN   zPyrexScanner.expect_dedentExpected a newlineFc                 C   sR   d }|r| j dkr|  }|   | j dkr| d| |d ur't|d d S d S )N;r1  r  zuseless trailing semicolon)r  r8  r  rK  r   )rE   rC  ignore_semicolonuseless_trailing_semicolonr   r   r   expect_newline  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     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   rX  rW  )rW  rX  )r   r   r  r   r   r7  r9  r   r   r   r   
exit_async$  s   
zPyrexScanner.exit_async)NNNNTNrF  r   )rR  F)rU   rV   rW   rF   r  r  r  r  r  r  r  r$  r%  r'  r*  r0  r2  r  r@  rB  r   r)  rK  rL  rH  rP  rQ  rV  r   rY  r   r   r   r   r   +  sD    	
,$






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  r9  r8  r   r~   rB  extendr   )rZ  errorsr  initial_stateerB  r   r   r   tentatively_scan-  s@   



r`  )-
__future__r   cythonrJ   objectr   r	   unicodedatar
   
contextlibr   r   r   Plex.Scannersr   Plex.Errorsr   Errorsr   r   r   r   r   Lexiconr   r   r   Futurer   debug_scannerr   scanner_debug_flagsscanner_dump_filer   r   r   r   rB   r   r   r   r   r   localsr`  r   r   r   r   <module>   sF   	*=D)  
