'Return an XModule instance for the specified location'

def load_item(self, location, for_parent=None):

    assert isinstance(location, UsageKey)
    if (location.run is None):
        location = location.replace(course_key=self.modulestore.fill_in_run(location.course_key))
    json_data = self.module_data.get(location)
    if (json_data is None):
        module = self.modulestore.get_item(location, using_descriptor_system=self)
        return module
    else:
        try:
            category = json_data['location']['category']
            class_ = self.load_block_type(category)
            definition = json_data.get('definition', {})
            metadata = json_data.get('metadata', {})
            for (old_name, new_name) in getattr(class_, 'metadata_translations', {}).items():
                if (old_name in metadata):
                    metadata[new_name] = metadata[old_name]
                    del metadata[old_name]
            children = [self._convert_reference_to_key(childloc) for childloc in definition.get('children', [])]
            parent = None
            if (self.cached_metadata is not None):
                parent_url = self.cached_metadata.get(unicode(location), {}).get('parent', {}).get((ModuleStoreEnum.Branch.published_only if (location.revision is None) else ModuleStoreEnum.Branch.draft_preferred))
                if parent_url:
                    parent = self._convert_reference_to_key(parent_url)
            if ((not parent) and (category not in DETACHED_XBLOCK_TYPES.union(['course']))):
                parent = self.modulestore.get_parent_location(as_published(location), (ModuleStoreEnum.RevisionOption.published_only if (location.revision is None) else ModuleStoreEnum.RevisionOption.draft_preferred))
            data = definition.get('data', {})
            if isinstance(data, basestring):
                data = {'data': data}
            mixed_class = self.mixologist.mix(class_)
            if data:
                data = self._convert_reference_fields_to_keys(mixed_class, location.course_key, data)
            metadata = self._convert_reference_fields_to_keys(mixed_class, location.course_key, metadata)
            kvs = MongoKeyValueStore(data, parent, children, metadata)
            field_data = KvsFieldData(kvs)
            scope_ids = ScopeIds(None, category, location, location)
            module = self.construct_xblock_from_class(class_, scope_ids, field_data, for_parent=for_parent)
            if (self.cached_metadata is not None):
                non_draft_loc = as_published(location)
                metadata_to_inherit = self.cached_metadata.get(unicode(non_draft_loc), {})
                inherit_metadata(module, metadata_to_inherit)
            module._edit_info = json_data.get('edit_info')
            if (module._edit_info is None):
                module._edit_info = {}
                raw_metadata = json_data.get('metadata', {})
                if raw_metadata.get('published_date'):
                    module._edit_info['published_date'] = datetime(*raw_metadata.get('published_date')[0:6]).replace(tzinfo=UTC)
                module._edit_info['published_by'] = raw_metadata.get('published_by')
            for wrapper in self.modulestore.xblock_field_data_wrappers:
                module._field_data = wrapper(module, module._field_data)
            module.save()
            return module
        except Exception:
            log.warning('Failed    to    load    descriptor    from    %s', json_data, exc_info=True)
            return ErrorDescriptor.from_json(json_data, self, location, error_msg=exc_info_to_str(sys.exc_info()))
