Skip to content

Commit

Permalink
Merge branch 'master' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
marians committed Apr 7, 2015
2 parents 5a0e538 + cfc4162 commit 7d212ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions runserver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# encoding: utf8

from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash, Markup
import redis
import time
from datetime import datetime, timedelta
import os
import base64

app = Flask(__name__)

Expand Down Expand Up @@ -199,8 +200,10 @@ def keys(host, port, db):
@app.route("/<host>:<int:port>/<int:db>/keys/<key>/")
def key(host, port, db, key):
"""
Show a specific key
Show a specific key.
key is expected to be URL-safe base64 encoded
"""
key = base64.urlsafe_b64decode(key.encode("utf8"))
s = time.time()
r = redis.StrictRedis(host=host, port=port, db=db)
dump = r.dump(key)
Expand Down Expand Up @@ -236,5 +239,14 @@ def key(host, port, db, key):
duration=time.time()-s)


@app.template_filter('urlsafe_base64')
def urlsafe_base64_encode(s):
if type(s) == 'Markup':
s = s.unescape()
s = s.encode('utf8')
s = base64.urlsafe_b64encode(s)
return Markup(s)


if __name__ == "__main__":
app.run(host="0.0.0.0", debug=False, port=5001)
2 changes: 1 addition & 1 deletion templates/keys.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1>All Keys</h1>
<tr>
<td class="text-right" style="width: 5%">{{ loop.index + offset }}</td>
<td>{{ types[key] }}</td>
<td><a href="{{ key|urlencode }}/">{{ key }}</a></td>
<td><a href="{{ key|urlsafe_base64 }}/">{{ key }}</a></td>
<td><form method="POST"><input type="hidden" name="action" value="delkey" /><input type="hidden" name="key" value="{{ key }}" /><button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-trash"></span></button></form></td>
</tr>
{% endfor %}
Expand Down

0 comments on commit 7d212ec

Please sign in to comment.