<s> """<STR_LIT>""" <EOL> try : <EOL> import simplejson as json <EOL> _ = json <EOL> except ImportError : <EOL> import json <EOL> from pyleus . storm import StormWentAwayError <EOL> from pyleus . storm . serializers . serializer import Serializer <EOL> class JSONSerializer ( Serializer ) : <EOL> def read_msg ( self ) : <EOL> """<STR_LIT>""" <EOL> lines = [ ] <EOL> while True : <EOL> line = self . _input_stream . readline ( ) <EOL> if not line : <EOL> raise StormWentAwayError ( ) <EOL> line = line . strip ( ) <EOL> if line == "<STR_LIT:end>" : <EOL> break <EOL> lines . append ( line ) <EOL> msg_str = '<STR_LIT:\n>' . join ( lines ) <EOL> return json . loads ( msg_str ) <EOL> def send_msg ( self , msg_dict ) : <EOL> """<STR_LIT>""" <EOL> self . _output_stream . write ( json . dumps ( msg_dict ) + '<STR_LIT>' ) <EOL> self . _output_stream . flush ( ) </s>
