except:
noDot = True
-def issequence(value):
- return isinstance(value, tuple) or isinstance(value, list)
-
class Singleton(type):
def __call__(cls, *args, **kwargs):
if hasattr(cls, '_instance'):
return False
def isSimObjSequence(value):
- if not issequence(value):
+ if not isinstance(value, (list, tuple)):
return False
for val in value:
if isNullPointer(child) or instance.top_child_names.has_key(name):
return
- if issequence(child):
+ if isinstance(child, (list, tuple)):
kid = []
for i,c in enumerate(child):
n = '%s%d' % (name, i)
for key,value in cls._getvalues().iteritems():
if isConfigNode(value):
cls.add_child(instance, key, value)
- if issequence(value):
- list = [ v for v in value if isConfigNode(v) ]
- if len(list):
- cls.add_child(instance, key, list)
+ if isinstance(value, (list, tuple)):
+ vals = [ v for v in value if isConfigNode(v) ]
+ if len(vals):
+ cls.add_child(instance, key, vals)
for pname,param in cls._getparams().iteritems():
try:
try:
if isConfigNode(value):
value = instance.child_objects[value]
- elif issequence(value):
+ elif isinstance(value, (list, tuple)):
v = []
for val in value:
if isConfigNode(val):
pval = param.value
try:
- if issequence(pval):
+ if isinstance(pval, (list, tuple)):
param.value = [ self.unproxy(ptype, pv) for pv in pval ]
else:
param.value = self.unproxy(ptype, pval)
if value == None:
return True
- if issequence(value):
+ if isinstance(value, (list, tuple)):
for val in value:
if not isinstance(val, Proxy):
self.ptype._convert(val)
if value == None:
return []
- if issequence(value):
+ if isinstance(value, (list, tuple)):
# list: coerce each element into new list
return [ self.ptype._convert(v) for v in value ]
else:
return self.ptype._convert(value)
def string(self, value):
- if issequence(value):
+ if isinstance(value, (list, tuple)):
return ' '.join([ self.ptype._string(v) for v in value])
else:
return self.ptype._string(value)
# __all__ defines the list of symbols that get exported when
# 'from config import *' is invoked. Try to keep this reasonably
# short to avoid polluting other namespaces.
-__all__ = ['issequence',
- 'ConfigNode', 'SimObject', 'ParamContext', 'Param', 'VectorParam',
+__all__ = ['ConfigNode', 'SimObject', 'ParamContext', 'Param', 'VectorParam',
'Super', 'Enum',
'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16',
'Int32', 'UInt32', 'Int64', 'UInt64',
p.flags = self.flags
p.precision = self.precision
- if issequence(self.value):
+ if isinstance(self.value, (list, tuple)):
if not len(self.value):
return
global globalTicks
globalTicks = None
-def issequence(t):
- return isinstance(t, types.TupleType) or isinstance(t, types.ListType)
-
def total(f):
if isinstance(f, FormulaStat):
v = f.value
v = f
f = FormulaStat()
- if issequence(v):
+ if isinstance(v, (list, tuple)):
f.value = reduce(operator.add, v)
else:
f.value = v
else:
v = f
- if issequence(v):
+ if isinstance(v, (list, tuple)):
return map(op, v)
else:
return op(v)
return result
def sums(x, y):
- if issequence(x):
+ if isinstance(x, (list, tuple)):
return map(lambda x, y: x + y, x, y)
else:
return x + y
-def alltrue(list):
- return reduce(lambda x, y: x and y, list)
+def alltrue(seq):
+ return reduce(lambda x, y: x and y, seq)
-def allfalse(list):
- return not reduce(lambda x, y: x or y, list)
+def allfalse(seq):
+ return not reduce(lambda x, y: x or y, seq)
-def enumerate(list):
- return map(None, range(len(list)), list)
+def enumerate(seq):
+ return map(None, range(len(seq)), seq)
def cmp(a, b):
if a < b:
len(self.value) == len(other.value)
def __eq__(self, other):
- if issequence(self.value) != issequence(other.value):
+ if isinstance(self.value, (list, tuple)) != \
+ isinstance(other.value, (list, tuple)):
return False
- if issequence(self.value):
+ if isinstance(self.value, (list, tuple)):
if len(self.value) != len(other.value):
return False
else:
def __itruediv__(self, other):
if not other:
return self
- if issequence(self.value):
+ if isinstance(self.value, (list, tuple)):
for i in xrange(len(self.value)):
self.value[i] /= other
else:
return alltrue(map(lambda x, y : x == y, self.dist, other.dist))
def __isub__(self, other):
- if issequence(self.dist) and issequence(other.dist):
+ if isinstance(self.dist, (list, tuple)) and \
+ isinstance(other.dist, (list, tuple)):
for sd,od in zip(self.dist, other.dist):
sd -= od
else:
return self
def __iadd__(self, other):
- if issequence(self.dist) and issequence(other.dist):
+ if isinstance(self.dist, (list, tuple)) and \
+ isinstance(other.dist, (list, tuple)):
for sd,od in zip(self.dist, other.dist):
sd += od
else:
def __itruediv__(self, other):
if not other:
return self
- if issequence(self.dist):
+ if isinstance(self.dist, (list, tuple)):
for dist in self.dist:
dist /= other
else:
p.flags = self.flags
p.precision = self.precision
- if issequence(self.value):
+ if isinstance(self.value, (list, tuple)):
if not len(self.value):
return