From: Panu Matilainen Date: Wed, 23 Sep 2009 05:51:12 +0000 (+0300) Subject: Add support for creating new header objects X-Git-Tag: rpm-4.8.0-beta1~215 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfc341170cdd5b324a3b90eb1b13620fd39298b4;p=platform%2Fupstream%2Frpm.git Add support for creating new header objects - without arguments, rpm.hdr() creates an empty header - with another header as argument, make a copy - string argument is considered an unloaded header blob and copy-loaded --- diff --git a/python/header-py.c b/python/header-py.c index e8b7bd9..98d76d3 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -301,6 +301,35 @@ static struct PyMethodDef hdr_methods[] = { {NULL, NULL} /* sentinel */ }; +static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) +{ + PyObject *obj = NULL; + Header h = NULL; + char *kwlist[] = { "obj", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &obj)) { + return NULL; + } + + if (obj == NULL) { + h = headerNew(); + } else if (hdrObject_Check(obj)) { + h = headerCopy(hdrGetHeader((hdrObject*) obj)); + } else if (PyString_Check(obj)) { + h = headerCopyLoad(PyString_AsString(obj)); + } else { + PyErr_SetNone(PyExc_TypeError); + return NULL; + } + + if (h == NULL) { + PyErr_SetString(pyrpmError, "bad header"); + return NULL; + } + + return hdr_Wrap(h); +} + static void hdr_dealloc(hdrObject * s) { if (s->h) headerFree(s->h); @@ -504,7 +533,7 @@ PyTypeObject hdr_Type = { 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - 0, /* tp_new */ + hdr_new, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ };