Commit 51ca8043 authored by Hanno Schlichting's avatar Hanno Schlichting

Start using six and canonicalize version_info check.

parent 3f9d9434
......@@ -64,6 +64,7 @@ setup(
'five.globalrequest',
'repoze.retry',
'setuptools',
'six',
'transaction',
'waitress',
'zExceptions >= 3.2',
......
......@@ -17,6 +17,8 @@ Extensions currently include external methods.
import imp
import os
from six import exec_
import Products
from zExceptions import NotFound
......@@ -184,7 +186,7 @@ def getObject(module, name, reload=0,
raise NotFound("The specified module, '%s', "
"couldn't be opened." % module)
module_dict = {}
exec execsrc in module_dict
exec_(execsrc, module_dict)
if old is not None:
# XXX Accretive??
......
......@@ -48,7 +48,7 @@ from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
from zope.lifecycleevent import ObjectCreatedEvent
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
manage_addFileForm = DTMLFile(
......
......@@ -24,6 +24,8 @@ import re
import sys
import time
from six import reraise
from AccessControl.class_init import InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.SecurityManagement import getSecurityManager
......@@ -189,7 +191,7 @@ class Item(Base,
if hasattr(self, '_v_eek'):
# Stop if there is recursion.
raise error_type, error_value, tb
reraise(error_type, error_value, tb)
self._v_eek = 1
if hasattr(error_type, '__name__'):
......
......@@ -22,6 +22,7 @@ from Acquisition import Explicit
from App.special_dtml import DTMLFile
from OFS.SimpleItem import Item
from Persistence import Overridable
from six import exec_
from ZODB.broken import Broken as ZODB_Broken
from ZODB.broken import persistentBroken
......@@ -58,8 +59,8 @@ def Broken(self, oid, pair):
else:
module, klassname = pair
d = {'BrokenClass': BrokenClass}
exec("class %s(BrokenClass): ' '; __module__=%r" %
(klassname, module)) in d
exec_("class %s(BrokenClass): ' '; __module__=%r" %
(klassname, module), d)
klass = broken_klasses[pair] = d[klassname]
module = module.split('.')
if len(module) > 2 and module[0] == 'Products':
......
......@@ -27,7 +27,7 @@ from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from Products.Five.browser.metaconfigure import page
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
basestring = str
logger = logging.getLogger('Products.Five')
......
......@@ -47,7 +47,7 @@ from zope.contentprovider.tales import TALESProviderExpression
from Products.PageTemplates import ZRPythonExpr
from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
basestring = str
unicode = str
......
......@@ -24,7 +24,7 @@ from DocumentTemplate.security import RestrictedDTML
from RestrictedPython import compile_restricted_eval
from zope.tales.pythonexpr import PythonExpr
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
......
......@@ -45,7 +45,7 @@ from Products.PageTemplates.utils import encodingFromXMLPreamble
from Products.PageTemplates.utils import charsetFromMetaEquiv
from Products.PageTemplates.utils import convertToUnicode
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
preferred_encodings = ['utf-8', 'iso-8859-15']
......
......@@ -5,7 +5,7 @@ import unittest
from zope.component.testing import PlacelessSetup
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
......
......@@ -27,7 +27,7 @@ from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
from Products.PageTemplates.unicodeconflictresolver import \
DefaultUnicodeEncodingConflictResolver
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
......
......@@ -26,7 +26,7 @@ from Products.PageTemplates.unicodeconflictresolver \
import PreferredCharsetResolver
import Zope2
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
ascii_str = '<html><body>hello world</body></html>'
......
......@@ -20,7 +20,7 @@ from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
from zope.interface import implements
from zope.i18n.interfaces import IUserPreferredCharsets
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
default_encoding = sys.getdefaultencoding()
......
......@@ -16,7 +16,7 @@
import re
import sys
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
xml_preamble_reg = re.compile(
......
......@@ -14,6 +14,8 @@
import re
import string
from six import exec_
from AccessControl.class_init import InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.SecurityManagement import getSecurityManager
......@@ -23,7 +25,6 @@ from AccessControl.unauthorized import Unauthorized
from AccessControl.ZopeGuards import guarded_getattr
from Acquisition import aq_parent
from Acquisition import aq_inner
from Persistence import Persistent
defaultBindings = {'name_context': 'context',
'name_container': 'container',
......@@ -207,7 +208,7 @@ class Bindings:
security.declareProtected('Change bindings', 'ZBindings_edit')
def ZBindings_edit(self, mapping):
names = self._setupBindings(mapping)
self._setupBindings(mapping)
self._prepareBindCode()
self._editedBindings()
......@@ -356,7 +357,7 @@ class Bindings:
bound_data = {}
else:
bound_data = []
exec bindcode
exec_(bindcode)
bound_data = bound_data[0]
return self._exec(bound_data, args, kw)
finally:
......
......@@ -26,6 +26,9 @@ Typically used as in
import os
import sys
import time
from six import exec_
from Testing.ZopeTestCase import layer
# Allow code to tell it is run by the test framework
......@@ -54,7 +57,7 @@ def _exec(cmd):
'''Prints the time it takes to execute 'cmd'.'''
if os.environ.get('X', None):
start = time.time()
exec cmd
exec_(cmd)
_print('(%.3fs)' % (time.time() - start))
_write('Loading Zope, please stand by ')
......
......@@ -46,7 +46,7 @@ from ZPublisher.BaseRequest import BaseRequest
from ZPublisher.BaseRequest import quote
from ZPublisher.Converters import get_converter
if sys.version_info >= (3, 0):
if sys.version_info >= (3, ):
unicode = str
# Flags
......
......@@ -18,6 +18,7 @@ from thread import allocate_lock
import transaction
from urlparse import urlparse
from six import reraise
from zExceptions import Redirect
from zope.event import notify
from zope.publisher.interfaces import ISkinnable
......@@ -45,7 +46,7 @@ class Retry(Exception):
if tb is None:
raise t(v)
try:
raise t, v, tb
reraise(t, v, tb)
finally:
tb = None
......@@ -310,7 +311,7 @@ def publish_module_standard(
request.response._requestShutdown(code)
try:
raise must_die[0], must_die[1], must_die[2]
reraise(must_die[0], must_die[1], must_die[2])
finally:
must_die = None
......@@ -378,10 +379,9 @@ def get_module_info(module_name, modules={},
modules[module_name] = modules[module_name + '.cgi'] = info
return info
except:
except Exception:
t, v, tb = sys.exc_info()
v = str(v)
raise ImportError, (t, v), tb
reraise(t, str(v), tb)
finally:
tb = None
release()
......
......@@ -119,7 +119,8 @@ def testBeforeTraverse(self):
Unregister the borken hook:
>>> _ = BeforeTraverse.unregisterBeforeTraverse(container, 'broken_callable')
>>> _ = BeforeTraverse.unregisterBeforeTraverse(
... container, 'broken_callable')
The list of 'before traverse' hooks is empty:
......
......@@ -188,7 +188,6 @@ class XMLRPCResponseTests(unittest.TestCase):
def test_functionattribute(self):
# Cannot marshal functions or methods, obviously
import sys
import xmlrpclib
def foo():
......@@ -198,11 +197,8 @@ class XMLRPCResponseTests(unittest.TestCase):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
if sys.version_info < (2, 6):
self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, faux._body)
else:
func = xmlrpclib.loads(faux._body)
self.assertEqual(func, (({'public': {}},), None))
func = xmlrpclib.loads(faux._body)
self.assertEqual(func, (({'public': {}},), None))
def test_emptystringattribute(self):
# Test an edge case: attribute name '' is possible,
......
......@@ -18,6 +18,8 @@ import logging
import sys
from time import asctime
from six import reraise
import AccessControl.User
import App.ZApplication
import ExtensionClass
......@@ -196,7 +198,7 @@ class ZPublisherExceptionHook:
def __call__(self, published, REQUEST, t, v, traceback):
try:
if t is SystemExit or issubclass(t, Redirect):
raise t, v, traceback
reraise(t, v, traceback)
if issubclass(t, ConflictError):
self.logConflicts(v, REQUEST)
......@@ -227,7 +229,7 @@ class ZPublisherExceptionHook:
if (REQUEST is None or
(getattr(REQUEST.get('RESPONSE', None),
'_error_format', '') != 'text/html')):
raise t, v, traceback
reraise(t, v, traceback)
# Lookup a view for the exception and render it, then
# raise the rendered value as the exception value
......@@ -247,7 +249,7 @@ class ZPublisherExceptionHook:
# correctly. We can't do that with all exceptions
# because some don't work with the rendered v as
# argument.
raise t, v, traceback
reraise(t, v, traceback)
response = REQUEST.RESPONSE
response.setStatus(t)
response.setBody(v)
......@@ -265,7 +267,7 @@ class ZPublisherExceptionHook:
if f is None:
published = aq_parent(published)
if published is None:
raise t, v, traceback
reraise(t, v, traceback)
else:
break
......@@ -293,7 +295,7 @@ class ZPublisherExceptionHook:
# correctly. We can't do that with all exceptions
# because some don't work with the rendered v as
# argument.
raise t, v, traceback
reraise(t, v, traceback)
response = REQUEST.RESPONSE
response.setStatus(t)
response.setBody(v)
......
......@@ -31,7 +31,7 @@ import os
import sys
import copyzopeskel
if sys.version_info > (3, 0):
if sys.version_info > (3, ):
raw_input = input
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment