<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> from tornado . escape import json_decode <EOL> from . . exceptions import ProtocolError <EOL> from . import messages <EOL> from . import versions <EOL> class Protocol ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , version ) : <EOL> if version not in versions . spec : <EOL> raise ProtocolError ( "<STR_LIT>" % version ) <EOL> self . _version = version <EOL> self . _messages = dict ( ) <EOL> for msgtype , revision in versions . spec [ version ] : <EOL> self . _messages [ msgtype ] = messages . index [ ( msgtype , revision ) ] <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . version <EOL> def create ( self , msgtype , * args , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if msgtype not in self . _messages : <EOL> raise ProtocolError ( "<STR_LIT>" % ( msgtype , self . _version ) ) <EOL> return self . _messages [ msgtype ] . create ( * args , ** kwargs ) <EOL> def assemble ( self , header_json , metadata_json , content_json ) : <EOL> '''<STR_LIT>''' <EOL> header = json_decode ( header_json ) <EOL> if '<STR_LIT>' not in header : <EOL> log . error ( "<STR_LIT>" , header ) <EOL> raise ProtocolError ( "<STR_LIT>" ) <EOL> return self . _messages [ header [ '<STR_LIT>' ] ] . assemble ( <EOL> header_json , metadata_json , content_json <EOL> ) <EOL> @ property <EOL> def version ( self ) : <EOL> return self . _version </s>
