MCPcopy
hub / github.com/django/django / _decode

Method _decode

django/contrib/messages/storage/cookie.py:198–214  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
217def bisect_keep_left(a, fn):

Callers 4

_getMethod · 0.95
encode_decodeMethod · 0.80
test_cookie_settingsMethod · 0.80

Calls 1

unsign_objectMethod · 0.80

Tested by 3

encode_decodeMethod · 0.64
test_cookie_settingsMethod · 0.64