o
    NiS/                     @  s   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rnddlmZmZmZmZ ddl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 dZ&G dd dZ'dS )zSupport for domains.

Domains are groupings of description directives
and roles describing e.g. constructs of one programming language.
    )annotationsN)TYPE_CHECKING)Index
IndexEntry)_)CallableIterableSequenceSet)Any)nodes)ElementNode)	Directive)Inliner)pending_xref)Builder)BuildEnvironment)XRefRole)RoleFunctionTitleGetter)Domainr   r   ObjTypec                   @  s"   e Zd ZdZddiZdddZdS )r   a3  
    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   lnamestrrolesr   attrsreturnNonec                O  s   || _ || _| j|B | _d S N)r   r   known_attrsr   )selfr   r   r    r$   K/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/domains/__init__.py__init__9   s   zObjType.__init__N)r   r   r   r   r   r   r   r    )__name__
__module____qualname____doc__r"   r&   r$   r$   r$   r%   r   &   s
    r   c                   @  s  e Zd ZU dZdZdZ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dXddZdYddZdZd d!Zd[d#d$Zd\d&d'Zd]d)d*Zd^d.d/Zd_d2d3ZdYd4d5Zd`d8d9ZdadCdDZdbdFdGZdcdIdJZdddedOdPZdfdSdTZdgdUdVZdWS )hr   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dict[str, ObjType]object_typeszdict[str, type[Directive]]
directivesz"dict[str, RoleFunction | XRefRole]r   zlist[type[Index]]indiceszdict[str, str]dangling_warningsz0dict[type[Node], tuple[str, TitleGetter | None]]enumerable_nodesdictinitial_datadict[str, Any]datar   envr   r   r    c                 C  s&  || _ i | _i | _i | _i | _t| j| _t| j| _t| j| _t	| j
| _
| j|jvrJt| jts5J t| j}| j|d< | | _|j| j< n|j| j | _| jd | jkr`td| j | j D ]!\}}|jD ]}| j|g | ql|jr|jd nd| j|< qe| jj| _| jj| _d S )Nversionzdata of %r domain out of dater   r+   )r5   _role_cache_directive_cache
_role2type
_type2roler1   r,   r-   r   listr.   name
domaindata
isinstancer2   copydeepcopydata_versionr4   OSErrorlabelitems
setdefaultappendgetobjtypes_for_rolerole_for_objtype)r#   r5   new_datar<   objrolenamer$   r$   r%   r&   m   s.   


zDomain.__init__c                 C  sJ   | j jj}| jD ]}|jr"|jr"| j d|j }|||d|j qdS )zSet up domain object.-r+   N)r5   domainsstandard_domainr.   r<   	localnamenote_hyperlink_target)r#   stdindexdocnamer$   r$   r%   setup   s   

zDomain.setupr<   r   objtyper   c                 C  sP   || j |< |jr|jd | j|< nd| j|< |jD ]}| j|g | qdS )zAdd an object type.r   r+   N)r,   r   r:   r9   rE   rF   )r#   r<   rV   roler$   r$   r%   add_object_type   s   


zDomain.add_object_typeRoleFunction | Nonec                   sX   j v r
j  S jvrdS j d  		dd fdd}|j < |S )zReturn a role adapter function that always gives the registered
        role its full name ('domain:name') as the first argument.
        N:r$   typr   rawtexttextlinenointinlinerr   optionsdict | NonecontentSequence[str]r   -tuple[list[Node], list[nodes.system_message]]c                   s   j   |||||pi |S r!   )r   )r[   r\   r]   r^   r`   ra   rc   fullnamer<   r#   r$   r%   role_adapter   s   
