<s> from twisted . internet import error as TxErrors <EOL> import couchbase . _libcouchbase as LCB <EOL> from couchbase . _libcouchbase import ( <EOL> Event , TimerEvent , IOEvent , <EOL> LCB_READ_EVENT , LCB_WRITE_EVENT , LCB_RW_EVENT , <EOL> PYCBC_EVSTATE_ACTIVE , <EOL> PYCBC_EVACTION_WATCH , <EOL> PYCBC_EVACTION_UNWATCH , <EOL> PYCBC_EVACTION_CLEANUP <EOL> ) <EOL> class TxIOEvent ( IOEvent ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ ] <EOL> def __init__ ( self ) : <EOL> super ( TxIOEvent , self ) . __init__ ( ) <EOL> def doRead ( self ) : <EOL> self . ready_r ( ) <EOL> def doWrite ( self ) : <EOL> self . ready_w ( ) <EOL> def connectionLost ( self , reason ) : <EOL> if self . state == PYCBC_EVSTATE_ACTIVE : <EOL> self . ready_w ( ) <EOL> def logPrefix ( self ) : <EOL> return "<STR_LIT>" <EOL> class TxTimer ( TimerEvent ) : <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self ) : <EOL> super ( TxTimer , self ) . __init__ ( ) <EOL> self . lcb_active = False <EOL> self . _txev = None <EOL> def _timer_wrap ( self ) : <EOL> if not self . lcb_active : <EOL> return <EOL> self . lcb_active = False <EOL> self . ready ( <NUM_LIT:0> ) <EOL> def schedule ( self , usecs , reactor ) : <EOL> nsecs = usecs / <NUM_LIT> <EOL> if not self . _txev or not self . _txev . active ( ) : <EOL> self . _txev = reactor . callLater ( nsecs , self . _timer_wrap ) <EOL> else : <EOL> self . _txev . reset ( nsecs ) <EOL> self . lcb_active = True <EOL> def cancel ( self ) : <EOL> self . lcb_active = False <EOL> def cleanup ( self ) : <EOL> if not self . _txev : <EOL> return <EOL> try : <EOL> self . _txev . cancel ( ) <EOL> except ( TxErrors . AlreadyCalled , TxErrors . AlreadyCancelled ) : <EOL> pass <EOL> self . _txev = None <EOL> class v0Iops ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , reactor , is_sync = False ) : <EOL> self . reactor = reactor <EOL> self . is_sync = is_sync <EOL> self . _stop = False <EOL> def update_event ( self , event , action , flags ) : <EOL> """<STR_LIT>""" <EOL> if action == PYCBC_EVACTION_UNWATCH : <EOL> if event . flags & LCB_READ_EVENT : <EOL> self . reactor . removeReader ( event ) <EOL> if event . flags & LCB_WRITE_EVENT : <EOL> self . reactor . removeWriter ( event ) <EOL> elif action == PYCBC_EVACTION_WATCH : <EOL> if flags & LCB_READ_EVENT : <EOL> self . reactor . addReader ( event ) <EOL> if flags & LCB_WRITE_EVENT : <EOL> self . reactor . addWriter ( event ) <EOL> if flags & LCB_READ_EVENT == <NUM_LIT:0> : <EOL> self . reactor . removeReader ( event ) <EOL> if flags & LCB_WRITE_EVENT == <NUM_LIT:0> : <EOL> self . reactor . removeWriter ( event ) <EOL> def update_timer ( self , timer , action , usecs ) : <EOL> """<STR_LIT>""" <EOL> if action == PYCBC_EVACTION_WATCH : <EOL> timer . schedule ( usecs , self . reactor ) <EOL> elif action == PYCBC_EVACTION_UNWATCH : <EOL> timer . cancel ( ) <EOL> elif action == PYCBC_EVACTION_CLEANUP : <EOL> timer . cleanup ( ) <EOL> def io_event_factory ( self ) : <EOL> return TxIOEvent ( ) <EOL> def timer_event_factory ( self ) : <EOL> return TxTimer ( ) <EOL> def start_watching ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . is_sync : <EOL> return <EOL> self . _stop = False <EOL> while not self . _stop : <EOL> self . reactor . doIteration ( <NUM_LIT:0> ) <EOL> def stop_watching ( self ) : <EOL> self . _stop = True </s>
