Browse Source

Internal cleanup for Flask.

pull/24/head
Ben Kurtovic 10 years ago
parent
commit
1344594c33
7 changed files with 23 additions and 22 deletions
  1. +9
    -6
      app.fcgi
  2. +6
    -7
      copyvios/cookies.py
  3. +2
    -2
      templates/debug.mako
  4. +2
    -2
      templates/index.mako
  5. +2
    -2
      templates/settings.mako
  6. +1
    -1
      templates/support/footer.mako
  7. +1
    -2
      templates/support/header.mako

+ 9
- 6
app.fcgi View File

@@ -27,18 +27,21 @@ def write_access_log(response):


@app.route("/") @app.route("/")
def index(): def index():
cookies = parse_cookies(request.environ)
return render_template("index.mako", environ=request.environ, cookies=cookies)
root = request.environ["SCRIPT_NAME"]
cookies = parse_cookies(root, request.environ.get("HTTP_COOKIE"))
return render_template("index.mako", root=root, environ=request.environ, cookies=cookies)


@app.route("/settings") @app.route("/settings")
def settings(): def settings():
cookies = parse_cookies(request.environ)
return render_template("settings.mako", environ=request.environ, cookies=cookies)
root = request.environ["SCRIPT_NAME"]
cookies = parse_cookies(root, request.environ.get("HTTP_COOKIE"))
return render_template("settings.mako", root=root, environ=request.environ, cookies=cookies)


@app.route("/debug") @app.route("/debug")
def debug(): def debug():
cookies = parse_cookies(request.environ)
return render_template("debug.mako", environ=request.environ, cookies=cookies)
root = request.environ["SCRIPT_NAME"]
cookies = parse_cookies(root, request.environ.get("HTTP_COOKIE"))
return render_template("debug.mako", root=root, environ=request.environ, cookies=cookies)


if __name__ == '__main__': if __name__ == '__main__':
WSGIServer(app).run() WSGIServer(app).run()

+ 6
- 7
copyvios/cookies.py View File

@@ -3,16 +3,15 @@
import base64 import base64
from Cookie import CookieError, SimpleCookie from Cookie import CookieError, SimpleCookie
from datetime import datetime, timedelta from datetime import datetime, timedelta
from os import path


class _CookieManager(SimpleCookie): class _CookieManager(SimpleCookie):
MAGIC = "--cpv2" MAGIC = "--cpv2"


def __init__(self, environ):
self._path = path.dirname(environ["SCRIPT_NAME"])
def __init__(self, path, cookies):
self._path = path
try: try:
super(_CookieManager, self).__init__(environ["HTTP_COOKIE"])
except (CookieError, KeyError):
super(_CookieManager, self).__init__(cookies)
except CookieError:
super(_CookieManager, self).__init__() super(_CookieManager, self).__init__()
for cookie in self.keys(): for cookie in self.keys():
if self[cookie].value is False: if self[cookie].value is False:
@@ -38,8 +37,8 @@ class _CookieManager(SimpleCookie):
return self._path return self._path




def parse_cookies(environ):
return _CookieManager(environ)
def parse_cookies(path, cookies):
return _CookieManager(path, cookies)


def set_cookie(headers, cookies, key, value, days=0): def set_cookie(headers, cookies, key, value, days=0):
cookies[key] = value cookies[key] = value


+ 2
- 2
templates/debug.mako View File

@@ -1,4 +1,4 @@
<%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Debug - Earwig\'s Copyvio Detector'"/>
<%include file="/support/header.mako" args="title='Debug - Earwig\'s Copyvio Detector', root=root, cookies=cookies"/>
<ul> <ul>
% for key, value in environ.items(): % for key, value in environ.items():
% if key not in ["wsgi.input", "wsgi.errors", "PATH"]: % if key not in ["wsgi.input", "wsgi.errors", "PATH"]:
@@ -8,4 +8,4 @@
% endif % endif
% endfor % endfor
</ul> </ul>
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>
<%include file="/support/footer.mako" args="cookies=cookies"/>

+ 2
- 2
templates/index.mako View File

@@ -1,4 +1,4 @@
<%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Earwig\'s Copyvio Detector'"/>\
<%include file="/support/header.mako" args="title='Earwig\'s Copyvio Detector', root=root, cookies=cookies"/>
<%namespace module="copyvios" import="main, highlight_delta"/>\ <%namespace module="copyvios" import="main, highlight_delta"/>\
<%namespace module="copyvios.misc" import="urlstrip"/>\ <%namespace module="copyvios.misc" import="urlstrip"/>\
<% <%
@@ -158,4 +158,4 @@
</div> </div>
</div> </div>
% endif % endif
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>
<%include file="/support/footer.mako" args="cookies=cookies"/>

+ 2
- 2
templates/settings.mako View File

@@ -1,6 +1,6 @@
<%namespace module="copyvios.settings" import="main"/>\ <%namespace module="copyvios.settings" import="main"/>\
<% bot, status, langs, projects = main(environ, headers, cookies) %>\ <% bot, status, langs, projects = main(environ, headers, cookies) %>\
<%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Settings - Earwig\'s Copyvio Detector'"/>\
<%include file="/support/header.mako" args="title='Settings - Earwig\'s Copyvio Detector', root=root, cookies=cookies"/>
<%! from json import dumps, loads %>\ <%! from json import dumps, loads %>\
% if status: % if status:
<div id="info-box" class="green-box"> <div id="info-box" class="green-box">
@@ -106,4 +106,4 @@
% else: % else:
<p>No cookies!</p> <p>No cookies!</p>
% endif % endif
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>
<%include file="/support/footer.mako" args="cookies=cookies"/>

+ 1
- 1
templates/support/footer.mako View File

@@ -1,4 +1,4 @@
<%page args="environ, cookies"/>\
<%page args="cookies"/>\
<%namespace module="copyvios.background" import="get_desc_url"/>\ <%namespace module="copyvios.background" import="get_desc_url"/>\
</div> </div>
<div id="footer"> <div id="footer">


+ 1
- 2
templates/support/header.mako View File

@@ -1,6 +1,5 @@
<%page args="environ, cookies, title"/>\
<%page args="title, root, cookies"/>\
<%namespace module="copyvios.background" import="set_background"/>\ <%namespace module="copyvios.background" import="set_background"/>\
<% root = environ["SCRIPT_NAME"] %>\
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>


Loading…
Cancel
Save