
    -PhhJ                       U d Z ddlmZ ddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlZddlmZmZmZmZmZ dd	lmZ erPdd
lmZmZmZmZm Z  ddlm!Z!m"Z"m#Z# ddl$m%Z% ddlm&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5  ej6        dej7                  Z8 e9 e:ej;         e<e          =                                                    Z>de?d<   d=dZ@d>d ZA G d! d"eB          ZC G d# d$          ZD G d% d&e          ZE G d' d(e          ZFd?d,ZGd@d.ZHdAd2ZIdBd4ZJdCd6ZKdDd8ZLdEd<ZMdS )FaQ  Defines a docutils directive for inserting inheritance diagrams.

Provide the directive with one or more classes or modules (separated
by whitespace).  For modules, all of the classes in that module will
be used.

Example::

   Given the following classes:

   class A: pass
   class B(A): pass
   class C(A): pass
   class D(B, C): pass
   class E(B): pass

   .. inheritance-diagram: D E

   Produces a graph like the following:

               A
              / \
             B   C
            / \ /
           E   D

The graph is inserted as a PNG+image map into HTML and a PDF in
LaTeX.
    )annotationsN)import_module)TYPE_CHECKINGcast)nodes)
directives)figure_wrappergraphvizrender_dot_htmlrender_dot_latexrender_dot_texinfo)SphinxDirective)
CollectionIterableIteratorSequenceSet)AnyClassVarFinal)Node)addnodes)Sphinx)Config)BuildEnvironment)ExtensionMetadata
OptionSpec)HTML5Translator)LaTeXTranslator)TexinfoTranslatorzY^
    (?:([\w.]*)\.)?  # module names
    (\w+)  \s* $     # class/final module name
    r   PY_BUILTINSobjnamestrreturnr   c                6   	 t          |           S # t          $ r Y dS t          $ rq t                              |           }|sY dS |                                \  }}|Y dS 	 t          |          }t          ||d          cY S # t          $ r Y Y dS w xY ww xY w)zImport a object or module using *name* and *currentmodule*.
    *name* should be a relative name from *currentmodule* or
    a fully-qualified name.

    Returns imported object or module.  If failed, returns None value.
    N)r   	TypeErrorImportErrormodule_sig_rematchgroupsgetattr)r"   matchedmodnameattrnamemodules        ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/ext/inheritance_diagram.py
try_importr1   Q   s    W%%%   tt   %%g.. 	44#NN,,?44	"7++F68T22222 	 	 	444	s8    
B%BB#BB
BBBBname
currmodulelist[type[Any]]c                H   d|rt          |dz   | z             t          |           t          d| z            t          j                  rgS t          j                  r%fdj                                        D             S | d}t          |          )z0Import a class using its fully-qualified *name*.N.zECould not import class or module %r specified for inheritance diagramc                \    g | ](}t          j        |          r|j        j        k    &|)S  )inspectisclass
__module____name__).0clstargets     r0   
<listcomp>z"import_classes.<locals>.<listcomp>   sF     
 
 
s##
 ),&/(I(I (I(I(I    z; specified for inheritance diagram is not a class or module)r1   InheritanceExceptionr9   r:   ismodule__dict__values)r2   r3   msgr?   s      @r0   import_classesrG   n   s    F  5J,t344 ~D!!~""$()
 
 	

 v 	
x		&	!	! 

 
 
 
--//
 
 
 	

 
P
P
PC
s
#
##rA   c                      e Zd ZdS )rB   N)r<   r;   __qualname__r8   rA   r0   rB   rB      s        DrA   rB   c                      e Zd ZU dZdddd e            dfdAdZdBdZdCdZ	 dDdEdZdFdZ	d d!d"d#Z
d$ed%<   d&d'd(d)d*d+d,Zd$ed-<   d.d/d0Zd$ed1<   dGd3ZdGd4Z	 	 	 	 	 dHdId=Z	 	 	 	 	 dHdJd@ZdS )KInheritanceGraphzGiven a list of classes, determines the set of classes that they inherit
    from all the way to the root "object", and then is able to generate a
    graphviz dot graph from them.
    Fr   Nclass_names	list[str]r3   r#   show_builtinsboolprivate_basespartsintaliasesdict[str, str] | Nonetop_classesSet[str]include_subclassesr$   Nonec	                &   || _         |                     ||          }	|r:h |	}
t          |
          D ]$}|
                    t	          |                     %|
}	|                     |	|||||          | _        | j        sd}t          |          dS )z*class_names* is a list of child classes to show bases from.

        If *show_builtins* is True, then Python builtins will be shown
        in the graph.
        z(No classes found for inheritance diagramN)rL   _import_classestupleupdate_subclasses_class_info
class_inforB   )selfrL   r3   rN   rP   rQ   rS   rU   rW   classesclasses_setr>   rF   s                r0   __init__zInheritanceGraph.__init__   s      ')-)=)=k:)V)V 	"$G*K[)) 5 5"";s#3#34444!G**]M5';
 
  	,<C&s+++	, 	,rA   Sequence[type[Any]]c                Z    g }|D ]%}|                     t          ||                     &|S )zImport a list of classes.)extendrG   )r`   rL   r3   ra   r2   s        r0   rZ   z InheritanceGraph._import_classes   s<     $& 	= 	=DNN>$
;;<<<<rA   ra   Collection[type[Any]]0list[tuple[str, str, Sequence[str], str | None]]c           	         	 i d	 fd	|D ]} 	|           d                                  D             S )a  Return name and bases for all classes that are ancestors of
        *classes*.

        *parts* gives the number of dotted name parts to include in the
        displayed node names, from right to left. If given as a negative, the
        number of parts to drop from the left. A value of 0 displays the full
        dotted name. E.g. ``sphinx.ext.inheritance_diagram.InheritanceGraph``
        with ``parts=2`` or ``parts=-2`` gets displayed as
        ``inheritance_diagram.InheritanceGraph``, and as
        ``ext.inheritance_diagram.InheritanceGraph`` with ``parts=3`` or
        ``parts=-1``.

        *top_classes* gives the name(s) of the top most ancestor class to
        traverse to. Multiple names can be specified separated by comma.
        r>   	type[Any]r$   rX   c                   s| t           v rd S 
s| j                            d          rd S                     | 	          }                    | d          }d }	 | j        rM| j                                                            d          d         }|rd|                    dd          z  }n# t          $ r Y nw xY wg }||||f| <   |v rd S | j	        D ]d}s
|t           v r
s|j                            d          r+|
                                        |	                     |vr |           ed S )N_r   
z"%s""z\")r!   r<   
startswith
class_name__doc__stripsplitreplace	Exception	__bases__append)r>   nodenamefullnametooltipdocbaselistbaserS   all_classesrQ   rP   recurser`   rN   rU   s          r0   r   z-InheritanceGraph._class_info.<locals>.recurse   s     SK%7%7  S\%<%<S%A%A sE7;;HsAw77H G; C+++--33D99!<C C"(3;;sE+B+B"B    #%H ((HgFK;&& " "$ )<)<$ )A)A#)F)F eW E EFFF{**GDMMM" "s   AB3 3
C ?C c                >    g | ]\  }}}}||t          |          |fS r8   )r[   )r=   cls_namery   basesrz   s        r0   r@   z0InheritanceGraph._class_info.<locals>.<listcomp>   s?     
 
 
48UG xuw7
 
 
rA   )r>   rj   r$   rX   )rE   )
r`   ra   rN   rP   rQ   rS   rU   r>   r~   r   s
   ` ````` @@r0   r^   zInheritanceGraph._class_info   s    0  	"  	"  	"  	"  	"  	"  	"  	"  	"  	"  	"  	"  	"D  	 	CGCLLLL
 
8C8J8J8L8L
 
 
 	
rA   r>   rj   c                    |j         }|dv r|j        }n| d|j         }|dk    r|}n3|                    d          }d                    || d                   }|||v r||         S |S )zGiven a class object, return a fully-qualified name.

        This works for things I've tested in matplotlib so far, but may not be
        completely general.
        >   builtins__builtin__r6   r   N)r;   r<   rI   rs   join)r`   r>   rQ   rS   r/   ry   result
name_partss           r0   rp   zInheritanceGraph.class_name  s     000|HH 553#355HA::FF!,,JXXj%122F6W#4#46?"rA   c                $    d | j         D             S )z1Get all of the class names involved in the graph.c                    g | ]	\  }}}}|
S r8   r8   )r=   rl   ry   s      r0   r@   z8InheritanceGraph.get_all_class_names.<locals>.<listcomp>  s!    DDD0a1aDDDrA   )r_   )r`   s    r0   get_all_class_namesz$InheritanceGraph.get_all_class_names  s    DDDODDDDrA   LRz"8.0, 12.0"transparent)rankdirsizebgcolordict[str, float | int | str]default_graph_attrsbox
   g      ?zA"Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans"z"setlinewidth(0.5),filled"white)shapefontsizeheightfontnamestyle	fillcolordefault_node_attrsg      ?z"setlinewidth(0.5)")	arrowsizer   default_edge_attrsattrsc                ~    d                     d t          |                                          D                       S )N,c              3  *   K   | ]\  }}| d | V  dS )=Nr8   r=   kvs      r0   	<genexpr>z6InheritanceGraph._format_node_attrs.<locals>.<genexpr>1  s0      EEtq!1

q

EEEEEErA   r   sorteditemsr`   r   s     r0   _format_node_attrsz#InheritanceGraph._format_node_attrs0  s3    xxEEvekkmm/D/DEEEEEErA   c                ~    d                     d t          |                                          D                       S )N c              3  ,   K   | ]\  }}| d | dV  dS )r   z;
Nr8   r   s      r0   r   z7InheritanceGraph._format_graph_attrs.<locals>.<genexpr>4  s2      GGA!}}a}}}GGGGGGrA   r   r   s     r0   _format_graph_attrsz$InheritanceGraph._format_graph_attrs3  s3    wwGG1F1FGGGGGGrA   r2   urlsenvBuildEnvironment | Nonegraph_attrs#dict[str, float | int | str] | None
node_attrs
edge_attrsc                L    ||j         nd }|                     ||||||          S N)config_generate_dot)r`   r2   r   r   r   r   r   r   s           r0   generate_dotzInheritanceGraph.generate_dot6  s8      #D!!$Z
 
 	
rA   r   Config | Nonec           	         |i } j                                         } j                                        } j                                        ||                    |           ||                    |           |                    |           |rN|                    |j                   |                    |j                                       |j                   d| d                     |          g}	t           j
                  D ]\  }
}}|                                }|
|v rd||
          d|d<   d|d<   |r||d<   |	                    d	 d
                     |           d           |	                     fd|D                        |	                    d           d                    |	          S )aV  Generate a graphviz dot graph from the classes that were passed in
        to __init__.

        *name* is the name of the graph.

        *urls* is a dictionary mapping class names to HTTP URLs.

        *graph_attrs*, *node_attrs*, *edge_attrs* are dictionaries containing
        key/value pairs to pass on as graphviz properties.
        Nzdigraph z {
rn   URLz"_top"r?   rz     "" [];
c           	   3  V   K   | ]#}d | d d                                dV  $dS )r   z" -> "r   r   N)r   )r=   	base_namer   e_attrsr`   s     r0   r   z1InheritanceGraph._generate_dot.<locals>.<genexpr>y  sa         [iZZxZZD4K4KG4T4TZZZ     rA   z}
r   )r   copyr   r   r\   inheritance_graph_attrsinheritance_node_attrsinheritance_edge_attrsr   r   r_   rw   r   rf   r   )r`   r2   r   r   r   r   r   g_attrsn_attrsresry   r   rz   this_node_attrsr   r   s   `             @@r0   r   zInheritanceGraph._generate_dotD  s    & <D*//11)..00)..00"NN;'''!NN:&&&!NN:&&& 	:NN69:::NN68999NN68999 #t"""$$W--

 392I2I 	 	.Hhw%llnnO4)>T(^)>)>)>&,4) 5-4	*JJQhQQ4#:#:?#K#KQQQ  
 JJ      !&       	

5wws||rA   )rL   rM   r3   r#   rN   rO   rP   rO   rQ   rR   rS   rT   rU   rV   rW   rO   r$   rX   )rL   rM   r3   r#   r$   rd   )ra   rg   rN   rO   rP   rO   rQ   rR   rS   rT   rU   rV   r$   rh   )r   N)r>   rj   rQ   rR   rS   rT   r$   r#   )r$   rM   )r   r   r$   r#   )NNNNN)r2   r#   r   rT   r   r   r   r   r   r   r   r   r$   r#   )r2   r#   r   rT   r   r   r   r   r   r   r   r   r$   r#   )r<   r;   rI   rq   	frozensetrc   rZ   r^   rp   r   r   __annotations__r   r   r   r   r   r   r8   rA   r0   rK   rK      s          $#)- )	#(, , , , ,<   B
 B
 B
 B
J PT    ,E E E E  9 9     W-8 8     &8 8    
F F F FH H H H '+'+;?:>:>
 
 
 
 
" '+ $;?:>:>: : : : : : :rA   rK   c                      e Zd ZdZdS )inheritance_diagramzDA docutils node to use as a placeholder for the inheritance diagram.N)r<   r;   rI   rq   r8   rA   r0   r   r     s        NNDrA   r   c                  n    e Zd ZU dZdZdZdZdZee	j
        e	j        e	j        e	j
        dZded<   ddZdS )InheritanceDiagramz@Run when the inheritance_diagram directive is first encountered.F   r   T)rQ   private-basescaptiontop-classesinclude-subclasseszClassVar[OptionSpec]option_specr$   
list[Node]c           
     B  
 t                      }| j        j        |_        | j        d                                         }| j        j        j                            d          }| j	        
                    dd          |d<   d                    |          |d<   t          
fd| j	        
                    dd                              d	          D                       |d<   	 t          || j        j        
                    d
          |d         d| j	        v | j        j        |d         d| j	        v           }n># t"          $ r1}|j        j                            || j                  gcY d }~S d }~ww xY w|                                D ]7} |dd| d|d| j        j                  \  }}|                    |           8||d<   d| j	        vr|                     |           |gS t3          | || j	        d                   }	|                     |	           |	gS )Nr   classrQ   z, contentc                @    h | ]}|                                 xS r8   )rr   )r=   r>   cls_strippeds     r0   	<setcomp>z)InheritanceDiagram.run.<locals>.<setcomp>  s<     )
 )
 )
 #		+)
)
 )
 )
rA   r   r   r   z	py:moduler   r   )rQ   rP   rS   rU   rW   )linez:class:``graphr   )r   statedocument	argumentsrs   r   domainspython_domainroleoptionsgetr   r   rK   ref_contextr   inheritance_aliasrB   reporterwarninglinenor   inlinerrf   add_namer	   )r`   noderL   
class_roler   errr2   refnodesxfigurer   s             @r0   runzInheritanceDiagram.run  sU   "$$
+nQ'--//X%388AA
((!44W))K00Y' )
 )
 )
 )
|''r::@@EE)
 )
 )
  ]	K$$((557m-=5 /#74<#G  EE $ 	K 	K 	KM*223T[2IIJJJJJJJ	K --// 	" 	"D$*+D+++T1dj6H KHa KK!!!! WDL((MM$6M#D$Y0GHHFMM&!!!8Os   %AD= =
E8&E3-E83E8N)r$   r   )r<   r;   rI   rq   has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacerR   r   flag	unchangedunchanged_requiredr   r   r   r8   rA   r0   r   r     s         JJK $#'!4(o) )K    / / / / / /rA   r   r>   rj   Iterator[type[Any]]c              #  j   K   | V  |                                  D ]}t          |          E d {V  d S r   )__subclasses__r]   )r>   sub_clss     r0   r]   r]     sW      
III%%'' ( (w''''''''''( (rA   r   c                    | d         t          | d                   z                                   }t          j        |d                                          dd          S )Nr   rQ   F)usedforsecurityi)r#   encodehashlibmd5	hexdigest)r   encodeds     r0   get_graph_hashr    sR    IT']!3!33;;==G;w666@@BB344HHrA   r`   r   rX   c                @   |d         }t          |          }d|z  }| j        j                                        }t          j                            | j        j        | j        j	        z             }i }t          d|          }|D ]}	|	                    d          Z|	                    dd          s#|	d                             dd	          d
         }
n|	d         }
|	                    d          ||
<   q|	                    d          L|dk    r%|dz   |	                    d          z   ||	d         <   d|	                    d          z   ||	d         <   |                    ||| j                  }t          | ||i ddd|d         z              t          j        )zUOutput the graph for HTML.  This will insert a PNG with clickable
    image map.
    r   inheritance%szIterable[addnodes.pending_xref]refuriNinternalT#r   reftitlerefidSVG)r   inheritancezInheritance diagram of r   )alt)r  r   graphviz_output_formatupperospathbasenamebuildercurrent_docname
out_suffixr   r   rsplitr   r   r   SkipNode)r`   r   r   
graph_hashr2   r  current_filenamer   pending_xrefschildrefnamedotcodes               r0   html_visit_inheritance_diagramr(    s    ME%%JZ'D "[?EEGGw''$t|'>>  D:DAAM C C99X*99Z.. ,/00a88<
+!IIh//DMMYYw+%..*:S*@599WCUCU*UU:&''*-		'0B0B*BU:&'!!$T[!AAG
%Y7    .rA   r   c                    |d         }t          |          }d|z  }|                    || j        ddi          }t          | ||i d           t          j        )z4Output the graph for LaTeX.  This will insert a PDF.r   r  r   	"6.0,6.0"r   r   r  )r  r   r   r   r   r!  r`   r   r   r"  r2   r'  s         r0   latex_visit_inheritance_diagramr-    sl     ME%%JZ'D!!T[v{.C "  G T4"m<<<
.rA   r    c                    |d         }t          |          }d|z  }|                    || j        ddi          }t          | ||i d           t          j        )z6Output the graph for Texinfo.  This will insert a PNG.r   r  r   r*  r+  r  )r  r   r   r   r   r!  r,  s         r0   !texinfo_visit_inheritance_diagramr/    sl    
 ME%%JZ'D!!T[v{.C "  G tT7B>>>
.rA   nodes.NodeVisitorc                    t           j        r   )r   r!  )r`   r   s     r0   skipr2  "  s
    
.rA   appr   r   c           	     f   |                      d           |                     t          t          d ft          d ft
          d ft
          d ft          d f           |                     dt                     | 	                    di dt          t          h                     | 	                    di dt          t          h                     | 	                    di dt          t          h                     | 	                    d	i dt          t          h                     t          j        d
dS )Nzsphinx.ext.graphviz)latexhtmltextmantexinfozinheritance-diagramr   r   )typesr   r   r   T)versionparallel_read_safe)setup_extensionadd_noder   r-  r(  r2  r/  add_directiver   add_config_valuer   dictsphinx__display_version__)r3  s    r0   setuprD  &  s-   -...LL.5,d3D\4L2D9     +-?@@@2B)TFBSBSTTT12rD6ARARSSS12rD6ARARSSS,b"Itf<M<MNNN-"  rA   )r"   r#   r$   r   )r2   r#   r3   r#   r$   r4   )r>   rj   r$   r  )r   r   r$   r#   )r`   r   r   r   r$   rX   )r`   r   r   r   r$   rX   )r`   r    r   r   r$   rX   )r`   r0  r   r   r$   rX   )r3  r   r$   r   )Nrq   
__future__r   r   r  r9   os.pathr  re	importlibr   typingr   r   docutilsr   docutils.parsers.rstr   rB  sphinx.ext.graphvizr	   r
   r   r   r   sphinx.util.docutilsr   collections.abcr   r   r   r   r   r   r   r   docutils.nodesr   r   sphinx.applicationr   sphinx.configr   sphinx.environmentr   sphinx.util.typingr   r   sphinx.writers.html5r   sphinx.writers.latexr   sphinx.writers.texinfor    compileVERBOSEr(   r   filterr:   varsrE   r!   r   r1   rG   ru   rB   rK   r   r   r]   r  r(  r-  r/  r2  rD  r8   rA   r0   <module>r[     s    < # " " " " "     				 # # # # # # & & & & & & & &       + + + + + +               1 0 0 0 0 0 9MMMMMMMMMMMMMM++++++++++######))))))$$$$$$333333@@@@@@@@444444444444888888
 J  YvvgottH~~7L7L7N7NOOPP P P P P   :$ $ $ $@	 	 	 	 	9 	 	 	l l l l l l l l^	 	 	 	 	( 	 	 	> > > > > > > >B( ( ( (I I I I
+ + + +\       "        rA   