def main(): from twisted.internet.app import Application from twisted.web import server app = Application("xmlrpc") r = xmlrpc.PB(Echoer()) app.listenTCP(7080, server.Site(r)) app.run(0)
def main(options=None): from twisted.runner import inetdtap as tap # Parse options, read various config files if not options: options = tap.Options() options.parseOptions() app = Application('tinet') tap.updateApplications(app, options) app.run(save=0)
def test1(): class MaildirTest(MaildirTwisted): def messageReceived(self, filename): print "changed:", filename from twisted.internet.app import Application #from maildir import MaildirTest # note that MaildirTest is really __main__.MaildirTest, which makes # maildir-test-shutdown.tap unusable app = Application("maildir-test") # add the service to the app m = MaildirTest("maildir", app, basedir="ddir") print "watching ddir/new/" app.run() print "done"
def setup(): # Setup state, app, boxes, trainers and account state.createWorkers() proxyListeners = [] app = Application("SpambayesIMAPServer") spam_box = SpambayesMailbox("Spam", 0, options["Storage", "spam_cache"]) unsure_box = SpambayesMailbox("Unsure", 1, options["Storage", "unknown_cache"]) ham_train_box = SpambayesMailbox("TrainAsHam", 2, options["Storage", "ham_cache"]) inbox = SpambayesInbox(3) spam_trainer = Trainer(spam_box, True) ham_trainer = Trainer(ham_train_box, False) spam_box.addListener(spam_trainer) ham_train_box.addListener(ham_trainer) user_account = SpambayesAccount(options["imapserver", "username"], ham_train_box, spam_box, unsure_box, inbox) # add IMAP4 server f = OneParameterFactory() f.protocol = SpambayesIMAPServer f.parameter = user_account state.imap_port = options["imapserver", "port"] app.listenTCP(state.imap_port, f) # add POP3 proxy for (server, serverPort), proxyPort in zip(state.servers, state.proxyPorts): listener = MyBayesProxyListener(server, serverPort, proxyPort, spam_box, unsure_box) proxyListeners.append(listener) state.buildServerStrings() # add web interface httpServer = UserInterfaceServer(state.uiPort) serverUI = ServerUserInterface(state, _recreateState) httpServer.register(serverUI) return app
def main(): from twisted.internet.app import Application factory = Factory() factory.protocol = Echo app = Application("echo") app.listenTCP(8000,factory) app.run(save=0)
def main(): global DEBUG if not (os.path.exists(tmppath) and os.path.isdir(tmppath)): os.mkdir(tmppath) os.chdir(tmppath) app = Application("CommDetectServer") if len(sys.argv) >= 2 and sys.argv[1] == "debug": es = CommDetectServer(True) import commdetectcore commdetectcore.DEBUG = True else: es = CommDetectServer() _debug_('main: DEBUG=%s' % DEBUG, 0) if (DEBUG == 0): app.listenTCP(config.COMMDETECTSERVER_PORT, server.Site(es, logPath='/dev/null')) else: app.listenTCP(config.COMMDETECTSERVER_PORT, server.Site(es)) app.run(save=0)
def setUp(self): self.refs = [] # these will be .broker.transport.loseConnection()'ed c = pb.Broker() auth = authorizer.DefaultAuthorizer() appl = Application("pb-test") auth.setServiceCollection(appl) ident = identity.Identity("guest", authorizer=auth) ident.setPassword("guest") svc = DummyService("test", appl, authorizer=auth) ident.addKeyForPerspective(svc.getPerspectiveNamed("any")) auth.addIdentity(ident) ident2 = identity.Identity("foo", authorizer=auth) ident2.setPassword("foo") ident2.addKeyForPerspective(svc.getPerspectiveNamed("foo")) auth.addIdentity(ident2) self.svr = pb.BrokerFactory(pb.AuthRoot(auth)) self.port = reactor.listenTCP(0, self.svr, interface="127.0.0.1") self.portno = self.port.getHost().port
def main(): global DEBUG #check for /tmp/encodingserver and if it doesn't exist make it if not (os.path.exists(tmppath) and os.path.isdir(tmppath)): os.mkdir(tmppath) #chdir to /tmp/encodingserver os.chdir(tmppath) app = Application("EncodingServer") if len(sys.argv) >= 2 and sys.argv[1] == "debug": es = EncodingServer(True) import encodingcore encodingcore.DEBUG = True else: es = EncodingServer() _debug_('main: DEBUG=%s' % DEBUG, 0) if (DEBUG == 0): app.listenTCP(config.ENCODINGSERVER_PORT, server.Site(es, logPath='/dev/null')) else: app.listenTCP(config.ENCODINGSERVER_PORT, server.Site(es)) app.run(save=0)
def connectedServerAndClient(): """Returns a 3-tuple: (client, server, pump) """ c = pb.Broker() auth = authorizer.DefaultAuthorizer() appl = Application("pb-test") auth.setServiceCollection(appl) ident = identity.Identity("guest", authorizer=auth) ident.setPassword("guest") svc = DummyService("test", appl, authorizer=auth) ident.addKeyForPerspective(svc.getPerspectiveNamed("any")) auth.addIdentity(ident) svr = pb.BrokerFactory(pb.AuthRoot(auth)) s = svr.buildProtocol(('127.0.0.1', )) s.copyTags = {} cio = StringIO() sio = StringIO() c.makeConnection(protocol.FileWrapper(cio)) s.makeConnection(protocol.FileWrapper(sio)) pump = IOPump(c, s, cio, sio) # Challenge-response authentication: pump.flush() return c, s, pump
def main(): from twisted.internet.app import Application from twisted.cred.identity import Identity from twisted.cred.authorizer import DefaultAuthorizer from twisted.manhole.telnet import ShellFactory import flashweb import flash import bots def add_user(ident_name,password="",serv_name=""): persp_name = ident_name persp = svc.createPerspective(persp_name) ident = auth.createIdentity(ident_name) #ident.setPassword(password) ident.addKeyByString("unmovie_service", persp_name) auth.addIdentity(ident) return persp,ident def add_bot(ident_name,password="",params=[]): persp_name = ident_name + "_perspective" part,ident = add_user(ident_name,password) bot = bots.FlashBotChatter() bot.participant = part.attached(bot,ident_name) bot.service = svc bot.name = ident_name bot.setInitialValues(params) return bot appl = Application("unmovie") auth = DefaultAuthorizer(appl) svc = flash.FlashService("unmovie_service",appl,auth) svc.perspectiveClass = flash.FlashMember add_user("axel") add_user('philip') for x in range(0,2): add_user("me_%d" % x) for x in range(USERS_ALLOWED): add_user("you_%d" % x) # nietzsche = add_bot("nietzsche",params=[20,10,20,5,6,30]) # dylan = add_bot("dylan",params=[8,12,40,7,3,20]) # tark = add_bot("tark",params=[12,7,17,6,2,14]) # geisha = add_bot("geisha",params=[7,16,70,6,2,20]) # dogen = add_bot("dogen",params=[7,7,40,6,4,40]) nietzsche = add_bot("nietzsche",params=[20,10,20,5,6,10]) dylan = add_bot("dylan",params=[8,12,40,7,3,8]) tark = add_bot("tark",params=[12,7,17,6,2,6]) geisha = add_bot("geisha",params=[7,16,70,6,2,8]) dogen = add_bot("dogen",params=[7,7,40,6,4,7]) fls = FlashFactory(svc,"******","9998") # sf = ShellFactory() # sf.username = '******' # sf.password = '******' # sf.namespace['server'] = svc # sf.namespace['factory'] = fls # # appl.listenTCP(8780, sf) # adm = server.Site(flashweb.WordsGadget(svc)) appl.listenTCP(9998,fls) # appl.listenTCP(9996,pb.BrokerFactory(pb.AuthRoot(auth))) # appl.listenTCP(9997,adm) appl.run()
from OpenSSL import SSL class ServerContextFactory: def getContext(self): """Create an SSL context. This is a sample implementation that loads a certificate from a file called 'server.pem'.""" ctx = SSL.Context(SSL.SSLv23_METHOD) ctx.use_certificate_file('server.pem') ctx.use_privatekey_file('server.pem') return ctx ### Persistent Application Builder # This builds a .tap file if __name__ == '__main__': import echoserv from twisted.protocols.protocol import Factory from twisted.internet.app import Application from twisted.internet import ssl from echoserv_ssl import ServerContextFactory factory = Factory() factory.protocol = echoserv.Echo app = Application("echo-ssl") app.listenSSL(8000, factory, ServerContextFactory()) app.save("start")
# Import Twisted code from twisted.spread.pb import AuthRoot, BrokerFactory, portno from twisted.internet.app import Application from twisted.cred.authorizer import DefaultAuthorizer # Import our own library import cellphone import metamorph # Create root-level object and authorizer app = Application("Metamorphosis") auth = DefaultAuthorizer(app) # Create our services (inside the App directory) phoneCompany = cellphone.PhoneCompany("cellphone", app, auth) buggyWorld = metamorph.BuggyWorld("metamorph", app, auth) # Create Identities for Joe and Bob. def makeAccount(userName, phoneNumber, bugName, pw): # Create a cell phone for the player, so they can chat. phone = phoneCompany.createPerspective(phoneNumber) # Create a bug for the player, so they can play the game. bug = buggyWorld.createPerspective(bugName) # Create an identity for the player, so they can log in. i = auth.createIdentity(userName) i.setPassword(pw) # add perspectives to identity we created i.addKeyForPerspective(phone) i.addKeyForPerspective(bug) # Finally, commit the identity back to its authorizer. i.save() # Create both Bob's and Joe's accounts. makeAccount("joe", "222-303-8484", "fritz", "joepass")
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from twisted.protocols.protocol import Protocol, Factory from twisted.internet import udp ### Protocol Implementation # This is just about the simplest possible protocol class Echo(Protocol): def dataReceived(self, data): "As soon as any data is received, write it back." self.transport.write(data) ### Persistent Application Builder # This builds a .tap file if __name__ == '__main__': # Since this is persistent, it's important to get the module naming right # (If we just used Echo, then it would be __main__.Echo when it attempted # to unpickle) import echoserv from twisted.internet.app import Application factory = Factory() factory.protocol = echoserv.Echo app = Application("echo") app.listenTCP(8000,factory) app.listenUDP(8000, factory) app.save("start")
return p def __init__(self, botnick, channel): self.nick = botnick self.channel = channel def clientConnectionLost(self, connector, reason): """If we get disconnected, reconnect to server.""" connector.connect() def clientConnectionFailed(self, connector, reason): print "connection failed:", reason reactor.stop() if __name__ == '__main__': from twisted.internet.app import Application import gzz_mail_parser, msglistener mp = gzz_mail_parser.GZZMailParser botf = BotFactory('cvsbot', '#fenfire') mlf = msglistener.MsgListenerFactory(botf, mp) app = Application("cvsbot") app.connectTCP("irc.jyu.fi", 6667, botf) app.listenTCP(9999, mlf) app.run()
to_be_sent = [p for p in patches if p not in patches_sent] has_sent = [] for p in to_be_sent: if send(proj, p, send_notice): has_sent.append(p) f = open(FILE, 'a') for p in has_sent: f.write(p + '\n') return inventory_mtime if __name__ == '__main__': from twisted.internet.app import Application import darcsbot try: channel = sys.argv[1] except: channel = CHANNEL botf = darcsbot.BotFactory(NICK, channel) app = Application("darcsbot") app.connectTCP(IRC_SERVER, 6667, botf) app.run()
def main(): from twisted.internet.app import Application app = Application("xmlrpc") r = Example() app.listenTCP(7080, server.Site(r)) return app
e = TwistedEngine(path=self.path, request=request) e.start() e.setDir(os.path.split(self.path)[0]) e.injectParts() e.runDotWeblibPy() #import pdb; pdb.set_trace() e.runScript() if e.result in (e.SUCCESS, e.EXIT): for k, v in e.response.headers: # @TODO: encapsulate me! request.setHeader(k, v) return e.response.buffer elif e.result == e.FAILURE: # assertion failure: return str(e.error) elif e.result == e.EXCEPTION: request.setHeader('content-type', "text/plain") return e.error #return util.formatFailure(failure.Failure(e.exception)) else: raise Exception("should never get here: unknown Engine.result:%s" % e.result) application = Application("rantserver") fl = static.File('/home/pair/lib/') fl.processors = {'.app': RantResource, '.py': RantResource} application.listenTCP( 8109, Site(fl), ) #interface="65.61.166.185",)
def updateApplication(app, config): factory = AptProxyFactory() aptProxyFactoryConfig(factory) app = Application("AptProxy") app.listenTCP(factory.proxy_port, factory)
"""Thread that does processing on data received from Echo protocol""" def __init__(self, protocol): threading.Thread.__init__(self) self.protocol = protocol def run(self): while 1: # read data from queue data = self.protocol.messagequeue.get() if data != None: # write back data unchanged self.protocol.send(data) else: # connection was closed return ### Persistent Application Builder # This builds a .tap file if __name__ == '__main__': from twisted.internet.app import Application factory = Factory() factory.protocol = Echo app = Application("echo") app.listenTCP(8000, factory) app.run(save=0)
request.finish() def _thread(self, request): e = TwistedEngine(path=self.path, request=request) e.start() e.setDir(os.path.split(self.path)[0]) e.injectParts() e.runDotWeblibPy() #import pdb; pdb.set_trace() e.runScript() if e.result in (e.SUCCESS, e.EXIT): for k,v in e.response.headers: # @TODO: encapsulate me! request.setHeader(k,v) return e.response.buffer elif e.result == e.FAILURE: # assertion failure: return str(e.error) elif e.result == e.EXCEPTION: request.setHeader('content-type', "text/plain") return e.error #return util.formatFailure(failure.Failure(e.exception)) else: raise Exception("should never get here: unknown Engine.result:%s" % e.result) application = Application("rantserver") fl = static.File('/home/pair/lib/') fl.processors = {'.app': RantResource, '.py': RantResource} application.listenTCP(8109, Site(fl), )#interface="65.61.166.185",)
from twisted.protocols.protocol import Protocol, Factory from twisted.internet import udp ### Protocol Implementation # This is just about the simplest possible protocol class Echo(Protocol): def dataReceived(self, data): "As soon as any data is received, write it back." self.transport.write(data) ### Persistent Application Builder # This builds a .tap file if __name__ == '__main__': # Since this is persistent, it's important to get the module naming right # (If we just used Echo, then it would be __main__.Echo when it attempted # to unpickle) import echoserv from twisted.internet.app import Application factory = Factory() factory.protocol = echoserv.Echo app = Application("echo") app.listenTCP(8000, factory) app.listenUDP(8000, factory) app.save("start")