
    .dg                       d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZmZmZ dd	lmZ dd
lmZ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'm(Z(  G d de      Z) G d de      Z* G d de      Z+ G d de      Z, G d de,      Z- G d d      Z.dddZ/ G d d      Z0d Z1 ee1       y) a7  
reactive API

`rx` is a wrapper around a Python object that lets users create
reactive expression pipelines by calling existing APIs on an object with dynamic
parameters or widgets.

An `rx` instance watches what operations are applied to the object
and records these on each instance, which are then strung together
into a chain.

The original input to an `rx` object is stored in a mutable list and can be
accessed via the `_obj` property. The shared mutable data structure
ensures that all `rx` instances created from the same object can
hold a shared reference that can be updated, e.g. via the `.value`
property or because the input was itself a reference to some object that
can potentially be updated.

When an operation is applied to an `rx` instance, it will
record the operation and create a new instance using the `_clone` method,
e.g. `dfi.head()` first records that the `'head'` attribute is
accessed, which is achieved by overriding `__getattribute__`. A new
reactive object is returned, which will then record that it is
being called, and that new object will be itself called, as
`rx` implements `__call__`. `__call__` returns another
`rx` instance. To be able to watch all the potential
operations that may be applied to an object, `rx` implements:

- `__getattribute__`: Watching for attribute accesses
- `__call__`: Intercepting both actual calls or method calls if an
  attribute was previously accessed
- `__getitem__`: Intercepting indexing operations
- Operators: Implementing all valid operators `__gt__`, `__add__`, etc.
- `__array_ufunc__`: Intercepting numpy universal function calls

The `rx` object evaluates operations lazily, but whenever the
current value is needed the operations are automatically
evaluated. Note that even attribute access or tab-completion
operations can result in evaluation of the pipeline. This is very
useful in a REPL, as this allows inspecting the transformed
object at any point of the pipeline, and as such provide correct
auto-completion and docstrings. E.g. executing `dfi.A.max?` in an
interactive REPL or notebook where it allows returning the docstring
of the method being accessed.

The actual operations are stored as a dictionary on the `_operation`
attribute of each instance. They contain 4 keys:

- `fn`: The function to apply (either an actual function or a string
        indicating the operation is a method on the object)
- `args`: Any arguments to supply to the `fn`.
- `kwargs`: Any keyword arguments to supply to the `fn`.
- `reverse`: If the function is not a method this indicates whether
             the first arg and the input object should be supplied in
             reverse order.

The `_depth` attribute starts at 0 and is incremented by 1 every time
a new `rx` instance is created part of a chain. The root
instance in a reactive expression  has a `_depth` of 0. A reactive
expression can consist of multiple chains, such as `dfi[dfi.A > 1]`,
as the `rx` instance is referenced twice in the expression. As a
consequence `_depth` is not the total count of `rx` instance
creations of a pipeline, it is the count of instances created in the
outer chain. In the example, that would be `dfi[]`. Each `rx`
instance keeps a reference to the previous instance in the chain and
each instance tracks whether its current value is up-to-date via the
`_dirty` attribute, which is set to False if any dependency changes.

The `_method` attribute is a string that temporarily stores the
method/attr accessed on the object, e.g. `_method` is 'head' in
`dfi.head()`, until the `rx` instance created in the pipeline
is called at which point `_method` is reset to None. In cases such as
`dfi.head` or `dfi.A`, `_method` is not (yet) reset to None. At this
stage the `rx` instance returned has its `_current` attribute
not updated, e.g. `dfi.A._current` is still the original dataframe,
not the 'A' series. Keeping `_method` is thus useful for instance to
display `dfi.A`, as the evaluation of the object will check whether
`_method` is set or not, and if it's set it will use it to compute the
object returned, e.g. the series `df.A` or the method `df.head`, and
display its repr.
    )annotationsN)IterableIterator)partial)FunctionType
MethodType)AnyCallableOptional   )depends)_display_accessors_reactive_display_objs)
	ParameterParameterizedSkip	Undefinedeval_function_with_depsget_method_ownerregister_reference_transformresolve_refresolve_valuetransform_reference)BooleanEvent)_to_async_geniscoroutinefunctionfull_groupbyc                  "    e Zd ZdZ ed      Zy)Wrapperz5Helper class to allow updating literal values easily.F
allow_refsN__name__
__module____qualname____doc__r   object     .lib/python3.12/site-packages/param/reactive.pyr    r    h   s    ?%(Fr*   r    c                  "    e Zd ZdZ ed      Zy)
GenWrapperz9Helper class to allow streaming from generator functions.Tr!   Nr#   r)   r*   r+   r-   r-   n   s    C$'Fr*   r-   c                  2     e Zd ZdZ e       Zd fd	Z xZS )Triggerz?Helper class to allow triggering an event under some condition.c                @    t        |   di | || _        || _        y Nr)   )super__init__internal
parameters)selfr5   r4   params	__class__s       r+   r3   zTrigger.__init__y   s!    "6" $r*   NF)r$   r%   r&   r'   r   valuer3   __classcell__r8   s   @r+   r/   r/   t   s    IGE% %r*   r/   c                       e Zd ZdZ ed      Z ed      Z e       Z fdZ	d Z
 eddd	      d
        Zd Z xZS )Resolverz9Helper class to allow (recursively) resolving references.Tr!   F)defaultc                2    g | _         t        |   di | y r1   )	_watchersr2   r3   )r6   r7   r8   s     r+   r3   zResolver.__init__   s    "6"r*   c                   | j                   j                  j                  }t        | j                  |      }t	        | j                  |      }| j
                  ret        ||      D cg c]	  }||vs| }}|r2||z  }t	        ||      }t        ||      D cg c]	  }||vs| }}|r2|r| j                  |       || _        |S c c}w c c}w N)paramr(   nested_refsr   r   	recursive_update_refsr:   )r6   eventsnestedrefsr:   rnew_refss          r+   _resolve_valuezResolver._resolve_value   s    ""..4;;/dkk62>>#.uf#=O#=a$#=HO %eV4'25&'AS'A!Qd]A'AS  !!$'
 P Ts   '	C1C	C"Cr(   )watchon_initc                F    | j                         }| j                  |       y rC   )rM   rG   )r6   rJ   s     r+   _resolve_objectzResolver._resolve_object   s    ""$$r*   c           
        | j                   D ]5  }|j                  xs |j                  j                  j	                  |       7 g | _         t        |d       D ]i  \  }}| j                   j                  |d   j                  j                  j                  | j                  |D cg c]  }|j                   c}             k y c c}w )Nc                ,    t        | j                        S rC   idownerxs    r+   <lambda>z'Resolver._update_refs.<locals>.<lambda>   s    bkr*   r   )rA   instclsrD   unwatchr   appendrV   rN   rM   name)r6   rJ   w_r7   ps         r+   rG   zResolver._update_refs   s    AVV_quu##++A.  %d,ABIAvNN!!q	%%++D,?,?RXAYRXQ!&&RXAYZ CAYs   %C)r$   r%   r&   r'   r   r(   r   rF   r:   r3   rM   r   rQ   rG   r;   r<   s   @r+   r>   r>   ~   sM    C$'F&IKE# XT40  1 r*   r>   c                       e Zd Z edd      Zy)NestedResolverT)r"   rE   N)r$   r%   r&   r   r(   r)   r*   r+   rc   rc      s    $D9Fr*   rc   c                      e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd ZddZd ZeddZd Zed        Zej2                  d        ZddZddZy)reactive_opsa  
    The reactive namespace.

    Provides reactive versions of operations that cannot be made reactive through operator overloading, such as
    `.rx.and_` and `.rx.bool`. Calling this namespace (`()`) returns a reactive expression.

    Returns
    -------
    Reactive expression
        The result of calling the reactive namespace is a reactive expression.

    User Guide
    ----------
    https://param.holoviz.org/user_guide/Reactive_Expressions.html#special-methods-on-rx

    Examples
    --------
    Create a Parameterized instance:

    >>> import param
    >>> class P(param.Parameterized):
    ...     a = param.Number()
    >>> p = P(a=1)

    Get the current value:

    >>> a = p.param.a.rx.value

    Call it to get a reactive expression:

    >>> rx_value = p.param.a.rx()

    c                    || _         y rC   )	_reactive)r6   reactives     r+   r3   zreactive_ops.__init__   s	    !r*   c                \    t        | j                  t              r| j                  S  |        S rC   )
