From f593aa99728697ed0683c7470ca9d5702b242f5d Mon Sep 17 00:00:00 2001 From: Ted Timmons Date: Sat, 27 Jan 2024 12:44:48 -0800 Subject: [PATCH 1/2] add cpython example Shows the basic incantations to make it run in a cpython environment. --- examples/httpserver_cpython.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/httpserver_cpython.py diff --git a/examples/httpserver_cpython.py b/examples/httpserver_cpython.py new file mode 100644 index 0000000..1d97364 --- /dev/null +++ b/examples/httpserver_cpython.py @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: 2024 Ted Timmons +# +# SPDX-License-Identifier: Unlicense +# +# Simple example showing how to use httpserver in cpython (e.g., on a computer). + +import socket + + +# fake the wifi class, reduces changes required later in the code. +class wifi: + class radio: + ipv4_address = '0.0.0.0' + + +from adafruit_httpserver import Server, Request, Response + + +pool = socket +server = Server(pool, "/static", debug=True) + + +@server.route("/") +def base(request: Request): + """ + Serve a default static plain text message. + """ + return Response(request, "Hello from the CircuitPython HTTP Server!") + + +server.serve_forever(str(wifi.radio.ipv4_address)) From c048bdeba1c3bb2d00874c9b3556046fde392323 Mon Sep 17 00:00:00 2001 From: Ted Timmons Date: Sat, 27 Jan 2024 13:01:55 -0800 Subject: [PATCH 2/2] lint/black fixes --- examples/httpserver_cpython.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/httpserver_cpython.py b/examples/httpserver_cpython.py index 1d97364..f85e055 100644 --- a/examples/httpserver_cpython.py +++ b/examples/httpserver_cpython.py @@ -5,15 +5,13 @@ # Simple example showing how to use httpserver in cpython (e.g., on a computer). import socket +from adafruit_httpserver import Server, Request, Response # fake the wifi class, reduces changes required later in the code. -class wifi: - class radio: - ipv4_address = '0.0.0.0' - - -from adafruit_httpserver import Server, Request, Response +class wifi: # pylint: disable=too-few-public-methods + class radio: # pylint: disable=too-few-public-methods + ipv4_address = "0.0.0.0" pool = socket