memory.gexf¶
memory.gexf ¶
Minimal, safe GEXF (Graph Exchange XML Format) serializer.
A tiny, dependency-free builder used by both the memory tree exporter
(:mod:memory.export) and the zettelkasten exporter
(:mod:zettelkasten.export). It lives in memory/ deliberately: the memory
subsystem must never import zettelkasten (the dependency is strictly one-way),
so the shared helper sits on the side that both may depend on.
Safety¶
The builder only ever constructs an XML document with
:mod:xml.etree.ElementTree — it never parses untrusted XML, so there is no
XXE / external-entity / entity-expansion surface here. Text is emitted through
ElementTree's own attribute/character escaping, so arbitrary note titles/tags
(which are DATA, never markup) cannot break out of the document. Any caller that
needs to read GEXF back should parse it with a hardened parser.
build_gexf ¶
build_gexf(nodes: Iterable[tuple[str, str, Mapping[str, object]]], edges: Iterable[tuple[str, str, str, object]], *, node_attributes: Sequence[str] = (), directed: bool = True) -> str
Serialize nodes/edges into a GEXF 1.2 document string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Iterable[tuple[str, str, Mapping[str, object]]]
|
iterable of |
required |
edges
|
Iterable[tuple[str, str, str, object]]
|
iterable of |
required |
node_attributes
|
Sequence[str]
|
ordered attribute names declared once in the GEXF
|
()
|
directed
|
bool
|
whether edges are directed (default) or undirected. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
A UTF-8 XML document (with declaration) as a |