summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-10-23 21:07:10 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-10-23 21:07:10 +0300
commite13a476fc94509cb6f3d159e6135b48fdafcdf78 (patch)
tree6134983ec34da30f3f830fea0b3726d7a0c1989f /python
parentb457e2200bd41b0c7420e32d5c9ed5a10b082922 (diff)
downloadlibrpm-tizen-e13a476fc94509cb6f3d159e6135b48fdafcdf78.tar.gz
librpm-tizen-e13a476fc94509cb6f3d159e6135b48fdafcdf78.tar.bz2
librpm-tizen-e13a476fc94509cb6f3d159e6135b48fdafcdf78.zip
Add conversion function for handling python unicode -> string issues
- In Python 3 everything is unicode, forcing each and every caller to convert manually is a bit much.
Diffstat (limited to 'python')
-rw-r--r--python/header-py.c15
-rw-r--r--python/header-py.h2
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);