
    Ri0                       d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 erLddlmZmZmZ ddl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 ddlmZ ddl m!Z! ddl"m#Z#m$Z$ dZ% G d d      Z& G d d      Z'y)zSupport for domains.

Domains are groupings of description directives
and roles describing e.g. constructs of one programming language.
    )annotationsN)TYPE_CHECKING)Index
IndexEntry)_)IterableSequenceSet)AnyClassVar)nodes)ElementNode)	Directive)Inliner)pending_xref)Builder)BuildEnvironment)XRefRole)RoleFunctionTitleGetter)Domainr   r   ObjTypec                       e Zd ZdZddiZddZy)r   a.  An ObjType is the description for a type of object that a domain can
    document.  In the object_types attribute of Domain subclasses, object type
    names are mapped to instances of this class.

    Constructor arguments:

    - *lname*: localized name of the type (do not include domain name)
    - *roles*: all the roles that can refer to an object of this type
    - *attrs*: object attributes -- currently only "searchprio" is known,
      which defines the object's priority in the full-text search index,
      see :meth:`Domain.get_objects()`.
    
searchprio   c               H    || _         || _        | j                  |z  | _        y N)lnamerolesknown_attrsattrs)selfr   r    r"   s       O/home/agent/.friday_env/lib/python3.12/site-packages/sphinx/domains/__init__.py__init__zObjType.__init__8   s"    
&+
%)%5%5%=
    N)r   strr    r   r"   r   returnNone)__name__
__module____qualname____doc__r!   r%    r&   r$   r   r   &   s     	aK>r&   r   c                  v   e Zd ZU dZdZded<   dZded<   i Zded<   i Zded	<   i Z	d
ed<   g Z
ded<   i Zded<   i Zded<   i Zded<   ded<   dZded<   d*dZd+dZd,dZd-dZd.dZd/dZd0dZ	 	 	 	 	 	 	 	 d1d Zd+d!Zd2d"Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3d#Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d$Zd5d%Zd6d7d&Zd8d'Zd9d(Zy)):r   a  A Domain is meant to be a group of "object" description directives for
    objects of a similar nature, and corresponding roles to create references to
    them.  Examples would be Python modules, classes, functions etc., elements
    of a templating language, Sphinx roles and directives, etc.

    Each domain has a separate storage for information about existing objects
    and how to reference them in `self.data`, which must be a dictionary.  It
    also must implement several functions that expose the object information in
    a uniform way to parts of Sphinx that allow the user to reference or search
    for objects in a domain-agnostic way.

    About `self.data`: since all object and cross-referencing information is
    stored on a BuildEnvironment instance, the `domain.data` object is also
    stored in the `env.domaindata` dict under the key `domain.name`.  Before the
    build process starts, every active domain is instantiated and given the
    environment object; the `domaindata` dict must then either be nonexistent or
    a dictionary whose 'version' key is equal to the domain class'
    :attr:`data_version` attribute.  Otherwise, `OSError` is raised and the
    pickled environment is discarded.
     zClassVar[str]namelabelzClassVar[dict[str, ObjType]]object_typesz$ClassVar[dict[str, type[Directive]]]
directivesz,ClassVar[dict[str, RoleFunction | XRefRole]]r    zClassVar[list[type[Index]]]indiceszClassVar[dict[str, str]]dangling_warningsz:ClassVar[dict[type[Node], tuple[str, TitleGetter | None]]]enumerable_nodeszClassVar[dict[str, Any]]initial_datadict[str, Any]datar   zClassVar[int]data_versionc                   |j                   }|| _        i | _        i | _        i | _        i | _        t        | j                        | _        t        | j                        | _        t        | j                        | _	        t        | j                        | _        | j                  |vrat        | j                  t              sJ t        j                   | j                        }| j"                  |d<   |x| _        || j                  <   nH|| j                     | _        | j$                  d   | j"                  k7  rt'        d| j(                  z        | j                  j+                         D ]k  \  }}|j                  D ]-  }| j                  j-                  |g       j/                  |       / |j                  r|j                  d   nd| j
                  |<   m | j                  j0                  | _        | j
                  j0                  | _        y )Nversionzdata of %r domain out of dater   r0   )
