Пример #1
0
 def test_serializeString(self):
     self.assertEqual(ten.flatten('one'), u'one')
     self.assertEqual(type(ten.flatten('<>')), tags.raw)
     self.assertEqual(ten.flatten('<abc&&>123'),
                      u'&lt;abc&amp;&amp;&gt;123')
     self.assertEqual(ten.flatten(tags.xml('<>&')), u'<>&')
     self.assertEqual(
         ten.flatten(tags.xml(u'\xc2\xa3')).encode('utf-8'),
         b'\xc3\x82\xc2\xa3')
Пример #2
0
    def render_link_maybe(self, ctx, data):
        from codebay.l2tpserver import interfacehelper
        from nevow.flat.ten import flatten

        have_network_connection = False

        try:
            ifname = 'eth0'  # XXX: hardcoded in livecd
            ifaces = interfacehelper.get_interfaces()
            iface = ifaces.get_interface_by_name(ifname)
            if iface is not None:
                addr = iface.get_current_ipv4_address_info()
                if addr is not None:
                    have_network_connection = True
        except:
            _log.exception(
                'livecd cannot determine whether we have a network connection or not'
            )

        if have_network_connection:
            return ctx.tag
        else:
            # XXX: ugly hack, but without this markup would need heavier elements
            txt = flatten(ctx.tag.children)
            return T.strong(_class='cb-strong')[txt]
Пример #3
0
 def output(self):
     return flatten(T.html[
         T.head[T.script(type="text/javascript", src="wz_jsgraphics.js")],
         T.body(bgcolor="#cdcdb4")[T.script(
             type="text/javascript")["var jg = new jsGraphics();",
                                     self.draw_cmds, "jg.paint();", ],
                                   self.html_cmds]])
Пример #4
0
 def test_reallyDynamic(self):
     self.assertEquals(
         ten.flatten(
             tags.html[
                 lambda c, d: tags.body[
                     lambda c, d: 'stuff']]),
         '<html><body>stuff</body></html>')
Пример #5
0
 def test_tagWithRender(self):
     render = lambda c, d: 'body'
     result = ten.precompile(tags.html[tags.body(render=render)])
     prelude, dynamic, postlude = result
     self.assertEqual(prelude, '<html>')
     self.assertEqual(dynamic.tag.render, render)
     self.assertEqual(postlude, '</html>')
     self.assertEqual(ten.flatten(result), '<html>body</html>')
Пример #6
0
 def test_dynamic(self):
     render = lambda c, d: 'one'
     result = ten.precompile(tags.html[render])
     prelude, dynamic, postlude = result
     self.assertEqual(prelude, '<html>')
     self.assertEqual(dynamic.tag.render, render)
     self.assertEqual(postlude, '</html>')
     self.assertEqual(ten.flatten(result), '<html>one</html>')
Пример #7
0
 def test_dynamic(self):
     render = lambda c, d: 'one'
     result = ten.precompile(
         tags.html[
             render])
     prelude, dynamic, postlude = result
     self.assertEquals(prelude, '<html>')
     self.assertEquals(dynamic.tag.render, render)
     self.assertEquals(postlude, '</html>')
     self.assertEquals(ten.flatten(result), '<html>one</html>')
Пример #8
0
 def test_tagWithRender(self):
     render = lambda c, d: 'body'
     result = ten.precompile(
         tags.html[
             tags.body(render=render)])
     prelude, dynamic, postlude = result
     self.assertEquals(prelude, '<html>')
     self.assertEquals(dynamic.tag.render, render)
     self.assertEquals(postlude, '</html>')
     self.assertEquals(ten.flatten(result), '<html>body</html>')
Пример #9
0
 def output(self):
     return flatten(
         T.html[
           T.head[T.script(type="text/javascript", src="wz_jsgraphics.js")],
           T.body(bgcolor="#cdcdb4")[
             T.script(type="text/javascript")[
                  "var jg = new jsGraphics();",
                  self.draw_cmds,
                  "jg.paint();",
                  ],
             self.html_cmds
         ]])
Пример #10
0
    def render_link_maybe(self, ctx, data):
        from codebay.l2tpserver import interfacehelper
        from nevow.flat.ten import flatten

        have_network_connection = False

        try:
            ifname = 'eth0'  # XXX: hardcoded in livecd
            ifaces = interfacehelper.get_interfaces()
            iface = ifaces.get_interface_by_name(ifname)
            if iface is not None:
                addr = iface.get_current_ipv4_address_info()
                if addr is not None:
                    have_network_connection = True
        except:
            _log.exception('livecd cannot determine whether we have a network connection or not')

        if have_network_connection:
            return ctx.tag
        else:
            # XXX: ugly hack, but without this markup would need heavier elements
            txt = flatten(ctx.tag.children)
            return T.strong(_class='cb-strong')[txt]
Пример #11
0
 def test_someTypes(self):
     self.assertEquals(ten.flatten(1), '1')
     self.assertEquals(ten.flatten([1,2,3]), '123')
Пример #12
0
 def test_unescaped(self):
     self.assertEqual(
         ten.flatten(tags.xml('<<<%s>>>' % u)).encode("utf-8"),
         (b'<<<%s>>>' % u).encode('utf8'))
Пример #13
0
 def test_flattenTwice(self):
     """Test that flattening a string twice does not encode it twice.
     """
     self.assertEquals(ten.flatten(ten.flatten('&')), '&amp;')
Пример #14
0
 def test_serializeString(self):
     self.assertEquals(ten.flatten('one'), 'one')
     self.assertEquals(type(ten.flatten('<>')), tags.raw)
     self.assertEquals(ten.flatten('<abc&&>123'), '&lt;abc&amp;&amp;&gt;123')
     self.assertEquals(ten.flatten(tags.xml('<>&')), '<>&')
     self.assertEquals(ten.flatten(tags.xml(u'\xc2\xa3')), '\xc3\x82\xc2\xa3')
Пример #15
0
 def test_it(self):
     self.assertEquals(ten.flatten(u), u.encode('utf8'))
Пример #16
0
 def test_dynamic(self):
     self.assertEquals(
         ten.flatten(
             tags.html[
                 tags.body(render=lambda c, d: 'body!')]),
         '<html>body!</html>')
Пример #17
0
 def test_nestedTags(self):
     self.assertEquals(
         ten.flatten(
             tags.html(hi='there')[
                 tags.body[ 42 ]]),
         '<html hi="there"><body>42</body></html>')
Пример #18
0
 def test_unescaped(self):
     self.assertEquals(ten.flatten(tags.xml(u'<<<%s>>>' % u)), (u'<<<%s>>>' % u).encode('utf8'))
Пример #19
0
        
if __name__ == '__main__':
    from nevow.flat.ten import flatten

    h = PrimaryNamespace(
        'html', "http://www.w3.org/2002/06/xhtml2",
        singletons=('model', 'key'))
    x = TagNamespace(
        'xforms', "http://www.w3.org/2002/xforms",
        singletons=('model', 'key'))
    
    a = h.html(x, h)[
            h.head[
                x.model(schema="foo.xsd")['Not a singleton'],
                x.key(modifier='control', _key='c'),
                h.key(modifier='control', _key='c')
            ]
        ]

    print flatten(a)

    print "-" * 20

    b = h.html(x=x)[
            h.head[
                x.model
            ]
        ]
    
    print flatten(b)