From 6cb099fb7a6e97248325d2553892a2c8531015e9 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Thu, 4 Jun 2015 15:10:20 -0500 Subject: [PATCH 1/2] Support Python 3.2 Also workaround an issue obvserved where locale can return an empty preferred encoding. --- .travis.yml | 20 +++++++++--------- setup.py | 2 ++ src/zope/applicationcontrol/runtimeinfo.py | 20 +++++++++++------- .../tests/test_runtimeinfo.py | 21 ++++++++++++------- tox.ini | 3 +-- 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index a8be229..83db3d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,16 @@ language: python sudo: false -python: - - 2.6 - - 2.7 - - 3.3 - - 3.4 - - pypy - - pypy3 +env: + - TOXENV=py26 + - TOXENV=py27 + - TOXENV=py32 + - TOXENV=py33 + - TOXENV=py34 + - TOXENV=pypy + - TOXENV=pypy3 install: - - pip install - - pip install zope.applicationcontrol[test] + - pip install tox script: - - python setup.py -q test -q + - tox notifications: email: false diff --git a/setup.py b/setup.py index 4396a0b..3ff38a0 100644 --- a/setup.py +++ b/setup.py @@ -61,9 +61,11 @@ def alltests(): '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', + 'Programming Language :: Python :: Implementation :: PyPy', 'Natural Language :: English', 'Operating System :: OS Independent', 'Topic :: Internet :: WWW/HTTP', diff --git a/src/zope/applicationcontrol/runtimeinfo.py b/src/zope/applicationcontrol/runtimeinfo.py index dad5fb7..b52181a 100644 --- a/src/zope/applicationcontrol/runtimeinfo.py +++ b/src/zope/applicationcontrol/runtimeinfo.py @@ -39,6 +39,10 @@ appsetup = None PY3 = sys.version_info[0] == 3 +if PY3: + _u = str +else: + _u = unicode @implementer(IRuntimeInfo) @adapter(IApplicationControl) @@ -62,12 +66,14 @@ def getDeveloperMode(self): def getPreferredEncoding(self): """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" - if locale is not None: - try: - return locale.getpreferredencoding() - except locale.Error: - pass - return sys.getdefaultencoding() + try: + result = locale.getpreferredencoding() + except (locale.Error, AttributeError): + result = '' + # Under some systems, getpreferredencoding() can return '' + # (e.g., Python 2.7/MacOSX/LANG=en_us.UTF-8). This then blows + # up with 'unknown encoding' + return result or sys.getdefaultencoding() def getFileSystemEncoding(self): """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" @@ -105,7 +111,7 @@ def getSystemPlatform(self): except ValueError: continue info.append(t) - return u" ".join(info) + return _u(" ").join(info) def getCommandLine(self): """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" diff --git a/src/zope/applicationcontrol/tests/test_runtimeinfo.py b/src/zope/applicationcontrol/tests/test_runtimeinfo.py index 365d7bf..ec76132 100644 --- a/src/zope/applicationcontrol/tests/test_runtimeinfo.py +++ b/src/zope/applicationcontrol/tests/test_runtimeinfo.py @@ -31,6 +31,11 @@ stupid_version_string = "3085t0klvn93850voids" PY3 = sys.version_info[0] == 3 +if PY3: + _u = str +else: + _u = unicode + @implementer(IZopeVersion) class TestZopeVersion(object): @@ -47,12 +52,14 @@ def _Test__new(self): return RuntimeInfo(applicationController) def _getPreferredEncoding(self): - if locale is not None: - try: - return locale.getpreferredencoding() - except locale.Error: - pass - return sys.getdefaultencoding() + try: + result = locale.getpreferredencoding() + except (locale.Error, AttributeError): + result = '' + # Under some systems, getpreferredencoding() can return '' + # (e.g., Python 2.7/MacOSX/LANG=en_us.UTF-8). This then blows + # up with 'unknown encoding' + return result or sys.getdefaultencoding() def _getFileSystemEncoding(self): enc = sys.getfilesystemencoding() @@ -77,7 +84,7 @@ def test_ZopeVersion(self): runtime_info = self._Test__new() # we expect that there is no utility - self.assertEqual(runtime_info.getZopeVersion(), u"Unavailable") + self.assertEqual(runtime_info.getZopeVersion(), _u("Unavailable")) siteManager = component.getSiteManager() siteManager.registerUtility(TestZopeVersion(), IZopeVersion) diff --git a/tox.ini b/tox.ini index f78aecc..3da49d6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py26,py27,py33,py34,pypy,pypy3 + py26,py27,py32,py33,py34,pypy,pypy3 [testenv] commands = @@ -15,4 +15,3 @@ deps = zope.traversing zope.testing zope.testrunner - From 9c0bab2e333529288b31d96b30ab752e0246ae70 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 5 Jun 2015 12:58:24 -0400 Subject: [PATCH 2/2] Work around pip + wheel + conditional deps in zope.schema. --- tox.ini | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tox.ini b/tox.ini index 3da49d6..d4ca877 100644 --- a/tox.ini +++ b/tox.ini @@ -15,3 +15,10 @@ deps = zope.traversing zope.testing zope.testrunner + +[testenv:py26] +commands = + {[testenv]commands} +deps = + {[testenv]deps} + ordereddict