python-awips/awips/dataaccess/PyData.py

48 lines
1.3 KiB
Python
Raw Normal View History

2018-09-05 15:52:38 -06:00
#
# Implements IData for use by native Python clients to the Data Access
# Framework.
#
#
# SOFTWARE HISTORY
#
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 06/03/13 dgilling Initial Creation.
# 10/05/18 mjames@ucar Encode/decode attribute names.
2018-09-05 15:52:38 -06:00
#
#
from awips.dataaccess import IData
import six
2018-09-05 15:52:38 -06:00
2018-10-14 16:28:05 -06:00
2018-09-05 15:52:38 -06:00
class PyData(IData):
def __init__(self, dataRecord):
self.__time = dataRecord.getTime()
self.__level = dataRecord.getLevel()
self.__locationName = dataRecord.getLocationName()
self.__attributes = dataRecord.getAttributes()
def getAttribute(self, key):
if six.PY2:
return self.__attributes[key]
value = self.__attributes[key.encode('utf-8')]
return value.decode('utf-8')
2018-09-05 15:52:38 -06:00
def getAttributes(self):
return self.__attributes.keys()
2018-09-05 15:52:38 -06:00
def getDataTime(self):
return self.__time
def getLevel(self):
if six.PY2:
return self.__level
2018-10-14 16:28:05 -06:00
if not isinstance(self.__level, str):
return self.__level.decode('utf-8')
2018-10-09 09:33:28 -06:00
return self.__level
2018-09-05 15:52:38 -06:00
def getLocationName(self):
return self.__locationName