From a0258d526ee5cffa2f117ff7babe3e228f8538c7 Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Wed, 24 Nov 2004 10:00:20 +0000 Subject: It makes packages, sort of Author: jgg Date: 2001-04-06 05:30:09 GMT It makes packages, sort of --- python/apt_pkgmodule.cc | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d48eed0b..27ca20db 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt_pkgmodule.cc,v 1.2 2001/02/23 05:46:02 jgg Exp $ +// $Id: apt_pkgmodule.cc,v 1.3 2001/04/06 05:30:09 jgg Exp $ /* ###################################################################### apt_pkgmodule - Top level for the python module. Create the internal @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -195,6 +196,43 @@ static PyObject *md5sum(PyObject *Self,PyObject *Args) return CppPyString(Sum.Result().Value()); } + PyErr_SetString(PyExc_TypeError,"Only understand strings and files"); + return 0; +} + /*}}}*/ +// sha1sum - Compute the sha1sum of a file or string /*{{{*/ +// --------------------------------------------------------------------- +static char *doc_sha1sum = "sha1sum(String) -> String or sha1sum(File) -> String"; +static PyObject *sha1sum(PyObject *Self,PyObject *Args) +{ + PyObject *Obj; + if (PyArg_ParseTuple(Args,"O",&Obj) == 0) + return 0; + + // Digest of a string. + if (PyString_Check(Obj) != 0) + { + SHA1Summation Sum; + Sum.Add(PyString_AsString(Obj)); + return CppPyString(Sum.Result().Value()); + } + + // Digest of a file + if (PyFile_Check(Obj) != 0) + { + SHA1Summation 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; } @@ -277,6 +315,7 @@ static PyMethodDef methods[] = // Stuff {"md5sum",md5sum,METH_VARARGS,doc_md5sum}, + {"sha1sum",sha1sum,METH_VARARGS,doc_sha1sum}, // Strings {"CheckDomainList",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, -- cgit v1.2.3