Skip to content

Commit 182cf5c

Browse files
committed
rename storage -> wiki_storage, reduce long lines, change title note on new page, use f-string instead of format, ignore some pylints
1 parent a8c3445 commit 182cf5c

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

Fruit_Jam/Fruit_Jam_Tiny_Wiki/code.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# SPDX-License-Identifier: MIT
44
"""CircuitPython port of Tiny Wiki for the Fruit Jam.
55
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
78
89
This script runs on CircuitPython with the ESP32SPI WiFi coprocessor. It uses
910
Adafruit's HTTP Server and TemplateEngine libraries to serve a small Wiki system.
@@ -24,7 +25,7 @@
2425
from adafruit_templateengine import render_template
2526

2627
from tiny_wiki.markdown import SimpleMarkdown
27-
from tiny_wiki.storage import WikiStorage
28+
from tiny_wiki.wiki_storage import WikiStorage
2829

2930
# directory for HTML template files
3031
TEMPLATES_DIR = "/templates"
@@ -76,18 +77,18 @@ def _init_wifi():
7677
esp32_reset = DigitalInOut(board.ESP_RESET)
7778
esp32_cs = DigitalInOut(board.ESP_CS)
7879

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)
8081

8182
print(f"Connecting to {WIFI_SSID}...")
82-
radio.connect(WIFI_SSID, WIFI_PASSWORD)
83+
_radio.connect(WIFI_SSID, WIFI_PASSWORD)
8384
print("WiFi connected")
8485

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)
8788
connection_manager = adafruit_connection_manager.get_connection_manager(pool)
8889

8990
# Keep the connection manager alive to ensure sockets stay open
90-
return radio, pool, connection_manager
91+
return _radio, pool, connection_manager
9192

9293
# initialize WiFi and server object
9394
radio, socket_pool, _connection_manager = _init_wifi()
@@ -283,6 +284,7 @@ def login_form(request):
283284
def login_submit(request):
284285
"""Validate credentials and set session token auth cookie."""
285286

287+
# pylint: disable=too-many-locals
286288
form = request.form_data
287289
username = (form.get("username", "") or "").strip()
288290
password = (form.get("password", "") or "").strip()
@@ -324,7 +326,9 @@ def login_submit(request):
324326
)
325327

326328
# 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")
328332

329333
# session token will be the hash of above str
330334
token = hashlib.new("sha256", token_input_data).digest().hex()

Fruit_Jam/Fruit_Jam_Tiny_Wiki/templates/new_page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ <h1>Create New Page</h1>
2424
</div>
2525
</form>
2626
<hr>
27-
<p><small>Page names can contain spaces. Some special characters like parenthesis and ampersand are supported, but others may not work.</small></p>
27+
<p><small>Page names can contain spaces. Other special characters are unsupported.</small></p>
2828
{% endblock content %}

Fruit_Jam/Fruit_Jam_Tiny_Wiki/tiny_wiki/markdown.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-FileCopyrightText: 2026 Tim C, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4-
# Adapted from files found in [tini_wiki for Micropython by Kevin McAleer](https://github.com/kevinmcaleer/tiny_wiki)
4+
# Adapted from files found in tini_wiki for Micropython by Kevin McAleer:
5+
# https://github.com/kevinmcaleer/tiny_wiki
56
import re
67

78
class SimpleMarkdown:
@@ -17,7 +18,7 @@ def replace_link(match):
1718
page_name = match.group(1)
1819
if link_callback:
1920
return link_callback(page_name)
20-
return '<a href="/wiki/{}">{}</a>'.format(page_name, page_name)
21+
return f'<a href="/wiki/{page_name}">{page_name}</a>'
2122

2223
result = []
2324
index = 0
@@ -40,6 +41,7 @@ def replace_link(match):
4041

4142
def to_html(self, markdown_text):
4243
"""Convert markdown to HTML (simplified)"""
44+
# pylint: disable=too-many-branches, too-many-statements
4345
if not markdown_text:
4446
return ""
4547

Fruit_Jam/Fruit_Jam_Tiny_Wiki/tiny_wiki/storage.py renamed to Fruit_Jam/Fruit_Jam_Tiny_Wiki/tiny_wiki/wiki_storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-FileCopyrightText: 2026 Tim C, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4-
# Adapted from files found in [tini_wiki for Micropython by Kevin McAleer](https://github.com/kevinmcaleer/tiny_wiki)
4+
# Adapted from files found in tini_wiki for Micropython by Kevin McAleer:
5+
# https://github.com/kevinmcaleer/tiny_wiki
56
import os
67
import board
78
import busio

0 commit comments

Comments
 (0)