isinstancerg   rxr6   s    r+   _as_rxzreactive_ops._as_rx   s     !+DNNB!?t~~KTVKr*   c                \    | j                   }t        t        t              r|S t        |      S )zCreates a reactive expression.)rg   rj   rk   )r6   rxis     r+   __call__zreactive_ops.__call__   s#    nn R(s5bg5r*   c                D    | j                         j                  d |      S )z&Replacement for the ``and`` statement.c                    | xr |S rC   r)   objothers     r+   rY   z#reactive_ops.and_.<locals>.<lambda>   s
    r*   rm   _apply_operatorr6   ru   s     r+   and_zreactive_ops.and_   s    {{},,-MuUUr*   c                H    | j                         j                  t              S )z=__bool__ cannot be implemented so it is provided as a method.)rm   rw   boolrl   s    r+   r{   zreactive_ops.bool   s    {{},,T22r*   c                R    g fd}| j                         j                  ||      S )z,Collects the last n items that were emitted.c                    j                  |        t              |kD  r j                  d       t              |kD  r S Nr   )r]   lenpop)newnitemss     r+   collectz$reactive_ops.buffer.<locals>.collect   s7    LLe*q.		! e*q.Lr*   rv   )r6   r   r   r   s      @r+   bufferzreactive_ops.buffer   s(    	
 {{},,Wa88r*   c                b    | j                         j                  t        j                  |d      S )z%Replacement for the ``in`` statement.Treverse)rm   rw   operatorcontainsrx   s     r+   in_zreactive_ops.in_   s&    {{},,X->->t,TTr*   c                ^    | j                         j                  t        j                  |      S )z%Replacement for the ``is`` statement.)rm   rw   r   is_rx   s     r+   r   zreactive_ops.is_   s    {{},,X\\5AAr*   c                ^    | j                         j                  t        j                  |      S )z)Replacement for the ``is not`` statement.)rm   rw   r   is_notrx   s     r+   r   zreactive_ops.is_not   s    {{},,X__eDDr*   c                H    | j                         j                  t              S )z<__len__ cannot be implemented so it is provided as a method.)rm   rw   r   rl   s    r+   r   zreactive_ops.len   s    {{},,S11r*   c                   t        j                        st        j                        rt        d      t        j                        rfd}nfd} | j                         j                  |g|i |S )a6  
        Apply a function to each item.

        Arguments:
        ---------
        func: function
          Function to apply.
        args: iterable, optional
          Positional arguments to pass to `func`.
        kwargs: mapping, optional
          A dictionary of keywords to pass to `func`.

        z\Cannot map a generator function. Only regular function or coroutine functions are permitted.c                p   K   t        t        j                  fd| D          d {         S 7 w)Nc              3  6   K   | ]  } |gi   y wrC   r)   ).0vargsfunckwargss     r+   	<genexpr>z2reactive_ops.map.<locals>.apply.<locals>.<genexpr>  s$     2XUWPQ43KD3KF3KUWs   )listasynciogather)vsr   r   r   s    ``r+   applyzreactive_ops.map.<locals>.apply  s(     '..2XUW2X"YYZZYs   &64	6c                B    | D cg c]  } |g|i | c}S c c}w rC   r)   )r   r   r   r   r   s       r+   r   zreactive_ops.map.<locals>.apply  s*    :<="QQ000"===s   )inspectisasyncgenfunctionisgeneratorfunction	TypeErrorr   rm   rw   )r6   r   r   r   r   s    `   r+   mapzreactive_ops.map   sp     %%d+w/J/J4/P8  &&t,[>,t{{},,UDTDVDDr*   c                \    | j                         j                  t        j                        S )zE__bool__ cannot be implemented so not has to be provided as a method.)rm   rw   r   not_rl   s    r+   r   zreactive_ops.not_  s    {{},,X]];;r*   c                D    | j                         j                  d |      S )z%Replacement for the ``or`` statement.c                    | xs |S rC   r)   rs   s     r+   rY   z"reactive_ops.or_.<locals>.<lambda>  s
    ur*   rv   rx   s     r+   or_zreactive_ops.or_  s    {{},,-LeTTr*   c               J     | j                         j                  |g|i |S )a2  
        Apply chainable functions.

        Arguments:
        ---------
        func: function
          Function to apply.
        args: iterable, optional
          Positional arguments to pass to `func`.
        kwargs: mapping, optional
          A dictionary of keywords to pass to `func`.

        rv   )r6   r   r   r   s       r+   pipezreactive_ops.pipe!  s'     -t{{},,TCDCFCCr*   c                    |rt         nt        } || j                  |      }|j                  j                  j                         S )aM  
        Resolves references held by the expression.

        As an example if the expression returns a list of parameters
        this operation will return a list of the parameter values.

        Arguments:
        ---------
        nested: bool
          Whether to resolve references contained within nested objects,
          i.e. tuples, lists, sets and dictionaries.
        recursive: bool
          Whether to recursively resolve references, i.e. if a reference
          itself returns a reference we recurse into it until no more
          references can be resolved.

        )r(   rF   )rc   r>   rg   rD   r:   rk   )r6   rI   rF   resolver_typeresolvers        r+   resolvezreactive_ops.resolve1  s6    $ +1h )L~~##&&((r*   c                    t        d      | j                  fdd       | j                  fdd       j                  j                  j	                         S )zGReturns a new expression that is True while the expression is updating.Fr(   c                <    j                   j                  d      S )NTr   rD   updateewrappers    r+   rY   z'reactive_ops.updating.<locals>.<lambda>J  s    gmm22$2?r*   i
precedencec                <    j                   j                  d      S )NFr   r   r   s    r+   rY   z'reactive_ops.updating.<locals>.<lambda>K  s    gmm22%2@r*   i  )r    _watchrD   r(   rk   )r6   r   s    @r+   updatingzreactive_ops.updatingG  sH    '?DQ@SQ}}##&&((r*   )initialc                    |D cg c]  }t        |      D ]  }|  }}}t        d |D              g d fd
}t        |g| j                         S c c}}w )af  
        Returns a reactive expression that emits the contents of this
        expression only when the dependencies change. If initial value
        is provided and the dependencies are all param.Event types the
        expression will not be evaluated until the first event is
        triggered.

        Arguments:
        ---------
        dependencies: param.Parameter | rx
          A dependency that will trigger an update in the output.
        initial: object
          Object that will stand in for the actual value until the
          first time a param.Event in the dependencies is triggered.

        c              3  <   K   | ]  }t        |t                y wrC   )rj   r   )r   deps     r+   r   z$reactive_ops.when.<locals>.<genexpr>`  s     >#z#u-s   )	evaluatedc                Z    rt         ur| s| j                  d       S j                  S NT)r   r]   r:   )r   r`   r   is_eventr6   s     r+   evalzreactive_ops.when.<locals>.evala  s,    G94Y  &zz!r*   )r   allbindrk   )r6   r   dependenciesdra   depsr   r   s   ``     @r+   whenzreactive_ops.whenN  sc    " (@<aQA<@>>>! 	" 	" D 4 ##%% As   Ac                   	 t              }t              }t         j                  t              r j                  j                  }nt         j                        }t        |      	|r 	fd}t        |g|ddi |r 	fd}t        |g|ddi fd}t        | j                  	j                  j                        S )aY  
        Returns either x or y depending on the current state of the
        expression, i.e. replaces a ternary if statement.

        Arguments:
        ---------
        x: object
          The value to return if the expression evaluates to True.
        y: object
          The value to return if the expression evaluates to False.

        )r5   c                 V    j                   rj                  j                  d       y y Nr:   r:   rD   triggerr   r6   r   s    r+   	trigger_xz%reactive_ops.where.<locals>.trigger_x  s!    ::MM))'2 r*   rN   Tc                 V    j                   sj                  j                  d       y y r   r   r   s    r+   	trigger_yz%reactive_ops.where.<locals>.trigger_y  s!    zzMM))'2 "r*   c                4    | rt              S t              S rC   )r   )	conditionr`   rX   ys     r+   ternaryz#reactive_ops.where.<locals>.ternary  s    '0=#FmA6FFr*   )	r   rj   rg   rk   _paramsr/   r   rD   r:   )
r6   rX   r   xrefsyrefsr7   r   r   r   r   s
   ```      @r+   wherezreactive_ops.wherej  s     AAdnnb)^^++F 0FV,3 /U/$/3 /U/$/	GGT^^W]]-@-@AAr*   c                &   t        | j                  t              r| j                  j                         S t        | j                  t              r4t        | j                  j                  | j                  j                        S | j                         S )zj
        Returns the current state of the reactive expression by
        evaluating the pipeline.
        )rj   rg   rk   _resolver   getattrrV   r^   rl   s    r+   r:   zreactive_ops.value  sa     dnnb)>>**,,	24>>//1D1DEE>>##r*   c                |   t        | j                  t              rt        d      t        | j                  t              st        d      | j                  j
                  | j                  urt        d      | j                  j                  t        d      t        |      | j                  j                  _        y)z5Allows overriding the original input to the pipeline.zO`Parameter.rx.value = value` is not supported. Cannot override parameter value.zX`bind(...).rx.value = value` is not supported. Cannot override the output of a function.zThe value of a derived expression cannot be set. Ensure you set the value on the root node wrapping a concrete value, e.g.:

    a = rx(1)
    b = a + 1
    a.rx.value = 2

 is valid but you may not set `b.rx.value = 2`.NzSetting the value of a reactive expression is only supported if it wraps a concrete value. A reactive expression wrapping a Parameter or another dynamic reference cannot be updated.)	rj   rg   r   AttributeErrorrk   _root_wrapperr   r(   )r6   r   s     r+   r:   zreactive_ops.value  s     dnni0 #  DNNB/ ,  ^^!!7 A  >>""* /  *7s);&r*   Nc                N    |dk  rt        d      | j                  ||||       y)z
        Adds a callable that observes the output of the pipeline.
        If no callable is provided this simply causes the expression
        to be eagerly evaluated.
        r   zyUser-defined watch callbacks must declare a positive precedence. Negative precedences are reserved for internal Watchers.)onlychangedqueuedr   N)
ValueErrorr   )r6   fnr   r   r   s        r+   rN   zreactive_ops.watch  s6     > C D D 	BK:Vr*   c                @    fd}t        || j                  d       y )Nc                d    ddl m} t              r |t        |              y 	 |        y y Nr   )async_executor)parameterizedr   r   r   )r:   r   r   s     r+   cbzreactive_ops._watch.<locals>.cb  s.    5"2&wr5125	  r*   TrN   )r   rg   )r6   r   r   r   r   r   s    `    r+   r   zreactive_ops._watch  s    	 	Rt,r*   )TF)NTFr   )r$   r%   r&   r'   r3   rm   rp   ry   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr:   setterrN   r   r)   r*   r+   re   re      s     D"L6
V39UBE2E6<UD ),) +4 &8!BJ 
$ 
$ \\< <8
W-r*   re   Fr   c          	         t        d D              j                         D ci c]  \  }}|t        |       c}}ci }t               }t        |t              st        |d      r||d<   t              D ]  \  }}	t        |	d      r\t        |	j                  d         D ]  \  }
}||d| d|
 <    |	j                  d   j                         D ]  \  }}||d| d| <    nt        |	t              s|	|d| <    j                         D ]  \  }}t        |d      r\t        |j                  d         D ]  \  }
}||d	| d|
 <    |j                  d   j                         D ]  \  }}||d	| d
