def CheckReference(request_trusted,
                   request_app_id,
                   key,
                   require_id_or_name=True):
  """Check this key.

  Args:
    request_trusted: If the request is trusted.
    request_app_id: The application ID of the app making the request.
    key: entity_pb.Reference
    require_id_or_name: Boolean indicating if we should enforce the presence of
      an id or name in the last element of the key's path.

  Raises:
    apiproxy_errors.ApplicationError: if the key is invalid
  """

  assert isinstance(key, entity_pb.Reference)

  CheckAppId(request_trusted, request_app_id, key.app())

  Check(key.path().element_size() > 0, 'key\'s path cannot be empty')

  if require_id_or_name and not datastore_pbs.is_complete_v3_key(key):
    raise datastore_errors.BadRequestError('missing key id/name')

  for elem in key.path().element_list():
    Check(not elem.has_id() or not elem.has_name(),
          key % 'each key path element should have id or name but not both: %r')
    CheckValidUTF8(elem.type(), 'key path element type')
    if elem.has_name():
      CheckValidUTF8(elem.name(), 'key path element name')
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/datastore/datastore_stub_util.py/CheckReference/swapped operands of `%`