<s> from twisted . internet . protocol import Factory <EOL> from twisted . internet import reactor <EOL> from twisted . protocols import basic <EOL> from xcaplib . green import XCAPClient <EOL> from eventlet . twistedutil import deferToGreenThread <EOL> from eventlet . twistedutil import join_reactor <EOL> class LineOnlyReceiver ( basic . LineOnlyReceiver ) : <EOL> def lineReceived ( self , line ) : <EOL> print '<STR_LIT>' % line <EOL> if not line : <EOL> return <EOL> app , context , node = ( line + '<STR_LIT:U+0020>' ) . split ( '<STR_LIT:U+0020>' , <NUM_LIT:3> ) <EOL> context = { '<STR_LIT:u>' : '<STR_LIT>' , '<STR_LIT:g>' : '<STR_LIT>' } . get ( context , context ) <EOL> d = deferToGreenThread ( client . _get , app , node , globaltree = context == '<STR_LIT>' ) <EOL> def callback ( result ) : <EOL> self . transport . write ( str ( result ) ) <EOL> def errback ( error ) : <EOL> self . transport . write ( error . getTraceback ( ) ) <EOL> d . addCallback ( callback ) <EOL> d . addErrback ( errback ) <EOL> class MyFactory ( Factory ) : <EOL> protocol = LineOnlyReceiver <EOL> client = XCAPClient ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> reactor . listenTCP ( <NUM_LIT> , MyFactory ( ) ) <EOL> reactor . run ( ) </s>
