U
    /et'                     @  s  U d Z ddlmZ ddlZeeZddlmZm	Z	m
Z
mZmZmZ ddlmZ dZe
eeed f ef Zd	d
d	dddZd
dddddZdd
ddddZG dd dZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZed(d) ed*d) ed+d) ed,d) ed-d) ed.d) ed/d) iZd0e d1< dd2dd3d4d5Z!dS )6z} The query module provides functions for searching collections of Bokeh
models for instances that match specified criteria.

    )annotationsN)AnyCallableDictIterableTypeUnion   )Model)EQfindGEQGTINLEQLTNEQORr   matchis_single_string_selector	_OperatorzIterable[Model]SelectorType)objsselectorreturnc                   s    fdd| D S )a   Query a collection of Bokeh models and yield any that match the
    a selector.

    Args:
        obj (Model) : object to test
        selector (JSON-like) : query selector

    Yields:
        Model : objects that match the query

    Queries are specified as selectors similar to MongoDB style query
    selectors, as described for :func:`~bokeh.core.query.match`.

    Examples:

        .. code-block:: python

            # find all objects with type Grid
            find(p.references(), {'type': Grid})

            # find all objects with type Grid or Axis
            find(p.references(), {OR: [
                {'type': Grid}, {'type': Axis}
            ]})

            # same query, using IN operator
            find(p.references(), {'type': {IN: [Grid, Axis]}})

    c                 3  s   | ]}t | r|V  qd S Nr   ).0objr    4/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/core/query.py	<genexpr>\   s     
 zfind.<locals>.<genexpr>r    )r   r   r    r   r!   r   >   s    r   strbool)r   fieldr   c                 C  s"   t | dko || ko t| | tS )z Whether a selector is a simple single field, e.g. ``{name: "foo"}``

    Args:
        selector (JSON-like) : query selector
        field (str) : field name to check for

    Returns
        bool

       )len
isinstancer#   )r   r%   r    r    r!   r   _   s    r   r
   )r   r   r   c              	     s|  |  D ]l\}}t|tr.|dkrvt|trdt| tgkrdt fdd|t D st dS nt |st dS n|dkrt|tr| jkr dS nFzt	|t	 j@ sW  dS W n& t
k
r   | jkrY  dS Y nX nJt |s dS t |}t|trt||s, dS n||krv dS q|tkrLt |sv dS q|tkrnt|  |sv dS qtdqdS )a   Test whether a given Bokeh model matches a given selector.

    Args:
        obj (Model) : object to test
        selector (JSON-like) : query selector

    Returns:
        bool : True if the object matches, False otherwise

    In general, the selectors have the form:

    .. code-block:: python

        { attrname : predicate }

    Where a predicate is constructed from the operators ``EQ``, ``GT``, etc.
    and is used to compare against values of model attributes named
    ``attrname``.

    For example:

    .. code-block:: python

        >>> from bokeh.plotting import figure
        >>> p = figure(width=400)

        >>> match(p, {'width': {EQ: 400}})
        True

        >>> match(p, {'width': {GT: 500}})
        False

    There are two selector keys that are handled especially. The first
    is 'type', which will do an isinstance check:

    .. code-block:: python

        >>> from bokeh.plotting import figure
        >>> from bokeh.models import Axis
        >>> p = figure()

        >>> match(p.xaxis[0], {'type': Axis})
        True

        >>> match(p.title, {'type': Axis})
        False

    There is also a ``'tags'`` attribute that ``Model`` objects have, that
    is a list of user-supplied values. The ``'tags'`` selector key can be
    used to query against this list of tags. An object matches if any of the
    tags in the selector match any of the tags on the object:

    .. code-block:: python

        >>> from bokeh.plotting import figure
        >>> p = figure(tags = ["my plot", 10])

        >>> match(p, {'tags': "my plot"})
        True

        >>> match(p, {'tags': ["my plot", 10]})
        True

        >>> match(p, {'tags': ["foo"]})
        False

    typec                 3  s   | ]}t  |V  qd S r   )r(   )r   xr   r    r!   r"      s     zmatch.<locals>.<genexpr>Ftagszmalformed query selectorT)itemsr(   r#   dictlistkeysr   anyr,   set	TypeErrorhasattrgetattrr   r   _or