| <    nt        |t              s|||<    dfd	 fdt        j                         r-fd} t        di |d|i|      }|j                  |_        n~t        j                         r-fd} t        di |d|i|      }|j                  |_        n<t               rt        di |d|ifd       }nt        di |d|ifd       } |_        t        |      |_        t!        j"                  |       t%        j                         D ]  \  }}t'        || ||              |S c c}}w )a  
    Given a function, returns a wrapper function that binds the values
    of some or all arguments to Parameter values and expresses Param
    dependencies on those values, so that the function can be invoked
    whenever the underlying values change and the output will reflect
    those updated values.

    As for functools.partial, arguments can also be bound to constants,
    which allows all of the arguments to be bound, leaving a simple
    callable object.

    Arguments:
    ---------
    function: callable
        The function to bind constant or dynamic args and kwargs to.
    args: object, param.Parameter
        Positional arguments to bind to the function.
    watch: boolean
        Whether to evaluate the function automatically whenever one of
        the bound parameters changes.
    kwargs: object, param.Parameter
        Keyword arguments to bind to the function.

    Returns
    -------
    Returns a new function with the args and kwargs bound to it and
    annotated with all dependencies.

    c              3  2   K   | ]  }t        |        y wrC   )r   )r   args     r+   r   zbind.<locals>.<genexpr>  s     7$3!#&$s   _dinfo__fnr   __arg_argkw_arg___kwarg_r`   c                
   g }	D ][  }t        |d      rt        |      }n0t        |t              r t	        |j
                  |j                        }|j                  |       ] |t        |       z  }i }
j                         D ]R  \  }}t        |d      rt        |      }n0t        |t              r t	        |j
                  |j                        }|||<   T |j                         D ]  \  }}|rU|j                  d      r$|dd  }|j                         r.||t        |      <   n|j                  d      r|dd  }||v r|||<   ]|j                  d      s"|j                  d      s|j                  d      r|||<    ||fS )Nr   r      __kwarg   r   )hasattrr   rj   r   r   rV   r^   r]   r   r   
startswithisdigitint)wargswkwargsasynchronouscombined_argsr   combined_kwargsr   index	substringr   r   s            r+   combine_argumentszbind.<locals>.combine_arguments
  sg   CsH%-c2C+cii2  %  	e$||~GBsH%-c2C+cii2"%OB & }}GB==)qrFE}}47c%j1]]9- "12I O358	2w'2==+Cr}}U[G\"%OB ' o--r*   c                     t              r} | S t              }t        |t              r"t	        |j
                  |j                        } | S t        |      } | S rC   )callabler   rj   r   r   rV   r^   r   )r   ra   functions     r+   eval_fnzbind.<locals>.eval_fn+  sY    HB 	 $H-A!Y'QWWaff- 	 -Q/	r*   c               ?  Z   K    | |d      \  }}         |i |}|D ]  }|  y wNT)r  r)   r  r  r  r  evaledvalr  r  s         r+   wrappedzbind.<locals>.wrapped7  sA     ->wT.*M? WYAAF	 s   (+rN   c                l   K    | |d      \  }}         |i |}|2 3 d {   }| 7 
