<s> "<STR_LIT>" <EOL> from thespian . actors import ActorSystemMessage <EOL> class Thespian_StatusReq ( ActorSystemMessage ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> class _Common_StatusResp ( ActorSystemMessage ) : <EOL> def __init__ ( self ) : <EOL> self . pendingMessages = [ ] <EOL> self . pendingWakeups = { } <EOL> self . receivedMessages = [ ] <EOL> self . childActors = [ ] <EOL> self . governer = None <EOL> self . _numSent = <NUM_LIT:0> <EOL> self . _numSendFailures = <NUM_LIT:0> <EOL> self . _numReceived = <NUM_LIT:0> <EOL> self . miscKeyVals = { } <EOL> self . _pendingAddrCnts = { } <EOL> def addChild ( self , childAddress ) : self . childActors . append ( childAddress ) <EOL> def addPendingMessage ( self , fromActor , toActor , msgstr ) : <EOL> self . pendingMessages . append ( ( fromActor , toActor , str ( msgstr ) ) ) <EOL> def addReceivedMessage ( self , fromActor , toActor , msgstr ) : <EOL> self . receivedMessages . append ( ( fromActor , toActor , str ( msgstr ) ) ) <EOL> def addWakeups ( self , wakeupdict ) : <EOL> self . pendingWakeups . update ( wakeupdict ) <EOL> def addSent ( self , count ) : self . _numSent += count <EOL> def addSendFailures ( self , count ) : self . _numSendFailures += count <EOL> def addReceived ( self , count ) : self . _numReceived += count <EOL> def addKeyVal ( self , key , value ) : self . miscKeyVals [ key ] = value <EOL> def addTXPendingAddressCount ( self , address , count ) : <EOL> self . _pendingAddrCnts [ address ] = count + self . _pendingAddrCnts . get ( address , <NUM_LIT:0> ) <EOL> class Thespian_SystemStatus ( _Common_StatusResp ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , address , conventionLeader = None , capabilities = None , inShutdown = False ) : <EOL> super ( Thespian_SystemStatus , self ) . __init__ ( ) <EOL> self . adminAddress = address <EOL> self . conventionLeader = conventionLeader <EOL> self . capabilities = { } if capabilities is None else capabilities <EOL> self . conventionRegisterTime = None <EOL> self . conventionAttendees = [ ] <EOL> self . deadLetterHandler = None <EOL> self . deadLetterAddresses = [ ] <EOL> self . notifyAddresses = [ ] <EOL> self . globalActors = { } <EOL> self . inShutdown = inShutdown <EOL> self . sourceAuthority = None <EOL> self . loadedSources = [ ] <EOL> def addDeadLetter ( self , deadAddress ) : self . deadLetterAddresses . append ( deadAddress ) <EOL> def setConventionLeaderAddress ( self , addr ) : self . conventionLeader = addr <EOL> def addConventioneer ( self , memberAddress , validTime ) : <EOL> self . conventionAttendees . append ( ( memberAddress , validTime ) ) <EOL> def setConventionRegisterTime ( self , time ) : self . conventionRegisterTime = time <EOL> def addGlobalActor ( self , name , address ) : self . globalActors [ name ] = address <EOL> def setDeadLetterHandler ( self , address ) : self . deadLetterHandler = address <EOL> def setNotifyHandlers ( self , addresses ) : self . notifyAddresses = addresses <EOL> def setLoadedSources ( self , sourceHashes ) : self . loadedSources = sourceHashes <EOL> class Thespian_ActorStatus ( _Common_StatusResp ) : <EOL> def __init__ ( self , address , actorClass , adminAddress , parentAddress = None , sourceHash = None ) : <EOL> super ( Thespian_ActorStatus , self ) . __init__ ( ) <EOL> self . actorAddress = address <EOL> self . actorClass = str ( actorClass ) <EOL> self . adminAddress = adminAddress <EOL> self . parentAddress = parentAddress <EOL> self . sourceHash = sourceHash <EOL> def _common_formatStatus ( tofd , response , childActorTag , showAddress = str ) : <EOL> tofd . write ( '<STR_LIT>' % ( childActorTag , len ( response . childActors ) ) ) <EOL> for A in response . childActors : <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( A ) ) ) <EOL> if response . governer : <EOL> tofd . write ( '<STR_LIT>' % ( str ( response . governer ) ) ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . pendingMessages ) ) <EOL> for F , T , M in response . pendingMessages : <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( F ) , showAddress ( T ) , M ) ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . receivedMessages ) ) <EOL> for F , T , M in response . receivedMessages : <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( T ) , showAddress ( F ) , M ) ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . pendingWakeups ) ) <EOL> import datetime <EOL> for W in response . pendingWakeups : <EOL> tofd . write ( '<STR_LIT>' % ( str ( W ) , <EOL> ( '<STR_LIT>' % ( W - datetime . datetime . now ( ) ) if isinstance ( W , datetime . datetime ) <EOL> else '<STR_LIT>' ) ) ) <EOL> tofd . write ( '<STR_LIT>' % ( len ( response . _pendingAddrCnts ) ) ) <EOL> for A in response . _pendingAddrCnts : <EOL> tofd . write ( '<STR_LIT>' % ( A , response . _pendingAddrCnts [ A ] ) ) <EOL> if response . miscKeyVals : <EOL> miscKeys = list ( response . miscKeyVals . keys ( ) ) <EOL> miscKeys . sort ( ) <EOL> maxValLen = min ( <NUM_LIT> , max ( map ( len , map ( str , response . miscKeyVals . values ( ) ) ) ) ) <EOL> for K in miscKeys : <EOL> tofd . write ( '<STR_LIT>' % maxValLen % ( str ( response . miscKeyVals [ K ] ) , K ) ) <EOL> def formatStatus ( response , showAddress = str , tofd = None ) : <EOL> if tofd is None : <EOL> import sys <EOL> tofd = sys . stdout <EOL> if isinstance ( response , Thespian_SystemStatus ) : <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( response . adminAddress ) , <EOL> '<STR_LIT>' if response . inShutdown else '<STR_LIT>' ) ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . capabilities ) ) <EOL> for k in response . capabilities : <EOL> tofd . write ( '<STR_LIT>' % ( k , response . capabilities [ k ] ) ) <EOL> if response . conventionLeader : <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( response . conventionLeader ) ) ) <EOL> if response . conventionRegisterTime : <EOL> tofd . write ( '<STR_LIT>' % ( str ( response . conventionRegisterTime ) ) ) <EOL> elif response . conventionAttendees : <EOL> tofd . write ( '<STR_LIT>' ) <EOL> if response . notifyAddresses : <EOL> tofd . write ( '<STR_LIT>' % len ( response . notifyAddresses ) ) <EOL> for each in response . notifyAddresses : <EOL> tofd . write ( '<STR_LIT:U+0020>' + showAddress ( each ) + '<STR_LIT:\n>' ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . conventionAttendees ) ) <EOL> for addr , validtime in response . conventionAttendees : <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( addr ) , str ( validtime ) ) ) <EOL> _common_formatStatus ( tofd , response , '<STR_LIT>' , showAddress ) <EOL> if response . deadLetterHandler : <EOL> tofd . write ( '<STR_LIT>' % showAddress ( response . deadLetterHandler ) ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . deadLetterAddresses ) ) <EOL> for A in response . deadLetterAddresses : <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( A ) ) ) <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( response . sourceAuthority ) ) ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . loadedSources ) ) <EOL> for S in response . loadedSources : <EOL> tofd . write ( '<STR_LIT>' % ( str ( S ) ) ) <EOL> tofd . write ( '<STR_LIT>' % len ( response . globalActors ) ) <EOL> for N in response . globalActors : <EOL> tofd . write ( '<STR_LIT>' % ( N , showAddress ( response . globalActors [ N ] ) ) ) <EOL> elif isinstance ( response , Thespian_ActorStatus ) : <EOL> tofd . write ( '<STR_LIT>' % ( response . actorClass , <EOL> showAddress ( response . actorAddress ) ) ) <EOL> if response . sourceHash : <EOL> tofd . write ( '<STR_LIT>' % ( response . sourceHash ) ) <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( response . adminAddress ) ) ) <EOL> tofd . write ( '<STR_LIT>' % ( showAddress ( response . parentAddress ) ) ) <EOL> _common_formatStatus ( tofd , response , '<STR_LIT>' , showAddress ) <EOL> else : <EOL> tofd . write ( '<STR_LIT>' % ( str ( response ) ) ) </s>
