Created
August 9, 2017 00:42
-
-
Save souenzzo/1a482893456e584565c0000776acc70f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http.server | |
def bar(props): | |
return ["bar", {}, str(props)] | |
x = ["div", {}, | |
["sp", {"onClick": "foobar()"}, ["code", {}, "foo"]], | |
[bar, 44, 666, 77], | |
["p", {}, "Olá mundo!"]] | |
def parseMeta(x): | |
s = "" | |
for i in x: | |
s = s + " " + i + "=\"" + x[i] + "\"" | |
return s | |
def parse(x): | |
if type(x) == type([]): | |
fn, *args = x | |
if type(fn) == type(""): | |
tag, props, *body = x | |
metaStr = parseMeta(props) | |
bodyStr = "" | |
for i in body: | |
bodyStr = bodyStr + parse(i) | |
return "".join(["<", tag, metaStr, ">", bodyStr, "</", tag, ">"]) | |
return parse(fn(args)) | |
return str(x) | |
def handler(servlet_request, client_address, servlet): | |
f = servlet_request.makefile("wb") | |
f.write(b"HTTP/1.1 200 OK\r\n") | |
f.write(b"Content-Type: text/html\r\n") | |
f.write(b"\r\n") | |
f.write(parse(x).encode()) | |
addr = ("", 8000) | |
srv = http.server.HTTPServer(addr, handler) | |
srv.serve_forever() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment