Translate a node into some output format.
        :param node: a treebrd node
        :return: a node's translation to some format
498327
def translate(self, node):
        
        _translate = self._translate_functions.get(node.operator)
        return _translate(node)
1239829
def export_node(self, n) -> Dict[str, Union[str, List[str]]]:
        
        node_dict = {
            "name": n[0],
            "units": _get_units(n[0]),
            "dtype": _get_dtype(n[0]),
            "arguments": list(self.predecessors(n[0])),
        }

        if not n[1].get("indicators") is None:
            for indicator in n[1]["indicators"].values():
                if "dataset" in indicator.__dict__:
                    del indicator.__dict__["dataset"]

            node_dict["indicators"] = [
                _process_datetime(indicator.__dict__)
                for indicator in n[1]["indicators"].values()
            ]
        else:
            node_dict["indicators"] = None

        return node_dict
150806
def parse(self, node):
        
        self._attrs = {}
        vals = []
        yielded = False

        for x in self._read_parts(node):
            if isinstance(x, Field):
                yielded = True
                x.attrs = self._attrs
                yield x
            else:
                vals.append(ustr(x).strip(' \n\t'))

        joined = ' '.join([ x for x in vals if x ])
        if joined:
            yielded = True
            yield Field(node, guess_type(joined), self._attrs)

        if not yielded:
            yield Field(node, "", self._attrs)
1110688
def node_to_object(self, node, object):
        ""

        attribute = self.to_lower(node.tag)

        # Yield is a protected keyword in Python, so let's rename it
        attribute = "_yield" if attribute == "yield" else attribute

        try:
            valueString = node.text or ""
            value = float(valueString)
        except ValueError:
            value = node.text

        try:
            setattr(object, attribute, value)
        except AttributeError():
            sys.stderr.write("Attribute <%s> not supported." % attribute)
800700
def _tree_to_string(cls, root_element, xml_declaration=True, pretty_print=True):
        
        from lxml import etree
        return gf.safe_unicode(etree.tostring(
            root_element,
            encoding="UTF-8",
            method="xml",
            xml_declaration=xml_declaration,
            pretty_print=pretty_print
        ))
400021
def transform(self, transform, node):
        
        method = transform.get('Algorithm')
        if method not in constants.TransformUsageDSigTransform:
            raise Exception('Method not allowed')
        # C14N methods are allowed
        if method in constants.TransformUsageC14NMethod:
            return self.canonicalization(method, etree.fromstring(node))
        # Enveloped method removes the Signature Node from the element
        if method == constants.TransformEnveloped:
            tree = transform.getroottree()
            root = etree.fromstring(node)
            signature = root.find(
                tree.getelementpath(
                    transform.getparent().getparent().getparent().getparent()
                )
            )
            root.remove(signature)
            return self.canonicalization(
                    constants.TransformInclC14N, root)
        if method == constants.TransformBase64:
            try:
                root = etree.fromstring(node)
                return base64.b64decode(root.text)
            except Exception:
                return base64.b64decode(node)

        raise Exception('Method not found')
677443
def tree(s, token=[WORD, POS, CHUNK, PNP, REL, LEMMA]):
    
    return Text(s, token)
1224982
def describe_node(self, node):
        
        incoming, outgoing, data = self.nodes[node]
        return node, data, outgoing, incoming
446851
def node_to_dict(node):
    
    dic = dict(tag=striptag(node.tag))
    if node.attrib:
        dic['attrib'] = node.attrib
    if node.text is not None:
        dic['text'] = node.text
    if node.nodes:
        dic['nodes'] = [node_to_dict(n) for n in node]
    return dic
