Exemplo n.º 1
0
 def test_encoding_errors(self):
     self._do_memory_test(
         u("""KGB (transliteration of "КГБ") is the Russian-language abbreviation for Committee for State Security, (Russian: Комит́ет Госуд́арственной Безоп́асности (help·info); Komitet Gosudarstvennoy Bezopasnosti)"""),
         u("""KGB (transliteration of "КГБ") is the Russian-language abbreviation for Committee for State Security, (Russian: Комит́ет Госуд́арственной Безоп́асности (help·info); Komitet Gosudarstvennoy Bezopasnosti)""").encode('iso-8859-1', 'replace'),
         output_encoding='iso-8859-1', encoding_errors='replace',
         unicode_=False
     )
Exemplo n.º 2
0
 def test_unicode_literal_in_controlline(self):
     if compat.py3k:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             <%
                 x = "drôle de petite voix m’a réveillé."
             %>
             % if x=="drôle de petite voix m’a réveillé.":
                 hi, ${x}
             % endif
             """).encode('utf-8'),
             u("""hi, drôle de petite voix m’a réveillé."""),
             filters=lambda s: s.strip(),
         )
     else:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             <%
                 x = u"drôle de petite voix m’a réveillé."
             %>
             % if x==u"drôle de petite voix m’a réveillé.":
                 hi, ${x}
             % endif
             """).encode('utf-8'),
             u("""hi, drôle de petite voix m’a réveillé."""),
             filters=lambda s: s.strip(),
         )
Exemplo n.º 3
0
 def test_encoding_doesnt_conflict(self):
     self._do_memory_test(
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
           ),
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
           ),
         output_encoding='utf-8')
Exemplo n.º 4
0
 def test_unicode_literal_in_controlline(self):
     if compat.py3k:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             <%
                 x = "drôle de petite voix m’a réveillé."
             %>
             % if x=="drôle de petite voix m’a réveillé.":
                 hi, ${x}
             % endif
             """).encode('utf-8'),
             u("""hi, drôle de petite voix m’a réveillé."""),
             filters=lambda s:s.strip(),
         )
     else:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             <%
                 x = u"drôle de petite voix m’a réveillé."
             %>
             % if x==u"drôle de petite voix m’a réveillé.":
                 hi, ${x}
             % endif
             """).encode('utf-8'),
             u("""hi, drôle de petite voix m’a réveillé."""),
             filters=lambda s:s.strip(),
         )
Exemplo n.º 5
0
 def _do_test_traceback(self, utf8, memory, syntax):
     if memory:
         if syntax:
             source = u('## coding: utf-8\n<% print "m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! » %>')
         else:
             source = u('## coding: utf-8\n<% print u"m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + str(5/0) %>')
         if utf8:
             source = source.encode('utf-8')
         else:
             source = source
         templateargs = {'text': source}
     else:
         if syntax:
             filename = 'unicode_syntax_error.html'
         else:
             filename = 'unicode_runtime_error.html'
         source = util.read_file(self._file_path(filename), 'rb')
         if not utf8:
             source = source.decode('utf-8')
         templateargs = {'filename': self._file_path(filename)}
     try:
         template = Template(**templateargs)
         if not syntax:
             template.render_unicode()
         assert False
     except Exception:
         tback = errors.RichTraceback()
         if utf8:
             assert tback.source == source.decode('utf-8')
         else:
             assert tback.source == source
Exemplo n.º 6
0
 def _do_test_traceback(self, utf8, memory, syntax):
     if memory:
         if syntax:
             source = u('## coding: utf-8\n<% print "m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! » %>')
         else:
             source = u('## coding: utf-8\n<% print u"m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + str(5/0) %>')
         if utf8:
             source = source.encode('utf-8')
         else:
             source = source
         templateargs = {'text': source}
     else:
         if syntax:
             filename = 'unicode_syntax_error.html'
         else:
             filename = 'unicode_runtime_error.html'
         source = util.read_file(self._file_path(filename), 'rb')
         if not utf8:
             source = source.decode('utf-8')
         templateargs = {'filename': self._file_path(filename)}
     try:
         template = Template(**templateargs)
         if not syntax:
             template.render_unicode()
         assert False
     except Exception:
         tback = errors.RichTraceback()
         if utf8:
             assert tback.source == source.decode('utf-8')
         else:
             assert tback.source == source
