[Zope-dev] getUserById
Florent Guillaume
fg at nuxeo.com
Mon Dec 13 11:15:50 EST 2004
In article <F312FBAF-4C54-11D9-9062-000D93325646 at epy.co.at> you write:
> In User.py the method is defined as
>
> def getUserById(self, id, default=_marker):
> try:
> return self.getUser(id)
> except:
> if default is _marker: raise
> return default
>
> I am wondering whether anybody actually depends on the fact that
> getUser is supposed to raise an exception. I know of no user folder
> implementation that actually does that.
>
> Rather, I'd like to change it to the way it's done in LDAPUserFolder
> where the method looks (more or less) like:
>
> def getUserById(self, id, default=_marker):
> user = self.getUser(id)
> if user is None and default is not _marker:
> return default
> return user
Can we have instead:
def getUserById(self, id, default=_marker):
"""Return the user corresponding to the given id.
Raises a KeyError if the user does not exist and no default
is provided.
"""
user = self.getUser(id)
if user is not None:
return user
if default is not _marker:
return default
raise KeyError(id)
Florent
--
Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D
+33 1 40 33 71 59 http://nuxeo.com fg at nuxeo.com
More information about the Zope-Dev
mailing list