<s> import json <EOL> from tempodb . temporal . validate import convert_iso_stamp <EOL> def make_generator ( d ) : <EOL> """<STR_LIT>""" <EOL> for i in d : <EOL> yield i <EOL> def check_response ( resp ) : <EOL> """<STR_LIT>""" <EOL> s = resp . status <EOL> if s != <NUM_LIT:200> : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % s ) <EOL> class Cursor ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data , t , response ) : <EOL> self . response = response <EOL> self . type = t <EOL> self . data = make_generator ( <EOL> [ self . type ( d , self . response ) for d in data ] ) <EOL> def __iter__ ( self ) : <EOL> while True : <EOL> try : <EOL> x = self . data . next ( ) <EOL> yield x <EOL> except StopIteration : <EOL> self . _fetch_next ( ) <EOL> def _fetch_next ( self ) : <EOL> raise StopIteration <EOL> class DataPointCursor ( Cursor ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data , t , response , tz = None ) : <EOL> self . response = response <EOL> self . type = t <EOL> self . tz = tz <EOL> self . rollup = data . get ( '<STR_LIT>' ) <EOL> self . start = convert_iso_stamp ( data . get ( '<STR_LIT:start>' ) ) <EOL> self . end = convert_iso_stamp ( data . get ( '<STR_LIT:end>' ) ) <EOL> self . data = make_generator ( <EOL> [ self . type ( d , self . response , tz = tz ) for d in data [ '<STR_LIT:data>' ] ] ) <EOL> def _fetch_next ( self ) : <EOL> try : <EOL> link = self . response . resp . links [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] <EOL> except KeyError : <EOL> raise StopIteration <EOL> n = self . response . session . get ( link ) <EOL> from tempodb . response import Response <EOL> self . response = Response ( n , self . response . session ) <EOL> check_response ( self . response ) <EOL> j = json . loads ( n . text ) <EOL> self . data = make_generator ( <EOL> [ self . type ( d , self . response , tz = self . tz ) for d in j [ '<STR_LIT:data>' ] ] ) <EOL> class SeriesCursor ( Cursor ) : <EOL> """<STR_LIT>""" <EOL> def _fetch_next ( self ) : <EOL> try : <EOL> link = self . response . resp . links [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] <EOL> except KeyError : <EOL> raise StopIteration <EOL> n = self . response . session . get ( link ) <EOL> from tempodb . response import Response <EOL> self . response = Response ( n , self . response . session ) <EOL> check_response ( self . response ) <EOL> j = json . loads ( n . text ) <EOL> self . data = make_generator ( <EOL> [ self . type ( d , self . response ) for d in j ] ) <EOL> class SingleValueCursor ( Cursor ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
