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(): from twisted.internet.app import Application factory = Factory() factory.protocol = Echo app = Application("echo") app.listenTCP(8000,factory) app.run(save=0)
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(): 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 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)
# 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") makeAccount("bob", "222-303-8485", "franz", "bobpass") app.listenTCP(portno, BrokerFactory(AuthRoot(auth))) app.run()
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") makeAccount("bob", "222-303-8485", "franz", "bobpass") app.listenTCP(portno, BrokerFactory(AuthRoot(auth))) from twisted.web.server import Site from twisted.web.static import File from twisted.web.script import ResourceScript f = File('.') f.processors = { '.rpy': ResourceScript } app.listenTCP(8080, Site(f)) app.run()
# 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()
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)
def main(): from twisted.internet.app import Application app = Application("xmlrpc") r = Example() app.listenTCP(7080, server.Site(r)) return app
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()
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")