
    %hT                         d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	 dgZ
 G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Zedk(  r eee      Zej+                          yy)a  
  Copyright 2011 by the Massachusetts
  Institute of Technology.  All Rights Reserved.

  Export of this software from the United States of America may
  require a specific license from the United States Government.
  It is the responsibility of any person or organization contemplating
  export to obtain such a license before exporting.

  WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
  distribute this software and its documentation for any purpose and
  without fee is hereby granted, provided that the above copyright
  notice appear in all copies and that both that copyright notice and
  this permission notice appear in supporting documentation, and that
  the name of M.I.T. not be used in advertising or publicity pertaining
  to distribution of the software without specific, written prior
  permission.  Furthermore if you modify this software you must label
  your software as modified software and not distribute it in such a
  fashion that it might be confused with the original M.I.T. software.
  M.I.T. makes no representations about the suitability of
  this software for any purpose.  It is provided "as is" without express
  or implied warranty.
    N)defaultdict)make_parser)ContentHandler)*krb5_free_octet_datac                   ,    e Zd ZdZd Zg fdZd Zd Zy)DocNodez/
    Represents the structure of xml node.
    c                 v    || _         t               | _        t               | _        t        t              | _        y)a  
        @param node: name - the name of a node.
        @param attributes: a dictionary populated with attributes of a node
        @param children: a dictionary with lists of children nodes. Nodes
            in lists are ordered as they appear in a document.
        @param content: a content of xml node represented as a list of
            tuples [(type,value)] with type = ['char'|'element'].
            If type is 'char' then the value is a character string otherwise
            it is a reference to a child node.
        N)namelistcontentdict
attributesr   children)selfr   s     //tmp/krb5-1.22.1/doc/tools/doxybuilder_funcs.py__init__zDocNode.__init__&   s)     	v&#D)    c                    t               }|j                  | j                  |d         }|j                  |d          ||d<   | j                  D ]L  \  }}|dk(  r|dk7  s|j                  |       #|j                  |d|      }|9|j                  d|z         N |j                         |d<    || dj                  |            }|.|dk(  rt        j                  dd|      }|S |j                         }|S )Ndefaultchar    z %s z[ ]+ )r   getr   appendr   walkpopjoinresubstrip)	r   
decoratorssub_wsstackresult	decoratorobj_typeobjpartials	            r   r   zDocNode.walk6   s    NN499j.CD	Z	*+ )
9"ll 	4NXc6!"9MM#&((:a7&MM&7"23	4 !&		
941{v6   r   c                 T    dd i}| j                  |d      }t        |      dk(  rd }|S )Nr   c                     |S N )nodevalues     r   <lambda>z$DocNode.getContent.<locals>.<lambda>O   s    E r   r   r   )r   len)r   r#   r&   s      r   
getContentzDocNode.getContentN   s3    !9:
:q)v;!Fr   c                 8   d| j                   z  g}| j                  j                         D ]  \  }}|j                  d|d|        | j                  j                         D ]$  \  }}|j                  d|t        |      fz         & dj                  |      S )NzContent: %szAttr: z = zChild: %s,%i
)r   r   	iteritemsr   r   r2   r   )r   r&   keyr0   s       r   __repr__zDocNode.__repr__V   s    $,,./??446 	9KSMMS78	9==224 	=KSMM.CE
+;;<	= yy  r   N)__name__
__module____qualname____doc__r   r   r3   r8   r.   r   r   r	   r	   "   s     *  .0 0!r   r	   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)DoxyContenHandlerc                 V    || _         t        t              | _        d | _        d | _        y r-   )builderr   intcounters_nodes_current)r   r@   s     r   r   zDoxyContenHandler.__init__a   s#    #C(r   c                      y r-   r.   r   s    r   startDocumentzDoxyContenHandler.startDocumentg   s    r   c                     dd l }y )Nr   )sys)r   rI   s     r   endDocumentzDoxyContenHandler.endDocumentj   s    r   c                    || j                   j                  k(  rg | _        |dk(  r5|j                  d      }|t	        d      | j
                  |xx   dz  cc<   | j                  y t        |      }|j                         D ]  \  }}||j                  |<    | j                  M| j                  j                  |   j                  |       | j                  j                  | j                         || _	        y )N	memberdefkindzKind is not definedr   )r@   toplevelrC   r   
