o
    Ni|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   L/home/ubuntu/.local/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__;      
zCompileTimeScope.__init__c                 C   s   || j |< d S r   rC   )rE   namevaluer   r   r   declare?      zCompileTimeScope.declarec                 C   s   | j | d S r   )rC   updaterE   otherr   r   r   rM   B      zCompileTimeScope.updatec                 C   s
   | j | S r   rH   rE   rI   r   r   r   lookup_hereE      
zCompileTimeScope.lookup_herec                 C   s
   || j v S r   rH   rQ   r   r   r   __contains__H   rS   zCompileTimeScope.__contains__c                 C   s6   z|  |W S  ty   | j}|r|| Y S  w r   )rR   KeyErrorrD   lookup)rE   rI   rD   r   r   r   rV   K   s   zCompileTimeScope.lookupr   )	__name__
__module____qualname__rF   rK   rM   rR   rT   rV   r   r   r   r   rB   9   s    
rB   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)UNAME_SYSNAMEUNAME_NODENAMEUNAME_RELEASEUNAME_VERSION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)rB   r   r   unamerK   builtinsgetattr	functoolsr   r   rt   r~   )benvnamesrI   rJ   r   r   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   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   filenamerI   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   rS   zSourceDescriptor.is_cython_filec                 C   s
   | j dkS )Npyr   r   r   r   r   is_python_file   rS   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AttributeErrorrN   r   r   r   __gt__   
   zSourceDescriptor.__gt__c                 C   s$   z| j |j k W S  ty   Y dS w r   r   rN   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   rN   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__)rW   rX   rY   __doc__r   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
startswithru   	file_pathr   r   _lines)rE   r   r   workdirr   r   r   rF      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)rE   r   r   keylinesfr   r   r   	get_lines   s   zFileSourceDescriptor.get_linesc                 C   s   t | j||S r   )r   open_source_filer   rE   r   r   r   r   r   r      rP   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   ru   )rE   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   rN   r   r   r   __eq__      zFileSourceDescriptor.__eq__c                 C   s
   t | jS r   )rr   r   r   r   r   r   __hash__   rS   zFileSourceDescriptor.__hash__c                 C   
   d| j  S )Nz<FileSourceDescriptor:%s>)r   r   r   r   r   __repr__   rS   zFileSourceDescriptor.__repr__r   NN)rW   rX   rY   r   rF   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>)rI   
splitlines	codelinesr   )rE   rI   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   )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   rI   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   rI   rN   r   r   r   r     r   zStringSourceDescriptor.__eq__c                 C   r   )Nz<StringSourceDescriptor:%s>r   r   r   r   r   r     rS   zStringSourceDescriptor.__repr__r   )rW   rX   rY   r   rF   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   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   optionsrM   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syrz   )
rE   filer   parent_scannerscoper   r  r  initial_posr   r   r   r   rF   '  sH   
zPyrexScanner.__init__c                 C   s"   |  s	td|}| t| d S )NNFKC)isasciir	   producer   rE   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   )rE   r  symbolr   r   r   strip_underscores_  s   zPyrexScanner.strip_underscoresc                 C   s
   | j d S N)r  r   r   r   r   current_levelb  rS   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  rS   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_action	SQ_STRING	DQ_STRING
TSQ_STRING
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   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   
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   _FTr   BEGIN_FT_STRING)r   r   r6  r	  appendFTStringStater  r  )rE   r  is_raw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 )Nr8  r   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  r8  {)r  r	  push_bracket_stater  r
  r  )rE   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   CHARSrG  )ru   r	  r'  rJ  r~   r  )rE   r  len_textrI  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*  )rE   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   rK  r%  )ru   r	  r'  rS  r~   r  )rE   r  rL  rM  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  rU  r   r  ru   r  r?  r  rE  )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   rW  r   EOF)ru   r  r  rE  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   rU  r   r   r   r   future_directivesrE  language_levelintern_ustringr  r?  positionr  systringr   )rE   r  rc  r  r   coltr   r   r   rz     s&   



zPyrexScanner.nextc                 C   sT   | j | jf}|  }|   | j | jf}| | j | j|   |\| _ | _|| _|S r   )r  rc  rb  rz   unreadlast_token_position_tuple)rE   saved	saved_posrz   r   r   r   peek,  s   zPyrexScanner.peekc                 C   s*   |  | j| j| j || _|| _|| _d S r   )rf  r  rc  rg  )rE   r  rc  rO  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)rb  r  r   )rE   messagerO  rP  errr   r   r   r   =  s   


zPyrexScanner.errorc                 C   s   |   }| ||d d S NT)rQ  r   )rE   rl  rO  r   r   r   rU  E  s   zPyrexScanner.error_at_scanposc                 C   s&   | j |kr|   d S | || d S r   )r  rz   expectedrE   whatrl  r   r   r   expectK  s   
zPyrexScanner.expectc                 C   s0   | j tkr| j|kr|   d S | || d S r   )r  r   rc  rz   ro  rp  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   rc  )rE   rq  rl  foundr   r   r   ro  W  s   
zPyrexScanner.expectedc                 C      |  dd d S )Nr   z)Expected an increase in indentation levelrr  r   r   r   r   expect_indenta  rP   zPyrexScanner.expect_indentc                 C   ru  )NrW  z(Expected a decrease in indentation levelrv  r   r   r   r   expect_dedentd  rP   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;r[  r-  zuseless trailing semicolon)r  rb  rz   rr  r   )rE   rl  rz  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   r  r~  )r~  r  )r   r   r  r   r   ra  rc  r   r   r   r   
exit_asyncx  s   
zPyrexScanner.exit_async)NNNNTNrn  r   )ry  F)*rW   rX   rY   rF   r  r  r  r  r!  r#  r$  r*  r,  r.  r6  r   r7  r:  rC  rF  rJ  rN  rS  rT  rV  rZ  r\  rz   rj  rk  r   rU  rr  rs  ro  rw  rx  cythonbintr}  r   r  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  rc  rb  r   r   rk  extendr   )r  errorsr  initial_stateerk  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)rE   r(  r   r   r   rF     rG   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'    r  z!FTStringState.in_format_specifierc                 C   s   d| j d _d S )NTr  r  r   r   r   r   r+    rP   z%FTStringState.set_in_format_specifierr  c                 C   s   | j t| d S r   )r  r?  FTStringBracketStaterE   r  r   r   r   rH    s   z FTStringState.push_bracket_statec                 C   s   | j   d S r   )r  rE  r   r   r   r   r)    rL   zFTStringState.pop_bracket_stateN)
rW   rX   rY   rF   r  r'  r+  rt   rH  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 )r  r  r'  r  r'  c                 C   s   || _ d| _d S r   r  r  r   r   r   rF     rG   zFTStringBracketState.__init__N)rW   rX   rY   	__slots__rt   __annotations__rf   rF   r   r   r   r   r    s
   
 r  )-r  rK   objectr   r   unicodedatar	   
contextlibr
   r   r   Plex.Scannersr   Plex.Errorsr   Errorsr   r   r   r   r   Lexiconr   r   r   r   Futurer   debug_scannerr  scanner_debug_flagsscanner_dump_filer   r   r   r   rB   r   r   r   r   r   r  r@  r  r   r   r   r   <module>   sF   	#;A)  e