MCPcopy Create free account
hub / github.com/datacamp/pythonwhat / getRepresentation

Function getRepresentation

pythonwhat/tasks.py:252–287  ·  view source on GitHub ↗
(name, process)

Source from the content-addressed store, hash-verified

250
251
252def getRepresentation(name, process):
253 obj_class = getClass(name, process)
254 converters = pythonwhat.State.State.root_state.converters
255 if obj_class in converters:
256 repres = convert(name, dill.dumps(converters[obj_class]), process)
257 if errored(repres):
258 return ReprFail("manual conversion failed: {}".format(repres))
259 else:
260 return repres
261 else:
262 # first try to pickle
263 try:
264 stream = getStreamPickle(name, process)
265 if not errored(stream):
266 return pickle.loads(stream)
267 except:
268 pass
269
270 # if it failed, try to dill
271 try:
272 stream = getStreamDill(name, process)
273 if not errored(stream):
274 return dill.loads(stream)
275 return ReprFail(
276 "dilling inside process failed for %s - write manual converter"
277 % obj_class
278 )
279 except PicklingError:
280 return ReprFail(
281 "undilling of bytestream failed with PicklingError - write manual converter"
282 )
283 except Exception as e:
284 return ReprFail(
285 "undilling of bytestream failed for class %s - write manual converter."
286 "Error: %s - %s" % (obj_class, type(e), e)
287 )
288
289
290def errored(el):

Callers 1

getResultFromProcessFunction · 0.85

Calls 6

getClassFunction · 0.85
convertFunction · 0.85
erroredFunction · 0.85
ReprFailClass · 0.85
getStreamPickleFunction · 0.85
getStreamDillFunction · 0.85

Tested by

no test coverage detected