Upgrade to Pylons 1.0. #283
[zzz-spline-gts.git] / splinext / gts / controllers / gts.py
index 5f7bfaf..c4bed33 100644 (file)
@@ -12,13 +12,14 @@ import struct
 import pokedex.db
 import pokedex.db.tables as tables
 import pokedex.formulae
-from pokedex.savefile import PokemonSave
+from pokedex.struct import SaveFilePokemon
 from pylons import config, request, response, session, tmpl_context as c, url
-from pylons.controllers.util import abort, redirect_to
+from pylons.controllers.util import abort, redirect
 from sqlalchemy import and_, or_, not_
 from sqlalchemy.orm import aliased, contains_eager, eagerload, eagerload_all, join
 from sqlalchemy.orm.exc import NoResultFound
 from sqlalchemy.sql import func
+from sqlalchemy.exc import IntegrityError
 
 from spline.model import meta
 from spline.lib.base import BaseController, render
@@ -156,7 +157,7 @@ class GTSController(BaseController):
                 .one()
             # We've got one!  Cool, send it back.  The game will ask us to
             # delete it after receiving successfully
-            pokemon_save = PokemonSave(stored_pokemon.pokemon_blob)
+            pokemon_save = SaveFilePokemon(stored_pokemon.pokemon_blob)
             return pokemon_save.as_encrypted
 
         except:
@@ -186,7 +187,7 @@ class GTSController(BaseController):
 
         try:
             # The uploaded Pokémon is encrypted, which is not very useful
-            pokemon_save = PokemonSave(data, encrypted=True)
+            pokemon_save = SaveFilePokemon(data, encrypted=True)
 
             # Create a record...
             stored_pokemon = gts_model.GTSPokemon(
@@ -196,9 +197,9 @@ class GTSController(BaseController):
             meta.Session.add(stored_pokemon)
             meta.Session.commit()
             return '\x01\x00'
-        except:
-            # If that failed (presumably due to unique key collision), we're
-            # already storing something.  Reject!
+        except IntegrityError:
+            # If that failed due to unique key collision, we're already storing
+            # something.  Reject!
             return '\x0c\x00'
 
     def page_post_finish(self, pid, data):