Exemplo n.º 1
0
    def setvalue(self,
                 node,
                 name,
                 converter,
                 value,
                 attribs=None,
                 hsdblock=False):
        """Creates a child with the given value.

        Parameters
        ----------
        node : Element
            Parent node.
        name : str
            Name of the child node to create.
        converter : converter object
            Object with methods fromhsd() and tohsd() which can
            convert between the hsd element and the desired type. See
            converters in hsd.converter for examples.
        value : arbitrary
            Value which should be converted to text by the converter.
        attribs : dict
            Dictionary with attributes for the child.
        hsdblock : bool, optional
            Whether the given value should be added in hsd block notation
            (enclosed in curly braces) instead of an assignment.

        Returns
        -------
        child : Element
            The child node which had been created and added.
        """

        child = Element(name, attribs or {})
        if converter:
            child.text = converter.tohsd(value)
        else:
            child.text = value
        self.markprocessed(child)
        if not hsdblock:
            child.sethsd(hsd.HSDATTR_EQUAL, True)
        node.append(child)
        return child