'Load and return block info.'

@contract(block_key='BlockKey    |    None')
def xblock_from_json(self, class_, course_key, block_key, block_data, course_entry_override=None, **kwargs):

    if (course_entry_override is None):
        course_entry_override = self.course_entry
    else:
        self.course_entry = CourseEnvelope(course_entry_override.course_key, self.course_entry.structure)
    definition_id = block_data.definition
    if (block_key is None):
        block_key = BlockKey(block_data.block_type, LocalId())
    convert_fields = (lambda field: self.modulestore.convert_references_to_keys(course_key, class_, field, self.course_entry.structure['blocks']))
    if ((definition_id is not None) and (not block_data.definition_loaded)):
        definition_loader = DefinitionLazyLoader(self.modulestore, course_key, block_key.type, definition_id, convert_fields)
    else:
        definition_loader = None
    if (definition_id is None):
        definition_id = LocalId()
    block_locator = course_key.make_usage_key(block_type=block_key.type, block_id=block_key.id)
    converted_fields = convert_fields(block_data.fields)
    converted_defaults = convert_fields(block_data.defaults)
    if (block_key in self._parent_map):
        parent_key = self._parent_map[block_key]
        parent = course_key.make_usage_key(parent_key.type, parent_key.id)
    else:
        parent = None
    aside_fields = None
    try:
        if block_data.asides:
            aside_fields = {block_key.type: {}}
            for aside in block_data.asides:
                aside_fields[block_key.type].update(aside['fields'])
    except AttributeError:
        pass
    try:
        kvs = SplitMongoKVS(definition_loader, converted_fields, converted_defaults, parent=parent, aside_fields=aside_fields, field_decorator=kwargs.get('field_decorator'))
        if (InheritanceMixin in self.modulestore.xblock_mixins):
            field_data = inheriting_field_data(kvs)
        else:
            field_data = KvsFieldData(kvs)
        module = self.construct_xblock_from_class(class_, ScopeIds(None, block_key.type, definition_id, block_locator), field_data, for_parent=kwargs.get('for_parent'))
    except Exception:
        log.warning('Failed    to    load    descriptor', exc_info=True)
        return ErrorDescriptor.from_json(block_data, self, course_entry_override.course_key.make_usage_key(block_type='error', block_id=block_key.id), error_msg=exc_info_to_str(sys.exc_info()))
    edit_info = block_data.edit_info
    module._edited_by = edit_info.edited_by
    module._edited_on = edit_info.edited_on
    module.previous_version = edit_info.previous_version
    module.update_version = edit_info.update_version
    module.source_version = edit_info.source_version
    module.definition_locator = DefinitionLocator(block_key.type, definition_id)
    for wrapper in self.modulestore.xblock_field_data_wrappers:
        module._field_data = wrapper(module, module._field_data)
    module.save()
    if isinstance(block_locator.block_id, LocalId):
        self.local_modules[block_locator] = module
    return module