_operators
ValueError)r   r   keyvalattrr    r+   r!   r   l   sD    D 
 

  
 
 
 
 
 
 
r   c                   @  s   e Zd ZdS )r   N)__name__
__module____qualname__r    r    r    r!   r      s   c                   @  s   e Zd ZdZdS )r   aY   Form disjunctions from other query predicates.

    Construct an ``OR`` expression by making a dict with ``OR`` as the key,
    and a list of other query expressions as the value:

    .. code-block:: python

        # matches any Axis subclasses or models with .name == "mycircle"
        { OR: [dict(type=Axis), dict(name="mycircle")] }

    Nr<   r=   r>   __doc__r    r    r    r!   r      s   r   c                   @  s   e Zd ZdZdS )r   aO   Predicate to test if property values are in some collection.

    Construct and ``IN`` predicate as a dict with ``IN`` as the key,
    and a list of values to check against.

    .. code-block:: python

        # matches any models with .name in ['a', 'mycircle', 'myline']
        dict(name={ IN: ['a', 'mycircle', 'myline'] })

    Nr?   r    r    r    r!   r      s   r   c                   @  s   e Zd ZdZdS )r   a   Predicate to test if property values are greater than some value.

    Construct and ``GT`` predicate as a dict with ``GT`` as the key,
    and a value to compare against.

    .. code-block:: python

        # matches any models with .size > 10
        dict(size={ GT: 10 })

    Nr?   r    r    r    r!   r     s   r   c                   @  s   e Zd ZdZdS )r   a   Predicate to test if property values are less than some value.

    Construct and ``LT`` predicate as a dict with ``LT`` as the key,
    and a value to compare against.

    .. code-block:: python

        # matches any models with .size < 10
        dict(size={ LT: 10 })

    Nr?   r    r    r    r!   r     s   r   c                   @  s   e Zd ZdZdS )r   a   Predicate to test if property values are equal to some value.

    Construct and ``EQ`` predicate as a dict with ``EQ`` as the key,
    and a value to compare against.

    .. code-block:: python

        # matches any models with .size == 10
        dict(size={ EQ: 10 })

    Nr?   r    r    r    r!   r     s   r   c                   @  s   e Zd ZdZdS )r   a.   Predicate to test if property values are greater than or equal to
    some value.

    Construct and ``GEQ`` predicate as a dict with ``GEQ`` as the key,
    and a value to compare against.

    .. code-block:: python

        # matches any models with .size >= 10
        dict(size={ GEQ: 10 })

    Nr?   r    r    r    r!   r   -  s   r   c                   @  s   e Zd ZdZdS )r   a+   Predicate to test if property values are less than or equal to
    some value.

    Construct and ``LEQ`` predicate as a dict with ``LEQ`` as the key,
    and a value to compare against.

    .. code-block:: python

        # matches any models with .size <= 10
        dict(size={ LEQ: 10 })

    Nr?   r    r    r    r!   r   <  s   r   c                   @  s   e Zd ZdZdS )r   a   Predicate to test if property values are unequal to some value.

    Construct and ``NEQ`` predicate as a dict with ``NEQ`` as the key,
    and a value to compare against.

    .. code-block:: python

        # matches any models with .size != 10
        dict(size={ NEQ: 10 })

    Nr?   r    r    r    r!   r   K  s   r   c                 C  s   | |kS r   r    r*   yr    r    r!   <lambda>_      rC   c                 C  s   | |kS r   r    rA   r    r    r!   rC   `  rD   c                 C  s   | |k S r   r    rA   r    r    r!   rC   a  rD   c                 C  s   | |kS r   r    rA   r    r    r!   rC   b  rD   c                 C  s   | |kS r   r    rA   r    r    r!   rC   c  rD   c                 C  s   | |kS r   r    rA   r    r    r!   rC   d  rD   c                 C  s   | |kS r   r    rA   r    r    r!   rC   e  rD   z2Dict[Type['_Operator'], Callable[[Any, Any], Any]]r7   zIterable[SelectorType])r   	selectorsr   c                   s   t  fdd|D S )Nc                 3  s   | ]}t  |V  qd S r   r   )r   r   r+   r    r!   r"   j  s     z_or.<locals>.<genexpr>)r1   )r   rE   r    r+   r!   r6   i  s    r6   )"r@   
__future__r   logging	getLoggerr<   logtypingr   r   r   r   r   r   modelr
   __all__r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   __annotations__r6   r    r    r    r!   <module>   sF   
 
!x       