<s> class EventListener : <EOL> def __init__ ( self , events = [ ] ) : <EOL> self . _events = events <EOL> def append ( self , event ) : <EOL> self . _events . append ( event ) <EOL> def fire ( self , e ) : <EOL> for _event in self . _events : <EOL> _event ( e ) <EOL> class IndexedDB : <EOL> def __init__ ( self ) : <EOL> if not __BRYTHON__ . has_indexedDB : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> return <EOL> self . _indexedDB = __BRYTHON__ . indexedDB ( ) <EOL> self . _db = None <EOL> self . _version = None <EOL> def _onsuccess ( self , event ) : <EOL> self . _db = event . target . result <EOL> def open ( self , name , onsuccess , version = <NUM_LIT:1.0> , onerror = None , <EOL> onupgradeneeded = None ) : <EOL> self . _version = version <EOL> _result = self . _indexedDB . open ( name , version ) <EOL> _success = EventListener ( [ self . _onsuccess , onsuccess ] ) <EOL> _result . onsuccess = _success . fire <EOL> _result . onupgradeneeded = onupgradeneeded <EOL> def onerror ( e ) : <EOL> print ( "<STR_LIT>" % ( e . type , e . target . result ) ) <EOL> def onblocked ( e ) : <EOL> print ( "<STR_LIT>" % ( e . type , e . result ) ) <EOL> _result . onerror = onerror <EOL> _result . onblocked = onblocked <EOL> def transaction ( self , entities , mode = '<STR_LIT>' ) : <EOL> return Transaction ( self . _db . transaction ( entities , mode ) ) <EOL> class Transaction : <EOL> def __init__ ( self , transaction ) : <EOL> self . _transaction = transaction <EOL> def objectStore ( self , name ) : <EOL> return ObjectStore ( self . _transaction . objectStore ( name ) ) <EOL> class ObjectStore : <EOL> def __init__ ( self , objectStore ) : <EOL> self . _objectStore = objectStore <EOL> self . _data = [ ] <EOL> def clear ( self , onsuccess = None , onerror = None ) : <EOL> _result = self . _objectStore . clear ( ) <EOL> if onsuccess is not None : <EOL> _result . onsuccess = onsuccess <EOL> if onerror is not None : <EOL> _result . onerror = onerror <EOL> def _helper ( self , func , object , onsuccess = None , onerror = None ) : <EOL> _result = func ( object ) <EOL> if onsuccess is not None : <EOL> _result . onsuccess = onsuccess <EOL> if onerror is not None : <EOL> _result . onerror = onerror <EOL> def put ( self , obj , key = None , onsuccess = None , onerror = None ) : <EOL> _r = self . _objectStore . put ( obj , key ) <EOL> _r . onsuccess = onsuccess <EOL> _r . onerror = onerror <EOL> def add ( self , obj , key , onsuccess = None , onerror = None ) : <EOL> _r = self . _objectStore . add ( obj , key ) <EOL> _r . onsuccess = onsuccess <EOL> _r . onerror = onerror <EOL> def delete ( self , index , onsuccess = None , onerror = None ) : <EOL> self . _helper ( self . _objectStore . delete , index , onsuccess , onerror ) <EOL> def query ( self , * args ) : <EOL> self . _data = [ ] <EOL> def onsuccess ( event ) : <EOL> cursor = event . target . result <EOL> if cursor is not None : <EOL> self . _data . append ( cursor . value ) <EOL> getattr ( cursor , "<STR_LIT>" ) ( ) <EOL> self . _objectStore . openCursor ( args ) . onsuccess = onsuccess <EOL> def fetchall ( self ) : <EOL> yield self . _data <EOL> def get ( self , key , onsuccess = None , onerror = None ) : <EOL> self . _helper ( self . _objectStore . get , key , onsuccess , onerror ) </s>
