Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
45fb143b
Commit
45fb143b
authored
Apr 26, 2014
by
Paul Sokolovsky
Browse files
streams: Make .write() support arbitrary objects with buffer interface.
This in particular fixes writing str vs bytes.
parent
1463c1fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/stream.c
View file @
45fb143b
...
...
@@ -42,10 +42,11 @@ STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
"Operation not supported"
));
}
uint
sz
;
const
char
*
buf
=
mp_obj_str_get_data
(
arg
,
&
sz
);
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
arg
,
&
bufinfo
,
MP_BUFFER_READ
);
int
error
;
machine_int_t
out_sz
=
o
->
type
->
stream_p
->
write
(
self_in
,
buf
,
sz
,
&
error
);
machine_int_t
out_sz
=
o
->
type
->
stream_p
->
write
(
self_in
,
buf
info
.
buf
,
bufinfo
.
len
,
&
error
);
if
(
out_sz
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_OSError
,
"[Errno %d]"
,
error
));
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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