22# Copyright (c) Microsoft Corporation. All rights reserved.
33# Licensed under the MIT License. See License.txt in the project root for license information.
44# --------------------------------------------------------------------------------------------
5+ from __future__ import unicode_literals
56
67import datetime
78import time
89import json
910
11+ import six
12+
1013from uamqp import Message , BatchMessage
1114from uamqp import types , constants , errors
1215from uamqp .message import MessageHeader , MessageProperties
@@ -63,6 +66,8 @@ def __init__(self, body=None, batch=None, to_device=None, message=None):
6366 :type body: str, bytes or list
6467 :param batch: A data generator to send batched messages.
6568 :type batch: Generator
69+ :param to_device: An IoT device to route to.
70+ :type to_device: str
6671 :param message: The received message.
6772 :type message: ~uamqp.message.Message
6873 """
@@ -94,7 +99,7 @@ def sequence_number(self):
9499 """
95100 The sequence number of the event data object.
96101
97- :rtype: int
102+ :rtype: int or long
98103 """
99104 return self ._annotations .get (EventData .PROP_SEQ_NUMBER , None )
100105
@@ -103,7 +108,7 @@ def offset(self):
103108 """
104109 The offset of the event data object.
105110
106- :rtype: int
111+ :rtype: ~azure.eventhub.common.Offset
107112 """
108113 try :
109114 return Offset (self ._annotations [EventData .PROP_OFFSET ].decode ('UTF-8' ))
@@ -200,13 +205,13 @@ def body_as_str(self, encoding='UTF-8'):
200205
201206 :param encoding: The encoding to use for decoding message data.
202207 Default is 'UTF-8'
203- :rtype: str
208+ :rtype: str or unicode
204209 """
205210 data = self .body
206211 try :
207212 return "" .join (b .decode (encoding ) for b in data )
208213 except TypeError :
209- return str (data )
214+ return six . text_type (data )
210215 except : # pylint: disable=bare-except
211216 pass
212217 try :
@@ -269,7 +274,7 @@ def selector(self):
269274 if isinstance (self .value , datetime .datetime ):
270275 timestamp = (time .mktime (self .value .timetuple ()) * 1000 ) + (self .value .microsecond / 1000 )
271276 return ("amqp.annotation.x-opt-enqueued-time {} '{}'" .format (operator , int (timestamp ))).encode ('utf-8' )
272- if isinstance (self .value , int ):
277+ if isinstance (self .value , six . integer_types ):
273278 return ("amqp.annotation.x-opt-sequence-number {} '{}'" .format (operator , self .value )).encode ('utf-8' )
274279 return ("amqp.annotation.x-opt-offset {} '{}'" .format (operator , self .value )).encode ('utf-8' )
275280
@@ -310,7 +315,7 @@ def __init__(self, message, details=None):
310315
311316 def _parse_error (self , error_list ):
312317 details = []
313- self .message = error_list if isinstance (error_list , str ) else error_list .decode ('UTF-8' )
318+ self .message = error_list if isinstance (error_list , six . text_type ) else error_list .decode ('UTF-8' )
314319 details_index = self .message .find (" Reference:" )
315320 if details_index >= 0 :
316321 details_msg = self .message [details_index + 1 :]
0 commit comments