[Rpm-maint] [PATCH 14/15] Generalize tag data -> python conversion to work with both Python 2 and Python 3
David Malcolm
dmalcolm at redhat.com
Thu Oct 15 19:15:08 UTC 2009
Use PyBytes_ with RPM_STRING_CLASS and RPM_BINARY_CLASS, giving strings as before
on Python 2, and bytes on on Python 3.
This is reasonable for RPM_BINARY_CLASS, but is perhaps oversimplifying for string
data, as it leaves the decision about which encoding is in use to the user.
---
python/rpmtd-py.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/python/rpmtd-py.c b/python/rpmtd-py.c
index aa5be4f..e477ccf 100644
--- a/python/rpmtd-py.c
+++ b/python/rpmtd-py.c
@@ -17,13 +17,14 @@ static PyObject * rpmtd_ItemAsPyobj(rpmtd td, rpmTagClass class)
switch (class) {
case RPM_STRING_CLASS:
- res = PyString_FromString(rpmtdGetString(td));
+ /* FIXME: encoding issues; simplest here to leave decoding to the user (punting the issue) */
+ res = PyBytes_FromString(rpmtdGetString(td));
break;
case RPM_NUMERIC_CLASS:
res = PyLong_FromLongLong(rpmtdGetNumber(td));
break;
case RPM_BINARY_CLASS:
- res = PyString_FromStringAndSize(td->data, td->count);
+ res = PyBytes_FromStringAndSize(td->data, td->count);
break;
default:
PyErr_SetString(PyExc_KeyError, "unknown data type");
--
1.6.2.5
More information about the Rpm-maint
mailing list