Skip to content

Commit

Permalink
Merge pull request #7 from pimoroni/pypi
Browse files Browse the repository at this point in the history
Fix some minor issues and bump to v0.0.2
  • Loading branch information
Gadgetoid authored Aug 18, 2022
2 parents 949a9ab + bde52eb commit 8995e8b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#
# with your wifi details instead of <ssid> and <password>.

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
Expand All @@ -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"])
Expand Down
6 changes: 4 additions & 2 deletions phew/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions phew/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion phew/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
4 changes: 2 additions & 2 deletions phew/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8995e8b

Please sign in to comment.