ValueErrorrB   r	   itemsr   rD   r   r   )r   r   attrsrM   r/   r7   r0   s          r   startElementzDoxyContenHandler.startElementm   s    4<<(((DK;99V$D| !677MM$1$;;t} ;;= 	)KS#(DOOC 	)==$MM""4(//5KKt}}-r   c                     | j                   6| j                   j                  j                  d|j                         f       y y )Nr   )rD   r   r   r"   )r   r   s     r   
characterszDoxyContenHandler.characters   s4    ==$MM!!((&)AB %r   c                    || j                   j                  k(  rXt        | j                        dk(  sJ d | _        | j                   j                  j                  | j                         d | _        y | j                  S| j                  }| j                  j                         | _        | j                  j                  j                  d|f       y y )Nr   element)	r@   rN   r2   rC   documentr   rD   r   r   )r   r   r/   s      r   
endElementzDoxyContenHandler.endElement   s    4<<(((t{{#q()(DKLL!!((7 DM{{&}} $ 1%%,,i-=> 'r   N)	r9   r:   r;   r   rG   rJ   rR   rT   rX   r.   r   r   r>   r>   `   s!    *C

?r   r>   c                       e Zd ZdZddZy)XML2ASTz
    Translates XML document into Abstract Syntax Tree like representation
    The content of document is stored in self.document
    c                     t               | _        || _        t               | _        t        |       }| j                  j                  |       d}|d|}| j                  j                  t        |d             y )Nzkrb5_8hin.xml/r)	r   rW   rN   r   parserr>   setContentHandlerparseopen)r   xmlpathrN   handlerfilenamefilepaths         r   r   zXML2AST.__init__   s_     !m#D)%%g."%h/$x,-r   N)doxygen)r9   r:   r;   r<   r   r.   r   r   rZ   rZ      s    .r   rZ   c                        e Zd Z f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d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZddZ xZS )	DoxyFuncsc                 N    t         t        |   |d       t               | _        y )NrL   )rN   )superrh   r   r   objects)r   path	__class__s     r   r   zDoxyFuncs.__init__   s     i'k'Bvr   c                 H    | j                   D ]  }| j                  |        y r-   )rW   process)r   r/   s     r   runzDoxyFuncs.run   s!    MM 	DLL	r   c                     |j                   d   }|dk(  r| j                  |      }ny d|v r|d   t        v ry | j                  j	                  t        di |       y )NrM   functionr   r.   )r   _process_function_nodeexclude_funcsrk   r   DocModel)r   r/   	node_typedatas       r   ro   zDoxyFuncs.process   sZ    OOF+	
"..t4DT>d6lm;H,t,-r   c                     | j                   D ]5  }||j                     }|d|j                  d}|j                  ||       7 y )Nr\   z.rst)rk   categoryr   save)r   	templates
target_dirr)   template_pathoutpaths         r   rz   zDoxyFuncs.save   s?    << 	-C%cll3M%/9GHHWm,	-r   c                    |j                   d   d   j                         }|j                  d   }| j                  |j                   d   d         }|j                   d   d   j                         }|j                   d   d   }| j	                  |      }| j                  |      }| j                  |      }	| j                  |      }
| j                  |      }| j                  |      }| j                  |      }| j                  |      }| j                  |      }|j                   d   d   j                         }|j                   d   d   j                         }d	|||d
   ||	||
|||||t               d}|d   }t        |j                   d         D ]  \  }}|j                   d   d   }| j                  |      }|d
   j                  d      dkD  rd}nd }|j                   j!                  d      }||d   j                         }|j!                  |d      \  }}||||d
   |d   |d}|j#                  |        t%        di |}t'        || j(                         |S )Nr   r   idtypebriefdescriptiondetaileddescription
