
    $gP                       d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZ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!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z) ej*        dk     rddl+m,Z, nddl-m,Z, erddlm.Z. e	Z/ G d de0          Z1 G d de0          Z2d!d"dZ3 G d d          Z4 G d d           Z5dS )#z\Base module for handlers.

This module contains the base classes for implementing handlers.
    )annotationsN)Path)
TYPE_CHECKINGAnyBinaryIOClassVarIterableIteratorMappingMutableMappingSequencecast)Elementtostring)EnvironmentFileSystemLoader)Markdown)TocTreeprocessor)Markup)AutorefsInlineProcessor)HeadingShiftingTreeprocessorHighlighterIdPrependingTreeprocessorMkdocstringsInnerExtensionParagraphStrippingTreeprocessor)	Inventory)get_template_logger)   
   entry_points)AutorefsHookInterfacec                      e Zd ZdZdS )CollectionErrorz8An exception raised when some collection of data failed.N__name__
__module____qualname____doc__     Z/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/mkdocstrings/handlers/base.pyr$   r$   *   s        BBBBr+   r$   c                      e Zd ZdZdS )ThemeNotSupportedz5An exception raised to tell a theme is not supported.Nr%   r*   r+   r,   r.   r.   .   s        ????r+   r.   seqr   	attribute
str | Nonereturnboolc                \    t          |           S t          fd| D                       S )aX  Check if at least one of the item in the sequence evaluates to true.

    The `any` builtin as a filter for Jinja templates.

    Arguments:
        seq: An iterable object.
        attribute: The attribute name to use on each object of the iterable.

    Returns:
        A boolean telling if any object of the iterable evaluated to True.
    Nc              3  (   K   | ]}|         V  d S Nr*   ).0_r0   s     r,   	<genexpr>zdo_any.<locals>.<genexpr>@   s'      ))q|))))))r+   )any)r/   r0   s    `r,   do_anyr;   2   s9     3xx))))S))))))r+   c                      e Zd ZU dZdZded<   	 dZded<   	 dZded	<   	 i Zd
ed<   	 dZ	ded<   	 dZ
	 dDdEdZe	 dDdFd            ZdGd!ZdHd$ZdId%ZdDdJd'ZdKd)ZdLd+Z	 dMddd,dNd5Zdddd6dOd<ZdPd>ZdQdBZdQdCZdS )RBaseHandlera  The base handler class.

    Inherit from this class to implement a handler.

    You will have to implement the `collect` and `render` methods.
    You can also implement the `teardown` method,
    and  override the `update_env` method, to add more filters to the Jinja environment,
    making them available in your Jinja templates.

    To define a fallback theme, add a `fallback_theme` class-variable.
    To add custom CSS, add an `extra_css` variable or create an 'style.css' file beside the templates.
     strnamedefaultdomainFr3   enable_inventoryzClassVar[dict]fallback_configfallback_themeNhandlerthemecustom_templatesr1   r2   Nonec                   g }|                      |          }|                    ||z             |                     |          }|D ]}|                    ||z             | j        rJ| j        |k    r?|                    || j        z             |D ]}|                    || j        z              |D ]D}|dz  }	|	                                r)| xj        d|	                    d          z   z  c_         nE|)|                    dt          |          |z  |z             t          dt          |          d	          | _        t          | j        j        d
<   t          | j                  | j        j        d<   g | _        d| _        dS )aq  Initialize the object.

        If the given theme is not supported (it does not exist), it will look for a `fallback_theme` attribute
        in `self` to use as a fallback theme.

        Arguments:
            handler: The name of the handler.
            theme: The name of theme to use.
            custom_templates: Directory containing custom templates.
        z	style.css
zutf-8encodingNr   TF)
autoescapeloaderauto_reloadr:   log)get_templates_dirappendget_extended_templates_dirsrE   is_file	extra_css	read_textinsertr   r   r   envr;   filtersr   r@   globals	_headings_md)
selfrF   rG   rH   paths
themes_dirextended_templates_dirstemplates_dirpathcss_paths
             r,   __init__zBaseHandler.__init___   s     ++G44
