From 59e19b1f3e06294a73354ab413502a85ed7ad964 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Thu, 12 Dec 2013 20:43:15 -0500 Subject: [PATCH] Assume hashkeys are double quoted. --- xonstat/__init__.py | 5 +++-- xonstat/views/player.py | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/xonstat/__init__.py b/xonstat/__init__.py index b2314b3..c38d31c 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -48,7 +48,7 @@ def main(global_config, **settings): config.add_route("player_info", "/player/{id:\d+}") config.add_view(player_info, route_name="player_info", renderer="player_info.mako") - config.add_route("player_hashkey_info_json", "/player/{hashkey:.{44}}.json") + config.add_route("player_hashkey_info_json", "/player/me.json") config.add_view(player_hashkey_info_json, route_name="player_hashkey_info_json", renderer="jsonp") config.add_route("player_hashkey_info_text", "/player/me") @@ -60,7 +60,8 @@ def main(global_config, **settings): config.add_route("player_elo_info_text", "/player/{hashkey}/elo.txt") config.add_view(player_elo_info_text, route_name="player_elo_info_text", renderer="player_elo_info_text.mako") - config.add_route("player_elo_info_json", "/player/{hashkey}/elo.json") ## FIXME - doesn't seem to work? + # FIXME - needs an additional method to convert to JSON + config.add_route("player_elo_info_json", "/player/{hashkey}/elo.json") config.add_view(player_elo_info_json, route_name="player_elo_info_json", renderer="jsonp") config.add_route("player_accuracy", "/player/{id:\d+}/accuracy") diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 41217e5..19ec081 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -10,6 +10,7 @@ from xonstat.models import * from xonstat.util import page_url, to_json, pretty_date, datetime_seconds from xonstat.util import is_cake_day, verify_request from xonstat.views.helpers import RecentGame, recent_games_q +from urllib import unquote log = logging.getLogger(__name__) @@ -788,7 +789,13 @@ def player_damage_json(request): def player_hashkey_info_data(request): - (idfp, status) = verify_request(request) + # hashkey = request.matchdict['hashkey'] + + # the incoming hashkey is double quoted, and WSGI unquotes once... + # hashkey = unquote(hashkey) + + # if using request verification to obtain the hashkey + (hashkey, status) = verify_request(request) # if config is to *not* verify requests and we get nothing back, this # query will return nothing and we'll 404. @@ -796,7 +803,7 @@ def player_hashkey_info_data(request): player = DBSession.query(Player).\ filter(Player.player_id == Hashkey.player_id).\ filter(Player.active_ind == True).\ - filter(Hashkey.hashkey == idfp).one() + filter(Hashkey.hashkey == hashkey).one() games_played = get_games_played(player.player_id) overall_stats = get_overall_stats(player.player_id) @@ -913,7 +920,10 @@ def player_elo_info_data(request): Provides elo information on a specific player. Raw data is returned. """ hashkey = request.matchdict['hashkey'] - print "player_elo_info_data [hashkey={0}]".format(hashkey) + + # the incoming hashkey is double quoted, and WSGI unquotes once... + hashkey = unquote(hashkey) + try: player = DBSession.query(Player).\ filter(Player.player_id == Hashkey.player_id).\ -- 2.39.2