35789
def etree_to_text(tree,
                  guess_punct_space=True,
                  guess_layout=True,
                  newline_tags=NEWLINE_TAGS,
                  double_newline_tags=DOUBLE_NEWLINE_TAGS):
    
    chunks = []

    _NEWLINE = object()
    _DOUBLE_NEWLINE = object()

    class Context:
        """ workaround for missing `nonlocal` in Python 2 """
        # _NEWLINE, _DOUBLE_NEWLINE or content of the previous chunk (str)
        prev = _DOUBLE_NEWLINE

    def should_add_space(text, prev):
        """ Return True if extra whitespace should be added before text """
        if prev in {_NEWLINE, _DOUBLE_NEWLINE}:
            return False
        if not _has_trailing_whitespace(prev):
            if _has_punct_after(text) or _has_open_bracket_before(prev):
                return False
        return True

    def get_space_between(text, prev):
        if not text or not guess_punct_space:
            return ' '
        return ' ' if should_add_space(text, prev) else ''

    def add_newlines(tag, context):
        if not guess_layout:
            return
        prev = context.prev
        if prev is _DOUBLE_NEWLINE:  # don't output more than 1 blank line
            return
        if tag in double_newline_tags:
            context.prev = _DOUBLE_NEWLINE
            chunks.append('\n' if prev is _NEWLINE else '\n\n')
        elif tag in newline_tags:
            context.prev = _NEWLINE
            if prev is not _NEWLINE:
                chunks.append('\n')

    def add_text(text_content, context):
        text = _normalize_whitespace(text_content) if text_content else ''
        if not text:
            return
        space = get_space_between(text, context.prev)
        chunks.extend([space, text])
        context.prev = text_content

    def traverse_text_fragments(tree, context, handle_tail=True):
        """ Extract text from the ``tree``: fill ``chunks`` variable """
        add_newlines(tree.tag, context)
        add_text(tree.text, context)
        for child in tree:
            traverse_text_fragments(child, context)
        add_newlines(tree.tag, context)
        if handle_tail:
            add_text(tree.tail, context)

    traverse_text_fragments(tree, context=Context(), handle_tail=False)
    return ''.join(chunks).strip()
1228289
def to_xml(node, pretty=False):
    
    fout = Sio()
    etree = et.ElementTree(node)

    etree.write(fout)
    xml = fout.getvalue()
    if pretty:
        xml = pretty_xml(xml, True)
    return xml
1033024
def tree_text(node):
    
    text = []
    for descendant in walk_dom(node):
        if is_text(descendant):
            text.append(descendant.nodeValue)
    return ' '.join(text)
1372357
def convert_reshape(node, **kwargs):
    
    name, input_nodes, attrs = get_inputs(node, kwargs)

    output_shape_list = convert_string_to_list(attrs["shape"])

    initializer = kwargs["initializer"]
    output_shape_np = np.array(output_shape_list, dtype='int64')
    data_type = onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[output_shape_np.dtype]
    dims = np.shape(output_shape_np)

    output_shape_name = "reshape_attr_tensor" + str(kwargs["idx"])
    tensor_node = onnx.helper.make_tensor_value_info(output_shape_name, data_type, dims)

    initializer.append(
        onnx.helper.make_tensor(
            name=output_shape_name,
            data_type=data_type,
            dims=dims,
            vals=output_shape_list,
            raw=False,
        )
    )

    input_nodes.append(output_shape_name)

    not_supported_shape = [-2, -3, -4]

    for val in output_shape_list:
        if val in not_supported_shape:
            raise AttributeError("Reshape: Shape value not supported in ONNX", val)

    reshape_node = onnx.helper.make_node(
        "Reshape",
        input_nodes,
        [name],
        name=name
    )

    return [tensor_node, reshape_node]
739424
def assign(self, node):
        
        child = self.translate(node.child)
        attributes = ''
        if node.attributes:
            attributes = '({})'.format(','.join(node.attributes.names))
        return '[.${name}{attributes}$ {child} ]'\
            .format(name=node.name, attributes=attributes, child=child)
77303
def tostring(node, indent=4, nsmap=None):
    
    out = io.BytesIO()
    writer = StreamingXMLWriter(out, indent, nsmap=nsmap)
    writer.serialize(node)
    return out.getvalue()
176547
def paragraph(node):
    
    text = ''
    if node.string_content is not None:
        text = node.string_content
    o = nodes.paragraph('', ' '.join(text))
    o.line = node.sourcepos[0][0]
    for n in MarkDown(node):
        o.append(n)

    return o
193822
def project(self, node):
        
        child_object = self.translate(node.child)
        child_object.select_block = str(node.attributes)
        return child_object