PyData, PyGeometryData encoding/decoding fix

This commit is contained in:
Michael James 2018-10-05 17:11:49 -06:00
parent 49fd731b44
commit 5be5677888
2 changed files with 16 additions and 15 deletions

View file

@ -1,6 +1,3 @@
##
##
# #
# Implements IData for use by native Python clients to the Data Access # Implements IData for use by native Python clients to the Data Access
# Framework. # Framework.
@ -11,6 +8,7 @@
# Date Ticket# Engineer Description # Date Ticket# Engineer Description
# ------------ ---------- ----------- -------------------------- # ------------ ---------- ----------- --------------------------
# 06/03/13 dgilling Initial Creation. # 06/03/13 dgilling Initial Creation.
# 10/05/18 mjames@ucar Encode/decode attribute names.
# #
# #
@ -25,7 +23,8 @@ class PyData(IData):
self.__attributes = dataRecord.getAttributes() self.__attributes = dataRecord.getAttributes()
def getAttribute(self, key): def getAttribute(self, key):
return self.__attributes[key] value = self.__attributes[key.encode('utf-8')]
return value.decode('utf-8')
def getAttributes(self): def getAttributes(self):
return list(self.__attributes.keys()) return list(self.__attributes.keys())

View file

@ -1,6 +1,3 @@
##
##
# #
# Implements IGeometryData for use by native Python clients to the Data Access # Implements IGeometryData for use by native Python clients to the Data Access
# Framework. # Framework.
@ -16,6 +13,7 @@
# is called for data that is not a # is called for data that is not a
# numeric Type. # numeric Type.
# 06/09/16 5574 mapeters Handle 'SHORT' type in getNumber(). # 06/09/16 5574 mapeters Handle 'SHORT' type in getNumber().
# 10/05/18 mjames@ucar Encode/decode string, number val, and type
# #
# #
@ -39,25 +37,29 @@ class PyGeometryData(IGeometryData, PyData.PyData):
return list(self.__dataMap.keys()) return list(self.__dataMap.keys())
def getString(self, param): def getString(self, param):
param = param.encode('utf-8')
value = self.__dataMap[param][0] value = self.__dataMap[param][0]
return value return value.decode('utf-8')
def getNumber(self, param): def getNumber(self, param):
value = self.__dataMap[param][0]
t = self.getType(param) t = self.getType(param)
if t == 'INT' or t == 'SHORT': param = param.encode('utf-8')
return int(value) value = self.__dataMap[param][0]
elif t == 'LONG': if t == 'INT' or t == 'SHORT' or t == 'LONG':
return int(value) return int(value)
elif t == 'FLOAT': elif t == 'FLOAT':
return float(value) return float(value)
elif t == 'DOUBLE': elif t == 'DOUBLE':
return float(value) return float(value)
else: else:
raise TypeError("Data for parameter " + param + " is not a numeric type.") raise TypeError("Data for parameter " + param.decode('utf-8') + " is not a numeric type.")
def getUnit(self, param): def getUnit(self, param):
return self.__dataMap[param][2] param = param.encode('utf-8')
unit = self.__dataMap[param][2]
return unit.decode('utf-8')
def getType(self, param): def getType(self, param):
return self.__dataMap[param][1] param = param.encode('utf-8')
type = self.__dataMap[param][1]
return type.decode('utf-8')