Updates type integer in the cerate UO specification.
        Type has to already have generations flags set correctly.
        Generation field is set accordingly.

        :param spec:
        :param obj_type:
        :return:

def set_type(spec, obj_type):
        """
        Updates type integer in the cerate UO specification.
        Type has to already have generations flags set correctly.
        Generation field is set accordingly.

        :param spec:
        :param obj_type:
        :return:
        """
        if spec is None:
            raise ValueError('Spec cannot be None')
        if TemplateFields.generation not in spec:
            spec[TemplateFields.generation] = {}

        spec[TemplateFields.generation][TemplateFields.commkey] = \
            Gen.CLIENT if (obj_type & (int(1) << TemplateFields.FLAG_COMM_GEN)) > 0 else Gen.LEGACY_RANDOM
        spec[TemplateFields.generation][TemplateFields.appkey] = \
            Gen.CLIENT if (obj_type & (int(1) << TemplateFields.FLAG_APP_GEN)) > 0 else Gen.LEGACY_RANDOM
        spec[TemplateFields.type] = "%x" % obj_type
        return spec