def apply_request_middleware(request, **attrs):
 for middleware_path in settings.MIDDLEWARE_CLASSES:
  mw_class = import_string(middleware_path)
  try:
   mw_instance = mw_class()
  except MiddlewareNotUsed:
   continue
  if hasattr(mw_instance, 'process_request'):
   mw_instance.process_request(request)
 for (key, value) in attrs.items():
  setattr(request, key, value)
 return request

def apply_request_middleware ( request , ** attrs ) : for middleware_path in settings . MIDDLEWARE_CLASSES : mw_class = import_string ( middleware_path ) try : mw_instance = mw_class ( ) except MiddlewareNotUsed : continue if hasattr ( mw_instance , 'process_request' ) : mw_instance . process_request ( request ) for ( key , value ) in attrs . items ( ) : setattr ( request , key , value ) return request
apply all the process_request capable middleware configured into the given request .