summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2006-07-27 15:00:12 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2006-07-27 15:00:12 +0200
commitaf398fcce8671bc864e4300c1b0bbeb07ab95aaf (patch)
treee89efbe87083941ab7a220c3a9a93f0e9f6df05c /python
parent0b081c5451d6394618290cd9a5767d767d98b819 (diff)
parent8d79b99c1a3338e31e8def858cee3209824ae8bf (diff)
downloadpython-apt-af398fcce8671bc864e4300c1b0bbeb07ab95aaf.tar.gz
* merged with mainline
Diffstat (limited to 'python')
-rw-r--r--python/apt_pkgmodule.cc39
-rw-r--r--python/indexfile.cc20
-rw-r--r--python/pkgsrcrecords.cc4
3 files changed, 60 insertions, 3 deletions
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc
index e73628c3..b1c5c2a5 100644
--- a/python/apt_pkgmodule.cc
+++ b/python/apt_pkgmodule.cc
@@ -19,6 +19,7 @@
#include <apt-pkg/tagfile.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
+#include <apt-pkg/sha256.h>
#include <apt-pkg/init.h>
#include <apt-pkg/pkgsystem.h>
@@ -236,6 +237,43 @@ static PyObject *sha1sum(PyObject *Self,PyObject *Args)
return 0;
}
/*}}}*/
+// sha256sum - Compute the sha1sum of a file or string /*{{{*/
+// ---------------------------------------------------------------------
+static char *doc_sha256sum = "sha256sum(String) -> String or sha256sum(File) -> String";
+static PyObject *sha256sum(PyObject *Self,PyObject *Args)
+{
+ PyObject *Obj;
+ if (PyArg_ParseTuple(Args,"O",&Obj) == 0)
+ return 0;
+
+ // Digest of a string.
+ if (PyString_Check(Obj) != 0)
+ {
+ SHA256Summation Sum;
+ Sum.Add(PyString_AsString(Obj));
+ return CppPyString(Sum.Result().Value());
+ }
+
+ // Digest of a file
+ if (PyFile_Check(Obj) != 0)
+ {
+ SHA256Summation Sum;
+ int Fd = fileno(PyFile_AsFile(Obj));
+ struct stat St;
+ if (fstat(Fd,&St) != 0 ||
+ Sum.AddFD(Fd,St.st_size) == false)
+ {
+ PyErr_SetFromErrno(PyExc_SystemError);
+ return 0;
+ }
+
+ return CppPyString(Sum.Result().Value());
+ }
+
+ PyErr_SetString(PyExc_TypeError,"Only understand strings and files");
+ return 0;
+}
+ /*}}}*/
// init - 3 init functions /*{{{*/
// ---------------------------------------------------------------------
static char *doc_Init =
@@ -370,6 +408,7 @@ static PyMethodDef methods[] =
// Stuff
{"md5sum",md5sum,METH_VARARGS,doc_md5sum},
{"sha1sum",sha1sum,METH_VARARGS,doc_sha1sum},
+ {"sha256sum",sha256sum,METH_VARARGS,doc_sha256sum},
// Strings
{"CheckDomainList",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"},
diff --git a/python/indexfile.cc b/python/indexfile.cc
index 4e106e25..ef6ffc8a 100644
--- a/python/indexfile.cc
+++ b/python/indexfile.cc
@@ -15,6 +15,22 @@
#include <Python.h>
+static PyObject *PackageIndexFileArchiveURI(PyObject *Self,PyObject *Args)
+{
+ pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
+ char *path;
+
+ if (PyArg_ParseTuple(Args, "s",&path) == 0)
+ return 0;
+
+ return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str()));
+}
+
+static PyMethodDef PackageIndexFileMethods[] =
+{
+ {"ArchiveURI",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"},
+ {}
+};
static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name)
@@ -33,8 +49,7 @@ static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name)
else if (strcmp("IsTrusted",Name) == 0)
return Py_BuildValue("i",(File->IsTrusted()));
- PyErr_SetString(PyExc_AttributeError,Name);
- return 0;
+ return Py_FindMethod(PackageIndexFileMethods,Self,Name);
}
static PyObject *PackageIndexFileRepr(PyObject *Self)
@@ -51,6 +66,7 @@ static PyObject *PackageIndexFileRepr(PyObject *Self)
File->IsTrusted(), File->ArchiveURI("").c_str());
return PyString_FromString(S);
}
+
PyTypeObject PackageIndexFileType =
{
PyObject_HEAD_INIT(&PyType_Type)
diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc
index abb29c74..5e04f5fc 100644
--- a/python/pkgsrcrecords.cc
+++ b/python/pkgsrcrecords.cc
@@ -96,8 +96,10 @@ static PyObject *PkgSrcRecordsAttr(PyObject *Self,char *Name)
*b != 0;
++b)
PyList_Append(List, CppPyString(*b));
-
return List; // todo
+ } else if (strcmp("Index",Name) == 0) {
+ const pkgIndexFile &tmp = Struct.Last->Index();
+ return CppOwnedPyObject_NEW<pkgIndexFile*>(Self,&PackageIndexFileType, (pkgIndexFile*)&tmp);
} else if (strcmp("Files",Name) == 0) {
PyObject *List = PyList_New(0);