Skip to content

Instantly share code, notes, and snippets.

@altendky
Created August 16, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altendky/1fd7e1eb44a4a2c6a3c08a56150f4258 to your computer and use it in GitHub Desktop.
Save altendky/1fd7e1eb44a4a2c6a3c08a56150f4258 to your computer and use it in GitHub Desktop.
diff --git a/sunspec/core/client.py b/sunspec/core/client.py
index b2d825b..ed730d3 100644
--- a/sunspec/core/client.py
+++ b/sunspec/core/client.py
@@ -21,6 +21,7 @@
IN THE SOFTWARE.
"""
from __future__ import division
+oldstr = str
from builtins import str
from builtins import object
from past.utils import old_div
@@ -403,7 +404,7 @@ def model_class_get(model_id):
class_name = 'Model' + str(model_id)
class_ = globals().get(class_name)
if class_ is None:
- class_ = type(class_name, (SunSpecClientModelBase,), {'__init__' : class_init})
+ class_ = type(oldstr(class_name), (SunSpecClientModelBase,), {'__init__' : class_init})
globals()[class_name] = class_
setattr(class_, 'points', [])
@@ -422,7 +423,7 @@ def model_class_get(model_id):
block_type = model_type.repeating_block
if block_type is not None:
block_class_name = class_name + 'Repeating'
- block_class = type(block_class_name, (SunSpecClientBlockBase,), {'__init__' : block_class_init})
+ block_class = type(oldstr(block_class_name), (SunSpecClientBlockBase,), {'__init__' : block_class_init})
globals()[block_class_name] = block_class
setattr(block_class, 'points', [])
diff --git a/sunspec/core/data.py b/sunspec/core/data.py
index 3df93c1..9d60b13 100644
--- a/sunspec/core/data.py
+++ b/sunspec/core/data.py
@@ -20,6 +20,7 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
"""
+oldstr = str
from builtins import str
from builtins import object
@@ -235,7 +236,7 @@ class ModelData(object):
def to_xml(self, parent):
- attr = {SDX_MODEL_ID: str(self.model_id)}
+ attr = {SDX_MODEL_ID: oldstr(self.model_id)}
if self.index > 1:
attr[SDX_MODEL_INDEX] = self.index
@@ -277,7 +278,7 @@ class PointData(object):
def to_xml(self, parent):
- attr = {SDX_POINT_ID: str(self.point_id)}
+ attr = {SDX_POINT_ID: self.point_id}#.decode('UTF-8')}
if self.index:
attr[SDX_POINT_INDEX] = str(self.index)
diff --git a/sunspec/core/modbus/mbmap.py b/sunspec/core/modbus/mbmap.py
index 8e627a7..0b4e690 100644
--- a/sunspec/core/modbus/mbmap.py
+++ b/sunspec/core/modbus/mbmap.py
@@ -206,7 +206,7 @@ class ModbusMap(object):
elif rtype == MBMAP_REGS_TYPE_STRING:
if rlen == 0:
rlen = old_div((len(text) + 3),4)
- data = struct.pack(str(rlen * 2) + 's', str(text))
+ data = struct.pack(str(rlen * 2) + 's', text)
elif rtype == MBMAP_REGS_TYPE_HEX_STRING:
if text:
# remove any spaces
diff --git a/sunspec/core/test/test_data.py b/sunspec/core/test/test_data.py
index ed17008..273b03d 100644
--- a/sunspec/core/test/test_data.py
+++ b/sunspec/core/test/test_data.py
@@ -21,6 +21,7 @@
IN THE SOFTWARE.
"""
from __future__ import print_function
+oldstr = str
from builtins import str
import sys
diff --git a/sunspec/core/util.py b/sunspec/core/util.py
index 4708479..bad1784 100644
--- a/sunspec/core/util.py
+++ b/sunspec/core/util.py
@@ -20,6 +20,7 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
"""
+oldstr = str
from builtins import str
from builtins import object
@@ -137,7 +138,7 @@ def float_to_data(f, len=None):
def str_to_data(s, slen=None):
if slen is None:
slen = len(s)
- return struct.pack(str(slen) + 's', s)
+ return struct.pack(str(slen) + 's', oldstr(s))
def eui48_to_data(eui48):
return ('0000' + eui48.replace(':', '')).decode('hex')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment