mirror of
https://github.com/Unidata/python-awips.git
synced 2025-02-23 22:57:56 -05:00
use isinstance() rather than type()
This commit is contained in:
parent
817f9ccd9b
commit
9f55c3d0ef
9 changed files with 40 additions and 52 deletions
|
@ -15,6 +15,7 @@
|
|||
from awips.dataaccess import IData
|
||||
import six
|
||||
|
||||
|
||||
class PyData(IData):
|
||||
|
||||
def __init__(self, dataRecord):
|
||||
|
@ -36,7 +37,7 @@ class PyData(IData):
|
|||
def getLevel(self):
|
||||
if six.PY2:
|
||||
return self.__level
|
||||
if type(self.__level) is not str:
|
||||
if not isinstance(self.__level, str):
|
||||
return self.__level.decode('utf-8')
|
||||
return self.__level
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class PyGridData(IGridData, PyData.PyData):
|
|||
def getUnit(self):
|
||||
if six.PY2:
|
||||
return self.__unit
|
||||
if self.__unit is not None and type(self.__unit) is not str:
|
||||
if self.__unit is not None and not isinstance(self.__unit, str):
|
||||
return self.__unit.decode('utf-8')
|
||||
return self.__unit
|
||||
|
||||
|
|
|
@ -1,17 +1,3 @@
|
|||
from awips import ThriftClient
|
||||
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import DatabaseID
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import ParmID
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import CommitGridsRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import GetGridInventoryRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import GetParmListRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import GetSelectTimeRangeRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.server.request import CommitGridRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.message import WsId
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.site.requests import GetActiveSitesRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.server.message import ServerResponse
|
||||
|
||||
|
||||
#
|
||||
# Provides a Python-based interface for executing GFE requests.
|
||||
#
|
||||
|
@ -26,6 +12,18 @@ from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.server.messa
|
|||
#
|
||||
#
|
||||
|
||||
from awips import ThriftClient
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import DatabaseID
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import ParmID
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import CommitGridsRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import GetGridInventoryRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import GetParmListRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.request import GetSelectTimeRangeRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.server.request import CommitGridRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.message import WsId
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.site.requests import GetActiveSitesRequest
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.server.message import ServerResponse
|
||||
|
||||
|
||||
class IFPClient(object):
|
||||
def __init__(self, host, port, user, site=None, progName=None):
|
||||
|
@ -39,7 +37,7 @@ class IFPClient(object):
|
|||
self.__siteId = site
|
||||
|
||||
def commitGrid(self, request):
|
||||
if type(request) is CommitGridRequest:
|
||||
if isinstance(request, CommitGridRequest):
|
||||
return self.__commitGrid([request])
|
||||
elif self.__isHomogenousIterable(request, CommitGridRequest):
|
||||
return self.__commitGrid([cgr for cgr in request])
|
||||
|
@ -82,7 +80,7 @@ class IFPClient(object):
|
|||
return True
|
||||
|
||||
def getGridInventory(self, parmID):
|
||||
if type(parmID) is ParmID:
|
||||
if isinstance(parmID, ParmID):
|
||||
sr = self.__getGridInventory([parmID])
|
||||
list = []
|
||||
try:
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
##
|
||||
##
|
||||
|
||||
# File auto-generated against equivalent DynamicSerialize Java class
|
||||
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import ParmID
|
||||
|
@ -20,12 +17,12 @@ class GFERecord(object):
|
|||
self.dataTime = None
|
||||
self.parmId = None
|
||||
if timeRange is not None:
|
||||
if type(timeRange) is TimeRange:
|
||||
if isinstance(timeRange, TimeRange):
|
||||
self.dataTime = DataTime(refTime=timeRange.getStart(), validPeriod=timeRange)
|
||||
else:
|
||||
raise TypeError("Invalid TimeRange object specified.")
|
||||
if parmId is not None:
|
||||
if type(parmId) is ParmID.ParmID:
|
||||
if isinstance(parmId, ParmID.ParmID):
|
||||
self.parmId = parmId
|
||||
self.parmName = parmId.getParmName()
|
||||
self.parmLevel = parmId.getParmLevel()
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
##
|
||||
##
|
||||
|
||||
# File auto-generated against equivalent DynamicSerialize Java class
|
||||
# Modified by njensen to add __repr__
|
||||
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import DatabaseID
|
||||
|
||||
|
||||
class ParmID(object):
|
||||
|
||||
def __init__(self, parmIdentifier=None, dbId=None, level=None):
|
||||
|
@ -19,9 +17,9 @@ class ParmID(object):
|
|||
if (parmIdentifier is not None) and (dbId is not None):
|
||||
self.parmName = parmIdentifier
|
||||
|
||||
if type(dbId) is DatabaseID:
|
||||
if isinstance(dbId, DatabaseID):
|
||||
self.dbId = dbId
|
||||
elif type(dbId) is str:
|
||||
elif isinstance(dbId, str):
|
||||
self.dbId = DatabaseID(dbId)
|
||||
else:
|
||||
raise TypeError("Invalid database ID specified.")
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
##
|
||||
##
|
||||
|
||||
# File auto-generated against equivalent DynamicSerialize Java class
|
||||
# and then modified post-generation to add additional features to better
|
||||
# match Java implementation.
|
||||
|
@ -21,10 +18,10 @@ import re
|
|||
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.level import MasterLevel
|
||||
|
||||
|
||||
LEVEL_NAMING_REGEX = re.compile("^(\d*(?:\.\d*)?)(?:_(\d*(?:\.\d*)?))?([a-zA-Z]+)$")
|
||||
INVALID_VALUE = numpy.float64(-999999)
|
||||
|
||||
|
||||
class Level(object):
|
||||
|
||||
def __init__(self, levelString=None):
|
||||
|
@ -51,7 +48,7 @@ class Level(object):
|
|||
return hashCode
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return False
|
||||
else:
|
||||
return (self.masterLevel, self.levelonevalue, self.leveltwovalue) == \
|
||||
|
@ -61,7 +58,7 @@ class Level(object):
|
|||
return not self.__eq__(other)
|
||||
|
||||
def __lt__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
elif self.masterLevel.getName() != other.masterLevel.getName():
|
||||
return NotImplemented
|
||||
|
@ -93,7 +90,7 @@ class Level(object):
|
|||
return False
|
||||
|
||||
def __le__(self, other):
|
||||
if not isinstance(self, other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
elif self.masterLevel.getName() != other.masterLevel.getName():
|
||||
return NotImplemented
|
||||
|
@ -101,7 +98,7 @@ class Level(object):
|
|||
return self.__lt__(other) or self.__eq__(other)
|
||||
|
||||
def __gt__(self, other):
|
||||
if not isinstance(self, other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
elif self.masterLevel.getName() != other.masterLevel.getName():
|
||||
return NotImplemented
|
||||
|
@ -128,12 +125,11 @@ class Level(object):
|
|||
elif otherLevel2 != INVALID_VALUE:
|
||||
level2Cmp = self.__compareLevelValues(compareType, myLevel1, otherLevel2)
|
||||
return level2Cmp == 1
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
||||
def __ge__(self, other):
|
||||
if not isinstance(self, other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
elif self.masterLevel.getName() != other.masterLevel.getName():
|
||||
return NotImplemented
|
||||
|
|
|
@ -28,7 +28,7 @@ class MasterLevel(object):
|
|||
return hash(self.name)
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return False
|
||||
else:
|
||||
return self.name == other.name
|
||||
|
@ -56,7 +56,7 @@ class MasterLevel(object):
|
|||
def getName(self):
|
||||
if six.PY2:
|
||||
return self.name
|
||||
if self.name is not None and type(self.name) is not str:
|
||||
if (self.name is not None) and (not isinstance(self.name, str)):
|
||||
return self.name.decode('utf-8')
|
||||
return self.name
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class DataTime(object):
|
|||
else:
|
||||
self.fcstTime = 0
|
||||
self.refTime = refTime
|
||||
if validPeriod is not None and type(validPeriod) is not TimeRange:
|
||||
if validPeriod is not None and not isinstance(validPeriod, TimeRange):
|
||||
raise ValueError("Invalid validPeriod object specified for DataTime.")
|
||||
self.validPeriod = validPeriod
|
||||
self.utilityFlags = EnumSet('com.raytheon.uf.common.time.DataTime$FLAG')
|
||||
|
@ -193,7 +193,7 @@ class DataTime(object):
|
|||
return hashCode
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return False
|
||||
|
||||
if other.getRefTime() is None:
|
||||
|
@ -207,7 +207,7 @@ class DataTime(object):
|
|||
return not self.__eq__(other)
|
||||
|
||||
def __lt__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
|
||||
myValidTime = self.getRefTime().getTime() + self.getFcstTime()
|
||||
|
@ -230,13 +230,13 @@ class DataTime(object):
|
|||
return False
|
||||
|
||||
def __le__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
|
||||
return self.__lt__(other) or self.__eq__(other)
|
||||
|
||||
def __gt__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
|
||||
myValidTime = self.getRefTime().getTime() + self.getFcstTime()
|
||||
|
@ -259,7 +259,7 @@ class DataTime(object):
|
|||
return False
|
||||
|
||||
def __ge__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
|
||||
return self.__gt__(other) or self.__eq__(other)
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
##
|
||||
##
|
||||
|
||||
# File auto-generated against equivalent DynamicSerialize Java class. Then modified to add functionality
|
||||
#
|
||||
#
|
||||
|
@ -23,6 +20,7 @@ import time
|
|||
MAX_TIME = 2147483647
|
||||
MICROS_IN_SECOND = 1000000
|
||||
|
||||
|
||||
class TimeRange(object):
|
||||
def __init__(self, start=None, end=None, startExtraMicros=None, endExtraMicros=None):
|
||||
self.start = self.__convertToDateTimeWithExtra(start, startExtraMicros)
|
||||
|
@ -35,7 +33,7 @@ class TimeRange(object):
|
|||
return "(" + self.start.strftime("%b %d %y %H:%M:%S %Z") + ", " + self.end.strftime("%b %d %y %H:%M:%S %Z") + ")"
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return False
|
||||
|
||||
if self.isValid() and other.isValid():
|
||||
|
@ -117,7 +115,7 @@ class TimeRange(object):
|
|||
return (timeArg.start >= self.start and timeArg.end <= self.end)
|
||||
else:
|
||||
convTime = self.__convertToDateTime(timeArg)
|
||||
if type(convTime) is not datetime.datetime:
|
||||
if not isinstance(convTime, datetime.datetime):
|
||||
raise TypeError("Invalid type for argument time specified to TimeRange.contains().")
|
||||
if self.duration() != 0:
|
||||
return (convTime >= self.start and convTime < self.end)
|
||||
|
|
Loading…
Add table
Reference in a new issue