definition
argsstringrr   r   )ry   r   Idreturn_typereturn_descriptionretval_descriptionsa_descriptionwarn_descriptionnotes_descriptionshort_descriptionversion_numlong_descriptiondeprecated_description
parametersr   paramz...r   declname)NN)seqnor   	directionr   typeIddescription)filer.   )r   r3   r   _process_type_node_process_description_node!_process_return_value_description_process_retval_description_process_warning_description_process_seealso_description_process_notes_description_process_version_description_process_deprecated_descriptionprocess_parameter_descriptionr   	enumeratefindr   r   Functionprinttmp)r   r/   f_namef_Id
f_ret_typef_brief
f_detaileddetailed_descriptionreturn_value_descriptionr   warning_descriptionseealso_descriptionr   	f_versionr   param_description_mapf_definitionf_argsstringfunction_descrr   ip	type_nodep_typep_namep_name_nodep_directionp_descrparam_descrr&   s                                 r   rs   z DoxyFuncs._process_function_node   s   v&q)446t$,,T]]6-B1-EF
-- 23A6AAC]]#89!<
#==jI#'#I#I*#U !==jI"??
K"??
K ;;JG55jA	!%!E!Ej!Q $ B B: N}}\215@@B}}\215@@B&0"( $)3A0H0B,?.A/@/6)2.B4J(,0 $L1
t}}W56 	+EQq

6*1-I,,Y7Fay~~e$r)**..4K&$Q224$9$=$=f[$Q![$%#)(3#)!9%+AY*13K k*%	+& +N+f488$r   c                 f   |j                   j                  d      }||d   j                  d   }nd}|j                         }t	        j
                  dd|      }t	        j
                  dd|      }t	        j
                  dd|      }t	        j
                  d	d|      }|j                         }||fS )
aR  
        Type node has form
            <type>type_string</type>
        for build in types and
            <type>
              <ref refid='reference',kindref='member|compound'>
                  'type_name'
              </ref></type>
              postfix (ex. *, **m, etc.)
            </type>
        for user defined types.
        refNr   refidKRB5_ATTR_DEPRECATEDr   KRB5_CALLCONV_CKRB5_CALLCONV_WRONGKRB5_CALLCONV)r   r   r   r3   r    r!   r"   )r   r   type_ref_node	p_type_idr   s        r   r   zDoxyFuncs._process_type_node   s     "**..u5$%a(33G<II%%'.F;)2v6-r6:V46""r   c           	         |j                   j                  d      }t               }|Pd| j                  i}|D ]=  }|j	                  t        |j                  |d                   |j	                  d       ? dj                  |      }|S )zL
        Description node is comprised of <para>...</para> sections
        parar   r   r5   )r   r   r   paragraph_content_decoratorr   strr   r   )r   r/   r   r&   r#   es         r   r   z#DoxyFuncs._process_description_node  s     }}  (#T%E%EFJ $c!&&Q"789d#$ 6"r   c                     |j                   dk(  r/|j                  d   dk(  rt               }|j                         }|S y y )N
