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> & unaltered.</div>''' )]]] output = flatten(template) self.assertEqual(output, ( u'<html><head><title>test_escaping</title></head>' u'<body><div style="width: 400px;<should be &escaped&>">' u'<p class="foo">&&&</p><p>Coffee & cream</p>' u'<div>this should be <u>unescaped</u> & unaltered.</div></div></body></html>' ))
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> & unaltered.</div>""") ] ] ] output = flatten(template) assert output == ('<html><head><title>test_escaping</title></head>' '<body><div style="width: 400px;<should be &escaped&>">' '<p class="foo">&&&</p><p>Coffee & cream</p>' '<div>this should be <u>unescaped</u> & unaltered.</div></div>' '</body></html>')
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 =\n%s' % ( name, value ) ) exception.append ( '</span>' ) return xml ( ''.join ( exception ) )
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 =\n%s' % (name, value)) exception.append('</span>') return xml(''.join(exception))
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''
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''