o
    Óó·iƒ  ã                   @   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   údC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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>.gN©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>.gNr   )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>.gN)r   r    r   r,   r   ÚcountingCallsk   s   r.   )Ú__doc__Ú	functoolsr   r   Útypingr   r   r   r   r   Ztwisted.internet.deferr	   r
   r   r   r   r   Úboolr   r   r!   r%   ZfromCoroutiner&   Ú__annotations__r*   Úintr.   r   r   r   r   Ú<module>   s0   (*4þÿþ
ý(