Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
349fd521
Commit
349fd521
authored
Apr 23, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #8468: bz2.BZ2File() accepts str with surrogates and bytes filenames
parent
13daf12b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
Misc/NEWS
Misc/NEWS
+2
-0
Modules/bz2module.c
Modules/bz2module.c
+8
-2
No files found.
Misc/NEWS
View file @
349fd521
...
...
@@ -329,6 +329,8 @@ C-API
Library
-------
- Issue #8468: bz2.BZ2File() accepts str with surrogates and bytes filenames
- Issue #8451: Syslog module now uses basename(sys.argv[0]) instead of
the string "python" as the *ident*. openlog() arguments are all optional
and keywords.
...
...
Modules/bz2module.c
View file @
349fd521
...
...
@@ -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,17 @@ 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
;
name
=
PyBytes_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 +1206,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 +1221,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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment