diff --git a/main.py b/main.py index 4189022..121191a 100644 --- a/main.py +++ b/main.py @@ -8,12 +8,11 @@ # # with your wifi details instead of and . -import sys, network, time - -from phew import server, logging, connect_to_wifi +from phew import server, connect_to_wifi from phew.template import render_template import secrets + connect_to_wifi(secrets.WIFI_SSID, secrets.WIFI_PASSWORD) # basic response with status code and content type @@ -39,7 +38,7 @@ def teapot(request): # custom response object @server.route("/response", methods=["GET"]) def response_object(request): - return Response("test body", status=302, content_type="text/html", headers={"Cache-Control": "max-age=3600"}) + return server.Response("test body", status=302, content_type="text/html", headers={"Cache-Control": "max-age=3600"}) # query string example @server.route("/random", methods=["GET"]) diff --git a/phew/__init__.py b/phew/__init__.py index 5d08a45..a412c2c 100644 --- a/phew/__init__.py +++ b/phew/__init__.py @@ -1,5 +1,7 @@ -# highly recommended to set a lowish garbage collection threshold -# to minimise memory fragmentation as we sometimes want to +__version__ = "0.0.2" + +# highly recommended to set a lowish garbage collection threshold +# to minimise memory fragmentation as we sometimes want to # allocate relatively large blocks of ram. import gc gc.threshold(50000) diff --git a/phew/dns.py b/phew/dns.py index 5aae6c4..4d0439a 100644 --- a/phew/dns.py +++ b/phew/dns.py @@ -20,13 +20,13 @@ async def _handler(socket, ip_address): except Exception as e: logging.error(e) -def run_catchall(ip_address, port = 53): +def run_catchall(ip_address, port=53): logging.info("> starting catch all dns server on port {}".format(port)) _socket = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM) _socket.setblocking(False) _socket.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, 1) _socket.bind(usocket.getaddrinfo(ip_address, port, 0, usocket.SOCK_DGRAM)[0][-1]) - + loop = uasyncio.get_event_loop() loop.create_task(_handler(_socket, ip_address)) diff --git a/phew/logging.py b/phew/logging.py index 9f843fd..0c8ab04 100644 --- a/phew/logging.py +++ b/phew/logging.py @@ -65,7 +65,7 @@ def info(*items): def warn(*items): log("warning", " ".join(map(str, items))) - + def error(*items): log("error", " ".join(map(str, items))) diff --git a/phew/template.py b/phew/template.py index 41305d9..46f1b3f 100644 --- a/phew/template.py +++ b/phew/template.py @@ -5,7 +5,7 @@ async def render_template(template, **kwargs): start_time = time.ticks_ms() with open(template, "rb") as f: - # read the whole template file, we could work on single lines but + # read the whole template file, we could work on single lines but # the performance is much worse - so long as our templates are # just a handful of kB it's ok to do this data = f.read() @@ -26,7 +26,7 @@ async def render_template(template, **kwargs): expression = data[start + 2:end] # output the bit before the tag - yield data[token_caret:start] + yield data[token_caret:start] # merge locals with the supplied named arguments and # the response object diff --git a/setup.py b/setup.py index fdfdb98..206a7c1 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="micropython-phew", - version="0.0.1-post1", + version="0.0.2", description="A small webserver and templating library specifically designed for MicroPython on the Pico W.", long_description=open("README.md").read(), long_description_content_type="text/markdown",