[Zope-dev] getUserById

Lennart Regebro regebro at nuxeo.com
Mon Dec 13 13:56:32 EST 2004


Stefan H. Holek wrote:
> 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
> 
> Any objections?

def getUserById(self, id, default=None):
     user = self.getUser(id)
     if user is None:
         return default
     return user

Seems easier to do the same thing, And in fact, if it shouldn't raise 
anything, then it shouldn't have a default at all.

def getUserById(self, id):
     return self.getUser(id)

But that would break anything that actually calls default...

-- 
Lennart Regebro, Nuxeo     http://www.nuxeo.com/
CPS Content Management     http://www.cps-project.org/


More information about the Zope-Dev mailing list