o
    wiN                  	   @   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 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)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_prefixr   IDENT)r   c                   C   s   t st a t S N)r   r    r   r   U/home/ubuntu/sommelier/.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)	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)selfrC   r   r   r   __init__;   s   
zCompileTimeScope.__init__c                 C   s   || j |< d S r   rB   )rD   namevaluer   r   r   declare?   s   zCompileTimeScope.declarec                 C   s   | j | d S r   )rB   updaterD   otherr   r   r   rJ   B      zCompileTimeScope.updatec                 C   s
   | j | S r   rF   rD   rG   r   r   r   lookup_hereE      
zCompileTimeScope.lookup_herec                 C   s
   || j v S r   rF   rN   r   r   r   __contains__H   rP   zCompileTimeScope.__contains__c                 C   s6   z|  |W S  ty   | j}|r|| Y S  w r   )rO   KeyErrorrC   lookup)rD   rG   rC   r   r   r   rS   K   s   zCompileTimeScope.lookupr   )	__name__
__module____qualname__rE   rI   rJ   rO   rQ   rS   r   r   r   r   rA   9   s    
rA   c               	   C   s   t  } d}t|t D ]
\}}| || qdd l}d}|D ]}z| |t|| W q ty5   Y qw ddlm	} | d| | dt
 | 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   unicodelongrr   xranger{   )rA   r   r   unamerI   builtinsgetattrAttributeError	functoolsr   r   )benvnamesrG   rH   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   rD   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)rD   filenamerG   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   rP   zSourceDescriptor.is_cython_filec                 C   s
   | j dkS )Npyr   r   r   r   r   is_python_file   rP   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_namer   rK   r   r   r   __gt__   
   zSourceDescriptor.__gt__c                 C   s$   z| j |j k W S  ty   Y dS w r   r   rK   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   rK   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   )rD   memor   r   r   __deepcopy__   r   zSourceDescriptor.__deepcopy__)rT   rU   rV   __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                   @   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
startswithrs   	file_pathr   r   _lines)rD   r   r   workdirr   r   r   rE      s   

 

zFileSourceDescriptor.__init__c                 C   s   ||f}z| j | }|d ur|W S W n	 ty   Y nw | j||d}| }W d    n1 s2w   Y  || j v rC|| j |< |S d | j |< |S )Nencodingerror_handling)r   rR   get_file_object	readlines)rD   r   r   keylinesfr   r   r   	get_lines   s"   




zFileSourceDescriptor.get_linesc                 C   s   t | j||S r   )r   open_source_filer   rD   r   r   r   r   r   r      rM   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   rs   )rD   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   rK   r   r   r   __eq__      zFileSourceDescriptor.__eq__c                 C   s
   t | jS r   )rp   r   r   r   r   r   __hash__   rP   zFileSourceDescriptor.__hash__c                 C   
   d| j  S )Nz<FileSourceDescriptor:%s>)r   r   r   r   r   __repr__   rP   zFileSourceDescriptor.__repr__r   NN)rT   rU   rV   r   rE   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 | _|| _d S )Nc                 S   s   g | ]}|d  qS )
r   ).0xr   r   r   
<listcomp>  s    z3StringSourceDescriptor.__init__.<locals>.<listcomp>r   )rG   split	codelinesr   )rD   rG   coder   r   r   rE     s   
zStringSourceDescriptor.__init__Nc                    s     s| j S  fdd| j D S )Nc                    s   g | ]}|   qS r   )encodedecode)r   liner   r   r   r     s    z4StringSourceDescriptor.get_lines.<locals>.<listcomp>)r   r   r   r   r   r     s
   z StringSourceDescriptor.get_linesc                 C   r   r   rG   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   rG   rK   r   r   r   r      r   zStringSourceDescriptor.__eq__c                 C   r   )Nz<StringSourceDescriptor:%s>r   r   r   r   r   r   #  rP   zStringSourceDescriptor.__repr__r   )rT   rU   rV   r   rE   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efddZdd Zdd Zdefdd Zd!d" Zd#d$ Zd%d& Zd'd( ZdAd)d*Zd+d, ZdBd-d.ZdBd/d0ZdBd1d2Zd3d4 Zd5d6 ZdCd9ejfd:d;Zd<d= Zd>d? Z dS )D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   rE   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   optionsrJ   parse_commentssource_encodingtrace_scannertraceindentation_stackindentation_charbracket_nesting_levelput_back_on_failurebeginsynext)
rD   filer   parent_scannerscoper   r   r   initial_posr   r   r   r   rE   2  sD   
zPyrexScanner.__init__c                 C   s"   |  s	td|}| t| d S )NNFKC)isasciir	   producer   rD   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  c  s   zPyrexScanner.commentlinec                 C   s   |  ||dd d S )N_r   )r  r   )rD   r  symbolr   r   r   strip_underscoresg  s   zPyrexScanner.strip_underscoresc                 C   s
   | j d S )N)r   r   r   r   r   current_levelj  rP   zPyrexScanner.current_levelc                 C   s   |  j d7  _ |S Nr   r  r  r   r   r   open_bracket_actionm     z PyrexScanner.open_bracket_actionc                 C   s   |  j d8  _ |S r  r  r  r   r   r   close_bracket_actionq  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_actionu  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   |  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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   r)  r   r  rs   r   appendr  pop)rD   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)rs   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   )rD   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)rD   saved	saved_posr  r   r   r   peek  s   zPyrexScanner.peekc                 C   s*   |  | j| j| j || _|| _|| _d S r   )r<  r  r9  r=  )rD   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   )rD   messagerA  fatalerrr   r   r   r     s   


zPyrexScanner.errorc                 C   s   |   }| ||d d S NT)get_current_scan_posr   )rD   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rD   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  )rD   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	  rM   zPyrexScanner.expect_indentc                 C   rN  )Nr+  z(Expected a decrease in indentation levelrO  r   r   r   r   expect_dedent  rM   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;r1  r  zuseless trailing semicolon)r  r8  r  rK  r   )rD   rC  rS  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)!rT   rU   rV   rE   r  r  r  r  r  r  r  r$  r   r%  r'  r*  r0  r2  r  r@  rB  r   r)  rK  rL  rH  rP  rQ  cythonbintrV  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   )r\  errorsr  initial_stateerB  r   r   r   tentatively_scan)  s@   



rb  )*rZ  rI   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   rA   r   r   r   r   r   rb  r   r   r   r   <module>   sB   	';H)  