summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-11-23 12:30:38 +0200
committerPanu Matilainen <pmatilai@redhat.com>2010-11-23 12:33:09 +0200
commit8093218e8ca543c3631a18032b4fff902a845c0d (patch)
tree816a5117e0a22e0067b265c2b1c630ef3159f392 /python
parent466cd4642ba71c9d836d5e60a606e8330fe81316 (diff)
downloadlibrpm-tizen-8093218e8ca543c3631a18032b4fff902a845c0d.tar.gz
librpm-tizen-8093218e8ca543c3631a18032b4fff902a845c0d.tar.bz2
librpm-tizen-8093218e8ca543c3631a18032b4fff902a845c0d.zip
Permit unicode paths in rpm.fd() (RhBug:654145)
- Python 3 has fs-specific converter function, for Python 2 just assume utf-8 and hope the best.
Diffstat (limited to 'python')
-rw-r--r--python/rpmfd-py.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c
index acd8f7279..9819e14d7 100644
--- a/python/rpmfd-py.c
+++ b/python/rpmfd-py.c
@@ -42,6 +42,17 @@ static PyObject *err_closed(void)
return NULL;
}
+static FD_t openPath(const char *path, const char *mode, const char *flags)
+{
+ FD_t fd;
+ char *m = rstrscat(NULL, mode, ".", flags, NULL);
+ Py_BEGIN_ALLOW_THREADS
+ fd = Fopen(path, m);
+ Py_END_ALLOW_THREADS;
+ free(m);
+ return fd;
+}
+
static PyObject *rpmfd_new(PyTypeObject *subtype,
PyObject *args, PyObject *kwds)
{
@@ -58,11 +69,21 @@ static PyObject *rpmfd_new(PyTypeObject *subtype,
return NULL;
if (PyBytes_Check(fo)) {
- char *m = rstrscat(NULL, mode, ".", flags, NULL);
- Py_BEGIN_ALLOW_THREADS
- fd = Fopen(PyBytes_AsString(fo), m);
- Py_END_ALLOW_THREADS
- free(m);
+ fd = openPath(PyBytes_AsString(fo), mode, flags);
+ } else if (PyUnicode_Check(fo)) {
+ PyObject *enc = NULL;
+ int rc;
+#if PY_MAJOR_VERSION >= 3
+ rc = PyUnicode_FSConverter(fo, &enc);
+#else
+ rc = utf8FromPyObject(fo, &enc);
+#endif
+ if (rc == 0)
+ return NULL;
+
+ fd = openPath(PyBytes_AsString(enc), mode, flags);
+ Py_DECREF(enc);
+
} else if ((fdno = PyObject_AsFileDescriptor(fo)) >= 0) {
fd = fdDup(fdno);
} else {