<s> """<STR_LIT>""" <EOL> from twisted . internet import stdio , reactor <EOL> from twisted . protocols import basic <EOL> from twisted . web import client <EOL> class WebCheckerCommandProtocol ( basic . LineReceiver ) : <EOL> delimiter = '<STR_LIT:\n>' <EOL> def connectionMade ( self ) : <EOL> self . sendLine ( "<STR_LIT>" ) <EOL> def lineReceived ( self , line ) : <EOL> if not line : return <EOL> commandParts = line . split ( ) <EOL> command = commandParts [ <NUM_LIT:0> ] . lower ( ) <EOL> args = commandParts [ <NUM_LIT:1> : ] <EOL> try : <EOL> method = getattr ( self , '<STR_LIT>' + command ) <EOL> except AttributeError , e : <EOL> self . sendLine ( '<STR_LIT>' ) <EOL> else : <EOL> try : <EOL> method ( * args ) <EOL> except Exception , e : <EOL> self . sendLine ( '<STR_LIT>' + str ( e ) ) <EOL> def do_help ( self , command = None ) : <EOL> """<STR_LIT>""" <EOL> if command : <EOL> self . sendLine ( getattr ( self , '<STR_LIT>' + command ) . __doc__ ) <EOL> else : <EOL> commands = [ cmd [ <NUM_LIT:3> : ] for cmd in dir ( self ) if cmd . startswith ( '<STR_LIT>' ) ] <EOL> self . sendLine ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( commands ) ) <EOL> def do_quit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . sendLine ( '<STR_LIT>' ) <EOL> self . transport . loseConnection ( ) <EOL> def do_check ( self , url ) : <EOL> """<STR_LIT>""" <EOL> client . getPage ( url ) . addCallback ( <EOL> self . __checkSuccess ) . addErrback ( <EOL> self . __checkFailure ) <EOL> def __checkSuccess ( self , pageData ) : <EOL> self . sendLine ( "<STR_LIT>" % len ( pageData ) ) <EOL> def __checkFailure ( self , failure ) : <EOL> self . sendLine ( "<STR_LIT>" + failure . getErrorMessage ( ) ) <EOL> def connectionLost ( self , reason ) : <EOL> reactor . stop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> stdio . StandardIO ( WebCheckerCommandProtocol ( ) ) <EOL> reactor . run ( ) </s>
