def getPorts(app, config): ports = [] if config.telnet: from twisted.protocols import telnet factory = telnet.ShellFactory() ports.append((int(config.telnet), factory)) try: root = config.root config.root.indexName = config.index except AttributeError: # This really ought to be web.Admin or something root = test.Test() site = server.Site(root) if config.personal: import pwd, os pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \ = pwd.getpwuid(os.getuid()) ports.append((os.path.join(pw_dir, distrib.UserDirectory.userSocketName), pb.BrokerFactory(distrib.ResourcePublisher(site)))) else: ports.append((int(config.port), site)) return ports
def getPorts(app, config): svc = service.Service("twisted.words", app) bkr = pb.BrokerFactory(pb.AuthRoot(app)) irc = ircservice.IRCGateway(svc) adm = server.Site(webwords.WordsGadget(svc)) return [(int(config.port), bkr), (int(config.irc), irc), (int(config.web), adm)]
def getPorts(app, config): svc = service.Service(application=app) p = svc.createPerspective(config.user) p.makeIdentity(config.password) try: portno = config.portno except AttributeError: portno = pb.portno return [(portno, pb.BrokerFactory(pb.AuthRoot(app)))]
def getPorts(app, config): if not config.map: raise Exception("Please give a map name") print 'Loading %s...' % config.map sys.stdout.flush() rdf = reality._default = load(open(config.map, 'rb')) rdf.setApplication(app) # Should this be considered 'Legacy'? rdf.addPlayersAsIdentities() print 'Loaded.' app.addDelayed(rdf) spigot = plumbing.Spigot(rdf) site = server.Site(plumbing.Web(rdf)) bf = pb.BrokerFactory(pb.AuthRoot(app)) return [(8080, site), (4040, spigot), (8787, bf)]
def makeService(config): s = service.MultiService() if config['root']: root = config['root'] if config['indexes']: config['root'].indexNames = config['indexes'] else: # This really ought to be web.Admin or something root = demo.Test() if isinstance(root, static.File): root.registry.setComponent(interfaces.IServiceCollection, s) if config['logfile']: site = server.Site(root, logPath=config['logfile']) else: site = server.Site(root) site.displayTracebacks = not config["notracebacks"] if config['personal']: import pwd, os pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \ = pwd.getpwuid(os.getuid()) i = internet.UNIXServer( os.path.join(pw_dir, distrib.UserDirectory.userSocketName), pb.BrokerFactory(distrib.ResourcePublisher(site))) i.setServiceParent(s) else: if config['https']: from twisted.internet.ssl import DefaultOpenSSLContextFactory i = internet.SSLServer( int(config['https']), site, DefaultOpenSSLContextFactory(config['privkey'], config['certificate'])) i.setServiceParent(s) strports.service(config['port'], site).setServiceParent(s) flashport = config.get('flashconduit', None) if flashport: from twisted.web.woven.flashconduit import FlashConduitFactory i = internet.TCPServer(int(flashport), FlashConduitFactory(site)) i.setServiceParent(s) return s
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 updateApplication(app, config): profileTable=McFoo.score.ProfileTable() filler=McFoo.suggest.Suggestions(config.songdirs, profileTable) playqueue = McFoo.playqueue.PlayQueue(filler.get) volume = McFoo.volume.VolumeControl() auth = DefaultAuthorizer() auth.setApplication(app) dj=McFoo.dj.Dj(app, auth, playqueue, volume, profileTable) perspective=dj.getPerspectiveNamed("guest") perspective.setService(dj) perspective.makeIdentity("guest") portno = config.port prot = pb.BrokerFactory(pb.AuthRoot(auth)) app.listenTCP(portno, prot) SaveService("save", app, auth)
def connectedServerAndClient(): """Returns a 3-tuple: (client, server, pump) """ c = pb.Broker() app = main.Application("pb-test") ident = passport.Identity("guest", app) ident.setPassword("guest") svc = DummyService("test", app) ident.addKeyForPerspective(svc.getPerspectiveNamed("any")) app.authorizer.addIdentity(ident) svr = pb.BrokerFactory(pb.AuthRoot(app)) 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: while pump.pump(): pass return c, s, pump
self.restart = reactor.callLater(RESTART_DELAY, self._start) def _ping(self): self.dog = reactor.callLater(DOG_DELAY, self._start) self.ball += 1 print('THROW', self.ball, end=' ') dfr = self.remote.callRemote('Pong', self.ball) dfr.addCallbacks(self._pong, self._remoteFail) def _pong(self, ball): self.dog.cancel() print('CATCH', ball) self.ball = ball self.ping = reactor.callLater(DELAY, self._ping) class Ponger(pb.Root): def remote_Pong(self, ball): print('CATCH', ball, end=' ') ball += 1 print('THROW', ball) return ball if len(sys.argv) > 1: Pinger(sys.argv[1]) else: reactor.listenTCP(PORT, pb.BrokerFactory(Ponger())) reactor.run()
#! /usr/bin/python from twisted.spread import pb import twisted.internet.app class ServerObject(pb.Root): def remote_add(self, one, two): answer = one + two print "returning result:", answer return answer def remote_subtract(self, one, two): return one - two app = twisted.internet.app.Application("server1") app.listenTCP(8800, pb.BrokerFactory(ServerObject())) app.run(save=0)
def startListening(self): """Start a server, and wait for a connection attempt.""" print 'No server found. Listening for connections' reactor.listenTCP(self.game.port, pb.BrokerFactory(self))
# Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from twisted.spread import pb from twisted.internet import app class SimplePerspective(pb.Perspective): def perspective_echo(self, text): print 'echoing', text return text class SimpleService(pb.Service): def getPerspectiveNamed(self, name): p = SimplePerspective(name) p.setService(self) return p if __name__ == '__main__': import pbecho appl = app.Application("pbecho") pbecho.SimpleService( "pbecho", appl).getPerspectiveNamed("guest").makeIdentity("guest") appl.listenTCP(pb.portno, pb.BrokerFactory(pb.AuthRoot(appl))) appl.save("start")
# Twisted, the Framework of Your Internet # Copyright (C) 2001 Matthew W. Lefkowitz # # This library is free software; you can redistribute it and/or # modify it under the terms of version 2.1 of the GNU Lesser General Public # License as published by the Free Software Foundation. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from twisted.spread import pb from twisted.internet import app class Echoer(pb.Root): def remote_echo(self, st): print 'echoing:', st return st if __name__ == '__main__': appl = app.Application("pbsimple") appl.listenTCP(8789, pb.BrokerFactory(Echoer())) appl.run()