Ensure items will serialize. For a given list of arbitrary objects, return the object or a string representation, safe for serialization. Arguments: items (Iterable[Any]): Objects to serialize. encoder (Callable): Callable function to serialize with.
(items, encoder)
| 78 | |
| 79 | |
| 80 | def ensure_serializable(items, encoder): |
| 81 | """Ensure items will serialize. |
| 82 | |
| 83 | For a given list of arbitrary objects, return the object |
| 84 | or a string representation, safe for serialization. |
| 85 | |
| 86 | Arguments: |
| 87 | items (Iterable[Any]): Objects to serialize. |
| 88 | encoder (Callable): Callable function to serialize with. |
| 89 | """ |
| 90 | safe_exc_args = [] |
| 91 | for arg in items: |
| 92 | try: |
| 93 | encoder(arg) |
| 94 | safe_exc_args.append(arg) |
| 95 | except Exception: # pylint: disable=broad-except |
| 96 | safe_exc_args.append(safe_repr(arg)) |
| 97 | return tuple(safe_exc_args) |
| 98 | |
| 99 | |
| 100 | class UnpickleableExceptionWrapper(Exception): |
no outgoing calls