]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/web/handlers_fireinfo.py
blog: Add dialogue to publish posts at a certain time
[ipfire.org.git] / src / web / handlers_fireinfo.py
index bc3d102f59a93f8d45a081a978d3fdb95e8e8dd1..12c417ea4d29cbda4cbff791be18a0e6d35cd665 100644 (file)
@@ -1,19 +1,19 @@
 #!/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] + "..."
@@ -40,7 +40,7 @@ class Profile(dict):
                try:
                        return self[key]
                except KeyError:
-                       raise AttributeError, key
+                       raise AttributeError(key)
 
        def __setattr__(self, key, val):
                self[key] = val
@@ -65,7 +65,7 @@ class FireinfoProfileSendHandler(FireinfoBaseHandler):
                        "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):
@@ -135,8 +135,8 @@ class FireinfoProfileSendHandler(FireinfoBaseHandler):
 
                # 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.
@@ -156,12 +156,12 @@ class FireinfoProfileSendHandler(FireinfoBaseHandler):
                        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.")