Skip to content

Commit c5d9015

Browse files
Making use of existing python2to3.py
1 parent 6cda055 commit c5d9015

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

xbee/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414
import struct, threading, time
1515
from xbee.frame import APIFrame
16-
from xbee.python2to3 import byteToInt, intToByte
16+
from xbee.python2to3 import byteToInt, intToByte, stringToBytes
1717

1818
class ThreadQuitException(Exception):
1919
pass
@@ -182,7 +182,7 @@ def _build_command(self, cmd, **kwargs):
182182
# Read this field's name from the function arguments dict
183183
data = kwargs[field['name']]
184184
if isinstance(data, str):
185-
data = str.encode(data)
185+
data = stringToBytes(data)
186186

187187
except KeyError:
188188
# Data wasn't given

xbee/python2to3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
Helper functions for handling Python 2 and Python 3 datatype shenanigans.
77
"""
8+
import sys
89

910
def byteToInt(byte):
1011
"""
@@ -31,4 +32,4 @@ def stringToBytes(s):
3132
3233
Converts a string into an appropriate bytes object
3334
"""
34-
return s.encode('ascii')
35+
return s.encode('ascii') if sys.version_info >= (3, 0) else s

0 commit comments

Comments
 (0)