diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-23 11:19:05 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-23 11:19:05 (GMT) |
commit | 95503238235a8c4387606f43aae4b8f641ac6614 (patch) | |
tree | a487f2b69a96484c9ff74c63afdf2a3a0b36036c /Modules/bz2module.c | |
parent | 9b9e0a1b4b0a55d06c12cfda64ef5b05a68bf6cf (diff) | |
download | cpython-95503238235a8c4387606f43aae4b8f641ac6614.zip cpython-95503238235a8c4387606f43aae4b8f641ac6614.tar.gz cpython-95503238235a8c4387606f43aae4b8f641ac6614.tar.bz2 |
Merged revisions 80402 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r80402 | victor.stinner | 2010-04-23 12:56:17 +0200 (ven., 23 avril 2010) | 2 lines
Issue #8468: bz2.BZ2File() accepts str with surrogates and bytes filenames
........
Diffstat (limited to 'Modules/bz2module.c')
-rw-r--r-- | Modules/bz2module.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c index 550f1cf..3e8eb8b 100644 --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -1162,6 +1162,7 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"filename", "mode", "buffering", "compresslevel", 0}; + PyObject *name_obj = NULL; char *name; char *mode = "r"; int buffering = -1; @@ -1171,14 +1172,20 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs) self->size = -1; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|sii:BZ2File", - kwlist, &name, &mode, &buffering, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|sii:BZ2File", + kwlist, PyUnicode_FSConverter, &name_obj, + &mode, &buffering, &compresslevel)) return -1; + if (PyBytes_Check(name_obj)) + name = PyBytes_AsString(name_obj); + else + name = PyByteArray_AsString(name_obj); if (compresslevel < 1 || compresslevel > 9) { PyErr_SetString(PyExc_ValueError, "compresslevel must be between 1 and 9"); + Py_DECREF(name_obj); return -1; } @@ -1202,6 +1209,7 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs) if (error) { PyErr_Format(PyExc_ValueError, "invalid mode char %c", *mode); + Py_DECREF(name_obj); return -1; } mode++; @@ -1216,6 +1224,7 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs) mode = (mode_char == 'r') ? "rb" : "wb"; self->rawfp = fopen(name, mode); + Py_DECREF(name_obj); if (self->rawfp == NULL) { PyErr_SetFromErrno(PyExc_IOError); return -1; |