summaryrefslogtreecommitdiff
path: root/python/indexfile.cc
diff options
context:
space:
mode:
Diffstat (limited to 'python/indexfile.cc')
-rw-r--r--python/indexfile.cc104
1 files changed, 70 insertions, 34 deletions
diff --git a/python/indexfile.cc b/python/indexfile.cc
index 107eae27..a6f8904e 100644
--- a/python/indexfile.cc
+++ b/python/indexfile.cc
@@ -22,69 +22,105 @@ static PyObject *PackageIndexFileArchiveURI(PyObject *Self,PyObject *Args)
if (PyArg_ParseTuple(Args, "s",&path) == 0)
return 0;
-
return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str()));
}
static PyMethodDef PackageIndexFileMethods[] =
{
+ {"archive_uri",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"},
+ #ifdef COMPAT_0_7
{"ArchiveURI",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"},
+ #endif
{}
};
-
-static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name)
-{
- pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
- if (strcmp("Label",Name) == 0)
- return Safe_FromString(File->GetType()->Label);
- else if (strcmp("Describe",Name) == 0)
- return Safe_FromString(File->Describe().c_str());
- else if (strcmp("Exists",Name) == 0)
- return Py_BuildValue("i",(File->Exists()));
- else if (strcmp("HasPackages",Name) == 0)
- return Py_BuildValue("i",(File->HasPackages()));
- else if (strcmp("Size",Name) == 0)
- return Py_BuildValue("i",(File->Size()));
- else if (strcmp("IsTrusted",Name) == 0)
- return Py_BuildValue("i",(File->IsTrusted()));
-
- return Py_FindMethod(PackageIndexFileMethods,Self,Name);
+#define File (GetCpp<pkgIndexFile*>(Self))
+static PyObject *PackageIndexFileGetLabel(PyObject *Self,void*) {
+ return Safe_FromString(File->GetType()->Label);
+}
+static PyObject *PackageIndexFileGetDescribe(PyObject *Self,void*) {
+ return Safe_FromString(File->Describe().c_str());
}
+static PyObject *PackageIndexFileGetExists(PyObject *Self,void*) {
+ return Py_BuildValue("i",(File->Exists()));
+}
+static PyObject *PackageIndexFileGetHasPackages(PyObject *Self,void*) {
+ return Py_BuildValue("i",(File->HasPackages()));
+}
+static PyObject *PackageIndexFileGetSize(PyObject *Self,void*) {
+ return Py_BuildValue("i",(File->Size()));
+}
+static PyObject *PackageIndexFileGetIsTrusted(PyObject *Self,void*) {
+ return Py_BuildValue("i",(File->IsTrusted()));
+}
+#undef File
+#define S(x) (x ? x : "")
static PyObject *PackageIndexFileRepr(PyObject *Self)
{
pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
-
- char S[1024];
- snprintf(S,sizeof(S),"<pkIndexFile object: "
+ return PyString_FromFormat("<pkIndexFile object: "
"Label:'%s' Describe='%s' Exists='%i' "
- "HasPackages='%i' Size='%i' "
+ "HasPackages='%i' Size='%lu' "
"IsTrusted='%i' ArchiveURI='%s'>",
- File->GetType()->Label, File->Describe().c_str(), File->Exists(),
+ S(File->GetType()->Label), File->Describe().c_str(), File->Exists(),
File->HasPackages(), File->Size(),
File->IsTrusted(), File->ArchiveURI("").c_str());
- return PyString_FromString(S);
}
+#undef S
+
+static PyGetSetDef PackageIndexFileGetSet[] = {
+ {"describe",PackageIndexFileGetDescribe},
+ {"exists",PackageIndexFileGetExists},
+ {"has_packages",PackageIndexFileGetHasPackages},
+ {"is_trusted",PackageIndexFileGetIsTrusted},
+ {"label",PackageIndexFileGetLabel},
+ {"size",PackageIndexFileGetSize},
+ #ifdef COMPAT_0_7
+ {"Describe",PackageIndexFileGetDescribe},
+ {"Exists",PackageIndexFileGetExists},
+ {"HasPackages",PackageIndexFileGetHasPackages},
+ {"IsTrusted",PackageIndexFileGetIsTrusted},
+ {"Label",PackageIndexFileGetLabel},
+ {"Size",PackageIndexFileGetSize},
+ #endif
+ {}
+};
-PyTypeObject PackageIndexFileType =
+PyTypeObject PyPackageIndexFile_Type =
{
- PyObject_HEAD_INIT(&PyType_Type)
- 0, // ob_size
- "pkgIndexFile", // tp_name
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "apt_pkg.PackageIndexFile", // tp_name
sizeof(CppOwnedPyObject<pkgIndexFile*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgIndexFile*>, // tp_dealloc
+ // Not ..Ptr, because the pointer is managed somewhere else.
+ CppOwnedDeallocPtr<pkgIndexFile*>, // tp_dealloc
0, // tp_print
- PackageIndexFileAttr, // tp_getattr
+ 0, // tp_getattr
0, // tp_setattr
0, // tp_compare
- PackageIndexFileRepr, // tp_repr
+ PackageIndexFileRepr, // tp_repr
0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
+ 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 | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "IndexFile Object", // tp_doc
+ CppOwnedTraverse<pkgIndexFile*>, // tp_traverse
+ CppOwnedClear<pkgIndexFile*>, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ PackageIndexFileMethods, // tp_methods
+ 0, // tp_members
+ PackageIndexFileGetSet, // tp_getset
};