Exemple #1
0
 def testListenUnlistenUNIX(self):
     a = app.Application("foo")
     f = protocol.ServerFactory()
     a.listenUNIX("xxx", f)
     self.assertEquals(len(a.unixPorts), 1)
     a.unlistenUNIX("xxx")
     self.assertEquals(len(a.unixPorts), 0)
Exemple #2
0
    def testIllegalUnlistens(self):
        a = app.Application("foo")

        self.assertRaises(error.NotListeningError, a.unlistenTCP, 1010)
        self.assertRaises(error.NotListeningError, a.unlistenUNIX, '1010')
        self.assertRaises(error.NotListeningError, a.unlistenSSL, 1010)
        self.assertRaises(error.NotListeningError, a.unlistenUDP, 1010)
 def testWords(self):
     a = app.Application("testwords")
     s = service.Service('twisted.words',a)
     s.createParticipant("glyph")
     s.createParticipant("sean")
     glyph = s.getPerspectiveNamed("glyph")
     sean = s.getPerspectiveNamed("sean")
     glyph.addContact("sean")
Exemple #4
0
 def setUp(self):
     self.app = app.Application("guard")
     ident = passport.Identity("bob", self.app)
     ident.setPassword("joe")
     self.app.authorizer.addIdentity(ident)
     self.svc = passport.Service("simple", self.app)
     self.psp = passport.Perspective('jethro', ident.name)
     self.svc.addPerspective(self.psp)
     ident.addKeyForPerspective(self.psp)
Exemple #5
0
 def testListenUnlistenUDP(self):
     a = app.Application("foo")
     f = protocol.DatagramProtocol()
     a.listenUDP(9999, f)
     a.listenUDP(9998, f)
     self.assertEquals(len(a.udpPorts), 2)
     a.unlistenUDP(9999)
     self.assertEquals(len(a.udpPorts), 1)
     a.listenUDP(9999, f, interface='127.0.0.1')
     self.assertEquals(len(a.udpPorts), 2)
     a.unlistenUDP(9999, '127.0.0.1')
     self.assertEquals(len(a.udpPorts), 1)
     a.unlistenUDP(9998)
     self.assertEquals(len(a.udpPorts), 0)
Exemple #6
0
 def testListenUnlistenTCP(self):
     a = app.Application("foo")
     f = protocol.ServerFactory()
     a.listenTCP(9999, f)
     a.listenTCP(9998, f)
     self.assertEquals(len(a.tcpPorts), 2)
     a.unlistenTCP(9999)
     self.assertEquals(len(a.tcpPorts), 1)
     a.listenTCP(9999, f, interface='127.0.0.1')
     self.assertEquals(len(a.tcpPorts), 2)
     a.unlistenTCP(9999, '127.0.0.1')
     self.assertEquals(len(a.tcpPorts), 1)
     a.unlistenTCP(9998)
     self.assertEquals(len(a.tcpPorts), 0)
Exemple #7
0
def main():
    """..."""
    from twisted.spread import pb
    from twisted.application import service
    from twisted.cred.authorizer import DefaultAuthorizer
    from twisted.internet import reactor, app

    evManager = EventManager()
    sharedObjectRegistry = {}

    log = TextLogView(evManager)
    timer = TimerController(evManager, reactor)
    #clientContr = NetworkClientController( evManager, sharedObjectRegistry )
    clientView = NetworkClientView(evManager, sharedObjectRegistry)
    game = Game(evManager)

    #from twisted.spread.jelly import globalSecurity
    #globalSecurity.allowModules( network )

    application = app.Application("myServer")
    auth = DefaultAuthorizer(application)

    #create a service, tell it to generate NetworkClientControllers
    serv = pb.Service("myService", application, auth)
    serv.perspectiveClass = NetworkClientController

    #create a Perspective
    per1 = serv.createPerspective("perspective1")
    per1.PostInit(evManager, sharedObjectRegistry)

    #create an Identity
    iden1 = auth.createIdentity("user1")
    iden1.setPassword("asdf")
    #allow it access to the perspective named perspective1
    iden1.addKeyByString("myService", "perspective1")
    auth.addIdentity(iden1)

    #application.listenTCP(8000, pb.BrokerFactory(clientContr) )
    application.listenTCP(8000, pb.PBServerFactory(pb.AuthRoot(auth)))

    application.run(save=0)
