<s> import time <EOL> from django . http import HttpResponseRedirect <EOL> from django . utils . http import cookie_date <EOL> from django . conf import settings <EOL> from browsecap . browser import is_mobile <EOL> DEFAULT_COOKIE_MAX_AGE = <NUM_LIT> * <NUM_LIT> * <NUM_LIT> <EOL> class MobileRedirectMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> if not getattr ( settings , '<STR_LIT>' , False ) : <EOL> return <EOL> if ( <EOL> request . COOKIES . get ( '<STR_LIT>' , '<STR_LIT:0>' ) == '<STR_LIT:1>' or ( <EOL> '<STR_LIT>' in request . META <EOL> and <EOL> request . COOKIES . get ( '<STR_LIT>' , '<STR_LIT:0>' ) != '<STR_LIT:1>' <EOL> and <EOL> is_mobile ( request . META [ '<STR_LIT>' ] ) <EOL> ) <EOL> ) : <EOL> redirect = settings . MOBILE_DOMAIN <EOL> if getattr ( settings , '<STR_LIT>' , False ) : <EOL> redirect = redirect . rstrip ( '<STR_LIT:/>' ) + request . path_info <EOL> response = HttpResponseRedirect ( redirect ) <EOL> max_age = getattr ( settings , '<STR_LIT>' , DEFAULT_COOKIE_MAX_AGE ) <EOL> expires_time = time . time ( ) + max_age <EOL> expires = cookie_date ( expires_time ) <EOL> response . set_cookie ( '<STR_LIT>' , '<STR_LIT:1>' , domain = settings . SESSION_COOKIE_DOMAIN , max_age = max_age , expires = expires ) <EOL> return response </s>
