3
hN                 @   s  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"ddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.gZ#e#d/d0d1d2d3d4d5d6d7g	 Z$G d8d9 d9eZ%d:d; Z&G d<d= d=eZ'G d>d? d?e'Z(G d@dA dAe'Z)G dBdC dCeZ*e
ej+edDdEdF Z,dS )G    )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   j/var/www/html/CrowdFlow/Picklecon/ble_analysis_env/lib/python3.6/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 )N)entriesouter)selfr<   r   r   r   __init__<   s    zCompileTimeScope.__init__c             C   s   || j |< d S )N)r;   )r=   namevaluer   r   r   declare@   s    zCompileTimeScope.declarec             C   s   | j j| d S )N)r;   update)r=   otherr   r   r   rB   C   s    zCompileTimeScope.updatec             C   s
   | j | S )N)r;   )r=   r?   r   r   r   lookup_hereF   s    zCompileTimeScope.lookup_herec             C   s
   || j kS )N)r;   )r=   r?   r   r   r   __contains__I   s    zCompileTimeScope.__contains__c             C   s:   y
| j |S  tk
r4   | j}|r.|j|S  Y nX d S )N)rD   KeyErrorr<   lookup)r=   r?   r<   r   r   r   rG   L   s    

zCompileTimeScope.lookup)N)	__name__
__module____qualname__r>   rA   rB   rD   rE   rG   r   r   r   r   r:   :   s   
r:   c           2   C   s  t  } d6}x&t|tj D ]\}}| j|| qW ydd l}W n tk
rZ   dd l}Y nX d7}x8|D ]0}y| j|t|| W qf t	k
r   Y qfX qfW dd1l
m} | jd2| | jd3t|d3t|d- | jd4t|d4t|d | jd5t|d5t|d& t | }|S )8N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)reducerz   unicodelongxrange)rK   rL   rM   rN   rO   )*rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   )r:   ry   r	   unamerA   __builtin__ImportErrorbuiltinsgetattrAttributeError	functoolsrz   )Zbenvnamesr?   r@   r   rz   Zdenvr   r   r   initial_compile_time_envW   s6          

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   dst d S )NF)AssertionError)r=   r   r   r   __str__   s    zSourceDescriptor.__str__c             C   s.   t jj|\}}|dkr$|dd  p&d| _d S )N.pyx.pxd.pyr   r   )r   r   r   )r   pathsplitext
_file_type)r=   filenamer?   extr   r   r   set_file_type_from_name   s    z(SourceDescriptor.set_file_type_from_namec             C   s
   | j dkS )Nr   pxd)r   r   )r   )r=   r   r   r   is_cython_file   s    zSourceDescriptor.is_cython_filec             C   s
   | j dkS )Npy)r   )r=   r   r   r   is_python_file   s    zSourceDescriptor.is_python_filec             C   s4   | j d kr.| j jddjd}|jdd| _ | j S )NASCIIreplace\/)_escaped_descriptionget_descriptionencodedecoder   )r=   Zesc_descr   r   r   get_escaped_description   s    
z(SourceDescriptor.get_escaped_descriptionc             C   s&   y| j |j kS  tk
r    dS X d S )NF)	_cmp_namer   )r=   rC   r   r   r   __gt__   s    zSourceDescriptor.__gt__c             C   s&   y| j |j k S  tk
r    dS X d S )NF)r   r   )r=   rC   r   r   r   __lt__   s    zSourceDescriptor.__lt__c             C   s&   y| j |j kS  tk
r    dS X d S )NF)r   r   )r=   rC   r   r   r   __le__   s    zSourceDescriptor.__le__c             C   s   | S )Nr   )r=   r   r   r   __copy__   s    zSourceDescriptor.__copy__c             C   s   | S )Nr   )r=   memor   r   r   __deepcopy__   s    zSourceDescriptor.__deepcopy__)rH   rI   rJ   __doc__r   Z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 j|}|p|| _|| _tjjdtj }|j|rF|t	|d  n|| _
| j| || _i | _d S )N.)r   decode_filenamepath_descriptionr   r   r   abspathsep
startswithrg   	file_pathr   r   _lines)r=   r   r   Zworkdirr   r   r   r>      s    

 
zFileSourceDescriptor.__init__c             C   s   ||f}y| j | }|d k	r |S W n tk
r6   Y nX tj| j||d}t|}W d Q R X || j krt|| j |< n
d | j |< |S )N)encodingerror_handling)r   rF   r   Zopen_source_filer   rh   )r=   r   r   keylinesfr   r   r   	get_lines   s    


zFileSourceDescriptor.get_linesc             C   s*   yt jj| jS  tk
r$   | jS X d S )N)r   r   relpathr   
ValueError)r=   r   r   r   r      s    z$FileSourceDescriptor.get_descriptionc             C   s:   | j }tjtj tjj }|j|r6|t|d  S |S )N)	r   r   r   r   getcwdr   r   r   rg   )r=   r   cwdr   r   r   get_error_description   s
    
z*FileSourceDescriptor.get_error_descriptionc             C   s   | j S )N)r   )r=   r   r   r   get_filenametable_entry   s    z,FileSourceDescriptor.get_filenametable_entryc             C   s   t |to| j|jkS )N)
isinstancer   r   )r=   rC   r   r   r   __eq__   s    zFileSourceDescriptor.__eq__c             C   s
   t | jS )N)rd   r   )r=   r   r   r   __hash__   s    zFileSourceDescriptor.__hash__c             C   s
   d| j  S )Nz<FileSourceDescriptor:%s>)r   )r=   r   r   r   __repr__   s    zFileSourceDescriptor.__repr__)N)NN)rH   rI   rJ   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 |jdD | _|| _d S )Nc             S   s   g | ]}|d  qS )
r   ).0xr   r   r   
<listcomp>
  s    z3StringSourceDescriptor.__init__.<locals>.<listcomp>r   )r?   split	codelinesr   )r=   r?   coder   r   r   r>     s    zStringSourceDescriptor.__init__Nc                s$    s
| j S  fdd| j D S d S )Nc                s   g | ]}|j  j qS r   )r   r   )r   line)r   r   r   r   r     s   z4StringSourceDescriptor.get_lines.<locals>.<listcomp>)r   )r=   r   r   r   )r   r   r   r     s    z StringSourceDescriptor.get_linesc             C   s   | j S )N)r?   )r=   r   r   r   r     s    z&StringSourceDescriptor.get_descriptionc             C   s   dS )Nz<stringsource>r   )r=   r   r   r   r     s    z.StringSourceDescriptor.get_filenametable_entryc             C   s   t | S )N)id)r=   r   r   r   r     s    zStringSourceDescriptor.__hash__c             C   s   t |to| j|jkS )N)r   r   r?   )r=   rC   r   r   r   r   "  s    zStringSourceDescriptor.__eq__c             C   s
   d| j  S )Nz<StringSourceDescriptor:%s>)r?   )r=   r   r   r   r   %  s    zStringSourceDescriptor.__repr__)NN)rH   rI   rJ   r   r>   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dAd.d/ZdBd0d1Zd2d3 Zd4d5 ZdCd8d9Zd:d; Zd<d= ZdS )DPyrexScannerNTc	       
      C   s  t j| t ||| |j r(d| _t}	n
d| _t}	dd |	D | _d| _|r|j	| _	|j
| _
|j| _|j| _|j| _|jr| j  n@|| _	|j
| _
t | _d| _d| _t|jdd r| jj|jj || _|| _t| _dg| _d | _d| _d | _| jd d	| _| j  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   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   optionsrB   parse_commentssource_encodingtrace_scannertraceindentation_stackindentation_charbracket_nesting_levelput_back_on_failurebeginsynext)
r=   filer   Zparent_scannerZscoper   r   r   Zinitial_posr   r   r   r   r>   4  sB    

