Ejemplo n.º 1
0
    def set(self, name, value, reverse_name = None, validate = True):
        """Sets the property name to the given value.

        If value is an ObjectNode, we're actually setting a link between them two, so we use reverseName as the
        name of the link when followed in the other direction.
        If reverseName is not given, a default of 'isNameOf' (using the given name) will be used."""
        if isinstance(value, (BaseObject, AbstractNode, list, set, collections.Iterator)):
            if reverse_name is None:
                reverse_name = is_of(name)
            self.set_link(name, value, reverse_name)

        elif is_literal(value):
            self.set_literal(name, value)

        else:
            raise TypeError("Trying to set property '%s' of %s to '%s', but it is not of a supported type (literal or object node): %s" % (name, self, value, type(value).__name__))

        # update the cache of valid classes
        if validate:
            self.update_valid_classes()
Ejemplo n.º 2
0
    def set(self, name, value, reverse_name=None, validate=True):
        """Sets the property name to the given value.

        If value is an ObjectNode, we're actually setting a link between them two, so we use reverseName as the
        name of the link when followed in the other direction.
        If reverseName is not given, a default of 'isNameOf' (using the given name) will be used."""
        if isinstance(
                value,
            (BaseObject, AbstractNode, list, set, collections.Iterator)):
            if reverse_name is None:
                reverse_name = is_of(name)
            self.set_link(name, value, reverse_name)

        elif is_literal(value):
            self.set_literal(name, value)

        else:
            raise TypeError(
                "Trying to set property '%s' of %s to '%s', but it is not of a supported type (literal or object node): %s"
                % (name, self, value, type(value).__name__))

        # update the cache of valid classes
        if validate:
            self.update_valid_classes()
Ejemplo n.º 3
0
 def literal_values(self):
     return (v for v in self._props.values() if is_literal(v))
Ejemplo n.º 4
0
 def literal_keys(self):
     return (k for k, v in self._props.items() if is_literal(v))
Ejemplo n.º 5
0
 def get_literal(self, name):
     # if name is not a literal, we need to throw an exception
     result = self._props[name]
     if is_literal(result):
         return result
     raise AttributeError
Ejemplo n.º 6
0
 def edge_items(self):
     return ((k, iter(v)) for k, v in self._props.items() if not is_literal(v))
Ejemplo n.º 7
0
 def edge_values(self):
     return (iter(v) for v in self._props.values() if not is_literal(v))
Ejemplo n.º 8
0
 def edge_keys(self):
     return (k for k, v in self._props.items() if not is_literal(v))
Ejemplo n.º 9
0
 def _outgoing_edge_endpoints(self, name):
     # if name is not an edge, we need to throw an exception
     result = self._props.get(name, [])
     if not is_literal(result):
         return iter(result)
     raise AttributeError
Ejemplo n.º 10
0
 def literal_items(self):
     return ((k, v) for k, v in self._props.items() if is_literal(v))