Mercurial > hg > index.fcgi > www > www-1
annotate myw/redirect_app.py @ 121:26cc1a16e7a3
laterlinks3: fix gcs_upload() function
author | paulo |
---|---|
date | Sat, 16 Jan 2021 10:14:02 +0000 |
parents | 6a45e46f0c05 |
children |
rev | line source |
---|---|
paulo@91 | 1 import os |
paulo@91 | 2 |
paulo@91 | 3 import html |
paulo@91 | 4 |
paulo@91 | 5 |
paulo@91 | 6 TITLE = "myw" |
paulo@91 | 7 REDIRECT_FILE = ".htaccess" |
paulo@91 | 8 |
paulo@91 | 9 |
paulo@91 | 10 def main(environ): |
paulo@91 | 11 links = [] |
paulo@91 | 12 |
paulo@91 | 13 with open(REDIRECT_FILE) as f: |
paulo@91 | 14 for l in f: |
paulo@91 | 15 l = l.lstrip() |
paulo@91 | 16 if l.startswith("Redirect"): |
paulo@91 | 17 ls = l.split() |
paulo@91 | 18 if len(ls) == 4: |
paulo@91 | 19 path = ls[2].strip('"') |
paulo@91 | 20 links.append(os.path.basename(path)) |
paulo@91 | 21 |
paulo@91 | 22 root = html.HTML("html") |
paulo@91 | 23 |
paulo@96 | 24 header = root.head |
paulo@91 | 25 header.title(TITLE) |
paulo@91 | 26 header.link(rel="stylesheet", type="text/css", href="index.css") |
paulo@91 | 27 |
paulo@91 | 28 body = root.body(klass="body") |
paulo@91 | 29 |
paulo@91 | 30 for i in links: |
paulo@91 | 31 div = body.div() |
paulo@91 | 32 div.a(i.capitalize(), href=i) |
paulo@91 | 33 |
paulo@91 | 34 return unicode(root).encode("utf-8") |
paulo@91 | 35 |
paulo@91 | 36 |
paulo@91 | 37 def app(environ, start_response): |
paulo@91 | 38 response_body = main(environ) |
paulo@91 | 39 response_headers = [ |
paulo@91 | 40 ("Content-Type", "text/html; charset=UTF-8"), |
paulo@91 | 41 ("Content-Length", str(len(response_body))), |
paulo@91 | 42 ] |
paulo@91 | 43 start_response("200 OK", response_headers) |
paulo@91 | 44 |
paulo@91 | 45 return [response_body] |