Ñò
\©äJc           @   s  d  Z  d d k Z d d k Z d d k Z d d k l Z l Z d „  Z d „  Z d d d „  ƒ  YZ	 d d d	 „  ƒ  YZ
 d
 e	 e
 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 e
 f d „  ƒ  YZ d d „ Z e d j o= d d k Z e e i d ƒ Z d d k l Z e e ƒ n d S(   s^   
Python class/function parser

Derived from "Demo/parser/example.py" from Python distribution
iÿÿÿÿN(   t   ListTypet	   TupleTypec         C   sc   t  |  d ƒ i ƒ  d } t i i t i i |  ƒ d ƒ } t i | ƒ } t | i	 d t
 ƒ | ƒ S(   Nt   Us   
i    t	   line_info(   t   opent   readt   ost   patht   basenamet   splitextt   parsert   suitet
   ModuleInfot   totuplet   True(   t   fileNamet   sourceR   t   ast(    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyt   get_info   s    "c   
      C   só   t  |  ƒ } g  } xŽ | i ƒ  D]€ } | i | ƒ } g  } x< | i ƒ  D]. } | i | ƒ } | i | i ƒ  | f ƒ qG W| i ƒ  | i | i ƒ  | | f ƒ q Wx? | i ƒ  D]1 } | i	 | ƒ }	 | i |	 i ƒ  | d f ƒ q° W| i ƒ  | S(   s½   
    Return classes (with methods) and functions of module *filename*:
    [ (class1_lineno, class1_name, [ (method1_lineno, method1_name), ]),
      (func1_lineno, func1_name, None),]
    N(   R   t   get_class_namest   get_class_infot   get_method_namest   get_method_infot   appendt
   get_linenot   sortt   get_function_namest   get_function_infot   None(
   t   filenamet
   moduleinfot   classest	   classnamet   clinfot   methodst
   methodnamet   minfot   funcnamet   finfo(    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyt   get_classes   s$      
   
t   SuiteInfoBasec           B   sq   e  Z d  Z d Z e i e i d g f f Z d
 d „ Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d	 „  Z RS(   t    iÿÿÿÿt   compoundc         C   s.   h  |  _  h  |  _ | o |  i | ƒ n d  S(   N(   t   _class_infot   _function_infot   _extract_info(   t   selft   tree(    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyt   __init__6   s    		c         C   s®   x§ | d D]› } t  |  i | ƒ \ } } | ov | d } | d t i j o  t | ƒ } | |  i | i <q¦ | d t i j o  t | ƒ } | |  i	 | i <q¦ q q Wd  S(   Ni   R*   i    (
   t   matcht   COMPOUND_STMT_PATTERNt   symbolt   funcdeft   FunctionInfoR,   t   _namet   classdeft	   ClassInfoR+   (   R.   R/   t   nodet   foundt   varst   cstmtt	   func_infot
   class_info(    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR-   <   s     
c         C   s   |  i  S(   N(   R6   (   R.   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyt   get_nameJ   s    c         C   s   |  i  S(   N(   t   _lineno(   R.   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   M   s    c         C   s   |  i  i ƒ  S(   N(   R+   t   keys(   R.   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   P   s    c         C   s   |  i  | S(   N(   R+   (   R.   t   name(    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   S   s    c         C   s1   y |  i  | SWn t j
 o |  i | SXd  S(   N(   R+   t   KeyErrorR,   (   R.   RB   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyt   __getitem__V   s    N(   t   __name__t
   __module__R6   R@   R3   t   stmtt   compound_stmtR2   R   R0   R-   R?   R   R   R   RD   (    (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR(   +   s   					t   SuiteFuncInfoc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   |  i  i ƒ  S(   N(   R,   RA   (   R.   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   `   s    c         C   s   |  i  | S(   N(   R,   (   R.   RB   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   c   s    (   RE   RF   R   R   (    (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyRI   ]   s   	R5   c           B   s   e  Z d d  „ Z RS(   c         C   s„   d } d } | d d t  i j o | d 7} d } n | | | d |  _ | | d |  _ t i |  | o | d p d  ƒ d  S(   Ni   R)   i   i    t   @iÿÿÿÿ(   R3   t
   decoratorsR6   R@   R(   R0   R   (   R.   R/   t   indext   prefix(    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR0   h   s    

N(   RE   RF   R   R0   (    (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR5   g   s   R8   c           B   s&   e  Z d d  „ Z d „  Z d „  Z RS(   c         C   sH   | d d |  _  | d d |  _ t i |  | o | d p d  ƒ d  S(   Ni   i   iÿÿÿÿ(   R6   R@   R(   R0   R   (   R.   R/   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR0   t   s    c         C   s   |  i  i ƒ  S(   N(   R,   RA   (   R.   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   y   s    c         C   s   |  i  | S(   N(   R,   (   R.   RB   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   |   s    N(   RE   RF   R   R0   R   R   (    (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR8   s   s   	R   c           B   s   e  Z d d  d „ Z RS(   s   <string>c         C   s^   | |  _  d |  _ | d t i j o | d |  _ | d } n
 d |  _ t i |  | ƒ d  S(   Ni    i   i   t   ascii(   R6   R@   R3   t   encoding_declt	   _encodingR(   R0   (   R.   R/   RB   (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR0      s    			N(   RE   RF   R   R0   (    (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR   €   s   c         C   sÜ   | d j o
 h  } n t |  ƒ t j o | | |  d <d | f St |  ƒ t j	 o |  | j | f St | ƒ t |  ƒ j o d | f SxD t d |  | ƒ D]0 \ }  } t |  | | ƒ \ } } | p Pqž qž W| | f S(   sa  Match `data' to `pattern', with variable extraction.

    pattern
        Pattern to match against, possibly containing variables.

    data
        Data to be checked and against which variables are extracted.

    vars
        Dictionary of variables which have already been found.  If not
        provided, an empty dictionary is created.

    The `pattern' value may contain variables of the form ['varname'] which
    are allowed to match anything.  The value that is matched is returned as
    part of a dictionary which maps 'varname' to the matched value.  'varname'
    is not required to be a string object, but using strings makes patterns
    and the code which uses them more readable.

    This function returns two values: a boolean indicating whether a match
    was found and a dictionary mapping variable names to their associated
    values.
    i    i   N(   R   t   typeR    R   t   lent   mapR1   (   t   patternt   dataR;   t   same(    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyR1   Œ   s    
 	t   __main__i   (   t   pprint(    (    (   t   __doc__R   R
   R3   t   typesR    R   R   R'   R(   RI   R5   R8   R   R   R1   RE   t   syst   argvR   RX   (    (    (    sM   P:\graphics\Tools\Python26\lib\site-packages\spyderlib\widgets\classparser.pyt   <module>   s"   		2
'