3 \�2� @s�dZddlZddlZddlZddlmZddlmZdddgZGdd�d�Z dd d�Z ej d ej �j Zd d�Zdd�Zedkr�eej�dkr�ee ��n,ejdZee��Zee ee��WdQRXdS)z8A lexical analyzer class for simple shell-like syntaxes.�N)�deque)�StringIO�shlex�split�quotec@sfeZdZdZddd�Zdd�Zddd �Zd d �Zd d �Zdd�Z dd�Z ddd�Z dd�Z dd�Z dS)rz8A lexical analyzer class for simple shell-like syntaxes.NFcCst|t�rt|�}|dk r(||_||_ntj|_d|_||_|rHd|_nd|_d|_ d|_ |jrn|j d7_ d|_ d|_ d|_ d|_d |_d |_t�|_d |_d |_d|_t�|_d|_|s�d}n |d kr�d}||_|�rt�|_|j d7_ |j jtj|��}|j j|�|_ dS)N��#Z?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_u|ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÃ�ÂÃÄÅÆÇÈÉÊËÌÃ�ÃŽÃ�Ã�ÑÒÓÔÕÖØÙÚÛÜÃ�Þz Fz'"�\�"� �rTz();<>|&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)�selfrrrr#�t�r+�/usr/lib64/python3.6/shlex.py�__init__sJ zshlex.__init__cCs*|jdkrtdt|��|jj|�dS)z:Push a token onto the stack popped by the get_token methodr zshlex: pushing token N)r�print�reprr� appendleft)r)�tokr+r+r,� push_tokenDs zshlex.push_tokencCspt|t�rt|�}|jj|j|j|jf�||_||_d|_|jrl|dk r\t d|jf�nt d|jf�dS)z9Push an input source onto the lexer's input source stack.r Nzshlex: pushing to file %szshlex: pushing to stream %s) r rrr!r0rrrrr.)r)� newstream�newfiler+r+r,� push_sourceJs zshlex.push_sourcecCsD|jj�|jj�\|_|_|_|jr:td|j|jf�d|_dS)zPop the input source stack.zshlex: popping to %s, line %dr N) r�closer!�popleftrrrr.r)r)r+r+r,� pop_sourceXs  zshlex.pop_sourcecCs�|jr.|jj�}|jdkr*tdt|��|S|j�}|jdk r~x<||jkr||j|j��}|rr|\}}|j||�|j �}qBWx*||j kr�|j s�|j S|j �|j �}q�W|jdkr�||j kr�tdt|��ntd�|S)zBGet a token from the input stream (or from stack if it's nonempty)r zshlex: popping token Nz shlex: token=zshlex: token=EOF) rr7rr.r/� read_tokenr"� sourcehookr5� get_tokenrr!r8)r)r1�raw�specr4r3r+r+r,r;as.          zshlex.get_tokencCs�d}d}�x\|jr$|jr$|jj�}n |jjd�}|dkrF|jd7_|jdkrbtd|j|f�|jdkrvd|_ Pq |jdk�r�|s�d|_P�qd||j kr�|jdkr�td �|j s�|j r |r Pnq n�||j kr�|jj �|jd7_n�|j o�||jk�rd }||_n�||jk�r"||_ d |_np||jk�r<||_ d |_nV||jk�r^|j �sV||_ ||_n4|j�rt||_ d |_n||_ |j �s�|j r |r Pnq q |j|jk�r|j �r,||jk�r,|j|jk�r,|j}||_n|j |7_ q |j|jk�r�|�sl|jdk�rdtd�td��||jk�r�||jk�r�||k�r�|j |j7_ |j |7_ ||_q |jdkr |�s�d|_Pq ||j k�r|jdk�r�td�d|_|j �s|j r |r Pnq q ||j k�rZ|jj �|jd7_|j �rdd|_|j �sR|j r |r Pnq q |jd k�r�||jk�r�|j |7_ n ||j k�r�|jj|�d|_Pq |j �r�||jk�r�||_q |j �r�||jk�r�d }||_q ||jk�s||jk�s|j�r|j |7_ q |j�r&|jj|�n |jj|�|jdk�rFtd�d|_|j �s^|j r |r Pq q q W|j }d|_ |j �r�| �r�|dk�r�d}|jdk�r�|�r�tdt|��ntd�|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 statezNo closing quotationz shlex: I see EOF in escape statezNo escaped characterz%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)rArB)r#r$�popr�readrrr.rr rrr�readlinerrrr� ValueErrorr�appendrr0r/)r)ZquotedZ escapedstateZnextchar�resultr+r+r,r9�s�                               zshlex.read_tokencCsX|ddkr|dd�}t|jt�rJtjj|� rJtjjtjj|j�|�}|t|d�fS)z(Hook called on a filename to be sourced.rr r �r�����) r rr�os�path�isabs�join�dirname�open)r)r4r+r+r,r:s   zshlex.sourcehookcCs(|dkr|j}|dkr|j}d||fS)zs&