(name, process)
| 250 | |
| 251 | |
| 252 | def 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 | |
| 290 | def errored(el): |
no test coverage detected