+class PokemonFormAdapter(Adapter):
+ """Converts form ids to form names, and vice versa."""
+ pokemon_forms = {
+ # Unown
+ 201: 'abcdefghijklmnopqrstuvwxyz!?',
+
+ # Deoxys
+ 386: ['normal', 'attack', 'defense', 'speed'],
+
+ # Burmy and Wormadam
+ 412: ['plant', 'sandy', 'trash'],
+ 413: ['plant', 'sandy', 'trash'],
+
+ # Shellos and Gastrodon
+ 422: ['west', 'east'],
+ 423: ['west', 'east'],
+
+ # Rotom
+ 479: ['normal', 'heat', 'wash', 'frost', 'fan', 'cut'],
+
+ # Giratina
+ 487: ['altered', 'origin'],
+
+ # Shaymin
+ 492: ['land', 'sky'],
+
+ # Arceus
+ 493: [
+ 'normal', 'fighting', 'flying', 'poison', 'ground', 'rock',
+ 'bug', 'ghost', 'steel', 'fire', 'water', 'grass',
+ 'thunder', 'psychic', 'ice', 'dragon', 'dark', '???',
+ ],
+ }
+
+ def _decode(self, obj, context):
+ try:
+ forms = self.pokemon_forms[ context['national_id'] ]
+ except KeyError:
+ return None
+
+ return forms[obj >> 3]
+
+ def _encode(self, obj, context):
+ try:
+ forms = self.pokemon_forms[ context['national_id'] ]
+ except KeyError:
+ return None
+
+ return forms.index(obj) << 3
+
+
+