summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTres Seaver <tseaver@palladion.com>2015-06-05 16:37:13 -0400
committerTres Seaver <tseaver@palladion.com>2015-06-05 16:37:13 -0400
commit769a45ec1d399d3798519529cd00757df199e5bf (patch)
treefac38f79dd10c8d6e8d1d384ed093bae74c63522
parent1b93961f40a9902af9ba88b8c6f52f8673947ae2 (diff)
parent0093b687b550d6e675bd2a026b70a1b9cc7d7d49 (diff)
downloadzope-tal-769a45ec1d399d3798519529cd00757df199e5bf.tar.gz
Merge branch 'NextThought-py32'
-rw-r--r--.travis.yml1
-rw-r--r--CHANGES.rst3
-rw-r--r--setup.py1
-rw-r--r--src/zope/tal/talinterpreter.py4
-rw-r--r--src/zope/tal/tests/__init__.py32
-rw-r--r--src/zope/tal/tests/test_talgettext.py6
-rw-r--r--src/zope/tal/tests/test_talinterpreter.py49
-rw-r--r--src/zope/tal/tests/test_xmlparser.py9
-rw-r--r--tox.ini4
9 files changed, 74 insertions, 35 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
diff --git a/CHANGES.rst b/CHANGES.rst
index 616b20f..b50e394 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -8,6 +8,7 @@ Changes
argument (passed to ``HTMLParser``). Also ensures that upcoming change
to the default in Python 3.5 will not affect us.
+- Add support for Python 3.2 and PyPy3.
4.1.0 (2014-12-19)
------------------
@@ -114,6 +115,6 @@ Changes
``zope.security``.
.. note::
-
+
Changes before 3.4.0b1 where not tracked as an individual
package and have been documented in the Zope 3 changelog.
diff --git a/setup.py b/setup.py
index 793c179..cfbffe6 100644
--- a/setup.py
+++ b/setup.py
@@ -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 "&#45" as "&#45"
+ if IS_PYPY or sys.version_info[:2] <= (3, 2):
+ # HTMLParser.HTMLParser in Python 2.x--3.2 parses "&#45" as "&#45"
INPUT = ('<img tal:define="foo nothing" '
'alt="&a; &#1; &#x0a; &a &#45 &; <>" />')
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:
diff --git a/tox.ini b/tox.ini
index c4bc1d3..09ae62a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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