

def _comparison(self, op, value):
    if (op != '='):
        raise datastore_errors.BadFilterError('StructuredProperty filter can only use ==')
    if (not self._indexed):
        raise datastore_errors.BadFilterError(('Cannot query for unindexed StructuredProperty %s' % self._name))
    from .query import ConjunctionNode, PostFilterNode
    from .query import RepeatedStructuredPropertyPredicate
    if (value is None):
        from .query import FilterNode
        return FilterNode(self._name, op, value)
    value = self._do_validate(value)
    value = self._call_to_base_type(value)
    filters = []
    match_keys = []
    for prop in self._modelclass._properties.itervalues():
        vals = prop._get_base_value_unwrapped_as_list(value)
        if prop._repeated:
            if vals:
                raise datastore_errors.BadFilterError(('Cannot query for non-empty repeated property %s' % prop._name))
            continue
        assert (isinstance(vals, list) and (len(vals) == 1)), repr(vals)
        val = vals[0]
        if (val is not None):
            altprop = getattr(self, prop._code_name)
            filt = altprop._comparison(op, val)
            filters.append(filt)
            match_keys.append(altprop._name)
    if (not filters):
        raise datastore_errors.BadFilterError('StructuredProperty filter without any values')
    if (len(filters) == 1):
        return filters[0]
    if self._repeated:
        pb = value._to_pb(allow_partial=True)
        pred = RepeatedStructuredPropertyPredicate(match_keys, pb, (self._name + '.'))
        filters.append(PostFilterNode(pred))
    return ConjunctionNode(*filters)

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