Ejemplo n.º 1
0
class LaterDataTest(RenderHelper):
    def data_later(self, context, data):
        return self.d

    def data_later2(self, context, data):
        return self.d2

    def setUp(self):
        self.d = Deferred()
        self.d2 = Deferred()
        self.r = rend.Page(
            docFactory=loaders.stan(
                html(data=self.data_later)[
                    "Hello ", str, " and " "goodbye ", str, span(data=self.data_later2, render=str)
                ]
            )
        )

    def test_deferredSupport(self):
        req = self.renderIt()
        self.assertEquals(req.v, "")
        self.d.callback("world")
        self.assertEquals(req.v, "<html>Hello world and goodbye world")
        self.d2.callback(".")
        self.assertEquals(req.v, "<html>Hello world and goodbye world.</html>")
Ejemplo n.º 2
0
 def setUp(self):
     self.d = Deferred()
     self.d2 = Deferred()
     self.r = rend.Page(docFactory=loaders.stan(
         tags.html(data=self.data_later)[
             'Hello ', str, ' and '
             'goodbye ',str,
             tags.span(data=self.data_later2, render=str)]))
Ejemplo n.º 3
0
 def setUp(self):
     self.d = Deferred()
     self.d2 = Deferred()
     self.r = rend.Page(
         docFactory=loaders.stan(
             html(data=self)["Hello ", invisible[invisible[invisible[invisible[deferit]]]], deferdot]
         )
     )
Ejemplo n.º 4
0
 def setUp(self):
     self.d = Deferred()
     self.d2 = Deferred()
     self.r = rend.Page(docFactory=loaders.stan(
         html(
             data=self)['Hello ',
                        invisible[invisible[invisible[invisible[deferit]]]],
                        deferdot, ]))
Ejemplo n.º 5
0
 def setUp(self):
     self.d = Deferred()
     self.d2 = Deferred()
     self.r = rend.Page(
         docFactory=loaders.stan(
             html(data=self.data_later)[
                 "Hello ", str, " and " "goodbye ", str, span(data=self.data_later2, render=str)
             ]
         )
     )
Ejemplo n.º 6
0
 def setUp(self):
     self.d = Deferred()
     self.d2 = Deferred()
     self.r = rend.Page(
         docFactory=loaders.stan(
             tags.html(data=self)[
                 'Hello ', tags.invisible[tags.invisible[tags.invisible[tags.invisible[deferit]]]],
                 deferdot,
                 ]
             )
         )
Ejemplo n.º 7
0
 def login(self, ctx, userName, password):
     session = inevow.ISession(ctx)
     
     session.agent = TSWebAgent.createAgent('web', 
                                            config.get('tsserver', 'host'),
                                            config.getInt('tsserver', 'port'))
     session.agent.setAuthData(userName, password)
     
     d = Deferred()
     d.addCallback(self.loginResponse, session)
     
     session.agent.setEventListener(d)
     
     return d
Ejemplo n.º 8
0
    def login(self, ctx, userName, password):
        session = inevow.ISession(ctx)

        session.agent = TSWebAgent.createAgent(
            'web', config.get('tsserver', 'host'),
            config.getInt('tsserver', 'port'))
        session.agent.setAuthData(userName, password)

        d = Deferred()
        d.addCallback(self.loginResponse, session)

        session.agent.setEventListener(d)

        return d
Ejemplo n.º 9
0
def deferflatten(stan, ctx, writer):
    finished = Deferred()

    iterable = flat.iterflatten(stan, ctx, writer,
                                lambda D: isinstance(D, Deferred))

    def drive():
        try:
            deferred, returner = iterable.next()

            def cb(result):
                returner(result)
                drive()
                return result

            def eb(failure):
                finished.errback(failure)
                return failure

            cfac = getCtx('CursorFactory')
            if cfac:
                deferred.addCallback(cfac.store.transback,
                                     cb).addErrback(cfac.store.transback, eb)
            else:
                deferred.addCallback(cb).addErrback(eb)
        except StopIteration:
            finished.callback('')

    drive()
    return finished
Ejemplo n.º 10
0
class LaterDataTest(RenderHelper):
    def data_later(self, context, data):
        return self.d

    def data_later2(self, context, data):
        return self.d2

    def setUp(self):
        self.d = Deferred()
        self.d2 = Deferred()
        self.r = rend.Page(docFactory=loaders.stan(
            tags.html(data=self.data_later)[
                'Hello ', str, ' and '
                'goodbye ',str,
                tags.span(data=self.data_later2, render=str)]))

    def test_deferredSupport(self):
        req = self.renderIt()
        self.assertEqual(req.v, '')
        self.d.callback("world")
        self.assertEqual(req.v, '<html>Hello world and goodbye world')
        self.d2.callback(".")
        self.assertEqual(req.v, '<html>Hello world and goodbye world.</html>')