z!Domain.role.<locals>.role_adapter)Nr$   )r[   r   r\   r   r]   r   r^   r_   r`   r   ra   rb   rc   rd   r   re   )r7   r   r<   )r#   r<   rh   r$   rf   r%   rW      s   



zDomain.roleCallable | Nonec                   s^   || j v r
| j | S || jvrdS | j d|  | j| }G  fddd|}|| j |< |S )zReturn a directive adapter class that always gives the registered
        directive its full name ('domain:name') as ``self.name``.
        NrZ   c                      s    e Zd Zd fddZ  ZS )z*Domain.directive.<locals>.DirectiveAdapterr   
list[Node]c                   s   | _ t  S r!   )r<   superrunr#   )	__class__rg   r$   r%   rl      s   
z.Domain.directive.<locals>.DirectiveAdapter.run)r   rj   )r'   r(   r)   rl   __classcell__r$   rg   )rn   r%   DirectiveAdapter   s    rq   )r8   r-   r<   )r#   r<   BaseDirectiverq   r$   rp   r%   	directive   s   




zDomain.directiverT   c                 C     dS )z?Remove traces of a document in the domain-specific inventories.Nr$   )r#   rT   r$   r$   r%   	clear_doc      zDomain.clear_docdocnamesSet[str]	otherdatac                 C  s   t d| j )zMerge in data regarding *docnames* from a different domaindata
        inventory (coming from a subprocess in parallel builds).
        zLmerge_domaindata must be implemented in %s to be able to do parallel builds!)NotImplementedErrorrn   )r#   rw   ry   r$   r$   r%   merge_domaindata   s   zDomain.merge_domaindatadocumentnodes.documentc                 C  rt   )z7Process a document after it is read by the environment.Nr$   )r#   r5   rT   r|   r$   r$   r%   process_doc   s   zDomain.process_docc                 C  rt   )z)Do consistency checks (**experimental**).Nr$   rm   r$   r$   r%   check_consistency   rv   zDomain.check_consistencypnoder   c                 C  rt   )zxProcess a pending xref created in a doc field.
        For example, attach information about the current scope.
        Nr$   )r#   r   r$   r$   r%   process_field_xref   s   zDomain.process_field_xreffromdocnamebuilderr   r[   targetnodecontnoder   Element | Nonec                 C  rt   )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#   r5   r   r   r[   r   r   r   r$   r$   r%   resolve_xref      zDomain.resolve_xreflist[tuple[str, Element]]c                 C  s   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
        )rz   )r#   r5   r   r   r   r   r   r$   r$   r%   resolve_any_xref   r   zDomain.resolve_any_xref-Iterable[tuple[str, str, str, str, str, int]]c                 C  s   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$   rm   r$   r$   r%   get_objects  s   !zDomain.get_objectsFtypeprimaryboolc                 C  s   |r|j S td| j|j f S )z#Return full name for given ObjType.z%s %s)r   r   rC   )r#   r   r   r$   r$   r%   get_type_name'  s   zDomain.get_type_namer   
str | Nonec                 C  s   | j |jd\}}|S )z,Get type of enumerable nodes (experimental).)NN)r0   rG   rn   )r#   r   enum_node_typer   r$   r$   r%   get_enumerable_node_type-  s   zDomain.get_enumerable_node_typec                 C  rt   )z*Return full qualified name for given node.Nr$   )r#   r   r$   r$   r%   get_full_qualified_name2  rv   zDomain.get_full_qualified_nameN)r5   r   r   r    )r   r    )r<   r   rV   r   r   r    )r<   r   r   rY   )r<   r   r   ri   )rT   r   r   r    )rw   rx   ry   r3   r   r    )r5   r   rT   r   r|   r}   r   r    )r   r   r   r    )r5   r   r   r   r   r   r[   r   r   r   r   r   r   r   r   r   )r5   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )F)r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r'   r(   r)   r*   r<   rC   r,   __annotations__r-   r   r.   r/   r0   r2   rA   r&   rU   rX   rW   rs   ru   r{   r~   r   r   r   r   r   r   r   r   r$   r$   r$   r%   r   ?   s:   
 


	









#
r   )(r*   
__future__r   r?   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$   r%   <module>   s*    