<s> import json <EOL> from django . contrib . messages . storage . base import BaseStorage <EOL> from django . contrib . messages . storage . cookie import ( <EOL> MessageDecoder , MessageEncoder , <EOL> ) <EOL> from django . utils import six <EOL> class SessionStorage ( BaseStorage ) : <EOL> """<STR_LIT>""" <EOL> session_key = '<STR_LIT>' <EOL> def __init__ ( self , request , * args , ** kwargs ) : <EOL> assert hasattr ( request , '<STR_LIT>' ) , "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> super ( SessionStorage , self ) . __init__ ( request , * args , ** kwargs ) <EOL> def _get ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . deserialize_messages ( self . request . session . get ( self . session_key ) ) , True <EOL> def _store ( self , messages , response , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if messages : <EOL> self . request . session [ self . session_key ] = self . serialize_messages ( messages ) <EOL> else : <EOL> self . request . session . pop ( self . session_key , None ) <EOL> return [ ] <EOL> def serialize_messages ( self , messages ) : <EOL> encoder = MessageEncoder ( separators = ( '<STR_LIT:U+002C>' , '<STR_LIT::>' ) ) <EOL> return encoder . encode ( messages ) <EOL> def deserialize_messages ( self , data ) : <EOL> if data and isinstance ( data , six . string_types ) : <EOL> return json . loads ( data , cls = MessageDecoder ) <EOL> return data </s>