Exemplo n.º 7
0
 def test_unicode_arg(self):
     val = u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""")
     self._do_memory_test(
         "${val}",
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""),
         template_args={'val':val}
     )
Exemplo n.º 8
0
 def test_encoding(self):
     self._do_memory_test(
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""),
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""").encode('utf-8'),
         output_encoding='utf-8',
         unicode_=False
     )
Exemplo n.º 9
0
 def test_unicode_text(self):
     val = u(
         """<%text>Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »</%text>"""
     )
     self._do_memory_test(
         ("## -*- coding: utf-8 -*-\n" + val).encode('utf-8'),
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
           ))
Exemplo n.º 10
0
 def test_encode_filter(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """,
                  default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=u("voix m’a réveillé")).strip(),
         u("some stuff.... voix m’a réveillé"))
Exemplo n.º 11
0
 def test_encode_filter(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=u("voix m’a réveillé")).strip(),
         u("some stuff.... voix m’a réveillé")
     )
Exemplo n.º 12
0
 def test_unicode_arg(self):
     val = u(
         """Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
     )
     self._do_memory_test(
         "${val}",
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
           ),
         template_args={'val': val})
Exemplo n.º 13
0
 def test_encoding_errors(self):
     self._do_memory_test(
         u("""KGB (transliteration of "КГБ") is the Russian-language abbreviation for Committee for State Security, (Russian: Комит́ет Госуд́арственной Безоп́асности (help·info); Komitet Gosudarstvennoy Bezopasnosti)"""
           ),
         u("""KGB (transliteration of "КГБ") is the Russian-language abbreviation for Committee for State Security, (Russian: Комит́ет Госуд́арственной Безоп́асности (help·info); Komitet Gosudarstvennoy Bezopasnosti)"""
           ).encode('iso-8859-1', 'replace'),
         output_encoding='iso-8859-1',
         encoding_errors='replace',
         unicode_=False)
Exemplo n.º 14
0
 def test_translator_comment(self):
     input = io.BytesIO(
         compat.b('''
     <p>
       ## TRANSLATORS: This is a comment.
       ${_("Message")}
     </p>'''))
     messages = list(extract(input, ['_'], ['TRANSLATORS:'], {}))
     self.assertEqual(messages,
                      [(4, '_', compat.u('Message'),
                        [compat.u('TRANSLATORS: This is a comment.')])])
Exemplo n.º 15
0
 def test_translator_comment(self):
     input = io.BytesIO(compat.b('''
     <p>
       ## TRANSLATORS: This is a comment.
       ${_("Message")}
     </p>'''))
     messages = list(extract(input, ['_'], ['TRANSLATORS:'], {}))
     self.assertEqual(
         messages,
         [(4, '_', compat.u('Message'),
             [compat.u('TRANSLATORS: This is a comment.')])])
Exemplo n.º 16
0
 def test_unicode_text_ccall(self):
     val = u("""
     <%def name="foo()">
         ${capture(caller.body)}
     </%def>
     <%call expr="foo()">
     <%text>Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »</%text>
     </%call>""")
     self._do_memory_test(
         ("## -*- coding: utf-8 -*-\n" + val).encode('utf-8'),
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
           ),
         filters=flatten_result)
Exemplo n.º 17
0
 def test_unicode_text_ccall(self):
     val = u("""
     <%def name="foo()">
         ${capture(caller.body)}
     </%def>
     <%call expr="foo()">
     <%text>Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »</%text>
     </%call>""")
     self._do_memory_test(
         ("## -*- coding: utf-8 -*-\n" + val).encode('utf-8'),
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""),
         filters=flatten_result
     )
