瀏覽代碼

Internal cleanup for Flask.

pull/24/head
Ben Kurtovic 10 年之前
父節點
當前提交
1344594c33
共有 7 個檔案被更改,包括 23 行新增22 行删除
  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 查看文件

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

@app.route("/")
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")
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")
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__':
WSGIServer(app).run()

+ 6
- 7
copyvios/cookies.py 查看文件

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

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

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


+ 2
- 2
templates/debug.mako 查看文件

@@ -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>
% for key, value in environ.items():
% if key not in ["wsgi.input", "wsgi.errors", "PATH"]:
@@ -8,4 +8,4 @@
% endif
% endfor
</ul>
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>
<%include file="/support/footer.mako" args="cookies=cookies"/>

+ 2
- 2
templates/index.mako 查看文件

@@ -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.misc" import="urlstrip"/>\
<%
@@ -158,4 +158,4 @@
</div>
</div>
% endif
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>
<%include file="/support/footer.mako" args="cookies=cookies"/>

+ 2
- 2
templates/settings.mako 查看文件

@@ -1,6 +1,6 @@
<%namespace module="copyvios.settings" import="main"/>\
<% 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 %>\
% if status:
<div id="info-box" class="green-box">
@@ -106,4 +106,4 @@
% else:
<p>No cookies!</p>
% 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 查看文件

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


+ 1
- 2
templates/support/header.mako 查看文件

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


Loading…
取消
儲存