def getRepresentation(name, process):
obj_class = getClass(name, process)
converters = pythonwhat.State.State.root_state.converters
if obj_class in converters:
repres = convert(name, dill.dumps(converters[obj_class]), process)
if (errored(repres)):
return ReprFail("manual conversion failed")
else:
return repres
else:
# first try to pickle
try:
stream = getStreamPickle(name, process)
if not errored(stream): return pickle.loads(stream)
except:
pass
# if it failed, try to dill
try:
stream = getStreamDill(name, process)
if not errored(stream): return dill.loads(stream)
return ReprFail("dilling inside process failed for %s - write manual converter" % obj_class)
except PicklingError:
return ReprFail("undilling of bytestream failed with PicklingError - write manual converter")
except Exception as e:
return ReprFail("undilling of bytestream failed for class %s - write manual converter."
"Error: %s - %s" % (obj_class, type(e), e))
评论列表
文章目录