8484from ._common import millis2secs , secs2millis
8585from ._data import AnnotationDict , Data , char , symbol , ulong
8686from ._endpoints import Link
87- from ._exceptions import EXCEPTIONS , MessageException
87+ from ._exceptions import EXCEPTIONS , MessageException , ArgumentOutOfRangeException
8888
8989if TYPE_CHECKING :
9090 from proton ._data import Described , PythonAMQPData
@@ -110,17 +110,26 @@ class Message(object):
110110 """ Default AMQP message priority"""
111111
112112 def __init__ (
113- self ,
114- body : Union [
115- bytes , str , dict , list , int , float , "UUID" , "Described" , None
116- ] = None ,
117- ** kwargs
113+ self ,
114+ body : Union [
115+ bytes , dict , None
116+ ] = None ,
117+ ** kwargs
118118 ) -> None :
119+ # validate the types
120+
121+ if not isinstance (body , (bytes , dict , type (None ))):
122+ raise ArgumentOutOfRangeException (
123+ "Message body must be of type bytes, dict or None"
124+ )
125+
119126 self ._msg = pn_message ()
120127 self .instructions = None
121128 self .annotations = None
122129 self .properties = None
123130 self .body = body
131+ self .inferred = True
132+
124133 for k , v in kwargs .items ():
125134 getattr (self , k ) # Raise exception if it's not a valid attribute.
126135 setattr (self , k , v )
@@ -236,7 +245,8 @@ def inferred(self) -> bool:
236245
237246 :raise: :exc:`MessageException` if there is any Proton error when using the setter.
238247 """
239- return pn_message_is_inferred (self ._msg )
248+ x = pn_message_is_inferred (self ._msg )
249+ return x
240250
241251 @inferred .setter
242252 def inferred (self , value : bool ) -> None :
@@ -503,7 +513,7 @@ def instructions(self) -> Optional[AnnotationDict]:
503513
504514 @instructions .setter
505515 def instructions (
506- self , instructions : Optional [Dict [Union [str , int ], "PythonAMQPData" ]]
516+ self , instructions : Optional [Dict [Union [str , int ], "PythonAMQPData" ]]
507517 ) -> None :
508518 if isinstance (instructions , dict ):
509519 self .instruction_dict = AnnotationDict (instructions , raise_on_error = False )
@@ -526,7 +536,7 @@ def annotations(self) -> Optional[AnnotationDict]:
526536
527537 @annotations .setter
528538 def annotations (
529- self , annotations : Optional [Dict [Union [str , int ], "PythonAMQPData" ]]
539+ self , annotations : Optional [Dict [Union [str , int ], "PythonAMQPData" ]]
530540 ) -> None :
531541 if isinstance (annotations , dict ):
532542 self .annotation_dict = AnnotationDict (annotations , raise_on_error = False )
@@ -593,7 +603,8 @@ def send(self, sender: "Sender", tag: Optional[str] = None) -> "Delivery":
593603 return dlv
594604
595605 @overload
596- def recv (self , link : "Sender" ) -> None : ...
606+ def recv (self , link : "Sender" ) -> None :
607+ ...
597608
598609 def recv (self , link : "Receiver" ) -> Optional ["Delivery" ]:
599610 """
@@ -624,24 +635,24 @@ def recv(self, link: "Receiver") -> Optional["Delivery"]:
624635 def __repr__ (self ) -> str :
625636 props = []
626637 for attr in (
627- "inferred" ,
628- "address" ,
629- "reply_to" ,
630- "durable" ,
631- "ttl" ,
632- "priority" ,
633- "first_acquirer" ,
634- "delivery_count" ,
635- "id" ,
636- "correlation_id" ,
637- "user_id" ,
638- "group_id" ,
639- "group_sequence" ,
640- "reply_to_group_id" ,
641- "instructions" ,
642- "annotations" ,
643- "properties" ,
644- "body" ,
638+ "inferred" ,
639+ "address" ,
640+ "reply_to" ,
641+ "durable" ,
642+ "ttl" ,
643+ "priority" ,
644+ "first_acquirer" ,
645+ "delivery_count" ,
646+ "id" ,
647+ "correlation_id" ,
648+ "user_id" ,
649+ "group_id" ,
650+ "group_sequence" ,
651+ "reply_to_group_id" ,
652+ "instructions" ,
653+ "annotations" ,
654+ "properties" ,
655+ "body" ,
645656 ):
646657 value = getattr (self , attr )
647658 if value :
0 commit comments