Skip to content

Commit

Permalink
add compatibility for micropython above 1.19.0 (#57)
Browse files Browse the repository at this point in the history
* uasyncio is renamed to asyncio
* directly use core from asyncio
  • Loading branch information
FabianClemenz authored Feb 5, 2024
1 parent c6c64fe commit d067b98
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tinyweb/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
(C) Konstantin Belyalov 2017-2018
"""
import logging
import uasyncio as asyncio
import uasyncio.core
import asyncio
import ujson as json
import gc
import uos as os
Expand All @@ -18,9 +17,11 @@

type_gen = type((lambda: (yield))())

# uasyncio v3 is shipped with MicroPython 1.13, and contains some subtle
# with v1.21.0 release all u-modules where renamend without the u prefix
# -> uasyncio no named asyncio
# asyncio v3 is shipped with MicroPython 1.13, and contains some subtle
# but breaking changes. See also https://github.com/peterhinch/micropython-async/blob/master/v3/README.md
IS_UASYNCIO_V3 = hasattr(asyncio, "__version__") and asyncio.__version__ >= (3,)
IS_ASYNCIO_V3 = hasattr(asyncio, "__version__") and asyncio.__version__ >= (3,)


def urldecode_plus(s):
Expand Down Expand Up @@ -645,8 +646,8 @@ async def _tcp_server(self, host, port, backlog):
sock.listen(backlog)
try:
while True:
if IS_UASYNCIO_V3:
yield uasyncio.core._io_queue.queue_read(sock)
if IS_ASYNCIO_V3:
yield asyncio.core._io_queue.queue_read(sock)
else:
yield asyncio.IORead(sock)
csock, caddr = sock.accept()
Expand Down

0 comments on commit d067b98

Please sign in to comment.