
bc           @   s  d  Z  d d l Z d d l Z d d l m Z y d d l m Z Wn! e k
 re d d l m Z n Xd d g Z	 d d d     YZ
 e e d  Z e d	 k re e j  d
 k r e
   Z n" e j d
 Z e
 e e  e  Z x, e j   Z e r
d e e  GHq Pq Wn  d S(   s8   A lexical analyzer class for simple shell-like syntaxes.iN(   t   deque(   t   StringIOt   shlext   splitc           B   sz   e  Z d  Z d d e d  Z d   Z d d  Z d   Z d   Z	 d   Z
 d   Z d d d  Z d	   Z d
   Z RS(   s8   A lexical analyzer class for simple shell-like syntaxes.c         C   s<  t  | t  r t |  } n  | d  k	 r? | |  _ | |  _ n t j |  _ d  |  _ | |  _ | ro d  |  _	 n	 d |  _	 d |  _
 d |  _ |  j r |  j d 7_ n  d |  _ t |  _ d |  _ d |  _ d |  _ d	 |  _ t   |  _ d
 |  _ d |  _ d |  _ t   |  _ d  |  _ |  j r8d |  j |  j f GHn  d  S(   Nt    t   #t?   abcdfeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_s>   s    	
s   '"s   \t   "t    i   i    s   shlex: reading from %s, line %d(   t
   isinstancet
   basestringR   t   Nonet   instreamt   infilet   syst   stdint   posixt   eoft
   commenterst	   wordcharst
   whitespacet   Falset   whitespace_splitt   quotest   escapet   escapedquotest   stateR    t   pushbackt   linenot   debugt   tokent	   filestackt   source(   t   selfR   R   R   (    (    s   /usr/lib/python2.7/shlex.pyt   __init__   s<    																		c         C   s5   |  j  d k r! d t |  GHn  |  j j |  d S(   s:   Push a token onto the stack popped by the get_token methodi   s   shlex: pushing token N(   R   t   reprR   t
   appendleft(   R!   t   tok(    (    s   /usr/lib/python2.7/shlex.pyt
   push_token;   s    c         C   s   t  | t  r t |  } n  |  j j |  j |  j |  j f  | |  _ | |  _ d |  _ |  j r | d k	 r d |  j f GHq d |  j f GHn  d S(   s9   Push an input source onto the lexer's input source stack.i   s   shlex: pushing to file %ss   shlex: pushing to stream %sN(
   R	   R
   R   R   R$   R   R   R   R   R   (   R!   t	   newstreamt   newfile(    (    s   /usr/lib/python2.7/shlex.pyt   push_sourceA   s    "				c         C   s\   |  j  j   |  j j   \ |  _ |  _  |  _ |  j rO d |  j  |  j f GHn  d |  _ d S(   s   Pop the input source stack.s   shlex: popping to %s, line %dR   N(   R   t   closeR   t   popleftR   R   R   R   (   R!   (    (    s   /usr/lib/python2.7/shlex.pyt
   pop_sourceO   s    !	c         C   s/  |  j  r= |  j  j   } |  j d k r9 d t |  GHn  | S|  j   } |  j d k	 r x\ | |  j k r |  j |  j    } | r | \ } } |  j | |  n  |  j	   } q[ Wn  x9 | |  j
 k r |  j s |  j
 S|  j   |  j	   } q W|  j d k r+| |  j
 k r#d t |  GHq+d GHn  | S(   sB   Get a token from the input stream (or from stack if it's nonempty)i   s   shlex: popping token s   shlex: token=s   shlex: token=EOFN(   R   R+   R   R#   t
   read_tokenR    R   t
   sourcehookR)   t	   get_tokenR   R   R,   (   R!   R%   t   rawt   specR(   R'   (    (    s   /usr/lib/python2.7/shlex.pyR/   X   s.    		
c         C   s}  t  } d } xt r|  j j d  } | d k rF |  j d |  _ n  |  j d k rx d Gt |  j  Gd Gt |  GHn  |  j d  k r d |  _	 Pq |  j d k r| s d  |  _ Pq| |  j
 k r |  j d k r d	 GHn  |  j	 s |  j r | r Pqq q| |  j k r-|  j j   |  j d |  _ q|  j rW| |  j k rWd
 } | |  _ q| |  j k r{| |  _	 d
 |  _ q| |  j k r|  j s| |  _	 n  | |  _ q|  j r| |  _	 d
 |  _ q| |  _	 |  j	 s|  j r | r Pqq q |  j |  j k rt } | s5|  j d k r)d GHn  t d  n  | |  j k rv|  j sj|  j	 | |  _	 d |  _ Pqd
 |  _ q|  j r| |  j k r|  j |  j k r|  j } | |  _ q|  j	 | |  _	 q |  j |  j k r_| s|  j d k rd GHn  t d  n  | |  j k rC| |  j k rC| | k rC|  j	 |  j |  _	 n  |  j	 | |  _	 | |  _ q |  j d
 k r | sd  |  _ Pq| |  j
 k r|  j d k rd GHn  d |  _ |  j	 s|  j r | r Pqq q| |  j k r5|  j j   |  j d |  _ |  j rd |  _ |  j	 s(|  j r | r Pq2q qq|  j rY| |  j k rY| |  _ q|  j r| |  j k rd
 } | |  _ q| |  j k s| |  j k s|  j r|  j	 | |  _	 q|  j j |  |  j d k rd GHn  d |  _ |  j	 s|  j r | r Pqq q q W|  j	 } d |  _	 |  j rJ| rJ| d k rJd  } n  |  j d k ry| rqd t |  GHqyd GHn  | S(   NR   i   s   
i   s   shlex: in states   I see character:R   i   s+   shlex: I see whitespace in whitespace statet   as    shlex: I see EOF in quotes states   No closing quotations    shlex: I see EOF in escape states   No escaped characters%   shlex: I see whitespace in word states&   shlex: I see punctuation in word states   shlex: raw token=s   shlex: raw token=EOF(   R   t   TrueR   t   readR   R   R#   R   R   R   R   R   R   t   readlineR   R   R   R   t
   ValueErrorR   R   R$   (   R!   t   quotedt   escapedstatet   nextchart   result(    (    s   /usr/lib/python2.7/shlex.pyR-   x   s    																		
			c         C   s   | d d k r  | d d !} n  t  |  j t  rl t j j |  rl t j j t j j |  j  |  } n  | t | d  f S(   s(   Hook called on a filename to be sourced.i    R   i   it   r(	   R	   R   R
   t   ost   patht   isabst   joint   dirnamet   open(   R!   R(   (    (    s   /usr/lib/python2.7/shlex.pyR.      s
    %'c         C   s>   | d k r |  j } n  | d k r0 |  j } n  d | | f S(   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_leader  s
    c         C   s   |  S(   N(    (   R!   (    (    s   /usr/lib/python2.7/shlex.pyt   __iter__	  s    c         C   s(   |  j    } | |  j k r$ t  n  | S(   N(   R/   R   t   StopIteration(   R!   R   (    (    s   /usr/lib/python2.7/shlex.pyt   next  s    	N(   t   __name__t
   __module__t   __doc__R   R   R"   R&   R)   R,   R/   R-   R.   RB   RC   RE   (    (    (    s   /usr/lib/python2.7/shlex.pyR      s   $				 				c         C   s7   t  |  d | } t | _ | s- d | _ n  t |  S(   NR   R   (   R   R3   R   R   t   list(   t   st   commentsR   t   lex(    (    s   /usr/lib/python2.7/shlex.pyR     s
    	t   __main__i   s   Token: (    (   RH   t   os.pathR<   R   t   collectionsR    t	   cStringIOR   t   ImportErrort   __all__R   R   R3   R   RF   t   lent   argvt   lexert   fileRA   R/   t   ttR#   (    (    (    s   /usr/lib/python2.7/shlex.pyt   <module>   s(   