def SetPublicEndpointStatus(api_query, status=None):
  """Change the public endpoint status of an API Query.

  Args:
    api_query: The API Query to change
    status: The status to change the API Query to. If status=None then the
            status of the API Query will be toggled.

  Returns:
    True if status change was successful, False otherwise.
  """
  if api_query and status in (None, True, False):
    if not status:
      api_query.is_active = not api_query.is_active
    else:
      api_query.is_active = status

    if api_query.is_active is False:
      api_query.is_scheduled = False

    try:
      api_query.put()
      memcache.delete_multi(['api_query'] + co.SUPPORTED_FORMATS.keys(),
                            key_prefix=str(api_query.key()))
      return True
    except db.TransactionFailedError:
      return False
  return False
dataset/ETHPy150Open googleanalytics/google-analytics-super-proxy/src/controllers/util/query_helper.py/SetPublicEndpointStatus/original