diff options
Diffstat (limited to 'plugins/yaml/python/tree.c')
-rw-r--r-- | plugins/yaml/python/tree.c | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/plugins/yaml/python/tree.c b/plugins/yaml/python/tree.c index eeab3de..c23406a 100644 --- a/plugins/yaml/python/tree.c +++ b/plugins/yaml/python/tree.c @@ -150,6 +150,7 @@ static PyObject *py_yaml_tree_new(PyTypeObject *type, PyObject *args, PyObject * static PyObject *py_yaml_tree_find_by_path(PyObject *self, PyObject *args) { PyObject *result; /* Instance à retourner */ + int prepare; /* Orientation des résultats */ const char *path; /* Chemin d'accès à traiter */ int ret; /* Bilan de lecture des args. */ GYamlTree *tree; /* Version GLib du type */ @@ -159,19 +160,26 @@ static PyObject *py_yaml_tree_find_by_path(PyObject *self, PyObject *args) #define YAML_TREE_FIND_BY_PATH PYTHON_METHOD_DEF \ ( \ - find_by_path, "path", \ + find_by_path, "path, /, prepare=False", \ METH_VARARGS, py_yaml_tree, \ "Find nodes in a Yaml tree using a path.\n" \ "\n" \ "Paths are node keys separated by '/', such as '/my/path/to/node'." \ + "\n" \ + "In case where the path ends with a trailing '/', the operation can" \ + " be used to prepare a further look by returning a node which can be" \ + " searched by a new call to this function instead of returning all its" \ + " contained nodes." \ ) - ret = PyArg_ParseTuple(args, "s", &path); + prepare = 0; + + ret = PyArg_ParseTuple(args, "s|p", &path, &prepare); if (!ret) return NULL; tree = G_YAML_TREE(pygobject_get(self)); - g_yaml_tree_find_by_path(tree, path, &found, &count); + g_yaml_tree_find_by_path(tree, path, prepare, &found, &count); result = PyTuple_New(count); @@ -198,6 +206,69 @@ static PyObject *py_yaml_tree_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_tree_find_one_by_path(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + int prepare; /* Orientation des résultats */ + const char *path; /* Chemin d'accès à traiter */ + int ret; /* Bilan de lecture des args. */ + GYamlTree *tree; /* Version GLib du type */ + GYamlNode *found; /* Création GLib à transmettre */ + +#define YAML_TREE_FIND_ONE_BY_PATH PYTHON_METHOD_DEF \ +( \ + find_one_by_path, "path, /, prepare=False", \ + METH_VARARGS, py_yaml_tree, \ + "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." \ + "\n" \ + "In case where the path ends with a trailing '/', the operation can" \ + " be used to prepare a further look by returning a node which can be" \ + " searched by a new call to this function instead of returning all its" \ + " contained nodes." \ +) + + prepare = 0; + + ret = PyArg_ParseTuple(args, "s|p", &path, &prepare); + if (!ret) return NULL; + + tree = G_YAML_TREE(pygobject_get(self)); + + found = g_yaml_tree_find_one_by_path(tree, path, prepare); + + 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. * * * @@ -249,6 +320,7 @@ PyTypeObject *get_python_yaml_tree_type(void) { static PyMethodDef py_yaml_tree_methods[] = { YAML_TREE_FIND_BY_PATH, + YAML_TREE_FIND_ONE_BY_PATH, { NULL } }; |