Commit 507767e1 authored by Vincent Pelletier's avatar Vincent Pelletier

Improve default-value support to improve backward compatibility:

 - return None when no password is set and no default was provided, instead of raising
 - return default (or None) when requested encoding is not present (even if password value is a string)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25616 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 03e08980
......@@ -227,26 +227,35 @@ class Person(XMLObject):
default (anything)
Value to return if no passord is set on context.
Default: no default, raises AttributeError if property is not set.
Default: None
format (string)
String defining the format in which the password is expected.
If passowrd is not available in that format, KeyError will be
raised.
Default: 'default'
"""
password = getattr(aq_base(self), 'password', *args)
marker = []
password = getattr(aq_base(self), 'password', marker)
if password is marker:
if len(args):
password = args[0]
else:
password = None
else:
format = kw.get('format', 'default')
try:
# Backward compatibility: if it's not a PersistentMapping instance,
# assume it's a monovalued string, which corresponds to default
# password encoding.
if isinstance(password, PersistentMapping):
password = password[format]
password = password.get(format, marker)
if password is marker:
if len(args):
password = args[0]
else:
password = None
else:
if format != 'default':
raise KeyError
except KeyError:
raise KeyError, 'Password is not available in %r format.' % (format, )
password = None
return password
# Time management
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment