
    -Ph<                       d Z ddlmZ ddlZddlmZmZmZm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mZ dd
lmZ er(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lmZm Z   ej!        d          Z" ej!        d          Z#d#dZ$ ed          Z% G d deee%                   Z& G d de          Z' G d de          Z(d$d"Z)dS )%z(Handlers for additional ReST directives.    )annotationsN)TYPE_CHECKINGGenericTypeVarcast)nodes)
directivesroles)addnodes)docutils)DocFieldTransformer)SphinxDirective)ClassVar)Node)desc_signature)Sphinx)Field
TypedField)ExtensionMetadata
OptionSpecz\\\nz\\(.)argumentstrreturn
int | Nonec                Z    | dS t          |           }|dk     rd}t          |          |S )zICheck for an integer argument or None value; raise ``ValueError`` if not.Nr   z(negative value; must be positive or zero)int
ValueError)r   valuemsgs      Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/directives/__init__.pyoptional_intr!       s7    tH199<CS//!    ObjDescTc                     e Zd ZU dZdZdZdZdZej	        ej	        ej	        ej	        ej	        ej	        ej	        dZ
ded<   g Zded	<   d
Zded<   ded<   ded<   i Zded<   d*dZd+dZd,dZd-dZd.dZd/d"Zd.d#Zd0d&Zd1d'Zd2d)Zd
S )3ObjectDescriptionzDirective to describe a class, function or similar object.

    Not used directly, but subclassed (in domain-specific directives)
    to add custom behaviour.
    T   r   )no-indexno-index-entryno-contents-entryno-typesettingnoindexnoindexentrynocontentsentryClassVar[OptionSpec]option_speczlist[Field]doc_field_typesNz
str | Nonedomainr   objtypezaddnodes.index	indexnodedict[str, tuple[Field, bool]]_doc_field_type_mapr   c                    | j         i k    rTi | _         | j        D ]E}|j        D ]}|df| j         |<   |j        r&t	          d|          }|j        D ]}|df| j         |<   F| j         S )NFr   T)r5   r0   namesis_typedr   	typenames)selffieldnametyped_fields       r    get_field_type_mapz$ObjectDescription.get_field_type_mapM   s    #r))')D$- G G!K D DD6;U^D,T22> G"&|U";";K + 5 G G:?066''r"   	list[str]c                    t                               d| j        d                                       d          }| j        j        rd |D             S d |D             S )zRetrieve the signatures to document from the directive arguments.

        By default, signatures are given as arguments, one per line.
         r   
c                h    g | ]/}t                               d |                                          0S )z\1)strip_backslash_resubstrip.0lines     r    
<listcomp>z4ObjectDescription.get_signatures.<locals>.<listcomp>c   s1    RRRD&**5$**,,??RRRr"   c                6    g | ]}|                                 S  )rF   rG   s     r    rJ   z4ObjectDescription.get_signatures.<locals>.<listcomp>e   s     333TDJJLL333r"   )nl_escape_rerE   	argumentssplitconfigstrip_signature_backslash)r:   liness     r    get_signaturesz ObjectDescription.get_signatures[   sc    
   T^A%677==dCC;0 	4RRERRRR33U3333r"   sigsignoder   r#   c                    t           )a  Parse the signature *sig*.

        The individual nodes are then appended to *signode*.
        If ValueError is raised, parsing is aborted and the whole
        *sig* is put into a single desc_name node.

        The return value should be a value that identifies the object.  It is
        passed to :meth:`add_target_and_index()` unchanged, and otherwise only
        used to skip duplicates.
        )r   )r:   rT   rU   s      r    handle_signaturez"ObjectDescription.handle_signatureg   s
     r"   r<   Nonec                    dS )zAdd cross-reference IDs and entries to self.indexnode, if applicable.

        *name* is whatever :meth:`handle_signature()` returned.
        NrL   )r:   r<   rT   rU   s       r    add_target_and_indexz&ObjectDescription.add_target_and_indext   	     	r"   c                    dS )zCalled before parsing content.

        Used to set information about the current directive context
        on the build environment.
        NrL   r:   s    r    before_contentz ObjectDescription.before_content}   	     	r"   content_nodeaddnodes.desc_contentc                    dS )zCan be used to manipulate the content.

        Called after creating the content through nested parsing,
        but before the ``object-description-transform`` event is emitted,
        and before the info-fields are transformed.
        NrL   )r:   r`   s     r    transform_contentz#ObjectDescription.transform_content   r[   r"   c                    dS )zCalled after parsing content.

        Used to reset information about the current directive context
        on the build environment.
        NrL   r]   s    r    after_contentzObjectDescription.after_content   r_   r"   sig_nodetuple[str, ...]c                    dS )a  Returns a tuple of strings, one entry for each part of the object's
        hierarchy (e.g. ``('module', 'submodule', 'Class', 'method')``). The
        returned tuple is used to properly nest children within parents in the
        table of contents, and can also be used within the
        :py:meth:`_toc_entry_name` method.

        This method must not be used outwith table of contents generation.
        rL   rL   r:   rf   s     r    _object_hierarchy_partsz)ObjectDescription._object_hierarchy_parts   s	     rr"   c                    dS )a  Returns the text of the table of contents entry for the object.

        This function is called once, in :py:meth:`run`, to set the name for the
        table of contents entry (a special attribute ``_toc_name`` is set on the
        object node, later used in
        ``environment.collectors.toctree.TocTreeCollector.process_doc().build_toc()``
        when the table of contents entries are collected).

        To support table of contents entries for their objects, domains must
        override this method, also respecting the configuration setting
        ``toc_object_entries_show_parents``. Domains must also override
        :py:meth:`_object_hierarchy_parts`, with one (string) entry for each part of the
        object's hierarchy. The result of this method is set on the signature
        node, and can be accessed as ``sig_node['_toc_parts']`` for use within
        this method. The resulting tuple is also used to properly nest children
        within parents in the table of contents.

        An example implementations of this method is within the python domain
        (:meth:`!PyObject._toc_entry_name`). The python domain sets the
        ``_toc_parts`` attribute within the :py:meth:`handle_signature()`
        method.
        rA   rL   ri   s     r    _toc_entry_namez!ObjectDescription._toc_entry_name   s	    . rr"   
list[Node]c                
   d| j         v r)| j                             dd          \  | _        | _        nd| j         c| _        | _        t	          j        g           | _        t	          j                    }| j        j	        |_	        | 
                                \  }}||dz  }| j        j	                            ||           | j        |d<   | j        x|d<   |d<   d	| j        vrd
| j        v r| j        d
         | j        d	<   d| j        vrd| j        v r| j        d         | j        d<   d| j        vrd| j        v r| j        d         | j        d<   d	| j        v x|d	<   x|d
<   }d| j        v x|d<   |d<   d| j        v x|d<   |d<   d| j        v |d<   | j        r |d                             | j                   |d                             |d                    g | _        |                                 }|D ]}t	          j        |d          }|                     |           |                    |           	 |                     ||          }n# t&          $ rv |                                 |t	          j        ||          z  }Y | j        j        r1|                     |          |d<   |                     |          |d<   d|d<   d|d<   w xY w	 | j        j        r1|                     |          |d<   |                     |          |d<   nWd|d<   d|d<   nL# | j        j        r1|                     |          |d<   |                     |          |d<   n
d|d<   d|d<   w xY w|| j        vr3| j                            |           |s|                     |||           | j        re| j        d         }	t7          |	t8                    r%t;          |	d                   | j        j        _         nt;          |	          | j        j        _         | !                                 | "                    d          }
t	          j#        dg|
R  }|                    |           | $                    |           | j        j%        &                    d| j        | j        |           tO          |           (                    |           d| j        j        _         | )                                 |d         rfd |*                    tV          j,                  D             x}r3tW          j-        |          }|                     |           | j        |gS | j        gS | j        |gS )a  Main directive entry function, called by docutils upon encountering the
        directive.

        This directive is meant to be quite easily subclassable, so it delegates
        to several additional methods.  What it does:

        * find out if called as a domain-specific directive, set self.domain
        * create a `desc` node to fit all description inside
        * parse standard options, currently `no-index`
        * create an index node if needed as self.indexnode
        * parse all given signatures (as returned by self.get_signatures())
          using self.handle_signature(), which should either return a name
          or raise ValueError
        * add index entries using self.add_target_and_index()
        * parse the content and handle doc fields in it
        :r&   rA   )entriesNr1   r2   desctyper'   r+   r(   r,   r)   r-   r*   classes
_toc_parts	_toc_namerL   r   T)allow_section_headingsobject-description-transformc                D    g | ]}|                     d d          D ]}|S )idsrL   )get)rH   elnode_ids      r    rJ   z)ObjectDescription.run.<locals>.<listcomp>4  sM       !vveR00      r"   )rx   ).r<   rO   r1   r2   r   indexr3   descstatedocumentget_source_infonote_sourceoptionsappendr7   rS   r   set_source_inforW   r   clear	desc_namerP   toc_object_entriesrj   rl   rZ   
isinstancetupler   envcurrent_documentobj_desc_namer^   parse_content_to_nodesdesc_contentrc   eventsemitr   transform_allre   findallr   Elementtarget)r:   nodesourcerI   no_index
signaturesrT   rU   r<   object_namecontent_childrenr`   node_idstarget_nodes                 r    runzObjectDescription.run   s   " $)(,	Q(?(?%DK(*DI%DK!333}
+++-- AID
''555X-1\9Y$z*
 T\))i4<.G.G'+|I'>DL$4<//Ndl4R4R-1\.-IDL)*t|33!T\1104=N0ODL,-8Bdl8RRZR4	?X8HDL8XXn!54</	
 !D):$; "2T\!A; 	0O""4;///YtI///%'
