コード例 #1
0
 def test_visit(self):
     """
     Test that L{nevow.stan.visit} invokes the visitor it is given with all
     the nodes in the DOM it is given in pre-order.
     """
     visited = []
     def visitor(t):
         visited.append(t)
     root = stan.Proto('root')()
     firstChild = stan.Proto('firstChild')()
     secondChild = stan.Proto('secondChild')()
     firstGrandchild = stan.Proto('firstGrandchild')()
     secondGrandchild = stan.Proto('secondGrandchild')()
     thirdGrandchild = 'thirdGrandchild'
     root[firstChild, secondChild]
     secondChild[firstGrandchild, secondGrandchild, thirdGrandchild]
     stan.visit(root, visitor)
     self.assertEqual(
         visited,
         [root, firstChild, secondChild,
          firstGrandchild, secondGrandchild, thirdGrandchild])
コード例 #2
0
from twisted.internet import defer

from zope.interface import implements, Interface

from nevow import stan
from nevow import context
from nevow import tags
from nevow import entities
from nevow import inevow
from nevow import flat
from nevow import rend
from nevow.testutil import FakeRequest, TestCase

from nevow.flat import twist

proto = stan.Proto('hello')


class Base(TestCase):
    contextFactory = context.WovenContext
    def renderer(self, context, data):
        return lambda context, data: ""

    def setupContext(self, precompile=False, setupRequest=lambda r:r):
        fr = setupRequest(FakeRequest(uri='/', currentSegments=['']))
        ctx = context.RequestContext(tag=fr)
        ctx.remember(fr, inevow.IRequest)
        ctx.remember(None, inevow.IData)
        ctx = context.WovenContext(parent=ctx, precompile=precompile)
        return ctx
コード例 #3
0
ファイル: test_stan.py プロジェクト: calston/tums
 def test_suffix(self):
     proto = stan.Proto('div')
     tag = proto()
     tag(class_='a')
     self.assertEquals(tag.attributes, {'class': 'a'})
コード例 #4
0
ファイル: test_stan.py プロジェクト: calston/tums
 def test_proto(self):
     tagName = "hello"
     proto = stan.Proto(tagName)
     self.assertEquals(tagName, str(proto))
コード例 #5
0
ファイル: test_stan.py プロジェクト: calston/tums
 def test_getItemCreatesTag(self):
     proto = stan.Proto("hello")
     tag = proto[proto]
     self.assertEquals(proto, tag.tagName)
     self.assertEquals(tag.children, [proto])
コード例 #6
0
ファイル: test_stan.py プロジェクト: calston/tums
 def test_callCreatesTag(self):
     proto = stan.Proto("hello")
     tag = proto(world="1")
     self.assertEquals(proto, tag.tagName)
     self.assertEquals(tag.attributes['world'], '1')
コード例 #7
0
ファイル: test_stan.py プロジェクト: calston/tums
        self.assertEquals(tagName, str(proto))

    def test_callCreatesTag(self):
        proto = stan.Proto("hello")
        tag = proto(world="1")
        self.assertEquals(proto, tag.tagName)
        self.assertEquals(tag.attributes['world'], '1')

    def test_getItemCreatesTag(self):
        proto = stan.Proto("hello")
        tag = proto[proto]
        self.assertEquals(proto, tag.tagName)
        self.assertEquals(tag.children, [proto])


proto = stan.Proto("hello")


class TestTag(TestCase):
    def test_clone(self):
        tag = proto(hello="world")["How are you"]
        tag.fillSlots('foo', 'bar')
        clone = tag.clone()
        self.assertEquals(clone.attributes['hello'], 'world')
        self.assertNotIdentical(clone.attributes, tag.attributes)
        self.assertEquals(clone.children, ["How are you"])
        self.assertNotIdentical(clone.children, tag.children)
        self.assertEquals(tag.slotData, clone.slotData)
        self.assertNotIdentical(tag.slotData, clone.slotData)

    ## TODO: need better clone test here to test clone(deep=True),
コード例 #8
0
 def test_prefix(self):
     proto = stan.Proto('div')
     tag = proto()
     tag(_class='a')
     self.assertEqual(tag.attributes, {'class': 'a'})
コード例 #9
0
ファイル: athena.py プロジェクト: calston/tums
            callDeferred.errback(getJSFailure(result, self.jsModules.mapping))

    def action_noop(self, ctx):
        """
        Handle noop, used to initialise and ping the live transport.
        """

    def action_close(self, ctx):
        """
        The client is going away.  Clean up after them.
        """
        self._messageDeliverer.close()
        self._disconnected(error.ConnectionDone("Connection closed"))


handler = stan.Proto('athena:handler')
_handlerFormat = "return Nevow.Athena.Widget.handleEvent(this, %(event)s, %(handler)s);"


def _rewriteEventHandlerToAttribute(tag):
    """
    Replace athena:handler children of the given tag with attributes on the tag
    which correspond to those event handlers.
    """
    if isinstance(tag, stan.Tag):
        extraAttributes = {}
        for i in xrange(len(tag.children) - 1, -1, -1):
            if isinstance(
                    tag.children[i],
                    stan.Tag) and tag.children[i].tagName == 'athena:handler':
                info = tag.children.pop(i)