U e5d 4 @sdZddlZddlZddlZddlmZddlmZddddgZGd ddZ dd dZ d dZ e dej jZddZddZedkreejdkree n,ejdZeeZee eeW5QRXdS)8A lexical analyzer class for simple shell-like syntaxes.N)deque)StringIOshlexsplitquotejoinc@sreZdZdZdddZeddZdd Zdd d Zd d Z ddZ ddZ ddZ dddZ ddZddZdS)rrNFcCst|trt|}|dk r(||_||_ntj|_d|_||_|rHd|_nd|_d|_ d|_ |jrn|j d7_ d|_ d|_ d|_ d|_d |_d |_t|_d |_d |_d|_t|_d|_|sd}n |d krd}||_|rt|_|j d7_ |j t|}|j ||_ dS)N#Z?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_u|ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞz Fz'"\" rTz();<>|&z~-./*?=) isinstancestrrinstreaminfilesysstdinposixeof commenters wordchars whitespacewhitespace_splitquotesescape escapedquotesstaterpushbacklinenodebugtoken filestacksource_punctuation_chars_pushback_chars maketransdictfromkeys translate)selfrrrpunctuation_charstr./usr/lib64/python3.8/shlex.py__init__sJ zshlex.__init__cCs|jSN)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!printreprr appendleft)r+tokr.r.r/ push_tokenHs zshlex.push_tokencCspt|trt|}|j|j|j|jf||_||_d|_|jrl|dk r\t d|jfnt d|jfdS)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+ newstreamnewfiler.r.r/ push_sourceNs zshlex.push_sourcecCsD|j|j\|_|_|_|jr:td|j|jfd|_dS)zPop the input source stack.zshlex: popping to %s, line %dr N) rcloser#popleftrr r!r3rr2r.r.r/ pop_source\s  zshlex.pop_sourcecCs|jr.|j}|jdkr*tdt||S|}|jdk rz||jkrz||}|rp|\}}|||| }q@||j kr|j s|j S| | }qz|jdkr||j krtdt|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+r6rawspecr9r8r.r.r/r@es.          zshlex.get_tokencCsd}d}|jr |jr |j}n |jd}|dkrB|jd7_|jdkr^td|j|f|jdkrtd|_ qq|jdkr|sd|_qq||j kr|jdkrtd |j s|j r|rqnqn||j kr|j |jd7_n|j r ||jkr d }||_n||jkr&||_ d |_nr||jkr@||_ d |_nX||jkrb|j sZ||_ ||_n6|jrx||_ d |_n ||_ |j s|j r|rqnqq|j|jkrDd }|s|jdkrtd td||jkr|j s|j |7_ d|_qnd |_n>|j r4||jkr4|j|jkr4|j}||_n|j |7_ q|j|jkr|st|jdkrltdtd||jkr||jkr||kr|j |j7_ |j |7_ ||_q|jdkr|sd|_qq||j kr|jdkrtdd|_|j s|j r|rqnqq||j krh|j |jd7_|j rd|_|j s|j r|rqnqq|jd kr||jkr|j |7_ n"||j kr|j|d|_qq|j r||jkr||_q|j r||jkrd }||_q||jks||jks|jr,||jkr,|j |7_ q|jrB|j|n |j||jdkrbtdd|_|j s|j r|rqqqq|j }d|_ |j r|s|dkrd}|jdkr|rtdt|ntd|S)NFr r z&shlex: in state %r I see character: %rr z+shlex: I see whitespace in whitespace stateacTz 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&poprreadr r!r3rr"rrrreadlinerrrr ValueErrorrappendrr5r4)r+ZquotedZ escapedstateZnextcharresultr.r.r/r>s                              zshlex.read_tokencCsV|ddkr|dd}t|jtrHtj|sHtjtj|j|}|t|dfS)z(Hook called on a filename to be sourced.rr rr) rrrospathisabsrdirnameopen)r+r9r.r.r/r?s   zshlex.sourcehookcCs(|dkr|j}|dkr|j}d||fS)zr?rUrVrXr.r.r.r/rs  /     FTcCs$t||d}d|_|sd|_t|S)z-Split the string *s* using shell-like syntax.)rTr )rrrlist)sZcommentsrZlexr.r.r/r1s  cCsddd|DS)z3Return a shell-escaped string from *split_command*.r css|]}t|VqdSr1)r).0argr.r.r/ <szjoin..)r)Z split_commandr.r.r/r:sz[^\w@%+=:,./-]cCs,|sdSt|dkr|Sd|dddS)z1Return a shell-escaped version of the string *s*.z''N'z'"'"') _find_unsafereplace)r_r.r.r/rAs  cCs$|}|sq tdt|qdS)NzToken: )r@r3r4)ZlexerZttr.r.r/ _print_tokensMsrf__main__r)FT)r\rPrer collectionsrior__all__rrrcompileASCIIsearchrdrrfrYlenargvfnrTfr.r.r.r/s(