<s> from __future__ import unicode_literals <EOL> from django . core . signing import b64_encode <EOL> from django . middleware . csrf import get_token <EOL> from django . utils . crypto import get_random_string <EOL> from django . utils . encoding import force_bytes , force_text <EOL> from django . utils . functional import lazy <EOL> from django . utils . six import text_type <EOL> from debreach . utils import xor <EOL> def csrf ( request ) : <EOL> """<STR_LIT>""" <EOL> def _get_val ( ) : <EOL> token = get_token ( request ) <EOL> if token is None : <EOL> return '<STR_LIT>' <EOL> else : <EOL> token = force_bytes ( token , encoding = '<STR_LIT>' ) <EOL> key = force_bytes ( <EOL> get_random_string ( len ( token ) ) , <EOL> encoding = '<STR_LIT>' <EOL> ) <EOL> value = b64_encode ( xor ( token , key ) ) <EOL> return force_text ( b'<STR_LIT:$>' . join ( ( key , value ) ) , encoding = '<STR_LIT>' ) <EOL> _get_val = lazy ( _get_val , text_type ) <EOL> return { '<STR_LIT>' : _get_val ( ) } </s>