6 y wr  r)   r  s         r+   r  zbind.<locals>.wrappedA  sI     ->wT.*M? WYAAF# c	Vs   4202424c                 Z   K    | |d      \  }}         |i |}| d {   S 7 wr  r)   )r  r  r  r  r  r  r  s        r+   r  zbind.<locals>.wrappedK  s<     ->wT.*M? WYAAF<<s   !+)+c                 6     | |      \  }}         |i |S rC   r)   )r  r  r  r  r  r  s       r+   r  zbind.<locals>.wrappedS  s(    ->ug-N*M?79m???r*   )Fr)   )tupler   r   rj   r   r   	enumerater   r   r   r   r   r   __bound_function__re   rk   r   addr   setattr)r  rN   r   r   keyr   r   fn_depira   jr   kwargr   pkwr  
wrapper_fnr^   accessorr  r  s   ` ``               @@r+   r   r     s   > 	7$777=||~F~83!#&	&~F D& L !*F&)$(A%V $11h#AHH^$<=336uQCtA3/0 >XXd^113	E5:uQCuRD12 49%()L5%   A1h#AHH^$<=37:xt4s34 >hhtn224
U6;xt1SE23 59% L  .B	 ""8,	 :W9|959'B
#**		#	#H	-	 :W9|959'B
#**	X	&		-<	-u	-	  
.	  
	-<	-u	-	@ 
.	@ "*Gg&GJw',224hx01 5N[ 	Gs   Kc                      e Zd ZU dZi Zded<   dZded<   i Zded<   i Zd	ed
<   e		 dW	 	 	 	 	 dXd       Z
e	d        Ze	d        ZdW fd	Z	 	 dYdZedZd       Zed        Zej$                  d        Zed        Zd Zd[dZd[dZd\d]dZd Zd Zd Zd Zd Zd Zed        Zd^d Z fd!Z d" Z! fd#Z"d$ Z#d% Z$dd&d'Z%d( Z&d) Z'dWd*Z(d+ Z)d, Z*d- Z+d. Z,d/ Z-d0 Z.d1 Z/d2 Z0d3 Z1d4 Z2d5 Z3d6 Z4d7 Z5d8 Z6d9 Z7d: Z8d; Z9d< Z:d= Z;d> Z<d? Z=d@ Z>dA Z?dB Z@dC ZAdD ZBdE ZCdF ZDdG ZEdH ZFdI ZGdJ ZHdK ZIdL ZJdM ZKdN ZLdO ZMdP ZNdQ ZOdR ZPdS ZQdT ZRdU ZSdV ZT xZUS )_rk   a;  
    `rx` allows wrapping objects and then operating on them
    interactively while recording any operations applied to them. By
    recording all arguments or operands in the operations the recorded
    pipeline can be replayed if an operand represents a dynamic value.

    Parameters
    ----------
    obj: any
        A supported data structure object

    Examples
    --------
    Instantiate it from an object:

    >>> ifloat = rx(3.14)
    >>> ifloat * 2
    6.28

    Then update the original value and see the new result:
    >>> ifloat.value = 1
    2

    zdict[str, Callable[[rx], Any]]
_accessorsr)   z
tuple[str]_display_optionsz&dict[type, tuple[Any, dict[str, Any]]]_display_handlerszdict[str, Callable]_method_handlersc                &    ||f| j                   |<   y)a  
        Registers an accessor that extends rx with custom behavior.

        Arguments:
        ---------
        name: str
          The name of the accessor will be attribute-accessible under.
        accessor: Callable[[rx], any]
          A callable that will return the accessor namespace object
          given the rx object it is registered on.
        predicate: Callable[[Any], bool] | None

        N)r'  )r[   r^   r%  	predicates       r+   register_accessorzrx.register_accessor  s    $ !))4tr*   c                &    ||f| j                   |<   y)a%  
        Registers a display handler for a specific type of object,
        making it possible to define custom display options for
        specific objects.

        Arguments:
        ---------
        obj_type: type | callable
          The type to register a custom display handler on.
        handler: Viewable | callable
          A Viewable or callable that is given the object to be displayed
          and the custom keyword arguments.
        kwargs: dict[str, Any]
          Additional display options to register for this type.

        N)r)  )r[   obj_typehandlerr   s       r+   register_display_handlerzrx.register_display_handler  s    $ ,3F*;h'r*   c                "    || j                   |<   y)zk
        Registers a handler that is called when a specific method on
        an object is called.
        N)r*  )r[   methodr0  s      r+   register_method_handlerzrx.register_method_handler  s     (/V$r*   c                   d }t        |      }|j                  d      r$|j                  d      }|j                  dd       }nt        j                  |      st        |      r4t        |      }t        d |j                  j                        }t        }nt        |t        t        f      rt        |d      r|}d }nkt        |t              r.t        d |      }t!        |j"                  |j$                        }n-t'        |      }t        d |j                  j                        }t(        t*        | [  |       }||_        |j                  d|d n|g      |_        ||_        |S )	Nr   r   r   c                    | S rC   r)   rt   s    r+   rY   zrx.__new__.<locals>.<lambda>      #r*   r   c                    | S rC   r)   r7  s    r+   rY   zrx.__new__.<locals>.<lambda>  r8  r*   c                    | S rC   r)   r7  s    r+   rY   zrx.__new__.<locals>.<lambda>  r8  r*   _shared_obj)r   getr   r   r   r   r-   r   rD   r(   r   rj   r   r   r   r   r   rV   r^   r    r2   rk   __new___fnr;  r   )r[   rt   r   r   r   rZ   r8   s         r+   r=  z
rx.__new__  s$   !#&::dD!BjjT2G((-1DS1I ,Gow}}';';<BClJ78WS(=SBCY'os+B#))SXX.C S)Gow}}';';<BR%c*!::mS[TseTr*   c
           	     b    d _         i } j                  j                         D ]"  \  }}|j                         D ]
  \  }}|||<    $ |j	                   j
                  t        |      z   D ci c]  }||
v r||
j                  |       c}       | _        | _	        | _
        | _        |d u  _        d _        d  _        d  _        | _        t#        |t$              r
|s| _        n| _        |rCt)        |d         st+        j,                  |d         rt/        d       _        t2         _        nd  _         j5                          _         j9                          _         j=                          _         j>                  D cg c]\  }t#        |j@                  t.              r>|j@                  jB                  s(tE         fd|j@                  jF                  D              r|^ c} _$         jK                  |       |
 _&        tO                _(        d _         tS        j                         D ]  \  }}tU         | |               t$        jV                  j                         D ]0  \  }\  }}| | jX                        stU         | |              2 y c c}w c c}w )NFr   T)r4   c              3  :   K   | ]  }|j                   v  y wrC   )_internal_params)r   ra   r6   s     r+   r   zrx.__init__.<locals>.<genexpr>  s     O<NqAT222<Ns   )-_initr)  valuesr   r   r(  r  r   _display_opts_method
_operation_depth_dirty
_dirty_obj_current_task_error_state	_current_rj   rk   _prevr   r   r   r/   _triggerr   _compute_rootr   _compute_fn_params
_fn_params_compute_paramsrA  rV   r4   anyr5   r   _setup_invalidations_kwargsre   _rxr   r  r'  _current)r6   rt   	operationr   depthr3  prevr;  rW  r   r   display_optsr`   optskodoptra   r^   r%  r,  s   `                    r+   r3   zrx.__init__  sh    
--446GAt

1"#Q % 7 	/3/D/Du\GZ/Z
/Ztv~ &**T""/Z
 	 *#$&! !c2tDJDJ -io>'B]B]^ghl^mBn#T2DM&DN DM'')
113 $ 4 4 6 ,,
,!Z5QUVU\U\UeUeOAGG<N<NOO ,
 	!!%(%
0668ND(D$/ 9+-==+>+>+@'D'8Y Idmm$<dHTN3 ,AO
:
s   /J'A!J,c                    | j                   S )aw  
        The reactive namespace.

        Provides reactive versions of operations that cannot be made reactive through operator overloading, such as
        `.rx.and_` and `.rx.bool`. Calling this namespace (`()`) returns a reactive expression.

        Returns
        -------
        Reactive expression
            The result of calling the reactive namespace is a reactive expression.

        User Guide
        ----------
        https://param.holoviz.org/user_guide/Reactive_Expressions.html#special-methods-on-rx

        Examples
        --------
        Create a Parameterized instance:

        >>> import param
        >>> class P(param.Parameterized):
        ...     a = param.Number()
        >>> p = P(a=1)

        Get the current value:

        >>> a = p.param.a.rx.value

        Call it to get a reactive expression:

        >>> rx_value = p.param.a.rx()

        )rV  rl   s    r+   rk   zrx.rx  s    F xxr*   c                   | j                   t        | j                        | _        nK| j                  j
                  r5| j                  }t        |j                        |j                   d<   d|_        | j                   d   S )Nr   F)r;  r   r>  _objr   rI  r6   roots     r+   rb  zrx._obj*  se    #/9DIZZ""::D"9$(("CDQ#DO""r*   c                L    | j                   	|g| _         y || j                   d<   y r~   )r;  )r6   rt   s     r+   rb  zrx._obj4  s(    # #uD"%DQr*   c                    | j                   r| j                   | j                  s| j                  j                  r| j	                          | j
                  S rC   )rK  rH  r   rI  r   rL  rl   s    r+   rW  zrx._current;  s=    ###[[DJJ11MMO~~r*   c                p    | j                   | S | }|j                   |j                   }|j                   |S rC   )rM  rc  s     r+   rO  zrx._compute_rootC  s:    ::Kjj$::D jj$r*   c                   | j                   g S t        | j                         }|H|j                  j                  | j                   j                        D cg c]  }|j
                   }}|S t        | j                   di       }t        |j                  dg             }t        |j                  di       j                               }||z   S c c}w )Nr   r   r   )
r>  r   rD   method_dependenciesr$   pobjr   r   r<  rC  )r6   rV   r   r   dinfor   r   s          r+   rP  zrx._compute_fn_paramsK  s    88I *$)KK$C$CDHHDUDU$V$VS$V   K(B/EIInb12eiib)0023f}s   Cc                   t        | j                        }| j                  r/|j                  | j                  j                  j
                         | j                  }|6|j                  D ]  }||vs|j                  |        |j                  }|6| j                  |S t        | j                  d         D ]  }||vs|j                  |        t        | j                  d         t        | j                  d   j                               z   D ]*  }t        |d      D ]  }||vs|j                  |        , |S )Nr   r   r   T)rF   )r   rQ  rN  r]   rD   r:   rM  r   rF  r   rC  )r6   psrZ  ra   refr   s         r+   rR  zrx._compute_params[  s   $//"==IIdmm))//0 zz\\B;IIaL " ::D	  ??"I tt45C"}		# 6 /0dooh6O6V6V6X1YYC"3$7b=IIcN 8 Z
 	r*   c                   | j                   t        | j                  d       D ]o  \  }}|D cg c]'  }|| j                  j                  v s|j                  ) }}|s;|d   j
                  j                  j                  | j                  |d       q t        | j                  d       D ]R  \  }}|d   j
                  j                  j                  | j                  |D cg c]  }|j                   c}d       T yc c}w c c}w )a  
        Since the parameters of the pipeline can change at any time
        we have to invalidate the internal state of the pipeline.
        To handle both invalidations of the inputs of the pipeline
        and the pipeline itself we set up watchers on both.

        1. The first invalidation we have to set up is to re-evaluate
           the function that feeds the pipeline. Only the root node of
           a pipeline has to perform this invalidation because all
           leaf nodes inherit the same shared_obj. This avoids
           evaluating the same function for every branch of the pipeline.
        2. The second invalidation is for the pipeline itself, i.e.
           if any parameter changes we have to notify the pipeline that
           it has to re-evaluate the pipeline. This is done by marking
           the pipeline as `_dirty`. The next time the `_current` value
           is requested the value is resolved by re-executing the
           pipeline.
        Nc                ,    t        | j                        S rC   rT   rW   s    r+   rY   z)rx._setup_invalidations.<locals>.<lambda>  s    R[r*   r   r   c                ,    t        | j                        S rC   rT   rW   s    r+   rY   z)rx._setup_invalidations.<locals>.<lambda>  s    r!''{r*   )r>  r   rQ  r   r^   rV   rD   r   _invalidate_objrA  _invalidate_current)r6   rY  r`   r7   ra   fpss         r+   rT  zrx._setup_invalidationsv  s    & 88)$//;PQ	6'-Lv!djj6K6K1KqvvvL1IOO))001E1EsWY0Z R &d&;&;=RSIAv1IOO!!(()A)ATZC[TZqAFFTZC[hj(k T M D\s   DD$Dc                L     t         fd|D              ry d _        d  _        y )Nc              3  N   K   | ]  }|j                   j                  u   y wrC   )rt   rN  )r   eventr6   s     r+   r   z)rx._invalidate_current.<locals>.<genexpr>  s     >veuyyDMM)vs   "%T)r   rH  rK  r6   rH   s   ` r+   rt  zrx._invalidate_current  s#    >v>> r*   c                4    d| j                   _        d | _        y r   )r   rI  rK  ry  s     r+   rs  zrx._invalidate_obj  s     $

 r*   c                  K   t        j                         x| _        }t        j                  |      rH|2 3 d {   }| j                  |ur y || _        | j                  j                  j                  d       F| d {   }| j                  |u r-|| _        | j                  j                  j                  d       y y 7 6 y 7 Dwr   )	r   current_taskrJ  r   
