
    -e[                        d Z ddlmZ ddlZ ej        e          ZddlmZm	Z	m
Z
 ddlmZmZ ddlmZmZ erddlmZ dd	lmZ d
dlmZ dZ G d d          Zd"dZd#dZd$dZd%dZd&d!ZdS )'z` Provide a base class for all objects (called Bokeh Models) that can go in
a Bokeh |Document|.

    )annotationsN)TYPE_CHECKINGAnyCallable   )HasProps	Qualified)entriesis_dataclass)ID)Document   Model)HasDocumentRefr	   collect_filtered_modelscollect_models	get_class visit_immediate_value_references(visit_value_and_its_immediate_referencesc                  n     e Zd ZU ded<   ded<    fdZedd            Zej        dd
            Z xZS )r   Document | None	_document_temp_documentc                V     t                      j        |i | d | _        d | _        d S N)super__init__r   r   )selfargskw	__class__s      0lib/python3.11/site-packages/bokeh/model/util.pyr   zHasDocumentRef.__init__>   s4    $%"%%%"    returnc                ,    | j         | j         S | j        S )zE The |Document| this model is attached to (can be ``None``)

        )r   r   )r   s    r#   documentzHasDocumentRef.documentC   s    
 *&&~r$   docr   Nonec                    || _         d S r   )r   )r   r(   s     r#   r'   zHasDocumentRef.documentL   s    r$   )r%   r   )r(   r   r%   r)   )	__name__
__module____qualname____annotations__r   propertyr'   setter__classcell__)r"   s   @r#   r   r   9   s         ##### # # # #
    X _   _    r$   r   discardCallable[[Model], bool] | Noneinput_valuesr   r%   list[Model]c                ,    t                      g }g d fd}|D ]}t          ||           r_                    d          }|j        vr?                    |j                   |                    |           t          ||           _|S )a   Collect a duplicate-free list of all other Bokeh models referred to by
    this model, or by any of its references, etc, unless filtered-out by the
    provided callable.

    Iterate over ``input_values`` and descend through their structure
    collecting all nested ``Models`` on the go.

    Args:
        *discard (Callable[[Model], bool])
            a callable which accepts a *Model* instance as its single argument
            and returns a boolean stating whether to discard the instance. The
            latter means that the instance will not be added to collected
            models nor will its references be explored.

        *input_values (Model)
            Bokeh models to collect other models from

    Returns:
        list(Model)

    objr   r%   r)   c                    | j         vr1t                    r |           s                    |            d S d S d S r   )idcallableappend)r7   r2   idsqueueds    r#   	queue_onez*collect_filtered_models.<locals>.queue_onek   sP    6hw&7&7GGCLLMM# r$   r   )r7   r   r%   r)   )setr   popr9   addr;   r   )r2   r4   	collectedr>   valuer7   r<   r=   s   `     @@r#   r   r   P   s    . 55CIF         C C0	BBBB
 =jjmm6GGCFOOOS!!!,S)<<<  = r$   c                     t          dg| R  S )a   Collect a duplicate-free list of all other Bokeh models referred to by
    this model, or by any of its references, etc.

    Iterate over ``input_values`` and descend through their structure
    collecting all nested ``Models`` on the go. The resulting list is
    duplicate-free based on objects' identifiers.

    Args:
        *input_values (Model)
            Bokeh models to collect other models from

    Returns:
        list[Model] : all models reachable from this one.

    N)r   )r4   s    r#   r   r   {   s      #47,7777r$   view_model_namestrtype[Model]c                r    ddl m} ddl m} ddlm} |j        }| |v r||          S t          d|  d          )a   Look up a Bokeh model class, given its view model name.

    Args:
        view_model_name (str) :
            A view model name for a Bokeh model to look up

    Returns:
        Model: the model class corresponding to ``view_model_name``

    Raises:
        KeyError, if the model cannot be found

    Example:

        .. code-block:: python

            >>> from bokeh.model import get_class
            >>> get_class("Range1d")
            <class 'bokeh.models.ranges.Range1d'>

    r   )models)plottingr   r   zView model name 'z' not found) rI   rJ   modelr   model_class_reverse_mapKeyError)rE   rI   rJ   r   known_modelss        r#   r   r      sr    4 0L,&&O,,G?GGGHHHr$   rC   visitorCallable[[Model], None]r)   c                    t          | t                    r9|                                 D ]"}t          | |          }t	          ||           #dS t	          | |           dS )z Visit all references to another Model without recursing into any
    of the child Model; may visit the same Model more than once if
    it's referenced more than once. Does not visit the passed-in value.

    N)
isinstancer   properties_with_refsgetattrr   )rC   rP   attrchilds       r#   r   r      sz     %"" A..00 	E 	EDE4((E4UGDDDD	E 	E 	1@@@@@r$   r7   c                n   ddl m} t          |           }|t          t          t
          hv rdS |t          u st          |t          t          f          r| D ]}t          ||           dS t          |t                    r<|                                 D ]%\  }}t          ||           t          ||           &dS t          |t                    r/t          ||          r ||            dS t          | |           dS t          |           r%t          |           D ]\  }}t          ||           dS dS )a   Visit Models, HasProps, and Python containers.

    Recurses down HasProps references and Python containers (does not recurse
    down Model subclasses).

    The ordering in this function is to optimize performance.  We check the
    most comomn types (int, float, str) first so that we can quickly return in
    the common case.  We avoid isinstance and issubclass checks in a couple
    places with `type` checks because isinstance checks can be slow.
    r   r   N)rL   r   typeintfloatrF   list
issubclasstupler   dictitemsr   r   r   r
   )r7   rP   r   typitemkeyrC   _s           r#   r   r      s    
s))C
sE3
d{{jtUm44{ 	D 	DD4T7CCCC	D 	D	C		 E))++ 	E 	EJC4S'BBB4UGDDDD	E 	E 
C	"	" Ec5!! 	;GCLLLLL -S':::::	c		 E 	E 	EHAu4UGDDDDE E	E 	Er$   )r2   r3   r4   r   r%   r5   )r4   r   r%   r5   )rE   rF   r%   rG   )rC   r   rP   rQ   r%   r)   )r7   r   rP   rQ   r%   r)   )__doc__
__future__r   logging	getLoggerr+   logtypingr   r   r   core.has_propsr   r	   util.dataclassesr
   r   
core.typesr   r'   r   rL   r   __all__r   r   r   r   r   r    r$   r#   <module>rp      s{    # " " " " " g!! 0 / / / / / / / / / 1 0 0 0 0 0 0 0 4 4 4 4 4 4 4 4 ######$       .) ) ) )V8 8 8 8$"I "I "I "IHA A A AE E E E E Er$   