[Rpm-maint] [PATCH 10/15] Port tagNumFromPyObject on Python 3 to use unicode objects
James Antill
james at fedoraproject.org
Thu Oct 15 19:55:52 UTC 2009
On Thu, 2009-10-15 at 15:15 -0400, David Malcolm wrote:
> 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
There's no reason for ifdef here, as it isn't a bug if:
ipkg.hdr[u'name']
...works in 2.* ... dito. hdr[b'name'] working in 3.*.
More information about the Rpm-maint
mailing list