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
2777c021
Commit
2777c021
authored
Sep 19, 2001
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #462849: Pass Unicode objects to file's .write method.
parent
5b5e0b9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
Misc/NEWS
Misc/NEWS
+5
-0
Objects/fileobject.c
Objects/fileobject.c
+8
-3
No files found.
Misc/NEWS
View file @
2777c021
...
...
@@ -3,6 +3,11 @@ What's New in Python 2.2a4?
Core
- PyFile_WriteObject now passes Unicode object to the file's write
method. As a result, all file-like object which may be the target
of a print statement must support Unicode objects, i.e. they must
at least convert them into ASCII strings.
- The builtin file type can be subclassed now. In the usual pattern,
"file" is the name of the builtin type, and file() is a new builtin
constructor, with the same signature as the builtin open() function.
...
...
Objects/fileobject.c
View file @
2777c021
...
...
@@ -1503,9 +1503,14 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
writer
=
PyObject_GetAttrString
(
f
,
"write"
);
if
(
writer
==
NULL
)
return
-
1
;
if
(
flags
&
Py_PRINT_RAW
)
value
=
PyObject_Str
(
v
);
else
if
(
flags
&
Py_PRINT_RAW
)
{
if
(
PyUnicode_Check
(
v
))
{
value
=
v
;
Py_INCREF
(
value
);
}
else
value
=
PyObject_Str
(
v
);
}
else
value
=
PyObject_Repr
(
v
);
if
(
value
==
NULL
)
{
Py_DECREF
(
writer
);
...
...
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