((**
 	B 	BC -c266G  )))KK   . ,,S'::   8-c3777 ;1 .,0,H,H,Q,QGL)+/+?+?+H+HGK((,.GL)+-GK((  ;1 .,0,H,H,Q,QGL)+/+?+?+H+HGK((,.GL)+-GK(( ;1 .,0,H,H,Q,QGL)+/+?+?+H+HGK((,.GL)+-GK(----4:%%
!!$''' B --dCAAA: 	K$(JqMK+u-- K:=k!n:M:M)77:=k:J:J)766d6SS,RC2BCCCL!!!|,,,*DK|	
 	
 	
 	D!!//===24!/ ! 	$ ,,u}55   x 5
 $lx888$$[11144N##%%s+   :IL6KLKLA	M&)r   r4   )r   r?   )rT   r   rU   r   r   r#   )r<   r#   rT   r   rU   r   r   rX   )r   rX   )r`   ra   r   rX   )rf   r   r   rg   )rf   r   r   r   r   rm   )__name__
__module____qualname____doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer	   flagr/   __annotations__r0   r1   r5   r>   rS   rW   rZ   r^   rc   re   rj   rl   r   rL   r"   r    r%   r%   /   s          K $O$/'_$/?"%?) )K     $&O%%%%FLLL :<;;;;( ( ( (
4 
4 
4 
4               	 	 	 	   2C& C& C& C& C& C&r"   r%   c                  "    e Zd ZdZdZdZddZdS )	DefaultRolezASet the default interpreted text role.  Overridden from docutils.r&   Fr   rm   c                   | j         st          j        d           g S | j         d         }t          j        || j        j        | j        | j        j	                  \  }}|r't          j
        d|           || j        j        _        nQt          j        | j        | j                  }| j        j	        }|                    d|z  || j                  }||gz  }t%          d|          S )NrA   r   z#Unknown interpreted text role "%s".)rI   zlist[nodes.Node])rN   r   unregister_roler
   rolestate_machinelanguagelinenor~   reporterregister_roler   r   default_roler   literal_block
block_texterrorr   )r:   	role_namer   messagesr   r   r   s          r    r   zDefaultRole.runF  s    ~ 	$R(((IN1%	t)2DKAT
 
h  	 "2t,,,5>DH%22!/QQMz*HNN5	A[ #  E
 H&111r"   Nr   )r   r   r   r   r   r   r   rL   r"   r    r   r   @  s:        KK %2 2 2 2 2 2r"   r   c                  :    e Zd ZU dZdZdZdZdZi Zde	d<   dd	Z
d
S )DefaultDomainz>Directive to (re-)set the default domain for this source file.Fr&   r   r.   r/   r   rm   c                    | j         d                                         }| j        j                            |          }|| j        j        _        g S )Nr   )rN   lowerr   domainsry   r   default_domain)r:   domain_namer   s      r    r   zDefaultDomain.rung  sD    nQ'--//)--k::3A!0	r"   Nr   )r   r   r   r   r   r   r   r   r/   r   r   rL   r"   r    r   r   ^  sX         HHK %(*K****     r"   r   appr   r   c                `   |                      dddt          t          h                     t          j        dt
                     t          j        dt                     t          j        dt                     t          j        dt                     |                     d	           d
dddS )NrQ   Fr   )typeszdefault-rolezdefault-domaindescribeobjectrv   builtinT)versionparallel_read_safeparallel_write_safe)	add_config_value	frozensetboolr	   register_directiver   r   r%   	add_event)r   s    r    setupr   n  s    #UED69J9J     !.+>>>!"2MBBB!*.?@@@!(,=>>>MM0111 "#  r"   )r   r   r   r   )r   r   r   r   )*r   
__future__r   retypingr   r   r   r   r   r   docutils.parsers.rstr	   r
   sphinxr   sphinx.utilsphinx.util.docfieldsr   sphinx.util.docutilsr   r   docutils.nodesr   sphinx.addnodesr   sphinx.applicationr   r   r   sphinx.util.typingr   r   compilerM   rD   r!   r#   r%   r   r   r   rL   r"   r    <module>r      s3   . . " " " " " " 				 8 8 8 8 8 8 8 8 8 8 8 8       2 2 2 2 2 2 2 2                   5 5 5 5 5 5 0 0 0 0 0 0 A######......))))))77777777@@@@@@@@ rz'""RZ)) 	 	 	 	 7:N& N& N& N& N&): N& N& N&b2 2 2 2 2/ 2 2 2<    O         r"   