isasyncgenrL  rN  rD   r   )r6   rt   taskr  r:   s        r+   _resolve_asynczrx._resolve_async  s     $+$8$8$::Tc"  5c%%T1!$##++G4IE!!T)!&##++G4 *5S s3   3CCCCAC CA CCCc                    ddl m} t        j                  |      rt	        |      } |t        | j                  |             y r   )r   r   r   isgeneratorr   r   r  )r6   rt   r   s      r+   _lazy_resolvezrx._lazy_resolve  s2    1s#$Cwt22C89r*   c                   | j                   r| j                   | j                  s| j                  j                  r	 | j                  | j
                  n| j                  j                         }|t        u s|t        u rt        | _	        t        | j                  }|rv| j                  ||      }t        j                  |      s*t        j                  |      st        j                  |      r| j!                  |       t        }|t        u rt        |x| _	        }n| j                  }d| _        | j$                  rt'        || j$                  |      }t)        |d      r/| j*                  j,                  | j*                  j.                  _        |S # t        $ r d| _        | j                  cY S t"        $ r}|| _         |d }~ww xY w)NFrp   )rK  rH  r   rI  rM  rb  r   r   r   rL  rF  _eval_operationr   r}  iscoroutiner  r  	ExceptionrE  r   r   rp   r'   __func__)r6   rt   rX  r   currents        r+   r   zrx._resolve  sj   ###[[DJJ11#'::#5dii4::;N;N;P$;#"2%.DNJ OO	..sI>C))#.'2E2Ec2JgNaNabeNf**3/"d{"
 (+*DNWnnG<<gt||W=G7J'-1]]-B-BDMM""*  &#~~% $%!s   CF G.G6	F??Gc                d   d}| j                   j                         D ]s  \  }\  }}| j                  j                         D ci c]  \  }}||v s|| }}}|j                  | j                         	  ||fi |}|sc ||fi |}	|	|usq|	c S  |S c c}}w # t
        $ r  ||      }Y 1w xY w)z4Applies custom display handlers before their output.F)r)  r   rD  r   rU  r   )