Exemplo n.º 18
0
    def test_input_encoding(self):
        """test the 'input_encoding' flag on Template, and that unicode
            objects arent double-decoded"""

        if compat.py3k:
            self._do_memory_test(
                u("hello ${f('śląsk')}"),
                u("hello śląsk"),
                input_encoding='utf-8',
                template_args={'f': lambda x:x}
            )

            self._do_memory_test(
                u("## -*- coding: utf-8 -*-\nhello ${f('śląsk')}"),
                u("hello śląsk"),
                template_args={'f': lambda x:x}
            )
        else:
            self._do_memory_test(
                u("hello ${f(u'śląsk')}"),
                u("hello śląsk"),
                input_encoding='utf-8',
                template_args={'f': lambda x:x}
            )

            self._do_memory_test(
                u("## -*- coding: utf-8 -*-\nhello ${f(u'śląsk')}"),
                u("hello śląsk"),
                template_args={'f': lambda x:x}
            )
Exemplo n.º 19
0
    def test_unicode_bom(self):
        self._do_file_test(
            'bom.html',
            u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
              ))

        self._do_file_test(
            'bommagic.html',
            u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
              ))

        self.assertRaises(errors.CompileException,
                          Template,
                          filename=self._file_path('badbom.html'),
                          module_directory=module_base)
Exemplo n.º 20
0
    def test_unicode_bom(self):
        self._do_file_test(
            'bom.html',
            u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""")
        )

        self._do_file_test(
            'bommagic.html',
            u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""")
        )

        self.assertRaises(
            errors.CompileException,
            Template, filename=self._file_path('badbom.html'),
            module_directory=module_base
        )
Exemplo n.º 21
0
 def test_fast_buffer_encoded(self):
     s = u("drôl m’a rée « S’il")
     buf = util.FastEncodingBuffer(encoding='utf-8')
     buf.write(s[0:10])
     buf.write(s[10:])
     q = buf.getvalue()
     eq_(buf.getvalue(), s.encode('utf-8'))
Exemplo n.º 22
0
 def test_render(self):
     assert result_lines(tl.render({}, template='/index.html')) == [
         "this is index"
     ]
     assert result_lines(tl.render({}, template=compat.u('/index.html'))) == [
         "this is index"
     ]
Exemplo n.º 23
0
 def test_fast_buffer_encoded(self):
     s = u("drôl m’a rée « S’il")
     buf = util.FastEncodingBuffer(encoding='utf-8')
     buf.write(s[0:10])
     buf.write(s[10:])
     q = buf.getvalue()
     eq_(buf.getvalue(), s.encode('utf-8'))
Exemplo n.º 24
0
 def test_encode_filter_non_str(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=3).strip(),
         u("some stuff.... 3")
     )
Exemplo n.º 25
0
 def test_encode_filter_non_str(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=3).strip(),
         u("some stuff.... 3")
     )
Exemplo n.º 26
0
 def test_unicode_literal_in_expr(self):
     if compat.py3k:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             ${"Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"}
             """).encode('utf-8'),
             u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
               ),
             filters=lambda s: s.strip())
     else:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             ${u"Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"}
             """).encode('utf-8'),
             u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
               ),
             filters=lambda s: s.strip())
