35 #if MICROPY_STREAMS_NON_BLOCK 37 #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) 38 #define EWOULDBLOCK 140 46 #define DEFAULT_BUFFER_SIZE 256 50 #define STREAM_CONTENT_TYPE(stream) (((stream)->is_text) ? &mp_type_str : &mp_type_bytes) 62 io_func = (io_func_t)stream_p->
write;
64 io_func = stream_p->
read;
70 mp_uint_t out_sz = io_func(stream, buf, size, errcode);
126 #if MICROPY_PY_BUILTINS_STR_UNICODE 141 while (more_bytes > 0) {
161 if (out_sz < more_bytes) {
171 for (
mp_uint_t off = last_buf_offset;;) {
177 }
else if ((b & 0xe0) == 0xc0) {
180 }
else if ((b & 0xf0) == 0xe0) {
183 }
else if ((b & 0xf8) == 0xf0) {
190 if (off + n <= vstr.
len) {
194 last_buf_offset = off;
195 if (off >= vstr.
len) {
202 more_bytes = (off + n - vstr.
len) + (sz - 1);
269 size_t max_len = (
size_t)-1;
273 }
else if (n_args == 4) {
276 if (off > bufinfo.
len) {
303 if (len > bufinfo.
len) {
331 mp_uint_t out_sz = stream_p->
read(self_in, p, current_read, &error);
337 if (total_size == 0) {
347 total_size += out_sz;
348 if (out_sz < current_read) {
349 current_read -= out_sz;
357 vstr.
len = total_size;
371 if (max_size != -1) {
377 while (max_size == -1 || max_size-- != 0) {
506 #if MICROPY_STREAMS_POSIX_API 519 ssize_t mp_stream_posix_write(
mp_obj_t stream,
const void *buf,
size_t len) {
522 mp_uint_t out_sz = stream_p->
write(stream, buf, len, &mp_stream_errno);
533 mp_uint_t out_sz = stream_p->
read(stream, buf, len, &mp_stream_errno);
551 return seek_s.offset;
554 int mp_stream_posix_fsync(
mp_obj_t stream) {
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
char * vstr_extend(vstr_t *vstr, size_t size)
STATIC mp_obj_t stream_flush(mp_obj_t self)
#define MP_STREAM_OP_WRITE
void vstr_init_len(vstr_t *vstr, size_t len)
mp_uint_t(* read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode)
#define mp_stream_read_exactly(stream, buf, size, err)
STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags)
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
void vstr_init(vstr_t *vstr, size_t alloc)
#define MP_OBJ_FROM_PTR(p)
STATIC mp_obj_t stream_write1_method(mp_obj_t self_in, mp_obj_t arg)
MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_unbuffered_readlines_obj, stream_unbuffered_readlines)
const mp_stream_p_t * mp_get_stream_raise(mp_obj_t self_in, int flags)
STATIC mp_obj_t stream_unbuffered_readlines(mp_obj_t self)
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items)
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self)
mp_uint_t(* ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode)
#define MP_OBJ_SMALL_INT_VALUE(o)
char * vstr_add_len(vstr_t *vstr, size_t len)
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest)
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj, 1, 2, stream_read)
STATIC mp_obj_t stream_read(size_t n_args, const mp_obj_t *args)
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg)
STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args)
#define MP_OBJ_NEW_SMALL_INT(small_int)
#define MP_STREAM_RW_WRITE
mp_obj_t mp_stream_close(mp_obj_t stream)
STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args)
#define mp_is_nonblocking_error(errno)
const mp_obj_type_t mp_type_OSError
NORETURN void mp_raise_OSError(int errno_)
const mp_obj_type_t mp_type_str
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value)
MP_DEFINE_CONST_FUN_OBJ_2(mp_stream_write1_obj, stream_write1_method)
STATIC mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args)
#define STREAM_CONTENT_TYPE(stream)
mp_obj_t mp_obj_new_int(mp_int_t value)
#define MP_STREAM_OP_IOCTL
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr)
void mp_stream_write_adaptor(void *self, const char *buf, size_t len)
mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len, byte flags)
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args)
mp_uint_t(* write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode)
STATIC mp_obj_t stream_tell(mp_obj_t self)
STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args)
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args)
#define UTF8_IS_NONASCII(ch)
#define MP_STREAM_RW_ONCE
#define MP_OBJ_STOP_ITERATION
#define DEFAULT_BUFFER_SIZE
#define MP_STREAM_RW_READ
mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode, byte flags)
STATIC mp_obj_t stream_read1(size_t n_args, const mp_obj_t *args)
mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg)
void vstr_clear(vstr_t *vstr)
bool mp_obj_is_true(mp_obj_t arg)
#define MP_STREAM_OP_READ
STATIC mp_obj_t stream_readall(mp_obj_t self_in)
void vstr_cut_tail_bytes(vstr_t *vstr, size_t bytes_to_cut)