[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/authentication/ Fixed incorrect behavior of PAU's getPrincipal: IAuthentication says it should raise PrincipalLookupError -- it was returning None.

Garrett Smith garrett at mojave-corp.com
Fri Apr 1 18:38:22 EST 2005


Log message for revision 29823:
  Fixed incorrect behavior of PAU's getPrincipal: IAuthentication says it should raise PrincipalLookupError -- it was returning None.

Changed:
  U   Zope3/trunk/src/zope/app/authentication/README.txt
  U   Zope3/trunk/src/zope/app/authentication/authentication.py

-=-
Modified: Zope3/trunk/src/zope/app/authentication/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/authentication/README.txt	2005-04-01 23:37:19 UTC (rev 29822)
+++ Zope3/trunk/src/zope/app/authentication/README.txt	2005-04-01 23:38:21 UTC (rev 29823)
@@ -327,13 +327,16 @@
 search capability, so when we look for a principal:
 
   >>> print pau.getPrincipal('bob')
-  None
+  Traceback (most recent call last):
+  PrincipalLookupError: 'bob'
 
   >>> print pau.getPrincipal('white')
-  None
+  Traceback (most recent call last):
+  PrincipalLookupError: 'white'
 
   >>> print pau.getPrincipal('black')
-  None
+  Traceback (most recent call last):
+  PrincipalLookupError: 'black'
 
 For a PAU to support search, it needs to be configured with one or more
 authenticator plugins that support search. To illustrate, we'll create a new
@@ -386,7 +389,8 @@
 but only those it knows about:
 
   >>> print pau.getPrincipal('black')
-  None
+  Traceback (most recent call last):
+  PrincipalLookupError: 'black'
 
 Found Principal Creates Events
 ------------------------------

Modified: Zope3/trunk/src/zope/app/authentication/authentication.py
===================================================================
--- Zope3/trunk/src/zope/app/authentication/authentication.py	2005-04-01 23:37:19 UTC (rev 29822)
+++ Zope3/trunk/src/zope/app/authentication/authentication.py	2005-04-01 23:38:21 UTC (rev 29823)
@@ -21,7 +21,7 @@
 
 from zope import component
 from zope.schema.interfaces import ISourceQueriables
-from zope.app.security.interfaces import IAuthentication
+from zope.app.security.interfaces import IAuthentication, PrincipalLookupError
 from zope.app.component import queryNextUtility
 from zope.app.component.site import SiteManagementFolder
 
@@ -82,7 +82,9 @@
             principal.id = self.prefix + info.id
             return principal
         next = queryNextUtility(self, IAuthentication)
-        return (next is not None) and next.getPrincipal(self.prefix+id) or None
+        if next is not None:
+            return next.getPrincipal(self.prefix + id)
+        raise PrincipalLookupError(id)
 
     def getQueriables(self):
         for name in self.authenticatorPlugins:



More information about the Zope3-Checkins mailing list