def Create(self, urn, aff4_type, mode="w", token=None, age=NEWEST_TIME,
             ignore_cache=False, 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".
      ignore_cache: Bypass the aff4 cache.
      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 transaction is passed to the object.

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

    Raises:
      AttributeError: If the mode is invalid.
    """
    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)

    if "r" in mode:
      # Check to see if an object already exists.
      try:
        existing = self.Open(
            urn, mode=mode, token=token, age=age,
            ignore_cache=ignore_cache, 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

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

    # Object does not exist, just make it.
    cls = AFF4Object.classes[str(aff4_type)]
    result = cls(urn, mode=mode, token=token, age=age, aff4_type=aff4_type,
                 object_exists=object_exists, mutation_pool=mutation_pool,
                 transaction=transaction)
    result.Initialize()
    if force_new_version:
      result.ForceNewVersion()

    return result
dataset/ETHPy150Open google/grr/grr/lib/aff4.py/Factory.Create