simplesectrM   return)r   r   setr3   )r   r/   r0   conts       r   "return_value_description_decoratorz,DoxyFuncs.return_value_description_decorator$  sA    99$v&(2u( 3
 r   c                    |j                   dk(  r|dz   S |j                   dk(  r|j                  d   dk(  ry y |j                   dk(  r$|j                  d      dk\  rd	|z   d
z   S d|z   d
z   S |j                   dk(  rd|z   dz   S |j                   dk(  rd|z   S |j                   dk(  rd|z   dz   S |j                   dk(  rd|z   dz   S y )Nr   r5   r   rM   r   r   z()r   z	:c:func:``z:data:`emphasisr   itemizedlistlistitemz
	 - computeroutputz**)r   r   r   r   r/   r0   s      r   r   z%DoxyFuncs.paragraph_content_decorator-  s    994<YY,&v&(2 3YY%zz$1$'%/#55 &-33YY*$;$$YY.(%<YY*$u$t++YY**%<$&&r   c                     |j                   dk(  r&|j                  j                  d      }||d|}|S |j                   dk(  ry |S )Nparameternamer   :parameterdescription)r   r   r   )r   r/   r0   r   s       r   parameter_name_decoratorz"DoxyFuncs.parameter_name_decoratorE  sL    99'++K8I$#(3LYY00Lr   c                 H    |j                   dk(  r|S |j                   dk(  ry |S )Nr   r   )r   r   s      r   parameter_description_decoratorz)DoxyFuncs.parameter_description_decoratorQ  s(    99..LYY/)Lr   c                    |j                   j                  d      }t               }||D ]  }|j                   j                  d      }|!|d   j                   j                  d      }|B|D ]{  }d| j                  i}d}	|j	                  |d      j                  d      }
t        |
      dk(  r|
d	   }	| j                  | j                  d
}|j	                  |d      }|	|f||
d   <   }  |S )zT
        Parameter descriptions reside inside detailed description section.
        r   Nparameterlistr   parameteritemr   r      r   r   r   )	r   r   r   r   r   splitr2   r   r   )r   r/   r   r&   r   
param_listparam_itemsitr#   r   r   r   s               r   r   z'DoxyFuncs.process_parameter_descriptionY  s    }}  ( >ZZ^^O<
%(m4488I&% 
>B"+T-J-J!KJ $I77:a066s;D4yA~$(G	-1-Q-Q*.*J*J"LJ"$''*a"8K'0&=F47O
>>& r   c                 .   d }t               }|j                  j                  d      }|k|D ]f  }|j                  j                  d      }|!|D ]A  }| j                  | j                  d}|j                  |d      }|1|j                  |       C h |S Nr   r   r   r   )r   r   r   r   r   r   r   )	r   r/   r&   retr   r   simplesect_listr   r#   s	            r   r   z+DoxyFuncs._process_return_value_descriptionv  s    f}}  ( 	+"#**..">"*) +B-1-T-T*.*G*G"IJWWZ3F)

6*+		+ 
r   c                 j   |j                   j                  d      }d}t               }||D ]  }|j                   j                  d      }|"|D ]  }|j                  d   }|dk(  s|j                   j                  d      }	|	6|	D ]  }
|
j                   j                  d      }|6|d   j                   j                  d      }||d   j	                         }nd	}d
| j
                  i}|
j                  |d      j                  d      }|d   }d|d}|j                  |          |S )zQ
        retval descriptions reside inside detailed description section.
        r   Nr   rM   retvalr   r   r   r   r   r   r   r   z  )	r   r   r   r   r3   r   r   r   r   )r   r/   r   r&   r   r   r   r   rM   r   r   r   val	val_descrr#   r   s                   r   r   z%DoxyFuncs._process_retval_description  sG    }}  (f 0ZZ^^O<
%# 0A<</Dx'&'jjnn_&E&.$ #. 0B*,++//:P*QK*6&1!n&=&=&A&A&&I#&?03A0A0A0CI 02I*3T5R5R)SJ#%77:q#9#?#?#DD"&q'C25y%AFJJ/#00	0> 
r   c                 L    |j                   dk(  r|j                  d   dk(  r|S y y )Nr   rM   warningr   r   r   s      r   return_warning_decoratorz"DoxyFuncs.return_warning_decorator  .    99$v&)3 4 r   c                    d }|j                   j                  d      }|_|D ]Z  }|j                   j                  d      }|!|D ]5  }| j                  | j                  d}|j	                  |d      }|1|c c S  \ |S r   )r   r   r   r   r   r   r/   r&   r   r   r   r   r#   s           r   r   z&DoxyFuncs._process_warning_description  s    }}  ( 
&"#**..">"*) &B-1-J-J*.*J*J"LJWWZ3F)%&	
& r   c                 L    |j                   dk(  r|j                  d   dk(  r|S y y )Nr   rM   seer   r   s      r   return_seealso_decoratorz"DoxyFuncs.return_seealso_decorator  s.    99$v&%/ 0 r   c                     d }|j                   j                  d      }|W|D ]R  }|j                   j                  d      }|!|D ]-  }| j                  | j                  d}|j	                  |d      }/ T |S r   )r   r   r   r   r   r   s           r   r   z&DoxyFuncs._process_seealso_description  s    }}  ( 4"#**..">"*) 4B-1-J-J*.*J*J"LJWWZ3F4	4 r   c                 L    |j                   dk(  r|j                  d   dk(  r|S y y )Nr   rM   versionr   r   s      r   return_version_decoratorz"DoxyFuncs.return_version_decorator  r   r   c                    d }|j                   j                  d      }|_|D ]Z  }|j                   j                  d      }|!|D ]5  }| j                  | j                  d}|j	                  |d      }|1|c c S  \ |S r   )r   r   r   r   r   r   s           r   r   z&DoxyFuncs._process_version_description  s    }}  ( 	&"#**..">"*) &B-1-J-J*.*J*J"LJWWZ3F)%&		& r   c                 l    |j                   dk(  r%|j                  d   dk(  r|j                  dd      S y y )Nr   rM   notez
  z

	  )r   r   replacer   s      r   return_notes_decoratorz DoxyFuncs.return_notes_decorator  s:    99$v&&0}}VZ88 1 r   c                    d }|j                   j                  d      }|_|D ]Z  }|j                   j                  d      }|!|D ]5  }| j                  | j                  d}|j	                  |d      }|1|c c S  \ |S r   )r   r   r  r   r   r   s           r   r   z$DoxyFuncs._process_notes_description   s    }}  ( 	&"#**..">"*) &B-1-H-H*.*J*J"LJWWZ3F)%&		& r   c                    |j                   dk(  rv|j                  d   j                  d      dkD  rT|j                  j	                  d      }|d   3|j                  j	                  d      }d|d   j                         z  }|S y y y )	Nxrefsectr   deprecated_r   	xreftitler   xrefdescriptionzDEPRECATED %s)r   r   r   r   r   r3   )r   r/   r0   r
  	xrefdescrdeprecated_descrs         r   return_deprecated_decoratorz%DoxyFuncs.return_deprecated_decorator  s    99
"t$))-82= MM--k:	Q<+ $ 1 12C DI'619P9P9R'R$++ , > r   c                    d }|j                   j                  d      }|_|D ]Z  }|j                   j                  d      }|!|D ]5  }| j                  | j                  d}|j	                  |d      }|1|c c S  \ |S )Nr   r  r   r   )r   r   r  r   r   )r   r/   r&   r   r   xrefsect_listr   r#   s           r   r   z)DoxyFuncs._process_deprecated_description  s    }}  ( 	& !

z : (' &B-1-M-M*.*J*J"LJWWZ3F)%&		& r   c                     t        dt        |      |      t        |      gz   }t               }t        |d d |dd        D ]  \  }}|j	                  |||         dj                  |      }|S )Nr   r   r   r5   )ranger2   r   zipr   r   )r   r0   linelenbreaksr&   startends          r   break_into_lineszDoxyFuncs.break_into_lines+  sr    qUG,E
|;vcr{6!":6 	,KU3MM%c*+	,6"r   c                     |t         j                  }nt        |d      }|D ]%  }|j                  ddj	                  |      z         ' ||j                          y y )Nwz%s
,)rI   stdoutra   writer   close)r   tablerl   fls        r   _savezDoxyFuncs._save4  sW    <

AT3A 	*AGGFSXXa[()	*GGI r   )R   r-   )r9   r:   r;   r   rp   ro   rz   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r  r"  __classcell__rm   s   @r   rh   rh      s    	.-8t#80
:&)V"  	 r   rh   c                   *     e Zd Z fdZd Zd Z xZS )DoxyBuilderFuncsc                 ~    t         t        |   |       || _        | j                  dd}t	        |d      | _        y )Nr\   zout.txtr  )rj   r'  r   r|   ra   r   )r   rb   rstpathoutfilerm   s       r   r   zDoxyBuilderFuncs.__init__A  s6    t-g6!!__i8%r   c                 d    | j                          ddi}| j                  || j                         y )Nrr   zfunc_document.tmpl)rp   rz   r|   )r   r{   s     r   run_allzDoxyBuilderFuncs.run_allG  s(    
!56			)T__-r   c                 $    | j                          y r-   )rp   rF   s    r   test_runzDoxyBuilderFuncs.test_runL  s    
r   )r9   r:   r;   r   r,  r.  r$  r%  s   @r   r'  r'  @  s    &.
r   r'  __main__)r<   rI   r    collectionsr   xml.saxr   xml.sax.handlerr   docmodelrt   objectr	   r>   rZ   rh   r'  r9   rb   r)  r@   r,  r.   r   r   <module>r5     s   .  	 #  * '(<!f <!|1? 1?h.f . X Xxy  zw0GOO r   