summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/cattribs.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2021-10-08 06:52:02 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2021-10-08 06:52:02 (GMT)
commit0aea964ab880a972e8a4d54b36f7eee340f49d5b (patch)
tree64b09b80f5d92e96a18a73188197eff5241a2687 /plugins/pychrysalide/analysis/cattribs.c
parentda3da13a32a2f98c16a591a389e274a7803fc48a (diff)
Extract filenames when creating content attributes.
Diffstat (limited to 'plugins/pychrysalide/analysis/cattribs.c')
-rw-r--r--plugins/pychrysalide/analysis/cattribs.c79
1 files changed, 26 insertions, 53 deletions
diff --git a/plugins/pychrysalide/analysis/cattribs.c b/plugins/pychrysalide/analysis/cattribs.c
index be5c5b1..895fed8 100644
--- a/plugins/pychrysalide/analysis/cattribs.c
+++ b/plugins/pychrysalide/analysis/cattribs.c
@@ -45,9 +45,6 @@ static PyObject *py_content_attributes_new(PyTypeObject *, PyObject *, PyObject
/* Fournit l'ensemble des clefs d'un ensemble d'attributs. */
static PyObject *py_content_attributes_subscript(PyObject *, PyObject *);
-/* Fournit le fichier de base compris dans le chemin initial. */
-static PyObject *py_content_attributes_get_filename(PyObject *, void *);
-
/* Fournit l'ensemble des clefs d'un ensemble d'attributs. */
static PyObject *py_content_attributes_get_keys(PyObject *, void *);
@@ -72,7 +69,10 @@ static PyObject *py_content_attributes_new(PyTypeObject *type, PyObject *args, P
PyObject *result; /* Instance à retourner */
const char *path; /* Chemin d'accès à traiter */
int ret; /* Bilan de lecture des args. */
+ char *filename; /* Nom de fichier embarqué */
GContentAttributes *attribs; /* Création GLib à transmettre */
+ PyObject *obj; /* Objet Python à retourner */
+ PyObject *str; /* Chaîne à retourner */
#define CONTENT_ATTRIBUTES_DOC \
"ContentAttributes is a set of values used at binary content loading.\n" \
@@ -87,25 +87,43 @@ static PyObject *py_content_attributes_new(PyTypeObject *type, PyObject *args, P
"\n" \
" ContentAttributes(path)\n" \
"\n" \
- "Where path is a list of parameters: '[...]&key0=value0&key1=value1...'"
+ "Where path is a list of parameters: '[...]&key0=value0&key1=value1...'" \
+ "\n" \
+ "The constructor returns a tuple containing a ContentAttributes instance" \
+ " and the original targot filename."
ret = PyArg_ParseTuple(args, "s", &path);
if (!ret) return NULL;
- attribs = g_content_attributes_new(path);
+ attribs = g_content_attributes_new(path, &filename);
if (attribs != NULL)
{
g_object_ref_sink(G_OBJECT(attribs));
- result = pygobject_new(G_OBJECT(attribs));
+ obj = pygobject_new(G_OBJECT(attribs));
g_object_unref(attribs);
}
else
{
- result = Py_None;
- Py_INCREF(result);
+ obj = Py_None;
+ Py_INCREF(obj);
}
+ if (filename != NULL)
+ {
+ str = PyUnicode_FromString(filename);
+ free(filename);
+ }
+ else
+ {
+ str = Py_None;
+ Py_INCREF(str);
+ }
+
+ result = PyTuple_New(2);
+ PyTuple_SetItem(result, 0, obj);
+ PyTuple_SetItem(result, 1, str);
+
return result;
}
@@ -200,50 +218,6 @@ static PyObject *py_content_attributes_get_keys(PyObject *self, void *closure)
/******************************************************************************
* *
-* Paramètres : self = objet Python concerné par l'appel. *
-* closure = non utilisé ici. *
-* *
-* Description : Fournit le fichier de base compris dans le chemin initial. *
-* *
-* Retour : Nom de fichier renvoyant vers un contenu à charger ou None. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_content_attributes_get_filename(PyObject *self, void *closure)
-{
- PyObject *result; /* Valeur à retourner */
- GContentAttributes *cattribs; /* Version native */
- const char *filename; /* Nom de fichier natif */
-
-#define CONTENT_ATTRIBUTES_FILENAME_ATTRIB PYTHON_GET_DEF_FULL \
-( \
- filename, py_content_attributes, \
- "Filename extracted from the path provided to the attribute set," \
- " constructor, or None if no filename was defined." \
-)
-
- cattribs = G_CONTENT_ATTRIBUTES(pygobject_get(self));
-
- filename = g_content_attributes_get_filename(cattribs);
-
- if (filename != NULL)
- result = PyUnicode_FromString(filename);
-
- else
- {
- result = Py_None;
- Py_INCREF(result);
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -267,7 +241,6 @@ PyTypeObject *get_python_content_attributes_type(void)
};
static PyGetSetDef py_content_attributes_getseters[] = {
- CONTENT_ATTRIBUTES_FILENAME_ATTRIB,
CONTENT_ATTRIBUTES_KEYS_ATTRIB,
{ NULL }
};