Ejemplo n.º 11
0
class LaterRenderTest(RenderHelper):
    def setUp(self):
        self.d = Deferred()
        self.d2 = Deferred()
        self.r = rend.Page(
            docFactory=loaders.stan(
                tags.html(data=self)[
                    'Hello ', tags.invisible[tags.invisible[tags.invisible[tags.invisible[deferit]]]],
                    deferdot,
                    ]
                )
            )

    def test_deferredSupport(self):
        req = self.renderIt()
        self.assertEqual(req.v, '<html>Hello ')
        self.d.callback("world")
        self.assertEqual(req.v, '<html>Hello world')
        self.d2.callback(".")
        self.assertEqual(req.v, '<html>Hello world.</html>')


    def test_deferredSupport2(self):
        req = self.renderIt()
        self.assertEqual(req.v, '<html>Hello ')
        self.d2.callback(".")
        self.assertEqual(req.v, '<html>Hello ')
        self.d.callback("world")
        self.assertEqual(req.v, '<html>Hello world.</html>')

    def test_deferredSupport3(self):
        self.r.buffered = True
        req = self.renderIt()
        self.assertEqual(req.v, '')
        self.d.callback("world")
        self.assertEqual(req.v, '')
        self.d2.callback(".")
        self.assertEqual(req.v, '<html>Hello world.</html>')

    def test_renderNestedDeferredCallables(self):
        """
        Test flattening of a renderer which returns a Deferred which fires with
        a renderer which returns a Deferred.
        """
        def render_inner(ctx, data):
            return defer.succeed('')

        def render_outer(ctx, data):
            return defer.succeed(render_inner)

        ctx = context.WovenContext()
        ctx.remember(None, inevow.IData)

        out = []
        d = twist.deferflatten(render_outer, ctx, out.append)
        def flattened(ign):
            self.assertEqual(out, [''])
        d.addCallback(flattened)
        return d


    def test_renderNestedDeferredErrorHandling(self):
        """
        Test that flattening a renderer which returns a Deferred which fires
        with a renderer which raises an exception causes the outermost Deferred
        to errback.
        """
        class NestedException(Exception):
            pass

        def render_inner(ctx, data):
            raise NestedException()

        def render_outer(ctx, data):
            return defer.succeed(render_inner)

        ctx = context.WovenContext()
        ctx.remember(None, inevow.IData)

        out = []
        d = twist.deferflatten(render_outer, ctx, out.append)
        return self.assertFailure(d, NestedException)
Ejemplo n.º 12
0
class LaterRenderTest(RenderHelper):
    def setUp(self):
        self.d = Deferred()
        self.d2 = Deferred()
        self.r = rend.Page(
            docFactory=loaders.stan(
                html(data=self)["Hello ", invisible[invisible[invisible[invisible[deferit]]]], deferdot]
            )
        )

    def test_deferredSupport(self):
        req = self.renderIt()
        self.assertEquals(req.v, "<html>Hello ")
        self.d.callback("world")
        self.assertEquals(req.v, "<html>Hello world")
        self.d2.callback(".")
        self.assertEquals(req.v, "<html>Hello world.</html>")

    def test_deferredSupport2(self):
        req = self.renderIt()
        self.assertEquals(req.v, "<html>Hello ")
        self.d2.callback(".")
        self.assertEquals(req.v, "<html>Hello ")
        self.d.callback("world")
        self.assertEquals(req.v, "<html>Hello world.</html>")

    def test_deferredSupport3(self):
        self.r.buffered = True
        req = self.renderIt()
        self.assertEquals(req.v, "")
        self.d.callback("world")
        self.assertEquals(req.v, "")
        self.d2.callback(".")
        self.assertEquals(req.v, "<html>Hello world.</html>")
Ejemplo n.º 13
0
class LaterRenderTest(RenderHelper):
    def setUp(self):
        self.d = Deferred()
        self.d2 = Deferred()
        self.r = rend.Page(docFactory=loaders.stan(
            html(
                data=self)['Hello ',
                           invisible[invisible[invisible[invisible[deferit]]]],
                           deferdot, ]))

    def test_deferredSupport(self):
        req = self.renderIt()
        self.assertEquals(req.v, '<html>Hello ')
        self.d.callback("world")
        self.assertEquals(req.v, '<html>Hello world')
        self.d2.callback(".")
        self.assertEquals(req.v, '<html>Hello world.</html>')

    def test_deferredSupport2(self):
        req = self.renderIt()
        self.assertEquals(req.v, '<html>Hello ')
        self.d2.callback(".")
        self.assertEquals(req.v, '<html>Hello ')
        self.d.callback("world")
        self.assertEquals(req.v, '<html>Hello world.</html>')

    def test_deferredSupport3(self):
        self.r.buffered = True
        req = self.renderIt()
        self.assertEquals(req.v, '')
        self.d.callback("world")
        self.assertEquals(req.v, '')
        self.d2.callback(".")
        self.assertEquals(req.v, '<html>Hello world.</html>')