Z%'((( #'"B"B7"K"K4 	0 	0MLL.////  	B4#6%#?#?LLd&99::: "9 B B]T-@@AAAA 	 	Dk)H!! $););W);)M)M"MM 'LLD!122W<uDEEE#E**
 
 

 #)"5di"@"@(*!r+   in_filer   urlbase_urlkwargsr   Iterator[tuple[str, str]]c              +     K   dE d{V  dS )a  Yield items and their URLs from an inventory file streamed from `in_file`.

        Arguments:
            in_file: The binary file-like object to read the inventory from.
            url: The URL that this file is being streamed from (used to guess `base_url`).
            base_url: The URL that this inventory's sub-paths are relative to.
            **kwargs: Ignore additional arguments passed from the config.

        Yields:
            Tuples of (item identifier, item URL).
        r*   Nr*   )clsrf   rg   rh   ri   s        r,   load_inventoryzBaseHandler.load_inventory   s      & r+   
identifierconfigMutableMapping[str, Any]CollectorItemc                    t           )a  Collect data given an identifier and user configuration.

        In the implementation, you typically call a subprocess that returns JSON, and load that JSON again into
        a Python dictionary for example, though the implementation is completely free.

        Arguments:
            identifier: An identifier for which to collect data. For example, in Python,
                it would be 'mkdocstrings.handlers' to collect documentation about the handlers module.
                It can be anything that you can feed to the tool of your choice.
            config: The handler's configuration options.

        Returns:
            Anything you want, as long as you can feed it to the handler's `render` method.
        NotImplementedError)r^   rn   ro   s      r,   collectzBaseHandler.collect   s
     "!r+   dataMapping[str, Any]c                    t           )a  Render a template using provided data and configuration options.

        Arguments:
            data: The collected data to render.
            config: The handler's configuration options.

        Returns:
            The rendered template as HTML.
        rs   )r^   rv   ro   s      r,   renderzBaseHandler.render   s
     "!r+   c                    dS )zTeardown the handler.

        This method should be implemented to, for example, terminate a subprocess
        that was started when creating the handler instance.
        Nr*   r^   s    r,   teardownzBaseHandler.teardown   s      r+   r   c                    |p| j         }	 ddl}n&# t          $ r}t          d| d          |d}~ww xY w|j        D ]+}t	          ||d          }|                                r|c S ,t          d| d          )a  Return the path to the handler's templates directory.

        Override to customize how the templates directory is found.

        Arguments:
            handler: The name of the handler to get the templates directory of.

        Raises:
            ModuleNotFoundError: When no such handler is installed.
            FileNotFoundError: When the templates directory cannot be found.

        Returns:
            The templates directory path.
        r   Nz	Handler 'z' not found, is it installed?	templatesz+Can't find 'templates' folder for handler '')r@   mkdocstrings_handlersModuleNotFoundError__path__r   existsFileNotFoundError)r^   rF   r   errorrc   
