From 6bad14680b22f2bffbe9a3a10a954acaf13a7ad5 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 8 Jun 2009 17:55:23 +0200 Subject: python/indexrecords.cc: Swap tuple elements in lookup, and raise KeyError when none is found. --- python/indexrecords.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/python/indexrecords.cc b/python/indexrecords.cc index e6099a69..917c3bbf 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -45,7 +45,7 @@ static PyObject *IndexRecords_Load(PyObject *self,PyObject *args) } static const char *IndexRecords_Lookup_doc = "lookup(metakey)\n\n" - "Lookup the filename given by metakey, return a tuple (size,hash).\n" + "Lookup the filename given by metakey, return a tuple (hash, size).\n" "The hash part is a HashString() object."; static PyObject *IndexRecords_Lookup(PyObject *self,PyObject *args) { @@ -54,8 +54,13 @@ static PyObject *IndexRecords_Lookup(PyObject *self,PyObject *args) return 0; indexRecords *records = GetCpp(self); const indexRecords::checkSum *result = records->Lookup(keyname); - return Py_BuildValue("(iO)",result->Size, - PyHashString_FromCpp((HashString*)&result->Hash)); + if (result == 0) { + PyErr_SetString(PyExc_KeyError,keyname); + return 0; + } + return Py_BuildValue("(Oi)", + PyHashString_FromCpp((HashString*)&result->Hash), + result->Size); } static PyObject *IndexRecords_GetDist(PyObject *self) -- cgit v1.2.3