def execute_task(task, retries=0, handlers_map=None):
  # Find the handler class
  if not handlers_map:
    handlers_map = main.create_handlers_map()

  url = task["url"]
  handler = None

  params = []

  for (re_str, handler_class) in handlers_map:
    re_str = "^" + re_str + "($|\\?)"
    m = re.match(re_str, url)
    if m:
      params = m.groups()[:-1]  # last groups was added by ($|\\?) above
      break
  else:
    raise Exception("Can't determine handler for %s" % task)

  request = mock_webapp.MockRequest()
  request.set_url(url)

  # Set dependent env vars if test hasn't set them.
  version = "mr-test-support-version.1"
  module = "mr-test-support-module"
  default_version_hostname = "mr-test-support.appspot.com"
  host = "%s.%s.%s" % (version.split(".")[0],
                       module,
                       default_version_hostname)

  if "CURRENT_VERSION_ID" not in os.environ:
    request.environ["CURRENT_VERSION_ID"] = version
  if "DEFAULT_VERSION_HOSTNAME" not in os.environ:
    request.environ["DEFAULT_VERSION_HOSTNAME"] = (
        default_version_hostname)
  if "CURRENT_MODULE_ID" not in os.environ:
    request.environ["CURRENT_MODULE_ID"] = module
  if "HTTP_HOST" not in os.environ:
    request.environ["HTTP_HOST"] = host

  # Set taskqueue specific headers and env vars.
  for k, v in task.get("headers", []):
    request.headers[k] = v
    environ_key = "HTTP_" + k.replace("-", "_").upper()
    request.environ[environ_key] = v
  request.headers["X-AppEngine-TaskExecutionCount"] = retries
  request.environ["HTTP_X_APPENGINE_TASKNAME"] = (
      task.get("name", "default_task_name"))
  request.environ["HTTP_X_APPENGINE_QUEUENAME"] = (
      task.get("queue_name", "default"))
  request.environ["PATH_INFO"] = request.path

  if task["method"] == "POST":
    # taskqueue_stub base64 encodes body when it returns the task to us.
    request.body = base64.b64decode(task["body"])
    for k, v in decode_task_payload(task).iteritems():
      request.set(k, v)

  response = mock_webapp.MockResponse()
  saved_os_environ = os.environ
  copy_os_environ = dict(os.environ)
  copy_os_environ.update(request.environ)

  try:
    os.environ = copy_os_environ
    # Webapp2 expects request/response in the handler instantiation, and calls
    # initialize automatically.
    handler = handler_class(request, response)
  except TypeError:
    # For webapp, setup request before calling initialize.
    handler = handler_class()
    handler.initialize(request, response)
  finally:
    os.environ = saved_os_environ

  try:
    os.environ = copy_os_environ

    if task["method"] == "POST":
      handler.post(*params)
    elif task["method"] == "GET":
      handler.get(*params)
    else:
      raise Exception("Unsupported method: %s" % task.method)
  finally:
    os.environ = saved_os_environ

  if handler.response.status != 200:
    raise Exception("Handler failure: %s (%s). \nTask: %s\nHandler: %s" %
                    (handler.response.status,
                     handler.response.status_message,
                     task,
                     handler))
  return handler
Most important function. Please send me feedback :-)
dataset/ETHPy150Open GoogleCloudPlatform/appengine-mapreduce/python/src/mapreduce/test_support.py/execute_task--crossover with--dataset/ETHPy150Open kootenpv/yagmail/yagmail/yagmail.py/SMTP.feedback