theme_paths         r,   rR   zBaseHandler.get_templates_dir   s     &TY	e(((((" 	e 	e 	e%&X'&X&X&XYY_dd	e *2 	" 	"DdG[99J  "" "!!!!"   Xg X X XYYYs    
3.3
list[Path]c                B    t          d| d          }d |D             S )a  Load template extensions for the given handler, return their templates directories.

        Arguments:
            handler: The name of the handler to get the extended templates directory of.

        Returns:
            The extensions templates directories.
        zmkdocstrings.z
.templates)groupc                F    g | ]} |                                             S r*   )load)r7   	extensions     r,   
<listcomp>z;BaseHandler.get_extended_templates_dirs.<locals>.<listcomp>   s+    JJJy 	  ""JJJr+   r    )r^   rF   discovered_extensionss      r,   rT   z'BaseHandler.get_extended_templates_dirs   s6     !-3V73V3V3V W W WJJ4IJJJJr+   tuple[str, ...]c                    dS )zReturn the possible identifiers (HTML anchors) for a collected item.

        Arguments:
            data: The collected data.

        Returns:
            The HTML anchors (without '#'), or an empty tuple if this item doesn't have an anchor.
        r*   r*   )r^   rv   s     r,   get_anchorszBaseHandler.get_anchors   s	     rr+   )strip_paragraphautoref_hooktextheading_levelinthtml_idr   r   AutorefsHookInterface | Noner   c               J   | j         j        }||t          j                 _        |o|dz   |t
          j                 _        ||t          j                 _        |r!|| j         j	        t          j                 _        	 t          | j                             |                    d|t          j                 _        d|t
          j                 _        d|t          j                 _        d| j         j	        t          j                 _        | j                                          S # d|t          j                 _        d|t
          j                 _        d|t          j                 _        d| j         j	        t          j                 _        | j                                          w xY w)a  Render Markdown text; for use inside templates.

        Arguments:
            text: The text to convert.
            heading_level: The base heading level to start all Markdown headings from.
            html_id: The HTML id of the element that's considered the parent of this element.
            strip_paragraph: Whether to exclude the <p> tag from around the whole output.

        Returns:
            An HTML string.
        z--r   r>   FN)r]   treeprocessorsr   r@   shift_byr   	id_prefixr   stripinlinePatternsr   hookr   convertreset)r^   r   r   r   r   r   r   s          r,   do_convert_markdownzBaseHandler.do_convert_markdown   sN   ( 0ER389BCJC]wY]~056@ET6;<B 	VIUDH#$;$@AF	$(**40011IJN7<=FGIN49:DINN:?@FIMDH#$;$@AFHNN	 JKN7<=FGIN49:DINN:?@FIMDH#$;$@AFHNNs   ;&D! !BF")rolehidden	toc_labelcontentr   r   r   
attributesc               ^   t          d| |          }|+t          |t                    r|                                n|}|                    d|           |r|                    d|           | j                            |           |r(t          d                              |d                   S t          d| |          }|                    t          d                     t          t          | j
        j        d                   }|j        r|                    ||d                    |j        r|                    ||d                    t!          |d	
          }	|	                    d          dk    sJ d|	            |	                    d|          }
t          |
          S )af  Render an HTML heading and register it for the table of contents. For use inside templates.

        Arguments:
            content: The HTML within the heading.
            heading_level: The level of heading (e.g. 3 -> `h3`).
            role: An optional role for the object bound to this heading.
            hidden: If True, only register it for the table of contents, don't render anything.
            toc_label: The title to use in the table of contents ('data-toc-label' attribute).
            **attributes: Any extra HTML attributes of the heading.

        Returns:
            An HTML string.
        hNzdata-toc-labelz	data-rolez<a id="{0}"></a>idzmkdocstrings-placeholdertocunicoderL   z<mkdocstrings-placeholder />   z*Bug in mkdocstrings: failed to replace in )r   
