

def _deserialize(self, entity, p, depth=1):
    if (not self._repeated):
        subentity = self._retrieve_value(entity)
        if (subentity is None):
            subentity = self._modelclass()
            self._store_value(entity, _BaseValue(subentity))
        cls = self._modelclass
        if isinstance(subentity, _BaseValue):
            subentity = subentity.b_val
        if (not isinstance(subentity, cls)):
            raise RuntimeError(('Cannot deserialize StructuredProperty %s; value retrieved not a %s instance %r' % (self._name, cls.__name__, subentity)))
        indexed = (p.meaning_uri() != _MEANING_URI_COMPRESSED)
        prop = subentity._get_property_for(p, depth=depth, indexed=indexed)
        if (prop is None):
            self._store_value(entity, None)
            return
        prop._deserialize(subentity, p, (depth + 1))
        return
    name = p.name()
    parts = name.split('.')
    if (len(parts) <= depth):
        raise RuntimeError(('StructuredProperty %s expected to find properties separated by periods at a depth of %i; received %r' % (self._name, depth, parts)))
    next = parts[depth]
    rest = parts[(depth + 1):]
    prop = self._modelclass._properties.get(next)
    prop_is_fake = False
    if (prop is None):
        if rest:
            logging.warn('Skipping unknown structured subproperty (%s) in repeated structured property (%s of %s)', name, self._name, entity.__class__.__name__)
            return
        compressed = (p.meaning_uri() == _MEANING_URI_COMPRESSED)
        prop = GenericProperty(next, compressed=compressed)
        prop._code_name = next
        prop_is_fake = True
    if (not hasattr(entity, '_subentity_counter')):
        entity._subentity_counter = _NestedCounter()
    counter = entity._subentity_counter
    counter_path = parts[(depth - 1):]
    next_index = counter.get(counter_path)
    subentity = None
    if self._has_value(entity):
        while (next_index < self._get_value_size(entity)):
            subentity = self._get_base_value_at_index(entity, next_index)
            if (not isinstance(subentity, self._modelclass)):
                raise TypeError('sub-entities must be instances of their Model class.')
            if (not prop._has_value(subentity, rest)):
                break
            next_index = counter.increment(counter_path)
        else:
            subentity = None
    counter.increment(counter_path)
    if (not subentity):
        subentity = self._modelclass()
        values = self._retrieve_value(entity, self._default)
        if (values is None):
            self._store_value(entity, [])
            values = self._retrieve_value(entity, self._default)
        values.append(_BaseValue(subentity))
    if prop_is_fake:
        subentity._clone_properties()
        subentity._properties[prop._name] = prop
    prop._deserialize(subentity, p, (depth + 1))

dataset/ETHPy150Open GoogleCloudPlatform/datastore-ndb-python/ndb/model.py StructuredProperty._deserialize/original