Preserve the string-based API to headers:
h['name']
by expecting a PyUnicode on Python 3, and a PyString on Python 2.
---
python/header-py.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/python/header-py.c b/python/header-py.c
index 98cd753..f3454df 100644
--- a/python/header-py.c
+++ b/python/header-py.c
@@ -421,8 +421,15 @@ int tagNumFromPyObject (PyObject *item, rpmTag *tagp)
if (PyInt_Check(item)) {
/* XXX we should probably validate tag numbers too */
tag = PyInt_AsLong(item);
+#if PY_MAJOR_VERSION >= 3
+ } else if (PyUnicode_Check(item)) {
+ PyObject *utf8_bytes = PyUnicode_AsUTF8String(item);
+ tag = rpmTagGetValue(PyBytes_AsString(utf8_bytes));
+ Py_XDECREF(utf8_bytes);
+#else
} else if (PyString_Check(item)) {
tag = rpmTagGetValue(PyString_AsString(item));
+#endif
} else {
PyErr_SetString(PyExc_TypeError, "expected a string or integer");
return 0;
--
1.6.2.5
_______________________________________________
Rpm-maint mailing list
[email protected]
http://lists.rpm.org/mailman/listinfo/rpm-maint