^Rc@sdZddlZddlZddlmZyddlmZWn!ek reddlmZnXddgZ dd dYZ e e dZ ed kreejd kre Zn"ejd Ze eeeZx+ejZer d eeGHqPqndS( s8A lexical analyzer class for simple shell-like syntaxes.iN(tdeque(tStringIOtshlextsplitcBszeZdZd d edZdZd dZdZdZ dZ dZ d d dZ d Z d ZRS( s8A lexical analyzer class for simple shell-like syntaxes.cCs<t|trt|}n|dk r?||_||_ntj|_d|_||_|rod|_ n d|_ d|_ d|_ |jr|j d7_ nd|_ t |_d|_d|_d|_d |_t|_d |_d |_d|_t|_d|_|jr8d |j|jfGHndS( Ntt#t?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_s>s s'"s\t"t iisshlex: reading from %s, line %d(t isinstancet basestringRtNonetinstreamtinfiletsyststdintposixteoft commenterst wordcharst whitespacetFalsetwhitespace_splittquotestescapet escapedquoteststateRtpushbacktlinenotdebugttokent filestacktsource(tselfR R R((s/usr/lib/python2.7/shlex.pyt__init__s<                        cCs5|jdkr!dt|GHn|jj|dS(s:Push a token onto the stack popped by the get_token methodisshlex: pushing token N(RtreprRt appendleft(R!ttok((s/usr/lib/python2.7/shlex.pyt push_token;scCst|trt|}n|jj|j|j|jf||_||_d|_|jr|dk rd|jfGHqd|jfGHndS(s9Push an input source onto the lexer's input source stack.isshlex: pushing to file %ssshlex: pushing to stream %sN( R R RRR$R R RRR (R!t newstreamtnewfile((s/usr/lib/python2.7/shlex.pyt push_sourceAs"     cCs\|jj|jj\|_|_|_|jrOd|j|jfGHnd|_dS(sPop the input source stack.sshlex: popping to %s, line %dRN(R tcloseRtpopleftR RRR(R!((s/usr/lib/python2.7/shlex.pyt pop_sourceOs  ! cCs/|jr=|jj}|jdkr9dt|GHn|S|j}|jdk rx\||jkr|j|j}|r|\}}|j||n|j }q[Wnx9||j kr|j s|j S|j |j }qW|jdkr+||j kr#dt|GHq+dGHn|S(sBGet a token from the input stream (or from stack if it's nonempty)isshlex: popping token s shlex: token=sshlex: token=EOFN( RR+RR#t read_tokenR R t sourcehookR)t get_tokenRRR,(R!R%trawtspecR(R'((s/usr/lib/python2.7/shlex.pyR/Xs.     cCsnt}d}xtr|jjd}|dkrF|jd|_n|jdkrxdGt|jGdGt|GHn|jdkrd|_ Pq|jdkr|sd|_Pq||j kr|jdkrd GHn|j s|j r|rPqqq||j kr-|jj |jd|_q|j rW||jkrWd }||_q||jkr{||_ d |_q||jkr|j s||_ n||_q|jr||_ d |_q||_ |j s|j r|rPqqq|j|jkrt}|s5|jdkr)d GHntd n||jkrv|j sj|j ||_ d|_Pqd |_q|j r||jkr|j|jkr|j}||_q|j ||_ q|j|jkr_|s|jdkrd GHntdn||jkrC||jkrC||krC|j |j|_ n|j ||_ ||_q|jd kr|sd|_Pq||j kr|jdkrdGHnd|_|j s|j r|rPqqq||j kr5|jj |jd|_|j rd|_|j s(|j r|rPq2qqq|j rY||jkrY||_q|j r||jkrd }||_q||jks||jks|jr|j ||_ q|jj||jdkrdGHnd|_|j rPqqqqW|j }d|_ |j r;| r;|dkr;d}n|jdkrj|rbdt|GHqjdGHn|S(NRis isshlex: in statesI see character:Ris+shlex: I see whitespace in whitespace statetas shlex: I see EOF in quotes statesNo closing quotations shlex: I see EOF in escape statesNo escaped characters%shlex: I see whitespace in word states&shlex: I see punctuation in word statesshlex: raw token=sshlex: raw token=EOF(RtTrueR treadRRR#RR RRRRtreadlineRRRRt ValueErrorRRR$(R!tquotedt escapedstatetnextchartresult((s/usr/lib/python2.7/shlex.pyR-xs                                      cCs|ddkr |dd!}nt|jtrltjj| rltjjtjj|j|}n|t|dfS(s(Hook called on a filename to be sourced.iRiitr( R R R tostpathtisabstjointdirnametopen(R!R(((s/usr/lib/python2.7/shlex.pyR.s %'cCs>|dkr|j}n|dkr0|j}nd||fS(s<Emit a C-compiler-like, Emacs-friendly error-message leader.s"%s", line %d: N(R R R(R!R R((s/usr/lib/python2.7/shlex.pyt error_leaders     cCs|S(N((R!((s/usr/lib/python2.7/shlex.pyt__iter__ scCs(|j}||jkr$tn|S(N(R/Rt StopIteration(R!R((s/usr/lib/python2.7/shlex.pytnext s  N(t__name__t __module__t__doc__R RR"R&R)R,R/R-R.RBRCRE(((s/usr/lib/python2.7/shlex.pyRs$    cCs7t|d|}t|_|s-d|_nt|S(NRR(RR3RRtlist(tstcommentsRtlex((s/usr/lib/python2.7/shlex.pyRs   t__main__isToken: ((RHtos.pathR<Rt collectionsRt cStringIORt ImportErrort__all__RRR3RRFtlentargvtlexertfileRAR/tttR#(((s/usr/lib/python2.7/shlex.pyts(