summaryrefslogtreecommitdiff
path: root/docs/esp8266/tutorial/network_tcp.rst
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-06-04 15:54:26 +1000
committerDamien George <damien.p.george@gmail.com>2018-06-12 12:29:26 +1000
commitaf0932a7793478f0b90b754d38955d69700b0bee (patch)
tree71468d9bde42fd60358270f8d5fb6d49b9df9463 /docs/esp8266/tutorial/network_tcp.rst
parent6a445b60fad87c94a1d00ce3a043b881a1f7a5a4 (diff)
py/modio: Add uio.IOBase class to allow to define user streams.
A user class derived from IOBase and implementing readinto/write/ioctl can now be used anywhere a native stream object is accepted. The mapping from C to Python is: stream_p->read --> readinto(buf) stream_p->write --> write(buf) stream_p->ioctl --> ioctl(request, arg) Among other things it allows the user to: - create an object which can be passed as the file argument to print: print(..., file=myobj), and then print will pass all the data to the object via the objects write method (same as CPython) - pass a user object to uio.BufferedWriter to buffer the writes (same as CPython) - use select.select on a user object - register user objects with select.poll, in particular so user objects can be used with uasyncio - create user files that can be returned from user filesystems, and import can import scripts from these user files For example: class MyOut(io.IOBase): def write(self, buf): print('write', repr(buf)) return len(buf) print('hello', file=MyOut()) The feature is enabled via MICROPY_PY_IO_IOBASE which is disabled by default.
Diffstat (limited to 'docs/esp8266/tutorial/network_tcp.rst')
0 files changed, 0 insertions, 0 deletions