Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def cloneListOrObject(v, extra_args):
"""
This clones the value v by determining if the value of v is a list or not.
If v is a list then a new list is returned with elements copied via cloneObject
if v is not a list then a new instance of the list is copied via cloneObject
Args:
v (unknown): Object we want a new copy of
extra_args (tuple): Contains the name of the attribute being copied and the object which owns the object being copied
"""
name=extra_args[0]
obj=extra_args[1]
if isinstance(v, (list, tuple, GangaList)):
new_v = GangaList()
for elem in v:
new_v.append(Descriptor.cloneObject(elem, obj, name))
return new_v
else:
return Descriptor.cloneObject(v, obj, name)
This clones the value v by determining if the value of v is a list or not.
If v is a list then a new list is returned with elements copied via cloneObject
if v is not a list then a new instance of the list is copied via cloneObject
Args:
v (unknown): Object we want a new copy of
extra_args (tuple): Contains the name of the attribute being copied and the object which owns the object being copied
"""
name=extra_args[0]
obj=extra_args[1]
if isinstance(v, (list, tuple, GangaList)):
new_v = GangaList()
for elem in v:
new_v.append(Descriptor.cloneObject(elem, obj, name))
return new_v
else:
return Descriptor.cloneObject(v, obj, name)
return int(v)
elif isinstance(v, dict):
new_dict = {}
for key, item in v.iteritems():
new_dict[key] = Descriptor.cloneObject(item, obj, name)
return new_dict
else:
if not isinstance(v, Node) and isinstance(v, (list, tuple)):
try:
# must import here as will fail at the top
from GangaCore.GPIDev.Lib.GangaList.GangaList import GangaList
new_v = GangaList()
except ImportError:
new_v = []
for elem in v:
new_v.append(Descriptor.cloneObject(elem, obj, name))
#return new_v
elif not isinstance(v, Node):
if isclass(v):
new_v = v()
else:
new_v = v
if not isinstance(new_v, Node):
logger.error("v: %s" % v)
raise GangaException("Error: found Object: %s of type: %s expected an object inheriting from Node!" % (v, type(v)))
else:
new_v = Descriptor.cloneNodeObject(new_v, obj, name)
else:
new_v = Descriptor.cloneNodeObject(v, obj, name)
return new_v
If v is a list then a new list is returned with elements copied via cloneObject
if v is not a list then a new instance of the list is copied via cloneObject
Args:
v (unknown): Object we want a new copy of
extra_args (tuple): Contains the name of the attribute being copied and the object which owns the object being copied
"""
name=extra_args[0]
obj=extra_args[1]
if isinstance(v, (list, tuple, GangaList)):
new_v = GangaList()
for elem in v:
new_v.append(Descriptor.cloneObject(elem, obj, name))
return new_v
else:
return Descriptor.cloneObject(v, obj, name)
assertion = item['optional'] and (item['category'] != 'internal')
else:
assertion = item['optional']
#assert(assertion)
if assertion is False:
logger.warning("Item: '%s'. of class type: '%s'. Has a Default value of 'None' but is NOT optional!!!" % (name, type(obj)))
logger.warning("Please contact the developers and make sure this is updated!")
return None
elif isinstance(v, str):
return str(v)
elif isinstance(v, int):
return int(v)
elif isinstance(v, dict):
new_dict = {}
for key, item in v.items():
new_dict[key] = Descriptor.cloneObject(item, obj, name)
return new_dict
else:
if not isinstance(v, Node) and isinstance(v, (list, tuple)):
try:
# must import here as will fail at the top
from GangaCore.GPIDev.Lib.GangaList.GangaList import GangaList
new_v = GangaList()
except ImportError:
new_v = []
for elem in v:
new_v.append(Descriptor.cloneObject(elem, obj, name))
#return new_v
elif not isinstance(v, Node):
if isclass(v):
new_v = v()
else:
assertion = item['optional'] and (item['category'] != 'internal')
else:
assertion = item['optional']
#assert(assertion)
if assertion is False:
logger.warning("Item: '%s'. of class type: '%s'. Has a Default value of 'None' but is NOT optional!!!" % (name, type(obj)))
logger.warning("Please contact the developers and make sure this is updated!")
return None
elif isinstance(v, str):
return str(v)
elif isinstance(v, int):
return int(v)
elif isinstance(v, dict):
new_dict = {}
for key, item in v.iteritems():
new_dict[key] = Descriptor.cloneObject(item, obj, name)
return new_dict
else:
if not isinstance(v, Node) and isinstance(v, (list, tuple)):
try:
# must import here as will fail at the top
from GangaCore.GPIDev.Lib.GangaList.GangaList import GangaList
new_v = GangaList()
except ImportError:
new_v = []
for elem in v:
new_v.append(Descriptor.cloneObject(elem, obj, name))
#return new_v
elif not isinstance(v, Node):
if isclass(v):
new_v = v()
else:
@staticmethod
def cloneListOrObject(v, extra_args):
"""
This clones the value v by determining if the value of v is a list or not.
If v is a list then a new list is returned with elements copied via cloneObject
if v is not a list then a new instance of the list is copied via cloneObject
Args:
v (unknown): Object we want a new copy of
extra_args (tuple): Contains the name of the attribute being copied and the object which owns the object being copied
"""
name=extra_args[0]
obj=extra_args[1]
if isinstance(v, (list, tuple, GangaList)):
new_v = GangaList()
for elem in v:
new_v.append(Descriptor.cloneObject(elem, obj, name))
return new_v
else:
return Descriptor.cloneObject(v, obj, name)