
    Pf.                     b    d Z ddlmZ ddlmZ g dZd Zd Zd Zd Z	dd
Z
d Zd Zd Zd Zd	S )zFunctional utilities.   )Thenablepromise)maybe_promiseensure_promiseppartialpreplaceready_promisestarpromise	transformwrapc                 R    | r$t          | t                    st          |           S | S )zBReturn None if p is undefined, otherwise make sure it's a promise.)
isinstancer   r   ps    ?/var/www/html/env/lib/python3.11/site-packages/vine/funtools.pyr   r      s-     !X&& 	1::H    c                 @    | t                      S t          |           S )zeEnsure p is a promise.

    If p is not a promise, a new promise is created with p' as callback.
    )r   r   r   s    r   r   r      s!    
 	yyyr   c                 ~    t          |           } |r|| j        z   | _        |r| j                            |           | S )z-Create/modify promise with partial arguments.)r   argskwargsupdate)r   r   r   s      r   r   r      sE    qA   	Hr   c                 4      fd}t          |          S )zReplace promise arguments.

    This will force the promise to disregard any arguments
    the promise is fulfilled with, and to be called with the
    provided arguments instead.
    c                       i S N )___r   r   r   s     r   	_replacerzpreplace.<locals>._replacer/   s    q$!&!!!r   r   )r   r   r   r   s   ``` r   r	   r	   (   s6    " " " " " " "9r   Nc                 .    t          |           } ||  |S )z)Create promise that is already fulfilled.)r   )callbackr   r   s      r   r
   r
   4   s    x  AAtHHHr   c                 $    t          | ||          S )z%Create promise, using star arguments.r   )funr   r   s      r   r   r   ;   s    3f%%%r   c                     t          |          }t          t          | |||f          }|                    t                      |j                   |S )a?  Filter final argument to a promise.

    E.g. to coerce callback argument to :class:`int`::

        transform(int, callback)

    or a more complex example extracting something from a dict
    and coercing the value to :class:`float`:

    .. code-block:: python

        def filter_key_value(key, filter_, mapping):
            return filter_(mapping[key])

        def get_page_expires(self, url, callback=None):
            return self.request(
                'GET', url,
                callback=transform(get_key, callback, 'PageExpireValue', int),
            )

    )r   r   
_transbackthenthrow)filter_r!   filter_argsfilter_kwargsPs        r   r   r   @   sH    , h''H
Wh]KLLAFF799hn%%%Hr   c                 |    	  | ||fz   i |} ||          S # t           $ r |                                 Y d S w xY wr   )	Exceptionr'   )r(   r!   r   r   rets        r   r%   r%   \   sg    gtsf}/// x}}    s    ;;c                       fd}|S )zWrap promise.

    This wraps the promise such that if the promise is called with a promise as
    argument, we attach ourselves to that promise instead.
    c                      t          |           dk    r6t          | d         t                    r| d                                       S  | i |S )Nr       )lenr   r   r&   )r   r   r   s     r   on_callzwrap.<locals>.on_callk   sM    t99>>ja'::>7<<??"1d%f%%%r   r   )r   r3   s   ` r   r   r   e   s#    & & & & & Nr   r   )__doc__abstractr   promisesr   __all__r   r   r   r	   r
   r   r   r%   r   r   r   r   <module>r8      s                         	 	 	   & & &
  8      r   