diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-04-13 18:41:05 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-04-13 18:41:05 +0200 |
| commit | eaefd2f4cb97ed069375f18fb67d8570dc5eaed8 (patch) | |
| tree | 5b87306720642912f2cd10186d0c803f69d45e02 | |
| parent | 506cb021d62e643fba38ddb4b84572a86cb3a3ba (diff) | |
| download | python-apt-eaefd2f4cb97ed069375f18fb67d8570dc5eaed8.tar.gz | |
* apt/tag.cc: Rework TagFile using tp_methods and tp_getset
By using tp_methods and tp_getset instead of a function for tp_getattr,
the resulting object is easier to understand and access to attributes and
methods is faster.
It also helps the port to Python 3, where Py_FindMethod does not exist
anymore.
| -rw-r--r-- | python/apt_pkgmodule.cc | 1 | ||||
| -rw-r--r-- | python/tag.cc | 47 |
2 files changed, 31 insertions, 17 deletions
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 34669fd5..1417e5d0 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -474,6 +474,7 @@ extern "C" void initapt_pkg() { // Finalize our types to add slots, etc. if (PyType_Ready(&TagSecType) == -1) return; + if (PyType_Ready(&TagFileType) == -1) return; // Initialize the module PyObject *Module = Py_InitModule("apt_pkg",methods); diff --git a/python/tag.cc b/python/tag.cc index cab32370..f3fb2e6c 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -423,38 +423,51 @@ static PyMethodDef TagFileMethods[] = {} }; -// TagFileGetAttr - Get an attribute - variable/method /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static PyObject *TagFileGetAttr(PyObject *Self,char *Name) -{ - if (strcmp("Section",Name) == 0) - { - PyObject *Obj = ((TagFileData *)Self)->Section; - Py_INCREF(Obj); - return Obj; - } - - return Py_FindMethod(TagFileMethods,Self,Name); +// Return the current section. +static PyObject *TagFileGetSection(PyObject *Self,void*) { + PyObject *Obj = ((TagFileData *)Self)->Section; + Py_INCREF(Obj); + return Obj; } +static PyGetSetDef TagFileGetSet[] = { + {"Section",TagFileGetSection,0,"Return a TagSection.",0}, + {} +}; + // Type for a Tag File PyTypeObject TagFileType = { PyObject_HEAD_INIT(&PyType_Type) - 0, // ob_size - "TagFile", // tp_name + 0, // ob_size + "TagFile", // tp_name sizeof(TagFileData), // tp_basicsize 0, // tp_itemsize // Methods TagFileFree, // tp_dealloc 0, // tp_print - TagFileGetAttr, // tp_getattr + 0, // tp_getattr 0, // tp_setattr 0, // tp_compare 0, // tp_repr 0, // tp_as_number 0, // tp_as_sequence - 0, // tp_as_mapping + 0, // tp_as_mapping 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "TagFile Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + TagFileMethods, // tp_methods + 0, // tp_members + TagFileGetSet // tp_getset }; |
