<s> from rosbridge_library . capability import Capability <EOL> from rosbridge_library . internal . publishers import manager <EOL> class Publish ( Capability ) : <EOL> publish_msg_fields = [ ( True , "<STR_LIT>" , ( str , unicode ) ) ] <EOL> def __init__ ( self , protocol ) : <EOL> Capability . __init__ ( self , protocol ) <EOL> protocol . register_operation ( "<STR_LIT>" , self . publish ) <EOL> self . _published = { } <EOL> def publish ( self , message ) : <EOL> self . basic_type_check ( message , self . publish_msg_fields ) <EOL> topic = message [ "<STR_LIT>" ] <EOL> latch = message . get ( "<STR_LIT>" , False ) <EOL> queue_size = message . get ( "<STR_LIT>" , <NUM_LIT:100> ) <EOL> client_id = self . protocol . client_id <EOL> manager . register ( client_id , topic , latch = latch , queue_size = queue_size ) <EOL> self . _published [ topic ] = True <EOL> msg = message . get ( "<STR_LIT>" , { } ) <EOL> manager . publish ( client_id , topic , msg , latch = latch , queue_size = queue_size ) <EOL> def finish ( self ) : <EOL> client_id = self . protocol . client_id <EOL> for topic in self . _published : <EOL> manager . unregister ( client_id , topic ) <EOL> self . _published . clear ( ) </s>
