mirror of
https://github.com/Unidata/python-awips.git
synced 2025-02-23 14:57:56 -05:00
Merge pull request #109 from srcarter3/v20
Replace type() with isinstance()
This commit is contained in:
commit
853c011507
7 changed files with 32 additions and 44 deletions
|
@ -42,7 +42,7 @@ from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.server.messa
|
|||
# Date Ticket# Engineer Description
|
||||
# ------------ ---------- ----------- --------------------------
|
||||
# 07/26/12 dgilling Initial Creation.
|
||||
#
|
||||
# 08/31/23 srcarter@ucar From MJ - replace type with isinstance
|
||||
#
|
||||
#
|
||||
|
||||
|
@ -59,7 +59,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])
|
||||
|
@ -74,8 +74,7 @@ class IFPClient(object):
|
|||
return ssr
|
||||
|
||||
def getParmList(self, id):
|
||||
argType = type(id)
|
||||
if argType is DatabaseID:
|
||||
if isinstance(argType, DatabaseID):
|
||||
return self.__getParmList([id])
|
||||
elif self.__isHomogenousIterable(id, DatabaseID):
|
||||
return self.__getParmList([dbid for dbid in id])
|
||||
|
@ -102,7 +101,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:
|
||||
|
|
|
@ -39,12 +39,12 @@ class GFERecord(PersistableDataObject):
|
|||
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()
|
||||
|
|
|
@ -36,9 +36,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.")
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
# 06/29/15 4480 dgilling Implement __hash__, __eq__,
|
||||
# __str__ and rich comparison operators.
|
||||
# 02/17/22 8608 mapeters Subclass PersistableDataObject
|
||||
#
|
||||
# 08/31/23 srcarter@ucar From MJ - replace type with isinstance
|
||||
#
|
||||
|
||||
import numpy
|
||||
|
@ -71,17 +71,15 @@ class Level(PersistableDataObject):
|
|||
return hashCode
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(self) != type(other):
|
||||
return False
|
||||
else:
|
||||
if isinstance(self, type(other)):
|
||||
return (self.masterLevel, self.levelonevalue, self.leveltwovalue) == \
|
||||
(other.masterLevel, other.levelonevalue, other.leveltwovalue)
|
||||
|
||||
return False
|
||||
def __ne__(self, other):
|
||||
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
|
||||
|
@ -113,7 +111,7 @@ class Level(PersistableDataObject):
|
|||
return False
|
||||
|
||||
def __le__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
elif self.masterLevel.getName() != other.masterLevel.getName():
|
||||
return NotImplemented
|
||||
|
@ -121,7 +119,7 @@ class Level(PersistableDataObject):
|
|||
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
|
||||
elif self.masterLevel.getName() != other.masterLevel.getName():
|
||||
return NotImplemented
|
||||
|
@ -153,7 +151,7 @@ class Level(PersistableDataObject):
|
|||
return False
|
||||
|
||||
def __ge__(self, other):
|
||||
if type(self) != type(other):
|
||||
if not isinstance(self, type(other)):
|
||||
return NotImplemented
|
||||
elif self.masterLevel.getName() != other.masterLevel.getName():
|
||||
return NotImplemented
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
# 06/29/15 4480 dgilling Implement __hash__, __eq__
|
||||
# and __str__.
|
||||
# 02/17/22 8608 mapeters Subclass PersistableDataObject
|
||||
#
|
||||
# 08/31/23 srcarter@ucar From MJ - replace type with isinstance
|
||||
#
|
||||
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.persist import PersistableDataObject
|
||||
|
@ -49,7 +49,7 @@ class MasterLevel(PersistableDataObject):
|
|||
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
|
||||
|
|
|
@ -27,11 +27,11 @@
|
|||
# Jun 27, 2016 5725 tgurney Add NOT IN
|
||||
# Jul 22, 2016 2416 tgurney Add evaluate()
|
||||
# Jun 26, 2019 7888 tgurney Python 3 fixes
|
||||
#
|
||||
# Aug 31, 2023 srcarter@ucar Small formatting and logic changes
|
||||
#
|
||||
|
||||
import re
|
||||
from ...time import DataTime
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.time import DataTime
|
||||
|
||||
|
||||
class RequestConstraint(object):
|
||||
|
@ -212,7 +212,7 @@ class RequestConstraint(object):
|
|||
return self._evalValue.match(value) is not None
|
||||
|
||||
def _evalIsNull(self, value):
|
||||
return value is None or 'null' == value
|
||||
return value is None or value == 'null'
|
||||
|
||||
# DAF-specific stuff begins here ##########################################
|
||||
|
||||
|
@ -228,11 +228,11 @@ class RequestConstraint(object):
|
|||
|
||||
@staticmethod
|
||||
def _stringify(value):
|
||||
if type(value) in {int, bool, float}:
|
||||
if isinstance(value, (int, bool, float)):
|
||||
return str(value)
|
||||
elif type(value) is str:
|
||||
elif isinstance(value, str):
|
||||
return value
|
||||
elif type(value) is bytes:
|
||||
elif isinstance(value, bytes):
|
||||
return value.decode()
|
||||
else:
|
||||
# Collections are not allowed; they are handled separately.
|
||||
|
@ -249,7 +249,7 @@ class RequestConstraint(object):
|
|||
except TypeError:
|
||||
raise TypeError("value for IN / NOT IN constraint must be an iterable")
|
||||
stringValue = ', '.join(cls._stringify(item) for item in iterator)
|
||||
if len(stringValue) == 0:
|
||||
if not stringValue:
|
||||
raise ValueError('cannot use IN / NOT IN with empty collection')
|
||||
obj = cls()
|
||||
obj.setConstraintType(constraintType)
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
# plus misc cleanup
|
||||
# 09/13/19 7888 tgurney Python 3 division fixes
|
||||
# 11/18/19 7881 tgurney Fix __hash__
|
||||
# 08/31/23 srcarter@ucar Small formatting fixes to match MJ's changes
|
||||
|
||||
|
||||
import calendar
|
||||
|
@ -59,12 +60,8 @@ _TIME = r'(\d{2}:\d{2}:\d{2})'
|
|||
_MILLIS = '(?:\.(\d{1,3})(?:\d{1,4})?)?'
|
||||
REFTIME_PATTERN_STR = _DATE + '[ _]' + _TIME + _MILLIS
|
||||
FORECAST_PATTERN_STR = r'(?:[ _]\((\d+)(?::(\d{1,2}))?\))?'
|
||||
VALID_PERIOD_PATTERN_STR = r'(?:\[' + REFTIME_PATTERN_STR + \
|
||||
'--' + REFTIME_PATTERN_STR + r'\])?'
|
||||
STR_PATTERN = re.compile(
|
||||
REFTIME_PATTERN_STR +
|
||||
FORECAST_PATTERN_STR +
|
||||
VALID_PERIOD_PATTERN_STR)
|
||||
VALID_PERIOD_PATTERN_STR = r'(?:\[' + REFTIME_PATTERN_STR + '--' + REFTIME_PATTERN_STR + r'\])?'
|
||||
STR_PATTERN = re.compile(REFTIME_PATTERN_STR + FORECAST_PATTERN_STR + VALID_PERIOD_PATTERN_STR)
|
||||
|
||||
|
||||
class DataTime(object):
|
||||
|
@ -88,18 +85,14 @@ class DataTime(object):
|
|||
self.fcstTime = 0
|
||||
self.refTime = refTime
|
||||
if validPeriod is not None and not isinstance(validPeriod, TimeRange):
|
||||
raise ValueError(
|
||||
"Invalid validPeriod object specified for DataTime.")
|
||||
raise ValueError("Invalid validPeriod object specified for DataTime.")
|
||||
self.validPeriod = validPeriod
|
||||
self.utilityFlags = EnumSet(
|
||||
'com.raytheon.uf.common.time.DataTime$FLAG')
|
||||
self.utilityFlags = EnumSet('com.raytheon.uf.common.time.DataTime$FLAG')
|
||||
self.levelValue = numpy.float64(-1.0)
|
||||
|
||||
if self.refTime is not None:
|
||||
if isinstance(self.refTime, datetime.datetime):
|
||||
self.refTime = int(
|
||||
calendar.timegm(
|
||||
self.refTime.utctimetuple()) * 1000)
|
||||
self.refTime = int(calendar.timegm(self.refTime.utctimetuple()) * 1000)
|
||||
elif isinstance(self.refTime, time.struct_time):
|
||||
self.refTime = int(calendar.timegm(self.refTime) * 1000)
|
||||
elif hasattr(self.refTime, 'getTime'):
|
||||
|
@ -124,8 +117,7 @@ class DataTime(object):
|
|||
fcstTimeMin = groups[4]
|
||||
periodStart = groups[5], groups[6], (groups[7] or 0)
|
||||
periodEnd = groups[8], groups[9], (groups[10] or 0)
|
||||
self.refTime = self._getTimeAsEpochMillis(
|
||||
rDate, rTime, rMillis)
|
||||
self.refTime = self._getTimeAsEpochMillis(rDate, rTime, rMillis)
|
||||
|
||||
if fcstTimeHr is not None:
|
||||
self.fcstTime = int(fcstTimeHr) * 3600
|
||||
|
@ -134,8 +126,7 @@ class DataTime(object):
|
|||
|
||||
if periodStart[0] is not None:
|
||||
self.validPeriod = TimeRange()
|
||||
periodStartTime = self._getTimeAsEpochMillis(
|
||||
*periodStart)
|
||||
periodStartTime = self._getTimeAsEpochMillis(*periodStart)
|
||||
self.validPeriod.setStart(periodStartTime // 1000)
|
||||
periodEndTime = self._getTimeAsEpochMillis(*periodEnd)
|
||||
self.validPeriod.setEnd(periodEndTime // 1000)
|
||||
|
|
Loading…
Add table
Reference in a new issue