Fix some junk

This commit is contained in:
Neale Pickett 2020-02-28 15:24:23 -07:00
parent 3d0e73d0e9
commit 6d2c65f9c0
2 changed files with 11 additions and 1 deletions

View File

@ -153,7 +153,7 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler):
except KeyError: except KeyError:
self.send_error( self.send_error(
HTTPStatus.NOT_FOUND, HTTPStatus.NOT_FOUND,
"File Not Found", "File Not Found: %s" % self.req["filename"],
) )
return return
@ -233,6 +233,8 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler):
HTTPStatus.NOT_IMPLEMENTED, HTTPStatus.NOT_IMPLEMENTED,
"Unsupported method (%r)" % self.command, "Unsupported method (%r)" % self.command,
) )
# I don't fully understand why you can't do this inside the class definition.
MothRequestHandler.extensions_map[".mjs"] = "application/ecmascript" MothRequestHandler.extensions_map[".mjs"] = "application/ecmascript"

View File

@ -233,6 +233,12 @@ class Puzzle:
except IndexError: except IndexError:
pass pass
self.files[name] = PuzzleFile(stream, name, not hidden) self.files[name] = PuzzleFile(stream, name, not hidden)
elif key == 'files':
for file in val:
path = file["path"]
stream = open(path, "rb")
name = file.get("name") or path
self.files[name] = PuzzleFile(stream, name, not file.get("hidden"))
elif key == 'script': elif key == 'script':
stream = open(val, 'rb') stream = open(val, 'rb')
self.add_script_stream(stream, val) self.add_script_stream(stream, val)
@ -400,10 +406,12 @@ class Puzzle:
"""Return a dict packaging of the puzzle.""" """Return a dict packaging of the puzzle."""
files = [fn for fn,f in self.files.items() if f.visible] files = [fn for fn,f in self.files.items() if f.visible]
hidden = [fn for fn,f in self.files.items() if not f.visible]
return { return {
'authors': self.get_authors(), 'authors': self.get_authors(),
'hashes': self.hashes(), 'hashes': self.hashes(),
'files': files, 'files': files,
'hidden': hidden,
'scripts': self.scripts, 'scripts': self.scripts,
'pattern': self.pattern, 'pattern': self.pattern,
'body': self.html_body(), 'body': self.html_body(),