Ϫf UdZddlmZmZddlmZmZmZmZm Z ddl m Z m Z e dZ e dZe dZde d ee d e fd Zd ee gefd ee d ee fdZdee deed efdZdee egefd eee geffdZdeegefdee gefd ee geffdZee j,eeee dZeee ge dfed<dee gefdegee fd e fdZdeege fd ege ffdZy)z1 General functional-style helpers for disttrial. )partialwraps) AwaitableCallableIterableOptionalTypeVar)Deferredsucceed_A_B_Cdefaultoptionalreturnc||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. )rrs @/usr/lib/python3/dist-packages/twisted/trial/_dist/functional.py fromOptionalrs O conditionxsc#6K|D]}||r|yyw)z :return: An iterable over C{xs} that stops when C{condition} returns ``False`` based on the value of iterated C{xs}. Nr)rrxs r takeWhilers&  Q<G  sabc:K|d{|d{S77w)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)rrs rsequencer+s GG7N s fc.tfd}|S)zc Create a function like another but with the order of the first two arguments flipped. c||SNr)rrr s rgzflip..g<sAwrr)r r$s` rflipr&6s"  1X HrfxfycNttfd}|S)z Create a function that calls one function with an argument and then another function with the result of the first function. c |Sr#r)rr'r(s rr$zcompose..gIs"Q%yrr%)r'r(r$s`` rcomposer+Cs.  2Y 2Y HrN discardResult predicateactioncDK |d{}||s|S7w)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.results r iterateWhiler1Xs) x M s  c(ddtffd }|S)z Wrap a function with another that automatically passes an integer counter of the number of calls that have gone through the wrapper. rrc8 }dz |S#dz wxYw)Nr)r0counterr s rr$zcountingCalls..grs, wZF qLG  qLGs)r )r r$r5s` @r countingCallsr6ks Gr Hr)__doc__ functoolsrrtypingrrrrr twisted.internet.deferr r r r rrboolrrr&r+ fromCoroutiner,__annotations__r1intr6rrrr?s%CC4 T] T] T] "    2$*- 8B< HRL im " "  Hb"Xr\ "  xR" '=    "r"  "r(:  xb?Q