summaryrefslogtreecommitdiff
path: root/plugins/yaml/python
diff options
context:
space:
mode:
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 }
};