U
    ª€ljƒ  ã                   @   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eee edœd	d
„Zeegef ee ee dœdd„Zee ee edœdd„Zeeegef eeegef dœdd„Zeegef eegef eegef dœdd„ZeejeeeƒedƒƒƒZeee ged f ed< eegef eg ee f edœdd„Zeegef eg ef dœ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k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   úB/tmp/pip-unpacked-wheel-aghyhbke/twisted/trial/_dist/functional.pyÚfromOptional   s    r   )Ú	conditionÚxsr   c                 c   s"   |D ]}| |ƒr|V  q qq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Úbr   c                 Ã   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   )Úfr   c                    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Úfyr   c                    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Úactionr   c                 Ã   s   |ƒ I dH }| |ƒs |S q dS )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}.
    Nr   )r'   r(   Úresultr   r   r   ÚiterateWhileX   s    r*   c                    s   d‰ t dœ‡ ‡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 5 ˆ d7 ‰ X | S )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   Ztwisted.internet.deferr	   r
   r   r   r   r   Úboolr   r   r!   r%   ZfromCoroutiner&   Ú__annotations__r*   Úintr.   r   r   r   r   Ú<module>   s(   $(0þý