WcW4csdZddlZddlZddlZddlmZddlmZgdZGddZ 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)shlexsplitquotejoincsjeZdZdZ ddZedZdZddZdZ d Z d Z d Z dd Z d ZdZdS)rrNFcst|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)Nz#Z?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_u|ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞz Fz'"z\" rTz();<>|&z~-./*?=) isinstancestrrinstreaminfilesysZstdinposixeof commenters wordchars whitespacewhitespace_splitquotesescape escapedquotesstaterpushbacklinenodebugtoken filestacksource_punctuation_chars_pushback_charsZ maketransZdictZfromkeysZ translate)selfrrrpunctuation_charsZt /usr/lib64/python3.12/shlex.py__init__zshlex.__init__st h $ $)H  $DM DKKIIDMDK 5DHHDHB ::: NNN ^ _NN# %           "   $ & & ) "3  #(7D NNNi 'NN((7H)IJA!^^55a8DNNN  cs|jSN)r!r# r&r$zshlex.punctuation_charsDs&&&r(cs|jdkrtdt|z|jj |dS)z:Push a token onto the stack popped by the get_token methodr zshlex: pushing token N)rprintreprr appendleft)r#tok r& push_tokenzshlex.push_tokenHs? ::?? )DI5 6 6   %%%%r(csvt|tr t|}|jj |j |j |jf||_||_d|_|jr:|td|j dStd|j dSdS)z9Push an input source onto the lexer's input source stack.r Nzshlex: pushing to file zshlex: pushing to stream ) r r rrr.rrrrr,)r# newstreamnewfile r& push_sourcezshlex.push_sourceNs i % % +I !!4;; t{{"KLL !  :::"T[[[BCCCCt}}}FGGGG :r(cs |jj|jj\|_|_|_|j r&td|j|j fzd|_dS)zPop the input source stack.zshlex: popping to %s, line %dr N) rZcloserpopleftrrrr,rr*r+r& pop_sourcezshlex.pop_source\sm 48NN4J4J4L1dmT[ ::: 1]]DKK01 2 2 r(cs |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)r zshlex: popping token Nz shlex: token=zshlex: token=EOF) rr6rr,r- read_tokenr sourcehookr5 get_tokenrrr7)r#r/ZrawZspecr3r2r%r&r:zshlex.get_tokenesR ===--'')CzzQ-S 9::Joo ;; "$$t'894+/(Wi$$Y88nn& $$TXXoo>>>xx!!nn& TXXoo ::??dhhoS 122 ()) r(cs 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)NFr Tr z izshlex: in state z I see character: riz+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)r;r<z%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)r$r"ZpoprZreadrrr,rrrrrZreadlinerrrr ValueErrorrZappendrr.r-)r#ZquotedZ escapedstateZnextcharZresults r&r8zshlex.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 ,-- r(csV|ddkr|dd}t|jtrltjj |sKtjj tjj|j|}|t|dfS)z(Hook called on a filename to be sourced.rr r iZr) r rr osZpathZisabsrZdirnameopen)r#r3r0r&r9zshlex.sourcehooksv 1:  amG dkk3 ' ' g0F0Fggll277??4;;#?IGgs+,,r(csH| |j}| |j}d||fzS)z[[F >[[F"ff%555r(cs|Sr)r*r+r&__iter__zshlex.__iter__(s r(csV|j}||jkrt|Sr))r:rZ StopIteration)r#rr0r&__next__zshlex.__next__+s(  DHH    r()NNFFr))NN)__name__Z __module__Z __qualname____doc__r'Zpropertyr$r1r5r7r:r8r9r@rBrCrAr(r&rrs>>9>#(-9-9-9-9^'''&&& H H H H@PPPd---6666r(rFTcsx| tdt||}d|_|sd|_t |S)z-Split the string *s* using shell-like syntax.Nzs argument must not be None)rTr)r=rrrZlist)sZcommentsrZlexs r&rr1s@y677   CC 8 9r(cs6djd|DS)z3Return a shell-escaped string from *split_command*.r c3s2K|]}t|dSr))r)Z.0Zargr0r&z zjoin..>s"883E#JJJJJ88r()r)Z split_commandr+r&rr<s 8888-88 88r(z[^\w@%+=:,./-]csZ|sdSt||Sd|jddzdzS)z1Return a shell-escaped version of the string *s*.z''Nz'z'"'"') _find_unsafeZreplace)rFr+r&rrCs8 1tA 3 * *S 00r(csf |j}|sdStdt|z1)Nr zToken: )r:r,r-)ZlexerZttr0r& _print_tokensrHOs4 __ r E i$r("## r(Z__main__r )FT)rEr>ZrerZ collectionsrZiorZ__all__rrrZcompileZASCIIZsearchrGrrHrDZlenZargvZfnr?ZfrAr(r&rIs>>  - - -\\\\\\\|999 rzz+RXX6==  1 1 1$$$ z s388} eeg XXa[ T"X ( M%%2, ' ' ( ( ( ( ( ( (   ( ( ( ( ( ( ( ( ( (s (CC