summaryrefslogtreecommitdiff
path: root/python/metaindex.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2010-01-15 15:22:12 +0100
committerJulian Andres Klode <jak@debian.org>2010-01-15 15:22:12 +0100
commit7bfefb84523645fe24d0e5603d56c23cf410328e (patch)
tree3965ce6e2e968a2facd5efa2e3ea4fb34c4140ff /python/metaindex.cc
parent71aad7e28bbaf1ee8efdad77ebfb4e4c0fd0ec26 (diff)
parent52cca77b8179a7f625673f19cb132686c0d416c9 (diff)
downloadpython-apt-7bfefb84523645fe24d0e5603d56c23cf410328e.tar.gz
Merge debian-experimental.
Diffstat (limited to 'python/metaindex.cc')
-rw-r--r--python/metaindex.cc137
1 files changed, 82 insertions, 55 deletions
diff --git a/python/metaindex.cc b/python/metaindex.cc
index efbc38af..4e059f0c 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,67 +15,94 @@
#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 *MetaIndexRepr(PyObject *Self)
-{
- metaIndex *meta = GetCpp<metaIndex*>(Self);
+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++)
+ {
+ CppOwnedPyObject<pkgIndexFile*> *Obj;
+ Obj = CppOwnedPyObject_NEW<pkgIndexFile*>(Self, &PyPackageIndexFile_Type,*I);
+ // Do not delete pkgIndexFile*, they are managed by metaIndex.
+ Obj->NoDelete = true;
+ PyList_Append(List,Obj);
+ Py_DECREF(Obj);
+ }
+ return List;
+}
- 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());
+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
+ {}
+};
- return PyString_FromString(S);
+#define S(x) (x ? x : "")
+static PyObject *MetaIndexRepr(PyObject *Self)
+{
+ metaIndex *meta = GetCpp<metaIndex*>(Self);
+ return PyString_FromFormat("<%s object: type='%s', uri:'%s' dist='%s' "
+ "is_trusted='%i'>", Self->ob_type->tp_name,
+ S(meta->GetType()), meta->GetURI().c_str(),
+ meta->GetDist().c_str(), meta->IsTrusted());
}
+#undef S
-PyTypeObject MetaIndexType =
+PyTypeObject PyMetaIndex_Type =
{
- PyObject_HEAD_INIT(&PyType_Type)
- 0, // ob_size
- "metaIndex", // tp_name
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "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
+ CppOwnedDeallocPtr<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
};
-
-
-
-