Example #1
0
    def test_escaping(self):
        '''escaping, xml() directive'''

        T = tags
        template = T.html[T.head[T.title[my_name()]], T.body[T.div(
            style='width: 400px;<should be &escaped&>'
        )[T.p(class_='foo')['&&&'], T.p['Coffee', E.nbsp, E.amp, E.nbsp,
                                        'cream'],
          xml('''<div>this should be <u>unescaped</u> &amp; unaltered.</div>'''
              )]]]
        output = flatten(template)
        self.assertEqual(output, (
            u'<html><head><title>test_escaping</title></head>'
            u'<body><div style="width: 400px;&lt;should be &amp;escaped&amp;&gt;">'
            u'<p class="foo">&amp;&amp;&amp;</p><p>Coffee&#160;&#38;&#160;cream</p>'
            u'<div>this should be <u>unescaped</u> &amp; unaltered.</div></div></body></html>'
        ))
Example #2
0
def test_escaping():
    """escaping, xml() directive"""
    template = T.html[
        T.head[T.title[my_name()]],
        T.body[
            T.div(style='width: 400px;<should be &escaped&>')[
                T.p(class_='foo')['&&&'],
                T.p['Coffee', E.nbsp, E.amp, E.nbsp, 'cream'],
                xml ("""<div>this should be <u>unescaped</u> &amp; unaltered.</div>""")
            ]
        ]
    ]
    output = flatten(template)
    assert output == ('<html><head><title>test_escaping</title></head>'
                      '<body><div style="width: 400px;&lt;should be &amp;escaped&amp;&gt;">'
                      '<p class="foo">&amp;&amp;&amp;</p><p>Coffee&#160;&#38;&#160;cream</p>'
                      '<div>this should be <u>unescaped</u> &amp; unaltered.</div></div>'
                      '</body></html>')
Example #3
0
    def debug_out ( T, exc_info, filename ):
        import cgitb; cgitb.enable ( )
        raise

        ( etype, evalue ) = exc_info

        exception = [
            '<span class="template_exception">',
            'Error in template: %s %s: %s' %
            ( filename,
              pydoc.html.escape ( str ( etype ) ),
              pydoc.html.escape ( str ( evalue ) ) )
        ]
        if type ( evalue ) is types.InstanceType:
            for name in dir ( evalue ):
                if name [ :1 ] == '_' or name == 'args': continue
                value = pydoc.html.repr ( getattr ( evalue, name ) )
                exception.append ( '\n<br />%s&nbsp;=\n%s' % ( name, value ) )
        exception.append ( '</span>' )
        return xml ( ''.join ( exception ) )
Example #4
0
    def debug_out(T, exc_info, filename):
        import cgitb
        cgitb.enable()
        raise

        (etype, evalue) = exc_info

        exception = [
            '<span class="template_exception">',
            'Error in template: %s %s: %s' %
            (filename, pydoc.html.escape(
                str(etype)), pydoc.html.escape(str(evalue)))
        ]
        if type(evalue) is types.InstanceType:
            for name in dir(evalue):
                if name[:1] == '_' or name == 'args': continue
                value = pydoc.html.repr(getattr(evalue, name))
                exception.append('\n<br />%s&nbsp;=\n%s' % (name, value))
        exception.append('</span>')
        return xml(''.join(exception))
Example #5
0
 def __str__ ( self ):
     if self.name in T.fragments:
         return xml ( flatten ( T.fragments [ self.name ] ) )
     if self.children:
         return u''.join ( [ flatten ( c ) for c in self.children ] )
     return u''
Example #6
0
 def __str__(self):
     if self.name in T.fragments:
         return xml(flatten(T.fragments[self.name]))
     if self.children:
         return u''.join([flatten(c) for c in self.children])
     return u''