<s> from __future__ import unicode_literals <EOL> import uuid <EOL> from machina . core . loading import get_class <EOL> PermissionHandler = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class ForumPermissionMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> anonymous_forum_key_session_id = '<STR_LIT>' <EOL> def process_request ( self , request ) : <EOL> if not request . user . is_authenticated ( ) : <EOL> anonymous_forum_key = request . session . get ( self . anonymous_forum_key_session_id , None ) <EOL> if anonymous_forum_key is None : <EOL> anonymous_forum_key = self . get_anonymous_forum_key ( ) <EOL> request . session [ self . anonymous_forum_key_session_id ] = anonymous_forum_key <EOL> setattr ( request . user , '<STR_LIT>' , anonymous_forum_key ) <EOL> request . forum_permission_handler = PermissionHandler ( ) <EOL> def get_anonymous_forum_key ( self ) : <EOL> """<STR_LIT>""" <EOL> return uuid . uuid4 ( ) . hex </s>
