Ver código fonte

Internal cleanup for Flask.

pull/24/head
Ben Kurtovic 10 anos atrás
pai
commit
1344594c33
7 arquivos alterados com 23 adições e 22 exclusões
  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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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>


Carregando…
Cancelar
Salvar