|
3 | 3 | # SPDX-License-Identifier: MIT |
4 | 4 | """CircuitPython port of Tiny Wiki for the Fruit Jam. |
5 | 5 |
|
6 | | -This project was ported from [tiny_wiki for Micropython](https://github.com/kevinmcaleer/tiny_wiki) by Kevin McAleer. |
| 6 | +This project was ported from tiny_wiki for Micropython by Kevin McAleer: |
| 7 | +https://github.com/kevinmcaleer/tiny_wiki |
7 | 8 |
|
8 | 9 | This script runs on CircuitPython with the ESP32SPI WiFi coprocessor. It uses |
9 | 10 | Adafruit's HTTP Server and TemplateEngine libraries to serve a small Wiki system. |
|
24 | 25 | from adafruit_templateengine import render_template |
25 | 26 |
|
26 | 27 | from tiny_wiki.markdown import SimpleMarkdown |
27 | | -from tiny_wiki.storage import WikiStorage |
| 28 | +from tiny_wiki.wiki_storage import WikiStorage |
28 | 29 |
|
29 | 30 | # directory for HTML template files |
30 | 31 | TEMPLATES_DIR = "/templates" |
@@ -76,18 +77,18 @@ def _init_wifi(): |
76 | 77 | esp32_reset = DigitalInOut(board.ESP_RESET) |
77 | 78 | esp32_cs = DigitalInOut(board.ESP_CS) |
78 | 79 |
|
79 | | - radio = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) |
| 80 | + _radio = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) |
80 | 81 |
|
81 | 82 | print(f"Connecting to {WIFI_SSID}...") |
82 | | - radio.connect(WIFI_SSID, WIFI_PASSWORD) |
| 83 | + _radio.connect(WIFI_SSID, WIFI_PASSWORD) |
83 | 84 | print("WiFi connected") |
84 | 85 |
|
85 | | - pool = adafruit_connection_manager.get_radio_socketpool(radio) |
86 | | - _ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio) |
| 86 | + pool = adafruit_connection_manager.get_radio_socketpool(_radio) |
| 87 | + _ssl_context = adafruit_connection_manager.get_radio_ssl_context(_radio) |
87 | 88 | connection_manager = adafruit_connection_manager.get_connection_manager(pool) |
88 | 89 |
|
89 | 90 | # Keep the connection manager alive to ensure sockets stay open |
90 | | - return radio, pool, connection_manager |
| 91 | + return _radio, pool, connection_manager |
91 | 92 |
|
92 | 93 | # initialize WiFi and server object |
93 | 94 | radio, socket_pool, _connection_manager = _init_wifi() |
@@ -283,6 +284,7 @@ def login_form(request): |
283 | 284 | def login_submit(request): |
284 | 285 | """Validate credentials and set session token auth cookie.""" |
285 | 286 |
|
| 287 | + # pylint: disable=too-many-locals |
286 | 288 | form = request.form_data |
287 | 289 | username = (form.get("username", "") or "").strip() |
288 | 290 | password = (form.get("password", "") or "").strip() |
@@ -324,7 +326,9 @@ def login_submit(request): |
324 | 326 | ) |
325 | 327 |
|
326 | 328 | # combine password_hash + server secret_key + random str |
327 | | - token_input_data = f"{password_hash}:){WIKI_AUTH_SECRET_KEY}=D{random_str}".encode("utf-8") |
| 329 | + token_input_data = (f"{password_hash}:)" |
| 330 | + f"{WIKI_AUTH_SECRET_KEY}=D" |
| 331 | + f"{random_str}").encode("utf-8") |
328 | 332 |
|
329 | 333 | # session token will be the hash of above str |
330 | 334 | token = hashlib.new("sha256", token_input_data).digest().hex() |
|
0 commit comments