-í
ç¶<c       s¿   d  Z  d k Z d k Z d k Z d k Z d g Z d Z e i d e i e i	 Be i
 Bƒ i Z h  Z d f  d „  ƒ  YZ d e f d „  ƒ  YZ g  d	 d
 „ Z g  d	 d „ Z e i d „ Z d S(   sZ	  Parse a Python file and retrieve classes and methods.

Parse enough of a Python file to recognize class and method
definitions and to find out the superclasses of a class.

The interface consists of a single function:
        readmodule(module, path)
module is the name of a Python module, path is an optional list of
directories where the module is to be searched.  If present, path is
prepended to the system search path sys.path.
The return value is a dictionary.  The keys of the dictionary are
the names of the classes defined in the module (including classes
that are defined via the from XXX import YYY construct).  The values
are class instances of the class Class defined here.

A class is described by the class Class in this module.  Instances
of this class have the following instance variables:
        name -- the name of the class
        super -- a list of super classes (Class instances)
        methods -- a dictionary of methods
        file -- the file in which the class was defined
        lineno -- the line in the file on which the class statement occurred
The dictionary of methods uses the method names as keys and the line
numbers on which the method was defined as values.
If the name of a super class is not recognized, the corresponding
entry in the list of super classes is not a class instance but a
string giving the name of the super class.  Since import statements
are recognized and imported modules are scanned as well, this
shouldn't happen often.

BUGS
- Continuation lines are not dealt with at all, except inside strings.
- Nested classes and functions can confuse it.
- Code that doesn't pass tabnanny or python -t will confuse it, unless
  you set the module TABWIDTH vrbl (default 8) to the correct tab width
  for the file.

PACKAGE RELATED BUGS
- If you have a package and a module inside that or another package
  with the same name, module caching doesn't work properly since the
  key is the base name of the module/package.
- The only entry that is returned when you readmodule a package is a
  __path__ whose value is a list which confuses certain class browsers.
- When code does:
  from package import subpackage
  class MyClass(subpackage.SuperClass):
    ...
  It can't locate the parent.  It probably needs to have the same
  hairy logic that the import locator already does.  (This logic
  exists coded in Python in the freeze package.)
Ns
   readmodulei   s2  
    (?P<String>
       \""" [^"\\]* (?:
                        (?: \\. | "(?!"") )
                        [^"\\]*
                    )*
       \"""

    |   ''' [^'\\]* (?:
                        (?: \\. | '(?!'') )
                        [^'\\]*
                    )*
        '''

    |   " [^"\\\n]* (?: \\. [^"\\\n]*)* "

    |   ' [^'\\\n]* (?: \\. [^'\\\n]*)* '
    )

|   (?P<Method>
        ^
        (?P<MethodIndent> [ \t]* )
        def [ \t]+
        (?P<MethodName> [a-zA-Z_] \w* )
        [ \t]* \(
    )

|   (?P<Class>
        ^
        (?P<ClassIndent> [ \t]* )
        class [ \t]+
        (?P<ClassName> [a-zA-Z_] \w* )
        [ \t]*
        (?P<ClassSupers> \( [^)\n]* \) )?
        [ \t]* :
    )

|   (?P<Import>
        ^ import [ \t]+
        (?P<ImportList> [^#;\n]+ )
    )

|   (?P<ImportFrom>
        ^ from [ \t]+
        (?P<ImportFromPath>
            [a-zA-Z_] \w*
            (?:
                [ \t]* \. [ \t]* [a-zA-Z_] \w*
            )*
        )
        [ \t]+
        import [ \t]+
        (?P<ImportFromList> [^#;\n]+ )
    )
s   Classc      s    t  Z d  Z d „  Z d „  Z RS(   s"   Class to represent a Python class.c    sQ   | |  _  | |  _ | t j o
 g  } n | |  _ h  |  _ | |  _ | |  _ d  S(   N(   s   modules   selfs   names   supers   Nones   methodss   files   lineno(   s   selfs   modules   names   supers   files   lineno(    (    s   /usr/lib/python2.2/pyclbr.pys   __init__{ s    		
			c    s   | |  i | <d  S(   N(   s   linenos   selfs   methodss   name(   s   selfs   names   lineno(    (    s   /usr/lib/python2.2/pyclbr.pys
   _addmethod… s    (   s   __name__s
   __module__s   __doc__s   __init__s
   _addmethod(    (    (    s   /usr/lib/python2.2/pyclbr.pys   Classy s    	
s   Functionc      s    t  Z d  Z d „  Z d „  Z RS(   s.   Class to represent a top-level Python functionc    s    t  i |  | | t | | ƒ d  S(   N(   s   Classs   __init__s   selfs   modules   names   Nones   files   lineno(   s   selfs   modules   names   files   lineno(    (    s   /usr/lib/python2.2/pyclbr.pys   __init__Š s    c    s   d  S(   N(    (   s   selfs   names   lineno(    (    s   /usr/lib/python2.2/pyclbr.pys
   _addmethodŒ s    (   s   __name__s
   __module__s   __doc__s   __init__s
   _addmethod(    (    (    s   /usr/lib/python2.2/pyclbr.pys   Functionˆ s    	i    c    s\   t  |  | | ƒ } h  } x9 | i ƒ  D]+ \ } } t	 | t
 ƒ o | | | <n q% W| Sd S(   sx   Backwards compatible interface.

    Like readmodule_ex() but strips Function objects from the
    resulting dictionary.N(   s   readmodule_exs   modules   paths	   inpackages   dicts   ress   itemss   keys   values
   isinstances   Function(   s   modules   paths	   inpackages   dicts   keys   ress   value(    (    s   /usr/lib/python2.2/pyclbr.pys
   readmodule s      c     sw  h  } |  i d ƒ } | d j oT |  |  i ƒ  } |  | d i ƒ  } t | | | ƒ } t | | d d ƒ } | Sn t i |  ƒ o t |  Sn |  t i j o | t |  <| Sn t } | oH y( t i |  | ƒ \ } } \ } } } Wn t j
 o t } n Xn | t j o; t | ƒ t i } t i |  | ƒ \ } } \ } } } n | t i j oO | g | d <| t |  <| g | } t i d | g ƒ \ } } \ } } } n | t i j o | i ƒ  | t |  <| Sn | t |  <g  } | i ƒ  } | i ƒ  t! i" } d d f \ } } d } xId oAt& | | ƒ } | o Pn | i( ƒ  \ } } | i) d ƒ d j oº t* | i+ d ƒ ƒ } | i+ d ƒ }	 | | | d	 | | ƒ } | } x( | o | d
 d | j o | d
 =q·W| o" | d
 d } | i/ |	 | ƒ n  t0 |  |	 | | ƒ } | | |	 <n@| i) d ƒ d j o n&| i) d ƒ d j o§t* | i+ d ƒ ƒ } x( | o | d
 d | j o | d
 =qsW| | | d	 | | ƒ } | } | i+ d ƒ }
 | i+ d ƒ } | oê | d d
 !i ƒ  } g  } xÄ | i4 d ƒ D]³ } | i ƒ  } | i | ƒ o | | } nw | i4 d ƒ } t7 | ƒ d j oT | d } | d
 } t i | ƒ o, t | } | i | ƒ o | | } n n n | i9 | ƒ qW| } n t: |  |
 | | | ƒ } | | |
 <| i9 | | f ƒ ni| i) d ƒ d j oS xL | i+ d ƒ i4 d ƒ D]2 } | i ƒ  } y t | | | ƒ } Wn n Xq1Wn | i) d ƒ d j oé | i+ d ƒ } | i+ d ƒ i4 d ƒ } y t | | | ƒ } Wn
 q&n Xx˜ | D] } | i ƒ  } | i | ƒ o | | | | <n] | d j oO xH | i< ƒ  D]: } | d d j o | i | ƒ o | | | | <n q Wn qÒWn q&W| Sd S(   sÐ   Read a module file and return a dictionary of classes.

    Search for MODULE in PATH and sys.path, read and parse the
    module and return a dictionary with one entry for each class
    found in the module.s   .i    i   s   __path__s   __init__s   Methods   MethodIndents
   MethodNames   
iÿÿÿÿs   Strings   Classs   ClassIndents	   ClassNames   ClassSuperss   ,iþÿÿÿs   Imports
   ImportLists
   ImportFroms   ImportFromPaths   ImportFromLists   *s   _N(=   s   dicts   modules   rfinds   is   strips   packages	   submodules   readmodule_exs   paths	   inpackages   parents   childs   _moduless   has_keys   syss   builtin_module_namess   Nones   fs   imps   find_modules   files   suffs   modes   types   ImportErrors   lists   fullpaths   PKG_DIRECTORYs	   PY_SOURCEs   closes
   classstacks   reads   srcs   strings   counts   countnls   linenos   last_lineno_poss   _getnexts   ms   spans   starts   _indents   groups
   thisindents	   meth_names	   cur_classs
   _addmethods   Functions
   class_names   inherits   namess   splits   ns   cs   lens   ds   appends   Classs   mods   keys(    s   modules   paths	   inpackages   suffs   namess   files	   submodules   countnls
   thisindents	   meth_names
   class_names   dicts   linenos   last_lineno_poss   types   starts   parents	   cur_classs   childs
   classstacks   mods   srcs   cs   ds   packages   is   fs   ms   inherits   ns   modes   fullpath(    (    s   /usr/lib/python2.2/pyclbr.pys   readmodule_exœ sð     
((
+



	  	  




   ""c    s   t  | |  t ƒ ƒ Sd  S(   N(   s   lens   _expandtabss   wss   TABWIDTH(   s   wss   _expandtabs(    (    s   /usr/lib/python2.2/pyclbr.pys   _indentPs    (   s   __doc__s   syss   imps   res   strings   __all__s   TABWIDTHs   compiles   VERBOSEs   DOTALLs	   MULTILINEs   searchs   _getnexts   _moduless   Classs   Functions
   readmodules   readmodule_exs
   expandtabss   _indent(   s   Functions   strings   __all__s   res   _moduless   syss   imps   _getnexts   TABWIDTHs   _indents   readmodule_exs   Classs
   readmodule(    (    s   /usr/lib/python2.2/pyclbr.pys   ?3 s   					&8´