summaryrefslogtreecommitdiff
path: root/plugins/yaml/python
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-11-17 19:10:25 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-11-17 19:10:25 (GMT)
commitcef46f9f06a7448db60116e8c0ccadee44d83692 (patch)
tree75201f66b26499ad1968d6e1cec88f18ad80b72b /plugins/yaml/python
parentc02661b7a8151a49a77c39241b040aa9bdb30223 (diff)
Extended the API to find an unique Yaml node.
Diffstat (limited to 'plugins/yaml/python')
-rw-r--r--plugins/yaml/python/node.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/plugins/yaml/python/node.c b/plugins/yaml/python/node.c
index f2984d1..17aa065 100644
--- a/plugins/yaml/python/node.c
+++ b/plugins/yaml/python/node.c
@@ -43,6 +43,9 @@ static PyObject *py_yaml_node_new(PyTypeObject *, PyObject *, PyObject *);
/* Recherche les noeuds correspondant à un chemin. */
static PyObject *py_yaml_node_find_by_path(PyObject *, PyObject *);
+/* Recherche l'unique noeud correspondant à un chemin. */
+static PyObject *py_yaml_node_find_one_by_path(PyObject *, PyObject *);
+
/* Fournit la ligne principale associée à un noeud. */
static PyObject *py_yaml_node_get_yaml_line(PyObject *, void *);
@@ -162,6 +165,61 @@ static PyObject *py_yaml_node_find_by_path(PyObject *self, PyObject *args)
/******************************************************************************
* *
+* Paramètres : self = variable non utilisée ici. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Recherche l'unique noeud correspondant à un chemin. *
+* *
+* Retour : Noeud avec correspondance établie ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_yaml_node_find_one_by_path(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Instance à retourner */
+ const char *path; /* Chemin d'accès à traiter */
+ int ret; /* Bilan de lecture des args. */
+ GYamlNode *node; /* Version GLib du noeud */
+ GYamlNode *found; /* Création GLib à transmettre */
+
+#define YAML_NODE_FIND_ONE_BY_PATH PYTHON_METHOD_DEF \
+( \
+ find_one_by_path, "path", \
+ METH_VARARGS, py_yaml_node, \
+ "Find a given node from a Yaml node using a path.\n" \
+ "\n" \
+ "Paths are node keys separated by '/', such as '/my/path/to/node'." \
+ "\n" \
+ "Only one node has to match the path for the function success." \
+)
+
+ ret = PyArg_ParseTuple(args, "s", &path);
+ if (!ret) return NULL;
+
+ node = G_YAML_NODE(pygobject_get(self));
+
+ found = g_yaml_node_find_one_by_path(node, path);
+
+ if (found == NULL)
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+ else
+ {
+ result = pygobject_new(G_OBJECT(found));
+ g_object_unref(G_OBJECT(found));
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -316,6 +374,7 @@ PyTypeObject *get_python_yaml_node_type(void)
{
static PyMethodDef py_yaml_node_methods[] = {
YAML_NODE_FIND_BY_PATH,
+ YAML_NODE_FIND_ONE_BY_PATH,
{ NULL }
};