<s> """<STR_LIT>""" <EOL> class AsyncStateMachine : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _clear ( ) <EOL> def _clear ( self ) : <EOL> self . handshaker = None <EOL> self . closer = None <EOL> self . reader = None <EOL> self . writer = None <EOL> self . result = None <EOL> def _checkAssert ( self , maxActive = <NUM_LIT:1> ) : <EOL> activeOps = <NUM_LIT:0> <EOL> if self . handshaker : <EOL> activeOps += <NUM_LIT:1> <EOL> if self . closer : <EOL> activeOps += <NUM_LIT:1> <EOL> if self . reader : <EOL> activeOps += <NUM_LIT:1> <EOL> if self . writer : <EOL> activeOps += <NUM_LIT:1> <EOL> if self . result == None : <EOL> if activeOps != <NUM_LIT:0> : <EOL> raise AssertionError ( ) <EOL> elif self . result in ( <NUM_LIT:0> , <NUM_LIT:1> ) : <EOL> if activeOps != <NUM_LIT:1> : <EOL> raise AssertionError ( ) <EOL> else : <EOL> raise AssertionError ( ) <EOL> if activeOps > maxActive : <EOL> raise AssertionError ( ) <EOL> def wantsReadEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . result != None : <EOL> return self . result == <NUM_LIT:0> <EOL> return None <EOL> def wantsWriteEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . result != None : <EOL> return self . result == <NUM_LIT:1> <EOL> return None <EOL> def outConnectEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def outCloseEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def outReadEvent ( self , readBuffer ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def outWriteEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def inReadEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _checkAssert ( ) <EOL> if self . handshaker : <EOL> self . _doHandshakeOp ( ) <EOL> elif self . closer : <EOL> self . _doCloseOp ( ) <EOL> elif self . reader : <EOL> self . _doReadOp ( ) <EOL> elif self . writer : <EOL> self . _doWriteOp ( ) <EOL> else : <EOL> self . reader = self . tlsConnection . readAsync ( <NUM_LIT> ) <EOL> self . _doReadOp ( ) <EOL> except : <EOL> self . _clear ( ) <EOL> raise <EOL> def inWriteEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _checkAssert ( ) <EOL> if self . handshaker : <EOL> self . _doHandshakeOp ( ) <EOL> elif self . closer : <EOL> self . _doCloseOp ( ) <EOL> elif self . reader : <EOL> self . _doReadOp ( ) <EOL> elif self . writer : <EOL> self . _doWriteOp ( ) <EOL> else : <EOL> self . outWriteEvent ( ) <EOL> except : <EOL> self . _clear ( ) <EOL> raise <EOL> def _doHandshakeOp ( self ) : <EOL> try : <EOL> self . result = self . handshaker . next ( ) <EOL> except StopIteration : <EOL> self . handshaker = None <EOL> self . result = None <EOL> self . outConnectEvent ( ) <EOL> def _doCloseOp ( self ) : <EOL> try : <EOL> self . result = self . closer . next ( ) <EOL> except StopIteration : <EOL> self . closer = None <EOL> self . result = None <EOL> self . outCloseEvent ( ) <EOL> def _doReadOp ( self ) : <EOL> self . result = self . reader . next ( ) <EOL> if not self . result in ( <NUM_LIT:0> , <NUM_LIT:1> ) : <EOL> readBuffer = self . result <EOL> self . reader = None <EOL> self . result = None <EOL> self . outReadEvent ( readBuffer ) <EOL> def _doWriteOp ( self ) : <EOL> try : <EOL> self . result = self . writer . next ( ) <EOL> except StopIteration : <EOL> self . writer = None <EOL> self . result = None <EOL> def setHandshakeOp ( self , handshaker ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _checkAssert ( <NUM_LIT:0> ) <EOL> self . handshaker = handshaker <EOL> self . _doHandshakeOp ( ) <EOL> except : <EOL> self . _clear ( ) <EOL> raise <EOL> def setServerHandshakeOp ( self , ** args ) : <EOL> """<STR_LIT>""" <EOL> handshaker = self . tlsConnection . handshakeServerAsync ( ** args ) <EOL> self . setHandshakeOp ( handshaker ) <EOL> def setCloseOp ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _checkAssert ( <NUM_LIT:0> ) <EOL> self . closer = self . tlsConnection . closeAsync ( ) <EOL> self . _doCloseOp ( ) <EOL> except : <EOL> self . _clear ( ) <EOL> raise <EOL> def setWriteOp ( self , writeBuffer ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _checkAssert ( <NUM_LIT:0> ) <EOL> self . writer = self . tlsConnection . writeAsync ( writeBuffer ) <EOL> self . _doWriteOp ( ) <EOL> except : <EOL> self . _clear ( ) <EOL> raise </s>
