[Zope-Checkins] SVN: Zope/trunk/lib/python/zExceptions/unauthorized.py 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.

Hanno Schlichting plone at hannosch.info
Sat Jan 17 11:52:50 EST 2009


Log message for revision 94803:
  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.
  

Changed:
  U   Zope/trunk/lib/python/zExceptions/unauthorized.py

-=-
Modified: Zope/trunk/lib/python/zExceptions/unauthorized.py
===================================================================
--- Zope/trunk/lib/python/zExceptions/unauthorized.py	2009-01-17 16:39:38 UTC (rev 94802)
+++ Zope/trunk/lib/python/zExceptions/unauthorized.py	2009-01-17 16:52:50 UTC (rev 94803)
@@ -14,7 +14,6 @@
 $Id$
 """
 
-from types import StringType
 from zope.interface import implements
 from zope.security.interfaces import IUnauthorized
 
@@ -38,7 +37,7 @@
         provides are added to needed.
         """
         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
             name=message
             message=None
@@ -53,8 +52,17 @@
 
         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):
-        if self.message is not None: return self.message
+        if self.message is not None:
+            return self.message
         if self.name is not None:
             return ("You are not allowed to access '%s' in this context"
                     % self.name)
@@ -63,7 +71,6 @@
                     % self.getValueName())
         return repr(self)
 
-
     def getValueName(self):
         v=self.value
         vname=getattr(v, '__name__', None)



More information about the Zope-Checkins mailing list