mò
­fIc           @   s  d  Z  d k Z d k Z d k l Z y d k l Z Wn  e j
 o d k l Z n Xd d g Z	 d f  d „  ƒ  YZ
 e d „ Z e d j ox e e i ƒ d	 j o e
 ƒ  Z n# e i d	 Z e
 e e ƒ e ƒ Z x0 e i ƒ  Z e o d
 e e ƒ GHqÙ PqÙ Wn d S(   s8   A lexical analyzer class for simple shell-like syntaxes.N(   s   deque(   s   StringIOt   shlext   splitc           B   sz   t  Z d  Z e e e d „ Z d „  Z e d „ Z d „  Z d „  Z	 d „  Z
 d „  Z e e d „ Z d	 „  Z d
 „  Z RS(   s8   A lexical analyzer class for simple shell-like syntaxes.c         C   sF  t  | t ƒ o t | ƒ } n | d  j	 o | |  _ | |  _ n t i |  _ d  |  _ | |  _	 | o d  |  _
 n
 d |  _
 d |  _ d |  _ |  i	 o |  i d 7_ n d |  _ t |  _ d |  _ d |  _ d |  _ d	 |  _ t ƒ  |  _ d
 |  _ d |  _ d |  _ t ƒ  |  _ d  |  _ |  i o d |  i |  i 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   instreamt
   basestringt   StringIOt   Nonet   selft   infilet   syst   stdint   posixt   eoft
   commenterst	   wordcharst
   whitespacet   Falset   whitespace_splitt   quotest   escapet   escapedquotest   statet   dequet   pushbackt   linenot   debugt   tokent	   filestackt   source(   R   R   R   R   (    (    t"   /mit/python/lib/python2.4/shlex.pyt   __init__   s:    						
										
c         C   s7   |  i d j o d t | ƒ GHn |  i i | ƒ d S(   s:   Push a token onto the stack popped by the get_token methodi   s   shlex: pushing token N(   R   R   t   reprt   tokR   t
   appendleft(   R   R%   (    (    R"   t
   push_token;   s     c         C   sž   t  | t ƒ o t | ƒ } n |  i i |  i |  i |  i	 f ƒ | |  _ | |  _ d |  _	 |  i o3 | d j	 o d |  i f GHqš d |  i 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   t	   newstreamR	   R
   R   R    R&   R   R   R   t   newfileR   R   (   R   R(   R)   (    (    R"   t   push_sourceA   s     "			
c         C   s^   |  i i ƒ  |  i i ƒ  \ |  _ |  _ |  _ |  i o d |  i |  i f GHn d |  _ d S(   s   Pop the input source stack.s   shlex: popping to %s, line %dR   N(	   R   R   t   closeR    t   popleftR   R   R   R   (   R   (    (    R"   t
   pop_sourceO   s     !
c         C   sG  |  i o: |  i i ƒ  } |  i d j o d t | ƒ GHn | Sn |  i ƒ  } |  i d j	 od xa | |  i j oL |  i
 |  i ƒ  ƒ } | o  | \ } } |  i | | ƒ n |  i ƒ  } qc Wn x@ | |  i j o/ |  i p |  i SqÇ |  i ƒ  |  i ƒ  } qÇ W|  i d j o, | |  i j o d t | ƒ GHqC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%   R   R$   t
   read_tokent   rawR!   R   t
   sourcehookt   specR)   R(   R*   t	   get_tokenR   R    R-   (   R   R/   R%   R(   R1   R)   (    (    R"   R2   X   s4     
  

	c         C   sÕ  t  } d } xTt oL|  i i d ƒ } | d j o |  i d |  _ n |  i	 d j o$ d Gt
 |  i ƒ Gd Gt
 | ƒ GHn |  i d  j o d |  _ Pq |  i d j om| p d  |  _ Pq^| |  i j o@ |  i	 d j o	 d	 GHn |  i p |  i o | o Pqq q^| |  i j o! |  i i ƒ  |  i d |  _ q^|  i o# | |  i j o d
 } | |  _ q^| |  i j o | |  _ d
 |  _ q^| |  i j o$ |  i p | |  _ n | |  _ q^|  i o | |  _ d
 |  _ q^| |  _ |  i p |  i o | o Pq^q q |  i |  i j oÏ t } | p& |  i	 d j o	 d GHn t d ‚ n | |  i j o5 |  i p |  i | |  _ d |  _ Pqöd
 |  _ q^|  i o9 | |  i j o) |  i |  i j o |  i } | |  _ q^|  i | |  _ q |  i |  i j oŽ | p& |  i	 d j o	 d GHn t d ‚ n | |  i j o4 | |  i j o$ | | j o |  i |  i |  _ n |  i | |  _ | |  _ q |  i d
 j o³| p d  |  _ Pq^| |  i j oI |  i	 d j o	 d GHn d |  _ |  i p |  i o | o PqZq q^| |  i j o[ |  i i ƒ  |  i d |  _ |  i o0 d |  _ |  i p |  i o | o Pq€q qZq^|  i o | |  i j o | |  _ q^|  i o# | |  i j o d
 } | |  _ q^| |  i j p | |  i j p
 |  i o |  i | |  _ q^|  i i | ƒ |  i	 d j o	 d GHn d |  _ |  i o Pq^q q q W|  i } d |  _ |  i o | o | d j o
 d  } n |  i	 d j o# | o d t
 | ƒ GHqÑ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   quotedt   escapedstatet   TrueR   R   t   readt   nextcharR   R   R$   R   R   R   R   R   R   t   readlineR   R   R   R   t
   ValueErrorR   R   R&   t   result(   R   R4   R;   R8   R5   (    (    R"   R.   x   sÚ     $				

			
	-		-			
	*		
		
	c         C   s„   | d d j o | d d !} n t |  i t ƒ o< t i i | ƒ o( t i i t i i	 |  i ƒ | ƒ } n | t
 | d ƒ f S(   s(   Hook called on a filename to be sourced.i    R   i   iÿÿÿÿt   rN(   R)   R   R   R   R	   t   ost   patht   isabst   joint   dirnamet   open(   R   R)   (    (    R"   R0   ø   s     '(c         C   sB   | d j o |  i  } n | d j o |  i } 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   R   (    (    R"   t   error_leader  s     c         C   s   |  S(   N(   R   (   R   (    (    R"   t   __iter__	  s    c         C   s*   |  i ƒ  } | |  i j o
 t ‚ n | S(   N(   R   R2   R   R   t   StopIteration(   R   R   (    (    R"   t   next  s    
(   t   __name__t
   __module__t   __doc__R   R   R#   R'   R*   R-   R2   R.   R0   RC   RD   RF   (    (    (    R"   R       s    $				 	€			c         C   s9   t  |  d t ƒ} t | _ | p d | _ n t | ƒ S(   NR   R   (   R    t   sR6   t   lexR   t   commentsR   t   list(   RJ   RL   RK   (    (    R"   R     s
    	t   __main__i   s   Token: (   RI   t   os.pathR=   R   t   collectionsR   t	   cStringIOR
   t   ImportErrort   __all__R    R   R   RG   t   lent   argvt   lexert   fileRB   R2   t   ttR$   (
   R   RS   R
   RX   RV   R   R    RW   R=   R   (    (    R"   t   ?   s*   		ý  