o
    >h                     @   s  U d Z ddlmZmZ ddlmZmZmZmZm	Z	 ddl
mZmZ e	dZe	dZe	dZded	ee d
efddZdeegef dee d
ee fddZdee dee d
efddZdeeegef d
eeegef fddZdeegef deegef d
eegef fddZeejeeeedZeee ged f ed< deegef deg ee f d
efd d!Zdeegef d
eg ef fd"d#ZdS )$z1
General functional-style helpers for disttrial.
    )partialwraps)	AwaitableCallableIterableOptionalTypeVar)Deferredsucceed_A_B_Cdefaultoptionalreturnc                 C   s   |du r| S |S )z
    Get a definite value from an optional value.

    @param default: The value to return if the optional value is missing.

    @param optional: The optional value to return if it exists.
    N )r   r   r   r   ~/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/trial/_dist/functional.pyfromOptional   s   r   	conditionxsc                 c   s$    |D ]}| |r|V  q dS dS )z
    :return: An iterable over C{xs} that stops when C{condition} returns
        ``False`` based on the value of iterated C{xs}.
    Nr   )r   r   xr   r   r   	takeWhile   s   r   abc                    s   | I dH  |I dH S )z
    Wait for one action to complete and then another.

    If either action fails, failure is propagated.  If the first action fails,
    the second action is not waited on.
    Nr   )r   r   r   r   r   sequence+   s   

r   fc                    s   t   fdd}|S )zc
    Create a function like another but with the order of the first two
    arguments flipped.
    c                    s
    || S Nr   )r   r   r   r   r   g<   s   
zflip.<locals>.gr   r   r   r   r   r   flip6   s   r!   fxfyc                    s"   t  t  fdd}|S )z
    Create a function that calls one function with an argument and then
    another function with the result of the first function.
    c                    s    | S r   r   )r   r"   r#   r   r   r   I   s   zcompose.<locals>.gr   )r"   r#   r   r   r$   r   composeC   s   r%   NdiscardResult	predicateactionc                    s   	 | I dH }| |s|S q)z
    Call a function repeatedly until its result fails to satisfy a predicate.

    @param predicate: The check to apply.

    @param action: The function to call.

    @return: The result of C{action} which did not satisfy C{predicate}.
    TNr   )r'   r(   resultr   r   r   iterateWhileX   s   r*   c                    s   d dt f fdd}|S )z
    Wrap a function with another that automatically passes an integer counter
    of the number of calls that have gone through the wrapper.
    r   r   c                     s"   z } W  d7  | S  d7  w )N   r   )r)   counterr   r   r   r   r   s
   

zcountingCalls.<locals>.g)r   r    r   r,   r   countingCallsk   s   r.   )__doc__	functoolsr   r   typingr   r   r   r   r   twisted.internet.deferr	   r
   r   r   r   r   boolr   r   r!   r%   fromCoroutiner&   __annotations__r*   intr.   r   r   r   r   <module>   s0   (*4
(