Creates the urn if it does not already exist, otherwise opens it.

    If the urn exists and is of a different type, this will also promote it to
    the specified type.

    Args:
      urn: The object to create.
      aff4_type: The desired type for this object.
      mode: The desired mode for this object.
      token: The Security Token to use for opening this item.
      age: The age policy used to build this object. Only makes sense when mode
        has "r".
      force_new_version: Forces the creation of a new object in the data_store.
      object_exists: If we know the object already exists we can skip index
        creation.
      mutation_pool: An optional MutationPool object to write to. If not given,
        the data_store is used directly.
      transaction: For locked objects, a lock is passed to the object.

    Returns:
      An AFF4 object of the desired type and mode.

    Raises:
      AttributeError: If the mode is invalid.

def Create(self,
             urn,
             aff4_type,
             mode="w",
             token=None,
             age=NEWEST_TIME,
             force_new_version=True,
             object_exists=False,
             mutation_pool=None,
             transaction=None):
    """Creates the urn if it does not already exist, otherwise opens it.

    If the urn exists and is of a different type, this will also promote it to
    the specified type.

    Args:
      urn: The object to create.
      aff4_type: The desired type for this object.
      mode: The desired mode for this object.
      token: The Security Token to use for opening this item.
      age: The age policy used to build this object. Only makes sense when mode
        has "r".
      force_new_version: Forces the creation of a new object in the data_store.
      object_exists: If we know the object already exists we can skip index
        creation.
      mutation_pool: An optional MutationPool object to write to. If not given,
        the data_store is used directly.
      transaction: For locked objects, a lock is passed to the object.

    Returns:
      An AFF4 object of the desired type and mode.

    Raises:
      AttributeError: If the mode is invalid.
    """
    if not data_store.AFF4Enabled():
      raise NotImplementedError("AFF4 data store has been disabled.")

    if mode not in ["w", "r", "rw"]:
      raise AttributeError("Invalid mode %s" % mode)

    if token is None:
      token = data_store.default_token

    if urn is not None:
      urn = rdfvalue.RDFURN(urn)

    _ValidateAFF4Type(aff4_type)

    if "r" in mode:
      # Check to see if an object already exists.
      try:
        existing = self.Open(
            urn, mode=mode, token=token, age=age, transaction=transaction)

        result = existing.Upgrade(aff4_type)

        # We can't pass aff4_type into the Open call since it will raise with a
        # type mismatch. We set it like this so BadGetAttributeError checking
        # works.
        if aff4_type:
          result.aff4_type = aff4_type.__name__

        if force_new_version and existing.Get(
            result.Schema.TYPE) != aff4_type.__name__:
          result.ForceNewVersion()
        return result
      except IOError:
        pass

    result = aff4_type(
        urn,
        mode=mode,
        token=token,
        age=age,
        aff4_type=aff4_type.__name__,
        object_exists=object_exists,
        mutation_pool=mutation_pool,
        transaction=transaction)
    result.Initialize()
    if force_new_version:
      result.ForceNewVersion()

    return result