make it actually work

This commit is contained in:
Neale Pickett 2019-08-14 07:00:21 -06:00
parent 97f808804e
commit cf083dca5c
2 changed files with 37 additions and 37 deletions

View File

@ -210,7 +210,6 @@ sessionStorage.setItem("id", "devel-server")
self.end_headers() self.end_headers()
self.wfile.write(body.encode('utf-8')) self.wfile.write(body.encode('utf-8'))
endpoints.append((r"/", handle_index)) endpoints.append((r"/", handle_index))
endpoints.append((r"/{ignored}", handle_index))
def handle_theme_file(self): def handle_theme_file(self):

View File

@ -15,7 +15,7 @@ import tempfile
import shlex import shlex
import yaml import yaml
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' messageChars = string.ascii_letters.encode("utf-8")
def djb2hash(str): def djb2hash(str):
h = 5381 h = 5381
@ -52,7 +52,7 @@ class PuzzleFile:
from it without having to seek to the beginning of the file. from it without having to seek to the beginning of the file.
name: The name of the output file. name: The name of the output file.
visible: A boolean indicating whether this file should visible to the user. If False, visible: A boolean indicating whether this file should visible to the user. If False,
the file is still expected to be accessible, but it's path must be known the file is still expected to be accessible, but its path must be known
(or figured out) to retrieve it.""" (or figured out) to retrieve it."""
def __init__(self, stream, name, visible=True): def __init__(self, stream, name, visible=True):
@ -91,48 +91,49 @@ class Puzzle:
self.logs.append(msg) self.logs.append(msg)
def read_stream(self, stream): def read_stream(self, stream):
header = True header = io.StringIO()
line = "" body = io.StringIO()
if stream.read(3) == "---": eoh = None
header = "yaml" parser = None
else: doing = header
header = "moth" for lineno, line in enumerate(stream):
sline = line.strip()
stream.seek(0) if lineno == 0:
if sline == "---":
if header == "yaml": eoh = "---"
self.read_yaml_header(stream) parser = self.parse_yaml_header
elif header == "moth":
self.read_moth_header(stream)
for line in stream:
self.body.write(line)
def read_yaml_header(self, stream):
contents = ""
header = False
for line in stream:
if line.strip() == "---" and header: # Handle last line
break
elif line.strip() == "---": # Handle first line
header = True
continue continue
else: else:
contents += line eoh = ""
parser = self.parse_moth_header
if (doing is header) and (sline == eoh):
doing = body
continue
doing.write(line)
header.seek(0)
body.seek(0)
config = yaml.safe_load(contents) if not header:
raise RuntimeError("Empty header block")
parser(header)
self.body = body
def parse_yaml_header(self, stream):
config = yaml.safe_load(stream)
print(config)
for key, value in config.items(): for key, value in config.items():
key = key.lower() key = key.lower()
self.handle_header_key(key, value) self.handle_header_key(key, value)
def read_moth_header(self, stream): def parse_moth_header(self, stream):
for line in stream: for line in stream:
line = line.strip() sline = line.strip()
if not line: if not sline:
break break
key, val = line.split(':', 1) key, val = sline.split(':', 1)
key = key.lower() key = key.lower()
val = val.strip() val = val.strip()
self.handle_header_key(key, val) self.handle_header_key(key, val)