#NEWLINE# def process_request( self , request ) : #NEWLINE# #INDENT# '\n        Check for denied User-Agents and rewrite the URL based on\n        settings.APPEND_SLASH and settings.PREPEND_WWW\n        ' #NEWLINE# if ( 'HTTP_USER_AGENT' in request . META ) : #NEWLINE# #INDENT# for user_agent_regex in settings . DISALLOWED_USER_AGENTS : #NEWLINE# #INDENT# if user_agent_regex . search ( request . META [ 'HTTP_USER_AGENT' ] ) : #NEWLINE# #INDENT# logger . warning ( 'Forbidden (User agent): %s' , request . path , extra = { #NEWLINE# #INDENT# 'status_code' : 403 , #NEWLINE# 'request' : request , #NEWLINE# #UNINDENT# } ) #NEWLINE# return http . HttpResponseForbidden ( '<h1>Forbidden</h1>' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# host = request . get_host ( ) #NEWLINE# old_url = [ host , request . path ] #NEWLINE# new_url = old_url [ : ] #NEWLINE# if ( settings . PREPEND_WWW and old_url [ 0 ] and ( not old_url [ 0 ] . startswith ( 'www.' ) ) ) : #NEWLINE# #INDENT# new_url [ 0 ] = ( 'www.' + old_url [ 0 ] ) #NEWLINE# #UNINDENT# if ( settings . APPEND_SLASH and ( not old_url [ 1 ] . endswith ( '/' ) ) ) : #NEWLINE# #INDENT# urlconf = getattr ( request , 'urlconf' , None ) #NEWLINE# if ( ( not urlresolvers . is_valid_path ( request . path_info , urlconf ) ) and urlresolvers . is_valid_path ( ( '%s/' % request . path_info ) , urlconf ) ) : #NEWLINE# #INDENT# new_url [ 1 ] = ( new_url [ 1 ] + '/' ) #NEWLINE# if ( settings . DEBUG and ( request . method == 'POST' ) ) : #NEWLINE# #INDENT# raise RuntimeError ( ( "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % ( new_url [ 0 ] , new_url [ 1 ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( new_url == old_url ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if new_url [ 0 ] : #NEWLINE# #INDENT# newurl = ( '%s://%s%s' % ( ( 'https' if request . is_secure ( ) else 'http' ) , new_url [ 0 ] , urlquote ( new_url [ 1 ] ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# newurl = urlquote ( new_url [ 1 ] ) #NEWLINE# #UNINDENT# if request . META . get ( 'QUERY_STRING' , '' ) : #NEWLINE# #INDENT# if six . PY3 : #NEWLINE# #INDENT# newurl += ( '?' + request . META [ 'QUERY_STRING' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# newurl += ( '?' + request . META [ 'QUERY_STRING' ] . decode ( ) ) #NEWLINE# #UNINDENT# except UnicodeDecodeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return http . HttpResponsePermanentRedirect ( newurl )