Exemple #8
0
def main():
    # the start and stop stuff will be handled from the freevo script

    logfile = '%s/%s-%s.log' % (config.LOGDIR, appname, os.getuid())
    log.startLogging(open(logfile, 'a'))

    if os.path.isdir(os.path.join(os.environ['FREEVO_PYTHON'], 'www/htdocs')):
        docRoot = os.path.join(os.environ['FREEVO_PYTHON'], 'www/htdocs')
    else:
        docRoot = os.path.join(config.SHARE_DIR, 'htdocs')

    root = static.File(docRoot)
    root.processors = {
        '.rpy': script.ResourceScript,
    }

    child_resources = []
    child_resources.extend(config.VIDEO_ITEMS)
    child_resources.extend(config.AUDIO_ITEMS)
    child_resources.extend(config.IMAGE_ITEMS)
    child_resources.extend([('Recorded TV', config.TV_RECORD_DIR)])
    child_resources.extend([('Webserver Cache', config.WEBSERVER_CACHEDIR)])
    for item in child_resources:
        if isinstance(item, tuple) and len(item) == 2:
            (title, path) = item
            root.putChild(path.replace("/", "_"), static.File(path))

    root.putChild('vhost', vhost.VHostMonsterResource())
    rewriter = rewrite.RewriterResource(root, helpimagesrewrite)
    if (config.DEBUG == 0):
        site = server.Site(rewriter, logPath='/dev/null')
    else:
        site = server.Site(rewriter)

    application = app.Application('web')
    application.listenTCP(config.WEBSERVER_PORT, site)
    application.run(save=0)
Exemple #9
0
 def testRegisterService(self):
     a = app.Application("foo")
     svc = app.ApplicationService("service", a)
     self.assertEquals(a.getServiceNamed("service"), svc)
     self.assertEquals(a, svc.serviceParent)
 def testOldApplication(self):
     from twisted.internet import app as oapp
     application = oapp.Application("HELLO")
     oapp.MultiService("HELLO", application)
     compat.convert(application)
Exemple #11
0
# 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.internet import app
from twisted.web import proxy, server

site = server.Site(proxy.ReverseProxyResource('www.yahoo.com', 80, '/'))
application = app.Application('web-proxy')
application.listenTCP(8080, site)
Exemple #12
0
# 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")
Exemple #13
0
# 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()
Exemple #14
0
from twisted.web import widgets


class EchoDisplay(widgets.Presentation):
    template = """<H1>Welcome to my widget, displaying %%%%echotext%%%%.</h1>
    <p>Here it is: %%%%getEchoPerspective()%%%%</p>"""
    echotext = 'hello web!'

    def getEchoPerspective(self):
        d = defer.Deferred()
        pb.connect(d.callback, d.errback, "localhost", pb.portno, "guest",
                   "guest", "pbecho", "guest", 1)
        d.addCallbacks(self.makeListOf, self.formatTraceback)
        return ['<b>', d, '</b>']

    def makeListOf(self, echoer):
        d = defer.Deferred()
        echoer.echo(self.echotext, pbcallback=d.callback, pberrback=d.errback)
        d.addCallbacks(widgets.listify, self.formatTraceback)
        return [d]


if __name__ == "__main__":
    from twisted.web import server
    from twisted.internet import app
    a = app.Application("pbweb")
    gdgt = widgets.Gadget()
    gdgt.widgets['index'] = EchoDisplay()
    a.listenTCP(8080, server.Site(gdgt))
    a.run()