r6   rt   appliesr,  r0  r\  r]  r   r[  r   s
             r+   _transform_outputzrx._transform_output  s    *.*@*@*F*F*H&I!%!3!3!9!9!;!;AqDy1!;   -)#C8<8 c2\2c>J +I 
  )#C.)s   BB4	BB/.B/c                F      j                   } fd}|rt        |g| S |S )Nc                     j                   }j                  rt        |j                        }j                  |      S rC   )rW  rE  r   r  )r   r   outr6   s      r+   evaluatezrx._callback.<locals>.evaluate  s4    --C||c4<<0))#..r*   )r   r   )r6   r7   r  s   `  r+   	_callbackzrx._callback  s+    	/
 *6**r*   Fc           	        |xs | j                   }| j                  dz   }|r9t        | j                  f| j                  | j
                  | j                  d|}n!t        dd| it        | j                  fi |}t        | j                  fi |} t        |       | j                  f||| j                  | j                  | j                  d|S )Nr   )rW  r3  rZ  rZ  )rX  rY  r   r;  r   r)   )rF  rG  dictrU  rW  rE  rM  rD  typerb  r>  r;  r   )r6   rX  copyr   rY  s        r+   _clonez	rx._clone  s    0	a'+}}T\\ZZ#)F
 DtDtDLL'CF'CDFd((3F3tDzII
!*%DHH((4==
 
 	
r*   c           
        | j                   }| j                  rt        || j                        }t        |      D ch c]  }|j	                  d      r| }}	 t        t        t        | !               |z        S c c}w # t        $ rB t        t        t        t        |                   t        | j                        z  |z        cY S w xY w)Nr`   )rW  rE  r   dirr  sortedsetr2   __dir__r  r  __dict__)r6   r  attrextrasr8   s       r+   r  z
rx.__dir__   s    --<<gt||4G#&w<L<4ts7K$<L	N#ego/069:: M  	N#c$t*o.T]]1CCfLMM	Ns   A>A>"B ACCc                    | j                   s| j                  d      S t        | j                   fi dd}d | _         | j                  |      S )NTr  Fr   r   r   r   )rE  r  r   )r6   rX  s     r+   _resolve_accessorzrx._resolve_accessor
  sM    ||;;D;))
 \\O	
	 {{9%%r*   c                4   t         	|   d      }|j                  d      r|dk(  s|j                  d      rt         	|   |      S |d   }|d   }|r| j	                          |d   }|d   }|rt        ||      }t        |      D cg c]  }|j                  d      r| }}||v s|t        u rE|t         	| !         vr5| j                         }||_
        	 t        ||      j                  |_        |S t         	|   |      S c c}w # t        $ r Y |S w xY w)Nr  rB  rk   r`   rL  rH  rE  )r2   __getattribute__r<  r  r   r   r  r   r  r  rE  r'   r  )
r6   r^   	self_dictr  dirtyr3  r   r  r   r8   s
            r+   r  zrx.__getattribute__  s)   G,Z8	}}W%9M7+D11K((#MMO,G9%gv.G !\C\c1B!\CFNg2EGODU8U((*C CK%gt4<< Jw'-- D  Js   DDD
 
	DDc                l   | j                  d      }|j                  xs d}|dk(  r7| j                  dk(  r(t        | j                  d      s | j
                  |i |S |t        j                  v rt        j                  |   } ||       }d |_        t        |      }|||dd}|j                  |      S )NTr  rp   r   Fr  )	r  rE  rG  r   rW  set_displayrk   r*  r  )r6   r   r   r   r3  r0  rX  s          r+   rp   zrx.__call__7  s    kktk$*
ZDKK1$4WT]]T^=_#4##T4V44R((())&1GT]Ff	
	 zz)$$r*   c                l    | j                         }t        ||      |dd  |dd}|j                  |      S )Nr   Fr  )r  r   r  )r6   ufuncr3  r   r   r   rX  s          r+   __array_ufunc__zrx.__array_ufunc__N  sA    $$&%(H	
	 zz)$$r*   r   c               R    | j                         }||||d}|j                  |      S )Nr  )r  r  )r6   r   r   r   r   r   rX  s          r+   rw   zrx._apply_operatorX  s4    $$&	
	 zz)$$r*   c                ,    | j                  t              S rC   )rw   absrl   s    r+   __abs__z
