<s> import random <EOL> from calvin . utilities . calvinlogger import get_logger <EOL> _log = get_logger ( __name__ ) <EOL> class PauseIteration ( Exception ) : <EOL> def __init__ ( self ) : <EOL> super ( PauseIteration , self ) . __init__ ( ) <EOL> class FailedElement ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( FailedElement , self ) . __init__ ( ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class FinalElement ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( FinalElement , self ) . __init__ ( ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class InfiniteElement ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( InfiniteElement , self ) . __init__ ( ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class DynOps ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( DynOps , self ) . __init__ ( ) <EOL> self . _trigger = None <EOL> self . infinite_set = False <EOL> self . infinite_sent = False <EOL> self . cb_args = [ ] <EOL> self . cb_kwargs = { } <EOL> self . name = "<STR_LIT>" <EOL> def set_name ( self , name ) : <EOL> self . name = name <EOL> return self <EOL> def set_cb ( self , trigger , * args , ** kwargs ) : <EOL> self . cb_args = args <EOL> self . cb_kwargs = kwargs <EOL> self . _trigger = trigger <EOL> def miss_cb_str ( self ) : <EOL> return "<STR_LIT>" if self . _trigger else "<STR_LIT>" <EOL> def trig ( self ) : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) ) ) <EOL> if self . _trigger : <EOL> self . _trigger ( * self . cb_args , ** self . cb_kwargs ) <EOL> def trigger_add ( self , iters ) : <EOL> for i in iters : <EOL> if hasattr ( i , '<STR_LIT>' ) : <EOL> i . set_cb ( self . trig ) <EOL> def op ( self ) : <EOL> """<STR_LIT>""" <EOL> raise StopIteration <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> if self . infinite_set : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> if self . infinite_sent : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> raise StopIteration <EOL> else : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> self . infinite_sent = True <EOL> return InfiniteElement <EOL> return self . op ( ) <EOL> def __next__ ( self ) : <EOL> return self . next ( ) <EOL> def __repr__ ( self ) : <EOL> return self . __str__ ( ) <EOL> class Union ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * iters ) : <EOL> super ( Union , self ) . __init__ ( ) <EOL> self . iters = [ iter ( v ) for v in iters ] <EOL> self . infinite_set = any ( [ True for v in self . iters if getattr ( v , '<STR_LIT>' , False ) ] ) <EOL> self . set = [ ] <EOL> self . trigger_add ( self . iters ) <EOL> self . final = False <EOL> if self . infinite_set : <EOL> self . trig ( ) <EOL> self . final = True <EOL> return <EOL> def op ( self ) : <EOL> paused = False <EOL> for v in self . iters : <EOL> try : <EOL> while True : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , str ( v ) ) ) <EOL> n = v . next ( ) <EOL> if n not in self . set : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , str ( n ) , str ( v ) ) ) <EOL> self . set . append ( n ) <EOL> return n <EOL> except PauseIteration : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , str ( v ) ) ) <EOL> paused = True <EOL> except StopIteration : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , str ( v ) ) ) <EOL> pass <EOL> if paused : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , ) ) <EOL> raise PauseIteration <EOL> else : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , ) ) <EOL> self . final = True <EOL> raise StopIteration <EOL> def __str__ ( self ) : <EOL> s = "<STR_LIT>" <EOL> for i in self . iters : <EOL> sub = i . __str__ ( ) <EOL> for line in sub . splitlines ( ) : <EOL> s += "<STR_LIT>" + line <EOL> s += "<STR_LIT:U+002CU+0020>" <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> "<STR_LIT>" if self . infinite_set else "<STR_LIT>" , <EOL> "<STR_LIT:#>" if self . final else "<STR_LIT:->" , self . miss_cb_str ( ) , s [ : - <NUM_LIT:2> ] ) <EOL> class Intersection ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * iters ) : <EOL> super ( Intersection , self ) . __init__ ( ) <EOL> self . iters = [ iter ( v ) for v in iters if not getattr ( v , '<STR_LIT>' , False ) ] <EOL> self . set = set ( [ ] ) <EOL> self . candidates = set ( [ ] ) <EOL> self . drawn = { id ( k ) : set ( [ ] ) for k in self . iters } <EOL> self . final = { id ( k ) : False for k in self . iters } <EOL> self . infs = { id ( k ) : False for k in self . iters } <EOL> self . trigger_add ( self . iters ) <EOL> self . _final = False <EOL> if len ( self . iters ) == <NUM_LIT:0> and len ( iters ) > <NUM_LIT:0> : <EOL> self . infinite_set = True <EOL> self . trig ( ) <EOL> def op ( self ) : <EOL> if self . candidates : <EOL> e = self . candidates . pop ( ) <EOL> self . set . add ( e ) <EOL> return e <EOL> while True : <EOL> active = False <EOL> for v in self . iters : <EOL> if not self . final [ id ( v ) ] : <EOL> try : <EOL> n = v . next ( ) <EOL> if isinstance ( n , InfiniteElement ) : <EOL> self . infs [ id ( v ) ] = True <EOL> self . final [ id ( v ) ] = True <EOL> self . drawn [ id ( v ) ] . add ( n ) <EOL> active = True <EOL> except PauseIteration : <EOL> pass <EOL> except StopIteration : <EOL> self . final [ id ( v ) ] = True <EOL> if all ( self . infs . values ( ) ) : <EOL> self . infinite_set = True <EOL> if self . infinite_sent : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> raise StopIteration <EOL> else : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> self . infinite_sent = True <EOL> return InfiniteElement <EOL> self . candidates . update ( set . intersection ( * [ self . drawn [ id ( v ) ] for v in self . iters if not self . infs [ id ( v ) ] ] ) ) <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> "<STR_LIT>" if self . infinite_set else "<STR_LIT>" , <EOL> "<STR_LIT:#>" if self . _final else "<STR_LIT:->" , self . candidates , self . drawn . values ( ) , self . infs . values ( ) ) ) <EOL> for v in self . drawn . values ( ) : <EOL> v . difference_update ( self . candidates ) <EOL> self . candidates . difference_update ( self . set ) <EOL> if self . candidates : <EOL> e = self . candidates . pop ( ) <EOL> self . set . add ( e ) <EOL> return e <EOL> if not active or all ( self . final . values ( ) ) : <EOL> break <EOL> if all ( [ self . final [ id ( v ) ] for v in self . iters ] ) : <EOL> self . _final = True <EOL> raise StopIteration <EOL> else : <EOL> raise PauseIteration <EOL> def __str__ ( self ) : <EOL> s = "<STR_LIT>" <EOL> for i in self . iters : <EOL> sub = i . __str__ ( ) <EOL> for line in sub . splitlines ( ) : <EOL> s += "<STR_LIT>" + line <EOL> s += "<STR_LIT:U+002CU+0020>" <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> "<STR_LIT>" if self . infinite_set else "<STR_LIT>" , <EOL> "<STR_LIT:#>" if self . _final else "<STR_LIT:->" , self . miss_cb_str ( ) , s [ : - <NUM_LIT:2> ] , self . set , self . candidates ) <EOL> class Difference ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , first , * iters ) : <EOL> super ( Difference , self ) . __init__ ( ) <EOL> self . first = iter ( first ) <EOL> if getattr ( self . first . infinite_set , '<STR_LIT>' , False ) : <EOL> raise NotImplemented <EOL> self . iters = [ iter ( v ) for v in iters ] <EOL> self . zero_set = any ( [ True for v in self . iters if getattr ( v , '<STR_LIT>' , False ) ] ) <EOL> self . trigger_add ( [ self . first ] + self . iters ) <EOL> self . set = [ ] <EOL> self . remove = set ( [ ] ) <EOL> self . final = { id ( k ) : False for k in self . iters } <EOL> def op ( self ) : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> if self . zero_set : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> raise StopIteration <EOL> if all ( self . final . values ( ) ) : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , str ( self . remove ) ) ) <EOL> while True : <EOL> n = self . first . next ( ) <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , str ( n ) ) ) <EOL> if n not in self . remove : <EOL> self . remove . add ( n ) <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , str ( n ) ) ) <EOL> return n <EOL> paused = False <EOL> for v in self . iters : <EOL> try : <EOL> while True : <EOL> self . remove . add ( v . next ( ) ) <EOL> except PauseIteration : <EOL> paused = True <EOL> except StopIteration : <EOL> self . final [ id ( v ) ] = True <EOL> if paused : <EOL> raise PauseIteration <EOL> else : <EOL> return self . op ( ) <EOL> def __str__ ( self ) : <EOL> s = "<STR_LIT>" <EOL> for i in self . iters : <EOL> sub = i . __str__ ( ) <EOL> for line in sub . splitlines ( ) : <EOL> s += "<STR_LIT>" + line <EOL> s += "<STR_LIT:U+002CU+0020>" <EOL> f = "<STR_LIT>" <EOL> sub = self . first . __str__ ( ) <EOL> for line in sub . splitlines ( ) : <EOL> f += "<STR_LIT>" + line <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , "<STR_LIT>" if self . infinite_set else "<STR_LIT>" , <EOL> f , self . miss_cb_str ( ) , s [ : - <NUM_LIT:2> ] ) <EOL> class Map ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def identity ( out_iter , kwargs , final , * elems ) : <EOL> if len ( elems ) > <NUM_LIT:1> : <EOL> out_iter . extend ( [ tuple ( * elems ) ] ) <EOL> else : <EOL> out_iter . append ( elems [ <NUM_LIT:0> ] ) <EOL> def __init__ ( self , func , * iters , ** kwargs ) : <EOL> super ( Map , self ) . __init__ ( ) <EOL> self . func = func or Map . identity <EOL> self . eager = kwargs . pop ( '<STR_LIT>' , False ) <EOL> self . kwargs = kwargs <EOL> self . iters = [ iter ( v ) for v in iters ] <EOL> self . drawn = { id ( k ) : [ ] for k in self . iters } <EOL> self . final = { id ( k ) : False for k in self . iters } <EOL> self . trigger_add ( self . iters ) <EOL> self . out_iter = List ( ) <EOL> self . during_next = False <EOL> def get_kwargs ( self ) : <EOL> return self . kwargs <EOL> def out_trig ( self ) : <EOL> if not self . during_next : <EOL> self . trig ( ) <EOL> def set_cb ( self , trigger , * args , ** kwargs ) : <EOL> self . cb_args = args <EOL> self . cb_kwargs = kwargs <EOL> self . _trigger = trigger <EOL> self . out_iter . _trigger = self . out_trig <EOL> def trig ( self ) : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) ) ) <EOL> if self . eager : <EOL> try : <EOL> while True : <EOL> self . _op ( True ) <EOL> except : <EOL> pass <EOL> if self . _trigger : <EOL> self . _trigger ( * self . cb_args , ** self . cb_kwargs ) <EOL> def _op ( self , eager = False ) : <EOL> self . during_next = True <EOL> while True : <EOL> active = False <EOL> for v in self . iters : <EOL> if not self . final [ id ( v ) ] : <EOL> try : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , self . func . __name__ , str ( v ) ) ) <EOL> e = v . next ( ) <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , self . func . __name__ , e ) ) <EOL> self . drawn [ id ( v ) ] . append ( e ) <EOL> active = True <EOL> except PauseIteration : <EOL> pass <EOL> except StopIteration : <EOL> self . final [ id ( v ) ] = True <EOL> except Exception as e : <EOL> _log . exception ( "<STR_LIT>" ) <EOL> raise e <EOL> try : <EOL> l = min ( [ len ( self . drawn [ id ( i ) ] ) for i in self . iters if not self . final [ id ( i ) ] ] ) <EOL> except ValueError : <EOL> l = <NUM_LIT:0> <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , self . func . __name__ , l , self . final . values ( ) ) ) <EOL> for i in range ( l ) : <EOL> try : <EOL> self . func ( self . out_iter , self . kwargs , [ self . final [ id ( i ) ] for i in self . iters ] , <EOL> * [ None if self . final [ id ( i ) ] else self . drawn [ id ( i ) ] . pop ( <NUM_LIT:0> ) for i in self . iters ] ) <EOL> except PauseIteration : <EOL> break <EOL> except StopIteration : <EOL> self . final = { id ( k ) : True for k in self . iters } <EOL> except Exception as e : <EOL> _log . exception ( "<STR_LIT>" ) <EOL> raise e <EOL> if all ( self . final . values ( ) ) : <EOL> try : <EOL> self . func ( self . out_iter , self . kwargs , self . final . values ( ) , <EOL> * ( [ None ] * len ( self . iters ) ) ) <EOL> except PauseIteration : <EOL> pass <EOL> except StopIteration : <EOL> pass <EOL> except Exception as e : <EOL> _log . exception ( "<STR_LIT>" ) <EOL> raise e <EOL> if not eager : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> self . func . __name__ , self . out_iter ) ) <EOL> try : <EOL> e = self . out_iter . next ( ) <EOL> except StopIteration : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> self . func . __name__ ) ) <EOL> self . during_next = False <EOL> raise StopIteration <EOL> except PauseIteration : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> self . func . __name__ ) ) <EOL> self . during_next = False <EOL> raise PauseIteration <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> self . func . __name__ , e ) ) <EOL> self . during_next = False <EOL> return e <EOL> if not active or all ( self . final . values ( ) ) : <EOL> self . during_next = False <EOL> raise Exception ( ) <EOL> def op ( self ) : <EOL> self . during_next = True <EOL> try : <EOL> n = self . out_iter . next ( ) <EOL> self . during_next = False <EOL> return n <EOL> except PauseIteration : <EOL> return self . _op ( ) <EOL> def __str__ ( self ) : <EOL> s = "<STR_LIT>" <EOL> for i in self . iters : <EOL> sub = i . __str__ ( ) <EOL> for line in sub . splitlines ( ) : <EOL> s += "<STR_LIT>" + line <EOL> s += "<STR_LIT:U+002CU+0020>" <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , <EOL> "<STR_LIT:#>" if self . out_iter . _final else "<STR_LIT:->" , self . miss_cb_str ( ) , <EOL> self . func . __name__ , s [ : - <NUM_LIT:2> ] , self . out_iter . __str__ ( ) ) <EOL> class Chain ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , it ) : <EOL> super ( Chain , self ) . __init__ ( ) <EOL> self . it = iter ( it ) <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> self . elem_it = iter ( [ ] ) <EOL> self . trigger_add ( [ self . it ] ) <EOL> def op ( self ) : <EOL> try : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , str ( self . elem_it ) ) ) <EOL> e = self . elem_it . next ( ) <EOL> _log . debug ( "<STR_LIT>" % ( ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , str ( e ) ) ) ) <EOL> return e <EOL> except StopIteration : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , str ( self . elem_it ) ) ) <EOL> try : <EOL> self . elem_it = self . it . next ( ) <EOL> except StopIteration : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , str ( self . it ) ) ) <EOL> raise StopIteration <EOL> except PauseIteration : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , str ( self . it ) ) ) <EOL> raise PauseIteration <EOL> except Exception as e : <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , str ( self . it ) ) , exc_info = True ) <EOL> raise e <EOL> _log . debug ( "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , str ( self . elem_it ) ) ) <EOL> return self . op ( ) <EOL> def __str__ ( self ) : <EOL> f = "<STR_LIT>" <EOL> sub = self . it . __str__ ( ) <EOL> for line in sub . splitlines ( ) : <EOL> f += "<STR_LIT>" + line <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , self . miss_cb_str ( ) , f ) <EOL> class Collect ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , it , keyed = True ) : <EOL> super ( Collect , self ) . __init__ ( ) <EOL> self . it = iter ( it ) <EOL> self . it_final = False <EOL> self . keyed = keyed <EOL> self . iters = [ ] <EOL> self . trigger_add ( [ self . it ] ) <EOL> def fill_iters ( self ) : <EOL> if self . it_final : <EOL> return <EOL> while True : <EOL> try : <EOL> self . iters . append ( self . it . next ( ) ) <EOL> except StopIteration : <EOL> self . it_final = True <EOL> break <EOL> except : <EOL> break <EOL> def op ( self ) : <EOL> self . fill_iters ( ) <EOL> if self . it_final and not self . iters : <EOL> raise StopIteration <EOL> iters_copy = self . iters <EOL> random . shuffle ( iters_copy ) <EOL> for elem in iters_copy : <EOL> key , it = elem if self . keyed else ( None , elem ) <EOL> try : <EOL> e = it . next ( ) <EOL> return ( key , e ) if self . keyed else e <EOL> except PauseIteration : <EOL> continue <EOL> except StopIteration : <EOL> self . iters . remove ( elem ) <EOL> continue <EOL> raise PauseIteration <EOL> def __str__ ( self ) : <EOL> f = "<STR_LIT>" <EOL> sub = self . it . __str__ ( ) <EOL> for line in sub . splitlines ( ) : <EOL> f += "<STR_LIT>" + line <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , self . miss_cb_str ( ) , f ) <EOL> class List ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , elems = None ) : <EOL> super ( List , self ) . __init__ ( ) <EOL> self . list = elems if elems else [ ] <EOL> self . _final = False <EOL> self . index = <NUM_LIT:0> <EOL> self . max_length = float ( "<STR_LIT>" ) <EOL> def append ( self , elem , trigger_iter = None ) : <EOL> """<STR_LIT>""" <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , elem ) ) <EOL> if not self . _final : <EOL> self . list . append ( elem ) <EOL> self . trigger_add ( [ trigger_iter if trigger_iter else elem ] ) <EOL> self . trig ( ) <EOL> def extend ( self , elems , trigger_iters = None ) : <EOL> """<STR_LIT>""" <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , elems ) ) <EOL> if not self . _final : <EOL> self . list . extend ( elems ) <EOL> self . trigger_add ( trigger_iters if trigger_iters else elems ) <EOL> self . trig ( ) <EOL> def final ( self ) : <EOL> if not self . _final : <EOL> self . _final = True <EOL> self . trig ( ) <EOL> def auto_final ( self , max_length ) : <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , <EOL> max_length , self . index , str ( self . _final ) , str ( self . _trigger ) ) ) <EOL> self . max_length = max_length <EOL> if self . index >= self . max_length : <EOL> self . final ( ) <EOL> def op ( self ) : <EOL> if self . index >= self . max_length : <EOL> self . _final = True <EOL> raise StopIteration <EOL> try : <EOL> e = self . list [ self . index ] <EOL> _log . debug ( "<STR_LIT>" % ( self . __str__ ( ) , e ) ) <EOL> self . index += <NUM_LIT:1> <EOL> return e <EOL> except : <EOL> if self . _final : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> raise StopIteration <EOL> else : <EOL> _log . debug ( "<STR_LIT>" % self . __str__ ( ) ) <EOL> raise PauseIteration <EOL> def __str__ ( self ) : <EOL> s = "<STR_LIT>" <EOL> c = <NUM_LIT:0> <EOL> for i in self . list : <EOL> sub = i . __str__ ( ) <EOL> p = True <EOL> for line in sub . splitlines ( ) : <EOL> s += "<STR_LIT>" if c == self . index and p else "<STR_LIT>" <EOL> p = False <EOL> s += line <EOL> s += "<STR_LIT:U+002CU+0020>" <EOL> c += <NUM_LIT:1> <EOL> s = s [ : - <NUM_LIT:2> ] <EOL> s += "<STR_LIT>" if c == self . index else "<STR_LIT>" <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , "<STR_LIT:#>" if self . _final else "<STR_LIT:->" , <EOL> self . miss_cb_str ( ) , s ) <EOL> class Infinite ( DynOps ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( Infinite , self ) . __init__ ( ) <EOL> self . infinite_set = True <EOL> def op ( self ) : <EOL> raise StopIteration <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( ( "<STR_LIT:<>" + self . name + "<STR_LIT:>>" ) if self . name else "<STR_LIT>" , self . miss_cb_str ( ) , ) <EOL> import pprint <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> def gotit ( ) : <EOL> print "<STR_LIT>" <EOL> try : <EOL> for i in d : <EOL> print i <EOL> except PauseIteration : <EOL> print "<STR_LIT>" <EOL> l1 = List ( ) <EOL> def map_func ( it , kwargs , final , * iters ) : <EOL> if all ( final ) : <EOL> it . final ( ) <EOL> else : <EOL> print kwargs , iters <EOL> it . append ( sum ( [ <NUM_LIT:0> if i is None else i for i in iters ] ) + kwargs [ '<STR_LIT>' ] ) <EOL> kwargs [ '<STR_LIT>' ] += <NUM_LIT:10> <EOL> d = Map ( map_func , l1 , eager = True , bias = <NUM_LIT:100> ) <EOL> d . set_cb ( gotit ) <EOL> l1 . append ( <NUM_LIT:1> ) <EOL> l1 . extend ( [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> l1 . final ( ) <EOL> """<STR_LIT>""" </s>
