Archive field
        :param elem:
        :param elem_type:
        :param params:
        :param obj:
        :return:
433239
async def field(self, elem=None, elem_type=None, params=None, obj=None):
        
        elem_type = elem_type if elem_type else elem.__class__
        fvalue = None

        src = elem if self.writing else obj
        dst = obj if self.writing else elem

        # TODO: optional elem, default value for deserialization...

        # Blob wrapper. Underlying structure should be serialized as blob.
        if x.is_type(elem_type, BlobFieldWrapper):
            blobber = Blobber(self.writing, data=x.get_elem(src) if not self.writing else None)
            fvalue = await blobber.blobize(elem=x.get_elem(src), elem_type=elem_type.ftype, params=params)
            fvalue = NoSetSentinel() if fvalue is None or len(fvalue) == 0 else fvalue

        elif issubclass(elem_type, x.UVarintType):
            fvalue = await self.uvarint(x.get_elem(src))

        elif issubclass(elem_type, x.IntType):
            fvalue = await self.uint(elem=x.get_elem(src), elem_type=elem_type, params=params)

        elif issubclass(elem_type, x.BlobType):
            fvalue = await self.blob(elem=x.get_elem(src), elem_type=elem_type, params=params)

        elif issubclass(elem_type, x.UnicodeType):
            fvalue = await self.unicode_type(x.get_elem(src))

        elif issubclass(elem_type, x.VariantType):
            fvalue = await self.variant(elem=x.get_elem(src), elem_type=elem_type, params=params, obj=dst)

        elif issubclass(elem_type, x.ContainerType):  # container ~ simple list
            fvalue = await self.container(container=x.get_elem(src), container_type=elem_type, params=params, obj=dst)

        elif issubclass(elem_type, x.TupleType):  # tuple ~ simple list
            fvalue = await self.tuple(elem=x.get_elem(src), elem_type=elem_type, params=params, obj=dst)

        elif issubclass(elem_type, x.MessageType):
            fvalue = await self.message(x.get_elem(src), msg_type=elem_type, obj=dst)

        else:
            raise TypeError

        return x.set_elem(dst, fvalue) if not isinstance(fvalue, NoSetSentinel) else fvalue
1006356
async def _dump_variant(self, writer, elem, elem_type=None, params=None):
        
        if isinstance(elem, VariantType) or elem_type.WRAPS_VALUE:
            await dump_uint(writer, elem.variant_elem_type.VARIANT_CODE, 1)
            await self.dump_field(
                writer, getattr(elem, elem.variant_elem), elem.variant_elem_type
            )

        else:
            fdef = find_variant_fdef(elem_type, elem)
            await dump_uint(writer, fdef[1].VARIANT_CODE, 1)
            await self.dump_field(writer, elem, fdef[1])
565830
async def dump_message_field(obj, msg, field, field_archiver=None):
    
    fname, ftype, params = field[0], field[1], field[2:]
    fvalue = getattr(msg, fname, None)
    field_archiver = field_archiver if field_archiver else dump_field
    return await field_archiver(eref(obj, fname, True), fvalue, ftype, params)
698985
def asset_archive(class_obj: type) -> type:
    
    assert isinstance(class_obj, type), "class_obj is not a Class"
    global _asset_archive_resource_type
    _asset_archive_resource_type = class_obj
    return class_obj
846518
def record_to_objects(self, preference=None):
        
        from ambry.orm.file import File

        for f in self.list_records():

            pref = preference if preference else f.record.preference

            if pref == File.PREFERENCE.FILE:
                self._bundle.logger.debug('   Cleaning objects for file {}'.format(f.path))
                f.clean_objects()

            if pref in (File.PREFERENCE.FILE, File.PREFERENCE.MERGE):
                self._bundle.logger.debug('   rto {}'.format(f.path))
                f.record_to_objects()
1353252
async def blob(self, elem=None, elem_type=None, params=None):
        
        elem_type = elem_type if elem_type else elem.__class__
        if hasattr(elem_type, 'kv_serialize'):
            elem = elem_type() if elem is None else elem
            return await elem.kv_serialize(self, elem=elem, elem_type=elem_type, params=params)

        if self.writing:
            elem_is_blob = isinstance(elem, x.BlobType)
            data = getattr(elem, x.BlobType.DATA_ATTR) if elem_is_blob else elem
            if data is None:
                return NoSetSentinel()
            if len(data) == 0:
                return b''

            fval = Modeler.to_bytes(data)
            if self.hexlify:
                return binascii.hexlify(fval).decode('ascii')
            else:
                return fval

        else:
            if elem is None:
                return NoSetSentinel()
            if self.hexlify:
                return bytes(binascii.unhexlify(elem))
            else:
                return bytes(elem)
93483
def _get_archive_listing(self, archive_name):
        '''
        
        '''

        res = self.collection.find_one({'_id': archive_name})

        if res is None:
            raise KeyError

        return res
1037149
def build_archive(cls, **kwargs):
        
        if cls._archive is None:
            cls._archive = cls(**kwargs)
        return cls._archive
