ó
¦V]c           @@  s  d  Z  d d l m Z d d l Z d d l Z e j d ƒ j Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z i e d 6e d 6e d 6e d 6e d 6e d 6Z i e d 6Z d „  Z d „  Z d „  Z d „  Z d S(   sî   
A simple XPath-like language for tree traversal.

This works by creating a filter chain of generator functions.  Each
function selects a part of the expression, e.g. a child node, a
specific descendant or a node that holds an attribute.
i    (   t   absolute_importNsD   ('[^']*'|\"[^\"]*\"|//?|\(\)|==?|[/.*\[\]()@])|([^/\[\]()@=\s]+)|\s+c         C@  sC   t  |  | ƒ } | d  k	 r; t | ƒ t k r1 | S| g Sn d Sd  S(   N(    (   t   getattrt   Nonet   typet   list(   t   nodet	   attr_namet   child(    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   iterchildren   s    
c         C@  sL   y3 y |  j  } Wn t k
 r* t  |  ƒ SX| ƒ  SWn t k
 rG d  SXd  S(   N(   t   nextt   AttributeErrort   StopIterationR   (   t   itt   _next(    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   _get_first_or_none$   s    c         C@  s   |  j  j j d ƒ d S(   Nt   .iÿÿÿÿ(   t	   __class__t   __name__t   split(   R   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt	   type_name/   s    c         C@  sO   | d } |  ƒ  } | d d k r6 t  d | ƒ ‚ n  t |  | ƒ } | | f S(   Ni   i    t   (s%   Expected '(' after function name '%s'(   t
   ValueErrort   handle_predicate(   R	   t   tokent   namet	   predicate(    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt
   parse_func2   s    
	c         @  s(   t  |  | ƒ \ } ‰  ‡  f d †  } | S(   s   
    not(...)
    c         3@  s8   x1 |  D]) } t  ˆ  | g ƒ ƒ d  k r | Vq q Wd  S(   N(   R   R   (   t   resultR   (   R   (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   select@   s    (   R   (   R	   R   R   R   (    (   R   s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   handle_func_not:   s    c         @  s:   | d ‰  ˆ  t  k r' t  ˆ  |  | ƒ S‡  f d †  } | S(   s)   
    /NodeName/
    or
    func(...)
    i   c         3@  s]   xV |  D]N } xE | j  D]: } x1 t | | ƒ D]  } t | ƒ ˆ  k r- | Vq- q- Wq Wq Wd  S(   N(   t   child_attrsR   R   (   R   R   R   R   (   R   (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   O   s
    (   t	   functions(   R	   R   R   (    (   R   s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   handle_nameF   s
    
c         C@  s   d „  } | S(   s   
    /*/
    c         s@  sH   xA |  D]9 } x0 | j  D]% } x t | | ƒ D] } | Vq- Wq Wq Wd  S(   N(   R   R   (   R   R   R   R   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   [   s    (    (   R	   R   R   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   handle_starW   s    	c         C@  s   d „  } | S(   s   
    /./
    c         S@  s   |  S(   N(    (   R   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   f   s    (    (   R	   R   R   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt
   handle_dotb   s    	c         @  ss   |  ƒ  } | d d k r+ ‡  f d †  ‰  n5 | d sT | d ‰ ‡  ‡ f d †  ‰  n t  d ƒ ‚ ‡  f d †  } | S(   s   
    //...
    i    t   *c         3@  sS   xL |  j  D]A } x8 t |  | ƒ D]' } | Vx ˆ  | ƒ D] } | Vq8 Wq  Wq
 Wd  S(   N(   R   R   (   R   R   R   t   c(   t   iter_recursive(    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR%   p   s
    i   c         3@  sh   xa |  j  D]V } xM t |  | ƒ D]< } t | ƒ ˆ k r@ | Vn  x ˆ  | ƒ D] } | VqM Wq  Wq
 Wd  S(   N(   R   R   R   (   R   R   R   R$   (   R%   t	   node_name(    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR%   x   s    s   Expected node name after '//'c         3@  s1   x* |  D]" } x ˆ  | ƒ D] } | Vq Wq Wd  S(   N(    (   R   R   R   (   R%   (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   ‚   s    (   R   (   R	   R   R   (    (   R%   R&   s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   handle_descendantsj   s    	

c         @  sµ   |  ƒ  } | d r" t  d ƒ ‚ n  | d } d  ‰ y |  ƒ  } Wn t k
 rR n  X| d d k rr t |  ƒ ‰ n  t j | ƒ ‰  ˆ d  k rŸ ‡  f d †  } n ‡  ‡ f d †  } | S(   Ni    s   Expected attribute namei   t   =c         3@  sP   xI |  D]A } y ˆ  | ƒ } Wn t  k
 r3 q n X| d  k	 r | Vq q Wd  S(   N(   R
   R   (   R   R   t
   attr_value(   t   readattr(    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   ™   s    c         3@  sP   xI |  D]A } y ˆ  | ƒ } Wn t  k
 r3 q n X| ˆ k r | Vq q Wd  S(   N(   R
   (   R   R   R)   (   R*   t   value(    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   ¢   s    (   R   R   R   t   parse_path_valuet   operatort
   attrgetter(   R	   R   R   R   (    (   R*   R+   s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   handle_attributeŠ   s     	

	c         C@  sË   |  ƒ  } | d } | ri | d  d k s9 | d  d k rD | d d !Sy t  | ƒ SWq· t k
 re q· XnN | d j ƒ  r‡ t  | d ƒ S| d j ƒ  } | d k r§ t S| d k r· t St d | ƒ ‚ d  S(	   Ni    i   t   't   "iÿÿÿÿt   truet   falses!   Invalid attribute predicate: '%s'(   t   intR   t   isdigitt   lowert   Truet   False(   R	   R   R+   R   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR,   ­   s"    	
 c         @  sÆ   |  ƒ  } g  ‰  x¡ | d d k r² ˆ  j  t | d |  | ƒ ƒ y |  ƒ  } Wn t k
 ra Pn X| d d k r~ |  ƒ  } n  | d r | d d k r t ˆ  t |  | ƒ ƒ Sq W‡  f d †  } | S(   Ni    t   ]t   /i   t   andc         3@  sa   xZ |  D]R } t  | f ƒ } x ˆ  D] } | | ƒ } q# Wt | ƒ } | d  k	 r | Vq q Wd  S(   N(   t   iterR   R   (   R   R   t	   subresultR   t   predicate_result(   t   selector(    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   Ñ   s    (   t   appendt
   operationsR   t   logical_andR   (   R	   R   R   (    (   R?   s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   Á   s    	c         @  s   ‡  ‡ f d †  } | S(   Nc         3@  s‡   x€ |  D]x } t  | f ƒ } x ˆ  D] } | | ƒ } q# Wt | ƒ } t  | f ƒ } | d  k	 r x ˆ | ƒ D] } | Vqm Wq q Wd  S(   N(   R<   R   R   (   R   R   R=   R   R>   t   result_node(   t   lhs_selectst
   rhs_select(    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   Ü   s    (    (   RD   RE   R   (    (   RD   RE   s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyRB   Û   s    
t   @t    R#   R   s   //t   [t   notc         @  s  t  g  t |  ƒ D]$ \ } } | s( | r | | f ^ q ƒ ‰  y ˆ  j } Wn  t k
 rl ‡  f d †  } n X| ƒ  } g  } x„ y" | j t | d | | ƒ ƒ Wn t k
 rÀ t d ƒ ‚ n Xy) | ƒ  } | d d k ré | ƒ  } n  Wq t k
 rþ Pq Xq W| S(   Nc           @  s
   t  ˆ  ƒ S(   N(   R	   (    (   t   stream(    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyR   ÿ   s    i    s   invalid pathR:   (   R<   t   path_tokenizerR	   R
   R@   RA   R   R   (   t   patht   specialt   textR   R   R?   (    (   RJ   s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   _build_path_iteratorö   s*    !	"		c         C@  s<   t  | ƒ } t |  f ƒ } x | D] } | | ƒ } q" W| S(   N(   RO   R<   (   R   RL   t   selector_chainR   R   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   iterfind  s
    c         C@  s   t  t |  | ƒ ƒ S(   N(   R   RQ   (   R   RL   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt
   find_first  s    c         C@  s   t  t |  | ƒ ƒ S(   N(   R   RQ   (   R   RL   (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   find_all  s    (   t   __doc__t
   __future__R    t   reR-   t   compilet   findallRK   R   R   R   R   R   R    R!   R"   R'   R/   R,   R   RB   RA   R   RO   RQ   RR   RS   (    (    (    s7   lib/python2.7/site-packages/Cython/Compiler/TreePath.pyt   <module>   s>   
									 	#			

			