Quellcode durchsuchen

Support GET and POST in query.

pull/24/head
Ben Kurtovic vor 12 Jahren
Ursprung
Commit
0fad121316
4 geänderte Dateien mit 14 neuen und 22 gelöschten Zeilen
  1. +0
    -15
      pages/bash.mako
  2. +1
    -3
      pages/support/footer.mako
  3. +12
    -3
      toolserver/misc.py
  4. +1
    -1
      toolserver/settings.py

+ 0
- 15
pages/bash.mako Datei anzeigen

@@ -1,15 +0,0 @@
<%!
from random import choice
bashes = [
"Now 20% cooler!",
"I make tools and tool accessories."
]
%>\
<%def name="get_bash()">${choice(bashes)}</%def>\
<%include file="/support/header.mako" args="environ=environ, title='Bash'"/>
<ol>
% for bash in bashes:
<li>${bash}</li>
% endfor
</ol>
<%include file="/support/footer.mako" args="environ=environ"/>

+ 1
- 3
pages/support/footer.mako Datei anzeigen

@@ -1,5 +1,4 @@
<%page args="environ"/>\
<%namespace name="bash" file="/bash.mako" import="get_bash"/>\
<%!
from os import path
%>\
@@ -20,8 +19,7 @@
<a href="mailto:earwig@toolserver.org">Contact</a> &bull; \
<a href="https://github.com/earwig/toolserver">View Source</a> &bull; \
<a id="bg_image_link" href="">Background</a> &bull; \
<a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0 Strict</a><br />
<i><a class="black" href="${pretty}/bash">"${get_bash()}"</a></i>
<a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0 Strict</a>
</p>
</td>
<td>


+ 12
- 3
toolserver/misc.py Datei anzeigen

@@ -7,11 +7,20 @@ from earwigbot.bot import Bot
import oursql

class Query(object):
def __init__(self, environ):
def __init__(self, environ, method="GET"):
self.query = {}
parsed = parse_qs(environ["QUERY_STRING"])
if method == "GET":
parsed = parse_qs(environ["QUERY_STRING"])
elif method == "POST":
size = environ.get("CONTENT_LENGTH", 0)
parsed = parse_qs(environ["wsgi.input"].read(size))
else:
parsed = {}
for key, value in parsed.iteritems():
self.query[key] = value[-1].decode("utf8")
try:
self.query[key] = value[-1].decode("utf8")
except UnicodeDecodeError:
pass

def __getattr__(self, key):
try:


+ 1
- 1
toolserver/settings.py Datei anzeigen

@@ -6,7 +6,7 @@ from .sites import get_sites

def main(context, environ, headers):
cookies = parse_cookies(context, environ)
query = Query(environ)
query = Query(environ, method="POST")

if query.action == "set":
if query.lang:


Laden…
Abbrechen
Speichern