rx.__abs__d      ##C((r*   c                ,    | j                  t              S rC   )rw   strrl   s    r+   __str__z
rx.__str__g  r  r*   c                >    |dn|f} | j                   t        g| S r1   )rw   round)r6   ndigitsr   s      r+   	__round__zrx.__round__j  s'    _r7*#t##E1D11r*   c                @    | j                  t        j                        S rC   )rw   mathceilrl   s    r+   __ceil__zrx.__ceil__o  s    ##DII..r*   c                @    | j                  t        j                        S rC   )rw   r  floorrl   s    r+   	__floor__zrx.__floor__q      ##DJJ//r*   c                @    | j                  t        j                        S rC   )rw   r   invrl   s    r+   
__invert__zrx.__invert__s      ##HLL11r*   c                @    | j                  t        j                        S rC   )rw   r   negrl   s    r+   __neg__z
rx.__neg__u  r  r*   c                @    | j                  t        j                        S rC   )rw   r   posrl   s    r+   __pos__z
rx.__pos__w  r  r*   c                @    | j                  t        j                        S rC   )rw   r  truncrl   s    r+   	__trunc__zrx.__trunc__y  r  r*   c                B    | j                  t        j                  |      S rC   rw   r   r  rx   s     r+   __add__z
rx.__add__}      ##HLL%88r*   c                B    | j                  t        j                  |      S rC   rw   r   ry   rx   s     r+   __and__z
rx.__and__  s    ##HMM599r*   c                B    | j                  t        j                  |      S rC   )rw   r   r   rx   s     r+   __contains_zrx.__contains_      ##H$5$5u==r*   c                .    | j                  t        |      S rC   rw   divmodrx   s     r+   
__divmod__zrx.__divmod__  s    ##FE22r*   c                B    | j                  t        j                  |      S rC   )rw   r   eqrx   s     r+   __eq__z	rx.__eq__      ##HKK77r*   c                B    | j                  t        j                  |      S rC   rw   r   floordivrx   s     r+   __floordiv__zrx.__floordiv__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   gerx   s     r+   __ge__z	rx.__ge__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   gtrx   s     r+   __gt__z	rx.__gt__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   lerx   s     r+   __le__z	rx.__le__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   ltrx   s     r+   __lt__z	rx.__lt__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   lshiftrx   s     r+   
__lshift__zrx.__lshift__      ##HOOU;;r*   c                B    | j                  t        j                  |      S rC   )rw   r   matmulrx   s     r+   
__matmul__zrx.__matmul__  r  r*   c                B    | j                  t        j                  |      S rC   rw   r   modrx   s     r+   __mod__z
rx.__mod__  r  r*   c                B    | j                  t        j                  |      S rC   rw   r   mulrx   s     r+   __mul__z
rx.__mul__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   nerx   s     r+   __ne__z	rx.__ne__  r  r*   c                B    | j                  t        j                  |      S rC   rw   r   r   rx   s     r+   __or__z	rx.__or__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   rshiftrx   s     r+   
__rshift__zrx.__rshift__  r  r*   c                B    | j                  t        j                  |      S rC   rw   r   powrx   s     r+   __pow__z
rx.__pow__  r  r*   c                B    | j                  t        j                  |      S rC   rw   r   subrx   s     r+   __sub__z
rx.__sub__  r  r*   c                B    | j                  t        j                  |      S rC   rw   r   truedivrx   s     r+   __truediv__zrx.__truediv__      ##H$4$4e<<r*   c                B    | j                  t        j                  |      S rC   rw   r   xorrx   s     r+   __xor__z
rx.__xor__  r  r*   c                F    | j                  t        j                  |d      S NTr   r  rx   s     r+   __radd__zrx.__radd__      ##HLL%#FFr*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rand__zrx.__rand__  s    ##HMM5$#GGr*   c                F    | j                  t        j                  |d      S r  )rw   r   divrx   s     r+   __rdiv__zrx.__rdiv__  r  r*   c                2    | j                  t        |d      S r  r  rx   s     r+   __rdivmod__zrx.__rdivmod__  s    ##FE4#@@r*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rfloordiv__zrx.__rfloordiv__  s     ##H$5$5ud#KKr*   c                B    | j                  t        j                  |      S rC   )rw   r   rlshiftrx   s     r+   __rlshift__zrx.__rlshift__  r  r*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rmod__zrx.__rmod__  r  r*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rmul__zrx.__rmul__  r  r*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __ror__z
rx.__ror__  r  r*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rpow__zrx.__rpow__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   rrshiftrx   s     r+   __rrshift__zrx.__rrshift__  r  r*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rsub__zrx.__rsub__  r  r*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rtruediv__zrx.__rtruediv__  s     ##H$4$4eT#JJr*   c                F    | j                  t        j                  |d      S r  r  rx   s     r+   __rxor__zrx.__rxor__  r  r*   c                B    | j                  t        j                  |      S rC   )rw   r   getitemrx   s     r+   __getitem__zrx.__getitem__  r  r*   c              #    K   t        | j                  t              r2	 	 | j                  t              }|j
                  j                   | 1t        | j                  t              s,t        dt        | j                        j                   d      | j                  t              }t        t        | j                              D ]	  }||     y # t        $ r Y y w xY ww)Nzcannot unpack non-iterable z object.)rj   rW  r   rw   nextrk   r:   RuntimeErrorr   r   r  r$   r   ranger   )r6   r   r   r   s       r+   __iter__zrx.__iter__  s     dmmX...t4CFFLL 	  DMM849$t}}:M:V:V9WW_`aa$$T*s4==)*A(N + $ s)   C$+C 
BC$	C!C$ C!!C$c                   |d   |d   |d   }}}g }|D ]4  }t        |      }|t        u s|t        u rt        |j                  |       6 i }	|j	                         D ]+  \  }
}t        |      }|t        u s|t        u rt        ||	|
<   - t        |t              r t        ||      |i |	}|S |j                  d      r ||d   |g|dd  i |	}|S  ||g|i |	}|S )Nr   r   r   r   r   r   )	r   r   r   r]   r   rj   r  r   r<  )r6   rt   rX  r   r   r   resolved_argsr   r  resolved_kwargsr]  s              r+   r  zrx._eval_operation  s   $T?If,=y?R&DC$Cd{cY.
  %	 
 llnFAs$Cd{cY.
!$OA	 %
 b#"'#r"ME_EC
 
	 ]]9%]1%sR]12->R/RC 
 S<=<O<C
r*   rC   )r^   r  r%  zCallable[[rx], Any]r,  zOptional[Callable[[Any], bool]])	NNNr   NNNNN)returnre   )rC  zlist[Parameter])r   )rY  r  r9   )Vr$   r%   r&   r'   r'  __annotations__r(  r)  r*  classmethodr-  r1  r4  r=  r3   r   rk   rb  r   rW  rO  rP  rR  rT  rt  rs  r  r  r   r  r  r  r  r  r  rp   r  rw   r  r  r  r  r  r  r  r  r  r  r  _rx__contains_r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r!  r#  r&  r(  r*  r,  r.  r1  r3  r5  r7  r:  r?  r  r;   r<   s   @r+   rk   rk   _  sa   2 24J.3#%j%@B=B,.). 6:55"5525 5& < <& / /> MQ2644l " "H # # 
[[& &   6l6!!5: D$ 	 	
"N& .:%.% 8= %))2
/022209:>38>8888<<9989<99=9GHGAL=GGGG=GKG= r*   rk   c                Z     t         t              s S t         fdg j                   S )Nc                 0    j                   j                  S rC   )rk   r:   )r`   rt   s    r+   rY   z_rx_transform.<locals>.<lambda>  s    366<<r*   )rj   rk   r   r   r7  s   `r+   _rx_transformrI    s'    c2
'6#++66r*   )2r'   
__future__r   r   r   r  r   collections.abcr   r   	functoolsr   typesr   r   typingr	   r
   r   r   displayr   r   r   r   r   r   r   r   r   r   r   r   r   r5   r   r   _utilsr   r   r   r    r-   r/   r>   rc   re   r   rk   rI  r)   r*   r+   <module>rQ     s   Pb #     .  * * *  ?   ' D D)m )( (%m %(} (V:X :
^- ^-B	 !& M`N
 N
b7
 ] +r*   