kopia lustrzana https://github.com/micropython/micropython
Merge 89d8f887e0
into 01c31ea804
commit
bd9ee8ed84
|
@ -77,6 +77,13 @@ static void stringio_copy_on_write(mp_obj_stringio_t *o) {
|
||||||
|
|
||||||
static mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
|
static mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||||
(void)errcode;
|
(void)errcode;
|
||||||
|
|
||||||
|
if (!mp_obj_is_type(o_in, &mp_type_stringio)) {
|
||||||
|
|
||||||
|
if (!mp_obj_is_type(o_in, &mp_type_bytesio)) {
|
||||||
|
mp_raise_TypeError(MP_ERROR_TEXT("expecting a StringIO or BytesIO object"));
|
||||||
|
}
|
||||||
|
}
|
||||||
mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in);
|
mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in);
|
||||||
check_stringio_is_open(o);
|
check_stringio_is_open(o);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path[0] = ".frozen" # avoid local dir io import
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
|
|
||||||
|
class TestStream(io.StringIO):
|
||||||
|
def __init_(self, alloc_size):
|
||||||
|
super().__init__(alloc_size)
|
||||||
|
|
||||||
|
|
||||||
|
class ByteStream(io.BytesIO):
|
||||||
|
def __init_(self, alloc_size):
|
||||||
|
super().__init__(alloc_size)
|
||||||
|
|
||||||
|
|
||||||
|
test_stringio = TestStream(100)
|
||||||
|
|
||||||
|
test_bytesio = ByteStream(100)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print("hello", file=test_stringio)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
print("hello", file=test_bytesio)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
|
@ -0,0 +1,2 @@
|
||||||
|
expecting a StringIO or BytesIO object
|
||||||
|
expecting a StringIO or BytesIO object
|
Ładowanie…
Reference in New Issue