zPyrexScanner.__init__c             C   s>   y|j d W n tk
r,   td|}Y nX | jt| d S )NrU   NFKC)r   UnicodeEncodeErrorr
   producer   )r=   textr   r   r   normalize_ident`  s
    zPyrexScanner.normalize_identc             C   s   | j r| jd| d S )Ncommentline)r   r   )r=   r   r   r   r   r   g  s    zPyrexScanner.commentlinec             C   s   | j ||jdd d S )N_r   )r   r   )r=   r   symbolr   r   r   strip_underscoresk  s    zPyrexScanner.strip_underscoresc             C   s
   | j d S )Nr   )r   )r=   r   r   r   current_leveln  s    zPyrexScanner.current_levelc             C   s   |  j d7  _ |S )Nr   )r   )r=   r   r   r   r   open_bracket_actionq  s    z PyrexScanner.open_bracket_actionc             C   s   |  j d8  _ |S )Nr   )r   )r=   r   r   r   r   close_bracket_actionu  s    z!PyrexScanner.close_bracket_actionc             C   s$   | j dkr | jd | jdd d S )Nr   r   NEWLINEr   )r   r   r   )r=   r   r   r   r   newline_actiony  s    

zPyrexScanner.newline_actionZ	SQ_STRINGZ	DQ_STRINGZ
TSQ_STRINGZ
TDQ_STRING)'"z'''z"""c             C   s@   x |d d t kr |dd  }qW | j| j|  | jd d S )Nr   ZBEGIN_STRING)r   r   string_statesr   )r=   r   r   r   r   begin_string_action  s    z PyrexScanner.begin_string_actionc             C   s   | j d | jd d S )Nr   Z
END_STRING)r   r   )r=   r   r   r   r   end_string_action  s    
zPyrexScanner.end_string_actionc             C   s   | j | | jd d S )NzUnclosed string literal)r   error_at_scanpos)r=   r   r   r   r   unclosed_string_action  s    
z#PyrexScanner.unclosed_string_actionc             C   s   | j d |rV|d }| jd kr(|| _n| j|kr<| jd |j|ddkrV| jd | j }t|}||krrd S ||kr| jj| | jdd n>x&|| j k r| jj	  | jdd qW || j kr| jd d S )Nr   r   zMixed use of tabs and spacesr   DEDENTzInconsistent indentation)
r   r   r   r   r   rg   r   appendr   pop)r=   r   cr   Z	new_levelr   r   r   indentation_action  s*    





zPyrexScanner.indentation_actionc             C   s:   x(t | jdkr(| jdd | jj  qW | jdd d S )Nr   r   r   EOF)rg   r   r   r   )r=   r   r   r   r   
eof_action  s    zPyrexScanner.eof_actionc             C   s   y| j  \}}W n tk
r.   | jd d S X |tkr|| jkr|dkrft| jjkrf| jjdd  n.|dkr| jj	dkr| jjdd  n
| j| }| jj
|}| jd k	r| jj||| j f || _|| _d S )NzUnrecognized characterr   r%      )readr   r   r   r   r   r   Zfuture_directivesr   Zlanguage_levelintern_ustringr   r   positionr   systring)r=   r   r  r   r   r   r     s$    



zPyrexScanner.nextc             C   sT   | j | jf}| j }| j  | j | jf}| j| j | j| j  |\| _ | _|| _|S )N)r   r  r  r   unreadlast_token_position_tuple)r=   Zsaved	saved_posr   r   r   r   peek  s    zPyrexScanner.peekc             C   s*   | j | j| j| j || _|| _|| _d S )N)r  r   r  r  )r=   r   r  posr   r   r   put_back  s    zPyrexScanner.put_backc             C   s:   |d kr| j  }| jdkr$t|d t||}|r6|d S )Nr   z!Possible inconsistent indentation)r  r   r   )r=   messager  fatalerrr   r   r   r     s    


 zPyrexScanner.errorc             C   s   | j  }| j||d d S )NT)Zget_current_scan_posr   )r=   r  r  r   r   r   r     s    zPyrexScanner.error_at_scanposc             C   s$   | j |kr| j  n| j|| d S )N)r   r   expected)r=   whatr  r   r   r   expect  s    

zPyrexScanner.expectc             C   s.   | j tkr| j|kr| j  n| j|| d S )N)r   r   r  r   r  )r=   r  r  r   r   r   expect_keyword  s    
zPyrexScanner.expect_keywordc             C   s>   |r| j | n*| jtkr"| j}n| j}| j d||f  d S )NzExpected '%s', found '%s')r   r   r   r  )r=   r  r  foundr   r   r   r    s    
zPyrexScanner.expectedc             C   s   | j dd d S )Nr   z)Expected an increase in indentation level)r  )r=   r   r   r   expect_indent  s    zPyrexScanner.expect_indentc             C   s   | j dd d S )Nr   z(Expected a decrease in indentation level)r  )r=   r   r   r   expect_dedent  s    zPyrexScanner.expect_dedentExpected a newlineFc             C   sN   d }|r"| j dkr"| j }| j  | j dkr8| jd| |d k	rJt|d d S )N;r   r   zuseless trailing semicolon)r   r  r   r  r   )r=   r  Zignore_semicolonZuseless_trailing_semicolonr   r   r   expect_newline  s    
zPyrexScanner.expect_newlinec             C   s0   |  j d7  _ | j dkr,d| jd< d| jd< d S )Nr   asyncawait)r   r   )r=   r   r   r   r     s    

zPyrexScanner.enter_asyncc             C   sX   | j dkst|  j d8  _ | j sT| jd= | jd= | jdkrTt| jj| j | _| _d S )Nr   r   r  r  )r  r  )r   r   r   r   r   r   r  r  )r=   r   r   r   
exit_async$  s    
zPyrexScanner.exit_async)NNNNTN)NT)N)N)N)r  F)rH   rI   rJ   r>   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r
  r  r   r   r  r  r  r  r  r  r   r  r   r   r   r   r   +  s>   	 
+$






r   )scannerc             c   s   t  }z| j}g | _| j| j| j f}z2y
|V  W n" tk
rT } zW Y d d }~X nX W d |r| jrx$t| jd d D ]}| j|  qxW | j|  n|d k	r|j| j || _X W d t	dd X d S )Nr   T)ignorer   )
r   r   r   r  r  r   rq   r  extendr   )r  errorsr   Zinitial_stateer  r   r   r   tentatively_scan-  s$    
r"  )-
__future__r   ZcythonrA   objectr   r	   unicodedatar
   
contextlibr   r   r   ZPlex.Scannersr   ZPlex.Errorsr   ZErrorsr   r   r   r   r   ZLexiconr   r   r   Futurer   Zdebug_scannerr   Zscanner_debug_flagsZscanner_dump_filer   r   r   r   r:   r   r   r   r   r   localsr"  r   r   r   r   <module>   sL   


*=D)  