domaindataenv_role_cache_directive_cache
_role2type
_type2roledictr3   r4   r    listr5   r1   
isinstancer8   copydeepcopyr;   r:   OSErrorr2   items
setdefaultappendgetobjtypes_for_rolerole_for_objtype)r#   r?   domain_datanew_datar1   objrolenames          r$   r%   zDomain.__init__k   s   14%(46<>02*, !!2!23t/$**%
DLL)99K'd//666}}T%6%67H"&"3"3HY199DIDII.#DII.DIyy#t'8'88=

JKK**002 	FID#II F**8R8??EF47IICIIaL2DOOD!	F "&!4!4 $ 3 3r&   c                   | j                   j                  j                  }| j                  D ]U  }|j                  s|j
                  s| j                   d|j                   }|j                  ||d|j
                         W y)zSet up domain object.-r0   N)r?   domainsstandard_domainr5   r1   	localnamenote_hyperlink_target)r#   stdindexdocnames       r$   setupzDomain.setup   sk     hh..\\ 	QEzzeoo!YYKq5))'7BP	Qr&   c                
   || j                   |<   |j                  r|j                  d   | j                  |<   nd| j                  |<   |j                  D ]-  }| j                  j	                  |g       j                  |       / y)zAdd an object type.r   r0   N)r3   r    rC   rB   rK   rL   )r#   r1   objtyperoles       r$   add_object_typezDomain.add_object_type   sp    ")$==$+MM!$4DOOD!$&DOOD!MM 	>DOO&&tR077=	>r&   c                      j                   v r j                      S  j                  vry j                   d 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd}| j                   <   |S )zReturn a role adapter function that always gives the registered
        role its full name ('domain:name') as the first argument.
        N:c           	     B     	j                      |||||xs i |      S r   )r    )
typrawtexttextlinenoinlineroptionscontentfullnamer1   r#   s
          r$   role_adapterz!Domain.role.<locals>.role_adapter   s0     $4::d#'4'-R r&   )Nr.   )re   r'   rf   r'   rg   r'   rh   intri   r   rj   zdict[str, Any] | Nonerk   zSequence[str]r(   z-tuple[list[Node], list[nodes.system_message]])r@   r    r1   )r#   r1   rm   rl   s   `` @r$   r`   zDomain.role   s     4#####D))tzz!ii[$( .2%'			 	 		
 	 +	 #	 ;	 ".r&   c                    || j                   v r| j                   |   S || j                  vry| j                   d| | j                  |   } G fdd|      }|| j                   |<   |S )zReturn a directive adapter class that always gives the registered
        directive its full name ('domain:name') as ``self.name``.
        Nrc   c                  $     e Zd Zd fdZ xZS )*Domain.directive.<locals>.DirectiveAdapterc                .    | _         t        | 	         S r   )r1   superrun)r#   	__class__rl   s    r$   rt   z.Domain.directive.<locals>.DirectiveAdapter.run   s    $	w{}$r&   )r(   z