1149461
def format_content_type_object(repo, content_type, uuid):
    
    try:
        storage_manager = StorageManager(repo)
        model_class = load_model_class(repo, content_type)
        return dict(storage_manager.get(model_class, uuid))
    except GitCommandError:
        raise NotFound('Object does not exist.')
626620
def elem_type(self):
        
        if not hasattr(self, "_elem_type"):
            self._elem_type = get_elem_type(self.elem)
        return self._elem_type
316787
async def field(self, elem=None, elem_type=None, params=None):
        
        elem_type = elem_type if elem_type else elem.__class__
        fvalue = None

        src = elem
        if issubclass(elem_type, x.UVarintType):
            fvalue = await self.uvarint(x.get_elem(src))

        elif issubclass(elem_type, x.IntType):
            fvalue = await self.uint(elem=x.get_elem(src), elem_type=elem_type, params=params)

        elif issubclass(elem_type, x.BlobType):
            fvalue = await self.blob(elem=x.get_elem(src), elem_type=elem_type, params=params)

        elif issubclass(elem_type, x.UnicodeType):
            fvalue = await self.unicode_type(x.get_elem(src))

        elif issubclass(elem_type, x.VariantType):
            fvalue = await self.variant(elem=x.get_elem(src), elem_type=elem_type, params=params)

        elif issubclass(elem_type, x.ContainerType):  # container ~ simple list
            fvalue = await self.container(container=x.get_elem(src), container_type=elem_type, params=params)

        elif issubclass(elem_type, x.TupleType):  # tuple ~ simple list
            fvalue = await self.tuple(elem=x.get_elem(src), elem_type=elem_type, params=params)

        elif issubclass(elem_type, x.MessageType):
            fvalue = await self.message(x.get_elem(src), msg_type=elem_type)

        else:
            raise TypeError

        return fvalue if self.writing else x.set_elem(elem, fvalue)
501306
async def container(self, container=None, container_type=None, params=None):
        
        if hasattr(container_type, "serialize_archive"):
            container = container_type() if container is None else container
            return await container.serialize_archive(
                self, elem=container, elem_type=container_type, params=params
            )

        if self.writing:
            return await self._dump_container(
                self.iobj, container, container_type, params
            )
        else:
            return await self._load_container(
                self.iobj, container_type, params=params, container=container
            )
1200356
def get_elem_type(elem):
    
    elem_type = None
    if isinstance(elem, list):
        if elem[0].get("type") == "radio":
            elem_type = "radio"
        else:
            raise ValueError(u"Unknown element type: {}".format(elem))

    elif elem.name == "select":
        elem_type = "select"

    elif elem.name == "input":
        elem_type = elem.get("type")

    else:
        raise ValueError(u"Unknown element type: {}".format(elem))

    # To be removed
    assert elem_type is not None

    return elem_type
695761
async def tuple(self, elem=None, elem_type=None, params=None):
        
        if hasattr(elem_type, "serialize_archive"):
            container = elem_type() if elem is None else elem
            return await container.serialize_archive(
                self, elem=elem, elem_type=elem_type, params=params
            )

        if self.writing:
            return await self._dump_tuple(self.iobj, elem, elem_type, params)
        else:
            return await self._load_tuple(
                self.iobj, elem_type, params=params, elem=elem
            )
1003904
async def dump_variant(obj, elem, elem_type=None, params=None, field_archiver=None):
    
    field_archiver = field_archiver if field_archiver else dump_field
    if isinstance(elem, x.VariantType) or elem_type.WRAPS_VALUE:
        return {
            elem.variant_elem: await field_archiver(None, getattr(elem, elem.variant_elem), elem.variant_elem_type)
        }

    else:
        fdef = elem_type.find_fdef(elem_type.f_specs(), elem)
        return {
            fdef[0]: await field_archiver(None, elem, fdef[1])
        }
1202491
async def dump_message(obj, msg, field_archiver=None):
    
    mtype = msg.__class__
    fields = mtype.f_specs()

    obj = collections.OrderedDict() if obj is None else get_elem(obj)
    for field in fields:
        await dump_message_field(obj, msg=msg, field=field, field_archiver=field_archiver)
    return obj
684679
async def variant(self, elem=None, elem_type=None, params=None):
        
        elem_type = elem_type if elem_type else elem.__class__
        version = await self.version(elem_type, params, elem=elem)

        if self.is_tracked():
            return self.get_tracked()

        if hasattr(elem_type, 'boost_serialize'):
            elem = elem_type() if elem is None else elem
            self.pop_track()
            return await elem.boost_serialize(self, elem=elem, elem_type=elem_type, params=params, version=version)

        if self.writing:
            self.pop_track()
            return await self.dump_variant(elem=elem,
                                           elem_type=elem_type if elem_type else elem.__class__, params=params)
        else:
            obj = await self.load_variant(elem_type=elem_type if elem_type else elem.__class__,
                                          params=params, elem=elem)
            return self.track_obj(obj)