3 \2 @sdZddlZddlZddlZddlmZddlmZdddgZGdddZ dd dZ ej d ej j Zd dZddZedkreejdkree n,ejdZeeZee eeWdQRXdS)z8A lexical analyzer class for simple shell-like syntaxes.N)deque)StringIOshlexsplitquotec@sfeZdZdZdddZddZddd Zd d Zd d ZddZ ddZ dddZ ddZ ddZ dS)rz8A lexical analyzer class for simple shell-like syntaxes.NFcCst|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 jtj|}|j j||_ dS)N#Z?abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_u|ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞz Fz'"\" rTz();<>|&z~-./*?=) isinstancestrrinstreaminfilesysstdinposixeof commenters wordchars whitespacewhitespace_splitquotesescape escapedquotesstaterpushbacklinenodebugtoken filestacksourcepunctuation_chars_pushback_chars maketransdictfromkeys translate)selfrrrr#tr+/usr/lib64/python3.6/shlex.py__init__sJ zshlex.__init__cCs*|jdkrtdt||jj|dS)z:Push a token onto the stack popped by the get_token methodr zshlex: pushing token N)rprintreprr appendleft)r)tokr+r+r, push_tokenDs zshlex.push_tokencCspt|trt|}|jj|j|j|jf||_||_d|_|jrl|dk r\t d|jfnt d|jfdS)z9Push an input source onto the lexer's input source stack.r Nzshlex: pushing to file %szshlex: pushing to stream %s) r rrr!r0rrrrr.)r) newstreamnewfiler+r+r, push_sourceJs zshlex.push_sourcecCsD|jj|jj\|_|_|_|jr:td|j|jfd|_dS)zPop the input source stack.zshlex: popping to %s, line %dr N) rcloser!popleftrrrr.r)r)r+r+r, pop_sourceXs  zshlex.pop_sourcecCs|jr.|jj}|jdkr*tdt||S|j}|jdk r~x<||jkr||j|j}|rr|\}}|j|||j }qBWx*||j kr|j s|j S|j |j }qW|jdkr||j krtdt|ntd|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) rr7rr.r/ read_tokenr" sourcehookr5 get_tokenrr!r8)r)r1rawspecr4r3r+r+r,r;as.          zshlex.get_tokencCsd}d}x\|jr$|jr$|jj}n |jjd}|dkrF|jd7_|jdkrbtd|j|f|jdkrvd|_ Pq |jdkr|sd|_Pqd||j kr|jdkrtd |j s|j r |r Pnq n||j kr|jj |jd7_n|j o||jkrd }||_n||jkr"||_ d |_np||jkr<||_ d |_nV||jkr^|j sV||_ ||_n4|jrt||_ d |_n||_ |j s|j r |r Pnq q |j|jkr|j r,||jkr,|j|jkr,|j}||_n|j |7_ q |j|jkr|sl|jdkrdtdtd||jkr||jkr||kr|j |j7_ |j |7_ ||_q |jdkr |sd|_Pq ||j kr|jdkrtdd|_|j s|j r |r Pnq q ||j krZ|jj |jd7_|j rdd|_|j sR|j r |r Pnq q |jd kr||jkr|j |7_ n ||j kr|jj|d|_Pq |j r||jkr||_q |j r||jkrd }||_q ||jks||jks|jr|j |7_ q |jr&|jj|n |jj||jdkrFtdd|_|j s^|j r |r Pq q q W|j }d|_ |j r| r|dkrd}|jdkr|rtdt|ntd|S)NFr r  z&shlex: in state %r I see character: %rrz+shlex: I see whitespace in whitespace stateacTz shlex: I see EOF in quotes statezNo closing quotationz shlex: I see EOF in escape statezNo escaped characterz%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)rArB)r#r$poprreadrrr.rr rrrreadlinerrrr ValueErrorrappendrr0r/)r)ZquotedZ escapedstateZnextcharresultr+r+r,r9s                               zshlex.read_tokencCsX|ddkr|dd}t|jtrJtjj| rJtjjtjj|j|}|t|dfS)z(Hook called on a filename to be sourced.rr r r) r rrospathisabsjoindirnameopen)r)r4r+r+r,r:s   zshlex.sourcehookcCs(|dkr|j}|dkr|j}d||fS)zs&