<s> from __future__ import with_statement <EOL> from . base import ConsumerBase , check_callable <EOL> from . . utils import json <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class SyncConsumer ( ConsumerBase ) : <EOL> def wait_once ( self , cb = None , ** params ) : <EOL> if cb is not None : <EOL> check_callable ( cb ) <EOL> params . update ( { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> resp = self . db . res . get ( "<STR_LIT>" , ** params ) <EOL> buf = "<STR_LIT>" <EOL> with resp . body_stream ( ) as body : <EOL> while True : <EOL> data = body . read ( ) <EOL> if not data : <EOL> break <EOL> buf += data <EOL> ret = json . loads ( buf ) <EOL> if cb is not None : <EOL> cb ( ret ) <EOL> return <EOL> return ret <EOL> def wait ( self , cb , ** params ) : <EOL> check_callable ( cb ) <EOL> params . update ( { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> resp = self . db . res . get ( "<STR_LIT>" , ** params ) <EOL> with resp . body_stream ( ) as body : <EOL> while True : <EOL> try : <EOL> line = body . readline ( ) <EOL> if not line : <EOL> break <EOL> if line . endswith ( "<STR_LIT:\r\n>" ) : <EOL> line = line [ : - <NUM_LIT:2> ] <EOL> else : <EOL> line = line [ : - <NUM_LIT:1> ] <EOL> if not line : <EOL> continue <EOL> cb ( json . loads ( line ) ) <EOL> except ( KeyboardInterrupt , SystemExit , ) : <EOL> break </s>
