import copy


def recode_ids(cropobjects,
               document_namespace,
               dataset_namespace):
    """Recode all IDs of the given CropObjects, so that they are (hopefully)
    globally unique. That is, from e.g. ``611``, we get
    ``MUSCIMA++_1.0::CVC-MUSCIMA_W-35_N-08_D-ideal::611.

    Creates new CropObjects, does *not* modify the input in-place.

    :param cropobjects: A list of CropObject instances.

    :param document_namespace: An identifier of the given
        CropObjectList. It should be unique for each dataset,
        i.e. ``absolute_dataset_namespace``.

    :param dataset_namespace: An identifier of the given
        dataset. It should be globally unique (which is impossible
        to guarantee, but at least within further versions of MUSCIMA++,
        it should hold).
    """
    output_cropobjects = []
    for c in cropobjects:
        c_out = copy.deepcopy(c)
        uid = c.UID_DELIMITER.join([dataset_namespace,
                                    document_namespace,
                                    str(c.objid)])
        c_out.set_uid(uid)
        output_cropobjects.append(c_out)
    return output_cropobjects