a �DOg�4�@s�dZddlZddlZddlZddlmZddlmZgd�ZGdd�d�Z dd d �Z d d �Z e� dej �jZdd�Zdd�Zedkr�eej�dkr�ee ��n@ejdZee��Zee ee��Wd�n1s�0YdS)�8A lexical analyzer class for simple shell-like syntaxes.�N)�deque)�StringIO)�shlex�split�quote�joinc@sreZdZdZddd�Zedd��Zdd �Zdd d �Zd d �Z dd�Z dd�Z dd�Z ddd�Z dd�Zdd�ZdS)rrNFcCst|t�rt|�}|dur(||_||_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 ur�d}||_|�rt�|_|j d7_ |j �t�|��}|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)�selfrrr�punctuation_chars�t�r.�/usr/lib64/python3.9/shlex.py�__init__sJ zshlex.__init__cCs|jS�N)r%�r+r.r.r/r,Dszshlex.punctuation_charscCs*|jdkrtdt|��|j�|�dS)z:Push a token onto the stack popped by the get_token methodrzshlex: pushing token N)r!�print�reprr� appendleft)r+�tokr.r.r/� push_tokenHs zshlex.push_tokencCspt|t�rt|�}|j�|j|j|jf�||_||_d|_|jrl|dur\t d|jf�nt d|jf�dS)z9Push an input source onto the lexer's input source stack.rNzshlex: pushing to file %szshlex: pushing to stream %s) rrrr#r5rrr r!r3)r+� newstream�newfiler.r.r/� push_sourceNs zshlex.push_sourcecCsD|j��|j��\|_|_|_|jr:td|j|jf�d|_dS)zPop the input source stack.zshlex: popping to %s, line %dr N) r�closer#�popleftrr r!r3rr2r.r.r/� pop_source\s  �zshlex.pop_sourcecCs�|jr.|j��}|jdkr*tdt|��|S|��}|jdurz||jkrz|�|���}|rp|\}}|�||�|� �}q@||j kr�|j s�|j S|� �|� �}qz|jdkr�||j kr�tdt|��ntd�|S)zBGet a token from the input stream (or from stack if it's nonempty)rzshlex: popping token Nz shlex: token=zshlex: token=EOF) rr<r!r3r4� read_tokenr$� sourcehookr:� get_tokenrr#r=)r+r6�raw�specr9r8r.r.r/r@es.          zshlex.get_tokencCs�d}d}|jr |jr |j��}n |j�d�}|dkrB|jd7_|jdkr^td|j|f�|jdurtd|_ �q�q|jdk�r�|s�d|_�q��q�||j vr�|jdkr�td �|j s�|j r|r�q�nqn�||j vr�|j� �|jd7_n�|j �r ||jv�r d }||_n�||jv�r&||_ d |_nr||jv�r@||_ d |_nX||jv�rb|j �sZ||_ ||_n6|j�rx||_ d |_n ||_ |j �s�|j r|r�q�nqq|j|jv�rDd }|�s�|jdk�r�td �td��||jk�r|j �s�|j |7_ d|_�q�nd |_n>|j �r4||jv�r4|j|jv�r4|j}||_n|j |7_ q|j|jv�r�|�st|jdk�rltd�td��||jv�r�||jk�r�||k�r�|j |j7_ |j |7_ ||_q|jdvr|�s�d|_�q�q||j v�r|jdk�r�td�d|_|j �s�|j r|r�q�nqq||j v�rh|j� �|jd7_|j �r�d|_|j �s�|j r|r�q�nqq|jd k�r�||jv�r�|j |7_ n"||j v�r�|j�|�d|_�q�q|j �r�||jv�r�||_q|j �r�||jv�r�d }||_q||jv�s||jv�s|j�r,||jv�r,|j |7_ q|j�rB|j�|�n |j�|�|jdk�rbtd�d|_|j �s�|j r|r�q�qqq|j }d|_ |j �r�|�s�|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 character)rFrGz%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)r,r&�popr�readr r!r3rr"rrr�readlinerrrr� ValueErrorr�appendrr5r4)r+ZquotedZ escapedstateZnextchar�resultr.r.r/r>�s     �           �  ��         ��   zshlex.read_tokencCsV|ddkr|dd�}t|jt�rHtj�|�sHtj�tj�|j�|�}|t|d�fS)z(Hook called on a filename to be sourced.rr r������r) rrr�os�path�isabsr�dirname�open)r+r9r.r.r/r?s   zshlex.sourcehookcCs(|dur|j}|dur|j}d||fS)zr?rUrVrXr.r.r.r/rs � /     rFTcCsD|dur ddl}|jdtdd�t||d�}d|_|s@�zjoin..)r)Z split_commandr.r.r/r>srz[^\w@%+=:,./-]cCs,|sdSt|�dur|Sd|�dd�dS)z1Return a shell-escaped version of the string *s*.z''N�'z'"'"')� _find_unsafe�replace)rcr.r.r/rEs  rcCs$|��}|sq tdt|��qdS)NzToken: )r@r3r4)Zlexer�ttr.r.r/� _print_tokensQsrl�__main__r)FT)r\rP�rer� collectionsr�ior�__all__rrr�compile�ASCII�searchrirrlrY�len�argv�fnrT�fr.r.r.r/�s(