Exemplo n.º 27
0
 def test_unicode_literal_in_expr(self):
     if compat.py3k:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             ${"Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"}
             """).encode('utf-8'),
             u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""),
             filters = lambda s:s.strip()
         )
     else:
         self._do_memory_test(
             u("""## -*- coding: utf-8 -*-
             ${u"Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"}
             """).encode('utf-8'),
             u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""),
             filters = lambda s:s.strip()
         )
Exemplo n.º 28
0
 def __init__(self, encoding=None, errors='strict', as_unicode=False):
     self.data = collections.deque()
     self.encoding = encoding
     if as_unicode:
         self.delim = compat.u('')
     else:
         self.delim = ''
     self.as_unicode = as_unicode
     self.errors = errors
     self.write = self.data.append
Exemplo n.º 29
0
    def test_encode_filter_non_str_we_return_bytes(self):
        class Foo(object):
            def __str__(self):
                return compat.b("å")

        t = Template("""# coding: utf-8
            some stuff.... ${x}
        """,
                     default_filters=['decode.utf8'])
        eq_(t.render_unicode(x=Foo()).strip(), u("some stuff.... å"))
Exemplo n.º 30
0
 def __init__(self, encoding=None, errors='strict', as_unicode=False):
     self.data = collections.deque()
     self.encoding = encoding
     if as_unicode:
         self.delim = compat.u('')
     else:
         self.delim = ''
     self.as_unicode = as_unicode
     self.errors = errors
     self.write = self.data.append
Exemplo n.º 31
0
 def test_unicode_file_lookup(self):
     lookup = TemplateLookup(directories=[template_base],
                             output_encoding='utf-8',
                             default_filters=['decode.utf8'])
     if compat.py3k:
         template = lookup.get_template('/chs_unicode_py3k.html')
     else:
         template = lookup.get_template('/chs_unicode.html')
     eq_(flatten_result(template.render_unicode(name='毛泽东')),
         u('毛泽东 是 新中国的主席<br/> Welcome 你 to 北京.'))
Exemplo n.º 32
0
 def test_encode_filter_non_str_we_return_bytes(self):
     class Foo(object):
         def __str__(self):
             return compat.b("å")
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=Foo()).strip(),
         u("some stuff.... å")
     )
Exemplo n.º 33
0
    def test_raw_strings(self):
        """test that raw strings go straight thru with default_filters turned off,
        bytestring_passthrough enabled.

        """

        self._do_memory_test(
            u("## -*- coding: utf-8 -*-\nhello ${x}"),
            "hello śląsk",
            default_filters=[],
            template_args={'x': 'śląsk'},
            unicode_=False,
            bytestring_passthrough=True,
            output_encoding=None  #'ascii'
        )

        # now, the way you *should* be doing it....
        self._do_memory_test(u("## -*- coding: utf-8 -*-\nhello ${x}"),
                             u("hello śląsk"),
                             template_args={'x': u('śląsk')})
Exemplo n.º 34
0
 def test_py_utf8_html_error_template(self):
     try:
         foo = u('日本')
         raise RuntimeError('test')
     except:
         html_error = errors.html_error_template().render()
         if compat.py3k:
             assert 'RuntimeError: test' in html_error.decode('utf-8')
             assert "foo = u(&#39;日本&#39;)" in html_error.decode('utf-8')
         else:
             assert 'RuntimeError: test' in html_error
             assert "foo = u(&#39;&#x65E5;&#x672C;&#39;)" in html_error
Exemplo n.º 35
0
 def test_unicode_file_lookup(self):
     lookup = TemplateLookup(
                 directories=[template_base],
                 output_encoding='utf-8',
                 default_filters=['decode.utf8'])
     if compat.py3k:
         template = lookup.get_template('/chs_unicode_py3k.html')
     else:
         template = lookup.get_template('/chs_unicode.html')
     eq_(
         flatten_result(template.render_unicode(name='毛泽东')),
         u('毛泽东 是 新中国的主席<br/> Welcome 你 to 北京.')
     )
Exemplo n.º 36
0
    def test_raw_strings(self):
        """test that raw strings go straight thru with default_filters turned off,
        bytestring_passthrough enabled.

        """

        self._do_memory_test(
            u("## -*- coding: utf-8 -*-\nhello ${x}"),
            "hello śląsk",
            default_filters=[],
            template_args={'x':'śląsk'},
            unicode_=False,
            bytestring_passthrough=True,
            output_encoding=None #'ascii'
        )

        # now, the way you *should* be doing it....
        self._do_memory_test(
            u("## -*- coding: utf-8 -*-\nhello ${x}"),
            u("hello śląsk"),
            template_args={'x':u('śląsk')}
        )
Exemplo n.º 37
0
    def test_unicode_literal_in_def(self):
        if compat.py3k:
            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="bello(foo, bar)">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                <%call expr="bello(foo='árvíztűrő tükörfúrógép', bar='ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                </%call>""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""
                  ),
                filters=flatten_result)

            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="hello(foo='árvíztűrő tükörfúrógép', bar='ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                ${ hello() }""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""
                  ),
                filters=flatten_result)
        else:
            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="bello(foo, bar)">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                <%call expr="bello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                </%call>""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""
                  ),
                filters=flatten_result)

            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="hello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                ${ hello() }""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""
                  ),
                filters=flatten_result)
Exemplo n.º 38
0
    def test_unicode_literal_in_def(self):
        if compat.py3k:
            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="bello(foo, bar)">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                <%call expr="bello(foo='árvíztűrő tükörfúrógép', bar='ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                </%call>""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""),
                filters=flatten_result
            )

            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="hello(foo='árvíztűrő tükörfúrógép', bar='ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                ${ hello() }""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""),
                filters=flatten_result
            )
        else:
            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="bello(foo, bar)">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                <%call expr="bello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                </%call>""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""),
                filters=flatten_result
            )

            self._do_memory_test(
                u("""## -*- coding: utf-8 -*-
                <%def name="hello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')">
                Foo: ${ foo }
                Bar: ${ bar }
                </%def>
                ${ hello() }""").encode('utf-8'),
                u("""Foo: árvíztűrő tükörfúrógép Bar: ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"""),
                filters=flatten_result
            )
Exemplo n.º 39
0
    def test_unicode_literal_in_tag(self):
        self._do_file_test("unicode_arguments.html", [
            u('x is: drôle de petite voix m’a réveillé'),
            u('x is: drôle de petite voix m’a réveillé'),
            u('x is: drôle de petite voix m’a réveillé'),
            u('x is: drôle de petite voix m’a réveillé'),
        ],
                           filters=result_lines)

        self._do_memory_test(util.read_file(
            self._file_path("unicode_arguments.html")), [
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
            ],
                             filters=result_lines)
Exemplo n.º 40
0
 def process_python(self, code, code_lineno, translator_strings):
     source = code.getvalue().strip()
     if source.endswith(compat.b(':')):
         if source in (compat.b('try:'), compat.b('else:')) or source.startswith(compat.b('except')):
             source = compat.b('') # Ignore try/except and else
         elif source.startswith(compat.b('elif')):
             source = source[2:] # Replace "elif" with "if"
         source += compat.b('pass')
     code = io.BytesIO(source)
     for msg in self.python_extractor(
             self.filename, self.options, code, code_lineno -1):
         if translator_strings:
             msg = Message(msg.msgctxt, msg.msgid, msg.msgid_plural,
                           msg.flags,
                           compat.u(' ').join(
                               translator_strings + [msg.comment]),
                           msg.tcomment, msg.location)
         yield msg
Exemplo n.º 41
0
 def process_python(self, code, code_lineno, translator_strings):
     source = code.getvalue().strip()
     if source.endswith(compat.b(':')):
         if source in (compat.b('try:'),
                       compat.b('else:')) or source.startswith(
                           compat.b('except')):
             source = compat.b('')  # Ignore try/except and else
         elif source.startswith(compat.b('elif')):
             source = source[2:]  # Replace "elif" with "if"
         source += compat.b('pass')
     code = io.BytesIO(source)
     for msg in self.python_extractor(self.filename, self.options, code,
                                      code_lineno - 1):
         if translator_strings:
             msg = Message(
                 msg.msgctxt, msg.msgid, msg.msgid_plural, msg.flags,
                 compat.u(' ').join(translator_strings + [msg.comment]),
                 msg.tcomment, msg.location)
         yield msg
Exemplo n.º 42
0
    def test_utf8_html_error_template_no_pygments(self):
        """test the html_error_template with a Template containing UTF-8
        chars"""

        if compat.py3k:
            code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${'привет'}
% endif
"""
        else:
            code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${u'привет'}
