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