"""Interfaces for storing data"""
import abc
from future.utils import with_metaclass
class _Sink(with_metaclass(abc.ABCMeta, object)):
"""Generic interface specifying methods that all sinks must implement"""
@abc.abstractmethod
def flush(self):
"""
Flush any buffered operations
Returns:
None
"""
@abc.abstractmethod
def close(self):
"""
Close the sink, flushing any buffered operations and releasing any
locks on the underlying backend
Returns:
None
"""
def __enter__(self):
return self
def __exit__(self, *exc):
self.close()
[docs]class MovesetSink(_Sink):
"""Sink for storing movesets"""
@abc.abstractmethod
[docs] def store_movesets(self, movesets):
"""
Store the provided movesets.
Args:
movesets (:obj:`dict` of :obj:`str` to :obj:`onix.dto.Moveset`) :
A map where the values are the movesets to store and the keys
their corresponding set IDs.
Returns:
None
"""
[docs]class BattleInfoSink(_Sink):
"""Sink for storing battle metadata"""
@abc.abstractmethod
[docs] def store_battle_info(self, battle_info):
"""
Store the provided battle info.
Args:
battle_info (onix.model.BattleInfo) :
The battle metadata to store
Returns:
None
"""
[docs]class BattleSink(_Sink):
"""Sink for storing the turn-by-turn battle logs"""
@abc.abstractmethod
[docs] def store_battle(self, battle):
"""
Store the provided battle.
Args:
battle (onix.battle.Battle) :
The battle to store
Returns:
None
"""