<s> from __future__ import unicode_literals <EOL> import sys , os <EOL> from django . conf import settings <EOL> from django . http import HttpResponseRedirect , HttpResponse <EOL> from django . utils import timezone <EOL> from six . moves import StringIO <EOL> class AjaxRedirect ( object ) : <EOL> def process_response ( self , request , response ) : <EOL> if request . is_ajax ( ) : <EOL> if type ( response ) == HttpResponseRedirect : <EOL> response = HttpResponse ( response [ "<STR_LIT>" ] ) <EOL> response . status_code = <NUM_LIT> <EOL> return response <EOL> class ProfileMiddleware ( ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def process_view ( self , request , view , * args , ** kwargs ) : <EOL> import hotshot , hotshot . stats <EOL> for item in request . META [ '<STR_LIT>' ] . split ( '<STR_LIT:&>' ) : <EOL> if item . split ( '<STR_LIT:=>' ) [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> std_old , std_new = sys . stdout , StringIO . StringIO ( ) <EOL> sys . stdout = std_new <EOL> tmpfile = '<STR_LIT>' % request . COOKIES [ '<STR_LIT>' ] <EOL> prof = hotshot . Profile ( tmpfile ) <EOL> response = prof . runcall ( view , request , * args [ <NUM_LIT:0> ] , ** args [ <NUM_LIT:1> ] ) <EOL> prof . close ( ) <EOL> stats = hotshot . stats . load ( tmpfile ) <EOL> stats . strip_dirs ( ) <EOL> stats . sort_stats ( '<STR_LIT:time>' ) <EOL> stats . print_stats ( <NUM_LIT:1.0> ) <EOL> sys . stdout = std_old <EOL> os . remove ( tmpfile ) <EOL> return HttpResponse ( '<STR_LIT>' % std_new . getvalue ( ) ) <EOL> return None <EOL> class TimezoneMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> user_tz = getattr ( settings , '<STR_LIT>' , None ) <EOL> if user_tz : <EOL> timezone . activate ( user_tz ) </s>
