<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from flask import _request_ctx_stack , abort , request <EOL> from flaskext . kvsession import KVSessionExtension <EOL> from flaskext . csrf import csrf , csrf_exempt <EOL> from simplekv . memory import DictStore <EOL> class Mitten ( object ) : <EOL> def __init__ ( self , app = None ) : <EOL> if app is not None : <EOL> self . init_app ( app ) <EOL> def init_app ( self , app ) : <EOL> self . app = app <EOL> self . banner = '<STR_LIT>' <EOL> self . cookie_httponly = True <EOL> self . _json_views = [ ] <EOL> self . app . before_request ( self . before_request ) <EOL> self . app . after_request ( self . after_request ) <EOL> store = DictStore ( ) <EOL> KVSessionExtension ( store , self . app ) <EOL> csrf ( self . app ) <EOL> self . csrf_exempt = csrf_exempt <EOL> def before_request ( self ) : <EOL> ctx = _request_ctx_stack . top <EOL> dest = self . app . view_functions . get ( request . endpoint ) <EOL> ctx . request_json = dest in self . _json_views <EOL> if ctx . request_json : <EOL> if not request . is_xhr : <EOL> ctx . forbidden = True <EOL> abort ( <NUM_LIT> ) <EOL> else : <EOL> ctx . forbidden = False <EOL> def after_request ( self , response ) : <EOL> ctx = _request_ctx_stack . top <EOL> headers = response . headers <EOL> headers [ '<STR_LIT>' ] = self . banner <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> if self . cookie_httponly and '<STR_LIT>' in response . headers : <EOL> headers [ '<STR_LIT>' ] += '<STR_LIT>' <EOL> if ctx . request_json and not ctx . forbidden : <EOL> headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return response <EOL> def json ( self , view ) : <EOL> self . _json_views . append ( view ) <EOL> return view </s>
