<s> from handshake import * <EOL> class HeartbeatMessage ( object ) : <EOL> HeartbeatRequest = <NUM_LIT:1> <EOL> HeartbeatReponse = <NUM_LIT:2> <EOL> message_types = { <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> <NUM_LIT:2> : '<STR_LIT>' <EOL> } <EOL> def __init__ ( self ) : <EOL> self . bytes = '<STR_LIT>' <EOL> @ classmethod <EOL> def create ( cls , message_type , payload , length = - <NUM_LIT:1> , padding = None ) : <EOL> self = cls ( ) <EOL> if length < <NUM_LIT:0> : <EOL> length = len ( payload ) <EOL> if padding is None : <EOL> padding = '<STR_LIT:*>' * <NUM_LIT:16> <EOL> self . bytes = struct . pack ( '<STR_LIT>' % ( len ( payload ) , len ( padding ) ) , <EOL> message_type , <EOL> length , <EOL> payload , <EOL> padding ) <EOL> return self <EOL> @ classmethod <EOL> def from_bytes ( cls , bytes ) : <EOL> self = cls ( ) <EOL> self . bytes = bytes <EOL> return self <EOL> class HeartbeatExtension ( TLSExtension ) : <EOL> PeerAllowedToSend = <NUM_LIT:1> <EOL> PeerNotAllowedToSend = <NUM_LIT:2> <EOL> def __init__ ( self ) : <EOL> TLSExtension . __init__ ( self ) <EOL> @ classmethod <EOL> def create ( cls , allowed = PeerAllowedToSend ) : <EOL> data = struct . pack ( '<STR_LIT>' , <NUM_LIT:1> , allowed ) <EOL> return TLSExtension . create ( TLSExtension . Heartbeat , data ) </s>
