Skip to content

Commit d16b593

Browse files
qinz0822minglumlu
authored andcommitted
Remove the use of types
Signed-off-by: Qin Zhang (张琴) <[email protected]>
1 parent 9612776 commit d16b593

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

XSConsoleHotData.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def __getattr__(self, inName):
6161

6262
def __iter__(self):
6363
iterData = HotData.Inst().GetData(self.name, {}, self.refs)
64-
if isinstance(iterData, types.DictType):
64+
if isinstance(iterData, dict):
6565
self.iterKeys = iterData.keys()
66-
elif isinstance(iterData, (types.ListType, types.TupleType)):
66+
elif isinstance(iterData, (list, tuple)):
6767
self.iterKeys = iterData[:] # [:] copy is necessary
6868
else:
6969
raise Exception(Lang("Cannot iterate over type '")+str(type(iterData))+"'")
@@ -80,7 +80,7 @@ def next(self):
8080

8181
def __getitem__(self, inParam):
8282
# These are square brackets selecting a particular item from a dict using its OpaqueRef
83-
if not isinstance(inParam, (types.IntType, HotOpaqueRef)):
83+
if not isinstance(inParam, (int, HotOpaqueRef)):
8484
raise Exception('Use of HotAccessor[param] requires param of type int or HotOpaqueRef, but got '+str(type(inParam)))
8585
retVal = HotAccessor(self.name[:], self.refs[:])
8686
retVal.refs[-1] = inParam
@@ -134,7 +134,7 @@ def Fetch(self, inName, inRef):
134134
fetcher = self.fetchers[inName]
135135
timeNow = time.time()
136136
# If inRef is an array index, the result can't be cached
137-
if not isinstance(inRef, types.IntType) and cacheEntry is not None and timeNow - cacheEntry.timestamp < fetcher.lifetimeSecs:
137+
if not isinstance(inRef, int) and cacheEntry is not None and timeNow - cacheEntry.timestamp < fetcher.lifetimeSecs:
138138
retVal = cacheEntry.value
139139
else:
140140
try:
@@ -172,7 +172,7 @@ def GetData(self, inNames, inDefault, inRefs):
172172
# We have a fetcher for this element, so use it
173173

174174
# Handle the case where itemRef is a dictionary containing the key/value pair ( current name : HotOpaqueRef )
175-
if isinstance(itemRef, types.DictType) and name in itemRef and isinstance(itemRef[name], HotOpaqueRef):
175+
if isinstance(itemRef, dict) and name in itemRef and isinstance(itemRef[name], HotOpaqueRef):
176176
# This is a subitem with an OpaqueRef supplied by xapi, so fetch the obect it's referring to
177177
itemRef = self.Fetch(name, itemRef[name])
178178
else:
@@ -189,8 +189,8 @@ def GetData(self, inNames, inDefault, inRefs):
189189
itemRef = itemRef[name] # Allow to throw if element not present
190190

191191
# Handle integer references as list indices
192-
if isinstance(currentRef, types.IntType):
193-
if not isinstance(itemRef, (types.ListType, types.TupleType)):
192+
if isinstance(currentRef, int):
193+
if not isinstance(itemRef, (list, tuple)):
194194
raise Exception("List index supplied but element '"+'.'.join(inNames)+"' is not a list")
195195
if inRefs[i] >= len(itemRef) or currentRef < -len(itemRef):
196196
raise Exception("List index "+str(currentRef)+" out of range in '"+'.'.join(inNames)+"'")
@@ -454,9 +454,9 @@ def ConvertOpaqueRefs(cls, *inArgs, **inKeywords):
454454
if obj is not None:
455455
if isinstance(obj, str):
456456
ioObj[keyword] = HotOpaqueRef(obj, value)
457-
elif isinstance(obj, types.ListType):
457+
elif isinstance(obj, list):
458458
ioObj[keyword] = [ HotOpaqueRef(x, value) for x in obj ]
459-
elif isinstance(obj, types.DictType):
459+
elif isinstance(obj, dict):
460460
result = {}
461461
for key, item in obj.items():
462462
result[ HotOpaqueRef(key, value) ] = item
@@ -466,12 +466,12 @@ def ConvertOpaqueRefs(cls, *inArgs, **inKeywords):
466466
for key,value in ioObj.items():
467467
if isinstance(value, str) and value.startswith('OpaqueRef'):
468468
print('Missed OpaqueRef string in HotData item: '+key)
469-
elif isinstance(value, types.ListType):
469+
elif isinstance(value, list):
470470
for item in value:
471471
if isinstance(item, str) and item.startswith('OpaqueRef'):
472472
print('Missed OpaqueRef List in HotData item: '+key)
473473
break
474-
elif isinstance(value, types.DictType):
474+
elif isinstance(value, dict):
475475
for item in value.keys():
476476
if isinstance(item, str) and item.startswith('OpaqueRef'):
477477
print('Missed OpaqueRef Dict in HotData item: '+key)

XSConsoleUtils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, *inParams):
5151
self.called = False
5252

5353
def _NewPipe(self, *inParams):
54-
if len(inParams) == 1 and isinstance(inParams, (types.ListType, types.TupleType)):
54+
if len(inParams) == 1 and isinstance(inParams, (list, tuple)):
5555
params = inParams[0]
5656
else:
5757
params = inParams
@@ -84,7 +84,7 @@ def Communicate(self, inInput = None):
8484
self.called = True
8585
while True:
8686
try:
87-
if isinstance(inInput, (types.ListType, types.TupleType)):
87+
if isinstance(inInput, (list, tuple)):
8888
stdout, stderr = self.pipe.communicate("\n".join(inInput))
8989
else:
9090
stdout, stderr = self.pipe.communicate(inInput)

0 commit comments

Comments
 (0)