diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-06-04 17:01:51 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-06-04 17:01:51 +0200 |
| commit | 34f5670f3af2b04a4a575695584e46e4bf4106e9 (patch) | |
| tree | 9893b46395d79e998cb5963400c80a4aad496994 /python/metaindex.cc | |
| parent | 0726f9830527c0d5eb4aff7d71d983e5c69fa018 (diff) | |
| download | python-apt-34f5670f3af2b04a4a575695584e46e4bf4106e9.tar.gz | |
python/cache.cc, python/metaindex.cc: Convert remaining stuff to getset descriptors.
Diffstat (limited to 'python/metaindex.cc')
| -rw-r--r-- | python/metaindex.cc | 130 |
1 files changed, 78 insertions, 52 deletions
diff --git a/python/metaindex.cc b/python/metaindex.cc index 557aacd8..b451f0b5 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -1,13 +1,13 @@ // -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ +// Description /*{{{*/ // $Id: metaindex.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ /* ###################################################################### metaindex - Wrapper for the metaIndex functions ##################################################################### */ - /*}}}*/ -// Include Files /*{{{*/ + /*}}}*/ +// Include Files /*{{{*/ #include "generic.h" #include "apt_pkgmodule.h" @@ -15,69 +15,95 @@ #include <Python.h> +static PyObject *MetaIndexGetURI(PyObject *Self,void*) { + metaIndex *meta = GetCpp<metaIndex*>(Self); + return Safe_FromString(meta->GetURI().c_str()); +} -static PyObject *MetaIndexAttr(PyObject *Self,char *Name) -{ - metaIndex *meta = GetCpp<metaIndex*>(Self); - if (strcmp("URI",Name) == 0) - return Safe_FromString(meta->GetURI().c_str()); - else if (strcmp("Dist",Name) == 0) - return Safe_FromString(meta->GetDist().c_str()); - else if (strcmp("IsTrusted",Name) == 0) - return Py_BuildValue("i",(meta->IsTrusted())); - else if (strcmp("IndexFiles",Name) == 0) - { - PyObject *List = PyList_New(0); - vector<pkgIndexFile *> *indexFiles = meta->GetIndexFiles(); - for (vector<pkgIndexFile *>::const_iterator I = indexFiles->begin(); - I != indexFiles->end(); I++) - { - PyObject *Obj; - Obj = CppPyObject_NEW<pkgIndexFile*>(&PackageIndexFileType,*I); - PyList_Append(List,Obj); - } - return List; - } +static PyObject *MetaIndexGetDist(PyObject *Self,void*) { + metaIndex *meta = GetCpp<metaIndex*>(Self); + return Safe_FromString(meta->GetDist().c_str()); +} - PyErr_SetString(PyExc_AttributeError,Name); - return 0; +static PyObject *MetaIndexGetIsTrusted(PyObject *Self,void*) { + metaIndex *meta = GetCpp<metaIndex*>(Self); + return Py_BuildValue("i",(meta->IsTrusted())); } +static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) { + metaIndex *meta = GetCpp<metaIndex*>(Self); + PyObject *List = PyList_New(0); + vector<pkgIndexFile *> *indexFiles = meta->GetIndexFiles(); + for (vector<pkgIndexFile *>::const_iterator I = indexFiles->begin(); + I != indexFiles->end(); I++) + { + PyObject *Obj; + Obj = CppPyObject_NEW<pkgIndexFile*>(&PackageIndexFileType,*I); + PyList_Append(List,Obj); + } + return List; +} + +static PyGetSetDef MetaIndexGetSet[] = { + {"dist",MetaIndexGetDist}, + {"index_files",MetaIndexGetIndexFiles}, + {"is_trusted",MetaIndexGetIsTrusted}, + {"uri",MetaIndexGetURI}, + #ifdef COMPAT_0_7 + {"Dist",MetaIndexGetDist}, + {"IndexFiles",MetaIndexGetIndexFiles}, + {"IsTrusted",MetaIndexGetIsTrusted}, + {"URI",MetaIndexGetURI}, + #endif + {} +}; + static PyObject *MetaIndexRepr(PyObject *Self) { - metaIndex *meta = GetCpp<metaIndex*>(Self); - - char S[1024]; - snprintf(S,sizeof(S),"<metaIndex object: " - "Type='%s', URI:'%s' Dist='%s' IsTrusted='%i'>", - meta->GetType(), meta->GetURI().c_str(), meta->GetDist().c_str(), - meta->IsTrusted()); + metaIndex *meta = GetCpp<metaIndex*>(Self); - return PyString_FromString(S); + char S[1024]; + snprintf(S,sizeof(S),"<apt_pkg.MetaIndex object: " + "Type='%s', URI:'%s' Dist='%s' IsTrusted='%i'>", + meta->GetType(), meta->GetURI().c_str(), meta->GetDist().c_str(), + meta->IsTrusted()); + return PyString_FromString(S); } PyTypeObject MetaIndexType = { PyObject_HEAD_INIT(&PyType_Type) #if PY_MAJOR_VERSION < 3 - 0, // ob_size + 0, // ob_size #endif - "apt_pkg.MetaIndex", // tp_name + "apt_pkg.MetaIndex", // tp_name sizeof(CppOwnedPyObject<metaIndex*>), // tp_basicsize - 0, // tp_itemsize + 0, // tp_itemsize // Methods - CppOwnedDealloc<metaIndex*>, // tp_dealloc - 0, // tp_print - MetaIndexAttr, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - MetaIndexRepr, // tp_repr - 0, // tp_as_number - 0, // tp_as_sequence - 0, // tp_as_mapping - 0, // tp_hash + CppOwnedDealloc<metaIndex*>, // tp_dealloc + 0, // tp_print + 0, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + MetaIndexRepr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 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 + "apt_pkg.MetaIndex Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + MetaIndexGetSet, // tp_getset }; - - - - |
