<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import msgpack <EOL> import salt . ext . six as six <EOL> def frame_msg ( body , header = None , raw_body = False ) : <EOL> '''<STR_LIT>''' <EOL> framed_msg = { } <EOL> if header is None : <EOL> header = { } <EOL> framed_msg [ '<STR_LIT>' ] = header <EOL> framed_msg [ '<STR_LIT:body>' ] = body <EOL> return msgpack . dumps ( framed_msg ) <EOL> def frame_msg_ipc ( body , header = None , raw_body = False ) : <EOL> '''<STR_LIT>''' <EOL> framed_msg = { } <EOL> if header is None : <EOL> header = { } <EOL> framed_msg [ '<STR_LIT>' ] = header <EOL> framed_msg [ '<STR_LIT:body>' ] = body <EOL> if six . PY2 : <EOL> return msgpack . dumps ( framed_msg ) <EOL> else : <EOL> return msgpack . dumps ( framed_msg , use_bin_type = True ) <EOL> def _decode_embedded_list ( src ) : <EOL> '''<STR_LIT>''' <EOL> output = [ ] <EOL> for elem in src : <EOL> if isinstance ( elem , dict ) : <EOL> elem = _decode_embedded_dict ( elem ) <EOL> elif isinstance ( elem , list ) : <EOL> elem = _decode_embedded_list ( elem ) <EOL> elif isinstance ( elem , bytes ) : <EOL> try : <EOL> elem = elem . decode ( ) <EOL> except UnicodeError : <EOL> pass <EOL> output . append ( elem ) <EOL> return output <EOL> def _decode_embedded_dict ( src ) : <EOL> '''<STR_LIT>''' <EOL> output = { } <EOL> for key , val in six . iteritems ( src ) : <EOL> if isinstance ( val , dict ) : <EOL> val = _decode_embedded_dict ( val ) <EOL> elif isinstance ( val , list ) : <EOL> val = _decode_embedded_list ( val ) <EOL> elif isinstance ( val , bytes ) : <EOL> try : <EOL> val = val . decode ( ) <EOL> except UnicodeError : <EOL> pass <EOL> if isinstance ( key , bytes ) : <EOL> try : <EOL> key = key . decode ( ) <EOL> except UnicodeError : <EOL> pass <EOL> output [ key ] = val <EOL> return output <EOL> def decode_embedded_strs ( src ) : <EOL> '''<STR_LIT>''' <EOL> if not six . PY3 : <EOL> return src <EOL> if isinstance ( src , dict ) : <EOL> return _decode_embedded_dict ( src ) <EOL> elif isinstance ( src , list ) : <EOL> return _decode_embedded_list ( src ) <EOL> elif isinstance ( src , bytes ) : <EOL> try : <EOL> return src . decode ( ) <EOL> except UnicodeError : <EOL> return src <EOL> else : <EOL> return src </s>
