Ejemplo n.º 1
0
    def ProcessIndexNode(self, node):
        """Processes XML <datastore-index> nodes into Index objects.

    The following information is parsed out:
    kind: specifies the kind of entities to index.
    ancestor: true if the index supports queries that filter by
      ancestor-key to constraint results to a single entity group.
    property: represents the entity properties to index, with a name
      and direction attribute.

    Args:
      node: <datastore-index> XML node in datastore-indexes.xml.
    """
        if node.tag != 'datastore-index':
            self.errors.append('Unrecognized node: <%s>' % node.tag)
            return

        index = Index()
        index.kind = node.attrib.get('kind', '')
        if not index.kind:
            self.errors.append(MISSING_KIND)
        ancestor = node.attrib.get('ancestor', 'false')
        index.ancestor = _BooleanAttribute(ancestor)
        if index.ancestor is None:
            self.errors.append(
                'Value for ancestor should be true or false, not "%s"' %
                ancestor)
        properties = []
        property_nodes = [n for n in node.getchildren() if n.tag == 'property']
        for property_node in property_nodes:
            name = property_node.attrib.get('name', '')
            if not name:
                self.errors.append(NAME_MISSING % index.kind)
                continue

            direction = property_node.attrib.get('direction', 'asc')
            if direction not in ('asc', 'desc'):
                self.errors.append(BAD_DIRECTION % direction)
                continue
            properties.append(Property(name=name, direction=direction))
        index.properties = properties
        self.indexes.append(index)
Ejemplo n.º 2
0
  def ProcessIndexNode(self, node):
    """Processes XML <datastore-index> nodes into Index objects.

    The following information is parsed out:
    kind: specifies the kind of entities to index.
    ancestor: true if the index supports queries that filter by
      ancestor-key to constraint results to a single entity group.
    property: represents the entity properties to index, with a name
      and direction attribute.

    Args:
      node: <datastore-index> XML node in datastore-indexes.xml.
    """
    if node.tag != 'datastore-index':
      self.errors.append('Unrecognized node: <%s>' % node.tag)
      return

    index = Index()
    index.kind = node.attrib.get('kind', '')
    if not index.kind:
      self.errors.append(MISSING_KIND)
    ancestor = node.attrib.get('ancestor', 'false')
    index.ancestor = _BooleanAttribute(ancestor)
    if index.ancestor is None:
      self.errors.append(
          'Value for ancestor should be true or false, not "%s"' % ancestor)
    properties = []
    property_nodes = [n for n in node.getchildren() if n.tag == 'property']
    for property_node in property_nodes:
      name = property_node.attrib.get('name', '')
      if not name:
        self.errors.append(NAME_MISSING % index.kind)
        continue

      direction = property_node.attrib.get('direction', 'asc')
      if direction not in ('asc', 'desc'):
        self.errors.append(BAD_DIRECTION % direction)
        continue
      properties.append(Property(name=name, direction=direction))
    index.properties = properties
    self.indexes.append(index)