Translation
-----------

This document contains functional template tests covering the TAL
directives.

  >>> from z3c.pt.translation import translate

  >>> def render(body, **kwargs):
  ...    source, _globals = translate(body)
  ...    _locals = {}
  ...    exec source in _globals, _locals
  ...    return _locals['render'](**kwargs)
  
Canonical test template
-----------------------

  >>> body = """\
  ... <div xmlns="http://www.w3.org/1999/xhtml"
  ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
  ...   <span id="test"
  ...         class="dummy"
  ...         tal:define="a 'abc'"
  ...         tal:attributes="class 'def' + a; style 'position: absolute'"
  ...         tal:content="a + 'ghi'" />
  ...   <ul>
  ...     <li tal:repeat="i range(5)">
  ...       <span tal:replace="'Item ' + str(i) + ')'" />
  ...     </li>
  ...   </ul>
  ...   <tal:example replace="'Hello World!'" />
  ...   <tal:div content="'Hello World!'" />
  ...   <tal:multiple repeat="i range(5)" replace="i" />
  ...   <p tal:omit-tag="">No paragraph here.</p>
  ...   <p tal:omit-tag="True">No paragraph here either.</p>
  ...   <p tal:omit-tag="False">A paragraph here.</p>
  ...   <span tal:replace="'Hello World!'">Hello Universe!</span>
  ...   <span tal:content="'%s'" />
  ...   <span tal:content="None" />
  ... </div>
  ... """ % (u'La Pe\xf1a').encode('utf-8')

  >>> print render(body)
  <div>
    <span style="position: absolute" id="test" class="defabc">abcghi</span>
    <ul>
      <li>
	Item 0)
      </li>
    <li>
	Item 1)
      </li>
    <li>
	Item 2)
      </li>
    <li>
	Item 3)
      </li>
    <li>
	Item 4)
      </li>
    </ul>
    Hello World!
    <div>Hello World!</div>
    0
    1
    2
    3
    4
    No paragraph here.
    No paragraph here either.
    <p>A paragraph here.</p>
    Hello World!
    <span>La Peña</span>
    <span></span>
  </div>
    
Error handling
--------------

This section demonstrates how the package handles templates that
contain errors.

No default namespace declaration:
  A default namespace must be explicitly declared for the parser to work.
  
  >>> body = '<br />'
  >>> render(body)
  Traceback (most recent call last):
    ...
  ValueError: Must set default namespace.
    
Bad XML
  We expect the xml-parser to raise an exception.
  
  >>> body = '<div xmlns="http://www.w3.org/1999/xhtml"'
  >>> render(body)
  Traceback (most recent call last):
    ...
  XMLSyntaxError: line 1: Couldn't find end of Start Tag div line 1

Missing namespace definition:
    We expect the engine to render the attributes as static.

  >>> body = """\
  ... <div xmlns="http://www.w3.org/1999/xhtml" tal:content="'Hello World'" />
  ... """

  >>> print render(body)
  <div content="'Hello World'" />