isinstancer   unescapesetr\   rS   formatr   r   r]   r   use_anchors
add_anchoruse_permalinksadd_permalinkr   countreplace)r^   r   r   r   r   r   r   elr   html_with_placeholderhtmls              r,   
do_headingzBaseHandler.do_heading"  s   B (((*55.8&.I.IV((***wI
+++ 	&FF;%%%b!!! 	G,--44Z5EFFF (((*55
		'455666#TX%<U%CDD? 	1NN2z$/000 	4b*T"2333
 !)i @ @ @!''(FGG1LLLQ8MQQ MLL$,,-KWUUd||r+   Sequence[Element]c                `    t          | j                  }| j                                         |S )znReturn and clear the headings gathered so far.

        Returns:
            A list of HTML elements.
        )listr\   clear)r^   results     r,   get_headingszBaseHandler.get_headingsc  s,     dn%%r+   mdr   dictc                    || _         t          |          j        | j        j        d<   | j        | j        j        d<   | j        | j        j        d<   dS )a  Update the Jinja environment.

        Arguments:
            md: The Markdown instance. Useful to add functions able to convert Markdown into the environment filters.
            config: Configuration options for `mkdocs` and `mkdocstrings`, read from `mkdocs.yml`. See the source code
                of [mkdocstrings.plugin.MkdocstringsPlugin.on_config][] to see what's in this dictionary.
        	highlightconvert_markdownheadingN)r]   r   r   rY   rZ   r   r   )r^   r   ro   s      r,   
update_envzBaseHandler.update_envm  sM     (3B(A%/3/G+,&*o###r+   c                    |d         t          | j                  gz   }t          ||d                   }d|j        v r(|j                            |j        d         dd           |                     ||           dS )zgUpdate our handler to point to our configured Markdown instance, grabbing some of the config from `md`.mdxmdx_configs)
extensionsextension_configsrelpathr   )priorityN)r   r\   r   r   registerr   )r^   r   ro   r   new_mds        r,   _update_envzBaseHandler._update_envz  s    E]&@&P&P%QQ
Z6-CXYYY)))!**2+<Y+G]^*___'''''r+   r6   )rF   r?   rG   r?   rH   r1   r2   rI   )
rf   r   rg   r?   rh   r1   ri   r   r2   rj   )rn   r?   ro   rp   r2   rq   )rv   rq   ro   rw   r2   r?   r2   rI   )rF   r1   r2   r   )rF   r?   r2   r   )rv   rq   r2   r   )r>   )r   r?   r   r   r   r?   r   r3   r   r   r2   r   )r   r   r   r   r   r1   r   r3   r   r1   r   r?   r2   r   )r2   r   )r   r   ro   r   r2   rI   )r&   r'   r(   r)   r@   __annotations__rB   rC   rD   rE   rV   re   classmethodrm   ru   ry   r|   rR   rT   r   r   r   r   r   r   r*   r+   r,   r=   r=   C   s          DNNNN3F\"""""4&(O((((HNTI0" 0" 0" 0" 0"d 
  $	    [(" " " ""
" 
" 
" 
"   Z Z Z Z Z8
K 
K 
K 
K	 	 	 	 	# !&59# # # # # #T   $? ? ? ? ? ?B   6 6 6 6	( 	( 	( 	( 	( 	(r+   r=   c                  \    e Zd ZdZddZdd
ZddZddZdddZe	dd            Z
ddZdS )Handlersa  A collection of handlers.

    Do not instantiate this directly. [The plugin][mkdocstrings.plugin.MkdocstringsPlugin] will keep one instance of
    this for the purpose of caching. Use [mkdocstrings.plugin.MkdocstringsPlugin.get_handler][] for convenient access.
    ro   r   r2   rI   c                n    || _         i | _        t          | j         d         d                   | _        dS )a  Initialize the object.

        Arguments:
            config: Configuration options for `mkdocs` and `mkdocstrings`, read from `mkdocs.yml`. See the source code
                of [mkdocstrings.plugin.MkdocstringsPlugin.on_config][] to see what's in this dictionary.
        mkdocs	site_name)projectN)_config	_handlersr   	inventory)r^   ro   s     r,   re   zHandlers.__init__  s4     13$-dl86L[6Y$Z$Z$Zr+   rn   r?   r   c                    | j                                         D ]T}t          |di           }	 |                    |                    ||                    }n# t
          $ r Y Jw xY w|r|c S UdS )a  Return the canonical HTML anchor for the identifier, if any of the seen handlers can collect it.

        Arguments:
            identifier: The identifier (one that [collect][mkdocstrings.handlers.base.BaseHandler.collect] can accept).

        Returns:
            A tuple of strings - anchors without '#', or an empty tuple if there isn't any identifier familiar with it.
        rD   r*   )r   valuesgetattrr   ru   r$   )r^   rn   rF   rD   anchorss        r,   r   zHandlers.get_anchors  s     ~,,.. 	 	G%g/@"EEO!--gooj/.Z.Z[["    rs   )A
A%$A%c                D    | j         d         }d|v r|d         S |d         S )a-  Return the handler name defined in an "autodoc" instruction YAML configuration, or the global default handler.

        Arguments:
            config: A configuration dictionary, obtained from YAML below the "autodoc" instruction.

        Returns:
            The name of the handler to use.
        mkdocstringsrF   default_handler)r   )r^   ro   global_configs      r,   get_handler_namezHandlers.get_handler_name  s2     ^4)$$.//r+   r@   c                x    | j         d                             di           }|r|                    |i           S i S )a  Return the global configuration of the given handler.

        Arguments:
            name: The name of the handler to get the global configuration of.

        Returns:
            The global configuration of the given handler. It can be an empty dictionary.
        r   handlers)r   get)r^   r@   r   s      r,   get_handler_configzHandlers.get_handler_config  sA     </33JCC 	*<<b)))	r+   Nhandler_configdict | Noner=   c                J   || j         vr||                     |          }|                    | j                   t	          j        d|           } |j        d	| j        d         | j        d         d         | j        d         d         d|| j         |<   | j         |         S )
a)  Get a handler thanks to its name.

        This function dynamically imports a module named "mkdocstrings.handlers.NAME", calls its
        `get_handler` method to get an instance of a handler, and caches it in dictionary.
        It means that during one run (for each reload when serving, or once when building),
        a handler is instantiated only once, and reused for each "autodoc" instruction asking for it.

        Arguments:
            name: The name of the handler. Really, it's the name of the Python module holding it.
            handler_config: Configuration passed to the handler.

        Returns:
            An instance of a subclass of [`BaseHandler`][mkdocstrings.handlers.base.BaseHandler],
                as instantiated by the `get_handler` method of the handler's module.
        Nzmkdocstrings_handlers.
theme_namer   rH   r   config_file_path)rG   rH   r   r*   )r   r   updater   	importlibimport_moduleget_handler)r^   r@   r   modules       r,   r   zHandlers.get_handler  s      t~%%%!%!8!8!>!>!!$,///,-Ld-L-LMMF#56#5 $l<0!%n!=>P!Q!%h!78J!K$ $ !	$ $DN4  ~d##r+   Iterable[BaseHandler]c                4    | j                                         S )zGet the handlers that were encountered so far throughout the build.

        Returns:
            An iterable of instances of [`BaseHandler`][mkdocstrings.handlers.base.BaseHandler]
            (usable only to loop through it).
        )r   r   r{   s    r,   seen_handlerszHandlers.seen_handlers  s     ~$$&&&r+   c                t    | j         D ]}|                                 | j                                         dS )z1Teardown all cached handlers and clear the cache.N)r   r|   r   r   )r^   rF   s     r,   r|   zHandlers.teardown  sC    ) 	 	Gr+   )ro   r   r2   rI   )rn   r?   r2   r   )ro   r   r2   r?   )r@   r?   r2   r   r6   )r@   r?   r   r   r2   r=   )r2   r   r   )r&   r'   r(   r)   re   r   r   r   r   propertyr   r|   r*   r+   r,   r   r     s         	[ 	[ 	[ 	[   &0 0 0 0   $ $ $ $ $: ' ' ' X'     r+   r   r6   )r/   r   r0   r1   r2   r3   )6r)   
__future__r   r   syspathlibr   typingr   r   r   r   r	   r
   r   r   r   r   xml.etree.ElementTreer   r   jinja2r   r   markdownr   markdown.extensions.tocr   
markupsafer   mkdocs_autorefs.referencesr   mkdocstrings.handlers.renderingr   r   r   r   r   mkdocstrings.inventoryr   mkdocstrings.loggersr   version_infoimportlib_metadatar!   importlib.metadatar"   rq   	Exceptionr$   r.   r;   r=   r   r*   r+   r,   <module>r     s   
 # " " " " "     



       v v v v v v v v v v v v v v v v v v v v v v v v 3 3 3 3 3 3 3 3 0 0 0 0 0 0 0 0       4 4 4 4 4 4       > > > > > >              - , , , , , 4 4 4 4 4 4 g///////////// A@@@@@@C C C C Ci C C C@ @ @ @ @	 @ @ @* * * * *"@( @( @( @( @( @( @( @(F
l l l l l l l l l lr+   