σ
mάJ]c           @` s½   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   Z d d d d  Z d   Z d   Z d d d  Z d   Z d d d d  Z d   Z d S(   u©   Provide a set of decorators useful for repeatedly updating a
a function parameter in a specified way each time the function is
called.

These decorators can be especially useful in conjunction with periodic
callbacks in a Bokeh server application.

Example:

    As an example, consider the ``bounce`` forcing function, which
    advances a sequence forwards and backwards:

    .. code-block:: python

        from bokeh.driving import bounce

        @bounce([0, 1, 2])
        def update(i):
            print(i)

    If this function is repeatedly called, it will print the following
    sequence on standard out:

    .. code-block:: none

        0 1 2 2 1 0 0 1 2 2 1 ...

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   partialu   bounceu   cosineu   countu   forceu   linearu   repeatu   sinec         ` s4   t         f d   } t t d t |  S(   u   Return a driver function that can advance a "bounced" sequence
    of values.

    .. code-block:: none

        seq = [0, 1, 2, 3]

        # bounce(seq) => [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, ...]

    Args:
        sequence (seq) : a sequence of values for the driver to bounce

    c         ` sA   t  |     \ } } | d d k r-  | S   | d Sd  S(   Ni   i    i   (   t   divmod(   t   it   divt   mod(   t   Nt   sequence(    s,   lib/python2.7/site-packages/bokeh/driving.pyt   fX   s    R
   (   t   lenR   t   forcet   _advance(   R
   R   (    (   R	   R
   s,   lib/python2.7/site-packages/bokeh/driving.pyt   bounceI   s    i   c         ` sA   d d l  m        f d   } t t d t |  S(   u   Return a driver function that can advance a sequence of cosine values.

    .. code-block:: none

        value = A * cos(w*i + phi) + offset

    Args:
        w (float) : a frequency for the cosine driver
        A (float) : an amplitude for the cosine driver
        phi (float) : a phase offset to start the cosine driver with
        offset (float) : a global offset to add to the driver values

    i    (   t   cosc         ` s       |     S(   N(    (   R   (   t   AR   t   offsett   phit   w(    s,   lib/python2.7/site-packages/bokeh/driving.pyR   o   s    R
   (   t   mathR   R   R   R   (   R   R   R   R   R   (    (   R   R   R   R   R   s,   lib/python2.7/site-packages/bokeh/driving.pyt   cosine`   s    c           C` s   t  t d t d    S(   u@    Return a driver function that can advance a simple count.

    R
   c         S` s   |  S(   N(    (   t   x(    (    s,   lib/python2.7/site-packages/bokeh/driving.pyt   <lambda>w   t    (   R   R   R   (    (    (    s,   lib/python2.7/site-packages/bokeh/driving.pyt   counts   s    c         ` s      f d   } | S(   uΝ    Return a decorator that can "force" a function with an arbitrary
    supplied generator

    Args:
        sequence (iterable) :
            generator to drive f with

    Returns:
        decorator

    c           ` s     t     d  S(   N(   t   next(    (   R   R
   (    s,   lib/python2.7/site-packages/bokeh/driving.pyt   wrapper   s    (    (   R   R
   R   (    (   R   R
   s,   lib/python2.7/site-packages/bokeh/driving.pyR   y   s    c         ` s(      f d   } t  t d t |  S(   uσ    Return a driver function that can advance a sequence of linear values.

    .. code-block:: none

        value = m * i + b

    Args:
        m (float) : a slope for the linear driver
        x (float) : an offset for the linear driver

    c         ` s    |    S(   N(    (   R   (   t   bt   m(    s,   lib/python2.7/site-packages/bokeh/driving.pyR      s    R
   (   R   R   R   (   R   R   R   (    (   R   R   s,   lib/python2.7/site-packages/bokeh/driving.pyt   linear   s    c         ` s4   t         f d   } t t d t |  S(   u   Return a driver function that can advance a repeated of values.

    .. code-block:: none

        seq = [0, 1, 2, 3]

        # repeat(seq) => [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...]

    Args:
        sequence (seq) : a sequence of values for the driver to bounce

    c         ` s    |    S(   N(    (   R   (   R	   R
   (    s,   lib/python2.7/site-packages/bokeh/driving.pyR   §   s    R
   (   R   R   R   R   (   R
   R   (    (   R	   R
   s,   lib/python2.7/site-packages/bokeh/driving.pyt   repeat   s    c         ` sA   d d l  m        f d   } t t d t |  S(   u   Return a driver function that can advance a sequence of sine values.

    .. code-block:: none

        value = A * sin(w*i + phi) + offset

    Args:
        w (float) : a frequency for the sine driver
        A (float) : an amplitude for the sine driver
        phi (float) : a phase offset to start the sine driver with
        offset (float) : a global offset to add to the driver values

    i    (   t   sinc         ` s       |     S(   N(    (   R   (   R   R   R   R!   R   (    s,   lib/python2.7/site-packages/bokeh/driving.pyR   Ί   s    R
   (   R   R!   R   R   R   (   R   R   R   R   R   (    (   R   R   R   R!   R   s,   lib/python2.7/site-packages/bokeh/driving.pyt   sine«   s    c         c` s,   d } x t  r' |  |  V| d 7} q	 Wd S(   uλ    Yield a sequence generated by calling a given function with
    successively incremented integer values.

    Args:
        f (callable) :
            The function to advance

    Yields:
        f(i) where i increases each call

    i    i   N(   t   True(   R   R   (    (    s,   lib/python2.7/site-packages/bokeh/driving.pyR   Ζ   s    	(   u   bounceu   cosineu   countu   forceu   linearu   repeatu   sine(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logt	   functoolsR   t   __all__R   R   R   R   R   R    R"   R   (    (    (    s,   lib/python2.7/site-packages/bokeh/driving.pyt   <module>"   s&   "      				