B
    u9a2              	   @   s   d dl Z d dlZd dlZd dlmZ d dlmZ dddgZG dd dZdd
dZ	e
dejjZdd Zdd Zedkreejdkree  n,ejd ZeeZeeee W dQ R X dS )    N)deque)StringIOshlexsplitquotec               @   sb   e Zd ZdddZdd ZdddZd	d
 Zdd Zdd Zdd Z	dddZ
dd Zdd ZdS )r   NFc             C   s  t |trt|}|d k	r(|| _|| _ntj| _d | _|| _|rHd | _nd| _d| _	d| _
| jrn|  j
d7  _
d| _d| _d| _d| _d	| _d
| _t | _d| _d| _d| _t | _d | _|sd}n|dkrd}|| _|rt | _|  j
d7  _
| j
t|}| j
|| _
d S )N #Z?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_u|   ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞz 	
Fz'"\"    r   Tz();<>|&z~-./*?=)
isinstancestrr   instreaminfilesysstdinposixeof
commenters	wordchars
whitespacewhitespace_splitquotesescapeescapedquotesstater   pushbacklinenodebugtoken	filestacksourcepunctuation_chars_pushback_chars	maketransdictfromkeys	translate)selfr   r   r   r#   t r+   /usr/lib/python3.7/shlex.py__init__   sJ    
zshlex.__init__c             C   s*   | j dkrtdt|  | j| d S )Nr   zshlex: pushing token )r   printreprr   
appendleft)r)   tokr+   r+   r,   
push_tokenD   s    
zshlex.push_tokenc             C   sp   t |trt|}| j| j| j| jf || _|| _d| _| jrl|d k	r\t	d| jf  nt	d| jf  d S )Nr   zshlex: pushing to file %szshlex: pushing to stream %s)
r   r   r   r!   r0   r   r   r   r   r.   )r)   	newstreamnewfiler+   r+   r,   push_sourceJ   s    
zshlex.push_sourcec             C   sD   | j   | j \| _| _ | _| jr:td| j | jf  d| _d S )Nzshlex: popping to %s, line %dr   )	r   closer!   popleftr   r   r   r.   r   )r)   r+   r+   r,   
pop_sourceX   s    
zshlex.pop_sourcec             C   s   | j r.| j  }| jdkr*tdt|  |S |  }| jd k	r~x<|| jkr|| |  }|rr|\}}| || | 	 }qBW x*|| j
kr| js| j
S |   | 	 }qW | jdkr|| j
krtdt|  ntd |S )Nr   zshlex: popping token zshlex: token=zshlex: token=EOF)r   r7   r   r.   r/   
read_tokenr"   
sourcehookr5   	get_tokenr   r!   r8   )r)   r1   rawspecr4   r3   r+   r+   r,   r;   a   s.    




zshlex.get_tokenc             C   s  d}d}x^| j r$| jr$| j }n| jd}|dkrF|  jd7  _| jdkrbtd| j|f  | jd krvd| _	P q| jdkr|sd | _P qf|| j
kr| jdkrtd	 | j	s| jr|rP nqn|| jkr| j  |  jd7  _n| jr
|| jkr
d
}|| _n|| jkr$|| _	d
| _np|| j kr>|| _	d| _nV|| jkr`| jsX|| _	|| _n4| jrv|| _	d
| _n|| _	| j	s| jr|rP nqq| j| jkr>d}|s| jdkrtd td|| jkr| js|  j	|7  _	d| _P nd
| _n>| jr.|| jkr.| j| jkr.| j}|| _n|  j	|7  _	q| j| jkr|sn| jdkrftd td|| jkr|| jkr||kr|  j	| j7  _	|  j	|7  _	|| _q| jdkr|sd | _P q|| j
kr| jdkrtd d| _| j	s| jr|rP nqq|| jkr\| j  |  jd7  _| jrfd| _| j	sT| jr|rP nqq| jdkr|| j kr|  j	|7  _	n || j
kr| j| d| _P q| jr|| jkr|| _q| jr|| jkrd
}|| _q|| jks|| jks| jr|  j	|7  _	q| j r(| j| n| j| | jdkrHtd d| _| j	s`| jr|rP qqqW | j	}d| _	| jr|s|dkrd }| jdkr|rtdt|  ntd |S )NFr   r   
   z&shlex: in state %r I see character: %rr      z+shlex: I see whitespace in whitespace stateacTz shlex: I see EOF in quotes statezNo closing quotationz shlex: I see EOF in escape statezNo escaped character)rA   rB   z%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)r#   r$   popr   readr   r   r.   r   r    r   r   r   readliner   r   r   r   
ValueErrorr   appendr   r0   r/   )r)   ZquotedZescapedstateZnextcharresultr+   r+   r,   r9      s    









zshlex.read_tokenc             C   sV   |d dkr|dd }t | jtrHtj|sHtjtj| j|}|t|dfS )Nr   r
   r   r)	r   r   r   ospathisabsjoindirnameopen)r)   r4   r+   r+   r,   r:     s
    zshlex.sourcehookc             C   s(   |d kr| j }|d kr| j}d||f S )Nz"%s", line %d: )r   r   )r)   r   r   r+   r+   r,   error_leader  s
    zshlex.error_leaderc             C   s   | S )Nr+   )r)   r+   r+   r,   __iter__#  s    zshlex.__iter__c             C   s   |   }|| jkrt|S )N)r;   r   StopIteration)r)   r    r+   r+   r,   __next__&  s    
zshlex.__next__)NNFF)N)NN)__name__
__module____qualname__r-   r2   r5   r8   r;   r9   r:   rQ   rR   rT   r+   r+   r+   r,   r      s    
.
	  	
FTc             C   s$   t | |d}d|_|sd|_t|S )N)r   Tr   )r   r   r   list)sZcommentsr   Zlexr+   r+   r,   r   ,  s
    z[^\w@%+=:,./-]c             C   s,   | sdS t | d kr| S d| dd d S )Nz'''z'"'"')_find_unsafereplace)rY   r+   r+   r,   r   6  s
    c             C   s(   x"|   }|sP tdt|  qW d S )NzToken: )r;   r.   r/   )Zlexerttr+   r+   r,   _print_tokensB  s
    r^   __main__r   )FT)rK   rer   collectionsr   ior   __all__r   r   compileASCIIsearchr[   r   r^   rU   lenargvfnrP   fr+   r+   r+   r,   <module>
   s$   
  


