diff myw/redirect_app.py @ 91:6a45e46f0c05

myw: use new redirect_app
author paulo
date Thu, 06 Apr 2017 22:42:03 -0700
parents
children 259a484f691b
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/myw/redirect_app.py	Thu Apr 06 22:42:03 2017 -0700
     1.3 @@ -0,0 +1,45 @@
     1.4 +import os
     1.5 +
     1.6 +import html
     1.7 +
     1.8 +
     1.9 +TITLE = "myw"
    1.10 +REDIRECT_FILE = ".htaccess"
    1.11 +
    1.12 +
    1.13 +def main(environ):
    1.14 +	links = []
    1.15 +	
    1.16 +	with open(REDIRECT_FILE) as f:
    1.17 +		for l in f:
    1.18 +			l = l.lstrip()
    1.19 +			if l.startswith("Redirect"):
    1.20 +				ls = l.split()
    1.21 +				if len(ls) == 4:
    1.22 +					path = ls[2].strip('"')
    1.23 +					links.append(os.path.basename(path))
    1.24 +	
    1.25 +	root = html.HTML("html")
    1.26 +	
    1.27 +	header = root.header
    1.28 +	header.title(TITLE)
    1.29 +	header.link(rel="stylesheet", type="text/css", href="index.css")
    1.30 +	
    1.31 +	body = root.body(klass="body")
    1.32 +	
    1.33 +	for i in links:
    1.34 +		div = body.div()
    1.35 +		div.a(i.capitalize(), href=i)
    1.36 +	
    1.37 +	return unicode(root).encode("utf-8")
    1.38 +
    1.39 +
    1.40 +def app(environ, start_response):
    1.41 +	response_body = main(environ)
    1.42 +	response_headers = [
    1.43 +		("Content-Type", "text/html; charset=UTF-8"),
    1.44 +		("Content-Length", str(len(response_body))),
    1.45 +	]
    1.46 +	start_response("200 OK", response_headers)
    1.47 +
    1.48 +	return [response_body]