B \]2 @sdZddlZddlZddlZddlmZddlmZdddgZGdddZ dd dZ e 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 t|}|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/local/lib/python3.7/shlex.py__init__sJ zshlex.__init__cCs*|jdkrtdt||j|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|}|j|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|j|j\|_|_|_|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.|j}|jdkr*tdt||S|}|jdk r~x<||jkr|||}|rr|\}}|||| }qBWx*||j kr|j s|j S| | }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$|j}n |jd}|dkrF|jd7_|jdkrbtd|j|f|jdkrvd|_ Pq |jdkr|sd|_Pqf||j kr|jdkrtd |j s|j r |r Pnq n||j kr|j |jd7_n|j r ||jkr d }||_n||jkr$||_ d |_np||jkr>||_ d |_nV||jkr`|j sX||_ ||_n4|jrv||_ d |_n||_ |j s|j r |r Pnq q |j|jkr>d }|s|jdkrtd td||jkr|j s|j |7_ d|_Pnd |_n>|j r.||jkr.|j|jkr.|j}||_n|j |7_ q |j|jkr|sn|jdkrftdtd||jkr||jkr||kr|j |j7_ |j |7_ ||_q |jdkr |sd|_Pq ||j kr|jdkrtdd|_|j s|j r |r Pnq q ||j kr\|j |jd7_|j rfd|_|j sT|j r |r Pnq q |jd kr||jkr|j |7_ n ||j kr|j|d|_Pq |j r||jkr||_q |j r||jkrd }||_q ||jks||jks|jr|j |7_ q |jr(|j|n |j||jdkrHtdd|_|j s`|j r |r Pq q q W|j }d|_ |j r|s|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 character)rArBz%shlex: I see whitespace in word statez&shlex: I see punctuation in word statezshlex: raw token=zshlex: raw token=EOF)r#r$poprreadrrr.rr rrrreadlinerrrr ValueErrorrappendrr0r/)r)ZquotedZ escapedstateZnextcharresultr+r+r,r9s                               zshlex.read_tokencCsV|ddkr|dd}t|jtrHtj|sHtjtj|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&