% endif
"""
        try:
            template = Template(code)
            template.render_unicode()
        except errors.CompileException:
            html_error = errors.html_error_template().render()
            if compat.py3k:
                assert ("CompileException: Fragment &#39;if 2 == 2: /an "
                    "error&#39; is not a partial control statement "
                    "at line: 2 char: 1").encode(sys.getdefaultencoding(),
                            'htmlentityreplace') in \
                    html_error
            else:
                assert ("CompileException: Fragment &#39;if 2 == 2: /an "
                        "error&#39; is not a partial control statement "
                        "at line: 2 char: 1") in \
                        html_error

            if compat.py3k:
                assert "${&#39;привет&#39;}".encode(sys.getdefaultencoding(),
                                 'htmlentityreplace') in html_error
            else:
                assert u("${u&#39;привет&#39;}").encode(sys.getdefaultencoding(),
                                    'htmlentityreplace') in html_error
        else:
            assert False, ("This function should trigger a CompileException, "
                           "but didn't")
Exemplo n.º 43
0
    def test_unicode_literal_in_tag(self):
        self._do_file_test(
            "unicode_arguments.html",
            [
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
            ],
            filters=result_lines
        )

        self._do_memory_test(
            util.read_file(self._file_path("unicode_arguments.html")),
            [
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
            ],
            filters=result_lines
        )
Exemplo n.º 44
0
    def test_input_encoding(self):
        """test the 'input_encoding' flag on Template, and that unicode
            objects arent double-decoded"""

        if compat.py3k:
            self._do_memory_test(u("hello ${f('śląsk')}"),
                                 u("hello śląsk"),
                                 input_encoding='utf-8',
                                 template_args={'f': lambda x: x})

            self._do_memory_test(
                u("## -*- coding: utf-8 -*-\nhello ${f('śląsk')}"),
                u("hello śląsk"),
                template_args={'f': lambda x: x})
        else:
            self._do_memory_test(u("hello ${f(u'śląsk')}"),
                                 u("hello śląsk"),
                                 input_encoding='utf-8',
                                 template_args={'f': lambda x: x})

            self._do_memory_test(
                u("## -*- coding: utf-8 -*-\nhello ${f(u'śląsk')}"),
                u("hello śląsk"),
                template_args={'f': lambda x: x})
Exemplo n.º 45
0
 def test_python_gettext_call(self):
     input = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
     messages = list(extract(input, ['_'], [], {}))
     self.assertEqual(messages, [(1, '_', compat.u('Message'), [])])
Exemplo n.º 46
0
 def test_unicode_file_code(self):
     self._do_file_test(
         'unicode_code.html',
         u("""hi, drôle de petite voix m’a réveillé."""),
         filters=flatten_result
     )
Exemplo n.º 47
0
 def test_unicode_file(self):
     self._do_file_test(
         "unicode.html",
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""")
     )
