ó
mÜJ]c        
   @` sz  d  Z  d d l m Z m Z m Z m Z d d l Z e j e ƒ Z	 d d l
 m Z d) Z d d „ Z d d „ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ i d! „  e 6d" „  e 6d# „  e 6d$ „  e 6d% „  e 6d& „  e 6d' „  e 6Z d( „  Z d S(*   u}    The query module provides functions for searching collections of Bokeh
models for instances that match specified criteria.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   string_typesu   EQu   findu   GEQu   GTu   INu   LEQu   LTu   matchu   NEQu   ORc         ` s   ‡  ‡ f d †  |  Dƒ S(   u   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
        context (dict) : kwargs to supply callable query attributes

    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]}})

            # find all plot objects on the 'left' layout of the Plot
            # here layout is a method that takes a plot as context
            find(p.references(), {'layout': 'left'}, {'plot': p})

    c         3` s'   |  ] } t  | ˆ ˆ  ƒ r | Vq d  S(   N(   t   match(   t   .0t   obj(   t   contextt   selector(    s/   lib/python2.7/site-packages/bokeh/core/query.pys	   <genexpr>W   s    (    (   t   objsR	   R   (    (   R   R	   s/   lib/python2.7/site-packages/bokeh/core/query.pyt   find4   s    #c         ` s  | p	 i  } xú| j  ƒ  D]ì\ } } t | t ƒ r±| d k r§ t | t ƒ r‘ t | j ƒ  ƒ t g k r‘ t ‡  f d †  | t Dƒ ƒ s¤ t Sq®t ˆ  | ƒ s®t Sq| d k r#t | t ƒ rØ | ˆ  j	 k r t Sq®y! t
 | ƒ t
 ˆ  j	 ƒ @sø t SWq®t k
 r| ˆ  j	 k r t Sq®Xqt ˆ  | ƒ s6t St ˆ  | ƒ } t | ƒ rvy | | |  sgt SWq®t SXqt | t ƒ ržt | | | ƒ s®t Sq| | k rt Sq | t k rÓt ˆ  | ƒ st Sq | t k rùt | ˆ  | ƒ st Sq t d ƒ ‚ q Wt S(   u   Test whether a given Bokeh model matches a given selector.

    Args:
        obj (Model) : object to test
        selector (JSON-like) : query selector
        context (dict) : kwargs to supply callable query attributes

    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(plot_width=400)

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

        >>> match(p, {'plot_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

    u   typec         3` s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   t
   isinstance(   R   t   x(   R   (    s/   lib/python2.7/site-packages/bokeh/core/query.pys	   <genexpr>¨   s    u   tagsu   malformed query selector(   t   itemsR   R   t   dictt   listt   keyst   INt   anyt   Falset   tagst   sett	   TypeErrort   hasattrt   getattrt   callableR   t   ORt   _ort
   _operatorst
   ValueErrort   True(   R   R	   R   t   keyt   valt   attr(    (   R   s/   lib/python2.7/site-packages/bokeh/core/query.pyR   Y   sR    E*            R   c           B` s   e  Z d  Z RS(   uY   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")] }

    (   t   __name__t
   __module__t   __doc__(    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR   Ù   s   R   c           B` s   e  Z d  Z RS(   uO   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'] })

    (   R#   R$   R%   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR   ç   s   t   GTc           B` s   e  Z d  Z RS(   u   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 })

    (   R#   R$   R%   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR&   õ   s   t   LTc           B` s   e  Z d  Z RS(   u   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 })

    (   R#   R$   R%   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR'     s   t   EQc           B` s   e  Z d  Z RS(   u   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 })

    (   R#   R$   R%   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR(     s   t   GEQc           B` s   e  Z d  Z RS(   u.   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 })

    (   R#   R$   R%   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR)     s   t   LEQc           B` s   e  Z d  Z RS(   u+   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 })

    (   R#   R$   R%   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR*   .  s   t   NEQc           B` s   e  Z d  Z RS(   u   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 })

    (   R#   R$   R%   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR+   =  s   c         C` s
   |  | k S(   N(    (   R   t   y(    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyt   <lambda>Q  t    c         C` s
   |  | k S(   N(    (   R   R,   (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR-   R  R.   c         C` s
   |  | k  S(   N(    (   R   R,   (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR-   S  R.   c         C` s
   |  | k S(   N(    (   R   R,   (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR-   T  R.   c         C` s
   |  | k S(   N(    (   R   R,   (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR-   U  R.   c         C` s
   |  | k S(   N(    (   R   R,   (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR-   V  R.   c         C` s
   |  | k S(   N(    (   R   R,   (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyR-   W  R.   c         ` s   t  ‡  f d †  | Dƒ ƒ S(   Nc         3` s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   R   (   R   R	   (   R   (    s/   lib/python2.7/site-packages/bokeh/core/query.pys	   <genexpr>\  s    (   R   (   R   t	   selectors(    (   R   s/   lib/python2.7/site-packages/bokeh/core/query.pyR   [  s    (
   u   EQu   findu   GEQu   GTu   INu   LEQu   LTu   matchu   NEQu   OR(   R%   t
   __future__R    R   R   R   t   loggingt	   getLoggerR#   t   logt   sixR   t   __all__t   NoneR   R   t   objectR   R   R&   R'   R(   R)   R*   R+   R   R   (    (    (    s/   lib/python2.7/site-packages/bokeh/core/query.pyt   <module>
   sB   "		         %€





