-
2;c       sr    d  Z     h  d d <d d <d d <d d <d	 d
 <d d <d d <d d <Z 1 y 2 e d i d  d Z Wn 3 4 d Z n X9 d k Z : d k Z ; d k Z < d k Z K e i e i	 d g f f Z
 g e i e i e i e i e i e i e i e i e i e i e i d g f f f f f f f f f f f Z { e i e i e i e i e i e i e i e i e i e i e i e i e i e i e i e i e i e i e i d g f f f f f f f f f f f f f f f f f e i d f f f Z  d   Z   d d  Z!  e" d  Z#  d   Z$  e" d d  Z% +e" d d  Z& d S(    s*   Utility functions for parseinfo package.

s   $RCSfile: utils.py,v $s   module_names:   $Id: utils.py,v 1.2 2001/11/18 22:13:24 doughellmann Exp $s   rcs_ids    Doug Hellmann <doug@hellfly.net>s   creators   UNSPECIFIEDs   projects   Sun, 11-Nov-2001 10:47:39 ESTs   createds   $Author: doughellmann $s   authors   $Revision: 1.2 $s   versions   $Date: 2001/11/18 22:13:24 $s   dates    i   s   0.0Ns   compounds   powers	   docstrings    c    s     | i   d f j o  d } n: | o | d d d d f j oF  | d d j o |  o |  d d j o  | } n
  d } n  |  p( |  o |  d d f j p |  d f j o  d } n  |  o |  d d d d	 f j o | o | d d
 d d f j o  d } n;  |  o |  d d d d	 f j o  | } n
  | }  d |  | | f }  | Sd S(   s   Join two code snippets into one string.

    Use some general code content rules to try to make the
    resulting snippet look nice.
    s   .s    i    s   ,s   (is   -s   [s   {s   )s   ]s   }s   %s%s%sN(   s   seconds   strips   sep_to_be_useds   firsts	   separators   text(   s   firsts   seconds	   separators   texts   sep_to_be_used(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   joinCodeSnippets s    $,6E$	c    s      d }  |  o t |   t i t i f j o  t |  d  t i t i f j o  |  } n  |  d }  t | d   |  }  x& | D ] }  t | | |  } q Wn  t |   }  | Sd S(   s   Convert a parse tree to a string which would have parsed in that way.

    Given a parse tree, walk it to determine the original string
    which would have been parsed to produce that tree.
    s    i    i   c    s    t  |  |  S(   N(   s   parseTreeToStrings   xs   s(   s   xs   s(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   <lambda> s    N(   s   texts   trees   types   typess	   TupleTypes   ListTypes
   tree_partss   maps	   separators	   sub_partss   one_parts   joinCodeSnippetss   str(   s   trees	   separators   one_parts   texts
   tree_partss	   sub_parts(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   parseTreeToString s   	)&
 	c    s      | t j o  g  } n  t |   t i t i f j o  | Sn  |  d | j o  | i |   n/  x( |  d D ] }  t
 | | |  q W | Sd S(   sA   Return a sequence of subtrees starting with node value of 'node'.i    i   N(   s   responses   Nones   types   trees   typess   ListTypes	   TupleTypes   nodes   appends   subtrees   findNode(   s   trees   nodes   responses   subtree(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   findNode s   " 	c    sb      xK t  |  D ]: }  y  |  d }  Wn  t j
 o  f  Sn Xq W |  Sd S(   sB   Return the section of the parse 'tree' that is 'depth' nodes deep.i   N(   s   ranges   depths   is   trees
   IndexError(   s   trees   depths   i(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   drill s    	i    c    sh   t  |   } | t j o 	h  } n 
| t i j o" | | |  d <d | f Sn | t i j	 oS | t i	 j o | o | d d j o d | f Sn |  | j | f Sn t
 |  t
 |   j o d | f Sn xW t t |  |  D]@ \ }  } "t |  | | d | \ } } #| o $Pn qW%| | f Sd S(   sj  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   s   #s   dbgN(   s   types   patterns   pattern_types   varss   Nones   typess   ListTypes   datas	   TupleTypes
   StringTypes   lens   maps   matchs   dbgs   same(   s   patterns   datas   varss   dbgs   pattern_types   same(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   match s&   	+ !c    s#  +GN| t j o Oh  } n Pt |   t i j o" S| | |  d <Td | f Sn Ut |   t i j	 o X|  | j | f Sn Yd } Z|  o | oj [x` t	 t |  |  D[]I \ }  } ^t
 |  | | d | \ } } _| o `Pn
 b| } q Wn c| | f Sd S(   s  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 is based on the match() function, but is more lenient.
    The pattern does not have to completely describe the tree.  Instead,
    it can be the 'top' portion of the tree.  Everything must match down
    to the leaves of the pattern.  At that point, the matching stops.  If
    a match was found at all, the return values indicate a match.
    
    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   s   dbgN(   s   varss   Nones   types   patterns   typess   ListTypes   datas	   TupleTypes   found_matchs   maps   lenientMatchs   dbgs   same(   s   patterns   datas   varss   dbgs   sames   found_match(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   lenientMatch+s"   	 !('   s   __doc__s   __rcs_info__s   splits   __version__s   pprints   symbols   tokens   typess   stmts   compound_stmts   COMPOUND_STMT_PATTERNs   tests   and_tests   not_tests
   comparisons   exprs   xor_exprs   and_exprs
   shift_exprs
   arith_exprs   terms   factors   BASE_CLASS_NAME_PATTERNs   simple_stmts
   small_stmts	   expr_stmts   testlists   powers   atoms   STRINGs   NEWLINEs   DOCSTRING_STMT_PATTERNs   joinCodeSnippetss   parseTreeToStrings   Nones   findNodes   drills   matchs   lenientMatch(   s   findNodes   parseTreeToStrings   symbols   pprints   COMPOUND_STMT_PATTERNs   __rcs_info__s   tokens   BASE_CLASS_NAME_PATTERNs   matchs   drills   __version__s   lenientMatchs   joinCodeSnippetss   typess   DOCSTRING_STMT_PATTERN(    (    sY   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_1/happydoclib/parseinfo/utils.pys   ? s$   Qo#@