#!/usr/bin/python
-from __future__ import division
+
import datetime
import hwdata
import logging
import re
-import simplejson
+import json
import tornado.web
-import backend
+from .. import fireinfo
-from handlers_base import *
+from . import base
-class FireinfoBaseHandler(BaseHandler):
+class FireinfoBaseHandler(base.BaseHandler):
def cut_string(self, s, limit=15):
if len(s) > limit:
s = s[:limit] + "..."
try:
return self[key]
except KeyError:
- raise AttributeError, key
+ raise AttributeError(key)
def __setattr__(self, key, val):
self[key] = val
"public_id",
)
for attr in attributes:
- if not profile.has_key(attr):
+ if attr not in profile:
raise tornado.web.HTTPError(400, "Profile lacks '%s' attribute: %s" % (attr, profile))
def __check_valid_ids(self, profile):
# Try to decode the profile.
try:
- return simplejson.loads(profile)
- except simplejson.decoder.JSONDecodeError, e:
+ return json.loads(profile)
+ except json.decoder.JSONDecodeError as e:
raise tornado.web.HTTPError(400, "Profile could not be decoded: %s" % e)
# The GET method is only allowed in debugging mode.
location = location.country
# Handle the profile.
- with self.db.transaction():
- try:
- self.fireinfo.handle_profile(public_id, profile_blob, location=location)
+ with self.db.transaction():
+ try:
+ self.fireinfo.handle_profile(public_id, profile_blob, location=location)
- except backend.fireinfo.ProfileParserError:
- raise tornado.web.HTTPError(400)
+ except fireinfo.ProfileParserError:
+ raise tornado.web.HTTPError(400)
self.finish("Your profile was successfully saved to the database.")