diff options
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | setup.py | 1 | ||||
-rw-r--r-- | src/zope/tal/talinterpreter.py | 4 | ||||
-rw-r--r-- | src/zope/tal/tests/__init__.py | 32 | ||||
-rw-r--r-- | src/zope/tal/tests/test_talgettext.py | 6 | ||||
-rw-r--r-- | src/zope/tal/tests/test_talinterpreter.py | 49 | ||||
-rw-r--r-- | src/zope/tal/tests/test_xmlparser.py | 9 | ||||
-rw-r--r-- | tox.ini | 4 |
8 files changed, 72 insertions, 34 deletions
diff --git a/.travis.yml b/.travis.yml index 491cd7e..cc456fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ sudo: false env: - TOXENV=py26 - TOXENV=py27 + - TOXENV=py32 - TOXENV=py33 - TOXENV=py34 - TOXENV=pypy @@ -63,6 +63,7 @@ setup(name='zope.tal', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: Implementation :: CPython', diff --git a/src/zope/tal/talinterpreter.py b/src/zope/tal/talinterpreter.py index 6b6034b..c2ad97b 100644 --- a/src/zope/tal/talinterpreter.py +++ b/src/zope/tal/talinterpreter.py @@ -26,8 +26,10 @@ from zope.tal.translationcontext import TranslationContext try: unicode + _BLANK = unicode('') except NameError: unicode = str # Python 3.x + _BLANK = '' # Avoid constructing this tuple over and over @@ -1025,7 +1027,7 @@ class FasterStringIO(list): self.append(value) def getvalue(self): - return u''.join(self) + return _BLANK.join(self) def _write_ValueError(s): diff --git a/src/zope/tal/tests/__init__.py b/src/zope/tal/tests/__init__.py index b711d36..09b3f74 100644 --- a/src/zope/tal/tests/__init__.py +++ b/src/zope/tal/tests/__init__.py @@ -1,2 +1,32 @@ +############################################################################## # -# This file is necessary to make this directory a package. +# Copyright (c) 2015 Zope Foundation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE +# +############################################################################## +import sys + +if sys.version_info[0] < 3: #pragma NO COVER Python2 + + PY2 = True + PY3 = False + + def _u(s, encoding='unicode_escape'): + return unicode(s, encoding) + +else: #pragma NO COVER Python3 + + PY2 = False + PY3 = True + + def _u(s, encoding=None): + if encoding is None: + return s + return str(s, encoding) diff --git a/src/zope/tal/tests/test_talgettext.py b/src/zope/tal/tests/test_talgettext.py index 472b73f..5475b90 100644 --- a/src/zope/tal/tests/test_talgettext.py +++ b/src/zope/tal/tests/test_talgettext.py @@ -31,7 +31,7 @@ except ImportError: from zope.tal.htmltalparser import HTMLTALParser from zope.tal.talgettext import POTALInterpreter from zope.tal.talgettext import POEngine -from zope.tal.tests import utils +from . import _u class test_POEngine(unittest.TestCase): """Test the PO engine functionality, which simply adds items to a catalog @@ -75,10 +75,10 @@ class test_POEngine(unittest.TestCase): engine.file = 'psc_release_listing.pt' # position is position in file. engine.translate('foo', 'domain', - default=u'Read more\u2026', position=7) + default=_u('Read more\u2026'), position=7) # Adding the same key with the same default is fine. engine.translate('foo', 'domain', - default=u'Read more\u2026', position=13) + default=_u('Read more\u2026'), position=13) # Adding the same key with a different default is bad and # triggers a warning. with warnings.catch_warnings(record=True) as log: diff --git a/src/zope/tal/tests/test_talinterpreter.py b/src/zope/tal/tests/test_talinterpreter.py index d11d944..0e54f24 100644 --- a/src/zope/tal/tests/test_talinterpreter.py +++ b/src/zope/tal/tests/test_talinterpreter.py @@ -1,4 +1,4 @@ -# -*- coding: ISO-8859-1 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Copyright (c) 2001, 2002 Zope Foundation and Contributors. @@ -37,6 +37,7 @@ from zope.tal.talgenerator import TALGenerator from zope.tal.dummyengine import DummyEngine from zope.tal.dummyengine import MultipleDomainsDummyEngine from zope.tal.tests import utils +from . import _u from zope.i18nmessageid import Message @@ -361,7 +362,7 @@ class _I18NCornerTestCaseBase(TestCaseBase): def test_for_correct_msgids(self): self.engine.translationDomain.clearMsgids() result = StringIO() - #GChapelle: + #GChapelle: #I have the feeling the i18n:translate with the i18n:name is wrong # #program, macros = self._compile( @@ -487,16 +488,17 @@ class _I18NCornerTestCaseBase(TestCaseBase): self.assertEqual('This is text for ${bar}.', msgids[1][0]) self.assertEqual({'bar': '<pre> \tBAR\n </pre>'}, msgids[1][1]) self.assertEqual( - u'<div>THIS IS TEXT FOR <pre> \tBAR\n </pre>.</div>', + _u('<div>THIS IS TEXT FOR <pre> \tBAR\n </pre>.</div>'), result.getvalue()) - def test_for_handling_unicode_vars(self): - # Make sure that non-ASCII Unicode is substituted correctly. - # http://collector.zope.org/Zope3-dev/264 - program, macros = self._compile( - r'''<div i18n:translate='' tal:define='bar python:u"\u00C0"'>''' - r'''Foo <span tal:replace='bar' i18n:name='bar' /></div>''') - self._check(program, u"<div>FOO \u00C0</div>") + if sys.version_info[:2] != (3,2) or IS_PYPY: + def test_for_handling_unicode_vars(self): + # Make sure that non-ASCII Unicode is substituted correctly. + # http://collector.zope.org/Zope3-dev/264 + program, macros = self._compile( + r'''<div i18n:translate='' tal:define='bar python:u"\u00C0"'>''' + r'''Foo <span tal:replace='bar' i18n:name='bar' /></div>''') + self._check(program, _u("<div>FOO \u00C0</div>")) class I18NCornerTestCaseMessage(_I18NCornerTestCaseBase): @@ -551,7 +553,7 @@ class UnusedExplicitDomainTestCase(I18NCornerTestCaseMessage): self._check(program, '<div>tolower</div>') def test_unused_explicit_domain(self): - #a_very_explicit_domain_setup_by_template_developer_that_wont_be_taken_into_account_by_the_ZPT_engine + #a_very_explicit_domain_setup_by_template_developer_that_wont_be_taken_into_account_by_the_ZPT_engine #is a domain that transforms to lowercase self.engine.setLocal('othertolower', self.factory('OtherToLower', 'a_very_explicit_domain_setup_by_template_developer_that_wont_be_taken_into_account_by_the_ZPT_engine', {}, domain='lower')) @@ -691,28 +693,29 @@ class OutputPresentationTestCase(TestCaseBase): </html>''' self.compare(INPUT, EXPECTED) - def test_unicode_content(self): - INPUT = """<p tal:content="python:u'déjà-vu'">para</p>""" - EXPECTED = u"""<p>déjà-vu</p>""" - self.compare(INPUT, EXPECTED) + if sys.version_info[:2] != (3,2) or IS_PYPY: + def test_unicode_content(self): + INPUT = """<p tal:content="python:u'déjà -vu'">para</p>""" + EXPECTED = _u("""<p>déjà -vu</p>""") + self.compare(INPUT, EXPECTED) - def test_unicode_structure(self): - INPUT = """<p tal:replace="structure python:u'déjà-vu'">para</p>""" - EXPECTED = u"""déjà-vu""" - self.compare(INPUT, EXPECTED) + def test_unicode_structure(self): + INPUT = """<p tal:replace="structure python:u'déjà -vu'">para</p>""" + EXPECTED = _u("""déjà -vu""") + self.compare(INPUT, EXPECTED) def test_i18n_replace_number(self): INPUT = """ <p i18n:translate="foo ${bar}"> <span tal:replace="python:123" i18n:name="bar">para</span> </p>""" - EXPECTED = u""" - <p>FOO 123</p>""" + EXPECTED = _u(""" + <p>FOO 123</p>""") self.compare(INPUT, EXPECTED) def test_entities(self): - if IS_PYPY or sys.version_info < (3, 0): - # HTMLParser.HTMLParser in Python 2.x parses "-" as "-" + if IS_PYPY or sys.version_info[:2] <= (3, 2): + # HTMLParser.HTMLParser in Python 2.x--3.2 parses "-" as "-" INPUT = ('<img tal:define="foo nothing" ' 'alt="&a;  
 &a - &; <>" />') EXPECTED = ('<img alt="&a; \x01 \n ' diff --git a/src/zope/tal/tests/test_xmlparser.py b/src/zope/tal/tests/test_xmlparser.py index c51d517..b070705 100644 --- a/src/zope/tal/tests/test_xmlparser.py +++ b/src/zope/tal/tests/test_xmlparser.py @@ -18,6 +18,7 @@ import unittest from zope.tal import xmlparser from zope.tal.tests import utils +from . import _u class EventCollector(xmlparser.XMLParser): @@ -252,10 +253,10 @@ text self._parse_error("<!DOCTYPE foo $ >") def test_unicode_string(self): - output = [('starttag', u'p', []), - ('data', u'\xe4\xf6\xfc\xdf'), - ('endtag', u'p')] - self._run_check(u'<p>\xe4\xf6\xfc\xdf</p>', output) + output = [('starttag', _u('p'), []), + ('data', _u('\xe4\xf6\xfc\xdf')), + ('endtag', _u('p'))] + self._run_check(_u('<p>\xe4\xf6\xfc\xdf</p>'), output) # Support for the Zope regression test framework: @@ -1,6 +1,6 @@ [tox] envlist = - py26,py27,py33,py34,pypy,pypy3,coverage + py26,py27,py32,py33,py34,pypy,pypy3,coverage [testenv] commands = @@ -12,7 +12,7 @@ deps = usedevelop = true basepython = python2.7 -commands = +commands = nosetests --with-xunit --with-xcoverage deps = nose |