diff --git a/bin/micropython b/bin/micropython index 81495b8..41e162e 100755 Binary files a/bin/micropython and b/bin/micropython differ diff --git a/libs/micropython/time.py b/libs/micropython/time.py deleted file mode 100644 index 68f7d92..0000000 --- a/libs/micropython/time.py +++ /dev/null @@ -1,79 +0,0 @@ -from utime import * -from micropython import const - -_TS_YEAR = const(0) -_TS_MON = const(1) -_TS_MDAY = const(2) -_TS_HOUR = const(3) -_TS_MIN = const(4) -_TS_SEC = const(5) -_TS_WDAY = const(6) -_TS_YDAY = const(7) -_TS_ISDST = const(8) - -_WDAY = const(("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")) -_MDAY = const( - ( - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", - ) -) - - -def strftime(datefmt, ts): - from io import StringIO - - fmtsp = False - ftime = StringIO() - for k in datefmt: - if fmtsp: - if k == "a": - ftime.write(_WDAY[ts[_TS_WDAY]][0:3]) - elif k == "A": - ftime.write(_WDAY[ts[_TS_WDAY]]) - elif k == "b": - ftime.write(_MDAY[ts[_TS_MON] - 1][0:3]) - elif k == "B": - ftime.write(_MDAY[ts[_TS_MON] - 1]) - elif k == "d": - ftime.write("%02d" % ts[_TS_MDAY]) - elif k == "H": - ftime.write("%02d" % ts[_TS_HOUR]) - elif k == "I": - ftime.write("%02d" % (ts[_TS_HOUR] % 12)) - elif k == "j": - ftime.write("%03d" % ts[_TS_YDAY]) - elif k == "m": - ftime.write("%02d" % ts[_TS_MON]) - elif k == "M": - ftime.write("%02d" % ts[_TS_MIN]) - elif k == "P": - ftime.write("AM" if ts[_TS_HOUR] < 12 else "PM") - elif k == "S": - ftime.write("%02d" % ts[_TS_SEC]) - elif k == "w": - ftime.write(str(ts[_TS_WDAY])) - elif k == "y": - ftime.write("%02d" % (ts[_TS_YEAR] % 100)) - elif k == "Y": - ftime.write(str(ts[_TS_YEAR])) - else: - ftime.write(k) - fmtsp = False - elif k == "%": - fmtsp = True - else: - ftime.write(k) - val = ftime.getvalue() - ftime.close() - return val diff --git a/src/microdot/microdot.py b/src/microdot/microdot.py index 65c8d37..4bfa005 100644 --- a/src/microdot/microdot.py +++ b/src/microdot/microdot.py @@ -595,7 +595,7 @@ class Response: if expires: if isinstance(expires, str): http_cookie += '; Expires=' + expires - else: + else: # pragma: no cover http_cookie += '; Expires=' + time.strftime( '%a, %d %b %Y %H:%M:%S GMT', expires.timetuple()) if max_age: diff --git a/tests/test_response.py b/tests/test_response.py index 3780f92..1fdae2b 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -1,5 +1,4 @@ import asyncio -from datetime import datetime import unittest from microdot import Response from tests.mock_socket import FakeStreamAsync @@ -186,12 +185,12 @@ class TestResponse(unittest.TestCase): res.set_cookie('foo2', 'bar2', path='/', partitioned=True) res.set_cookie('foo3', 'bar3', domain='example.com:1234') res.set_cookie('foo4', 'bar4', - expires=datetime(2019, 11, 5, 2, 23, 54)) + expires='Tue, 05 Nov 2019 02:23:54 GMT') res.set_cookie('foo5', 'bar5', max_age=123, expires='Thu, 01 Jan 1970 00:00:00 GMT') res.set_cookie('foo6', 'bar6', secure=True, http_only=True) res.set_cookie('foo7', 'bar7', path='/foo', domain='example.com:1234', - expires=datetime(2019, 11, 5, 2, 23, 54), max_age=123, + expires='Tue, 05 Nov 2019 02:23:54 GMT', max_age=123, secure=True, http_only=True) res.delete_cookie('foo8', http_only=True) self.assertEqual(res.headers, {'Set-Cookie': [ diff --git a/tools/Dockerfile b/tools/Dockerfile index 2f68fb9..dce4144 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -1,23 +1,24 @@ FROM ubuntu:22.04 ARG DEBIAN_FRONTEND=noninteractive +ARG VERSION=master +ENV VERSION=$VERSION RUN apt-get update && \ apt-get install -y build-essential libffi-dev git pkg-config python3 && \ rm -rf /var/lib/apt/lists/* && \ git clone https://github.com/micropython/micropython.git && \ cd micropython && \ + git checkout $VERSION && \ git submodule update --init && \ cd mpy-cross && \ make && \ cd .. && \ cd ports/unix && \ make && \ - make test && \ make install && \ apt-get purge --auto-remove -y build-essential libffi-dev git pkg-config python3 && \ cd ../../.. && \ rm -rf micropython CMD ["/usr/local/bin/micropython"] - diff --git a/tools/Dockerfile.circuitpython b/tools/Dockerfile.circuitpython new file mode 100644 index 0000000..9d2492e --- /dev/null +++ b/tools/Dockerfile.circuitpython @@ -0,0 +1,24 @@ +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive +ARG VERSION=main +ENV VERSION=$VERSION + +RUN apt-get update && \ + apt-get install -y build-essential libffi-dev git pkg-config python3 && \ + rm -rf /var/lib/apt/lists/* && \ + git clone https://github.com/adafruit/circuitpython.git && \ + cd circuitpython && \ + git checkout $VERSION && \ + git submodule update --init lib tools frozen && \ + cd mpy-cross && \ + make && \ + cd .. && \ + cd ports/unix && \ + make && \ + make install && \ + apt-get purge --auto-remove -y build-essential libffi-dev git pkg-config python3 && \ + cd ../../.. && \ + rm -rf circuitpython + +CMD ["/usr/local/bin/micropython"] diff --git a/tools/update-circuitpython.sh b/tools/update-circuitpython.sh new file mode 100755 index 0000000..8946cda --- /dev/null +++ b/tools/update-circuitpython.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# this script updates the micropython binary in the /bin directory that is +# used to run unit tests under GitHub Actions builds + +DOCKER=${DOCKER:-docker} +VERSION=${1:-main} + +$DOCKER build -f Dockerfile.circuitpython --build-arg VERSION=$VERSION -t circuitpython . +$DOCKER create -t --name dummy-circuitpython circuitpython +$DOCKER cp dummy-circuitpython:/usr/local/bin/micropython ../bin/circuitpython +$DOCKER rm dummy-circuitpython diff --git a/tools/update-micropython.sh b/tools/update-micropython.sh index 1bd1f4c..f8a7a40 100755 --- a/tools/update-micropython.sh +++ b/tools/update-micropython.sh @@ -3,8 +3,9 @@ # used to run unit tests under GitHub Actions builds DOCKER=${DOCKER:-docker} +VERSION=${1:-master} -$DOCKER build -t micropython . +$DOCKER build --build-arg VERSION=$VERSION -t micropython . $DOCKER create -it --name dummy-micropython micropython $DOCKER cp dummy-micropython:/usr/local/bin/micropython ../bin/micropython $DOCKER rm dummy-micropython diff --git a/tox.ini b/tox.ini index f5350c4..8d5a46f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=flake8,py38,py39,py310,py311,py312,upy,benchmark +envlist=flake8,py38,py39,py310,py311,py312,upy,cpy,benchmark skipsdist=True skip_missing_interpreters=True @@ -29,6 +29,10 @@ setenv= allowlist_externals=sh commands=sh -c "bin/micropython run_tests.py" +[testenv:cpy] +allowlist_externals=sh +commands=sh -c "bin/circuitpython run_tests.py" + [testenv:upy-mac] allowlist_externals=micropython commands=micropython run_tests.py