Ejemplo n.º 1
0
 def test_errorPropogation(self):
     
     # A generator that raises an error
     def gen(ctx, data):
         yield 1
         pop
         yield 2
         
     # Hacky imports
     from cStringIO import StringIO
     from nevow.flat import twist
     
     # Simple context with None IData
     ctx = context.WovenContext()
     ctx.remember(None, inevow.IData)
     
     # The actual test
     notquiteglobals = {}
     io = StringIO()
     def finished(spam):
         print 'FINISHED'
     def error(failure):
         notquiteglobals['exception'] = failure.value
     def checker(result):
         if not isinstance(notquiteglobals['exception'], NameError):
             self.fail('deferflatten did not errback with the correct failure')
         return result
     d = twist.deferflatten(gen, ctx, io.write)
     d.addCallback(finished)
     d.addErrback(error)
     d.addBoth(checker)
     return d
Ejemplo n.º 2
0
Archivo: skin.py Proyecto: antong/webut
 def render_skin(ctx, data):
     content = inevow.IQ(ctx.tag).onePattern('skincontent')
     gather = tags.invisible()
     d = deferflatten(content, ctx, gather.__getitem__)
     def gotContent(s):
         self.content = gather
         return skin
     d.addCallback(gotContent)
     return d
Ejemplo n.º 3
0
    def flatten(self, obj):
        """
        Flatten the given object using L{twist.deferflatten} and a simple context.

        Return the Deferred returned by L{twist.deferflatten}.
        it.
        """
        # Simple context with None IData
        ctx = context.WovenContext()
        ctx.remember(None, inevow.IData)
        return twist.deferflatten(obj, ctx, lambda bytes: None)
Ejemplo n.º 4
0
    def flatten(self, obj):
        """
        Flatten the given object using L{twist.deferflatten} and a simple context.

        Return the Deferred returned by L{twist.deferflatten}.
        it.
        """
        # Simple context with None IData
        ctx = context.WovenContext()
        ctx.remember(None, inevow.IData)
        return twist.deferflatten(obj, ctx, lambda bytes: None)
Ejemplo n.º 5
0
 def render(self, tag, precompile=False, data=None, setupRequest=lambda r: r, setupContext=lambda c:c, wantDeferred=False):
     ctx = self.setupContext(precompile, setupRequest)
     ctx = setupContext(ctx)
     if precompile:
         return flat.precompile(tag, ctx)
     else:
         if wantDeferred:
             L = []
             D = twist.deferflatten(tag, ctx, L.append)
             D.addCallback(lambda igresult: ''.join(L))
             return D
         else:
             return flat.flatten(tag, ctx)
Ejemplo n.º 6
0
 def render(self, tag, precompile=False, data=None, setupRequest=lambda r: r, setupContext=lambda c:c, wantDeferred=False):
     ctx = self.setupContext(precompile, setupRequest)
     ctx = setupContext(ctx)
     if precompile:
         return flat.precompile(tag, ctx)
     else:
         if wantDeferred:
             L = []
             D = twist.deferflatten(tag, ctx, L.append)
             D.addCallback(lambda igresult: ''.join(L))
             return D
         else:
             return flat.flatten(tag, ctx)
Ejemplo n.º 7
0
 def render(self, tag, precompile=False, data=None, setupRequest=lambda r: r, setupContext=lambda c:c):
     ctx = self.setupContext(precompile, setupRequest)
     ctx = setupContext(ctx)
     if precompile:
         return flat.precompile(tag, ctx)
     else:
         try:
             from twisted.trial import util
             from nevow.flat import twist
         except ImportError:
             return flat.flatten(tag, ctx)
         else:
             L = []
             util.deferredResult(twist.deferflatten(tag, ctx, L.append))
             return ''.join(L)
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
 def render(self,
            tag,
            precompile=False,
            data=None,
            setupRequest=lambda r: r,
            setupContext=lambda c: c):
     ctx = self.setupContext(precompile, setupRequest)
     ctx = setupContext(ctx)
     if precompile:
         return flat.precompile(tag, ctx)
     else:
         try:
             from twisted.trial import util
             from nevow.flat import twist
         except ImportError:
             return flat.flatten(tag, ctx)
         else:
             L = []
             util.deferredResult(twist.deferflatten(tag, ctx, L.append))
             return ''.join(L)
Ejemplo n.º 10
0
    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.º 11
0
    def test_errorPropogation(self):

        # A generator that raises an error
        def gen(ctx, data):
            yield 1
            raise Exception('This is an exception!')
            yield 2

        # Hacky imports
        from cStringIO import StringIO
        from nevow.flat import twist

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

        # The actual test
        notquiteglobals = {}
        io = StringIO()

        def finished(spam):
            print 'FINISHED'

        def error(failure):
            notquiteglobals['exception'] = failure.value

        def checker(result):
            if not isinstance(notquiteglobals['exception'], Exception):
                self.fail(
                    'deferflatten did not errback with the correct failure')
            return result

        d = twist.deferflatten(gen, ctx, io.write)
        d.addCallback(finished)
        d.addErrback(error)
        d.addBoth(checker)
        return d
Ejemplo n.º 12
0
 def flattenFactory(stan, ctx, writer, finisher):
     from nevow.flat.twist import deferflatten
     return deferflatten(stan, ctx, writer).addCallback(finisher)
Ejemplo n.º 13
0
    def flattenFactory(stan, ctx, writer, finisher):
        from nevow.flat.twist import deferflatten

        return deferflatten(stan, ctx, writer).addCallback(finisher)