From 9e836fdcbe585f38e103cde0a89a9b332b2e00c5 Mon Sep 17 00:00:00 2001 From: Sidnei da Silva Date: Sun, 26 Oct 2008 05:59:00 +0000 Subject: [PATCH] - Merge remaining changes from gsoc-python-2.5 branch. We now 'work' on Python 2.6 --- __init__.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 957bc57..fdc8ba2 100644 --- a/__init__.py +++ b/__init__.py @@ -18,12 +18,13 @@ $Id$ """ -from unauthorized import Unauthorized +import warnings from zope.interface import implements from zope.interface.common.interfaces import IException from zope.publisher.interfaces import INotFound from zope.security.interfaces import IForbidden +from zExceptions.unauthorized import Unauthorized class BadRequest(Exception): implements(IException) @@ -42,3 +43,29 @@ class MethodNotAllowed(Exception): class Redirect(Exception): pass + +def upgradeException(t, v): + # If a string exception is found, convert it to an equivalent + # exception defined either in builtins or zExceptions. If none of + # that works, tehn convert it to an InternalError and keep the + # original exception name as part of the exception value. + import zExceptions + + if not isinstance(t, basestring): + return t, v + + warnings.warn('String exceptions are deprecated starting ' + 'with Python 2.5 and will be removed in a ' + 'future release', DeprecationWarning, stacklevel=2) + + n = None + if __builtins__.has_key(t): + n = __builtins__[t] + elif hasattr(zExceptions, t): + n = getattr(zExceptions, t) + if n is not None and issubclass(n, Exception): + t = n + else: + v = t, v + t = InternalError + return t, v