def _GetHandlerFromRequest(request):
  """Safely extracts a request handler from a Request.

  Args:
    request: A webapp2.Request instance.

  Returns:
    The handler that corresponds to the given Request (which can be a class or
    method), or None if there is no such handler (e.g. 404's).
  """
  route = getattr(request, 'route', None)
  if route is not None:
    return getattr(route, 'handler', None)