[Zope3-checkins] SVN: Zope3/trunk/src/zope/exceptions/ Removed
dependency on i18n. zope.exceptions shouldn't be trying to set
Jim Fulton
jim at zope.com
Wed Jul 7 13:42:50 EDT 2004
Log message for revision 26171:
Removed dependency on i18n. zope.exceptions shouldn't be trying to set
the domain of strings padded to Unauthorized. It turns out that in
all cases that mattered, the strings passed were ignored.
-=-
Modified: Zope3/trunk/src/zope/exceptions/__init__.py
===================================================================
--- Zope3/trunk/src/zope/exceptions/__init__.py 2004-07-07 17:38:47 UTC (rev 26170)
+++ Zope3/trunk/src/zope/exceptions/__init__.py 2004-07-07 17:42:50 UTC (rev 26171)
@@ -19,16 +19,6 @@
$Id$
"""
-# XXX catching import errors is almost always evil
-# This module should be independent of I18n, so let's not require it.
-try:
- from zope.i18n import MessageIDFactory
-except ImportError:
- ZopeMessageIDFactory = unicode
-else:
- # Import _ to use to create message ids in the zope domain
- ZopeMessageIDFactory = MessageIDFactory('zope')
-
from zope.exceptions._zope_error import ZopeError, IZopeError
from zope.exceptions.unauthorized import Unauthorized, IUnauthorized
from zope.exceptions._notfounderror import NotFoundError, INotFoundError
Modified: Zope3/trunk/src/zope/exceptions/unauthorized.py
===================================================================
--- Zope3/trunk/src/zope/exceptions/unauthorized.py 2004-07-07 17:38:47 UTC (rev 26170)
+++ Zope3/trunk/src/zope/exceptions/unauthorized.py 2004-07-07 17:42:50 UTC (rev 26171)
@@ -15,13 +15,10 @@
$Id$
"""
-from types import StringType
from zope.exceptions import ZopeError
from zope.exceptions import IZopeError
-from zope.exceptions import ZopeMessageIDFactory as _
from zope.interface import implements
-
class IUnauthorized(IZopeError):
pass
@@ -29,57 +26,3 @@
"""Some user wasn't allowed to access a resource"""
implements(IUnauthorized)
-
- def __init__(self, message=None, value=None, needed=None, name=None, **kw):
- """Possible signatures:
-
- Unauthorized()
- Unauthorized(message) # Note that message includes a space
- Unauthorized(name)
- Unauthorized(name, value)
- Unauthorized(name, value, needed)
- Unauthorized(message, value, needed, name)
-
- Where needed is a mapping objects with items represnting requirements
- (e.g. {'permission': 'add spam'}). Any extra keyword arguments
- provides are added to needed.
- """
- if name is None and (
- not isinstance(message, StringType) or len(message.split()) <= 1):
- # First arg is a name, not a message
- name = message
- message = None
-
- self.name = name
- self.message = message
- self.value = value
-
- if kw:
- if needed:
- needed.update(kw)
- else:
- needed = kw
-
- self.needed = needed
-
- def __str__(self):
- if self.message is not None:
- return _(self.message)
- if self.name is not None:
- msg = _("You are not allowed to access ${name} in this context")
- msg.mapping = {'name': self.name}
- elif self.value is not None:
- msg = _("You are not allowed to access ${name} in this context")
- msg.mapping = {'name': self.getValueName()}
- return _("You are not authorized")
-
-
- def getValueName(self):
- v = self.value
- vname = getattr(v, '__name__', None)
- if vname:
- return vname
- c = getattr(v, '__class__', type(v))
- c = getattr(c, '__name__', 'object')
- msg = _("a particular ${object}")
- msg.mapping = {'object': c}
More information about the Zope3-Checkins
mailing list