Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 6acd0df

Browse files
committed
Support 2.7 types
1 parent 3af1d7a commit 6acd0df

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

azure/eventhub/async_ops/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import asyncio
88
import time
99
import datetime
10-
try:
11-
from urllib import urlparse, unquote_plus, urlencode, quote_plus
12-
except ImportError:
13-
from urllib.parse import urlparse, unquote_plus, urlencode, quote_plus
10+
from urllib.parse import urlparse, unquote_plus, urlencode, quote_plus
1411

1512
from uamqp import authentication, constants, types, errors
1613
from uamqp import (

azure/eventhub/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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

67
import logging
78
import datetime
@@ -10,10 +11,12 @@
1011
import time
1112
import functools
1213
try:
13-
from urllib import urlparse, unquote_plus, urlencode, quote_plus
14+
from urlparse import urlparse
15+
from urllib import unquote_plus, urlencode, quote_plus
1416
except ImportError:
1517
from urllib.parse import urlparse, unquote_plus, urlencode, quote_plus
1618

19+
import six
1720
import uamqp
1821
from uamqp import Message
1922
from uamqp import authentication

azure/eventhub/common.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
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

67
import datetime
78
import time
89
import json
910

11+
import six
12+
1013
from uamqp import Message, BatchMessage
1114
from uamqp import types, constants, errors
1215
from 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_types) 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:]

azure/eventhub/receiver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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

67
import uuid
78
import logging
@@ -106,7 +107,7 @@ def reconnect(self):
106107
# pylint: disable=protected-access
107108
alt_creds = {
108109
"username": self.client._auth_config.get("iot_username"),
109-
"password":self.client._auth_config.get("iot_password")}
110+
"password": self.client._auth_config.get("iot_password")}
110111
self._handler.close()
111112
source = Source(self.source)
112113
if self.offset is not None:

azure/eventhub/sender.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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

67
import uuid
78
import logging

0 commit comments

Comments
 (0)