[Zope3-checkins] CVS: Zope3/src/zope/app/services - auth.py:1.6

Guido van Rossum guido@python.org
Fri, 27 Dec 2002 13:54:18 -0500


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv11919

Modified Files:
	auth.py 
Log Message:
Turns out UnicodeDecodeError is only defined in Python 2.3.
Fortunately, it's a subclass of UnicodeError, and the same condition
raises UnicodeError in Python 2.2.  So use that.

Also some style cleanup: Putting the one-line body of a try or if on
the same line as the try or if (etc.) is ugly, so fixed that; and
added a module level docstring.


=== Zope3/src/zope/app/services/auth.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/services/auth.py:1.5	Fri Dec 27 13:42:09 2002
+++ Zope3/src/zope/app/services/auth.py	Fri Dec 27 13:54:17 2002
@@ -11,10 +11,13 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
+"""Authentication service implementation.
+
 $Id$
 """
+
 from types import TupleType
+
 from persistence import Persistent
 from zodb.btrees.OOBTree import OOBTree
 
@@ -35,8 +38,11 @@
 
 
 
-class DuplicateLogin(Exception): pass
-class DuplicateId(Exception): pass
+class DuplicateLogin(Exception):
+    pass
+
+class DuplicateId(Exception):
+    pass
 
 
 class AuthenticationService(Persistent):
@@ -48,8 +54,10 @@
         self._usersbyid = OOBTree()
 
     def getPrincipalByLogin(self, login):
-        try: return self._usersbylogin[login]
-        except KeyError: raise NotFoundError(login)
+        try:
+            return self._usersbylogin[login]
+        except KeyError:
+            raise NotFoundError(login)
 
     def queryPrincipalByLogin(self, login):
         return self._usersbylogin.get(login)
@@ -80,8 +88,10 @@
 
     def getPrincipal(self, id):
         'See IAuthenticationService'
-        try: return self._usersbyid[id]
-        except KeyError: raise NotFoundError(id)
+        try:
+            return self._usersbyid[id]
+        except KeyError:
+            raise NotFoundError(id)
 
     def getPrincipals(self, name):
         'See IAuthenticationService'
@@ -97,10 +107,14 @@
     def setObject(self, key, object):
         'See IWriteContainer'
         # XXX I think this should generate an id if blank is passed. (RDM)
-        if not isinstance(key, (str, unicode)): raise TypeError(key)
-        try: unicode(key)
-        except UnicodeDecodeError: raise TypeError(key)
-        if not key: raise ValueError(key)
+        if not isinstance(key, (str, unicode)):
+            raise TypeError(key)
+        try:
+            unicode(key)
+        except UnicodeError:
+            raise TypeError(key)
+        if not key:
+            raise ValueError(key)
         self._usersbyid[key] = object
         self._usersbylogin[object.getLogin()] = object
 
@@ -194,6 +208,3 @@
         'See IReadUser'
         annotations = AttributeAnnotations(self)
         annotations['roles'] = roles
-
-    #
-    ############################################################