2
2
# Copyright (c) Microsoft Corporation. All rights reserved.
3
3
# Licensed under the MIT License. See License.txt in the project root for license information.
4
4
# --------------------------------------------------------------------------------------------
5
+ from __future__ import unicode_literals
5
6
6
7
import datetime
7
8
import time
8
9
import json
9
10
11
+ import six
12
+
10
13
from uamqp import Message , BatchMessage
11
14
from uamqp import types , constants , errors
12
15
from uamqp .message import MessageHeader , MessageProperties
@@ -63,6 +66,8 @@ def __init__(self, body=None, batch=None, to_device=None, message=None):
63
66
:type body: str, bytes or list
64
67
:param batch: A data generator to send batched messages.
65
68
:type batch: Generator
69
+ :param to_device: An IoT device to route to.
70
+ :type to_device: str
66
71
:param message: The received message.
67
72
:type message: ~uamqp.message.Message
68
73
"""
@@ -94,7 +99,7 @@ def sequence_number(self):
94
99
"""
95
100
The sequence number of the event data object.
96
101
97
- :rtype: int
102
+ :rtype: int or long
98
103
"""
99
104
return self ._annotations .get (EventData .PROP_SEQ_NUMBER , None )
100
105
@@ -103,7 +108,7 @@ def offset(self):
103
108
"""
104
109
The offset of the event data object.
105
110
106
- :rtype: int
111
+ :rtype: ~azure.eventhub.common.Offset
107
112
"""
108
113
try :
109
114
return Offset (self ._annotations [EventData .PROP_OFFSET ].decode ('UTF-8' ))
@@ -200,13 +205,13 @@ def body_as_str(self, encoding='UTF-8'):
200
205
201
206
:param encoding: The encoding to use for decoding message data.
202
207
Default is 'UTF-8'
203
- :rtype: str
208
+ :rtype: str or unicode
204
209
"""
205
210
data = self .body
206
211
try :
207
212
return "" .join (b .decode (encoding ) for b in data )
208
213
except TypeError :
209
- return str (data )
214
+ return six . text_type (data )
210
215
except : # pylint: disable=bare-except
211
216
pass
212
217
try :
@@ -269,7 +274,7 @@ def selector(self):
269
274
if isinstance (self .value , datetime .datetime ):
270
275
timestamp = (time .mktime (self .value .timetuple ()) * 1000 ) + (self .value .microsecond / 1000 )
271
276
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 ):
273
278
return ("amqp.annotation.x-opt-sequence-number {} '{}'" .format (operator , self .value )).encode ('utf-8' )
274
279
return ("amqp.annotation.x-opt-offset {} '{}'" .format (operator , self .value )).encode ('utf-8' )
275
280
@@ -310,7 +315,7 @@ def __init__(self, message, details=None):
310
315
311
316
def _parse_error (self , error_list ):
312
317
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' )
314
319
details_index = self .message .find (" Reference:" )
315
320
if details_index >= 0 :
316
321
details_msg = self .message [details_index + 1 :]
0 commit comments