Exemplo n.º 48
0
 def test_py_unicode_error_html_error_template(self):
     try:
         raise RuntimeError(u('日本'))
     except:
         html_error = errors.html_error_template().render()
         assert u("RuntimeError: 日本").encode('ascii', 'ignore') in html_error
Exemplo n.º 49
0
 def test_unicode_literal_in_expr_file(self):
     self._do_file_test(
         'unicode_expr.html',
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
           ), lambda t: t.strip())
Exemplo n.º 50
0
 def test_python_gettext_call(self):
     input = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
     messages = list(extract(input, ['_'], [], {}))
     self.assertEqual(messages, [(1, '_', compat.u('Message'), [])])
Exemplo n.º 51
0
 def test_unicode_text(self):
     val = u("""<%text>Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »</%text>""")
     self._do_memory_test(
         ("## -*- coding: utf-8 -*-\n" + val).encode('utf-8'),
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""")
     )
Exemplo n.º 52
0
 def test_unicode_file_code(self):
     self._do_file_test('unicode_code.html',
                        u("""hi, drôle de petite voix m’a réveillé."""),
                        filters=flatten_result)
Exemplo n.º 53
0
 def test_unicode_file(self):
     self._do_file_test(
         "unicode.html",
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""
           ))
Exemplo n.º 54
0
 def test_render(self):
     assert result_lines(tl.render(
         {}, template='/index.html')) == ["this is index"]
     assert result_lines(tl.render(
         {}, template=compat.u('/index.html'))) == ["this is index"]
Exemplo n.º 55
0
 def test_unicode_literal_in_expr_file(self):
     self._do_file_test(
         'unicode_expr.html',
         u("""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""),
         lambda t:t.strip()
     )