diff options
-rw-r--r-- | python/header-py.c | 15 | ||||
-rw-r--r-- | python/header-py.h | 2 |
2 files changed, 16 insertions, 1 deletions
diff --git a/python/header-py.c b/python/header-py.c index 1ea5acf87..dc26d8e4e 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -415,6 +415,21 @@ static PyObject * hdr_iternext(hdrObject *s) return res; } +int utf8FromPyObject(PyObject *item, PyObject **str) +{ + PyObject *res = NULL; + if (PyBytes_Check(item)) { + Py_XINCREF(item); + res = item; + } else if (PyUnicode_Check(item)) { + res = PyUnicode_AsUTF8String(item); + } + if (res == NULL) return 0; + + *str = res; + return 1; +} + int tagNumFromPyObject (PyObject *item, rpmTag *tagp) { rpmTag tag = RPMTAG_NOT_FOUND; diff --git a/python/header-py.h b/python/header-py.h index 497ce3ac1..28378ac58 100644 --- a/python/header-py.h +++ b/python/header-py.h @@ -17,7 +17,7 @@ extern PyObject * pyrpmError; PyObject * hdr_Wrap(PyTypeObject *subtype, Header h); int hdrFromPyObject(PyObject *item, Header *h); - +int utf8FromPyObject(PyObject *item, PyObject **str); int tagNumFromPyObject (PyObject *item, rpmTag *tagp); PyObject * labelCompare (PyObject * self, PyObject * args); |