list[Node])r*   r+   r,   rt   __classcell__)ru   rl   s   @r$   DirectiveAdapterrq      s    % %r&   rw   )rA   r4   r1   )r#   r1   BaseDirectiverw   rl   s       @r$   	directivezDomain.directive   sy     4(((((..t&ii[$(-	%} 	%
 '7d#r&   c                     y)z?Remove traces of a document in the domain-specific inventories.Nr.   )r#   r\   s     r$   	clear_doczDomain.clear_doc       r&   c                8    d| j                    d}t        |      )zMerge in data regarding *docnames* from a different domaindata
        inventory (coming from a subprocess in parallel builds).
        z(merge_domaindata must be implemented in z" to be able to do parallel builds!)ru   NotImplementedError)r#   docnames	otherdatamsgs       r$   merge_domaindatazDomain.merge_domaindata   s-    
 7t~~6F G0 0 	 "#&&r&   c                     y)z7Process a document after it is read by the environment.Nr.   )r#   r?   r\   documents       r$   process_doczDomain.process_doc        	r&   c                     y)z)Do consistency checks (**experimental**).Nr.   r#   s    r$   check_consistencyzDomain.check_consistency   r|   r&   c                     y)zxProcess a pending xref created in a doc field.
        For example, attach information about the current scope.
        Nr.   )r#   pnodes     r$   process_field_xrefzDomain.process_field_xref   r   r&   c                     y)aL  Resolve the pending_xref *node* with the given *typ* and *target*.

        This method should return a new node, to replace the xref node,
        containing the *contnode* which is the markup content of the
        cross-reference.

        If no resolution can be found, None can be returned; the xref node will
        then given to the :event:`missing-reference` event, and if that yields no
        resolution, replaced by *contnode*.

        The method can also raise :exc:`sphinx.environment.NoUri` to suppress
        the :event:`missing-reference` event being emitted.
        Nr.   )r#   r?   fromdocnamebuilderre   targetnodecontnodes           r$   resolve_xrefzDomain.resolve_xref   s    . 	r&   c                    t         )a9  Resolve the pending_xref *node* with the given *target*.

        The reference comes from an "any" or similar role, which means that we
        don't know the type.  Otherwise, the arguments are the same as for
        :meth:`resolve_xref`.

        The method must return a list (potentially empty) of tuples
        ``('domain:role', newnode)``, where ``'domain:role'`` is the name of a
        role that could have created the same reference, e.g. ``'py:func'``.
        ``newnode`` is what :meth:`resolve_xref` would return.

        .. versionadded:: 1.3
        )r~   )r#   r?   r   r   r   r   r   s          r$   resolve_any_xrefzDomain.resolve_any_xref  s
    , "!r&   c                    g S )au  Return an iterable of "object descriptions".

        Object descriptions are tuples with six items:

        ``name``
          Fully qualified name.

        ``dispname``
          Name to display when searching/linking.

        ``type``
          Object type, a key in ``self.object_types``.

        ``docname``
          The document where it is to be found.

        ``anchor``
          The anchor name for the object.

        ``priority``
          How "important" the object is (determines placement in search
          results). One of:

          ``1``
            Default priority (placed before full-text matches).
          ``0``
            Object is important (placed before default-priority objects).
          ``2``
            Object is unimportant (placed after full-text matches).
          ``-1``
            Object should not show up in search at all.
        r.   r   s    r$   get_objectszDomain.get_objects  s
    B 	r&   c                f    |r|j                   S t        d      | j                  |j                   fz  S )z#Return full name for given ObjType.z%s %s)r   r   r2   )r#   typeprimarys      r$   get_type_namezDomain.get_type_name>  s+    ::zTZZ444r&   c                X    | j                   j                  |j                  d      \  }}|S )z,Get type of enumerable nodes (experimental).)NN)r7   rM   ru   )r#   r   enum_node_typer   s       r$   get_enumerable_node_typezDomain.get_enumerable_node_typeD  s)     1155dnnlSr&   c                     y)z*Return full qualified name for given node.Nr.   )r#   r   s     r$   get_full_qualified_namezDomain.get_full_qualified_nameI  r|   r&   N)r?   r   r(   r)   )r(   r)   )r1   r'   r_   r   r(   r)   )r1   r'   r(   zRoleFunction | None)r1   r'   r(   ztype[Directive] | None)r\   r'   r(   r)   )r   zSet[str]r   r9   r(   r)   )r?   r   r\   r'   r   znodes.documentr(   r)   )r   r   r(   r)   )r?   r   r   r'   r   r   re   r'   r   r'   r   r   r   r   r(   znodes.reference | None)r?   r   r   r'   r   r   r   r'   r   r   r   r   r(   z!list[tuple[str, nodes.reference]])r(   z-Iterable[tuple[str, str, str, str, str, int]])F)r   r   r   boolr(   r'   )r   r   r(   
str | None)r   r   r(   r   )r*   r+   r,   r-   r1   __annotations__r2   r3   r4   r    r5   r6   r7   r8   r;   r%   r]   ra   r`   ry   r{   r   r   r   r   r   r   r   r   r   r   r.   r&   r$   r   r   >   s   , D-E=13L.379J49:<E7<+-G(-24/4SUPU-/L*/
"#L-#4<Q	>4 *'#.1=K	  	
     
 2"" " 	"
 " " " 
+"0!F5
r&   r   )(r-   
__future__r   rG   typingr   sphinx.domains._indexr   r   sphinx.localer   collections.abcr   r	   r
   r   r   docutilsr   docutils.nodesr   r   docutils.parsers.rstr   docutils.parsers.rst.statesr   sphinx.addnodesr   sphinx.buildersr   sphinx.environmentr   sphinx.rolesr   sphinx.util.typingr   r   __all__r   r   r.   r&   r$   <module>r      s_    #    3 77$,.3,'3%<> >0M Mr&   