Commit 4913d686 authored by Sidnei da Silva's avatar Sidnei da Silva

- Avoid raising string exceptions. If one is found, upgrade it to...

 - Avoid raising string exceptions. If one is found, upgrade it to InternalError and keep the original exception name as part of exc_value
parent d459676a
......@@ -48,7 +48,7 @@ from OFS.interfaces import ICopyContainer
from OFS.interfaces import ICopySource
CopyError='Copy Error'
class CopyError(Exception): pass
copy_re = re.compile('^copy([0-9]*)_of_(.*)')
......
......@@ -36,7 +36,7 @@ from DocumentTemplate.html_quote import html_quote
from DocumentTemplate.ustr import ustr
from ExtensionClass import Base
from webdav.Resource import Resource
from zExceptions import Redirect
from zExceptions import Redirect, InternalError
from zExceptions.ExceptionFormatter import format_exception
from zope.interface import implements
......@@ -181,16 +181,29 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
elif type(tb) is type('') and not error_tb:
error_tb = tb
# turn error_type into a string
if hasattr(error_type, '__name__'):
error_type=error_type.__name__
# warn if error_type is a string
error_name = 'Unknown'
if isinstance(error_type, basestring):
# String Exceptions are deprecated on Python 2.5 and
# plain won't work at all on Python 2.6. So upgrade it
# to an InternalError exception but keep the original
# exception in the value.
error_name = error_type
error_type = InternalError
error_value = (error_name, error_value)
warnings.warn('String exceptions are deprecated starting '
'with Python 2.5 and will be removed in a '
'future release', DeprecationWarning)
else:
if hasattr(error_type, '__name__'):
error_name = error_type.__name__
if hasattr(self, '_v_eek'):
# Stop if there is recursion.
raise error_type, error_value, tb
self._v_eek=1
if str(error_type).lower() in ('redirect',):
if error_name.lower() in ('redirect',):
raise error_type, error_value, tb
if not error_message:
......@@ -216,7 +229,10 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
else:
client = aq_parent(client)
s=getattr(client, 'standard_error_message')
kwargs = {'error_type': error_type,
# For backward compatibility, we pass 'error_name' as
# 'error_type' here as historically this has always
# been a string.
kwargs = {'error_type': error_name,
'error_value': error_value,
'error_tb': error_tb,
'error_traceback': error_tb,
......
......@@ -347,7 +347,7 @@ class TestCopySupportSecurity( CopySupportTestBase ):
if ce_regex is not None:
pattern = re.compile( ce_regex, re.DOTALL )
if pattern.search( e ) is None:
if pattern.search( e.args[0] ) is None:
self.fail( "Paste failed; didn't match pattern:\n%s" % e )
else:
......
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