55from .address_helper import AddressHelper
66from .common import CommonValues , QueueType
77from .entities import (
8- BindingSpecification ,
98 ExchangeSpecification ,
9+ ExchangeToExchangeBindingSpecification ,
10+ ExchangeToQueueBindingSpecification ,
1011 QueueInfo ,
1112)
1213from .exceptions import ValidationCodeException
@@ -301,12 +302,25 @@ def _validate_reponse_code(
301302 "wrong response code received: " + str (response_code )
302303 )
303304
304- def bind (self , bind_specification : BindingSpecification ) -> str :
305+ def bind (
306+ self ,
307+ bind_specification : Union [
308+ ExchangeToQueueBindingSpecification , ExchangeToExchangeBindingSpecification
309+ ],
310+ ) -> str :
305311 logger .debug ("Bind Operation called" )
312+
306313 body = {}
307- body ["binding_key" ] = bind_specification .binding_key
314+ if bind_specification .binding_key is not None :
315+ body ["binding_key" ] = bind_specification .binding_key
316+ else :
317+ body ["binding_key" ] = ""
308318 body ["source" ] = bind_specification .source_exchange
309- body ["destination_queue" ] = bind_specification .destination_queue
319+ if isinstance (bind_specification , ExchangeToQueueBindingSpecification ):
320+ body ["destination_queue" ] = bind_specification .destination_queue
321+ elif isinstance (bind_specification , ExchangeToExchangeBindingSpecification ):
322+ body ["destination_exchange" ] = bind_specification .destination_exchange
323+
310324 body ["arguments" ] = {} # type: ignore
311325
312326 path = AddressHelper .path_address ()
@@ -319,17 +333,43 @@ def bind(self, bind_specification: BindingSpecification) -> str:
319333 CommonValues .response_code_204 .value ,
320334 ],
321335 )
336+ binding_path = ""
322337
323- binding_path_with_queue = AddressHelper .binding_path_with_exchange_queue (
324- bind_specification
325- )
326- return binding_path_with_queue
338+ if isinstance (bind_specification , ExchangeToQueueBindingSpecification ):
339+ binding_path = AddressHelper .binding_path_with_exchange_queue (
340+ bind_specification
341+ )
342+ elif isinstance (bind_specification , ExchangeToExchangeBindingSpecification ):
343+ binding_path = AddressHelper .binding_path_with_exchange_exchange (
344+ bind_specification
345+ )
327346
328- def unbind (self , binding_exchange_queue_path : str ) -> None :
347+ return binding_path
348+
349+ def unbind (
350+ self ,
351+ bind_specification : Union [
352+ str ,
353+ ExchangeToQueueBindingSpecification ,
354+ ExchangeToExchangeBindingSpecification ,
355+ ],
356+ ) -> None :
329357 logger .debug ("UnBind Operation called" )
358+ binding_name = ""
359+ if isinstance (bind_specification , str ):
360+ binding_name = bind_specification
361+ else :
362+ if isinstance (bind_specification , ExchangeToQueueBindingSpecification ):
363+ binding_name = AddressHelper .binding_path_with_exchange_queue (
364+ bind_specification
365+ )
366+ elif isinstance (bind_specification , ExchangeToExchangeBindingSpecification ):
367+ binding_name = AddressHelper .binding_path_with_exchange_exchange (
368+ bind_specification
369+ )
330370 self .request (
331371 None ,
332- binding_exchange_queue_path ,
372+ binding_name ,
333373 CommonValues .command_delete .value ,
334374 [
335375 CommonValues .response_code_204 .value ,
0 commit comments