Safely decode an encoded text stream back into a list of messages. If the encoded text stream contained an invalid hash or was in an invalid format, return None.
(self, data)
| 196 | return self._encode_parts(serialized_messages, encode_empty=encode_empty) |
| 197 | |
| 198 | def _decode(self, data): |
| 199 | """ |
| 200 | Safely decode an encoded text stream back into a list of messages. |
| 201 | |
| 202 | If the encoded text stream contained an invalid hash or was in an |
| 203 | invalid format, return None. |
| 204 | """ |
| 205 | if not data: |
| 206 | return None |
| 207 | try: |
| 208 | return self.signer.unsign_object(data, serializer=MessageSerializer) |
| 209 | except (signing.BadSignature, binascii.Error, json.JSONDecodeError): |
| 210 | pass |
| 211 | # Mark the data as used (so it gets removed) since something was wrong |
| 212 | # with the data. |
| 213 | self.used = True |
| 214 | return None |
| 215 | |
| 216 | |
| 217 | def bisect_keep_left(a, fn): |