Args: item: data item to be hashed protocol: protocol version used for pickling, defaults to `pickle.HIGHEST_PROTOCOL`. Returns: the corresponding hash key
(item, protocol=pickle.HIGHEST_PROTOCOL)
| 1378 | |
| 1379 | |
| 1380 | def pickle_hashing(item, protocol=pickle.HIGHEST_PROTOCOL) -> bytes: |
| 1381 | """ |
| 1382 | |
| 1383 | Args: |
| 1384 | item: data item to be hashed |
| 1385 | protocol: protocol version used for pickling, |
| 1386 | defaults to `pickle.HIGHEST_PROTOCOL`. |
| 1387 | |
| 1388 | Returns: the corresponding hash key |
| 1389 | |
| 1390 | """ |
| 1391 | cache_key = "" |
| 1392 | if sys.version_info.minor < 9: |
| 1393 | cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest() |
| 1394 | else: |
| 1395 | cache_key = hashlib.md5( |
| 1396 | pickle.dumps(sorted_dict(item), protocol=protocol), usedforsecurity=False # type: ignore |
| 1397 | ).hexdigest() |
| 1398 | return f"{cache_key}".encode() |
| 1399 | |
| 1400 | |
| 1401 | def sorted_dict(item, key=None, reverse=False): |
searching dependent graphs…