Commit 28d6690c authored by Hanno Schlichting's avatar Hanno Schlichting

Python has deprecated the message attribute of exceptions in 2.6. We will keep...

Python has deprecated the message attribute of exceptions in 2.6. We will keep it for this exception and avoid the warning, as message has a special meaning here.
parent 6b60b643
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
$Id$ $Id$
""" """
from types import StringType
from zope.interface import implements from zope.interface import implements
from zope.security.interfaces import IUnauthorized from zope.security.interfaces import IUnauthorized
...@@ -38,7 +37,7 @@ class Unauthorized(Exception): ...@@ -38,7 +37,7 @@ class Unauthorized(Exception):
provides are added to needed. provides are added to needed.
""" """
if name is None and ( if name is None and (
not isinstance(message, StringType) or len(message.split()) <= 1): not isinstance(message, basestring) or len(message.split()) <= 1):
# First arg is a name, not a message # First arg is a name, not a message
name=message name=message
message=None message=None
...@@ -53,8 +52,17 @@ class Unauthorized(Exception): ...@@ -53,8 +52,17 @@ class Unauthorized(Exception):
self.needed=needed self.needed=needed
# Python has deprecated the message attribute of exceptions in 2.6. We
# will keep it for this exception and avoid the warning.
def _get_message(self, message):
return self._message
def _set_message(self, message):
self._message = message
message = property(_get_message, _set_message)
def __str__(self): def __str__(self):
if self.message is not None: return self.message if self.message is not None:
return self.message
if self.name is not None: if self.name is not None:
return ("You are not allowed to access '%s' in this context" return ("You are not allowed to access '%s' in this context"
% self.name) % self.name)
...@@ -63,7 +71,6 @@ class Unauthorized(Exception): ...@@ -63,7 +71,6 @@ class Unauthorized(Exception):
% self.getValueName()) % self.getValueName())
return repr(self) return repr(self)
def getValueName(self): def getValueName(self):
v=self.value v=self.value
vname=getattr(v, '__name__', None) vname=getattr(v, '__name__', None)
......
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