WcW4dZddlZddlZddlZddlmZddlmZgdZGddZ dd Z d Z ejd ejjZd ZdZedkr`eej(dkree dSej(dZee5Zee eeddddSdS#1swYdSxYw)8A lexical analyzer class for simple shell-like syntaxes.N)deque)StringIO)shlexsplitquotejoincjeZdZdZ ddZedZdZddZdZ d Z d Z d Z dd Z d ZdZdS)rrNFct|tr t|}|||_||_nt j |_d|_||_|rd|_nd|_d|_ d|_ |jr|xjdz c_ d|_ d|_ d|_ d|_d |_d |_t#|_d |_d |_d|_t#|_d|_|sd}n|d urd}||_|rzt#|_|xjdz c_ |jj5t6j9|}|jj;||_ dSdS)N#?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_u|ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞz Fz'"\" rTz();<>|&z~-./*?=) isinstancestrrinstreaminfilesysstdinposixeof commenters wordchars whitespacewhitespace_splitquotesescape escapedquotesstaterpushbacklinenodebugtoken filestacksource_punctuation_chars_pushback_chars maketransdictfromkeys translate)selfrrrpunctuation_charsts /usr/lib64/python3.12/shlex.py__init__zshlex.__init__st h $ $)H  $DM DKKIIDMDK 5DHHDHB ::: NNN ^ _NN# %           "   $ & & ) "3  #(7D NNNi 'NN((7H)IJA!^^55a8DNNN  c|jSN)r)r/s r2r0zshlex.punctuation_charsDs&&&r4c|jdkrtdt|z|jj |dS)z:Push a token onto the stack popped by the get_token methodrzshlex: pushing token N)r%printreprr# appendleft)r/toks r2 push_tokenzshlex.push_tokenHs? ::?? )DI5 6 6   %%%%r4cvt|tr t|}|jj |j |j |jf||_||_d|_|jr:|td|j dStd|j dSdS)z9Push an input source onto the lexer's input source stack.rNzshlex: pushing to file zshlex: pushing to stream ) rrrr'r;rrr$r%r9)r/ newstreamnewfiles r2 push_sourcezshlex.push_sourceNs i % % +I !!4;; t{{"KLL !  :::"T[[[BCCCCt}}}FGGGG :r4c |jj|jj\|_|_|_|j r&td|j|j fzd|_dS)zPop the input source stack.zshlex: popping to %s, line %drN) rcloser'popleftrr$r%r9r"r7s r2 pop_sourcezshlex.pop_source\sm 48NN4J4J4L1dmT[ ::: 1]]DKK01 2 2 r4c |jrH|jj}|jdkrtdt |z|S|j }|j m||j kr]|j|j }|r|\}}|j|||j}||j kr]||jkrK|js |jS|j|j}||jkrK|jdkr:||jkrtdt |z|Std|S)zBGet a token from the input stream (or from stack if it's nonempty)rzshlex: popping token Nz shlex: token=zshlex: token=EOF) r#rDr%r9r: read_tokenr( sourcehookrA get_tokenrr'rE)r/r<rawspecr@r?s r2rIzshlex.get_tokenesR ===--'')CzzQ-S 9::Joo ;; "$$t'894+/(Wi$$Y88nn& $$TXXoo>>>xx!!nn& TXXoo ::??dhhoS 122 ()) r4c d}d} |jr(|jr|jj}n|jj d}|dkr|xj dz c_|j dkrtd|jd||j d |_ nY|jdkr`|s d|_n=||jvr;|j d kr td |js|jr|rn||jvr2|jj|xj dz c_n|jr||jvr d }||_n||jvr||_ d |_no||jvr||_ d |_nQ||j vr|js||_ ||_n'|j"r||_ d |_n ||_ |js|jr|rn|j|j vrd}|s*|j d kr tdt%d||jkr3|js|xj|z c_ d|_nhd |_n]|jr;||jvr-|j|j&vr|j}||_n|xj|z c_ n|j|jvr|s*|j d kr tdt%d||j vr5||jkr%||kr|xj|jz c_ |xj|z c_ ||_nZ|jdvrK|s d|_nB||jvrB|j d kr tdd|_|js|jr|rn||jvrb|jj|xj dz c_|jrd|_|js|jr|rn|jd krX||jvr|xj|z c_ nK||jvr|jj)|d|_n|jr||j vr||_n|jr||jvr d }||_n||jvs(||j vs|j"r$||jvr|xj|z c_ n|jr|jj)|n|j*j-||j d kr tdd|_|js|jr|rn|j}d |_ |jr |s|d krd}|j dkr,|rtdt/|z|Std|S)NFrTr zshlex: in state z I see character: r z+shlex: I see whitespace in whitespace stateacz shlex: I see EOF in quotes statezNo closing quotationz shlex: I see EOF in escape statezNo escaped character)rPrQz%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)r0r*poprreadr$r%r9r"r&rrrreadliner rrr ValueErrorr!appendr#r;r:)r/quoted escapedstatenextcharresults r2rGzshlex.read_tokens- %%%$*>*>*>//335==--a04 q zzQ$****BJ(LMMzz! s""x!%DJ00zzQKLLzzzdjjjVV 00MM**,,KKK1$KKKZZZH $;$;#&L!)DJJ//!)DJ!$DJJ!7!777!)DJ!$DJJ,,:::%- !)DJJ***!)DJ!$DJJ!)DJzzzdjjjVV t{{**xzzQ@AA$%;<<tzz))::: h. %( %( jjjX%<%<++B,B,#'::L!)DJJJJJ(*JJJt{{**xzzQ@AA$%;<<!DKK// DJJ..8|3K3KJJJ$**,JJ h& ) z))x!%DJ00zzQEFF!$DJzzzdjjjVV 00MM**,,KKK1$KKzzz%( :::$***!$ZZ3&&4#9#999 h. #4??:: 0077AA%( ZZZH $;$;!)DJJZZZH $;$;#&L!)DJJ$..00H 4K4K///"$*@*@@@JJJ(*JJJ---,,33H=== 00::zzQFGG!$DJzzzdjjjVV GH :::ff2F ::>>v)DL899 ,-- r4cV|ddkr|dd}t|jtrltjj |sKtjj tjj|j|}|t|dfS)z(Hook called on a filename to be sourced.rrrr) rrrospathisabsr dirnameopen)r/r@s r2rHzshlex.sourcehooksv 1:  amG dkk3 ' ' g0F0Fggll277??4;;#?IGgs+,,r4cH| |j}| |j}d||fzS)z[[F >[[F"ff%555r4c|Sr6r7s r2__iter__zshlex.__iter__(s r4cV|j}||jkrt|Sr6)rIr StopIteration)r/r&s r2__next__zshlex.__next__+s(  DHH    r4)NNFFr6)NN)__name__ __module__ __qualname____doc__r3propertyr0r=rArErIrGrHrdrgrjrfr4r2rrs>>9>#(-9-9-9-9^'''&&& H H H H@PPPd---6666r4rFTcx| tdt||}d|_|sd|_t |S)z-Split the string *s* using shell-like syntax.Nzs argument must not be None)rTr )rUrrrlist)scommentsrlexs r2rr1s@y677   CC 8 9r4c6djd|DS)z3Return a shell-escaped string from *split_command*.rc32K|]}t|dSr6)r).0args r2 zjoin..>s"883E#JJJJJ88r4)r ) split_commands r2r r <s 8888-88 88r4z[^\w@%+=:,./-]cZ|sdSt||Sd|jddzdzS)z1Return a shell-escaped version of the string *s*.z''N'z'"'"') _find_unsafereplace)rrs r2rrCs8 1tA 3 * *S 00r4cf |j}|sdStdt|z1)NrzToken: )rIr9r:)lexertts r2 _print_tokensrOs4 __ r E i$r("## r4__main__r)FT)rnr^rer collectionsrior__all__rrr compileASCIIsearchr}rrrklenargvfnrbfrfr4r2rs>>  - - -\\\\\\\|999 rzz+RXX6==  1 1 1$$$ z s388} eeg XXa[ T"X ( M%%2, ' ' ( ( ( ( ( ( (   ( ( ( ( ( ( ( ( ( (s (CC